aboutsummaryrefslogtreecommitdiffstats
path: root/sound/isa/cs423x/cs4231_lib.c
diff options
context:
space:
mode:
authorKrzysztof Helt <krzysztof.h1@wp.pl>2007-09-06 09:03:59 -0400
committerJaroslav Kysela <perex@perex.cz>2007-10-16 10:49:10 -0400
commit6c041b5eae5a3e5c950c1d99f59d907c680922d2 (patch)
treeefcea2e397a3c2807f15042d9227d61d46335074 /sound/isa/cs423x/cs4231_lib.c
parent8e6a2c2ec9e7c99128425e6b73bea8437efd3a93 (diff)
[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: Rene Herman <rene.herman@gmail.com> Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
Diffstat (limited to 'sound/isa/cs423x/cs4231_lib.c')
-rw-r--r--sound/isa/cs423x/cs4231_lib.c50
1 files changed, 20 insertions, 30 deletions
diff --git a/sound/isa/cs423x/cs4231_lib.c b/sound/isa/cs423x/cs4231_lib.c
index 642bdaa703be..db9bba130b28 100644
--- a/sound/isa/cs423x/cs4231_lib.c
+++ b/sound/isa/cs423x/cs4231_lib.c
@@ -74,7 +74,7 @@ static unsigned int rates[14] = {
74}; 74};
75 75
76static struct snd_pcm_hw_constraint_list hw_constraints_rates = { 76static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
77 .count = 14, 77 .count = ARRAY_SIZE(rates),
78 .list = rates, 78 .list = rates,
79 .mask = 0, 79 .mask = 0,
80}; 80};
@@ -134,29 +134,31 @@ static inline u8 cs4231_inb(struct snd_cs4231 *chip, u8 offset)
134 return inb(chip->port + offset); 134 return inb(chip->port + offset);
135} 135}
136 136
137static void snd_cs4231_outm(struct snd_cs4231 *chip, unsigned char reg, 137static void snd_cs4231_wait(struct snd_cs4231 *chip)
138 unsigned char mask, unsigned char value)
139{ 138{
140 int timeout; 139 int timeout;
141 unsigned char tmp;
142 140
143 for (timeout = 250; 141 for (timeout = 250;
144 timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT); 142 timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
145 timeout--) 143 timeout--)
146 udelay(100); 144 udelay(100);
145}
146
147static void snd_cs4231_outm(struct snd_cs4231 *chip, unsigned char reg,
148 unsigned char mask, unsigned char value)
149{
150 unsigned char tmp = (chip->image[reg] & mask) | value;
151
152 snd_cs4231_wait(chip);
147#ifdef CONFIG_SND_DEBUG 153#ifdef CONFIG_SND_DEBUG
148 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) 154 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
149 snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value); 155 snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
150#endif 156#endif
151 if (chip->calibrate_mute) { 157 chip->image[reg] = tmp;
152 chip->image[reg] &= mask; 158 if (!chip->calibrate_mute) {
153 chip->image[reg] |= value;
154 } else {
155 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg); 159 cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
156 mb(); 160 wmb();
157 tmp = (chip->image[reg] & mask) | value;
158 cs4231_outb(chip, CS4231P(REG), tmp); 161 cs4231_outb(chip, CS4231P(REG), tmp);
159 chip->image[reg] = tmp;
160 mb(); 162 mb();
161 } 163 }
162} 164}
@@ -176,12 +178,7 @@ static void snd_cs4231_dout(struct snd_cs4231 *chip, unsigned char reg, unsigned
176 178
177void snd_cs4231_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char value) 179void snd_cs4231_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char value)
178{ 180{
179 int timeout; 181 snd_cs4231_wait(chip);
180
181 for (timeout = 250;
182 timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
183 timeout--)
184 udelay(100);
185#ifdef CONFIG_SND_DEBUG 182#ifdef CONFIG_SND_DEBUG
186 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) 183 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
187 snd_printk("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value); 184 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 cs4231_outb(chip, CS4231P(REG), value); 187 cs4231_outb(chip, CS4231P(REG), value);
191 chip->image[reg] = value; 188 chip->image[reg] = value;
192 mb(); 189 mb();
193#if 0 190 snd_printdd("codec out - reg 0x%x = 0x%x\n",
194 printk("codec out - reg 0x%x = 0x%x\n", chip->mce_bit | reg, value); 191 chip->mce_bit | reg, value);
195#endif
196} 192}
197 193
198unsigned char snd_cs4231_in(struct snd_cs4231 *chip, unsigned char reg) 194unsigned char snd_cs4231_in(struct snd_cs4231 *chip, unsigned char reg)
199{ 195{
200 int timeout; 196 snd_cs4231_wait(chip);
201
202 for (timeout = 250;
203 timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
204 timeout--)
205 udelay(100);
206#ifdef CONFIG_SND_DEBUG 197#ifdef CONFIG_SND_DEBUG
207 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) 198 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
208 snd_printk("in: auto calibration time out - reg = 0x%x\n", reg); 199 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 unsigned long flags; 295 unsigned long flags;
305 int timeout; 296 int timeout;
306 297
307 for (timeout = 250; timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT); timeout--) 298 snd_cs4231_wait(chip);
308 udelay(100);
309#ifdef CONFIG_SND_DEBUG 299#ifdef CONFIG_SND_DEBUG
310 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) 300 if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
311 snd_printk("mce_up - auto calibration time out (0)\n"); 301 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{ 449{
460 int i; 450 int i;
461 451
462 for (i = 0; i < 14; i++) 452 for (i = 0; i < ARRAY_SIZE(rates); i++)
463 if (rate == rates[i]) 453 if (rate == rates[i])
464 return freq_bits[i]; 454 return freq_bits[i];
465 // snd_BUG(); 455 // snd_BUG();
466 return freq_bits[13]; 456 return freq_bits[ARRAY_SIZE(rates) - 1];
467} 457}
468 458
469static unsigned char snd_cs4231_get_format(struct snd_cs4231 *chip, 459static unsigned char snd_cs4231_get_format(struct snd_cs4231 *chip,