Skip to content

Commit 315c845

Browse files
committed
ASoC: intel/sdw_utils: Add volume limits to CS35L56
Merge series from Stefan Binding <[email protected]>: Both CS35L56 and CS42L43 have maximum volumes above 0dB. However, for many use cases, this can cause distorted audio, depending various factors, such as other signal-processing elements in the chain, for example if the audio passes through a gain control before reaching the amp or the signal path has been tuned for a particular maximum gain in the amp. In the cases where systems use the soc_sdw_* drivers, audio above the 0dB volume will likely always be distorted, therefore apply a 0dB limit to those devices. Stefan Binding (2): ASoC: intel/sdw_utils: Add volume limit to cs42l43 speakers ASoC: intel/sdw_utils: Add volume limit to cs35l56 speakers include/sound/soc_sdw_utils.h | 1 + sound/soc/sdw_utils/soc_sdw_bridge_cs35l56.c | 4 ++++ sound/soc/sdw_utils/soc_sdw_cs42l43.c | 10 ++++++++ sound/soc/sdw_utils/soc_sdw_cs_amp.c | 24 ++++++++++++++++++++ 4 files changed, 39 insertions(+) -- 2.43.0
2 parents 844af99 + d5463e5 commit 315c845

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

include/sound/soc_sdw_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ int asoc_sdw_cs_amp_init(struct snd_soc_card *card,
226226
bool playback);
227227
int asoc_sdw_cs_spk_feedback_rtd_init(struct snd_soc_pcm_runtime *rtd,
228228
struct snd_soc_dai *dai);
229+
int asoc_sdw_cs35l56_volume_limit(struct snd_soc_card *card, const char *name_prefix);
229230

230231
/* MAXIM codec support */
231232
int asoc_sdw_maxim_init(struct snd_soc_card *card,

sound/soc/sdw_utils/soc_sdw_bridge_cs35l56.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ static int asoc_sdw_bridge_cs35l56_asp_init(struct snd_soc_pcm_runtime *rtd)
6060

6161
/* 4 x 16-bit sample slots and FSYNC=48000, BCLK=3.072 MHz */
6262
for_each_rtd_codec_dais(rtd, i, codec_dai) {
63+
ret = asoc_sdw_cs35l56_volume_limit(card, codec_dai->component->name_prefix);
64+
if (ret)
65+
return ret;
66+
6367
ret = snd_soc_dai_set_tdm_slot(codec_dai, tx_mask, rx_mask, 4, 16);
6468
if (ret < 0)
6569
return ret;

sound/soc/sdw_utils/soc_sdw_cs42l43.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <sound/soc-dapm.h>
2121
#include <sound/soc_sdw_utils.h>
2222

23+
#define CS42L43_SPK_VOLUME_0DB 128 /* 0dB Max */
24+
2325
static const struct snd_soc_dapm_route cs42l43_hs_map[] = {
2426
{ "Headphone", NULL, "cs42l43 AMP3_OUT" },
2527
{ "Headphone", NULL, "cs42l43 AMP4_OUT" },
@@ -117,6 +119,14 @@ int asoc_sdw_cs42l43_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_so
117119
return -ENOMEM;
118120
}
119121

122+
ret = snd_soc_limit_volume(card, "cs42l43 Speaker Digital Volume",
123+
CS42L43_SPK_VOLUME_0DB);
124+
if (ret)
125+
dev_err(card->dev, "cs42l43 speaker volume limit failed: %d\n", ret);
126+
else
127+
dev_info(card->dev, "Setting CS42L43 Speaker volume limit to %d\n",
128+
CS42L43_SPK_VOLUME_0DB);
129+
120130
ret = snd_soc_dapm_add_routes(&card->dapm, cs42l43_spk_map,
121131
ARRAY_SIZE(cs42l43_spk_map));
122132
if (ret)

sound/soc/sdw_utils/soc_sdw_cs_amp.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@
1616

1717
#define CODEC_NAME_SIZE 8
1818
#define CS_AMP_CHANNELS_PER_AMP 4
19+
#define CS35L56_SPK_VOLUME_0DB 400 /* 0dB Max */
20+
21+
int asoc_sdw_cs35l56_volume_limit(struct snd_soc_card *card, const char *name_prefix)
22+
{
23+
char *volume_ctl_name;
24+
int ret;
25+
26+
volume_ctl_name = kasprintf(GFP_KERNEL, "%s Speaker Volume", name_prefix);
27+
if (!volume_ctl_name)
28+
return -ENOMEM;
29+
30+
ret = snd_soc_limit_volume(card, volume_ctl_name, CS35L56_SPK_VOLUME_0DB);
31+
if (ret)
32+
dev_err(card->dev, "%s limit set failed: %d\n", volume_ctl_name, ret);
33+
34+
kfree(volume_ctl_name);
35+
return ret;
36+
}
37+
EXPORT_SYMBOL_NS(asoc_sdw_cs35l56_volume_limit, "SND_SOC_SDW_UTILS");
1938

2039
int asoc_sdw_cs_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
2140
{
@@ -40,6 +59,11 @@ int asoc_sdw_cs_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai
4059

4160
snprintf(widget_name, sizeof(widget_name), "%s SPK",
4261
codec_dai->component->name_prefix);
62+
63+
ret = asoc_sdw_cs35l56_volume_limit(card, codec_dai->component->name_prefix);
64+
if (ret)
65+
return ret;
66+
4367
ret = snd_soc_dapm_add_routes(&card->dapm, &route, 1);
4468
if (ret)
4569
return ret;

0 commit comments

Comments
 (0)