Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Copyright (c) 2004 James Courtier-Dutton <James@superbug.demon.co.uk> | |
3 | * Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit | |
7199acdc | 4 | * Version: 0.0.23 |
1da177e4 LT |
5 | * |
6 | * FEATURES currently supported: | |
7 | * Front, Rear and Center/LFE. | |
8 | * Surround40 and Surround51. | |
9 | * Capture from MIC an LINE IN input. | |
10 | * SPDIF digital playback of PCM stereo and AC3/DTS works. | |
11 | * (One can use a standard mono mini-jack to one RCA plugs cable. | |
12 | * or one can use a standard stereo mini-jack to two RCA plugs cable. | |
13 | * Plug one of the RCA plugs into the Coax input of the external decoder/receiver.) | |
14 | * ( In theory one could output 3 different AC3 streams at once, to 3 different SPDIF outputs. ) | |
15 | * Notes on how to capture sound: | |
16 | * The AC97 is used in the PLAYBACK direction. | |
17 | * The output from the AC97 chip, instead of reaching the speakers, is fed into the Philips 1361T ADC. | |
18 | * So, to record from the MIC, set the MIC Playback volume to max, | |
19 | * unmute the MIC and turn up the MASTER Playback volume. | |
20 | * So, to prevent feedback when capturing, minimise the "Capture feedback into Playback" volume. | |
21 | * | |
22 | * The only playback controls that currently do anything are: - | |
23 | * Analog Front | |
24 | * Analog Rear | |
25 | * Analog Center/LFE | |
26 | * SPDIF Front | |
27 | * SPDIF Rear | |
28 | * SPDIF Center/LFE | |
29 | * | |
30 | * For capture from Mic in or Line in. | |
31 | * Digital/Analog ( switch must be in Analog mode for CAPTURE. ) | |
32 | * | |
33 | * CAPTURE feedback into PLAYBACK | |
34 | * | |
35 | * Changelog: | |
36 | * Support interrupts per period. | |
37 | * Removed noise from Center/LFE channel when in Analog mode. | |
38 | * Rename and remove mixer controls. | |
39 | * 0.0.6 | |
40 | * Use separate card based DMA buffer for periods table list. | |
41 | * 0.0.7 | |
42 | * Change remove and rename ctrls into lists. | |
43 | * 0.0.8 | |
44 | * Try to fix capture sources. | |
45 | * 0.0.9 | |
46 | * Fix AC3 output. | |
47 | * Enable S32_LE format support. | |
48 | * 0.0.10 | |
49 | * Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".) | |
50 | * 0.0.11 | |
51 | * Add Model name recognition. | |
52 | * 0.0.12 | |
53 | * Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period. | |
54 | * Remove redundent "voice" handling. | |
55 | * 0.0.13 | |
56 | * Single trigger call for multi channels. | |
57 | * 0.0.14 | |
58 | * Set limits based on what the sound card hardware can do. | |
59 | * playback periods_min=2, periods_max=8 | |
60 | * capture hw constraints require period_size = n * 64 bytes. | |
61 | * playback hw constraints require period_size = n * 64 bytes. | |
62 | * 0.0.15 | |
63 | * Minor updates. | |
64 | * 0.0.16 | |
65 | * Implement 192000 sample rate. | |
66 | * 0.0.17 | |
67 | * Add support for SB0410 and SB0413. | |
68 | * 0.0.18 | |
69 | * Modified Copyright message. | |
70 | * 0.0.19 | |
71 | * Finally fix support for SB Live 24 bit. SB0410 and SB0413. | |
72 | * The output codec needs resetting, otherwise all output is muted. | |
73 | * 0.0.20 | |
74 | * Merge "pci_disable_device(pci);" fixes. | |
75 | * 0.0.21 | |
76 | * Add 4 capture channels. (SPDIF only comes in on channel 0. ) | |
77 | * Add SPDIF capture using optional digital I/O module for SB Live 24bit. (Analog capture does not yet work.) | |
78 | * 0.0.22 | |
79 | * Add support for MSI K8N Diamond Motherboard with onboard SB Live 24bit without AC97. From kiksen, bug #901 | |
7199acdc JCD |
80 | * 0.0.23 |
81 | * Implement support for Line-in capture on SB Live 24bit. | |
1da177e4 LT |
82 | * |
83 | * BUGS: | |
84 | * Some stability problems when unloading the snd-ca0106 kernel module. | |
85 | * -- | |
86 | * | |
87 | * TODO: | |
88 | * 4 Capture channels, only one implemented so far. | |
89 | * Other capture rates apart from 48khz not implemented. | |
90 | * MIDI | |
91 | * -- | |
92 | * GENERAL INFO: | |
93 | * Model: SB0310 | |
94 | * P17 Chip: CA0106-DAT | |
95 | * AC97 Codec: STAC 9721 | |
96 | * ADC: Philips 1361T (Stereo 24bit) | |
97 | * DAC: WM8746EDS (6-channel, 24bit, 192Khz) | |
98 | * | |
99 | * GENERAL INFO: | |
100 | * Model: SB0410 | |
101 | * P17 Chip: CA0106-DAT | |
102 | * AC97 Codec: None | |
103 | * ADC: WM8775EDS (4 Channel) | |
104 | * DAC: CS4382 (114 dB, 24-Bit, 192 kHz, 8-Channel D/A Converter with DSD Support) | |
105 | * SPDIF Out control switches between Mic in and SPDIF out. | |
106 | * No sound out or mic input working yet. | |
107 | * | |
108 | * GENERAL INFO: | |
109 | * Model: SB0413 | |
110 | * P17 Chip: CA0106-DAT | |
111 | * AC97 Codec: None. | |
112 | * ADC: Unknown | |
113 | * DAC: Unknown | |
114 | * Trying to handle it like the SB0410. | |
115 | * | |
116 | * This code was initally based on code from ALSA's emu10k1x.c which is: | |
117 | * Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com> | |
118 | * | |
119 | * This program is free software; you can redistribute it and/or modify | |
120 | * it under the terms of the GNU General Public License as published by | |
121 | * the Free Software Foundation; either version 2 of the License, or | |
122 | * (at your option) any later version. | |
123 | * | |
124 | * This program is distributed in the hope that it will be useful, | |
125 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
126 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
127 | * GNU General Public License for more details. | |
128 | * | |
129 | * You should have received a copy of the GNU General Public License | |
130 | * along with this program; if not, write to the Free Software | |
131 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
132 | * | |
133 | */ | |
134 | #include <sound/driver.h> | |
135 | #include <linux/delay.h> | |
136 | #include <linux/init.h> | |
137 | #include <linux/interrupt.h> | |
138 | #include <linux/pci.h> | |
139 | #include <linux/slab.h> | |
140 | #include <linux/moduleparam.h> | |
141 | #include <sound/core.h> | |
142 | #include <sound/initval.h> | |
143 | #include <sound/pcm.h> | |
144 | #include <sound/ac97_codec.h> | |
145 | #include <sound/info.h> | |
146 | ||
147 | MODULE_AUTHOR("James Courtier-Dutton <James@superbug.demon.co.uk>"); | |
148 | MODULE_DESCRIPTION("CA0106"); | |
149 | MODULE_LICENSE("GPL"); | |
150 | MODULE_SUPPORTED_DEVICE("{{Creative,SB CA0106 chip}}"); | |
151 | ||
152 | // module parameters (see "Module Parameters") | |
153 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; | |
154 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; | |
155 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; | |
156 | ||
157 | module_param_array(index, int, NULL, 0444); | |
158 | MODULE_PARM_DESC(index, "Index value for the CA0106 soundcard."); | |
159 | module_param_array(id, charp, NULL, 0444); | |
160 | MODULE_PARM_DESC(id, "ID string for the CA0106 soundcard."); | |
161 | module_param_array(enable, bool, NULL, 0444); | |
162 | MODULE_PARM_DESC(enable, "Enable the CA0106 soundcard."); | |
163 | ||
164 | #include "ca0106.h" | |
165 | ||
1baa705b JCD |
166 | static ca0106_details_t ca0106_chip_details[] = { |
167 | /* AudigyLS[SB0310] */ | |
168 | { .serial = 0x10021102, | |
169 | .name = "AudigyLS [SB0310]", | |
170 | .ac97 = 1 } , | |
171 | /* Unknown AudigyLS that also says SB0310 on it */ | |
172 | { .serial = 0x10051102, | |
173 | .name = "AudigyLS [SB0310b]", | |
174 | .ac97 = 1 } , | |
175 | /* New Sound Blaster Live! 7.1 24bit. This does not have an AC97. 53SB041000001 */ | |
176 | { .serial = 0x10061102, | |
177 | .name = "Live! 7.1 24bit [SB0410]", | |
7199acdc JCD |
178 | .gpio_type = 1, |
179 | .i2c_adc = 1 } , | |
1baa705b JCD |
180 | /* New Dell Sound Blaster Live! 7.1 24bit. This does not have an AC97. */ |
181 | { .serial = 0x10071102, | |
182 | .name = "Live! 7.1 24bit [SB0413]", | |
7199acdc JCD |
183 | .gpio_type = 1, |
184 | .i2c_adc = 1 } , | |
1baa705b JCD |
185 | /* MSI K8N Diamond Motherboard with onboard SB Live 24bit without AC97 */ |
186 | { .serial = 0x10091462, | |
187 | .name = "MSI K8N Diamond MB [SB0438]", | |
7199acdc JCD |
188 | .gpio_type = 1, |
189 | .i2c_adc = 1 } , | |
1baa705b JCD |
190 | { .serial = 0, |
191 | .name = "AudigyLS [Unknown]" } | |
1da177e4 LT |
192 | }; |
193 | ||
194 | /* hardware definition */ | |
195 | static snd_pcm_hardware_t snd_ca0106_playback_hw = { | |
196 | .info = (SNDRV_PCM_INFO_MMAP | | |
197 | SNDRV_PCM_INFO_INTERLEAVED | | |
198 | SNDRV_PCM_INFO_BLOCK_TRANSFER | | |
199 | SNDRV_PCM_INFO_MMAP_VALID), | |
200 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, | |
201 | .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000, | |
202 | .rate_min = 48000, | |
203 | .rate_max = 192000, | |
204 | .channels_min = 2, //1, | |
205 | .channels_max = 2, //6, | |
206 | .buffer_bytes_max = ((65536 - 64) * 8), | |
207 | .period_bytes_min = 64, | |
208 | .period_bytes_max = (65536 - 64), | |
209 | .periods_min = 2, | |
210 | .periods_max = 8, | |
211 | .fifo_size = 0, | |
212 | }; | |
213 | ||
214 | static snd_pcm_hardware_t snd_ca0106_capture_hw = { | |
215 | .info = (SNDRV_PCM_INFO_MMAP | | |
216 | SNDRV_PCM_INFO_INTERLEAVED | | |
217 | SNDRV_PCM_INFO_BLOCK_TRANSFER | | |
218 | SNDRV_PCM_INFO_MMAP_VALID), | |
883130b4 JCD |
219 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, |
220 | .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000, | |
221 | .rate_min = 44100, | |
222 | .rate_max = 192000, | |
1da177e4 LT |
223 | .channels_min = 2, |
224 | .channels_max = 2, | |
225 | .buffer_bytes_max = ((65536 - 64) * 8), | |
226 | .period_bytes_min = 64, | |
227 | .period_bytes_max = (65536 - 64), | |
228 | .periods_min = 2, | |
229 | .periods_max = 2, | |
230 | .fifo_size = 0, | |
231 | }; | |
232 | ||
233 | unsigned int snd_ca0106_ptr_read(ca0106_t * emu, | |
234 | unsigned int reg, | |
235 | unsigned int chn) | |
236 | { | |
237 | unsigned long flags; | |
238 | unsigned int regptr, val; | |
239 | ||
240 | regptr = (reg << 16) | chn; | |
241 | ||
242 | spin_lock_irqsave(&emu->emu_lock, flags); | |
243 | outl(regptr, emu->port + PTR); | |
244 | val = inl(emu->port + DATA); | |
245 | spin_unlock_irqrestore(&emu->emu_lock, flags); | |
246 | return val; | |
247 | } | |
248 | ||
249 | void snd_ca0106_ptr_write(ca0106_t *emu, | |
250 | unsigned int reg, | |
251 | unsigned int chn, | |
252 | unsigned int data) | |
253 | { | |
254 | unsigned int regptr; | |
255 | unsigned long flags; | |
256 | ||
257 | regptr = (reg << 16) | chn; | |
258 | ||
259 | spin_lock_irqsave(&emu->emu_lock, flags); | |
260 | outl(regptr, emu->port + PTR); | |
261 | outl(data, emu->port + DATA); | |
262 | spin_unlock_irqrestore(&emu->emu_lock, flags); | |
263 | } | |
264 | ||
7199acdc JCD |
265 | int snd_ca0106_i2c_write(ca0106_t *emu, |
266 | u32 reg, | |
267 | u32 value) | |
268 | { | |
269 | u32 tmp; | |
270 | int timeout=0; | |
271 | int status; | |
272 | int retry; | |
273 | if ((reg > 0x7f) || (value > 0x1ff)) | |
274 | { | |
275 | snd_printk("i2c_write: invalid values.\n"); | |
276 | return -EINVAL; | |
277 | } | |
278 | ||
279 | tmp = reg << 25 | value << 16; | |
8fabab15 JCD |
280 | /* Not sure what this I2C channel controls. */ |
281 | /* snd_ca0106_ptr_write(emu, I2C_D0, 0, tmp); */ | |
282 | ||
283 | /* This controls the I2C connected to the WM8775 ADC Codec */ | |
7199acdc JCD |
284 | snd_ca0106_ptr_write(emu, I2C_D1, 0, tmp); |
285 | ||
286 | for(retry=0;retry<10;retry++) | |
287 | { | |
288 | /* Send the data to i2c */ | |
289 | tmp = snd_ca0106_ptr_read(emu, I2C_A, 0); | |
290 | tmp = tmp & ~(I2C_A_ADC_READ|I2C_A_ADC_LAST|I2C_A_ADC_START|I2C_A_ADC_ADD_MASK); | |
291 | tmp = tmp | (I2C_A_ADC_LAST|I2C_A_ADC_START|I2C_A_ADC_ADD); | |
292 | snd_ca0106_ptr_write(emu, I2C_A, 0, tmp); | |
293 | ||
294 | /* Wait till the transaction ends */ | |
295 | while(1) | |
296 | { | |
297 | status = snd_ca0106_ptr_read(emu, I2C_A, 0); | |
298 | //snd_printk("I2C:status=0x%x\n", status); | |
299 | timeout++; | |
300 | if((status & I2C_A_ADC_START)==0) | |
301 | break; | |
302 | ||
303 | if(timeout>1000) | |
304 | break; | |
305 | } | |
306 | //Read back and see if the transaction is successful | |
307 | if((status & I2C_A_ADC_ABORT)==0) | |
308 | break; | |
309 | } | |
310 | ||
311 | if(retry==10) | |
312 | { | |
313 | snd_printk("Writing to ADC failed!\n"); | |
314 | return -EINVAL; | |
315 | } | |
316 | ||
317 | return 0; | |
318 | } | |
319 | ||
320 | ||
1da177e4 LT |
321 | static void snd_ca0106_intr_enable(ca0106_t *emu, unsigned int intrenb) |
322 | { | |
323 | unsigned long flags; | |
324 | unsigned int enable; | |
325 | ||
326 | spin_lock_irqsave(&emu->emu_lock, flags); | |
327 | enable = inl(emu->port + INTE) | intrenb; | |
328 | outl(enable, emu->port + INTE); | |
329 | spin_unlock_irqrestore(&emu->emu_lock, flags); | |
330 | } | |
331 | ||
332 | static void snd_ca0106_pcm_free_substream(snd_pcm_runtime_t *runtime) | |
333 | { | |
334 | ca0106_pcm_t *epcm = runtime->private_data; | |
335 | ||
336 | if (epcm) { | |
337 | kfree(epcm); | |
338 | } | |
339 | } | |
340 | ||
341 | /* open_playback callback */ | |
342 | static int snd_ca0106_pcm_open_playback_channel(snd_pcm_substream_t *substream, int channel_id) | |
343 | { | |
344 | ca0106_t *chip = snd_pcm_substream_chip(substream); | |
345 | ca0106_channel_t *channel = &(chip->playback_channels[channel_id]); | |
346 | ca0106_pcm_t *epcm; | |
347 | snd_pcm_runtime_t *runtime = substream->runtime; | |
348 | int err; | |
349 | ||
350 | epcm = kcalloc(1, sizeof(*epcm), GFP_KERNEL); | |
351 | ||
352 | if (epcm == NULL) | |
353 | return -ENOMEM; | |
354 | epcm->emu = chip; | |
355 | epcm->substream = substream; | |
356 | epcm->channel_id=channel_id; | |
357 | ||
358 | runtime->private_data = epcm; | |
359 | runtime->private_free = snd_ca0106_pcm_free_substream; | |
360 | ||
361 | runtime->hw = snd_ca0106_playback_hw; | |
362 | ||
363 | channel->emu = chip; | |
364 | channel->number = channel_id; | |
365 | ||
366 | channel->use=1; | |
367 | //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel); | |
368 | //channel->interrupt = snd_ca0106_pcm_channel_interrupt; | |
369 | channel->epcm=epcm; | |
370 | if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) | |
371 | return err; | |
372 | if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0) | |
373 | return err; | |
374 | return 0; | |
375 | } | |
376 | ||
377 | /* close callback */ | |
378 | static int snd_ca0106_pcm_close_playback(snd_pcm_substream_t *substream) | |
379 | { | |
380 | ca0106_t *chip = snd_pcm_substream_chip(substream); | |
381 | snd_pcm_runtime_t *runtime = substream->runtime; | |
382 | ca0106_pcm_t *epcm = runtime->private_data; | |
383 | chip->playback_channels[epcm->channel_id].use=0; | |
384 | /* FIXME: maybe zero others */ | |
385 | return 0; | |
386 | } | |
387 | ||
388 | static int snd_ca0106_pcm_open_playback_front(snd_pcm_substream_t *substream) | |
389 | { | |
390 | return snd_ca0106_pcm_open_playback_channel(substream, PCM_FRONT_CHANNEL); | |
391 | } | |
392 | ||
393 | static int snd_ca0106_pcm_open_playback_center_lfe(snd_pcm_substream_t *substream) | |
394 | { | |
395 | return snd_ca0106_pcm_open_playback_channel(substream, PCM_CENTER_LFE_CHANNEL); | |
396 | } | |
397 | ||
398 | static int snd_ca0106_pcm_open_playback_unknown(snd_pcm_substream_t *substream) | |
399 | { | |
400 | return snd_ca0106_pcm_open_playback_channel(substream, PCM_UNKNOWN_CHANNEL); | |
401 | } | |
402 | ||
403 | static int snd_ca0106_pcm_open_playback_rear(snd_pcm_substream_t *substream) | |
404 | { | |
405 | return snd_ca0106_pcm_open_playback_channel(substream, PCM_REAR_CHANNEL); | |
406 | } | |
407 | ||
408 | /* open_capture callback */ | |
409 | static int snd_ca0106_pcm_open_capture_channel(snd_pcm_substream_t *substream, int channel_id) | |
410 | { | |
411 | ca0106_t *chip = snd_pcm_substream_chip(substream); | |
412 | ca0106_channel_t *channel = &(chip->capture_channels[channel_id]); | |
413 | ca0106_pcm_t *epcm; | |
414 | snd_pcm_runtime_t *runtime = substream->runtime; | |
415 | int err; | |
416 | ||
417 | epcm = kcalloc(1, sizeof(*epcm), GFP_KERNEL); | |
418 | if (epcm == NULL) { | |
419 | snd_printk("open_capture_channel: failed epcm alloc\n"); | |
420 | return -ENOMEM; | |
421 | } | |
422 | epcm->emu = chip; | |
423 | epcm->substream = substream; | |
424 | epcm->channel_id=channel_id; | |
425 | ||
426 | runtime->private_data = epcm; | |
427 | runtime->private_free = snd_ca0106_pcm_free_substream; | |
428 | ||
429 | runtime->hw = snd_ca0106_capture_hw; | |
430 | ||
431 | channel->emu = chip; | |
432 | channel->number = channel_id; | |
433 | ||
434 | channel->use=1; | |
435 | //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel); | |
436 | //channel->interrupt = snd_ca0106_pcm_channel_interrupt; | |
437 | channel->epcm=epcm; | |
438 | if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) | |
439 | return err; | |
440 | //snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hw_constraints_capture_period_sizes); | |
441 | if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0) | |
442 | return err; | |
443 | return 0; | |
444 | } | |
445 | ||
446 | /* close callback */ | |
447 | static int snd_ca0106_pcm_close_capture(snd_pcm_substream_t *substream) | |
448 | { | |
449 | ca0106_t *chip = snd_pcm_substream_chip(substream); | |
450 | snd_pcm_runtime_t *runtime = substream->runtime; | |
451 | ca0106_pcm_t *epcm = runtime->private_data; | |
452 | chip->capture_channels[epcm->channel_id].use=0; | |
453 | /* FIXME: maybe zero others */ | |
454 | return 0; | |
455 | } | |
456 | ||
457 | static int snd_ca0106_pcm_open_0_capture(snd_pcm_substream_t *substream) | |
458 | { | |
459 | return snd_ca0106_pcm_open_capture_channel(substream, 0); | |
460 | } | |
461 | ||
462 | static int snd_ca0106_pcm_open_1_capture(snd_pcm_substream_t *substream) | |
463 | { | |
464 | return snd_ca0106_pcm_open_capture_channel(substream, 1); | |
465 | } | |
466 | ||
467 | static int snd_ca0106_pcm_open_2_capture(snd_pcm_substream_t *substream) | |
468 | { | |
469 | return snd_ca0106_pcm_open_capture_channel(substream, 2); | |
470 | } | |
471 | ||
472 | static int snd_ca0106_pcm_open_3_capture(snd_pcm_substream_t *substream) | |
473 | { | |
474 | return snd_ca0106_pcm_open_capture_channel(substream, 3); | |
475 | } | |
476 | ||
477 | /* hw_params callback */ | |
478 | static int snd_ca0106_pcm_hw_params_playback(snd_pcm_substream_t *substream, | |
479 | snd_pcm_hw_params_t * hw_params) | |
480 | { | |
481 | return snd_pcm_lib_malloc_pages(substream, | |
482 | params_buffer_bytes(hw_params)); | |
483 | } | |
484 | ||
485 | /* hw_free callback */ | |
486 | static int snd_ca0106_pcm_hw_free_playback(snd_pcm_substream_t *substream) | |
487 | { | |
488 | return snd_pcm_lib_free_pages(substream); | |
489 | } | |
490 | ||
491 | /* hw_params callback */ | |
492 | static int snd_ca0106_pcm_hw_params_capture(snd_pcm_substream_t *substream, | |
493 | snd_pcm_hw_params_t * hw_params) | |
494 | { | |
495 | return snd_pcm_lib_malloc_pages(substream, | |
496 | params_buffer_bytes(hw_params)); | |
497 | } | |
498 | ||
499 | /* hw_free callback */ | |
500 | static int snd_ca0106_pcm_hw_free_capture(snd_pcm_substream_t *substream) | |
501 | { | |
502 | return snd_pcm_lib_free_pages(substream); | |
503 | } | |
504 | ||
505 | /* prepare playback callback */ | |
506 | static int snd_ca0106_pcm_prepare_playback(snd_pcm_substream_t *substream) | |
507 | { | |
508 | ca0106_t *emu = snd_pcm_substream_chip(substream); | |
509 | snd_pcm_runtime_t *runtime = substream->runtime; | |
510 | ca0106_pcm_t *epcm = runtime->private_data; | |
511 | int channel = epcm->channel_id; | |
512 | u32 *table_base = (u32 *)(emu->buffer.area+(8*16*channel)); | |
513 | u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size); | |
514 | u32 hcfg_mask = HCFG_PLAYBACK_S32_LE; | |
515 | u32 hcfg_set = 0x00000000; | |
516 | u32 hcfg; | |
517 | u32 reg40_mask = 0x30000 << (channel<<1); | |
518 | u32 reg40_set = 0; | |
519 | u32 reg40; | |
520 | /* FIXME: Depending on mixer selection of SPDIF out or not, select the spdif rate or the DAC rate. */ | |
521 | u32 reg71_mask = 0x03030000 ; /* Global. Set SPDIF rate. We only support 44100 to spdif, not to DAC. */ | |
522 | u32 reg71_set = 0; | |
523 | u32 reg71; | |
524 | int i; | |
525 | ||
526 | //snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1)); | |
527 | //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base); | |
528 | //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes); | |
529 | /* Rate can be set per channel. */ | |
530 | /* reg40 control host to fifo */ | |
531 | /* reg71 controls DAC rate. */ | |
532 | switch (runtime->rate) { | |
533 | case 44100: | |
534 | reg40_set = 0x10000 << (channel<<1); | |
535 | reg71_set = 0x01010000; | |
536 | break; | |
537 | case 48000: | |
538 | reg40_set = 0; | |
539 | reg71_set = 0; | |
540 | break; | |
541 | case 96000: | |
542 | reg40_set = 0x20000 << (channel<<1); | |
543 | reg71_set = 0x02020000; | |
544 | break; | |
545 | case 192000: | |
546 | reg40_set = 0x30000 << (channel<<1); | |
547 | reg71_set = 0x03030000; | |
548 | break; | |
549 | default: | |
550 | reg40_set = 0; | |
551 | reg71_set = 0; | |
552 | break; | |
553 | } | |
554 | /* Format is a global setting */ | |
555 | /* FIXME: Only let the first channel accessed set this. */ | |
556 | switch (runtime->format) { | |
557 | case SNDRV_PCM_FORMAT_S16_LE: | |
558 | hcfg_set = 0; | |
559 | break; | |
560 | case SNDRV_PCM_FORMAT_S32_LE: | |
561 | hcfg_set = HCFG_PLAYBACK_S32_LE; | |
562 | break; | |
563 | default: | |
564 | hcfg_set = 0; | |
565 | break; | |
566 | } | |
567 | hcfg = inl(emu->port + HCFG) ; | |
568 | hcfg = (hcfg & ~hcfg_mask) | hcfg_set; | |
569 | outl(hcfg, emu->port + HCFG); | |
570 | reg40 = snd_ca0106_ptr_read(emu, 0x40, 0); | |
571 | reg40 = (reg40 & ~reg40_mask) | reg40_set; | |
572 | snd_ca0106_ptr_write(emu, 0x40, 0, reg40); | |
573 | reg71 = snd_ca0106_ptr_read(emu, 0x71, 0); | |
574 | reg71 = (reg71 & ~reg71_mask) | reg71_set; | |
575 | snd_ca0106_ptr_write(emu, 0x71, 0, reg71); | |
576 | ||
577 | /* FIXME: Check emu->buffer.size before actually writing to it. */ | |
578 | for(i=0; i < runtime->periods; i++) { | |
579 | table_base[i*2]=runtime->dma_addr+(i*period_size_bytes); | |
580 | table_base[(i*2)+1]=period_size_bytes<<16; | |
581 | } | |
582 | ||
583 | snd_ca0106_ptr_write(emu, PLAYBACK_LIST_ADDR, channel, emu->buffer.addr+(8*16*channel)); | |
584 | snd_ca0106_ptr_write(emu, PLAYBACK_LIST_SIZE, channel, (runtime->periods - 1) << 19); | |
585 | snd_ca0106_ptr_write(emu, PLAYBACK_LIST_PTR, channel, 0); | |
586 | snd_ca0106_ptr_write(emu, PLAYBACK_DMA_ADDR, channel, runtime->dma_addr); | |
587 | snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, frames_to_bytes(runtime, runtime->period_size)<<16); // buffer size in bytes | |
588 | /* FIXME test what 0 bytes does. */ | |
589 | snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, 0); // buffer size in bytes | |
590 | snd_ca0106_ptr_write(emu, PLAYBACK_POINTER, channel, 0); | |
591 | snd_ca0106_ptr_write(emu, 0x07, channel, 0x0); | |
592 | snd_ca0106_ptr_write(emu, 0x08, channel, 0); | |
593 | snd_ca0106_ptr_write(emu, PLAYBACK_MUTE, 0x0, 0x0); /* Unmute output */ | |
594 | #if 0 | |
595 | snd_ca0106_ptr_write(emu, SPCS0, 0, | |
596 | SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | | |
597 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | | |
598 | SPCS_GENERATIONSTATUS | 0x00001200 | | |
599 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT ); | |
600 | } | |
601 | #endif | |
602 | ||
603 | return 0; | |
604 | } | |
605 | ||
606 | /* prepare capture callback */ | |
607 | static int snd_ca0106_pcm_prepare_capture(snd_pcm_substream_t *substream) | |
608 | { | |
609 | ca0106_t *emu = snd_pcm_substream_chip(substream); | |
610 | snd_pcm_runtime_t *runtime = substream->runtime; | |
611 | ca0106_pcm_t *epcm = runtime->private_data; | |
612 | int channel = epcm->channel_id; | |
883130b4 JCD |
613 | u32 hcfg_mask = HCFG_CAPTURE_S32_LE; |
614 | u32 hcfg_set = 0x00000000; | |
615 | u32 hcfg; | |
616 | u32 over_sampling=0x2; | |
617 | u32 reg71_mask = 0x0000c000 ; /* Global. Set ADC rate. */ | |
618 | u32 reg71_set = 0; | |
619 | u32 reg71; | |
620 | ||
621 | //snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1)); | |
622 | //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base); | |
623 | //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes); | |
624 | /* reg71 controls ADC rate. */ | |
625 | switch (runtime->rate) { | |
626 | case 44100: | |
627 | reg71_set = 0x00004000; | |
628 | break; | |
629 | case 48000: | |
630 | reg71_set = 0; | |
631 | break; | |
632 | case 96000: | |
633 | reg71_set = 0x00008000; | |
634 | over_sampling=0xa; | |
635 | break; | |
636 | case 192000: | |
637 | reg71_set = 0x0000c000; | |
638 | over_sampling=0xa; | |
639 | break; | |
640 | default: | |
641 | reg71_set = 0; | |
642 | break; | |
643 | } | |
644 | /* Format is a global setting */ | |
645 | /* FIXME: Only let the first channel accessed set this. */ | |
646 | switch (runtime->format) { | |
647 | case SNDRV_PCM_FORMAT_S16_LE: | |
648 | hcfg_set = 0; | |
649 | break; | |
650 | case SNDRV_PCM_FORMAT_S32_LE: | |
651 | hcfg_set = HCFG_CAPTURE_S32_LE; | |
652 | break; | |
653 | default: | |
654 | hcfg_set = 0; | |
655 | break; | |
656 | } | |
657 | hcfg = inl(emu->port + HCFG) ; | |
658 | hcfg = (hcfg & ~hcfg_mask) | hcfg_set; | |
659 | outl(hcfg, emu->port + HCFG); | |
660 | reg71 = snd_ca0106_ptr_read(emu, 0x71, 0); | |
661 | reg71 = (reg71 & ~reg71_mask) | reg71_set; | |
662 | snd_ca0106_ptr_write(emu, 0x71, 0, reg71); | |
663 | if (emu->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */ | |
664 | snd_ca0106_i2c_write(emu, ADC_MASTER, over_sampling); /* Adjust the over sampler to better suit the capture rate. */ | |
665 | } | |
666 | ||
667 | ||
1da177e4 LT |
668 | //printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, frames_to_bytes(runtime, 1)); |
669 | snd_ca0106_ptr_write(emu, 0x13, channel, 0); | |
670 | snd_ca0106_ptr_write(emu, CAPTURE_DMA_ADDR, channel, runtime->dma_addr); | |
671 | snd_ca0106_ptr_write(emu, CAPTURE_BUFFER_SIZE, channel, frames_to_bytes(runtime, runtime->buffer_size)<<16); // buffer size in bytes | |
672 | snd_ca0106_ptr_write(emu, CAPTURE_POINTER, channel, 0); | |
673 | ||
674 | return 0; | |
675 | } | |
676 | ||
677 | /* trigger_playback callback */ | |
678 | static int snd_ca0106_pcm_trigger_playback(snd_pcm_substream_t *substream, | |
679 | int cmd) | |
680 | { | |
681 | ca0106_t *emu = snd_pcm_substream_chip(substream); | |
682 | snd_pcm_runtime_t *runtime; | |
683 | ca0106_pcm_t *epcm; | |
684 | int channel; | |
685 | int result = 0; | |
686 | struct list_head *pos; | |
687 | snd_pcm_substream_t *s; | |
688 | u32 basic = 0; | |
689 | u32 extended = 0; | |
690 | int running=0; | |
691 | ||
692 | switch (cmd) { | |
693 | case SNDRV_PCM_TRIGGER_START: | |
694 | running=1; | |
695 | break; | |
696 | case SNDRV_PCM_TRIGGER_STOP: | |
697 | default: | |
698 | running=0; | |
699 | break; | |
700 | } | |
701 | snd_pcm_group_for_each(pos, substream) { | |
702 | s = snd_pcm_group_substream_entry(pos); | |
703 | runtime = s->runtime; | |
704 | epcm = runtime->private_data; | |
705 | channel = epcm->channel_id; | |
706 | //snd_printk("channel=%d\n",channel); | |
707 | epcm->running = running; | |
708 | basic |= (0x1<<channel); | |
709 | extended |= (0x10<<channel); | |
710 | snd_pcm_trigger_done(s, substream); | |
711 | } | |
712 | //snd_printk("basic=0x%x, extended=0x%x\n",basic, extended); | |
713 | ||
714 | switch (cmd) { | |
715 | case SNDRV_PCM_TRIGGER_START: | |
716 | snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) | (extended)); | |
717 | snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0)|(basic)); | |
718 | break; | |
719 | case SNDRV_PCM_TRIGGER_STOP: | |
720 | snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0) & ~(basic)); | |
721 | snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) & ~(extended)); | |
722 | break; | |
723 | default: | |
724 | result = -EINVAL; | |
725 | break; | |
726 | } | |
727 | return result; | |
728 | } | |
729 | ||
730 | /* trigger_capture callback */ | |
731 | static int snd_ca0106_pcm_trigger_capture(snd_pcm_substream_t *substream, | |
732 | int cmd) | |
733 | { | |
734 | ca0106_t *emu = snd_pcm_substream_chip(substream); | |
735 | snd_pcm_runtime_t *runtime = substream->runtime; | |
736 | ca0106_pcm_t *epcm = runtime->private_data; | |
737 | int channel = epcm->channel_id; | |
738 | int result = 0; | |
739 | ||
740 | switch (cmd) { | |
741 | case SNDRV_PCM_TRIGGER_START: | |
742 | snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) | (0x110000<<channel)); | |
743 | snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0)|(0x100<<channel)); | |
744 | epcm->running = 1; | |
745 | break; | |
746 | case SNDRV_PCM_TRIGGER_STOP: | |
747 | snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0) & ~(0x100<<channel)); | |
748 | snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) & ~(0x110000<<channel)); | |
749 | epcm->running = 0; | |
750 | break; | |
751 | default: | |
752 | result = -EINVAL; | |
753 | break; | |
754 | } | |
755 | return result; | |
756 | } | |
757 | ||
758 | /* pointer_playback callback */ | |
759 | static snd_pcm_uframes_t | |
760 | snd_ca0106_pcm_pointer_playback(snd_pcm_substream_t *substream) | |
761 | { | |
762 | ca0106_t *emu = snd_pcm_substream_chip(substream); | |
763 | snd_pcm_runtime_t *runtime = substream->runtime; | |
764 | ca0106_pcm_t *epcm = runtime->private_data; | |
765 | snd_pcm_uframes_t ptr, ptr1, ptr2,ptr3,ptr4 = 0; | |
766 | int channel = epcm->channel_id; | |
767 | ||
768 | if (!epcm->running) | |
769 | return 0; | |
770 | ||
771 | ptr3 = snd_ca0106_ptr_read(emu, PLAYBACK_LIST_PTR, channel); | |
772 | ptr1 = snd_ca0106_ptr_read(emu, PLAYBACK_POINTER, channel); | |
773 | ptr4 = snd_ca0106_ptr_read(emu, PLAYBACK_LIST_PTR, channel); | |
774 | if (ptr3 != ptr4) ptr1 = snd_ca0106_ptr_read(emu, PLAYBACK_POINTER, channel); | |
775 | ptr2 = bytes_to_frames(runtime, ptr1); | |
776 | ptr2+= (ptr4 >> 3) * runtime->period_size; | |
777 | ptr=ptr2; | |
778 | if (ptr >= runtime->buffer_size) | |
779 | ptr -= runtime->buffer_size; | |
780 | //printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate); | |
781 | ||
782 | return ptr; | |
783 | } | |
784 | ||
785 | /* pointer_capture callback */ | |
786 | static snd_pcm_uframes_t | |
787 | snd_ca0106_pcm_pointer_capture(snd_pcm_substream_t *substream) | |
788 | { | |
789 | ca0106_t *emu = snd_pcm_substream_chip(substream); | |
790 | snd_pcm_runtime_t *runtime = substream->runtime; | |
791 | ca0106_pcm_t *epcm = runtime->private_data; | |
792 | snd_pcm_uframes_t ptr, ptr1, ptr2 = 0; | |
793 | int channel = channel=epcm->channel_id; | |
794 | ||
795 | if (!epcm->running) | |
796 | return 0; | |
797 | ||
798 | ptr1 = snd_ca0106_ptr_read(emu, CAPTURE_POINTER, channel); | |
799 | ptr2 = bytes_to_frames(runtime, ptr1); | |
800 | ptr=ptr2; | |
801 | if (ptr >= runtime->buffer_size) | |
802 | ptr -= runtime->buffer_size; | |
803 | //printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate); | |
804 | ||
805 | return ptr; | |
806 | } | |
807 | ||
808 | /* operators */ | |
809 | static snd_pcm_ops_t snd_ca0106_playback_front_ops = { | |
810 | .open = snd_ca0106_pcm_open_playback_front, | |
811 | .close = snd_ca0106_pcm_close_playback, | |
812 | .ioctl = snd_pcm_lib_ioctl, | |
813 | .hw_params = snd_ca0106_pcm_hw_params_playback, | |
814 | .hw_free = snd_ca0106_pcm_hw_free_playback, | |
815 | .prepare = snd_ca0106_pcm_prepare_playback, | |
816 | .trigger = snd_ca0106_pcm_trigger_playback, | |
817 | .pointer = snd_ca0106_pcm_pointer_playback, | |
818 | }; | |
819 | ||
820 | static snd_pcm_ops_t snd_ca0106_capture_0_ops = { | |
821 | .open = snd_ca0106_pcm_open_0_capture, | |
822 | .close = snd_ca0106_pcm_close_capture, | |
823 | .ioctl = snd_pcm_lib_ioctl, | |
824 | .hw_params = snd_ca0106_pcm_hw_params_capture, | |
825 | .hw_free = snd_ca0106_pcm_hw_free_capture, | |
826 | .prepare = snd_ca0106_pcm_prepare_capture, | |
827 | .trigger = snd_ca0106_pcm_trigger_capture, | |
828 | .pointer = snd_ca0106_pcm_pointer_capture, | |
829 | }; | |
830 | ||
831 | static snd_pcm_ops_t snd_ca0106_capture_1_ops = { | |
832 | .open = snd_ca0106_pcm_open_1_capture, | |
833 | .close = snd_ca0106_pcm_close_capture, | |
834 | .ioctl = snd_pcm_lib_ioctl, | |
835 | .hw_params = snd_ca0106_pcm_hw_params_capture, | |
836 | .hw_free = snd_ca0106_pcm_hw_free_capture, | |
837 | .prepare = snd_ca0106_pcm_prepare_capture, | |
838 | .trigger = snd_ca0106_pcm_trigger_capture, | |
839 | .pointer = snd_ca0106_pcm_pointer_capture, | |
840 | }; | |
841 | ||
842 | static snd_pcm_ops_t snd_ca0106_capture_2_ops = { | |
843 | .open = snd_ca0106_pcm_open_2_capture, | |
844 | .close = snd_ca0106_pcm_close_capture, | |
845 | .ioctl = snd_pcm_lib_ioctl, | |
846 | .hw_params = snd_ca0106_pcm_hw_params_capture, | |
847 | .hw_free = snd_ca0106_pcm_hw_free_capture, | |
848 | .prepare = snd_ca0106_pcm_prepare_capture, | |
849 | .trigger = snd_ca0106_pcm_trigger_capture, | |
850 | .pointer = snd_ca0106_pcm_pointer_capture, | |
851 | }; | |
852 | ||
853 | static snd_pcm_ops_t snd_ca0106_capture_3_ops = { | |
854 | .open = snd_ca0106_pcm_open_3_capture, | |
855 | .close = snd_ca0106_pcm_close_capture, | |
856 | .ioctl = snd_pcm_lib_ioctl, | |
857 | .hw_params = snd_ca0106_pcm_hw_params_capture, | |
858 | .hw_free = snd_ca0106_pcm_hw_free_capture, | |
859 | .prepare = snd_ca0106_pcm_prepare_capture, | |
860 | .trigger = snd_ca0106_pcm_trigger_capture, | |
861 | .pointer = snd_ca0106_pcm_pointer_capture, | |
862 | }; | |
863 | ||
864 | static snd_pcm_ops_t snd_ca0106_playback_center_lfe_ops = { | |
865 | .open = snd_ca0106_pcm_open_playback_center_lfe, | |
866 | .close = snd_ca0106_pcm_close_playback, | |
867 | .ioctl = snd_pcm_lib_ioctl, | |
868 | .hw_params = snd_ca0106_pcm_hw_params_playback, | |
869 | .hw_free = snd_ca0106_pcm_hw_free_playback, | |
870 | .prepare = snd_ca0106_pcm_prepare_playback, | |
871 | .trigger = snd_ca0106_pcm_trigger_playback, | |
872 | .pointer = snd_ca0106_pcm_pointer_playback, | |
873 | }; | |
874 | ||
875 | static snd_pcm_ops_t snd_ca0106_playback_unknown_ops = { | |
876 | .open = snd_ca0106_pcm_open_playback_unknown, | |
877 | .close = snd_ca0106_pcm_close_playback, | |
878 | .ioctl = snd_pcm_lib_ioctl, | |
879 | .hw_params = snd_ca0106_pcm_hw_params_playback, | |
880 | .hw_free = snd_ca0106_pcm_hw_free_playback, | |
881 | .prepare = snd_ca0106_pcm_prepare_playback, | |
882 | .trigger = snd_ca0106_pcm_trigger_playback, | |
883 | .pointer = snd_ca0106_pcm_pointer_playback, | |
884 | }; | |
885 | ||
886 | static snd_pcm_ops_t snd_ca0106_playback_rear_ops = { | |
887 | .open = snd_ca0106_pcm_open_playback_rear, | |
888 | .close = snd_ca0106_pcm_close_playback, | |
889 | .ioctl = snd_pcm_lib_ioctl, | |
890 | .hw_params = snd_ca0106_pcm_hw_params_playback, | |
891 | .hw_free = snd_ca0106_pcm_hw_free_playback, | |
892 | .prepare = snd_ca0106_pcm_prepare_playback, | |
893 | .trigger = snd_ca0106_pcm_trigger_playback, | |
894 | .pointer = snd_ca0106_pcm_pointer_playback, | |
895 | }; | |
896 | ||
897 | ||
898 | static unsigned short snd_ca0106_ac97_read(ac97_t *ac97, | |
899 | unsigned short reg) | |
900 | { | |
901 | ca0106_t *emu = ac97->private_data; | |
902 | unsigned long flags; | |
903 | unsigned short val; | |
904 | ||
905 | spin_lock_irqsave(&emu->emu_lock, flags); | |
906 | outb(reg, emu->port + AC97ADDRESS); | |
907 | val = inw(emu->port + AC97DATA); | |
908 | spin_unlock_irqrestore(&emu->emu_lock, flags); | |
909 | return val; | |
910 | } | |
911 | ||
912 | static void snd_ca0106_ac97_write(ac97_t *ac97, | |
913 | unsigned short reg, unsigned short val) | |
914 | { | |
915 | ca0106_t *emu = ac97->private_data; | |
916 | unsigned long flags; | |
917 | ||
918 | spin_lock_irqsave(&emu->emu_lock, flags); | |
919 | outb(reg, emu->port + AC97ADDRESS); | |
920 | outw(val, emu->port + AC97DATA); | |
921 | spin_unlock_irqrestore(&emu->emu_lock, flags); | |
922 | } | |
923 | ||
924 | static int snd_ca0106_ac97(ca0106_t *chip) | |
925 | { | |
926 | ac97_bus_t *pbus; | |
927 | ac97_template_t ac97; | |
928 | int err; | |
929 | static ac97_bus_ops_t ops = { | |
930 | .write = snd_ca0106_ac97_write, | |
931 | .read = snd_ca0106_ac97_read, | |
932 | }; | |
933 | ||
934 | if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0) | |
935 | return err; | |
936 | pbus->no_vra = 1; /* we don't need VRA */ | |
937 | ||
938 | memset(&ac97, 0, sizeof(ac97)); | |
939 | ac97.private_data = chip; | |
36c4dc42 | 940 | ac97.scaps = AC97_SCAP_NO_SPDIF; |
1da177e4 LT |
941 | return snd_ac97_mixer(pbus, &ac97, &chip->ac97); |
942 | } | |
943 | ||
944 | static int snd_ca0106_free(ca0106_t *chip) | |
945 | { | |
946 | if (chip->res_port != NULL) { /* avoid access to already used hardware */ | |
947 | // disable interrupts | |
948 | snd_ca0106_ptr_write(chip, BASIC_INTERRUPT, 0, 0); | |
949 | outl(0, chip->port + INTE); | |
950 | snd_ca0106_ptr_write(chip, EXTENDED_INT_MASK, 0, 0); | |
951 | udelay(1000); | |
952 | // disable audio | |
953 | //outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG); | |
954 | outl(0, chip->port + HCFG); | |
955 | /* FIXME: We need to stop and DMA transfers here. | |
956 | * But as I am not sure how yet, we cannot from the dma pages. | |
957 | * So we can fix: snd-malloc: Memory leak? pages not freed = 8 | |
958 | */ | |
959 | } | |
960 | // release the data | |
961 | #if 1 | |
962 | if (chip->buffer.area) | |
963 | snd_dma_free_pages(&chip->buffer); | |
964 | #endif | |
965 | ||
966 | // release the i/o port | |
967 | if (chip->res_port) { | |
968 | release_resource(chip->res_port); | |
969 | kfree_nocheck(chip->res_port); | |
970 | } | |
971 | // release the irq | |
972 | if (chip->irq >= 0) | |
973 | free_irq(chip->irq, (void *)chip); | |
974 | pci_disable_device(chip->pci); | |
975 | kfree(chip); | |
976 | return 0; | |
977 | } | |
978 | ||
979 | static int snd_ca0106_dev_free(snd_device_t *device) | |
980 | { | |
981 | ca0106_t *chip = device->device_data; | |
982 | return snd_ca0106_free(chip); | |
983 | } | |
984 | ||
985 | static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id, | |
986 | struct pt_regs *regs) | |
987 | { | |
988 | unsigned int status; | |
989 | ||
990 | ca0106_t *chip = dev_id; | |
991 | int i; | |
992 | int mask; | |
993 | unsigned int stat76; | |
994 | ca0106_channel_t *pchannel; | |
995 | ||
996 | spin_lock(&chip->emu_lock); | |
997 | ||
998 | status = inl(chip->port + IPR); | |
999 | ||
1000 | // call updater, unlock before it | |
1001 | spin_unlock(&chip->emu_lock); | |
1002 | ||
1003 | if (! status) | |
1004 | return IRQ_NONE; | |
1005 | ||
1006 | stat76 = snd_ca0106_ptr_read(chip, EXTENDED_INT, 0); | |
1007 | //snd_printk("interrupt status = 0x%08x, stat76=0x%08x\n", status, stat76); | |
1008 | //snd_printk("ptr=0x%08x\n",snd_ca0106_ptr_read(chip, PLAYBACK_POINTER, 0)); | |
1009 | mask = 0x11; /* 0x1 for one half, 0x10 for the other half period. */ | |
1010 | for(i = 0; i < 4; i++) { | |
1011 | pchannel = &(chip->playback_channels[i]); | |
1012 | if(stat76 & mask) { | |
1013 | /* FIXME: Select the correct substream for period elapsed */ | |
1014 | if(pchannel->use) { | |
1015 | snd_pcm_period_elapsed(pchannel->epcm->substream); | |
1016 | //printk(KERN_INFO "interrupt [%d] used\n", i); | |
1017 | } | |
1018 | } | |
1019 | //printk(KERN_INFO "channel=%p\n",pchannel); | |
1020 | //printk(KERN_INFO "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number); | |
1021 | mask <<= 1; | |
1022 | } | |
1023 | mask = 0x110000; /* 0x1 for one half, 0x10 for the other half period. */ | |
1024 | for(i = 0; i < 4; i++) { | |
1025 | pchannel = &(chip->capture_channels[i]); | |
1026 | if(stat76 & mask) { | |
1027 | /* FIXME: Select the correct substream for period elapsed */ | |
1028 | if(pchannel->use) { | |
1029 | snd_pcm_period_elapsed(pchannel->epcm->substream); | |
1030 | //printk(KERN_INFO "interrupt [%d] used\n", i); | |
1031 | } | |
1032 | } | |
1033 | //printk(KERN_INFO "channel=%p\n",pchannel); | |
1034 | //printk(KERN_INFO "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number); | |
1035 | mask <<= 1; | |
1036 | } | |
1037 | ||
1038 | snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76); | |
1039 | spin_lock(&chip->emu_lock); | |
1040 | // acknowledge the interrupt if necessary | |
1041 | outl(status, chip->port+IPR); | |
1042 | ||
1043 | spin_unlock(&chip->emu_lock); | |
1044 | ||
1045 | return IRQ_HANDLED; | |
1046 | } | |
1047 | ||
1048 | static void snd_ca0106_pcm_free(snd_pcm_t *pcm) | |
1049 | { | |
1050 | ca0106_t *emu = pcm->private_data; | |
1051 | emu->pcm = NULL; | |
1052 | snd_pcm_lib_preallocate_free_for_all(pcm); | |
1053 | } | |
1054 | ||
1055 | static int __devinit snd_ca0106_pcm(ca0106_t *emu, int device, snd_pcm_t **rpcm) | |
1056 | { | |
1057 | snd_pcm_t *pcm; | |
1058 | snd_pcm_substream_t *substream; | |
1059 | int err; | |
1060 | ||
1061 | if (rpcm) | |
1062 | *rpcm = NULL; | |
1063 | if ((err = snd_pcm_new(emu->card, "ca0106", device, 1, 1, &pcm)) < 0) | |
1064 | return err; | |
1065 | ||
1066 | pcm->private_data = emu; | |
1067 | pcm->private_free = snd_ca0106_pcm_free; | |
1068 | ||
1069 | switch (device) { | |
1070 | case 0: | |
1071 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_front_ops); | |
1072 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_0_ops); | |
1073 | break; | |
1074 | case 1: | |
1075 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_rear_ops); | |
1076 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_1_ops); | |
1077 | break; | |
1078 | case 2: | |
1079 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_center_lfe_ops); | |
1080 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_2_ops); | |
1081 | break; | |
1082 | case 3: | |
1083 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_unknown_ops); | |
1084 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_3_ops); | |
1085 | break; | |
1086 | } | |
1087 | ||
1088 | pcm->info_flags = 0; | |
1089 | pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; | |
1090 | strcpy(pcm->name, "CA0106"); | |
1091 | emu->pcm = pcm; | |
1092 | ||
1093 | for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; | |
1094 | substream; | |
1095 | substream = substream->next) { | |
1096 | if ((err = snd_pcm_lib_preallocate_pages(substream, | |
1097 | SNDRV_DMA_TYPE_DEV, | |
1098 | snd_dma_pci_data(emu->pci), | |
1099 | 64*1024, 64*1024)) < 0) /* FIXME: 32*1024 for sound buffer, between 32and64 for Periods table. */ | |
1100 | return err; | |
1101 | } | |
1102 | ||
1103 | for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; | |
1104 | substream; | |
1105 | substream = substream->next) { | |
1106 | if ((err = snd_pcm_lib_preallocate_pages(substream, | |
1107 | SNDRV_DMA_TYPE_DEV, | |
1108 | snd_dma_pci_data(emu->pci), | |
1109 | 64*1024, 64*1024)) < 0) | |
1110 | return err; | |
1111 | } | |
1112 | ||
1113 | if (rpcm) | |
1114 | *rpcm = pcm; | |
1115 | ||
1116 | return 0; | |
1117 | } | |
1118 | ||
1119 | static int __devinit snd_ca0106_create(snd_card_t *card, | |
1120 | struct pci_dev *pci, | |
1121 | ca0106_t **rchip) | |
1122 | { | |
1123 | ca0106_t *chip; | |
1baa705b | 1124 | ca0106_details_t *c; |
1da177e4 LT |
1125 | int err; |
1126 | int ch; | |
1127 | static snd_device_ops_t ops = { | |
1128 | .dev_free = snd_ca0106_dev_free, | |
1129 | }; | |
1130 | ||
1131 | *rchip = NULL; | |
1132 | ||
1133 | if ((err = pci_enable_device(pci)) < 0) | |
1134 | return err; | |
1135 | if (pci_set_dma_mask(pci, 0xffffffffUL) < 0 || | |
1136 | pci_set_consistent_dma_mask(pci, 0xffffffffUL) < 0) { | |
1137 | printk(KERN_ERR "error to set 32bit mask DMA\n"); | |
1138 | pci_disable_device(pci); | |
1139 | return -ENXIO; | |
1140 | } | |
1141 | ||
1142 | chip = kcalloc(1, sizeof(*chip), GFP_KERNEL); | |
1143 | if (chip == NULL) { | |
1144 | pci_disable_device(pci); | |
1145 | return -ENOMEM; | |
1146 | } | |
1147 | ||
1148 | chip->card = card; | |
1149 | chip->pci = pci; | |
1150 | chip->irq = -1; | |
1151 | ||
1152 | spin_lock_init(&chip->emu_lock); | |
1153 | ||
1154 | chip->port = pci_resource_start(pci, 0); | |
1155 | if ((chip->res_port = request_region(chip->port, 0x20, | |
1156 | "snd_ca0106")) == NULL) { | |
1157 | snd_ca0106_free(chip); | |
1158 | printk(KERN_ERR "cannot allocate the port\n"); | |
1159 | return -EBUSY; | |
1160 | } | |
1161 | ||
1162 | if (request_irq(pci->irq, snd_ca0106_interrupt, | |
1163 | SA_INTERRUPT|SA_SHIRQ, "snd_ca0106", | |
1164 | (void *)chip)) { | |
1165 | snd_ca0106_free(chip); | |
1166 | printk(KERN_ERR "cannot grab irq\n"); | |
1167 | return -EBUSY; | |
1168 | } | |
1169 | chip->irq = pci->irq; | |
1170 | ||
1171 | /* This stores the periods table. */ | |
1172 | if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 1024, &chip->buffer) < 0) { | |
1173 | snd_ca0106_free(chip); | |
1174 | return -ENOMEM; | |
1175 | } | |
1176 | ||
1177 | pci_set_master(pci); | |
1178 | /* read revision & serial */ | |
1179 | pci_read_config_byte(pci, PCI_REVISION_ID, (char *)&chip->revision); | |
1180 | pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial); | |
1181 | pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model); | |
1182 | #if 1 | |
1183 | printk(KERN_INFO "Model %04x Rev %08x Serial %08x\n", chip->model, | |
1184 | chip->revision, chip->serial); | |
1185 | #endif | |
1baa705b JCD |
1186 | strcpy(card->driver, "CA0106"); |
1187 | strcpy(card->shortname, "CA0106"); | |
1188 | ||
1189 | for (c=ca0106_chip_details; c->serial; c++) { | |
1190 | if (c->serial == chip->serial) break; | |
1191 | } | |
1192 | chip->details = c; | |
1193 | sprintf(card->longname, "%s at 0x%lx irq %i", | |
1194 | c->name, chip->port, chip->irq); | |
1da177e4 LT |
1195 | |
1196 | outl(0, chip->port + INTE); | |
1197 | ||
1198 | /* | |
1199 | * Init to 0x02109204 : | |
1200 | * Clock accuracy = 0 (1000ppm) | |
1201 | * Sample Rate = 2 (48kHz) | |
1202 | * Audio Channel = 1 (Left of 2) | |
1203 | * Source Number = 0 (Unspecified) | |
1204 | * Generation Status = 1 (Original for Cat Code 12) | |
1205 | * Cat Code = 12 (Digital Signal Mixer) | |
1206 | * Mode = 0 (Mode 0) | |
1207 | * Emphasis = 0 (None) | |
1208 | * CP = 1 (Copyright unasserted) | |
1209 | * AN = 0 (Audio data) | |
1210 | * P = 0 (Consumer) | |
1211 | */ | |
1212 | snd_ca0106_ptr_write(chip, SPCS0, 0, | |
1213 | chip->spdif_bits[0] = | |
1214 | SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | | |
1215 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | | |
1216 | SPCS_GENERATIONSTATUS | 0x00001200 | | |
1217 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT); | |
1218 | /* Only SPCS1 has been tested */ | |
1219 | snd_ca0106_ptr_write(chip, SPCS1, 0, | |
1220 | chip->spdif_bits[1] = | |
1221 | SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | | |
1222 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | | |
1223 | SPCS_GENERATIONSTATUS | 0x00001200 | | |
1224 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT); | |
1225 | snd_ca0106_ptr_write(chip, SPCS2, 0, | |
1226 | chip->spdif_bits[2] = | |
1227 | SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | | |
1228 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | | |
1229 | SPCS_GENERATIONSTATUS | 0x00001200 | | |
1230 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT); | |
1231 | snd_ca0106_ptr_write(chip, SPCS3, 0, | |
1232 | chip->spdif_bits[3] = | |
1233 | SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | | |
1234 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | | |
1235 | SPCS_GENERATIONSTATUS | 0x00001200 | | |
1236 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT); | |
1237 | ||
1238 | snd_ca0106_ptr_write(chip, PLAYBACK_MUTE, 0, 0x00fc0000); | |
1239 | snd_ca0106_ptr_write(chip, CAPTURE_MUTE, 0, 0x00fc0000); | |
1240 | ||
1241 | /* Write 0x8000 to AC97_REC_GAIN to mute it. */ | |
1242 | outb(AC97_REC_GAIN, chip->port + AC97ADDRESS); | |
1243 | outw(0x8000, chip->port + AC97DATA); | |
1244 | #if 0 | |
1245 | snd_ca0106_ptr_write(chip, SPCS0, 0, 0x2108006); | |
1246 | snd_ca0106_ptr_write(chip, 0x42, 0, 0x2108006); | |
1247 | snd_ca0106_ptr_write(chip, 0x43, 0, 0x2108006); | |
1248 | snd_ca0106_ptr_write(chip, 0x44, 0, 0x2108006); | |
1249 | #endif | |
1250 | ||
1251 | //snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0xf0f003f); /* OSS drivers set this. */ | |
1252 | /* Analog or Digital output */ | |
1253 | snd_ca0106_ptr_write(chip, SPDIF_SELECT1, 0, 0xf); | |
8f55fbb0 | 1254 | snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0x000f0000); /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers. Use 0x000f0000 for surround71 */ |
1da177e4 LT |
1255 | chip->spdif_enable = 0; /* Set digital SPDIF output off */ |
1256 | chip->capture_source = 3; /* Set CAPTURE_SOURCE */ | |
1257 | //snd_ca0106_ptr_write(chip, 0x45, 0, 0); /* Analogue out */ | |
1258 | //snd_ca0106_ptr_write(chip, 0x45, 0, 0xf00); /* Digital out */ | |
1259 | ||
1260 | snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 0, 0x40c81000); /* goes to 0x40c80000 when doing SPDIF IN/OUT */ | |
1261 | snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 1, 0xffffffff); /* (Mute) CAPTURE feedback into PLAYBACK volume. Only lower 16 bits matter. */ | |
1262 | snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 2, 0x30300000); /* SPDIF IN Volume */ | |
1263 | snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 3, 0x00700000); /* SPDIF IN Volume, 0x70 = (vol & 0x3f) | 0x40 */ | |
1264 | snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING1, 0, 0x32765410); | |
1265 | snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING2, 0, 0x76767676); | |
1266 | snd_ca0106_ptr_write(chip, CAPTURE_ROUTING1, 0, 0x32765410); | |
1267 | snd_ca0106_ptr_write(chip, CAPTURE_ROUTING2, 0, 0x76767676); | |
1268 | for(ch = 0; ch < 4; ch++) { | |
1269 | snd_ca0106_ptr_write(chip, CAPTURE_VOLUME1, ch, 0x30303030); /* Only high 16 bits matter */ | |
1270 | snd_ca0106_ptr_write(chip, CAPTURE_VOLUME2, ch, 0x30303030); | |
1271 | //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0x40404040); /* Mute */ | |
1272 | //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0x40404040); /* Mute */ | |
1273 | snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0xffffffff); /* Mute */ | |
1274 | snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0xffffffff); /* Mute */ | |
1275 | } | |
1276 | snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4); /* Select MIC, Line in, TAD in, AUX in */ | |
1277 | chip->capture_source = 3; /* Set CAPTURE_SOURCE */ | |
1278 | ||
1baa705b | 1279 | if (chip->details->gpio_type == 1) { /* The SB0410 and SB0413 use GPIO differently. */ |
1da177e4 LT |
1280 | /* FIXME: Still need to find out what the other GPIO bits do. E.g. For digital spdif out. */ |
1281 | outl(0x0, chip->port+GPIO); | |
1282 | //outl(0x00f0e000, chip->port+GPIO); /* Analog */ | |
8f55fbb0 | 1283 | outl(0x005f4301, chip->port+GPIO); /* Analog */ |
1da177e4 LT |
1284 | } else { |
1285 | outl(0x0, chip->port+GPIO); | |
1286 | outl(0x005f03a3, chip->port+GPIO); /* Analog */ | |
1287 | //outl(0x005f02a2, chip->port+GPIO); /* SPDIF */ | |
1288 | } | |
1289 | snd_ca0106_intr_enable(chip, 0x105); /* Win2000 uses 0x1e0 */ | |
1290 | ||
1291 | //outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG); | |
1292 | //outl(0x00001409, chip->port+HCFG); /* 0x1000 causes AC3 to fails. Maybe it effects 24 bit output. */ | |
1293 | //outl(0x00000009, chip->port+HCFG); | |
1294 | outl(HCFG_AC97 | HCFG_AUDIOENABLE, chip->port+HCFG); /* AC97 2.0, Enable outputs. */ | |
1295 | ||
7199acdc JCD |
1296 | if (chip->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */ |
1297 | snd_ca0106_i2c_write(chip, ADC_MUX, ADC_MUX_LINEIN); /* Enable Line-in capture. MIC in currently untested. */ | |
1298 | } | |
1299 | ||
1da177e4 LT |
1300 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, |
1301 | chip, &ops)) < 0) { | |
1302 | snd_ca0106_free(chip); | |
1303 | return err; | |
1304 | } | |
1305 | *rchip = chip; | |
1306 | return 0; | |
1307 | } | |
1308 | ||
1309 | static int __devinit snd_ca0106_probe(struct pci_dev *pci, | |
1310 | const struct pci_device_id *pci_id) | |
1311 | { | |
1312 | static int dev; | |
1313 | snd_card_t *card; | |
1314 | ca0106_t *chip; | |
1da177e4 LT |
1315 | int err; |
1316 | ||
1317 | if (dev >= SNDRV_CARDS) | |
1318 | return -ENODEV; | |
1319 | if (!enable[dev]) { | |
1320 | dev++; | |
1321 | return -ENOENT; | |
1322 | } | |
1323 | ||
1324 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); | |
1325 | if (card == NULL) | |
1326 | return -ENOMEM; | |
1327 | ||
1328 | if ((err = snd_ca0106_create(card, pci, &chip)) < 0) { | |
1329 | snd_card_free(card); | |
1330 | return err; | |
1331 | } | |
1332 | ||
1333 | if ((err = snd_ca0106_pcm(chip, 0, NULL)) < 0) { | |
1334 | snd_card_free(card); | |
1335 | return err; | |
1336 | } | |
1337 | if ((err = snd_ca0106_pcm(chip, 1, NULL)) < 0) { | |
1338 | snd_card_free(card); | |
1339 | return err; | |
1340 | } | |
1341 | if ((err = snd_ca0106_pcm(chip, 2, NULL)) < 0) { | |
1342 | snd_card_free(card); | |
1343 | return err; | |
1344 | } | |
1345 | if ((err = snd_ca0106_pcm(chip, 3, NULL)) < 0) { | |
1346 | snd_card_free(card); | |
1347 | return err; | |
1348 | } | |
1baa705b | 1349 | if (chip->details->ac97 == 1) { /* The SB0410 and SB0413 do not have an AC97 chip. */ |
1da177e4 LT |
1350 | if ((err = snd_ca0106_ac97(chip)) < 0) { |
1351 | snd_card_free(card); | |
1352 | return err; | |
1353 | } | |
1354 | } | |
1355 | if ((err = snd_ca0106_mixer(chip)) < 0) { | |
1356 | snd_card_free(card); | |
1357 | return err; | |
1358 | } | |
1359 | ||
1360 | snd_ca0106_proc_init(chip); | |
1361 | ||
1da177e4 LT |
1362 | if ((err = snd_card_register(card)) < 0) { |
1363 | snd_card_free(card); | |
1364 | return err; | |
1365 | } | |
1366 | ||
1367 | pci_set_drvdata(pci, card); | |
1368 | dev++; | |
1369 | return 0; | |
1370 | } | |
1371 | ||
1372 | static void __devexit snd_ca0106_remove(struct pci_dev *pci) | |
1373 | { | |
1374 | snd_card_free(pci_get_drvdata(pci)); | |
1375 | pci_set_drvdata(pci, NULL); | |
1376 | } | |
1377 | ||
1378 | // PCI IDs | |
1379 | static struct pci_device_id snd_ca0106_ids[] = { | |
1380 | { 0x1102, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Audigy LS or Live 24bit */ | |
1381 | { 0, } | |
1382 | }; | |
1383 | MODULE_DEVICE_TABLE(pci, snd_ca0106_ids); | |
1384 | ||
1385 | // pci_driver definition | |
1386 | static struct pci_driver driver = { | |
1387 | .name = "CA0106", | |
1388 | .id_table = snd_ca0106_ids, | |
1389 | .probe = snd_ca0106_probe, | |
1390 | .remove = __devexit_p(snd_ca0106_remove), | |
1391 | }; | |
1392 | ||
1393 | // initialization of the module | |
1394 | static int __init alsa_card_ca0106_init(void) | |
1395 | { | |
1396 | int err; | |
1397 | ||
01d25d46 | 1398 | if ((err = pci_register_driver(&driver)) > 0) |
1da177e4 LT |
1399 | return err; |
1400 | ||
1401 | return 0; | |
1402 | } | |
1403 | ||
1404 | // clean up the module | |
1405 | static void __exit alsa_card_ca0106_exit(void) | |
1406 | { | |
1407 | pci_unregister_driver(&driver); | |
1408 | } | |
1409 | ||
1410 | module_init(alsa_card_ca0106_init) | |
1411 | module_exit(alsa_card_ca0106_exit) |