Skip to contentSkip to conversation

ALSA: hda/tas2781: Remove tas2781_spi_fwlib.c and leverage SND_SOC_TAS2781_FMWLIB

PATCH Superseded Shenghao Ding 3 participants 3 messages Apr 24, 2025 – Apr 25, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Shenghao Ding

author maintainer
#0 lore raw

PATCH 1/1 ALSA: hda/tas2781: Remove tas2781_spi_fwlib.c and leverage SND_SOC_TAS2781_FMWLIB

Most codes in tas2781_spi_fwlib.c are same as tas2781-fmwlib.c, mainly for firmware parsing, only differece is the register reading, bit update and book switching in i2c and spi. The main purpose of this patch is for code cleaup and arrange the shared part for i2c and spi.

---
v1:
- Move the definition of TASDEVICE_CRC8_POLYNOMIAL to tas2781.h for both SPI use.
- Add isspi flag in the struct tasdevice_priv to distinguish SPI or I2C.
- Define three register-read related methods due to the difference between SPI and I2C. For SPI-based TAS2781, it will have one-byte delay to read memory-mapped registers. During init, these three method will be initialized as spi or i2c register-read methods.
- Define book-switching method due to the difference between SPI and I2C.
- Add select SND_SOC_TAS2781_COMLIB & SND_SOC_TAS2781_FMWLIB for tas2781 hda spi driver in Kconfig.
- remove tas2781-spi.h & tas2781_spi_fwlib.c.
- remove tas2781_spi_fwlib.o in Makefile
- Move the definition of TASDEVICE_CALIBRATION_DATA_NAME.
- Remove the useless calib_data definition for code cleanup.
- Define the TASDEV_CALIB_N definition in tas2781_hda.h for hda driver calibration.
- Use TASDEV_CALIB_N instead of TAS2563_CAL_N.
- Include tas2781.h instead of tas2781-dsp.h in tas2781_hda_spi.c.
- Remove #include "tas2781-spi.h" in tas2781_hda_spi.c.
- Move the macro definitions only for hda spi tas2781 driver into tas2781_hda_spi.c.
- Add read_flag_mask and reg_shift setting in tasdevice_regmap.

---
 include/sound/tas2781.h           |   13 +
 sound/pci/hda/Kconfig             |    2 +
 sound/pci/hda/Makefile            |    2 +-
 sound/pci/hda/tas2781-spi.h       |  157 ---
 sound/pci/hda/tas2781_hda.h       |    3 +
 sound/pci/hda/tas2781_hda_i2c.c   |   25 +-
 sound/pci/hda/tas2781_hda_spi.c   |  540 ++++----
 sound/pci/hda/tas2781_spi_fwlib.c | 2006 -----------------------------
 sound/soc/codecs/tas2781-comlib.c |   18 +-
 sound/soc/codecs/tas2781-fmwlib.c |   17 +-
 10 files changed, 320 insertions(+), 2463 deletions(-)
 delete mode 100644 sound/pci/hda/tas2781-spi.h
 delete mode 100644 sound/pci/hda/tas2781_spi_fwlib.c
include/sound/tas2781.h +13 -0
index eff011444cc8..a86a82f4c544 100644
@@ -32,6 +32,8 @@
 	SNDRV_PCM_FMTBIT_S24_LE | \
 	SNDRV_PCM_FMTBIT_S32_LE)
 
+#define TASDEVICE_CRC8_POLYNOMIAL		0x4d
+
 /* PAGE Control Register (available in page0 of each book) */
 #define TASDEVICE_PAGE_SELECT		0x00
 #define TASDEVICE_BOOKCTL_PAGE		0x00
@@ -193,6 +195,7 @@ struct tasdevice_priv {
 	bool force_fwload_status;
 	bool playback_started;
 	bool isacpi;
+	bool isspi;
 	bool is_user_space_calidata;
 	unsigned int global_addr;
 
@@ -210,6 +213,16 @@ struct tasdevice_priv {
 	int (*tasdevice_load_block)(struct tasdevice_priv *tas_priv,
 		struct tasdev_blk *block);
 
+	int (*change_chn_book)(struct tasdevice_priv *tas_priv,
+		unsigned short chn, int book);
+	int (*update_bits)(struct tasdevice_priv *tas_priv,
+		unsigned short chn, unsigned int reg, unsigned int mask,
+		unsigned int value);
+	int (*dev_read)(struct tasdevice_priv *tas_priv,
+		unsigned short chn, unsigned int reg, unsigned int *value);
+	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);
 };
sound/pci/hda/Kconfig +2 -0
index 9c427270ff4f..90f12e0227eb 100644
@@ -210,6 +210,8 @@ config SND_HDA_SCODEC_TAS2781_SPI
 	depends on ACPI
 	depends on EFI
 	depends on SND_SOC
+	select SND_SOC_TAS2781_COMLIB
+	select SND_SOC_TAS2781_FMWLIB
 	select CRC32
 	help
 	  Say Y or M here to include TAS2781 SPI HD-audio side codec support
sound/pci/hda/Makefile +1 -1
index 210c406dfbc5..72ef3a64d9db 100644
@@ -40,7 +40,7 @@ snd-hda-scodec-cs35l56-spi-y :=	cs35l56_hda_spi.o
 snd-hda-cs-dsp-ctls-y :=	hda_cs_dsp_ctl.o
 snd-hda-scodec-component-y :=	hda_component.o
 snd-hda-scodec-tas2781-i2c-y :=	tas2781_hda_i2c.o
-snd-hda-scodec-tas2781-spi-y :=	tas2781_hda_spi.o tas2781_spi_fwlib.o
+snd-hda-scodec-tas2781-spi-y :=	tas2781_hda_spi.o
 
 # common driver
 obj-$(CONFIG_SND_HDA) := snd-hda-codec.o
sound/pci/hda/tas2781-spi.h deleted +0 -157

157 lines not on this page · raw message

sound/pci/hda/tas2781_hda.h +3 -0
index 32d27b202591..444231f87e53 100644
@@ -9,6 +9,9 @@
 
 #include <sound/asound.h>
 
+#define TASDEVICE_CALIBRATION_DATA_NAME	L"CALI_DATA"
+#define TASDEV_CALIB_N			5
+
 /*
  * No standard control callbacks for SNDRV_CTL_ELEM_IFACE_CARD
  * Define two controls, one is Volume control callbacks, the other is
sound/pci/hda/tas2781_hda_i2c.c +7 -18
index 9d94ae5fcfe0..1be86d1b4a53 100644
@@ -34,15 +34,6 @@
 
 #define TASDEVICE_SPEAKER_CALIBRATION_SIZE	20
 
-enum calib_data {
-	R0_VAL = 0,
-	INV_R0,
-	R0LOW,
-	POWER,
-	TLIM,
-	CALIB_MAX
-};
-
 #define TAS2563_MAX_CHANNELS	4
 
 #define TAS2563_CAL_POWER	TASDEVICE_REG(0, 0x0d, 0x3c)
@@ -50,17 +41,15 @@ enum calib_data {
 #define TAS2563_CAL_INVR0	TASDEVICE_REG(0, 0x0f, 0x40)
 #define TAS2563_CAL_R0_LOW	TASDEVICE_REG(0, 0x0f, 0x48)
 #define TAS2563_CAL_TLIM	TASDEVICE_REG(0, 0x10, 0x14)
-#define TAS2563_CAL_N		5
 #define TAS2563_CAL_DATA_SIZE	4
 #define TAS2563_CAL_CH_SIZE	20
 #define TAS2563_CAL_ARRAY_SIZE	80
 
-static unsigned int cal_regs[TAS2563_CAL_N] = {
+static unsigned int cal_regs[TASDEV_CALIB_N] = {
 	TAS2563_CAL_POWER, TAS2563_CAL_R0, TAS2563_CAL_INVR0,
 	TAS2563_CAL_R0_LOW, TAS2563_CAL_TLIM,
 };
 
-
 struct tas2781_hda {
 	struct device *dev;
 	struct tasdevice_priv *priv;
@@ -475,7 +464,7 @@ static void tas2563_apply_calib(struct tasdevice_priv *tas_priv)
 	int ret;
 
 	for (int i = 0; i < tas_priv->ndev; i++) {
-		for (int j = 0; j < TAS2563_CAL_N; ++j) {
+		for (int j = 0; j < TASDEV_CALIB_N; ++j) {
 			data = cpu_to_be32(
 				*(uint32_t *)&tas_priv->cali_data.data[offset]);
 			ret = tasdevice_dev_bulk_write(tas_priv, i, cal_regs[j],
@@ -493,7 +482,7 @@ static int tas2563_save_calibration(struct tasdevice_priv *tas_priv)
 	static efi_guid_t efi_guid = EFI_GUID(0x1f52d2a1, 0xbb3a, 0x457d, 0xbc,
 		0x09, 0x43, 0xa3, 0xf4, 0x31, 0x0a, 0x92);
 
-	static efi_char16_t *efi_vars[TAS2563_MAX_CHANNELS][TAS2563_CAL_N] = {
+	static efi_char16_t *efi_vars[TAS2563_MAX_CHANNELS][TASDEV_CALIB_N] = {
 		{ L"Power_1", L"R0_1", L"InvR0_1", L"R0_Low_1", L"TLim_1" },
 		{ L"Power_2", L"R0_2", L"InvR0_2", L"R0_Low_2", L"TLim_2" },
 		{ L"Power_3", L"R0_3", L"InvR0_3", L"R0_Low_3", L"TLim_3" },
@@ -511,7 +500,7 @@ static int tas2563_save_calibration(struct tasdevice_priv *tas_priv)
 		return -ENOMEM;
 
 	for (int i = 0; i < tas_priv->ndev; ++i) {
-		for (int j = 0; j < TAS2563_CAL_N; ++j) {
+		for (int j = 0; j < TASDEV_CALIB_N; ++j) {
 			status = efi.get_variable(efi_vars[i][j],
 				&efi_guid, &attr, &max_size,
 				&tas_priv->cali_data.data[offset]);
@@ -535,7 +524,7 @@ static void tas2781_apply_calib(struct tasdevice_priv *tas_priv)
 {
 	struct calidata *cali_data = &tas_priv->cali_data;
 	struct cali_reg *r = &cali_data->cali_reg_array;
-	unsigned int cali_reg[CALIB_MAX] = {
+	unsigned int cali_reg[TASDEV_CALIB_N] = {
 		TASDEVICE_REG(0, 0x17, 0x74),
 		TASDEVICE_REG(0, 0x18, 0x0c),
 		TASDEVICE_REG(0, 0x18, 0x14),
@@ -555,7 +544,7 @@ static void tas2781_apply_calib(struct tasdevice_priv *tas_priv)
 	}
 
 	for (i = 0; i < tas_priv->ndev; i++) {
-		for (j = 0; j < CALIB_MAX; j++) {
+		for (j = 0; j < TASDEV_CALIB_N; j++) {
 			data = cpu_to_be32(
 				*(uint32_t *)&tas_priv->cali_data.data[oft]);
 			rc = tasdevice_dev_bulk_write(tas_priv, i,
@@ -578,7 +567,7 @@ static int tas2781_save_calibration(struct tasdevice_priv *tas_priv)
 {
 	efi_guid_t efi_guid = EFI_GUID(0x02f9af02, 0x7734, 0x4233, 0xb4, 0x3d,
 		0x93, 0xfe, 0x5a, 0xa3, 0x5d, 0xb3);
-	static efi_char16_t efi_name[] = L"CALI_DATA";
+	static efi_char16_t efi_name[] = TASDEVICE_CALIBRATION_DATA_NAME;
 	unsigned int attr, crc;
 	unsigned int *tmp_val;
 	efi_status_t status;
sound/pci/hda/tas2781_hda_spi.c +272 -268

875 lines not on this page · raw message

sound/pci/hda/tas2781_spi_fwlib.c deleted +0 -2006

1,831 lines not on this page · raw message

sound/soc/codecs/tas2781-comlib.c +11 -7
index 1e0b3aa95749..4df2edcfac40 100644

Lines of this file are not shown. View the raw message.

sound/soc/codecs/tas2781-fmwlib.c +11 -6
index 13a197468193..3dd76aff1b6e 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.43.0

Part of the diff is not shown here. View the raw message.

maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Shenghao Ding

Most codes in tas2781_spi_fwlib.c are same as tas2781-fmwlib.c, mainly for firmware parsing, only differece is the register reading, bit update and book switching in i2c and spi. The main purpose of this patch is for code cleaup and arrange the shared part for i2c and spi.

#2 lore raw
In reply to Shenghao Ding
kernel test robot noticed the following build warnings:

Hi Shenghao,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tiwai-sound/for-next]
[also build test WARNING on next-20250424]
[cannot apply to tiwai-sound/for-linus broonie-sound/for-next linus/master v6.15-rc3] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Shenghao-Ding/ALSA-hda-tas2781-Remove-tas2781_spi_fwlib-c-and-leverage-SND_SOC_TAS2781_FMWLIB/20250424-214314
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
patch link:    https://lore.kernel.org/r/20250424133814.216-1-shenghao-ding%40ti.com
patch subject: [PATCH v1] ALSA: hda/tas2781: Remove tas2781_spi_fwlib.c and leverage SND_SOC_TAS2781_FMWLIB
config: x86_64-kismet-CONFIG_SND_SOC_TAS2781_COMLIB-CONFIG_SND_HDA_SCODEC_TAS2781_SPI-0-0 (https://download.01.org/0day-ci/archive/20250426/[email protected]/config)
reproduce: (https://download.01.org/0day-ci/archive/20250426/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

kismet warnings: (new ones prefixed by >>)

>> kismet: WARNING: unmet direct dependencies detected for SND_SOC_TAS2781_COMLIB when selected by SND_HDA_SCODEC_TAS2781_SPI

WARNING: unmet direct dependencies detected for SND_SOC_TAS2781_COMLIB
Depends on [n]: SOUND [=y] && SND [=y] && SND_SOC [=y] && I2C [=n]
Selected by [y]:
- SND_HDA_SCODEC_TAS2781_SPI [=y] && SOUND [=y] && SND [=y] && SND_HDA [=y] && SPI_MASTER [=y] && ACPI [=y] && EFI [=y] && SND_SOC [=y]

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki