1 /*****************************************************************************
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
6 * This file is part of the Audiowerk2 ALSA driver
8 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.
12 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 *****************************************************************************/
23 #include <linux/init.h>
24 #include <linux/pci.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
28 #include <linux/delay.h>
30 #include <linux/module.h>
31 #include <sound/core.h>
32 #include <sound/initval.h>
33 #include <sound/pcm.h>
34 #include <sound/pcm_params.h>
35 #include <sound/control.h>
38 #include "aw2-saa7146.h"
40 MODULE_AUTHOR("Cedric Bregardis <cedric.bregardis@free.fr>, "
41 "Jean-Christian Hassler <jhassler@free.fr>");
42 MODULE_DESCRIPTION("Emagic Audiowerk 2 sound driver");
43 MODULE_LICENSE("GPL");
45 /*********************************
47 ********************************/
48 #define CTL_ROUTE_ANALOG 0
49 #define CTL_ROUTE_DIGITAL 1
51 /*********************************
53 ********************************/
54 /* hardware definition */
55 static struct snd_pcm_hardware snd_aw2_playback_hw
= {
56 .info
= (SNDRV_PCM_INFO_MMAP
|
57 SNDRV_PCM_INFO_INTERLEAVED
|
58 SNDRV_PCM_INFO_BLOCK_TRANSFER
| SNDRV_PCM_INFO_MMAP_VALID
),
59 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
60 .rates
= SNDRV_PCM_RATE_44100
,
65 .buffer_bytes_max
= 32768,
66 .period_bytes_min
= 4096,
67 .period_bytes_max
= 32768,
72 static struct snd_pcm_hardware snd_aw2_capture_hw
= {
73 .info
= (SNDRV_PCM_INFO_MMAP
|
74 SNDRV_PCM_INFO_INTERLEAVED
|
75 SNDRV_PCM_INFO_BLOCK_TRANSFER
| SNDRV_PCM_INFO_MMAP_VALID
),
76 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
77 .rates
= SNDRV_PCM_RATE_44100
,
82 .buffer_bytes_max
= 32768,
83 .period_bytes_min
= 4096,
84 .period_bytes_max
= 32768,
89 struct aw2_pcm_device
{
91 unsigned int stream_number
;
96 struct snd_aw2_saa7146 saa7146
;
103 unsigned long iobase_phys
;
104 void __iomem
*iobase_virt
;
106 struct snd_card
*card
;
108 struct aw2_pcm_device device_playback
[NB_STREAM_PLAYBACK
];
109 struct aw2_pcm_device device_capture
[NB_STREAM_CAPTURE
];
112 /*********************************
113 * FUNCTION DECLARATIONS
114 ********************************/
115 static int __init
alsa_card_aw2_init(void);
116 static void __exit
alsa_card_aw2_exit(void);
117 static int snd_aw2_dev_free(struct snd_device
*device
);
118 static int __devinit
snd_aw2_create(struct snd_card
*card
,
119 struct pci_dev
*pci
, struct aw2
**rchip
);
120 static int __devinit
snd_aw2_probe(struct pci_dev
*pci
,
121 const struct pci_device_id
*pci_id
);
122 static void __devexit
snd_aw2_remove(struct pci_dev
*pci
);
123 static int snd_aw2_pcm_playback_open(struct snd_pcm_substream
*substream
);
124 static int snd_aw2_pcm_playback_close(struct snd_pcm_substream
*substream
);
125 static int snd_aw2_pcm_capture_open(struct snd_pcm_substream
*substream
);
126 static int snd_aw2_pcm_capture_close(struct snd_pcm_substream
*substream
);
127 static int snd_aw2_pcm_hw_params(struct snd_pcm_substream
*substream
,
128 struct snd_pcm_hw_params
*hw_params
);
129 static int snd_aw2_pcm_hw_free(struct snd_pcm_substream
*substream
);
130 static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream
*substream
);
131 static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream
*substream
);
132 static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream
*substream
,
134 static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream
*substream
,
136 static snd_pcm_uframes_t
snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
138 static snd_pcm_uframes_t
snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
140 static int __devinit
snd_aw2_new_pcm(struct aw2
*chip
);
142 static int snd_aw2_control_switch_capture_info(struct snd_kcontrol
*kcontrol
,
143 struct snd_ctl_elem_info
*uinfo
);
144 static int snd_aw2_control_switch_capture_get(struct snd_kcontrol
*kcontrol
,
145 struct snd_ctl_elem_value
147 static int snd_aw2_control_switch_capture_put(struct snd_kcontrol
*kcontrol
,
148 struct snd_ctl_elem_value
151 /*********************************
153 ********************************/
154 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
155 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
156 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
158 module_param_array(index
, int, NULL
, 0444);
159 MODULE_PARM_DESC(index
, "Index value for Audiowerk2 soundcard.");
160 module_param_array(id
, charp
, NULL
, 0444);
161 MODULE_PARM_DESC(id
, "ID string for the Audiowerk2 soundcard.");
162 module_param_array(enable
, bool, NULL
, 0444);
163 MODULE_PARM_DESC(enable
, "Enable Audiowerk2 soundcard.");
165 static DEFINE_PCI_DEVICE_TABLE(snd_aw2_ids
) = {
166 {PCI_VENDOR_ID_PHILIPS
, PCI_DEVICE_ID_PHILIPS_SAA7146
, 0, 0,
171 MODULE_DEVICE_TABLE(pci
, snd_aw2_ids
);
173 /* pci_driver definition */
174 static struct pci_driver driver
= {
175 .name
= KBUILD_MODNAME
,
176 .id_table
= snd_aw2_ids
,
177 .probe
= snd_aw2_probe
,
178 .remove
= __devexit_p(snd_aw2_remove
),
181 /* operators for playback PCM alsa interface */
182 static struct snd_pcm_ops snd_aw2_playback_ops
= {
183 .open
= snd_aw2_pcm_playback_open
,
184 .close
= snd_aw2_pcm_playback_close
,
185 .ioctl
= snd_pcm_lib_ioctl
,
186 .hw_params
= snd_aw2_pcm_hw_params
,
187 .hw_free
= snd_aw2_pcm_hw_free
,
188 .prepare
= snd_aw2_pcm_prepare_playback
,
189 .trigger
= snd_aw2_pcm_trigger_playback
,
190 .pointer
= snd_aw2_pcm_pointer_playback
,
193 /* operators for capture PCM alsa interface */
194 static struct snd_pcm_ops snd_aw2_capture_ops
= {
195 .open
= snd_aw2_pcm_capture_open
,
196 .close
= snd_aw2_pcm_capture_close
,
197 .ioctl
= snd_pcm_lib_ioctl
,
198 .hw_params
= snd_aw2_pcm_hw_params
,
199 .hw_free
= snd_aw2_pcm_hw_free
,
200 .prepare
= snd_aw2_pcm_prepare_capture
,
201 .trigger
= snd_aw2_pcm_trigger_capture
,
202 .pointer
= snd_aw2_pcm_pointer_capture
,
205 static struct snd_kcontrol_new aw2_control __devinitdata
= {
206 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
207 .name
= "PCM Capture Route",
209 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
210 .private_value
= 0xffff,
211 .info
= snd_aw2_control_switch_capture_info
,
212 .get
= snd_aw2_control_switch_capture_get
,
213 .put
= snd_aw2_control_switch_capture_put
216 /*********************************
217 * FUNCTION IMPLEMENTATIONS
218 ********************************/
220 /* initialization of the module */
221 static int __init
alsa_card_aw2_init(void)
223 snd_printdd(KERN_DEBUG
"aw2: Load aw2 module\n");
224 return pci_register_driver(&driver
);
227 /* clean up the module */
228 static void __exit
alsa_card_aw2_exit(void)
230 snd_printdd(KERN_DEBUG
"aw2: Unload aw2 module\n");
231 pci_unregister_driver(&driver
);
234 module_init(alsa_card_aw2_init
);
235 module_exit(alsa_card_aw2_exit
);
237 /* component-destructor */
238 static int snd_aw2_dev_free(struct snd_device
*device
)
240 struct aw2
*chip
= device
->device_data
;
243 snd_aw2_saa7146_free(&chip
->saa7146
);
245 /* release the irq */
247 free_irq(chip
->irq
, (void *)chip
);
248 /* release the i/o ports & memory */
249 if (chip
->iobase_virt
)
250 iounmap(chip
->iobase_virt
);
252 pci_release_regions(chip
->pci
);
253 /* disable the PCI entry */
254 pci_disable_device(chip
->pci
);
255 /* release the data */
261 /* chip-specific constructor */
262 static int __devinit
snd_aw2_create(struct snd_card
*card
,
263 struct pci_dev
*pci
, struct aw2
**rchip
)
267 static struct snd_device_ops ops
= {
268 .dev_free
= snd_aw2_dev_free
,
273 /* initialize the PCI entry */
274 err
= pci_enable_device(pci
);
279 /* check PCI availability (32bit DMA) */
280 if ((pci_set_dma_mask(pci
, DMA_BIT_MASK(32)) < 0) ||
281 (pci_set_consistent_dma_mask(pci
, DMA_BIT_MASK(32)) < 0)) {
282 printk(KERN_ERR
"aw2: Impossible to set 32bit mask DMA\n");
283 pci_disable_device(pci
);
286 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
288 pci_disable_device(pci
);
292 /* initialize the stuff */
297 /* (1) PCI resource allocation */
298 err
= pci_request_regions(pci
, "Audiowerk2");
300 pci_disable_device(pci
);
304 chip
->iobase_phys
= pci_resource_start(pci
, 0);
306 ioremap_nocache(chip
->iobase_phys
,
307 pci_resource_len(pci
, 0));
309 if (chip
->iobase_virt
== NULL
) {
310 printk(KERN_ERR
"aw2: unable to remap memory region");
311 pci_release_regions(pci
);
312 pci_disable_device(pci
);
317 /* (2) initialization of the chip hardware */
318 snd_aw2_saa7146_setup(&chip
->saa7146
, chip
->iobase_virt
);
320 if (request_irq(pci
->irq
, snd_aw2_saa7146_interrupt
,
321 IRQF_SHARED
, KBUILD_MODNAME
, chip
)) {
322 printk(KERN_ERR
"aw2: Cannot grab irq %d\n", pci
->irq
);
324 iounmap(chip
->iobase_virt
);
325 pci_release_regions(chip
->pci
);
326 pci_disable_device(chip
->pci
);
330 chip
->irq
= pci
->irq
;
332 err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
);
334 free_irq(chip
->irq
, (void *)chip
);
335 iounmap(chip
->iobase_virt
);
336 pci_release_regions(chip
->pci
);
337 pci_disable_device(chip
->pci
);
342 snd_card_set_dev(card
, &pci
->dev
);
346 "Audiowerk 2 sound card (saa7146 chipset) detected and "
352 static int __devinit
snd_aw2_probe(struct pci_dev
*pci
,
353 const struct pci_device_id
*pci_id
)
356 struct snd_card
*card
;
360 /* (1) Continue if device is not enabled, else inc dev */
361 if (dev
>= SNDRV_CARDS
)
368 /* (2) Create card instance */
369 err
= snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
, 0, &card
);
373 /* (3) Create main component */
374 err
= snd_aw2_create(card
, pci
, &chip
);
380 /* initialize mutex */
381 mutex_init(&chip
->mtx
);
383 spin_lock_init(&chip
->reg_lock
);
384 /* (4) Define driver ID and name string */
385 strcpy(card
->driver
, "aw2");
386 strcpy(card
->shortname
, "Audiowerk2");
388 sprintf(card
->longname
, "%s with SAA7146 irq %i",
389 card
->shortname
, chip
->irq
);
391 /* (5) Create other components */
392 snd_aw2_new_pcm(chip
);
394 /* (6) Register card instance */
395 err
= snd_card_register(card
);
401 /* (7) Set PCI driver data */
402 pci_set_drvdata(pci
, card
);
409 static void __devexit
snd_aw2_remove(struct pci_dev
*pci
)
411 snd_card_free(pci_get_drvdata(pci
));
412 pci_set_drvdata(pci
, NULL
);
416 static int snd_aw2_pcm_playback_open(struct snd_pcm_substream
*substream
)
418 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
420 snd_printdd(KERN_DEBUG
"aw2: Playback_open\n");
421 runtime
->hw
= snd_aw2_playback_hw
;
426 static int snd_aw2_pcm_playback_close(struct snd_pcm_substream
*substream
)
432 static int snd_aw2_pcm_capture_open(struct snd_pcm_substream
*substream
)
434 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
436 snd_printdd(KERN_DEBUG
"aw2: Capture_open\n");
437 runtime
->hw
= snd_aw2_capture_hw
;
442 static int snd_aw2_pcm_capture_close(struct snd_pcm_substream
*substream
)
444 /* TODO: something to do ? */
448 /* hw_params callback */
449 static int snd_aw2_pcm_hw_params(struct snd_pcm_substream
*substream
,
450 struct snd_pcm_hw_params
*hw_params
)
452 return snd_pcm_lib_malloc_pages(substream
,
453 params_buffer_bytes(hw_params
));
456 /* hw_free callback */
457 static int snd_aw2_pcm_hw_free(struct snd_pcm_substream
*substream
)
459 return snd_pcm_lib_free_pages(substream
);
462 /* prepare callback for playback */
463 static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream
*substream
)
465 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
466 struct aw2
*chip
= pcm_device
->chip
;
467 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
468 unsigned long period_size
, buffer_size
;
470 mutex_lock(&chip
->mtx
);
472 period_size
= snd_pcm_lib_period_bytes(substream
);
473 buffer_size
= snd_pcm_lib_buffer_bytes(substream
);
475 snd_aw2_saa7146_pcm_init_playback(&chip
->saa7146
,
476 pcm_device
->stream_number
,
477 runtime
->dma_addr
, period_size
,
480 /* Define Interrupt callback */
481 snd_aw2_saa7146_define_it_playback_callback(pcm_device
->stream_number
,
482 (snd_aw2_saa7146_it_cb
)
483 snd_pcm_period_elapsed
,
486 mutex_unlock(&chip
->mtx
);
491 /* prepare callback for capture */
492 static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream
*substream
)
494 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
495 struct aw2
*chip
= pcm_device
->chip
;
496 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
497 unsigned long period_size
, buffer_size
;
499 mutex_lock(&chip
->mtx
);
501 period_size
= snd_pcm_lib_period_bytes(substream
);
502 buffer_size
= snd_pcm_lib_buffer_bytes(substream
);
504 snd_aw2_saa7146_pcm_init_capture(&chip
->saa7146
,
505 pcm_device
->stream_number
,
506 runtime
->dma_addr
, period_size
,
509 /* Define Interrupt callback */
510 snd_aw2_saa7146_define_it_capture_callback(pcm_device
->stream_number
,
511 (snd_aw2_saa7146_it_cb
)
512 snd_pcm_period_elapsed
,
515 mutex_unlock(&chip
->mtx
);
520 /* playback trigger callback */
521 static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream
*substream
,
525 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
526 struct aw2
*chip
= pcm_device
->chip
;
527 spin_lock(&chip
->reg_lock
);
529 case SNDRV_PCM_TRIGGER_START
:
530 snd_aw2_saa7146_pcm_trigger_start_playback(&chip
->saa7146
,
534 case SNDRV_PCM_TRIGGER_STOP
:
535 snd_aw2_saa7146_pcm_trigger_stop_playback(&chip
->saa7146
,
542 spin_unlock(&chip
->reg_lock
);
546 /* capture trigger callback */
547 static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream
*substream
,
551 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
552 struct aw2
*chip
= pcm_device
->chip
;
553 spin_lock(&chip
->reg_lock
);
555 case SNDRV_PCM_TRIGGER_START
:
556 snd_aw2_saa7146_pcm_trigger_start_capture(&chip
->saa7146
,
560 case SNDRV_PCM_TRIGGER_STOP
:
561 snd_aw2_saa7146_pcm_trigger_stop_capture(&chip
->saa7146
,
568 spin_unlock(&chip
->reg_lock
);
572 /* playback pointer callback */
573 static snd_pcm_uframes_t
snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
576 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
577 struct aw2
*chip
= pcm_device
->chip
;
578 unsigned int current_ptr
;
580 /* get the current hardware pointer */
581 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
583 snd_aw2_saa7146_get_hw_ptr_playback(&chip
->saa7146
,
584 pcm_device
->stream_number
,
586 runtime
->buffer_size
);
588 return bytes_to_frames(substream
->runtime
, current_ptr
);
591 /* capture pointer callback */
592 static snd_pcm_uframes_t
snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
595 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
596 struct aw2
*chip
= pcm_device
->chip
;
597 unsigned int current_ptr
;
599 /* get the current hardware pointer */
600 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
602 snd_aw2_saa7146_get_hw_ptr_capture(&chip
->saa7146
,
603 pcm_device
->stream_number
,
605 runtime
->buffer_size
);
607 return bytes_to_frames(substream
->runtime
, current_ptr
);
610 /* create a pcm device */
611 static int __devinit
snd_aw2_new_pcm(struct aw2
*chip
)
613 struct snd_pcm
*pcm_playback_ana
;
614 struct snd_pcm
*pcm_playback_num
;
615 struct snd_pcm
*pcm_capture
;
616 struct aw2_pcm_device
*pcm_device
;
619 /* Create new Alsa PCM device */
621 err
= snd_pcm_new(chip
->card
, "Audiowerk2 analog playback", 0, 1, 0,
624 printk(KERN_ERR
"aw2: snd_pcm_new error (0x%X)\n", err
);
629 pcm_device
= &chip
->device_playback
[NUM_STREAM_PLAYBACK_ANA
];
631 /* Set PCM device name */
632 strcpy(pcm_playback_ana
->name
, "Analog playback");
633 /* Associate private data to PCM device */
634 pcm_playback_ana
->private_data
= pcm_device
;
635 /* set operators of PCM device */
636 snd_pcm_set_ops(pcm_playback_ana
, SNDRV_PCM_STREAM_PLAYBACK
,
637 &snd_aw2_playback_ops
);
638 /* store PCM device */
639 pcm_device
->pcm
= pcm_playback_ana
;
640 /* give base chip pointer to our internal pcm device
642 pcm_device
->chip
= chip
;
643 /* Give stream number to PCM device */
644 pcm_device
->stream_number
= NUM_STREAM_PLAYBACK_ANA
;
646 /* pre-allocation of buffers */
647 /* Preallocate continuous pages. */
648 err
= snd_pcm_lib_preallocate_pages_for_all(pcm_playback_ana
,
652 64 * 1024, 64 * 1024);
654 printk(KERN_ERR
"aw2: snd_pcm_lib_preallocate_pages_for_all "
655 "error (0x%X)\n", err
);
657 err
= snd_pcm_new(chip
->card
, "Audiowerk2 digital playback", 1, 1, 0,
661 printk(KERN_ERR
"aw2: snd_pcm_new error (0x%X)\n", err
);
665 pcm_device
= &chip
->device_playback
[NUM_STREAM_PLAYBACK_DIG
];
667 /* Set PCM device name */
668 strcpy(pcm_playback_num
->name
, "Digital playback");
669 /* Associate private data to PCM device */
670 pcm_playback_num
->private_data
= pcm_device
;
671 /* set operators of PCM device */
672 snd_pcm_set_ops(pcm_playback_num
, SNDRV_PCM_STREAM_PLAYBACK
,
673 &snd_aw2_playback_ops
);
674 /* store PCM device */
675 pcm_device
->pcm
= pcm_playback_num
;
676 /* give base chip pointer to our internal pcm device
678 pcm_device
->chip
= chip
;
679 /* Give stream number to PCM device */
680 pcm_device
->stream_number
= NUM_STREAM_PLAYBACK_DIG
;
682 /* pre-allocation of buffers */
683 /* Preallocate continuous pages. */
684 err
= snd_pcm_lib_preallocate_pages_for_all(pcm_playback_num
,
688 64 * 1024, 64 * 1024);
691 "aw2: snd_pcm_lib_preallocate_pages_for_all error "
696 err
= snd_pcm_new(chip
->card
, "Audiowerk2 capture", 2, 0, 1,
700 printk(KERN_ERR
"aw2: snd_pcm_new error (0x%X)\n", err
);
705 pcm_device
= &chip
->device_capture
[NUM_STREAM_CAPTURE_ANA
];
707 /* Set PCM device name */
708 strcpy(pcm_capture
->name
, "Capture");
709 /* Associate private data to PCM device */
710 pcm_capture
->private_data
= pcm_device
;
711 /* set operators of PCM device */
712 snd_pcm_set_ops(pcm_capture
, SNDRV_PCM_STREAM_CAPTURE
,
713 &snd_aw2_capture_ops
);
714 /* store PCM device */
715 pcm_device
->pcm
= pcm_capture
;
716 /* give base chip pointer to our internal pcm device
718 pcm_device
->chip
= chip
;
719 /* Give stream number to PCM device */
720 pcm_device
->stream_number
= NUM_STREAM_CAPTURE_ANA
;
722 /* pre-allocation of buffers */
723 /* Preallocate continuous pages. */
724 err
= snd_pcm_lib_preallocate_pages_for_all(pcm_capture
,
728 64 * 1024, 64 * 1024);
731 "aw2: snd_pcm_lib_preallocate_pages_for_all error "
736 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&aw2_control
, chip
));
738 printk(KERN_ERR
"aw2: snd_ctl_add error (0x%X)\n", err
);
745 static int snd_aw2_control_switch_capture_info(struct snd_kcontrol
*kcontrol
,
746 struct snd_ctl_elem_info
*uinfo
)
748 static char *texts
[2] = {
751 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
753 uinfo
->value
.enumerated
.items
= 2;
754 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
) {
755 uinfo
->value
.enumerated
.item
=
756 uinfo
->value
.enumerated
.items
- 1;
758 strcpy(uinfo
->value
.enumerated
.name
,
759 texts
[uinfo
->value
.enumerated
.item
]);
763 static int snd_aw2_control_switch_capture_get(struct snd_kcontrol
*kcontrol
,
764 struct snd_ctl_elem_value
767 struct aw2
*chip
= snd_kcontrol_chip(kcontrol
);
768 if (snd_aw2_saa7146_is_using_digital_input(&chip
->saa7146
))
769 ucontrol
->value
.enumerated
.item
[0] = CTL_ROUTE_DIGITAL
;
771 ucontrol
->value
.enumerated
.item
[0] = CTL_ROUTE_ANALOG
;
775 static int snd_aw2_control_switch_capture_put(struct snd_kcontrol
*kcontrol
,
776 struct snd_ctl_elem_value
779 struct aw2
*chip
= snd_kcontrol_chip(kcontrol
);
782 snd_aw2_saa7146_is_using_digital_input(&chip
->saa7146
);
784 if (((ucontrol
->value
.integer
.value
[0] == CTL_ROUTE_DIGITAL
)
786 || ((ucontrol
->value
.integer
.value
[0] == CTL_ROUTE_ANALOG
)
788 snd_aw2_saa7146_use_digital_input(&chip
->saa7146
, !is_disgital
);