3 * Support for audio capture
4 * PCI function #1 of the cx2388x.
6 * (c) 2007 Trent Piepho <xyzzy@speakeasy.org>
7 * (c) 2005,2006 Ricardo Cerqueira <v4l@cerqueira.org>
8 * (c) 2005 Mauro Carvalho Chehab <mchehab@infradead.org>
9 * Based on a dummy cx88 module by Gerd Knorr <kraxel@bytesex.org>
10 * Based on dummy.c by Jaroslav Kysela <perex@perex.cz>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <linux/module.h>
28 #include <linux/init.h>
29 #include <linux/device.h>
30 #include <linux/interrupt.h>
31 #include <linux/vmalloc.h>
32 #include <linux/dma-mapping.h>
33 #include <linux/pci.h>
34 #include <linux/slab.h>
36 #include <asm/delay.h>
37 #include <sound/core.h>
38 #include <sound/pcm.h>
39 #include <sound/pcm_params.h>
40 #include <sound/control.h>
41 #include <sound/initval.h>
42 #include <sound/tlv.h>
43 #include <media/wm8775.h>
48 #define dprintk(level, fmt, arg...) do { \
49 if (debug + 1 > level) \
50 printk(KERN_INFO "%s/1: " fmt, chip->core->name , ## arg);\
53 #define dprintk_core(level, fmt, arg...) do { \
54 if (debug + 1 > level) \
55 printk(KERN_DEBUG "%s/1: " fmt, chip->core->name , ## arg);\
58 /****************************************************************************
59 Data type declarations - Can be moded to a header file later
60 ****************************************************************************/
62 struct cx88_audio_buffer
{
64 struct cx88_riscmem risc
;
66 struct scatterlist
*sglist
;
71 struct cx88_audio_dev
{
72 struct cx88_core
*core
;
73 struct cx88_dmaqueue q
;
81 struct snd_card
*card
;
86 unsigned int dma_size
;
87 unsigned int period_size
;
88 unsigned int num_periods
;
90 struct cx88_audio_buffer
*buf
;
92 struct snd_pcm_substream
*substream
;
94 typedef struct cx88_audio_dev snd_cx88_card_t
;
98 /****************************************************************************
99 Module global static vars
100 ****************************************************************************/
102 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
103 static const char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
104 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
106 module_param_array(enable
, bool, NULL
, 0444);
107 MODULE_PARM_DESC(enable
, "Enable cx88x soundcard. default enabled.");
109 module_param_array(index
, int, NULL
, 0444);
110 MODULE_PARM_DESC(index
, "Index value for cx88x capture interface(s).");
113 /****************************************************************************
115 ****************************************************************************/
117 MODULE_DESCRIPTION("ALSA driver module for cx2388x based TV cards");
118 MODULE_AUTHOR("Ricardo Cerqueira");
119 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
120 MODULE_LICENSE("GPL");
121 MODULE_VERSION(CX88_VERSION
);
123 MODULE_SUPPORTED_DEVICE("{{Conexant,23881},"
125 "{{Conexant,23883}");
126 static unsigned int debug
;
127 module_param(debug
,int,0644);
128 MODULE_PARM_DESC(debug
,"enable debug messages");
130 /****************************************************************************
131 Module specific funtions
132 ****************************************************************************/
135 * BOARD Specific: Sets audio DMA
138 static int _cx88_start_audio_dma(snd_cx88_card_t
*chip
)
140 struct cx88_audio_buffer
*buf
= chip
->buf
;
141 struct cx88_core
*core
=chip
->core
;
142 const struct sram_channel
*audio_ch
= &cx88_sram_channels
[SRAM_CH25
];
144 /* Make sure RISC/FIFO are off before changing FIFO/RISC settings */
145 cx_clear(MO_AUD_DMACNTRL
, 0x11);
147 /* setup fifo + format - out channel */
148 cx88_sram_channel_setup(chip
->core
, audio_ch
, buf
->bpl
, buf
->risc
.dma
);
151 cx_write(MO_AUDD_LNGTH
, buf
->bpl
);
154 cx_write(MO_AUDD_GPCNTRL
, GP_COUNT_CONTROL_RESET
);
155 atomic_set(&chip
->count
, 0);
157 dprintk(1, "Start audio DMA, %d B/line, %d lines/FIFO, %d periods, %d "
158 "byte buffer\n", buf
->bpl
, cx_read(audio_ch
->cmds_start
+ 8)>>1,
159 chip
->num_periods
, buf
->bpl
* chip
->num_periods
);
161 /* Enables corresponding bits at AUD_INT_STAT */
162 cx_write(MO_AUD_INTMSK
, AUD_INT_OPC_ERR
| AUD_INT_DN_SYNC
|
163 AUD_INT_DN_RISCI2
| AUD_INT_DN_RISCI1
);
165 /* Clean any pending interrupt bits already set */
166 cx_write(MO_AUD_INTSTAT
, ~0);
168 /* enable audio irqs */
169 cx_set(MO_PCI_INTMSK
, chip
->core
->pci_irqmask
| PCI_INT_AUDINT
);
172 cx_set(MO_DEV_CNTRL2
, (1<<5)); /* Enables Risc Processor */
173 cx_set(MO_AUD_DMACNTRL
, 0x11); /* audio downstream FIFO and RISC enable */
176 cx88_sram_channel_dump(chip
->core
, audio_ch
);
182 * BOARD Specific: Resets audio DMA
184 static int _cx88_stop_audio_dma(snd_cx88_card_t
*chip
)
186 struct cx88_core
*core
=chip
->core
;
187 dprintk(1, "Stopping audio DMA\n");
190 cx_clear(MO_AUD_DMACNTRL
, 0x11);
193 cx_clear(MO_PCI_INTMSK
, PCI_INT_AUDINT
);
194 cx_clear(MO_AUD_INTMSK
, AUD_INT_OPC_ERR
| AUD_INT_DN_SYNC
|
195 AUD_INT_DN_RISCI2
| AUD_INT_DN_RISCI1
);
198 cx88_sram_channel_dump(chip
->core
, &cx88_sram_channels
[SRAM_CH25
]);
203 #define MAX_IRQ_LOOP 50
206 * BOARD Specific: IRQ dma bits
208 static const char *cx88_aud_irqs
[32] = {
209 "dn_risci1", "up_risci1", "rds_dn_risc1", /* 0-2 */
211 "dn_risci2", "up_risci2", "rds_dn_risc2", /* 4-6 */
213 "dnf_of", "upf_uf", "rds_dnf_uf", /* 8-10 */
215 "dn_sync", "up_sync", "rds_dn_sync", /* 12-14 */
217 "opc_err", "par_err", "rip_err", /* 16-18 */
218 "pci_abort", "ber_irq", "mchg_irq" /* 19-21 */
222 * BOARD Specific: Threats IRQ audio specific calls
224 static void cx8801_aud_irq(snd_cx88_card_t
*chip
)
226 struct cx88_core
*core
= chip
->core
;
229 status
= cx_read(MO_AUD_INTSTAT
);
230 mask
= cx_read(MO_AUD_INTMSK
);
231 if (0 == (status
& mask
))
233 cx_write(MO_AUD_INTSTAT
, status
);
234 if (debug
> 1 || (status
& mask
& ~0xff))
235 cx88_print_irqbits(core
->name
, "irq aud",
236 cx88_aud_irqs
, ARRAY_SIZE(cx88_aud_irqs
),
238 /* risc op code error */
239 if (status
& AUD_INT_OPC_ERR
) {
240 printk(KERN_WARNING
"%s/1: Audio risc op code error\n",core
->name
);
241 cx_clear(MO_AUD_DMACNTRL
, 0x11);
242 cx88_sram_channel_dump(core
, &cx88_sram_channels
[SRAM_CH25
]);
244 if (status
& AUD_INT_DN_SYNC
) {
245 dprintk(1, "Downstream sync error\n");
246 cx_write(MO_AUDD_GPCNTRL
, GP_COUNT_CONTROL_RESET
);
249 /* risc1 downstream */
250 if (status
& AUD_INT_DN_RISCI1
) {
251 atomic_set(&chip
->count
, cx_read(MO_AUDD_GPCNT
));
252 snd_pcm_period_elapsed(chip
->substream
);
254 /* FIXME: Any other status should deserve a special handling? */
258 * BOARD Specific: Handles IRQ calls
260 static irqreturn_t
cx8801_irq(int irq
, void *dev_id
)
262 snd_cx88_card_t
*chip
= dev_id
;
263 struct cx88_core
*core
= chip
->core
;
265 int loop
, handled
= 0;
267 for (loop
= 0; loop
< MAX_IRQ_LOOP
; loop
++) {
268 status
= cx_read(MO_PCI_INTSTAT
) &
269 (core
->pci_irqmask
| PCI_INT_AUDINT
);
272 dprintk(3, "cx8801_irq loop %d/%d, status %x\n",
273 loop
, MAX_IRQ_LOOP
, status
);
275 cx_write(MO_PCI_INTSTAT
, status
);
277 if (status
& core
->pci_irqmask
)
278 cx88_core_irq(core
, status
);
279 if (status
& PCI_INT_AUDINT
)
280 cx8801_aud_irq(chip
);
283 if (MAX_IRQ_LOOP
== loop
) {
285 "%s/1: IRQ loop detected, disabling interrupts\n",
287 cx_clear(MO_PCI_INTMSK
, PCI_INT_AUDINT
);
291 return IRQ_RETVAL(handled
);
294 static int cx88_alsa_dma_init(struct cx88_audio_dev
*chip
, int nr_pages
)
296 struct cx88_audio_buffer
*buf
= chip
->buf
;
300 buf
->vaddr
= vmalloc_32(nr_pages
<< PAGE_SHIFT
);
301 if (NULL
== buf
->vaddr
) {
302 dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages
);
306 dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n",
307 (unsigned long)buf
->vaddr
,
308 nr_pages
<< PAGE_SHIFT
);
310 memset(buf
->vaddr
, 0, nr_pages
<< PAGE_SHIFT
);
311 buf
->nr_pages
= nr_pages
;
313 buf
->sglist
= vzalloc(buf
->nr_pages
* sizeof(*buf
->sglist
));
314 if (NULL
== buf
->sglist
)
317 sg_init_table(buf
->sglist
, buf
->nr_pages
);
318 for (i
= 0; i
< buf
->nr_pages
; i
++) {
319 pg
= vmalloc_to_page(buf
->vaddr
+ i
* PAGE_SIZE
);
321 goto vmalloc_to_page_err
;
322 sg_set_page(&buf
->sglist
[i
], pg
, PAGE_SIZE
, 0);
335 static int cx88_alsa_dma_map(struct cx88_audio_dev
*dev
)
337 struct cx88_audio_buffer
*buf
= dev
->buf
;
339 buf
->sglen
= dma_map_sg(&dev
->pci
->dev
, buf
->sglist
,
340 buf
->nr_pages
, PCI_DMA_FROMDEVICE
);
342 if (0 == buf
->sglen
) {
343 pr_warn("%s: cx88_alsa_map_sg failed\n", __func__
);
349 static int cx88_alsa_dma_unmap(struct cx88_audio_dev
*dev
)
351 struct cx88_audio_buffer
*buf
= dev
->buf
;
356 dma_unmap_sg(&dev
->pci
->dev
, buf
->sglist
, buf
->sglen
, PCI_DMA_FROMDEVICE
);
361 static int cx88_alsa_dma_free(struct cx88_audio_buffer
*buf
)
371 static int dsp_buffer_free(snd_cx88_card_t
*chip
)
373 struct cx88_riscmem
*risc
= &chip
->buf
->risc
;
375 BUG_ON(!chip
->dma_size
);
377 dprintk(2,"Freeing buffer\n");
378 cx88_alsa_dma_unmap(chip
);
379 cx88_alsa_dma_free(chip
->buf
);
381 pci_free_consistent(chip
->pci
, risc
->size
, risc
->cpu
, risc
->dma
);
389 /****************************************************************************
391 ****************************************************************************/
394 * Digital hardware definition
396 #define DEFAULT_FIFO_SIZE 4096
397 static const struct snd_pcm_hardware snd_cx88_digital_hw
= {
398 .info
= SNDRV_PCM_INFO_MMAP
|
399 SNDRV_PCM_INFO_INTERLEAVED
|
400 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
401 SNDRV_PCM_INFO_MMAP_VALID
,
402 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
404 .rates
= SNDRV_PCM_RATE_48000
,
409 /* Analog audio output will be full of clicks and pops if there
410 are not exactly four lines in the SRAM FIFO buffer. */
411 .period_bytes_min
= DEFAULT_FIFO_SIZE
/4,
412 .period_bytes_max
= DEFAULT_FIFO_SIZE
/4,
415 .buffer_bytes_max
= (1024*1024),
419 * audio pcm capture open callback
421 static int snd_cx88_pcm_open(struct snd_pcm_substream
*substream
)
423 snd_cx88_card_t
*chip
= snd_pcm_substream_chip(substream
);
424 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
428 printk(KERN_ERR
"BUG: cx88 can't find device struct."
429 " Can't proceed with open\n");
433 err
= snd_pcm_hw_constraint_pow2(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIODS
);
437 chip
->substream
= substream
;
439 runtime
->hw
= snd_cx88_digital_hw
;
441 if (cx88_sram_channels
[SRAM_CH25
].fifo_size
!= DEFAULT_FIFO_SIZE
) {
442 unsigned int bpl
= cx88_sram_channels
[SRAM_CH25
].fifo_size
/ 4;
443 bpl
&= ~7; /* must be multiple of 8 */
444 runtime
->hw
.period_bytes_min
= bpl
;
445 runtime
->hw
.period_bytes_max
= bpl
;
450 dprintk(1,"Error opening PCM!\n");
455 * audio close callback
457 static int snd_cx88_close(struct snd_pcm_substream
*substream
)
465 static int snd_cx88_hw_params(struct snd_pcm_substream
* substream
,
466 struct snd_pcm_hw_params
* hw_params
)
468 snd_cx88_card_t
*chip
= snd_pcm_substream_chip(substream
);
470 struct cx88_audio_buffer
*buf
;
473 if (substream
->runtime
->dma_area
) {
474 dsp_buffer_free(chip
);
475 substream
->runtime
->dma_area
= NULL
;
478 chip
->period_size
= params_period_bytes(hw_params
);
479 chip
->num_periods
= params_periods(hw_params
);
480 chip
->dma_size
= chip
->period_size
* params_periods(hw_params
);
482 BUG_ON(!chip
->dma_size
);
483 BUG_ON(chip
->num_periods
& (chip
->num_periods
-1));
485 buf
= kzalloc(sizeof(*buf
), GFP_KERNEL
);
490 buf
->bpl
= chip
->period_size
;
492 ret
= cx88_alsa_dma_init(chip
,
493 (PAGE_ALIGN(chip
->dma_size
) >> PAGE_SHIFT
));
497 ret
= cx88_alsa_dma_map(chip
);
501 ret
= cx88_risc_databuffer(chip
->pci
, &buf
->risc
, buf
->sglist
,
502 chip
->period_size
, chip
->num_periods
, 1);
506 /* Loop back to start of program */
507 buf
->risc
.jmp
[0] = cpu_to_le32(RISC_JUMP
|RISC_IRQ1
|RISC_CNT_INC
);
508 buf
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
);
510 substream
->runtime
->dma_area
= chip
->buf
->vaddr
;
511 substream
->runtime
->dma_bytes
= chip
->dma_size
;
512 substream
->runtime
->dma_addr
= 0;
523 static int snd_cx88_hw_free(struct snd_pcm_substream
* substream
)
526 snd_cx88_card_t
*chip
= snd_pcm_substream_chip(substream
);
528 if (substream
->runtime
->dma_area
) {
529 dsp_buffer_free(chip
);
530 substream
->runtime
->dma_area
= NULL
;
539 static int snd_cx88_prepare(struct snd_pcm_substream
*substream
)
547 static int snd_cx88_card_trigger(struct snd_pcm_substream
*substream
, int cmd
)
549 snd_cx88_card_t
*chip
= snd_pcm_substream_chip(substream
);
552 /* Local interrupts are already disabled by ALSA */
553 spin_lock(&chip
->reg_lock
);
556 case SNDRV_PCM_TRIGGER_START
:
557 err
=_cx88_start_audio_dma(chip
);
559 case SNDRV_PCM_TRIGGER_STOP
:
560 err
=_cx88_stop_audio_dma(chip
);
567 spin_unlock(&chip
->reg_lock
);
575 static snd_pcm_uframes_t
snd_cx88_pointer(struct snd_pcm_substream
*substream
)
577 snd_cx88_card_t
*chip
= snd_pcm_substream_chip(substream
);
578 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
581 count
= atomic_read(&chip
->count
);
583 // dprintk(2, "%s - count %d (+%u), period %d, frame %lu\n", __func__,
584 // count, new, count & (runtime->periods-1),
585 // runtime->period_size * (count & (runtime->periods-1)));
586 return runtime
->period_size
* (count
& (runtime
->periods
-1));
590 * page callback (needed for mmap)
592 static struct page
*snd_cx88_page(struct snd_pcm_substream
*substream
,
593 unsigned long offset
)
595 void *pageptr
= substream
->runtime
->dma_area
+ offset
;
596 return vmalloc_to_page(pageptr
);
602 static struct snd_pcm_ops snd_cx88_pcm_ops
= {
603 .open
= snd_cx88_pcm_open
,
604 .close
= snd_cx88_close
,
605 .ioctl
= snd_pcm_lib_ioctl
,
606 .hw_params
= snd_cx88_hw_params
,
607 .hw_free
= snd_cx88_hw_free
,
608 .prepare
= snd_cx88_prepare
,
609 .trigger
= snd_cx88_card_trigger
,
610 .pointer
= snd_cx88_pointer
,
611 .page
= snd_cx88_page
,
615 * create a PCM device
617 static int snd_cx88_pcm(snd_cx88_card_t
*chip
, int device
, const char *name
)
622 err
= snd_pcm_new(chip
->card
, name
, device
, 0, 1, &pcm
);
625 pcm
->private_data
= chip
;
626 strcpy(pcm
->name
, name
);
627 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_cx88_pcm_ops
);
632 /****************************************************************************
634 ****************************************************************************/
635 static int snd_cx88_volume_info(struct snd_kcontrol
*kcontrol
,
636 struct snd_ctl_elem_info
*info
)
638 info
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
640 info
->value
.integer
.min
= 0;
641 info
->value
.integer
.max
= 0x3f;
646 static int snd_cx88_volume_get(struct snd_kcontrol
*kcontrol
,
647 struct snd_ctl_elem_value
*value
)
649 snd_cx88_card_t
*chip
= snd_kcontrol_chip(kcontrol
);
650 struct cx88_core
*core
=chip
->core
;
651 int vol
= 0x3f - (cx_read(AUD_VOL_CTL
) & 0x3f),
652 bal
= cx_read(AUD_BAL_CTL
);
654 value
->value
.integer
.value
[(bal
& 0x40) ? 0 : 1] = vol
;
656 value
->value
.integer
.value
[(bal
& 0x40) ? 1 : 0] = vol
< 0 ? 0 : vol
;
661 static void snd_cx88_wm8775_volume_put(struct snd_kcontrol
*kcontrol
,
662 struct snd_ctl_elem_value
*value
)
664 snd_cx88_card_t
*chip
= snd_kcontrol_chip(kcontrol
);
665 struct cx88_core
*core
= chip
->core
;
666 int left
= value
->value
.integer
.value
[0];
667 int right
= value
->value
.integer
.value
[1];
670 /* Pass volume & balance onto any WM8775 */
673 b
= left
? (0x8000 * right
) / left
: 0x8000;
676 b
= right
? 0xffff - (0x8000 * left
) / right
: 0x8000;
678 wm8775_s_ctrl(core
, V4L2_CID_AUDIO_VOLUME
, v
);
679 wm8775_s_ctrl(core
, V4L2_CID_AUDIO_BALANCE
, b
);
682 /* OK - TODO: test it */
683 static int snd_cx88_volume_put(struct snd_kcontrol
*kcontrol
,
684 struct snd_ctl_elem_value
*value
)
686 snd_cx88_card_t
*chip
= snd_kcontrol_chip(kcontrol
);
687 struct cx88_core
*core
=chip
->core
;
688 int left
, right
, v
, b
;
693 snd_cx88_wm8775_volume_put(kcontrol
, value
);
695 left
= value
->value
.integer
.value
[0] & 0x3f;
696 right
= value
->value
.integer
.value
[1] & 0x3f;
704 /* Do we really know this will always be called with IRQs on? */
705 spin_lock_irq(&chip
->reg_lock
);
706 old
= cx_read(AUD_VOL_CTL
);
707 if (v
!= (old
& 0x3f)) {
708 cx_swrite(SHADOW_AUD_VOL_CTL
, AUD_VOL_CTL
, (old
& ~0x3f) | v
);
711 if ((cx_read(AUD_BAL_CTL
) & 0x7f) != b
) {
712 cx_write(AUD_BAL_CTL
, b
);
715 spin_unlock_irq(&chip
->reg_lock
);
720 static const DECLARE_TLV_DB_SCALE(snd_cx88_db_scale
, -6300, 100, 0);
722 static const struct snd_kcontrol_new snd_cx88_volume
= {
723 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
724 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
725 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
726 .name
= "Analog-TV Volume",
727 .info
= snd_cx88_volume_info
,
728 .get
= snd_cx88_volume_get
,
729 .put
= snd_cx88_volume_put
,
730 .tlv
.p
= snd_cx88_db_scale
,
733 static int snd_cx88_switch_get(struct snd_kcontrol
*kcontrol
,
734 struct snd_ctl_elem_value
*value
)
736 snd_cx88_card_t
*chip
= snd_kcontrol_chip(kcontrol
);
737 struct cx88_core
*core
= chip
->core
;
738 u32 bit
= kcontrol
->private_value
;
740 value
->value
.integer
.value
[0] = !(cx_read(AUD_VOL_CTL
) & bit
);
744 static int snd_cx88_switch_put(struct snd_kcontrol
*kcontrol
,
745 struct snd_ctl_elem_value
*value
)
747 snd_cx88_card_t
*chip
= snd_kcontrol_chip(kcontrol
);
748 struct cx88_core
*core
= chip
->core
;
749 u32 bit
= kcontrol
->private_value
;
753 spin_lock_irq(&chip
->reg_lock
);
754 vol
= cx_read(AUD_VOL_CTL
);
755 if (value
->value
.integer
.value
[0] != !(vol
& bit
)) {
757 cx_swrite(SHADOW_AUD_VOL_CTL
, AUD_VOL_CTL
, vol
);
758 /* Pass mute onto any WM8775 */
759 if (core
->sd_wm8775
&& ((1<<6) == bit
))
760 wm8775_s_ctrl(core
, V4L2_CID_AUDIO_MUTE
, 0 != (vol
& bit
));
763 spin_unlock_irq(&chip
->reg_lock
);
767 static const struct snd_kcontrol_new snd_cx88_dac_switch
= {
768 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
769 .name
= "Audio-Out Switch",
770 .info
= snd_ctl_boolean_mono_info
,
771 .get
= snd_cx88_switch_get
,
772 .put
= snd_cx88_switch_put
,
773 .private_value
= (1<<8),
776 static const struct snd_kcontrol_new snd_cx88_source_switch
= {
777 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
778 .name
= "Analog-TV Switch",
779 .info
= snd_ctl_boolean_mono_info
,
780 .get
= snd_cx88_switch_get
,
781 .put
= snd_cx88_switch_put
,
782 .private_value
= (1<<6),
785 static int snd_cx88_alc_get(struct snd_kcontrol
*kcontrol
,
786 struct snd_ctl_elem_value
*value
)
788 snd_cx88_card_t
*chip
= snd_kcontrol_chip(kcontrol
);
789 struct cx88_core
*core
= chip
->core
;
792 val
= wm8775_g_ctrl(core
, V4L2_CID_AUDIO_LOUDNESS
);
793 value
->value
.integer
.value
[0] = val
? 1 : 0;
797 static int snd_cx88_alc_put(struct snd_kcontrol
*kcontrol
,
798 struct snd_ctl_elem_value
*value
)
800 snd_cx88_card_t
*chip
= snd_kcontrol_chip(kcontrol
);
801 struct cx88_core
*core
= chip
->core
;
802 struct v4l2_control client_ctl
;
804 memset(&client_ctl
, 0, sizeof(client_ctl
));
805 client_ctl
.value
= 0 != value
->value
.integer
.value
[0];
806 client_ctl
.id
= V4L2_CID_AUDIO_LOUDNESS
;
807 call_hw(core
, WM8775_GID
, core
, s_ctrl
, &client_ctl
);
812 static struct snd_kcontrol_new snd_cx88_alc_switch
= {
813 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
814 .name
= "Line-In ALC Switch",
815 .info
= snd_ctl_boolean_mono_info
,
816 .get
= snd_cx88_alc_get
,
817 .put
= snd_cx88_alc_put
,
820 /****************************************************************************
821 Basic Flow for Sound Devices
822 ****************************************************************************/
825 * PCI ID Table - 14f1:8801 and 14f1:8811 means function 1: Audio
826 * Only boards with eeprom and byte 1 at eeprom=1 have it
829 static const struct pci_device_id cx88_audio_pci_tbl
[] = {
830 {0x14f1,0x8801,PCI_ANY_ID
,PCI_ANY_ID
,0,0,0},
831 {0x14f1,0x8811,PCI_ANY_ID
,PCI_ANY_ID
,0,0,0},
834 MODULE_DEVICE_TABLE(pci
, cx88_audio_pci_tbl
);
837 * Chip-specific destructor
840 static int snd_cx88_free(snd_cx88_card_t
*chip
)
844 free_irq(chip
->irq
, chip
);
846 cx88_core_put(chip
->core
,chip
->pci
);
848 pci_disable_device(chip
->pci
);
853 * Component Destructor
855 static void snd_cx88_dev_free(struct snd_card
* card
)
857 snd_cx88_card_t
*chip
= card
->private_data
;
864 * Alsa Constructor - Component probe
868 static int snd_cx88_create(struct snd_card
*card
, struct pci_dev
*pci
,
869 snd_cx88_card_t
**rchip
,
870 struct cx88_core
**core_ptr
)
872 snd_cx88_card_t
*chip
;
873 struct cx88_core
*core
;
875 unsigned char pci_lat
;
879 err
= pci_enable_device(pci
);
885 chip
= card
->private_data
;
887 core
= cx88_core_get(pci
);
893 err
= pci_set_dma_mask(pci
,DMA_BIT_MASK(32));
895 dprintk(0, "%s/1: Oops: no 32bit PCI DMA ???\n",core
->name
);
896 cx88_core_put(core
, pci
);
905 spin_lock_init(&chip
->reg_lock
);
910 err
= request_irq(chip
->pci
->irq
, cx8801_irq
,
911 IRQF_SHARED
, chip
->core
->name
, chip
);
913 dprintk(0, "%s: can't get IRQ %d\n",
914 chip
->core
->name
, chip
->pci
->irq
);
919 pci_read_config_byte(pci
, PCI_LATENCY_TIMER
, &pci_lat
);
921 dprintk(1,"ALSA %s/%i: found at %s, rev: %d, irq: %d, "
922 "latency: %d, mmio: 0x%llx\n", core
->name
, devno
,
923 pci_name(pci
), pci
->revision
, pci
->irq
,
924 pci_lat
, (unsigned long long)pci_resource_start(pci
,0));
926 chip
->irq
= pci
->irq
;
927 synchronize_irq(chip
->irq
);
935 static int cx88_audio_initdev(struct pci_dev
*pci
,
936 const struct pci_device_id
*pci_id
)
938 struct snd_card
*card
;
939 snd_cx88_card_t
*chip
;
940 struct cx88_core
*core
= NULL
;
943 if (devno
>= SNDRV_CARDS
)
946 if (!enable
[devno
]) {
951 err
= snd_card_new(&pci
->dev
, index
[devno
], id
[devno
], THIS_MODULE
,
952 sizeof(snd_cx88_card_t
), &card
);
956 card
->private_free
= snd_cx88_dev_free
;
958 err
= snd_cx88_create(card
, pci
, &chip
, &core
);
962 err
= snd_cx88_pcm(chip
, 0, "CX88 Digital");
966 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_cx88_volume
, chip
));
969 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_cx88_dac_switch
, chip
));
972 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_cx88_source_switch
, chip
));
976 /* If there's a wm8775 then add a Line-In ALC switch */
978 snd_ctl_add(card
, snd_ctl_new1(&snd_cx88_alc_switch
, chip
));
980 strcpy (card
->driver
, "CX88x");
981 sprintf(card
->shortname
, "Conexant CX%x", pci
->device
);
982 sprintf(card
->longname
, "%s at %#llx",
983 card
->shortname
,(unsigned long long)pci_resource_start(pci
, 0));
984 strcpy (card
->mixername
, "CX88");
986 dprintk (0, "%s/%i: ALSA support for cx2388x boards\n",
989 err
= snd_card_register(card
);
992 pci_set_drvdata(pci
,card
);
1004 static void cx88_audio_finidev(struct pci_dev
*pci
)
1006 struct snd_card
*card
= pci_get_drvdata(pci
);
1008 snd_card_free(card
);
1014 * PCI driver definition
1017 static struct pci_driver cx88_audio_pci_driver
= {
1018 .name
= "cx88_audio",
1019 .id_table
= cx88_audio_pci_tbl
,
1020 .probe
= cx88_audio_initdev
,
1021 .remove
= cx88_audio_finidev
,
1024 module_pci_driver(cx88_audio_pci_driver
);