From ccac09b842ecbe00433a9a3965470be93e5f867b Mon Sep 17 00:00:00 2001 From: "Peter.Yang" Date: Fri, 11 May 2018 06:22:37 +0000 Subject: [PATCH] Fix: reset ac101/ac108 chips after fill cache --- ac101.c | 40 ++++++++++++++++++++-------------------- ac108.c | 22 +++++++++++++++++----- install.sh | 3 ++- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/ac101.c b/ac101.c index 6d3e8eb..5f69467 100644 --- a/ac101.c +++ b/ac101.c @@ -1490,32 +1490,32 @@ int ac101_codec_resume(struct snd_soc_codec *codec) static ssize_t ac101_debug_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - static int val = 0, flag = 0; - u8 reg,num,i=0; - u16 value_w,value_r[128]; struct ac10x_priv *ac10x = dev_get_drvdata(dev); + int val = 0, flag = 0; + u16 value_w, value_r; + u8 reg, num, i=0; + val = simple_strtol(buf, NULL, 16); flag = (val >> 24) & 0xF; - if(flag) { + if (flag) { reg = (val >> 16) & 0xFF; value_w = val & 0xFFFF; ac101_write(ac10x->codec, reg, value_w); - printk("write 0x%x to reg:0x%x\n",value_w,reg); + printk("write 0x%x to reg:0x%x\n", value_w, reg); } else { - reg =(val>>8)& 0xFF; - num=val&0xff; + reg = (val >> 8) & 0xFF; + num = val & 0xff; printk("\n"); - printk("read:start add:0x%x,count:0x%x\n",reg,num); + printk("read:start add:0x%x,count:0x%x\n", reg, num); + + regcache_cache_bypass(ac10x->regmap101, true); do { - value_r[i] = ac101_read(ac10x->codec, reg); - printk("0x%x: 0x%04x ",reg,value_r[i]); - reg+=1; - i++; - if(i == num) + value_r = ac101_read(ac10x->codec, reg); + printk("0x%x: 0x%04x ", reg++, value_r); + if (++i % 4 == 0 || i == num) printk("\n"); - if(i%4==0) - printk("\n"); - } while(iregmap101, false); } return count; } @@ -1602,13 +1602,13 @@ int ac101_probe(struct i2c_client *i2c, const struct i2c_device_id *id) return ret; } - ac10x_fill_regcache(&i2c->dev, ac10x->regmap101); - /* Chip reset */ - /* + regcache_cache_only(ac10x->regmap101, false); ret = regmap_write(ac10x->regmap101, CHIP_AUDIO_RST, 0); msleep(50); - */ + + /* sync regcache for FLAT type */ + ac10x_fill_regcache(&i2c->dev, ac10x->regmap101); ret = regmap_read(ac10x->regmap101, CHIP_AUDIO_RST, &v); if (ret < 0) { diff --git a/ac108.c b/ac108.c index 7048d82..e569e5b 100644 --- a/ac108.c +++ b/ac108.c @@ -173,8 +173,11 @@ static const DECLARE_TLV_DB_SCALE(tlv_ch_digital_vol, -11925,75,0); int ac10x_read(u8 reg, u8* rt_val, struct regmap* i2cm) { int r, v = 0; - r = regmap_read(i2cm, reg, &v); - *rt_val = v; + if ((r = regmap_read(i2cm, reg, &v)) < 0) { + pr_err("ac10x_read error->[REG-0x%02x]\n", reg); + } else { + *rt_val = v; + } return r; } @@ -1325,12 +1328,16 @@ static ssize_t ac108_store(struct device *dev, struct device_attribute *attr, co ac108_multi_write(reg, value_w, ac10x); printk("Write 0x%02x to REG:0x%02x\n", value_w, reg); } else { + int k; + reg = (val >> 8) & 0xFF; num = val & 0xff; printk("\nRead: start REG:0x%02x,count:0x%02x\n", reg, num); + for (k = 0; k < ac10x->codec_cnt; k++) { + regcache_cache_bypass(ac10x->i2cmap[k], true); + } do { - int k; memset(value_r, 0, sizeof value_r); @@ -1348,6 +1355,9 @@ static ssize_t ac108_store(struct device *dev, struct device_attribute *attr, co printk("\n"); } } while (i < num); + for (k = 0; k < ac10x->codec_cnt; k++) { + regcache_cache_bypass(ac10x->i2cmap[k], false); + } } return count; @@ -1429,15 +1439,17 @@ static int ac108_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *i return ret; } - ac10x_fill_regcache(&i2c->dev, ac10x->i2cmap[index]); - /* * Writing this register with 0x12 * will resets all register to their default state. */ + regcache_cache_only(ac10x->i2cmap[index], false); ret = regmap_write(ac10x->i2cmap[index], CHIP_RST, CHIP_RST_VAL); msleep(1); + /* sync regcache for FLAT type */ + ac10x_fill_regcache(&i2c->dev, ac10x->i2cmap[index]); + ac10x->codec_cnt++; pr_err(" ac10x codec count : %d\n", ac10x->codec_cnt); diff --git a/install.sh b/install.sh index 9fc2bd1..e41610b 100755 --- a/install.sh +++ b/install.sh @@ -57,7 +57,8 @@ cp seeed-8mic-voicecard.dtbo /boot/overlays #install alsa plugins # no need this plugin now -# install -D ac108_plugin/libasound_module_pcm_ac108.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so +# install -D ac108_plugin/libasound_module_pcm_ac108.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so +rm -f /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so #set kernel moduels grep -q "snd-soc-seeed-voicecard" /etc/modules || \