Skip to content

Commit

Permalink
Fix: reset ac101/ac108 chips after fill cache
Browse files Browse the repository at this point in the history
  • Loading branch information
turmary committed May 11, 2018
1 parent 0548a6d commit ccac09b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
40 changes: 20 additions & 20 deletions ac101.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
printk("\n");
if(i%4==0)
value_r = ac101_read(ac10x->codec, reg);
printk("0x%x: 0x%04x ", reg++, value_r);
if (++i % 4 == 0 || i == num)
printk("\n");
} while(i<num);
} while (i < num);
regcache_cache_bypass(ac10x->regmap101, false);
}
return count;
}
Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 17 additions & 5 deletions ac108.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 || \
Expand Down

0 comments on commit ccac09b

Please sign in to comment.