提交 7e6120c5 编写于 作者: P Peter Ujfalusi 提交者: Liam Girdwood

ASoC: TWL4030: Use usleep_range when appropriate

Change the busy loop delays with usleep_range or msleep calls.
Signed-off-by: NPeter Ujfalusi <peter.ujfalusi@nokia.com>
Acked-by: NMark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: NLiam Girdwood <lrg@slimlogic.co.uk>
上级 506ecbca
...@@ -233,6 +233,16 @@ static int twl4030_write(struct snd_soc_codec *codec, ...@@ -233,6 +233,16 @@ static int twl4030_write(struct snd_soc_codec *codec,
return 0; return 0;
} }
static inline void twl4030_wait_ms(int time)
{
if (time < 60) {
time *= 1000;
usleep_range(time, time + 500);
} else {
msleep(time);
}
}
static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable) static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable)
{ {
struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
...@@ -338,10 +348,14 @@ static void twl4030_init_chip(struct snd_soc_codec *codec) ...@@ -338,10 +348,14 @@ static void twl4030_init_chip(struct snd_soc_codec *codec)
twl4030_write(codec, TWL4030_REG_ANAMICL, twl4030_write(codec, TWL4030_REG_ANAMICL,
reg | TWL4030_CNCL_OFFSET_START); reg | TWL4030_CNCL_OFFSET_START);
/* wait for offset cancellation to complete */ /*
* Wait for offset cancellation to complete.
* Since this takes a while, do not slam the i2c.
* Start polling the status after ~20ms.
*/
msleep(20);
do { do {
/* this takes a little while, so don't slam i2c */ usleep_range(1000, 2000);
udelay(2000);
twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte, twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte,
TWL4030_REG_ANAMICL); TWL4030_REG_ANAMICL);
} while ((i++ < 100) && } while ((i++ < 100) &&
...@@ -725,9 +739,12 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp) ...@@ -725,9 +739,12 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
/* Base values for ramp delay calculation: 2^19 - 2^26 */ /* Base values for ramp delay calculation: 2^19 - 2^26 */
unsigned int ramp_base[] = {524288, 1048576, 2097152, 4194304, unsigned int ramp_base[] = {524288, 1048576, 2097152, 4194304,
8388608, 16777216, 33554432, 67108864}; 8388608, 16777216, 33554432, 67108864};
unsigned int delay;
hs_gain = twl4030_read_reg_cache(codec, TWL4030_REG_HS_GAIN_SET); hs_gain = twl4030_read_reg_cache(codec, TWL4030_REG_HS_GAIN_SET);
hs_pop = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET); hs_pop = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET);
delay = (ramp_base[(hs_pop & TWL4030_RAMP_DELAY) >> 2] /
twl4030->sysclk) + 1;
/* Enable external mute control, this dramatically reduces /* Enable external mute control, this dramatically reduces
* the pop-noise */ * the pop-noise */
...@@ -751,16 +768,14 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp) ...@@ -751,16 +768,14 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
hs_pop |= TWL4030_RAMP_EN; hs_pop |= TWL4030_RAMP_EN;
twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop); twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
/* Wait ramp delay time + 1, so the VMID can settle */ /* Wait ramp delay time + 1, so the VMID can settle */
mdelay((ramp_base[(hs_pop & TWL4030_RAMP_DELAY) >> 2] / twl4030_wait_ms(delay);
twl4030->sysclk) + 1);
} else { } else {
/* Headset ramp-down _not_ according to /* Headset ramp-down _not_ according to
* the TRM, but in a way that it is working */ * the TRM, but in a way that it is working */
hs_pop &= ~TWL4030_RAMP_EN; hs_pop &= ~TWL4030_RAMP_EN;
twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop); twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
/* Wait ramp delay time + 1, so the VMID can settle */ /* Wait ramp delay time + 1, so the VMID can settle */
mdelay((ramp_base[(hs_pop & TWL4030_RAMP_DELAY) >> 2] / twl4030_wait_ms(delay);
twl4030->sysclk) + 1);
/* Bypass the reg_cache to mute the headset */ /* Bypass the reg_cache to mute the headset */
twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
hs_gain & (~0x0f), hs_gain & (~0x0f),
...@@ -835,7 +850,7 @@ static int digimic_event(struct snd_soc_dapm_widget *w, ...@@ -835,7 +850,7 @@ static int digimic_event(struct snd_soc_dapm_widget *w,
struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec); struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec);
if (twl4030->digimic_delay) if (twl4030->digimic_delay)
mdelay(twl4030->digimic_delay); twl4030_wait_ms(twl4030->digimic_delay);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册