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
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.
22 * The only playback controls that currently do anything are: -
30 * For capture from Mic in or Line in.
31 * Digital/Analog ( switch must be in Analog mode for CAPTURE. )
33 * CAPTURE feedback into PLAYBACK
36 * Support interrupts per period.
37 * Removed noise from Center/LFE channel when in Analog mode.
38 * Rename and remove mixer controls.
40 * Use separate card based DMA buffer for periods table list.
42 * Change remove and rename ctrls into lists.
44 * Try to fix capture sources.
47 * Enable S32_LE format support.
49 * Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".)
51 * Add Model name recognition.
53 * Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period.
54 * Remove redundent "voice" handling.
56 * Single trigger call for multi channels.
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.
65 * Implement 192000 sample rate.
67 * Add support for SB0410 and SB0413.
69 * Modified Copyright message.
71 * Finally fix support for SB Live 24 bit. SB0410 and SB0413.
72 * The output codec needs resetting, otherwise all output is muted.
74 * Merge "pci_disable_device(pci);" fixes.
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.)
79 * Add support for MSI K8N Diamond Motherboard with onboard SB Live 24bit without AC97. From kiksen, bug #901
81 * Implement support for Line-in capture on SB Live 24bit.
84 * Some stability problems when unloading the snd-ca0106 kernel module.
88 * 4 Capture channels, only one implemented so far.
89 * Other capture rates apart from 48khz not implemented.
94 * P17 Chip: CA0106-DAT
95 * AC97 Codec: STAC 9721
96 * ADC: Philips 1361T (Stereo 24bit)
97 * DAC: WM8746EDS (6-channel, 24bit, 192Khz)
101 * P17 Chip: CA0106-DAT
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.
110 * P17 Chip: CA0106-DAT
114 * Trying to handle it like the SB0410.
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>
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.
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.
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
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 <linux/dma-mapping.h>
142 #include <sound/core.h>
143 #include <sound/initval.h>
144 #include <sound/pcm.h>
145 #include <sound/ac97_codec.h>
146 #include <sound/info.h>
148 MODULE_AUTHOR("James Courtier-Dutton <James@superbug.demon.co.uk>");
149 MODULE_DESCRIPTION("CA0106");
150 MODULE_LICENSE("GPL");
151 MODULE_SUPPORTED_DEVICE("{{Creative,SB CA0106 chip}}");
153 // module parameters (see "Module Parameters")
154 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
155 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
156 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
158 module_param_array(index
, int, NULL
, 0444);
159 MODULE_PARM_DESC(index
, "Index value for the CA0106 soundcard.");
160 module_param_array(id
, charp
, NULL
, 0444);
161 MODULE_PARM_DESC(id
, "ID string for the CA0106 soundcard.");
162 module_param_array(enable
, bool, NULL
, 0444);
163 MODULE_PARM_DESC(enable
, "Enable the CA0106 soundcard.");
167 static ca0106_details_t ca0106_chip_details
[] = {
168 /* AudigyLS[SB0310] */
169 { .serial
= 0x10021102,
170 .name
= "AudigyLS [SB0310]",
172 /* Unknown AudigyLS that also says SB0310 on it */
173 { .serial
= 0x10051102,
174 .name
= "AudigyLS [SB0310b]",
176 /* New Sound Blaster Live! 7.1 24bit. This does not have an AC97. 53SB041000001 */
177 { .serial
= 0x10061102,
178 .name
= "Live! 7.1 24bit [SB0410]",
181 /* New Dell Sound Blaster Live! 7.1 24bit. This does not have an AC97. */
182 { .serial
= 0x10071102,
183 .name
= "Live! 7.1 24bit [SB0413]",
186 /* MSI K8N Diamond Motherboard with onboard SB Live 24bit without AC97 */
187 { .serial
= 0x10091462,
188 .name
= "MSI K8N Diamond MB [SB0438]",
192 .name
= "AudigyLS [Unknown]" }
195 /* hardware definition */
196 static snd_pcm_hardware_t snd_ca0106_playback_hw
= {
197 .info
= (SNDRV_PCM_INFO_MMAP
|
198 SNDRV_PCM_INFO_INTERLEAVED
|
199 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
200 SNDRV_PCM_INFO_MMAP_VALID
),
201 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S32_LE
,
202 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_96000
| SNDRV_PCM_RATE_192000
,
205 .channels_min
= 2, //1,
206 .channels_max
= 2, //6,
207 .buffer_bytes_max
= ((65536 - 64) * 8),
208 .period_bytes_min
= 64,
209 .period_bytes_max
= (65536 - 64),
215 static snd_pcm_hardware_t snd_ca0106_capture_hw
= {
216 .info
= (SNDRV_PCM_INFO_MMAP
|
217 SNDRV_PCM_INFO_INTERLEAVED
|
218 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
219 SNDRV_PCM_INFO_MMAP_VALID
),
220 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S32_LE
,
221 .rates
= SNDRV_PCM_RATE_44100
| SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_96000
| SNDRV_PCM_RATE_192000
,
226 .buffer_bytes_max
= ((65536 - 64) * 8),
227 .period_bytes_min
= 64,
228 .period_bytes_max
= (65536 - 64),
234 unsigned int snd_ca0106_ptr_read(ca0106_t
* emu
,
239 unsigned int regptr
, val
;
241 regptr
= (reg
<< 16) | chn
;
243 spin_lock_irqsave(&emu
->emu_lock
, flags
);
244 outl(regptr
, emu
->port
+ PTR
);
245 val
= inl(emu
->port
+ DATA
);
246 spin_unlock_irqrestore(&emu
->emu_lock
, flags
);
250 void snd_ca0106_ptr_write(ca0106_t
*emu
,
258 regptr
= (reg
<< 16) | chn
;
260 spin_lock_irqsave(&emu
->emu_lock
, flags
);
261 outl(regptr
, emu
->port
+ PTR
);
262 outl(data
, emu
->port
+ DATA
);
263 spin_unlock_irqrestore(&emu
->emu_lock
, flags
);
266 int snd_ca0106_i2c_write(ca0106_t
*emu
,
274 if ((reg
> 0x7f) || (value
> 0x1ff))
276 snd_printk("i2c_write: invalid values.\n");
280 tmp
= reg
<< 25 | value
<< 16;
281 /* Not sure what this I2C channel controls. */
282 /* snd_ca0106_ptr_write(emu, I2C_D0, 0, tmp); */
284 /* This controls the I2C connected to the WM8775 ADC Codec */
285 snd_ca0106_ptr_write(emu
, I2C_D1
, 0, tmp
);
287 for(retry
=0;retry
<10;retry
++)
289 /* Send the data to i2c */
290 tmp
= snd_ca0106_ptr_read(emu
, I2C_A
, 0);
291 tmp
= tmp
& ~(I2C_A_ADC_READ
|I2C_A_ADC_LAST
|I2C_A_ADC_START
|I2C_A_ADC_ADD_MASK
);
292 tmp
= tmp
| (I2C_A_ADC_LAST
|I2C_A_ADC_START
|I2C_A_ADC_ADD
);
293 snd_ca0106_ptr_write(emu
, I2C_A
, 0, tmp
);
295 /* Wait till the transaction ends */
298 status
= snd_ca0106_ptr_read(emu
, I2C_A
, 0);
299 //snd_printk("I2C:status=0x%x\n", status);
301 if((status
& I2C_A_ADC_START
)==0)
307 //Read back and see if the transaction is successful
308 if((status
& I2C_A_ADC_ABORT
)==0)
314 snd_printk("Writing to ADC failed!\n");
322 static void snd_ca0106_intr_enable(ca0106_t
*emu
, unsigned int intrenb
)
327 spin_lock_irqsave(&emu
->emu_lock
, flags
);
328 enable
= inl(emu
->port
+ INTE
) | intrenb
;
329 outl(enable
, emu
->port
+ INTE
);
330 spin_unlock_irqrestore(&emu
->emu_lock
, flags
);
333 static void snd_ca0106_pcm_free_substream(snd_pcm_runtime_t
*runtime
)
335 kfree(runtime
->private_data
);
338 /* open_playback callback */
339 static int snd_ca0106_pcm_open_playback_channel(snd_pcm_substream_t
*substream
, int channel_id
)
341 ca0106_t
*chip
= snd_pcm_substream_chip(substream
);
342 ca0106_channel_t
*channel
= &(chip
->playback_channels
[channel_id
]);
344 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
347 epcm
= kcalloc(1, sizeof(*epcm
), GFP_KERNEL
);
352 epcm
->substream
= substream
;
353 epcm
->channel_id
=channel_id
;
355 runtime
->private_data
= epcm
;
356 runtime
->private_free
= snd_ca0106_pcm_free_substream
;
358 runtime
->hw
= snd_ca0106_playback_hw
;
361 channel
->number
= channel_id
;
364 //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
365 //channel->interrupt = snd_ca0106_pcm_channel_interrupt;
367 if ((err
= snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
)) < 0)
369 if ((err
= snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, 64)) < 0)
375 static int snd_ca0106_pcm_close_playback(snd_pcm_substream_t
*substream
)
377 ca0106_t
*chip
= snd_pcm_substream_chip(substream
);
378 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
379 ca0106_pcm_t
*epcm
= runtime
->private_data
;
380 chip
->playback_channels
[epcm
->channel_id
].use
=0;
381 /* FIXME: maybe zero others */
385 static int snd_ca0106_pcm_open_playback_front(snd_pcm_substream_t
*substream
)
387 return snd_ca0106_pcm_open_playback_channel(substream
, PCM_FRONT_CHANNEL
);
390 static int snd_ca0106_pcm_open_playback_center_lfe(snd_pcm_substream_t
*substream
)
392 return snd_ca0106_pcm_open_playback_channel(substream
, PCM_CENTER_LFE_CHANNEL
);
395 static int snd_ca0106_pcm_open_playback_unknown(snd_pcm_substream_t
*substream
)
397 return snd_ca0106_pcm_open_playback_channel(substream
, PCM_UNKNOWN_CHANNEL
);
400 static int snd_ca0106_pcm_open_playback_rear(snd_pcm_substream_t
*substream
)
402 return snd_ca0106_pcm_open_playback_channel(substream
, PCM_REAR_CHANNEL
);
405 /* open_capture callback */
406 static int snd_ca0106_pcm_open_capture_channel(snd_pcm_substream_t
*substream
, int channel_id
)
408 ca0106_t
*chip
= snd_pcm_substream_chip(substream
);
409 ca0106_channel_t
*channel
= &(chip
->capture_channels
[channel_id
]);
411 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
414 epcm
= kcalloc(1, sizeof(*epcm
), GFP_KERNEL
);
416 snd_printk("open_capture_channel: failed epcm alloc\n");
420 epcm
->substream
= substream
;
421 epcm
->channel_id
=channel_id
;
423 runtime
->private_data
= epcm
;
424 runtime
->private_free
= snd_ca0106_pcm_free_substream
;
426 runtime
->hw
= snd_ca0106_capture_hw
;
429 channel
->number
= channel_id
;
432 //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
433 //channel->interrupt = snd_ca0106_pcm_channel_interrupt;
435 if ((err
= snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
)) < 0)
437 //snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hw_constraints_capture_period_sizes);
438 if ((err
= snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, 64)) < 0)
444 static int snd_ca0106_pcm_close_capture(snd_pcm_substream_t
*substream
)
446 ca0106_t
*chip
= snd_pcm_substream_chip(substream
);
447 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
448 ca0106_pcm_t
*epcm
= runtime
->private_data
;
449 chip
->capture_channels
[epcm
->channel_id
].use
=0;
450 /* FIXME: maybe zero others */
454 static int snd_ca0106_pcm_open_0_capture(snd_pcm_substream_t
*substream
)
456 return snd_ca0106_pcm_open_capture_channel(substream
, 0);
459 static int snd_ca0106_pcm_open_1_capture(snd_pcm_substream_t
*substream
)
461 return snd_ca0106_pcm_open_capture_channel(substream
, 1);
464 static int snd_ca0106_pcm_open_2_capture(snd_pcm_substream_t
*substream
)
466 return snd_ca0106_pcm_open_capture_channel(substream
, 2);
469 static int snd_ca0106_pcm_open_3_capture(snd_pcm_substream_t
*substream
)
471 return snd_ca0106_pcm_open_capture_channel(substream
, 3);
474 /* hw_params callback */
475 static int snd_ca0106_pcm_hw_params_playback(snd_pcm_substream_t
*substream
,
476 snd_pcm_hw_params_t
* hw_params
)
478 return snd_pcm_lib_malloc_pages(substream
,
479 params_buffer_bytes(hw_params
));
482 /* hw_free callback */
483 static int snd_ca0106_pcm_hw_free_playback(snd_pcm_substream_t
*substream
)
485 return snd_pcm_lib_free_pages(substream
);
488 /* hw_params callback */
489 static int snd_ca0106_pcm_hw_params_capture(snd_pcm_substream_t
*substream
,
490 snd_pcm_hw_params_t
* hw_params
)
492 return snd_pcm_lib_malloc_pages(substream
,
493 params_buffer_bytes(hw_params
));
496 /* hw_free callback */
497 static int snd_ca0106_pcm_hw_free_capture(snd_pcm_substream_t
*substream
)
499 return snd_pcm_lib_free_pages(substream
);
502 /* prepare playback callback */
503 static int snd_ca0106_pcm_prepare_playback(snd_pcm_substream_t
*substream
)
505 ca0106_t
*emu
= snd_pcm_substream_chip(substream
);
506 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
507 ca0106_pcm_t
*epcm
= runtime
->private_data
;
508 int channel
= epcm
->channel_id
;
509 u32
*table_base
= (u32
*)(emu
->buffer
.area
+(8*16*channel
));
510 u32 period_size_bytes
= frames_to_bytes(runtime
, runtime
->period_size
);
511 u32 hcfg_mask
= HCFG_PLAYBACK_S32_LE
;
512 u32 hcfg_set
= 0x00000000;
514 u32 reg40_mask
= 0x30000 << (channel
<<1);
517 /* FIXME: Depending on mixer selection of SPDIF out or not, select the spdif rate or the DAC rate. */
518 u32 reg71_mask
= 0x03030000 ; /* Global. Set SPDIF rate. We only support 44100 to spdif, not to DAC. */
523 //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));
524 //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base);
525 //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes);
526 /* Rate can be set per channel. */
527 /* reg40 control host to fifo */
528 /* reg71 controls DAC rate. */
529 switch (runtime
->rate
) {
531 reg40_set
= 0x10000 << (channel
<<1);
532 reg71_set
= 0x01010000;
539 reg40_set
= 0x20000 << (channel
<<1);
540 reg71_set
= 0x02020000;
543 reg40_set
= 0x30000 << (channel
<<1);
544 reg71_set
= 0x03030000;
551 /* Format is a global setting */
552 /* FIXME: Only let the first channel accessed set this. */
553 switch (runtime
->format
) {
554 case SNDRV_PCM_FORMAT_S16_LE
:
557 case SNDRV_PCM_FORMAT_S32_LE
:
558 hcfg_set
= HCFG_PLAYBACK_S32_LE
;
564 hcfg
= inl(emu
->port
+ HCFG
) ;
565 hcfg
= (hcfg
& ~hcfg_mask
) | hcfg_set
;
566 outl(hcfg
, emu
->port
+ HCFG
);
567 reg40
= snd_ca0106_ptr_read(emu
, 0x40, 0);
568 reg40
= (reg40
& ~reg40_mask
) | reg40_set
;
569 snd_ca0106_ptr_write(emu
, 0x40, 0, reg40
);
570 reg71
= snd_ca0106_ptr_read(emu
, 0x71, 0);
571 reg71
= (reg71
& ~reg71_mask
) | reg71_set
;
572 snd_ca0106_ptr_write(emu
, 0x71, 0, reg71
);
574 /* FIXME: Check emu->buffer.size before actually writing to it. */
575 for(i
=0; i
< runtime
->periods
; i
++) {
576 table_base
[i
*2]=runtime
->dma_addr
+(i
*period_size_bytes
);
577 table_base
[(i
*2)+1]=period_size_bytes
<<16;
580 snd_ca0106_ptr_write(emu
, PLAYBACK_LIST_ADDR
, channel
, emu
->buffer
.addr
+(8*16*channel
));
581 snd_ca0106_ptr_write(emu
, PLAYBACK_LIST_SIZE
, channel
, (runtime
->periods
- 1) << 19);
582 snd_ca0106_ptr_write(emu
, PLAYBACK_LIST_PTR
, channel
, 0);
583 snd_ca0106_ptr_write(emu
, PLAYBACK_DMA_ADDR
, channel
, runtime
->dma_addr
);
584 snd_ca0106_ptr_write(emu
, PLAYBACK_PERIOD_SIZE
, channel
, frames_to_bytes(runtime
, runtime
->period_size
)<<16); // buffer size in bytes
585 /* FIXME test what 0 bytes does. */
586 snd_ca0106_ptr_write(emu
, PLAYBACK_PERIOD_SIZE
, channel
, 0); // buffer size in bytes
587 snd_ca0106_ptr_write(emu
, PLAYBACK_POINTER
, channel
, 0);
588 snd_ca0106_ptr_write(emu
, 0x07, channel
, 0x0);
589 snd_ca0106_ptr_write(emu
, 0x08, channel
, 0);
590 snd_ca0106_ptr_write(emu
, PLAYBACK_MUTE
, 0x0, 0x0); /* Unmute output */
592 snd_ca0106_ptr_write(emu
, SPCS0
, 0,
593 SPCS_CLKACCY_1000PPM
| SPCS_SAMPLERATE_48
|
594 SPCS_CHANNELNUM_LEFT
| SPCS_SOURCENUM_UNSPEC
|
595 SPCS_GENERATIONSTATUS
| 0x00001200 |
596 0x00000000 | SPCS_EMPHASIS_NONE
| SPCS_COPYRIGHT
);
603 /* prepare capture callback */
604 static int snd_ca0106_pcm_prepare_capture(snd_pcm_substream_t
*substream
)
606 ca0106_t
*emu
= snd_pcm_substream_chip(substream
);
607 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
608 ca0106_pcm_t
*epcm
= runtime
->private_data
;
609 int channel
= epcm
->channel_id
;
610 u32 hcfg_mask
= HCFG_CAPTURE_S32_LE
;
611 u32 hcfg_set
= 0x00000000;
613 u32 over_sampling
=0x2;
614 u32 reg71_mask
= 0x0000c000 ; /* Global. Set ADC rate. */
618 //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));
619 //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base);
620 //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes);
621 /* reg71 controls ADC rate. */
622 switch (runtime
->rate
) {
624 reg71_set
= 0x00004000;
630 reg71_set
= 0x00008000;
634 reg71_set
= 0x0000c000;
641 /* Format is a global setting */
642 /* FIXME: Only let the first channel accessed set this. */
643 switch (runtime
->format
) {
644 case SNDRV_PCM_FORMAT_S16_LE
:
647 case SNDRV_PCM_FORMAT_S32_LE
:
648 hcfg_set
= HCFG_CAPTURE_S32_LE
;
654 hcfg
= inl(emu
->port
+ HCFG
) ;
655 hcfg
= (hcfg
& ~hcfg_mask
) | hcfg_set
;
656 outl(hcfg
, emu
->port
+ HCFG
);
657 reg71
= snd_ca0106_ptr_read(emu
, 0x71, 0);
658 reg71
= (reg71
& ~reg71_mask
) | reg71_set
;
659 snd_ca0106_ptr_write(emu
, 0x71, 0, reg71
);
660 if (emu
->details
->i2c_adc
== 1) { /* The SB0410 and SB0413 use I2C to control ADC. */
661 snd_ca0106_i2c_write(emu
, ADC_MASTER
, over_sampling
); /* Adjust the over sampler to better suit the capture rate. */
665 //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));
666 snd_ca0106_ptr_write(emu
, 0x13, channel
, 0);
667 snd_ca0106_ptr_write(emu
, CAPTURE_DMA_ADDR
, channel
, runtime
->dma_addr
);
668 snd_ca0106_ptr_write(emu
, CAPTURE_BUFFER_SIZE
, channel
, frames_to_bytes(runtime
, runtime
->buffer_size
)<<16); // buffer size in bytes
669 snd_ca0106_ptr_write(emu
, CAPTURE_POINTER
, channel
, 0);
674 /* trigger_playback callback */
675 static int snd_ca0106_pcm_trigger_playback(snd_pcm_substream_t
*substream
,
678 ca0106_t
*emu
= snd_pcm_substream_chip(substream
);
679 snd_pcm_runtime_t
*runtime
;
683 struct list_head
*pos
;
684 snd_pcm_substream_t
*s
;
690 case SNDRV_PCM_TRIGGER_START
:
693 case SNDRV_PCM_TRIGGER_STOP
:
698 snd_pcm_group_for_each(pos
, substream
) {
699 s
= snd_pcm_group_substream_entry(pos
);
700 runtime
= s
->runtime
;
701 epcm
= runtime
->private_data
;
702 channel
= epcm
->channel_id
;
703 //snd_printk("channel=%d\n",channel);
704 epcm
->running
= running
;
705 basic
|= (0x1<<channel
);
706 extended
|= (0x10<<channel
);
707 snd_pcm_trigger_done(s
, substream
);
709 //snd_printk("basic=0x%x, extended=0x%x\n",basic, extended);
712 case SNDRV_PCM_TRIGGER_START
:
713 snd_ca0106_ptr_write(emu
, EXTENDED_INT_MASK
, 0, snd_ca0106_ptr_read(emu
, EXTENDED_INT_MASK
, 0) | (extended
));
714 snd_ca0106_ptr_write(emu
, BASIC_INTERRUPT
, 0, snd_ca0106_ptr_read(emu
, BASIC_INTERRUPT
, 0)|(basic
));
716 case SNDRV_PCM_TRIGGER_STOP
:
717 snd_ca0106_ptr_write(emu
, BASIC_INTERRUPT
, 0, snd_ca0106_ptr_read(emu
, BASIC_INTERRUPT
, 0) & ~(basic
));
718 snd_ca0106_ptr_write(emu
, EXTENDED_INT_MASK
, 0, snd_ca0106_ptr_read(emu
, EXTENDED_INT_MASK
, 0) & ~(extended
));
727 /* trigger_capture callback */
728 static int snd_ca0106_pcm_trigger_capture(snd_pcm_substream_t
*substream
,
731 ca0106_t
*emu
= snd_pcm_substream_chip(substream
);
732 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
733 ca0106_pcm_t
*epcm
= runtime
->private_data
;
734 int channel
= epcm
->channel_id
;
738 case SNDRV_PCM_TRIGGER_START
:
739 snd_ca0106_ptr_write(emu
, EXTENDED_INT_MASK
, 0, snd_ca0106_ptr_read(emu
, EXTENDED_INT_MASK
, 0) | (0x110000<<channel
));
740 snd_ca0106_ptr_write(emu
, BASIC_INTERRUPT
, 0, snd_ca0106_ptr_read(emu
, BASIC_INTERRUPT
, 0)|(0x100<<channel
));
743 case SNDRV_PCM_TRIGGER_STOP
:
744 snd_ca0106_ptr_write(emu
, BASIC_INTERRUPT
, 0, snd_ca0106_ptr_read(emu
, BASIC_INTERRUPT
, 0) & ~(0x100<<channel
));
745 snd_ca0106_ptr_write(emu
, EXTENDED_INT_MASK
, 0, snd_ca0106_ptr_read(emu
, EXTENDED_INT_MASK
, 0) & ~(0x110000<<channel
));
755 /* pointer_playback callback */
756 static snd_pcm_uframes_t
757 snd_ca0106_pcm_pointer_playback(snd_pcm_substream_t
*substream
)
759 ca0106_t
*emu
= snd_pcm_substream_chip(substream
);
760 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
761 ca0106_pcm_t
*epcm
= runtime
->private_data
;
762 snd_pcm_uframes_t ptr
, ptr1
, ptr2
,ptr3
,ptr4
= 0;
763 int channel
= epcm
->channel_id
;
768 ptr3
= snd_ca0106_ptr_read(emu
, PLAYBACK_LIST_PTR
, channel
);
769 ptr1
= snd_ca0106_ptr_read(emu
, PLAYBACK_POINTER
, channel
);
770 ptr4
= snd_ca0106_ptr_read(emu
, PLAYBACK_LIST_PTR
, channel
);
771 if (ptr3
!= ptr4
) ptr1
= snd_ca0106_ptr_read(emu
, PLAYBACK_POINTER
, channel
);
772 ptr2
= bytes_to_frames(runtime
, ptr1
);
773 ptr2
+= (ptr4
>> 3) * runtime
->period_size
;
775 if (ptr
>= runtime
->buffer_size
)
776 ptr
-= runtime
->buffer_size
;
777 //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);
782 /* pointer_capture callback */
783 static snd_pcm_uframes_t
784 snd_ca0106_pcm_pointer_capture(snd_pcm_substream_t
*substream
)
786 ca0106_t
*emu
= snd_pcm_substream_chip(substream
);
787 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
788 ca0106_pcm_t
*epcm
= runtime
->private_data
;
789 snd_pcm_uframes_t ptr
, ptr1
, ptr2
= 0;
790 int channel
= channel
=epcm
->channel_id
;
795 ptr1
= snd_ca0106_ptr_read(emu
, CAPTURE_POINTER
, channel
);
796 ptr2
= bytes_to_frames(runtime
, ptr1
);
798 if (ptr
>= runtime
->buffer_size
)
799 ptr
-= runtime
->buffer_size
;
800 //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);
806 static snd_pcm_ops_t snd_ca0106_playback_front_ops
= {
807 .open
= snd_ca0106_pcm_open_playback_front
,
808 .close
= snd_ca0106_pcm_close_playback
,
809 .ioctl
= snd_pcm_lib_ioctl
,
810 .hw_params
= snd_ca0106_pcm_hw_params_playback
,
811 .hw_free
= snd_ca0106_pcm_hw_free_playback
,
812 .prepare
= snd_ca0106_pcm_prepare_playback
,
813 .trigger
= snd_ca0106_pcm_trigger_playback
,
814 .pointer
= snd_ca0106_pcm_pointer_playback
,
817 static snd_pcm_ops_t snd_ca0106_capture_0_ops
= {
818 .open
= snd_ca0106_pcm_open_0_capture
,
819 .close
= snd_ca0106_pcm_close_capture
,
820 .ioctl
= snd_pcm_lib_ioctl
,
821 .hw_params
= snd_ca0106_pcm_hw_params_capture
,
822 .hw_free
= snd_ca0106_pcm_hw_free_capture
,
823 .prepare
= snd_ca0106_pcm_prepare_capture
,
824 .trigger
= snd_ca0106_pcm_trigger_capture
,
825 .pointer
= snd_ca0106_pcm_pointer_capture
,
828 static snd_pcm_ops_t snd_ca0106_capture_1_ops
= {
829 .open
= snd_ca0106_pcm_open_1_capture
,
830 .close
= snd_ca0106_pcm_close_capture
,
831 .ioctl
= snd_pcm_lib_ioctl
,
832 .hw_params
= snd_ca0106_pcm_hw_params_capture
,
833 .hw_free
= snd_ca0106_pcm_hw_free_capture
,
834 .prepare
= snd_ca0106_pcm_prepare_capture
,
835 .trigger
= snd_ca0106_pcm_trigger_capture
,
836 .pointer
= snd_ca0106_pcm_pointer_capture
,
839 static snd_pcm_ops_t snd_ca0106_capture_2_ops
= {
840 .open
= snd_ca0106_pcm_open_2_capture
,
841 .close
= snd_ca0106_pcm_close_capture
,
842 .ioctl
= snd_pcm_lib_ioctl
,
843 .hw_params
= snd_ca0106_pcm_hw_params_capture
,
844 .hw_free
= snd_ca0106_pcm_hw_free_capture
,
845 .prepare
= snd_ca0106_pcm_prepare_capture
,
846 .trigger
= snd_ca0106_pcm_trigger_capture
,
847 .pointer
= snd_ca0106_pcm_pointer_capture
,
850 static snd_pcm_ops_t snd_ca0106_capture_3_ops
= {
851 .open
= snd_ca0106_pcm_open_3_capture
,
852 .close
= snd_ca0106_pcm_close_capture
,
853 .ioctl
= snd_pcm_lib_ioctl
,
854 .hw_params
= snd_ca0106_pcm_hw_params_capture
,
855 .hw_free
= snd_ca0106_pcm_hw_free_capture
,
856 .prepare
= snd_ca0106_pcm_prepare_capture
,
857 .trigger
= snd_ca0106_pcm_trigger_capture
,
858 .pointer
= snd_ca0106_pcm_pointer_capture
,
861 static snd_pcm_ops_t snd_ca0106_playback_center_lfe_ops
= {
862 .open
= snd_ca0106_pcm_open_playback_center_lfe
,
863 .close
= snd_ca0106_pcm_close_playback
,
864 .ioctl
= snd_pcm_lib_ioctl
,
865 .hw_params
= snd_ca0106_pcm_hw_params_playback
,
866 .hw_free
= snd_ca0106_pcm_hw_free_playback
,
867 .prepare
= snd_ca0106_pcm_prepare_playback
,
868 .trigger
= snd_ca0106_pcm_trigger_playback
,
869 .pointer
= snd_ca0106_pcm_pointer_playback
,
872 static snd_pcm_ops_t snd_ca0106_playback_unknown_ops
= {
873 .open
= snd_ca0106_pcm_open_playback_unknown
,
874 .close
= snd_ca0106_pcm_close_playback
,
875 .ioctl
= snd_pcm_lib_ioctl
,
876 .hw_params
= snd_ca0106_pcm_hw_params_playback
,
877 .hw_free
= snd_ca0106_pcm_hw_free_playback
,
878 .prepare
= snd_ca0106_pcm_prepare_playback
,
879 .trigger
= snd_ca0106_pcm_trigger_playback
,
880 .pointer
= snd_ca0106_pcm_pointer_playback
,
883 static snd_pcm_ops_t snd_ca0106_playback_rear_ops
= {
884 .open
= snd_ca0106_pcm_open_playback_rear
,
885 .close
= snd_ca0106_pcm_close_playback
,
886 .ioctl
= snd_pcm_lib_ioctl
,
887 .hw_params
= snd_ca0106_pcm_hw_params_playback
,
888 .hw_free
= snd_ca0106_pcm_hw_free_playback
,
889 .prepare
= snd_ca0106_pcm_prepare_playback
,
890 .trigger
= snd_ca0106_pcm_trigger_playback
,
891 .pointer
= snd_ca0106_pcm_pointer_playback
,
895 static unsigned short snd_ca0106_ac97_read(ac97_t
*ac97
,
898 ca0106_t
*emu
= ac97
->private_data
;
902 spin_lock_irqsave(&emu
->emu_lock
, flags
);
903 outb(reg
, emu
->port
+ AC97ADDRESS
);
904 val
= inw(emu
->port
+ AC97DATA
);
905 spin_unlock_irqrestore(&emu
->emu_lock
, flags
);
909 static void snd_ca0106_ac97_write(ac97_t
*ac97
,
910 unsigned short reg
, unsigned short val
)
912 ca0106_t
*emu
= ac97
->private_data
;
915 spin_lock_irqsave(&emu
->emu_lock
, flags
);
916 outb(reg
, emu
->port
+ AC97ADDRESS
);
917 outw(val
, emu
->port
+ AC97DATA
);
918 spin_unlock_irqrestore(&emu
->emu_lock
, flags
);
921 static int snd_ca0106_ac97(ca0106_t
*chip
)
924 ac97_template_t ac97
;
926 static ac97_bus_ops_t ops
= {
927 .write
= snd_ca0106_ac97_write
,
928 .read
= snd_ca0106_ac97_read
,
931 if ((err
= snd_ac97_bus(chip
->card
, 0, &ops
, NULL
, &pbus
)) < 0)
933 pbus
->no_vra
= 1; /* we don't need VRA */
935 memset(&ac97
, 0, sizeof(ac97
));
936 ac97
.private_data
= chip
;
937 ac97
.scaps
= AC97_SCAP_NO_SPDIF
;
938 return snd_ac97_mixer(pbus
, &ac97
, &chip
->ac97
);
941 static int snd_ca0106_free(ca0106_t
*chip
)
943 if (chip
->res_port
!= NULL
) { /* avoid access to already used hardware */
944 // disable interrupts
945 snd_ca0106_ptr_write(chip
, BASIC_INTERRUPT
, 0, 0);
946 outl(0, chip
->port
+ INTE
);
947 snd_ca0106_ptr_write(chip
, EXTENDED_INT_MASK
, 0, 0);
950 //outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
951 outl(0, chip
->port
+ HCFG
);
952 /* FIXME: We need to stop and DMA transfers here.
953 * But as I am not sure how yet, we cannot from the dma pages.
954 * So we can fix: snd-malloc: Memory leak? pages not freed = 8
959 if (chip
->buffer
.area
)
960 snd_dma_free_pages(&chip
->buffer
);
963 // release the i/o port
964 if (chip
->res_port
) {
965 release_resource(chip
->res_port
);
966 kfree_nocheck(chip
->res_port
);
970 free_irq(chip
->irq
, (void *)chip
);
971 pci_disable_device(chip
->pci
);
976 static int snd_ca0106_dev_free(snd_device_t
*device
)
978 ca0106_t
*chip
= device
->device_data
;
979 return snd_ca0106_free(chip
);
982 static irqreturn_t
snd_ca0106_interrupt(int irq
, void *dev_id
,
983 struct pt_regs
*regs
)
987 ca0106_t
*chip
= dev_id
;
991 ca0106_channel_t
*pchannel
;
993 spin_lock(&chip
->emu_lock
);
995 status
= inl(chip
->port
+ IPR
);
997 // call updater, unlock before it
998 spin_unlock(&chip
->emu_lock
);
1003 stat76
= snd_ca0106_ptr_read(chip
, EXTENDED_INT
, 0);
1004 //snd_printk("interrupt status = 0x%08x, stat76=0x%08x\n", status, stat76);
1005 //snd_printk("ptr=0x%08x\n",snd_ca0106_ptr_read(chip, PLAYBACK_POINTER, 0));
1006 mask
= 0x11; /* 0x1 for one half, 0x10 for the other half period. */
1007 for(i
= 0; i
< 4; i
++) {
1008 pchannel
= &(chip
->playback_channels
[i
]);
1010 /* FIXME: Select the correct substream for period elapsed */
1012 snd_pcm_period_elapsed(pchannel
->epcm
->substream
);
1013 //printk(KERN_INFO "interrupt [%d] used\n", i);
1016 //printk(KERN_INFO "channel=%p\n",pchannel);
1017 //printk(KERN_INFO "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number);
1020 mask
= 0x110000; /* 0x1 for one half, 0x10 for the other half period. */
1021 for(i
= 0; i
< 4; i
++) {
1022 pchannel
= &(chip
->capture_channels
[i
]);
1024 /* FIXME: Select the correct substream for period elapsed */
1026 snd_pcm_period_elapsed(pchannel
->epcm
->substream
);
1027 //printk(KERN_INFO "interrupt [%d] used\n", i);
1030 //printk(KERN_INFO "channel=%p\n",pchannel);
1031 //printk(KERN_INFO "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number);
1035 snd_ca0106_ptr_write(chip
, EXTENDED_INT
, 0, stat76
);
1036 spin_lock(&chip
->emu_lock
);
1037 // acknowledge the interrupt if necessary
1038 outl(status
, chip
->port
+IPR
);
1040 spin_unlock(&chip
->emu_lock
);
1045 static void snd_ca0106_pcm_free(snd_pcm_t
*pcm
)
1047 ca0106_t
*emu
= pcm
->private_data
;
1049 snd_pcm_lib_preallocate_free_for_all(pcm
);
1052 static int __devinit
snd_ca0106_pcm(ca0106_t
*emu
, int device
, snd_pcm_t
**rpcm
)
1055 snd_pcm_substream_t
*substream
;
1060 if ((err
= snd_pcm_new(emu
->card
, "ca0106", device
, 1, 1, &pcm
)) < 0)
1063 pcm
->private_data
= emu
;
1064 pcm
->private_free
= snd_ca0106_pcm_free
;
1068 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ca0106_playback_front_ops
);
1069 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_ca0106_capture_0_ops
);
1072 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ca0106_playback_rear_ops
);
1073 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_ca0106_capture_1_ops
);
1076 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ca0106_playback_center_lfe_ops
);
1077 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_ca0106_capture_2_ops
);
1080 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ca0106_playback_unknown_ops
);
1081 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_ca0106_capture_3_ops
);
1085 pcm
->info_flags
= 0;
1086 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
1087 strcpy(pcm
->name
, "CA0106");
1090 for(substream
= pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
;
1092 substream
= substream
->next
) {
1093 if ((err
= snd_pcm_lib_preallocate_pages(substream
,
1095 snd_dma_pci_data(emu
->pci
),
1096 64*1024, 64*1024)) < 0) /* FIXME: 32*1024 for sound buffer, between 32and64 for Periods table. */
1100 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
;
1102 substream
= substream
->next
) {
1103 if ((err
= snd_pcm_lib_preallocate_pages(substream
,
1105 snd_dma_pci_data(emu
->pci
),
1106 64*1024, 64*1024)) < 0)
1116 static int __devinit
snd_ca0106_create(snd_card_t
*card
,
1117 struct pci_dev
*pci
,
1121 ca0106_details_t
*c
;
1124 static snd_device_ops_t ops
= {
1125 .dev_free
= snd_ca0106_dev_free
,
1130 if ((err
= pci_enable_device(pci
)) < 0)
1132 if (pci_set_dma_mask(pci
, DMA_32BIT_MASK
) < 0 ||
1133 pci_set_consistent_dma_mask(pci
, DMA_32BIT_MASK
) < 0) {
1134 printk(KERN_ERR
"error to set 32bit mask DMA\n");
1135 pci_disable_device(pci
);
1139 chip
= kcalloc(1, sizeof(*chip
), GFP_KERNEL
);
1141 pci_disable_device(pci
);
1149 spin_lock_init(&chip
->emu_lock
);
1151 chip
->port
= pci_resource_start(pci
, 0);
1152 if ((chip
->res_port
= request_region(chip
->port
, 0x20,
1153 "snd_ca0106")) == NULL
) {
1154 snd_ca0106_free(chip
);
1155 printk(KERN_ERR
"cannot allocate the port\n");
1159 if (request_irq(pci
->irq
, snd_ca0106_interrupt
,
1160 SA_INTERRUPT
|SA_SHIRQ
, "snd_ca0106",
1162 snd_ca0106_free(chip
);
1163 printk(KERN_ERR
"cannot grab irq\n");
1166 chip
->irq
= pci
->irq
;
1168 /* This stores the periods table. */
1169 if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
), 1024, &chip
->buffer
) < 0) {
1170 snd_ca0106_free(chip
);
1174 pci_set_master(pci
);
1175 /* read revision & serial */
1176 pci_read_config_byte(pci
, PCI_REVISION_ID
, (char *)&chip
->revision
);
1177 pci_read_config_dword(pci
, PCI_SUBSYSTEM_VENDOR_ID
, &chip
->serial
);
1178 pci_read_config_word(pci
, PCI_SUBSYSTEM_ID
, &chip
->model
);
1180 printk(KERN_INFO
"Model %04x Rev %08x Serial %08x\n", chip
->model
,
1181 chip
->revision
, chip
->serial
);
1183 strcpy(card
->driver
, "CA0106");
1184 strcpy(card
->shortname
, "CA0106");
1186 for (c
=ca0106_chip_details
; c
->serial
; c
++) {
1187 if (c
->serial
== chip
->serial
) break;
1190 sprintf(card
->longname
, "%s at 0x%lx irq %i",
1191 c
->name
, chip
->port
, chip
->irq
);
1193 outl(0, chip
->port
+ INTE
);
1196 * Init to 0x02109204 :
1197 * Clock accuracy = 0 (1000ppm)
1198 * Sample Rate = 2 (48kHz)
1199 * Audio Channel = 1 (Left of 2)
1200 * Source Number = 0 (Unspecified)
1201 * Generation Status = 1 (Original for Cat Code 12)
1202 * Cat Code = 12 (Digital Signal Mixer)
1204 * Emphasis = 0 (None)
1205 * CP = 1 (Copyright unasserted)
1206 * AN = 0 (Audio data)
1209 snd_ca0106_ptr_write(chip
, SPCS0
, 0,
1210 chip
->spdif_bits
[0] =
1211 SPCS_CLKACCY_1000PPM
| SPCS_SAMPLERATE_48
|
1212 SPCS_CHANNELNUM_LEFT
| SPCS_SOURCENUM_UNSPEC
|
1213 SPCS_GENERATIONSTATUS
| 0x00001200 |
1214 0x00000000 | SPCS_EMPHASIS_NONE
| SPCS_COPYRIGHT
);
1215 /* Only SPCS1 has been tested */
1216 snd_ca0106_ptr_write(chip
, SPCS1
, 0,
1217 chip
->spdif_bits
[1] =
1218 SPCS_CLKACCY_1000PPM
| SPCS_SAMPLERATE_48
|
1219 SPCS_CHANNELNUM_LEFT
| SPCS_SOURCENUM_UNSPEC
|
1220 SPCS_GENERATIONSTATUS
| 0x00001200 |
1221 0x00000000 | SPCS_EMPHASIS_NONE
| SPCS_COPYRIGHT
);
1222 snd_ca0106_ptr_write(chip
, SPCS2
, 0,
1223 chip
->spdif_bits
[2] =
1224 SPCS_CLKACCY_1000PPM
| SPCS_SAMPLERATE_48
|
1225 SPCS_CHANNELNUM_LEFT
| SPCS_SOURCENUM_UNSPEC
|
1226 SPCS_GENERATIONSTATUS
| 0x00001200 |
1227 0x00000000 | SPCS_EMPHASIS_NONE
| SPCS_COPYRIGHT
);
1228 snd_ca0106_ptr_write(chip
, SPCS3
, 0,
1229 chip
->spdif_bits
[3] =
1230 SPCS_CLKACCY_1000PPM
| SPCS_SAMPLERATE_48
|
1231 SPCS_CHANNELNUM_LEFT
| SPCS_SOURCENUM_UNSPEC
|
1232 SPCS_GENERATIONSTATUS
| 0x00001200 |
1233 0x00000000 | SPCS_EMPHASIS_NONE
| SPCS_COPYRIGHT
);
1235 snd_ca0106_ptr_write(chip
, PLAYBACK_MUTE
, 0, 0x00fc0000);
1236 snd_ca0106_ptr_write(chip
, CAPTURE_MUTE
, 0, 0x00fc0000);
1238 /* Write 0x8000 to AC97_REC_GAIN to mute it. */
1239 outb(AC97_REC_GAIN
, chip
->port
+ AC97ADDRESS
);
1240 outw(0x8000, chip
->port
+ AC97DATA
);
1242 snd_ca0106_ptr_write(chip
, SPCS0
, 0, 0x2108006);
1243 snd_ca0106_ptr_write(chip
, 0x42, 0, 0x2108006);
1244 snd_ca0106_ptr_write(chip
, 0x43, 0, 0x2108006);
1245 snd_ca0106_ptr_write(chip
, 0x44, 0, 0x2108006);
1248 //snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0xf0f003f); /* OSS drivers set this. */
1249 /* Analog or Digital output */
1250 snd_ca0106_ptr_write(chip
, SPDIF_SELECT1
, 0, 0xf);
1251 snd_ca0106_ptr_write(chip
, SPDIF_SELECT2
, 0, 0x000f0000); /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers. Use 0x000f0000 for surround71 */
1252 chip
->spdif_enable
= 0; /* Set digital SPDIF output off */
1253 chip
->capture_source
= 3; /* Set CAPTURE_SOURCE */
1254 //snd_ca0106_ptr_write(chip, 0x45, 0, 0); /* Analogue out */
1255 //snd_ca0106_ptr_write(chip, 0x45, 0, 0xf00); /* Digital out */
1257 snd_ca0106_ptr_write(chip
, CAPTURE_CONTROL
, 0, 0x40c81000); /* goes to 0x40c80000 when doing SPDIF IN/OUT */
1258 snd_ca0106_ptr_write(chip
, CAPTURE_CONTROL
, 1, 0xffffffff); /* (Mute) CAPTURE feedback into PLAYBACK volume. Only lower 16 bits matter. */
1259 snd_ca0106_ptr_write(chip
, CAPTURE_CONTROL
, 2, 0x30300000); /* SPDIF IN Volume */
1260 snd_ca0106_ptr_write(chip
, CAPTURE_CONTROL
, 3, 0x00700000); /* SPDIF IN Volume, 0x70 = (vol & 0x3f) | 0x40 */
1261 snd_ca0106_ptr_write(chip
, PLAYBACK_ROUTING1
, 0, 0x32765410);
1262 snd_ca0106_ptr_write(chip
, PLAYBACK_ROUTING2
, 0, 0x76767676);
1263 snd_ca0106_ptr_write(chip
, CAPTURE_ROUTING1
, 0, 0x32765410);
1264 snd_ca0106_ptr_write(chip
, CAPTURE_ROUTING2
, 0, 0x76767676);
1265 for(ch
= 0; ch
< 4; ch
++) {
1266 snd_ca0106_ptr_write(chip
, CAPTURE_VOLUME1
, ch
, 0x30303030); /* Only high 16 bits matter */
1267 snd_ca0106_ptr_write(chip
, CAPTURE_VOLUME2
, ch
, 0x30303030);
1268 //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0x40404040); /* Mute */
1269 //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0x40404040); /* Mute */
1270 snd_ca0106_ptr_write(chip
, PLAYBACK_VOLUME1
, ch
, 0xffffffff); /* Mute */
1271 snd_ca0106_ptr_write(chip
, PLAYBACK_VOLUME2
, ch
, 0xffffffff); /* Mute */
1273 snd_ca0106_ptr_write(chip
, CAPTURE_SOURCE
, 0x0, 0x333300e4); /* Select MIC, Line in, TAD in, AUX in */
1274 chip
->capture_source
= 3; /* Set CAPTURE_SOURCE */
1276 if (chip
->details
->gpio_type
== 1) { /* The SB0410 and SB0413 use GPIO differently. */
1277 /* FIXME: Still need to find out what the other GPIO bits do. E.g. For digital spdif out. */
1278 outl(0x0, chip
->port
+GPIO
);
1279 //outl(0x00f0e000, chip->port+GPIO); /* Analog */
1280 outl(0x005f5301, chip
->port
+GPIO
); /* Analog */
1282 outl(0x0, chip
->port
+GPIO
);
1283 outl(0x005f03a3, chip
->port
+GPIO
); /* Analog */
1284 //outl(0x005f02a2, chip->port+GPIO); /* SPDIF */
1286 snd_ca0106_intr_enable(chip
, 0x105); /* Win2000 uses 0x1e0 */
1288 //outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG);
1289 //outl(0x00001409, chip->port+HCFG); /* 0x1000 causes AC3 to fails. Maybe it effects 24 bit output. */
1290 //outl(0x00000009, chip->port+HCFG);
1291 outl(HCFG_AC97
| HCFG_AUDIOENABLE
, chip
->port
+HCFG
); /* AC97 2.0, Enable outputs. */
1293 if (chip
->details
->i2c_adc
== 1) { /* The SB0410 and SB0413 use I2C to control ADC. */
1294 snd_ca0106_i2c_write(chip
, ADC_MUX
, ADC_MUX_LINEIN
); /* Enable Line-in capture. MIC in currently untested. */
1297 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
,
1299 snd_ca0106_free(chip
);
1306 static int __devinit
snd_ca0106_probe(struct pci_dev
*pci
,
1307 const struct pci_device_id
*pci_id
)
1314 if (dev
>= SNDRV_CARDS
)
1321 card
= snd_card_new(index
[dev
], id
[dev
], THIS_MODULE
, 0);
1325 if ((err
= snd_ca0106_create(card
, pci
, &chip
)) < 0) {
1326 snd_card_free(card
);
1330 if ((err
= snd_ca0106_pcm(chip
, 0, NULL
)) < 0) {
1331 snd_card_free(card
);
1334 if ((err
= snd_ca0106_pcm(chip
, 1, NULL
)) < 0) {
1335 snd_card_free(card
);
1338 if ((err
= snd_ca0106_pcm(chip
, 2, NULL
)) < 0) {
1339 snd_card_free(card
);
1342 if ((err
= snd_ca0106_pcm(chip
, 3, NULL
)) < 0) {
1343 snd_card_free(card
);
1346 if (chip
->details
->ac97
== 1) { /* The SB0410 and SB0413 do not have an AC97 chip. */
1347 if ((err
= snd_ca0106_ac97(chip
)) < 0) {
1348 snd_card_free(card
);
1352 if ((err
= snd_ca0106_mixer(chip
)) < 0) {
1353 snd_card_free(card
);
1357 snd_ca0106_proc_init(chip
);
1359 if ((err
= snd_card_register(card
)) < 0) {
1360 snd_card_free(card
);
1364 pci_set_drvdata(pci
, card
);
1369 static void __devexit
snd_ca0106_remove(struct pci_dev
*pci
)
1371 snd_card_free(pci_get_drvdata(pci
));
1372 pci_set_drvdata(pci
, NULL
);
1376 static struct pci_device_id snd_ca0106_ids
[] = {
1377 { 0x1102, 0x0007, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 }, /* Audigy LS or Live 24bit */
1380 MODULE_DEVICE_TABLE(pci
, snd_ca0106_ids
);
1382 // pci_driver definition
1383 static struct pci_driver driver
= {
1385 .id_table
= snd_ca0106_ids
,
1386 .probe
= snd_ca0106_probe
,
1387 .remove
= __devexit_p(snd_ca0106_remove
),
1390 // initialization of the module
1391 static int __init
alsa_card_ca0106_init(void)
1395 if ((err
= pci_register_driver(&driver
)) > 0)
1401 // clean up the module
1402 static void __exit
alsa_card_ca0106_exit(void)
1404 pci_unregister_driver(&driver
);
1407 module_init(alsa_card_ca0106_init
)
1408 module_exit(alsa_card_ca0106_exit
)