Skip to content

Commit

Permalink
Fix: ac101 i2c accessing is too often.
Browse files Browse the repository at this point in the history
  • Loading branch information
turmary committed May 21, 2018
1 parent ccac09b commit a8d0a23
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions ac101.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <linux/gpio/consumer.h>
#include <linux/regmap.h>
#include <linux/input.h>
#include <linux/delay.h>
#include "ac101_regs.h"
#include "ac10x.h"

Expand Down Expand Up @@ -77,23 +78,29 @@ int ac101_read(struct snd_soc_codec *codec, unsigned reg) {
int r, v = 0;

if ((r = regmap_read(ac10x->regmap101, reg, &v)) < 0) {
dev_err(codec->dev, "%s() L%d read reg %02X fail\n",
__func__, __LINE__, reg);
return r;
}
return v;
}

int ac101_write(struct snd_soc_codec *codec, unsigned reg, unsigned val) {
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
int v;

return regmap_write(ac10x->regmap101, reg, val);
v = regmap_write(ac10x->regmap101, reg, val);
return v;
}

int ac101_update_bits(struct snd_soc_codec *codec, unsigned reg,
unsigned mask, unsigned value
) {
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
int v;

return regmap_update_bits(ac10x->regmap101, reg, mask, value);
v = regmap_update_bits(ac10x->regmap101, reg, mask, value);
return v;
}


Expand Down Expand Up @@ -210,14 +217,16 @@ static int __ac101_get_hmic_data(struct snd_soc_codec *codec) {
#ifdef AC101_DEBG
static long counter;
#endif
int r;
int d;
int r, d;

d = GET_HMIC_DATA(ac101_read(codec, HMIC_STS));

r = 0x1 << HMIC_DATA_PEND;
ac101_write(codec, HMIC_STS, r);

/* prevent i2c accessing too frequently */
usleep_range(1500, 3000);

AC101_DBG("%s,line:%d HMIC_DATA(%3ld): %02X\n", __func__, __LINE__,
counter++, d
);
Expand Down Expand Up @@ -426,7 +435,7 @@ static int ac101_switch_probe(struct ac10x_priv *ac10x) {
_err_input_allocate_device:

if (ac10x->irq) {
devm_free_irq(&i2c->dev, ac10x->irq, NULL);
devm_free_irq(&i2c->dev, ac10x->irq, ac10x);
ac10x->irq = 0;
}
_err_irq:
Expand Down Expand Up @@ -1440,12 +1449,20 @@ int ac101_codec_remove(struct snd_soc_codec *codec)
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);

if (ac10x->irq) {
/* devm_free_irq(codec->dev, ac10x->irq, NULL); */
devm_free_irq(codec->dev, ac10x->irq, ac10x);
ac10x->irq = 0;
}

if (cancel_work_sync(&ac10x->work_switch) != 0) {
}

if (cancel_work_sync(&ac10x->work_clear_irq) != 0) {
}

if (ac10x->inpdev) {
input_unregister_device(ac10x->inpdev);
ac10x->inpdev = NULL;
}
#endif

return 0;
Expand Down

0 comments on commit a8d0a23

Please sign in to comment.