#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/io.h>
-#include <sound/driver.h>
#include <sound/initval.h>
#include <sound/control.h>
#include <sound/core.h>
u8 spi_rbuffer[2];
/* Image of the SPI registers in AT73C213. */
u8 reg_image[18];
- /* Protect registers against concurrent access. */
+ /* Protect SSC registers against concurrent access. */
spinlock_t lock;
+ /* Protect mixer registers against concurrent access. */
+ struct mutex mixer_lock;
};
#define get_chip(card) ((struct snd_at73c213 *)card->private_data)
static int snd_at73c213_set_bitrate(struct snd_at73c213 *chip)
{
unsigned long ssc_rate = clk_get_rate(chip->ssc->clk);
- unsigned long dac_rate_new, ssc_div, status;
+ unsigned long dac_rate_new, ssc_div;
+ int status;
unsigned long ssc_div_max, ssc_div_min;
int max_tries;
int mask = (kcontrol->private_value >> 16) & 0xff;
int invert = (kcontrol->private_value >> 24) & 0xff;
- spin_lock_irq(&chip->lock);
+ mutex_lock(&chip->mixer_lock);
ucontrol->value.integer.value[0] =
(chip->reg_image[reg] >> shift) & mask;
ucontrol->value.integer.value[0] =
mask - ucontrol->value.integer.value[0];
- spin_unlock_irq(&chip->lock);
+ mutex_unlock(&chip->mixer_lock);
return 0;
}
val = mask - val;
val <<= shift;
- spin_lock_irq(&chip->lock);
+ mutex_lock(&chip->mixer_lock);
val = (chip->reg_image[reg] & ~(mask << shift)) | val;
change = val != chip->reg_image[reg];
retval = snd_at73c213_write_reg(chip, reg, val);
- spin_unlock_irq(&chip->lock);
+ mutex_unlock(&chip->mixer_lock);
if (retval)
return retval;
int mask = (kcontrol->private_value >> 24) & 0xff;
int invert = (kcontrol->private_value >> 22) & 1;
- spin_lock_irq(&chip->lock);
+ mutex_lock(&chip->mixer_lock);
ucontrol->value.integer.value[0] =
(chip->reg_image[left_reg] >> shift_left) & mask;
mask - ucontrol->value.integer.value[1];
}
- spin_unlock_irq(&chip->lock);
+ mutex_unlock(&chip->mixer_lock);
return 0;
}
val1 <<= shift_left;
val2 <<= shift_right;
- spin_lock_irq(&chip->lock);
+ mutex_lock(&chip->mixer_lock);
val1 = (chip->reg_image[left_reg] & ~(mask << shift_left)) | val1;
val2 = (chip->reg_image[right_reg] & ~(mask << shift_right)) | val2;
|| val2 != chip->reg_image[right_reg];
retval = snd_at73c213_write_reg(chip, left_reg, val1);
if (retval) {
- spin_unlock_irq(&chip->lock);
+ mutex_unlock(&chip->mixer_lock);
goto out;
}
retval = snd_at73c213_write_reg(chip, right_reg, val2);
if (retval) {
- spin_unlock_irq(&chip->lock);
+ mutex_unlock(&chip->mixer_lock);
goto out;
}
- spin_unlock_irq(&chip->lock);
+ mutex_unlock(&chip->mixer_lock);
return change;
return retval;
}
-static int snd_at73c213_mono_switch_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
-{
- uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
- uinfo->count = 1;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 1;
-
- return 0;
-}
+#define snd_at73c213_mono_switch_info snd_ctl_boolean_mono_info
static int snd_at73c213_mono_switch_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
int shift = (kcontrol->private_value >> 8) & 0xff;
int invert = (kcontrol->private_value >> 24) & 0xff;
- spin_lock_irq(&chip->lock);
+ mutex_lock(&chip->mixer_lock);
ucontrol->value.integer.value[0] =
(chip->reg_image[reg] >> shift) & 0x01;
ucontrol->value.integer.value[0] =
0x01 - ucontrol->value.integer.value[0];
- spin_unlock_irq(&chip->lock);
+ mutex_unlock(&chip->mixer_lock);
return 0;
}
val = mask - val;
val <<= shift;
- spin_lock_irq(&chip->lock);
+ mutex_lock(&chip->mixer_lock);
val |= (chip->reg_image[reg] & ~(mask << shift));
change = val != chip->reg_image[reg];
retval = snd_at73c213_write_reg(chip, reg, val);
- spin_unlock_irq(&chip->lock);
+ mutex_unlock(&chip->mixer_lock);
if (retval)
return retval;
/*
* Device functions
*/
-static int snd_at73c213_ssc_init(struct snd_at73c213 *chip)
+static int __devinit snd_at73c213_ssc_init(struct snd_at73c213 *chip)
{
/*
* Continuous clock output.
return 0;
}
-static int snd_at73c213_chip_init(struct snd_at73c213 *chip)
+static int __devinit snd_at73c213_chip_init(struct snd_at73c213 *chip)
{
int retval;
unsigned char dac_ctrl = 0;
return irq;
spin_lock_init(&chip->lock);
+ mutex_init(&chip->mixer_lock);
chip->card = card;
chip->irq = -1;
return retval;
}
-static int snd_at73c213_probe(struct spi_device *spi)
+static int __devinit snd_at73c213_probe(struct spi_device *spi)
{
struct snd_card *card;
struct snd_at73c213 *chip;