[PATCH v4 3/4] ASoC: sdw_utils: TI amp utility for tac5xx2 family

Niranjan H Y
2026-04-01T13:22:50Z

Add TI amp utility for supporting the tac5xx2 family
of devices to support tac5572, tac5672, tac5682 and
tas2883

Signed-off-by: Niranjan H Y <niranjan.hy@ti.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
---
v4:
- no change

v3:
- no change
---
include/sound/soc_sdw_utils.h | 4 +
sound/soc/sdw_utils/soc_sdw_ti_amp.c | 144 ++++++++++++++++++++++++-
sound/soc/sdw_utils/soc_sdw_utils.c | 151 +++++++++++++++++++++++++++
3 files changed, 298 insertions(+), 1 deletion(-)

diff --git a/include/sound/soc_sdw_utils.h b/include/sound/soc_sdw_utils.h
index 4890831836734..d713ab2f66203 100644
--- a/include/sound/soc_sdw_utils.h
+++ b/include/sound/soc_sdw_utils.h
@@ -272,7 +272,11 @@ int asoc_sdw_ti_amp_init(struct snd_soc_card *card,
struct asoc_sdw_codec_info *info,
bool playback);
int asoc_sdw_ti_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
+int asoc_sdw_ti_tac5xx2_spk_rtd_init(struct snd_soc_pcm_runtime *rtd,
+ struct snd_soc_dai *dai);
int asoc_sdw_ti_amp_initial_settings(struct snd_soc_card *card,
const char *name_prefix);
+int asoc_sdw_ti_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
+int asoc_sdw_ti_sdca_jack_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);

#endif
diff --git a/sound/soc/sdw_utils/soc_sdw_ti_amp.c b/sound/soc/sdw_utils/soc_sdw_ti_amp.c
index 488ef2ef45d4f..514340a3e3f55 100644
--- a/sound/soc/sdw_utils/soc_sdw_ti_amp.c
+++ b/sound/soc/sdw_utils/soc_sdw_ti_amp.c
@@ -7,12 +7,15 @@

#include <linux/device.h>
#include <linux/errno.h>
-#include <sound/soc.h>
+#include <linux/input.h>
+#include <sound/jack.h>
#include <sound/soc-acpi.h>
#include <sound/soc-dai.h>
+#include <sound/soc.h>
#include <sound/soc_sdw_utils.h>

#define TIAMP_SPK_VOLUME_0DB 200
+#define TAC5XX2_WIDGET_NAME_MAX 32

int asoc_sdw_ti_amp_initial_settings(struct snd_soc_card *card,
const char *name_prefix)
@@ -95,3 +98,142 @@ int asoc_sdw_ti_amp_init(struct snd_soc_card *card,
return 0;
}
EXPORT_SYMBOL_NS(asoc_sdw_ti_amp_init, "SND_SOC_SDW_UTILS");
+
+static int asoc_sdw_ti_add_tac5xx2_routes(struct snd_soc_dapm_context *dapm,
+ const char *name_prefix)
+{
+ struct snd_soc_dapm_route routes[2];
+ char left_widget[TAC5XX2_WIDGET_NAME_MAX];
+ char right_widget[TAC5XX2_WIDGET_NAME_MAX];
+ int ret;
+
+ if (strlen(name_prefix) > (TAC5XX2_WIDGET_NAME_MAX - 7))
+ return -ENAMETOOLONG;
+
+ ret = scnprintf(left_widget, sizeof(left_widget), "%s SPK_L", name_prefix);
+ if (ret <= 0)
+ return -EINVAL;
+
+ ret = scnprintf(right_widget, sizeof(right_widget), "%s SPK_R", name_prefix);
+ if (ret <= 0)
+ return -EINVAL;
+
+ routes[0] = (struct snd_soc_dapm_route){"Left Spk", NULL, left_widget};
+ routes[1] = (struct snd_soc_dapm_route){"Right Spk", NULL, right_widget};
+
+ return snd_soc_dapm_add_routes(dapm, routes, ARRAY_SIZE(routes));
+}
+
+int asoc_sdw_ti_tac5xx2_spk_rtd_init(struct snd_soc_pcm_runtime *rtd,
+ struct snd_soc_dai *dai)
+{
+ struct snd_soc_card *card = rtd->card;
+ struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card);
+ int ret, i;
+ struct snd_soc_dai *codec_dai;
+ const char *prefix;
+
+ for_each_rtd_codec_dais(rtd, i, codec_dai) {
+ if (!strstr(codec_dai->name, "tac5") &&
+ !strstr(codec_dai->name, "tas2883"))
+ continue;
+
+ prefix = codec_dai->component->name_prefix;
+ if (!prefix) {
+ dev_warn(card->dev,
+ "No name prefix found for codec DAI: %s\n",
+ codec_dai->name);
+ continue;
+ }
+ ret = asoc_sdw_ti_add_tac5xx2_routes(dapm, prefix);
+ if (ret) {
+ dev_err(card->dev, "Failed to add routes for %s: %d\n",
+ prefix, ret);
+ return ret;
+ }
+ }
+
+ dev_dbg(card->dev, "Added TAC5XX2 speaker routes\n");
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(asoc_sdw_ti_tac5xx2_spk_rtd_init);
+
+int asoc_sdw_ti_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
+{
+ struct snd_soc_card *card = rtd->card;
+ struct snd_soc_component *component;
+ char *mic_name;
+
+ component = dai->component;
+ mic_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s", component->name_prefix);
+ if (!mic_name)
+ return -ENOMEM;
+
+ card->components = devm_kasprintf(card->dev, GFP_KERNEL,
+ "%s mic:%s", card->components,
+ mic_name);
+ if (!card->components)
+ return -ENOMEM;
+
+ dev_dbg(card->dev, "card->components: %s\n", card->components);
+
+ return 0;
+}
+EXPORT_SYMBOL_NS(asoc_sdw_ti_dmic_rtd_init, "SND_SOC_SDW_UTILS");
+
+static struct snd_soc_jack_pin ti_sdca_jack_pins[] = {
+ {
+ .pin = "Headphone",
+ .mask = SND_JACK_HEADPHONE,
+ },
+ {
+ .pin = "Headset Mic",
+ .mask = SND_JACK_MICROPHONE,
+ },
+};
+
+int asoc_sdw_ti_sdca_jack_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
+{
+ struct snd_soc_card *card = rtd->card;
+ struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card);
+ struct snd_soc_component *component;
+ struct snd_soc_jack *jack;
+ int ret;
+
+ component = dai->component;
+
+ card->components = devm_kasprintf(card->dev, GFP_KERNEL,
+ "%s hs:%s", card->components,
+ component->name_prefix);
+ if (!card->components)
+ return -ENOMEM;
+
+ ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
+ SND_JACK_HEADSET | SND_JACK_BTN_0 |
+ SND_JACK_BTN_1 | SND_JACK_BTN_2 |
+ SND_JACK_BTN_3 | SND_JACK_BTN_4,
+ &ctx->sdw_headset,
+ ti_sdca_jack_pins,
+ ARRAY_SIZE(ti_sdca_jack_pins));
+ if (ret) {
+ dev_err(rtd->card->dev, "Jack create failed%d\n", ret);
+ return ret;
+ }
+
+ jack = &ctx->sdw_headset;
+
+ snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
+ snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
+ snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
+ snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
+ snd_jack_set_key(jack->jack, SND_JACK_BTN_4, KEY_NEXTSONG);
+
+ ret = snd_soc_component_set_jack(component, jack, NULL);
+ if (ret)
+ dev_err(rtd->card->dev, "Headset Jack call-back failed: %d\n",
+ ret);
+
+ return ret;
+}
+EXPORT_SYMBOL_NS(asoc_sdw_ti_sdca_jack_rtd_init, "SND_SOC_SDW_UTILS");
diff --git a/sound/soc/sdw_utils/soc_sdw_utils.c b/sound/soc/sdw_utils/soc_sdw_utils.c
index 2807f536eef0c..ffc342c79d5ea 100644
--- a/sound/soc/sdw_utils/soc_sdw_utils.c
+++ b/sound/soc/sdw_utils/soc_sdw_utils.c
@@ -72,6 +72,157 @@ static const struct snd_kcontrol_new rt700_controls[] = {
};

struct asoc_sdw_codec_info codec_info_list[] = {
+ {
+ .vendor_id = 0x0102,
+ .part_id = 0x5572,
+ .name_prefix = "tac5572",
+ .dais = {
+ {
+ /* speaker */
+ .direction = {true, false},
+ .dai_name = "tac5xx2-aif1",
+ .dai_type = SOC_SDW_DAI_TYPE_AMP,
+ .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_UNUSED_DAI_ID},
+ .init = asoc_sdw_ti_amp_init,
+ .rtd_init = asoc_sdw_ti_tac5xx2_spk_rtd_init,
+ .controls = lr_spk_controls,
+ .num_controls = ARRAY_SIZE(lr_spk_controls),
+ .widgets = lr_spk_widgets,
+ .num_widgets = ARRAY_SIZE(lr_spk_widgets),
+ },
+ {
+ /* mic */
+ .direction = {false, true},
+ .dai_name = "tac5xx2-aif2",
+ .dai_type = SOC_SDW_DAI_TYPE_MIC,
+ .dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
+ .rtd_init = asoc_sdw_ti_dmic_rtd_init,
+ },
+ {
+ /* UAJ */
+ .direction = {true, true},
+ .dai_name = "tac5xx2-aif3",
+ .dai_type = SOC_SDW_DAI_TYPE_JACK,
+ .dailink = {SOC_SDW_JACK_OUT_DAI_ID, SOC_SDW_JACK_IN_DAI_ID},
+ .controls = generic_jack_controls,
+ .num_controls = ARRAY_SIZE(generic_jack_controls),
+ .widgets = generic_jack_widgets,
+ .num_widgets = ARRAY_SIZE(generic_jack_widgets),
+ .rtd_init = asoc_sdw_ti_sdca_jack_rtd_init,
+ },
+ },
+ .dai_num = 3,
+ },
+ {
+ .vendor_id = 0x0102,
+ .part_id = 0x5672,
+ .name_prefix = "tac5672",
+ .dais = {
+ {
+ /* speaker with IV sense feedback */
+ .direction = {true, true},
+ .dai_name = "tac5xx2-aif1",
+ .dai_type = SOC_SDW_DAI_TYPE_AMP,
+ .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_AMP_IN_DAI_ID},
+ .init = asoc_sdw_ti_amp_init,
+ .rtd_init = asoc_sdw_ti_tac5xx2_spk_rtd_init,
+ .controls = lr_spk_controls,
+ .num_controls = ARRAY_SIZE(lr_spk_controls),
+ .widgets = lr_spk_widgets,
+ .num_widgets = ARRAY_SIZE(lr_spk_widgets),
+ },
+ {
+ /* mic */
+ .direction = {false, true},
+ .dai_name = "tac5xx2-aif2",
+ .dai_type = SOC_SDW_DAI_TYPE_MIC,
+ .dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
+ .rtd_init = asoc_sdw_ti_dmic_rtd_init,
+ },
+ {
+ /* UAJ */
+ .direction = {true, true},
+ .dai_name = "tac5xx2-aif3",
+ .dai_type = SOC_SDW_DAI_TYPE_JACK,
+ .dailink = {SOC_SDW_JACK_OUT_DAI_ID, SOC_SDW_JACK_IN_DAI_ID},
+ .controls = generic_jack_controls,
+ .num_controls = ARRAY_SIZE(generic_jack_controls),
+ .widgets = generic_jack_widgets,
+ .num_widgets = ARRAY_SIZE(generic_jack_widgets),
+ .rtd_init = asoc_sdw_ti_sdca_jack_rtd_init,
+ },
+ },
+ .dai_num = 3,
+ },
+ {
+ .vendor_id = 0x0102,
+ .part_id = 0x5682,
+ .name_prefix = "tac5682",
+ .dais = {
+ {
+ /* speaker with echo reference feedback */
+ .direction = {true, true},
+ .dai_name = "tac5xx2-aif1",
+ .dai_type = SOC_SDW_DAI_TYPE_AMP,
+ .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_AMP_IN_DAI_ID},
+ .init = asoc_sdw_ti_amp_init,
+ .rtd_init = asoc_sdw_ti_tac5xx2_spk_rtd_init,
+ .controls = lr_spk_controls,
+ .num_controls = ARRAY_SIZE(lr_spk_controls),
+ .widgets = lr_spk_widgets,
+ .num_widgets = ARRAY_SIZE(lr_spk_widgets),
+ },
+ {
+ /* mic */
+ .direction = {false, true},
+ .dai_name = "tac5xx2-aif2",
+ .dai_type = SOC_SDW_DAI_TYPE_MIC,
+ .dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
+ .rtd_init = asoc_sdw_ti_dmic_rtd_init,
+ },
+ {
+ /* UAJ */
+ .direction = {true, true},
+ .dai_name = "tac5xx2-aif3",
+ .dai_type = SOC_SDW_DAI_TYPE_JACK,
+ .dailink = {SOC_SDW_JACK_OUT_DAI_ID, SOC_SDW_JACK_IN_DAI_ID},
+ .controls = generic_jack_controls,
+ .num_controls = ARRAY_SIZE(generic_jack_controls),
+ .widgets = generic_jack_widgets,
+ .num_widgets = ARRAY_SIZE(generic_jack_widgets),
+ .rtd_init = asoc_sdw_ti_sdca_jack_rtd_init,
+ },
+ },
+ .dai_num = 3,
+ },
+ {
+ .vendor_id = 0x0102,
+ .part_id = 0x2883,
+ .name_prefix = "tas2883",
+ .dais = {
+ {
+ .direction = {true, false},
+ .dai_name = "tac5xx2-aif1",
+ .dai_type = SOC_SDW_DAI_TYPE_AMP,
+ .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_UNUSED_DAI_ID},
+ .init = asoc_sdw_ti_amp_init,
+ .rtd_init = asoc_sdw_ti_tac5xx2_spk_rtd_init,
+ .controls = lr_spk_controls,
+ .num_controls = ARRAY_SIZE(lr_spk_controls),
+ .widgets = lr_spk_widgets,
+ .num_widgets = ARRAY_SIZE(lr_spk_widgets),
+ },
+ {
+ /* mic */
+ .direction = {false, true},
+ .dai_name = "tac5xx2-aif2",
+ .dai_type = SOC_SDW_DAI_TYPE_MIC,
+ .dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
+ .rtd_init = asoc_sdw_ti_dmic_rtd_init,
+ },
+ },
+ .dai_num = 2,
+ },
{
.vendor_id = 0x0102,
.part_id = 0x0000, /* TAS2783A */
--
2.34.1