Skip to content

Commit 8b9a614

Browse files
committed
ASoc: tas2783A: machine driver amp utility for TI devices
Signed-off-by: Niranjan H Y <[email protected]>
1 parent d23ce1d commit 8b9a614

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

include/sound/soc_sdw_utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,5 +248,13 @@ int asoc_sdw_cs42l43_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_so
248248
int asoc_sdw_cs42l43_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
249249
int asoc_sdw_cs_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
250250
int asoc_sdw_maxim_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
251+
/* TI */
252+
int asoc_sdw_ti_amp_init(struct snd_soc_card *card,
253+
struct snd_soc_dai_link *dai_links,
254+
struct asoc_sdw_codec_info *info,
255+
bool playback);
256+
int asoc_sdw_ti_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
257+
int asoc_sdw_ti_amp_initial_settings(struct snd_soc_card *card,
258+
const char *name_prefix);
251259

252260
#endif

sound/soc/sdw_utils/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ snd-soc-sdw-utils-y := soc_sdw_utils.o soc_sdw_dmic.o soc_sdw_rt_dmic.o \
66
soc_sdw_bridge_cs35l56.o \
77
soc_sdw_cs42l42.o soc_sdw_cs42l43.o \
88
soc_sdw_cs_amp.o \
9-
soc_sdw_maxim.o
9+
soc_sdw_maxim.o \
10+
soc_sdw_ti_amp.o
1011
obj-$(CONFIG_SND_SOC_SDW_UTILS) += snd-soc-sdw-utils.o
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
// Copyright (c) 2025 Texas Instruments Inc.
3+
4+
/*
5+
* soc_sdw_ti_amp - Helpers to handle TI's soundwire based codecs
6+
*/
7+
8+
#include <linux/device.h>
9+
#include <linux/errno.h>
10+
#include <sound/soc.h>
11+
#include <sound/soc-acpi.h>
12+
#include <sound/soc-dai.h>
13+
#include <sound/soc_sdw_utils.h>
14+
15+
#define TIAMP_SPK_VOLUME_0DB 200
16+
17+
int asoc_sdw_ti_amp_initial_settings(struct snd_soc_card *card,
18+
const char *name_prefix)
19+
{
20+
char *volume_ctl_name;
21+
int ret;
22+
23+
volume_ctl_name = kasprintf(GFP_KERNEL, "%s Speaker Volume",
24+
name_prefix);
25+
if (!volume_ctl_name)
26+
return -ENOMEM;
27+
28+
ret = snd_soc_limit_volume(card, volume_ctl_name,
29+
TIAMP_SPK_VOLUME_0DB);
30+
if (ret)
31+
dev_err(card->dev,
32+
"%s update failed %d\n",
33+
volume_ctl_name, ret);
34+
35+
kfree(volume_ctl_name);
36+
return 0;
37+
}
38+
EXPORT_SYMBOL_NS(asoc_sdw_ti_amp_initial_settings, "SND_SOC_SDW_UTILS");
39+
40+
int asoc_sdw_ti_spk_rtd_init(struct snd_soc_pcm_runtime *rtd,
41+
struct snd_soc_dai *dai)
42+
{
43+
struct snd_soc_card *card = rtd->card;
44+
char widget_name[16];
45+
char speaker[16];
46+
struct snd_soc_dapm_route route = {speaker, NULL, widget_name};
47+
struct snd_soc_dai *codec_dai;
48+
const char *prefix;
49+
int i, ret = 0;
50+
51+
for_each_rtd_codec_dais(rtd, i, codec_dai) {
52+
if (!strstr(codec_dai->name, "tas2783"))
53+
continue;
54+
55+
prefix = codec_dai->component->name_prefix;
56+
if (!strncmp(prefix, "tas2783-1", strlen("tas2783-1"))) {
57+
strncpy(speaker, "Left Spk", strlen("Left Spk") + 1);
58+
} else if (!strncmp(prefix, "tas2783-2", strlen("tas2783-2"))) {
59+
strncpy(speaker, "Right Spk", strlen("Right Spk") + 1);
60+
} else {
61+
ret = -EINVAL;
62+
dev_err(card->dev, "unhandled prefix %s", prefix);
63+
break;
64+
}
65+
66+
snprintf(widget_name, sizeof(widget_name), "%s SPK", prefix);
67+
ret = asoc_sdw_ti_amp_initial_settings(card, prefix);
68+
if (ret)
69+
return ret;
70+
71+
ret = snd_soc_dapm_add_routes(&card->dapm, &route, 1);
72+
if (ret)
73+
return ret;
74+
}
75+
76+
return ret;
77+
}
78+
EXPORT_SYMBOL_NS(asoc_sdw_ti_spk_rtd_init, "SND_SOC_SDW_UTILS");
79+
80+
int asoc_sdw_ti_amp_init(struct snd_soc_card *card,
81+
struct snd_soc_dai_link *dai_links,
82+
struct asoc_sdw_codec_info *info,
83+
bool playback)
84+
{
85+
if (!playback)
86+
return 0;
87+
88+
info->amp_num++;
89+
90+
return 0;
91+
}
92+
EXPORT_SYMBOL_NS(asoc_sdw_ti_amp_init, "SND_SOC_SDW_UTILS");
93+

sound/soc/sdw_utils/soc_sdw_utils.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ struct asoc_sdw_codec_info codec_info_list[] = {
6666
.dai_name = "tas2783-codec",
6767
.dai_type = SOC_SDW_DAI_TYPE_AMP,
6868
.dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_AMP_IN_DAI_ID},
69+
.init = asoc_sdw_ti_amp_init,
70+
.rtd_init = asoc_sdw_ti_spk_rtd_init,
71+
.controls = maxim_controls,
72+
.num_controls = ARRAY_SIZE(maxim_controls),
73+
.widgets = maxim_widgets,
74+
.num_widgets = ARRAY_SIZE(maxim_widgets),
6975
},
7076
},
7177
.dai_num = 1,

0 commit comments

Comments
 (0)