Skip to contentSkip to conversation

ASoC: codecs: add MAX98373 Soundwire driver

PATCH Superseded Pierre-Louis Bossart 2 participants 12 messages Jul 7, 2020 – Jul 8, 2020

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover ASoC: codecs: add MAX98373 Soundwire driver

V2 with a number of cleanups:
split between I2C and SoundWire modes, as done for rt5682, and updated Kconfigs.
removed useless initializations common to both modes removed idle_bias on
fixed register classified as volatile in error
fixed SPDX comments

Pierre-Louis Bossart (2):
ASoC: codecs: max98373: split I2C and common parts
ASoC: Intel: sof-sdw: add MAX98373 I2C dependencies

Ryan Lee (2):
ASoC: codecs: max98373: Removed superfluous volume control from chip
default
ASoC: codecs: max98373: add SoundWire support

randerwang (2):
ASoc: codecs: max98373: remove Idle_bias_on to let codec suspend
ASoC: Intel: sdw_max98373: add card_late_probe support

 sound/soc/codecs/Kconfig                  |  20 +-
 sound/soc/codecs/Makefile                 |   4 +
 sound/soc/codecs/max98373-i2c.c           | 612 +++++++++++++++
 sound/soc/codecs/max98373-sdw.c           | 887 ++++++++++++++++++++++
 sound/soc/codecs/max98373-sdw.h           |  72 ++
 sound/soc/codecs/max98373.c               | 619 +--------------
 sound/soc/codecs/max98373.h               |  17 +-
 sound/soc/intel/boards/Kconfig            |   7 +-
 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 +
 11 files changed, 1668 insertions(+), 607 deletions(-)
 create mode 100644 sound/soc/codecs/max98373-i2c.c
 create mode 100644 sound/soc/codecs/max98373-sdw.c
 create mode 100644 sound/soc/codecs/max98373-sdw.h

base-commit: a5911ac5790acaf98c929b826b3f7b4a438f9759

Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/6 ASoC: codecs: max98373: split I2C and common parts

To prepare support for SoundWire, let's first split the I2C and common parts. No new functionality, just indents and formatting to make checkpatch happy.

---
 sound/soc/codecs/Kconfig        |   6 +-
 sound/soc/codecs/Makefile       |   2 +
 sound/soc/codecs/max98373-i2c.c | 612 ++++++++++++++++++++++++++++++++
 sound/soc/codecs/max98373.c     | 601 +------------------------------
 sound/soc/codecs/max98373.h     |  10 +-
 sound/soc/intel/boards/Kconfig  |   6 +-
 6 files changed, 637 insertions(+), 600 deletions(-)
 create mode 100644 sound/soc/codecs/max98373-i2c.c
sound/soc/codecs/Kconfig +5 -1
index 986a6308818b..ebefb343f7ef 100644
@@ -115,7 +115,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_MAX98925
 	imply SND_SOC_MAX98926
 	imply SND_SOC_MAX98927
-	imply SND_SOC_MAX98373
+	imply SND_SOC_MAX98373_I2C
 	imply SND_SOC_MAX98390
 	imply SND_SOC_MAX9850
 	imply SND_SOC_MAX9860
@@ -868,8 +868,12 @@ config SND_SOC_MAX98927
 	depends on I2C
 
 config SND_SOC_MAX98373
+	tristate
+
+config SND_SOC_MAX98373_I2C
 	tristate "Maxim Integrated MAX98373 Speaker Amplifier"
 	depends on I2C
+	select SND_SOC_MAX98373
 
 config SND_SOC_MAX98390
 	tristate "Maxim Integrated MAX98390 Speaker Amplifier"
sound/soc/codecs/Makefile +2 -0
index 47ae3cebb61e..3ac82c3b6fc3 100644
@@ -115,6 +115,7 @@ snd-soc-max98925-objs := max98925.o
 snd-soc-max98926-objs := max98926.o
 snd-soc-max98927-objs := max98927.o
 snd-soc-max98373-objs := max98373.o
+snd-soc-max98373-i2c-objs := max98373-i2c.o
 snd-soc-max98390-objs := max98390.o
 snd-soc-max9850-objs := max9850.o
 snd-soc-max9860-objs := max9860.o
@@ -418,6 +419,7 @@ obj-$(CONFIG_SND_SOC_MAX98925)	+= snd-soc-max98925.o
 obj-$(CONFIG_SND_SOC_MAX98926)	+= snd-soc-max98926.o
 obj-$(CONFIG_SND_SOC_MAX98927)	+= snd-soc-max98927.o
 obj-$(CONFIG_SND_SOC_MAX98373)	+= snd-soc-max98373.o
+obj-$(CONFIG_SND_SOC_MAX98373_I2C)   += snd-soc-max98373-i2c.o
 obj-$(CONFIG_SND_SOC_MAX98390)	+= snd-soc-max98390.o
 obj-$(CONFIG_SND_SOC_MAX9850)	+= snd-soc-max9850.o
 obj-$(CONFIG_SND_SOC_MAX9860)	+= snd-soc-max9860.o
sound/soc/codecs/max98373-i2c.c new file +612 -0

612 lines not on this page · raw message

sound/soc/codecs/max98373.c +7 -594

646 lines not on this page · raw message

sound/soc/codecs/max98373.h +8 -2
index 63dae8be7105..30e02e7afb6d 100644
@@ -1,5 +1,5 @@
-// SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2017, Maxim Integrated
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (c) 2017 Maxim Integrated */
 
 #ifndef _MAX98373_H
 #define _MAX98373_H
@@ -213,4 +213,10 @@ struct max98373_priv {
 	unsigned int ch_size;
 	bool tdm_mode;
 };
+
+extern const struct snd_soc_component_driver soc_codec_dev_max98373;
+
+void max98373_reset(struct max98373_priv *max98373, struct device *dev);
+void max98373_slot_config(struct device *dev,
+			  struct max98373_priv *max98373);
 #endif
sound/soc/intel/boards/Kconfig +3 -3
index f176df2599a5..1032f6608045 100644
@@ -390,7 +390,7 @@ config SND_SOC_INTEL_KBL_DA7219_MAX98927_MACH
 	depends on MFD_INTEL_LPSS || COMPILE_TEST
 	select SND_SOC_DA7219
 	select SND_SOC_MAX98927
-	select SND_SOC_MAX98373
+	select SND_SOC_MAX98373_I2C
 	select SND_SOC_DMIC
 	select SND_SOC_HDAC_HDMI
 	help
@@ -467,7 +467,7 @@ config SND_SOC_INTEL_SOF_RT5682_MACH
 	depends on ((SND_HDA_CODEC_HDMI && SND_SOC_SOF_HDA_AUDIO_CODEC) &&\
 		    (MFD_INTEL_LPSS || COMPILE_TEST)) ||\
 		   (SND_SOC_SOF_BAYTRAIL && (X86_INTEL_LPSS || COMPILE_TEST))
-	select SND_SOC_MAX98373
+	select SND_SOC_MAX98373_I2C
 	select SND_SOC_RT1015
 	select SND_SOC_RT5682_I2C
 	select SND_SOC_DMIC
@@ -531,7 +531,7 @@ config SND_SOC_INTEL_SOF_DA7219_MAX98373_MACH
 	depends on MFD_INTEL_LPSS || COMPILE_TEST
 	depends on SND_HDA_CODEC_HDMI && SND_SOC_SOF_HDA_AUDIO_CODEC
 	select SND_SOC_DA7219
-	select SND_SOC_MAX98373
+	select SND_SOC_MAX98373_I2C
 	select SND_SOC_DMIC
 	help
 	  This adds support for ASoC machine driver for SOF platforms
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH v2 1/6] ASoC: codecs: max98373: split I2C and common parts

Quoted 3 lines · Pierre-Louis Bossart

To prepare support for SoundWire, let's first split the I2C and common parts. No new functionality, just indents and formatting to make checkpatch happy.

You've got a couple of fixes after this patch, the fixes should've been first.

#3 lore raw

Re: [PATCH v2 1/6] ASoC: codecs: max98373: split I2C and common parts

Quoted 7 lines · Mark Brown
Quoted 3 lines · Pierre-Louis Bossart

To prepare support for SoundWire, let's first split the I2C and common parts. No new functionality, just indents and formatting to make checkpatch happy.

You've got a couple of fixes after this patch, the fixes should've been first.

ok, will respin them.

#4 lore raw

PATCH v2 2/6 ASoC: codecs: max98373: Removed superfluous volume control from chip default

In reply to Pierre-Louis Bossart

From: Ryan Lee <[email protected]>

Volume control in probe function is not necessary.

---
 sound/soc/codecs/max98373.c | 7 -------
 1 file changed, 7 deletions(-)
sound/soc/codecs/max98373.c +0 -7
index a8ed9f12682b..c3202c1dc517 100644
@@ -331,13 +331,6 @@ static int max98373_probe(struct snd_soc_component *component)
 	regmap_write(max98373->regmap,
 		MAX98373_R202A_PCM_TO_SPK_MONO_MIX_2,
 		0x1);
-	/* Set inital volume (0dB) */
-	regmap_write(max98373->regmap,
-		MAX98373_R203D_AMP_DIG_VOL_CTRL,
-		0x00);
-	regmap_write(max98373->regmap,
-		MAX98373_R203E_AMP_PATH_GAIN,
-		0x00);
 	/* Enable DC blocker */
 	regmap_write(max98373->regmap,
 		MAX98373_R203F_AMP_DSP_CFG,
Signature · 1 line
2.25.1
#5 lore raw

PATCH v2 3/6 ASoc: codecs: max98373: remove Idle_bias_on to let codec suspend

In reply to Pierre-Louis Bossart

From: randerwang <[email protected]>

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.

---
 sound/soc/codecs/max98373.c | 1 -
 1 file changed, 1 deletion(-)
sound/soc/codecs/max98373.c +0 -1
index c3202c1dc517..bf5572fc4f66 100644
@@ -390,7 +390,6 @@ 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,
Signature · 1 line
2.25.1
#6 lore raw

PATCH v2 4/6 ASoC: codecs: max98373: add SoundWire support

In reply to Pierre-Louis Bossart

From: Ryan Lee <[email protected]>

Add SoundWire specific parts and extend common ones already split from I2C.

---
 sound/soc/codecs/Kconfig        |  14 +
 sound/soc/codecs/Makefile       |   2 +
 sound/soc/codecs/max98373-sdw.c | 887 ++++++++++++++++++++++++++++++++
 sound/soc/codecs/max98373-sdw.h |  72 +++
 sound/soc/codecs/max98373.c     |  14 +
 sound/soc/codecs/max98373.h     |   7 +
 6 files changed, 996 insertions(+)
 create mode 100644 sound/soc/codecs/max98373-sdw.c
 create mode 100644 sound/soc/codecs/max98373-sdw.h
sound/soc/codecs/Kconfig +14 -0
index ebefb343f7ef..946a70210f49 100644
@@ -116,6 +116,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_MAX98926
 	imply SND_SOC_MAX98927
 	imply SND_SOC_MAX98373_I2C
+	imply SND_SOC_MAX98373_SDW
 	imply SND_SOC_MAX98390
 	imply SND_SOC_MAX9850
 	imply SND_SOC_MAX9860
@@ -875,6 +876,19 @@ config SND_SOC_MAX98373_I2C
 	depends on I2C
 	select SND_SOC_MAX98373
 
+config SND_SOC_MAX98373_SDW
+	tristate "Maxim Integrated MAX98373 Speaker Amplifier - SDW"
+	depends on SOUNDWIRE
+	select SND_SOC_MAX98373
+	select REGMAP_SOUNDWIRE
+	help
+	  Enable support for Maxim Integrated MAX98373 Soundwire
+	  amplifier. MAX98373 supports either the MIPI SoundWire
+	  compatible interface for audio and control data, or
+	  the PCM interface for audio data and a standard I2C
+	  interface for control data. Select this if MAX98373 is
+	  connected via soundwire.
+
 config SND_SOC_MAX98390
 	tristate "Maxim Integrated MAX98390 Speaker Amplifier"
 	depends on I2C
sound/soc/codecs/Makefile +2 -0
index 3ac82c3b6fc3..0140c60db695 100644
@@ -116,6 +116,7 @@ snd-soc-max98926-objs := max98926.o
 snd-soc-max98927-objs := max98927.o
 snd-soc-max98373-objs := max98373.o
 snd-soc-max98373-i2c-objs := max98373-i2c.o
+snd-soc-max98373-sdw-objs := max98373-sdw.o
 snd-soc-max98390-objs := max98390.o
 snd-soc-max9850-objs := max9850.o
 snd-soc-max9860-objs := max9860.o
@@ -420,6 +421,7 @@ obj-$(CONFIG_SND_SOC_MAX98926)	+= snd-soc-max98926.o
 obj-$(CONFIG_SND_SOC_MAX98927)	+= snd-soc-max98927.o
 obj-$(CONFIG_SND_SOC_MAX98373)	+= snd-soc-max98373.o
 obj-$(CONFIG_SND_SOC_MAX98373_I2C)   += snd-soc-max98373-i2c.o
+obj-$(CONFIG_SND_SOC_MAX98373_SDW)   += snd-soc-max98373-sdw.o
 obj-$(CONFIG_SND_SOC_MAX98390)	+= snd-soc-max98390.o
 obj-$(CONFIG_SND_SOC_MAX9850)	+= snd-soc-max9850.o
 obj-$(CONFIG_SND_SOC_MAX9860)	+= snd-soc-max9860.o
sound/soc/codecs/max98373-sdw.c new file +887 -0

887 lines not on this page · raw message

sound/soc/codecs/max98373-sdw.h new file +72 -0

72 lines not on this page · raw message

sound/soc/codecs/max98373.c +14 -0
index bf5572fc4f66..929bb1798c43 100644
@@ -396,6 +396,20 @@ const struct snd_soc_component_driver soc_codec_dev_max98373 = {
 };
 EXPORT_SYMBOL_GPL(soc_codec_dev_max98373);
 
+const struct snd_soc_component_driver soc_codec_dev_max98373_sdw = {
+	.probe			= NULL,
+	.controls		= max98373_snd_controls,
+	.num_controls		= ARRAY_SIZE(max98373_snd_controls),
+	.dapm_widgets		= max98373_dapm_widgets,
+	.num_dapm_widgets	= ARRAY_SIZE(max98373_dapm_widgets),
+	.dapm_routes		= max98373_audio_map,
+	.num_dapm_routes	= ARRAY_SIZE(max98373_audio_map),
+	.use_pmdown_time	= 1,
+	.endianness		= 1,
+	.non_legacy_dai_naming	= 1,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_max98373_sdw);
+
 void max98373_slot_config(struct device *dev,
 			  struct max98373_priv *max98373)
 {
sound/soc/codecs/max98373.h +7 -0
index 30e02e7afb6d..4ab29b9d51c7 100644
@@ -212,9 +212,16 @@ struct max98373_priv {
 	bool interleave_mode;
 	unsigned int ch_size;
 	bool tdm_mode;
+	/* variables to support soundwire */
+	struct sdw_slave *slave;
+	bool hw_init;
+	bool pm_init_once;
+	int slot;
+	unsigned int rx_mask;
 };
 
 extern const struct snd_soc_component_driver soc_codec_dev_max98373;
+extern const struct snd_soc_component_driver soc_codec_dev_max98373_sdw;
 
 void max98373_reset(struct max98373_priv *max98373, struct device *dev);
 void max98373_slot_config(struct device *dev,
Signature · 1 line
2.25.1
#7 lore raw

PATCH v2 5/6 ASoC: Intel: sof-sdw: add MAX98373 I2C dependencies

In reply to Pierre-Louis Bossart

Reflect Kconfig changes and add both SoundWire and I2C modes

---
 sound/soc/intel/boards/Kconfig | 1 +
 1 file changed, 1 insertion(+)
sound/soc/intel/boards/Kconfig +1 -0
index 1032f6608045..d96fc1313434 100644
@@ -565,6 +565,7 @@ config SND_SOC_INTEL_SOUNDWIRE_SOF_MACH
 	depends on SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES || COMPILE_TEST
 	depends on SOUNDWIRE
 	depends on SND_HDA_CODEC_HDMI && SND_SOC_SOF_HDA_AUDIO_CODEC
+	select SND_SOC_MAX98373_I2C
 	select SND_SOC_MAX98373_SDW
 	select SND_SOC_RT700_SDW
 	select SND_SOC_RT711_SDW
Signature · 1 line
2.25.1
#8 lore raw

PATCH v2 6/6 ASoC: Intel: sdw_max98373: add card_late_probe support

In reply to Pierre-Louis Bossart

From: randerwang <[email protected]>

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

---
 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(-)
sound/soc/intel/boards/sof_sdw.c +18 -1
index 45be9ec6d4ef..be8eccb50450 100644
@@ -237,6 +237,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,
@@ -927,13 +928,29 @@ static int sof_card_dai_links_create(struct device *dev,
 	return 0;
 }
 
+static 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",
 	.owner = THIS_MODULE,
-	.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),
 };
sound/soc/intel/boards/sof_sdw_common.h +6 -0
index 3f820cf99a89..426017626b16 100644
@@ -11,6 +11,7 @@
 
 #include <linux/bits.h>
 #include <linux/types.h>
+#include <sound/soc.h>
 
 #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,
sound/soc/intel/boards/sof_sdw_max98373.c +12 -0
index a38ddc099a95..6437872a9b3d 100644
@@ -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);
+}
Signature · 1 line
2.25.1
maintainer
#9 lore raw

Re: [PATCH v2 6/6] ASoC: Intel: sdw_max98373: add card_late_probe support

Quoted 5 lines · Pierre-Louis Bossart

From: randerwang <[email protected]>

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

A commit ID would have been useful here.

#10 lore raw

Re: [PATCH v2 6/6] ASoC: Intel: sdw_max98373: add card_late_probe support

Quoted 8 lines · Mark Brown
Quoted 5 lines · Pierre-Louis Bossart

From: randerwang <[email protected]>

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

A commit ID would have been useful here.

yes, will add.

maintainer
#11 lore raw
In reply to Pierre-Louis Bossart
Quoted 9 lines · Pierre-Louis Bossart

V2 with a number of cleanups:
split between I2C and SoundWire modes, as done for rt5682, and updated Kconfigs.
removed useless initializations common to both modes removed idle_bias on
fixed register classified as volatile in error
fixed SPDX comments

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/2] ASoC: codecs: max98373: Removed superfluous volume control from chip default

      commit: a53bacc04d7e2b813ebe0ca4dae38716c00d7953
[2/2] ASoc: codecs: max98373: remove Idle_bias_on to let codec suspend
      commit: 0fd3935ef888b7231fde87eba3fdf613c4923b4a

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark