Skip to content

Commit 05ac384

Browse files
Shenghao-Dingtiwai
authored andcommitted
ALSA: hda/tas2781: A workaround solution to lower-vol issue among lower calibrated-impedance micro-speaker on TAS2781
On TAS2781, if the Speaker calibrated impedance is lower than default value hard-coded inside the TAS2781, it will cuase vol lower than normal. In order to fix this issue, the parameter of SineGainI need updating. Signed-off-by: Shenghao Ding <shenghao-ding@ti.com> Tested-by: Matthew Schwartz <matthew.schwartz@linux.dev> Link: https://patch.msgid.link/20260227144641.1243-1-shenghao-ding@ti.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 068641b commit 05ac384

3 files changed

Lines changed: 98 additions & 12 deletions

File tree

include/sound/tas2781.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ struct tasdevice {
151151
struct bulk_reg_val *cali_data_backup;
152152
struct bulk_reg_val alp_cali_bckp;
153153
struct tasdevice_fw *cali_data_fmw;
154+
void *cali_specific;
154155
unsigned int dev_addr;
155156
unsigned int err_code;
156157
unsigned char cur_book;

sound/hda/codecs/side-codecs/tas2781_hda_i2c.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ struct tas2781_hda_i2c_priv {
6060
int (*save_calibration)(struct tas2781_hda *h);
6161

6262
int hda_chip_id;
63-
bool skip_calibration;
6463
};
6564

6665
static int tas2781_get_i2c_res(struct acpi_resource *ares, void *data)
@@ -479,8 +478,7 @@ static void tasdevice_dspfw_init(void *context)
479478
/* If calibrated data occurs error, dsp will still works with default
480479
* calibrated data inside algo.
481480
*/
482-
if (!hda_priv->skip_calibration)
483-
hda_priv->save_calibration(tas_hda);
481+
hda_priv->save_calibration(tas_hda);
484482
}
485483

486484
static void tasdev_fw_ready(const struct firmware *fmw, void *context)
@@ -535,7 +533,6 @@ static int tas2781_hda_bind(struct device *dev, struct device *master,
535533
void *master_data)
536534
{
537535
struct tas2781_hda *tas_hda = dev_get_drvdata(dev);
538-
struct tas2781_hda_i2c_priv *hda_priv = tas_hda->hda_priv;
539536
struct hda_component_parent *parent = master_data;
540537
struct hda_component *comp;
541538
struct hda_codec *codec;
@@ -564,14 +561,6 @@ static int tas2781_hda_bind(struct device *dev, struct device *master,
564561
break;
565562
}
566563

567-
/*
568-
* Using ASUS ROG Xbox Ally X (RC73XA) UEFI calibration data
569-
* causes audio dropouts during playback, use fallback data
570-
* from DSP firmware as a workaround.
571-
*/
572-
if (codec->core.subsystem_id == 0x10431384)
573-
hda_priv->skip_calibration = true;
574-
575564
guard(pm_runtime_active_auto)(dev);
576565

577566
comp->dev = dev;
@@ -643,6 +632,7 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt)
643632
*/
644633
device_name = "TIAS2781";
645634
hda_priv->hda_chip_id = HDA_TAS2781;
635+
tas_hda->priv->chip_id = TAS2781;
646636
hda_priv->save_calibration = tas2781_save_calibration;
647637
tas_hda->priv->global_addr = TAS2781_GLOBAL_ADDR;
648638
} else if (strstarts(dev_name(&clt->dev), "i2c-TXNW2770")) {
@@ -656,6 +646,7 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt)
656646
"i2c-TXNW2781:00-tas2781-hda.0")) {
657647
device_name = "TXNW2781";
658648
hda_priv->hda_chip_id = HDA_TAS2781;
649+
tas_hda->priv->chip_id = TAS2781;
659650
hda_priv->save_calibration = tas2781_save_calibration;
660651
tas_hda->priv->global_addr = TAS2781_GLOBAL_ADDR;
661652
} else if (strstr(dev_name(&clt->dev), "INT8866")) {

sound/soc/codecs/tas2781-fmwlib.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
#define TAS2781_YRAM1_PAGE 42
3333
#define TAS2781_YRAM1_START_REG 88
3434

35+
#define TAS2781_PG_REG TASDEVICE_REG(0x00, 0x00, 0x7c)
36+
#define TAS2781_PG_1_0 0xA0
37+
#define TAS2781_PG_2_0 0xA8
38+
3539
#define TAS2781_YRAM2_START_PAGE 43
3640
#define TAS2781_YRAM2_END_PAGE 49
3741
#define TAS2781_YRAM2_START_REG 8
@@ -98,6 +102,12 @@ struct blktyp_devidx_map {
98102
unsigned char dev_idx;
99103
};
100104

105+
struct tas2781_cali_specific {
106+
unsigned char sin_gni[4];
107+
int sin_gni_reg;
108+
bool is_sin_gn_flush;
109+
};
110+
101111
static const char deviceNumber[TASDEVICE_DSP_TAS_MAX_DEVICE] = {
102112
1, 2, 1, 2, 1, 1, 0, 2, 4, 3, 1, 2, 3, 4, 1, 2
103113
};
@@ -2454,6 +2464,84 @@ static int tasdevice_load_data(struct tasdevice_priv *tas_priv,
24542464
return ret;
24552465
}
24562466

2467+
static int tas2781_cali_preproc(struct tasdevice_priv *priv, int i)
2468+
{
2469+
struct tas2781_cali_specific *spec = priv->tasdevice[i].cali_specific;
2470+
struct calidata *cali_data = &priv->cali_data;
2471+
struct cali_reg *p = &cali_data->cali_reg_array;
2472+
unsigned char *data = cali_data->data;
2473+
int rc;
2474+
2475+
/*
2476+
* On TAS2781, if the Speaker calibrated impedance is lower than
2477+
* default value hard-coded inside the TAS2781, it will cuase vol
2478+
* lower than normal. In order to fix this issue, the parameter of
2479+
* SineGainI need updating.
2480+
*/
2481+
if (spec == NULL) {
2482+
int k = i * (cali_data->cali_dat_sz_per_dev + 1);
2483+
int re_org, re_cal, corrected_sin_gn, pg_id;
2484+
unsigned char r0_deflt[4];
2485+
2486+
spec = devm_kzalloc(priv->dev, sizeof(*spec), GFP_KERNEL);
2487+
if (spec == NULL)
2488+
return -ENOMEM;
2489+
priv->tasdevice[i].cali_specific = spec;
2490+
rc = tasdevice_dev_bulk_read(priv, i, p->r0_reg, r0_deflt, 4);
2491+
if (rc < 0) {
2492+
dev_err(priv->dev, "invalid RE from %d = %d\n", i, rc);
2493+
return rc;
2494+
}
2495+
/*
2496+
* SineGainI need to be re-calculated, calculate the high 16
2497+
* bits.
2498+
*/
2499+
re_org = r0_deflt[0] << 8 | r0_deflt[1];
2500+
re_cal = data[k + 1] << 8 | data[k + 2];
2501+
if (re_org > re_cal) {
2502+
rc = tasdevice_dev_read(priv, i, TAS2781_PG_REG,
2503+
&pg_id);
2504+
if (rc < 0) {
2505+
dev_err(priv->dev, "invalid PG id %d = %d\n",
2506+
i, rc);
2507+
return rc;
2508+
}
2509+
2510+
spec->sin_gni_reg = (pg_id == TAS2781_PG_1_0) ?
2511+
TASDEVICE_REG(0, 0x1b, 0x34) :
2512+
TASDEVICE_REG(0, 0x18, 0x1c);
2513+
2514+
rc = tasdevice_dev_bulk_read(priv, i,
2515+
spec->sin_gni_reg,
2516+
spec->sin_gni, 4);
2517+
if (rc < 0) {
2518+
dev_err(priv->dev, "wrong sinegaini %d = %d\n",
2519+
i, rc);
2520+
return rc;
2521+
}
2522+
corrected_sin_gn = re_org * ((spec->sin_gni[0] << 8) +
2523+
spec->sin_gni[1]);
2524+
corrected_sin_gn /= re_cal;
2525+
spec->sin_gni[0] = corrected_sin_gn >> 8;
2526+
spec->sin_gni[1] = corrected_sin_gn & 0xff;
2527+
2528+
spec->is_sin_gn_flush = true;
2529+
}
2530+
}
2531+
2532+
if (spec->is_sin_gn_flush) {
2533+
rc = tasdevice_dev_bulk_write(priv, i, spec->sin_gni_reg,
2534+
spec->sin_gni, 4);
2535+
if (rc < 0) {
2536+
dev_err(priv->dev, "update failed %d = %d\n",
2537+
i, rc);
2538+
return rc;
2539+
}
2540+
}
2541+
2542+
return 0;
2543+
}
2544+
24572545
static void tasdev_load_calibrated_data(struct tasdevice_priv *priv, int i)
24582546
{
24592547
struct calidata *cali_data = &priv->cali_data;
@@ -2469,6 +2557,12 @@ static void tasdev_load_calibrated_data(struct tasdevice_priv *priv, int i)
24692557
}
24702558
k++;
24712559

2560+
if (priv->chip_id == TAS2781) {
2561+
rc = tas2781_cali_preproc(priv, i);
2562+
if (rc < 0)
2563+
return;
2564+
}
2565+
24722566
rc = tasdevice_dev_bulk_write(priv, i, p->r0_reg, &(data[k]), 4);
24732567
if (rc < 0) {
24742568
dev_err(priv->dev, "chn %d r0_reg bulk_wr err = %d\n", i, rc);

0 commit comments

Comments
 (0)