Skip to contentSkip to conversation

ASoC: dt-bindings: max98520: add initial bindings

PATCH Superseded George Song 3 participants 7 messages Oct 18, 2021 – Oct 20, 2021

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 ASoC: dt-bindings: max98520: add initial bindings

add initial bindings for max98520 audio amplifier

---
 .../bindings/sound/maxim,max98520.yaml        | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/maxim,max98520.yaml
Documentation/devicetree/bindings/sound/maxim,max98520.yaml new file +36 -0
new file mode 100644
index 000000000000..b6509cb2c8e0
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/maxim,max98520.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Maxim Integrated MAX98520 Speaker Amplifier Driver
+
+maintainers:
+  - George Song <[email protected]>
+
+properties:
+  compatible:
+    const: maxim,max98520
+
+  reg:
+    maxItems: 1
+    description: I2C address of the device.
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      max98520: amplifier@38 {
+        compatible = "maxim,max98520";
+        reg = <0x38>;
+      };
+    };
+
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 2/2 ASoC: max98520: add max98520 audio amplifier driver

add max98520 audio amplifier driver

---
 sound/soc/codecs/Kconfig    |  12 +
 sound/soc/codecs/Makefile   |   2 +
 sound/soc/codecs/max98520.c | 770 ++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/max98520.h | 159 ++++++++
 4 files changed, 943 insertions(+)
 create mode 100644 sound/soc/codecs/max98520.c
 create mode 100644 sound/soc/codecs/max98520.h
sound/soc/codecs/Kconfig +12 -0
index 82ee233a269d..e8817029c671 100644
@@ -115,6 +115,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_MAX98357A
 	imply SND_SOC_MAX98371
 	imply SND_SOC_MAX98504
+	imply SND_SOC_MAX98520
 	imply SND_SOC_MAX9867
 	imply SND_SOC_MAX98925
 	imply SND_SOC_MAX98926
@@ -922,6 +923,17 @@ config SND_SOC_MAX98927
 	tristate "Maxim Integrated MAX98927 Speaker Amplifier"
 	depends on I2C
 
+config SND_SOC_MAX98520
+	tristate "Maxim Integrated MAX98520 Speaker Amplifier"
+	depends on I2C
+	help
+	  Enable support for Maxim Integrated MAX98520 audio
+	  amplifier, which implements a tripler charge pump
+	  based boost converter and support sample rates of
+	  8KHz to 192KHz.
+
+	  To compile this driver as a module, choose M here.
+
 config SND_SOC_MAX98373
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index 8dcea2c4604a..daf63e31fdd0 100644
@@ -123,6 +123,7 @@ snd-soc-max9867-objs := max9867.o
 snd-soc-max98925-objs := max98925.o
 snd-soc-max98926-objs := max98926.o
 snd-soc-max98927-objs := max98927.o
+snd-soc-max98520-objs := max98520.o
 snd-soc-max98373-objs := max98373.o
 snd-soc-max98373-i2c-objs := max98373-i2c.o
 snd-soc-max98373-sdw-objs := max98373-sdw.o
@@ -450,6 +451,7 @@ obj-$(CONFIG_SND_SOC_MAX9867)	+= snd-soc-max9867.o
 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_MAX98520)	+= snd-soc-max98520.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
sound/soc/codecs/max98520.c new file +770 -0

770 lines not on this page · raw message

sound/soc/codecs/max98520.h new file +159 -0

159 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [v3 2/2] ASoC: max98520: add max98520 audio amplifier driver

sound/soc/codecs/max98520.c line 357

Quoted 7 lines · George Song
sound/soc/codecs/max98520.c new file +7 -0
+	case SND_SOC_DAPM_POST_PMD:
+		dev_dbg(component->dev, " AMP OFF\n");
+
+		regmap_write(max98520->regmap, MAX98520_R210F_GLOBAL_EN, 0);
+		usleep_range(30000, 31000);
+		max98520->tdm_mode = false;
+		break;

Why would stopping the DAC put us out of TDM mode? Not that I can see anything which ever sets tdm_mode to anything other than false or checks the value...

sound/soc/codecs/max98520.c line 377

Quoted 4 lines
sound/soc/codecs/max98520.c new file +4 -0
+static const struct snd_soc_dapm_widget max98520_dapm_widgets[] = {
+	SND_SOC_DAPM_DAC_E("Amp Enable", "HiFi Playback",
+			   MAX98520_R209F_AMP_EN, 0, 0, max98520_dac_event,
+	SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),

I can't help think that the global enable ought to be a _SUPPLY widget, it would get enabled before the DAC rather than after it but it's not clear that the ordering is critical here.

sound/soc/codecs/max98520.c line 385

Quoted 4 lines
sound/soc/codecs/max98520.c new file +4 -0
+static DECLARE_TLV_DB_SCALE(max98520_digital_tlv, -6300, 50, 1);
+static const DECLARE_TLV_DB_RANGE(max98520_spk_tlv,
+	0, 5, TLV_DB_SCALE_ITEM(600, 300, 0),
+);

Why is _digital_tlv not const? It's also a bit weird that _spk_tlv is a range with one entry not a scale.

sound/soc/codecs/max98520.c line 575

Quoted 10 lines
sound/soc/codecs/max98520.c new file +10 -0
+	count = 0;
+	while (count < 3) {
+		usleep_range(10000, 11000);
+		/* Software Reset Verification */
+		ret = regmap_read(max98520->regmap, MAX98520_R21FF_REVISION_ID, &reg);
+		if (!ret) {
+			dev_info(dev, "Reset completed (retry:%d)\n", count);
+			return;
+		}
+		count++;

Does this really need to be logged?

sound/soc/codecs/max98520.c line 587

Quoted 3 lines
sound/soc/codecs/max98520.c new file +3 -0
+	/* Software Reset */
+	max98520_reset(max98520, component->dev);
+	usleep_range(30000, 31000);

Shouldn't that delay be in the reset routine? Perhaps between the attempts to read the ID register?

sound/soc/codecs/max98520.c line 592

Quoted 4 lines
sound/soc/codecs/max98520.c new file +4 -0
+	/* L/R mix configuration */
+	regmap_write(max98520->regmap, MAX98520_R2043_PCM_RX_SRC1, 0x2);
+
+	regmap_write(max98520->regmap, MAX98520_R2044_PCM_RX_SRC2, 0x10);

These should be exposed to the user, not hard coded - different systems may need different configurations.

sound/soc/codecs/max98520.c line 597

Quoted 3 lines
sound/soc/codecs/max98520.c new file +3 -0
+	/* Disable Speaker Safe Mode */
+	regmap_update_bits(max98520->regmap,
+			   MAX98520_R2092_AMP_DSP_CFG, MAX98520_SPK_SAFE_EN_MASK, 0);

This seems like something that should be left as is by default given the name (or forced on if it were disabled by default)?

sound/soc/codecs/max98520.c line 605

Quoted 5 lines
sound/soc/codecs/max98520.c new file +5 -0
+	/* Hard coded values for the experiments */
+	regmap_write(max98520->regmap, MAX98520_R21FF_REVISION_ID, 0x54);
+	regmap_write(max98520->regmap, MAX98520_R21FF_REVISION_ID, 0x4d);
+	regmap_write(max98520->regmap, MAX98520_R2161_BOOST_TM1, 0x2);
+	regmap_write(max98520->regmap, MAX98520_R2095_AMP_CFG, 0xc8);

This doesn't seem suitable for upstream.

sound/soc/codecs/max98520.c line 700

Quoted 4 lines
sound/soc/codecs/max98520.c new file +4 -0
+	/* Power on device */
+	if (gpio_is_valid(max98520->reset_gpio)) {
+		ret = devm_gpio_request(&i2c->dev, max98520->reset_gpio,
+					"MAX98520_RESET");

You should use the gpiod APIs for new code, not the legacy GPIO interface. This GPIO wasn't mentioned in the DT bindings but should have been described there.

sound/soc/codecs/max98520.c line 710

Quoted 10 lines
sound/soc/codecs/max98520.c new file +10 -0
+		if (ret) {
+			dev_err(&i2c->dev, "%s: Failed to request gpio %d\n",
+				__func__, max98520->reset_gpio);
+			return -EINVAL;
+		}
+		gpio_direction_output(max98520->reset_gpio, 0);
+		msleep(50);
+		gpio_direction_output(max98520->reset_gpio, 1);
+		msleep(20);
+	}

Shouldn't the disable/enable of the reset GPIO be in the reset function?

#3 lore raw

RE: [EXTERNAL] Re: [v3 2/2] ASoC: max98520: add max98520 audio amplifier driver

Quoted 13 lines · George Song

sound/soc/codecs/max98520.c line 357

Quoted 8 lines
sound/soc/codecs/max98520.c new file +7 -0
+	case SND_SOC_DAPM_POST_PMD:
+		dev_dbg(component->dev, " AMP OFF\n");
+
+		regmap_write(max98520->regmap, MAX98520_R210F_GLOBAL_EN, 0);
+		usleep_range(30000, 31000);
+		max98520->tdm_mode = false;
+		break;

Why would stopping the DAC put us out of TDM mode? Not that I can see anything which ever sets tdm_mode to anything other than false or checks the value...

It will be removed tdm_mode to false line.

Quoted 9 lines

sound/soc/codecs/max98520.c line 377

Quoted 5 lines
sound/soc/codecs/max98520.c new file +4 -0
+static const struct snd_soc_dapm_widget max98520_dapm_widgets[] = {
+	SND_SOC_DAPM_DAC_E("Amp Enable", "HiFi Playback",
+			   MAX98520_R209F_AMP_EN, 0, 0, max98520_dac_event,
+	SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),

I can't help think that the global enable ought to be a _SUPPLY widget, it would get enabled before the DAC rather than after it but it's not clear that the ordering is critical here.

It will be modified SND_SOC_NOPM instead of MAX98520_R209F_AMP_EN.

Quoted 7 lines

sound/soc/codecs/max98520.c

Quoted 4 lines
sound/soc/codecs/max98520.c new file +3 -0
+static DECLARE_TLV_DB_SCALE(max98520_digital_tlv, -6300, 50, 1);
+static const DECLARE_TLV_DB_RANGE(max98520_spk_tlv,
+	0, 5, TLV_DB_SCALE_ITEM(600, 300, 0), );

Why is _digital_tlv not const? It's also a bit weird that _spk_tlv is a range with one entry not a scale.

It will be added const casting in front of DECLARE_TLV_DB_SCALE.

Quoted 7 lines

sound/soc/codecs/max98520.c

Quoted 6 lines
sound/soc/codecs/max98520.c new file +5 -0
+	count = 0;
+	while (count < 3) {
+		usleep_range(10000, 11000);
+		/* Software Reset Verification */
+		ret = regmap_read(max98520->regmap,

MAX98520_R21FF_REVISION_ID, &reg);

Quoted 7 lines

sound/soc/codecs/max98520.c line 575

Quoted 5 lines
sound/soc/codecs/max98520.c new file +5 -0
+		if (!ret) {
+			dev_info(dev, "Reset completed (retry:%d)\n", count);
+			return;
+		}
+		count++;

Does this really need to be logged?

It will be removed for logging regarding reset completed.

Quoted 7 lines

sound/soc/codecs/max98520.c line 587

Quoted 4 lines
sound/soc/codecs/max98520.c new file +3 -0
+	/* Software Reset */
+	max98520_reset(max98520, component->dev);
+	usleep_range(30000, 31000);

Shouldn't that delay be in the reset routine? Perhaps between the attempts to read the ID register?

It will be removed 30ms sleep after reset function.

Quoted 8 lines

sound/soc/codecs/max98520.c line 592

Quoted 5 lines
sound/soc/codecs/max98520.c new file +4 -0
+	/* L/R mix configuration */
+	regmap_write(max98520->regmap, MAX98520_R2043_PCM_RX_SRC1, 0x2);
+
+	regmap_write(max98520->regmap, MAX98520_R2044_PCM_RX_SRC2, 0x10);

These should be exposed to the user, not hard coded - different systems may need different configurations.

It`s already exposed for 2043 register which is regarding mono mixer for "DAI Sel Mux" It will be exposed for 2044 register which is regarding pcm input channel selection to dapm mixer.

Quoted 8 lines

sound/soc/codecs/max98520.c

Quoted 4 lines
sound/soc/codecs/max98520.c new file +3 -0
+	/* Disable Speaker Safe Mode */
+	regmap_update_bits(max98520->regmap,
+			   MAX98520_R2092_AMP_DSP_CFG,

MAX98520_SPK_SAFE_EN_MASK, 0);

This seems like something that should be left as is by default given the name (or forced on if it were disabled by default)?

It will be removed to be left as is by default given the name.

Quoted 8 lines

sound/soc/codecs/max98520.c line 605

Quoted 6 lines
sound/soc/codecs/max98520.c new file +5 -0
+	/* Hard coded values for the experiments */
+	regmap_write(max98520->regmap, MAX98520_R21FF_REVISION_ID, 0x54);
+	regmap_write(max98520->regmap, MAX98520_R21FF_REVISION_ID, 0x4d);
+	regmap_write(max98520->regmap, MAX98520_R2161_BOOST_TM1, 0x2);
+	regmap_write(max98520->regmap, MAX98520_R2095_AMP_CFG, 0xc8);

This doesn't seem suitable for upstream.

They will be removed.

Quoted 9 lines

sound/soc/codecs/max98520.c line 700

Quoted 5 lines
sound/soc/codecs/max98520.c new file +4 -0
+	/* Power on device */
+	if (gpio_is_valid(max98520->reset_gpio)) {
+		ret = devm_gpio_request(&i2c->dev, max98520->reset_gpio,
+					"MAX98520_RESET");

You should use the gpiod APIs for new code, not the legacy GPIO interface. This GPIO wasn't mentioned in the DT bindings but should have been described there.

It will be modified to gpiod APIs like devm_gpiod_get_optional for getting reset_gpio (struct gpio_desc *reset_gpio).

Quoted 13 lines

sound/soc/codecs/max98520.c line 710

Quoted 11 lines
sound/soc/codecs/max98520.c new file +10 -0
+		if (ret) {
+			dev_err(&i2c->dev, "%s: Failed to request gpio %d\n",
+				__func__, max98520->reset_gpio);
+			return -EINVAL;
+		}
+		gpio_direction_output(max98520->reset_gpio, 0);
+		msleep(50);
+		gpio_direction_output(max98520->reset_gpio, 1);
+		msleep(20);
+	}

Shouldn't the disable/enable of the reset GPIO be in the reset function?

It will be modified to gpiod APIs like gpiod_set_value_cansleep function instead of gpio_direction_output.

maintainer
#4 lore raw

Re: [EXTERNAL] Re: [v3 2/2] ASoC: max98520: add max98520 audio amplifier driver

Quoted 9 lines · George Song
Quoted 7 lines

sound/soc/codecs/max98520.c line 592

Quoted 4 lines
sound/soc/codecs/max98520.c new file +4 -0
+	/* L/R mix configuration */
+	regmap_write(max98520->regmap, MAX98520_R2043_PCM_RX_SRC1, 0x2);
+
+	regmap_write(max98520->regmap, MAX98520_R2044_PCM_RX_SRC2, 0x10);

These should be exposed to the user, not hard coded - different systems may need different configurations.

It`s already exposed for 2043 register which is regarding mono mixer for "DAI Sel Mux" It will be exposed for 2044 register which is regarding pcm input channel selection to dapm mixer.

Then leave the values at the defaults and let the user select what's sensible for their system.

Please fix your mail client to word wrap within paragraphs at something substantially less than 80 columns. Doing this makes your messages much easier to read and reply to.

#5 lore raw

RE: [EXTERNAL] Re: [v3 2/2] ASoC: max98520: add max98520 audio amplifier driver

Quoted 12 lines · George Song
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+	/* L/R mix configuration */
+	regmap_write(max98520->regmap,

MAX98520_R2043_PCM_RX_SRC1, 0x2);

Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	regmap_write(max98520->regmap,

MAX98520_R2044_PCM_RX_SRC2,

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

+0x10);

These should be exposed to the user, not hard coded - different systems may need different configurations.

Quoted 7 lines
Quoted 1 line

It`s already exposed for 2043 register which is regarding mono

mixer for "DAI Sel Mux"

Quoted 1 line

It will be exposed for 2044 register which is regarding pcm input

channel selection to dapm mixer.

Then leave the values at the defaults and let the user select what's sensible for their system.

It will be left the default value in probe function and described mixer/widget comment

Quoted 4 lines

Please fix your mail client to word wrap within paragraphs at something substantially less than 80 columns. Doing this makes your messages much easier to read and reply to.

OK I see.