ALSA: hda/tas2781: Remove tas2781_spi_fwlib.c and leverage SND_SOC_TAS2781_FMWLIB
Subsystems (3)
Shenghao Ding
maintainerPATCH v2 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.
---
v2:
- Split tas2781_comlib into two parts. One is the shared lib for both SPI and I2C. The other is the lib for I2C use only.
- Adjust the lib dependencies in Konfig and Makefile in HDA and CODECS
- | Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
v1:
- Move the definition of TASDEVICE_CRC8_POLYNOMIAL to tas2781.h for both SPI and I2C.
- 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-comlib-i2c.h | 37 + include/sound/tas2781.h | 45 +- sound/pci/hda/Kconfig | 4 +- 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 | 26 +- sound/pci/hda/tas2781_hda_spi.c | 542 +++---- sound/pci/hda/tas2781_spi_fwlib.c | 2006 ------------------------- sound/soc/codecs/Kconfig | 8 +- sound/soc/codecs/Makefile | 2 + sound/soc/codecs/tas2781-comlib-i2c.c | 375 +++++ sound/soc/codecs/tas2781-comlib.c | 406 +---- sound/soc/codecs/tas2781-fmwlib.c | 17 +- sound/soc/codecs/tas2781-i2c.c | 1 + 15 files changed, 768 insertions(+), 2863 deletions(-) create mode 100644 include/sound/tas2781-comlib-i2c.h delete mode 100644 sound/pci/hda/tas2781-spi.h delete mode 100644 sound/pci/hda/tas2781_spi_fwlib.c create mode 100644 sound/soc/codecs/tas2781-comlib-i2c.c
include/sound/tas2781-comlib-i2c.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +// +// ALSA SoC Texas Instruments TAS2563/TAS2781 Audio Smart Amplifier +// +// Copyright (C) 2025 Texas Instruments Incorporated +// https://www.ti.com +// +// The TAS2563/TAS2781 driver implements a flexible and configurable +// algo coefficient setting for one, two, or even multiple +// TAS2563/TAS2781 chips. +// +// Author: Shenghao Ding <[email protected]> +// + +#ifndef __TAS2781_COMLIB_I2C_H__ +#define __TAS2781_COMLIB_I2C_H__ + +void tasdevice_reset (struct tasdevice_priv *tas_dev); +int tascodec_init (struct tasdevice_priv *tas_priv,void *codec, +struct module *module, +void (*cont)(const struct firmware *fw,void *context)); +struct tasdevice_priv *tasdevice_kzalloc (struct i2c_client *i2c); +int tasdevice_init (struct tasdevice_priv *tas_priv); +int tasdev_chn_switch (struct tasdevice_priv *tas_priv, +unsigned short chn); +int tasdevice_dev_update_bits ( +struct tasdevice_priv *tasdevice,unsigned short chn, +unsigned int reg,unsigned int mask,unsigned int value); +int tasdevice_amp_putvol (struct tasdevice_priv *tas_priv, +struct snd_ctl_elem_value *ucontrol,struct soc_mixer_control *mc); +int tasdevice_amp_getvol (struct tasdevice_priv *tas_priv, +struct snd_ctl_elem_value *ucontrol,struct soc_mixer_control *mc); +int tasdevice_digital_getvol (struct tasdevice_priv *tas_priv, +struct snd_ctl_elem_value *ucontrol,struct soc_mixer_control *mc); +int tasdevice_digital_putvol (struct tasdevice_priv *tas_priv, +struct snd_ctl_elem_value *ucontrol,struct soc_mixer_control *mc); +#endif /* __TAS2781_COMLIB_I2C_H__ */
include/sound/tas2781.h +19 -26
72 lines not on this page · raw message
sound/pci/hda/Kconfig +3 -1
@@ -186,7 +186,7 @@ config SND_HDA_SCODEC_TAS2781_I2C depends on ACPI depends on EFI depends on SND_SOC - select SND_SOC_TAS2781_COMLIB + select SND_SOC_TAS2781_COMLIB_I2C select SND_SOC_TAS2781_FMWLIB select CRC32 help
@@ -202,6 +202,8 @@ config SND_HDA_SCODEC_TAS2781_SPI depends on ACPI depends on EFI depends on SND_SOC + select SND_SOC_TAS2781_FMWLIB + select CRC8 select CRC32 help Say Y or M here to include TAS2781 SPI HD-audio side codec support
sound/pci/hda/Makefile +1 -1
@@ -39,7 +39,7 @@ snd-hda-scodec-cs35l56-i2c-y := cs35l56_hda_i2c.o snd-hda-scodec-cs35l56-spi-y := cs35l56_hda_spi.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
@@ -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 +8 -18
@@ -22,6 +22,7 @@#include <sound/hda_codec.h> #include <sound/soc.h> #include <sound/tas2781.h> +#include <sound/tas2781-comlib-i2c.h> #include <sound/tlv.h> #include <sound/tas2781-tlv.h>
@@ -34,15 +35,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 +42,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 +465,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 +483,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 +501,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 +525,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 +545,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 +568,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 -270
877 lines not on this page · raw message
sound/pci/hda/tas2781_spi_fwlib.c deleted +0 -2006
1,736 lines not on this page · raw message
sound/soc/codecs/tas2781-comlib-i2c.c new file +375 -0
375 lines not on this page · raw message
sound/soc/codecs/tas2781-comlib.c +30 -376
406 lines not on this page · 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.
Quoted 8 lines · Shenghao Ding
Most codes in
tas2781_spi_fwlib.care same astas2781-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.Signed-off-by Shenghao Ding <[email protected]>Acked-by Mark Brown <[email protected]>
Applied now to for-next branch.
thanks,
Takashi