Skip to contentSkip to conversation

ALSA: hda/tas2781: Move and unified the calibrated-data getting function for SPI and I2C into the tas2781_hda lib.

PATCH In review Shenghao Ding 2 participants 2 messages May 22, 2025

Subsystems (3)
lore
Share & tools
lore

Shenghao Ding

author maintainer
#0 lore raw

PATCH 1/1 ALSA: hda/tas2781: Move and unified the calibrated-data getting function for SPI and I2C into the tas2781_hda lib.

Calibration data getting function for SPI and I2C HDA drivers are almost same, which read the calibration data from UEFI. To put them into tas2781_hda lib for code cleanup is more reasonable than to still keep them in the codec driver. For tas2781 codec driver, there're two different sources for calibrated data, one is from bin file, generated in factory test, requested and read in codec driver side; the other is from user space during device bootup.

---
v1:
- Correct the comment in tas2781.h.
- Move enum device_catlog_id {...} from tas2781.h into tas2781_hda.h.
- Move (*save_calibration)() and (*apply_calibration)() from tas2781.h into tas2781_hda.h.
- Move the declaration of tas2781_save_calibration into tas2781_hda.h.
- Define tasdev_fct_efi_guid[] and put all the supported devices into the tas2781_hda.c.
- Optimize and cleanup tas2563_save_calibration.
- Move the definition of TASDEVICE_CMD_XXX from tas2781.h to tas2781_fmwlib.c
- Drop tas2781_save_calibration() in tas2781-comlib.c.
- Move the implementation of tasdevice_remove to tas2781-comlib.c

---
 include/sound/tas2781.h           |  10 --
 sound/pci/hda/tas2781_hda.c       | 179 ++++++++++++++++++++++
 sound/pci/hda/tas2781_hda.h       |  12 ++
 sound/pci/hda/tas2781_hda_i2c.c   | 245 ++++++++++--------------------
 sound/pci/hda/tas2781_hda_spi.c   | 167 +-------------------
 sound/soc/codecs/tas2781-comlib.c |  15 --
 6 files changed, 272 insertions(+), 356 deletions(-)
include/sound/tas2781.h +0 -10
index 9dc178a7486a..40cd3bd079b5 100644
@@ -116,11 +116,6 @@ enum dspbin_type {
 	TASDEV_BETA,
 };
 
-enum device_catlog_id {
-	LENOVO = 0,
-	OTHERS
-};
-
 struct bulk_reg_val {
 	int reg;
 	unsigned char val[4];
@@ -190,7 +185,6 @@ struct tasdevice_priv {
 	struct regmap *regmap;
 	struct device *dev;
 
-	enum device_catlog_id catlog_id;
 	unsigned char cal_binaryname[TASDEVICE_MAX_CHANNELS][64];
 	unsigned char crc8_lkp_tbl[CRC8_TABLE_SIZE];
 	unsigned char coef_binaryname[64];
@@ -241,8 +235,6 @@ struct tasdevice_priv {
 	int (*dev_bulk_read)(struct tasdevice_priv *tas_priv,
 		unsigned short chn, unsigned int reg, unsigned char *p_data,
 		unsigned int n_length);
-	int (*save_calibration)(struct tasdevice_priv *tas_priv);
-	void (*apply_calibration)(struct tasdevice_priv *tas_priv);
 };
 
 int tasdevice_dev_read(struct tasdevice_priv *tas_priv,
@@ -256,6 +248,4 @@ int tasdevice_dev_bulk_write(
 	struct tasdevice_priv *tas_priv, unsigned short chn,
 	unsigned int reg, unsigned char *p_data, unsigned int n_length);
 void tasdevice_remove(struct tasdevice_priv *tas_priv);
-int tasdevice_save_calibration(struct tasdevice_priv *tas_priv);
-void tasdevice_apply_calibration(struct tasdevice_priv *tas_priv);
 #endif /* __TAS2781_H__ */
sound/pci/hda/tas2781_hda.c +179 -0

185 lines not on this page · raw message

sound/pci/hda/tas2781_hda.h +12 -0
index 95229083ce6a..575a701c8dfb 100644
@@ -9,6 +9,8 @@
 
 #include <sound/asound.h>
 
+/* Flag of calibration registers address. */
+#define TASDEV_UEFI_CALI_REG_ADDR_FLG	BIT(7)
 #define TASDEVICE_CALIBRATION_DATA_NAME	L"CALI_DATA"
 #define TASDEV_CALIB_N			5
 
@@ -44,6 +46,13 @@
 	.private_value = xdata, \
 }
 
+enum device_catlog_id {
+	DELL = 0,
+	HP,
+	LENOVO,
+	OTHERS
+};
+
 struct tas2781_hda {
 	struct device *dev;
 	struct tasdevice_priv *priv;
@@ -54,6 +63,9 @@ struct tas2781_hda {
 	void *hda_priv;
 };
 
+extern const efi_guid_t tasdev_fct_efi_guid[];
+
+int tas2781_save_calibration(struct tas2781_hda *p);
 void tas2781_hda_remove(struct device *dev,
 	const struct component_ops *ops);
 int tasdevice_info_profile(struct snd_kcontrol *kctl,
sound/pci/hda/tas2781_hda_i2c.c +80 -165

316 lines not on this page · raw message

sound/pci/hda/tas2781_hda_spi.c +1 -166

185 lines not on this page · raw message

sound/soc/codecs/tas2781-comlib.c +0 -15
index 076c1d955972..4cec9f8a00af 100644
@@ -130,21 +130,6 @@ int tasdevice_dev_bulk_write(
 }
 EXPORT_SYMBOL_GPL(tasdevice_dev_bulk_write);
 
-int tasdevice_save_calibration(struct tasdevice_priv *tas_priv)
-{
-	if (tas_priv->save_calibration)
-		return tas_priv->save_calibration(tas_priv);
-	return -EINVAL;
-}
-EXPORT_SYMBOL_GPL(tasdevice_save_calibration);
-
-void tasdevice_apply_calibration(struct tasdevice_priv *tas_priv)
-{
-	if (tas_priv->apply_calibration && tas_priv->cali_data.total_sz)
-		tas_priv->apply_calibration(tas_priv);
-}
-EXPORT_SYMBOL_GPL(tasdevice_apply_calibration);
-
 static void tasdev_dsp_prog_blk_remove(struct tasdevice_prog *prog)
 {
 	struct tasdevice_data *tas_dt;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 10 lines · Shenghao Ding

Calibration data getting function for SPI and I2C HDA drivers are almost same, which read the calibration data from UEFI. To put them into tas2781_hda lib for code cleanup is more reasonable than to still keep them in the codec driver. For tas2781 codec driver, there're two different sources for calibrated data, one is from bin file, generated in factory test, requested and read in codec driver side; the other is from user space during device bootup.

Applied now. Thanks.

Takashi