2 * Support for audio capture
3 * PCI function #1 of the cx2388x.
5 * (c) 2007 Trent Piepho <xyzzy@speakeasy.org>
6 * (c) 2005,2006 Ricardo Cerqueira <v4l@cerqueira.org>
7 * (c) 2005 Mauro Carvalho Chehab <mchehab@infradead.org>
8 * Based on a dummy cx88 module by Gerd Knorr <kraxel@bytesex.org>
9 * Based on dummy.c by Jaroslav Kysela <perex@perex.cz>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/device.h>
29 #include <linux/interrupt.h>
30 #include <linux/vmalloc.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/pci.h>
33 #include <linux/slab.h>
35 #include <sound/core.h>
36 #include <sound/pcm.h>
37 #include <sound/pcm_params.h>
38 #include <sound/control.h>
39 #include <sound/initval.h>
40 #include <sound/tlv.h>
41 #include <media/i2c/wm8775.h>
43 #define dprintk(level, fmt, arg...) do { \
44 if (debug + 1 > level) \
45 printk(KERN_DEBUG pr_fmt("%s: alsa: " fmt), \
46 chip->core->name, ##arg); \
50 * Data type declarations - Can be moded to a header file later
53 struct cx88_audio_buffer
{
55 struct cx88_riscmem risc
;
57 struct scatterlist
*sglist
;
62 struct cx88_audio_dev
{
63 struct cx88_core
*core
;
64 struct cx88_dmaqueue q
;
72 struct snd_card
*card
;
77 unsigned int dma_size
;
78 unsigned int period_size
;
79 unsigned int num_periods
;
81 struct cx88_audio_buffer
*buf
;
83 struct snd_pcm_substream
*substream
;
87 * Module global static vars
90 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
91 static const char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
92 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
94 module_param_array(enable
, bool, NULL
, 0444);
95 MODULE_PARM_DESC(enable
, "Enable cx88x soundcard. default enabled.");
97 module_param_array(index
, int, NULL
, 0444);
98 MODULE_PARM_DESC(index
, "Index value for cx88x capture interface(s).");
104 MODULE_DESCRIPTION("ALSA driver module for cx2388x based TV cards");
105 MODULE_AUTHOR("Ricardo Cerqueira");
106 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
107 MODULE_LICENSE("GPL");
108 MODULE_VERSION(CX88_VERSION
);
110 MODULE_SUPPORTED_DEVICE("{{Conexant,23881},{{Conexant,23882},{{Conexant,23883}");
111 static unsigned int debug
;
112 module_param(debug
, int, 0644);
113 MODULE_PARM_DESC(debug
, "enable debug messages");
116 * Module specific functions
120 * BOARD Specific: Sets audio DMA
123 static int _cx88_start_audio_dma(struct cx88_audio_dev
*chip
)
125 struct cx88_audio_buffer
*buf
= chip
->buf
;
126 struct cx88_core
*core
= chip
->core
;
127 const struct sram_channel
*audio_ch
= &cx88_sram_channels
[SRAM_CH25
];
129 /* Make sure RISC/FIFO are off before changing FIFO/RISC settings */
130 cx_clear(MO_AUD_DMACNTRL
, 0x11);
132 /* setup fifo + format - out channel */
133 cx88_sram_channel_setup(chip
->core
, audio_ch
, buf
->bpl
, buf
->risc
.dma
);
136 cx_write(MO_AUDD_LNGTH
, buf
->bpl
);
139 cx_write(MO_AUDD_GPCNTRL
, GP_COUNT_CONTROL_RESET
);
140 atomic_set(&chip
->count
, 0);
143 "Start audio DMA, %d B/line, %d lines/FIFO, %d periods, %d byte buffer\n",
144 buf
->bpl
, cx_read(audio_ch
->cmds_start
+ 8) >> 1,
145 chip
->num_periods
, buf
->bpl
* chip
->num_periods
);
147 /* Enables corresponding bits at AUD_INT_STAT */
148 cx_write(MO_AUD_INTMSK
, AUD_INT_OPC_ERR
| AUD_INT_DN_SYNC
|
149 AUD_INT_DN_RISCI2
| AUD_INT_DN_RISCI1
);
151 /* Clean any pending interrupt bits already set */
152 cx_write(MO_AUD_INTSTAT
, ~0);
154 /* enable audio irqs */
155 cx_set(MO_PCI_INTMSK
, chip
->core
->pci_irqmask
| PCI_INT_AUDINT
);
159 /* Enables Risc Processor */
160 cx_set(MO_DEV_CNTRL2
, (1 << 5));
161 /* audio downstream FIFO and RISC enable */
162 cx_set(MO_AUD_DMACNTRL
, 0x11);
165 cx88_sram_channel_dump(chip
->core
, audio_ch
);
171 * BOARD Specific: Resets audio DMA
173 static int _cx88_stop_audio_dma(struct cx88_audio_dev
*chip
)
175 struct cx88_core
*core
= chip
->core
;
177 dprintk(1, "Stopping audio DMA\n");
180 cx_clear(MO_AUD_DMACNTRL
, 0x11);
183 cx_clear(MO_PCI_INTMSK
, PCI_INT_AUDINT
);
184 cx_clear(MO_AUD_INTMSK
, AUD_INT_OPC_ERR
| AUD_INT_DN_SYNC
|
185 AUD_INT_DN_RISCI2
| AUD_INT_DN_RISCI1
);
188 cx88_sram_channel_dump(chip
->core
,
189 &cx88_sram_channels
[SRAM_CH25
]);
194 #define MAX_IRQ_LOOP 50
197 * BOARD Specific: IRQ dma bits
199 static const char *cx88_aud_irqs
[32] = {
200 "dn_risci1", "up_risci1", "rds_dn_risc1", /* 0-2 */
202 "dn_risci2", "up_risci2", "rds_dn_risc2", /* 4-6 */
204 "dnf_of", "upf_uf", "rds_dnf_uf", /* 8-10 */
206 "dn_sync", "up_sync", "rds_dn_sync", /* 12-14 */
208 "opc_err", "par_err", "rip_err", /* 16-18 */
209 "pci_abort", "ber_irq", "mchg_irq" /* 19-21 */
213 * BOARD Specific: Threats IRQ audio specific calls
215 static void cx8801_aud_irq(struct cx88_audio_dev
*chip
)
217 struct cx88_core
*core
= chip
->core
;
220 status
= cx_read(MO_AUD_INTSTAT
);
221 mask
= cx_read(MO_AUD_INTMSK
);
222 if (0 == (status
& mask
))
224 cx_write(MO_AUD_INTSTAT
, status
);
225 if (debug
> 1 || (status
& mask
& ~0xff))
226 cx88_print_irqbits("irq aud",
227 cx88_aud_irqs
, ARRAY_SIZE(cx88_aud_irqs
),
229 /* risc op code error */
230 if (status
& AUD_INT_OPC_ERR
) {
231 pr_warn("Audio risc op code error\n");
232 cx_clear(MO_AUD_DMACNTRL
, 0x11);
233 cx88_sram_channel_dump(core
, &cx88_sram_channels
[SRAM_CH25
]);
235 if (status
& AUD_INT_DN_SYNC
) {
236 dprintk(1, "Downstream sync error\n");
237 cx_write(MO_AUDD_GPCNTRL
, GP_COUNT_CONTROL_RESET
);
240 /* risc1 downstream */
241 if (status
& AUD_INT_DN_RISCI1
) {
242 atomic_set(&chip
->count
, cx_read(MO_AUDD_GPCNT
));
243 snd_pcm_period_elapsed(chip
->substream
);
245 /* FIXME: Any other status should deserve a special handling? */
249 * BOARD Specific: Handles IRQ calls
251 static irqreturn_t
cx8801_irq(int irq
, void *dev_id
)
253 struct cx88_audio_dev
*chip
= dev_id
;
254 struct cx88_core
*core
= chip
->core
;
256 int loop
, handled
= 0;
258 for (loop
= 0; loop
< MAX_IRQ_LOOP
; loop
++) {
259 status
= cx_read(MO_PCI_INTSTAT
) &
260 (core
->pci_irqmask
| PCI_INT_AUDINT
);
263 dprintk(3, "cx8801_irq loop %d/%d, status %x\n",
264 loop
, MAX_IRQ_LOOP
, status
);
266 cx_write(MO_PCI_INTSTAT
, status
);
268 if (status
& core
->pci_irqmask
)
269 cx88_core_irq(core
, status
);
270 if (status
& PCI_INT_AUDINT
)
271 cx8801_aud_irq(chip
);
274 if (loop
== MAX_IRQ_LOOP
) {
275 pr_err("IRQ loop detected, disabling interrupts\n");
276 cx_clear(MO_PCI_INTMSK
, PCI_INT_AUDINT
);
280 return IRQ_RETVAL(handled
);
283 static int cx88_alsa_dma_init(struct cx88_audio_dev
*chip
, int nr_pages
)
285 struct cx88_audio_buffer
*buf
= chip
->buf
;
289 buf
->vaddr
= vmalloc_32(nr_pages
<< PAGE_SHIFT
);
291 dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages
);
295 dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n",
296 (unsigned long)buf
->vaddr
, nr_pages
<< PAGE_SHIFT
);
298 memset(buf
->vaddr
, 0, nr_pages
<< PAGE_SHIFT
);
299 buf
->nr_pages
= nr_pages
;
301 buf
->sglist
= vzalloc(buf
->nr_pages
* sizeof(*buf
->sglist
));
305 sg_init_table(buf
->sglist
, buf
->nr_pages
);
306 for (i
= 0; i
< buf
->nr_pages
; i
++) {
307 pg
= vmalloc_to_page(buf
->vaddr
+ i
* PAGE_SIZE
);
309 goto vmalloc_to_page_err
;
310 sg_set_page(&buf
->sglist
[i
], pg
, PAGE_SIZE
, 0);
323 static int cx88_alsa_dma_map(struct cx88_audio_dev
*dev
)
325 struct cx88_audio_buffer
*buf
= dev
->buf
;
327 buf
->sglen
= dma_map_sg(&dev
->pci
->dev
, buf
->sglist
,
328 buf
->nr_pages
, PCI_DMA_FROMDEVICE
);
330 if (buf
->sglen
== 0) {
331 pr_warn("%s: cx88_alsa_map_sg failed\n", __func__
);
337 static int cx88_alsa_dma_unmap(struct cx88_audio_dev
*dev
)
339 struct cx88_audio_buffer
*buf
= dev
->buf
;
344 dma_unmap_sg(&dev
->pci
->dev
, buf
->sglist
, buf
->sglen
,
350 static int cx88_alsa_dma_free(struct cx88_audio_buffer
*buf
)
359 static int dsp_buffer_free(struct cx88_audio_dev
*chip
)
361 struct cx88_riscmem
*risc
= &chip
->buf
->risc
;
363 WARN_ON(!chip
->dma_size
);
365 dprintk(2, "Freeing buffer\n");
366 cx88_alsa_dma_unmap(chip
);
367 cx88_alsa_dma_free(chip
->buf
);
369 pci_free_consistent(chip
->pci
, risc
->size
,
370 risc
->cpu
, risc
->dma
);
383 * Digital hardware definition
385 #define DEFAULT_FIFO_SIZE 4096
386 static const struct snd_pcm_hardware snd_cx88_digital_hw
= {
387 .info
= SNDRV_PCM_INFO_MMAP
|
388 SNDRV_PCM_INFO_INTERLEAVED
|
389 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
390 SNDRV_PCM_INFO_MMAP_VALID
,
391 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
393 .rates
= SNDRV_PCM_RATE_48000
,
399 * Analog audio output will be full of clicks and pops if there
400 * are not exactly four lines in the SRAM FIFO buffer.
402 .period_bytes_min
= DEFAULT_FIFO_SIZE
/ 4,
403 .period_bytes_max
= DEFAULT_FIFO_SIZE
/ 4,
406 .buffer_bytes_max
= (1024 * 1024),
410 * audio pcm capture open callback
412 static int snd_cx88_pcm_open(struct snd_pcm_substream
*substream
)
414 struct cx88_audio_dev
*chip
= snd_pcm_substream_chip(substream
);
415 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
419 pr_err("BUG: cx88 can't find device struct. Can't proceed with open\n");
423 err
= snd_pcm_hw_constraint_pow2(runtime
, 0,
424 SNDRV_PCM_HW_PARAM_PERIODS
);
428 chip
->substream
= substream
;
430 runtime
->hw
= snd_cx88_digital_hw
;
432 if (cx88_sram_channels
[SRAM_CH25
].fifo_size
!= DEFAULT_FIFO_SIZE
) {
433 unsigned int bpl
= cx88_sram_channels
[SRAM_CH25
].fifo_size
/ 4;
435 bpl
&= ~7; /* must be multiple of 8 */
436 runtime
->hw
.period_bytes_min
= bpl
;
437 runtime
->hw
.period_bytes_max
= bpl
;
442 dprintk(1, "Error opening PCM!\n");
447 * audio close callback
449 static int snd_cx88_close(struct snd_pcm_substream
*substream
)
457 static int snd_cx88_hw_params(struct snd_pcm_substream
*substream
,
458 struct snd_pcm_hw_params
*hw_params
)
460 struct cx88_audio_dev
*chip
= snd_pcm_substream_chip(substream
);
462 struct cx88_audio_buffer
*buf
;
465 if (substream
->runtime
->dma_area
) {
466 dsp_buffer_free(chip
);
467 substream
->runtime
->dma_area
= NULL
;
470 chip
->period_size
= params_period_bytes(hw_params
);
471 chip
->num_periods
= params_periods(hw_params
);
472 chip
->dma_size
= chip
->period_size
* params_periods(hw_params
);
474 WARN_ON(!chip
->dma_size
);
475 WARN_ON(chip
->num_periods
& (chip
->num_periods
- 1));
477 buf
= kzalloc(sizeof(*buf
), GFP_KERNEL
);
482 buf
->bpl
= chip
->period_size
;
484 ret
= cx88_alsa_dma_init(chip
,
485 (PAGE_ALIGN(chip
->dma_size
) >> PAGE_SHIFT
));
489 ret
= cx88_alsa_dma_map(chip
);
493 ret
= cx88_risc_databuffer(chip
->pci
, &buf
->risc
, buf
->sglist
,
494 chip
->period_size
, chip
->num_periods
, 1);
498 /* Loop back to start of program */
499 buf
->risc
.jmp
[0] = cpu_to_le32(RISC_JUMP
| RISC_IRQ1
| RISC_CNT_INC
);
500 buf
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
);
502 substream
->runtime
->dma_area
= chip
->buf
->vaddr
;
503 substream
->runtime
->dma_bytes
= chip
->dma_size
;
504 substream
->runtime
->dma_addr
= 0;
515 static int snd_cx88_hw_free(struct snd_pcm_substream
*substream
)
517 struct cx88_audio_dev
*chip
= snd_pcm_substream_chip(substream
);
519 if (substream
->runtime
->dma_area
) {
520 dsp_buffer_free(chip
);
521 substream
->runtime
->dma_area
= NULL
;
530 static int snd_cx88_prepare(struct snd_pcm_substream
*substream
)
538 static int snd_cx88_card_trigger(struct snd_pcm_substream
*substream
, int cmd
)
540 struct cx88_audio_dev
*chip
= snd_pcm_substream_chip(substream
);
543 /* Local interrupts are already disabled by ALSA */
544 spin_lock(&chip
->reg_lock
);
547 case SNDRV_PCM_TRIGGER_START
:
548 err
= _cx88_start_audio_dma(chip
);
550 case SNDRV_PCM_TRIGGER_STOP
:
551 err
= _cx88_stop_audio_dma(chip
);
558 spin_unlock(&chip
->reg_lock
);
566 static snd_pcm_uframes_t
snd_cx88_pointer(struct snd_pcm_substream
*substream
)
568 struct cx88_audio_dev
*chip
= snd_pcm_substream_chip(substream
);
569 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
572 count
= atomic_read(&chip
->count
);
574 // dprintk(2, "%s - count %d (+%u), period %d, frame %lu\n", __func__,
575 // count, new, count & (runtime->periods-1),
576 // runtime->period_size * (count & (runtime->periods-1)));
577 return runtime
->period_size
* (count
& (runtime
->periods
- 1));
581 * page callback (needed for mmap)
583 static struct page
*snd_cx88_page(struct snd_pcm_substream
*substream
,
584 unsigned long offset
)
586 void *pageptr
= substream
->runtime
->dma_area
+ offset
;
588 return vmalloc_to_page(pageptr
);
594 static const struct snd_pcm_ops snd_cx88_pcm_ops
= {
595 .open
= snd_cx88_pcm_open
,
596 .close
= snd_cx88_close
,
597 .ioctl
= snd_pcm_lib_ioctl
,
598 .hw_params
= snd_cx88_hw_params
,
599 .hw_free
= snd_cx88_hw_free
,
600 .prepare
= snd_cx88_prepare
,
601 .trigger
= snd_cx88_card_trigger
,
602 .pointer
= snd_cx88_pointer
,
603 .page
= snd_cx88_page
,
607 * create a PCM device
609 static int snd_cx88_pcm(struct cx88_audio_dev
*chip
, int device
,
615 err
= snd_pcm_new(chip
->card
, name
, device
, 0, 1, &pcm
);
618 pcm
->private_data
= chip
;
619 strcpy(pcm
->name
, name
);
620 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_cx88_pcm_ops
);
628 static int snd_cx88_volume_info(struct snd_kcontrol
*kcontrol
,
629 struct snd_ctl_elem_info
*info
)
631 info
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
633 info
->value
.integer
.min
= 0;
634 info
->value
.integer
.max
= 0x3f;
639 static int snd_cx88_volume_get(struct snd_kcontrol
*kcontrol
,
640 struct snd_ctl_elem_value
*value
)
642 struct cx88_audio_dev
*chip
= snd_kcontrol_chip(kcontrol
);
643 struct cx88_core
*core
= chip
->core
;
644 int vol
= 0x3f - (cx_read(AUD_VOL_CTL
) & 0x3f),
645 bal
= cx_read(AUD_BAL_CTL
);
647 value
->value
.integer
.value
[(bal
& 0x40) ? 0 : 1] = vol
;
649 value
->value
.integer
.value
[(bal
& 0x40) ? 1 : 0] = vol
< 0 ? 0 : vol
;
654 static void snd_cx88_wm8775_volume_put(struct snd_kcontrol
*kcontrol
,
655 struct snd_ctl_elem_value
*value
)
657 struct cx88_audio_dev
*chip
= snd_kcontrol_chip(kcontrol
);
658 struct cx88_core
*core
= chip
->core
;
659 int left
= value
->value
.integer
.value
[0];
660 int right
= value
->value
.integer
.value
[1];
663 /* Pass volume & balance onto any WM8775 */
666 b
= left
? (0x8000 * right
) / left
: 0x8000;
669 b
= right
? 0xffff - (0x8000 * left
) / right
: 0x8000;
671 wm8775_s_ctrl(core
, V4L2_CID_AUDIO_VOLUME
, v
);
672 wm8775_s_ctrl(core
, V4L2_CID_AUDIO_BALANCE
, b
);
675 /* OK - TODO: test it */
676 static int snd_cx88_volume_put(struct snd_kcontrol
*kcontrol
,
677 struct snd_ctl_elem_value
*value
)
679 struct cx88_audio_dev
*chip
= snd_kcontrol_chip(kcontrol
);
680 struct cx88_core
*core
= chip
->core
;
681 int left
, right
, v
, b
;
686 snd_cx88_wm8775_volume_put(kcontrol
, value
);
688 left
= value
->value
.integer
.value
[0] & 0x3f;
689 right
= value
->value
.integer
.value
[1] & 0x3f;
697 /* Do we really know this will always be called with IRQs on? */
698 spin_lock_irq(&chip
->reg_lock
);
699 old
= cx_read(AUD_VOL_CTL
);
700 if (v
!= (old
& 0x3f)) {
701 cx_swrite(SHADOW_AUD_VOL_CTL
, AUD_VOL_CTL
, (old
& ~0x3f) | v
);
704 if ((cx_read(AUD_BAL_CTL
) & 0x7f) != b
) {
705 cx_write(AUD_BAL_CTL
, b
);
708 spin_unlock_irq(&chip
->reg_lock
);
713 static const DECLARE_TLV_DB_SCALE(snd_cx88_db_scale
, -6300, 100, 0);
715 static const struct snd_kcontrol_new snd_cx88_volume
= {
716 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
717 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
718 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
719 .name
= "Analog-TV Volume",
720 .info
= snd_cx88_volume_info
,
721 .get
= snd_cx88_volume_get
,
722 .put
= snd_cx88_volume_put
,
723 .tlv
.p
= snd_cx88_db_scale
,
726 static int snd_cx88_switch_get(struct snd_kcontrol
*kcontrol
,
727 struct snd_ctl_elem_value
*value
)
729 struct cx88_audio_dev
*chip
= snd_kcontrol_chip(kcontrol
);
730 struct cx88_core
*core
= chip
->core
;
731 u32 bit
= kcontrol
->private_value
;
733 value
->value
.integer
.value
[0] = !(cx_read(AUD_VOL_CTL
) & bit
);
737 static int snd_cx88_switch_put(struct snd_kcontrol
*kcontrol
,
738 struct snd_ctl_elem_value
*value
)
740 struct cx88_audio_dev
*chip
= snd_kcontrol_chip(kcontrol
);
741 struct cx88_core
*core
= chip
->core
;
742 u32 bit
= kcontrol
->private_value
;
746 spin_lock_irq(&chip
->reg_lock
);
747 vol
= cx_read(AUD_VOL_CTL
);
748 if (value
->value
.integer
.value
[0] != !(vol
& bit
)) {
750 cx_swrite(SHADOW_AUD_VOL_CTL
, AUD_VOL_CTL
, vol
);
751 /* Pass mute onto any WM8775 */
752 if (core
->sd_wm8775
&& ((1 << 6) == bit
))
754 V4L2_CID_AUDIO_MUTE
, 0 != (vol
& bit
));
757 spin_unlock_irq(&chip
->reg_lock
);
761 static const struct snd_kcontrol_new snd_cx88_dac_switch
= {
762 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
763 .name
= "Audio-Out Switch",
764 .info
= snd_ctl_boolean_mono_info
,
765 .get
= snd_cx88_switch_get
,
766 .put
= snd_cx88_switch_put
,
767 .private_value
= (1 << 8),
770 static const struct snd_kcontrol_new snd_cx88_source_switch
= {
771 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
772 .name
= "Analog-TV Switch",
773 .info
= snd_ctl_boolean_mono_info
,
774 .get
= snd_cx88_switch_get
,
775 .put
= snd_cx88_switch_put
,
776 .private_value
= (1 << 6),
779 static int snd_cx88_alc_get(struct snd_kcontrol
*kcontrol
,
780 struct snd_ctl_elem_value
*value
)
782 struct cx88_audio_dev
*chip
= snd_kcontrol_chip(kcontrol
);
783 struct cx88_core
*core
= chip
->core
;
786 val
= wm8775_g_ctrl(core
, V4L2_CID_AUDIO_LOUDNESS
);
787 value
->value
.integer
.value
[0] = val
? 1 : 0;
791 static int snd_cx88_alc_put(struct snd_kcontrol
*kcontrol
,
792 struct snd_ctl_elem_value
*value
)
794 struct cx88_audio_dev
*chip
= snd_kcontrol_chip(kcontrol
);
795 struct cx88_core
*core
= chip
->core
;
797 wm8775_s_ctrl(core
, V4L2_CID_AUDIO_LOUDNESS
,
798 value
->value
.integer
.value
[0] != 0);
802 static struct snd_kcontrol_new snd_cx88_alc_switch
= {
803 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
804 .name
= "Line-In ALC Switch",
805 .info
= snd_ctl_boolean_mono_info
,
806 .get
= snd_cx88_alc_get
,
807 .put
= snd_cx88_alc_put
,
811 * Basic Flow for Sound Devices
815 * PCI ID Table - 14f1:8801 and 14f1:8811 means function 1: Audio
816 * Only boards with eeprom and byte 1 at eeprom=1 have it
819 static const struct pci_device_id cx88_audio_pci_tbl
[] = {
820 {0x14f1, 0x8801, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
821 {0x14f1, 0x8811, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
824 MODULE_DEVICE_TABLE(pci
, cx88_audio_pci_tbl
);
827 * Chip-specific destructor
830 static int snd_cx88_free(struct cx88_audio_dev
*chip
)
833 free_irq(chip
->irq
, chip
);
835 cx88_core_put(chip
->core
, chip
->pci
);
837 pci_disable_device(chip
->pci
);
842 * Component Destructor
844 static void snd_cx88_dev_free(struct snd_card
*card
)
846 struct cx88_audio_dev
*chip
= card
->private_data
;
852 * Alsa Constructor - Component probe
856 static int snd_cx88_create(struct snd_card
*card
, struct pci_dev
*pci
,
857 struct cx88_audio_dev
**rchip
,
858 struct cx88_core
**core_ptr
)
860 struct cx88_audio_dev
*chip
;
861 struct cx88_core
*core
;
863 unsigned char pci_lat
;
867 err
= pci_enable_device(pci
);
873 chip
= card
->private_data
;
875 core
= cx88_core_get(pci
);
881 err
= pci_set_dma_mask(pci
, DMA_BIT_MASK(32));
883 dprintk(0, "%s/1: Oops: no 32bit PCI DMA ???\n", core
->name
);
884 cx88_core_put(core
, pci
);
892 spin_lock_init(&chip
->reg_lock
);
897 err
= request_irq(chip
->pci
->irq
, cx8801_irq
,
898 IRQF_SHARED
, chip
->core
->name
, chip
);
900 dprintk(0, "%s: can't get IRQ %d\n",
901 chip
->core
->name
, chip
->pci
->irq
);
906 pci_read_config_byte(pci
, PCI_LATENCY_TIMER
, &pci_lat
);
909 "ALSA %s/%i: found at %s, rev: %d, irq: %d, latency: %d, mmio: 0x%llx\n",
911 pci_name(pci
), pci
->revision
, pci
->irq
,
912 pci_lat
, (unsigned long long)pci_resource_start(pci
, 0));
914 chip
->irq
= pci
->irq
;
915 synchronize_irq(chip
->irq
);
923 static int cx88_audio_initdev(struct pci_dev
*pci
,
924 const struct pci_device_id
*pci_id
)
926 struct snd_card
*card
;
927 struct cx88_audio_dev
*chip
;
928 struct cx88_core
*core
= NULL
;
931 if (devno
>= SNDRV_CARDS
)
934 if (!enable
[devno
]) {
939 err
= snd_card_new(&pci
->dev
, index
[devno
], id
[devno
], THIS_MODULE
,
940 sizeof(struct cx88_audio_dev
), &card
);
944 card
->private_free
= snd_cx88_dev_free
;
946 err
= snd_cx88_create(card
, pci
, &chip
, &core
);
950 err
= snd_cx88_pcm(chip
, 0, "CX88 Digital");
954 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_cx88_volume
, chip
));
957 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_cx88_dac_switch
, chip
));
960 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_cx88_source_switch
, chip
));
964 /* If there's a wm8775 then add a Line-In ALC switch */
966 snd_ctl_add(card
, snd_ctl_new1(&snd_cx88_alc_switch
, chip
));
968 strcpy(card
->driver
, "CX88x");
969 sprintf(card
->shortname
, "Conexant CX%x", pci
->device
);
970 sprintf(card
->longname
, "%s at %#llx",
972 (unsigned long long)pci_resource_start(pci
, 0));
973 strcpy(card
->mixername
, "CX88");
975 dprintk(0, "%s/%i: ALSA support for cx2388x boards\n",
976 card
->driver
, devno
);
978 err
= snd_card_register(card
);
981 pci_set_drvdata(pci
, card
);
994 static void cx88_audio_finidev(struct pci_dev
*pci
)
996 struct snd_card
*card
= pci_get_drvdata(pci
);
1004 * PCI driver definition
1007 static struct pci_driver cx88_audio_pci_driver
= {
1008 .name
= "cx88_audio",
1009 .id_table
= cx88_audio_pci_tbl
,
1010 .probe
= cx88_audio_initdev
,
1011 .remove
= cx88_audio_finidev
,
1014 module_pci_driver(cx88_audio_pci_driver
);