From ca0d2fb75f1f5f2d6057c3dea7354aa8b4fd0ed8 Mon Sep 17 00:00:00 2001 From: randerwang Date: Mon, 15 Jun 2020 16:53:44 +0800 Subject: [PATCH 1/4] ASoC: Intel: sof_max98373: share code between I2S & sdw mode of max98373 This patch unify the codec prefix name to share code between I2S & sdw mode of max98373. Signed-off-by: randerwang --- sound/soc/intel/boards/Makefile | 1 + sound/soc/intel/boards/sof_maxim_common.c | 4 ++-- sound/soc/intel/boards/sof_maxim_common.h | 3 +++ sound/soc/intel/boards/sof_sdw.c | 4 ++-- sound/soc/intel/boards/sof_sdw_max98373.c | 9 ++------- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/sound/soc/intel/boards/Makefile b/sound/soc/intel/boards/Makefile index 3ba36a175329bc..dc04acb911b651 100644 --- a/sound/soc/intel/boards/Makefile +++ b/sound/soc/intel/boards/Makefile @@ -38,6 +38,7 @@ snd-soc-sof-sdw-objs += sof_sdw.o \ sof_sdw_rt711.o sof_sdw_rt700.o \ sof_sdw_rt1308.o sof_sdw_rt715.o \ sof_sdw_rt5682.o \ + sof_maxim_common.o \ sof_sdw_dmic.o sof_sdw_hdmi.o hda_dsp_common.o obj-$(CONFIG_SND_SOC_INTEL_SOF_RT5682_MACH) += snd-soc-sof_rt5682.o obj-$(CONFIG_SND_SOC_INTEL_HASWELL_MACH) += snd-soc-sst-haswell.o diff --git a/sound/soc/intel/boards/sof_maxim_common.c b/sound/soc/intel/boards/sof_maxim_common.c index 123e6e5313fb96..1ddf9181a95d85 100644 --- a/sound/soc/intel/boards/sof_maxim_common.c +++ b/sound/soc/intel/boards/sof_maxim_common.c @@ -11,7 +11,7 @@ #define MAX_98373_PIN_NAME 16 -static const struct snd_soc_dapm_route max_98373_dapm_routes[] = { +const struct snd_soc_dapm_route max_98373_dapm_routes[] = { /* speaker */ { "Left Spk", NULL, "Left BE_OUT" }, { "Right Spk", NULL, "Right BE_OUT" }, @@ -59,7 +59,7 @@ static int max98373_hw_params(struct snd_pcm_substream *substream, return 0; } -static int max98373_trigger(struct snd_pcm_substream *substream, int cmd) +int max98373_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_dai *codec_dai; diff --git a/sound/soc/intel/boards/sof_maxim_common.h b/sound/soc/intel/boards/sof_maxim_common.h index 785b3433536817..5240b1c9d379b9 100644 --- a/sound/soc/intel/boards/sof_maxim_common.h +++ b/sound/soc/intel/boards/sof_maxim_common.h @@ -18,7 +18,10 @@ extern struct snd_soc_dai_link_component max_98373_components[2]; extern struct snd_soc_ops max_98373_ops; +extern const struct snd_soc_dapm_route max_98373_dapm_routes[]; int max98373_spk_codec_init(struct snd_soc_pcm_runtime *rtd); void sof_max98373_codec_conf(struct snd_soc_card *card); +int max98373_trigger(struct snd_pcm_substream *substream, int cmd); + #endif /* __SOF_MAXIM_COMMON_H */ diff --git a/sound/soc/intel/boards/sof_sdw.c b/sound/soc/intel/boards/sof_sdw.c index b86dff03101847..381475eb94e0bc 100644 --- a/sound/soc/intel/boards/sof_sdw.c +++ b/sound/soc/intel/boards/sof_sdw.c @@ -140,11 +140,11 @@ static struct snd_soc_codec_conf codec_conf[] = { /* two MAX98373s on link1 with different unique id */ { .dlc = COMP_CODEC_CONF("sdw:1:19f:8373:0:3"), - .name_prefix = "mx8373-1", + .name_prefix = "Right", }, { .dlc = COMP_CODEC_CONF("sdw:1:19f:8373:0:7"), - .name_prefix = "mx8373-2", + .name_prefix = "Left", }, { .dlc = COMP_CODEC_CONF("sdw:0:25d:5682:0"), diff --git a/sound/soc/intel/boards/sof_sdw_max98373.c b/sound/soc/intel/boards/sof_sdw_max98373.c index 56e31ddbcc5767..67100714b573dd 100644 --- a/sound/soc/intel/boards/sof_sdw_max98373.c +++ b/sound/soc/intel/boards/sof_sdw_max98373.c @@ -9,18 +9,13 @@ #include #include #include "sof_sdw_common.h" +#include "sof_maxim_common.h" static const struct snd_soc_dapm_widget mx8373_widgets[] = { SND_SOC_DAPM_SPK("Left Spk", NULL), SND_SOC_DAPM_SPK("Right Spk", NULL), }; -static const struct snd_soc_dapm_route mx8373_map[] = { - /* Speakers */ - { "Left Spk", NULL, "mx8373-1 BE_OUT" }, - { "Right Spk", NULL, "mx8373-2 BE_OUT" }, -}; - static const struct snd_kcontrol_new mx8373_controls[] = { SOC_DAPM_PIN_SWITCH("Left Spk"), SOC_DAPM_PIN_SWITCH("Right Spk"), @@ -51,7 +46,7 @@ static int spk_init(struct snd_soc_pcm_runtime *rtd) return ret; } - ret = snd_soc_dapm_add_routes(&card->dapm, mx8373_map, 2); + ret = snd_soc_dapm_add_routes(&card->dapm, max_98373_dapm_routes, 2); if (ret) dev_err(rtd->dev, "failed to add first SPK map: %d\n", ret); From c4a8dc48febd6afe92a12409989aefccf50e0b02 Mon Sep 17 00:00:00 2001 From: randerwang Date: Mon, 15 Jun 2020 17:06:06 +0800 Subject: [PATCH 2/4] ASoC: Intel: sdw_max98373: add trigger function to sdw platform Port patch: ASoC: Intel: Boards: tgl_max98373: add dai_trigger function to sdw platform to fix runtime pm issue. Signed-off-by: randerwang --- sound/soc/intel/boards/sof_sdw.c | 4 ++-- sound/soc/intel/boards/sof_sdw_common.h | 3 +++ sound/soc/intel/boards/sof_sdw_max98373.c | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sound/soc/intel/boards/sof_sdw.c b/sound/soc/intel/boards/sof_sdw.c index 381475eb94e0bc..e02556fe671fb8 100644 --- a/sound/soc/intel/boards/sof_sdw.c +++ b/sound/soc/intel/boards/sof_sdw.c @@ -172,12 +172,12 @@ static struct snd_soc_dai_link_component platform_component[] = { }; /* these wrappers are only needed to avoid typecast compilation errors */ -static int sdw_startup(struct snd_pcm_substream *substream) +int sdw_startup(struct snd_pcm_substream *substream) { return sdw_startup_stream(substream); } -static void sdw_shutdown(struct snd_pcm_substream *substream) +void sdw_shutdown(struct snd_pcm_substream *substream) { sdw_shutdown_stream(substream); } diff --git a/sound/soc/intel/boards/sof_sdw_common.h b/sound/soc/intel/boards/sof_sdw_common.h index 679799a5ff5097..3f820cf99a8929 100644 --- a/sound/soc/intel/boards/sof_sdw_common.h +++ b/sound/soc/intel/boards/sof_sdw_common.h @@ -71,6 +71,9 @@ struct mc_private { extern unsigned long sof_sdw_quirk; +int sdw_startup(struct snd_pcm_substream *substream); +void sdw_shutdown(struct snd_pcm_substream *substream); + /* generic HDMI support */ int sof_sdw_hdmi_init(struct snd_soc_pcm_runtime *rtd); diff --git a/sound/soc/intel/boards/sof_sdw_max98373.c b/sound/soc/intel/boards/sof_sdw_max98373.c index 67100714b573dd..a38ddc099a95bb 100644 --- a/sound/soc/intel/boards/sof_sdw_max98373.c +++ b/sound/soc/intel/boards/sof_sdw_max98373.c @@ -53,6 +53,12 @@ static int spk_init(struct snd_soc_pcm_runtime *rtd) return ret; } +static const struct snd_soc_ops max_98373_sdw_ops = { + .startup = sdw_startup, + .trigger = max98373_trigger, + .shutdown = sdw_shutdown, +}; + int sof_sdw_mx8373_init(const struct snd_soc_acpi_link_adr *link, struct snd_soc_dai_link *dai_links, struct sof_sdw_codec_info *info, @@ -62,5 +68,7 @@ int sof_sdw_mx8373_init(const struct snd_soc_acpi_link_adr *link, if (info->amp_num == 2) dai_links->init = spk_init; + dai_links->ops = &max_98373_sdw_ops; + return 0; } From 142775021a00f5e8046a6307fe9d4c82effb68c4 Mon Sep 17 00:00:00 2001 From: randerwang Date: Mon, 15 Jun 2020 17:19:16 +0800 Subject: [PATCH 3/4] ASoC: Intel: sdw_max98373: add card_late_probe support Disable Left and Right Spk pin after boot so that sof can get suspended. Please check patch: ASoC: Intel: Boards: tgl_max98373: add dai_trigger function Signed-off-by: randerwang --- sound/soc/intel/boards/sof_sdw.c | 19 ++++++++++++++++++- sound/soc/intel/boards/sof_sdw_common.h | 6 ++++++ sound/soc/intel/boards/sof_sdw_max98373.c | 12 ++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/sound/soc/intel/boards/sof_sdw.c b/sound/soc/intel/boards/sof_sdw.c index e02556fe671fb8..13c6dd4b149dc7 100644 --- a/sound/soc/intel/boards/sof_sdw.c +++ b/sound/soc/intel/boards/sof_sdw.c @@ -219,6 +219,7 @@ static struct sof_sdw_codec_info codec_info_list[] = { .direction = {true, true}, .dai_name = "max98373-aif1", .init = sof_sdw_mx8373_init, + .codec_card_late_probe = sof_sdw_mx8373_late_probe, }, { .id = 0x5682, @@ -909,12 +910,28 @@ static int sof_card_dai_links_create(struct device *dev, return 0; } +int sof_sdw_card_late_probe(struct snd_soc_card *card) +{ + int i, ret; + + for (i = 0; i < ARRAY_SIZE(codec_info_list); i++) { + if (!codec_info_list[i].late_probe) + continue; + + ret = codec_info_list[i].codec_card_late_probe(card); + if (ret < 0) + return ret; + } + + return sof_sdw_hdmi_card_late_probe(card); +} + /* SoC card */ static const char sdw_card_long_name[] = "Intel Soundwire SOF"; static struct snd_soc_card card_sof_sdw = { .name = "soundwire", - .late_probe = sof_sdw_hdmi_card_late_probe, + .late_probe = sof_sdw_card_late_probe, .codec_conf = codec_conf, .num_configs = ARRAY_SIZE(codec_conf), }; diff --git a/sound/soc/intel/boards/sof_sdw_common.h b/sound/soc/intel/boards/sof_sdw_common.h index 3f820cf99a8929..426017626b16ed 100644 --- a/sound/soc/intel/boards/sof_sdw_common.h +++ b/sound/soc/intel/boards/sof_sdw_common.h @@ -11,6 +11,7 @@ #include #include +#include #define MAX_NO_PROPS 2 #define MAX_HDMI_NUM 4 @@ -61,6 +62,9 @@ struct sof_sdw_codec_info { struct snd_soc_dai_link *dai_links, struct sof_sdw_codec_info *info, bool playback); + + bool late_probe; + int (*codec_card_late_probe)(struct snd_soc_card *card); }; struct mc_private { @@ -114,6 +118,8 @@ int sof_sdw_mx8373_init(const struct snd_soc_acpi_link_adr *link, struct sof_sdw_codec_info *info, bool playback); +int sof_sdw_mx8373_late_probe(struct snd_soc_card *card); + /* RT5682 support */ int sof_sdw_rt5682_init(const struct snd_soc_acpi_link_adr *link, struct snd_soc_dai_link *dai_links, diff --git a/sound/soc/intel/boards/sof_sdw_max98373.c b/sound/soc/intel/boards/sof_sdw_max98373.c index a38ddc099a95bb..6437872a9b3d46 100644 --- a/sound/soc/intel/boards/sof_sdw_max98373.c +++ b/sound/soc/intel/boards/sof_sdw_max98373.c @@ -68,7 +68,19 @@ int sof_sdw_mx8373_init(const struct snd_soc_acpi_link_adr *link, if (info->amp_num == 2) dai_links->init = spk_init; + info->late_probe = true; + dai_links->ops = &max_98373_sdw_ops; return 0; } + +int sof_sdw_mx8373_late_probe(struct snd_soc_card *card) +{ + struct snd_soc_dapm_context *dapm = &card->dapm; + + /* Disable Left and Right Spk pin after boot */ + snd_soc_dapm_disable_pin(dapm, "Left Spk"); + snd_soc_dapm_disable_pin(dapm, "Right Spk"); + return snd_soc_dapm_sync(dapm); +} From daedc4663dcca9b2ab8d2a821ef586d97c0d8d9a Mon Sep 17 00:00:00 2001 From: randerwang Date: Mon, 15 Jun 2020 17:21:12 +0800 Subject: [PATCH 4/4] ASoc: codec: max98373: remove Idle_bias_on to make codec suspended Idle_bias_on is used to decide bias on/off in standby state by dapm. When Idle_bias_on is set to one, dapm will keep max98373 active at idle time. Max98373 is doing nothing in this state, so remove idle_bias_on setting to let max98373 get suspended when it is idle. Signed-off-by: randerwang Reviewed-by : Ryan Lee --- sound/soc/codecs/max98373.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c index f03835e1f3e458..dc2d97ff17396b 100644 --- a/sound/soc/codecs/max98373.c +++ b/sound/soc/codecs/max98373.c @@ -869,7 +869,6 @@ static const struct snd_soc_component_driver soc_codec_dev_max98373 = { .num_dapm_widgets = ARRAY_SIZE(max98373_dapm_widgets), .dapm_routes = max98373_audio_map, .num_dapm_routes = ARRAY_SIZE(max98373_audio_map), - .idle_bias_on = 1, .use_pmdown_time = 1, .endianness = 1, .non_legacy_dai_naming = 1, @@ -883,7 +882,6 @@ const struct snd_soc_component_driver soc_codec_dev_max98373_sdw = { .num_dapm_widgets = ARRAY_SIZE(max98373_dapm_widgets), .dapm_routes = max98373_audio_map, .num_dapm_routes = ARRAY_SIZE(max98373_audio_map), - .idle_bias_on = 1, .use_pmdown_time = 1, .endianness = 1, .non_legacy_dai_naming = 1,