1 | /*
|
---|
2 | * Driver for ESS Solo-1 (ES1938, ES1946) soundcard
|
---|
3 | * Copyright (c) by Jaromir Koutek <miri@punknet.cz>,
|
---|
4 | * Jaroslav Kysela <perex@suse.cz>,
|
---|
5 | * Thomas Sailer <sailer@ife.ee.ethz.ch>,
|
---|
6 | * Abramo Bagnara <abramo@alsa-project.org>,
|
---|
7 | * Markus Gruber <gruber@eikon.tum.de>
|
---|
8 | *
|
---|
9 | * Rewritted from sonicvibes.c source.
|
---|
10 | *
|
---|
11 | * TODO:
|
---|
12 | * MPU401
|
---|
13 | *
|
---|
14 | *
|
---|
15 | * This program is free software; you can redistribute it and/or modify
|
---|
16 | * it under the terms of the GNU General Public License as published by
|
---|
17 | * the Free Software Foundation; either version 2 of the License, or
|
---|
18 | * (at your option) any later version.
|
---|
19 | *
|
---|
20 | * This program is distributed in the hope that it will be useful,
|
---|
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
23 | * GNU General Public License for more details.
|
---|
24 | *
|
---|
25 | * You should have received a copy of the GNU General Public License
|
---|
26 | * along with this program; if not, write to the Free Software
|
---|
27 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
28 | *
|
---|
29 | */
|
---|
30 |
|
---|
31 | /*
|
---|
32 | NOTES:
|
---|
33 | - Capture data is written unaligned starting from dma_base + 1 so I need to
|
---|
34 | disable mmap and to add a copy callback.
|
---|
35 | - After several cycle of the following:
|
---|
36 | while : ; do arecord -d1 -f cd -t raw | aplay -f cd ; done
|
---|
37 | a "playback write error (DMA or IRQ trouble?)" may happen.
|
---|
38 | This is due to playback interrupts not generated.
|
---|
39 | I suspect a timing issue.
|
---|
40 | - Sometimes the interrupt handler is invoked wrongly during playback.
|
---|
41 | This generate some harmless "Unexpected hw_pointer: wrong interrupt
|
---|
42 | acknowledge".
|
---|
43 | I've seen that using small period sizes.
|
---|
44 | Reproducible with:
|
---|
45 | mpg123 test.mp3 &
|
---|
46 | hdparm -t -T /dev/hda
|
---|
47 | */
|
---|
48 |
|
---|
49 |
|
---|
50 | #define SNDRV_MAIN_OBJECT_FILE
|
---|
51 | #include <sound/driver.h>
|
---|
52 | #include <sound/control.h>
|
---|
53 | #include <sound/pcm.h>
|
---|
54 | #include <sound/opl3.h>
|
---|
55 | #define SNDRV_GET_ID
|
---|
56 | #include <sound/initval.h>
|
---|
57 |
|
---|
58 | #define chip_t es1938_t
|
---|
59 |
|
---|
60 | EXPORT_NO_SYMBOLS;
|
---|
61 | MODULE_DESCRIPTION("ESS Solo-1");
|
---|
62 | MODULE_CLASSES("{sound}");
|
---|
63 | MODULE_DEVICES("{{ESS,ES1938},"
|
---|
64 | "{ESS,ES1946},"
|
---|
65 | "{ESS,ES1969},"
|
---|
66 | "{TerraTec,128i PCI}}");
|
---|
67 |
|
---|
68 | #ifndef PCI_VENDOR_ID_ESS
|
---|
69 | #define PCI_VENDOR_ID_ESS 0x125d
|
---|
70 | #endif
|
---|
71 | #ifndef PCI_DEVICE_ID_ESS_ES1938
|
---|
72 | #define PCI_DEVICE_ID_ESS_ES1938 0x1969
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
|
---|
76 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
|
---|
77 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
|
---|
78 |
|
---|
79 | MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
80 | MODULE_PARM_DESC(index, "Index value for ESS Solo-1 soundcard.");
|
---|
81 | MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
|
---|
82 | MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
|
---|
83 | MODULE_PARM_DESC(id, "ID string for ESS Solo-1 soundcard.");
|
---|
84 | MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
|
---|
85 | MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
86 | MODULE_PARM_DESC(enable, "Enable ESS Solo-1 soundcard.");
|
---|
87 | MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
|
---|
88 |
|
---|
89 | #define SLIO_REG(chip, x) ((chip)->io_port + ESSIO_REG_##x)
|
---|
90 |
|
---|
91 | #define SLDM_REG(chip, x) ((chip)->ddma_port + ESSDM_REG_##x)
|
---|
92 |
|
---|
93 | #define SLSB_REG(chip, x) ((chip)->sb_port + ESSSB_REG_##x)
|
---|
94 |
|
---|
95 | #define SL_PCI_LEGACYCONTROL 0x40
|
---|
96 | #define SL_PCI_CONFIG 0x50
|
---|
97 | #define SL_PCI_DDMACONTROL 0x60
|
---|
98 |
|
---|
99 | #define ESSIO_REG_AUDIO2DMAADDR 0
|
---|
100 | #define ESSIO_REG_AUDIO2DMACOUNT 4
|
---|
101 | #define ESSIO_REG_AUDIO2MODE 6
|
---|
102 | #define ESSIO_REG_IRQCONTROL 7
|
---|
103 |
|
---|
104 | #define ESSDM_REG_DMAADDR 0x00
|
---|
105 | #define ESSDM_REG_DMACOUNT 0x04
|
---|
106 | #define ESSDM_REG_DMACOMMAND 0x08
|
---|
107 | #define ESSDM_REG_DMASTATUS 0x08
|
---|
108 | #define ESSDM_REG_DMAMODE 0x0b
|
---|
109 | #define ESSDM_REG_DMACLEAR 0x0d
|
---|
110 | #define ESSDM_REG_DMAMASK 0x0f
|
---|
111 |
|
---|
112 | #define ESSSB_REG_FMLOWADDR 0x00
|
---|
113 | #define ESSSB_REG_FMHIGHADDR 0x02
|
---|
114 | #define ESSSB_REG_MIXERADDR 0x04
|
---|
115 | #define ESSSB_REG_MIXERDATA 0x05
|
---|
116 |
|
---|
117 | #define ESSSB_IREG_AUDIO1 0x14
|
---|
118 | #define ESSSB_IREG_MICMIX 0x1a
|
---|
119 | #define ESSSB_IREG_RECSRC 0x1c
|
---|
120 | #define ESSSB_IREG_MASTER 0x32
|
---|
121 | #define ESSSB_IREG_FM 0x36
|
---|
122 | #define ESSSB_IREG_AUXACD 0x38
|
---|
123 | #define ESSSB_IREG_AUXB 0x3a
|
---|
124 | #define ESSSB_IREG_PCSPEAKER 0x3c
|
---|
125 | #define ESSSB_IREG_LINE 0x3e
|
---|
126 | #define ESSSB_IREG_SPATCONTROL 0x50
|
---|
127 | #define ESSSB_IREG_SPATLEVEL 0x52
|
---|
128 | #define ESSSB_IREG_MASTER_LEFT 0x60
|
---|
129 | #define ESSSB_IREG_MASTER_RIGHT 0x62
|
---|
130 | #define ESSSB_IREG_MPU401CONTROL 0x64
|
---|
131 | #define ESSSB_IREG_MICMIXRECORD 0x68
|
---|
132 | #define ESSSB_IREG_AUDIO2RECORD 0x69
|
---|
133 | #define ESSSB_IREG_AUXACDRECORD 0x6a
|
---|
134 | #define ESSSB_IREG_FMRECORD 0x6b
|
---|
135 | #define ESSSB_IREG_AUXBRECORD 0x6c
|
---|
136 | #define ESSSB_IREG_MONO 0x6d
|
---|
137 | #define ESSSB_IREG_LINERECORD 0x6e
|
---|
138 | #define ESSSB_IREG_MONORECORD 0x6f
|
---|
139 | #define ESSSB_IREG_AUDIO2SAMPLE 0x70
|
---|
140 | #define ESSSB_IREG_AUDIO2MODE 0x71
|
---|
141 | #define ESSSB_IREG_AUDIO2FILTER 0x72
|
---|
142 | #define ESSSB_IREG_AUDIO2TCOUNTL 0x74
|
---|
143 | #define ESSSB_IREG_AUDIO2TCOUNTH 0x76
|
---|
144 | #define ESSSB_IREG_AUDIO2CONTROL1 0x78
|
---|
145 | #define ESSSB_IREG_AUDIO2CONTROL2 0x7a
|
---|
146 | #define ESSSB_IREG_AUDIO2 0x7c
|
---|
147 |
|
---|
148 | #define ESSSB_REG_RESET 0x06
|
---|
149 |
|
---|
150 | #define ESSSB_REG_READDATA 0x0a
|
---|
151 | #define ESSSB_REG_WRITEDATA 0x0c
|
---|
152 | #define ESSSB_REG_READSTATUS 0x0c
|
---|
153 |
|
---|
154 | #define ESSSB_REG_STATUS 0x0e
|
---|
155 |
|
---|
156 | #define ESS_CMD_EXTSAMPLERATE 0xa1
|
---|
157 | #define ESS_CMD_FILTERDIV 0xa2
|
---|
158 | #define ESS_CMD_DMACNTRELOADL 0xa4
|
---|
159 | #define ESS_CMD_DMACNTRELOADH 0xa5
|
---|
160 | #define ESS_CMD_ANALOGCONTROL 0xa8
|
---|
161 | #define ESS_CMD_IRQCONTROL 0xb1
|
---|
162 | #define ESS_CMD_DRQCONTROL 0xb2
|
---|
163 | #define ESS_CMD_RECLEVEL 0xb4
|
---|
164 | #define ESS_CMD_SETFORMAT 0xb6
|
---|
165 | #define ESS_CMD_SETFORMAT2 0xb7
|
---|
166 | #define ESS_CMD_DMACONTROL 0xb8
|
---|
167 | #define ESS_CMD_DMATYPE 0xb9
|
---|
168 | #define ESS_CMD_OFFSETLEFT 0xba
|
---|
169 | #define ESS_CMD_OFFSETRIGHT 0xbb
|
---|
170 | #define ESS_CMD_READREG 0xc0
|
---|
171 | #define ESS_CMD_ENABLEEXT 0xc6
|
---|
172 | #define ESS_CMD_PAUSEDMA 0xd0
|
---|
173 | #define ESS_CMD_ENABLEAUDIO1 0xd1
|
---|
174 | #define ESS_CMD_STOPAUDIO1 0xd3
|
---|
175 | #define ESS_CMD_AUDIO1STATUS 0xd8
|
---|
176 | #define ESS_CMD_CONTDMA 0xd4
|
---|
177 | #define ESS_CMD_TESTIRQ 0xf2
|
---|
178 |
|
---|
179 | #define ESS_RECSRC_MIC 0
|
---|
180 | #define ESS_RECSRC_AUXACD 2
|
---|
181 | #define ESS_RECSRC_AUXB 5
|
---|
182 | #define ESS_RECSRC_LINE 6
|
---|
183 | #define ESS_RECSRC_NONE 7
|
---|
184 |
|
---|
185 | #define DAC1 0x01
|
---|
186 | #define ADC1 0x02
|
---|
187 | #define DAC2 0x04
|
---|
188 |
|
---|
189 | /*
|
---|
190 |
|
---|
191 | */
|
---|
192 |
|
---|
193 | typedef struct _snd_es1938 es1938_t;
|
---|
194 |
|
---|
195 | struct _snd_es1938 {
|
---|
196 | int irq;
|
---|
197 |
|
---|
198 | unsigned long io_port;
|
---|
199 | struct resource *res_io_port;
|
---|
200 | unsigned long sb_port;
|
---|
201 | struct resource *res_sb_port;
|
---|
202 | unsigned long vc_port;
|
---|
203 | struct resource *res_vc_port;
|
---|
204 | unsigned long mpu_port;
|
---|
205 | struct resource *res_mpu_port;
|
---|
206 | unsigned long game_port;
|
---|
207 | struct resource *res_game_port;
|
---|
208 | unsigned long ddma_port;
|
---|
209 |
|
---|
210 | unsigned char irqmask;
|
---|
211 | unsigned char revision;
|
---|
212 |
|
---|
213 | snd_kcontrol_t *hw_volume;
|
---|
214 | snd_kcontrol_t *hw_switch;
|
---|
215 | snd_kcontrol_t *master_volume;
|
---|
216 | snd_kcontrol_t *master_switch;
|
---|
217 |
|
---|
218 | struct pci_dev *pci;
|
---|
219 | snd_card_t *card;
|
---|
220 | snd_pcm_substream_t *capture_substream;
|
---|
221 | snd_pcm_substream_t *playback1_substream;
|
---|
222 | snd_pcm_substream_t *playback2_substream;
|
---|
223 | snd_kmixer_t *mixer;
|
---|
224 | snd_rawmidi_t *rmidi;
|
---|
225 |
|
---|
226 | unsigned int dma1_size;
|
---|
227 | unsigned int dma2_size;
|
---|
228 | unsigned int dma1_start;
|
---|
229 | unsigned int dma2_start;
|
---|
230 | unsigned int dma1_shift;
|
---|
231 | unsigned int dma2_shift;
|
---|
232 | unsigned int active;
|
---|
233 |
|
---|
234 | spinlock_t reg_lock;
|
---|
235 | spinlock_t mixer_lock;
|
---|
236 | snd_info_entry_t *proc_entry;
|
---|
237 |
|
---|
238 | #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
|
---|
239 | struct gameport gameport;
|
---|
240 | #endif
|
---|
241 | };
|
---|
242 |
|
---|
243 | static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *regs);
|
---|
244 |
|
---|
245 | static struct pci_device_id snd_es1938_ids[] __devinitdata = {
|
---|
246 | { 0x125d, 0x1969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Solo-1 */
|
---|
247 | { 0, }
|
---|
248 | };
|
---|
249 |
|
---|
250 | MODULE_DEVICE_TABLE(pci, snd_es1938_ids);
|
---|
251 |
|
---|
252 | #define RESET_LOOP_TIMEOUT 0x10000
|
---|
253 | #define WRITE_LOOP_TIMEOUT 0x10000
|
---|
254 | #define GET_LOOP_TIMEOUT 0x01000
|
---|
255 |
|
---|
256 | #undef REG_DEBUG
|
---|
257 | /* -----------------------------------------------------------------
|
---|
258 | * Write to a mixer register
|
---|
259 | * -----------------------------------------------------------------*/
|
---|
260 | static void snd_es1938_mixer_write(es1938_t *chip, unsigned char reg, unsigned char val)
|
---|
261 | {
|
---|
262 | unsigned long flags;
|
---|
263 | spin_lock_irqsave(&chip->mixer_lock, flags);
|
---|
264 | outb(reg, SLSB_REG(chip, MIXERADDR));
|
---|
265 | outb(val, SLSB_REG(chip, MIXERDATA));
|
---|
266 | spin_unlock_irqrestore(&chip->mixer_lock, flags);
|
---|
267 | #ifdef REG_DEBUG
|
---|
268 | snd_printk("Mixer reg %02x set to %02x\n", reg, val);
|
---|
269 | #endif
|
---|
270 | }
|
---|
271 |
|
---|
272 | /* -----------------------------------------------------------------
|
---|
273 | * Read from a mixer register
|
---|
274 | * -----------------------------------------------------------------*/
|
---|
275 | static int snd_es1938_mixer_read(es1938_t *chip, unsigned char reg)
|
---|
276 | {
|
---|
277 | int data;
|
---|
278 | unsigned long flags;
|
---|
279 | spin_lock_irqsave(&chip->mixer_lock, flags);
|
---|
280 | outb(reg, SLSB_REG(chip, MIXERADDR));
|
---|
281 | data = inb(SLSB_REG(chip, MIXERDATA));
|
---|
282 | spin_unlock_irqrestore(&chip->mixer_lock, flags);
|
---|
283 | #ifdef REG_DEBUG
|
---|
284 | snd_printk("Mixer reg %02x now is %02x\n", reg, data);
|
---|
285 | #endif
|
---|
286 | return data;
|
---|
287 | }
|
---|
288 |
|
---|
289 | /* -----------------------------------------------------------------
|
---|
290 | * Write to some bits of a mixer register (return old value)
|
---|
291 | * -----------------------------------------------------------------*/
|
---|
292 | static int snd_es1938_mixer_bits(es1938_t *chip, unsigned char reg, unsigned char mask, unsigned char val)
|
---|
293 | {
|
---|
294 | unsigned long flags;
|
---|
295 | unsigned char old, new, oval;
|
---|
296 | spin_lock_irqsave(&chip->mixer_lock, flags);
|
---|
297 | outb(reg, SLSB_REG(chip, MIXERADDR));
|
---|
298 | old = inb(SLSB_REG(chip, MIXERDATA));
|
---|
299 | oval = old & mask;
|
---|
300 | if (val != oval) {
|
---|
301 | new = (old & ~mask) | (val & mask);
|
---|
302 | outb(new, SLSB_REG(chip, MIXERDATA));
|
---|
303 | #ifdef REG_DEBUG
|
---|
304 | snd_printk("Mixer reg %02x was %02x, set to %02x\n", reg, old, new);
|
---|
305 | #endif
|
---|
306 | }
|
---|
307 | spin_unlock_irqrestore(&chip->mixer_lock, flags);
|
---|
308 | return oval;
|
---|
309 | }
|
---|
310 |
|
---|
311 | /* -----------------------------------------------------------------
|
---|
312 | * Write command to Controller Registers
|
---|
313 | * -----------------------------------------------------------------*/
|
---|
314 | static void snd_es1938_write_cmd(es1938_t *chip, unsigned char cmd)
|
---|
315 | {
|
---|
316 | int i;
|
---|
317 | unsigned char v;
|
---|
318 | for (i = 0; i < WRITE_LOOP_TIMEOUT; i++) {
|
---|
319 | if (!(v = inb(SLSB_REG(chip, READSTATUS)) & 0x80)) {
|
---|
320 | outb(cmd, SLSB_REG(chip, WRITEDATA));
|
---|
321 | return;
|
---|
322 | }
|
---|
323 | }
|
---|
324 | printk("snd_es1938_write_cmd timeout (0x02%x/0x02%x)\n", cmd, v);
|
---|
325 | }
|
---|
326 |
|
---|
327 | /* -----------------------------------------------------------------
|
---|
328 | * Read the Read Data Buffer
|
---|
329 | * -----------------------------------------------------------------*/
|
---|
330 | static int snd_es1938_get_byte(es1938_t *chip)
|
---|
331 | {
|
---|
332 | int i;
|
---|
333 | unsigned char v;
|
---|
334 | for (i = GET_LOOP_TIMEOUT; i; i--)
|
---|
335 | if ((v = inb(SLSB_REG(chip, STATUS))) & 0x80)
|
---|
336 | return inb(SLSB_REG(chip, READDATA));
|
---|
337 | snd_printk("get_byte timeout: status 0x02%x\n", v);
|
---|
338 | return -ENODEV;
|
---|
339 | }
|
---|
340 |
|
---|
341 | /* -----------------------------------------------------------------
|
---|
342 | * Write value cmd register
|
---|
343 | * -----------------------------------------------------------------*/
|
---|
344 | static void snd_es1938_write(es1938_t *chip, unsigned char reg, unsigned char val)
|
---|
345 | {
|
---|
346 | unsigned long flags;
|
---|
347 | spin_lock_irqsave(&chip->reg_lock, flags);
|
---|
348 | snd_es1938_write_cmd(chip, reg);
|
---|
349 | snd_es1938_write_cmd(chip, val);
|
---|
350 | spin_unlock_irqrestore(&chip->reg_lock, flags);
|
---|
351 | #ifdef REG_DEBUG
|
---|
352 | snd_printk("Reg %02x set to %02x\n", reg, val);
|
---|
353 | #endif
|
---|
354 | }
|
---|
355 |
|
---|
356 | /* -----------------------------------------------------------------
|
---|
357 | * Read data from cmd register and return it
|
---|
358 | * -----------------------------------------------------------------*/
|
---|
359 | static unsigned char snd_es1938_read(es1938_t *chip, unsigned char reg)
|
---|
360 | {
|
---|
361 | unsigned char val;
|
---|
362 | unsigned long flags;
|
---|
363 | spin_lock_irqsave(&chip->reg_lock, flags);
|
---|
364 | snd_es1938_write_cmd(chip, ESS_CMD_READREG);
|
---|
365 | snd_es1938_write_cmd(chip, reg);
|
---|
366 | val = snd_es1938_get_byte(chip);
|
---|
367 | spin_unlock_irqrestore(&chip->reg_lock, flags);
|
---|
368 | #ifdef REG_DEBUG
|
---|
369 | snd_printk("Reg %02x now is %02x\n", reg, val);
|
---|
370 | #endif
|
---|
371 | return val;
|
---|
372 | }
|
---|
373 |
|
---|
374 | /* -----------------------------------------------------------------
|
---|
375 | * Write data to cmd register and return old value
|
---|
376 | * -----------------------------------------------------------------*/
|
---|
377 | static int snd_es1938_bits(es1938_t *chip, unsigned char reg, unsigned char mask, unsigned char val)
|
---|
378 | {
|
---|
379 | unsigned long flags;
|
---|
380 | unsigned char old, new, oval;
|
---|
381 | spin_lock_irqsave(&chip->reg_lock, flags);
|
---|
382 | snd_es1938_write_cmd(chip, ESS_CMD_READREG);
|
---|
383 | snd_es1938_write_cmd(chip, reg);
|
---|
384 | old = snd_es1938_get_byte(chip);
|
---|
385 | oval = old & mask;
|
---|
386 | if (val != oval) {
|
---|
387 | snd_es1938_write_cmd(chip, reg);
|
---|
388 | new = (old & ~mask) | (val & mask);
|
---|
389 | snd_es1938_write_cmd(chip, new);
|
---|
390 | #ifdef REG_DEBUG
|
---|
391 | snd_printk("Reg %02x was %02x, set to %02x\n", reg, old, new);
|
---|
392 | #endif
|
---|
393 | }
|
---|
394 | spin_unlock_irqrestore(&chip->reg_lock, flags);
|
---|
395 | return oval;
|
---|
396 | }
|
---|
397 |
|
---|
398 | /* --------------------------------------------------------------------
|
---|
399 | * Reset the chip
|
---|
400 | * --------------------------------------------------------------------*/
|
---|
401 | static void snd_es1938_reset(es1938_t *chip)
|
---|
402 | {
|
---|
403 | int i;
|
---|
404 |
|
---|
405 | outb(3, SLSB_REG(chip, RESET));
|
---|
406 | inb(SLSB_REG(chip, RESET));
|
---|
407 | outb(0, SLSB_REG(chip, RESET));
|
---|
408 | for (i = 0; i < RESET_LOOP_TIMEOUT; i++) {
|
---|
409 | if (inb(SLSB_REG(chip, STATUS)) & 0x80) {
|
---|
410 | if (inb(SLSB_REG(chip, READDATA)) == 0xaa)
|
---|
411 | goto __next;
|
---|
412 | }
|
---|
413 | }
|
---|
414 | snd_printk("ESS Solo-1 reset failed\n");
|
---|
415 |
|
---|
416 | __next:
|
---|
417 | snd_es1938_write_cmd(chip, ESS_CMD_ENABLEEXT);
|
---|
418 |
|
---|
419 | /* Demand transfer DMA: 4 bytes per DMA request */
|
---|
420 | snd_es1938_write(chip, ESS_CMD_DMATYPE, 2);
|
---|
421 |
|
---|
422 | /* Change behaviour of register A1
|
---|
423 | 4x oversampling
|
---|
424 | 2nd channel DAC asynchronous */
|
---|
425 | snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2MODE, 0x32);
|
---|
426 | /* enable/select DMA channel and IRQ channel */
|
---|
427 | snd_es1938_bits(chip, ESS_CMD_IRQCONTROL, 0xf0, 0x50);
|
---|
428 | snd_es1938_bits(chip, ESS_CMD_DRQCONTROL, 0xf0, 0x50);
|
---|
429 | snd_es1938_write_cmd(chip, ESS_CMD_ENABLEAUDIO1);
|
---|
430 | /* Set spatializer parameters to recommended values */
|
---|
431 | snd_es1938_mixer_write(chip, 0x54, 0x8f);
|
---|
432 | snd_es1938_mixer_write(chip, 0x56, 0x95);
|
---|
433 | snd_es1938_mixer_write(chip, 0x58, 0x94);
|
---|
434 | snd_es1938_mixer_write(chip, 0x5a, 0x80);
|
---|
435 | }
|
---|
436 |
|
---|
437 | /* --------------------------------------------------------------------
|
---|
438 | * Reset the FIFOs
|
---|
439 | * --------------------------------------------------------------------*/
|
---|
440 | static void snd_es1938_reset_fifo(es1938_t *chip)
|
---|
441 | {
|
---|
442 | outb(2, SLSB_REG(chip, RESET));
|
---|
443 | outb(0, SLSB_REG(chip, RESET));
|
---|
444 | }
|
---|
445 |
|
---|
446 | #ifdef TARGET_OS2
|
---|
447 | static ratnum_t clocks[2] = {
|
---|
448 | {
|
---|
449 | 793800,
|
---|
450 | 1,
|
---|
451 | 128,
|
---|
452 | 1,
|
---|
453 | },
|
---|
454 | {
|
---|
455 | 768000,
|
---|
456 | 1,
|
---|
457 | 128,
|
---|
458 | 1,
|
---|
459 | }
|
---|
460 | };
|
---|
461 |
|
---|
462 | static snd_pcm_hw_constraint_ratnums_t hw_constraints_clocks = {
|
---|
463 | 2,
|
---|
464 | clocks,
|
---|
465 | };
|
---|
466 | #else
|
---|
467 | static ratnum_t clocks[2] = {
|
---|
468 | {
|
---|
469 | num: 793800,
|
---|
470 | den_min: 1,
|
---|
471 | den_max: 128,
|
---|
472 | den_step: 1,
|
---|
473 | },
|
---|
474 | {
|
---|
475 | num: 768000,
|
---|
476 | den_min: 1,
|
---|
477 | den_max: 128,
|
---|
478 | den_step: 1,
|
---|
479 | }
|
---|
480 | };
|
---|
481 |
|
---|
482 | static snd_pcm_hw_constraint_ratnums_t hw_constraints_clocks = {
|
---|
483 | nrats: 2,
|
---|
484 | rats: clocks,
|
---|
485 | };
|
---|
486 | #endif
|
---|
487 |
|
---|
488 | static void snd_es1938_rate_set(es1938_t *chip,
|
---|
489 | snd_pcm_substream_t *substream,
|
---|
490 | int mode)
|
---|
491 | {
|
---|
492 | unsigned int bits, div0;
|
---|
493 | snd_pcm_runtime_t *runtime = substream->runtime;
|
---|
494 | if (runtime->rate_num == clocks[0].num)
|
---|
495 | bits = 128 - runtime->rate_den;
|
---|
496 | else
|
---|
497 | bits = 256 - runtime->rate_den;
|
---|
498 |
|
---|
499 | /* set filter register */
|
---|
500 | div0 = 256 - 7160000*20/(8*82*runtime->rate);
|
---|
501 |
|
---|
502 | if (mode == DAC2) {
|
---|
503 | snd_es1938_mixer_write(chip, 0x70, bits);
|
---|
504 | snd_es1938_mixer_write(chip, 0x72, div0);
|
---|
505 | } else {
|
---|
506 | snd_es1938_write(chip, 0xA1, bits);
|
---|
507 | snd_es1938_write(chip, 0xA2, div0);
|
---|
508 | }
|
---|
509 | }
|
---|
510 |
|
---|
511 | /* --------------------------------------------------------------------
|
---|
512 | * Configure Solo1 builtin DMA Controller
|
---|
513 | * --------------------------------------------------------------------*/
|
---|
514 |
|
---|
515 | static void snd_es1938_playback1_setdma(es1938_t *chip)
|
---|
516 | {
|
---|
517 | outb(0x00, SLIO_REG(chip, AUDIO2MODE));
|
---|
518 | outl(chip->dma2_start, SLIO_REG(chip, AUDIO2DMAADDR));
|
---|
519 | outw(0, SLIO_REG(chip, AUDIO2DMACOUNT));
|
---|
520 | outw(chip->dma2_size, SLIO_REG(chip, AUDIO2DMACOUNT));
|
---|
521 | }
|
---|
522 |
|
---|
523 | static void snd_es1938_playback2_setdma(es1938_t *chip)
|
---|
524 | {
|
---|
525 | /* Enable DMA controller */
|
---|
526 | outb(0xc4, SLDM_REG(chip, DMACOMMAND));
|
---|
527 | /* 1. Master reset */
|
---|
528 | outb(0, SLDM_REG(chip, DMACLEAR));
|
---|
529 | /* 2. Mask DMA */
|
---|
530 | outb(1, SLDM_REG(chip, DMAMASK));
|
---|
531 | outb(0x18, SLDM_REG(chip, DMAMODE));
|
---|
532 | outl(chip->dma1_start, SLDM_REG(chip, DMAADDR));
|
---|
533 | outw(chip->dma1_size - 1, SLDM_REG(chip, DMACOUNT));
|
---|
534 | /* 3. Unmask DMA */
|
---|
535 | outb(0, SLDM_REG(chip, DMAMASK));
|
---|
536 | }
|
---|
537 |
|
---|
538 | static void snd_es1938_capture_setdma(es1938_t *chip)
|
---|
539 | {
|
---|
540 | /* Enable DMA controller */
|
---|
541 | outb(0xc4, SLDM_REG(chip, DMACOMMAND));
|
---|
542 | /* 1. Master reset */
|
---|
543 | outb(0, SLDM_REG(chip, DMACLEAR));
|
---|
544 | /* 2. Mask DMA */
|
---|
545 | outb(1, SLDM_REG(chip, DMAMASK));
|
---|
546 | outb(0x14, SLDM_REG(chip, DMAMODE));
|
---|
547 | outl(chip->dma1_start, SLDM_REG(chip, DMAADDR));
|
---|
548 | outw(chip->dma1_size - 1, SLDM_REG(chip, DMACOUNT));
|
---|
549 | /* 3. Unmask DMA */
|
---|
550 | outb(0, SLDM_REG(chip, DMAMASK));
|
---|
551 | }
|
---|
552 |
|
---|
553 | /* ----------------------------------------------------------------------
|
---|
554 | *
|
---|
555 | * *** PCM part ***
|
---|
556 | */
|
---|
557 |
|
---|
558 | static int snd_es1938_capture_trigger(snd_pcm_substream_t * substream,
|
---|
559 | int cmd)
|
---|
560 | {
|
---|
561 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
562 | int val;
|
---|
563 | switch (cmd) {
|
---|
564 | case SNDRV_PCM_TRIGGER_START:
|
---|
565 | val = 0x0f;
|
---|
566 | chip->active |= ADC1;
|
---|
567 | break;
|
---|
568 | case SNDRV_PCM_TRIGGER_STOP:
|
---|
569 | val = 0x00;
|
---|
570 | chip->active &= ~ADC1;
|
---|
571 | break;
|
---|
572 | default:
|
---|
573 | return -EINVAL;
|
---|
574 | }
|
---|
575 | snd_es1938_write(chip, ESS_CMD_DMACONTROL, val);
|
---|
576 | return 0;
|
---|
577 | }
|
---|
578 |
|
---|
579 | static int snd_es1938_playback1_trigger(snd_pcm_substream_t * substream,
|
---|
580 | int cmd)
|
---|
581 | {
|
---|
582 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
583 | switch (cmd) {
|
---|
584 | case SNDRV_PCM_TRIGGER_START:
|
---|
585 | /* According to the documentation this should be:
|
---|
586 | 0x13 but that value may randomly swap stereo channels */
|
---|
587 | snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0x93);
|
---|
588 | outb(0x0a, SLIO_REG(chip, AUDIO2MODE));
|
---|
589 | chip->active |= DAC2;
|
---|
590 | break;
|
---|
591 | case SNDRV_PCM_TRIGGER_STOP:
|
---|
592 | outb(0, SLIO_REG(chip, AUDIO2MODE));
|
---|
593 | snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0);
|
---|
594 | chip->active &= ~DAC2;
|
---|
595 | break;
|
---|
596 | default:
|
---|
597 | return -EINVAL;
|
---|
598 | }
|
---|
599 | return 0;
|
---|
600 | }
|
---|
601 |
|
---|
602 | static int snd_es1938_playback2_trigger(snd_pcm_substream_t * substream,
|
---|
603 | int cmd)
|
---|
604 | {
|
---|
605 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
606 | int val;
|
---|
607 | switch (cmd) {
|
---|
608 | case SNDRV_PCM_TRIGGER_START:
|
---|
609 | val = 5;
|
---|
610 | chip->active |= DAC1;
|
---|
611 | break;
|
---|
612 | case SNDRV_PCM_TRIGGER_STOP:
|
---|
613 | val = 0;
|
---|
614 | chip->active &= ~DAC1;
|
---|
615 | break;
|
---|
616 | default:
|
---|
617 | return -EINVAL;
|
---|
618 | }
|
---|
619 | snd_es1938_write(chip, ESS_CMD_DMACONTROL, val);
|
---|
620 | return 0;
|
---|
621 | }
|
---|
622 |
|
---|
623 | static int snd_es1938_playback_trigger(snd_pcm_substream_t *substream,
|
---|
624 | int cmd)
|
---|
625 | {
|
---|
626 | switch (substream->number) {
|
---|
627 | case 0:
|
---|
628 | return snd_es1938_playback1_trigger(substream, cmd);
|
---|
629 | case 1:
|
---|
630 | return snd_es1938_playback2_trigger(substream, cmd);
|
---|
631 | }
|
---|
632 | snd_BUG();
|
---|
633 | return -EINVAL;
|
---|
634 | }
|
---|
635 |
|
---|
636 | /* --------------------------------------------------------------------
|
---|
637 | * First channel for Extended Mode Audio 1 ADC Operation
|
---|
638 | * --------------------------------------------------------------------*/
|
---|
639 | static int snd_es1938_capture_prepare(snd_pcm_substream_t * substream)
|
---|
640 | {
|
---|
641 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
642 | snd_pcm_runtime_t *runtime = substream->runtime;
|
---|
643 | int u, is8, mono;
|
---|
644 | unsigned int size = snd_pcm_lib_buffer_bytes(substream);
|
---|
645 | unsigned int count = snd_pcm_lib_period_bytes(substream);
|
---|
646 |
|
---|
647 | chip->dma1_size = size;
|
---|
648 | chip->dma1_start = runtime->dma_addr;
|
---|
649 |
|
---|
650 | mono = (runtime->channels > 1) ? 0 : 1;
|
---|
651 | is8 = snd_pcm_format_width(runtime->format) == 16 ? 0 : 1;
|
---|
652 | u = snd_pcm_format_unsigned(runtime->format);
|
---|
653 |
|
---|
654 | chip->dma1_shift = 2 - mono - is8;
|
---|
655 |
|
---|
656 | snd_es1938_reset_fifo(chip);
|
---|
657 |
|
---|
658 | /* program type */
|
---|
659 | snd_es1938_bits(chip, ESS_CMD_ANALOGCONTROL, 0x03, (mono ? 2 : 1));
|
---|
660 |
|
---|
661 | /* set clock and counters */
|
---|
662 | snd_es1938_rate_set(chip, substream, ADC1);
|
---|
663 |
|
---|
664 | count = 0x10000 - count;
|
---|
665 | snd_es1938_write(chip, ESS_CMD_DMACNTRELOADL, count & 0xff);
|
---|
666 | snd_es1938_write(chip, ESS_CMD_DMACNTRELOADH, count >> 8);
|
---|
667 |
|
---|
668 | /* initialize and configure ADC */
|
---|
669 | snd_es1938_write(chip, ESS_CMD_SETFORMAT2, u ? 0x51 : 0x71);
|
---|
670 | snd_es1938_write(chip, ESS_CMD_SETFORMAT2, 0x90 |
|
---|
671 | (u ? 0x00 : 0x20) |
|
---|
672 | (is8 ? 0x00 : 0x04) |
|
---|
673 | (mono ? 0x40 : 0x08));
|
---|
674 |
|
---|
675 | // snd_es1938_reset_fifo(chip);
|
---|
676 |
|
---|
677 | /* 11. configure system interrupt controller and DMA controller */
|
---|
678 | snd_es1938_capture_setdma(chip);
|
---|
679 |
|
---|
680 | return 0;
|
---|
681 | }
|
---|
682 |
|
---|
683 |
|
---|
684 | /* ------------------------------------------------------------------------------
|
---|
685 | * Second Audio channel DAC Operation
|
---|
686 | * ------------------------------------------------------------------------------*/
|
---|
687 | static int snd_es1938_playback1_prepare(snd_pcm_substream_t * substream)
|
---|
688 | {
|
---|
689 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
690 | snd_pcm_runtime_t *runtime = substream->runtime;
|
---|
691 | int u, is8, mono;
|
---|
692 | unsigned int size = snd_pcm_lib_buffer_bytes(substream);
|
---|
693 | unsigned int count = snd_pcm_lib_period_bytes(substream);
|
---|
694 |
|
---|
695 | chip->dma2_size = size;
|
---|
696 | chip->dma2_start = runtime->dma_addr;
|
---|
697 |
|
---|
698 | mono = (runtime->channels > 1) ? 0 : 1;
|
---|
699 | is8 = snd_pcm_format_width(runtime->format) == 16 ? 0 : 1;
|
---|
700 | u = snd_pcm_format_unsigned(runtime->format);
|
---|
701 |
|
---|
702 | chip->dma2_shift = 2 - mono - is8;
|
---|
703 |
|
---|
704 | /* set clock and counters */
|
---|
705 | snd_es1938_rate_set(chip, substream, DAC2);
|
---|
706 |
|
---|
707 | count >>= 1;
|
---|
708 | count = 0x10000 - count;
|
---|
709 | snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2TCOUNTL, count & 0xff);
|
---|
710 | snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2TCOUNTH, count >> 8);
|
---|
711 |
|
---|
712 | /* initialize and configure Audio 2 DAC */
|
---|
713 | snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL2, 0x40 | (u ? 0 : 4) | (mono ? 0 : 2) | (is8 ? 0 : 1));
|
---|
714 |
|
---|
715 | /* program DMA */
|
---|
716 | snd_es1938_playback1_setdma(chip);
|
---|
717 |
|
---|
718 | return 0;
|
---|
719 | }
|
---|
720 |
|
---|
721 | static int snd_es1938_playback2_prepare(snd_pcm_substream_t * substream)
|
---|
722 | {
|
---|
723 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
724 | snd_pcm_runtime_t *runtime = substream->runtime;
|
---|
725 | int u, is8, mono;
|
---|
726 | unsigned int size = snd_pcm_lib_buffer_bytes(substream);
|
---|
727 | unsigned int count = snd_pcm_lib_period_bytes(substream);
|
---|
728 |
|
---|
729 | chip->dma1_size = size;
|
---|
730 | chip->dma1_start = runtime->dma_addr;
|
---|
731 |
|
---|
732 | mono = (runtime->channels > 1) ? 0 : 1;
|
---|
733 | is8 = snd_pcm_format_width(runtime->format) == 16 ? 0 : 1;
|
---|
734 | u = snd_pcm_format_unsigned(runtime->format);
|
---|
735 |
|
---|
736 | chip->dma1_shift = 2 - mono - is8;
|
---|
737 |
|
---|
738 | count = 0x10000 - count;
|
---|
739 |
|
---|
740 | /* reset */
|
---|
741 | snd_es1938_reset_fifo(chip);
|
---|
742 |
|
---|
743 | snd_es1938_bits(chip, ESS_CMD_ANALOGCONTROL, 0x03, (mono ? 2 : 1));
|
---|
744 |
|
---|
745 | /* set clock and counters */
|
---|
746 | snd_es1938_rate_set(chip, substream, DAC1);
|
---|
747 | snd_es1938_write(chip, ESS_CMD_DMACNTRELOADL, count & 0xff);
|
---|
748 | snd_es1938_write(chip, ESS_CMD_DMACNTRELOADH, count >> 8);
|
---|
749 |
|
---|
750 | /* initialized and configure DAC */
|
---|
751 | snd_es1938_write(chip, ESS_CMD_SETFORMAT, u ? 0x80 : 0x00);
|
---|
752 | snd_es1938_write(chip, ESS_CMD_SETFORMAT, u ? 0x51 : 0x71);
|
---|
753 | snd_es1938_write(chip, ESS_CMD_SETFORMAT2,
|
---|
754 | 0x90 | (mono ? 0x40 : 0x08) |
|
---|
755 | (is8 ? 0x00 : 0x04) | (u ? 0x00 : 0x20));
|
---|
756 |
|
---|
757 | /* program DMA */
|
---|
758 | snd_es1938_playback2_setdma(chip);
|
---|
759 |
|
---|
760 | return 0;
|
---|
761 | }
|
---|
762 |
|
---|
763 | static int snd_es1938_playback_prepare(snd_pcm_substream_t *substream)
|
---|
764 | {
|
---|
765 | switch (substream->number) {
|
---|
766 | case 0:
|
---|
767 | return snd_es1938_playback1_prepare(substream);
|
---|
768 | case 1:
|
---|
769 | return snd_es1938_playback2_prepare(substream);
|
---|
770 | }
|
---|
771 | snd_BUG();
|
---|
772 | return -EINVAL;
|
---|
773 | }
|
---|
774 |
|
---|
775 | static snd_pcm_uframes_t snd_es1938_capture_pointer(snd_pcm_substream_t * substream)
|
---|
776 | {
|
---|
777 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
778 | size_t ptr;
|
---|
779 | size_t old, new;
|
---|
780 | #if 1
|
---|
781 | /* This stuff is *needed*, don't ask why - AB */
|
---|
782 | old = inw(SLDM_REG(chip, DMACOUNT));
|
---|
783 | while ((new = inw(SLDM_REG(chip, DMACOUNT))) != old)
|
---|
784 | old = new;
|
---|
785 | ptr = chip->dma1_size - 1 - new;
|
---|
786 | #else
|
---|
787 | ptr = inl(SLDM_REG(chip, DMAADDR)) - chip->dma1_start;
|
---|
788 | #endif
|
---|
789 | return ptr >> chip->dma1_shift;
|
---|
790 | }
|
---|
791 |
|
---|
792 | static snd_pcm_uframes_t snd_es1938_playback1_pointer(snd_pcm_substream_t * substream)
|
---|
793 | {
|
---|
794 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
795 | size_t ptr;
|
---|
796 | #if 1
|
---|
797 | ptr = chip->dma2_size - inw(SLIO_REG(chip, AUDIO2DMACOUNT));
|
---|
798 | #else
|
---|
799 | ptr = inl(SLIO_REG(chip, AUDIO2DMAADDR)) - chip->dma2_start;
|
---|
800 | #endif
|
---|
801 | return ptr >> chip->dma2_shift;
|
---|
802 | }
|
---|
803 |
|
---|
804 | static snd_pcm_uframes_t snd_es1938_playback2_pointer(snd_pcm_substream_t * substream)
|
---|
805 | {
|
---|
806 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
807 | size_t ptr;
|
---|
808 | size_t old, new;
|
---|
809 | #if 1
|
---|
810 | /* This stuff is *needed*, don't ask why - AB */
|
---|
811 | old = inw(SLDM_REG(chip, DMACOUNT));
|
---|
812 | while ((new = inw(SLDM_REG(chip, DMACOUNT))) != old)
|
---|
813 | old = new;
|
---|
814 | ptr = chip->dma1_size - 1 - new;
|
---|
815 | #else
|
---|
816 | ptr = inl(SLDM_REG(chip, DMAADDR)) - chip->dma1_start;
|
---|
817 | #endif
|
---|
818 | return ptr >> chip->dma1_shift;
|
---|
819 | }
|
---|
820 |
|
---|
821 | static snd_pcm_uframes_t snd_es1938_playback_pointer(snd_pcm_substream_t *substream)
|
---|
822 | {
|
---|
823 | switch (substream->number) {
|
---|
824 | case 0:
|
---|
825 | return snd_es1938_playback1_pointer(substream);
|
---|
826 | case 1:
|
---|
827 | return snd_es1938_playback2_pointer(substream);
|
---|
828 | }
|
---|
829 | snd_BUG();
|
---|
830 | return -EINVAL;
|
---|
831 | }
|
---|
832 |
|
---|
833 | static int snd_es1938_capture_copy(snd_pcm_substream_t *substream,
|
---|
834 | int channel,
|
---|
835 | snd_pcm_uframes_t pos,
|
---|
836 | void *dst,
|
---|
837 | snd_pcm_uframes_t count)
|
---|
838 | {
|
---|
839 | snd_pcm_runtime_t *runtime = substream->runtime;
|
---|
840 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
841 | pos <<= chip->dma1_shift;
|
---|
842 | count <<= chip->dma1_shift;
|
---|
843 | snd_assert(pos + count <= chip->dma1_size, return -EINVAL);
|
---|
844 | if (pos + count < chip->dma1_size) {
|
---|
845 | if (copy_to_user(dst, runtime->dma_area + pos + 1, count))
|
---|
846 | return -EFAULT;
|
---|
847 | } else {
|
---|
848 | if (copy_to_user(dst, runtime->dma_area + pos + 1, count - 1))
|
---|
849 | return -EFAULT;
|
---|
850 | if (put_user(runtime->dma_area[0], ((unsigned char *)dst) + count - 1))
|
---|
851 | return -EFAULT;
|
---|
852 | }
|
---|
853 | return 0;
|
---|
854 | }
|
---|
855 |
|
---|
856 | #ifdef TARGET_OS2
|
---|
857 | /* ----------------------------------------------------------------------
|
---|
858 | * Audio1 Capture (ADC)
|
---|
859 | * ----------------------------------------------------------------------*/
|
---|
860 | static snd_pcm_hardware_t snd_es1938_capture =
|
---|
861 | {
|
---|
862 | /* info: */ (SNDRV_PCM_INFO_INTERLEAVED |
|
---|
863 | SNDRV_PCM_INFO_BLOCK_TRANSFER),
|
---|
864 | /* formats: */ SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE,
|
---|
865 | /* rates: */ SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
|
---|
866 | /* rate_min: */ 6000,
|
---|
867 | /* rate_max: */ 48000,
|
---|
868 | /* channels_min: */ 1,
|
---|
869 | /* channels_max: */ 2,
|
---|
870 | /* buffer_bytes_max: */ 65536,
|
---|
871 | /* period_bytes_min: */ 64,
|
---|
872 | /* period_bytes_max: */ 65536,
|
---|
873 | /* periods_min: */ 1,
|
---|
874 | /* periods_max: */ 1024,
|
---|
875 | /* fifo_size: */ 256,
|
---|
876 | };
|
---|
877 |
|
---|
878 | /* -----------------------------------------------------------------------
|
---|
879 | * Audio2 Playback (DAC)
|
---|
880 | * -----------------------------------------------------------------------*/
|
---|
881 | static snd_pcm_hardware_t snd_es1938_playback =
|
---|
882 | {
|
---|
883 | /* info: */ (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
|
---|
884 | SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
---|
885 | SNDRV_PCM_INFO_MMAP_VALID),
|
---|
886 | /* formats: */ SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE,
|
---|
887 | /* rates: */ SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
|
---|
888 | /* rate_min: */ 6000,
|
---|
889 | /* rate_max: */ 48000,
|
---|
890 | /* channels_min: */ 1,
|
---|
891 | /* channels_max: */ 2,
|
---|
892 | /* buffer_bytes_max: */ 65536,
|
---|
893 | /* period_bytes_min: */ 64,
|
---|
894 | /* period_bytes_max: */ 65536,
|
---|
895 | /* periods_min: */ 1,
|
---|
896 | /* periods_max: */ 1024,
|
---|
897 | /* fifo_size: */ 256,
|
---|
898 | };
|
---|
899 | #else
|
---|
900 | /* ----------------------------------------------------------------------
|
---|
901 | * Audio1 Capture (ADC)
|
---|
902 | * ----------------------------------------------------------------------*/
|
---|
903 | static snd_pcm_hardware_t snd_es1938_capture =
|
---|
904 | {
|
---|
905 | info: (SNDRV_PCM_INFO_INTERLEAVED |
|
---|
906 | SNDRV_PCM_INFO_BLOCK_TRANSFER),
|
---|
907 | formats: SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE,
|
---|
908 | rates: SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
|
---|
909 | rate_min: 6000,
|
---|
910 | rate_max: 48000,
|
---|
911 | channels_min: 1,
|
---|
912 | channels_max: 2,
|
---|
913 | buffer_bytes_max: 65536,
|
---|
914 | period_bytes_min: 64,
|
---|
915 | period_bytes_max: 65536,
|
---|
916 | periods_min: 1,
|
---|
917 | periods_max: 1024,
|
---|
918 | fifo_size: 256,
|
---|
919 | };
|
---|
920 |
|
---|
921 | /* -----------------------------------------------------------------------
|
---|
922 | * Audio2 Playback (DAC)
|
---|
923 | * -----------------------------------------------------------------------*/
|
---|
924 | static snd_pcm_hardware_t snd_es1938_playback =
|
---|
925 | {
|
---|
926 | info: (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
|
---|
927 | SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
---|
928 | SNDRV_PCM_INFO_MMAP_VALID),
|
---|
929 | formats: SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE,
|
---|
930 | rates: SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
|
---|
931 | rate_min: 6000,
|
---|
932 | rate_max: 48000,
|
---|
933 | channels_min: 1,
|
---|
934 | channels_max: 2,
|
---|
935 | buffer_bytes_max: 65536,
|
---|
936 | period_bytes_min: 64,
|
---|
937 | period_bytes_max: 65536,
|
---|
938 | periods_min: 1,
|
---|
939 | periods_max: 1024,
|
---|
940 | fifo_size: 256,
|
---|
941 | };
|
---|
942 | #endif
|
---|
943 |
|
---|
944 | static int snd_es1938_capture_open(snd_pcm_substream_t * substream)
|
---|
945 | {
|
---|
946 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
947 | snd_pcm_runtime_t *runtime = substream->runtime;
|
---|
948 |
|
---|
949 | if (chip->playback2_substream)
|
---|
950 | return -EAGAIN;
|
---|
951 | if ((runtime->dma_area = snd_malloc_pci_pages_fallback(chip->pci, chip->dma2size, &runtime->dma_addr, &runtime->dma_bytes)) == NULL)
|
---|
952 | return -ENOMEM;
|
---|
953 | chip->capture_substream = substream;
|
---|
954 | runtime->hw = snd_es1938_capture;
|
---|
955 | snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
|
---|
956 | &hw_constraints_clocks);
|
---|
957 | snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 0, 0xff00);
|
---|
958 | return 0;
|
---|
959 | }
|
---|
960 |
|
---|
961 | static int snd_es1938_playback_open(snd_pcm_substream_t * substream)
|
---|
962 | {
|
---|
963 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
964 | snd_pcm_runtime_t *runtime = substream->runtime;
|
---|
965 |
|
---|
966 | switch (substream->number) {
|
---|
967 | case 0:
|
---|
968 | if ((runtime->dma_area = snd_malloc_pci_pages_fallback(chip->pci, chip->dma1size, &runtime->dma_addr, &runtime->dma_bytes)) == NULL)
|
---|
969 | return -ENOMEM;
|
---|
970 | chip->playback1_substream = substream;
|
---|
971 | break;
|
---|
972 | case 1:
|
---|
973 | if (chip->capture_substream)
|
---|
974 | return -EAGAIN;
|
---|
975 | if ((runtime->dma_area = snd_malloc_pci_pages_fallback(chip->pci, chip->dma1size, &runtime->dma_addr, &runtime->dma_bytes)) == NULL)
|
---|
976 | return -ENOMEM;
|
---|
977 | chip->playback2_substream = substream;
|
---|
978 | break;
|
---|
979 | default:
|
---|
980 | snd_BUG();
|
---|
981 | return -EINVAL;
|
---|
982 | }
|
---|
983 | runtime->hw = snd_es1938_playback;
|
---|
984 | snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
|
---|
985 | &hw_constraints_clocks);
|
---|
986 | snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 0, 0xff00);
|
---|
987 | return 0;
|
---|
988 | }
|
---|
989 |
|
---|
990 | static int snd_es1938_capture_close(snd_pcm_substream_t * substream)
|
---|
991 | {
|
---|
992 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
993 | snd_pcm_runtime_t *runtime = substream->runtime;
|
---|
994 |
|
---|
995 | chip->capture_substream = NULL;
|
---|
996 | snd_free_pci_pages(chip->pci, runtime->dma_bytes, runtime->dma_area, runtime->dma_addr);
|
---|
997 | return 0;
|
---|
998 | }
|
---|
999 |
|
---|
1000 | static int snd_es1938_playback_close(snd_pcm_substream_t * substream)
|
---|
1001 | {
|
---|
1002 | es1938_t *chip = snd_pcm_substream_chip(substream);
|
---|
1003 | snd_pcm_runtime_t *runtime = substream->runtime;
|
---|
1004 |
|
---|
1005 | switch (substream->number) {
|
---|
1006 | case 0:
|
---|
1007 | chip->playback1_substream = NULL;
|
---|
1008 | break;
|
---|
1009 | case 1:
|
---|
1010 | chip->playback2_substream = NULL;
|
---|
1011 | break;
|
---|
1012 | default:
|
---|
1013 | snd_BUG();
|
---|
1014 | return -EINVAL;
|
---|
1015 | }
|
---|
1016 | snd_free_pci_pages(chip->pci, runtime->dma_bytes, runtime->dma_area, runtime->dma_addr);
|
---|
1017 | return 0;
|
---|
1018 | }
|
---|
1019 |
|
---|
1020 | #ifdef TARGET_OS2
|
---|
1021 | static snd_pcm_ops_t snd_es1938_playback_ops = {
|
---|
1022 | /* open: */ snd_es1938_playback_open,
|
---|
1023 | /* close: */ snd_es1938_playback_close,
|
---|
1024 | /* ioctl: */ snd_pcm_lib_ioctl,
|
---|
1025 | 0,0,
|
---|
1026 | /* prepare: */ snd_es1938_playback_prepare,
|
---|
1027 | /* trigger: */ snd_es1938_playback_trigger,
|
---|
1028 | /* pointer: */ snd_es1938_playback_pointer,
|
---|
1029 | 0,0
|
---|
1030 | };
|
---|
1031 |
|
---|
1032 | static snd_pcm_ops_t snd_es1938_capture_ops = {
|
---|
1033 | /* open: */ snd_es1938_capture_open,
|
---|
1034 | /* close: */ snd_es1938_capture_close,
|
---|
1035 | /* ioctl: */ snd_pcm_lib_ioctl,
|
---|
1036 | 0,0,
|
---|
1037 | /* prepare: */ snd_es1938_capture_prepare,
|
---|
1038 | /* trigger: */ snd_es1938_capture_trigger,
|
---|
1039 | /* pointer: */ snd_es1938_capture_pointer,
|
---|
1040 | /* copy: */ snd_es1938_capture_copy,
|
---|
1041 | 0
|
---|
1042 | };
|
---|
1043 | #else
|
---|
1044 | static snd_pcm_ops_t snd_es1938_playback_ops = {
|
---|
1045 | open: snd_es1938_playback_open,
|
---|
1046 | close: snd_es1938_playback_close,
|
---|
1047 | ioctl: snd_pcm_lib_ioctl,
|
---|
1048 | prepare: snd_es1938_playback_prepare,
|
---|
1049 | trigger: snd_es1938_playback_trigger,
|
---|
1050 | pointer: snd_es1938_playback_pointer,
|
---|
1051 | };
|
---|
1052 |
|
---|
1053 | static snd_pcm_ops_t snd_es1938_capture_ops = {
|
---|
1054 | open: snd_es1938_capture_open,
|
---|
1055 | close: snd_es1938_capture_close,
|
---|
1056 | ioctl: snd_pcm_lib_ioctl,
|
---|
1057 | prepare: snd_es1938_capture_prepare,
|
---|
1058 | trigger: snd_es1938_capture_trigger,
|
---|
1059 | pointer: snd_es1938_capture_pointer,
|
---|
1060 | copy: snd_es1938_capture_copy,
|
---|
1061 | };
|
---|
1062 | #endif
|
---|
1063 |
|
---|
1064 | static void snd_es1938_free_pcm(snd_pcm_t *pcm)
|
---|
1065 | {
|
---|
1066 | snd_pcm_lib_preallocate_free_for_all(pcm);
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | static int __init snd_es1938_new_pcm(es1938_t *chip, int device, snd_pcm_t ** rpcm)
|
---|
1070 | {
|
---|
1071 | snd_pcm_t *pcm;
|
---|
1072 | int err;
|
---|
1073 |
|
---|
1074 | if (rpcm)
|
---|
1075 | *rpcm = NULL;
|
---|
1076 | if ((err = snd_pcm_new(chip->card, "es-1938-1946", device, 2, 1, &pcm)) < 0)
|
---|
1077 | return err;
|
---|
1078 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es1938_playback_ops);
|
---|
1079 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es1938_capture_ops);
|
---|
1080 |
|
---|
1081 | pcm->private_data = chip;
|
---|
1082 | pcm->private_free = snd_es1938_free_pcm;
|
---|
1083 | pcm->info_flags = 0;
|
---|
1084 | strcpy(pcm->name, "ESS Solo-1");
|
---|
1085 |
|
---|
1086 | snd_pcm_lib_preallocate_pci_pages_for_all(chip->pci, pcm, 64*1024, 64*1024);
|
---|
1087 |
|
---|
1088 | if (rpcm)
|
---|
1089 | *rpcm = pcm;
|
---|
1090 | return 0;
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 | /* -------------------------------------------------------------------
|
---|
1094 | *
|
---|
1095 | * *** Mixer part ***
|
---|
1096 | */
|
---|
1097 |
|
---|
1098 | static int snd_es1938_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
|
---|
1099 | {
|
---|
1100 | static char *texts[8] = {
|
---|
1101 | "Mic", "Mic Master", "CD", "AOUT",
|
---|
1102 | "Mic1", "Mix", "Line", "Master"
|
---|
1103 | };
|
---|
1104 |
|
---|
1105 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
---|
1106 | uinfo->count = 1;
|
---|
1107 | uinfo->value.enumerated.items = 8;
|
---|
1108 | if (uinfo->value.enumerated.item > 7)
|
---|
1109 | uinfo->value.enumerated.item = 7;
|
---|
1110 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
|
---|
1111 | return 0;
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 | static int snd_es1938_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
|
---|
1115 | {
|
---|
1116 | es1938_t *chip = snd_kcontrol_chip(kcontrol);
|
---|
1117 | ucontrol->value.enumerated.item[0] = snd_es1938_mixer_read(chip, 0x1c) & 0x07;
|
---|
1118 | return 0;
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | static int snd_es1938_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
|
---|
1122 | {
|
---|
1123 | es1938_t *chip = snd_kcontrol_chip(kcontrol);
|
---|
1124 | unsigned char val = ucontrol->value.enumerated.item[0];
|
---|
1125 |
|
---|
1126 | if (val > 7)
|
---|
1127 | return -EINVAL;
|
---|
1128 | return snd_es1938_mixer_bits(chip, 0x1c, 0x07, val) != val;
|
---|
1129 | }
|
---|
1130 |
|
---|
1131 | static int snd_es1938_info_spatializer_enable(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
|
---|
1132 | {
|
---|
1133 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
|
---|
1134 | uinfo->count = 1;
|
---|
1135 | uinfo->value.integer.min = 0;
|
---|
1136 | uinfo->value.integer.max = 1;
|
---|
1137 | return 0;
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | static int snd_es1938_get_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
|
---|
1141 | {
|
---|
1142 | es1938_t *chip = snd_kcontrol_chip(kcontrol);
|
---|
1143 | unsigned char val = snd_es1938_mixer_read(chip, 0x50);
|
---|
1144 | ucontrol->value.integer.value[0] = !!(val & 8);
|
---|
1145 | return 0;
|
---|
1146 | }
|
---|
1147 |
|
---|
1148 | static int snd_es1938_put_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
|
---|
1149 | {
|
---|
1150 | es1938_t *chip = snd_kcontrol_chip(kcontrol);
|
---|
1151 | unsigned char oval, nval;
|
---|
1152 | int change;
|
---|
1153 | nval = ucontrol->value.integer.value[0] ? 0x0c : 0x04;
|
---|
1154 | oval = snd_es1938_mixer_read(chip, 0x50) & 0x0c;
|
---|
1155 | change = nval != oval;
|
---|
1156 | if (change) {
|
---|
1157 | snd_es1938_mixer_write(chip, 0x50, nval & ~0x04);
|
---|
1158 | snd_es1938_mixer_write(chip, 0x50, nval);
|
---|
1159 | }
|
---|
1160 | return change;
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | static int snd_es1938_info_hw_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
|
---|
1164 | {
|
---|
1165 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
---|
1166 | uinfo->count = 2;
|
---|
1167 | uinfo->value.integer.min = 0;
|
---|
1168 | uinfo->value.integer.max = 63;
|
---|
1169 | return 0;
|
---|
1170 | }
|
---|
1171 |
|
---|
1172 | static int snd_es1938_get_hw_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
|
---|
1173 | {
|
---|
1174 | es1938_t *chip = snd_kcontrol_chip(kcontrol);
|
---|
1175 | ucontrol->value.integer.value[0] = snd_es1938_mixer_read(chip, 0x61) & 0x3f;
|
---|
1176 | ucontrol->value.integer.value[1] = snd_es1938_mixer_read(chip, 0x63) & 0x3f;
|
---|
1177 | return 0;
|
---|
1178 | }
|
---|
1179 |
|
---|
1180 | static int snd_es1938_info_hw_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
|
---|
1181 | {
|
---|
1182 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
|
---|
1183 | uinfo->count = 2;
|
---|
1184 | uinfo->value.integer.min = 0;
|
---|
1185 | uinfo->value.integer.max = 1;
|
---|
1186 | return 0;
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | static int snd_es1938_get_hw_switch(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
|
---|
1190 | {
|
---|
1191 | es1938_t *chip = snd_kcontrol_chip(kcontrol);
|
---|
1192 | ucontrol->value.integer.value[0] = !(snd_es1938_mixer_read(chip, 0x61) & 0x40);
|
---|
1193 | ucontrol->value.integer.value[1] = !(snd_es1938_mixer_read(chip, 0x63) & 0x40);
|
---|
1194 | return 0;
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | static void snd_es1938_hwv_free(snd_kcontrol_t *kcontrol)
|
---|
1198 | {
|
---|
1199 | es1938_t *chip = snd_magic_cast(es1938_t, _snd_kcontrol_chip(kcontrol), return);
|
---|
1200 | chip->master_volume = NULL;
|
---|
1201 | chip->master_switch = NULL;
|
---|
1202 | chip->hw_volume = NULL;
|
---|
1203 | chip->hw_switch = NULL;
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | static int snd_es1938_reg_bits(es1938_t *chip, unsigned char reg,
|
---|
1207 | unsigned char mask, unsigned char val)
|
---|
1208 | {
|
---|
1209 | if (reg < 0xa0)
|
---|
1210 | return snd_es1938_mixer_bits(chip, reg, mask, val);
|
---|
1211 | else
|
---|
1212 | return snd_es1938_bits(chip, reg, mask, val);
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | static int snd_es1938_reg_read(es1938_t *chip, unsigned char reg)
|
---|
1216 | {
|
---|
1217 | if (reg < 0xa0)
|
---|
1218 | return snd_es1938_mixer_read(chip, reg);
|
---|
1219 | else
|
---|
1220 | return snd_es1938_read(chip, reg);
|
---|
1221 | }
|
---|
1222 |
|
---|
1223 | #ifdef TARGET_OS2
|
---|
1224 | #define ES1938_SINGLE(xname, xindex, reg, shift, mask, invert) \
|
---|
1225 | { SNDRV_CTL_ELEM_IFACE_MIXER, 0, 0, xname, xindex, \
|
---|
1226 | 0, 0, snd_es1938_info_single, \
|
---|
1227 | snd_es1938_get_single, snd_es1938_put_single, \
|
---|
1228 | reg | (shift << 8) | (mask << 16) | (invert << 24) }
|
---|
1229 | #else
|
---|
1230 | #define ES1938_SINGLE(xname, xindex, reg, shift, mask, invert) \
|
---|
1231 | { iface: SNDRV_CTL_ELEM_IFACE_MIXER, name: xname, index: xindex, \
|
---|
1232 | info: snd_es1938_info_single, \
|
---|
1233 | get: snd_es1938_get_single, put: snd_es1938_put_single, \
|
---|
1234 | private_value: reg | (shift << 8) | (mask << 16) | (invert << 24) }
|
---|
1235 | #endif
|
---|
1236 |
|
---|
1237 | static int snd_es1938_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
|
---|
1238 | {
|
---|
1239 | int mask = (kcontrol->private_value >> 16) & 0xff;
|
---|
1240 |
|
---|
1241 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
|
---|
1242 | uinfo->count = 1;
|
---|
1243 | uinfo->value.integer.min = 0;
|
---|
1244 | uinfo->value.integer.max = mask;
|
---|
1245 | return 0;
|
---|
1246 | }
|
---|
1247 |
|
---|
1248 | static int snd_es1938_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
|
---|
1249 | {
|
---|
1250 | es1938_t *chip = snd_kcontrol_chip(kcontrol);
|
---|
1251 | int reg = kcontrol->private_value & 0xff;
|
---|
1252 | int shift = (kcontrol->private_value >> 8) & 0xff;
|
---|
1253 | int mask = (kcontrol->private_value >> 16) & 0xff;
|
---|
1254 | int invert = (kcontrol->private_value >> 24) & 0xff;
|
---|
1255 | int val;
|
---|
1256 |
|
---|
1257 | val = snd_es1938_reg_read(chip, reg);
|
---|
1258 | ucontrol->value.integer.value[0] = (val >> shift) & mask;
|
---|
1259 | if (invert)
|
---|
1260 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
|
---|
1261 | return 0;
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | static int snd_es1938_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
|
---|
1265 | {
|
---|
1266 | es1938_t *chip = snd_kcontrol_chip(kcontrol);
|
---|
1267 | int reg = kcontrol->private_value & 0xff;
|
---|
1268 | int shift = (kcontrol->private_value >> 8) & 0xff;
|
---|
1269 | int mask = (kcontrol->private_value >> 16) & 0xff;
|
---|
1270 | int invert = (kcontrol->private_value >> 24) & 0xff;
|
---|
1271 | unsigned char val;
|
---|
1272 |
|
---|
1273 | val = (ucontrol->value.integer.value[0] & mask);
|
---|
1274 | if (invert)
|
---|
1275 | val = mask - val;
|
---|
1276 | mask <<= shift;
|
---|
1277 | val <<= shift;
|
---|
1278 | return snd_es1938_reg_bits(chip, reg, mask, val) != val;
|
---|
1279 | }
|
---|
1280 |
|
---|
1281 | #ifdef TARGET_OS2
|
---|
1282 | #define ES1938_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
|
---|
1283 | { SNDRV_CTL_ELEM_IFACE_MIXER, 0, 0, xname, xindex, \
|
---|
1284 | 0, 0, snd_es1938_info_double, \
|
---|
1285 | snd_es1938_get_double, snd_es1938_put_double, \
|
---|
1286 | left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
|
---|
1287 | #else
|
---|
1288 | #define ES1938_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
|
---|
1289 | { iface: SNDRV_CTL_ELEM_IFACE_MIXER, name: xname, index: xindex, \
|
---|
1290 | info: snd_es1938_info_double, \
|
---|
1291 | get: snd_es1938_get_double, put: snd_es1938_put_double, \
|
---|
1292 | private_value: left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
|
---|
1293 | #endif
|
---|
1294 |
|
---|
1295 | static int snd_es1938_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
|
---|
1296 | {
|
---|
1297 | int mask = (kcontrol->private_value >> 24) & 0xff;
|
---|
1298 |
|
---|
1299 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
|
---|
1300 | uinfo->count = 2;
|
---|
1301 | uinfo->value.integer.min = 0;
|
---|
1302 | uinfo->value.integer.max = mask;
|
---|
1303 | return 0;
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | static int snd_es1938_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
|
---|
1307 | {
|
---|
1308 | es1938_t *chip = snd_kcontrol_chip(kcontrol);
|
---|
1309 | int left_reg = kcontrol->private_value & 0xff;
|
---|
1310 | int right_reg = (kcontrol->private_value >> 8) & 0xff;
|
---|
1311 | int shift_left = (kcontrol->private_value >> 16) & 0x07;
|
---|
1312 | int shift_right = (kcontrol->private_value >> 19) & 0x07;
|
---|
1313 | int mask = (kcontrol->private_value >> 24) & 0xff;
|
---|
1314 | int invert = (kcontrol->private_value >> 22) & 1;
|
---|
1315 | unsigned char left, right;
|
---|
1316 |
|
---|
1317 | left = snd_es1938_reg_read(chip, left_reg);
|
---|
1318 | if (left_reg != right_reg)
|
---|
1319 | right = snd_es1938_reg_read(chip, right_reg);
|
---|
1320 | else
|
---|
1321 | right = left;
|
---|
1322 | ucontrol->value.integer.value[0] = (left >> shift_left) & mask;
|
---|
1323 | ucontrol->value.integer.value[1] = (right >> shift_right) & mask;
|
---|
1324 | if (invert) {
|
---|
1325 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
|
---|
1326 | ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
|
---|
1327 | }
|
---|
1328 | return 0;
|
---|
1329 | }
|
---|
1330 |
|
---|
1331 | static int snd_es1938_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
|
---|
1332 | {
|
---|
1333 | es1938_t *chip = snd_kcontrol_chip(kcontrol);
|
---|
1334 | int left_reg = kcontrol->private_value & 0xff;
|
---|
1335 | int right_reg = (kcontrol->private_value >> 8) & 0xff;
|
---|
1336 | int shift_left = (kcontrol->private_value >> 16) & 0x07;
|
---|
1337 | int shift_right = (kcontrol->private_value >> 19) & 0x07;
|
---|
1338 | int mask = (kcontrol->private_value >> 24) & 0xff;
|
---|
1339 | int invert = (kcontrol->private_value >> 22) & 1;
|
---|
1340 | int change;
|
---|
1341 | unsigned char val1, val2, mask1, mask2;
|
---|
1342 |
|
---|
1343 | val1 = ucontrol->value.integer.value[0] & mask;
|
---|
1344 | val2 = ucontrol->value.integer.value[1] & mask;
|
---|
1345 | if (invert) {
|
---|
1346 | val1 = mask - val1;
|
---|
1347 | val2 = mask - val2;
|
---|
1348 | }
|
---|
1349 | val1 <<= shift_left;
|
---|
1350 | val2 <<= shift_right;
|
---|
1351 | mask1 = mask << shift_left;
|
---|
1352 | mask2 = mask << shift_right;
|
---|
1353 | if (left_reg != right_reg) {
|
---|
1354 | change = 0;
|
---|
1355 | if (snd_es1938_reg_bits(chip, left_reg, mask1, val1) != val1)
|
---|
1356 | change = 1;
|
---|
1357 | if (snd_es1938_reg_bits(chip, right_reg, mask2, val2) != val2)
|
---|
1358 | change = 1;
|
---|
1359 | } else {
|
---|
1360 | change = (snd_es1938_reg_bits(chip, left_reg, mask1 | mask2,
|
---|
1361 | val1 | val2) != (val1 | val2));
|
---|
1362 | }
|
---|
1363 | return change;
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | static snd_kcontrol_new_t snd_es1938_controls[] = {
|
---|
1367 | ES1938_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0),
|
---|
1368 | ES1938_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1),
|
---|
1369 | #ifdef TARGET_OS2
|
---|
1370 | {
|
---|
1371 | SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
|
---|
1372 | "Hardware Master Playback Volume",0,
|
---|
1373 | SNDRV_CTL_ELEM_ACCESS_READ, 0,
|
---|
1374 | snd_es1938_info_hw_volume,
|
---|
1375 | snd_es1938_get_hw_volume,0,0
|
---|
1376 | },
|
---|
1377 | {
|
---|
1378 | SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
|
---|
1379 | "Hardware Master Playback Switch",0,
|
---|
1380 | SNDRV_CTL_ELEM_ACCESS_READ,0,
|
---|
1381 | snd_es1938_info_hw_switch,
|
---|
1382 | snd_es1938_get_hw_switch,0,0
|
---|
1383 | },
|
---|
1384 | #else
|
---|
1385 | {
|
---|
1386 | iface: SNDRV_CTL_ELEM_IFACE_MIXER,
|
---|
1387 | name: "Hardware Master Playback Volume",
|
---|
1388 | access: SNDRV_CTL_ELEM_ACCESS_READ,
|
---|
1389 | info: snd_es1938_info_hw_volume,
|
---|
1390 | get: snd_es1938_get_hw_volume,
|
---|
1391 | },
|
---|
1392 | {
|
---|
1393 | iface: SNDRV_CTL_ELEM_IFACE_MIXER,
|
---|
1394 | name: "Hardware Master Playback Switch",
|
---|
1395 | access: SNDRV_CTL_ELEM_ACCESS_READ,
|
---|
1396 | info: snd_es1938_info_hw_switch,
|
---|
1397 | get: snd_es1938_get_hw_switch,
|
---|
1398 | },
|
---|
1399 | #endif
|
---|
1400 | ES1938_SINGLE("Hardware Volume Split", 0, 0x64, 7, 1, 0),
|
---|
1401 | ES1938_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0),
|
---|
1402 | ES1938_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0),
|
---|
1403 | ES1938_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0),
|
---|
1404 | ES1938_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
|
---|
1405 | ES1938_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0),
|
---|
1406 | ES1938_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0),
|
---|
1407 | ES1938_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0),
|
---|
1408 | ES1938_SINGLE("PC Speaker Volume", 0, 0x3c, 0, 7, 0),
|
---|
1409 | ES1938_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
|
---|
1410 | ES1938_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
|
---|
1411 | {
|
---|
1412 | #ifdef TARGET_OS2
|
---|
1413 | SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
|
---|
1414 | "Capture Source",0,0, 0,
|
---|
1415 | snd_es1938_info_mux,
|
---|
1416 | snd_es1938_get_mux,
|
---|
1417 | snd_es1938_put_mux,0,
|
---|
1418 | #else
|
---|
1419 | iface: SNDRV_CTL_ELEM_IFACE_MIXER,
|
---|
1420 | name: "Capture Source",
|
---|
1421 | info: snd_es1938_info_mux,
|
---|
1422 | get: snd_es1938_get_mux,
|
---|
1423 | put: snd_es1938_put_mux,
|
---|
1424 | #endif
|
---|
1425 | },
|
---|
1426 | ES1938_DOUBLE("Mono Input Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
|
---|
1427 | ES1938_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0),
|
---|
1428 | ES1938_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0),
|
---|
1429 | ES1938_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0),
|
---|
1430 | ES1938_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0),
|
---|
1431 | ES1938_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0),
|
---|
1432 | ES1938_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0),
|
---|
1433 | ES1938_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0),
|
---|
1434 | ES1938_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0),
|
---|
1435 | ES1938_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0),
|
---|
1436 | ES1938_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
|
---|
1437 | {
|
---|
1438 | #ifdef TARGET_OS2
|
---|
1439 | SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
|
---|
1440 | "3D Control - Switch",0,0, 0,
|
---|
1441 | snd_es1938_info_spatializer_enable,
|
---|
1442 | snd_es1938_get_spatializer_enable,
|
---|
1443 | snd_es1938_put_spatializer_enable,0
|
---|
1444 | #else
|
---|
1445 | iface: SNDRV_CTL_ELEM_IFACE_MIXER,
|
---|
1446 | name: "3D Control - Switch",
|
---|
1447 | info: snd_es1938_info_spatializer_enable,
|
---|
1448 | get: snd_es1938_get_spatializer_enable,
|
---|
1449 | put: snd_es1938_put_spatializer_enable,
|
---|
1450 | #endif
|
---|
1451 | },
|
---|
1452 | ES1938_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0)
|
---|
1453 | };
|
---|
1454 |
|
---|
1455 |
|
---|
1456 | /* ---------------------------------------------------------------------------- */
|
---|
1457 | /* ---------------------------------------------------------------------------- */
|
---|
1458 |
|
---|
1459 | static int snd_es1938_free(es1938_t *chip)
|
---|
1460 | {
|
---|
1461 | if (chip->res_io_port)
|
---|
1462 | release_resource(chip->res_io_port);
|
---|
1463 | if (chip->res_sb_port)
|
---|
1464 | release_resource(chip->res_sb_port);
|
---|
1465 | if (chip->res_vc_port)
|
---|
1466 | release_resource(chip->res_vc_port);
|
---|
1467 | if (chip->res_mpu_port)
|
---|
1468 | release_resource(chip->res_mpu_port);
|
---|
1469 | if (chip->res_game_port)
|
---|
1470 | release_resource(chip->res_game_port);
|
---|
1471 | if (chip->irq >= 0)
|
---|
1472 | free_irq(chip->irq, (void *)chip);
|
---|
1473 | snd_magic_kfree(chip);
|
---|
1474 | return 0;
|
---|
1475 | }
|
---|
1476 |
|
---|
1477 | static int snd_es1938_dev_free(snd_device_t *device)
|
---|
1478 | {
|
---|
1479 | es1938_t *chip = snd_magic_cast(es1938_t, device->device_data, return -ENXIO);
|
---|
1480 | return snd_es1938_free(chip);
|
---|
1481 | }
|
---|
1482 |
|
---|
1483 | static int __init snd_es1938_create(snd_card_t * card,
|
---|
1484 | struct pci_dev * pci,
|
---|
1485 | unsigned long dma1size,
|
---|
1486 | unsigned long dma2size,
|
---|
1487 | es1938_t ** rchip)
|
---|
1488 | {
|
---|
1489 | es1938_t *chip;
|
---|
1490 | int err;
|
---|
1491 | #ifdef TARGET_OS2
|
---|
1492 | static snd_device_ops_t ops = {
|
---|
1493 | snd_es1938_dev_free,0,0
|
---|
1494 | };
|
---|
1495 | #else
|
---|
1496 | static snd_device_ops_t ops = {
|
---|
1497 | dev_free: snd_es1938_dev_free,
|
---|
1498 | };
|
---|
1499 | #endif
|
---|
1500 | *rchip = NULL;
|
---|
1501 |
|
---|
1502 | /* enable PCI device */
|
---|
1503 | if ((err = pci_enable_device(pci)) < 0)
|
---|
1504 | return err;
|
---|
1505 | /* check, if we can restrict PCI DMA transfers to 24 bits */
|
---|
1506 | if (!pci_dma_supported(pci, 0x00ffffff)) {
|
---|
1507 | snd_printk("architecture does not support 24bit PCI busmaster DMA\n");
|
---|
1508 | return -ENXIO;
|
---|
1509 | }
|
---|
1510 | pci_set_dma_mask(pci, 0x00ffffff);
|
---|
1511 |
|
---|
1512 | chip = snd_magic_kcalloc(es1938_t, 0, GFP_KERNEL);
|
---|
1513 | if (chip == NULL)
|
---|
1514 | return -ENOMEM;
|
---|
1515 | spin_lock_init(&chip->reg_lock);
|
---|
1516 | spin_lock_init(&chip->mixer_lock);
|
---|
1517 | chip->card = card;
|
---|
1518 | chip->pci = pci;
|
---|
1519 | chip->dma1size = dma1size;
|
---|
1520 | chip->dma2size = dma2size;
|
---|
1521 | chip->io_port = pci_resource_start(pci, 0);
|
---|
1522 | if ((chip->res_io_port = request_region(chip->io_port, 8, "ESS Solo-1")) == NULL) {
|
---|
1523 | snd_es1938_free(chip);
|
---|
1524 | snd_printk("unable to grab region 0x%lx-0x%lx\n", chip->io_port, chip->io_port + 8 - 1);
|
---|
1525 | return -EBUSY;
|
---|
1526 | }
|
---|
1527 | chip->sb_port = pci_resource_start(pci, 1);
|
---|
1528 | if ((chip->res_sb_port = request_region(chip->sb_port, 0x10, "ESS Solo-1 SB")) == NULL) {
|
---|
1529 | snd_es1938_free(chip);
|
---|
1530 | snd_printk("unable to grab SB region 0x%lx-0x%lx\n", chip->sb_port, chip->sb_port + 0x10 - 1);
|
---|
1531 | return -EBUSY;
|
---|
1532 | }
|
---|
1533 | chip->vc_port = pci_resource_start(pci, 2);
|
---|
1534 | if ((chip->res_vc_port = request_region(chip->vc_port, 0x10, "ESS Solo-1 VC (DMA)")) == NULL) {
|
---|
1535 | snd_es1938_free(chip);
|
---|
1536 | snd_printk("unable to grab VC (DMA) region 0x%lx-0x%lx\n", chip->vc_port, chip->vc_port + 0x10 - 1);
|
---|
1537 | return -EBUSY;
|
---|
1538 | }
|
---|
1539 | chip->mpu_port = pci_resource_start(pci, 3);
|
---|
1540 | if ((chip->res_mpu_port = request_region(chip->mpu_port, 4, "ESS Solo-1 MIDI")) == NULL) {
|
---|
1541 | snd_es1938_free(chip);
|
---|
1542 | snd_printk("unable to grab MIDI region 0x%lx-0x%lx\n", chip->mpu_port, chip->mpu_port + 4 - 1);
|
---|
1543 | return -EBUSY;
|
---|
1544 | }
|
---|
1545 | chip->game_port = pci_resource_start(pci, 4);
|
---|
1546 | if ((chip->res_game_port = request_region(chip->game_port, 4, "ESS Solo-1 GAME")) == NULL) {
|
---|
1547 | snd_es1938_free(chip);
|
---|
1548 | snd_printk("unable to grab GAME region 0x%lx-0x%lx\n", chip->game_port, chip->game_port + 4 - 1);
|
---|
1549 | return -EBUSY;
|
---|
1550 | }
|
---|
1551 | if (request_irq(pci->irq, snd_es1938_interrupt, SA_INTERRUPT|SA_SHIRQ, "ES1938", (void *)chip)) {
|
---|
1552 | snd_es1938_free(chip);
|
---|
1553 | snd_printk("unable to grab IRQ %d\n", pci->irq);
|
---|
1554 | return -EBUSY;
|
---|
1555 | }
|
---|
1556 | chip->irq = pci->irq;
|
---|
1557 | #ifdef ES1938_DDEBUG
|
---|
1558 | snd_printk("create: io: 0x%lx, sb: 0x%lx, vc: 0x%lx, mpu: 0x%lx, game: 0x%lx\n",
|
---|
1559 | chip->io_port, chip->sb_port, chip->vc_port, chip->mpu_port, chip->game_port);
|
---|
1560 | #endif
|
---|
1561 | /* reset chip */
|
---|
1562 | snd_es1938_reset(chip);
|
---|
1563 |
|
---|
1564 | /* configure native mode */
|
---|
1565 |
|
---|
1566 | /* enable bus master */
|
---|
1567 | pci_set_master(pci);
|
---|
1568 |
|
---|
1569 | /* disable legacy audio */
|
---|
1570 | pci_write_config_word(pci, SL_PCI_LEGACYCONTROL, 0x805f);
|
---|
1571 |
|
---|
1572 | /* set DDMA base */
|
---|
1573 | chip->ddma_port = chip->vc_port + 0x00; /* fix from Thomas Sailer */
|
---|
1574 | pci_write_config_word(pci, SL_PCI_DDMACONTROL, chip->ddma_port | 1);
|
---|
1575 |
|
---|
1576 | /* set DMA/IRQ policy */
|
---|
1577 | pci_write_config_dword(pci, SL_PCI_CONFIG, 0);
|
---|
1578 |
|
---|
1579 | /* enable Audio 1, Audio 2, MPU401 IRQ and HW volume IRQ*/
|
---|
1580 | outb(0xf0, SLIO_REG(chip, IRQCONTROL));
|
---|
1581 |
|
---|
1582 | /* reset DMA */
|
---|
1583 | outb(0, SLDM_REG(chip, DMACLEAR));
|
---|
1584 |
|
---|
1585 | /* enable bus mastering */
|
---|
1586 | pci_set_master(pci);
|
---|
1587 |
|
---|
1588 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
|
---|
1589 | snd_es1938_free(chip);
|
---|
1590 | return err;
|
---|
1591 | }
|
---|
1592 |
|
---|
1593 | *rchip = chip;
|
---|
1594 | return 0;
|
---|
1595 | }
|
---|
1596 |
|
---|
1597 | #if 0
|
---|
1598 | static void __init snd_es1938_midi(es1938_t *chip, mpu401_t * mpu)
|
---|
1599 | {
|
---|
1600 | mpu->private_data = chip;
|
---|
1601 | mpu->open_input = NULL; /* snd_es1938_midi_input_open; */
|
---|
1602 | mpu->close_input = NULL; /* snd_es1938_midi_input_close; */
|
---|
1603 | mpu->open_output = NULL; /* snd_es1938_midi_output_open; */
|
---|
1604 | }
|
---|
1605 | #endif
|
---|
1606 |
|
---|
1607 | /* --------------------------------------------------------------------
|
---|
1608 | * Interrupt handler
|
---|
1609 | * -------------------------------------------------------------------- */
|
---|
1610 | static void snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *regs)
|
---|
1611 | {
|
---|
1612 | es1938_t *chip = snd_magic_cast(es1938_t, dev_id, return);
|
---|
1613 | unsigned char status, audiostatus;
|
---|
1614 | #ifdef TARGET_OS2
|
---|
1615 | int fOurIrq = FALSE;
|
---|
1616 | #endif
|
---|
1617 |
|
---|
1618 | status = inb(SLIO_REG(chip, IRQCONTROL));
|
---|
1619 | #if 0
|
---|
1620 | printk("Es1938debug - interrupt status: =0x%x\n", status);
|
---|
1621 | #endif
|
---|
1622 |
|
---|
1623 | /* AUDIO 1 */
|
---|
1624 | if (status & 0x10) {
|
---|
1625 | #if 0
|
---|
1626 | printk("Es1938debug - AUDIO channel 1 interrupt\n");
|
---|
1627 | printk("Es1938debug - AUDIO channel 1 DMAC DMA count: %u\n", inw(SLDM_REG(chip, DMACOUNT)));
|
---|
1628 | printk("Es1938debug - AUDIO channel 1 DMAC DMA base: %u\n", inl(SLDM_REG(chip, DMAADDR)));
|
---|
1629 | printk("Es1938debug - AUDIO channel 1 DMAC DMA status: 0x%x\n", inl(SLDM_REG(chip, DMASTATUS)));
|
---|
1630 | #endif
|
---|
1631 | /* clear irq */
|
---|
1632 | audiostatus = inb(SLSB_REG(chip, STATUS));
|
---|
1633 | if (chip->active & ADC1)
|
---|
1634 | snd_pcm_period_elapsed(chip->capture_substream);
|
---|
1635 | else if (chip->active & DAC1)
|
---|
1636 | snd_pcm_period_elapsed(chip->playback2_substream);
|
---|
1637 | #ifdef TARGET_OS2
|
---|
1638 | fOurIrq = TRUE;
|
---|
1639 | #endif
|
---|
1640 | }
|
---|
1641 |
|
---|
1642 | /* AUDIO 2 */
|
---|
1643 | if (status & 0x20) {
|
---|
1644 | #if 0
|
---|
1645 | printk("Es1938debug - AUDIO channel 2 interrupt\n");
|
---|
1646 | printk("Es1938debug - AUDIO channel 2 DMAC DMA count: %u\n", inw(SLIO_REG(chip, AUDIO2DMACOUNT)));
|
---|
1647 | printk("Es1938debug - AUDIO channel 2 DMAC DMA base: %u\n", inl(SLIO_REG(chip, AUDIO2DMAADDR)));
|
---|
1648 |
|
---|
1649 | #endif
|
---|
1650 | /* clear irq */
|
---|
1651 | snd_es1938_mixer_bits(chip, ESSSB_IREG_AUDIO2CONTROL2, 0x80, 0);
|
---|
1652 | if (chip->active & DAC2)
|
---|
1653 | snd_pcm_period_elapsed(chip->playback1_substream);
|
---|
1654 | #ifdef TARGET_OS2
|
---|
1655 | fOurIrq = TRUE;
|
---|
1656 | #endif
|
---|
1657 | }
|
---|
1658 |
|
---|
1659 | /* Hardware volume */
|
---|
1660 | if (status & 0x40) {
|
---|
1661 | int split = snd_es1938_mixer_read(chip, 0x64) & 0x80;
|
---|
1662 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_switch->id);
|
---|
1663 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_volume->id);
|
---|
1664 | if (!split) {
|
---|
1665 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_switch->id);
|
---|
1666 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_volume->id);
|
---|
1667 | }
|
---|
1668 | /* ack interrupt */
|
---|
1669 | snd_es1938_mixer_write(chip, 0x66, 0x00);
|
---|
1670 | #ifdef TARGET_OS2
|
---|
1671 | fOurIrq = TRUE;
|
---|
1672 | #endif
|
---|
1673 | }
|
---|
1674 | #ifdef TARGET_OS2
|
---|
1675 | if (fOurIrq) {
|
---|
1676 | eoi_irq(irq);
|
---|
1677 | }
|
---|
1678 | #endif //TARGET_OS2
|
---|
1679 | }
|
---|
1680 |
|
---|
1681 | #define ES1938_DMA_SIZE 64
|
---|
1682 |
|
---|
1683 | static int __init snd_es1938_mixer(snd_pcm_t *pcm)
|
---|
1684 | {
|
---|
1685 | snd_card_t *card;
|
---|
1686 | es1938_t *chip;
|
---|
1687 | int err, idx;
|
---|
1688 | #ifndef TARGET_OS2
|
---|
1689 | snd_assert(pcm != NULL && pcm->card != NULL, return -EINVAL);
|
---|
1690 | #endif
|
---|
1691 | card = pcm->card;
|
---|
1692 | chip = snd_pcm_chip(pcm);
|
---|
1693 |
|
---|
1694 | strcpy(card->mixername, pcm->name);
|
---|
1695 |
|
---|
1696 | for (idx = 0; idx < sizeof(snd_es1938_controls) /
|
---|
1697 | sizeof(snd_es1938_controls[0]); idx++) {
|
---|
1698 | snd_kcontrol_t *kctl;
|
---|
1699 | kctl = snd_ctl_new1(&snd_es1938_controls[idx], chip);
|
---|
1700 | switch (idx) {
|
---|
1701 | case 0:
|
---|
1702 | chip->master_volume = kctl;
|
---|
1703 | kctl->private_free = snd_es1938_hwv_free;
|
---|
1704 | break;
|
---|
1705 | case 1:
|
---|
1706 | chip->master_switch = kctl;
|
---|
1707 | kctl->private_free = snd_es1938_hwv_free;
|
---|
1708 | break;
|
---|
1709 | case 2:
|
---|
1710 | chip->hw_volume = kctl;
|
---|
1711 | kctl->private_free = snd_es1938_hwv_free;
|
---|
1712 | break;
|
---|
1713 | case 3:
|
---|
1714 | chip->hw_switch = kctl;
|
---|
1715 | kctl->private_free = snd_es1938_hwv_free;
|
---|
1716 | break;
|
---|
1717 | }
|
---|
1718 | if ((err = snd_ctl_add(card, kctl)) < 0)
|
---|
1719 | return err;
|
---|
1720 | }
|
---|
1721 | return 0;
|
---|
1722 | }
|
---|
1723 |
|
---|
1724 |
|
---|
1725 | static int __init snd_es1938_probe(struct pci_dev *pci,
|
---|
1726 | const struct pci_device_id *id)
|
---|
1727 | {
|
---|
1728 | static int dev = 0;
|
---|
1729 | snd_card_t *card;
|
---|
1730 | es1938_t *chip;
|
---|
1731 | snd_pcm_t *pcm;
|
---|
1732 | opl3_t *opl3;
|
---|
1733 | int idx, err;
|
---|
1734 |
|
---|
1735 | for ( ; dev < SNDRV_CARDS; dev++) {
|
---|
1736 | if (!snd_enable[dev]) {
|
---|
1737 | dev++;
|
---|
1738 | return -ENOENT;
|
---|
1739 | }
|
---|
1740 | break;
|
---|
1741 | }
|
---|
1742 | if (dev >= SNDRV_CARDS)
|
---|
1743 | return -ENODEV;
|
---|
1744 |
|
---|
1745 | card = snd_card_new(snd_index[dev], snd_id[dev], THIS_MODULE, 0);
|
---|
1746 | if (card == NULL)
|
---|
1747 | return -ENOMEM;
|
---|
1748 | for (idx = 0; idx < 5; idx++) {
|
---|
1749 | if (pci_resource_start(pci, idx) == 0 ||
|
---|
1750 | !(pci_resource_flags(pci, idx) & IORESOURCE_IO)) {
|
---|
1751 | snd_card_free(card);
|
---|
1752 | return -ENODEV;
|
---|
1753 | }
|
---|
1754 | }
|
---|
1755 | if ((err = snd_es1938_create(card, pci,
|
---|
1756 | 64 * 1024,
|
---|
1757 | 64 * 1024,
|
---|
1758 | &chip)) < 0) {
|
---|
1759 | snd_card_free(card);
|
---|
1760 | return err;
|
---|
1761 | }
|
---|
1762 | if ((err = snd_es1938_new_pcm(chip, 0, &pcm)) < 0) {
|
---|
1763 | snd_card_free(card);
|
---|
1764 | return err;
|
---|
1765 | }
|
---|
1766 | if ((err = snd_es1938_mixer(pcm)) < 0) {
|
---|
1767 | snd_card_free(card);
|
---|
1768 | return err;
|
---|
1769 | }
|
---|
1770 | if (snd_opl3_create(card,
|
---|
1771 | SLSB_REG(chip, FMLOWADDR),
|
---|
1772 | SLSB_REG(chip, FMHIGHADDR),
|
---|
1773 | OPL3_HW_OPL3, 1, &opl3) < 0) {
|
---|
1774 | snd_printk("OPL3 not detected at 0x%lx\n",
|
---|
1775 | SLSB_REG(chip, FMLOWADDR));
|
---|
1776 | } else {
|
---|
1777 | if ((err = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
|
---|
1778 | snd_card_free(card);
|
---|
1779 | return err;
|
---|
1780 | }
|
---|
1781 | if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
|
---|
1782 | snd_card_free(card);
|
---|
1783 | return err;
|
---|
1784 | }
|
---|
1785 | }
|
---|
1786 |
|
---|
1787 | strcpy(card->driver, "ES1938");
|
---|
1788 | strcpy(card->shortname, "ESS ES1938 (Solo-1)");
|
---|
1789 | sprintf(card->longname, "%s rev %i, irq %i",
|
---|
1790 | card->shortname,
|
---|
1791 | chip->revision,
|
---|
1792 | chip->irq);
|
---|
1793 |
|
---|
1794 | if ((err = snd_card_register(card)) < 0) {
|
---|
1795 | snd_card_free(card);
|
---|
1796 | return err;
|
---|
1797 | }
|
---|
1798 |
|
---|
1799 | PCI_SET_DRIVER_DATA(pci, card);
|
---|
1800 | dev++;
|
---|
1801 | return 0;
|
---|
1802 | }
|
---|
1803 |
|
---|
1804 | static void __exit snd_es1938_remove(struct pci_dev *pci)
|
---|
1805 | {
|
---|
1806 | snd_card_free(PCI_GET_DRIVER_DATA(pci));
|
---|
1807 | PCI_SET_DRIVER_DATA(pci, NULL);
|
---|
1808 | }
|
---|
1809 |
|
---|
1810 | #ifdef TARGET_OS2
|
---|
1811 | static struct pci_driver driver = {
|
---|
1812 | 0, 0,"ESS ES1938 (Solo-1)",
|
---|
1813 | snd_es1938_ids,
|
---|
1814 | snd_es1938_probe,
|
---|
1815 | snd_es1938_remove,0,0
|
---|
1816 | };
|
---|
1817 | #else
|
---|
1818 | static struct pci_driver driver = {
|
---|
1819 | name: "ESS ES1938 (Solo-1)",
|
---|
1820 | id_table: snd_es1938_ids,
|
---|
1821 | probe: snd_es1938_probe,
|
---|
1822 | remove: snd_es1938_remove,
|
---|
1823 | };
|
---|
1824 | #endif
|
---|
1825 |
|
---|
1826 | static int __init alsa_card_es1938_init(void)
|
---|
1827 | {
|
---|
1828 | int err;
|
---|
1829 |
|
---|
1830 | if ((err = pci_module_init(&driver)) < 0) {
|
---|
1831 | #ifdef MODULE
|
---|
1832 | snd_printk("ESS Solo-1 soundcard not found or device busy\n");
|
---|
1833 | #endif
|
---|
1834 | return err;
|
---|
1835 | }
|
---|
1836 | return 0;
|
---|
1837 | }
|
---|
1838 |
|
---|
1839 | static void __exit alsa_card_es1938_exit(void)
|
---|
1840 | {
|
---|
1841 | pci_unregister_driver(&driver);
|
---|
1842 | }
|
---|
1843 |
|
---|
1844 | module_init(alsa_card_es1938_init)
|
---|
1845 | module_exit(alsa_card_es1938_exit)
|
---|
1846 |
|
---|
1847 | #ifndef MODULE
|
---|
1848 |
|
---|
1849 | /* format is: snd-card-es1938=snd_enable,snd_index,snd_id */
|
---|
1850 |
|
---|
1851 | static int __init alsa_card_es1938_setup(char *str)
|
---|
1852 | {
|
---|
1853 | static unsigned __initdata nr_dev = 0;
|
---|
1854 |
|
---|
1855 | if (nr_dev >= SNDRV_CARDS)
|
---|
1856 | return 0;
|
---|
1857 | (void)(get_option(&str,&snd_enable[nr_dev]) == 2 &&
|
---|
1858 | get_option(&str,&snd_index[nr_dev]) == 2 &&
|
---|
1859 | get_id(&str,&snd_id[nr_dev]) == 2);
|
---|
1860 | nr_dev++;
|
---|
1861 | return 1;
|
---|
1862 | }
|
---|
1863 |
|
---|
1864 | __setup("snd-card-es1938=", alsa_card_es1938_setup);
|
---|
1865 |
|
---|
1866 | #endif /* ifndef MODULE */
|
---|