* Re: [PATCH] cs4231-lib: replace common delay loop by function
[not found] <20070904184927.0bb3bc7c.krzysztof.h1@wp.pl>
@ 2007-09-04 22:37 ` Rene Herman
0 siblings, 0 replies; 3+ messages in thread
From: Rene Herman @ 2007-09-04 22:37 UTC (permalink / raw)
To: Krzysztof Helt; +Cc: Alsa-devel
On 09/04/2007 06:49 PM, Krzysztof Helt wrote:
> +static void snd_cs4231_ready(struct snd_cs4231 *chip)
> {
> int timeout;
> - unsigned char tmp;
>
> for (timeout = 250;
> timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
> timeout--)
> udelay(100);
> +}
> +
Would you terribly mind calling this snd_cs4231_wait() or something close?
> +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_ready(chip);
> #ifdef CONFIG_SND_DEBUG
> if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
> snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
> #endif
> - if (chip->calibrate_mute) {
> - chip->image[reg] &= mask;
> - chip->image[reg] |= value;
> - } else {
> + if (!chip->calibrate_mute) {
> cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
> - mb();
> - tmp = (chip->image[reg] & mask) | value;
> + wmb();
> cs4231_outb(chip, CS4231P(REG), tmp);
> - chip->image[reg] = tmp;
> mb();
> }
> + chip->image[reg] = tmp;
> }
Mmm, for the ! case, the chip->image[reg] = tmp is now after the mb() -- but
that's okay right?
Rene
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] cs4231-lib: replace common delay loop by function
@ 2007-09-05 17:09 Krzysztof Helt
2007-09-05 19:11 ` Rene Herman
0 siblings, 1 reply; 3+ messages in thread
From: Krzysztof Helt @ 2007-09-05 17:09 UTC (permalink / raw)
To: Alsa-devel
From: Krzysztof Helt <krzysztof.h1@wp.pl>
This patch replaces a common delay loop by a function.
It also uses ARRAY_SIZE macro for the rates table.
Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl>
---
diff -urp linux-2.6.23.orig/sound/isa/cs423x/cs4231_lib.c linux-2.6.23/sound/isa/cs423x/cs4231_lib.c
--- linux-2.6.23.orig/sound/isa/cs423x/cs4231_lib.c 2007-07-09 01:32:17.000000000 +0200
+++ linux-2.6.23/sound/isa/cs423x/cs4231_lib.c 2007-09-05 19:07:35.242811960 +0200
@@ -74,7 +74,7 @@ static unsigned int rates[14] = {
};
static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
- .count = 14,
+ .count = ARRAY_SIZE(rates),
.list = rates,
.mask = 0,
};
@@ -134,29 +134,31 @@ static inline u8 cs4231_inb(struct snd_c
return inb(chip->port + offset);
}
-static void snd_cs4231_outm(struct snd_cs4231 *chip, unsigned char reg,
- unsigned char mask, unsigned char value)
+static void snd_cs4231_wait(struct snd_cs4231 *chip)
{
int timeout;
- unsigned char tmp;
for (timeout = 250;
timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
timeout--)
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
if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
#endif
- if (chip->calibrate_mute) {
- chip->image[reg] &= mask;
- chip->image[reg] |= value;
- } else {
+ chip->image[reg] = tmp;
+ if (!chip->calibrate_mute) {
cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
- mb();
- tmp = (chip->image[reg] & mask) | value;
+ wmb();
cs4231_outb(chip, CS4231P(REG), tmp);
- chip->image[reg] = tmp;
mb();
}
}
@@ -176,12 +178,7 @@ static void snd_cs4231_dout(struct snd_c
void snd_cs4231_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char value)
{
- int timeout;
-
- for (timeout = 250;
- timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
- timeout--)
- udelay(100);
+ snd_cs4231_wait(chip);
#ifdef CONFIG_SND_DEBUG
if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
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 *c
cs4231_outb(chip, CS4231P(REG), value);
chip->image[reg] = value;
mb();
-#if 0
- printk("codec out - reg 0x%x = 0x%x\n", chip->mce_bit | reg, value);
-#endif
+ snd_printdd("codec out - reg 0x%x = 0x%x\n",
+ chip->mce_bit | reg, value);
}
unsigned char snd_cs4231_in(struct snd_cs4231 *chip, unsigned char reg)
{
- int timeout;
-
- for (timeout = 250;
- timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
- timeout--)
- udelay(100);
+ snd_cs4231_wait(chip);
#ifdef CONFIG_SND_DEBUG
if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
snd_printk("in: auto calibration time out - reg = 0x%x\n", reg);
@@ -304,8 +295,7 @@ void snd_cs4231_mce_up(struct snd_cs4231
unsigned long flags;
int timeout;
- for (timeout = 250; timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT); timeout--)
- udelay(100);
+ snd_cs4231_wait(chip);
#ifdef CONFIG_SND_DEBUG
if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
snd_printk("mce_up - auto calibration time out (0)\n");
@@ -459,11 +449,11 @@ static unsigned char snd_cs4231_get_rate
{
int i;
- for (i = 0; i < 14; i++)
+ for (i = 0; i < ARRAY_SIZE(rates); i++)
if (rate == rates[i])
return freq_bits[i];
// snd_BUG();
- return freq_bits[13];
+ return freq_bits[ARRAY_SIZE(rates) - 1];
}
static unsigned char snd_cs4231_get_format(struct snd_cs4231 *chip,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cs4231-lib: replace common delay loop by function
2007-09-05 17:09 Krzysztof Helt
@ 2007-09-05 19:11 ` Rene Herman
0 siblings, 0 replies; 3+ messages in thread
From: Rene Herman @ 2007-09-05 19:11 UTC (permalink / raw)
To: Krzysztof Helt; +Cc: Alsa-devel
On 09/05/2007 07:09 PM, Krzysztof Helt wrote:
> From: Krzysztof Helt <krzysztof.h1@wp.pl>
>
> This patch replaces a common delay loop by a function.
> It also uses ARRAY_SIZE macro for the rates table.
>
> Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl>
> ---
> +static void snd_cs4231_wait(struct snd_cs4231 *chip)
> {
> int timeout;
> - unsigned char tmp;
>
> for (timeout = 250;
> timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
> timeout--)
> udelay(100);
> +}
Like the inb() pulled out into the body of the for as you did for ad1848 a
bit better, but otherwise:
Acked-by: Rene Herman <rene.herman@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-09-05 19:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20070904184927.0bb3bc7c.krzysztof.h1@wp.pl>
2007-09-04 22:37 ` [PATCH] cs4231-lib: replace common delay loop by function Rene Herman
2007-09-05 17:09 Krzysztof Helt
2007-09-05 19:11 ` Rene Herman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.