OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [sound/] [dev_table.c] - Blame information for rev 1626

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*
2
 * sound/dev_table.c
3
 *
4
 * Device call tables.
5
 */
6
/*
7
 * Copyright (C) by Hannu Savolainen 1993-1996
8
 *
9
 * USS/Lite for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10
 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11
 * for more info.
12
 */
13
#include <linux/config.h>
14
 
15
 
16
#define _DEV_TABLE_C_
17
#include "sound_config.h"
18
 
19
int             sound_started = 0;
20
 
21
int             sndtable_get_cardcount (void);
22
 
23
int
24
snd_find_driver (int type)
25
{
26
  int             i, n = num_sound_drivers;
27
 
28
  for (i = 0; i < n; i++)
29
    if (sound_drivers[i].card_type == type)
30
      return i;
31
 
32
  return -1;
33
}
34
 
35
static void
36
start_services (void)
37
{
38
  int             soundcards_installed;
39
 
40
  if (!(soundcards_installed = sndtable_get_cardcount ()))
41
    return;                     /* No cards detected */
42
 
43
#ifdef CONFIG_AUDIO
44
  if (num_audiodevs)            /* Audio devices present */
45
    {
46
      DMAbuf_init ();
47
      audio_init ();
48
    }
49
#endif
50
 
51
#ifdef CONFIG_MIDI
52
  if (num_midis)
53
    MIDIbuf_init ();
54
#endif
55
 
56
#ifdef CONFIG_SEQUENCER
57
  if (num_midis + num_synths)
58
    sequencer_init ();
59
#endif
60
  return;
61
}
62
 
63
static void
64
start_cards (void)
65
{
66
  int             i, n = num_sound_cards;
67
  int             drv;
68
 
69
  sound_started = 1;
70
  if (trace_init)
71
    printk ("Sound initialization started\n");
72
 
73
/*
74
 * Check the number of cards actually defined in the table
75
 */
76
 
77
  for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
78
    num_sound_cards = i + 1;
79
 
80
  for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
81
    if (snd_installed_cards[i].enabled)
82
      {
83
        snd_installed_cards[i].for_driver_use = NULL;
84
 
85
        if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) == -1)
86
          {
87
            snd_installed_cards[i].enabled = 0;          /*
88
                                                         * Mark as not detected
89
                                                         */
90
            continue;
91
          }
92
 
93
        snd_installed_cards[i].config.card_subtype =
94
          sound_drivers[drv].card_subtype;
95
 
96
        if (sound_drivers[drv].probe (&snd_installed_cards[i].config))
97
          {
98
 
99
            sound_drivers[drv].attach (&snd_installed_cards[i].config);
100
 
101
          }
102
        else
103
          snd_installed_cards[i].enabled = 0;    /*
104
                                                 * Mark as not detected
105
                                                 */
106
      }
107
 
108
  if (trace_init)
109
    printk ("Sound initialization complete\n");
110
}
111
 
112
void
113
sndtable_init (void)
114
{
115
  return start_cards ();
116
}
117
 
118
void
119
sound_unload_drivers (void)
120
{
121
  int             i, n = num_sound_cards;
122
  int             drv;
123
 
124
  if (!sound_started)
125
    return;
126
 
127
  if (trace_init)
128
    printk ("Sound unload started\n");
129
 
130
  for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
131
    if (snd_installed_cards[i].enabled)
132
      if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) != -1)
133
        if (sound_drivers[drv].unload)
134
          {
135
            sound_drivers[drv].unload (&snd_installed_cards[i].config);
136
            snd_installed_cards[i].enabled = 0;
137
          }
138
 
139
  if (trace_init)
140
    printk ("Sound unload complete\n");
141
}
142
 
143
void
144
sound_unload_driver (int type)
145
{
146
  int             i, drv = -1, n = num_sound_cards;
147
 
148
  unsigned long   flags;
149
 
150
  DDB (printk ("unload driver %d: ", type));
151
 
152
  for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
153
    if (snd_installed_cards[i].card_type == type)
154
      {
155
        if (snd_installed_cards[i].enabled)
156
          {
157
            if ((drv = snd_find_driver (type)) != -1)
158
              {
159
                DDB (printk (" card %d", i));
160
                if (sound_drivers[drv].unload)
161
                  {
162
                    sound_drivers[drv].unload (&snd_installed_cards[i].config);
163
                    snd_installed_cards[i].enabled = 0;
164
                  }
165
              }
166
          }
167
      }
168
  DDB (printk ("\n"));
169
 
170
  save_flags (flags);
171
  cli ();
172
 
173
  restore_flags (flags);
174
}
175
 
176
 
177
int
178
sndtable_probe (int unit, struct address_info *hw_config)
179
{
180
  int             sel = -1;
181
 
182
  DDB (printk ("sndtable_probe(%d)\n", unit));
183
 
184
  if (!unit)
185
    return TRUE;
186
 
187
  sound_started = 1;
188
 
189
 
190
  if (sel == -1 && num_sound_cards < max_sound_cards)
191
    {
192
      int             i;
193
 
194
      i = sel = (num_sound_cards++);
195
 
196
      snd_installed_cards[sel].card_type = unit;
197
      snd_installed_cards[sel].enabled = 1;
198
    }
199
 
200
  if (sel != -1)
201
    {
202
      int             drv;
203
 
204
      snd_installed_cards[sel].for_driver_use = NULL;
205
      snd_installed_cards[sel].config.io_base = hw_config->io_base;
206
      snd_installed_cards[sel].config.irq = hw_config->irq;
207
      snd_installed_cards[sel].config.dma = hw_config->dma;
208
      snd_installed_cards[sel].config.dma2 = hw_config->dma2;
209
      snd_installed_cards[sel].config.name = hw_config->name;
210
      snd_installed_cards[sel].config.always_detect = hw_config->always_detect;
211
      snd_installed_cards[sel].config.driver_use_1 = hw_config->driver_use_1;
212
      snd_installed_cards[sel].config.driver_use_2 = hw_config->driver_use_2;
213
      snd_installed_cards[sel].config.card_subtype = hw_config->card_subtype;
214
      snd_installed_cards[sel].config.osp = hw_config->osp;
215
 
216
      if ((drv = snd_find_driver (snd_installed_cards[sel].card_type)) == -1)
217
        {
218
          snd_installed_cards[sel].enabled = 0;
219
          DDB (printk ("Failed to find driver\n"));
220
          return FALSE;
221
        }
222
      DDB (printk ("Driver name '%s'\n", sound_drivers[drv].name));
223
 
224
      hw_config->card_subtype =
225
        snd_installed_cards[sel].config.card_subtype =
226
        sound_drivers[drv].card_subtype;
227
 
228
      if (sound_drivers[drv].probe (hw_config))
229
        {
230
          DDB (printk ("Hardware probed OK\n"));
231
          return TRUE;
232
        }
233
 
234
      DDB (printk ("Failed to find hardware\n"));
235
      snd_installed_cards[sel].enabled = 0;      /*
236
                                                 * Mark as not detected
237
                                                 */
238
      return FALSE;
239
    }
240
 
241
  return FALSE;
242
}
243
 
244
int
245
sndtable_start_card (int unit, struct address_info *hw_config)
246
{
247
  int             sel = -1;
248
 
249
  DDB (printk ("sndtable_probe(%d)\n", unit));
250
 
251
  if (!unit)
252
    return TRUE;
253
 
254
  sound_started = 1;
255
 
256
  if (sel == -1 && num_sound_cards < max_sound_cards)
257
    {
258
      int             i;
259
 
260
      i = sel = (num_sound_cards++);
261
 
262
      snd_installed_cards[sel].card_type = unit;
263
      snd_installed_cards[sel].enabled = 1;
264
    }
265
 
266
  if (sel != -1)
267
    {
268
      int             drv;
269
 
270
      snd_installed_cards[sel].for_driver_use = NULL;
271
      snd_installed_cards[sel].config.io_base = hw_config->io_base;
272
      snd_installed_cards[sel].config.irq = hw_config->irq;
273
      snd_installed_cards[sel].config.dma = hw_config->dma;
274
      snd_installed_cards[sel].config.dma2 = hw_config->dma2;
275
      snd_installed_cards[sel].config.name = hw_config->name;
276
      snd_installed_cards[sel].config.always_detect = hw_config->always_detect;
277
      snd_installed_cards[sel].config.driver_use_1 = hw_config->driver_use_1;
278
      snd_installed_cards[sel].config.driver_use_2 = hw_config->driver_use_2;
279
      snd_installed_cards[sel].config.card_subtype = hw_config->card_subtype;
280
      snd_installed_cards[sel].config.osp = hw_config->osp;
281
 
282
      if ((drv = snd_find_driver (snd_installed_cards[sel].card_type)) == -1)
283
        {
284
          snd_installed_cards[sel].enabled = 0;
285
          DDB (printk ("Failed to find driver\n"));
286
          return FALSE;
287
        }
288
      DDB (printk ("Driver name '%s'\n", sound_drivers[drv].name));
289
 
290
      hw_config->card_subtype =
291
        snd_installed_cards[sel].config.card_subtype =
292
        sound_drivers[drv].card_subtype;
293
 
294
      if (sound_drivers[drv].probe (hw_config))
295
        {
296
          DDB (printk ("Hardware probed OK\n"));
297
          sound_drivers[drv].attach (hw_config);
298
          start_services ();
299
          return TRUE;
300
        }
301
 
302
      DDB (printk ("Failed to find hardware\n"));
303
      snd_installed_cards[sel].enabled = 0;      /*
304
                                                 * Mark as not detected
305
                                                 */
306
      return FALSE;
307
    }
308
 
309
  return FALSE;
310
}
311
 
312
int
313
sndtable_init_card (int unit, struct address_info *hw_config)
314
{
315
  int             i, n = num_sound_cards;
316
 
317
  DDB (printk ("sndtable_init_card(%d) entered\n", unit));
318
 
319
  if (!unit)
320
    {
321
      sndtable_init ();
322
      return TRUE;
323
    }
324
 
325
  for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
326
    if (snd_installed_cards[i].card_type == unit)
327
      {
328
        int             drv;
329
 
330
        snd_installed_cards[i].config.io_base = hw_config->io_base;
331
        snd_installed_cards[i].config.irq = hw_config->irq;
332
        snd_installed_cards[i].config.dma = hw_config->dma;
333
        snd_installed_cards[i].config.dma2 = hw_config->dma2;
334
        snd_installed_cards[i].config.name = hw_config->name;
335
        snd_installed_cards[i].config.always_detect = hw_config->always_detect;
336
        snd_installed_cards[i].config.driver_use_1 = hw_config->driver_use_1;
337
        snd_installed_cards[i].config.driver_use_2 = hw_config->driver_use_2;
338
        snd_installed_cards[i].config.card_subtype = hw_config->card_subtype;
339
        snd_installed_cards[i].config.osp = hw_config->osp;
340
 
341
        if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) == -1)
342
          snd_installed_cards[i].enabled = 0;    /*
343
                                                 * Mark as not detected
344
                                                 */
345
        else
346
          {
347
 
348
            DDB (printk ("Located card - calling attach routine\n"));
349
            sound_drivers[drv].attach (hw_config);
350
 
351
            DDB (printk ("attach routine finished\n"));
352
          }
353
        start_services ();
354
        return TRUE;
355
      }
356
 
357
  DDB (printk ("sndtable_init_card: No card defined with type=%d, num cards: %d\n",
358
               unit, num_sound_cards));
359
  return FALSE;
360
}
361
 
362
int
363
sndtable_get_cardcount (void)
364
{
365
  return num_audiodevs + num_mixers + num_synths + num_midis;
366
}
367
 
368
int
369
sndtable_identify_card (char *name)
370
{
371
  int             i, n = num_sound_drivers;
372
 
373
  if (name == NULL)
374
    return 0;
375
 
376
  for (i = 0; i < n; i++)
377
    if (sound_drivers[i].driver_id != NULL)
378
      {
379
        char           *id = sound_drivers[i].driver_id;
380
        int             j;
381
 
382
        for (j = 0; j < 80 && name[j] == id[j]; j++)
383
          if (id[j] == 0 && name[j] == 0) /* Match */
384
            return sound_drivers[i].card_type;
385
      }
386
 
387
  return 0;
388
}
389
 
390
void
391
sound_setup (char *str, int *ints)
392
{
393
  int             i, n = num_sound_cards;
394
 
395
  /*
396
     * First disable all drivers
397
   */
398
 
399
  for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
400
    snd_installed_cards[i].enabled = 0;
401
 
402
  if (ints[0] == 0 || ints[1] == 0)
403
    return;
404
  /*
405
     * Then enable them one by time
406
   */
407
 
408
  for (i = 1; i <= ints[0]; i++)
409
    {
410
      int             card_type, ioaddr, irq, dma, dma2, ptr, j;
411
      unsigned int    val;
412
 
413
      val = (unsigned int) ints[i];
414
 
415
      card_type = (val & 0x0ff00000) >> 20;
416
 
417
      if (card_type > 127)
418
        {
419
          /*
420
           * Add any future extensions here
421
           */
422
          return;
423
        }
424
 
425
      ioaddr = (val & 0x000fff00) >> 8;
426
      irq = (val & 0x000000f0) >> 4;
427
      dma = (val & 0x0000000f);
428
      dma2 = (val & 0xf0000000) >> 28;
429
 
430
      ptr = -1;
431
      for (j = 0; j < n && ptr == -1; j++)
432
        if (snd_installed_cards[j].card_type == card_type &&
433
            !snd_installed_cards[j].enabled)    /*
434
                                                 * Not already found
435
                                                 */
436
          ptr = j;
437
 
438
      if (ptr == -1)
439
        printk ("Sound: Invalid setup parameter 0x%08x\n", val);
440
      else
441
        {
442
          snd_installed_cards[ptr].enabled = 1;
443
          snd_installed_cards[ptr].config.io_base = ioaddr;
444
          snd_installed_cards[ptr].config.irq = irq;
445
          snd_installed_cards[ptr].config.dma = dma;
446
          snd_installed_cards[ptr].config.dma2 = dma2;
447
          snd_installed_cards[ptr].config.name = NULL;
448
          snd_installed_cards[ptr].config.always_detect = 0;
449
          snd_installed_cards[ptr].config.driver_use_1 = 0;
450
          snd_installed_cards[ptr].config.driver_use_2 = 0;
451
          snd_installed_cards[ptr].config.card_subtype = 0;
452
          snd_installed_cards[ptr].config.osp = NULL;
453
        }
454
    }
455
}
456
 
457
 
458
struct address_info
459
               *
460
sound_getconf (int card_type)
461
{
462
  int             j, ptr;
463
  int             n = num_sound_cards;
464
 
465
  ptr = -1;
466
  for (j = 0; j < n && ptr == -1 && snd_installed_cards[j].card_type; j++)
467
    if (snd_installed_cards[j].card_type == card_type)
468
      ptr = j;
469
 
470
  if (ptr == -1)
471
    return (struct address_info *) NULL;
472
 
473
  return &snd_installed_cards[ptr].config;
474
}
475
 
476
 
477
 
478
int
479
sound_install_audiodrv (int vers,
480
                        char *name,
481
                        struct audio_driver *driver,
482
                        int driver_size,
483
                        int flags,
484
                        unsigned int format_mask,
485
                        void *devc,
486
                        int dma1,
487
                        int dma2)
488
{
489
  struct audio_driver *d;
490
  struct audio_operations *op;
491
  int             l, num;
492
 
493
  if (num_audiodevs >= MAX_AUDIO_DEV)
494
    {
495
      printk ("Sound: Too many audio drivers\n");
496
      return -(EIO);
497
    }
498
 
499
  if (vers != AUDIO_DRIVER_VERSION ||
500
      driver_size > sizeof (struct audio_driver))
501
    {
502
      printk ("Sound: Incompatible audio driver for %s\n", name);
503
      return -(EIO);
504
    }
505
 
506
 
507
  d = (struct audio_driver *) (sound_mem_blocks[sound_nblocks] = vmalloc (sizeof (struct audio_driver)));
508
 
509
  if (sound_nblocks < 1024)
510
    sound_nblocks++;;
511
 
512
  op = (struct audio_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc (sizeof (struct audio_operations)));
513
 
514
  if (sound_nblocks < 1024)
515
    sound_nblocks++;;
516
  if (d == NULL || op == NULL)
517
    {
518
      printk ("Sound: Can't allocate driver for (%s)\n", name);
519
      return -(ENOSPC);
520
    }
521
 
522
  memset ((char *) op, 0, sizeof (struct audio_operations));
523
  if (driver_size < sizeof (struct audio_driver))
524
                    memset ((char *) d, 0, sizeof (struct audio_driver));
525
 
526
  memcpy ((char *) d, (char *) driver, driver_size);
527
 
528
  op->d = d;
529
 
530
  l = strlen (name) + 1;
531
  if (l > sizeof (op->name))
532
    l = sizeof (op->name);
533
  strncpy (op->name, name, l);
534
  op->name[l - 1] = 0;
535
  op->flags = flags;
536
  op->format_mask = format_mask;
537
  op->devc = devc;
538
  op->dmachan1 = dma1;
539
  op->dmachan2 = dma2;
540
 
541
/*
542
 *    Hardcoded defaults
543
 */
544
  op->buffsize = DSP_BUFFSIZE;
545
 
546
  audio_devs[num_audiodevs] = op;
547
  num = num_audiodevs++;
548
 
549
  DMAbuf_init ();
550
  audio_init ();
551
  return num;
552
}
553
 
554
int
555
sound_install_mixer (int vers,
556
                     char *name,
557
                     struct mixer_operations *driver,
558
                     int driver_size,
559
                     void *devc)
560
{
561
  struct mixer_operations *op;
562
  int             l;
563
 
564
  if (num_mixers >= MAX_MIXER_DEV)
565
    {
566
      printk ("Sound: Too many mixer drivers\n");
567
      return -(EIO);
568
    }
569
 
570
  if (vers != MIXER_DRIVER_VERSION ||
571
      driver_size > sizeof (struct mixer_operations))
572
    {
573
      printk ("Sound: Incompatible mixer driver for %s\n", name);
574
      return -(EIO);
575
    }
576
 
577
 
578
  op = (struct mixer_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc (sizeof (struct mixer_operations)));
579
 
580
  if (sound_nblocks < 1024)
581
    sound_nblocks++;;
582
  if (op == NULL)
583
    {
584
      printk ("Sound: Can't allocate mixer driver for (%s)\n", name);
585
      return -(ENOSPC);
586
    }
587
 
588
  memset ((char *) op, 0, sizeof (struct mixer_operations));
589
 
590
  memcpy ((char *) op, (char *) driver, driver_size);
591
 
592
  l = strlen (name) + 1;
593
  if (l > sizeof (op->name))
594
    l = sizeof (op->name);
595
  strncpy (op->name, name, l);
596
  op->name[l - 1] = 0;
597
  op->devc = devc;
598
 
599
  mixer_devs[num_mixers] = op;
600
  return num_mixers++;
601
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.