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 * See ca0106_main.c for features.
10 * Support interrupts per period.
11 * Removed noise from Center/LFE channel when in Analog mode.
12 * Rename and remove mixer controls.
14 * Use separate card based DMA buffer for periods table list.
16 * Change remove and rename ctrls into lists.
18 * Try to fix capture sources.
21 * Enable S32_LE format support.
23 * Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".)
25 * Add Model name recognition.
27 * Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period.
28 * Remove redundent "voice" handling.
30 * Single trigger call for multi channels.
32 * Set limits based on what the sound card hardware can do.
33 * playback periods_min=2, periods_max=8
34 * capture hw constraints require period_size = n * 64 bytes.
35 * playback hw constraints require period_size = n * 64 bytes.
37 * Separate ca0106.c into separate functional .c files.
39 * Modified Copyright message.
41 * Add iec958 file in proc file system to show status of SPDIF in.
43 * Implement support for Line-in capture on SB Live 24bit.
45 * This code was initally based on code from ALSA's emu10k1x.c which is:
46 * Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
48 * This program is free software; you can redistribute it and/or modify
49 * it under the terms of the GNU General Public License as published by
50 * the Free Software Foundation; either version 2 of the License, or
51 * (at your option) any later version.
53 * This program is distributed in the hope that it will be useful,
54 * but WITHOUT ANY WARRANTY; without even the implied warranty of
55 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56 * GNU General Public License for more details.
58 * You should have received a copy of the GNU General Public License
59 * along with this program; if not, write to the Free Software
60 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
63 #include <sound/driver.h>
64 #include <linux/delay.h>
65 #include <linux/init.h>
66 #include <linux/interrupt.h>
67 #include <linux/slab.h>
68 #include <linux/moduleparam.h>
69 #include <sound/core.h>
70 #include <sound/initval.h>
71 #include <sound/pcm.h>
72 #include <sound/ac97_codec.h>
73 #include <sound/info.h>
74 #include <sound/asoundef.h>
82 struct snd_ca0106_category_str
{
87 static struct snd_ca0106_category_str snd_ca0106_con_category
[] = {
88 { IEC958_AES1_CON_DAT
, "DAT" },
89 { IEC958_AES1_CON_VCR
, "VCR" },
90 { IEC958_AES1_CON_MICROPHONE
, "microphone" },
91 { IEC958_AES1_CON_SYNTHESIZER
, "synthesizer" },
92 { IEC958_AES1_CON_RATE_CONVERTER
, "rate converter" },
93 { IEC958_AES1_CON_MIXER
, "mixer" },
94 { IEC958_AES1_CON_SAMPLER
, "sampler" },
95 { IEC958_AES1_CON_PCM_CODER
, "PCM coder" },
96 { IEC958_AES1_CON_IEC908_CD
, "CD" },
97 { IEC958_AES1_CON_NON_IEC908_CD
, "non-IEC908 CD" },
98 { IEC958_AES1_CON_GENERAL
, "general" },
102 static void snd_ca0106_proc_dump_iec958( struct snd_info_buffer
*buffer
, u32 value
)
106 status
[0] = value
& 0xff;
107 status
[1] = (value
>> 8) & 0xff;
108 status
[2] = (value
>> 16) & 0xff;
109 status
[3] = (value
>> 24) & 0xff;
111 if (! (status
[0] & IEC958_AES0_PROFESSIONAL
)) {
113 snd_iprintf(buffer
, "Mode: consumer\n");
114 snd_iprintf(buffer
, "Data: ");
115 if (!(status
[0] & IEC958_AES0_NONAUDIO
)) {
116 snd_iprintf(buffer
, "audio\n");
118 snd_iprintf(buffer
, "non-audio\n");
120 snd_iprintf(buffer
, "Rate: ");
121 switch (status
[3] & IEC958_AES3_CON_FS
) {
122 case IEC958_AES3_CON_FS_44100
:
123 snd_iprintf(buffer
, "44100 Hz\n");
125 case IEC958_AES3_CON_FS_48000
:
126 snd_iprintf(buffer
, "48000 Hz\n");
128 case IEC958_AES3_CON_FS_32000
:
129 snd_iprintf(buffer
, "32000 Hz\n");
132 snd_iprintf(buffer
, "unknown\n");
135 snd_iprintf(buffer
, "Copyright: ");
136 if (status
[0] & IEC958_AES0_CON_NOT_COPYRIGHT
) {
137 snd_iprintf(buffer
, "permitted\n");
139 snd_iprintf(buffer
, "protected\n");
141 snd_iprintf(buffer
, "Emphasis: ");
142 if ((status
[0] & IEC958_AES0_CON_EMPHASIS
) != IEC958_AES0_CON_EMPHASIS_5015
) {
143 snd_iprintf(buffer
, "none\n");
145 snd_iprintf(buffer
, "50/15us\n");
147 snd_iprintf(buffer
, "Category: ");
148 for (i
= 0; i
< ARRAY_SIZE(snd_ca0106_con_category
); i
++) {
149 if ((status
[1] & IEC958_AES1_CON_CATEGORY
) == snd_ca0106_con_category
[i
].val
) {
150 snd_iprintf(buffer
, "%s\n", snd_ca0106_con_category
[i
].name
);
154 if (i
>= ARRAY_SIZE(snd_ca0106_con_category
)) {
155 snd_iprintf(buffer
, "unknown 0x%x\n", status
[1] & IEC958_AES1_CON_CATEGORY
);
157 snd_iprintf(buffer
, "Original: ");
158 if (status
[1] & IEC958_AES1_CON_ORIGINAL
) {
159 snd_iprintf(buffer
, "original\n");
161 snd_iprintf(buffer
, "1st generation\n");
163 snd_iprintf(buffer
, "Clock: ");
164 switch (status
[3] & IEC958_AES3_CON_CLOCK
) {
165 case IEC958_AES3_CON_CLOCK_1000PPM
:
166 snd_iprintf(buffer
, "1000 ppm\n");
168 case IEC958_AES3_CON_CLOCK_50PPM
:
169 snd_iprintf(buffer
, "50 ppm\n");
171 case IEC958_AES3_CON_CLOCK_VARIABLE
:
172 snd_iprintf(buffer
, "variable pitch\n");
175 snd_iprintf(buffer
, "unknown\n");
179 snd_iprintf(buffer
, "Mode: professional\n");
180 snd_iprintf(buffer
, "Data: ");
181 if (!(status
[0] & IEC958_AES0_NONAUDIO
)) {
182 snd_iprintf(buffer
, "audio\n");
184 snd_iprintf(buffer
, "non-audio\n");
186 snd_iprintf(buffer
, "Rate: ");
187 switch (status
[0] & IEC958_AES0_PRO_FS
) {
188 case IEC958_AES0_PRO_FS_44100
:
189 snd_iprintf(buffer
, "44100 Hz\n");
191 case IEC958_AES0_PRO_FS_48000
:
192 snd_iprintf(buffer
, "48000 Hz\n");
194 case IEC958_AES0_PRO_FS_32000
:
195 snd_iprintf(buffer
, "32000 Hz\n");
198 snd_iprintf(buffer
, "unknown\n");
201 snd_iprintf(buffer
, "Rate Locked: ");
202 if (status
[0] & IEC958_AES0_PRO_FREQ_UNLOCKED
)
203 snd_iprintf(buffer
, "no\n");
205 snd_iprintf(buffer
, "yes\n");
206 snd_iprintf(buffer
, "Emphasis: ");
207 switch (status
[0] & IEC958_AES0_PRO_EMPHASIS
) {
208 case IEC958_AES0_PRO_EMPHASIS_CCITT
:
209 snd_iprintf(buffer
, "CCITT J.17\n");
211 case IEC958_AES0_PRO_EMPHASIS_NONE
:
212 snd_iprintf(buffer
, "none\n");
214 case IEC958_AES0_PRO_EMPHASIS_5015
:
215 snd_iprintf(buffer
, "50/15us\n");
217 case IEC958_AES0_PRO_EMPHASIS_NOTID
:
219 snd_iprintf(buffer
, "unknown\n");
222 snd_iprintf(buffer
, "Stereophonic: ");
223 if ((status
[1] & IEC958_AES1_PRO_MODE
) == IEC958_AES1_PRO_MODE_STEREOPHONIC
) {
224 snd_iprintf(buffer
, "stereo\n");
226 snd_iprintf(buffer
, "not indicated\n");
228 snd_iprintf(buffer
, "Userbits: ");
229 switch (status
[1] & IEC958_AES1_PRO_USERBITS
) {
230 case IEC958_AES1_PRO_USERBITS_192
:
231 snd_iprintf(buffer
, "192bit\n");
233 case IEC958_AES1_PRO_USERBITS_UDEF
:
234 snd_iprintf(buffer
, "user-defined\n");
237 snd_iprintf(buffer
, "unkown\n");
240 snd_iprintf(buffer
, "Sample Bits: ");
241 switch (status
[2] & IEC958_AES2_PRO_SBITS
) {
242 case IEC958_AES2_PRO_SBITS_20
:
243 snd_iprintf(buffer
, "20 bit\n");
245 case IEC958_AES2_PRO_SBITS_24
:
246 snd_iprintf(buffer
, "24 bit\n");
248 case IEC958_AES2_PRO_SBITS_UDEF
:
249 snd_iprintf(buffer
, "user defined\n");
252 snd_iprintf(buffer
, "unknown\n");
255 snd_iprintf(buffer
, "Word Length: ");
256 switch (status
[2] & IEC958_AES2_PRO_WORDLEN
) {
257 case IEC958_AES2_PRO_WORDLEN_22_18
:
258 snd_iprintf(buffer
, "22 bit or 18 bit\n");
260 case IEC958_AES2_PRO_WORDLEN_23_19
:
261 snd_iprintf(buffer
, "23 bit or 19 bit\n");
263 case IEC958_AES2_PRO_WORDLEN_24_20
:
264 snd_iprintf(buffer
, "24 bit or 20 bit\n");
266 case IEC958_AES2_PRO_WORDLEN_20_16
:
267 snd_iprintf(buffer
, "20 bit or 16 bit\n");
270 snd_iprintf(buffer
, "unknown\n");
276 static void snd_ca0106_proc_iec958(struct snd_info_entry
*entry
,
277 struct snd_info_buffer
*buffer
)
279 struct snd_ca0106
*emu
= entry
->private_data
;
282 value
= snd_ca0106_ptr_read(emu
, SAMPLE_RATE_TRACKER_STATUS
, 0);
283 snd_iprintf(buffer
, "Status: %s, %s, %s\n",
284 (value
& 0x100000) ? "Rate Locked" : "Not Rate Locked",
285 (value
& 0x200000) ? "SPDIF Locked" : "No SPDIF Lock",
286 (value
& 0x400000) ? "Audio Valid" : "No valid audio" );
287 snd_iprintf(buffer
, "Estimated sample rate: %u\n",
288 ((value
& 0xfffff) * 48000) / 0x8000 );
289 if (value
& 0x200000) {
290 snd_iprintf(buffer
, "IEC958/SPDIF input status:\n");
291 value
= snd_ca0106_ptr_read(emu
, SPDIF_INPUT_STATUS
, 0);
292 snd_ca0106_proc_dump_iec958(buffer
, value
);
295 snd_iprintf(buffer
, "\n");
298 static void snd_ca0106_proc_reg_write32(struct snd_info_entry
*entry
,
299 struct snd_info_buffer
*buffer
)
301 struct snd_ca0106
*emu
= entry
->private_data
;
305 while (!snd_info_get_line(buffer
, line
, sizeof(line
))) {
306 if (sscanf(line
, "%x %x", ®
, &val
) != 2)
308 if ((reg
< 0x40) && (reg
>=0) && (val
<= 0xffffffff) ) {
309 spin_lock_irqsave(&emu
->emu_lock
, flags
);
310 outl(val
, emu
->port
+ (reg
& 0xfffffffc));
311 spin_unlock_irqrestore(&emu
->emu_lock
, flags
);
316 static void snd_ca0106_proc_reg_read32(struct snd_info_entry
*entry
,
317 struct snd_info_buffer
*buffer
)
319 struct snd_ca0106
*emu
= entry
->private_data
;
323 snd_iprintf(buffer
, "Registers:\n\n");
324 for(i
= 0; i
< 0x20; i
+=4) {
325 spin_lock_irqsave(&emu
->emu_lock
, flags
);
326 value
= inl(emu
->port
+ i
);
327 spin_unlock_irqrestore(&emu
->emu_lock
, flags
);
328 snd_iprintf(buffer
, "Register %02X: %08lX\n", i
, value
);
332 static void snd_ca0106_proc_reg_read16(struct snd_info_entry
*entry
,
333 struct snd_info_buffer
*buffer
)
335 struct snd_ca0106
*emu
= entry
->private_data
;
339 snd_iprintf(buffer
, "Registers:\n\n");
340 for(i
= 0; i
< 0x20; i
+=2) {
341 spin_lock_irqsave(&emu
->emu_lock
, flags
);
342 value
= inw(emu
->port
+ i
);
343 spin_unlock_irqrestore(&emu
->emu_lock
, flags
);
344 snd_iprintf(buffer
, "Register %02X: %04X\n", i
, value
);
348 static void snd_ca0106_proc_reg_read8(struct snd_info_entry
*entry
,
349 struct snd_info_buffer
*buffer
)
351 struct snd_ca0106
*emu
= entry
->private_data
;
355 snd_iprintf(buffer
, "Registers:\n\n");
356 for(i
= 0; i
< 0x20; i
+=1) {
357 spin_lock_irqsave(&emu
->emu_lock
, flags
);
358 value
= inb(emu
->port
+ i
);
359 spin_unlock_irqrestore(&emu
->emu_lock
, flags
);
360 snd_iprintf(buffer
, "Register %02X: %02X\n", i
, value
);
364 static void snd_ca0106_proc_reg_read1(struct snd_info_entry
*entry
,
365 struct snd_info_buffer
*buffer
)
367 struct snd_ca0106
*emu
= entry
->private_data
;
371 snd_iprintf(buffer
, "Registers\n");
372 for(i
= 0; i
< 0x40; i
++) {
373 snd_iprintf(buffer
, "%02X: ",i
);
374 for (j
= 0; j
< 4; j
++) {
375 value
= snd_ca0106_ptr_read(emu
, i
, j
);
376 snd_iprintf(buffer
, "%08lX ", value
);
378 snd_iprintf(buffer
, "\n");
382 static void snd_ca0106_proc_reg_read2(struct snd_info_entry
*entry
,
383 struct snd_info_buffer
*buffer
)
385 struct snd_ca0106
*emu
= entry
->private_data
;
389 snd_iprintf(buffer
, "Registers\n");
390 for(i
= 0x40; i
< 0x80; i
++) {
391 snd_iprintf(buffer
, "%02X: ",i
);
392 for (j
= 0; j
< 4; j
++) {
393 value
= snd_ca0106_ptr_read(emu
, i
, j
);
394 snd_iprintf(buffer
, "%08lX ", value
);
396 snd_iprintf(buffer
, "\n");
400 static void snd_ca0106_proc_reg_write(struct snd_info_entry
*entry
,
401 struct snd_info_buffer
*buffer
)
403 struct snd_ca0106
*emu
= entry
->private_data
;
405 unsigned int reg
, channel_id
, val
;
406 while (!snd_info_get_line(buffer
, line
, sizeof(line
))) {
407 if (sscanf(line
, "%x %x %x", ®
, &channel_id
, &val
) != 3)
409 if ((reg
< 0x80) && (reg
>=0) && (val
<= 0xffffffff) && (channel_id
>=0) && (channel_id
<= 3) )
410 snd_ca0106_ptr_write(emu
, reg
, channel_id
, val
);
414 static void snd_ca0106_proc_i2c_write(struct snd_info_entry
*entry
,
415 struct snd_info_buffer
*buffer
)
417 struct snd_ca0106
*emu
= entry
->private_data
;
419 unsigned int reg
, val
;
420 while (!snd_info_get_line(buffer
, line
, sizeof(line
))) {
421 if (sscanf(line
, "%x %x", ®
, &val
) != 2)
423 if ((reg
<= 0x7f) || (val
<= 0x1ff)) {
424 snd_ca0106_i2c_write(emu
, reg
, val
);
429 int __devinit
snd_ca0106_proc_init(struct snd_ca0106
* emu
)
431 struct snd_info_entry
*entry
;
433 if(! snd_card_proc_new(emu
->card
, "iec958", &entry
))
434 snd_info_set_text_ops(entry
, emu
, snd_ca0106_proc_iec958
);
435 if(! snd_card_proc_new(emu
->card
, "ca0106_reg32", &entry
)) {
436 snd_info_set_text_ops(entry
, emu
, snd_ca0106_proc_reg_read32
);
437 entry
->c
.text
.write
= snd_ca0106_proc_reg_write32
;
438 entry
->mode
|= S_IWUSR
;
440 if(! snd_card_proc_new(emu
->card
, "ca0106_reg16", &entry
))
441 snd_info_set_text_ops(entry
, emu
, snd_ca0106_proc_reg_read16
);
442 if(! snd_card_proc_new(emu
->card
, "ca0106_reg8", &entry
))
443 snd_info_set_text_ops(entry
, emu
, snd_ca0106_proc_reg_read8
);
444 if(! snd_card_proc_new(emu
->card
, "ca0106_regs1", &entry
)) {
445 snd_info_set_text_ops(entry
, emu
, snd_ca0106_proc_reg_read1
);
446 entry
->c
.text
.write
= snd_ca0106_proc_reg_write
;
447 entry
->mode
|= S_IWUSR
;
448 // entry->private_data = emu;
450 if(! snd_card_proc_new(emu
->card
, "ca0106_i2c", &entry
)) {
451 snd_info_set_text_ops(entry
, emu
, snd_ca0106_proc_i2c_write
);
452 entry
->c
.text
.write
= snd_ca0106_proc_i2c_write
;
453 entry
->mode
|= S_IWUSR
;
454 // entry->private_data = emu;
456 if(! snd_card_proc_new(emu
->card
, "ca0106_regs2", &entry
))
457 snd_info_set_text_ops(entry
, emu
, snd_ca0106_proc_reg_read2
);
461 #endif /* CONFIG_PROC_FS */