xref: /linux/sound/oss/dmasound/dmasound.h (revision 3d0fe49454652117522f60bfbefb978ba0e5300b)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _dmasound_h_
3 /*
4  *  linux/sound/oss/dmasound/dmasound.h
5  *
6  *
7  *  Minor numbers for the sound driver.
8  *
9  *  Unfortunately Creative called the codec chip of SB as a DSP. For this
10  *  reason the /dev/dsp is reserved for digitized audio use. There is a
11  *  device for true DSP processors but it will be called something else.
12  *  In v3.0 it's /dev/sndproc but this could be a temporary solution.
13  */
14 #define _dmasound_h_
15 
16 #include <linux/types.h>
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 /* switch on various prinks */
33 #define DEBUG_DMASOUND 1
34 
35 #define MAX_AUDIO_DEV	5
36 #define MAX_MIXER_DEV	4
37 #define MAX_SYNTH_DEV	3
38 #define MAX_MIDI_DEV	6
39 #define MAX_TIMER_DEV	3
40 
41 #define MAX_CATCH_RADIUS	10
42 
43 #define le2be16(x)	(((x)<<8 & 0xff00) | ((x)>>8 & 0x00ff))
44 #define le2be16dbl(x)	(((x)<<8 & 0xff00ff00) | ((x)>>8 & 0x00ff00ff))
45 
46 #define IOCTL_IN(arg, ret) \
47 	do { int error = get_user(ret, (int __user *)(arg)); \
48 		if (error) return error; \
49 	} while (0)
50 #define IOCTL_OUT(arg, ret)	ioctl_return((int __user *)(arg), ret)
51 
52 static inline int ioctl_return(int __user *addr, int value)
53 {
54 	return value < 0 ? value : put_user(value, addr);
55 }
56 
57 
58     /*
59      *  Configuration
60      */
61 
62 #undef HAS_8BIT_TABLES
63 
64 #if defined(CONFIG_DMASOUND_ATARI) || defined(CONFIG_DMASOUND_ATARI_MODULE) ||\
65     defined(CONFIG_DMASOUND_PAULA) || defined(CONFIG_DMASOUND_PAULA_MODULE) ||\
66     defined(CONFIG_DMASOUND_Q40) || defined(CONFIG_DMASOUND_Q40_MODULE)
67 #define HAS_8BIT_TABLES
68 #define MIN_BUFFERS	4
69 #define MIN_BUFSIZE	(1<<12)	/* in bytes (- where does this come from ?) */
70 #define MIN_FRAG_SIZE	8	/* not 100% sure about this */
71 #define MAX_BUFSIZE	(1<<17)	/* Limit for Amiga is 128 kb */
72 #define MAX_FRAG_SIZE	15	/* allow *4 for mono-8 => stereo-16 (for multi) */
73 
74 #else /* is pmac and multi is off */
75 
76 #define MIN_BUFFERS	2
77 #define MIN_BUFSIZE	(1<<8)	/* in bytes */
78 #define MIN_FRAG_SIZE	8
79 #define MAX_BUFSIZE	(1<<18)	/* this is somewhat arbitrary for pmac */
80 #define MAX_FRAG_SIZE	16	/* need to allow *4 for mono-8 => stereo-16 */
81 #endif
82 
83 #define DEFAULT_N_BUFFERS 4
84 #define DEFAULT_BUFF_SIZE (1<<15)
85 
86     /*
87      *  Initialization
88      */
89 
90 extern int dmasound_init(void);
91 extern void dmasound_deinit(void);
92 
93 /* description of the set-up applies to either hard or soft settings */
94 
95 typedef struct {
96     int format;		/* AFMT_* */
97     int stereo;		/* 0 = mono, 1 = stereo */
98     int size;		/* 8/16 bit*/
99     int speed;		/* speed */
100 } SETTINGS;
101 
102     /*
103      *  Machine definitions
104      */
105 
106 typedef struct {
107     const char *name;
108     const char *name2;
109     struct module *owner;
110     void *(*dma_alloc)(unsigned int, gfp_t);
111     void (*dma_free)(void *, unsigned int);
112     int (*irqinit)(void);
113     void (*irqcleanup)(void);
114     void (*init)(void);
115     void (*silence)(void);
116     int (*setFormat)(int);
117     int (*setVolume)(int);
118     int (*setBass)(int);
119     int (*setTreble)(int);
120     int (*setGain)(int);
121     void (*play)(void);
122     void (*record)(void);		/* optional */
123     void (*mixer_init)(void);		/* optional */
124     int (*mixer_ioctl)(u_int, u_long);	/* optional */
125     int (*write_sq_setup)(void);	/* optional */
126     int (*read_sq_setup)(void);		/* optional */
127     int (*sq_open)(fmode_t);		/* optional */
128     int (*state_info)(char *, size_t);	/* optional */
129     void (*abort_read)(void);		/* optional */
130     int min_dsp_speed;
131     int max_dsp_speed;
132     int version ;
133     int hardware_afmts ;		/* OSS says we only return h'ware info */
134 					/* when queried via SNDCTL_DSP_GETFMTS */
135     int capabilities ;		/* low-level reply to SNDCTL_DSP_GETCAPS */
136     SETTINGS default_hard ;	/* open() or init() should set something valid */
137     SETTINGS default_soft ;	/* you can make it look like old OSS, if you want to */
138 } MACHINE;
139 
140     /*
141      *  Low level stuff
142      */
143 
144 typedef struct {
145     ssize_t (*ct_ulaw)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
146     ssize_t (*ct_alaw)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
147     ssize_t (*ct_s8)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
148     ssize_t (*ct_u8)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
149     ssize_t (*ct_s16be)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
150     ssize_t (*ct_u16be)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
151     ssize_t (*ct_s16le)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
152     ssize_t (*ct_u16le)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
153 } TRANS;
154 
155 struct sound_settings {
156     MACHINE mach;	/* machine dependent things */
157     SETTINGS hard;	/* hardware settings */
158     SETTINGS soft;	/* software settings */
159     SETTINGS dsp;	/* /dev/dsp default settings */
160     TRANS *trans_write;	/* supported translations */
161     int volume_left;	/* volume (range is machine dependent) */
162     int volume_right;
163     int bass;		/* tone (range is machine dependent) */
164     int treble;
165     int gain;
166     int minDev;		/* minor device number currently open */
167     spinlock_t lock;
168 };
169 
170 extern struct sound_settings dmasound;
171 
172 #ifdef HAS_8BIT_TABLES
173 extern char dmasound_ulaw2dma8[];
174 extern char dmasound_alaw2dma8[];
175 #endif
176 
177     /*
178      *  Mid level stuff
179      */
180 
181 static inline int dmasound_set_volume(int volume)
182 {
183 	return dmasound.mach.setVolume(volume);
184 }
185 
186 static inline int dmasound_set_bass(int bass)
187 {
188 	return dmasound.mach.setBass ? dmasound.mach.setBass(bass) : 50;
189 }
190 
191 static inline int dmasound_set_treble(int treble)
192 {
193 	return dmasound.mach.setTreble ? dmasound.mach.setTreble(treble) : 50;
194 }
195 
196 static inline int dmasound_set_gain(int gain)
197 {
198 	return dmasound.mach.setGain ? dmasound.mach.setGain(gain) : 100;
199 }
200 
201 
202     /*
203      * Sound queue stuff, the heart of the driver
204      */
205 
206 struct sound_queue {
207     /* buffers allocated for this queue */
208     int numBufs;		/* real limits on what the user can have */
209     int bufSize;		/* in bytes */
210     char **buffers;
211 
212     /* current parameters */
213     int locked ;		/* params cannot be modified when != 0 */
214     int user_frags ;		/* user requests this many */
215     int user_frag_size ;	/* of this size */
216     int max_count;		/* actual # fragments <= numBufs */
217     int block_size;		/* internal block size in bytes */
218     int max_active;		/* in-use fragments <= max_count */
219 
220     /* it shouldn't be necessary to declare any of these volatile */
221     int front, rear, count;
222     int rear_size;
223     /*
224      *	The use of the playing field depends on the hardware
225      *
226      *	Atari, PMac: The number of frames that are loaded/playing
227      *
228      *	Amiga: Bit 0 is set: a frame is loaded
229      *	       Bit 1 is set: a frame is playing
230      */
231     int active;
232     wait_queue_head_t action_queue, open_queue, sync_queue;
233     int non_blocking;
234     int busy, syncing, xruns, died;
235 };
236 
237 #define WAKE_UP(queue)		(wake_up_interruptible(&queue))
238 
239 extern struct sound_queue dmasound_write_sq;
240 #define write_sq	dmasound_write_sq
241 
242 extern int dmasound_catchRadius;
243 #define catchRadius	dmasound_catchRadius
244 
245 /* define the value to be put in the byte-swap reg in mac-io
246    when we want it to swap for us.
247 */
248 #define BS_VAL 1
249 
250 #define SW_INPUT_VOLUME_SCALE	4
251 #define SW_INPUT_VOLUME_DEFAULT	(128 / SW_INPUT_VOLUME_SCALE)
252 
253 #endif /* _dmasound_h_ */
254