Skip to contentSkip to conversation

ALSA: hda/tas2781: Create an independent lib to save the shared parts for both SPI and I2C driver

PATCH In review Shenghao Ding 2 participants 2 messages May 7, 2025 – May 8, 2025 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: hda/tas2781: Create an independent lib to save the shared parts for both SPI and I2C driver

Some common parts, such as struct tas2781_hda{...} and some audio kcontrols are moved into an independent lib for code cleanup.

---
v1:
- Define a shared struct tas2781_hda{...} for both SPI and I2C HDA driver.
- Move the different part, such as sound controls, into tas2781_hda::priv.
- remove the unused dacpi in struct tas2781_hda{...} for SPI driver.
- Move tas2781_hda_remove to the tas2781-hda-lib.
- Optimize the kcontrols creation in SPI driver, remove the unnecessary kcotnrols

---
 sound/pci/hda/Kconfig           |   7 +
 sound/pci/hda/Makefile          |   2 +
 sound/pci/hda/tas2781_hda.c     | 198 +++++++++++++++
 sound/pci/hda/tas2781_hda.h     |  31 +++
 sound/pci/hda/tas2781_hda_i2c.c | 214 ++---------------
 sound/pci/hda/tas2781_hda_spi.c | 410 ++++++++++++--------------------
 6 files changed, 405 insertions(+), 457 deletions(-)
 create mode 100644 sound/pci/hda/tas2781_hda.c
sound/pci/hda/Kconfig +7 -0
index d5b29b5eb1f6..339c80d2cce5 100644
@@ -180,12 +180,17 @@ config SND_HDA_SCODEC_CS35L56_SPI
 	  Say Y or M here to include CS35L56 amplifier support with
 	  SPI control.
 
+config SND_HDA_SCODEC_TAS2781
+	tristate
+	select SND_HDA_GENERIC
+
 config SND_HDA_SCODEC_TAS2781_I2C
 	tristate "Build TAS2781 HD-audio side codec support for I2C Bus"
 	depends on I2C
 	depends on ACPI
 	depends on EFI
 	depends on SND_SOC
+	select SND_HDA_SCODEC_TAS2781
 	select SND_SOC_TAS2781_COMLIB_I2C
 	select SND_SOC_TAS2781_FMWLIB
 	select CRC32
@@ -202,6 +207,8 @@ config SND_HDA_SCODEC_TAS2781_SPI
 	depends on ACPI
 	depends on EFI
 	depends on SND_SOC
+	select SND_HDA_SCODEC_TAS2781
+	select SND_SOC_TAS2781_COMLIB
 	select SND_SOC_TAS2781_FMWLIB
 	select CRC8
 	select CRC32
sound/pci/hda/Makefile +2 -0
index 13d6c7e63203..5adff1cab101 100644
@@ -38,6 +38,7 @@ snd-hda-scodec-cs35l56-y :=	cs35l56_hda.o
 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-y :=	tas2781_hda.o
 snd-hda-scodec-tas2781-i2c-y :=	tas2781_hda_i2c.o
 snd-hda-scodec-tas2781-spi-y :=	tas2781_hda_spi.o
 
@@ -70,6 +71,7 @@ obj-$(CONFIG_SND_HDA_SCODEC_CS35L56) += snd-hda-scodec-cs35l56.o
 obj-$(CONFIG_SND_HDA_SCODEC_CS35L56_I2C) += snd-hda-scodec-cs35l56-i2c.o
 obj-$(CONFIG_SND_HDA_SCODEC_CS35L56_SPI) += snd-hda-scodec-cs35l56-spi.o
 obj-$(CONFIG_SND_HDA_SCODEC_COMPONENT) += snd-hda-scodec-component.o
+obj-$(CONFIG_SND_HDA_SCODEC_TAS2781) += snd-hda-scodec-tas2781.o
 obj-$(CONFIG_SND_HDA_SCODEC_TAS2781_I2C) += snd-hda-scodec-tas2781-i2c.o
 obj-$(CONFIG_SND_HDA_SCODEC_TAS2781_SPI) += snd-hda-scodec-tas2781-spi.o
 
sound/pci/hda/tas2781_hda.c new file +198 -0

198 lines not on this page · raw message

sound/pci/hda/tas2781_hda.h +31 -0
index 444231f87e53..95229083ce6a 100644
@@ -44,4 +44,35 @@
 	.private_value = xdata, \
 }
 
+struct tas2781_hda {
+	struct device *dev;
+	struct tasdevice_priv *priv;
+	struct snd_kcontrol *dsp_prog_ctl;
+	struct snd_kcontrol *dsp_conf_ctl;
+	struct snd_kcontrol *prof_ctl;
+	enum device_catlog_id catlog_id;
+	void *hda_priv;
+};
+
+void tas2781_hda_remove(struct device *dev,
+	const struct component_ops *ops);
+int tasdevice_info_profile(struct snd_kcontrol *kctl,
+	struct snd_ctl_elem_info *uctl);
+int tasdevice_info_programs(struct snd_kcontrol *kctl,
+	struct snd_ctl_elem_info *uctl);
+int tasdevice_info_config(struct snd_kcontrol *kctl,
+	struct snd_ctl_elem_info *uctl);
+int tasdevice_set_profile_id(struct snd_kcontrol *kctl,
+	struct snd_ctl_elem_value *uctl);
+int tasdevice_get_profile_id(struct snd_kcontrol *kctl,
+	struct snd_ctl_elem_value *uctl);
+int tasdevice_program_get(struct snd_kcontrol *kctl,
+	struct snd_ctl_elem_value *uctl);
+int tasdevice_program_put(struct snd_kcontrol *kctl,
+	struct snd_ctl_elem_value *uctl);
+int tasdevice_config_put(struct snd_kcontrol *kctl,
+	struct snd_ctl_elem_value *uctl);
+int tasdevice_config_get(struct snd_kcontrol *kctl,
+	struct snd_ctl_elem_value *uctl);
+
 #endif
sound/pci/hda/tas2781_hda_i2c.c +17 -197

280 lines not on this page · raw message

sound/pci/hda/tas2781_hda_spi.c +150 -260

546 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw
Quoted 5 lines · Shenghao Ding

Some common parts, such as struct tas2781_hda{...} and some audio kcontrols are moved into an independent lib for code cleanup.

Applied now. Thanks.

Takashi