Commit 6c041b5e authored by Krzysztof Helt's avatar Krzysztof Helt Committed by Jaroslav Kysela

[ALSA] cs4231-lib: replace common delay loop by function

This patch replaces a common delay loop by a function.
It also uses ARRAY_SIZE macro for the rates table.
Acked-by: default avatarRene Herman <rene.herman@gmail.com>
Signed-off-by: default avatarKrzysztof Helt <krzysztof.h1@wp.pl>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarJaroslav Kysela <perex@suse.cz>
parent 8e6a2c2e
...@@ -74,7 +74,7 @@ static unsigned int rates[14] = { ...@@ -74,7 +74,7 @@ static unsigned int rates[14] = {
}; };
static struct snd_pcm_hw_constraint_list hw_constraints_rates = { static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
.count = 14, .count = ARRAY_SIZE(rates),
.list = rates, .list = rates,
.mask = 0, .mask = 0,
}; };
...@@ -134,29 +134,31 @@ static inline u8 cs4231_inb(struct snd_cs4231 *chip, u8 offset) ...@@ -134,29 +134,31 @@ static inline u8 cs4231_inb(struct snd_cs4231 *chip, u8 offset)
return inb(chip->port + offset); return inb(chip->port + offset);
} }
static void snd_cs4231_outm(struct snd_cs4231 *chip, unsigned char reg, static void snd_cs4231_wait(struct snd_cs4231 *chip)
unsigned char mask, unsigned char value)
{ {
int timeout; int timeout;
unsigned char tmp;
for (timeout = 250; for (timeout = 250;
timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT); timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
timeout--) timeout--)
udelay(100); udelay(100);
}
static void snd_cs4231_outm(struct snd_cs4231 *chip, unsigned char reg,
unsigned char mask, unsigned char value)
{
unsigned char tmp = (chip->image[reg] & mask) | value;
snd_cs4231_wait(chip);
#ifdef CONFIG_SND_DEBUG #ifdef CONFIG_SND_DEBUG
if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value); snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
#endif #endif
if (chip->calibrate_mute) { chip->image[reg] = tmp;
chip->image[reg] &= mask; if (!chip->calibrate_mute) {
chip->image[reg] |= value;
} else {
cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg); cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
mb(); wmb();
tmp = (chip->image[reg] & mask) | value;
cs4231_outb(chip, CS4231P(REG), tmp); cs4231_outb(chip, CS4231P(REG), tmp);
chip->image[reg] = tmp;
mb(); mb();
} }
} }
...@@ -176,12 +178,7 @@ static void snd_cs4231_dout(struct snd_cs4231 *chip, unsigned char reg, unsigned ...@@ -176,12 +178,7 @@ static void snd_cs4231_dout(struct snd_cs4231 *chip, unsigned char reg, unsigned
void snd_cs4231_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char value) void snd_cs4231_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char value)
{ {
int timeout; snd_cs4231_wait(chip);
for (timeout = 250;
timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
timeout--)
udelay(100);
#ifdef CONFIG_SND_DEBUG #ifdef CONFIG_SND_DEBUG
if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
snd_printk("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value); snd_printk("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
...@@ -190,19 +187,13 @@ void snd_cs4231_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char va ...@@ -190,19 +187,13 @@ void snd_cs4231_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char va
cs4231_outb(chip, CS4231P(REG), value); cs4231_outb(chip, CS4231P(REG), value);
chip->image[reg] = value; chip->image[reg] = value;
mb(); mb();
#if 0 snd_printdd("codec out - reg 0x%x = 0x%x\n",
printk("codec out - reg 0x%x = 0x%x\n", chip->mce_bit | reg, value); chip->mce_bit | reg, value);
#endif
} }
unsigned char snd_cs4231_in(struct snd_cs4231 *chip, unsigned char reg) unsigned char snd_cs4231_in(struct snd_cs4231 *chip, unsigned char reg)
{ {
int timeout; snd_cs4231_wait(chip);
for (timeout = 250;
timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
timeout--)
udelay(100);
#ifdef CONFIG_SND_DEBUG #ifdef CONFIG_SND_DEBUG
if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
snd_printk("in: auto calibration time out - reg = 0x%x\n", reg); snd_printk("in: auto calibration time out - reg = 0x%x\n", reg);
...@@ -304,8 +295,7 @@ void snd_cs4231_mce_up(struct snd_cs4231 *chip) ...@@ -304,8 +295,7 @@ void snd_cs4231_mce_up(struct snd_cs4231 *chip)
unsigned long flags; unsigned long flags;
int timeout; int timeout;
for (timeout = 250; timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT); timeout--) snd_cs4231_wait(chip);
udelay(100);
#ifdef CONFIG_SND_DEBUG #ifdef CONFIG_SND_DEBUG
if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
snd_printk("mce_up - auto calibration time out (0)\n"); snd_printk("mce_up - auto calibration time out (0)\n");
...@@ -459,11 +449,11 @@ static unsigned char snd_cs4231_get_rate(unsigned int rate) ...@@ -459,11 +449,11 @@ static unsigned char snd_cs4231_get_rate(unsigned int rate)
{ {
int i; int i;
for (i = 0; i < 14; i++) for (i = 0; i < ARRAY_SIZE(rates); i++)
if (rate == rates[i]) if (rate == rates[i])
return freq_bits[i]; return freq_bits[i];
// snd_BUG(); // snd_BUG();
return freq_bits[13]; return freq_bits[ARRAY_SIZE(rates) - 1];
} }
static unsigned char snd_cs4231_get_format(struct snd_cs4231 *chip, static unsigned char snd_cs4231_get_format(struct snd_cs4231 *chip,
......
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