File: /usr/src/linux/drivers/sound/dmasound/dmasound.h

1     
2     /*
3      *  linux/drivers/sound/dmasound/dmasound.h
4      *
5      *
6      *  Minor numbers for the sound driver.
7      *
8      *  Unfortunately Creative called the codec chip of SB as a DSP. For this
9      *  reason the /dev/dsp is reserved for digitized audio use. There is a
10      *  device for true DSP processors but it will be called something else.
11      *  In v3.0 it's /dev/sndproc but this could be a temporary solution.
12      */
13     
14     
15     #include <linux/config.h>
16     
17     
18     #define SND_NDEVS	256	/* Number of supported devices */
19     #define SND_DEV_CTL	0	/* Control port /dev/mixer */
20     #define SND_DEV_SEQ	1	/* Sequencer output /dev/sequencer (FM
21     				   synthesizer and MIDI output) */
22     #define SND_DEV_MIDIN	2	/* Raw midi access */
23     #define SND_DEV_DSP	3	/* Digitized voice /dev/dsp */
24     #define SND_DEV_AUDIO	4	/* Sparc compatible /dev/audio */
25     #define SND_DEV_DSP16	5	/* Like /dev/dsp but 16 bits/sample */
26     #define SND_DEV_STATUS	6	/* /dev/sndstat */
27     /* #7 not in use now. Was in 2.4. Free for use after v3.0. */
28     #define SND_DEV_SEQ2	8	/* /dev/sequencer, level 2 interface */
29     #define SND_DEV_SNDPROC 9	/* /dev/sndproc for programmable devices */
30     #define SND_DEV_PSS	SND_DEV_SNDPROC
31     
32     #define DSP_DEFAULT_SPEED	8000
33     
34     #define ON		1
35     #define OFF		0
36     
37     #define MAX_AUDIO_DEV	5
38     #define MAX_MIXER_DEV	2
39     #define MAX_SYNTH_DEV	3
40     #define MAX_MIDI_DEV	6
41     #define MAX_TIMER_DEV	3
42     
43     
44     #define MAX_CATCH_RADIUS	10
45     #define MIN_BUFFERS		4
46     #define MIN_BUFSIZE		4	/* in KB */
47     #define MAX_BUFSIZE		128	/* Limit for Amiga in KB */
48     
49     
50     #define le2be16(x)	(((x)<<8 & 0xff00) | ((x)>>8 & 0x00ff))
51     #define le2be16dbl(x)	(((x)<<8 & 0xff00ff00) | ((x)>>8 & 0x00ff00ff))
52     
53     #define IOCTL_IN(arg, ret) \
54     	do { int error = get_user(ret, (int *)(arg)); \
55     		if (error) return error; \
56     	} while (0)
57     #define IOCTL_OUT(arg, ret)	ioctl_return((int *)(arg), ret)
58     
59     static inline int ioctl_return(int *addr, int value)
60     {
61     	return value < 0 ? value : put_user(value, addr);
62     }
63     
64     
65         /*
66          *  Configuration
67          */
68     
69     #undef HAS_8BIT_TABLES
70     #undef HAS_14BIT_TABLES
71     #undef HAS_16BIT_TABLES
72     #undef HAS_RECORD
73     
74     #if defined(CONFIG_DMASOUND_ATARI) || defined(CONFIG_DMASOUND_ATARI_MODULE) ||\
75         defined(CONFIG_DMASOUND_PAULA) || defined(CONFIG_DMASOUND_PAULA_MODULE) ||\
76         defined(CONFIG_DMASOUND_Q40) || defined(CONFIG_DMASOUND_Q40_MODULE)
77     #define HAS_8BIT_TABLES
78     #endif
79     #if defined(CONFIG_DMASOUND_AWACS) || defined(CONFIG_DMASOUND_AWACS_MODULE)
80     #define HAS_16BIT_TABLES
81     #define HAS_RECORD
82     #endif
83     
84     
85         /*
86          *  Initialization
87          */
88     
89     extern int dmasound_init(void);
90     #ifdef MODULE
91     extern void dmasound_deinit(void);
92     #else
93     #define dmasound_deinit()	do { } while (0)
94     #endif
95     
96     
97         /*
98          *  Machine definitions
99          */
100     
101     typedef struct {
102         const char *name;
103         const char *name2;
104         void (*open)(void);
105         void (*release)(void);
106         void *(*dma_alloc)(unsigned int, int);
107         void (*dma_free)(void *, unsigned int);
108         int (*irqinit)(void);
109     #ifdef MODULE
110         void (*irqcleanup)(void);
111     #endif
112         void (*init)(void);
113         void (*silence)(void);
114         int (*setFormat)(int);
115         int (*setVolume)(int);
116         int (*setBass)(int);
117         int (*setTreble)(int);
118         int (*setGain)(int);
119         void (*play)(void);
120         void (*record)(void);			/* optional */
121         void (*mixer_init)(void);			/* optional */
122         int (*mixer_ioctl)(u_int, u_long);		/* optional */
123         void (*write_sq_setup)(void);		/* optional */
124         void (*read_sq_setup)(void);		/* optional */
125         void (*sq_open)(void);			/* optional */
126         int (*state_info)(char *);			/* optional */
127         void (*abort_read)(void);			/* optional */
128         int min_dsp_speed;
129     } MACHINE;
130     
131     
132         /*
133          *  Low level stuff
134          */
135     
136     typedef struct {
137         int format;		/* AFMT_* */
138         int stereo;		/* 0 = mono, 1 = stereo */
139         int size;		/* 8/16 bit*/
140         int speed;		/* speed */
141     } SETTINGS;
142     
143     typedef struct {
144         ssize_t (*ct_ulaw)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
145         ssize_t (*ct_alaw)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
146         ssize_t (*ct_s8)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
147         ssize_t (*ct_u8)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
148         ssize_t (*ct_s16be)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
149         ssize_t (*ct_u16be)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
150         ssize_t (*ct_s16le)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
151         ssize_t (*ct_u16le)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
152     } TRANS;
153     
154     struct sound_settings {
155         MACHINE mach;	/* machine dependent things */
156         SETTINGS hard;	/* hardware settings */
157         SETTINGS soft;	/* software settings */
158         SETTINGS dsp;	/* /dev/dsp default settings */
159         TRANS *trans_write;	/* supported translations */
160     #ifdef HAS_RECORD
161         TRANS *trans_read;	/* supported translations */
162     #endif
163         int volume_left;	/* volume (range is machine dependent) */
164         int volume_right;
165         int bass;		/* tone (range is machine dependent) */
166         int treble;
167         int gain;
168         int minDev;		/* minor device number currently open */
169     };
170     
171     extern struct sound_settings dmasound;
172     
173     extern char dmasound_ulaw2dma8[];
174     extern char dmasound_alaw2dma8[];
175     extern short dmasound_ulaw2dma16[];
176     extern short dmasound_alaw2dma16[];
177     
178     
179         /*
180          *  Mid level stuff
181          */
182     
183     static inline int dmasound_set_volume(int volume)
184     {
185     	return dmasound.mach.setVolume(volume);
186     }
187     
188     static inline int dmasound_set_bass(int bass)
189     {
190     	return dmasound.mach.setBass ? dmasound.mach.setBass(bass) : 50;
191     }
192     
193     static inline int dmasound_set_treble(int treble)
194     {
195     	return dmasound.mach.setTreble ? dmasound.mach.setTreble(treble) : 50;
196     }
197     
198     static inline int dmasound_set_gain(int gain)
199     {
200     	return dmasound.mach.setGain ? dmasound.mach.setGain(gain) : 100;
201     }
202     
203     
204         /*
205          * Sound queue stuff, the heart of the driver
206          */
207     
208     struct sound_queue {
209         /* buffers allocated for this queue */
210         int numBufs;
211         int bufSize;			/* in bytes */
212         char **buffers;
213     
214         /* current parameters */
215         int max_count;
216         int block_size;			/* in bytes */
217         int max_active;
218     
219         /* it shouldn't be necessary to declare any of these volatile */
220         int front, rear, count;
221         int rear_size;
222         /*
223          *	The use of the playing field depends on the hardware
224          *
225          *	Atari, PMac: The number of frames that are loaded/playing
226          *
227          *	Amiga: Bit 0 is set: a frame is loaded
228          *	       Bit 1 is set: a frame is playing
229          */
230         int active;
231         wait_queue_head_t action_queue, open_queue, sync_queue;
232         int open_mode;
233         int busy, syncing;
234     };
235     
236     #define SLEEP(queue)		interruptible_sleep_on_timeout(&queue, HZ)
237     #define WAKE_UP(queue)		(wake_up_interruptible(&queue))
238     
239     extern struct sound_queue dmasound_write_sq;
240     extern struct sound_queue dmasound_read_sq;
241     
242     #define write_sq	dmasound_write_sq
243     #define read_sq		dmasound_read_sq
244     
245     extern int dmasound_catchRadius;
246     
247     #define catchRadius	dmasound_catchRadius
248     
249