aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/ca0106
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2005-11-17 10:40:18 +0100
committerJaroslav Kysela <perex@suse.cz>2006-01-03 12:17:01 +0100
commit95a98265eb7b112b3268761053d643635171e219 (patch)
treedaf88b4858b1ba856609c2a3138522ea4a2b6269 /sound/pci/ca0106
parent[ALSA] intel8x0 - Clean up delay function (diff)
downloadlinux-dev-95a98265eb7b112b3268761053d643635171e219.tar.xz
linux-dev-95a98265eb7b112b3268761053d643635171e219.zip
[ALSA] ca0106 - Code clean up
Modules: CA0106 driver Clean up snd-ca0106 driver code: - Fix spaces and indents - Remove unnecessary spinlocks - Clean up the mixer callbacks using private_value - Clean up mixer constructors using an array Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/ca0106')
-rw-r--r--sound/pci/ca0106/ca0106_main.c74
-rw-r--r--sound/pci/ca0106/ca0106_mixer.c417
2 files changed, 131 insertions, 360 deletions
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index a89eed255098..0120c4683c79 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -207,7 +207,8 @@ static snd_pcm_hardware_t snd_ca0106_playback_hw = {
SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_MMAP_VALID),
.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
- .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000,
+ .rates = (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |
+ SNDRV_PCM_RATE_192000),
.rate_min = 48000,
.rate_max = 192000,
.channels_min = 2, //1,
@@ -226,7 +227,8 @@ static snd_pcm_hardware_t snd_ca0106_capture_hw = {
SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_MMAP_VALID),
.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
- .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000,
+ .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
+ SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000),
.rate_min = 44100,
.rate_max = 192000,
.channels_min = 2,
@@ -276,11 +278,10 @@ int snd_ca0106_i2c_write(ca0106_t *emu,
u32 value)
{
u32 tmp;
- int timeout=0;
+ int timeout = 0;
int status;
int retry;
- if ((reg > 0x7f) || (value > 0x1ff))
- {
+ if ((reg > 0x7f) || (value > 0x1ff)) {
snd_printk(KERN_ERR "i2c_write: invalid values.\n");
return -EINVAL;
}
@@ -292,8 +293,7 @@ int snd_ca0106_i2c_write(ca0106_t *emu,
/* This controls the I2C connected to the WM8775 ADC Codec */
snd_ca0106_ptr_write(emu, I2C_D1, 0, tmp);
- for(retry=0;retry<10;retry++)
- {
+ for (retry = 0; retry < 10; retry++) {
/* Send the data to i2c */
tmp = snd_ca0106_ptr_read(emu, I2C_A, 0);
tmp = tmp & ~(I2C_A_ADC_READ|I2C_A_ADC_LAST|I2C_A_ADC_START|I2C_A_ADC_ADD_MASK);
@@ -301,24 +301,22 @@ int snd_ca0106_i2c_write(ca0106_t *emu,
snd_ca0106_ptr_write(emu, I2C_A, 0, tmp);
/* Wait till the transaction ends */
- while(1)
- {
+ while (1) {
status = snd_ca0106_ptr_read(emu, I2C_A, 0);
//snd_printk("I2C:status=0x%x\n", status);
timeout++;
- if((status & I2C_A_ADC_START)==0)
+ if ((status & I2C_A_ADC_START) == 0)
break;
- if(timeout>1000)
+ if (timeout > 1000)
break;
}
//Read back and see if the transaction is successful
- if((status & I2C_A_ADC_ABORT)==0)
+ if ((status & I2C_A_ADC_ABORT) == 0)
break;
}
- if(retry==10)
- {
+ if (retry == 10) {
snd_printk(KERN_ERR "Writing to ADC failed!\n");
return -EINVAL;
}
@@ -380,10 +378,10 @@ static int snd_ca0106_pcm_open_playback_channel(snd_pcm_substream_t *substream,
channel->emu = chip;
channel->number = channel_id;
- channel->use=1;
+ channel->use = 1;
//printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
//channel->interrupt = snd_ca0106_pcm_channel_interrupt;
- channel->epcm=epcm;
+ channel->epcm = epcm;
if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
return err;
if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0)
@@ -448,10 +446,10 @@ static int snd_ca0106_pcm_open_capture_channel(snd_pcm_substream_t *substream, i
channel->emu = chip;
channel->number = channel_id;
- channel->use=1;
+ channel->use = 1;
//printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
//channel->interrupt = snd_ca0106_pcm_channel_interrupt;
- channel->epcm=epcm;
+ channel->epcm = epcm;
if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
return err;
//snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hw_constraints_capture_period_sizes);
@@ -593,8 +591,8 @@ static int snd_ca0106_pcm_prepare_playback(snd_pcm_substream_t *substream)
/* FIXME: Check emu->buffer.size before actually writing to it. */
for(i=0; i < runtime->periods; i++) {
- table_base[i*2]=runtime->dma_addr+(i*period_size_bytes);
- table_base[(i*2)+1]=period_size_bytes<<16;
+ table_base[i*2] = runtime->dma_addr + (i * period_size_bytes);
+ table_base[i*2+1] = period_size_bytes << 16;
}
snd_ca0106_ptr_write(emu, PLAYBACK_LIST_ADDR, channel, emu->buffer.addr+(8*16*channel));
@@ -1008,13 +1006,8 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id,
unsigned int stat76;
ca0106_channel_t *pchannel;
- spin_lock(&chip->emu_lock);
-
status = inl(chip->port + IPR);
- // call updater, unlock before it
- spin_unlock(&chip->emu_lock);
-
if (! status)
return IRQ_NONE;
@@ -1024,11 +1017,11 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id,
mask = 0x11; /* 0x1 for one half, 0x10 for the other half period. */
for(i = 0; i < 4; i++) {
pchannel = &(chip->playback_channels[i]);
- if(stat76 & mask) {
+ if (stat76 & mask) {
/* FIXME: Select the correct substream for period elapsed */
if(pchannel->use) {
- snd_pcm_period_elapsed(pchannel->epcm->substream);
- //printk(KERN_INFO "interrupt [%d] used\n", i);
+ snd_pcm_period_elapsed(pchannel->epcm->substream);
+ //printk(KERN_INFO "interrupt [%d] used\n", i);
}
}
//printk(KERN_INFO "channel=%p\n",pchannel);
@@ -1038,11 +1031,11 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id,
mask = 0x110000; /* 0x1 for one half, 0x10 for the other half period. */
for(i = 0; i < 4; i++) {
pchannel = &(chip->capture_channels[i]);
- if(stat76 & mask) {
+ if (stat76 & mask) {
/* FIXME: Select the correct substream for period elapsed */
if(pchannel->use) {
- snd_pcm_period_elapsed(pchannel->epcm->substream);
- //printk(KERN_INFO "interrupt [%d] used\n", i);
+ snd_pcm_period_elapsed(pchannel->epcm->substream);
+ //printk(KERN_INFO "interrupt [%d] used\n", i);
}
}
//printk(KERN_INFO "channel=%p\n",pchannel);
@@ -1051,10 +1044,9 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id,
}
snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76);
- spin_lock(&chip->emu_lock);
if (chip->midi.dev_id &&
- (status & (chip->midi.ipr_tx|chip->midi.ipr_rx))) {
+ (status & (chip->midi.ipr_tx|chip->midi.ipr_rx))) {
if (chip->midi.interrupt)
chip->midi.interrupt(&chip->midi, status);
else
@@ -1064,8 +1056,6 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id,
// acknowledge the interrupt if necessary
outl(status, chip->port+IPR);
- spin_unlock(&chip->emu_lock);
-
return IRQ_HANDLED;
}
@@ -1202,8 +1192,9 @@ static int __devinit snd_ca0106_create(snd_card_t *card,
strcpy(card->driver, "CA0106");
strcpy(card->shortname, "CA0106");
- for (c=ca0106_chip_details; c->serial; c++) {
- if (c->serial == chip->serial) break;
+ for (c = ca0106_chip_details; c->serial; c++) {
+ if (c->serial == chip->serial)
+ break;
}
chip->details = c;
sprintf(card->longname, "%s at 0x%lx irq %i",
@@ -1359,7 +1350,7 @@ static int __devinit snd_ca0106_midi(ca0106_t *chip, unsigned int channel)
char *name;
int err;
- if(channel==CA0106_MIDI_CHAN_B) {
+ if (channel == CA0106_MIDI_CHAN_B) {
name = "CA0106 MPU-401 (UART) B";
midi = &chip->midi2;
midi->tx_enable = INTE_MIDI_TX_B;
@@ -1499,12 +1490,7 @@ static struct pci_driver driver = {
// initialization of the module
static int __init alsa_card_ca0106_init(void)
{
- int err;
-
- if ((err = pci_register_driver(&driver)) > 0)
- return err;
-
- return 0;
+ return pci_register_driver(&driver);
}
// clean up the module
diff --git a/sound/pci/ca0106/ca0106_mixer.c b/sound/pci/ca0106/ca0106_mixer.c
index c10e4a54301b..0730dc7c66e5 100644
--- a/sound/pci/ca0106/ca0106_mixer.c
+++ b/sound/pci/ca0106/ca0106_mixer.c
@@ -125,18 +125,11 @@ static int snd_ca0106_shared_spdif_put(snd_kcontrol_t * kcontrol,
return change;
}
-static snd_kcontrol_new_t snd_ca0106_shared_spdif __devinitdata =
-{
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "SPDIF Out",
- .info = snd_ca0106_shared_spdif_info,
- .get = snd_ca0106_shared_spdif_get,
- .put = snd_ca0106_shared_spdif_put
-};
-
static int snd_ca0106_capture_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
{
- static char *texts[6] = { "SPDIF out", "i2s mixer out", "SPDIF in", "i2s in", "AC97 in", "SRC out" };
+ static char *texts[6] = {
+ "SPDIF out", "i2s mixer out", "SPDIF in", "i2s in", "AC97 in", "SRC out"
+ };
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
uinfo->count = 1;
@@ -176,15 +169,6 @@ static int snd_ca0106_capture_source_put(snd_kcontrol_t * kcontrol,
return change;
}
-static snd_kcontrol_new_t snd_ca0106_capture_source __devinitdata =
-{
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "Capture Source",
- .info = snd_ca0106_capture_source_info,
- .get = snd_ca0106_capture_source_get,
- .put = snd_ca0106_capture_source_put
-};
-
static int snd_ca0106_capture_mic_line_in_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
{
static char *texts[2] = { "Line in", "Mic in" };
@@ -294,26 +278,6 @@ static int snd_ca0106_spdif_put(snd_kcontrol_t * kcontrol,
return change;
}
-static snd_kcontrol_new_t snd_ca0106_spdif_mask_control =
-{
- .access = SNDRV_CTL_ELEM_ACCESS_READ,
- .iface = SNDRV_CTL_ELEM_IFACE_PCM,
- .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
- .count = 4,
- .info = snd_ca0106_spdif_info,
- .get = snd_ca0106_spdif_get_mask
-};
-
-static snd_kcontrol_new_t snd_ca0106_spdif_control =
-{
- .iface = SNDRV_CTL_ELEM_IFACE_PCM,
- .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
- .count = 4,
- .info = snd_ca0106_spdif_info,
- .get = snd_ca0106_spdif_get,
- .put = snd_ca0106_spdif_put
-};
-
static int snd_ca0106_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
@@ -324,10 +288,14 @@ static int snd_ca0106_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t
}
static int snd_ca0106_volume_get(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol, int reg, int channel_id)
+ snd_ctl_elem_value_t * ucontrol)
{
ca0106_t *emu = snd_kcontrol_chip(kcontrol);
unsigned int value;
+ int channel_id, reg;
+
+ channel_id = (kcontrol->private_value >> 8) & 0xff;
+ reg = kcontrol->private_value & 0xff;
value = snd_ca0106_ptr_read(emu, reg, channel_id);
ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */
@@ -335,226 +303,92 @@ static int snd_ca0106_volume_get(snd_kcontrol_t * kcontrol,
return 0;
}
-static int snd_ca0106_volume_get_spdif_front(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_FRONT_CHANNEL;
- int reg = PLAYBACK_VOLUME1;
- return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
-}
-
-static int snd_ca0106_volume_get_spdif_center_lfe(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_CENTER_LFE_CHANNEL;
- int reg = PLAYBACK_VOLUME1;
- return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
-}
-static int snd_ca0106_volume_get_spdif_unknown(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_UNKNOWN_CHANNEL;
- int reg = PLAYBACK_VOLUME1;
- return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
-}
-static int snd_ca0106_volume_get_spdif_rear(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_REAR_CHANNEL;
- int reg = PLAYBACK_VOLUME1;
- return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
-}
-static int snd_ca0106_volume_get_analog_front(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_FRONT_CHANNEL;
- int reg = PLAYBACK_VOLUME2;
- return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
-}
-
-static int snd_ca0106_volume_get_analog_center_lfe(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_CENTER_LFE_CHANNEL;
- int reg = PLAYBACK_VOLUME2;
- return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
-}
-static int snd_ca0106_volume_get_analog_unknown(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_UNKNOWN_CHANNEL;
- int reg = PLAYBACK_VOLUME2;
- return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
-}
-static int snd_ca0106_volume_get_analog_rear(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_REAR_CHANNEL;
- int reg = PLAYBACK_VOLUME2;
- return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
-}
-
-static int snd_ca0106_volume_get_feedback(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = 1;
- int reg = CAPTURE_CONTROL;
- return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
-}
-
static int snd_ca0106_volume_put(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol, int reg, int channel_id)
+ snd_ctl_elem_value_t * ucontrol)
{
ca0106_t *emu = snd_kcontrol_chip(kcontrol);
- unsigned int value;
- //value = snd_ca0106_ptr_read(emu, reg, channel_id);
- //value = value & 0xffff;
- value = ((0xff - ucontrol->value.integer.value[0]) << 24) | ((0xff - ucontrol->value.integer.value[1]) << 16);
- value = value | ((0xff - ucontrol->value.integer.value[0]) << 8) | ((0xff - ucontrol->value.integer.value[1]) );
- snd_ca0106_ptr_write(emu, reg, channel_id, value);
- return 1;
-}
-static int snd_ca0106_volume_put_spdif_front(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_FRONT_CHANNEL;
- int reg = PLAYBACK_VOLUME1;
- return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
-}
-static int snd_ca0106_volume_put_spdif_center_lfe(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_CENTER_LFE_CHANNEL;
- int reg = PLAYBACK_VOLUME1;
- return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
-}
-static int snd_ca0106_volume_put_spdif_unknown(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_UNKNOWN_CHANNEL;
- int reg = PLAYBACK_VOLUME1;
- return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
-}
-static int snd_ca0106_volume_put_spdif_rear(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_REAR_CHANNEL;
- int reg = PLAYBACK_VOLUME1;
- return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
-}
-static int snd_ca0106_volume_put_analog_front(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_FRONT_CHANNEL;
- int reg = PLAYBACK_VOLUME2;
- return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
-}
-static int snd_ca0106_volume_put_analog_center_lfe(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_CENTER_LFE_CHANNEL;
- int reg = PLAYBACK_VOLUME2;
- return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
-}
-static int snd_ca0106_volume_put_analog_unknown(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_UNKNOWN_CHANNEL;
- int reg = PLAYBACK_VOLUME2;
- return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
-}
-static int snd_ca0106_volume_put_analog_rear(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = CONTROL_REAR_CHANNEL;
- int reg = PLAYBACK_VOLUME2;
- return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
-}
-
-static int snd_ca0106_volume_put_feedback(snd_kcontrol_t * kcontrol,
- snd_ctl_elem_value_t * ucontrol)
-{
- int channel_id = 1;
- int reg = CAPTURE_CONTROL;
- return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
-}
-
-static snd_kcontrol_new_t snd_ca0106_volume_control_analog_front =
-{
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "Analog Front Playback Volume",
- .info = snd_ca0106_volume_info,
- .get = snd_ca0106_volume_get_analog_front,
- .put = snd_ca0106_volume_put_analog_front
-};
-static snd_kcontrol_new_t snd_ca0106_volume_control_analog_center_lfe =
-{
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "Analog Center/LFE Playback Volume",
- .info = snd_ca0106_volume_info,
- .get = snd_ca0106_volume_get_analog_center_lfe,
- .put = snd_ca0106_volume_put_analog_center_lfe
-};
-static snd_kcontrol_new_t snd_ca0106_volume_control_analog_unknown =
-{
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "Analog Side Playback Volume",
- .info = snd_ca0106_volume_info,
- .get = snd_ca0106_volume_get_analog_unknown,
- .put = snd_ca0106_volume_put_analog_unknown
-};
-static snd_kcontrol_new_t snd_ca0106_volume_control_analog_rear =
-{
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "Analog Rear Playback Volume",
- .info = snd_ca0106_volume_info,
- .get = snd_ca0106_volume_get_analog_rear,
- .put = snd_ca0106_volume_put_analog_rear
-};
-static snd_kcontrol_new_t snd_ca0106_volume_control_spdif_front =
-{
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "SPDIF Front Playback Volume",
- .info = snd_ca0106_volume_info,
- .get = snd_ca0106_volume_get_spdif_front,
- .put = snd_ca0106_volume_put_spdif_front
-};
-static snd_kcontrol_new_t snd_ca0106_volume_control_spdif_center_lfe =
-{
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "SPDIF Center/LFE Playback Volume",
- .info = snd_ca0106_volume_info,
- .get = snd_ca0106_volume_get_spdif_center_lfe,
- .put = snd_ca0106_volume_put_spdif_center_lfe
-};
-static snd_kcontrol_new_t snd_ca0106_volume_control_spdif_unknown =
-{
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "SPDIF Unknown Playback Volume",
- .info = snd_ca0106_volume_info,
- .get = snd_ca0106_volume_get_spdif_unknown,
- .put = snd_ca0106_volume_put_spdif_unknown
-};
-static snd_kcontrol_new_t snd_ca0106_volume_control_spdif_rear =
-{
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "SPDIF Rear Playback Volume",
- .info = snd_ca0106_volume_info,
- .get = snd_ca0106_volume_get_spdif_rear,
- .put = snd_ca0106_volume_put_spdif_rear
-};
-
-static snd_kcontrol_new_t snd_ca0106_volume_control_feedback =
-{
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "CAPTURE feedback Playback Volume",
- .info = snd_ca0106_volume_info,
- .get = snd_ca0106_volume_get_feedback,
- .put = snd_ca0106_volume_put_feedback
+ unsigned int oval, nval;
+ int channel_id, reg;
+
+ channel_id = (kcontrol->private_value >> 8) & 0xff;
+ reg = kcontrol->private_value & 0xff;
+
+ oval = snd_ca0106_ptr_read(emu, reg, channel_id);
+ nval = ((0xff - ucontrol->value.integer.value[0]) << 24) |
+ ((0xff - ucontrol->value.integer.value[1]) << 16);
+ nval |= ((0xff - ucontrol->value.integer.value[0]) << 8) |
+ ((0xff - ucontrol->value.integer.value[1]) );
+ if (oval == nval)
+ return 0;
+ snd_ca0106_ptr_write(emu, reg, channel_id, nval);
+ return 1;
+}
+
+#define CA_VOLUME(xname,chid,reg) \
+{ \
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
+ .info = snd_ca0106_volume_info, \
+ .get = snd_ca0106_volume_get, \
+ .put = snd_ca0106_volume_put, \
+ .private_value = ((chid) << 8) | (reg) \
+}
+
+
+static snd_kcontrol_new_t snd_ca0106_volume_ctls[] __devinitdata = {
+ CA_VOLUME("Analog Front Playback Volume",
+ CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2),
+ CA_VOLUME("Analog Rear Playback Volume",
+ CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2),
+ CA_VOLUME("Analog Center/LFE Playback Volume",
+ CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2),
+ CA_VOLUME("Analog Side Playback Volume",
+ CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2),
+
+ CA_VOLUME("SPDIF Front Playback Volume",
+ CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1),
+ CA_VOLUME("SPDIF Rear Playback Volume",
+ CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1),
+ CA_VOLUME("SPDIF Center/LFE Playback Volume",
+ CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1),
+ CA_VOLUME("SPDIF Unknown Playback Volume",
+ CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1),
+
+ CA_VOLUME("CAPTURE feedback Playback Volume",
+ 1, CAPTURE_CONTROL),
+
+ {
+ .access = SNDRV_CTL_ELEM_ACCESS_READ,
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
+ .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
+ .count = 4,
+ .info = snd_ca0106_spdif_info,
+ .get = snd_ca0106_spdif_get_mask
+ },
+ {
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "SPDIF Out",
+ .info = snd_ca0106_shared_spdif_info,
+ .get = snd_ca0106_shared_spdif_get,
+ .put = snd_ca0106_shared_spdif_put
+ },
+ {
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "Capture Source",
+ .info = snd_ca0106_capture_source_info,
+ .get = snd_ca0106_capture_source_get,
+ .put = snd_ca0106_capture_source_put
+ },
+ {
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
+ .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
+ .count = 4,
+ .info = snd_ca0106_spdif_info,
+ .get = snd_ca0106_spdif_get,
+ .put = snd_ca0106_spdif_put
+ },
};
-
-static int remove_ctl(snd_card_t *card, const char *name)
+static int __devinit remove_ctl(snd_card_t *card, const char *name)
{
snd_ctl_elem_id_t id;
memset(&id, 0, sizeof(id));
@@ -563,7 +397,7 @@ static int remove_ctl(snd_card_t *card, const char *name)
return snd_ctl_remove_id(card, &id);
}
-static snd_kcontrol_t *ctl_find(snd_card_t *card, const char *name)
+static snd_kcontrol_t __devinit *ctl_find(snd_card_t *card, const char *name)
{
snd_ctl_elem_id_t sid;
memset(&sid, 0, sizeof(sid));
@@ -573,7 +407,7 @@ static snd_kcontrol_t *ctl_find(snd_card_t *card, const char *name)
return snd_ctl_find_id(card, &sid);
}
-static int rename_ctl(snd_card_t *card, const char *src, const char *dst)
+static int __devinit rename_ctl(snd_card_t *card, const char *src, const char *dst)
{
snd_kcontrol_t *kctl = ctl_find(card, src);
if (kctl) {
@@ -585,8 +419,7 @@ static int rename_ctl(snd_card_t *card, const char *src, const char *dst)
int __devinit snd_ca0106_mixer(ca0106_t *emu)
{
- int err;
- snd_kcontrol_t *kctl;
+ int i, err;
snd_card_t *card = emu->card;
char **c;
static char *ca0106_remove_ctls[] = {
@@ -627,70 +460,22 @@ int __devinit snd_ca0106_mixer(ca0106_t *emu)
NULL
};
#if 1
- for (c=ca0106_remove_ctls; *c; c++)
+ for (c = ca0106_remove_ctls; *c; c++)
remove_ctl(card, *c);
- for (c=ca0106_rename_ctls; *c; c += 2)
+ for (c = ca0106_rename_ctls; *c; c += 2)
rename_ctl(card, c[0], c[1]);
#endif
- if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_analog_front, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
- return err;
- if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_analog_rear, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
- return err;
- if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_analog_center_lfe, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
- return err;
- if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_analog_unknown, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
- return err;
- if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_spdif_front, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
- return err;
- if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_spdif_rear, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
- return err;
- if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_spdif_center_lfe, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
- return err;
- if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_spdif_unknown, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
- return err;
- if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_feedback, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
- return err;
- if ((kctl = snd_ctl_new1(&snd_ca0106_spdif_mask_control, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
- return err;
- if ((kctl = snd_ctl_new1(&snd_ca0106_shared_spdif, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
- return err;
- if ((kctl = snd_ctl_new1(&snd_ca0106_capture_source, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
- return err;
+ for (i = 0; i < ARRAY_SIZE(snd_ca0106_volume_ctls); i++) {
+ err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_volume_ctls[i], emu));
+ if (err < 0)
+ return err;
+ }
if (emu->details->i2c_adc == 1) {
- if ((kctl = snd_ctl_new1(&snd_ca0106_capture_mic_line_in, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
+ err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_mic_line_in, emu));
+ if (err < 0)
return err;
}
- if ((kctl = snd_ctl_new1(&snd_ca0106_spdif_control, emu)) == NULL)
- return -ENOMEM;
- if ((err = snd_ctl_add(card, kctl)))
- return err;
return 0;
}