Skip to contentSkip to conversation

ASoC: cs4271: init/timing problem

DISCUSSION Pascal Huerst 2 participants 8 messages Mar 31, 2015 – Apr 2, 2015

lore
Share & tools
lore
#0 lore raw

Hey all,

We have a custom built hw, based on am335x and from time to time we need to rmmod/modprobe the ASoC machine driver. Depending on the hw, the first call to regmap_update_bits(..) in cs4271_codec_probe(..) fails with -EREMOTEIO.

The error is originated in:

drivers/i2c/busses/i2c-omap.c

and happens if no i2c package acknowledge is received by the host.

I think this is a timing issue and on some devices, the codec is just not ready yet, for communication.

What is the right way to fix that? My attempt would be something like this:

const int retries = 5;

while (retries) {
	ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2,
                                 CS4271_MODE2_PDN | CS4271_MODE2_CPEN,
                                 CS4271_MODE2_PDN | CS4271_MODE2_CPEN);

        if (ret == -EREMOTEIO) {
                retries--;
                udelay(1);
                continue;

        } else if (ret)
                return ret;

        break;
}

But I might also just add a proper delay before the first call to regmap_update_bits(..)

So what is the proper way to handle this?

Thanks
Pascal

#1 lore raw
Quoted 9 lines · Pascal Huerst

Hey all,

We have a custom built hw, based on am335x and from time to time we need to rmmod/modprobe the ASoC machine driver. Depending on the hw, the first call to regmap_update_bits(..) in cs4271_codec_probe(..) fails with -EREMOTEIO.

The error is originated in:

Quoted 8 lines

drivers/i2c/busses/i2c-omap.c

and happens if no i2c package acknowledge is received by the host.

I think this is a timing issue and on some devices, the codec is just not ready yet, for communication.

What is the right way to fix that? My attempt would be something like this:

The error you are referring to is a NACK from a device (CODEC). That is usually seen when you dont have it hooked up correctly. Could also be that the I2C bus is too fast. How fast are you running the bus?

-Brian

#2 lore raw

Hey Brian,

Quoted 15 lines · Brian Austin
Quoted 13 lines · Pascal Huerst

Hey all,

We have a custom built hw, based on am335x and from time to time we need to rmmod/modprobe the ASoC machine driver. Depending on the hw, the first call to regmap_update_bits(..) in cs4271_codec_probe(..) fails with -EREMOTEIO.

The error is originated in:

drivers/i2c/busses/i2c-omap.c

and happens if no i2c package acknowledge is received by the host.

Quoted 8 lines
Quoted 4 lines

I think this is a timing issue and on some devices, the codec is just not ready yet, for communication.

What is the right way to fix that? My attempt would be something like this:

The error you are referring to is a NACK from a device (CODEC). That is usually seen when you dont have it hooked up correctly. Could also be that the I2C bus is too fast. How fast are you running the bus?

clock-frequency is set to 100000, hence 100 kHz, which should be ok, according to the datasheet.

#3 lore raw

Hey Brian,

Quoted 21 lines · Pascal Huerst

Hey Brian,

Quoted 18 lines · Brian Austin
Quoted 16 lines · Pascal Huerst

Hey all,

We have a custom built hw, based on am335x and from time to time we need to rmmod/modprobe the ASoC machine driver. Depending on the hw, the first call to regmap_update_bits(..) in cs4271_codec_probe(..) fails with -EREMOTEIO.

The error is originated in:

drivers/i2c/busses/i2c-omap.c

and happens if no i2c package acknowledge is received by the host.

I think this is a timing issue and on some devices, the codec is just not ready yet, for communication.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

What is the right way to fix that? My attempt would be something like this:

The error you are referring to is a NACK from a device (CODEC). That is usually seen when you dont have it hooked up correctly. Could also be that the I2C bus is too fast. How fast are you running the bus?

clock-frequency is set to 100000, hence 100 kHz, which should be ok, according to the datasheet.

I just lowered the clock-frequency to 50 kHz and I face the same problem, but it very much depends on the hardware. On some devices I don't face the problem at all and on others I can reproduce it very reliable. If I add a mdelay(20), or use the loop I postet earlier, the issue is gone on all devices.

#4 lore raw
Quoted 30 lines · Pascal Huerst

Hey Brian,

Quoted 27 lines · Pascal Huerst

Hey Brian,

Quoted 23 lines · Brian Austin
Quoted 9 lines · Pascal Huerst

Hey all,

We have a custom built hw, based on am335x and from time to time we need to rmmod/modprobe the ASoC machine driver. Depending on the hw, the first call to regmap_update_bits(..) in cs4271_codec_probe(..) fails with -EREMOTEIO.

The error is originated in:

Quoted 8 lines

drivers/i2c/busses/i2c-omap.c

and happens if no i2c package acknowledge is received by the host.

I think this is a timing issue and on some devices, the codec is just not ready yet, for communication.

What is the right way to fix that? My attempt would be something like this:

The error you are referring to is a NACK from a device (CODEC). That is usually seen when you dont have it hooked up correctly. Could also be that the I2C bus is too fast. How fast are you running the bus?

Quoted 8 lines
Quoted 2 lines

clock-frequency is set to 100000, hence 100 kHz, which should be ok, according to the datasheet.

I just lowered the clock-frequency to 50 kHz and I face the same problem, but it very much depends on the hardware. On some devices I don't face the problem at all and on others I can reproduce it very reliable. If I add a mdelay(20), or use the loop I postet earlier, the issue is gone on all devices.

Are there any other devices on the I2C bus? Lets take this off the ALSA list until there is a determination that it is an ASoC issue which it does not appear to be right now. OK?

Thanks,
Brian

#5 lore raw
Quoted 36 lines · Brian
Quoted 33 lines · Pascal Huerst

Hey Brian,

Quoted 29 lines · Pascal Huerst

Hey Brian,

Quoted 15 lines · Brian Austin
Quoted 13 lines · Pascal Huerst

Hey all,

We have a custom built hw, based on am335x and from time to time we need to rmmod/modprobe the ASoC machine driver. Depending on the hw, the first call to regmap_update_bits(..) in cs4271_codec_probe(..) fails with -EREMOTEIO.

The error is originated in:

drivers/i2c/busses/i2c-omap.c

and happens if no i2c package acknowledge is received by the host.

Quoted 8 lines
Quoted 4 lines

I think this is a timing issue and on some devices, the codec is just not ready yet, for communication.

What is the right way to fix that? My attempt would be something like this:

The error you are referring to is a NACK from a device (CODEC). That is usually seen when you dont have it hooked up correctly. Could also be that the I2C bus is too fast. How fast are you running the bus?

clock-frequency is set to 100000, hence 100 kHz, which should be ok, according to the datasheet.

Quoted 7 lines
Quoted 5 lines

I just lowered the clock-frequency to 50 kHz and I face the same problem, but it very much depends on the hardware. On some devices I don't face the problem at all and on others I can reproduce it very reliable. If I add a mdelay(20), or use the loop I postet earlier, the issue is gone on all devices.

Are there any other devices on the I2C bus? Lets take this off the ALSA list until there is a determination that it is an ASoC issue which it does not appear to be right now.

Well I think it is. There is a delay needed in sound/soc/codec/cs4271.c at line 569, in certain cases, because the call to regmap_update_bits on line 570 fails sometimes. If I add a delay of a few us on line 569, the call never fails.

But let me just send in a patch so we really know what we are talking about, then.

#6 lore raw
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

I just lowered the clock-frequency to 50 kHz and I face the same problem, but it very much depends on the hardware. On some devices I don't face the problem at all and on others I can reproduce it very reliable. If I add a mdelay(20), or use the loop I postet earlier, the issue is gone on all devices.

Are there any other devices on the I2C bus? Lets take this off the ALSA list until there is a determination that it is an ASoC issue which it does not appear to be right now.

Quoted 8 lines

Well I think it is. There is a delay needed in sound/soc/codec/cs4271.c at line 569, in certain cases, because the call to regmap_update_bits on line 570 fails sometimes. If I add a delay of a few us on line 569, the call never fails.

But let me just send in a patch so we really know what we are talking about, then.

can you try something like this?

gpio_direction_output(cs4271->gpio_nreset, 0);
-udelay(1);
gpio_set_value(cs4271->gpio_nreset, 1);
/* Give the codec time to wake up */
-udelay(1);

gpio_direction_output(cs4271->gpio_nreset, 0);
+mdelay(1);
gpio_set_value(cs4271->gpio_nreset, 1);
/* Give the codec time to wake up */
+mdelay(1);

See if that helps instead of adding another delay.

#7 lore raw
Quoted 24 lines · Brian Austin
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

I just lowered the clock-frequency to 50 kHz and I face the same problem, but it very much depends on the hardware. On some devices I don't face the problem at all and on others I can reproduce it very reliable. If I add a mdelay(20), or use the loop I postet earlier, the issue is gone on all devices.

Are there any other devices on the I2C bus? Lets take this off the ALSA list until there is a determination that it is an ASoC issue which it does not appear to be right now.

Quoted 8 lines

Well I think it is. There is a delay needed in sound/soc/codec/cs4271.c at line 569, in certain cases, because the call to regmap_update_bits on line 570 fails sometimes. If I add a delay of a few us on line 569, the call never fails.

But let me just send in a patch so we really know what we are talking about, then.

can you try something like this?

gpio_direction_output(cs4271->gpio_nreset, 0);
-udelay(1);
gpio_set_value(cs4271->gpio_nreset, 1);
/* Give the codec time to wake up */
-udelay(1);

Quoted 7 lines

gpio_direction_output(cs4271->gpio_nreset, 0);
+mdelay(1);
gpio_set_value(cs4271->gpio_nreset, 1);
/* Give the codec time to wake up */
+mdelay(1);

See if that helps instead of adding another delay.

Works perfect for me. Tested on different devices without any problems. If you agree on that, I'll send in a patch.