2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * Abramo Bagnara <abramo@alsa-project.org>
5 * Routines for control of Cirrus Logic CS461x chips
8 * - Sometimes the SPDIF input DSP tasks get's unsynchronized
9 * and the SPDIF get somewhat "distorcionated", or/and left right channel
10 * are swapped. To get around this problem when it happens, mute and unmute
11 * the SPDIF input mixer controll.
12 * - On the Hercules Game Theater XP the amplifier are sometimes turned
13 * off on inadecuate moments which causes distorcions on sound.
16 * - Secondary CODEC on some soundcards
17 * - SPDIF input support for other sample rates then 48khz
18 * - Posibility to mix the SPDIF output with analog sources.
19 * - PCM channels for Center and LFE on secondary codec
21 * NOTE: with CONFIG_SND_CS46XX_NEW_DSP unset uses old DSP image (which
22 * is default configuration), no SPDIF, no secondary codec, no
23 * multi channel PCM. But known to work.
25 * FINALLY: A credit to the developers Tom and Jordan
26 * at Cirrus for have helping me out with the DSP, however we
27 * still don't have sufficient documentation and technical
28 * references to be able to implement all fancy feutures
29 * supported by the cs46xx DSP's.
30 * Benny <benny@hostmobility.com>
32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version.
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
42 * You should have received a copy of the GNU General Public License
43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
48 #include <sound/driver.h>
49 #include <linux/delay.h>
50 #include <linux/pci.h>
52 #include <linux/init.h>
53 #include <linux/interrupt.h>
54 #include <linux/slab.h>
55 #include <linux/gameport.h>
57 #include <sound/core.h>
58 #include <sound/control.h>
59 #include <sound/info.h>
60 #include <sound/pcm.h>
61 #include <sound/pcm_params.h>
62 #include <sound/cs46xx.h>
66 #include "cs46xx_lib.h"
69 static void amp_voyetra(cs46xx_t
*chip
, int change
);
71 #ifdef CONFIG_SND_CS46XX_NEW_DSP
72 static snd_pcm_ops_t snd_cs46xx_playback_rear_ops
;
73 static snd_pcm_ops_t snd_cs46xx_playback_indirect_rear_ops
;
74 static snd_pcm_ops_t snd_cs46xx_playback_clfe_ops
;
75 static snd_pcm_ops_t snd_cs46xx_playback_indirect_clfe_ops
;
76 static snd_pcm_ops_t snd_cs46xx_playback_iec958_ops
;
77 static snd_pcm_ops_t snd_cs46xx_playback_indirect_iec958_ops
;
80 static snd_pcm_ops_t snd_cs46xx_playback_ops
;
81 static snd_pcm_ops_t snd_cs46xx_playback_indirect_ops
;
82 static snd_pcm_ops_t snd_cs46xx_capture_ops
;
83 static snd_pcm_ops_t snd_cs46xx_capture_indirect_ops
;
85 static unsigned short snd_cs46xx_codec_read(cs46xx_t
*chip
,
90 unsigned short result
,tmp
;
92 snd_assert ( (codec_index
== CS46XX_PRIMARY_CODEC_INDEX
) ||
93 (codec_index
== CS46XX_SECONDARY_CODEC_INDEX
),
96 chip
->active_ctrl(chip
, 1);
98 if (codec_index
== CS46XX_SECONDARY_CODEC_INDEX
)
99 offset
= CS46XX_SECONDARY_CODEC_OFFSET
;
102 * 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address
103 * 2. Write ACCDA = Command Data Register = 470h for data to write to AC97
104 * 3. Write ACCTL = Control Register = 460h for initiating the write7---55
105 * 4. Read ACCTL = 460h, DCV should be reset by now and 460h = 17h
106 * 5. if DCV not cleared, break and return error
107 * 6. Read ACSTS = Status Register = 464h, check VSTS bit
110 snd_cs46xx_peekBA0(chip
, BA0_ACSDA
+ offset
);
112 tmp
= snd_cs46xx_peekBA0(chip
, BA0_ACCTL
);
113 if ((tmp
& ACCTL_VFRM
) == 0) {
114 snd_printk(KERN_WARNING
"cs46xx: ACCTL_VFRM not set 0x%x\n",tmp
);
115 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL
, (tmp
& (~ACCTL_ESYN
)) | ACCTL_VFRM
);
117 tmp
= snd_cs46xx_peekBA0(chip
, BA0_ACCTL
+ offset
);
118 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL
, tmp
| ACCTL_ESYN
| ACCTL_VFRM
);
123 * Setup the AC97 control registers on the CS461x to send the
124 * appropriate command to the AC97 to perform the read.
125 * ACCAD = Command Address Register = 46Ch
126 * ACCDA = Command Data Register = 470h
127 * ACCTL = Control Register = 460h
128 * set DCV - will clear when process completed
129 * set CRW - Read command
130 * set VFRM - valid frame enabled
131 * set ESYN - ASYNC generation enabled
132 * set RSTN - ARST# inactive, AC97 codec not reset
135 snd_cs46xx_pokeBA0(chip
, BA0_ACCAD
, reg
);
136 snd_cs46xx_pokeBA0(chip
, BA0_ACCDA
, 0);
137 if (codec_index
== CS46XX_PRIMARY_CODEC_INDEX
) {
138 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL
,/* clear ACCTL_DCV */ ACCTL_CRW
|
139 ACCTL_VFRM
| ACCTL_ESYN
|
141 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL
, ACCTL_DCV
| ACCTL_CRW
|
142 ACCTL_VFRM
| ACCTL_ESYN
|
145 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL
, ACCTL_DCV
| ACCTL_TC
|
146 ACCTL_CRW
| ACCTL_VFRM
| ACCTL_ESYN
|
151 * Wait for the read to occur.
153 for (count
= 0; count
< 1000; count
++) {
155 * First, we want to wait for a short time.
159 * Now, check to see if the read has completed.
160 * ACCTL = 460h, DCV should be reset by now and 460h = 17h
162 if (!(snd_cs46xx_peekBA0(chip
, BA0_ACCTL
) & ACCTL_DCV
))
166 snd_printk("AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg
);
172 * Wait for the valid status bit to go active.
174 for (count
= 0; count
< 100; count
++) {
176 * Read the AC97 status register.
177 * ACSTS = Status Register = 464h
178 * VSTS - Valid Status
180 if (snd_cs46xx_peekBA0(chip
, BA0_ACSTS
+ offset
) & ACSTS_VSTS
)
185 snd_printk("AC'97 read problem (ACSTS_VSTS), codec_index %d, reg = 0x%x\n", codec_index
, reg
);
191 * Read the data returned from the AC97 register.
192 * ACSDA = Status Data Register = 474h
195 printk("e) reg = 0x%x, val = 0x%x, BA0_ACCAD = 0x%x\n", reg
,
196 snd_cs46xx_peekBA0(chip
, BA0_ACSDA
),
197 snd_cs46xx_peekBA0(chip
, BA0_ACCAD
));
200 //snd_cs46xx_peekBA0(chip, BA0_ACCAD);
201 result
= snd_cs46xx_peekBA0(chip
, BA0_ACSDA
+ offset
);
203 chip
->active_ctrl(chip
, -1);
207 static unsigned short snd_cs46xx_ac97_read(ac97_t
* ac97
,
210 cs46xx_t
*chip
= ac97
->private_data
;
212 int codec_index
= ac97
->num
;
214 snd_assert(codec_index
== CS46XX_PRIMARY_CODEC_INDEX
||
215 codec_index
== CS46XX_SECONDARY_CODEC_INDEX
,
218 val
= snd_cs46xx_codec_read(chip
, reg
, codec_index
);
224 static void snd_cs46xx_codec_write(cs46xx_t
*chip
,
231 snd_assert ((codec_index
== CS46XX_PRIMARY_CODEC_INDEX
) ||
232 (codec_index
== CS46XX_SECONDARY_CODEC_INDEX
),
235 chip
->active_ctrl(chip
, 1);
238 * 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address
239 * 2. Write ACCDA = Command Data Register = 470h for data to write to AC97
240 * 3. Write ACCTL = Control Register = 460h for initiating the write
241 * 4. Read ACCTL = 460h, DCV should be reset by now and 460h = 07h
242 * 5. if DCV not cleared, break and return error
246 * Setup the AC97 control registers on the CS461x to send the
247 * appropriate command to the AC97 to perform the read.
248 * ACCAD = Command Address Register = 46Ch
249 * ACCDA = Command Data Register = 470h
250 * ACCTL = Control Register = 460h
251 * set DCV - will clear when process completed
252 * reset CRW - Write command
253 * set VFRM - valid frame enabled
254 * set ESYN - ASYNC generation enabled
255 * set RSTN - ARST# inactive, AC97 codec not reset
257 snd_cs46xx_pokeBA0(chip
, BA0_ACCAD
, reg
);
258 snd_cs46xx_pokeBA0(chip
, BA0_ACCDA
, val
);
259 snd_cs46xx_peekBA0(chip
, BA0_ACCTL
);
261 if (codec_index
== CS46XX_PRIMARY_CODEC_INDEX
) {
262 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL
, /* clear ACCTL_DCV */ ACCTL_VFRM
|
263 ACCTL_ESYN
| ACCTL_RSTN
);
264 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL
, ACCTL_DCV
| ACCTL_VFRM
|
265 ACCTL_ESYN
| ACCTL_RSTN
);
267 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL
, ACCTL_DCV
| ACCTL_TC
|
268 ACCTL_VFRM
| ACCTL_ESYN
| ACCTL_RSTN
);
271 for (count
= 0; count
< 4000; count
++) {
273 * First, we want to wait for a short time.
277 * Now, check to see if the write has completed.
278 * ACCTL = 460h, DCV should be reset by now and 460h = 07h
280 if (!(snd_cs46xx_peekBA0(chip
, BA0_ACCTL
) & ACCTL_DCV
)) {
284 snd_printk("AC'97 write problem, codec_index = %d, reg = 0x%x, val = 0x%x\n", codec_index
, reg
, val
);
286 chip
->active_ctrl(chip
, -1);
289 static void snd_cs46xx_ac97_write(ac97_t
*ac97
,
293 cs46xx_t
*chip
= ac97
->private_data
;
294 int codec_index
= ac97
->num
;
296 snd_assert(codec_index
== CS46XX_PRIMARY_CODEC_INDEX
||
297 codec_index
== CS46XX_SECONDARY_CODEC_INDEX
,
300 snd_cs46xx_codec_write(chip
, reg
, val
, codec_index
);
305 * Chip initialization
308 int snd_cs46xx_download(cs46xx_t
*chip
,
310 unsigned long offset
,
314 unsigned int bank
= offset
>> 16;
315 offset
= offset
& 0xffff;
317 snd_assert(!(offset
& 3) && !(len
& 3), return -EINVAL
);
318 dst
= chip
->region
.idx
[bank
+1].remap_addr
+ offset
;
321 /* writel already converts 32-bit value to right endianess */
329 #ifdef CONFIG_SND_CS46XX_NEW_DSP
331 #include "imgs/cwc4630.h"
332 #include "imgs/cwcasync.h"
333 #include "imgs/cwcsnoop.h"
334 #include "imgs/cwcbinhack.h"
335 #include "imgs/cwcdma.h"
337 int snd_cs46xx_clear_BA1(cs46xx_t
*chip
,
338 unsigned long offset
,
342 unsigned int bank
= offset
>> 16;
343 offset
= offset
& 0xffff;
345 snd_assert(!(offset
& 3) && !(len
& 3), return -EINVAL
);
346 dst
= chip
->region
.idx
[bank
+1].remap_addr
+ offset
;
349 /* writel already converts 32-bit value to right endianess */
357 #else /* old DSP image */
359 #include "cs46xx_image.h"
361 int snd_cs46xx_download_image(cs46xx_t
*chip
)
364 unsigned long offset
= 0;
366 for (idx
= 0; idx
< BA1_MEMORY_COUNT
; idx
++) {
367 if ((err
= snd_cs46xx_download(chip
,
368 &BA1Struct
.map
[offset
],
369 BA1Struct
.memory
[idx
].offset
,
370 BA1Struct
.memory
[idx
].size
)) < 0)
372 offset
+= BA1Struct
.memory
[idx
].size
>> 2;
376 #endif /* CONFIG_SND_CS46XX_NEW_DSP */
382 static void snd_cs46xx_reset(cs46xx_t
*chip
)
387 * Write the reset bit of the SP control register.
389 snd_cs46xx_poke(chip
, BA1_SPCR
, SPCR_RSTSP
);
392 * Write the control register.
394 snd_cs46xx_poke(chip
, BA1_SPCR
, SPCR_DRQEN
);
397 * Clear the trap registers.
399 for (idx
= 0; idx
< 8; idx
++) {
400 snd_cs46xx_poke(chip
, BA1_DREG
, DREG_REGID_TRAP_SELECT
+ idx
);
401 snd_cs46xx_poke(chip
, BA1_TWPR
, 0xFFFF);
403 snd_cs46xx_poke(chip
, BA1_DREG
, 0);
406 * Set the frame timer to reflect the number of cycles per frame.
408 snd_cs46xx_poke(chip
, BA1_FRMT
, 0xadf);
411 static int cs46xx_wait_for_fifo(cs46xx_t
* chip
,int retry_timeout
)
415 * Make sure the previous FIFO write operation has completed.
417 for(i
= 0; i
< 50; i
++){
418 status
= snd_cs46xx_peekBA0(chip
, BA0_SERBST
);
420 if( !(status
& SERBST_WBSY
) )
423 mdelay(retry_timeout
);
426 if(status
& SERBST_WBSY
) {
427 snd_printk( KERN_ERR
"cs46xx: failure waiting for FIFO command to complete\n");
435 static void snd_cs46xx_clear_serial_FIFOs(cs46xx_t
*chip
)
437 int idx
, powerdown
= 0;
441 * See if the devices are powered down. If so, we must power them up first
442 * or they will not respond.
444 tmp
= snd_cs46xx_peekBA0(chip
, BA0_CLKCR1
);
445 if (!(tmp
& CLKCR1_SWCE
)) {
446 snd_cs46xx_pokeBA0(chip
, BA0_CLKCR1
, tmp
| CLKCR1_SWCE
);
451 * We want to clear out the serial port FIFOs so we don't end up playing
452 * whatever random garbage happens to be in them. We fill the sample FIFOS
453 * with zero (silence).
455 snd_cs46xx_pokeBA0(chip
, BA0_SERBWP
, 0);
458 * Fill all 256 sample FIFO locations.
460 for (idx
= 0; idx
< 0xFF; idx
++) {
462 * Make sure the previous FIFO write operation has completed.
464 if (cs46xx_wait_for_fifo(chip
,1)) {
465 snd_printdd ("failed waiting for FIFO at addr (%02X)\n",idx
);
468 snd_cs46xx_pokeBA0(chip
, BA0_CLKCR1
, tmp
);
473 * Write the serial port FIFO index.
475 snd_cs46xx_pokeBA0(chip
, BA0_SERBAD
, idx
);
477 * Tell the serial port to load the new value into the FIFO location.
479 snd_cs46xx_pokeBA0(chip
, BA0_SERBCM
, SERBCM_WRC
);
482 * Now, if we powered up the devices, then power them back down again.
483 * This is kinda ugly, but should never happen.
486 snd_cs46xx_pokeBA0(chip
, BA0_CLKCR1
, tmp
);
489 static void snd_cs46xx_proc_start(cs46xx_t
*chip
)
494 * Set the frame timer to reflect the number of cycles per frame.
496 snd_cs46xx_poke(chip
, BA1_FRMT
, 0xadf);
498 * Turn on the run, run at frame, and DMA enable bits in the local copy of
499 * the SP control register.
501 snd_cs46xx_poke(chip
, BA1_SPCR
, SPCR_RUN
| SPCR_RUNFR
| SPCR_DRQEN
);
503 * Wait until the run at frame bit resets itself in the SP control
506 for (cnt
= 0; cnt
< 25; cnt
++) {
508 if (!(snd_cs46xx_peek(chip
, BA1_SPCR
) & SPCR_RUNFR
))
512 if (snd_cs46xx_peek(chip
, BA1_SPCR
) & SPCR_RUNFR
)
513 snd_printk("SPCR_RUNFR never reset\n");
516 static void snd_cs46xx_proc_stop(cs46xx_t
*chip
)
519 * Turn off the run, run at frame, and DMA enable bits in the local copy of
520 * the SP control register.
522 snd_cs46xx_poke(chip
, BA1_SPCR
, 0);
526 * Sample rate routines
529 #define GOF_PER_SEC 200
531 static void snd_cs46xx_set_play_sample_rate(cs46xx_t
*chip
, unsigned int rate
)
534 unsigned int tmp1
, tmp2
;
535 unsigned int phiIncr
;
536 unsigned int correctionPerGOF
, correctionPerSec
;
539 * Compute the values used to drive the actual sample rate conversion.
540 * The following formulas are being computed, using inline assembly
541 * since we need to use 64 bit arithmetic to compute the values:
543 * phiIncr = floor((Fs,in * 2^26) / Fs,out)
544 * correctionPerGOF = floor((Fs,in * 2^26 - Fs,out * phiIncr) /
546 * ulCorrectionPerSec = Fs,in * 2^26 - Fs,out * phiIncr -M
547 * GOF_PER_SEC * correctionPerGOF
551 * phiIncr:other = dividend:remainder((Fs,in * 2^26) / Fs,out)
552 * correctionPerGOF:correctionPerSec =
553 * dividend:remainder(ulOther / GOF_PER_SEC)
556 phiIncr
= tmp1
/ 48000;
557 tmp1
-= phiIncr
* 48000;
562 tmp1
-= tmp2
* 48000;
563 correctionPerGOF
= tmp1
/ GOF_PER_SEC
;
564 tmp1
-= correctionPerGOF
* GOF_PER_SEC
;
565 correctionPerSec
= tmp1
;
568 * Fill in the SampleRateConverter control block.
570 spin_lock_irqsave(&chip
->reg_lock
, flags
);
571 snd_cs46xx_poke(chip
, BA1_PSRC
,
572 ((correctionPerSec
<< 16) & 0xFFFF0000) | (correctionPerGOF
& 0xFFFF));
573 snd_cs46xx_poke(chip
, BA1_PPI
, phiIncr
);
574 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
577 static void snd_cs46xx_set_capture_sample_rate(cs46xx_t
*chip
, unsigned int rate
)
580 unsigned int phiIncr
, coeffIncr
, tmp1
, tmp2
;
581 unsigned int correctionPerGOF
, correctionPerSec
, initialDelay
;
582 unsigned int frameGroupLength
, cnt
;
585 * We can only decimate by up to a factor of 1/9th the hardware rate.
586 * Correct the value if an attempt is made to stray outside that limit.
588 if ((rate
* 9) < 48000)
592 * We can not capture at at rate greater than the Input Rate (48000).
593 * Return an error if an attempt is made to stray outside that limit.
599 * Compute the values used to drive the actual sample rate conversion.
600 * The following formulas are being computed, using inline assembly
601 * since we need to use 64 bit arithmetic to compute the values:
603 * coeffIncr = -floor((Fs,out * 2^23) / Fs,in)
604 * phiIncr = floor((Fs,in * 2^26) / Fs,out)
605 * correctionPerGOF = floor((Fs,in * 2^26 - Fs,out * phiIncr) /
607 * correctionPerSec = Fs,in * 2^26 - Fs,out * phiIncr -
608 * GOF_PER_SEC * correctionPerGOF
609 * initialDelay = ceil((24 * Fs,in) / Fs,out)
613 * coeffIncr = neg(dividend((Fs,out * 2^23) / Fs,in))
614 * phiIncr:ulOther = dividend:remainder((Fs,in * 2^26) / Fs,out)
615 * correctionPerGOF:correctionPerSec =
616 * dividend:remainder(ulOther / GOF_PER_SEC)
617 * initialDelay = dividend(((24 * Fs,in) + Fs,out - 1) / Fs,out)
621 coeffIncr
= tmp1
/ 48000;
622 tmp1
-= coeffIncr
* 48000;
625 coeffIncr
+= tmp1
/ 48000;
626 coeffIncr
^= 0xFFFFFFFF;
629 phiIncr
= tmp1
/ rate
;
630 tmp1
-= phiIncr
* rate
;
636 correctionPerGOF
= tmp1
/ GOF_PER_SEC
;
637 tmp1
-= correctionPerGOF
* GOF_PER_SEC
;
638 correctionPerSec
= tmp1
;
639 initialDelay
= ((48000 * 24) + rate
- 1) / rate
;
642 * Fill in the VariDecimate control block.
644 spin_lock_irqsave(&chip
->reg_lock
, flags
);
645 snd_cs46xx_poke(chip
, BA1_CSRC
,
646 ((correctionPerSec
<< 16) & 0xFFFF0000) | (correctionPerGOF
& 0xFFFF));
647 snd_cs46xx_poke(chip
, BA1_CCI
, coeffIncr
);
648 snd_cs46xx_poke(chip
, BA1_CD
,
649 (((BA1_VARIDEC_BUF_1
+ (initialDelay
<< 2)) << 16) & 0xFFFF0000) | 0x80);
650 snd_cs46xx_poke(chip
, BA1_CPI
, phiIncr
);
651 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
654 * Figure out the frame group length for the write back task. Basically,
655 * this is just the factors of 24000 (2^6*3*5^3) that are not present in
656 * the output sample rate.
658 frameGroupLength
= 1;
659 for (cnt
= 2; cnt
<= 64; cnt
*= 2) {
660 if (((rate
/ cnt
) * cnt
) != rate
)
661 frameGroupLength
*= 2;
663 if (((rate
/ 3) * 3) != rate
) {
664 frameGroupLength
*= 3;
666 for (cnt
= 5; cnt
<= 125; cnt
*= 5) {
667 if (((rate
/ cnt
) * cnt
) != rate
)
668 frameGroupLength
*= 5;
672 * Fill in the WriteBack control block.
674 spin_lock_irqsave(&chip
->reg_lock
, flags
);
675 snd_cs46xx_poke(chip
, BA1_CFG1
, frameGroupLength
);
676 snd_cs46xx_poke(chip
, BA1_CFG2
, (0x00800000 | frameGroupLength
));
677 snd_cs46xx_poke(chip
, BA1_CCST
, 0x0000FFFF);
678 snd_cs46xx_poke(chip
, BA1_CSPB
, ((65536 * rate
) / 24000));
679 snd_cs46xx_poke(chip
, (BA1_CSPB
+ 4), 0x0000FFFF);
680 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
687 static void snd_cs46xx_pb_trans_copy(snd_pcm_substream_t
*substream
,
688 snd_pcm_indirect_t
*rec
, size_t bytes
)
690 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
691 cs46xx_pcm_t
* cpcm
= runtime
->private_data
;
692 memcpy(cpcm
->hw_buf
.area
+ rec
->hw_data
, runtime
->dma_area
+ rec
->sw_data
, bytes
);
695 static int snd_cs46xx_playback_transfer(snd_pcm_substream_t
*substream
)
697 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
698 cs46xx_pcm_t
* cpcm
= runtime
->private_data
;
699 snd_pcm_indirect_playback_transfer(substream
, &cpcm
->pcm_rec
, snd_cs46xx_pb_trans_copy
);
703 static void snd_cs46xx_cp_trans_copy(snd_pcm_substream_t
*substream
,
704 snd_pcm_indirect_t
*rec
, size_t bytes
)
706 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
707 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
708 memcpy(runtime
->dma_area
+ rec
->sw_data
,
709 chip
->capt
.hw_buf
.area
+ rec
->hw_data
, bytes
);
712 static int snd_cs46xx_capture_transfer(snd_pcm_substream_t
*substream
)
714 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
715 snd_pcm_indirect_capture_transfer(substream
, &chip
->capt
.pcm_rec
, snd_cs46xx_cp_trans_copy
);
719 static snd_pcm_uframes_t
snd_cs46xx_playback_direct_pointer(snd_pcm_substream_t
* substream
)
721 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
723 cs46xx_pcm_t
*cpcm
= substream
->runtime
->private_data
;
724 snd_assert (cpcm
->pcm_channel
,return -ENXIO
);
726 #ifdef CONFIG_SND_CS46XX_NEW_DSP
727 ptr
= snd_cs46xx_peek(chip
, (cpcm
->pcm_channel
->pcm_reader_scb
->address
+ 2) << 2);
729 ptr
= snd_cs46xx_peek(chip
, BA1_PBA
);
731 ptr
-= cpcm
->hw_buf
.addr
;
732 return ptr
>> cpcm
->shift
;
735 static snd_pcm_uframes_t
snd_cs46xx_playback_indirect_pointer(snd_pcm_substream_t
* substream
)
737 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
739 cs46xx_pcm_t
*cpcm
= substream
->runtime
->private_data
;
741 #ifdef CONFIG_SND_CS46XX_NEW_DSP
742 snd_assert (cpcm
->pcm_channel
,return -ENXIO
);
743 ptr
= snd_cs46xx_peek(chip
, (cpcm
->pcm_channel
->pcm_reader_scb
->address
+ 2) << 2);
745 ptr
= snd_cs46xx_peek(chip
, BA1_PBA
);
747 ptr
-= cpcm
->hw_buf
.addr
;
748 return snd_pcm_indirect_playback_pointer(substream
, &cpcm
->pcm_rec
, ptr
);
751 static snd_pcm_uframes_t
snd_cs46xx_capture_direct_pointer(snd_pcm_substream_t
* substream
)
753 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
754 size_t ptr
= snd_cs46xx_peek(chip
, BA1_CBA
) - chip
->capt
.hw_buf
.addr
;
755 return ptr
>> chip
->capt
.shift
;
758 static snd_pcm_uframes_t
snd_cs46xx_capture_indirect_pointer(snd_pcm_substream_t
* substream
)
760 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
761 size_t ptr
= snd_cs46xx_peek(chip
, BA1_CBA
) - chip
->capt
.hw_buf
.addr
;
762 return snd_pcm_indirect_capture_pointer(substream
, &chip
->capt
.pcm_rec
, ptr
);
765 static int snd_cs46xx_playback_trigger(snd_pcm_substream_t
* substream
,
768 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
769 /*snd_pcm_runtime_t *runtime = substream->runtime;*/
772 #ifdef CONFIG_SND_CS46XX_NEW_DSP
773 cs46xx_pcm_t
*cpcm
= substream
->runtime
->private_data
;
774 if (! cpcm
->pcm_channel
) {
779 case SNDRV_PCM_TRIGGER_START
:
780 case SNDRV_PCM_TRIGGER_RESUME
:
781 #ifdef CONFIG_SND_CS46XX_NEW_DSP
782 /* magic value to unmute PCM stream playback volume */
783 snd_cs46xx_poke(chip
, (cpcm
->pcm_channel
->pcm_reader_scb
->address
+
784 SCBVolumeCtrl
) << 2, 0x80008000);
786 if (cpcm
->pcm_channel
->unlinked
)
787 cs46xx_dsp_pcm_link(chip
,cpcm
->pcm_channel
);
789 if (substream
->runtime
->periods
!= CS46XX_FRAGS
)
790 snd_cs46xx_playback_transfer(substream
);
792 spin_lock(&chip
->reg_lock
);
793 if (substream
->runtime
->periods
!= CS46XX_FRAGS
)
794 snd_cs46xx_playback_transfer(substream
);
796 tmp
= snd_cs46xx_peek(chip
, BA1_PCTL
);
798 snd_cs46xx_poke(chip
, BA1_PCTL
, chip
->play_ctl
| tmp
);
800 spin_unlock(&chip
->reg_lock
);
803 case SNDRV_PCM_TRIGGER_STOP
:
804 case SNDRV_PCM_TRIGGER_SUSPEND
:
805 #ifdef CONFIG_SND_CS46XX_NEW_DSP
806 /* magic mute channel */
807 snd_cs46xx_poke(chip
, (cpcm
->pcm_channel
->pcm_reader_scb
->address
+
808 SCBVolumeCtrl
) << 2, 0xffffffff);
810 if (!cpcm
->pcm_channel
->unlinked
)
811 cs46xx_dsp_pcm_unlink(chip
,cpcm
->pcm_channel
);
813 spin_lock(&chip
->reg_lock
);
815 tmp
= snd_cs46xx_peek(chip
, BA1_PCTL
);
817 snd_cs46xx_poke(chip
, BA1_PCTL
, tmp
);
819 spin_unlock(&chip
->reg_lock
);
830 static int snd_cs46xx_capture_trigger(snd_pcm_substream_t
* substream
,
833 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
837 spin_lock(&chip
->reg_lock
);
839 case SNDRV_PCM_TRIGGER_START
:
840 case SNDRV_PCM_TRIGGER_RESUME
:
841 tmp
= snd_cs46xx_peek(chip
, BA1_CCTL
);
843 snd_cs46xx_poke(chip
, BA1_CCTL
, chip
->capt
.ctl
| tmp
);
845 case SNDRV_PCM_TRIGGER_STOP
:
846 case SNDRV_PCM_TRIGGER_SUSPEND
:
847 tmp
= snd_cs46xx_peek(chip
, BA1_CCTL
);
849 snd_cs46xx_poke(chip
, BA1_CCTL
, tmp
);
855 spin_unlock(&chip
->reg_lock
);
860 #ifdef CONFIG_SND_CS46XX_NEW_DSP
861 static int _cs46xx_adjust_sample_rate (cs46xx_t
*chip
, cs46xx_pcm_t
*cpcm
,
865 /* If PCMReaderSCB and SrcTaskSCB not created yet ... */
866 if ( cpcm
->pcm_channel
== NULL
) {
867 cpcm
->pcm_channel
= cs46xx_dsp_create_pcm_channel (chip
, sample_rate
,
868 cpcm
, cpcm
->hw_buf
.addr
,cpcm
->pcm_channel_id
);
869 if (cpcm
->pcm_channel
== NULL
) {
870 snd_printk(KERN_ERR
"cs46xx: failed to create virtual PCM channel\n");
873 cpcm
->pcm_channel
->sample_rate
= sample_rate
;
875 /* if sample rate is changed */
876 if ((int)cpcm
->pcm_channel
->sample_rate
!= sample_rate
) {
877 int unlinked
= cpcm
->pcm_channel
->unlinked
;
878 cs46xx_dsp_destroy_pcm_channel (chip
,cpcm
->pcm_channel
);
880 if ( (cpcm
->pcm_channel
= cs46xx_dsp_create_pcm_channel (chip
, sample_rate
, cpcm
,
882 cpcm
->pcm_channel_id
)) == NULL
) {
883 snd_printk(KERN_ERR
"cs46xx: failed to re-create virtual PCM channel\n");
887 if (!unlinked
) cs46xx_dsp_pcm_link (chip
,cpcm
->pcm_channel
);
888 cpcm
->pcm_channel
->sample_rate
= sample_rate
;
896 static int snd_cs46xx_playback_hw_params(snd_pcm_substream_t
* substream
,
897 snd_pcm_hw_params_t
* hw_params
)
899 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
902 #ifdef CONFIG_SND_CS46XX_NEW_DSP
903 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
904 int sample_rate
= params_rate(hw_params
);
905 int period_size
= params_period_bytes(hw_params
);
907 cpcm
= runtime
->private_data
;
909 #ifdef CONFIG_SND_CS46XX_NEW_DSP
910 snd_assert (sample_rate
!= 0, return -ENXIO
);
912 down (&chip
->spos_mutex
);
914 if (_cs46xx_adjust_sample_rate (chip
,cpcm
,sample_rate
)) {
915 up (&chip
->spos_mutex
);
919 snd_assert (cpcm
->pcm_channel
!= NULL
);
920 if (!cpcm
->pcm_channel
) {
921 up (&chip
->spos_mutex
);
926 if (cs46xx_dsp_pcm_channel_set_period (chip
,cpcm
->pcm_channel
,period_size
)) {
927 up (&chip
->spos_mutex
);
931 snd_printdd ("period_size (%d), periods (%d) buffer_size(%d)\n",
932 period_size
, params_periods(hw_params
),
933 params_buffer_bytes(hw_params
));
936 if (params_periods(hw_params
) == CS46XX_FRAGS
) {
937 if (runtime
->dma_area
!= cpcm
->hw_buf
.area
)
938 snd_pcm_lib_free_pages(substream
);
939 runtime
->dma_area
= cpcm
->hw_buf
.area
;
940 runtime
->dma_addr
= cpcm
->hw_buf
.addr
;
941 runtime
->dma_bytes
= cpcm
->hw_buf
.bytes
;
944 #ifdef CONFIG_SND_CS46XX_NEW_DSP
945 if (cpcm
->pcm_channel_id
== DSP_PCM_MAIN_CHANNEL
) {
946 substream
->ops
= &snd_cs46xx_playback_ops
;
947 } else if (cpcm
->pcm_channel_id
== DSP_PCM_REAR_CHANNEL
) {
948 substream
->ops
= &snd_cs46xx_playback_rear_ops
;
949 } else if (cpcm
->pcm_channel_id
== DSP_PCM_CENTER_LFE_CHANNEL
) {
950 substream
->ops
= &snd_cs46xx_playback_clfe_ops
;
951 } else if (cpcm
->pcm_channel_id
== DSP_IEC958_CHANNEL
) {
952 substream
->ops
= &snd_cs46xx_playback_iec958_ops
;
957 substream
->ops
= &snd_cs46xx_playback_ops
;
961 if (runtime
->dma_area
== cpcm
->hw_buf
.area
) {
962 runtime
->dma_area
= NULL
;
963 runtime
->dma_addr
= 0;
964 runtime
->dma_bytes
= 0;
966 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0) {
967 #ifdef CONFIG_SND_CS46XX_NEW_DSP
968 up (&chip
->spos_mutex
);
973 #ifdef CONFIG_SND_CS46XX_NEW_DSP
974 if (cpcm
->pcm_channel_id
== DSP_PCM_MAIN_CHANNEL
) {
975 substream
->ops
= &snd_cs46xx_playback_indirect_ops
;
976 } else if (cpcm
->pcm_channel_id
== DSP_PCM_REAR_CHANNEL
) {
977 substream
->ops
= &snd_cs46xx_playback_indirect_rear_ops
;
978 } else if (cpcm
->pcm_channel_id
== DSP_PCM_CENTER_LFE_CHANNEL
) {
979 substream
->ops
= &snd_cs46xx_playback_indirect_clfe_ops
;
980 } else if (cpcm
->pcm_channel_id
== DSP_IEC958_CHANNEL
) {
981 substream
->ops
= &snd_cs46xx_playback_indirect_iec958_ops
;
986 substream
->ops
= &snd_cs46xx_playback_indirect_ops
;
991 #ifdef CONFIG_SND_CS46XX_NEW_DSP
992 up (&chip
->spos_mutex
);
998 static int snd_cs46xx_playback_hw_free(snd_pcm_substream_t
* substream
)
1000 /*cs46xx_t *chip = snd_pcm_substream_chip(substream);*/
1001 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1004 cpcm
= runtime
->private_data
;
1006 /* if play_back open fails, then this function
1007 is called and cpcm can actually be NULL here */
1008 if (!cpcm
) return -ENXIO
;
1010 if (runtime
->dma_area
!= cpcm
->hw_buf
.area
)
1011 snd_pcm_lib_free_pages(substream
);
1013 runtime
->dma_area
= NULL
;
1014 runtime
->dma_addr
= 0;
1015 runtime
->dma_bytes
= 0;
1020 static int snd_cs46xx_playback_prepare(snd_pcm_substream_t
* substream
)
1024 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
1025 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1028 cpcm
= runtime
->private_data
;
1030 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1031 snd_assert (cpcm
->pcm_channel
!= NULL
, return -ENXIO
);
1033 pfie
= snd_cs46xx_peek(chip
, (cpcm
->pcm_channel
->pcm_reader_scb
->address
+ 1) << 2 );
1034 pfie
&= ~0x0000f03f;
1037 pfie
= snd_cs46xx_peek(chip
, BA1_PFIE
);
1038 pfie
&= ~0x0000f03f;
1042 /* if to convert from stereo to mono */
1043 if (runtime
->channels
== 1) {
1047 /* if to convert from 8 bit to 16 bit */
1048 if (snd_pcm_format_width(runtime
->format
) == 8) {
1052 /* if to convert to unsigned */
1053 if (snd_pcm_format_unsigned(runtime
->format
))
1056 /* Never convert byte order when sample stream is 8 bit */
1057 if (snd_pcm_format_width(runtime
->format
) != 8) {
1058 /* convert from big endian to little endian */
1059 if (snd_pcm_format_big_endian(runtime
->format
))
1063 memset(&cpcm
->pcm_rec
, 0, sizeof(cpcm
->pcm_rec
));
1064 cpcm
->pcm_rec
.sw_buffer_size
= snd_pcm_lib_buffer_bytes(substream
);
1065 cpcm
->pcm_rec
.hw_buffer_size
= runtime
->period_size
* CS46XX_FRAGS
<< cpcm
->shift
;
1067 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1069 tmp
= snd_cs46xx_peek(chip
, (cpcm
->pcm_channel
->pcm_reader_scb
->address
) << 2);
1071 tmp
|= (4 << cpcm
->shift
) - 1;
1072 /* playback transaction count register */
1073 snd_cs46xx_poke(chip
, (cpcm
->pcm_channel
->pcm_reader_scb
->address
) << 2, tmp
);
1075 /* playback format && interrupt enable */
1076 snd_cs46xx_poke(chip
, (cpcm
->pcm_channel
->pcm_reader_scb
->address
+ 1) << 2, pfie
| cpcm
->pcm_channel
->pcm_slot
);
1078 snd_cs46xx_poke(chip
, BA1_PBA
, cpcm
->hw_buf
.addr
);
1079 tmp
= snd_cs46xx_peek(chip
, BA1_PDTC
);
1081 tmp
|= (4 << cpcm
->shift
) - 1;
1082 snd_cs46xx_poke(chip
, BA1_PDTC
, tmp
);
1083 snd_cs46xx_poke(chip
, BA1_PFIE
, pfie
);
1084 snd_cs46xx_set_play_sample_rate(chip
, runtime
->rate
);
1090 static int snd_cs46xx_capture_hw_params(snd_pcm_substream_t
* substream
,
1091 snd_pcm_hw_params_t
* hw_params
)
1093 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
1094 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1097 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1098 cs46xx_dsp_pcm_ostream_set_period (chip
, params_period_bytes(hw_params
));
1100 if (runtime
->periods
== CS46XX_FRAGS
) {
1101 if (runtime
->dma_area
!= chip
->capt
.hw_buf
.area
)
1102 snd_pcm_lib_free_pages(substream
);
1103 runtime
->dma_area
= chip
->capt
.hw_buf
.area
;
1104 runtime
->dma_addr
= chip
->capt
.hw_buf
.addr
;
1105 runtime
->dma_bytes
= chip
->capt
.hw_buf
.bytes
;
1106 substream
->ops
= &snd_cs46xx_capture_ops
;
1108 if (runtime
->dma_area
== chip
->capt
.hw_buf
.area
) {
1109 runtime
->dma_area
= NULL
;
1110 runtime
->dma_addr
= 0;
1111 runtime
->dma_bytes
= 0;
1113 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
1115 substream
->ops
= &snd_cs46xx_capture_indirect_ops
;
1121 static int snd_cs46xx_capture_hw_free(snd_pcm_substream_t
* substream
)
1123 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
1124 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1126 if (runtime
->dma_area
!= chip
->capt
.hw_buf
.area
)
1127 snd_pcm_lib_free_pages(substream
);
1128 runtime
->dma_area
= NULL
;
1129 runtime
->dma_addr
= 0;
1130 runtime
->dma_bytes
= 0;
1135 static int snd_cs46xx_capture_prepare(snd_pcm_substream_t
* substream
)
1137 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
1138 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1140 snd_cs46xx_poke(chip
, BA1_CBA
, chip
->capt
.hw_buf
.addr
);
1141 chip
->capt
.shift
= 2;
1142 memset(&chip
->capt
.pcm_rec
, 0, sizeof(chip
->capt
.pcm_rec
));
1143 chip
->capt
.pcm_rec
.sw_buffer_size
= snd_pcm_lib_buffer_bytes(substream
);
1144 chip
->capt
.pcm_rec
.hw_buffer_size
= runtime
->period_size
* CS46XX_FRAGS
<< 2;
1145 snd_cs46xx_set_capture_sample_rate(chip
, runtime
->rate
);
1150 static irqreturn_t
snd_cs46xx_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1152 cs46xx_t
*chip
= dev_id
;
1154 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1155 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1158 cs46xx_pcm_t
*cpcm
= NULL
;
1162 * Read the Interrupt Status Register to clear the interrupt
1164 status1
= snd_cs46xx_peekBA0(chip
, BA0_HISR
);
1165 if ((status1
& 0x7fffffff) == 0) {
1166 snd_cs46xx_pokeBA0(chip
, BA0_HICR
, HICR_CHGM
| HICR_IEV
);
1170 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1171 status2
= snd_cs46xx_peekBA0(chip
, BA0_HSR0
);
1173 for (i
= 0; i
< DSP_MAX_PCM_CHANNELS
; ++i
) {
1175 if ( status1
& (1 << i
) ) {
1176 if (i
== CS46XX_DSP_CAPTURE_CHANNEL
) {
1177 if (chip
->capt
.substream
)
1178 snd_pcm_period_elapsed(chip
->capt
.substream
);
1180 if (ins
->pcm_channels
[i
].active
&&
1181 ins
->pcm_channels
[i
].private_data
&&
1182 !ins
->pcm_channels
[i
].unlinked
) {
1183 cpcm
= ins
->pcm_channels
[i
].private_data
;
1184 snd_pcm_period_elapsed(cpcm
->substream
);
1189 if ( status2
& (1 << (i
- 16))) {
1190 if (ins
->pcm_channels
[i
].active
&&
1191 ins
->pcm_channels
[i
].private_data
&&
1192 !ins
->pcm_channels
[i
].unlinked
) {
1193 cpcm
= ins
->pcm_channels
[i
].private_data
;
1194 snd_pcm_period_elapsed(cpcm
->substream
);
1202 if ((status1
& HISR_VC0
) && chip
->playback_pcm
) {
1203 if (chip
->playback_pcm
->substream
)
1204 snd_pcm_period_elapsed(chip
->playback_pcm
->substream
);
1206 if ((status1
& HISR_VC1
) && chip
->pcm
) {
1207 if (chip
->capt
.substream
)
1208 snd_pcm_period_elapsed(chip
->capt
.substream
);
1212 if ((status1
& HISR_MIDI
) && chip
->rmidi
) {
1215 spin_lock(&chip
->reg_lock
);
1216 while ((snd_cs46xx_peekBA0(chip
, BA0_MIDSR
) & MIDSR_RBE
) == 0) {
1217 c
= snd_cs46xx_peekBA0(chip
, BA0_MIDRP
);
1218 if ((chip
->midcr
& MIDCR_RIE
) == 0)
1220 snd_rawmidi_receive(chip
->midi_input
, &c
, 1);
1222 while ((snd_cs46xx_peekBA0(chip
, BA0_MIDSR
) & MIDSR_TBF
) == 0) {
1223 if ((chip
->midcr
& MIDCR_TIE
) == 0)
1225 if (snd_rawmidi_transmit(chip
->midi_output
, &c
, 1) != 1) {
1226 chip
->midcr
&= ~MIDCR_TIE
;
1227 snd_cs46xx_pokeBA0(chip
, BA0_MIDCR
, chip
->midcr
);
1230 snd_cs46xx_pokeBA0(chip
, BA0_MIDWP
, c
);
1232 spin_unlock(&chip
->reg_lock
);
1235 * EOI to the PCI part....reenables interrupts
1237 snd_cs46xx_pokeBA0(chip
, BA0_HICR
, HICR_CHGM
| HICR_IEV
);
1242 static snd_pcm_hardware_t snd_cs46xx_playback
=
1244 .info
= (SNDRV_PCM_INFO_MMAP
|
1245 SNDRV_PCM_INFO_INTERLEAVED
|
1246 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1247 SNDRV_PCM_INFO_RESUME
),
1248 .formats
= (SNDRV_PCM_FMTBIT_S8
| SNDRV_PCM_FMTBIT_U8
|
1249 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
|
1250 SNDRV_PCM_FMTBIT_U16_LE
| SNDRV_PCM_FMTBIT_U16_BE
),
1251 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1256 .buffer_bytes_max
= (256 * 1024),
1257 .period_bytes_min
= CS46XX_MIN_PERIOD_SIZE
,
1258 .period_bytes_max
= CS46XX_MAX_PERIOD_SIZE
,
1259 .periods_min
= CS46XX_FRAGS
,
1260 .periods_max
= 1024,
1264 static snd_pcm_hardware_t snd_cs46xx_capture
=
1266 .info
= (SNDRV_PCM_INFO_MMAP
|
1267 SNDRV_PCM_INFO_INTERLEAVED
|
1268 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1269 SNDRV_PCM_INFO_RESUME
),
1270 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1271 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1276 .buffer_bytes_max
= (256 * 1024),
1277 .period_bytes_min
= CS46XX_MIN_PERIOD_SIZE
,
1278 .period_bytes_max
= CS46XX_MAX_PERIOD_SIZE
,
1279 .periods_min
= CS46XX_FRAGS
,
1280 .periods_max
= 1024,
1284 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1286 static unsigned int period_sizes
[] = { 32, 64, 128, 256, 512, 1024, 2048 };
1288 static snd_pcm_hw_constraint_list_t hw_constraints_period_sizes
= {
1289 .count
= ARRAY_SIZE(period_sizes
),
1290 .list
= period_sizes
,
1296 static void snd_cs46xx_pcm_free_substream(snd_pcm_runtime_t
*runtime
)
1298 cs46xx_pcm_t
* cpcm
= runtime
->private_data
;
1302 static int _cs46xx_playback_open_channel (snd_pcm_substream_t
* substream
,int pcm_channel_id
)
1304 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
1305 cs46xx_pcm_t
* cpcm
;
1306 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1308 cpcm
= kcalloc(1, sizeof(*cpcm
), GFP_KERNEL
);
1311 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(chip
->pci
),
1312 PAGE_SIZE
, &cpcm
->hw_buf
) < 0) {
1317 runtime
->hw
= snd_cs46xx_playback
;
1318 runtime
->private_data
= cpcm
;
1319 runtime
->private_free
= snd_cs46xx_pcm_free_substream
;
1321 cpcm
->substream
= substream
;
1322 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1323 down (&chip
->spos_mutex
);
1324 cpcm
->pcm_channel
= NULL
;
1325 cpcm
->pcm_channel_id
= pcm_channel_id
;
1328 snd_pcm_hw_constraint_list(runtime
, 0,
1329 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1330 &hw_constraints_period_sizes
);
1332 up (&chip
->spos_mutex
);
1334 chip
->playback_pcm
= cpcm
; /* HACK */
1337 if (chip
->accept_valid
)
1338 substream
->runtime
->hw
.info
|= SNDRV_PCM_INFO_MMAP_VALID
;
1339 chip
->active_ctrl(chip
, 1);
1344 static int snd_cs46xx_playback_open(snd_pcm_substream_t
* substream
)
1346 snd_printdd("open front channel\n");
1347 return _cs46xx_playback_open_channel(substream
,DSP_PCM_MAIN_CHANNEL
);
1350 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1351 static int snd_cs46xx_playback_open_rear(snd_pcm_substream_t
* substream
)
1353 snd_printdd("open rear channel\n");
1355 return _cs46xx_playback_open_channel(substream
,DSP_PCM_REAR_CHANNEL
);
1358 static int snd_cs46xx_playback_open_clfe(snd_pcm_substream_t
* substream
)
1360 snd_printdd("open center - LFE channel\n");
1362 return _cs46xx_playback_open_channel(substream
,DSP_PCM_CENTER_LFE_CHANNEL
);
1365 static int snd_cs46xx_playback_open_iec958(snd_pcm_substream_t
* substream
)
1367 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
1369 snd_printdd("open raw iec958 channel\n");
1371 down (&chip
->spos_mutex
);
1372 cs46xx_iec958_pre_open (chip
);
1373 up (&chip
->spos_mutex
);
1375 return _cs46xx_playback_open_channel(substream
,DSP_IEC958_CHANNEL
);
1378 static int snd_cs46xx_playback_close(snd_pcm_substream_t
* substream
);
1380 static int snd_cs46xx_playback_close_iec958(snd_pcm_substream_t
* substream
)
1383 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
1385 snd_printdd("close raw iec958 channel\n");
1387 err
= snd_cs46xx_playback_close(substream
);
1389 down (&chip
->spos_mutex
);
1390 cs46xx_iec958_post_close (chip
);
1391 up (&chip
->spos_mutex
);
1397 static int snd_cs46xx_capture_open(snd_pcm_substream_t
* substream
)
1399 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
1401 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(chip
->pci
),
1402 PAGE_SIZE
, &chip
->capt
.hw_buf
) < 0)
1404 chip
->capt
.substream
= substream
;
1405 substream
->runtime
->hw
= snd_cs46xx_capture
;
1407 if (chip
->accept_valid
)
1408 substream
->runtime
->hw
.info
|= SNDRV_PCM_INFO_MMAP_VALID
;
1410 chip
->active_ctrl(chip
, 1);
1412 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1413 snd_pcm_hw_constraint_list(substream
->runtime
, 0,
1414 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1415 &hw_constraints_period_sizes
);
1420 static int snd_cs46xx_playback_close(snd_pcm_substream_t
* substream
)
1422 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
1423 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1424 cs46xx_pcm_t
* cpcm
;
1426 cpcm
= runtime
->private_data
;
1428 /* when playback_open fails, then cpcm can be NULL */
1429 if (!cpcm
) return -ENXIO
;
1431 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1432 down (&chip
->spos_mutex
);
1433 if (cpcm
->pcm_channel
) {
1434 cs46xx_dsp_destroy_pcm_channel(chip
,cpcm
->pcm_channel
);
1435 cpcm
->pcm_channel
= NULL
;
1437 up (&chip
->spos_mutex
);
1439 chip
->playback_pcm
= NULL
;
1442 cpcm
->substream
= NULL
;
1443 snd_dma_free_pages(&cpcm
->hw_buf
);
1444 chip
->active_ctrl(chip
, -1);
1449 static int snd_cs46xx_capture_close(snd_pcm_substream_t
* substream
)
1451 cs46xx_t
*chip
= snd_pcm_substream_chip(substream
);
1453 chip
->capt
.substream
= NULL
;
1454 snd_dma_free_pages(&chip
->capt
.hw_buf
);
1455 chip
->active_ctrl(chip
, -1);
1460 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1461 static snd_pcm_ops_t snd_cs46xx_playback_rear_ops
= {
1462 .open
= snd_cs46xx_playback_open_rear
,
1463 .close
= snd_cs46xx_playback_close
,
1464 .ioctl
= snd_pcm_lib_ioctl
,
1465 .hw_params
= snd_cs46xx_playback_hw_params
,
1466 .hw_free
= snd_cs46xx_playback_hw_free
,
1467 .prepare
= snd_cs46xx_playback_prepare
,
1468 .trigger
= snd_cs46xx_playback_trigger
,
1469 .pointer
= snd_cs46xx_playback_direct_pointer
,
1472 static snd_pcm_ops_t snd_cs46xx_playback_indirect_rear_ops
= {
1473 .open
= snd_cs46xx_playback_open_rear
,
1474 .close
= snd_cs46xx_playback_close
,
1475 .ioctl
= snd_pcm_lib_ioctl
,
1476 .hw_params
= snd_cs46xx_playback_hw_params
,
1477 .hw_free
= snd_cs46xx_playback_hw_free
,
1478 .prepare
= snd_cs46xx_playback_prepare
,
1479 .trigger
= snd_cs46xx_playback_trigger
,
1480 .pointer
= snd_cs46xx_playback_indirect_pointer
,
1481 .ack
= snd_cs46xx_playback_transfer
,
1484 static snd_pcm_ops_t snd_cs46xx_playback_clfe_ops
= {
1485 .open
= snd_cs46xx_playback_open_clfe
,
1486 .close
= snd_cs46xx_playback_close
,
1487 .ioctl
= snd_pcm_lib_ioctl
,
1488 .hw_params
= snd_cs46xx_playback_hw_params
,
1489 .hw_free
= snd_cs46xx_playback_hw_free
,
1490 .prepare
= snd_cs46xx_playback_prepare
,
1491 .trigger
= snd_cs46xx_playback_trigger
,
1492 .pointer
= snd_cs46xx_playback_direct_pointer
,
1495 static snd_pcm_ops_t snd_cs46xx_playback_indirect_clfe_ops
= {
1496 .open
= snd_cs46xx_playback_open_clfe
,
1497 .close
= snd_cs46xx_playback_close
,
1498 .ioctl
= snd_pcm_lib_ioctl
,
1499 .hw_params
= snd_cs46xx_playback_hw_params
,
1500 .hw_free
= snd_cs46xx_playback_hw_free
,
1501 .prepare
= snd_cs46xx_playback_prepare
,
1502 .trigger
= snd_cs46xx_playback_trigger
,
1503 .pointer
= snd_cs46xx_playback_indirect_pointer
,
1504 .ack
= snd_cs46xx_playback_transfer
,
1507 static snd_pcm_ops_t snd_cs46xx_playback_iec958_ops
= {
1508 .open
= snd_cs46xx_playback_open_iec958
,
1509 .close
= snd_cs46xx_playback_close_iec958
,
1510 .ioctl
= snd_pcm_lib_ioctl
,
1511 .hw_params
= snd_cs46xx_playback_hw_params
,
1512 .hw_free
= snd_cs46xx_playback_hw_free
,
1513 .prepare
= snd_cs46xx_playback_prepare
,
1514 .trigger
= snd_cs46xx_playback_trigger
,
1515 .pointer
= snd_cs46xx_playback_direct_pointer
,
1518 static snd_pcm_ops_t snd_cs46xx_playback_indirect_iec958_ops
= {
1519 .open
= snd_cs46xx_playback_open_iec958
,
1520 .close
= snd_cs46xx_playback_close_iec958
,
1521 .ioctl
= snd_pcm_lib_ioctl
,
1522 .hw_params
= snd_cs46xx_playback_hw_params
,
1523 .hw_free
= snd_cs46xx_playback_hw_free
,
1524 .prepare
= snd_cs46xx_playback_prepare
,
1525 .trigger
= snd_cs46xx_playback_trigger
,
1526 .pointer
= snd_cs46xx_playback_indirect_pointer
,
1527 .ack
= snd_cs46xx_playback_transfer
,
1532 static snd_pcm_ops_t snd_cs46xx_playback_ops
= {
1533 .open
= snd_cs46xx_playback_open
,
1534 .close
= snd_cs46xx_playback_close
,
1535 .ioctl
= snd_pcm_lib_ioctl
,
1536 .hw_params
= snd_cs46xx_playback_hw_params
,
1537 .hw_free
= snd_cs46xx_playback_hw_free
,
1538 .prepare
= snd_cs46xx_playback_prepare
,
1539 .trigger
= snd_cs46xx_playback_trigger
,
1540 .pointer
= snd_cs46xx_playback_direct_pointer
,
1543 static snd_pcm_ops_t snd_cs46xx_playback_indirect_ops
= {
1544 .open
= snd_cs46xx_playback_open
,
1545 .close
= snd_cs46xx_playback_close
,
1546 .ioctl
= snd_pcm_lib_ioctl
,
1547 .hw_params
= snd_cs46xx_playback_hw_params
,
1548 .hw_free
= snd_cs46xx_playback_hw_free
,
1549 .prepare
= snd_cs46xx_playback_prepare
,
1550 .trigger
= snd_cs46xx_playback_trigger
,
1551 .pointer
= snd_cs46xx_playback_indirect_pointer
,
1552 .ack
= snd_cs46xx_playback_transfer
,
1555 static snd_pcm_ops_t snd_cs46xx_capture_ops
= {
1556 .open
= snd_cs46xx_capture_open
,
1557 .close
= snd_cs46xx_capture_close
,
1558 .ioctl
= snd_pcm_lib_ioctl
,
1559 .hw_params
= snd_cs46xx_capture_hw_params
,
1560 .hw_free
= snd_cs46xx_capture_hw_free
,
1561 .prepare
= snd_cs46xx_capture_prepare
,
1562 .trigger
= snd_cs46xx_capture_trigger
,
1563 .pointer
= snd_cs46xx_capture_direct_pointer
,
1566 static snd_pcm_ops_t snd_cs46xx_capture_indirect_ops
= {
1567 .open
= snd_cs46xx_capture_open
,
1568 .close
= snd_cs46xx_capture_close
,
1569 .ioctl
= snd_pcm_lib_ioctl
,
1570 .hw_params
= snd_cs46xx_capture_hw_params
,
1571 .hw_free
= snd_cs46xx_capture_hw_free
,
1572 .prepare
= snd_cs46xx_capture_prepare
,
1573 .trigger
= snd_cs46xx_capture_trigger
,
1574 .pointer
= snd_cs46xx_capture_indirect_pointer
,
1575 .ack
= snd_cs46xx_capture_transfer
,
1578 static void snd_cs46xx_pcm_free(snd_pcm_t
*pcm
)
1580 cs46xx_t
*chip
= pcm
->private_data
;
1582 snd_pcm_lib_preallocate_free_for_all(pcm
);
1585 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1586 static void snd_cs46xx_pcm_rear_free(snd_pcm_t
*pcm
)
1588 cs46xx_t
*chip
= pcm
->private_data
;
1589 chip
->pcm_rear
= NULL
;
1590 snd_pcm_lib_preallocate_free_for_all(pcm
);
1593 static void snd_cs46xx_pcm_center_lfe_free(snd_pcm_t
*pcm
)
1595 cs46xx_t
*chip
= pcm
->private_data
;
1596 chip
->pcm_center_lfe
= NULL
;
1597 snd_pcm_lib_preallocate_free_for_all(pcm
);
1600 static void snd_cs46xx_pcm_iec958_free(snd_pcm_t
*pcm
)
1602 cs46xx_t
*chip
= pcm
->private_data
;
1603 chip
->pcm_iec958
= NULL
;
1604 snd_pcm_lib_preallocate_free_for_all(pcm
);
1607 #define MAX_PLAYBACK_CHANNELS (DSP_MAX_PCM_CHANNELS - 1)
1609 #define MAX_PLAYBACK_CHANNELS 1
1612 int __devinit
snd_cs46xx_pcm(cs46xx_t
*chip
, int device
, snd_pcm_t
** rpcm
)
1619 if ((err
= snd_pcm_new(chip
->card
, "CS46xx", device
, MAX_PLAYBACK_CHANNELS
, 1, &pcm
)) < 0)
1622 pcm
->private_data
= chip
;
1623 pcm
->private_free
= snd_cs46xx_pcm_free
;
1625 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_cs46xx_playback_ops
);
1626 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_cs46xx_capture_ops
);
1629 pcm
->info_flags
= 0;
1630 strcpy(pcm
->name
, "CS46xx");
1633 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1634 snd_dma_pci_data(chip
->pci
), 64*1024, 256*1024);
1643 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1644 int __devinit
snd_cs46xx_pcm_rear(cs46xx_t
*chip
, int device
, snd_pcm_t
** rpcm
)
1652 if ((err
= snd_pcm_new(chip
->card
, "CS46xx - Rear", device
, MAX_PLAYBACK_CHANNELS
, 0, &pcm
)) < 0)
1655 pcm
->private_data
= chip
;
1656 pcm
->private_free
= snd_cs46xx_pcm_rear_free
;
1658 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_cs46xx_playback_rear_ops
);
1661 pcm
->info_flags
= 0;
1662 strcpy(pcm
->name
, "CS46xx - Rear");
1663 chip
->pcm_rear
= pcm
;
1665 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1666 snd_dma_pci_data(chip
->pci
), 64*1024, 256*1024);
1674 int __devinit
snd_cs46xx_pcm_center_lfe(cs46xx_t
*chip
, int device
, snd_pcm_t
** rpcm
)
1682 if ((err
= snd_pcm_new(chip
->card
, "CS46xx - Center LFE", device
, MAX_PLAYBACK_CHANNELS
, 0, &pcm
)) < 0)
1685 pcm
->private_data
= chip
;
1686 pcm
->private_free
= snd_cs46xx_pcm_center_lfe_free
;
1688 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_cs46xx_playback_clfe_ops
);
1691 pcm
->info_flags
= 0;
1692 strcpy(pcm
->name
, "CS46xx - Center LFE");
1693 chip
->pcm_center_lfe
= pcm
;
1695 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1696 snd_dma_pci_data(chip
->pci
), 64*1024, 256*1024);
1704 int __devinit
snd_cs46xx_pcm_iec958(cs46xx_t
*chip
, int device
, snd_pcm_t
** rpcm
)
1712 if ((err
= snd_pcm_new(chip
->card
, "CS46xx - IEC958", device
, 1, 0, &pcm
)) < 0)
1715 pcm
->private_data
= chip
;
1716 pcm
->private_free
= snd_cs46xx_pcm_iec958_free
;
1718 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_cs46xx_playback_iec958_ops
);
1721 pcm
->info_flags
= 0;
1722 strcpy(pcm
->name
, "CS46xx - IEC958");
1723 chip
->pcm_rear
= pcm
;
1725 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1726 snd_dma_pci_data(chip
->pci
), 64*1024, 256*1024);
1738 static void snd_cs46xx_mixer_free_ac97_bus(ac97_bus_t
*bus
)
1740 cs46xx_t
*chip
= bus
->private_data
;
1742 chip
->ac97_bus
= NULL
;
1745 static void snd_cs46xx_mixer_free_ac97(ac97_t
*ac97
)
1747 cs46xx_t
*chip
= ac97
->private_data
;
1749 snd_assert ((ac97
== chip
->ac97
[CS46XX_PRIMARY_CODEC_INDEX
]) ||
1750 (ac97
== chip
->ac97
[CS46XX_SECONDARY_CODEC_INDEX
]),
1753 if (ac97
== chip
->ac97
[CS46XX_PRIMARY_CODEC_INDEX
]) {
1754 chip
->ac97
[CS46XX_PRIMARY_CODEC_INDEX
] = NULL
;
1755 chip
->eapd_switch
= NULL
;
1758 chip
->ac97
[CS46XX_SECONDARY_CODEC_INDEX
] = NULL
;
1761 static int snd_cs46xx_vol_info(snd_kcontrol_t
*kcontrol
,
1762 snd_ctl_elem_info_t
*uinfo
)
1764 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1766 uinfo
->value
.integer
.min
= 0;
1767 uinfo
->value
.integer
.max
= 0x7fff;
1771 static int snd_cs46xx_vol_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1773 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1774 int reg
= kcontrol
->private_value
;
1775 unsigned int val
= snd_cs46xx_peek(chip
, reg
);
1776 ucontrol
->value
.integer
.value
[0] = 0xffff - (val
>> 16);
1777 ucontrol
->value
.integer
.value
[1] = 0xffff - (val
& 0xffff);
1781 static int snd_cs46xx_vol_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1783 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1784 int reg
= kcontrol
->private_value
;
1785 unsigned int val
= ((0xffff - ucontrol
->value
.integer
.value
[0]) << 16 |
1786 (0xffff - ucontrol
->value
.integer
.value
[1]));
1787 unsigned int old
= snd_cs46xx_peek(chip
, reg
);
1788 int change
= (old
!= val
);
1791 snd_cs46xx_poke(chip
, reg
, val
);
1797 #ifdef CONFIG_SND_CS46XX_NEW_DSP
1799 static int snd_cs46xx_vol_dac_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1801 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1803 ucontrol
->value
.integer
.value
[0] = chip
->dsp_spos_instance
->dac_volume_left
;
1804 ucontrol
->value
.integer
.value
[1] = chip
->dsp_spos_instance
->dac_volume_right
;
1809 static int snd_cs46xx_vol_dac_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1811 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1814 if (chip
->dsp_spos_instance
->dac_volume_right
!= ucontrol
->value
.integer
.value
[0] ||
1815 chip
->dsp_spos_instance
->dac_volume_left
!= ucontrol
->value
.integer
.value
[1]) {
1816 cs46xx_dsp_set_dac_volume(chip
,
1817 ucontrol
->value
.integer
.value
[0],
1818 ucontrol
->value
.integer
.value
[1]);
1826 static int snd_cs46xx_vol_iec958_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1828 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1830 ucontrol
->value
.integer
.value
[0] = chip
->dsp_spos_instance
->spdif_input_volume_left
;
1831 ucontrol
->value
.integer
.value
[1] = chip
->dsp_spos_instance
->spdif_input_volume_right
;
1835 static int snd_cs46xx_vol_iec958_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1837 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1840 if (chip
->dsp_spos_instance
->spdif_input_volume_left
!= ucontrol
->value
.integer
.value
[0] ||
1841 chip
->dsp_spos_instance
->spdif_input_volume_right
!= ucontrol
->value
.integer
.value
[1]) {
1842 cs46xx_dsp_set_iec958_volume (chip
,
1843 ucontrol
->value
.integer
.value
[0],
1844 ucontrol
->value
.integer
.value
[1]);
1852 static int snd_mixer_boolean_info(snd_kcontrol_t
*kcontrol
,
1853 snd_ctl_elem_info_t
*uinfo
)
1855 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1857 uinfo
->value
.integer
.min
= 0;
1858 uinfo
->value
.integer
.max
= 1;
1862 static int snd_cs46xx_iec958_get(snd_kcontrol_t
*kcontrol
,
1863 snd_ctl_elem_value_t
*ucontrol
)
1865 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1866 int reg
= kcontrol
->private_value
;
1868 if (reg
== CS46XX_MIXER_SPDIF_OUTPUT_ELEMENT
)
1869 ucontrol
->value
.integer
.value
[0] = (chip
->dsp_spos_instance
->spdif_status_out
& DSP_SPDIF_STATUS_OUTPUT_ENABLED
);
1871 ucontrol
->value
.integer
.value
[0] = chip
->dsp_spos_instance
->spdif_status_in
;
1876 static int snd_cs46xx_iec958_put(snd_kcontrol_t
*kcontrol
,
1877 snd_ctl_elem_value_t
*ucontrol
)
1879 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1882 switch (kcontrol
->private_value
) {
1883 case CS46XX_MIXER_SPDIF_OUTPUT_ELEMENT
:
1884 down (&chip
->spos_mutex
);
1885 change
= (chip
->dsp_spos_instance
->spdif_status_out
& DSP_SPDIF_STATUS_OUTPUT_ENABLED
);
1886 if (ucontrol
->value
.integer
.value
[0] && !change
)
1887 cs46xx_dsp_enable_spdif_out(chip
);
1888 else if (change
&& !ucontrol
->value
.integer
.value
[0])
1889 cs46xx_dsp_disable_spdif_out(chip
);
1891 res
= (change
!= (chip
->dsp_spos_instance
->spdif_status_out
& DSP_SPDIF_STATUS_OUTPUT_ENABLED
));
1892 up (&chip
->spos_mutex
);
1894 case CS46XX_MIXER_SPDIF_INPUT_ELEMENT
:
1895 change
= chip
->dsp_spos_instance
->spdif_status_in
;
1896 if (ucontrol
->value
.integer
.value
[0] && !change
) {
1897 cs46xx_dsp_enable_spdif_in(chip
);
1898 /* restore volume */
1900 else if (change
&& !ucontrol
->value
.integer
.value
[0])
1901 cs46xx_dsp_disable_spdif_in(chip
);
1903 res
= (change
!= chip
->dsp_spos_instance
->spdif_status_in
);
1907 snd_assert(0, (void)0);
1913 static int snd_cs46xx_adc_capture_get(snd_kcontrol_t
*kcontrol
,
1914 snd_ctl_elem_value_t
*ucontrol
)
1916 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1917 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1919 if (ins
->adc_input
!= NULL
)
1920 ucontrol
->value
.integer
.value
[0] = 1;
1922 ucontrol
->value
.integer
.value
[0] = 0;
1927 static int snd_cs46xx_adc_capture_put(snd_kcontrol_t
*kcontrol
,
1928 snd_ctl_elem_value_t
*ucontrol
)
1930 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1931 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1934 if (ucontrol
->value
.integer
.value
[0] && !ins
->adc_input
) {
1935 cs46xx_dsp_enable_adc_capture(chip
);
1937 } else if (!ucontrol
->value
.integer
.value
[0] && ins
->adc_input
) {
1938 cs46xx_dsp_disable_adc_capture(chip
);
1944 static int snd_cs46xx_pcm_capture_get(snd_kcontrol_t
*kcontrol
,
1945 snd_ctl_elem_value_t
*ucontrol
)
1947 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1948 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1950 if (ins
->pcm_input
!= NULL
)
1951 ucontrol
->value
.integer
.value
[0] = 1;
1953 ucontrol
->value
.integer
.value
[0] = 0;
1959 static int snd_cs46xx_pcm_capture_put(snd_kcontrol_t
*kcontrol
,
1960 snd_ctl_elem_value_t
*ucontrol
)
1962 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1963 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1966 if (ucontrol
->value
.integer
.value
[0] && !ins
->pcm_input
) {
1967 cs46xx_dsp_enable_pcm_capture(chip
);
1969 } else if (!ucontrol
->value
.integer
.value
[0] && ins
->pcm_input
) {
1970 cs46xx_dsp_disable_pcm_capture(chip
);
1977 static int snd_herc_spdif_select_get(snd_kcontrol_t
*kcontrol
,
1978 snd_ctl_elem_value_t
*ucontrol
)
1980 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1982 int val1
= snd_cs46xx_peekBA0(chip
, BA0_EGPIODR
);
1984 if (val1
& EGPIODR_GPOE0
)
1985 ucontrol
->value
.integer
.value
[0] = 1;
1987 ucontrol
->value
.integer
.value
[0] = 0;
1993 * Game Theatre XP card - EGPIO[0] is used to select SPDIF input optical or coaxial.
1995 static int snd_herc_spdif_select_put(snd_kcontrol_t
*kcontrol
,
1996 snd_ctl_elem_value_t
*ucontrol
)
1998 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
1999 int val1
= snd_cs46xx_peekBA0(chip
, BA0_EGPIODR
);
2000 int val2
= snd_cs46xx_peekBA0(chip
, BA0_EGPIOPTR
);
2002 if (ucontrol
->value
.integer
.value
[0]) {
2003 /* optical is default */
2004 snd_cs46xx_pokeBA0(chip
, BA0_EGPIODR
,
2005 EGPIODR_GPOE0
| val1
); /* enable EGPIO0 output */
2006 snd_cs46xx_pokeBA0(chip
, BA0_EGPIOPTR
,
2007 EGPIOPTR_GPPT0
| val2
); /* open-drain on output */
2010 snd_cs46xx_pokeBA0(chip
, BA0_EGPIODR
, val1
& ~EGPIODR_GPOE0
); /* disable */
2011 snd_cs46xx_pokeBA0(chip
, BA0_EGPIOPTR
, val2
& ~EGPIOPTR_GPPT0
); /* disable */
2014 /* checking diff from the EGPIO direction register
2016 return (val1
!= (int)snd_cs46xx_peekBA0(chip
, BA0_EGPIODR
));
2020 static int snd_cs46xx_spdif_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
2022 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2027 static int snd_cs46xx_spdif_default_get(snd_kcontrol_t
* kcontrol
,
2028 snd_ctl_elem_value_t
* ucontrol
)
2030 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
2031 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
2033 down (&chip
->spos_mutex
);
2034 ucontrol
->value
.iec958
.status
[0] = _wrap_all_bits((ins
->spdif_csuv_default
>> 24) & 0xff);
2035 ucontrol
->value
.iec958
.status
[1] = _wrap_all_bits((ins
->spdif_csuv_default
>> 16) & 0xff);
2036 ucontrol
->value
.iec958
.status
[2] = 0;
2037 ucontrol
->value
.iec958
.status
[3] = _wrap_all_bits((ins
->spdif_csuv_default
) & 0xff);
2038 up (&chip
->spos_mutex
);
2043 static int snd_cs46xx_spdif_default_put(snd_kcontrol_t
* kcontrol
,
2044 snd_ctl_elem_value_t
* ucontrol
)
2046 cs46xx_t
* chip
= snd_kcontrol_chip(kcontrol
);
2047 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
2051 down (&chip
->spos_mutex
);
2052 val
= ((unsigned int)_wrap_all_bits(ucontrol
->value
.iec958
.status
[0]) << 24) |
2053 ((unsigned int)_wrap_all_bits(ucontrol
->value
.iec958
.status
[2]) << 16) |
2054 ((unsigned int)_wrap_all_bits(ucontrol
->value
.iec958
.status
[3])) |
2055 /* left and right validity bit */
2056 (1 << 13) | (1 << 12);
2059 change
= (unsigned int)ins
->spdif_csuv_default
!= val
;
2060 ins
->spdif_csuv_default
= val
;
2062 if ( !(ins
->spdif_status_out
& DSP_SPDIF_STATUS_PLAYBACK_OPEN
) )
2063 cs46xx_poke_via_dsp (chip
,SP_SPDOUT_CSUV
,val
);
2065 up (&chip
->spos_mutex
);
2070 static int snd_cs46xx_spdif_mask_get(snd_kcontrol_t
* kcontrol
,
2071 snd_ctl_elem_value_t
* ucontrol
)
2073 ucontrol
->value
.iec958
.status
[0] = 0xff;
2074 ucontrol
->value
.iec958
.status
[1] = 0xff;
2075 ucontrol
->value
.iec958
.status
[2] = 0x00;
2076 ucontrol
->value
.iec958
.status
[3] = 0xff;
2080 static int snd_cs46xx_spdif_stream_get(snd_kcontrol_t
* kcontrol
,
2081 snd_ctl_elem_value_t
* ucontrol
)
2083 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
2084 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
2086 down (&chip
->spos_mutex
);
2087 ucontrol
->value
.iec958
.status
[0] = _wrap_all_bits((ins
->spdif_csuv_stream
>> 24) & 0xff);
2088 ucontrol
->value
.iec958
.status
[1] = _wrap_all_bits((ins
->spdif_csuv_stream
>> 16) & 0xff);
2089 ucontrol
->value
.iec958
.status
[2] = 0;
2090 ucontrol
->value
.iec958
.status
[3] = _wrap_all_bits((ins
->spdif_csuv_stream
) & 0xff);
2091 up (&chip
->spos_mutex
);
2096 static int snd_cs46xx_spdif_stream_put(snd_kcontrol_t
* kcontrol
,
2097 snd_ctl_elem_value_t
* ucontrol
)
2099 cs46xx_t
* chip
= snd_kcontrol_chip(kcontrol
);
2100 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
2104 down (&chip
->spos_mutex
);
2105 val
= ((unsigned int)_wrap_all_bits(ucontrol
->value
.iec958
.status
[0]) << 24) |
2106 ((unsigned int)_wrap_all_bits(ucontrol
->value
.iec958
.status
[1]) << 16) |
2107 ((unsigned int)_wrap_all_bits(ucontrol
->value
.iec958
.status
[3])) |
2108 /* left and right validity bit */
2109 (1 << 13) | (1 << 12);
2112 change
= ins
->spdif_csuv_stream
!= val
;
2113 ins
->spdif_csuv_stream
= val
;
2115 if ( ins
->spdif_status_out
& DSP_SPDIF_STATUS_PLAYBACK_OPEN
)
2116 cs46xx_poke_via_dsp (chip
,SP_SPDOUT_CSUV
,val
);
2118 up (&chip
->spos_mutex
);
2123 #endif /* CONFIG_SND_CS46XX_NEW_DSP */
2126 #ifdef CONFIG_SND_CS46XX_DEBUG_GPIO
2127 static int snd_cs46xx_egpio_select_info(snd_kcontrol_t
*kcontrol
,
2128 snd_ctl_elem_info_t
*uinfo
)
2130 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2132 uinfo
->value
.integer
.min
= 0;
2133 uinfo
->value
.integer
.max
= 8;
2137 static int snd_cs46xx_egpio_select_get(snd_kcontrol_t
*kcontrol
,
2138 snd_ctl_elem_value_t
*ucontrol
)
2140 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
2141 ucontrol
->value
.integer
.value
[0] = chip
->current_gpio
;
2146 static int snd_cs46xx_egpio_select_put(snd_kcontrol_t
*kcontrol
,
2147 snd_ctl_elem_value_t
*ucontrol
)
2149 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
2150 int change
= (chip
->current_gpio
!= ucontrol
->value
.integer
.value
[0]);
2151 chip
->current_gpio
= ucontrol
->value
.integer
.value
[0];
2157 static int snd_cs46xx_egpio_get(snd_kcontrol_t
*kcontrol
,
2158 snd_ctl_elem_value_t
*ucontrol
)
2160 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
2161 int reg
= kcontrol
->private_value
;
2163 snd_printdd ("put: reg = %04x, gpio %02x\n",reg
,chip
->current_gpio
);
2164 ucontrol
->value
.integer
.value
[0] =
2165 (snd_cs46xx_peekBA0(chip
, reg
) & (1 << chip
->current_gpio
)) ? 1 : 0;
2170 static int snd_cs46xx_egpio_put(snd_kcontrol_t
*kcontrol
,
2171 snd_ctl_elem_value_t
*ucontrol
)
2173 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
2174 int reg
= kcontrol
->private_value
;
2175 int val
= snd_cs46xx_peekBA0(chip
, reg
);
2177 snd_printdd ("put: reg = %04x, gpio %02x\n",reg
,chip
->current_gpio
);
2179 if (ucontrol
->value
.integer
.value
[0])
2180 val
|= (1 << chip
->current_gpio
);
2182 val
&= ~(1 << chip
->current_gpio
);
2184 snd_cs46xx_pokeBA0(chip
, reg
,val
);
2185 snd_printdd ("put: val %08x oldval %08x\n",val
,oldval
);
2187 return (oldval
!= val
);
2189 #endif /* CONFIG_SND_CS46XX_DEBUG_GPIO */
2191 static snd_kcontrol_new_t snd_cs46xx_controls
[] __devinitdata
= {
2193 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2194 .name
= "DAC Volume",
2195 .info
= snd_cs46xx_vol_info
,
2196 #ifndef CONFIG_SND_CS46XX_NEW_DSP
2197 .get
= snd_cs46xx_vol_get
,
2198 .put
= snd_cs46xx_vol_put
,
2199 .private_value
= BA1_PVOL
,
2201 .get
= snd_cs46xx_vol_dac_get
,
2202 .put
= snd_cs46xx_vol_dac_put
,
2207 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2208 .name
= "ADC Volume",
2209 .info
= snd_cs46xx_vol_info
,
2210 .get
= snd_cs46xx_vol_get
,
2211 .put
= snd_cs46xx_vol_put
,
2212 #ifndef CONFIG_SND_CS46XX_NEW_DSP
2213 .private_value
= BA1_CVOL
,
2215 .private_value
= (VARIDECIMATE_SCB_ADDR
+ 0xE) << 2,
2218 #ifdef CONFIG_SND_CS46XX_NEW_DSP
2220 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2221 .name
= "ADC Capture Switch",
2222 .info
= snd_mixer_boolean_info
,
2223 .get
= snd_cs46xx_adc_capture_get
,
2224 .put
= snd_cs46xx_adc_capture_put
2227 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2228 .name
= "DAC Capture Switch",
2229 .info
= snd_mixer_boolean_info
,
2230 .get
= snd_cs46xx_pcm_capture_get
,
2231 .put
= snd_cs46xx_pcm_capture_put
2234 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2235 .name
= "IEC958 Output Switch",
2236 .info
= snd_mixer_boolean_info
,
2237 .get
= snd_cs46xx_iec958_get
,
2238 .put
= snd_cs46xx_iec958_put
,
2239 .private_value
= CS46XX_MIXER_SPDIF_OUTPUT_ELEMENT
,
2242 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2243 .name
= "IEC958 Input Switch",
2244 .info
= snd_mixer_boolean_info
,
2245 .get
= snd_cs46xx_iec958_get
,
2246 .put
= snd_cs46xx_iec958_put
,
2247 .private_value
= CS46XX_MIXER_SPDIF_INPUT_ELEMENT
,
2250 /* Input IEC958 volume does not work for the moment. (Benny) */
2252 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2253 .name
= "IEC958 Input Volume",
2254 .info
= snd_cs46xx_vol_info
,
2255 .get
= snd_cs46xx_vol_iec958_get
,
2256 .put
= snd_cs46xx_vol_iec958_put
,
2257 .private_value
= (ASYNCRX_SCB_ADDR
+ 0xE) << 2,
2261 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2262 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
2263 .info
= snd_cs46xx_spdif_info
,
2264 .get
= snd_cs46xx_spdif_default_get
,
2265 .put
= snd_cs46xx_spdif_default_put
,
2268 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2269 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,MASK
),
2270 .info
= snd_cs46xx_spdif_info
,
2271 .get
= snd_cs46xx_spdif_mask_get
,
2272 .access
= SNDRV_CTL_ELEM_ACCESS_READ
2275 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2276 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PCM_STREAM
),
2277 .info
= snd_cs46xx_spdif_info
,
2278 .get
= snd_cs46xx_spdif_stream_get
,
2279 .put
= snd_cs46xx_spdif_stream_put
2283 #ifdef CONFIG_SND_CS46XX_DEBUG_GPIO
2285 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2286 .name
= "EGPIO select",
2287 .info
= snd_cs46xx_egpio_select_info
,
2288 .get
= snd_cs46xx_egpio_select_get
,
2289 .put
= snd_cs46xx_egpio_select_put
,
2293 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2294 .name
= "EGPIO Input/Output",
2295 .info
= snd_mixer_boolean_info
,
2296 .get
= snd_cs46xx_egpio_get
,
2297 .put
= snd_cs46xx_egpio_put
,
2298 .private_value
= BA0_EGPIODR
,
2301 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2302 .name
= "EGPIO CMOS/Open drain",
2303 .info
= snd_mixer_boolean_info
,
2304 .get
= snd_cs46xx_egpio_get
,
2305 .put
= snd_cs46xx_egpio_put
,
2306 .private_value
= BA0_EGPIOPTR
,
2309 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2310 .name
= "EGPIO On/Off",
2311 .info
= snd_mixer_boolean_info
,
2312 .get
= snd_cs46xx_egpio_get
,
2313 .put
= snd_cs46xx_egpio_put
,
2314 .private_value
= BA0_EGPIOSR
,
2319 #ifdef CONFIG_SND_CS46XX_NEW_DSP
2320 /* set primary cs4294 codec into Extended Audio Mode */
2321 static int snd_cs46xx_front_dup_get(snd_kcontrol_t
*kcontrol
,
2322 snd_ctl_elem_value_t
*ucontrol
)
2324 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
2326 val
= snd_ac97_read(chip
->ac97
[CS46XX_PRIMARY_CODEC_INDEX
], AC97_CSR_ACMODE
);
2327 ucontrol
->value
.integer
.value
[0] = (val
& 0x200) ? 0 : 1;
2331 static int snd_cs46xx_front_dup_put(snd_kcontrol_t
*kcontrol
,
2332 snd_ctl_elem_value_t
*ucontrol
)
2334 cs46xx_t
*chip
= snd_kcontrol_chip(kcontrol
);
2335 return snd_ac97_update_bits(chip
->ac97
[CS46XX_PRIMARY_CODEC_INDEX
],
2336 AC97_CSR_ACMODE
, 0x200,
2337 ucontrol
->value
.integer
.value
[0] ? 0 : 0x200);
2340 static snd_kcontrol_new_t snd_cs46xx_front_dup_ctl
= {
2341 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2342 .name
= "Duplicate Front",
2343 .info
= snd_mixer_boolean_info
,
2344 .get
= snd_cs46xx_front_dup_get
,
2345 .put
= snd_cs46xx_front_dup_put
,
2349 #ifdef CONFIG_SND_CS46XX_NEW_DSP
2350 /* Only available on the Hercules Game Theater XP soundcard */
2351 static snd_kcontrol_new_t snd_hercules_controls
[] __devinitdata
= {
2353 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2354 .name
= "Optical/Coaxial SPDIF Input Switch",
2355 .info
= snd_mixer_boolean_info
,
2356 .get
= snd_herc_spdif_select_get
,
2357 .put
= snd_herc_spdif_select_put
,
2362 static void snd_cs46xx_codec_reset (ac97_t
* ac97
)
2364 unsigned long end_time
;
2367 /* reset to defaults */
2368 snd_ac97_write(ac97
, AC97_RESET
, 0);
2370 /* set the desired CODEC mode */
2371 if (ac97
->num
== CS46XX_PRIMARY_CODEC_INDEX
) {
2372 snd_printdd("cs46xx: CODOEC1 mode %04x\n",0x0);
2373 snd_cs46xx_ac97_write(ac97
,AC97_CSR_ACMODE
,0x0);
2374 } else if (ac97
->num
== CS46XX_SECONDARY_CODEC_INDEX
) {
2375 snd_printdd("cs46xx: CODOEC2 mode %04x\n",0x3);
2376 snd_cs46xx_ac97_write(ac97
,AC97_CSR_ACMODE
,0x3);
2378 snd_assert(0); /* should never happen ... */
2383 /* it's necessary to wait awhile until registers are accessible after RESET */
2384 /* because the PCM or MASTER volume registers can be modified, */
2385 /* the REC_GAIN register is used for tests */
2386 end_time
= jiffies
+ HZ
;
2388 unsigned short ext_mid
;
2390 /* use preliminary reads to settle the communication */
2391 snd_ac97_read(ac97
, AC97_RESET
);
2392 snd_ac97_read(ac97
, AC97_VENDOR_ID1
);
2393 snd_ac97_read(ac97
, AC97_VENDOR_ID2
);
2395 ext_mid
= snd_ac97_read(ac97
, AC97_EXTENDED_MID
);
2396 if (ext_mid
!= 0xffff && (ext_mid
& 1) != 0)
2399 /* test if we can write to the record gain volume register */
2400 snd_ac97_write_cache(ac97
, AC97_REC_GAIN
, 0x8a05);
2401 if ((err
= snd_ac97_read(ac97
, AC97_REC_GAIN
)) == 0x8a05)
2404 set_current_state(TASK_UNINTERRUPTIBLE
);
2405 schedule_timeout(HZ
/100);
2406 } while (time_after_eq(end_time
, jiffies
));
2408 snd_printk("CS46xx secondary codec dont respond!\n");
2412 static int __devinit
cs46xx_detect_codec(cs46xx_t
*chip
, int codec
)
2415 ac97_template_t ac97
;
2417 memset(&ac97
, 0, sizeof(ac97
));
2418 ac97
.private_data
= chip
;
2419 ac97
.private_free
= snd_cs46xx_mixer_free_ac97
;
2421 if (chip
->amplifier_ctrl
== amp_voyetra
)
2422 ac97
.scaps
= AC97_SCAP_INV_EAPD
;
2424 if (codec
== CS46XX_SECONDARY_CODEC_INDEX
) {
2425 snd_cs46xx_codec_write(chip
, AC97_RESET
, 0, codec
);
2427 if (snd_cs46xx_codec_read(chip
, AC97_RESET
, codec
) & 0x8000) {
2428 snd_printdd("snd_cs46xx: seconadry codec not present\n");
2433 snd_cs46xx_codec_write(chip
, AC97_MASTER
, 0x8000, codec
);
2434 for (idx
= 0; idx
< 100; ++idx
) {
2435 if (snd_cs46xx_codec_read(chip
, AC97_MASTER
, codec
) == 0x8000) {
2436 err
= snd_ac97_mixer(chip
->ac97_bus
, &ac97
, &chip
->ac97
[codec
]);
2439 set_current_state(TASK_INTERRUPTIBLE
);
2440 schedule_timeout(HZ
/100);
2442 snd_printdd("snd_cs46xx: codec %d detection timeout\n", codec
);
2446 int __devinit
snd_cs46xx_mixer(cs46xx_t
*chip
)
2448 snd_card_t
*card
= chip
->card
;
2449 snd_ctl_elem_id_t id
;
2452 static ac97_bus_ops_t ops
= {
2453 #ifdef CONFIG_SND_CS46XX_NEW_DSP
2454 .reset
= snd_cs46xx_codec_reset
,
2456 .write
= snd_cs46xx_ac97_write
,
2457 .read
= snd_cs46xx_ac97_read
,
2460 /* detect primary codec */
2461 chip
->nr_ac97_codecs
= 0;
2462 snd_printdd("snd_cs46xx: detecting primary codec\n");
2463 if ((err
= snd_ac97_bus(card
, 0, &ops
, chip
, &chip
->ac97_bus
)) < 0)
2465 chip
->ac97_bus
->private_free
= snd_cs46xx_mixer_free_ac97_bus
;
2467 if (cs46xx_detect_codec(chip
, CS46XX_PRIMARY_CODEC_INDEX
) < 0)
2469 chip
->nr_ac97_codecs
= 1;
2471 #ifdef CONFIG_SND_CS46XX_NEW_DSP
2472 snd_printdd("snd_cs46xx: detecting seconadry codec\n");
2473 /* try detect a secondary codec */
2474 if (! cs46xx_detect_codec(chip
, CS46XX_SECONDARY_CODEC_INDEX
))
2475 chip
->nr_ac97_codecs
= 2;
2476 #endif /* CONFIG_SND_CS46XX_NEW_DSP */
2478 /* add cs4630 mixer controls */
2479 for (idx
= 0; idx
< ARRAY_SIZE(snd_cs46xx_controls
); idx
++) {
2480 snd_kcontrol_t
*kctl
;
2481 kctl
= snd_ctl_new1(&snd_cs46xx_controls
[idx
], chip
);
2482 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
2486 /* get EAPD mixer switch (for voyetra hack) */
2487 memset(&id
, 0, sizeof(id
));
2488 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
2489 strcpy(id
.name
, "External Amplifier");
2490 chip
->eapd_switch
= snd_ctl_find_id(chip
->card
, &id
);
2492 #ifdef CONFIG_SND_CS46XX_NEW_DSP
2493 if (chip
->nr_ac97_codecs
== 1) {
2494 unsigned int id2
= chip
->ac97
[CS46XX_PRIMARY_CODEC_INDEX
]->id
& 0xffff;
2495 if (id2
== 0x592b || id2
== 0x592d) {
2496 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_cs46xx_front_dup_ctl
, chip
));
2499 snd_ac97_write_cache(chip
->ac97
[CS46XX_PRIMARY_CODEC_INDEX
],
2500 AC97_CSR_ACMODE
, 0x200);
2503 /* do soundcard specific mixer setup */
2504 if (chip
->mixer_init
) {
2505 snd_printdd ("calling chip->mixer_init(chip);\n");
2506 chip
->mixer_init(chip
);
2510 /* turn on amplifier */
2511 chip
->amplifier_ctrl(chip
, 1);
2520 static void snd_cs46xx_midi_reset(cs46xx_t
*chip
)
2522 snd_cs46xx_pokeBA0(chip
, BA0_MIDCR
, MIDCR_MRST
);
2524 snd_cs46xx_pokeBA0(chip
, BA0_MIDCR
, chip
->midcr
);
2527 static int snd_cs46xx_midi_input_open(snd_rawmidi_substream_t
* substream
)
2529 cs46xx_t
*chip
= substream
->rmidi
->private_data
;
2531 chip
->active_ctrl(chip
, 1);
2532 spin_lock_irq(&chip
->reg_lock
);
2533 chip
->uartm
|= CS46XX_MODE_INPUT
;
2534 chip
->midcr
|= MIDCR_RXE
;
2535 chip
->midi_input
= substream
;
2536 if (!(chip
->uartm
& CS46XX_MODE_OUTPUT
)) {
2537 snd_cs46xx_midi_reset(chip
);
2539 snd_cs46xx_pokeBA0(chip
, BA0_MIDCR
, chip
->midcr
);
2541 spin_unlock_irq(&chip
->reg_lock
);
2545 static int snd_cs46xx_midi_input_close(snd_rawmidi_substream_t
* substream
)
2547 cs46xx_t
*chip
= substream
->rmidi
->private_data
;
2549 spin_lock_irq(&chip
->reg_lock
);
2550 chip
->midcr
&= ~(MIDCR_RXE
| MIDCR_RIE
);
2551 chip
->midi_input
= NULL
;
2552 if (!(chip
->uartm
& CS46XX_MODE_OUTPUT
)) {
2553 snd_cs46xx_midi_reset(chip
);
2555 snd_cs46xx_pokeBA0(chip
, BA0_MIDCR
, chip
->midcr
);
2557 chip
->uartm
&= ~CS46XX_MODE_INPUT
;
2558 spin_unlock_irq(&chip
->reg_lock
);
2559 chip
->active_ctrl(chip
, -1);
2563 static int snd_cs46xx_midi_output_open(snd_rawmidi_substream_t
* substream
)
2565 cs46xx_t
*chip
= substream
->rmidi
->private_data
;
2567 chip
->active_ctrl(chip
, 1);
2569 spin_lock_irq(&chip
->reg_lock
);
2570 chip
->uartm
|= CS46XX_MODE_OUTPUT
;
2571 chip
->midcr
|= MIDCR_TXE
;
2572 chip
->midi_output
= substream
;
2573 if (!(chip
->uartm
& CS46XX_MODE_INPUT
)) {
2574 snd_cs46xx_midi_reset(chip
);
2576 snd_cs46xx_pokeBA0(chip
, BA0_MIDCR
, chip
->midcr
);
2578 spin_unlock_irq(&chip
->reg_lock
);
2582 static int snd_cs46xx_midi_output_close(snd_rawmidi_substream_t
* substream
)
2584 cs46xx_t
*chip
= substream
->rmidi
->private_data
;
2586 spin_lock_irq(&chip
->reg_lock
);
2587 chip
->midcr
&= ~(MIDCR_TXE
| MIDCR_TIE
);
2588 chip
->midi_output
= NULL
;
2589 if (!(chip
->uartm
& CS46XX_MODE_INPUT
)) {
2590 snd_cs46xx_midi_reset(chip
);
2592 snd_cs46xx_pokeBA0(chip
, BA0_MIDCR
, chip
->midcr
);
2594 chip
->uartm
&= ~CS46XX_MODE_OUTPUT
;
2595 spin_unlock_irq(&chip
->reg_lock
);
2596 chip
->active_ctrl(chip
, -1);
2600 static void snd_cs46xx_midi_input_trigger(snd_rawmidi_substream_t
* substream
, int up
)
2602 unsigned long flags
;
2603 cs46xx_t
*chip
= substream
->rmidi
->private_data
;
2605 spin_lock_irqsave(&chip
->reg_lock
, flags
);
2607 if ((chip
->midcr
& MIDCR_RIE
) == 0) {
2608 chip
->midcr
|= MIDCR_RIE
;
2609 snd_cs46xx_pokeBA0(chip
, BA0_MIDCR
, chip
->midcr
);
2612 if (chip
->midcr
& MIDCR_RIE
) {
2613 chip
->midcr
&= ~MIDCR_RIE
;
2614 snd_cs46xx_pokeBA0(chip
, BA0_MIDCR
, chip
->midcr
);
2617 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
2620 static void snd_cs46xx_midi_output_trigger(snd_rawmidi_substream_t
* substream
, int up
)
2622 unsigned long flags
;
2623 cs46xx_t
*chip
= substream
->rmidi
->private_data
;
2626 spin_lock_irqsave(&chip
->reg_lock
, flags
);
2628 if ((chip
->midcr
& MIDCR_TIE
) == 0) {
2629 chip
->midcr
|= MIDCR_TIE
;
2630 /* fill UART FIFO buffer at first, and turn Tx interrupts only if necessary */
2631 while ((chip
->midcr
& MIDCR_TIE
) &&
2632 (snd_cs46xx_peekBA0(chip
, BA0_MIDSR
) & MIDSR_TBF
) == 0) {
2633 if (snd_rawmidi_transmit(substream
, &byte
, 1) != 1) {
2634 chip
->midcr
&= ~MIDCR_TIE
;
2636 snd_cs46xx_pokeBA0(chip
, BA0_MIDWP
, byte
);
2639 snd_cs46xx_pokeBA0(chip
, BA0_MIDCR
, chip
->midcr
);
2642 if (chip
->midcr
& MIDCR_TIE
) {
2643 chip
->midcr
&= ~MIDCR_TIE
;
2644 snd_cs46xx_pokeBA0(chip
, BA0_MIDCR
, chip
->midcr
);
2647 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
2650 static snd_rawmidi_ops_t snd_cs46xx_midi_output
=
2652 .open
= snd_cs46xx_midi_output_open
,
2653 .close
= snd_cs46xx_midi_output_close
,
2654 .trigger
= snd_cs46xx_midi_output_trigger
,
2657 static snd_rawmidi_ops_t snd_cs46xx_midi_input
=
2659 .open
= snd_cs46xx_midi_input_open
,
2660 .close
= snd_cs46xx_midi_input_close
,
2661 .trigger
= snd_cs46xx_midi_input_trigger
,
2664 int __devinit
snd_cs46xx_midi(cs46xx_t
*chip
, int device
, snd_rawmidi_t
**rrawmidi
)
2666 snd_rawmidi_t
*rmidi
;
2671 if ((err
= snd_rawmidi_new(chip
->card
, "CS46XX", device
, 1, 1, &rmidi
)) < 0)
2673 strcpy(rmidi
->name
, "CS46XX");
2674 snd_rawmidi_set_ops(rmidi
, SNDRV_RAWMIDI_STREAM_OUTPUT
, &snd_cs46xx_midi_output
);
2675 snd_rawmidi_set_ops(rmidi
, SNDRV_RAWMIDI_STREAM_INPUT
, &snd_cs46xx_midi_input
);
2676 rmidi
->info_flags
|= SNDRV_RAWMIDI_INFO_OUTPUT
| SNDRV_RAWMIDI_INFO_INPUT
| SNDRV_RAWMIDI_INFO_DUPLEX
;
2677 rmidi
->private_data
= chip
;
2678 chip
->rmidi
= rmidi
;
2686 * gameport interface
2689 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
2691 static void snd_cs46xx_gameport_trigger(struct gameport
*gameport
)
2693 cs46xx_t
*chip
= gameport_get_port_data(gameport
);
2695 snd_assert(chip
, return);
2696 snd_cs46xx_pokeBA0(chip
, BA0_JSPT
, 0xFF); //outb(gameport->io, 0xFF);
2699 static unsigned char snd_cs46xx_gameport_read(struct gameport
*gameport
)
2701 cs46xx_t
*chip
= gameport_get_port_data(gameport
);
2703 snd_assert(chip
, return 0);
2704 return snd_cs46xx_peekBA0(chip
, BA0_JSPT
); //inb(gameport->io);
2707 static int snd_cs46xx_gameport_cooked_read(struct gameport
*gameport
, int *axes
, int *buttons
)
2709 cs46xx_t
*chip
= gameport_get_port_data(gameport
);
2710 unsigned js1
, js2
, jst
;
2712 snd_assert(chip
, return 0);
2714 js1
= snd_cs46xx_peekBA0(chip
, BA0_JSC1
);
2715 js2
= snd_cs46xx_peekBA0(chip
, BA0_JSC2
);
2716 jst
= snd_cs46xx_peekBA0(chip
, BA0_JSPT
);
2718 *buttons
= (~jst
>> 4) & 0x0F;
2720 axes
[0] = ((js1
& JSC1_Y1V_MASK
) >> JSC1_Y1V_SHIFT
) & 0xFFFF;
2721 axes
[1] = ((js1
& JSC1_X1V_MASK
) >> JSC1_X1V_SHIFT
) & 0xFFFF;
2722 axes
[2] = ((js2
& JSC2_Y2V_MASK
) >> JSC2_Y2V_SHIFT
) & 0xFFFF;
2723 axes
[3] = ((js2
& JSC2_X2V_MASK
) >> JSC2_X2V_SHIFT
) & 0xFFFF;
2725 for(jst
=0;jst
<4;++jst
)
2726 if(axes
[jst
]==0xFFFF) axes
[jst
] = -1;
2730 static int snd_cs46xx_gameport_open(struct gameport
*gameport
, int mode
)
2733 case GAMEPORT_MODE_COOKED
:
2735 case GAMEPORT_MODE_RAW
:
2743 int __devinit
snd_cs46xx_gameport(cs46xx_t
*chip
)
2745 struct gameport
*gp
;
2747 chip
->gameport
= gp
= gameport_allocate_port();
2749 printk(KERN_ERR
"cs46xx: cannot allocate memory for gameport\n");
2753 gameport_set_name(gp
, "CS46xx Gameport");
2754 gameport_set_phys(gp
, "pci%s/gameport0", pci_name(chip
->pci
));
2755 gameport_set_dev_parent(gp
, &chip
->pci
->dev
);
2756 gameport_set_port_data(gp
, chip
);
2758 gp
->open
= snd_cs46xx_gameport_open
;
2759 gp
->read
= snd_cs46xx_gameport_read
;
2760 gp
->trigger
= snd_cs46xx_gameport_trigger
;
2761 gp
->cooked_read
= snd_cs46xx_gameport_cooked_read
;
2763 snd_cs46xx_pokeBA0(chip
, BA0_JSIO
, 0xFF); // ?
2764 snd_cs46xx_pokeBA0(chip
, BA0_JSCTL
, JSCTL_SP_MEDIUM_SLOW
);
2766 gameport_register_port(gp
);
2771 static inline void snd_cs46xx_remove_gameport(cs46xx_t
*chip
)
2773 if (chip
->gameport
) {
2774 gameport_unregister_port(chip
->gameport
);
2775 chip
->gameport
= NULL
;
2779 int __devinit
snd_cs46xx_gameport(cs46xx_t
*chip
) { return -ENOSYS
; }
2780 static inline void snd_cs46xx_remove_gameport(cs46xx_t
*chip
) { }
2781 #endif /* CONFIG_GAMEPORT */
2787 static long snd_cs46xx_io_read(snd_info_entry_t
*entry
, void *file_private_data
,
2788 struct file
*file
, char __user
*buf
,
2789 unsigned long count
, unsigned long pos
)
2792 snd_cs46xx_region_t
*region
= (snd_cs46xx_region_t
*)entry
->private_data
;
2795 if (pos
+ (size_t)size
> region
->size
)
2796 size
= region
->size
- pos
;
2798 if (copy_to_user_fromio(buf
, region
->remap_addr
+ pos
, size
))
2804 static struct snd_info_entry_ops snd_cs46xx_proc_io_ops
= {
2805 .read
= snd_cs46xx_io_read
,
2808 static int __devinit
snd_cs46xx_proc_init(snd_card_t
* card
, cs46xx_t
*chip
)
2810 snd_info_entry_t
*entry
;
2813 for (idx
= 0; idx
< 5; idx
++) {
2814 snd_cs46xx_region_t
*region
= &chip
->region
.idx
[idx
];
2815 if (! snd_card_proc_new(card
, region
->name
, &entry
)) {
2816 entry
->content
= SNDRV_INFO_CONTENT_DATA
;
2817 entry
->private_data
= chip
;
2818 entry
->c
.ops
= &snd_cs46xx_proc_io_ops
;
2819 entry
->size
= region
->size
;
2820 entry
->mode
= S_IFREG
| S_IRUSR
;
2823 #ifdef CONFIG_SND_CS46XX_NEW_DSP
2824 cs46xx_dsp_proc_init(card
, chip
);
2829 static int snd_cs46xx_proc_done(cs46xx_t
*chip
)
2831 #ifdef CONFIG_SND_CS46XX_NEW_DSP
2832 cs46xx_dsp_proc_done(chip
);
2840 static void snd_cs46xx_hw_stop(cs46xx_t
*chip
)
2844 tmp
= snd_cs46xx_peek(chip
, BA1_PFIE
);
2847 snd_cs46xx_poke(chip
, BA1_PFIE
, tmp
); /* playback interrupt disable */
2849 tmp
= snd_cs46xx_peek(chip
, BA1_CIE
);
2852 snd_cs46xx_poke(chip
, BA1_CIE
, tmp
); /* capture interrupt disable */
2855 * Stop playback DMA.
2857 tmp
= snd_cs46xx_peek(chip
, BA1_PCTL
);
2858 snd_cs46xx_poke(chip
, BA1_PCTL
, tmp
& 0x0000ffff);
2863 tmp
= snd_cs46xx_peek(chip
, BA1_CCTL
);
2864 snd_cs46xx_poke(chip
, BA1_CCTL
, tmp
& 0xffff0000);
2867 * Reset the processor.
2869 snd_cs46xx_reset(chip
);
2871 snd_cs46xx_proc_stop(chip
);
2874 * Power down the PLL.
2876 snd_cs46xx_pokeBA0(chip
, BA0_CLKCR1
, 0);
2879 * Turn off the Processor by turning off the software clock enable flag in
2880 * the clock control register.
2882 tmp
= snd_cs46xx_peekBA0(chip
, BA0_CLKCR1
) & ~CLKCR1_SWCE
;
2883 snd_cs46xx_pokeBA0(chip
, BA0_CLKCR1
, tmp
);
2887 static int snd_cs46xx_free(cs46xx_t
*chip
)
2891 snd_assert(chip
!= NULL
, return -EINVAL
);
2893 if (chip
->active_ctrl
)
2894 chip
->active_ctrl(chip
, 1);
2896 snd_cs46xx_remove_gameport(chip
);
2898 if (chip
->amplifier_ctrl
)
2899 chip
->amplifier_ctrl(chip
, -chip
->amplifier
); /* force to off */
2901 snd_cs46xx_proc_done(chip
);
2903 if (chip
->region
.idx
[0].resource
)
2904 snd_cs46xx_hw_stop(chip
);
2906 for (idx
= 0; idx
< 5; idx
++) {
2907 snd_cs46xx_region_t
*region
= &chip
->region
.idx
[idx
];
2908 if (region
->remap_addr
)
2909 iounmap(region
->remap_addr
);
2910 if (region
->resource
) {
2911 release_resource(region
->resource
);
2912 kfree_nocheck(region
->resource
);
2916 free_irq(chip
->irq
, (void *)chip
);
2918 if (chip
->active_ctrl
)
2919 chip
->active_ctrl(chip
, -chip
->amplifier
);
2921 #ifdef CONFIG_SND_CS46XX_NEW_DSP
2922 if (chip
->dsp_spos_instance
) {
2923 cs46xx_dsp_spos_destroy(chip
);
2924 chip
->dsp_spos_instance
= NULL
;
2928 pci_disable_device(chip
->pci
);
2933 static int snd_cs46xx_dev_free(snd_device_t
*device
)
2935 cs46xx_t
*chip
= device
->device_data
;
2936 return snd_cs46xx_free(chip
);
2942 static int snd_cs46xx_chip_init(cs46xx_t
*chip
)
2947 * First, blast the clock control register to zero so that the PLL starts
2948 * out in a known state, and blast the master serial port control register
2949 * to zero so that the serial ports also start out in a known state.
2951 snd_cs46xx_pokeBA0(chip
, BA0_CLKCR1
, 0);
2952 snd_cs46xx_pokeBA0(chip
, BA0_SERMC1
, 0);
2955 * If we are in AC97 mode, then we must set the part to a host controlled
2956 * AC-link. Otherwise, we won't be able to bring up the link.
2958 #ifdef CONFIG_SND_CS46XX_NEW_DSP
2959 snd_cs46xx_pokeBA0(chip
, BA0_SERACC
, SERACC_HSP
| SERACC_CHIP_TYPE_2_0
|
2960 SERACC_TWO_CODECS
); /* 2.00 dual codecs */
2961 /* snd_cs46xx_pokeBA0(chip, BA0_SERACC, SERACC_HSP | SERACC_CHIP_TYPE_2_0); */ /* 2.00 codec */
2963 snd_cs46xx_pokeBA0(chip
, BA0_SERACC
, SERACC_HSP
| SERACC_CHIP_TYPE_1_03
); /* 1.03 codec */
2967 * Drive the ARST# pin low for a minimum of 1uS (as defined in the AC97
2968 * spec) and then drive it high. This is done for non AC97 modes since
2969 * there might be logic external to the CS461x that uses the ARST# line
2972 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL
, 0);
2973 #ifdef CONFIG_SND_CS46XX_NEW_DSP
2974 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL2
, 0);
2977 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL
, ACCTL_RSTN
);
2978 #ifdef CONFIG_SND_CS46XX_NEW_DSP
2979 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL2
, ACCTL_RSTN
);
2983 * The first thing we do here is to enable sync generation. As soon
2984 * as we start receiving bit clock, we'll start producing the SYNC
2987 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL
, ACCTL_ESYN
| ACCTL_RSTN
);
2988 #ifdef CONFIG_SND_CS46XX_NEW_DSP
2989 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL2
, ACCTL_ESYN
| ACCTL_RSTN
);
2993 * Now wait for a short while to allow the AC97 part to start
2994 * generating bit clock (so we don't try to start the PLL without an
3000 * Set the serial port timing configuration, so that
3001 * the clock control circuit gets its clock from the correct place.
3003 snd_cs46xx_pokeBA0(chip
, BA0_SERMC1
, SERMC1_PTC_AC97
);
3006 * Write the selected clock control setup to the hardware. Do not turn on
3007 * SWCE yet (if requested), so that the devices clocked by the output of
3008 * PLL are not clocked until the PLL is stable.
3010 snd_cs46xx_pokeBA0(chip
, BA0_PLLCC
, PLLCC_LPF_1050_2780_KHZ
| PLLCC_CDR_73_104_MHZ
);
3011 snd_cs46xx_pokeBA0(chip
, BA0_PLLM
, 0x3a);
3012 snd_cs46xx_pokeBA0(chip
, BA0_CLKCR2
, CLKCR2_PDIVS_8
);
3017 snd_cs46xx_pokeBA0(chip
, BA0_CLKCR1
, CLKCR1_PLLP
);
3020 * Wait until the PLL has stabilized.
3022 set_current_state(TASK_UNINTERRUPTIBLE
);
3023 schedule_timeout(HZ
/10); /* 100ms */
3026 * Turn on clocking of the core so that we can setup the serial ports.
3028 snd_cs46xx_pokeBA0(chip
, BA0_CLKCR1
, CLKCR1_PLLP
| CLKCR1_SWCE
);
3031 * Enable FIFO Host Bypass
3033 snd_cs46xx_pokeBA0(chip
, BA0_SERBCF
, SERBCF_HBP
);
3036 * Fill the serial port FIFOs with silence.
3038 snd_cs46xx_clear_serial_FIFOs(chip
);
3041 * Set the serial port FIFO pointer to the first sample in the FIFO.
3043 /* snd_cs46xx_pokeBA0(chip, BA0_SERBSP, 0); */
3046 * Write the serial port configuration to the part. The master
3047 * enable bit is not set until all other values have been written.
3049 snd_cs46xx_pokeBA0(chip
, BA0_SERC1
, SERC1_SO1F_AC97
| SERC1_SO1EN
);
3050 snd_cs46xx_pokeBA0(chip
, BA0_SERC2
, SERC2_SI1F_AC97
| SERC1_SO1EN
);
3051 snd_cs46xx_pokeBA0(chip
, BA0_SERMC1
, SERMC1_PTC_AC97
| SERMC1_MSPE
);
3054 #ifdef CONFIG_SND_CS46XX_NEW_DSP
3055 snd_cs46xx_pokeBA0(chip
, BA0_SERC7
, SERC7_ASDI2EN
);
3056 snd_cs46xx_pokeBA0(chip
, BA0_SERC3
, 0);
3057 snd_cs46xx_pokeBA0(chip
, BA0_SERC4
, 0);
3058 snd_cs46xx_pokeBA0(chip
, BA0_SERC5
, 0);
3059 snd_cs46xx_pokeBA0(chip
, BA0_SERC6
, 1);
3066 * Wait for the codec ready signal from the AC97 codec.
3069 while (timeout
-- > 0) {
3071 * Read the AC97 status register to see if we've seen a CODEC READY
3072 * signal from the AC97 codec.
3074 if (snd_cs46xx_peekBA0(chip
, BA0_ACSTS
) & ACSTS_CRDY
)
3076 set_current_state(TASK_UNINTERRUPTIBLE
);
3077 schedule_timeout((HZ
+99)/100);
3081 snd_printk("create - never read codec ready from AC'97\n");
3082 snd_printk("it is not probably bug, try to use CS4236 driver\n");
3085 #ifdef CONFIG_SND_CS46XX_NEW_DSP
3088 for (count
= 0; count
< 150; count
++) {
3089 /* First, we want to wait for a short time. */
3092 if (snd_cs46xx_peekBA0(chip
, BA0_ACSTS2
) & ACSTS_CRDY
)
3097 * Make sure CODEC is READY.
3099 if (!(snd_cs46xx_peekBA0(chip
, BA0_ACSTS2
) & ACSTS_CRDY
))
3100 snd_printdd("cs46xx: never read card ready from secondary AC'97\n");
3105 * Assert the vaid frame signal so that we can start sending commands
3106 * to the AC97 codec.
3108 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL
, ACCTL_VFRM
| ACCTL_ESYN
| ACCTL_RSTN
);
3109 #ifdef CONFIG_SND_CS46XX_NEW_DSP
3110 snd_cs46xx_pokeBA0(chip
, BA0_ACCTL2
, ACCTL_VFRM
| ACCTL_ESYN
| ACCTL_RSTN
);
3115 * Wait until we've sampled input slots 3 and 4 as valid, meaning that
3116 * the codec is pumping ADC data across the AC-link.
3119 while (timeout
-- > 0) {
3121 * Read the input slot valid register and see if input slots 3 and
3124 if ((snd_cs46xx_peekBA0(chip
, BA0_ACISV
) & (ACISV_ISV3
| ACISV_ISV4
)) == (ACISV_ISV3
| ACISV_ISV4
))
3126 set_current_state(TASK_UNINTERRUPTIBLE
);
3127 schedule_timeout((HZ
+99)/100);
3130 #ifndef CONFIG_SND_CS46XX_NEW_DSP
3131 snd_printk("create - never read ISV3 & ISV4 from AC'97\n");
3134 /* This may happen on a cold boot with a Terratec SiXPack 5.1.
3135 Reloading the driver may help, if there's other soundcards
3136 with the same problem I would like to know. (Benny) */
3138 snd_printk("ERROR: snd-cs46xx: never read ISV3 & ISV4 from AC'97\n");
3139 snd_printk(" Try reloading the ALSA driver, if you find something\n");
3140 snd_printk(" broken or not working on your soundcard upon\n");
3141 snd_printk(" this message please report to alsa-devel@lists.sourceforge.net\n");
3148 * Now, assert valid frame and the slot 3 and 4 valid bits. This will
3149 * commense the transfer of digital audio data to the AC97 codec.
3152 snd_cs46xx_pokeBA0(chip
, BA0_ACOSV
, ACOSV_SLV3
| ACOSV_SLV4
);
3156 * Power down the DAC and ADC. We will power them up (if) when we need
3159 /* snd_cs46xx_pokeBA0(chip, BA0_AC97_POWERDOWN, 0x300); */
3162 * Turn off the Processor by turning off the software clock enable flag in
3163 * the clock control register.
3165 /* tmp = snd_cs46xx_peekBA0(chip, BA0_CLKCR1) & ~CLKCR1_SWCE; */
3166 /* snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp); */
3172 * start and load DSP
3174 int __devinit
snd_cs46xx_start_dsp(cs46xx_t
*chip
)
3178 * Reset the processor.
3180 snd_cs46xx_reset(chip
);
3182 * Download the image to the processor.
3184 #ifdef CONFIG_SND_CS46XX_NEW_DSP
3186 if (cs46xx_dsp_load_module(chip
, &cwcemb80_module
) < 0) {
3187 snd_printk(KERN_ERR
"image download error\n");
3192 if (cs46xx_dsp_load_module(chip
, &cwc4630_module
) < 0) {
3193 snd_printk(KERN_ERR
"image download error [cwc4630]\n");
3197 if (cs46xx_dsp_load_module(chip
, &cwcasync_module
) < 0) {
3198 snd_printk(KERN_ERR
"image download error [cwcasync]\n");
3202 if (cs46xx_dsp_load_module(chip
, &cwcsnoop_module
) < 0) {
3203 snd_printk(KERN_ERR
"image download error [cwcsnoop]\n");
3207 if (cs46xx_dsp_load_module(chip
, &cwcbinhack_module
) < 0) {
3208 snd_printk(KERN_ERR
"image download error [cwcbinhack]\n");
3212 if (cs46xx_dsp_load_module(chip
, &cwcdma_module
) < 0) {
3213 snd_printk(KERN_ERR
"image download error [cwcdma]\n");
3217 if (cs46xx_dsp_scb_and_task_init(chip
) < 0)
3221 if (snd_cs46xx_download_image(chip
) < 0) {
3222 snd_printk("image download error\n");
3227 * Stop playback DMA.
3229 tmp
= snd_cs46xx_peek(chip
, BA1_PCTL
);
3230 chip
->play_ctl
= tmp
& 0xffff0000;
3231 snd_cs46xx_poke(chip
, BA1_PCTL
, tmp
& 0x0000ffff);
3237 tmp
= snd_cs46xx_peek(chip
, BA1_CCTL
);
3238 chip
->capt
.ctl
= tmp
& 0x0000ffff;
3239 snd_cs46xx_poke(chip
, BA1_CCTL
, tmp
& 0xffff0000);
3243 snd_cs46xx_set_play_sample_rate(chip
, 8000);
3244 snd_cs46xx_set_capture_sample_rate(chip
, 8000);
3246 snd_cs46xx_proc_start(chip
);
3249 * Enable interrupts on the part.
3251 snd_cs46xx_pokeBA0(chip
, BA0_HICR
, HICR_IEV
| HICR_CHGM
);
3253 tmp
= snd_cs46xx_peek(chip
, BA1_PFIE
);
3255 snd_cs46xx_poke(chip
, BA1_PFIE
, tmp
); /* playback interrupt enable */
3257 tmp
= snd_cs46xx_peek(chip
, BA1_CIE
);
3260 snd_cs46xx_poke(chip
, BA1_CIE
, tmp
); /* capture interrupt enable */
3262 #ifndef CONFIG_SND_CS46XX_NEW_DSP
3263 /* set the attenuation to 0dB */
3264 snd_cs46xx_poke(chip
, BA1_PVOL
, 0x80008000);
3265 snd_cs46xx_poke(chip
, BA1_CVOL
, 0x80008000);
3273 * AMP control - null AMP
3276 static void amp_none(cs46xx_t
*chip
, int change
)
3280 #ifdef CONFIG_SND_CS46XX_NEW_DSP
3281 static int voyetra_setup_eapd_slot(cs46xx_t
*chip
)
3284 u32 idx
, valid_slots
,tmp
,powerdown
= 0;
3285 u16 modem_power
,pin_config
,logic_type
;
3287 snd_printdd ("cs46xx: cs46xx_setup_eapd_slot()+\n");
3290 * See if the devices are powered down. If so, we must power them up first
3291 * or they will not respond.
3293 tmp
= snd_cs46xx_peekBA0(chip
, BA0_CLKCR1
);
3295 if (!(tmp
& CLKCR1_SWCE
)) {
3296 snd_cs46xx_pokeBA0(chip
, BA0_CLKCR1
, tmp
| CLKCR1_SWCE
);
3301 * Clear PRA. The Bonzo chip will be used for GPIO not for modem
3304 if(chip
->nr_ac97_codecs
!= 2) {
3305 snd_printk (KERN_ERR
"cs46xx: cs46xx_setup_eapd_slot() - no secondary codec configured\n");
3309 modem_power
= snd_cs46xx_codec_read (chip
,
3310 AC97_EXTENDED_MSTATUS
,
3311 CS46XX_SECONDARY_CODEC_INDEX
);
3312 modem_power
&=0xFEFF;
3314 snd_cs46xx_codec_write(chip
,
3315 AC97_EXTENDED_MSTATUS
, modem_power
,
3316 CS46XX_SECONDARY_CODEC_INDEX
);
3319 * Set GPIO pin's 7 and 8 so that they are configured for output.
3321 pin_config
= snd_cs46xx_codec_read (chip
,
3323 CS46XX_SECONDARY_CODEC_INDEX
);
3326 snd_cs46xx_codec_write(chip
,
3327 AC97_GPIO_CFG
, pin_config
,
3328 CS46XX_SECONDARY_CODEC_INDEX
);
3331 * Set GPIO pin's 7 and 8 so that they are compatible with CMOS logic.
3334 logic_type
= snd_cs46xx_codec_read(chip
, AC97_GPIO_POLARITY
,
3335 CS46XX_SECONDARY_CODEC_INDEX
);
3338 snd_cs46xx_codec_write (chip
, AC97_GPIO_POLARITY
, logic_type
,
3339 CS46XX_SECONDARY_CODEC_INDEX
);
3341 valid_slots
= snd_cs46xx_peekBA0(chip
, BA0_ACOSV
);
3342 valid_slots
|= 0x200;
3343 snd_cs46xx_pokeBA0(chip
, BA0_ACOSV
, valid_slots
);
3345 if ( cs46xx_wait_for_fifo(chip
,1) ) {
3346 snd_printdd("FIFO is busy\n");
3352 * Fill slots 12 with the correct value for the GPIO pins.
3354 for(idx
= 0x90; idx
<= 0x9F; idx
++) {
3356 * Initialize the fifo so that bits 7 and 8 are on.
3358 * Remember that the GPIO pins in bonzo are shifted by 4 bits to
3359 * the left. 0x1800 corresponds to bits 7 and 8.
3361 snd_cs46xx_pokeBA0(chip
, BA0_SERBWP
, 0x1800);
3364 * Wait for command to complete
3366 if ( cs46xx_wait_for_fifo(chip
,200) ) {
3367 snd_printdd("failed waiting for FIFO at addr (%02X)\n",idx
);
3373 * Write the serial port FIFO index.
3375 snd_cs46xx_pokeBA0(chip
, BA0_SERBAD
, idx
);
3378 * Tell the serial port to load the new value into the FIFO location.
3380 snd_cs46xx_pokeBA0(chip
, BA0_SERBCM
, SERBCM_WRC
);
3383 /* wait for last command to complete */
3384 cs46xx_wait_for_fifo(chip
,200);
3387 * Now, if we powered up the devices, then power them back down again.
3388 * This is kinda ugly, but should never happen.
3391 snd_cs46xx_pokeBA0(chip
, BA0_CLKCR1
, tmp
);
3401 static void amp_voyetra(cs46xx_t
*chip
, int change
)
3403 /* Manage the EAPD bit on the Crystal 4297
3404 and the Analog AD1885 */
3406 #ifdef CONFIG_SND_CS46XX_NEW_DSP
3407 int old
= chip
->amplifier
;
3411 chip
->amplifier
+= change
;
3412 oval
= snd_cs46xx_codec_read(chip
, AC97_POWERDOWN
,
3413 CS46XX_PRIMARY_CODEC_INDEX
);
3415 if (chip
->amplifier
) {
3416 /* Turn the EAPD amp on */
3419 /* Turn the EAPD amp off */
3423 snd_cs46xx_codec_write(chip
, AC97_POWERDOWN
, val
,
3424 CS46XX_PRIMARY_CODEC_INDEX
);
3425 if (chip
->eapd_switch
)
3426 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
3427 &chip
->eapd_switch
->id
);
3430 #ifdef CONFIG_SND_CS46XX_NEW_DSP
3431 if (chip
->amplifier
&& !old
) {
3432 voyetra_setup_eapd_slot(chip
);
3437 static void hercules_init(cs46xx_t
*chip
)
3439 /* default: AMP off, and SPDIF input optical */
3440 snd_cs46xx_pokeBA0(chip
, BA0_EGPIODR
, EGPIODR_GPOE0
);
3441 snd_cs46xx_pokeBA0(chip
, BA0_EGPIOPTR
, EGPIODR_GPOE0
);
3446 * Game Theatre XP card - EGPIO[2] is used to enable the external amp.
3448 static void amp_hercules(cs46xx_t
*chip
, int change
)
3450 int old
= chip
->amplifier
;
3451 int val1
= snd_cs46xx_peekBA0(chip
, BA0_EGPIODR
);
3452 int val2
= snd_cs46xx_peekBA0(chip
, BA0_EGPIOPTR
);
3454 chip
->amplifier
+= change
;
3455 if (chip
->amplifier
&& !old
) {
3456 snd_printdd ("Hercules amplifier ON\n");
3458 snd_cs46xx_pokeBA0(chip
, BA0_EGPIODR
,
3459 EGPIODR_GPOE2
| val1
); /* enable EGPIO2 output */
3460 snd_cs46xx_pokeBA0(chip
, BA0_EGPIOPTR
,
3461 EGPIOPTR_GPPT2
| val2
); /* open-drain on output */
3462 } else if (old
&& !chip
->amplifier
) {
3463 snd_printdd ("Hercules amplifier OFF\n");
3464 snd_cs46xx_pokeBA0(chip
, BA0_EGPIODR
, val1
& ~EGPIODR_GPOE2
); /* disable */
3465 snd_cs46xx_pokeBA0(chip
, BA0_EGPIOPTR
, val2
& ~EGPIOPTR_GPPT2
); /* disable */
3469 static void voyetra_mixer_init (cs46xx_t
*chip
)
3471 snd_printdd ("initializing Voyetra mixer\n");
3473 /* Enable SPDIF out */
3474 snd_cs46xx_pokeBA0(chip
, BA0_EGPIODR
, EGPIODR_GPOE0
);
3475 snd_cs46xx_pokeBA0(chip
, BA0_EGPIOPTR
, EGPIODR_GPOE0
);
3478 static void hercules_mixer_init (cs46xx_t
*chip
)
3480 #ifdef CONFIG_SND_CS46XX_NEW_DSP
3483 snd_card_t
*card
= chip
->card
;
3486 /* set EGPIO to default */
3487 hercules_init(chip
);
3489 snd_printdd ("initializing Hercules mixer\n");
3491 #ifdef CONFIG_SND_CS46XX_NEW_DSP
3492 for (idx
= 0 ; idx
< ARRAY_SIZE(snd_hercules_controls
); idx
++) {
3493 snd_kcontrol_t
*kctl
;
3495 kctl
= snd_ctl_new1(&snd_hercules_controls
[idx
], chip
);
3496 if ((err
= snd_ctl_add(card
, kctl
)) < 0) {
3497 printk (KERN_ERR
"cs46xx: failed to initialize Hercules mixer (%d)\n",err
);
3510 static void amp_voyetra_4294(cs46xx_t
*chip
, int change
)
3512 chip
->amplifier
+= change
;
3514 if (chip
->amplifier
) {
3515 /* Switch the GPIO pins 7 and 8 to open drain */
3516 snd_cs46xx_codec_write(chip
, 0x4C,
3517 snd_cs46xx_codec_read(chip
, 0x4C) & 0xFE7F);
3518 snd_cs46xx_codec_write(chip
, 0x4E,
3519 snd_cs46xx_codec_read(chip
, 0x4E) | 0x0180);
3520 /* Now wake the AMP (this might be backwards) */
3521 snd_cs46xx_codec_write(chip
, 0x54,
3522 snd_cs46xx_codec_read(chip
, 0x54) & ~0x0180);
3524 snd_cs46xx_codec_write(chip
, 0x54,
3525 snd_cs46xx_codec_read(chip
, 0x54) | 0x0180);
3534 #ifndef PCI_VENDOR_ID_INTEL
3535 #define PCI_VENDOR_ID_INTEL 0x8086
3536 #endif /* PCI_VENDOR_ID_INTEL */
3538 #ifndef PCI_DEVICE_ID_INTEL_82371AB_3
3539 #define PCI_DEVICE_ID_INTEL_82371AB_3 0x7113
3540 #endif /* PCI_DEVICE_ID_INTEL_82371AB_3 */
3543 * Handle the CLKRUN on a thinkpad. We must disable CLKRUN support
3544 * whenever we need to beat on the chip.
3546 * The original idea and code for this hack comes from David Kaiser at
3547 * Linuxcare. Perhaps one day Crystal will document their chips well
3548 * enough to make them useful.
3551 static void clkrun_hack(cs46xx_t
*chip
, int change
)
3555 if (chip
->acpi_dev
== NULL
)
3558 chip
->amplifier
+= change
;
3560 /* Read ACPI port */
3561 nval
= control
= inw(chip
->acpi_port
+ 0x10);
3563 /* Flip CLKRUN off while running */
3564 if (! chip
->amplifier
)
3568 if (nval
!= control
)
3569 outw(nval
, chip
->acpi_port
+ 0x10);
3574 * detect intel piix4
3576 static void clkrun_init(cs46xx_t
*chip
)
3580 chip
->acpi_dev
= pci_find_device(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82371AB_3
, NULL
);
3581 if (chip
->acpi_dev
== NULL
)
3582 return; /* Not a thinkpad thats for sure */
3584 /* Find the control port */
3585 pci_read_config_byte(chip
->acpi_dev
, 0x41, &pp
);
3586 chip
->acpi_port
= pp
<< 8;
3599 void (*init
)(cs46xx_t
*);
3600 void (*amp
)(cs46xx_t
*, int);
3601 void (*active
)(cs46xx_t
*, int);
3602 void (*mixer_init
)(cs46xx_t
*);
3605 static struct cs_card_type __devinitdata cards
[] = {
3609 .name
= "Genius Soundmaker 128 value",
3610 /* nothing special */
3617 .mixer_init
= voyetra_mixer_init
,
3622 .name
= "Mitac MI6020/21",
3628 .name
= "Hercules Game Theatre XP",
3629 .amp
= amp_hercules
,
3630 .mixer_init
= hercules_mixer_init
,
3635 .name
= "Hercules Game Theatre XP",
3636 .amp
= amp_hercules
,
3637 .mixer_init
= hercules_mixer_init
,
3642 .name
= "Hercules Game Theatre XP",
3643 .amp
= amp_hercules
,
3644 .mixer_init
= hercules_mixer_init
,
3650 .name
= "Hercules Game Theatre XP",
3651 .amp
= amp_hercules
,
3652 .mixer_init
= hercules_mixer_init
,
3657 .name
= "Hercules Game Theatre XP",
3658 .amp
= amp_hercules
,
3659 .mixer_init
= hercules_mixer_init
,
3664 .name
= "Hercules Game Theatre XP",
3665 .amp
= amp_hercules
,
3666 .mixer_init
= hercules_mixer_init
,
3672 .name
= "Terratec SiXPack 5.1",
3674 /* Not sure if the 570 needs the clkrun hack */
3676 .vendor
= PCI_VENDOR_ID_IBM
,
3678 .name
= "Thinkpad 570",
3679 .init
= clkrun_init
,
3680 .active
= clkrun_hack
,
3683 .vendor
= PCI_VENDOR_ID_IBM
,
3685 .name
= "Thinkpad 600X/A20/T20",
3686 .init
= clkrun_init
,
3687 .active
= clkrun_hack
,
3690 .vendor
= PCI_VENDOR_ID_IBM
,
3692 .name
= "Thinkpad 600E (unsupported)",
3702 static int snd_cs46xx_suspend(snd_card_t
*card
, pm_message_t state
)
3704 cs46xx_t
*chip
= card
->pm_private_data
;
3707 snd_pcm_suspend_all(chip
->pcm
);
3708 // chip->ac97_powerdown = snd_cs46xx_codec_read(chip, AC97_POWER_CONTROL);
3709 // chip->ac97_general_purpose = snd_cs46xx_codec_read(chip, BA0_AC97_GENERAL_PURPOSE);
3711 snd_ac97_suspend(chip
->ac97
[CS46XX_PRIMARY_CODEC_INDEX
]);
3712 if (chip
->ac97
[CS46XX_SECONDARY_CODEC_INDEX
])
3713 snd_ac97_suspend(chip
->ac97
[CS46XX_SECONDARY_CODEC_INDEX
]);
3715 amp_saved
= chip
->amplifier
;
3717 chip
->amplifier_ctrl(chip
, -chip
->amplifier
);
3718 snd_cs46xx_hw_stop(chip
);
3719 /* disable CLKRUN */
3720 chip
->active_ctrl(chip
, -chip
->amplifier
);
3721 chip
->amplifier
= amp_saved
; /* restore the status */
3722 pci_disable_device(chip
->pci
);
3726 static int snd_cs46xx_resume(snd_card_t
*card
)
3728 cs46xx_t
*chip
= card
->pm_private_data
;
3731 pci_enable_device(chip
->pci
);
3732 pci_set_master(chip
->pci
);
3733 amp_saved
= chip
->amplifier
;
3734 chip
->amplifier
= 0;
3735 chip
->active_ctrl(chip
, 1); /* force to on */
3737 snd_cs46xx_chip_init(chip
);
3740 snd_cs46xx_codec_write(chip
, BA0_AC97_GENERAL_PURPOSE
,
3741 chip
->ac97_general_purpose
);
3742 snd_cs46xx_codec_write(chip
, AC97_POWER_CONTROL
,
3743 chip
->ac97_powerdown
);
3745 snd_cs46xx_codec_write(chip
, BA0_AC97_POWERDOWN
,
3746 chip
->ac97_powerdown
);
3750 snd_ac97_resume(chip
->ac97
[CS46XX_PRIMARY_CODEC_INDEX
]);
3751 if (chip
->ac97
[CS46XX_SECONDARY_CODEC_INDEX
])
3752 snd_ac97_resume(chip
->ac97
[CS46XX_SECONDARY_CODEC_INDEX
]);
3755 chip
->amplifier_ctrl(chip
, 1); /* turn amp on */
3757 chip
->active_ctrl(chip
, -1); /* disable CLKRUN */
3758 chip
->amplifier
= amp_saved
;
3761 #endif /* CONFIG_PM */
3767 int __devinit
snd_cs46xx_create(snd_card_t
* card
,
3768 struct pci_dev
* pci
,
3769 int external_amp
, int thinkpad
,
3774 snd_cs46xx_region_t
*region
;
3775 struct cs_card_type
*cp
;
3776 u16 ss_card
, ss_vendor
;
3777 static snd_device_ops_t ops
= {
3778 .dev_free
= snd_cs46xx_dev_free
,
3783 /* enable PCI device */
3784 if ((err
= pci_enable_device(pci
)) < 0)
3787 chip
= kcalloc(1, sizeof(*chip
), GFP_KERNEL
);
3789 pci_disable_device(pci
);
3792 spin_lock_init(&chip
->reg_lock
);
3793 #ifdef CONFIG_SND_CS46XX_NEW_DSP
3794 init_MUTEX(&chip
->spos_mutex
);
3799 chip
->ba0_addr
= pci_resource_start(pci
, 0);
3800 chip
->ba1_addr
= pci_resource_start(pci
, 1);
3801 if (chip
->ba0_addr
== 0 || chip
->ba0_addr
== (unsigned long)~0 ||
3802 chip
->ba1_addr
== 0 || chip
->ba1_addr
== (unsigned long)~0) {
3803 snd_printk("wrong address(es) - ba0 = 0x%lx, ba1 = 0x%lx\n", chip
->ba0_addr
, chip
->ba1_addr
);
3804 snd_cs46xx_free(chip
);
3808 region
= &chip
->region
.name
.ba0
;
3809 strcpy(region
->name
, "CS46xx_BA0");
3810 region
->base
= chip
->ba0_addr
;
3811 region
->size
= CS46XX_BA0_SIZE
;
3813 region
= &chip
->region
.name
.data0
;
3814 strcpy(region
->name
, "CS46xx_BA1_data0");
3815 region
->base
= chip
->ba1_addr
+ BA1_SP_DMEM0
;
3816 region
->size
= CS46XX_BA1_DATA0_SIZE
;
3818 region
= &chip
->region
.name
.data1
;
3819 strcpy(region
->name
, "CS46xx_BA1_data1");
3820 region
->base
= chip
->ba1_addr
+ BA1_SP_DMEM1
;
3821 region
->size
= CS46XX_BA1_DATA1_SIZE
;
3823 region
= &chip
->region
.name
.pmem
;
3824 strcpy(region
->name
, "CS46xx_BA1_pmem");
3825 region
->base
= chip
->ba1_addr
+ BA1_SP_PMEM
;
3826 region
->size
= CS46XX_BA1_PRG_SIZE
;
3828 region
= &chip
->region
.name
.reg
;
3829 strcpy(region
->name
, "CS46xx_BA1_reg");
3830 region
->base
= chip
->ba1_addr
+ BA1_SP_REG
;
3831 region
->size
= CS46XX_BA1_REG_SIZE
;
3833 /* set up amp and clkrun hack */
3834 pci_read_config_word(pci
, PCI_SUBSYSTEM_VENDOR_ID
, &ss_vendor
);
3835 pci_read_config_word(pci
, PCI_SUBSYSTEM_ID
, &ss_card
);
3837 for (cp
= &cards
[0]; cp
->name
; cp
++) {
3838 if (cp
->vendor
== ss_vendor
&& cp
->id
== ss_card
) {
3839 snd_printdd ("hack for %s enabled\n", cp
->name
);
3841 chip
->amplifier_ctrl
= cp
->amp
;
3842 chip
->active_ctrl
= cp
->active
;
3843 chip
->mixer_init
= cp
->mixer_init
;
3852 snd_printk("Crystal EAPD support forced on.\n");
3853 chip
->amplifier_ctrl
= amp_voyetra
;
3857 snd_printk("Activating CLKRUN hack for Thinkpad.\n");
3858 chip
->active_ctrl
= clkrun_hack
;
3862 if (chip
->amplifier_ctrl
== NULL
)
3863 chip
->amplifier_ctrl
= amp_none
;
3864 if (chip
->active_ctrl
== NULL
)
3865 chip
->active_ctrl
= amp_none
;
3867 chip
->active_ctrl(chip
, 1); /* enable CLKRUN */
3869 pci_set_master(pci
);
3871 for (idx
= 0; idx
< 5; idx
++) {
3872 region
= &chip
->region
.idx
[idx
];
3873 if ((region
->resource
= request_mem_region(region
->base
, region
->size
, region
->name
)) == NULL
) {
3874 snd_printk("unable to request memory region 0x%lx-0x%lx\n", region
->base
, region
->base
+ region
->size
- 1);
3875 snd_cs46xx_free(chip
);
3878 region
->remap_addr
= ioremap_nocache(region
->base
, region
->size
);
3879 if (region
->remap_addr
== NULL
) {
3880 snd_printk("%s ioremap problem\n", region
->name
);
3881 snd_cs46xx_free(chip
);
3886 if (request_irq(pci
->irq
, snd_cs46xx_interrupt
, SA_INTERRUPT
|SA_SHIRQ
, "CS46XX", (void *) chip
)) {
3887 snd_printk("unable to grab IRQ %d\n", pci
->irq
);
3888 snd_cs46xx_free(chip
);
3891 chip
->irq
= pci
->irq
;
3893 #ifdef CONFIG_SND_CS46XX_NEW_DSP
3894 chip
->dsp_spos_instance
= cs46xx_dsp_spos_create(chip
);
3895 if (chip
->dsp_spos_instance
== NULL
) {
3896 snd_cs46xx_free(chip
);
3901 err
= snd_cs46xx_chip_init(chip
);
3903 snd_cs46xx_free(chip
);
3907 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
3908 snd_cs46xx_free(chip
);
3912 snd_cs46xx_proc_init(card
, chip
);
3914 snd_card_set_pm_callback(card
, snd_cs46xx_suspend
, snd_cs46xx_resume
, chip
);
3916 chip
->active_ctrl(chip
, -1); /* disable CLKRUN */
3918 snd_card_set_dev(card
, &pci
->dev
);