summaryrefslogtreecommitdiffstats
path: root/drivers/sound/dmasound/dmasound.h
blob: 985785e749dc0adabd8e8cbcb9d63a88270e1ffa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246

/*
 *  linux/drivers/sound/dmasound.h
 *
 *
 *  Minor numbers for the sound driver.
 *
 *  Unfortunately Creative called the codec chip of SB as a DSP. For this
 *  reason the /dev/dsp is reserved for digitized audio use. There is a
 *  device for true DSP processors but it will be called something else.
 *  In v3.0 it's /dev/sndproc but this could be a temporary solution.
 */


#include <linux/config.h>


#define SND_NDEVS	256	/* Number of supported devices */
#define SND_DEV_CTL	0	/* Control port /dev/mixer */
#define SND_DEV_SEQ	1	/* Sequencer output /dev/sequencer (FM
				   synthesizer and MIDI output) */
#define SND_DEV_MIDIN	2	/* Raw midi access */
#define SND_DEV_DSP	3	/* Digitized voice /dev/dsp */
#define SND_DEV_AUDIO	4	/* Sparc compatible /dev/audio */
#define SND_DEV_DSP16	5	/* Like /dev/dsp but 16 bits/sample */
#define SND_DEV_STATUS	6	/* /dev/sndstat */
/* #7 not in use now. Was in 2.4. Free for use after v3.0. */
#define SND_DEV_SEQ2	8	/* /dev/sequencer, level 2 interface */
#define SND_DEV_SNDPROC 9	/* /dev/sndproc for programmable devices */
#define SND_DEV_PSS	SND_DEV_SNDPROC

#define DSP_DEFAULT_SPEED	8000

#define ON		1
#define OFF		0

#define MAX_AUDIO_DEV	5
#define MAX_MIXER_DEV	2
#define MAX_SYNTH_DEV	3
#define MAX_MIDI_DEV	6
#define MAX_TIMER_DEV	3


#define MAX_CATCH_RADIUS	10
#define MIN_BUFFERS		4
#define MIN_BUFSIZE		4	/* in KB */
#define MAX_BUFSIZE		128	/* Limit for Amiga in KB */


#define arraysize(x)	(sizeof(x)/sizeof(*(x)))
#define min(x, y)	((x) < (y) ? (x) : (y))
#define le2be16(x)	(((x)<<8 & 0xff00) | ((x)>>8 & 0x00ff))
#define le2be16dbl(x)	(((x)<<8 & 0xff00ff00) | ((x)>>8 & 0x00ff00ff))

#define IOCTL_IN(arg, ret) \
	do { int error = get_user(ret, (int *)(arg)); \
		if (error) return error; \
	} while (0)
#define IOCTL_OUT(arg, ret)	ioctl_return((int *)(arg), ret)

static inline int ioctl_return(int *addr, int value)
{
	return value < 0 ? value : put_user(value, addr);
}


    /*
     *  Configuration
     */

#undef HAS_8BIT_TABLES
#undef HAS_14BIT_TABLES
#undef HAS_16BIT_TABLES
#undef HAS_RECORD

#if defined(CONFIG_DMASOUND_ATARI) || defined(CONFIG_DMASOUND_ATARI_MODULE) ||\
    defined(CONFIG_DMASOUND_PAULA) || defined(CONFIG_DMASOUND_PAULA_MODULE) ||\
    defined(CONFIG_DMASOUND_Q40) || defined(CONFIG_DMASOUND_Q40_MODULE)
#define HAS_8BIT_TABLES
#endif
#if defined(CONFIG_DMASOUND_AWACS) || defined(CONFIG_DMASOUND_AWACS_MODULE)
#define HAS_16BIT_TABLES
#define HAS_RECORD
#endif


    /*
     *  Initialization
     */

extern int dmasound_init(void);
extern void dmasound_deinit(void);


    /*
     *  Machine definitions
     */

typedef struct {
    const char *name;
    const char *name2;
    void (*open)(void);
    void (*release)(void);
    void *(*dma_alloc)(unsigned int, int);
    void (*dma_free)(void *, unsigned int);
    int (*irqinit)(void);
#ifdef MODULE
    void (*irqcleanup)(void);
#endif /* MODULE */
    void (*init)(void);
    void (*silence)(void);
    int (*setFormat)(int);
    int (*setVolume)(int);
    int (*setBass)(int);
    int (*setTreble)(int);
    int (*setGain)(int);
    void (*play)(void);
    void (*record)(void);			/* optional */
    void (*mixer_init)(void);			/* optional */
    int (*mixer_ioctl)(u_int, u_long);		/* optional */
    void (*write_sq_setup)(void);		/* optional */
    void (*read_sq_setup)(void);		/* optional */
    void (*sq_open)(void);			/* optional */
    int (*state_info)(char *);			/* optional */
    void (*abort_read)(void);			/* optional */
    int min_dsp_speed;
} MACHINE;


    /*
     *  Low level stuff
     */

typedef struct {
    int format;		/* AFMT_* */
    int stereo;		/* 0 = mono, 1 = stereo */
    int size;		/* 8/16 bit*/
    int speed;		/* speed */
} SETTINGS;

typedef struct {
    ssize_t (*ct_ulaw)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
    ssize_t (*ct_alaw)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
    ssize_t (*ct_s8)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
    ssize_t (*ct_u8)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
    ssize_t (*ct_s16be)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
    ssize_t (*ct_u16be)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
    ssize_t (*ct_s16le)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
    ssize_t (*ct_u16le)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
} TRANS;

struct sound_settings {
    MACHINE mach;	/* machine dependent things */
    SETTINGS hard;	/* hardware settings */
    SETTINGS soft;	/* software settings */
    SETTINGS dsp;	/* /dev/dsp default settings */
    TRANS *trans_write;	/* supported translations */
#ifdef HAS_RECORD
    TRANS *trans_read;	/* supported translations */
#endif
    int volume_left;	/* volume (range is machine dependent) */
    int volume_right;
    int bass;		/* tone (range is machine dependent) */
    int treble;
    int gain;
    int minDev;		/* minor device number currently open */
};

extern struct sound_settings dmasound;

extern char dmasound_ulaw2dma8[];
extern char dmasound_alaw2dma8[];
extern short dmasound_ulaw2dma16[];
extern short dmasound_alaw2dma16[];


    /*
     *  Mid level stuff
     */

static inline int dmasound_set_volume(int volume)
{
	return dmasound.mach.setVolume(volume);
}

static inline int dmasound_set_bass(int bass)
{
	return dmasound.mach.setBass ? dmasound.mach.setBass(bass) : 50;
}

static inline int dmasound_set_treble(int treble)
{
	return dmasound.mach.setTreble ? dmasound.mach.setTreble(treble) : 50;
}

static inline int dmasound_set_gain(int gain)
{
	return dmasound.mach.setGain ? dmasound.mach.setGain(gain) : 100;
}


    /*
     * Sound queue stuff, the heart of the driver
     */

struct sound_queue {
    /* buffers allocated for this queue */
    int numBufs;
    int bufSize;			/* in bytes */
    char **buffers;

    /* current parameters */
    int max_count;
    int block_size;			/* in bytes */
    int max_active;

    /* it shouldn't be necessary to declare any of these volatile */
    int front, rear, count;
    int rear_size;
    /*
     *	The use of the playing field depends on the hardware
     *
     *	Atari, PMac: The number of frames that are loaded/playing
     *
     *	Amiga: Bit 0 is set: a frame is loaded
     *	       Bit 1 is set: a frame is playing
     */
    int active;
    wait_queue_head_t action_queue, open_queue, sync_queue;
    int open_mode;
    int busy, syncing;
};

#define SLEEP(queue)		interruptible_sleep_on_timeout(&queue, HZ)
#define WAKE_UP(queue)		(wake_up_interruptible(&queue))

extern struct sound_queue dmasound_write_sq;
extern struct sound_queue dmasound_read_sq;

#define write_sq	dmasound_write_sq
#define read_sq		dmasound_read_sq

extern int dmasound_catchRadius;

#define catchRadius	dmasound_catchRadius