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 CTL_ROUTE_ANALOG 0
48 #define CTL_ROUTE_DIGITAL 1
50 /*********************************
52 ********************************/
53 /* hardware definition */
54 static struct snd_pcm_hardware snd_aw2_playback_hw
= {
55 .info
= (SNDRV_PCM_INFO_MMAP
|
56 SNDRV_PCM_INFO_INTERLEAVED
|
57 SNDRV_PCM_INFO_BLOCK_TRANSFER
| SNDRV_PCM_INFO_MMAP_VALID
),
58 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
59 .rates
= SNDRV_PCM_RATE_44100
,
64 .buffer_bytes_max
= 32768,
65 .period_bytes_min
= 4096,
66 .period_bytes_max
= 32768,
71 static struct snd_pcm_hardware snd_aw2_capture_hw
= {
72 .info
= (SNDRV_PCM_INFO_MMAP
|
73 SNDRV_PCM_INFO_INTERLEAVED
|
74 SNDRV_PCM_INFO_BLOCK_TRANSFER
| SNDRV_PCM_INFO_MMAP_VALID
),
75 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
76 .rates
= SNDRV_PCM_RATE_44100
,
81 .buffer_bytes_max
= 32768,
82 .period_bytes_min
= 4096,
83 .period_bytes_max
= 32768,
88 struct aw2_pcm_device
{
90 unsigned int stream_number
;
95 struct snd_aw2_saa7146 saa7146
;
102 unsigned long iobase_phys
;
103 void __iomem
*iobase_virt
;
105 struct snd_card
*card
;
107 struct aw2_pcm_device device_playback
[NB_STREAM_PLAYBACK
];
108 struct aw2_pcm_device device_capture
[NB_STREAM_CAPTURE
];
111 /*********************************
112 * FUNCTION DECLARATIONS
113 ********************************/
114 static int __init
alsa_card_aw2_init(void);
115 static void __exit
alsa_card_aw2_exit(void);
116 static int snd_aw2_dev_free(struct snd_device
*device
);
117 static int __devinit
snd_aw2_create(struct snd_card
*card
,
118 struct pci_dev
*pci
, struct aw2
**rchip
);
119 static int __devinit
snd_aw2_probe(struct pci_dev
*pci
,
120 const struct pci_device_id
*pci_id
);
121 static void __devexit
snd_aw2_remove(struct pci_dev
*pci
);
122 static int snd_aw2_pcm_playback_open(struct snd_pcm_substream
*substream
);
123 static int snd_aw2_pcm_playback_close(struct snd_pcm_substream
*substream
);
124 static int snd_aw2_pcm_capture_open(struct snd_pcm_substream
*substream
);
125 static int snd_aw2_pcm_capture_close(struct snd_pcm_substream
*substream
);
126 static int snd_aw2_pcm_hw_params(struct snd_pcm_substream
*substream
,
127 struct snd_pcm_hw_params
*hw_params
);
128 static int snd_aw2_pcm_hw_free(struct snd_pcm_substream
*substream
);
129 static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream
*substream
);
130 static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream
*substream
);
131 static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream
*substream
,
133 static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream
*substream
,
135 static snd_pcm_uframes_t
snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
137 static snd_pcm_uframes_t
snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
139 static int __devinit
snd_aw2_new_pcm(struct aw2
*chip
);
141 static int snd_aw2_control_switch_capture_info(struct snd_kcontrol
*kcontrol
,
142 struct snd_ctl_elem_info
*uinfo
);
143 static int snd_aw2_control_switch_capture_get(struct snd_kcontrol
*kcontrol
,
144 struct snd_ctl_elem_value
146 static int snd_aw2_control_switch_capture_put(struct snd_kcontrol
*kcontrol
,
147 struct snd_ctl_elem_value
150 /*********************************
152 ********************************/
153 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
154 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
155 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
157 module_param_array(index
, int, NULL
, 0444);
158 MODULE_PARM_DESC(index
, "Index value for Audiowerk2 soundcard.");
159 module_param_array(id
, charp
, NULL
, 0444);
160 MODULE_PARM_DESC(id
, "ID string for the Audiowerk2 soundcard.");
161 module_param_array(enable
, bool, NULL
, 0444);
162 MODULE_PARM_DESC(enable
, "Enable Audiowerk2 soundcard.");
164 static DEFINE_PCI_DEVICE_TABLE(snd_aw2_ids
) = {
165 {PCI_VENDOR_ID_PHILIPS
, PCI_DEVICE_ID_PHILIPS_SAA7146
, 0, 0,
170 MODULE_DEVICE_TABLE(pci
, snd_aw2_ids
);
172 /* pci_driver definition */
173 static struct pci_driver driver
= {
174 .name
= "Emagic Audiowerk 2",
175 .id_table
= snd_aw2_ids
,
176 .probe
= snd_aw2_probe
,
177 .remove
= __devexit_p(snd_aw2_remove
),
180 /* operators for playback PCM alsa interface */
181 static struct snd_pcm_ops snd_aw2_playback_ops
= {
182 .open
= snd_aw2_pcm_playback_open
,
183 .close
= snd_aw2_pcm_playback_close
,
184 .ioctl
= snd_pcm_lib_ioctl
,
185 .hw_params
= snd_aw2_pcm_hw_params
,
186 .hw_free
= snd_aw2_pcm_hw_free
,
187 .prepare
= snd_aw2_pcm_prepare_playback
,
188 .trigger
= snd_aw2_pcm_trigger_playback
,
189 .pointer
= snd_aw2_pcm_pointer_playback
,
192 /* operators for capture PCM alsa interface */
193 static struct snd_pcm_ops snd_aw2_capture_ops
= {
194 .open
= snd_aw2_pcm_capture_open
,
195 .close
= snd_aw2_pcm_capture_close
,
196 .ioctl
= snd_pcm_lib_ioctl
,
197 .hw_params
= snd_aw2_pcm_hw_params
,
198 .hw_free
= snd_aw2_pcm_hw_free
,
199 .prepare
= snd_aw2_pcm_prepare_capture
,
200 .trigger
= snd_aw2_pcm_trigger_capture
,
201 .pointer
= snd_aw2_pcm_pointer_capture
,
204 static struct snd_kcontrol_new aw2_control __devinitdata
= {
205 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
206 .name
= "PCM Capture Route",
208 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
209 .private_value
= 0xffff,
210 .info
= snd_aw2_control_switch_capture_info
,
211 .get
= snd_aw2_control_switch_capture_get
,
212 .put
= snd_aw2_control_switch_capture_put
215 /*********************************
216 * FUNCTION IMPLEMENTATIONS
217 ********************************/
219 /* initialization of the module */
220 static int __init
alsa_card_aw2_init(void)
222 snd_printdd(KERN_DEBUG
"aw2: Load aw2 module\n");
223 return pci_register_driver(&driver
);
226 /* clean up the module */
227 static void __exit
alsa_card_aw2_exit(void)
229 snd_printdd(KERN_DEBUG
"aw2: Unload aw2 module\n");
230 pci_unregister_driver(&driver
);
233 module_init(alsa_card_aw2_init
);
234 module_exit(alsa_card_aw2_exit
);
236 /* component-destructor */
237 static int snd_aw2_dev_free(struct snd_device
*device
)
239 struct aw2
*chip
= device
->device_data
;
242 snd_aw2_saa7146_free(&chip
->saa7146
);
244 /* release the irq */
246 free_irq(chip
->irq
, (void *)chip
);
247 /* release the i/o ports & memory */
248 if (chip
->iobase_virt
)
249 iounmap(chip
->iobase_virt
);
251 pci_release_regions(chip
->pci
);
252 /* disable the PCI entry */
253 pci_disable_device(chip
->pci
);
254 /* release the data */
260 /* chip-specific constructor */
261 static int __devinit
snd_aw2_create(struct snd_card
*card
,
262 struct pci_dev
*pci
, struct aw2
**rchip
)
266 static struct snd_device_ops ops
= {
267 .dev_free
= snd_aw2_dev_free
,
272 /* initialize the PCI entry */
273 err
= pci_enable_device(pci
);
278 /* check PCI availability (32bit DMA) */
279 if ((pci_set_dma_mask(pci
, DMA_BIT_MASK(32)) < 0) ||
280 (pci_set_consistent_dma_mask(pci
, DMA_BIT_MASK(32)) < 0)) {
281 printk(KERN_ERR
"aw2: Impossible to set 32bit mask DMA\n");
282 pci_disable_device(pci
);
285 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
287 pci_disable_device(pci
);
291 /* initialize the stuff */
296 /* (1) PCI resource allocation */
297 err
= pci_request_regions(pci
, "Audiowerk2");
299 pci_disable_device(pci
);
303 chip
->iobase_phys
= pci_resource_start(pci
, 0);
305 ioremap_nocache(chip
->iobase_phys
,
306 pci_resource_len(pci
, 0));
308 if (chip
->iobase_virt
== NULL
) {
309 printk(KERN_ERR
"aw2: unable to remap memory region");
310 pci_release_regions(pci
);
311 pci_disable_device(pci
);
316 /* (2) initialization of the chip hardware */
317 snd_aw2_saa7146_setup(&chip
->saa7146
, chip
->iobase_virt
);
319 if (request_irq(pci
->irq
, snd_aw2_saa7146_interrupt
,
320 IRQF_SHARED
, "Audiowerk2", chip
)) {
321 printk(KERN_ERR
"aw2: Cannot grab irq %d\n", pci
->irq
);
323 iounmap(chip
->iobase_virt
);
324 pci_release_regions(chip
->pci
);
325 pci_disable_device(chip
->pci
);
329 chip
->irq
= pci
->irq
;
331 err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
);
333 free_irq(chip
->irq
, (void *)chip
);
334 iounmap(chip
->iobase_virt
);
335 pci_release_regions(chip
->pci
);
336 pci_disable_device(chip
->pci
);
341 snd_card_set_dev(card
, &pci
->dev
);
345 "Audiowerk 2 sound card (saa7146 chipset) detected and "
351 static int __devinit
snd_aw2_probe(struct pci_dev
*pci
,
352 const struct pci_device_id
*pci_id
)
355 struct snd_card
*card
;
359 /* (1) Continue if device is not enabled, else inc dev */
360 if (dev
>= SNDRV_CARDS
)
367 /* (2) Create card instance */
368 err
= snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
, 0, &card
);
372 /* (3) Create main component */
373 err
= snd_aw2_create(card
, pci
, &chip
);
379 /* initialize mutex */
380 mutex_init(&chip
->mtx
);
382 spin_lock_init(&chip
->reg_lock
);
383 /* (4) Define driver ID and name string */
384 strcpy(card
->driver
, "aw2");
385 strcpy(card
->shortname
, "Audiowerk2");
387 sprintf(card
->longname
, "%s with SAA7146 irq %i",
388 card
->shortname
, chip
->irq
);
390 /* (5) Create other components */
391 snd_aw2_new_pcm(chip
);
393 /* (6) Register card instance */
394 err
= snd_card_register(card
);
400 /* (7) Set PCI driver data */
401 pci_set_drvdata(pci
, card
);
408 static void __devexit
snd_aw2_remove(struct pci_dev
*pci
)
410 snd_card_free(pci_get_drvdata(pci
));
411 pci_set_drvdata(pci
, NULL
);
415 static int snd_aw2_pcm_playback_open(struct snd_pcm_substream
*substream
)
417 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
419 snd_printdd(KERN_DEBUG
"aw2: Playback_open\n");
420 runtime
->hw
= snd_aw2_playback_hw
;
425 static int snd_aw2_pcm_playback_close(struct snd_pcm_substream
*substream
)
431 static int snd_aw2_pcm_capture_open(struct snd_pcm_substream
*substream
)
433 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
435 snd_printdd(KERN_DEBUG
"aw2: Capture_open\n");
436 runtime
->hw
= snd_aw2_capture_hw
;
441 static int snd_aw2_pcm_capture_close(struct snd_pcm_substream
*substream
)
443 /* TODO: something to do ? */
447 /* hw_params callback */
448 static int snd_aw2_pcm_hw_params(struct snd_pcm_substream
*substream
,
449 struct snd_pcm_hw_params
*hw_params
)
451 return snd_pcm_lib_malloc_pages(substream
,
452 params_buffer_bytes(hw_params
));
455 /* hw_free callback */
456 static int snd_aw2_pcm_hw_free(struct snd_pcm_substream
*substream
)
458 return snd_pcm_lib_free_pages(substream
);
461 /* prepare callback for playback */
462 static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream
*substream
)
464 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
465 struct aw2
*chip
= pcm_device
->chip
;
466 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
467 unsigned long period_size
, buffer_size
;
469 mutex_lock(&chip
->mtx
);
471 period_size
= snd_pcm_lib_period_bytes(substream
);
472 buffer_size
= snd_pcm_lib_buffer_bytes(substream
);
474 snd_aw2_saa7146_pcm_init_playback(&chip
->saa7146
,
475 pcm_device
->stream_number
,
476 runtime
->dma_addr
, period_size
,
479 /* Define Interrupt callback */
480 snd_aw2_saa7146_define_it_playback_callback(pcm_device
->stream_number
,
481 (snd_aw2_saa7146_it_cb
)
482 snd_pcm_period_elapsed
,
485 mutex_unlock(&chip
->mtx
);
490 /* prepare callback for capture */
491 static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream
*substream
)
493 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
494 struct aw2
*chip
= pcm_device
->chip
;
495 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
496 unsigned long period_size
, buffer_size
;
498 mutex_lock(&chip
->mtx
);
500 period_size
= snd_pcm_lib_period_bytes(substream
);
501 buffer_size
= snd_pcm_lib_buffer_bytes(substream
);
503 snd_aw2_saa7146_pcm_init_capture(&chip
->saa7146
,
504 pcm_device
->stream_number
,
505 runtime
->dma_addr
, period_size
,
508 /* Define Interrupt callback */
509 snd_aw2_saa7146_define_it_capture_callback(pcm_device
->stream_number
,
510 (snd_aw2_saa7146_it_cb
)
511 snd_pcm_period_elapsed
,
514 mutex_unlock(&chip
->mtx
);
519 /* playback trigger callback */
520 static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream
*substream
,
524 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
525 struct aw2
*chip
= pcm_device
->chip
;
526 spin_lock(&chip
->reg_lock
);
528 case SNDRV_PCM_TRIGGER_START
:
529 snd_aw2_saa7146_pcm_trigger_start_playback(&chip
->saa7146
,
533 case SNDRV_PCM_TRIGGER_STOP
:
534 snd_aw2_saa7146_pcm_trigger_stop_playback(&chip
->saa7146
,
541 spin_unlock(&chip
->reg_lock
);
545 /* capture trigger callback */
546 static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream
*substream
,
550 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
551 struct aw2
*chip
= pcm_device
->chip
;
552 spin_lock(&chip
->reg_lock
);
554 case SNDRV_PCM_TRIGGER_START
:
555 snd_aw2_saa7146_pcm_trigger_start_capture(&chip
->saa7146
,
559 case SNDRV_PCM_TRIGGER_STOP
:
560 snd_aw2_saa7146_pcm_trigger_stop_capture(&chip
->saa7146
,
567 spin_unlock(&chip
->reg_lock
);
571 /* playback pointer callback */
572 static snd_pcm_uframes_t
snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
575 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
576 struct aw2
*chip
= pcm_device
->chip
;
577 unsigned int current_ptr
;
579 /* get the current hardware pointer */
580 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
582 snd_aw2_saa7146_get_hw_ptr_playback(&chip
->saa7146
,
583 pcm_device
->stream_number
,
585 runtime
->buffer_size
);
587 return bytes_to_frames(substream
->runtime
, current_ptr
);
590 /* capture pointer callback */
591 static snd_pcm_uframes_t
snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
594 struct aw2_pcm_device
*pcm_device
= snd_pcm_substream_chip(substream
);
595 struct aw2
*chip
= pcm_device
->chip
;
596 unsigned int current_ptr
;
598 /* get the current hardware pointer */
599 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
601 snd_aw2_saa7146_get_hw_ptr_capture(&chip
->saa7146
,
602 pcm_device
->stream_number
,
604 runtime
->buffer_size
);
606 return bytes_to_frames(substream
->runtime
, current_ptr
);
609 /* create a pcm device */
610 static int __devinit
snd_aw2_new_pcm(struct aw2
*chip
)
612 struct snd_pcm
*pcm_playback_ana
;
613 struct snd_pcm
*pcm_playback_num
;
614 struct snd_pcm
*pcm_capture
;
615 struct aw2_pcm_device
*pcm_device
;
618 /* Create new Alsa PCM device */
620 err
= snd_pcm_new(chip
->card
, "Audiowerk2 analog playback", 0, 1, 0,
623 printk(KERN_ERR
"aw2: snd_pcm_new error (0x%X)\n", err
);
628 pcm_device
= &chip
->device_playback
[NUM_STREAM_PLAYBACK_ANA
];
630 /* Set PCM device name */
631 strcpy(pcm_playback_ana
->name
, "Analog playback");
632 /* Associate private data to PCM device */
633 pcm_playback_ana
->private_data
= pcm_device
;
634 /* set operators of PCM device */
635 snd_pcm_set_ops(pcm_playback_ana
, SNDRV_PCM_STREAM_PLAYBACK
,
636 &snd_aw2_playback_ops
);
637 /* store PCM device */
638 pcm_device
->pcm
= pcm_playback_ana
;
639 /* give base chip pointer to our internal pcm device
641 pcm_device
->chip
= chip
;
642 /* Give stream number to PCM device */
643 pcm_device
->stream_number
= NUM_STREAM_PLAYBACK_ANA
;
645 /* pre-allocation of buffers */
646 /* Preallocate continuous pages. */
647 err
= snd_pcm_lib_preallocate_pages_for_all(pcm_playback_ana
,
651 64 * 1024, 64 * 1024);
653 printk(KERN_ERR
"aw2: snd_pcm_lib_preallocate_pages_for_all "
654 "error (0x%X)\n", err
);
656 err
= snd_pcm_new(chip
->card
, "Audiowerk2 digital playback", 1, 1, 0,
660 printk(KERN_ERR
"aw2: snd_pcm_new error (0x%X)\n", err
);
664 pcm_device
= &chip
->device_playback
[NUM_STREAM_PLAYBACK_DIG
];
666 /* Set PCM device name */
667 strcpy(pcm_playback_num
->name
, "Digital playback");
668 /* Associate private data to PCM device */
669 pcm_playback_num
->private_data
= pcm_device
;
670 /* set operators of PCM device */
671 snd_pcm_set_ops(pcm_playback_num
, SNDRV_PCM_STREAM_PLAYBACK
,
672 &snd_aw2_playback_ops
);
673 /* store PCM device */
674 pcm_device
->pcm
= pcm_playback_num
;
675 /* give base chip pointer to our internal pcm device
677 pcm_device
->chip
= chip
;
678 /* Give stream number to PCM device */
679 pcm_device
->stream_number
= NUM_STREAM_PLAYBACK_DIG
;
681 /* pre-allocation of buffers */
682 /* Preallocate continuous pages. */
683 err
= snd_pcm_lib_preallocate_pages_for_all(pcm_playback_num
,
687 64 * 1024, 64 * 1024);
690 "aw2: snd_pcm_lib_preallocate_pages_for_all error "
695 err
= snd_pcm_new(chip
->card
, "Audiowerk2 capture", 2, 0, 1,
699 printk(KERN_ERR
"aw2: snd_pcm_new error (0x%X)\n", err
);
704 pcm_device
= &chip
->device_capture
[NUM_STREAM_CAPTURE_ANA
];
706 /* Set PCM device name */
707 strcpy(pcm_capture
->name
, "Capture");
708 /* Associate private data to PCM device */
709 pcm_capture
->private_data
= pcm_device
;
710 /* set operators of PCM device */
711 snd_pcm_set_ops(pcm_capture
, SNDRV_PCM_STREAM_CAPTURE
,
712 &snd_aw2_capture_ops
);
713 /* store PCM device */
714 pcm_device
->pcm
= pcm_capture
;
715 /* give base chip pointer to our internal pcm device
717 pcm_device
->chip
= chip
;
718 /* Give stream number to PCM device */
719 pcm_device
->stream_number
= NUM_STREAM_CAPTURE_ANA
;
721 /* pre-allocation of buffers */
722 /* Preallocate continuous pages. */
723 err
= snd_pcm_lib_preallocate_pages_for_all(pcm_capture
,
727 64 * 1024, 64 * 1024);
730 "aw2: snd_pcm_lib_preallocate_pages_for_all error "
735 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&aw2_control
, chip
));
737 printk(KERN_ERR
"aw2: snd_ctl_add error (0x%X)\n", err
);
744 static int snd_aw2_control_switch_capture_info(struct snd_kcontrol
*kcontrol
,
745 struct snd_ctl_elem_info
*uinfo
)
747 static char *texts
[2] = {
750 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
752 uinfo
->value
.enumerated
.items
= 2;
753 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
) {
754 uinfo
->value
.enumerated
.item
=
755 uinfo
->value
.enumerated
.items
- 1;
757 strcpy(uinfo
->value
.enumerated
.name
,
758 texts
[uinfo
->value
.enumerated
.item
]);
762 static int snd_aw2_control_switch_capture_get(struct snd_kcontrol
*kcontrol
,
763 struct snd_ctl_elem_value
766 struct aw2
*chip
= snd_kcontrol_chip(kcontrol
);
767 if (snd_aw2_saa7146_is_using_digital_input(&chip
->saa7146
))
768 ucontrol
->value
.enumerated
.item
[0] = CTL_ROUTE_DIGITAL
;
770 ucontrol
->value
.enumerated
.item
[0] = CTL_ROUTE_ANALOG
;
774 static int snd_aw2_control_switch_capture_put(struct snd_kcontrol
*kcontrol
,
775 struct snd_ctl_elem_value
778 struct aw2
*chip
= snd_kcontrol_chip(kcontrol
);
781 snd_aw2_saa7146_is_using_digital_input(&chip
->saa7146
);
783 if (((ucontrol
->value
.integer
.value
[0] == CTL_ROUTE_DIGITAL
)
785 || ((ucontrol
->value
.integer
.value
[0] == CTL_ROUTE_ANALOG
)
787 snd_aw2_saa7146_use_digital_input(&chip
->saa7146
, !is_disgital
);