2 * include/asm-sparc/audioio.h
5 * Copyright (C) 1996 Thomas K. Dyas (tdyas@noc.rutgers.edu)
12 * SunOS/Solaris /dev/audio interface
15 #if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
16 #include <linux/types.h>
17 #include <linux/time.h>
18 #include <linux/ioctl.h>
22 * This structure contains state information for audio device IO streams.
24 typedef struct audio_prinfo
{
26 * The following values describe the audio data encoding.
28 unsigned int sample_rate
; /* samples per second */
29 unsigned int channels
; /* number of interleaved channels */
30 unsigned int precision
; /* bit-width of each sample */
31 unsigned int encoding
; /* data encoding method */
34 * The following values control audio device configuration
36 unsigned int gain
; /* gain level: 0 - 255 */
37 unsigned int port
; /* selected I/O port (see below) */
38 unsigned int avail_ports
; /* available I/O ports (see below) */
39 unsigned int _xxx
[2]; /* Reserved for future use */
41 unsigned int buffer_size
; /* I/O buffer size */
44 * The following values describe driver state
46 unsigned int samples
; /* number of samples converted */
47 unsigned int eof
; /* End Of File counter (play only) */
49 unsigned char pause
; /* non-zero for pause, zero to resume */
50 unsigned char error
; /* non-zero if overflow/underflow */
51 unsigned char waiting
; /* non-zero if a process wants access */
52 unsigned char balance
; /* stereo channel balance */
54 unsigned short minordev
;
57 * The following values are read-only state flags
59 unsigned char open
; /* non-zero if open access permitted */
60 unsigned char active
; /* non-zero if I/O is active */
65 * This structure describes the current state of the audio device.
67 typedef struct audio_info
{
69 * Per-stream information
71 audio_prinfo_t play
; /* output status information */
72 audio_prinfo_t record
; /* input status information */
75 * Per-unit/channel information
77 unsigned int monitor_gain
; /* input to output mix: 0 - 255 */
78 unsigned char output_muted
; /* non-zero if output is muted */
79 unsigned char _xxx
[3]; /* Reserved for future use */
80 unsigned int _yyy
[3]; /* Reserved for future use */
85 * Audio encoding types
87 #define AUDIO_ENCODING_NONE (0) /* no encoding assigned */
88 #define AUDIO_ENCODING_ULAW (1) /* u-law encoding */
89 #define AUDIO_ENCODING_ALAW (2) /* A-law encoding */
90 #define AUDIO_ENCODING_LINEAR (3) /* Linear PCM encoding */
91 #define AUDIO_ENCODING_FLOAT (4) /* IEEE float (-1. <-> +1.) */
92 #define AUDIO_ENCODING_DVI (104) /* DVI ADPCM */
93 #define AUDIO_ENCODING_LINEAR8 (105) /* 8 bit UNSIGNED */
94 #define AUDIO_ENCODING_LINEARLE (106) /* Linear PCM LE encoding */
97 * These ranges apply to record, play, and monitor gain values
99 #define AUDIO_MIN_GAIN (0) /* minimum gain value */
100 #define AUDIO_MAX_GAIN (255) /* maximum gain value */
103 * These values apply to the balance field to adjust channel gain values
105 #define AUDIO_LEFT_BALANCE (0) /* left channel only */
106 #define AUDIO_MID_BALANCE (32) /* equal left/right channel */
107 #define AUDIO_RIGHT_BALANCE (64) /* right channel only */
108 #define AUDIO_BALANCE_SHIFT (3)
111 * Generic minimum/maximum limits for number of channels, both modes
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)
119 * Generic minimum/maximum limits for sample precision
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)
127 * Define some convenient names for typical audio ports
130 * output ports (several may be enabled simultaneously)
132 #define AUDIO_SPEAKER 0x01 /* output to built-in speaker */
133 #define AUDIO_HEADPHONE 0x02 /* output to headphone jack */
134 #define AUDIO_LINE_OUT 0x04 /* output to line out */
137 * input ports (usually only one at a time)
139 #define AUDIO_MICROPHONE 0x01 /* input from microphone */
140 #define AUDIO_LINE_IN 0x02 /* input from line in */
141 #define AUDIO_CD 0x04 /* input from on-board CD inputs */
142 #define AUDIO_INTERNAL_CD_IN AUDIO_CD /* input from internal CDROM */
143 #define AUDIO_ANALOG_LOOPBACK 0x40 /* input from output */
147 * This macro initializes an audio_info structure to 'harmless' values.
148 * Note that (~0) might not be a harmless value for a flag that was
151 #define AUDIO_INITINFO(i) { \
152 unsigned int *__x__; \
153 for (__x__ = (unsigned int *)(i); \
154 (char *) __x__ < (((char *)(i)) + sizeof (audio_info_t)); \
159 * These allow testing for what the user wants to set
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)
167 * Parameter for the AUDIO_GETDEV ioctl to determine current
170 #define MAX_AUDIO_DEV_LEN (16)
171 typedef struct audio_device
{
172 char name
[MAX_AUDIO_DEV_LEN
];
173 char version
[MAX_AUDIO_DEV_LEN
];
174 char config
[MAX_AUDIO_DEV_LEN
];
179 * Ioctl calls for the audio device.
183 * AUDIO_GETINFO retrieves the current state of the audio device.
185 * AUDIO_SETINFO copies all fields of the audio_info structure whose
186 * values are not set to the initialized value (-1) to the device state.
187 * It performs an implicit AUDIO_GETINFO to return the new state of the
188 * device. Note that the record.samples and play.samples fields are set
189 * to the last value before the AUDIO_SETINFO took effect. This allows
190 * an application to reset the counters while atomically retrieving the
193 * AUDIO_DRAIN suspends the calling process until the write buffers are
196 * AUDIO_GETDEV returns a structure of type audio_device_t which contains
197 * three strings. The string "name" is a short identifying string (for
198 * example, the SBus Fcode name string), the string "version" identifies
199 * the current version of the device, and the "config" string identifies
200 * the specific configuration of the audio stream. All fields are
201 * device-dependent -- see the device specific manual pages for details.
203 * AUDIO_GETDEV_SUNOS returns a number which is an audio device defined
204 * herein (making it not too portable)
206 * AUDIO_FLUSH stops all playback and recording, clears all queued buffers,
207 * resets error counters, and restarts recording and playback as appropriate
208 * for the current sampling mode.
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)
217 /* Define possible audio hardware configurations for
218 * old SunOS-style AUDIO_GETDEV ioctl */
219 #define AUDIO_DEV_UNKNOWN (0) /* not defined */
220 #define AUDIO_DEV_AMD (1) /* audioamd device */
221 #define AUDIO_DEV_SPEAKERBOX (2) /* dbri device with speakerbox */
222 #define AUDIO_DEV_CODEC (3) /* dbri device (internal speaker) */
223 #define AUDIO_DEV_CS4231 (5) /* cs4231 device */
226 * The following ioctl sets the audio device into an internal loopback mode,
227 * if the hardware supports this. The argument is TRUE to set loopback,
228 * FALSE to reset to normal operation. If the hardware does not support
229 * internal loopback, the ioctl should fail with EINVAL.
230 * Causes ADC data to be digitally mixed in and sent to the DAC.
232 #define AUDIO_DIAG_LOOPBACK _IOW('A', 101, int)
235 * Linux kernel internal implementation.
240 #include <linux/fs.h>
241 #include <linux/tqueue.h>
242 #include <linux/wait.h>
244 #define SDF_OPEN_WRITE 0x00000001
245 #define SDF_OPEN_READ 0x00000002
247 struct sparcaudio_ringbuffer
249 __u8
*rb_start
, *rb_end
; /* start, end of this memory buffer */
250 __u8
*rb_in
, *rb_out
; /* input, output pointers */
252 int rb_fragsize
; /* size of an audio frag */
253 int rb_numfrags
; /* number of frags */
255 int rb_count
, rb_hiwat
, rb_lowat
; /* bytes in use, hi/lo wat points */
257 int rb_bufsize
; /* total size of buffer */
260 struct sparcaudio_driver
263 struct sparcaudio_operations
*ops
;
266 struct strevent
*sd_siglist
;
267 /* duplex: 0=simplex, 1=duplex, 2=loop */
268 int sd_sigflags
, duplex
;
270 /* Which audio device are we? */
274 struct sbus_dev
*dev
;
276 /* Processes blocked on open() sit here. */
277 wait_queue_head_t open_wait
;
279 /* Task queue for this driver's bottom half. */
280 struct tq_struct tqueue
;
282 /* Start of ring buffer support */
283 __u8
*input_buffer
, *output_buffer
;
285 /* Support for a circular queue of output buffers. */
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
;
293 /* Support for a circular queue of input buffers. */
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
;
300 /* Hack to make it look like we support variable size buffers. */
303 int mixer_modify_counter
;
306 struct sparcaudio_operations
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
*);
313 /* Ask driver to begin playing a buffer. */
314 void (*start_output
)(struct sparcaudio_driver
*, __u8
*, unsigned long);
316 /* Ask driver to stop playing a buffer. */
317 void (*stop_output
)(struct sparcaudio_driver
*);
319 /* Ask driver to begin recording into a buffer. */
320 void (*start_input
)(struct sparcaudio_driver
*, __u8
*, unsigned long);
322 /* Ask driver to stop recording. */
323 void (*stop_input
)(struct sparcaudio_driver
*);
325 /* Return driver name/version to caller. (/dev/audio specific) */
326 void (*sunaudio_getdev
)(struct sparcaudio_driver
*, audio_device_t
*);
328 /* Get and set the output volume. (0-255) */
329 int (*set_output_volume
)(struct sparcaudio_driver
*, int);
330 int (*get_output_volume
)(struct sparcaudio_driver
*);
332 /* Get and set the input volume. (0-255) */
333 int (*set_input_volume
)(struct sparcaudio_driver
*, int);
334 int (*get_input_volume
)(struct sparcaudio_driver
*);
336 /* Get and set the monitor volume. (0-255) */
337 int (*set_monitor_volume
)(struct sparcaudio_driver
*, int);
338 int (*get_monitor_volume
)(struct sparcaudio_driver
*);
340 /* Get and set the output balance. (0-64) */
341 int (*set_output_balance
)(struct sparcaudio_driver
*, int);
342 int (*get_output_balance
)(struct sparcaudio_driver
*);
344 /* Get and set the input balance. (0-64) */
345 int (*set_input_balance
)(struct sparcaudio_driver
*, int);
346 int (*get_input_balance
)(struct sparcaudio_driver
*);
348 /* Get and set the output channels. (1-4) */
349 int (*set_output_channels
)(struct sparcaudio_driver
*, int);
350 int (*get_output_channels
)(struct sparcaudio_driver
*);
352 /* Get and set the input channels. (1-4) */
353 int (*set_input_channels
)(struct sparcaudio_driver
*, int);
354 int (*get_input_channels
)(struct sparcaudio_driver
*);
356 /* Get and set the output precision. (8-32) */
357 int (*set_output_precision
)(struct sparcaudio_driver
*, int);
358 int (*get_output_precision
)(struct sparcaudio_driver
*);
360 /* Get and set the input precision. (8-32) */
361 int (*set_input_precision
)(struct sparcaudio_driver
*, int);
362 int (*get_input_precision
)(struct sparcaudio_driver
*);
364 /* Get and set the output port. () */
365 int (*set_output_port
)(struct sparcaudio_driver
*, int);
366 int (*get_output_port
)(struct sparcaudio_driver
*);
368 /* Get and set the input port. () */
369 int (*set_input_port
)(struct sparcaudio_driver
*, int);
370 int (*get_input_port
)(struct sparcaudio_driver
*);
372 /* Get and set the output encoding. () */
373 int (*set_output_encoding
)(struct sparcaudio_driver
*, int);
374 int (*get_output_encoding
)(struct sparcaudio_driver
*);
376 /* Get and set the input encoding. () */
377 int (*set_input_encoding
)(struct sparcaudio_driver
*, int);
378 int (*get_input_encoding
)(struct sparcaudio_driver
*);
380 /* Get and set the output rate. () */
381 int (*set_output_rate
)(struct sparcaudio_driver
*, int);
382 int (*get_output_rate
)(struct sparcaudio_driver
*);
384 /* Get and set the input rate. () */
385 int (*set_input_rate
)(struct sparcaudio_driver
*, int);
386 int (*get_input_rate
)(struct sparcaudio_driver
*);
388 /* Return driver number to caller. (SunOS /dev/audio specific) */
389 int (*sunaudio_getdev_sunos
)(struct sparcaudio_driver
*);
391 /* Get available ports */
392 int (*get_output_ports
)(struct sparcaudio_driver
*);
393 int (*get_input_ports
)(struct sparcaudio_driver
*);
395 /* Get and set output mute */
396 int (*set_output_muted
)(struct sparcaudio_driver
*, int);
397 int (*get_output_muted
)(struct sparcaudio_driver
*);
399 /* Get and set output pause */
400 int (*set_output_pause
)(struct sparcaudio_driver
*, int);
401 int (*get_output_pause
)(struct sparcaudio_driver
*);
403 /* Get and set input pause */
404 int (*set_input_pause
)(struct sparcaudio_driver
*, int);
405 int (*get_input_pause
)(struct sparcaudio_driver
*);
407 /* Get and set output samples */
408 int (*set_output_samples
)(struct sparcaudio_driver
*, int);
409 int (*get_output_samples
)(struct sparcaudio_driver
*);
411 /* Get and set input samples */
412 int (*set_input_samples
)(struct sparcaudio_driver
*, int);
413 int (*get_input_samples
)(struct sparcaudio_driver
*);
415 /* Get and set output error */
416 int (*set_output_error
)(struct sparcaudio_driver
*, int);
417 int (*get_output_error
)(struct sparcaudio_driver
*);
419 /* Get and set input error */
420 int (*set_input_error
)(struct sparcaudio_driver
*, int);
421 int (*get_input_error
)(struct sparcaudio_driver
*);
423 /* Get supported encodings */
424 int (*get_formats
)(struct sparcaudio_driver
*);
427 extern int register_sparcaudio_driver(struct sparcaudio_driver
*, int);
428 extern int unregister_sparcaudio_driver(struct sparcaudio_driver
*, int);
429 extern void sparcaudio_output_done(struct sparcaudio_driver
*, int);
430 extern void sparcaudio_input_done(struct sparcaudio_driver
*, int);
431 extern int sparcaudio_init(void);
432 extern int amd7930_init(void);
433 extern int cs4231_init(void);
437 /* Device minor numbers */
439 #define SPARCAUDIO_MIXER_MINOR 0
440 /* No sequencer (1) */
442 #define SPARCAUDIO_DSP_MINOR 3
443 #define SPARCAUDIO_AUDIO_MINOR 4
444 #define SPARCAUDIO_DSP16_MINOR 5
445 #define SPARCAUDIO_STATUS_MINOR 6
446 #define SPARCAUDIO_AUDIOCTL_MINOR 7
447 /* No sequencer l2 (8) */
448 /* No sound processor (9) */
450 /* allocate 2^SPARCAUDIO_DEVICE_SHIFT minors per audio device */
451 #define SPARCAUDIO_DEVICE_SHIFT 4
453 /* With the coming of dummy devices this should perhaps be as high as 5? */
454 #define SPARCAUDIO_MAX_DEVICES 3
456 /* Streams crap for realaudio */
460 struct strevent
*se_next
; /* next event for this stream or NULL*/
461 struct strevent
*se_prev
; /* previous event for this stream or last
462 * event if this is the first one*/
463 pid_t se_pid
; /* process to be signaled */
464 short se_evs
; /* events wanted */
470 struct stdata
*sd_next
; /* all stdatas are linked together */
471 struct stdata
*sd_prev
;
472 struct strevent
*sd_siglist
; /* processes to be sent SIGPOLL */
473 int sd_sigflags
; /* logical OR of all siglist events */
476 #define I_NREAD _IOR('S',01, int)
477 #define I_NREAD_SOLARIS (('S'<<8)|1)
479 #define I_FLUSH _IO('S',05)
480 #define I_FLUSH_SOLARIS (('S'<<8)|5)
481 #define FLUSHR 1 /* flush read queue */
482 #define FLUSHW 2 /* flush write queue */
483 #define FLUSHRW 3 /* flush both queues */
485 #define I_SETSIG _IO('S',011)
486 #define I_SETSIG_SOLARIS (('S'<<8)|11)
489 #define S_OUTPUT 0x04
491 #define S_ERROR 0x0010
492 #define S_HANGUP 0x0020
493 #define S_RDNORM 0x0040
494 #define S_WRNORM S_OUTPUT
495 #define S_RDBAND 0x0080
496 #define S_WRBAND 0x0100
497 #define S_BANDURG 0x0200
500 #define I_GETSIG _IOR('S',012,int)
501 #define I_GETSIG_SOLARIS (('S'<<8)|12)
503 /* Conversion between Sun and OSS volume settings */
505 int OSS_LEFT(int value
)
507 return ((value
& 0xff) % 101);
511 int OSS_RIGHT(int value
)
513 return (((value
>> 8) & 0xff) % 101);
517 int O_TO_S(int value
)
519 return value
* 255 / 100;
523 int S_TO_O(int value
)
525 return value
* 100 / 255;
529 int OSS_TO_GAIN(int value
)
531 int l
= O_TO_S(OSS_LEFT(value
));
532 int r
= O_TO_S(OSS_RIGHT(value
));
533 return ((l
> r
) ? l
: r
);
537 int OSS_TO_LGAIN(int value
)
539 int l
= O_TO_S(OSS_LEFT(value
));
540 int r
= O_TO_S(OSS_RIGHT(value
));
541 return ((l
< r
) ? l
: r
);
545 int OSS_TO_BAL(int value
)
547 if (!OSS_TO_GAIN(value
))
548 return AUDIO_MID_BALANCE
;
549 if (!OSS_TO_LGAIN(value
)) {
550 if (OSS_TO_GAIN(value
) == OSS_TO_GAIN(OSS_RIGHT(value
)))
551 return AUDIO_RIGHT_BALANCE
;
553 return AUDIO_LEFT_BALANCE
;
555 if (OSS_TO_GAIN(value
) == OSS_TO_GAIN(OSS_RIGHT(value
)))
556 return ((OSS_TO_GAIN(value
) - OSS_TO_LGAIN(value
)) >> AUDIO_BALANCE_SHIFT
)
559 return AUDIO_MID_BALANCE
- ((OSS_TO_GAIN(value
) - OSS_TO_LGAIN(value
))
560 >> AUDIO_BALANCE_SHIFT
);
564 int BAL_TO_OSS(int value
, unsigned char balance
)
567 if (balance
> 63) balance
= 63;
568 if (balance
< AUDIO_MID_BALANCE
) {
569 l
= (int)value
* 100 / 255 + ((value
* 100 % 255) > 0);
570 adj
= ((AUDIO_MID_BALANCE
- balance
) << AUDIO_BALANCE_SHIFT
);
572 r
= (int)(value
- adj
)
575 } else if (balance
> AUDIO_MID_BALANCE
) {
576 r
= (int)value
* 100 / 255 + ((value
* 100 % 255) > 0);
577 adj
= ((balance
- AUDIO_MID_BALANCE
) << AUDIO_BALANCE_SHIFT
);
579 l
= (int)(value
- adj
)
583 l
= r
= (int)value
* 100 / 255 + ((value
* 100 % 255) > 0);
586 return ((r
<< 8) + l
);
589 /* OSS mixer ioctl port handling */
591 int OSS_PORT_AUDIO(struct sparcaudio_driver
*drv
, unsigned int set
)
594 if (drv
->ops
->get_output_port
) {
595 p
= drv
->ops
->get_output_port(drv
);
603 int OSS_IPORT_AUDIO(struct sparcaudio_driver
*drv
, unsigned int set
)
606 if (drv
->ops
->get_input_port
) {
607 p
= drv
->ops
->get_input_port(drv
);
615 void OSS_TWIDDLE_PORT(struct sparcaudio_driver
*drv
, unsigned int ioctl
,
616 unsigned int port
, unsigned int set
, unsigned int value
)
620 if (drv
->ops
->get_output_port
&& drv
->ops
->set_output_port
) {
621 p
= drv
->ops
->get_output_port(drv
);
622 if ((value
== 0) || ((p
& set
) && (OSS_LEFT(value
) < 100)))
623 drv
->ops
->set_output_port(drv
, p
& ~(set
));
625 drv
->ops
->set_output_port(drv
, p
| set
);
631 void OSS_TWIDDLE_IPORT(struct sparcaudio_driver
*drv
, unsigned int ioctl
,
632 unsigned int port
, unsigned int set
, unsigned int value
)
636 if (drv
->ops
->get_input_port
&& drv
->ops
->set_input_port
) {
637 p
= drv
->ops
->get_input_port(drv
);
638 if ((value
== 0) || ((p
& set
) && (OSS_LEFT(value
) < 100)))
639 drv
->ops
->set_input_port(drv
, p
& ~(set
));
641 drv
->ops
->set_input_port(drv
, p
| set
);
645 #endif /* _AUDIOIO_H_ */