Skip to content

Commit d2d377f

Browse files
brentlubroonie
authored andcommitted
ASoC: Intel: nau8825/rt5682: move speaker widget to common modules
Two machine drivers sof_rt5682 and sof_nau8825 always register two speaker widgets 'Left Spk' and 'Right Spk' regardless the actual number of speakers. Move the widget registration to speaker common modules to avoid useless speaker widgets for 1 or 4 speaker boards. Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com> Signed-off-by: Brent Lu <brent.lu@intel.com> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20240426152529.38345-2-pierre-louis.bossart@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 466c8c4 commit d2d377f

4 files changed

Lines changed: 180 additions & 15 deletions

File tree

sound/soc/intel/boards/sof_maxim_common.c

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@
1212
#include <uapi/sound/asound.h>
1313
#include "sof_maxim_common.h"
1414

15+
/*
16+
* Common structures and functions
17+
*/
18+
static const struct snd_kcontrol_new maxim_2spk_kcontrols[] = {
19+
SOC_DAPM_PIN_SWITCH("Left Spk"),
20+
SOC_DAPM_PIN_SWITCH("Right Spk"),
21+
22+
};
23+
24+
static const struct snd_soc_dapm_widget maxim_2spk_widgets[] = {
25+
SND_SOC_DAPM_SPK("Left Spk", NULL),
26+
SND_SOC_DAPM_SPK("Right Spk", NULL),
27+
};
28+
1529
/* helper function to get the number of specific codec */
1630
static unsigned int get_num_codecs(const char *hid)
1731
{
@@ -135,12 +149,40 @@ EXPORT_SYMBOL_NS(max_98373_ops, SND_SOC_INTEL_SOF_MAXIM_COMMON);
135149
int max_98373_spk_codec_init(struct snd_soc_pcm_runtime *rtd)
136150
{
137151
struct snd_soc_card *card = rtd->card;
152+
unsigned int num_codecs = get_num_codecs(MAX_98373_ACPI_HID);
138153
int ret;
139154

140-
ret = snd_soc_dapm_add_routes(&card->dapm, max_98373_dapm_routes,
141-
ARRAY_SIZE(max_98373_dapm_routes));
142-
if (ret)
143-
dev_err(rtd->dev, "Speaker map addition failed: %d\n", ret);
155+
switch (num_codecs) {
156+
case 2:
157+
ret = snd_soc_dapm_new_controls(&card->dapm, maxim_2spk_widgets,
158+
ARRAY_SIZE(maxim_2spk_widgets));
159+
if (ret) {
160+
dev_err(rtd->dev, "fail to add max98373 widgets, ret %d\n",
161+
ret);
162+
return ret;
163+
}
164+
165+
ret = snd_soc_add_card_controls(card, maxim_2spk_kcontrols,
166+
ARRAY_SIZE(maxim_2spk_kcontrols));
167+
if (ret) {
168+
dev_err(rtd->dev, "fail to add max98373 kcontrols, ret %d\n",
169+
ret);
170+
return ret;
171+
}
172+
173+
ret = snd_soc_dapm_add_routes(&card->dapm, max_98373_dapm_routes,
174+
ARRAY_SIZE(max_98373_dapm_routes));
175+
if (ret) {
176+
dev_err(rtd->dev, "fail to add max98373 routes, ret %d\n",
177+
ret);
178+
return ret;
179+
}
180+
break;
181+
default:
182+
dev_err(rtd->dev, "max98373: invalid num_codecs %d\n", num_codecs);
183+
return -EINVAL;
184+
}
185+
144186
return ret;
145187
}
146188
EXPORT_SYMBOL_NS(max_98373_spk_codec_init, SND_SOC_INTEL_SOF_MAXIM_COMMON);
@@ -287,6 +329,22 @@ static int max_98390_init(struct snd_soc_pcm_runtime *rtd)
287329
fallthrough;
288330
case 2:
289331
/* add regular speakers dapm route */
332+
ret = snd_soc_dapm_new_controls(&card->dapm, maxim_2spk_widgets,
333+
ARRAY_SIZE(maxim_2spk_widgets));
334+
if (ret) {
335+
dev_err(rtd->dev, "fail to add max98390 woofer widgets, ret %d\n",
336+
ret);
337+
return ret;
338+
}
339+
340+
ret = snd_soc_add_card_controls(card, maxim_2spk_kcontrols,
341+
ARRAY_SIZE(maxim_2spk_kcontrols));
342+
if (ret) {
343+
dev_err(rtd->dev, "fail to add max98390 woofer kcontrols, ret %d\n",
344+
ret);
345+
return ret;
346+
}
347+
290348
ret = snd_soc_dapm_add_routes(&card->dapm, max_98390_dapm_routes,
291349
ARRAY_SIZE(max_98390_dapm_routes));
292350
if (ret) {

sound/soc/intel/boards/sof_nau8825.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,11 @@ static int sof_card_late_probe(struct snd_soc_card *card)
140140
static const struct snd_kcontrol_new sof_controls[] = {
141141
SOC_DAPM_PIN_SWITCH("Headphone Jack"),
142142
SOC_DAPM_PIN_SWITCH("Headset Mic"),
143-
SOC_DAPM_PIN_SWITCH("Left Spk"),
144-
SOC_DAPM_PIN_SWITCH("Right Spk"),
145143
};
146144

147145
static const struct snd_soc_dapm_widget sof_widgets[] = {
148146
SND_SOC_DAPM_HP("Headphone Jack", NULL),
149147
SND_SOC_DAPM_MIC("Headset Mic", NULL),
150-
SND_SOC_DAPM_SPK("Left Spk", NULL),
151-
SND_SOC_DAPM_SPK("Right Spk", NULL),
152148
};
153149

154150
static const struct snd_soc_dapm_route sof_map[] = {

sound/soc/intel/boards/sof_realtek_common.c

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121
/*
2222
* Common structures and functions
2323
*/
24+
static const struct snd_kcontrol_new realtek_2spk_kcontrols[] = {
25+
SOC_DAPM_PIN_SWITCH("Left Spk"),
26+
SOC_DAPM_PIN_SWITCH("Right Spk"),
27+
28+
};
29+
30+
static const struct snd_soc_dapm_widget realtek_2spk_widgets[] = {
31+
SND_SOC_DAPM_SPK("Left Spk", NULL),
32+
SND_SOC_DAPM_SPK("Right Spk", NULL),
33+
};
34+
2435
static const struct snd_kcontrol_new realtek_4spk_kcontrols[] = {
2536
SOC_DAPM_PIN_SWITCH("WL Ext Spk"),
2637
SOC_DAPM_PIN_SWITCH("WR Ext Spk"),
@@ -181,6 +192,22 @@ static int rt1011_init(struct snd_soc_pcm_runtime *rtd)
181192
switch (num_codecs) {
182193
case 2:
183194
if (!soc_intel_is_cml()) {
195+
ret = snd_soc_dapm_new_controls(&card->dapm, realtek_2spk_widgets,
196+
ARRAY_SIZE(realtek_2spk_widgets));
197+
if (ret) {
198+
dev_err(rtd->dev, "fail to add rt1011 widgets, ret %d\n",
199+
ret);
200+
return ret;
201+
}
202+
203+
ret = snd_soc_add_card_controls(card, realtek_2spk_kcontrols,
204+
ARRAY_SIZE(realtek_2spk_kcontrols));
205+
if (ret) {
206+
dev_err(rtd->dev, "fail to add rt1011 kcontrols, ret %d\n",
207+
ret);
208+
return ret;
209+
}
210+
184211
ret = snd_soc_dapm_add_routes(&card->dapm, speaker_map_lr,
185212
ARRAY_SIZE(speaker_map_lr));
186213
if (ret) {
@@ -357,6 +384,20 @@ static int rt1015p_init(struct snd_soc_pcm_runtime *rtd)
357384
struct snd_soc_card *card = rtd->card;
358385
int ret;
359386

387+
ret = snd_soc_dapm_new_controls(&card->dapm, realtek_2spk_widgets,
388+
ARRAY_SIZE(realtek_2spk_widgets));
389+
if (ret) {
390+
dev_err(rtd->dev, "fail to add rt1015p widgets, ret %d\n", ret);
391+
return ret;
392+
}
393+
394+
ret = snd_soc_add_card_controls(card, realtek_2spk_kcontrols,
395+
ARRAY_SIZE(realtek_2spk_kcontrols));
396+
if (ret) {
397+
dev_err(rtd->dev, "fail to add rt1015p kcontrols, ret %d\n", ret);
398+
return ret;
399+
}
400+
360401
if (rt1015p_get_num_codecs() == 1)
361402
ret = snd_soc_dapm_add_routes(&card->dapm, rt1015p_1dev_dapm_routes,
362403
ARRAY_SIZE(rt1015p_1dev_dapm_routes));
@@ -486,8 +527,42 @@ static struct snd_soc_dai_link_component rt1015_components[] = {
486527

487528
static int speaker_codec_init_lr(struct snd_soc_pcm_runtime *rtd)
488529
{
489-
return snd_soc_dapm_add_routes(&rtd->card->dapm, speaker_map_lr,
490-
ARRAY_SIZE(speaker_map_lr));
530+
struct snd_soc_card *card = rtd->card;
531+
unsigned int num_codecs = get_num_codecs(RT1015_ACPI_HID);
532+
int ret;
533+
534+
switch (num_codecs) {
535+
case 2:
536+
ret = snd_soc_dapm_new_controls(&card->dapm, realtek_2spk_widgets,
537+
ARRAY_SIZE(realtek_2spk_widgets));
538+
if (ret) {
539+
dev_err(rtd->dev, "fail to add rt1015 widgets, ret %d\n",
540+
ret);
541+
return ret;
542+
}
543+
544+
ret = snd_soc_add_card_controls(card, realtek_2spk_kcontrols,
545+
ARRAY_SIZE(realtek_2spk_kcontrols));
546+
if (ret) {
547+
dev_err(rtd->dev, "fail to add rt1015 kcontrols, ret %d\n",
548+
ret);
549+
return ret;
550+
}
551+
552+
ret = snd_soc_dapm_add_routes(&rtd->card->dapm, speaker_map_lr,
553+
ARRAY_SIZE(speaker_map_lr));
554+
if (ret) {
555+
dev_err(rtd->dev, "fail to add rt1015 routes, ret %d\n",
556+
ret);
557+
return ret;
558+
}
559+
break;
560+
default:
561+
dev_err(rtd->dev, "rt1015: invalid num_codecs %d\n", num_codecs);
562+
return -EINVAL;
563+
}
564+
565+
return ret;
491566
}
492567

493568
void sof_rt1015_codec_conf(struct snd_soc_card *card)
@@ -624,6 +699,20 @@ static int rt1019p_init(struct snd_soc_pcm_runtime *rtd)
624699
struct snd_soc_card *card = rtd->card;
625700
int ret;
626701

702+
ret = snd_soc_dapm_new_controls(&card->dapm, realtek_2spk_widgets,
703+
ARRAY_SIZE(realtek_2spk_widgets));
704+
if (ret) {
705+
dev_err(rtd->dev, "fail to add rt1019p widgets, ret %d\n", ret);
706+
return ret;
707+
}
708+
709+
ret = snd_soc_add_card_controls(card, realtek_2spk_kcontrols,
710+
ARRAY_SIZE(realtek_2spk_kcontrols));
711+
if (ret) {
712+
dev_err(rtd->dev, "fail to add rt1019p kcontrols, ret %d\n", ret);
713+
return ret;
714+
}
715+
627716
ret = snd_soc_dapm_add_routes(&card->dapm, rt1019p_dapm_routes,
628717
ARRAY_SIZE(rt1019p_dapm_routes));
629718
if (ret) {

sound/soc/intel/boards/sof_rt5682.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,16 +431,11 @@ static int sof_card_late_probe(struct snd_soc_card *card)
431431
static const struct snd_kcontrol_new sof_controls[] = {
432432
SOC_DAPM_PIN_SWITCH("Headphone Jack"),
433433
SOC_DAPM_PIN_SWITCH("Headset Mic"),
434-
SOC_DAPM_PIN_SWITCH("Left Spk"),
435-
SOC_DAPM_PIN_SWITCH("Right Spk"),
436-
437434
};
438435

439436
static const struct snd_soc_dapm_widget sof_widgets[] = {
440437
SND_SOC_DAPM_HP("Headphone Jack", NULL),
441438
SND_SOC_DAPM_MIC("Headset Mic", NULL),
442-
SND_SOC_DAPM_SPK("Left Spk", NULL),
443-
SND_SOC_DAPM_SPK("Right Spk", NULL),
444439
};
445440

446441
static const struct snd_soc_dapm_route sof_map[] = {
@@ -452,6 +447,17 @@ static const struct snd_soc_dapm_route sof_map[] = {
452447
{ "IN1P", NULL, "Headset Mic" },
453448
};
454449

450+
static const struct snd_kcontrol_new rt5650_spk_kcontrols[] = {
451+
SOC_DAPM_PIN_SWITCH("Left Spk"),
452+
SOC_DAPM_PIN_SWITCH("Right Spk"),
453+
454+
};
455+
456+
static const struct snd_soc_dapm_widget rt5650_spk_widgets[] = {
457+
SND_SOC_DAPM_SPK("Left Spk", NULL),
458+
SND_SOC_DAPM_SPK("Right Spk", NULL),
459+
};
460+
455461
static const struct snd_soc_dapm_route rt5650_spk_dapm_routes[] = {
456462
/* speaker */
457463
{ "Left Spk", NULL, "SPOL" },
@@ -463,6 +469,22 @@ static int rt5650_spk_init(struct snd_soc_pcm_runtime *rtd)
463469
struct snd_soc_card *card = rtd->card;
464470
int ret;
465471

472+
ret = snd_soc_dapm_new_controls(&card->dapm, rt5650_spk_widgets,
473+
ARRAY_SIZE(rt5650_spk_widgets));
474+
if (ret) {
475+
dev_err(rtd->dev, "fail to add rt5650 spk widgets, ret %d\n",
476+
ret);
477+
return ret;
478+
}
479+
480+
ret = snd_soc_add_card_controls(card, rt5650_spk_kcontrols,
481+
ARRAY_SIZE(rt5650_spk_kcontrols));
482+
if (ret) {
483+
dev_err(rtd->dev, "fail to add rt5650 spk kcontrols, ret %d\n",
484+
ret);
485+
return ret;
486+
}
487+
466488
ret = snd_soc_dapm_add_routes(&card->dapm, rt5650_spk_dapm_routes,
467489
ARRAY_SIZE(rt5650_spk_dapm_routes));
468490
if (ret)

0 commit comments

Comments
 (0)