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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*
2
 * sound/sound_switch.c
3
 *
4
 * The system call switch handler
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
#include "sound_config.h"
17
 
18
struct sbc_device
19
  {
20
    int             usecount;
21
  };
22
 
23
static int      in_use = 0;      /* Total # of open devices */
24
 
25
/*
26
 * /dev/sndstatus -device
27
 */
28
static char    *status_buf = NULL;
29
static int      status_len, status_ptr;
30
static int      status_busy = 0;
31
 
32
static int
33
put_status (char *s)
34
{
35
  int             l = strlen (s);
36
 
37
  if (status_len + l >= 4000)
38
    return 0;
39
 
40
  memcpy (&status_buf[status_len], s, l);
41
  status_len += l;
42
 
43
  return 1;
44
}
45
 
46
static int
47
put_status_int (unsigned int val, int radix)
48
{
49
  int             l, v;
50
 
51
  static char     hx[] = "0123456789abcdef";
52
  char            buf[11];
53
 
54
  if (!val)
55
    return put_status ("0");
56
 
57
  l = 0;
58
  buf[10] = 0;
59
 
60
  while (val)
61
    {
62
      v = val % radix;
63
      val = val / radix;
64
 
65
      buf[9 - l] = hx[v];
66
      l++;
67
    }
68
 
69
  if (status_len + l >= 4000)
70
    return 0;
71
 
72
  memcpy (&status_buf[status_len], &buf[10 - l], l);
73
  status_len += l;
74
 
75
  return 1;
76
}
77
 
78
static void
79
init_status (void)
80
{
81
  /*
82
   * Write the status information to the status_buf and update status_len.
83
   * There is a limit of 4000 bytes for the data.
84
   */
85
 
86
  int             i;
87
 
88
  status_ptr = 0;
89
 
90
#ifdef SOUND_UNAME_A
91
  put_status ("Sound Driver:" SOUND_VERSION_STRING
92
              " (" SOUND_CONFIG_DATE " " SOUND_CONFIG_BY ",\n"
93
              SOUND_UNAME_A ")"
94
              "\n");
95
#else
96
  put_status ("Sound Driver:" SOUND_VERSION_STRING
97
              " (" SOUND_CONFIG_DATE " " SOUND_CONFIG_BY "@"
98
              SOUND_CONFIG_HOST "." SOUND_CONFIG_DOMAIN ")"
99
              "\n");
100
#endif
101
 
102
  put_status ("Kernel: ");
103
  put_status (system_utsname.sysname);
104
  put_status (" ");
105
  put_status (system_utsname.nodename);
106
  put_status (" ");
107
  put_status (system_utsname.release);
108
  put_status (" ");
109
  put_status (system_utsname.version);
110
  put_status (" ");
111
  put_status (system_utsname.machine);
112
  put_status ("\n");
113
 
114
  if (!put_status ("Config options: "))
115
    return;
116
  if (!put_status_int (SELECTED_SOUND_OPTIONS, 16))
117
    return;
118
 
119
  if (!put_status ("\n\nInstalled drivers: \n"))
120
    return;
121
 
122
  for (i = 0; i < num_sound_drivers; i++)
123
    if (sound_drivers[i].card_type != 0)
124
      {
125
        if (!put_status ("Type "))
126
          return;
127
        if (!put_status_int (sound_drivers[i].card_type, 10))
128
          return;
129
        if (!put_status (": "))
130
          return;
131
        if (!put_status (sound_drivers[i].name))
132
          return;
133
 
134
        if (!put_status ("\n"))
135
          return;
136
      }
137
 
138
  if (!put_status ("\nCard config: \n"))
139
    return;
140
 
141
  for (i = 0; i < num_sound_cards; i++)
142
    if (snd_installed_cards[i].card_type != 0)
143
      {
144
        int             drv, tmp;
145
 
146
        if (!snd_installed_cards[i].enabled)
147
          if (!put_status ("("))
148
            return;
149
 
150
        /*
151
         * if (!put_status_int(snd_installed_cards[i].card_type, 10)) return;
152
         * if (!put_status (": ")) return;
153
         */
154
 
155
        if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) != -1)
156
          if (!put_status (sound_drivers[drv].name))
157
            return;
158
 
159
        if (snd_installed_cards[i].config.io_base)
160
          {
161
            if (!put_status (" at 0x"))
162
              return;
163
            if (!put_status_int (snd_installed_cards[i].config.io_base, 16))
164
              return;
165
          }
166
 
167
        tmp = snd_installed_cards[i].config.irq;
168
        if (tmp != 0)
169
          {
170
            if (!put_status (" irq "))
171
              return;
172
            if (tmp < 0)
173
              tmp = -tmp;
174
            if (!put_status_int (tmp, 10))
175
              return;
176
          }
177
 
178
        if (snd_installed_cards[i].config.dma != -1)
179
          {
180
            if (!put_status (" drq "))
181
              return;
182
            if (!put_status_int (snd_installed_cards[i].config.dma, 10))
183
              return;
184
            if (snd_installed_cards[i].config.dma2 != -1)
185
              {
186
                if (!put_status (","))
187
                  return;
188
                if (!put_status_int (snd_installed_cards[i].config.dma2, 10))
189
                  return;
190
              }
191
          }
192
 
193
        if (!snd_installed_cards[i].enabled)
194
          if (!put_status (")"))
195
            return;
196
 
197
        if (!put_status ("\n"))
198
          return;
199
      }
200
 
201
  if (!sound_started)
202
    {
203
      put_status ("\n\n***** Sound driver not started *****\n\n");
204
      return;
205
    }
206
 
207
#ifndef CONFIG_AUDIO
208
  if (!put_status ("\nAudio devices: NOT ENABLED IN CONFIG\n"))
209
    return;
210
#else
211
  if (!put_status ("\nAudio devices:\n"))
212
    return;
213
 
214
  for (i = 0; i < num_audiodevs; i++)
215
    {
216
      if (!put_status_int (i, 10))
217
        return;
218
      if (!put_status (": "))
219
        return;
220
      if (!put_status (audio_devs[i]->name))
221
        return;
222
 
223
      if (audio_devs[i]->flags & DMA_DUPLEX)
224
        if (!put_status (" (DUPLEX)"))
225
          return;
226
 
227
      if (!put_status ("\n"))
228
        return;
229
    }
230
#endif
231
 
232
#ifndef CONFIG_SEQUENCER
233
  if (!put_status ("\nSynth devices: NOT ENABLED IN CONFIG\n"))
234
    return;
235
#else
236
  if (!put_status ("\nSynth devices:\n"))
237
    return;
238
 
239
  for (i = 0; i < num_synths; i++)
240
    {
241
      if (!put_status_int (i, 10))
242
        return;
243
      if (!put_status (": "))
244
        return;
245
      if (!put_status (synth_devs[i]->info->name))
246
        return;
247
      if (!put_status ("\n"))
248
        return;
249
    }
250
#endif
251
 
252
#ifndef CONFIG_MIDI
253
  if (!put_status ("\nMidi devices: NOT ENABLED IN CONFIG\n"))
254
    return;
255
#else
256
  if (!put_status ("\nMidi devices:\n"))
257
    return;
258
 
259
  for (i = 0; i < num_midis; i++)
260
    {
261
      if (!put_status_int (i, 10))
262
        return;
263
      if (!put_status (": "))
264
        return;
265
      if (!put_status (midi_devs[i]->info.name))
266
        return;
267
      if (!put_status ("\n"))
268
        return;
269
    }
270
#endif
271
 
272
  if (!put_status ("\nTimers:\n"))
273
    return;
274
 
275
  for (i = 0; i < num_sound_timers; i++)
276
    {
277
      if (!put_status_int (i, 10))
278
        return;
279
      if (!put_status (": "))
280
        return;
281
      if (!put_status (sound_timer_devs[i]->info.name))
282
        return;
283
      if (!put_status ("\n"))
284
        return;
285
    }
286
 
287
  if (!put_status ("\nMixers:\n"))
288
    return;
289
 
290
  for (i = 0; i < num_mixers; i++)
291
    {
292
      if (!put_status_int (i, 10))
293
        return;
294
      if (!put_status (": "))
295
        return;
296
      if (!put_status (mixer_devs[i]->name))
297
        return;
298
      if (!put_status ("\n"))
299
        return;
300
    }
301
}
302
 
303
static int
304
read_status (char *buf, int count)
305
{
306
  /*
307
   * Return at most 'count' bytes from the status_buf.
308
   */
309
  int             l, c;
310
 
311
  l = count;
312
  c = status_len - status_ptr;
313
 
314
  if (l > c)
315
    l = c;
316
  if (l <= 0)
317
    return 0;
318
 
319
  memcpy_tofs (&(buf)[0], &status_buf[status_ptr], l);
320
  status_ptr += l;
321
 
322
  return l;
323
}
324
 
325
int
326
sound_read_sw (int dev, struct fileinfo *file, char *buf, int count)
327
{
328
  DEB (printk ("sound_read_sw(dev=%d, count=%d)\n", dev, count));
329
 
330
  switch (dev & 0x0f)
331
    {
332
    case SND_DEV_STATUS:
333
      return read_status (buf, count);
334
      break;
335
 
336
#ifdef CONFIG_AUDIO
337
    case SND_DEV_DSP:
338
    case SND_DEV_DSP16:
339
    case SND_DEV_AUDIO:
340
      return audio_read (dev, file, buf, count);
341
      break;
342
#endif
343
 
344
#ifdef CONFIG_SEQUENCER
345
    case SND_DEV_SEQ:
346
    case SND_DEV_SEQ2:
347
      return sequencer_read (dev, file, buf, count);
348
      break;
349
#endif
350
 
351
#ifdef CONFIG_MIDI
352
    case SND_DEV_MIDIN:
353
      return MIDIbuf_read (dev, file, buf, count);
354
#endif
355
 
356
    default:
357
      printk ("Sound: Undefined minor device %d\n", dev);
358
    }
359
 
360
  return -(EPERM);
361
}
362
 
363
int
364
sound_write_sw (int dev, struct fileinfo *file, const char *buf, int count)
365
{
366
 
367
  DEB (printk ("sound_write_sw(dev=%d, count=%d)\n", dev, count));
368
 
369
  switch (dev & 0x0f)
370
    {
371
 
372
#ifdef CONFIG_SEQUENCER
373
    case SND_DEV_SEQ:
374
    case SND_DEV_SEQ2:
375
      return sequencer_write (dev, file, buf, count);
376
      break;
377
#endif
378
 
379
#ifdef CONFIG_AUDIO
380
    case SND_DEV_DSP:
381
    case SND_DEV_DSP16:
382
    case SND_DEV_AUDIO:
383
      return audio_write (dev, file, buf, count);
384
      break;
385
#endif
386
 
387
#ifdef CONFIG_MIDI
388
    case SND_DEV_MIDIN:
389
      return MIDIbuf_write (dev, file, buf, count);
390
#endif
391
 
392
    }
393
 
394
  return -(EPERM);
395
}
396
 
397
int
398
sound_open_sw (int dev, struct fileinfo *file)
399
{
400
  int             retval;
401
 
402
  DEB (printk ("sound_open_sw(dev=%d)\n", dev));
403
 
404
  if ((dev >= SND_NDEVS) || (dev < 0))
405
    {
406
      printk ("Invalid minor device %d\n", dev);
407
      return -(ENXIO);
408
    }
409
 
410
  switch (dev & 0x0f)
411
    {
412
    case SND_DEV_STATUS:
413
      if (status_busy)
414
        return -(EBUSY);
415
      status_busy = 1;
416
      if ((status_buf = (char *) vmalloc (4000)) == NULL)
417
        return -(EIO);
418
      status_len = status_ptr = 0;
419
      init_status ();
420
      break;
421
 
422
    case SND_DEV_CTL:
423
      if ((dev & 0xf0) && ((dev & 0xf0) >> 4) >= num_mixers)
424
        return -(ENXIO);
425
      return 0;
426
      break;
427
 
428
#ifdef CONFIG_SEQUENCER
429
    case SND_DEV_SEQ:
430
    case SND_DEV_SEQ2:
431
      if ((retval = sequencer_open (dev, file)) < 0)
432
        return retval;
433
      break;
434
#endif
435
 
436
#ifdef CONFIG_MIDI
437
    case SND_DEV_MIDIN:
438
      if ((retval = MIDIbuf_open (dev, file)) < 0)
439
        return retval;
440
      break;
441
#endif
442
 
443
#ifdef CONFIG_AUDIO
444
    case SND_DEV_DSP:
445
    case SND_DEV_DSP16:
446
    case SND_DEV_AUDIO:
447
      if ((retval = audio_open (dev, file)) < 0)
448
        return retval;
449
      break;
450
#endif
451
 
452
    default:
453
      printk ("Invalid minor device %d\n", dev);
454
      return -(ENXIO);
455
    }
456
 
457
  in_use++;
458
 
459
  return 0;
460
}
461
 
462
void
463
sound_release_sw (int dev, struct fileinfo *file)
464
{
465
 
466
  DEB (printk ("sound_release_sw(dev=%d)\n", dev));
467
 
468
  switch (dev & 0x0f)
469
    {
470
    case SND_DEV_STATUS:
471
      if (status_buf)
472
        vfree (status_buf);
473
      status_buf = NULL;
474
      status_busy = 0;
475
      break;
476
 
477
    case SND_DEV_CTL:
478
      break;
479
 
480
#ifdef CONFIG_SEQUENCER
481
    case SND_DEV_SEQ:
482
    case SND_DEV_SEQ2:
483
      sequencer_release (dev, file);
484
      break;
485
#endif
486
 
487
#ifdef CONFIG_MIDI
488
    case SND_DEV_MIDIN:
489
      MIDIbuf_release (dev, file);
490
      break;
491
#endif
492
 
493
#ifdef CONFIG_AUDIO
494
    case SND_DEV_DSP:
495
    case SND_DEV_DSP16:
496
    case SND_DEV_AUDIO:
497
      audio_release (dev, file);
498
      break;
499
#endif
500
 
501
    default:
502
      printk ("Sound error: Releasing unknown device 0x%02x\n", dev);
503
    }
504
  in_use--;
505
}
506
 
507
static int
508
get_mixer_info (int dev, caddr_t arg)
509
{
510
  mixer_info      info;
511
 
512
  if (dev < 0 || dev >= num_mixers)
513
    return -(ENXIO);
514
 
515
  strcpy (info.id, mixer_devs[dev]->id);
516
  strcpy (info.name, mixer_devs[dev]->name);
517
 
518
  memcpy_tofs (&((char *) arg)[0], (char *) &info, sizeof (info));
519
  return 0;
520
}
521
 
522
int
523
sound_ioctl_sw (int dev, struct fileinfo *file,
524
                unsigned int cmd, caddr_t arg)
525
{
526
  DEB (printk ("sound_ioctl_sw(dev=%d, cmd=0x%x, arg=0x%x)\n", dev, cmd, arg));
527
 
528
  if (((cmd >> 8) & 0xff) == 'M' && num_mixers > 0)      /* Mixer ioctl */
529
    if ((dev & 0x0f) != SND_DEV_CTL)
530
      {
531
        int             dtype = dev & 0x0f;
532
        int             mixdev;
533
 
534
        switch (dtype)
535
          {
536
#ifdef CONFIG_AUDIO
537
          case SND_DEV_DSP:
538
          case SND_DEV_DSP16:
539
          case SND_DEV_AUDIO:
540
            mixdev = audio_devs[dev >> 4]->mixer_dev;
541
            if (mixdev < 0 || mixdev >= num_mixers)
542
              return -(ENXIO);
543
            if (cmd == SOUND_MIXER_INFO)
544
              return get_mixer_info (mixdev, arg);
545
            return mixer_devs[mixdev]->ioctl (mixdev, cmd, arg);
546
            break;
547
#endif
548
 
549
          default:
550
            if (cmd == SOUND_MIXER_INFO)
551
              return get_mixer_info (0, arg);
552
            return mixer_devs[0]->ioctl (0, cmd, arg);
553
          }
554
      }
555
 
556
  switch (dev & 0x0f)
557
    {
558
 
559
    case SND_DEV_CTL:
560
 
561
      if (!num_mixers)
562
        return -(ENXIO);
563
 
564
      dev = dev >> 4;
565
 
566
      if (dev >= num_mixers)
567
        return -(ENXIO);
568
 
569
      if (cmd == SOUND_MIXER_INFO)
570
        return get_mixer_info (dev, arg);
571
      return mixer_devs[dev]->ioctl (dev, cmd, arg);
572
      break;
573
 
574
#ifdef CONFIG_SEQUENCER
575
    case SND_DEV_SEQ:
576
    case SND_DEV_SEQ2:
577
      return sequencer_ioctl (dev, file, cmd, arg);
578
      break;
579
#endif
580
 
581
#ifdef CONFIG_AUDIO
582
    case SND_DEV_DSP:
583
    case SND_DEV_DSP16:
584
    case SND_DEV_AUDIO:
585
      return audio_ioctl (dev, file, cmd, arg);
586
      break;
587
#endif
588
 
589
#ifdef CONFIG_MIDI
590
    case SND_DEV_MIDIN:
591
      return MIDIbuf_ioctl (dev, file, cmd, arg);
592
      break;
593
#endif
594
 
595
    }
596
 
597
  return -(EPERM);
598
}

powered by: WebSVN 2.1.0

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