Skip to content

Commit ccac09b

Browse files
committed
Fix: reset ac101/ac108 chips after fill cache
1 parent 0548a6d commit ccac09b

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed

ac101.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,32 +1490,32 @@ int ac101_codec_resume(struct snd_soc_codec *codec)
14901490
static ssize_t ac101_debug_store(struct device *dev,
14911491
struct device_attribute *attr, const char *buf, size_t count)
14921492
{
1493-
static int val = 0, flag = 0;
1494-
u8 reg,num,i=0;
1495-
u16 value_w,value_r[128];
14961493
struct ac10x_priv *ac10x = dev_get_drvdata(dev);
1494+
int val = 0, flag = 0;
1495+
u16 value_w, value_r;
1496+
u8 reg, num, i=0;
1497+
14971498
val = simple_strtol(buf, NULL, 16);
14981499
flag = (val >> 24) & 0xF;
1499-
if(flag) {
1500+
if (flag) {
15001501
reg = (val >> 16) & 0xFF;
15011502
value_w = val & 0xFFFF;
15021503
ac101_write(ac10x->codec, reg, value_w);
1503-
printk("write 0x%x to reg:0x%x\n",value_w,reg);
1504+
printk("write 0x%x to reg:0x%x\n", value_w, reg);
15041505
} else {
1505-
reg =(val>>8)& 0xFF;
1506-
num=val&0xff;
1506+
reg = (val >> 8) & 0xFF;
1507+
num = val & 0xff;
15071508
printk("\n");
1508-
printk("read:start add:0x%x,count:0x%x\n",reg,num);
1509+
printk("read:start add:0x%x,count:0x%x\n", reg, num);
1510+
1511+
regcache_cache_bypass(ac10x->regmap101, true);
15091512
do {
1510-
value_r[i] = ac101_read(ac10x->codec, reg);
1511-
printk("0x%x: 0x%04x ",reg,value_r[i]);
1512-
reg+=1;
1513-
i++;
1514-
if(i == num)
1515-
printk("\n");
1516-
if(i%4==0)
1513+
value_r = ac101_read(ac10x->codec, reg);
1514+
printk("0x%x: 0x%04x ", reg++, value_r);
1515+
if (++i % 4 == 0 || i == num)
15171516
printk("\n");
1518-
} while(i<num);
1517+
} while (i < num);
1518+
regcache_cache_bypass(ac10x->regmap101, false);
15191519
}
15201520
return count;
15211521
}
@@ -1602,13 +1602,13 @@ int ac101_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
16021602
return ret;
16031603
}
16041604

1605-
ac10x_fill_regcache(&i2c->dev, ac10x->regmap101);
1606-
16071605
/* Chip reset */
1608-
/*
1606+
regcache_cache_only(ac10x->regmap101, false);
16091607
ret = regmap_write(ac10x->regmap101, CHIP_AUDIO_RST, 0);
16101608
msleep(50);
1611-
*/
1609+
1610+
/* sync regcache for FLAT type */
1611+
ac10x_fill_regcache(&i2c->dev, ac10x->regmap101);
16121612

16131613
ret = regmap_read(ac10x->regmap101, CHIP_AUDIO_RST, &v);
16141614
if (ret < 0) {

ac108.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,11 @@ static const DECLARE_TLV_DB_SCALE(tlv_ch_digital_vol, -11925,75,0);
173173
int ac10x_read(u8 reg, u8* rt_val, struct regmap* i2cm) {
174174
int r, v = 0;
175175

176-
r = regmap_read(i2cm, reg, &v);
177-
*rt_val = v;
176+
if ((r = regmap_read(i2cm, reg, &v)) < 0) {
177+
pr_err("ac10x_read error->[REG-0x%02x]\n", reg);
178+
} else {
179+
*rt_val = v;
180+
}
178181
return r;
179182
}
180183

@@ -1325,12 +1328,16 @@ static ssize_t ac108_store(struct device *dev, struct device_attribute *attr, co
13251328
ac108_multi_write(reg, value_w, ac10x);
13261329
printk("Write 0x%02x to REG:0x%02x\n", value_w, reg);
13271330
} else {
1331+
int k;
1332+
13281333
reg = (val >> 8) & 0xFF;
13291334
num = val & 0xff;
13301335
printk("\nRead: start REG:0x%02x,count:0x%02x\n", reg, num);
13311336

1337+
for (k = 0; k < ac10x->codec_cnt; k++) {
1338+
regcache_cache_bypass(ac10x->i2cmap[k], true);
1339+
}
13321340
do {
1333-
int k;
13341341

13351342
memset(value_r, 0, sizeof value_r);
13361343

@@ -1348,6 +1355,9 @@ static ssize_t ac108_store(struct device *dev, struct device_attribute *attr, co
13481355
printk("\n");
13491356
}
13501357
} while (i < num);
1358+
for (k = 0; k < ac10x->codec_cnt; k++) {
1359+
regcache_cache_bypass(ac10x->i2cmap[k], false);
1360+
}
13511361
}
13521362

13531363
return count;
@@ -1429,15 +1439,17 @@ static int ac108_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *i
14291439
return ret;
14301440
}
14311441

1432-
ac10x_fill_regcache(&i2c->dev, ac10x->i2cmap[index]);
1433-
14341442
/*
14351443
* Writing this register with 0x12
14361444
* will resets all register to their default state.
14371445
*/
1446+
regcache_cache_only(ac10x->i2cmap[index], false);
14381447
ret = regmap_write(ac10x->i2cmap[index], CHIP_RST, CHIP_RST_VAL);
14391448
msleep(1);
14401449

1450+
/* sync regcache for FLAT type */
1451+
ac10x_fill_regcache(&i2c->dev, ac10x->i2cmap[index]);
1452+
14411453
ac10x->codec_cnt++;
14421454
pr_err(" ac10x codec count : %d\n", ac10x->codec_cnt);
14431455

install.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ cp seeed-8mic-voicecard.dtbo /boot/overlays
5757

5858
#install alsa plugins
5959
# no need this plugin now
60-
# install -D ac108_plugin/libasound_module_pcm_ac108.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so
60+
# install -D ac108_plugin/libasound_module_pcm_ac108.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so
61+
rm -f /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so
6162

6263
#set kernel moduels
6364
grep -q "snd-soc-seeed-voicecard" /etc/modules || \

0 commit comments

Comments
 (0)