Skip to content

Commit abed17f

Browse files
shumingfanbroonie
authored andcommitted
ASoC: rt1308-sdw: get calibration params after power on
It will be safe when getting the calibration params after power-on. All powers are ready to read the calibration params from EFUSE. Signed-off-by: Shuming Fan <shumingf@realtek.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20220315093740.12008-1-shumingf@realtek.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 9ebd62d commit abed17f

1 file changed

Lines changed: 40 additions & 33 deletions

File tree

sound/soc/codecs/rt1308-sdw.c

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ static bool rt1308_volatile_register(struct device *dev, unsigned int reg)
5050
case 0x3008:
5151
case 0x300a:
5252
case 0xc000:
53+
case 0xc860 ... 0xc863:
54+
case 0xc870 ... 0xc873:
5355
return true;
5456
default:
5557
return false;
@@ -159,12 +161,45 @@ static int rt1308_read_prop(struct sdw_slave *slave)
159161
return 0;
160162
}
161163

164+
static void rt1308_apply_calib_params(struct rt1308_sdw_priv *rt1308)
165+
{
166+
unsigned int efuse_m_btl_l, efuse_m_btl_r, tmp;
167+
unsigned int efuse_c_btl_l, efuse_c_btl_r;
168+
169+
/* read efuse to apply calibration parameters */
170+
regmap_write(rt1308->regmap, 0xc7f0, 0x04);
171+
regmap_write(rt1308->regmap, 0xc7f1, 0xfe);
172+
msleep(100);
173+
regmap_write(rt1308->regmap, 0xc7f0, 0x44);
174+
msleep(20);
175+
regmap_write(rt1308->regmap, 0xc240, 0x10);
176+
177+
regmap_read(rt1308->regmap, 0xc861, &tmp);
178+
efuse_m_btl_l = tmp;
179+
regmap_read(rt1308->regmap, 0xc860, &tmp);
180+
efuse_m_btl_l = efuse_m_btl_l | (tmp << 8);
181+
regmap_read(rt1308->regmap, 0xc863, &tmp);
182+
efuse_c_btl_l = tmp;
183+
regmap_read(rt1308->regmap, 0xc862, &tmp);
184+
efuse_c_btl_l = efuse_c_btl_l | (tmp << 8);
185+
regmap_read(rt1308->regmap, 0xc871, &tmp);
186+
efuse_m_btl_r = tmp;
187+
regmap_read(rt1308->regmap, 0xc870, &tmp);
188+
efuse_m_btl_r = efuse_m_btl_r | (tmp << 8);
189+
regmap_read(rt1308->regmap, 0xc873, &tmp);
190+
efuse_c_btl_r = tmp;
191+
regmap_read(rt1308->regmap, 0xc872, &tmp);
192+
efuse_c_btl_r = efuse_c_btl_r | (tmp << 8);
193+
dev_dbg(&rt1308->sdw_slave->dev, "%s m_btl_l=0x%x, m_btl_r=0x%x\n", __func__,
194+
efuse_m_btl_l, efuse_m_btl_r);
195+
dev_dbg(&rt1308->sdw_slave->dev, "%s c_btl_l=0x%x, c_btl_r=0x%x\n", __func__,
196+
efuse_c_btl_l, efuse_c_btl_r);
197+
}
198+
162199
static int rt1308_io_init(struct device *dev, struct sdw_slave *slave)
163200
{
164201
struct rt1308_sdw_priv *rt1308 = dev_get_drvdata(dev);
165202
int ret = 0;
166-
unsigned int efuse_m_btl_l, efuse_m_btl_r, tmp;
167-
unsigned int efuse_c_btl_l, efuse_c_btl_r;
168203

169204
if (rt1308->hw_init)
170205
return 0;
@@ -196,37 +231,6 @@ static int rt1308_io_init(struct device *dev, struct sdw_slave *slave)
196231
/* sw reset */
197232
regmap_write(rt1308->regmap, RT1308_SDW_RESET, 0);
198233

199-
/* read efuse */
200-
regmap_write(rt1308->regmap, 0xc360, 0x01);
201-
regmap_write(rt1308->regmap, 0xc361, 0x80);
202-
regmap_write(rt1308->regmap, 0xc7f0, 0x04);
203-
regmap_write(rt1308->regmap, 0xc7f1, 0xfe);
204-
msleep(100);
205-
regmap_write(rt1308->regmap, 0xc7f0, 0x44);
206-
msleep(20);
207-
regmap_write(rt1308->regmap, 0xc240, 0x10);
208-
209-
regmap_read(rt1308->regmap, 0xc861, &tmp);
210-
efuse_m_btl_l = tmp;
211-
regmap_read(rt1308->regmap, 0xc860, &tmp);
212-
efuse_m_btl_l = efuse_m_btl_l | (tmp << 8);
213-
regmap_read(rt1308->regmap, 0xc863, &tmp);
214-
efuse_c_btl_l = tmp;
215-
regmap_read(rt1308->regmap, 0xc862, &tmp);
216-
efuse_c_btl_l = efuse_c_btl_l | (tmp << 8);
217-
regmap_read(rt1308->regmap, 0xc871, &tmp);
218-
efuse_m_btl_r = tmp;
219-
regmap_read(rt1308->regmap, 0xc870, &tmp);
220-
efuse_m_btl_r = efuse_m_btl_r | (tmp << 8);
221-
regmap_read(rt1308->regmap, 0xc873, &tmp);
222-
efuse_c_btl_r = tmp;
223-
regmap_read(rt1308->regmap, 0xc872, &tmp);
224-
efuse_c_btl_r = efuse_c_btl_r | (tmp << 8);
225-
dev_dbg(&slave->dev, "%s m_btl_l=0x%x, m_btl_r=0x%x\n", __func__,
226-
efuse_m_btl_l, efuse_m_btl_r);
227-
dev_dbg(&slave->dev, "%s c_btl_l=0x%x, c_btl_r=0x%x\n", __func__,
228-
efuse_c_btl_l, efuse_c_btl_r);
229-
230234
/* initial settings */
231235
regmap_write(rt1308->regmap, 0xc103, 0xc0);
232236
regmap_write(rt1308->regmap, 0xc030, 0x17);
@@ -323,6 +327,8 @@ static int rt1308_classd_event(struct snd_soc_dapm_widget *w,
323327
{
324328
struct snd_soc_component *component =
325329
snd_soc_dapm_to_component(w->dapm);
330+
struct rt1308_sdw_priv *rt1308 =
331+
snd_soc_component_get_drvdata(component);
326332

327333
switch (event) {
328334
case SND_SOC_DAPM_POST_PMU:
@@ -331,6 +337,7 @@ static int rt1308_classd_event(struct snd_soc_dapm_widget *w,
331337
RT1308_SDW_OFFSET | (RT1308_POWER_STATUS << 4),
332338
0x3, 0x3);
333339
msleep(40);
340+
rt1308_apply_calib_params(rt1308);
334341
break;
335342
case SND_SOC_DAPM_PRE_PMD:
336343
snd_soc_component_update_bits(component,

0 commit comments

Comments
 (0)