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 <sound/core.h>
31 #include <sound/initval.h>
32 #include <sound/pcm.h>
33 #include <sound/pcm_params.h>
34 #include <sound/control.h>
37 #include "aw2-saa7146.h"
39 MODULE_AUTHOR("Cedric Bregardis <cedric.bregardis@free.fr>, "
40 "Jean-Christian Hassler <jhassler@free.fr>");
41 MODULE_DESCRIPTION("Emagic Audiowerk 2 sound driver");
42 MODULE_LICENSE("GPL");
44 /*********************************
46 ********************************/
47 #define PCI_VENDOR_ID_SAA7146 0x1131
48 #define PCI_DEVICE_ID_SAA7146 0x7146
50 #define CTL_ROUTE_ANALOG 0
51 #define CTL_ROUTE_DIGITAL 1
53 /*********************************
55 ********************************/
56 /* hardware definition */
57 static struct snd_pcm_hardware snd_aw2_playback_hw
= {
58 .info
= (SNDRV_PCM_INFO_MMAP
|
59 SNDRV_PCM_INFO_INTERLEAVED
|
60 SNDRV_PCM_INFO_BLOCK_TRANSFER
| SNDRV_PCM_INFO_MMAP_VALID
),
61 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
62 .rates
= SNDRV_PCM_RATE_44100
,
67 .buffer_bytes_max
= 32768,
68 .period_bytes_min
= 4096,
69 .period_bytes_max
= 32768,
74 static struct snd_pcm_hardware snd_aw2_capture_hw
= {
75 .info
= (SNDRV_PCM_INFO_MMAP
|
76 SNDRV_PCM_INFO_INTERLEAVED
|
77 SNDRV_PCM_INFO_BLOCK_TRANSFER
| SNDRV_PCM_INFO_MMAP_VALID
),
78 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
79 .rates
= SNDRV_PCM_RATE_44100
,
84 .buffer_bytes_max
= 32768,
85 .period_bytes_min
= 4096,
86 .period_bytes_max
= 32768,
91 struct aw2_pcm_device
{
93 unsigned int stream_number
;
98 struct snd_aw2_saa7146 saa7146
;
105 unsigned long iobase_phys
;
106 void __iomem
*iobase_virt
;
108 struct snd_card
*card
;
110 struct aw2_pcm_device device_playback
[NB_STREAM_PLAYBACK
];
111 struct aw2_pcm_device device_capture
[NB_STREAM_CAPTURE
];
114 /*********************************
115 * FUNCTION DECLARATIONS
116 ********************************/
117 static int __init
alsa_card_aw2_init(void);
118 static void __exit
alsa_card_aw2_exit(void);
119 static int snd_aw2_dev_free(struct snd_device
*device
);
120 static int __devinit
snd_aw2_create(struct snd_card
*card
,
121 struct pci_dev
*pci
, struct aw2
**rchip
);
122 static int __devinit
snd_aw2_probe(struct pci_dev
*pci
,
123 const struct pci_device_id
*pci_id
);
124 static void __devexit
snd_aw2_remove(struct pci_dev
*pci
);
125 static int snd_aw2_pcm_playback_open(struct snd_pcm_substream
*substream
);
126 static int snd_aw2_pcm_playback_close(struct snd_pcm_substream
*substream
);
127 static int snd_aw2_pcm_capture_open(struct snd_pcm_substream
*substream
);
128 static int snd_aw2_pcm_capture_close(struct snd_pcm_substream
*substream
);
129 static int snd_aw2_pcm_hw_params(struct snd_pcm_substream
*substream
,
130 struct snd_pcm_hw_params
*hw_params
);
131 static int snd_aw2_pcm_hw_free(struct snd_pcm_substream
*substream
);
132 static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream
*substream
);
133 static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream
*substream
);
134 static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream
*substream
,
136 static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream
*substream
,
138 static snd_pcm_uframes_t
snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
140 static snd_pcm_uframes_t
snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
142 static int __devinit
snd_aw2_new_pcm(struct aw2
*chip
);
144 static int snd_aw2_control_switch_capture_info(struct snd_kcontrol
*kcontrol
,
145 struct snd_ctl_elem_info
*uinfo
);
146 static int snd_aw2_control_switch_capture_get(struct snd_kcontrol
*kcontrol
,
147 struct snd_ctl_elem_value
149 static int snd_aw2_control_switch_capture_put(struct snd_kcontrol
*kcontrol
,
150 struct snd_ctl_elem_value
153 /*********************************
155 ********************************/
156 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
157 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
158 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
160 module_param_array(index
, int, NULL
, 0444);
161 MODULE_PARM_DESC(index
, "Index value for Audiowerk2 soundcard.");
162 module_param_array(id
, charp
, NULL
, 0444);
163 MODULE_PARM_DESC(id
, "ID string for the Audiowerk2 soundcard.");
164 module_param_array(enable
, bool, NULL
, 0444);
165 MODULE_PARM_DESC(enable
, "Enable Audiowerk2 soundcard.");
167 static DEFINE_PCI_DEVICE_TABLE(snd_aw2_ids
) = {
168 {PCI_VENDOR_ID_SAA7146
, PCI_DEVICE_ID_SAA7146
, 0, 0,
173 MODULE_DEVICE_TABLE(pci
, snd_aw2_ids
);
175 /* pci_driver definition */
176 static struct pci_driver driver
= {
177 .name
= "Emagic Audiowerk 2",
178 .id_table
= snd_aw2_ids
,
179 .probe
= snd_aw2_probe
,
180 .remove
= __devexit_p(snd_aw2_remove
),
183 /* operators for playback PCM alsa interface */
184 static struct snd_pcm_ops snd_aw2_playback_ops
= {
185 .open
= snd_aw2_pcm_playback_open
,
186 .close
= snd_aw2_pcm_playback_close
,
187 .ioctl
= snd_pcm_lib_ioctl
,
188 .hw_params
= snd_aw2_pcm_hw_params
,
189 .hw_free
= snd_aw2_pcm_hw_free
,
190 .prepare
= snd_aw2_pcm_prepare_playback
,
191 .trigger
= snd_aw2_pcm_trigger_playback
,
192 .pointer
= snd_aw2_pcm_pointer_playback
,
195 /* operators for capture PCM alsa interface */
196 static struct snd_pcm_ops snd_aw2_capture_ops
= {
197 .open
= snd_aw2_pcm_capture_open
,
198 .close
= snd_aw2_pcm_capture_close
,
199 .ioctl
= snd_pcm_lib_ioctl
,
200 .hw_params
= snd_aw2_pcm_hw_params
,
201 .hw_free
= snd_aw2_pcm_hw_free
,
202 .prepare
= snd_aw2_pcm_prepare_capture
,
203 .trigger
= snd_aw2_pcm_trigger_capture
,
204 .pointer
= snd_aw2_pcm_pointer_capture
,
207 static struct snd_kcontrol_new aw2_control __devinitdata
= {
208 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
209 .name
= "PCM Capture Route",
211 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
212 .private_value
= 0xffff,
213 .info
= snd_aw2_control_switch_capture_info
,
214 .get
= snd_aw2_control_switch_capture_get
,
215 .put
= snd_aw2_control_switch_capture_put
218 /*********************************
219 * FUNCTION IMPLEMENTATIONS
220 ********************************/
222 /* initialization of the module */
223 static int __init
alsa_card_aw2_init(void)
225 snd_printdd(KERN_DEBUG
"aw2: Load aw2 module\n");
226 return pci_register_driver(&driver
);
229 /* clean up the module */
230 static void __exit
alsa_card_aw2_exit(void)
232 snd_printdd(KERN_DEBUG
"aw2: Unload aw2 module\n");
233 pci_unregister_driver(&driver
);
236 module_init(alsa_card_aw2_init
);
237 module_exit(alsa_card_aw2_exit
);
239 /* component-destructor */
240 static int snd_aw2_dev_free(struct snd_device
*device
)
242 struct aw2
*chip
= device
->device_data
;
245 snd_aw2_saa7146_free(&chip
->saa7146
);
247 /* release the irq */
249 free_irq(chip
->irq
, (void *)chip
);
250 /* release the i/o ports & memory */
251 if (chip
->iobase_virt
)
252 iounmap(chip
->iobase_virt
);
254 pci_release_regions(chip
->pci
);
255 /* disable the PCI entry */
256 pci_disable_device(chip
->pci
);
257 /* release the data */
263 /* chip-specific constructor */
264 static int __devinit
snd_aw2_create(struct snd_card
*card
,
265 struct pci_dev
*pci
, struct aw2
**rchip
)
269 static struct snd_device_ops ops
= {
270 .dev_free
= snd_aw2_dev_free
,
275 /* initialize the PCI entry */
276 err
= pci_enable_device(pci
);
281 /* check PCI availability (32bit DMA) */
282 if ((pci_set_dma_mask(pci
, DMA_BIT_MASK(32)) < 0) ||
283 (pci_set_consistent_dma_mask(pci
, DMA_BIT_MASK(32)) < 0)) {
284 printk(KERN_ERR
"aw2: Impossible to set 32bit mask DMA\n");
285 pci_disable_device(pci
);
288 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
290 pci_disable_device(pci
);
294 /* initialize the stuff */
299 /* (1) PCI resource allocation */
300 err
= pci_request_regions(pci
, "Audiowerk2");
302 pci_disable_device(pci
);
306 chip
->iobase_phys
= pci_resource_start(pci
, 0);
308 ioremap_nocache(chip
->iobase_phys
,
309 pci_resource_len(pci
, 0));
311 if (chip
->iobase_virt
== NULL
) {
312 printk(KERN_ERR
"aw2: unable to remap memory region");
313 pci_release_regions(pci
);
314 pci_disable_device(pci
);
319 /* (2) initialization of the chip hardware */
320 snd_aw2_saa7146_setup(&chip
->saa7146
, chip
->iobase_virt
);
322 if (request_irq(pci
->irq
, snd_aw2_saa7146_interrupt
,
323 IRQF_SHARED
, "Audiowerk2", chip
)) {
324 printk(KERN_ERR
"aw2: Cannot grab irq %d\n", pci
->irq
);
326 iounmap(chip
->iobase_virt
);
327 pci_release_regions(chip
->pci
);
328 pci_disable_device(chip
->pci
);
332 chip
->irq
= pci
->irq
;
334 err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
);
336 free_irq(chip
->irq
, (void *)chip
);
337 iounmap(chip
->iobase_virt
);
338 pci_release_regions(chip
->pci
);
339 pci_disable_device(chip
->pci
);
344 snd_card_set_dev(card
, &pci
->dev
);
348 "Audiowerk 2 sound card (saa7146 chipset) detected and "
354 static int __devinit
snd_aw2_probe(struct pci_dev
*pci
,
355 const struct pci_device_id
*pci_id
)
358 struct snd_card
*card
;
362 /* (1) Continue if device is not enabled, else inc dev */
363 if (dev
>= SNDRV_CARDS
)
370 /* (2) Create card instance */
371 err
= snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
, 0, &card
);
375 /* (3) Create main component */
376 err
= snd_aw2_create(card
, pci
, &chip
);
382 /* initialize mutex */
383 mutex_init(&chip
->mtx
);
385 spin_lock_init(&chip
->reg_lock
);
386 /* (4) Define driver ID and name string */
387 strcpy(card
->driver
, "aw2");
388 strcpy(card
->shortname
, "Audiowerk2");
390 sprintf(card
->longname
, "%s with SAA7146 irq %i",
391 card
->shortname
, chip
->irq
);
393 /* (5) Create other components */
394 snd_aw2_new_pcm(chip
);
396 /* (6) Register card instance */
397 err
= snd_card_register(card
);
403 /* (7) Set PCI driver data */
404 pci_set_drvdata(pci
, card
);
411 static void __devexit
snd_aw2_remove(struct pci_dev
*pci
)
413 snd_card_free(pci_get_drvdata(pci
));
414 pci_set_drvdata(pci
, NULL
);
418 static int snd_aw2_pcm_playback_open(struct snd_pcm_substream
*substream
)
420 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
422 snd_printdd(KERN_DEBUG
"aw2: Playback_open \n");
423 runtime
->hw
= snd_aw2_playback_hw
;
428 static int snd_aw2_pcm_playback_close(struct snd_pcm_substream
*substream
)
434 static int snd_aw2_pcm_capture_open(struct snd_pcm_substream
*substream
)
436 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
438 snd_printdd(KERN_DEBUG
"aw2: Capture_open \n");
439 runtime
->hw
= snd_aw2_capture_hw
;
444 static int snd_aw2_pcm_capture_close(struct snd_pcm_substream
*substream
)
446 /* TODO: something to do ? */
450 /* hw_params callback */
451 static int snd_aw2_pcm_hw_params(struct snd_pcm_substream
*substream
,
452 struct snd_pcm_hw_params
*hw_params
)
454 return snd_pcm_lib_malloc_pages(substream
,
455 params_buffer_bytes(hw_params
));
458 /* hw_free callback */
459 static int snd_aw2_pcm_hw_free(struct snd_pcm_substream
*substream
)
461 return snd_pcm_lib_free_pages(substream
);
464 /* prepare callback for playback */
465 static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream
*substream
)
467 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
468 struct aw2
*chip
= pcm_device
->chip
;
469 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
470 unsigned long period_size
, buffer_size
;
472 mutex_lock(&chip
->mtx
);
474 period_size
= snd_pcm_lib_period_bytes(substream
);
475 buffer_size
= snd_pcm_lib_buffer_bytes(substream
);
477 snd_aw2_saa7146_pcm_init_playback(&chip
->saa7146
,
478 pcm_device
->stream_number
,
479 runtime
->dma_addr
, period_size
,
482 /* Define Interrupt callback */
483 snd_aw2_saa7146_define_it_playback_callback(pcm_device
->stream_number
,
484 (snd_aw2_saa7146_it_cb
)
485 snd_pcm_period_elapsed
,
488 mutex_unlock(&chip
->mtx
);
493 /* prepare callback for capture */
494 static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream
*substream
)
496 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
497 struct aw2
*chip
= pcm_device
->chip
;
498 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
499 unsigned long period_size
, buffer_size
;
501 mutex_lock(&chip
->mtx
);
503 period_size
= snd_pcm_lib_period_bytes(substream
);
504 buffer_size
= snd_pcm_lib_buffer_bytes(substream
);
506 snd_aw2_saa7146_pcm_init_capture(&chip
->saa7146
,
507 pcm_device
->stream_number
,
508 runtime
->dma_addr
, period_size
,
511 /* Define Interrupt callback */
512 snd_aw2_saa7146_define_it_capture_callback(pcm_device
->stream_number
,
513 (snd_aw2_saa7146_it_cb
)
514 snd_pcm_period_elapsed
,
517 mutex_unlock(&chip
->mtx
);
522 /* playback trigger callback */
523 static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream
*substream
,
527 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
528 struct aw2
*chip
= pcm_device
->chip
;
529 spin_lock(&chip
->reg_lock
);
531 case SNDRV_PCM_TRIGGER_START
:
532 snd_aw2_saa7146_pcm_trigger_start_playback(&chip
->saa7146
,
536 case SNDRV_PCM_TRIGGER_STOP
:
537 snd_aw2_saa7146_pcm_trigger_stop_playback(&chip
->saa7146
,
544 spin_unlock(&chip
->reg_lock
);
548 /* capture trigger callback */
549 static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream
*substream
,
553 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
554 struct aw2
*chip
= pcm_device
->chip
;
555 spin_lock(&chip
->reg_lock
);
557 case SNDRV_PCM_TRIGGER_START
:
558 snd_aw2_saa7146_pcm_trigger_start_capture(&chip
->saa7146
,
562 case SNDRV_PCM_TRIGGER_STOP
:
563 snd_aw2_saa7146_pcm_trigger_stop_capture(&chip
->saa7146
,
570 spin_unlock(&chip
->reg_lock
);
574 /* playback pointer callback */
575 static snd_pcm_uframes_t
snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
578 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
579 struct aw2
*chip
= pcm_device
->chip
;
580 unsigned int current_ptr
;
582 /* get the current hardware pointer */
583 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
585 snd_aw2_saa7146_get_hw_ptr_playback(&chip
->saa7146
,
586 pcm_device
->stream_number
,
588 runtime
->buffer_size
);
590 return bytes_to_frames(substream
->runtime
, current_ptr
);
593 /* capture pointer callback */
594 static snd_pcm_uframes_t
snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
597 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
598 struct aw2
*chip
= pcm_device
->chip
;
599 unsigned int current_ptr
;
601 /* get the current hardware pointer */
602 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
604 snd_aw2_saa7146_get_hw_ptr_capture(&chip
->saa7146
,
605 pcm_device
->stream_number
,
607 runtime
->buffer_size
);
609 return bytes_to_frames(substream
->runtime
, current_ptr
);
612 /* create a pcm device */
613 static int __devinit
snd_aw2_new_pcm(struct aw2
*chip
)
615 struct snd_pcm
*pcm_playback_ana
;
616 struct snd_pcm
*pcm_playback_num
;
617 struct snd_pcm
*pcm_capture
;
618 struct aw2_pcm_device
*pcm_device
;
621 /* Create new Alsa PCM device */
623 err
= snd_pcm_new(chip
->card
, "Audiowerk2 analog playback", 0, 1, 0,
626 printk(KERN_ERR
"aw2: snd_pcm_new error (0x%X)\n", err
);
631 pcm_device
= &chip
->device_playback
[NUM_STREAM_PLAYBACK_ANA
];
633 /* Set PCM device name */
634 strcpy(pcm_playback_ana
->name
, "Analog playback");
635 /* Associate private data to PCM device */
636 pcm_playback_ana
->private_data
= pcm_device
;
637 /* set operators of PCM device */
638 snd_pcm_set_ops(pcm_playback_ana
, SNDRV_PCM_STREAM_PLAYBACK
,
639 &snd_aw2_playback_ops
);
640 /* store PCM device */
641 pcm_device
->pcm
= pcm_playback_ana
;
642 /* give base chip pointer to our internal pcm device
644 pcm_device
->chip
= chip
;
645 /* Give stream number to PCM device */
646 pcm_device
->stream_number
= NUM_STREAM_PLAYBACK_ANA
;
648 /* pre-allocation of buffers */
649 /* Preallocate continuous pages. */
650 err
= snd_pcm_lib_preallocate_pages_for_all(pcm_playback_ana
,
654 64 * 1024, 64 * 1024);
656 printk(KERN_ERR
"aw2: snd_pcm_lib_preallocate_pages_for_all "
657 "error (0x%X)\n", err
);
659 err
= snd_pcm_new(chip
->card
, "Audiowerk2 digital playback", 1, 1, 0,
663 printk(KERN_ERR
"aw2: snd_pcm_new error (0x%X)\n", err
);
667 pcm_device
= &chip
->device_playback
[NUM_STREAM_PLAYBACK_DIG
];
669 /* Set PCM device name */
670 strcpy(pcm_playback_num
->name
, "Digital playback");
671 /* Associate private data to PCM device */
672 pcm_playback_num
->private_data
= pcm_device
;
673 /* set operators of PCM device */
674 snd_pcm_set_ops(pcm_playback_num
, SNDRV_PCM_STREAM_PLAYBACK
,
675 &snd_aw2_playback_ops
);
676 /* store PCM device */
677 pcm_device
->pcm
= pcm_playback_num
;
678 /* give base chip pointer to our internal pcm device
680 pcm_device
->chip
= chip
;
681 /* Give stream number to PCM device */
682 pcm_device
->stream_number
= NUM_STREAM_PLAYBACK_DIG
;
684 /* pre-allocation of buffers */
685 /* Preallocate continuous pages. */
686 err
= snd_pcm_lib_preallocate_pages_for_all(pcm_playback_num
,
690 64 * 1024, 64 * 1024);
693 "aw2: snd_pcm_lib_preallocate_pages_for_all error "
698 err
= snd_pcm_new(chip
->card
, "Audiowerk2 capture", 2, 0, 1,
702 printk(KERN_ERR
"aw2: snd_pcm_new error (0x%X)\n", err
);
707 pcm_device
= &chip
->device_capture
[NUM_STREAM_CAPTURE_ANA
];
709 /* Set PCM device name */
710 strcpy(pcm_capture
->name
, "Capture");
711 /* Associate private data to PCM device */
712 pcm_capture
->private_data
= pcm_device
;
713 /* set operators of PCM device */
714 snd_pcm_set_ops(pcm_capture
, SNDRV_PCM_STREAM_CAPTURE
,
715 &snd_aw2_capture_ops
);
716 /* store PCM device */
717 pcm_device
->pcm
= pcm_capture
;
718 /* give base chip pointer to our internal pcm device
720 pcm_device
->chip
= chip
;
721 /* Give stream number to PCM device */
722 pcm_device
->stream_number
= NUM_STREAM_CAPTURE_ANA
;
724 /* pre-allocation of buffers */
725 /* Preallocate continuous pages. */
726 err
= snd_pcm_lib_preallocate_pages_for_all(pcm_capture
,
730 64 * 1024, 64 * 1024);
733 "aw2: snd_pcm_lib_preallocate_pages_for_all error "
738 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&aw2_control
, chip
));
740 printk(KERN_ERR
"aw2: snd_ctl_add error (0x%X)\n", err
);
747 static int snd_aw2_control_switch_capture_info(struct snd_kcontrol
*kcontrol
,
748 struct snd_ctl_elem_info
*uinfo
)
750 static char *texts
[2] = {
753 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
755 uinfo
->value
.enumerated
.items
= 2;
756 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
) {
757 uinfo
->value
.enumerated
.item
=
758 uinfo
->value
.enumerated
.items
- 1;
760 strcpy(uinfo
->value
.enumerated
.name
,
761 texts
[uinfo
->value
.enumerated
.item
]);
765 static int snd_aw2_control_switch_capture_get(struct snd_kcontrol
*kcontrol
,
766 struct snd_ctl_elem_value
769 struct aw2
*chip
= snd_kcontrol_chip(kcontrol
);
770 if (snd_aw2_saa7146_is_using_digital_input(&chip
->saa7146
))
771 ucontrol
->value
.enumerated
.item
[0] = CTL_ROUTE_DIGITAL
;
773 ucontrol
->value
.enumerated
.item
[0] = CTL_ROUTE_ANALOG
;
777 static int snd_aw2_control_switch_capture_put(struct snd_kcontrol
*kcontrol
,
778 struct snd_ctl_elem_value
781 struct aw2
*chip
= snd_kcontrol_chip(kcontrol
);
784 snd_aw2_saa7146_is_using_digital_input(&chip
->saa7146
);
786 if (((ucontrol
->value
.integer
.value
[0] == CTL_ROUTE_DIGITAL
)
788 || ((ucontrol
->value
.integer
.value
[0] == CTL_ROUTE_ANALOG
)
790 snd_aw2_saa7146_use_digital_input(&chip
->saa7146
, !is_disgital
);