Skip to content

Commit f316c9d

Browse files
macchianbroonie
authored andcommitted
ASoC: Intel: boards: add max98390 2/4 speakers support
support 2 hw boards. 1. SSP2 connects max98390, 2 speakers. 2. SSP1 connects max98390, 2/4 speakers. 2 or 4 speakers playback add echo reference capture add bt offload support add DMI_OEM_STRING for board variants add ALC5682I-VS support Signed-off-by: Mark Hsieh <mark_hsieh@wistron.corp-partner.google.com> Signed-off-by: Mac Chiang <mac.chiang@intel.com> Signed-off-by: Kieth Tzeng <keith.tzeng@quantatw.com> Signed-off-by: Brent Lu <brent.lu@intel.com> Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20211125030453.4382-1-mac.chiang@intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 91745b0 commit f316c9d

6 files changed

Lines changed: 291 additions & 0 deletions

File tree

sound/soc/intel/boards/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ config SND_SOC_INTEL_SOF_RT5682_MACH
467467
(MFD_INTEL_LPSS || COMPILE_TEST)) ||\
468468
(SND_SOC_SOF_BAYTRAIL && (X86_INTEL_LPSS || COMPILE_TEST))
469469
select SND_SOC_MAX98373_I2C
470+
select SND_SOC_MAX98390
470471
select SND_SOC_RT1011
471472
select SND_SOC_RT1015
472473
select SND_SOC_RT1015P

sound/soc/intel/boards/sof_maxim_common.c

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/string.h>
66
#include <sound/pcm.h>
77
#include <sound/soc.h>
8+
#include <sound/soc-acpi.h>
89
#include <sound/soc-dai.h>
910
#include <sound/soc-dapm.h>
1011
#include <uapi/sound/asound.h>
@@ -133,6 +134,185 @@ void max_98373_set_codec_conf(struct snd_soc_card *card)
133134
}
134135
EXPORT_SYMBOL_NS(max_98373_set_codec_conf, SND_SOC_INTEL_SOF_MAXIM_COMMON);
135136

137+
/*
138+
* Maxim MAX98390
139+
*/
140+
const struct snd_soc_dapm_route max_98390_dapm_routes[] = {
141+
/* speaker */
142+
{ "Left Spk", NULL, "Left BE_OUT" },
143+
{ "Right Spk", NULL, "Right BE_OUT" },
144+
};
145+
146+
static const struct snd_kcontrol_new max_98390_tt_kcontrols[] = {
147+
SOC_DAPM_PIN_SWITCH("TL Spk"),
148+
SOC_DAPM_PIN_SWITCH("TR Spk"),
149+
};
150+
151+
static const struct snd_soc_dapm_widget max_98390_tt_dapm_widgets[] = {
152+
SND_SOC_DAPM_SPK("TL Spk", NULL),
153+
SND_SOC_DAPM_SPK("TR Spk", NULL),
154+
};
155+
156+
const struct snd_soc_dapm_route max_98390_tt_dapm_routes[] = {
157+
/* Tweeter speaker */
158+
{ "TL Spk", NULL, "Tweeter Left BE_OUT" },
159+
{ "TR Spk", NULL, "Tweeter Right BE_OUT" },
160+
};
161+
162+
static struct snd_soc_codec_conf max_98390_codec_conf[] = {
163+
{
164+
.dlc = COMP_CODEC_CONF(MAX_98390_DEV0_NAME),
165+
.name_prefix = "Right",
166+
},
167+
{
168+
.dlc = COMP_CODEC_CONF(MAX_98390_DEV1_NAME),
169+
.name_prefix = "Left",
170+
},
171+
};
172+
173+
static struct snd_soc_codec_conf max_98390_4spk_codec_conf[] = {
174+
{
175+
.dlc = COMP_CODEC_CONF(MAX_98390_DEV0_NAME),
176+
.name_prefix = "Right",
177+
},
178+
{
179+
.dlc = COMP_CODEC_CONF(MAX_98390_DEV1_NAME),
180+
.name_prefix = "Left",
181+
},
182+
{
183+
.dlc = COMP_CODEC_CONF(MAX_98390_DEV2_NAME),
184+
.name_prefix = "Tweeter Right",
185+
},
186+
{
187+
.dlc = COMP_CODEC_CONF(MAX_98390_DEV3_NAME),
188+
.name_prefix = "Tweeter Left",
189+
},
190+
};
191+
192+
struct snd_soc_dai_link_component max_98390_components[] = {
193+
{
194+
.name = MAX_98390_DEV0_NAME,
195+
.dai_name = MAX_98390_CODEC_DAI,
196+
},
197+
{
198+
.name = MAX_98390_DEV1_NAME,
199+
.dai_name = MAX_98390_CODEC_DAI,
200+
},
201+
};
202+
EXPORT_SYMBOL_NS(max_98390_components, SND_SOC_INTEL_SOF_MAXIM_COMMON);
203+
204+
struct snd_soc_dai_link_component max_98390_4spk_components[] = {
205+
{
206+
.name = MAX_98390_DEV0_NAME,
207+
.dai_name = MAX_98390_CODEC_DAI,
208+
},
209+
{
210+
.name = MAX_98390_DEV1_NAME,
211+
.dai_name = MAX_98390_CODEC_DAI,
212+
},
213+
{
214+
.name = MAX_98390_DEV2_NAME,
215+
.dai_name = MAX_98390_CODEC_DAI,
216+
},
217+
{
218+
.name = MAX_98390_DEV3_NAME,
219+
.dai_name = MAX_98390_CODEC_DAI,
220+
},
221+
};
222+
EXPORT_SYMBOL_NS(max_98390_4spk_components, SND_SOC_INTEL_SOF_MAXIM_COMMON);
223+
224+
static int max_98390_hw_params(struct snd_pcm_substream *substream,
225+
struct snd_pcm_hw_params *params)
226+
{
227+
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
228+
struct snd_soc_dai *codec_dai;
229+
int i;
230+
231+
for_each_rtd_codec_dais(rtd, i, codec_dai) {
232+
if (i >= ARRAY_SIZE(max_98390_4spk_components)) {
233+
dev_err(codec_dai->dev, "invalid codec index %d\n", i);
234+
return -ENODEV;
235+
}
236+
237+
if (!strcmp(codec_dai->component->name, MAX_98390_DEV0_NAME)) {
238+
/* DEV0 tdm slot configuration Right */
239+
snd_soc_dai_set_tdm_slot(codec_dai, 0x01, 3, 4, 32);
240+
}
241+
if (!strcmp(codec_dai->component->name, MAX_98390_DEV1_NAME)) {
242+
/* DEV1 tdm slot configuration Left */
243+
snd_soc_dai_set_tdm_slot(codec_dai, 0x02, 3, 4, 32);
244+
}
245+
246+
if (!strcmp(codec_dai->component->name, MAX_98390_DEV2_NAME)) {
247+
/* DEVi2 tdm slot configuration Tweeter Right */
248+
snd_soc_dai_set_tdm_slot(codec_dai, 0x04, 3, 4, 32);
249+
}
250+
if (!strcmp(codec_dai->component->name, MAX_98390_DEV3_NAME)) {
251+
/* DEV3 tdm slot configuration Tweeter Left */
252+
snd_soc_dai_set_tdm_slot(codec_dai, 0x08, 3, 4, 32);
253+
}
254+
}
255+
return 0;
256+
}
257+
258+
int max_98390_spk_codec_init(struct snd_soc_pcm_runtime *rtd)
259+
{
260+
struct snd_soc_card *card = rtd->card;
261+
int ret;
262+
263+
/* add regular speakers dapm route */
264+
ret = snd_soc_dapm_add_routes(&card->dapm, max_98390_dapm_routes,
265+
ARRAY_SIZE(max_98390_dapm_routes));
266+
if (ret) {
267+
dev_err(rtd->dev, "unable to add Left/Right Speaker dapm, ret %d\n", ret);
268+
return ret;
269+
}
270+
271+
/* add widgets/controls/dapm for tweeter speakers */
272+
if (acpi_dev_present("MX98390", "3", -1)) {
273+
ret = snd_soc_dapm_new_controls(&card->dapm, max_98390_tt_dapm_widgets,
274+
ARRAY_SIZE(max_98390_tt_dapm_widgets));
275+
276+
if (ret) {
277+
dev_err(rtd->dev, "unable to add tweeter dapm controls, ret %d\n", ret);
278+
/* Don't need to add routes if widget addition failed */
279+
return ret;
280+
}
281+
282+
ret = snd_soc_add_card_controls(card, max_98390_tt_kcontrols,
283+
ARRAY_SIZE(max_98390_tt_kcontrols));
284+
if (ret) {
285+
dev_err(rtd->dev, "unable to add tweeter card controls, ret %d\n", ret);
286+
return ret;
287+
}
288+
289+
ret = snd_soc_dapm_add_routes(&card->dapm, max_98390_tt_dapm_routes,
290+
ARRAY_SIZE(max_98390_tt_dapm_routes));
291+
if (ret)
292+
dev_err(rtd->dev,
293+
"unable to add Tweeter Left/Right Speaker dapm, ret %d\n", ret);
294+
}
295+
return ret;
296+
}
297+
EXPORT_SYMBOL_NS(max_98390_spk_codec_init, SND_SOC_INTEL_SOF_MAXIM_COMMON);
298+
299+
const struct snd_soc_ops max_98390_ops = {
300+
.hw_params = max_98390_hw_params,
301+
};
302+
EXPORT_SYMBOL_NS(max_98390_ops, SND_SOC_INTEL_SOF_MAXIM_COMMON);
303+
304+
void max_98390_set_codec_conf(struct snd_soc_card *card, int ch)
305+
{
306+
if (ch == ARRAY_SIZE(max_98390_4spk_codec_conf)) {
307+
card->codec_conf = max_98390_4spk_codec_conf;
308+
card->num_configs = ARRAY_SIZE(max_98390_4spk_codec_conf);
309+
} else {
310+
card->codec_conf = max_98390_codec_conf;
311+
card->num_configs = ARRAY_SIZE(max_98390_codec_conf);
312+
}
313+
}
314+
EXPORT_SYMBOL_NS(max_98390_set_codec_conf, SND_SOC_INTEL_SOF_MAXIM_COMMON);
315+
136316
/*
137317
* Maxim MAX98357A/MAX98360A
138318
*/

sound/soc/intel/boards/sof_maxim_common.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ int max_98373_spk_codec_init(struct snd_soc_pcm_runtime *rtd);
2424
void max_98373_set_codec_conf(struct snd_soc_card *card);
2525
int max_98373_trigger(struct snd_pcm_substream *substream, int cmd);
2626

27+
/*
28+
* Maxim MAX98390
29+
*/
30+
#define MAX_98390_CODEC_DAI "max98390-aif1"
31+
#define MAX_98390_DEV0_NAME "i2c-MX98390:00"
32+
#define MAX_98390_DEV1_NAME "i2c-MX98390:01"
33+
#define MAX_98390_DEV2_NAME "i2c-MX98390:02"
34+
#define MAX_98390_DEV3_NAME "i2c-MX98390:03"
35+
36+
extern struct snd_soc_dai_link_component max_98390_components[2];
37+
extern struct snd_soc_dai_link_component max_98390_4spk_components[4];
38+
extern const struct snd_soc_ops max_98390_ops;
39+
40+
void max_98390_set_codec_conf(struct snd_soc_card *card, int ch);
41+
int max_98390_spk_codec_init(struct snd_soc_pcm_runtime *rtd);
42+
2743
/*
2844
* Maxim MAX98357A/MAX98360A
2945
*/

sound/soc/intel/boards/sof_rt5682.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
(((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK)
6060
#define SOF_SSP_BT_OFFLOAD_PRESENT BIT(22)
6161
#define SOF_RT5682S_HEADPHONE_CODEC_PRESENT BIT(23)
62+
#define SOF_MAX98390_SPEAKER_AMP_PRESENT BIT(24)
63+
#define SOF_MAX98390_TWEETER_SPEAKER_PRESENT BIT(25)
64+
6265

6366
/* Default: MCLK on, MCLK 19.2M, SSP0 */
6467
static unsigned long sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
@@ -179,6 +182,36 @@ static const struct dmi_system_id sof_rt5682_quirk_table[] = {
179182
SOF_RT5682_SSP_AMP(2) |
180183
SOF_RT5682_NUM_HDMIDEV(4)),
181184
},
185+
{
186+
.callback = sof_rt5682_quirk_cb,
187+
.matches = {
188+
DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
189+
DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98390_ALC5682I_I2S"),
190+
},
191+
.driver_data = (void *)(SOF_RT5682_MCLK_EN |
192+
SOF_RT5682_SSP_CODEC(0) |
193+
SOF_SPEAKER_AMP_PRESENT |
194+
SOF_MAX98390_SPEAKER_AMP_PRESENT |
195+
SOF_RT5682_SSP_AMP(2) |
196+
SOF_RT5682_NUM_HDMIDEV(4)),
197+
},
198+
{
199+
.callback = sof_rt5682_quirk_cb,
200+
.matches = {
201+
DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
202+
DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98390_ALC5682I_I2S_4SPK"),
203+
},
204+
.driver_data = (void *)(SOF_RT5682_MCLK_EN |
205+
SOF_RT5682_SSP_CODEC(0) |
206+
SOF_SPEAKER_AMP_PRESENT |
207+
SOF_MAX98390_SPEAKER_AMP_PRESENT |
208+
SOF_MAX98390_TWEETER_SPEAKER_PRESENT |
209+
SOF_RT5682_SSP_AMP(1) |
210+
SOF_RT5682_NUM_HDMIDEV(4) |
211+
SOF_BT_OFFLOAD_SSP(2) |
212+
SOF_SSP_BT_OFFLOAD_PRESENT),
213+
214+
},
182215
{}
183216
};
184217

@@ -486,6 +519,7 @@ static int sof_card_late_probe(struct snd_soc_card *card)
486519
if (err < 0)
487520
return err;
488521
}
522+
489523
return hdac_hdmi_jack_port_init(component, &card->dapm);
490524
}
491525

@@ -784,6 +818,20 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
784818
} else if (sof_rt5682_quirk &
785819
SOF_RT1011_SPEAKER_AMP_PRESENT) {
786820
sof_rt1011_dai_link(&links[id]);
821+
} else if (sof_rt5682_quirk &
822+
SOF_MAX98390_SPEAKER_AMP_PRESENT) {
823+
if (sof_rt5682_quirk &
824+
SOF_MAX98390_TWEETER_SPEAKER_PRESENT) {
825+
links[id].codecs = max_98390_4spk_components;
826+
links[id].num_codecs = ARRAY_SIZE(max_98390_4spk_components);
827+
} else {
828+
links[id].codecs = max_98390_components;
829+
links[id].num_codecs = ARRAY_SIZE(max_98390_components);
830+
}
831+
links[id].init = max_98390_spk_codec_init;
832+
links[id].ops = &max_98390_ops;
833+
links[id].dpcm_capture = 1;
834+
787835
} else {
788836
max_98357a_dai_link(&links[id]);
789837
}
@@ -868,6 +916,10 @@ static int sof_audio_probe(struct platform_device *pdev)
868916
if (acpi_dev_present("RTL5682", NULL, -1))
869917
sof_rt5682_quirk |= SOF_RT5682S_HEADPHONE_CODEC_PRESENT;
870918

919+
/* Detect the headset codec variant to support machines in DMI quirk */
920+
if (acpi_dev_present("RTL5682", NULL, -1))
921+
sof_rt5682_quirk |= SOF_RT5682S_HEADPHONE_CODEC_PRESENT;
922+
871923
if (soc_intel_is_byt() || soc_intel_is_cht()) {
872924
is_legacy_cpu = 1;
873925
dmic_be_num = 0;
@@ -924,6 +976,14 @@ static int sof_audio_probe(struct platform_device *pdev)
924976
sof_rt1011_codec_conf(&sof_audio_card_rt5682);
925977
else if (sof_rt5682_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT)
926978
sof_rt1015p_codec_conf(&sof_audio_card_rt5682);
979+
else if (sof_rt5682_quirk & SOF_MAX98390_SPEAKER_AMP_PRESENT) {
980+
if (sof_rt5682_quirk & SOF_MAX98390_TWEETER_SPEAKER_PRESENT)
981+
max_98390_set_codec_conf(&sof_audio_card_rt5682,
982+
ARRAY_SIZE(max_98390_4spk_components));
983+
else
984+
max_98390_set_codec_conf(&sof_audio_card_rt5682,
985+
ARRAY_SIZE(max_98390_components));
986+
}
927987

928988
if (sof_rt5682_quirk & SOF_SSP_BT_OFFLOAD_PRESENT)
929989
sof_audio_card_rt5682.num_links++;
@@ -1050,6 +1110,17 @@ static const struct platform_device_id board_ids[] = {
10501110
SOF_RT5682_SSP_AMP(2) |
10511111
SOF_RT5682_NUM_HDMIDEV(4)),
10521112
},
1113+
{
1114+
.name = "adl_max98390_rt5682",
1115+
.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1116+
SOF_RT5682_SSP_CODEC(0) |
1117+
SOF_SPEAKER_AMP_PRESENT |
1118+
SOF_MAX98390_SPEAKER_AMP_PRESENT |
1119+
SOF_RT5682_SSP_AMP(1) |
1120+
SOF_RT5682_NUM_HDMIDEV(4) |
1121+
SOF_BT_OFFLOAD_SSP(2) |
1122+
SOF_SSP_BT_OFFLOAD_PRESENT),
1123+
},
10531124
{
10541125
.name = "adl_mx98360_rt5682",
10551126
.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
@@ -1080,6 +1151,7 @@ MODULE_DESCRIPTION("SOF Audio Machine driver");
10801151
MODULE_AUTHOR("Bard Liao <bard.liao@intel.com>");
10811152
MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
10821153
MODULE_AUTHOR("Brent Lu <brent.lu@intel.com>");
1154+
MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
10831155
MODULE_LICENSE("GPL v2");
10841156
MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
10851157
MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);

sound/soc/intel/common/soc-acpi-intel-adl-match.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,11 @@ static const struct snd_soc_acpi_codecs adl_rt1019p_amp = {
379379
.codecs = {"RTL1019"}
380380
};
381381

382+
static const struct snd_soc_acpi_codecs adl_max98390_amp = {
383+
.num_codecs = 1,
384+
.codecs = {"MX98390"}
385+
};
386+
382387
struct snd_soc_acpi_mach snd_soc_acpi_intel_adl_machines[] = {
383388
{
384389
.comp_ids = &adl_rt5682_rt5682s_hp,
@@ -434,6 +439,14 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_adl_machines[] = {
434439
.sof_fw_filename = "sof-adl.ri",
435440
.sof_tplg_filename = "sof-adl-nau8825.tplg",
436441
},
442+
{
443+
.comp_ids = &adl_rt5682_rt5682s_hp,
444+
.drv_name = "adl_max98390_rt5682",
445+
.machine_quirk = snd_soc_acpi_codec_list,
446+
.quirk_data = &adl_max98390_amp,
447+
.sof_fw_filename = "sof-adl.ri",
448+
.sof_tplg_filename = "sof-adl-max98390-rt5682.tplg",
449+
},
437450
{},
438451
};
439452
EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_adl_machines);

sound/soc/sof/sof-pci-dev.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ static const struct dmi_system_id sof_tplg_table[] = {
5959
},
6060
.driver_data = "sof-adl-rt5682-ssp0-max98373-ssp2.tplg",
6161
},
62+
{
63+
.callback = sof_tplg_cb,
64+
.matches = {
65+
DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
66+
DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98390_ALC5682I_I2S"),
67+
},
68+
.driver_data = "sof-adl-max98390-ssp2-rt5682-ssp0.tplg",
69+
},
70+
6271
{}
6372
};
6473

0 commit comments

Comments
 (0)