Commit 95a98265 authored by Takashi Iwai's avatar Takashi Iwai Committed by Jaroslav Kysela

[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: default avatarTakashi Iwai <tiwai@suse.de>
parent 954bea35
...@@ -207,7 +207,8 @@ static snd_pcm_hardware_t snd_ca0106_playback_hw = { ...@@ -207,7 +207,8 @@ static snd_pcm_hardware_t snd_ca0106_playback_hw = {
SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_MMAP_VALID), SNDRV_PCM_INFO_MMAP_VALID),
.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, .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_min = 48000,
.rate_max = 192000, .rate_max = 192000,
.channels_min = 2, //1, .channels_min = 2, //1,
...@@ -226,7 +227,8 @@ static snd_pcm_hardware_t snd_ca0106_capture_hw = { ...@@ -226,7 +227,8 @@ static snd_pcm_hardware_t snd_ca0106_capture_hw = {
SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_MMAP_VALID), SNDRV_PCM_INFO_MMAP_VALID),
.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, .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_min = 44100,
.rate_max = 192000, .rate_max = 192000,
.channels_min = 2, .channels_min = 2,
...@@ -276,11 +278,10 @@ int snd_ca0106_i2c_write(ca0106_t *emu, ...@@ -276,11 +278,10 @@ int snd_ca0106_i2c_write(ca0106_t *emu,
u32 value) u32 value)
{ {
u32 tmp; u32 tmp;
int timeout=0; int timeout = 0;
int status; int status;
int retry; int retry;
if ((reg > 0x7f) || (value > 0x1ff)) if ((reg > 0x7f) || (value > 0x1ff)) {
{
snd_printk(KERN_ERR "i2c_write: invalid values.\n"); snd_printk(KERN_ERR "i2c_write: invalid values.\n");
return -EINVAL; return -EINVAL;
} }
...@@ -292,8 +293,7 @@ int snd_ca0106_i2c_write(ca0106_t *emu, ...@@ -292,8 +293,7 @@ int snd_ca0106_i2c_write(ca0106_t *emu,
/* This controls the I2C connected to the WM8775 ADC Codec */ /* This controls the I2C connected to the WM8775 ADC Codec */
snd_ca0106_ptr_write(emu, I2C_D1, 0, tmp); 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 */ /* Send the data to i2c */
tmp = snd_ca0106_ptr_read(emu, I2C_A, 0); 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); 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, ...@@ -301,24 +301,22 @@ int snd_ca0106_i2c_write(ca0106_t *emu,
snd_ca0106_ptr_write(emu, I2C_A, 0, tmp); snd_ca0106_ptr_write(emu, I2C_A, 0, tmp);
/* Wait till the transaction ends */ /* Wait till the transaction ends */
while(1) while (1) {
{
status = snd_ca0106_ptr_read(emu, I2C_A, 0); status = snd_ca0106_ptr_read(emu, I2C_A, 0);
//snd_printk("I2C:status=0x%x\n", status); //snd_printk("I2C:status=0x%x\n", status);
timeout++; timeout++;
if((status & I2C_A_ADC_START)==0) if ((status & I2C_A_ADC_START) == 0)
break; break;
if(timeout>1000) if (timeout > 1000)
break; break;
} }
//Read back and see if the transaction is successful //Read back and see if the transaction is successful
if((status & I2C_A_ADC_ABORT)==0) if ((status & I2C_A_ADC_ABORT) == 0)
break; break;
} }
if(retry==10) if (retry == 10) {
{
snd_printk(KERN_ERR "Writing to ADC failed!\n"); snd_printk(KERN_ERR "Writing to ADC failed!\n");
return -EINVAL; return -EINVAL;
} }
...@@ -380,10 +378,10 @@ static int snd_ca0106_pcm_open_playback_channel(snd_pcm_substream_t *substream, ...@@ -380,10 +378,10 @@ static int snd_ca0106_pcm_open_playback_channel(snd_pcm_substream_t *substream,
channel->emu = chip; channel->emu = chip;
channel->number = channel_id; channel->number = channel_id;
channel->use=1; channel->use = 1;
//printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel); //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
//channel->interrupt = snd_ca0106_pcm_channel_interrupt; //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) if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
return err; return err;
if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0) 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 ...@@ -448,10 +446,10 @@ static int snd_ca0106_pcm_open_capture_channel(snd_pcm_substream_t *substream, i
channel->emu = chip; channel->emu = chip;
channel->number = channel_id; channel->number = channel_id;
channel->use=1; channel->use = 1;
//printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel); //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
//channel->interrupt = snd_ca0106_pcm_channel_interrupt; //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) if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
return err; return err;
//snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hw_constraints_capture_period_sizes); //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) ...@@ -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. */ /* FIXME: Check emu->buffer.size before actually writing to it. */
for(i=0; i < runtime->periods; i++) { for(i=0; i < runtime->periods; i++) {
table_base[i*2]=runtime->dma_addr+(i*period_size_bytes); table_base[i*2] = runtime->dma_addr + (i * period_size_bytes);
table_base[(i*2)+1]=period_size_bytes<<16; table_base[i*2+1] = period_size_bytes << 16;
} }
snd_ca0106_ptr_write(emu, PLAYBACK_LIST_ADDR, channel, emu->buffer.addr+(8*16*channel)); 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, ...@@ -1008,13 +1006,8 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id,
unsigned int stat76; unsigned int stat76;
ca0106_channel_t *pchannel; ca0106_channel_t *pchannel;
spin_lock(&chip->emu_lock);
status = inl(chip->port + IPR); status = inl(chip->port + IPR);
// call updater, unlock before it
spin_unlock(&chip->emu_lock);
if (! status) if (! status)
return IRQ_NONE; return IRQ_NONE;
...@@ -1024,7 +1017,7 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id, ...@@ -1024,7 +1017,7 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id,
mask = 0x11; /* 0x1 for one half, 0x10 for the other half period. */ mask = 0x11; /* 0x1 for one half, 0x10 for the other half period. */
for(i = 0; i < 4; i++) { for(i = 0; i < 4; i++) {
pchannel = &(chip->playback_channels[i]); pchannel = &(chip->playback_channels[i]);
if(stat76 & mask) { if (stat76 & mask) {
/* FIXME: Select the correct substream for period elapsed */ /* FIXME: Select the correct substream for period elapsed */
if(pchannel->use) { if(pchannel->use) {
snd_pcm_period_elapsed(pchannel->epcm->substream); snd_pcm_period_elapsed(pchannel->epcm->substream);
...@@ -1038,7 +1031,7 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id, ...@@ -1038,7 +1031,7 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id,
mask = 0x110000; /* 0x1 for one half, 0x10 for the other half period. */ mask = 0x110000; /* 0x1 for one half, 0x10 for the other half period. */
for(i = 0; i < 4; i++) { for(i = 0; i < 4; i++) {
pchannel = &(chip->capture_channels[i]); pchannel = &(chip->capture_channels[i]);
if(stat76 & mask) { if (stat76 & mask) {
/* FIXME: Select the correct substream for period elapsed */ /* FIXME: Select the correct substream for period elapsed */
if(pchannel->use) { if(pchannel->use) {
snd_pcm_period_elapsed(pchannel->epcm->substream); snd_pcm_period_elapsed(pchannel->epcm->substream);
...@@ -1051,7 +1044,6 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id, ...@@ -1051,7 +1044,6 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id,
} }
snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76); snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76);
spin_lock(&chip->emu_lock);
if (chip->midi.dev_id && if (chip->midi.dev_id &&
(status & (chip->midi.ipr_tx|chip->midi.ipr_rx))) { (status & (chip->midi.ipr_tx|chip->midi.ipr_rx))) {
...@@ -1064,8 +1056,6 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id, ...@@ -1064,8 +1056,6 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id,
// acknowledge the interrupt if necessary // acknowledge the interrupt if necessary
outl(status, chip->port+IPR); outl(status, chip->port+IPR);
spin_unlock(&chip->emu_lock);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -1202,8 +1192,9 @@ static int __devinit snd_ca0106_create(snd_card_t *card, ...@@ -1202,8 +1192,9 @@ static int __devinit snd_ca0106_create(snd_card_t *card,
strcpy(card->driver, "CA0106"); strcpy(card->driver, "CA0106");
strcpy(card->shortname, "CA0106"); strcpy(card->shortname, "CA0106");
for (c=ca0106_chip_details; c->serial; c++) { for (c = ca0106_chip_details; c->serial; c++) {
if (c->serial == chip->serial) break; if (c->serial == chip->serial)
break;
} }
chip->details = c; chip->details = c;
sprintf(card->longname, "%s at 0x%lx irq %i", 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) ...@@ -1359,7 +1350,7 @@ static int __devinit snd_ca0106_midi(ca0106_t *chip, unsigned int channel)
char *name; char *name;
int err; int err;
if(channel==CA0106_MIDI_CHAN_B) { if (channel == CA0106_MIDI_CHAN_B) {
name = "CA0106 MPU-401 (UART) B"; name = "CA0106 MPU-401 (UART) B";
midi = &chip->midi2; midi = &chip->midi2;
midi->tx_enable = INTE_MIDI_TX_B; midi->tx_enable = INTE_MIDI_TX_B;
...@@ -1499,12 +1490,7 @@ static struct pci_driver driver = { ...@@ -1499,12 +1490,7 @@ static struct pci_driver driver = {
// initialization of the module // initialization of the module
static int __init alsa_card_ca0106_init(void) static int __init alsa_card_ca0106_init(void)
{ {
int err; return pci_register_driver(&driver);
if ((err = pci_register_driver(&driver)) > 0)
return err;
return 0;
} }
// clean up the module // clean up the module
......
...@@ -125,18 +125,11 @@ static int snd_ca0106_shared_spdif_put(snd_kcontrol_t * kcontrol, ...@@ -125,18 +125,11 @@ static int snd_ca0106_shared_spdif_put(snd_kcontrol_t * kcontrol,
return change; 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 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->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
uinfo->count = 1; uinfo->count = 1;
...@@ -176,15 +169,6 @@ static int snd_ca0106_capture_source_put(snd_kcontrol_t * kcontrol, ...@@ -176,15 +169,6 @@ static int snd_ca0106_capture_source_put(snd_kcontrol_t * kcontrol,
return change; 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 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" }; static char *texts[2] = { "Line in", "Mic in" };
...@@ -294,26 +278,6 @@ static int snd_ca0106_spdif_put(snd_kcontrol_t * kcontrol, ...@@ -294,26 +278,6 @@ static int snd_ca0106_spdif_put(snd_kcontrol_t * kcontrol,
return change; 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) static int snd_ca0106_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
{ {
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 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 ...@@ -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, 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); ca0106_t *emu = snd_kcontrol_chip(kcontrol);
unsigned int value; 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); value = snd_ca0106_ptr_read(emu, reg, channel_id);
ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */ ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */
...@@ -335,226 +303,92 @@ static int snd_ca0106_volume_get(snd_kcontrol_t * kcontrol, ...@@ -335,226 +303,92 @@ static int snd_ca0106_volume_get(snd_kcontrol_t * kcontrol,
return 0; return 0;
} }
static int snd_ca0106_volume_get_spdif_front(snd_kcontrol_t * kcontrol, static int snd_ca0106_volume_put(snd_kcontrol_t * kcontrol,
snd_ctl_elem_value_t * ucontrol) snd_ctl_elem_value_t * ucontrol)
{ {
int channel_id = CONTROL_FRONT_CHANNEL; ca0106_t *emu = snd_kcontrol_chip(kcontrol);
int reg = PLAYBACK_VOLUME1; unsigned int oval, nval;
return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id); 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;
} }
static int snd_ca0106_volume_get_spdif_center_lfe(snd_kcontrol_t * kcontrol, #define CA_VOLUME(xname,chid,reg) \
snd_ctl_elem_value_t * ucontrol) { \
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
int channel_id = CONTROL_CENTER_LFE_CHANNEL; .info = snd_ca0106_volume_info, \
int reg = PLAYBACK_VOLUME1; .get = snd_ca0106_volume_get, \
return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id); .put = snd_ca0106_volume_put, \
} .private_value = ((chid) << 8) | (reg) \
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, static snd_kcontrol_new_t snd_ca0106_volume_ctls[] __devinitdata = {
snd_ctl_elem_value_t * ucontrol) CA_VOLUME("Analog Front Playback Volume",
{ CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2),
int channel_id = 1; CA_VOLUME("Analog Rear Playback Volume",
int reg = CAPTURE_CONTROL; CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2),
return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id); CA_VOLUME("Analog Center/LFE Playback Volume",
} CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2),
CA_VOLUME("Analog Side Playback Volume",
CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2),
static int snd_ca0106_volume_put(snd_kcontrol_t * kcontrol, CA_VOLUME("SPDIF Front Playback Volume",
snd_ctl_elem_value_t * ucontrol, int reg, int channel_id) CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1),
{ CA_VOLUME("SPDIF Rear Playback Volume",
ca0106_t *emu = snd_kcontrol_chip(kcontrol); CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1),
unsigned int value; CA_VOLUME("SPDIF Center/LFE Playback Volume",
//value = snd_ca0106_ptr_read(emu, reg, channel_id); CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1),
//value = value & 0xffff; CA_VOLUME("SPDIF Unknown Playback Volume",
value = ((0xff - ucontrol->value.integer.value[0]) << 24) | ((0xff - ucontrol->value.integer.value[1]) << 16); CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1),
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, CA_VOLUME("CAPTURE feedback Playback Volume",
snd_ctl_elem_value_t * ucontrol) 1, CAPTURE_CONTROL),
{
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 = {
{ .access = SNDRV_CTL_ELEM_ACCESS_READ,
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = "Analog Front Playback Volume", .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
.info = snd_ca0106_volume_info, .count = 4,
.get = snd_ca0106_volume_get_analog_front, .info = snd_ca0106_spdif_info,
.put = snd_ca0106_volume_put_analog_front .get = snd_ca0106_spdif_get_mask
}; },
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, .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "SPDIF Rear Playback Volume", .name = "SPDIF Out",
.info = snd_ca0106_volume_info, .info = snd_ca0106_shared_spdif_info,
.get = snd_ca0106_volume_get_spdif_rear, .get = snd_ca0106_shared_spdif_get,
.put = snd_ca0106_volume_put_spdif_rear .put = snd_ca0106_shared_spdif_put
}; },
{
static snd_kcontrol_new_t snd_ca0106_volume_control_feedback =
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "CAPTURE feedback Playback Volume", .name = "Capture Source",
.info = snd_ca0106_volume_info, .info = snd_ca0106_capture_source_info,
.get = snd_ca0106_volume_get_feedback, .get = snd_ca0106_capture_source_get,
.put = snd_ca0106_volume_put_feedback .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 __devinit remove_ctl(snd_card_t *card, const char *name)
static int remove_ctl(snd_card_t *card, const char *name)
{ {
snd_ctl_elem_id_t id; snd_ctl_elem_id_t id;
memset(&id, 0, sizeof(id)); memset(&id, 0, sizeof(id));
...@@ -563,7 +397,7 @@ static int remove_ctl(snd_card_t *card, const char *name) ...@@ -563,7 +397,7 @@ static int remove_ctl(snd_card_t *card, const char *name)
return snd_ctl_remove_id(card, &id); 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; snd_ctl_elem_id_t sid;
memset(&sid, 0, sizeof(sid)); memset(&sid, 0, sizeof(sid));
...@@ -573,7 +407,7 @@ static snd_kcontrol_t *ctl_find(snd_card_t *card, const char *name) ...@@ -573,7 +407,7 @@ static snd_kcontrol_t *ctl_find(snd_card_t *card, const char *name)
return snd_ctl_find_id(card, &sid); 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); snd_kcontrol_t *kctl = ctl_find(card, src);
if (kctl) { if (kctl) {
...@@ -585,8 +419,7 @@ static int rename_ctl(snd_card_t *card, const char *src, const char *dst) ...@@ -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 __devinit snd_ca0106_mixer(ca0106_t *emu)
{ {
int err; int i, err;
snd_kcontrol_t *kctl;
snd_card_t *card = emu->card; snd_card_t *card = emu->card;
char **c; char **c;
static char *ca0106_remove_ctls[] = { static char *ca0106_remove_ctls[] = {
...@@ -627,70 +460,22 @@ int __devinit snd_ca0106_mixer(ca0106_t *emu) ...@@ -627,70 +460,22 @@ int __devinit snd_ca0106_mixer(ca0106_t *emu)
NULL NULL
}; };
#if 1 #if 1
for (c=ca0106_remove_ctls; *c; c++) for (c = ca0106_remove_ctls; *c; c++)
remove_ctl(card, *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]); rename_ctl(card, c[0], c[1]);
#endif #endif
if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_analog_front, emu)) == NULL) for (i = 0; i < ARRAY_SIZE(snd_ca0106_volume_ctls); i++) {
return -ENOMEM; err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_volume_ctls[i], emu));
if ((err = snd_ctl_add(card, kctl))) if (err < 0)
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; return err;
}
if (emu->details->i2c_adc == 1) { if (emu->details->i2c_adc == 1) {
if ((kctl = snd_ctl_new1(&snd_ca0106_capture_mic_line_in, emu)) == NULL) err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_mic_line_in, emu));
return -ENOMEM; if (err < 0)
if ((err = snd_ctl_add(card, kctl)))
return err; 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; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment