1
2
3
4
5
6
7
8#ifndef _AUDIOIO_H_
9#define _AUDIOIO_H_
10
11
12
13
14
15#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
16#include <linux/types.h>
17#include <linux/time.h>
18#include <linux/ioctl.h>
19#endif
20
21
22
23
24typedef struct audio_prinfo {
25
26
27
28 unsigned int sample_rate;
29 unsigned int channels;
30 unsigned int precision;
31 unsigned int encoding;
32
33
34
35
36 unsigned int gain;
37 unsigned int port;
38 unsigned int avail_ports;
39 unsigned int _xxx[2];
40
41 unsigned int buffer_size;
42
43
44
45
46 unsigned int samples;
47 unsigned int eof;
48
49 unsigned char pause;
50 unsigned char error;
51 unsigned char waiting;
52 unsigned char balance;
53
54 unsigned short minordev;
55
56
57
58
59 unsigned char open;
60 unsigned char active;
61} audio_prinfo_t;
62
63
64
65
66
67typedef struct audio_info {
68
69
70
71 audio_prinfo_t play;
72 audio_prinfo_t record;
73
74
75
76
77 unsigned int monitor_gain;
78 unsigned char output_muted;
79 unsigned char _xxx[3];
80 unsigned int _yyy[3];
81} audio_info_t;
82
83
84
85
86
87#define AUDIO_ENCODING_NONE (0)
88#define AUDIO_ENCODING_ULAW (1)
89#define AUDIO_ENCODING_ALAW (2)
90#define AUDIO_ENCODING_LINEAR (3)
91#define AUDIO_ENCODING_FLOAT (4)
92#define AUDIO_ENCODING_DVI (104)
93#define AUDIO_ENCODING_LINEAR8 (105)
94#define AUDIO_ENCODING_LINEARLE (106)
95
96
97
98
99#define AUDIO_MIN_GAIN (0)
100#define AUDIO_MAX_GAIN (255)
101
102
103
104
105#define AUDIO_LEFT_BALANCE (0)
106#define AUDIO_MID_BALANCE (32)
107#define AUDIO_RIGHT_BALANCE (64)
108#define AUDIO_BALANCE_SHIFT (3)
109
110
111
112
113#define AUDIO_MIN_PLAY_CHANNELS (1)
114#define AUDIO_MAX_PLAY_CHANNELS (4)
115#define AUDIO_MIN_REC_CHANNELS (1)
116#define AUDIO_MAX_REC_CHANNELS (4)
117
118
119
120
121#define AUDIO_MIN_PLAY_PRECISION (8)
122#define AUDIO_MAX_PLAY_PRECISION (32)
123#define AUDIO_MIN_REC_PRECISION (8)
124#define AUDIO_MAX_REC_PRECISION (32)
125
126
127
128
129
130
131
132#define AUDIO_SPEAKER 0x01
133#define AUDIO_HEADPHONE 0x02
134#define AUDIO_LINE_OUT 0x04
135
136
137
138
139#define AUDIO_MICROPHONE 0x01
140#define AUDIO_LINE_IN 0x02
141#define AUDIO_CD 0x04
142#define AUDIO_INTERNAL_CD_IN AUDIO_CD
143#define AUDIO_ANALOG_LOOPBACK 0x40
144
145
146
147
148
149
150
151#define AUDIO_INITINFO(i) { \
152 unsigned int *__x__; \
153 for (__x__ = (unsigned int *)(i); \
154 (char *) __x__ < (((char *)(i)) + sizeof (audio_info_t)); \
155 *__x__++ = ~0); \
156}
157
158
159
160
161#define AUD_INITVALUE (~0)
162#define Modify(X) ((unsigned int)(X) != AUD_INITVALUE)
163#define Modifys(X) ((X) != (unsigned short)AUD_INITVALUE)
164#define Modifyc(X) ((X) != (unsigned char)AUD_INITVALUE)
165
166
167
168
169
170#define MAX_AUDIO_DEV_LEN (16)
171typedef struct audio_device {
172 char name[MAX_AUDIO_DEV_LEN];
173 char version[MAX_AUDIO_DEV_LEN];
174 char config[MAX_AUDIO_DEV_LEN];
175} audio_device_t;
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210#define AUDIO_GETINFO _IOR('A', 1, audio_info_t)
211#define AUDIO_SETINFO _IOWR('A', 2, audio_info_t)
212#define AUDIO_DRAIN _IO('A', 3)
213#define AUDIO_GETDEV _IOR('A', 4, audio_device_t)
214#define AUDIO_GETDEV_SUNOS _IOR('A', 4, int)
215#define AUDIO_FLUSH _IO('A', 5)
216
217
218
219#define AUDIO_DEV_UNKNOWN (0)
220#define AUDIO_DEV_AMD (1)
221#define AUDIO_DEV_SPEAKERBOX (2)
222#define AUDIO_DEV_CODEC (3)
223#define AUDIO_DEV_CS4231 (5)
224
225
226
227
228
229
230
231
232#define AUDIO_DIAG_LOOPBACK _IOW('A', 101, int)
233
234
235
236
237
238#ifdef __KERNEL__
239
240#include <linux/fs.h>
241#include <linux/tqueue.h>
242#include <linux/wait.h>
243
244#define SDF_OPEN_WRITE 0x00000001
245#define SDF_OPEN_READ 0x00000002
246
247struct sparcaudio_ringbuffer
248{
249 __u8 *rb_start, *rb_end;
250 __u8 *rb_in, *rb_out;
251
252 int rb_fragsize;
253 int rb_numfrags;
254
255 int rb_count, rb_hiwat, rb_lowat;
256
257 int rb_bufsize;
258};
259
260struct sparcaudio_driver
261{
262 const char * name;
263 struct sparcaudio_operations *ops;
264 void *private;
265 unsigned long flags;
266 struct strevent *sd_siglist;
267
268 int sd_sigflags, duplex;
269
270
271 int index;
272
273
274 struct sbus_dev *dev;
275
276
277 wait_queue_head_t open_wait;
278
279
280 struct tq_struct tqueue;
281
282
283 __u8 *input_buffer, *output_buffer;
284
285
286 __u8 **output_buffers;
287 size_t *output_sizes, output_size, output_buffer_size;
288 int num_output_buffers, output_front, output_rear, output_offset;
289 int output_count, output_active, playing_count, output_eof;
290 wait_queue_head_t output_write_wait, output_drain_wait;
291 char *output_notify;
292
293
294 __u8 **input_buffers;
295 size_t *input_sizes, input_size, input_buffer_size;
296 int num_input_buffers, input_front, input_rear, input_offset;
297 int input_count, input_active, recording_count;
298 wait_queue_head_t input_read_wait;
299
300
301 int buffer_size;
302
303 int mixer_modify_counter;
304};
305
306struct sparcaudio_operations
307{
308 int (*open)(struct inode *, struct file *, struct sparcaudio_driver *);
309 void (*release)(struct inode *, struct file *, struct sparcaudio_driver *);
310 int (*ioctl)(struct inode *, struct file *, unsigned int, unsigned long,
311 struct sparcaudio_driver *);
312
313
314 void (*start_output)(struct sparcaudio_driver *, __u8 *, unsigned long);
315
316
317 void (*stop_output)(struct sparcaudio_driver *);
318
319
320 void (*start_input)(struct sparcaudio_driver *, __u8 *, unsigned long);
321
322
323 void (*stop_input)(struct sparcaudio_driver *);
324
325
326 void (*sunaudio_getdev)(struct sparcaudio_driver *, audio_device_t *);
327
328
329 int (*set_output_volume)(struct sparcaudio_driver *, int);
330 int (*get_output_volume)(struct sparcaudio_driver *);
331
332
333 int (*set_input_volume)(struct sparcaudio_driver *, int);
334 int (*get_input_volume)(struct sparcaudio_driver *);
335
336
337 int (*set_monitor_volume)(struct sparcaudio_driver *, int);
338 int (*get_monitor_volume)(struct sparcaudio_driver *);
339
340
341 int (*set_output_balance)(struct sparcaudio_driver *, int);
342 int (*get_output_balance)(struct sparcaudio_driver *);
343
344
345 int (*set_input_balance)(struct sparcaudio_driver *, int);
346 int (*get_input_balance)(struct sparcaudio_driver *);
347
348
349 int (*set_output_channels)(struct sparcaudio_driver *, int);
350 int (*get_output_channels)(struct sparcaudio_driver *);
351
352
353 int (*set_input_channels)(struct sparcaudio_driver *, int);
354 int (*get_input_channels)(struct sparcaudio_driver *);
355
356
357 int (*set_output_precision)(struct sparcaudio_driver *, int);
358 int (*get_output_precision)(struct sparcaudio_driver *);
359
360
361 int (*set_input_precision)(struct sparcaudio_driver *, int);
362 int (*get_input_precision)(struct sparcaudio_driver *);
363
364
365 int (*set_output_port)(struct sparcaudio_driver *, int);
366 int (*get_output_port)(struct sparcaudio_driver *);
367
368
369 int (*set_input_port)(struct sparcaudio_driver *, int);
370 int (*get_input_port)(struct sparcaudio_driver *);
371
372
373 int (*set_output_encoding)(struct sparcaudio_driver *, int);
374 int (*get_output_encoding)(struct sparcaudio_driver *);
375
376
377 int (*set_input_encoding)(struct sparcaudio_driver *, int);
378 int (*get_input_encoding)(struct sparcaudio_driver *);
379
380
381 int (*set_output_rate)(struct sparcaudio_driver *, int);
382 int (*get_output_rate)(struct sparcaudio_driver *);
383
384
385 int (*set_input_rate)(struct sparcaudio_driver *, int);
386 int (*get_input_rate)(struct sparcaudio_driver *);
387
388
389 int (*sunaudio_getdev_sunos)(struct sparcaudio_driver *);
390
391
392 int (*get_output_ports)(struct sparcaudio_driver *);
393 int (*get_input_ports)(struct sparcaudio_driver *);
394
395
396 int (*set_output_muted)(struct sparcaudio_driver *, int);
397 int (*get_output_muted)(struct sparcaudio_driver *);
398
399
400 int (*set_output_pause)(struct sparcaudio_driver *, int);
401 int (*get_output_pause)(struct sparcaudio_driver *);
402
403
404 int (*set_input_pause)(struct sparcaudio_driver *, int);
405 int (*get_input_pause)(struct sparcaudio_driver *);
406
407
408 int (*set_output_samples)(struct sparcaudio_driver *, int);
409 int (*get_output_samples)(struct sparcaudio_driver *);
410
411
412 int (*set_input_samples)(struct sparcaudio_driver *, int);
413 int (*get_input_samples)(struct sparcaudio_driver *);
414
415
416 int (*set_output_error)(struct sparcaudio_driver *, int);
417 int (*get_output_error)(struct sparcaudio_driver *);
418
419
420 int (*set_input_error)(struct sparcaudio_driver *, int);
421 int (*get_input_error)(struct sparcaudio_driver *);
422
423
424 int (*get_formats)(struct sparcaudio_driver *);
425};
426
427extern int register_sparcaudio_driver(struct sparcaudio_driver *, int);
428extern int unregister_sparcaudio_driver(struct sparcaudio_driver *, int);
429extern void sparcaudio_output_done(struct sparcaudio_driver *, int);
430extern void sparcaudio_input_done(struct sparcaudio_driver *, int);
431
432#endif
433
434
435
436#define SPARCAUDIO_MIXER_MINOR 0
437
438
439#define SPARCAUDIO_DSP_MINOR 3
440#define SPARCAUDIO_AUDIO_MINOR 4
441#define SPARCAUDIO_DSP16_MINOR 5
442#define SPARCAUDIO_STATUS_MINOR 6
443#define SPARCAUDIO_AUDIOCTL_MINOR 7
444
445
446
447
448#define SPARCAUDIO_DEVICE_SHIFT 4
449
450
451#define SPARCAUDIO_MAX_DEVICES 3
452
453
454
455typedef
456struct strevent {
457 struct strevent *se_next;
458 struct strevent *se_prev;
459
460 pid_t se_pid;
461 short se_evs;
462} strevent_t;
463
464typedef
465struct stdata
466{
467 struct stdata *sd_next ;
468 struct stdata *sd_prev ;
469 struct strevent *sd_siglist;
470 int sd_sigflags;
471} stdata_t;
472
473#define I_NREAD _IOR('S',01, int)
474#define I_NREAD_SOLARIS (('S'<<8)|1)
475
476#define I_FLUSH _IO('S',05)
477#define I_FLUSH_SOLARIS (('S'<<8)|5)
478#define FLUSHR 1
479#define FLUSHW 2
480#define FLUSHRW 3
481
482#define I_SETSIG _IO('S',011)
483#define I_SETSIG_SOLARIS (('S'<<8)|11)
484#define S_INPUT 0x01
485#define S_HIPRI 0x02
486#define S_OUTPUT 0x04
487#define S_MSG 0x08
488#define S_ERROR 0x0010
489#define S_HANGUP 0x0020
490#define S_RDNORM 0x0040
491#define S_WRNORM S_OUTPUT
492#define S_RDBAND 0x0080
493#define S_WRBAND 0x0100
494#define S_BANDURG 0x0200
495#define S_ALL 0x03FF
496
497#define I_GETSIG _IOR('S',012,int)
498#define I_GETSIG_SOLARIS (('S'<<8)|12)
499
500
501static __inline__
502int OSS_LEFT(int value)
503{
504 return ((value & 0xff) % 101);
505}
506
507static __inline__
508int OSS_RIGHT(int value)
509{
510 return (((value >> 8) & 0xff) % 101);
511}
512
513static __inline__
514int O_TO_S(int value)
515{
516 return value * 255 / 100;
517}
518
519static __inline__
520int S_TO_O(int value)
521{
522 return value * 100 / 255;
523}
524
525static __inline__
526int OSS_TO_GAIN(int value)
527{
528 int l = O_TO_S(OSS_LEFT(value));
529 int r = O_TO_S(OSS_RIGHT(value));
530 return ((l > r) ? l : r);
531}
532
533static __inline__
534int OSS_TO_LGAIN(int value)
535{
536 int l = O_TO_S(OSS_LEFT(value));
537 int r = O_TO_S(OSS_RIGHT(value));
538 return ((l < r) ? l : r);
539}
540
541static __inline__
542int OSS_TO_BAL(int value)
543{
544 if (!OSS_TO_GAIN(value))
545 return AUDIO_MID_BALANCE;
546 if (!OSS_TO_LGAIN(value)) {
547 if (OSS_TO_GAIN(value) == OSS_TO_GAIN(OSS_RIGHT(value)))
548 return AUDIO_RIGHT_BALANCE;
549 else
550 return AUDIO_LEFT_BALANCE;
551 }
552 if (OSS_TO_GAIN(value) == OSS_TO_GAIN(OSS_RIGHT(value)))
553 return ((OSS_TO_GAIN(value) - OSS_TO_LGAIN(value)) >> AUDIO_BALANCE_SHIFT)
554 + AUDIO_MID_BALANCE;
555 else
556 return AUDIO_MID_BALANCE - ((OSS_TO_GAIN(value) - OSS_TO_LGAIN(value))
557 >> AUDIO_BALANCE_SHIFT);
558}
559
560static __inline__
561int BAL_TO_OSS(int value, unsigned char balance)
562{
563 int l, r, adj;
564 if (balance > 63) balance = 63;
565 if (balance < AUDIO_MID_BALANCE) {
566 l = (int)value * 100 / 255 + ((value * 100 % 255) > 0);
567 adj = ((AUDIO_MID_BALANCE - balance) << AUDIO_BALANCE_SHIFT);
568 if (adj < value)
569 r = (int)(value - adj)
570 * 100 / 255;
571 else r = 0;
572 } else if (balance > AUDIO_MID_BALANCE) {
573 r = (int)value * 100 / 255 + ((value * 100 % 255) > 0);
574 adj = ((balance - AUDIO_MID_BALANCE) << AUDIO_BALANCE_SHIFT);
575 if (adj < value)
576 l = (int)(value - adj)
577 * 100 / 255;
578 else l = 0;
579 } else {
580 l = r = (int)value * 100 / 255 + ((value * 100 % 255) > 0);
581 }
582
583 return ((r << 8) + l);
584}
585
586#ifdef __KERNEL__
587
588static __inline__
589int OSS_PORT_AUDIO(struct sparcaudio_driver *drv, unsigned int set)
590{
591 int p;
592 if (drv->ops->get_output_port) {
593 p = drv->ops->get_output_port(drv);
594 if (p & set)
595 return 0x6464;
596 }
597 return 0;
598}
599
600static __inline__
601int OSS_IPORT_AUDIO(struct sparcaudio_driver *drv, unsigned int set)
602{
603 int p;
604 if (drv->ops->get_input_port) {
605 p = drv->ops->get_input_port(drv);
606 if (p & set)
607 return 0x6464;
608 }
609 return 0;
610}
611
612static __inline__
613void OSS_TWIDDLE_PORT(struct sparcaudio_driver *drv, unsigned int ioctl,
614 unsigned int port, unsigned int set, unsigned int value)
615{
616 if (ioctl == port) {
617 int p;
618 if (drv->ops->get_output_port && drv->ops->set_output_port) {
619 p = drv->ops->get_output_port(drv);
620 if ((value == 0) || ((p & set) && (OSS_LEFT(value) < 100)))
621 drv->ops->set_output_port(drv, p & ~(set));
622 else
623 drv->ops->set_output_port(drv, p | set);
624 }
625 }
626}
627
628static __inline__
629void OSS_TWIDDLE_IPORT(struct sparcaudio_driver *drv, unsigned int ioctl,
630 unsigned int port, unsigned int set, unsigned int value)
631{
632 if (ioctl == port) {
633 int p;
634 if (drv->ops->get_input_port && drv->ops->set_input_port) {
635 p = drv->ops->get_input_port(drv);
636 if ((value == 0) || ((p & set) && (OSS_LEFT(value) < 100)))
637 drv->ops->set_input_port(drv, p & ~(set));
638 else
639 drv->ops->set_input_port(drv, p | set);
640 }
641 }
642}
643#endif
644#endif
645