xref: /openbmc/linux/include/sound/sb.h (revision b593bce5)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef __SOUND_SB_H
3 #define __SOUND_SB_H
4 
5 /*
6  *  Header file for SoundBlaster cards
7  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
8  */
9 
10 #include <sound/pcm.h>
11 #include <sound/rawmidi.h>
12 #include <linux/interrupt.h>
13 #include <linux/io.h>
14 
15 enum sb_hw_type {
16 	SB_HW_AUTO,
17 	SB_HW_10,
18 	SB_HW_20,
19 	SB_HW_201,
20 	SB_HW_PRO,
21 	SB_HW_JAZZ16,		/* Media Vision Jazz16 */
22 	SB_HW_16,
23 	SB_HW_16CSP,		/* SB16 with CSP chip */
24 	SB_HW_ALS100,		/* Avance Logic ALS100 chip */
25 	SB_HW_ALS4000,		/* Avance Logic ALS4000 chip */
26 	SB_HW_DT019X,		/* Diamond Tech. DT-019X / Avance Logic ALS-007 */
27 	SB_HW_CS5530,		/* Cyrix/NatSemi 5530 VSA1 */
28 };
29 
30 #define SB_OPEN_PCM			0x01
31 #define SB_OPEN_MIDI_INPUT		0x02
32 #define SB_OPEN_MIDI_OUTPUT		0x04
33 #define SB_OPEN_MIDI_INPUT_TRIGGER	0x08
34 #define SB_OPEN_MIDI_OUTPUT_TRIGGER	0x10
35 
36 #define SB_MODE_HALT		0x00
37 #define SB_MODE_PLAYBACK_8	0x01
38 #define SB_MODE_PLAYBACK_16	0x02
39 #define SB_MODE_PLAYBACK	(SB_MODE_PLAYBACK_8 | SB_MODE_PLAYBACK_16)
40 #define SB_MODE_CAPTURE_8	0x04
41 #define SB_MODE_CAPTURE_16	0x08
42 #define SB_MODE_CAPTURE		(SB_MODE_CAPTURE_8 | SB_MODE_CAPTURE_16)
43 
44 #define SB_RATE_LOCK_PLAYBACK	0x10
45 #define SB_RATE_LOCK_CAPTURE	0x20
46 #define SB_RATE_LOCK		(SB_RATE_LOCK_PLAYBACK | SB_RATE_LOCK_CAPTURE)
47 
48 #define SB_MPU_INPUT		1
49 
50 struct snd_sb {
51 	unsigned long port;		/* base port of DSP chip */
52 	struct resource *res_port;
53 	unsigned long mpu_port;		/* MPU port for SB DSP 4.0+ */
54 	int irq;			/* IRQ number of DSP chip */
55 	int dma8;			/* 8-bit DMA */
56 	int dma16;			/* 16-bit DMA */
57 	unsigned short version;		/* version of DSP chip */
58 	enum sb_hw_type hardware;	/* see to SB_HW_XXXX */
59 
60 	unsigned long alt_port;		/* alternate port (ALS4000) */
61 	struct pci_dev *pci;		/* ALS4000 */
62 
63 	unsigned int open;		/* see to SB_OPEN_XXXX for sb8 */
64 					/* also SNDRV_SB_CSP_MODE_XXX for sb16_csp */
65 	unsigned int mode;		/* current mode of stream */
66 	unsigned int force_mode16;	/* force 16-bit mode of streams */
67 	unsigned int locked_rate;	/* sb16 duplex */
68 	unsigned int playback_format;
69 	unsigned int capture_format;
70 	struct timer_list midi_timer;
71 	unsigned int p_dma_size;
72 	unsigned int p_period_size;
73 	unsigned int c_dma_size;
74 	unsigned int c_period_size;
75 
76 	spinlock_t mixer_lock;
77 
78 	char name[32];
79 
80 	void *csp; /* used only when CONFIG_SND_SB16_CSP is set */
81 
82 	struct snd_card *card;
83 	struct snd_pcm *pcm;
84 	struct snd_pcm_substream *playback_substream;
85 	struct snd_pcm_substream *capture_substream;
86 
87 	struct snd_rawmidi *rmidi;
88 	struct snd_rawmidi_substream *midi_substream_input;
89 	struct snd_rawmidi_substream *midi_substream_output;
90 	irq_handler_t rmidi_callback;
91 
92 	spinlock_t reg_lock;
93 	spinlock_t open_lock;
94 	spinlock_t midi_input_lock;
95 
96 	struct snd_info_entry *proc_entry;
97 
98 #ifdef CONFIG_PM
99 	unsigned char saved_regs[0x20];
100 #endif
101 };
102 
103 /* I/O ports */
104 
105 #define SBP(chip, x)		((chip)->port + s_b_SB_##x)
106 #define SBP1(port, x)		((port) + s_b_SB_##x)
107 
108 #define s_b_SB_RESET		0x6
109 #define s_b_SB_READ		0xa
110 #define s_b_SB_WRITE		0xc
111 #define s_b_SB_COMMAND		0xc
112 #define s_b_SB_STATUS		0xc
113 #define s_b_SB_DATA_AVAIL	0xe
114 #define s_b_SB_DATA_AVAIL_16 	0xf
115 #define s_b_SB_MIXER_ADDR	0x4
116 #define s_b_SB_MIXER_DATA	0x5
117 #define s_b_SB_OPL3_LEFT	0x0
118 #define s_b_SB_OPL3_RIGHT	0x2
119 #define s_b_SB_OPL3_BOTH	0x8
120 
121 #define SB_DSP_OUTPUT		0x14
122 #define SB_DSP_INPUT		0x24
123 #define SB_DSP_BLOCK_SIZE	0x48
124 #define SB_DSP_HI_OUTPUT	0x91
125 #define SB_DSP_HI_INPUT		0x99
126 #define SB_DSP_LO_OUTPUT_AUTO	0x1c
127 #define SB_DSP_LO_INPUT_AUTO	0x2c
128 #define SB_DSP_HI_OUTPUT_AUTO	0x90
129 #define SB_DSP_HI_INPUT_AUTO	0x98
130 #define SB_DSP_IMMED_INT	0xf2
131 #define SB_DSP_GET_VERSION	0xe1
132 #define SB_DSP_SPEAKER_ON	0xd1
133 #define SB_DSP_SPEAKER_OFF	0xd3
134 #define SB_DSP_DMA8_OFF		0xd0
135 #define SB_DSP_DMA8_ON		0xd4
136 #define SB_DSP_DMA8_EXIT	0xda
137 #define SB_DSP_DMA16_OFF	0xd5
138 #define SB_DSP_DMA16_ON		0xd6
139 #define SB_DSP_DMA16_EXIT	0xd9
140 #define SB_DSP_SAMPLE_RATE	0x40
141 #define SB_DSP_SAMPLE_RATE_OUT	0x41
142 #define SB_DSP_SAMPLE_RATE_IN	0x42
143 #define SB_DSP_MONO_8BIT	0xa0
144 #define SB_DSP_MONO_16BIT	0xa4
145 #define SB_DSP_STEREO_8BIT	0xa8
146 #define SB_DSP_STEREO_16BIT	0xac
147 
148 #define SB_DSP_MIDI_INPUT_IRQ	0x31
149 #define SB_DSP_MIDI_UART_IRQ	0x35
150 #define SB_DSP_MIDI_OUTPUT	0x38
151 
152 #define SB_DSP4_OUT8_AI		0xc6
153 #define SB_DSP4_IN8_AI		0xce
154 #define SB_DSP4_OUT16_AI	0xb6
155 #define SB_DSP4_IN16_AI		0xbe
156 #define SB_DSP4_MODE_UNS_MONO	0x00
157 #define SB_DSP4_MODE_SIGN_MONO	0x10
158 #define SB_DSP4_MODE_UNS_STEREO	0x20
159 #define SB_DSP4_MODE_SIGN_STEREO 0x30
160 
161 #define SB_DSP4_OUTPUT		0x3c
162 #define SB_DSP4_INPUT_LEFT	0x3d
163 #define SB_DSP4_INPUT_RIGHT	0x3e
164 
165 /* registers for SB 2.0 mixer */
166 #define SB_DSP20_MASTER_DEV	0x02
167 #define SB_DSP20_PCM_DEV	0x0A
168 #define SB_DSP20_CD_DEV		0x08
169 #define SB_DSP20_FM_DEV		0x06
170 
171 /* registers for SB PRO mixer */
172 #define SB_DSP_MASTER_DEV	0x22
173 #define SB_DSP_PCM_DEV		0x04
174 #define SB_DSP_LINE_DEV		0x2e
175 #define SB_DSP_CD_DEV		0x28
176 #define SB_DSP_FM_DEV		0x26
177 #define SB_DSP_MIC_DEV		0x0a
178 #define SB_DSP_CAPTURE_SOURCE	0x0c
179 #define SB_DSP_CAPTURE_FILT	0x0c
180 #define SB_DSP_PLAYBACK_FILT	0x0e
181 #define SB_DSP_STEREO_SW	0x0e
182 
183 #define SB_DSP_MIXS_MIC0	0x00	/* same as MIC */
184 #define SB_DSP_MIXS_CD		0x01
185 #define SB_DSP_MIXS_MIC		0x02
186 #define SB_DSP_MIXS_LINE	0x03
187 
188 /* registers (only for left channel) for SB 16 mixer */
189 #define SB_DSP4_MASTER_DEV	0x30
190 #define SB_DSP4_BASS_DEV	0x46
191 #define SB_DSP4_TREBLE_DEV	0x44
192 #define SB_DSP4_SYNTH_DEV	0x34
193 #define SB_DSP4_PCM_DEV		0x32
194 #define SB_DSP4_SPEAKER_DEV	0x3b
195 #define SB_DSP4_LINE_DEV	0x38
196 #define SB_DSP4_MIC_DEV		0x3a
197 #define SB_DSP4_OUTPUT_SW	0x3c
198 #define SB_DSP4_CD_DEV		0x36
199 #define SB_DSP4_IGAIN_DEV	0x3f
200 #define SB_DSP4_OGAIN_DEV	0x41
201 #define SB_DSP4_MIC_AGC		0x43
202 
203 /* additional registers for SB 16 mixer */
204 #define SB_DSP4_IRQSETUP	0x80
205 #define SB_DSP4_DMASETUP	0x81
206 #define SB_DSP4_IRQSTATUS	0x82
207 #define SB_DSP4_MPUSETUP	0x84
208 
209 #define SB_DSP4_3DSE		0x90
210 
211 /* Registers for DT-019x / ALS-007 mixer */
212 #define SB_DT019X_MASTER_DEV	0x62
213 #define SB_DT019X_PCM_DEV	0x64
214 #define SB_DT019X_SYNTH_DEV	0x66
215 #define SB_DT019X_CD_DEV	0x68
216 #define SB_DT019X_MIC_DEV	0x6a
217 #define SB_DT019X_SPKR_DEV	0x6a
218 #define SB_DT019X_LINE_DEV	0x6e
219 #define SB_DT019X_OUTPUT_SW2	0x4c
220 #define SB_DT019X_CAPTURE_SW	0x6c
221 
222 #define SB_DT019X_CAP_CD	0x02
223 #define SB_DT019X_CAP_MIC	0x04
224 #define SB_DT019X_CAP_LINE	0x06
225 #define SB_DT019X_CAP_SYNTH	0x07
226 #define SB_DT019X_CAP_MAIN	0x07
227 
228 #define SB_ALS4000_MONO_IO_CTRL	0x4b
229 #define SB_ALS4000_OUT_MIXER_CTRL_2	0x4c
230 #define SB_ALS4000_MIC_IN_GAIN	0x4d
231 #define SB_ALS4000_ANALOG_REFRNC_VOLT_CTRL 0x4e
232 #define SB_ALS4000_FMDAC	0x4f
233 #define SB_ALS4000_3D_SND_FX	0x50
234 #define SB_ALS4000_3D_TIME_DELAY	0x51
235 #define SB_ALS4000_3D_AUTO_MUTE	0x52
236 #define SB_ALS4000_ANALOG_BLOCK_CTRL 0x53
237 #define SB_ALS4000_3D_DELAYLINE_PATTERN 0x54
238 #define SB_ALS4000_CR3_CONFIGURATION	0xc3 /* bit 7 is Digital Loop Enable */
239 #define SB_ALS4000_QSOUND	0xdb
240 
241 /* IRQ setting bitmap */
242 #define SB_IRQSETUP_IRQ9	0x01
243 #define SB_IRQSETUP_IRQ5	0x02
244 #define SB_IRQSETUP_IRQ7	0x04
245 #define SB_IRQSETUP_IRQ10	0x08
246 
247 /* IRQ types */
248 #define SB_IRQTYPE_8BIT		0x01
249 #define SB_IRQTYPE_16BIT	0x02
250 #define SB_IRQTYPE_MPUIN	0x04
251 #define ALS4K_IRQTYPE_CR1E_DMA	0x20
252 
253 /* DMA setting bitmap */
254 #define SB_DMASETUP_DMA0	0x01
255 #define SB_DMASETUP_DMA1	0x02
256 #define SB_DMASETUP_DMA3	0x08
257 #define SB_DMASETUP_DMA5	0x20
258 #define SB_DMASETUP_DMA6	0x40
259 #define SB_DMASETUP_DMA7	0x80
260 
261 /*
262  *
263  */
264 
265 static inline void snd_sb_ack_8bit(struct snd_sb *chip)
266 {
267 	inb(SBP(chip, DATA_AVAIL));
268 }
269 
270 static inline void snd_sb_ack_16bit(struct snd_sb *chip)
271 {
272 	inb(SBP(chip, DATA_AVAIL_16));
273 }
274 
275 /* sb_common.c */
276 int snd_sbdsp_command(struct snd_sb *chip, unsigned char val);
277 int snd_sbdsp_get_byte(struct snd_sb *chip);
278 int snd_sbdsp_reset(struct snd_sb *chip);
279 int snd_sbdsp_create(struct snd_card *card,
280 		     unsigned long port,
281 		     int irq,
282 		     irq_handler_t irq_handler,
283 		     int dma8, int dma16,
284 		     unsigned short hardware,
285 		     struct snd_sb **r_chip);
286 /* sb_mixer.c */
287 void snd_sbmixer_write(struct snd_sb *chip, unsigned char reg, unsigned char data);
288 unsigned char snd_sbmixer_read(struct snd_sb *chip, unsigned char reg);
289 int snd_sbmixer_new(struct snd_sb *chip);
290 #ifdef CONFIG_PM
291 void snd_sbmixer_suspend(struct snd_sb *chip);
292 void snd_sbmixer_resume(struct snd_sb *chip);
293 #endif
294 
295 /* sb8_init.c */
296 int snd_sb8dsp_pcm(struct snd_sb *chip, int device);
297 /* sb8.c */
298 irqreturn_t snd_sb8dsp_interrupt(struct snd_sb *chip);
299 int snd_sb8_playback_open(struct snd_pcm_substream *substream);
300 int snd_sb8_capture_open(struct snd_pcm_substream *substream);
301 int snd_sb8_playback_close(struct snd_pcm_substream *substream);
302 int snd_sb8_capture_close(struct snd_pcm_substream *substream);
303 /* midi8.c */
304 irqreturn_t snd_sb8dsp_midi_interrupt(struct snd_sb *chip);
305 int snd_sb8dsp_midi(struct snd_sb *chip, int device);
306 
307 /* sb16_init.c */
308 int snd_sb16dsp_pcm(struct snd_sb *chip, int device);
309 const struct snd_pcm_ops *snd_sb16dsp_get_pcm_ops(int direction);
310 int snd_sb16dsp_configure(struct snd_sb *chip);
311 /* sb16.c */
312 irqreturn_t snd_sb16dsp_interrupt(int irq, void *dev_id);
313 
314 /* exported mixer stuffs */
315 enum {
316 	SB_MIX_SINGLE,
317 	SB_MIX_DOUBLE,
318 	SB_MIX_INPUT_SW,
319 	SB_MIX_CAPTURE_PRO,
320 	SB_MIX_CAPTURE_DT019X,
321 	SB_MIX_MONO_CAPTURE_ALS4K
322 };
323 
324 #define SB_MIXVAL_DOUBLE(left_reg, right_reg, left_shift, right_shift, mask) \
325   ((left_reg) | ((right_reg) << 8) | ((left_shift) << 16) | ((right_shift) << 19) | ((mask) << 24))
326 #define SB_MIXVAL_SINGLE(reg, shift, mask) \
327   ((reg) | ((shift) << 16) | ((mask) << 24))
328 #define SB_MIXVAL_INPUT_SW(reg1, reg2, left_shift, right_shift) \
329   ((reg1) | ((reg2) << 8) | ((left_shift) << 16) | ((right_shift) << 24))
330 
331 int snd_sbmixer_add_ctl(struct snd_sb *chip, const char *name, int index, int type, unsigned long value);
332 
333 /* for ease of use */
334 struct sbmix_elem {
335 	const char *name;
336 	int type;
337 	unsigned long private_value;
338 };
339 
340 #define SB_SINGLE(xname, reg, shift, mask) \
341 { .name = xname, \
342   .type = SB_MIX_SINGLE, \
343   .private_value = SB_MIXVAL_SINGLE(reg, shift, mask) }
344 
345 #define SB_DOUBLE(xname, left_reg, right_reg, left_shift, right_shift, mask) \
346 { .name = xname, \
347   .type = SB_MIX_DOUBLE, \
348   .private_value = SB_MIXVAL_DOUBLE(left_reg, right_reg, left_shift, right_shift, mask) }
349 
350 #define SB16_INPUT_SW(xname, reg1, reg2, left_shift, right_shift) \
351 { .name = xname, \
352   .type = SB_MIX_INPUT_SW, \
353   .private_value = SB_MIXVAL_INPUT_SW(reg1, reg2, left_shift, right_shift) }
354 
355 static inline int snd_sbmixer_add_ctl_elem(struct snd_sb *chip, const struct sbmix_elem *c)
356 {
357 	return snd_sbmixer_add_ctl(chip, c->name, 0, c->type, c->private_value);
358 }
359 
360 #endif /* __SOUND_SB_H */
361