Skip to contentSkip to conversation

ASoC: dt-bindings: max98396: add amplifier driver

PATCH Superseded Ryan Lee 2 participants 3 messages Apr 21, 2022 – Apr 22, 2022

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ryan Lee

author
#0 lore raw

PATCH v2 1/2 ASoC: dt-bindings: max98396: add amplifier driver

From: Ryan Lee <[email protected]>

This patch adds dt-bindings information for Analog Devices MAX98396 and MAX98397 Smart Amplifier.

---
Changes from v1:
Fixed yamllint/dtschema/dtc warnings and errors

 .../bindings/sound/adi,max98396.yaml          | 79 +++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/adi,max98396.yaml
Documentation/devicetree/bindings/sound/adi,max98396.yaml new file +79 -0
new file mode 100644
index 000000000000..ec4c10c2598a
@@ -0,0 +1,79 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/adi,max98396.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices MAX98396 Speaker Amplifier Device Tree Bindings
+
+maintainers:
+  - Ryan Lee <[email protected]>
+
+description:
+  The MAX98396 is a mono Class-DG speaker amplifier with I/V sense.
+  The device provides a PCM interface for audio data and a standard
+  I2C interface for control data communication.
+  The MAX98397 is a variant of MAX98396 with wide input supply range.
+
+properties:
+  compatible:
+    enum:
+      - adi,max98396
+      - adi,max98397
+  reg:
+    maxItems: 1
+    description: I2C address of the device.
+
+  adi,vmon-slot-no:
+    description: slot number of the voltage sense monitor
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  adi,imon-slot-no:
+    description: slot number of the current sense monitor
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  adi,spkfb-slot-no:
+    description: slot number of speaker DSP monitor
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  adi,interleave-mode:
+    description:
+      For cases where a single combined channel for the I/V sense data
+      is not sufficient, the device can also be configured to share
+      a single data output channel on alternating frames.
+      In this configuration, the current and voltage data will be frame
+      interleaved on a single output channel.
+    type: boolean
+
+  reset-gpios:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        max98396: amplifier@39 {
+            compatible = "adi,max98396";
+            reg = <0x39>;
+            adi,vmon-slot-no = <0>;
+            adi,imon-slot-no = <1>;
+            reset-gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
+        };
+    };
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 2/2 ASoC: max98396: add amplifier driver

This series of patches adds support for Analog Devices MAX98396 mono amplifier with IV sense. The device provides a PCM interface for audio data and a standard I2C interface for control data communication. This driver also supports MAX98397 which is a variant of MAX98396 with wide input supply range.

---
Changes from v1:
: Fixed DAI format configuration issue. BCLK/FRSYNC polarity configuration was inappropriate.
: max98396_mux_put function return 1 if the value changed. Otherwise the function return 0 or -EINVAL;
: Modified wrong amp POR(Power On Register) value in max98396_reg.

 sound/soc/codecs/Kconfig    |   10 +
 sound/soc/codecs/Makefile   |    2 +
 sound/soc/codecs/max98396.c | 1640 +++++++++++++++++++++++++++++++++++
 sound/soc/codecs/max98396.h |  306 +++++++
 4 files changed, 1958 insertions(+)
 create mode 100644 sound/soc/codecs/max98396.c
 create mode 100644 sound/soc/codecs/max98396.h
sound/soc/codecs/Kconfig +10 -0
index f46a22660103..7881e6120dea 100644
@@ -127,6 +127,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_MAX98373_I2C
 	imply SND_SOC_MAX98373_SDW
 	imply SND_SOC_MAX98390
+	imply SND_SOC_MAX98396
 	imply SND_SOC_MAX9850
 	imply SND_SOC_MAX9860
 	imply SND_SOC_MAX9759
@@ -1015,6 +1016,15 @@ config SND_SOC_MAX98390
 	tristate "Maxim Integrated MAX98390 Speaker Amplifier"
 	depends on I2C
 
+config SND_SOC_MAX98396
+	tristate "Analog Devices MAX98396 Speaker Amplifier"
+	depends on I2C
+	help
+	  Enable support for Analog Devices MAX98396 audio
+	  amplifier. The device provides a PCM interface for
+	  audio data and a standard I2C interface for control
+	  data communication.
+
 config SND_SOC_MAX9850
 	tristate
 	depends on I2C
sound/soc/codecs/Makefile +2 -0
index 8637e9e869e3..8bfe32cbcb06 100644
@@ -135,6 +135,7 @@ 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-max98396-objs := max98396.o
 snd-soc-max9850-objs := max9850.o
 snd-soc-max9860-objs := max9860.o
 snd-soc-mc13783-objs := mc13783.o
@@ -474,6 +475,7 @@ 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_MAX98396)	+= snd-soc-max98396.o
 obj-$(CONFIG_SND_SOC_MAX9850)	+= snd-soc-max9850.o
 obj-$(CONFIG_SND_SOC_MAX9860)	+= snd-soc-max9860.o
 obj-$(CONFIG_SND_SOC_MC13783)	+= snd-soc-mc13783.o
sound/soc/codecs/max98396.c new file +1640 -0

1,640 lines not on this page · raw message

sound/soc/codecs/max98396.h new file +306 -0

306 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH V2 2/2] ASoC: max98396: add amplifier driver

Thank you for the patch! Perhaps something to improve:

Hi Ryan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on broonie-sound/for-next]
[also build test WARNING on v5.18-rc3 next-20220421]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Ryan-Lee/ASoC-dt-bindings-max98396-add-amplifier-driver/20220422-070610
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
config: arm-buildonly-randconfig-r003-20220421 (https://download.01.org/0day-ci/archive/20220422/[email protected]/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 5bd87350a5ae429baf8f373cb226a57b62f87280)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# https://github.com/intel-lab-lkp/linux/commit/1acb9ac9acbd834a2e93c2127be6bdd1716dc6dd
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ryan-Lee/ASoC-dt-bindings-max98396-add-amplifier-driver/20220422-070610 git checkout 1acb9ac9acbd834a2e93c2127be6bdd1716dc6dd
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash sound/soc/codecs/

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> sound/soc/codecs/max98396.c:408:7: warning: variable 'update' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
                   if (format != (reg & MAX98396_PCM_MODE_CFG_FORMAT_MASK))
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   sound/soc/codecs/max98396.c:411:7: note: uninitialized use occurs here
                   if (update)
                       ^~~~~~
   sound/soc/codecs/max98396.c:408:3: note: remove the 'if' if its condition is always true
                   if (format != (reg & MAX98396_PCM_MODE_CFG_FORMAT_MASK))
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   sound/soc/codecs/max98396.c:349:13: note: initialize the variable 'update' to silence this warning
           bool update;
                      ^
                       = 0

1 warning generated.

vim +408 sound/soc/codecs/max98396.c

339
340 static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
341 {
342 struct snd_soc_component *component = codec_dai->component;
343 struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component);
344 unsigned int format;
345 unsigned int bclk_pol = 0;
346 unsigned int fsync_pol = 0;
347 int ret, status;
348 int reg;
349 bool update;
350
351 dev_dbg(component->dev, "%s: fmt 0x%08X\n", __func__, fmt);
352
353 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
354 case SND_SOC_DAIFMT_NB_NF:
355 break;
356 case SND_SOC_DAIFMT_NB_IF:
357 fsync_pol = MAX98396_PCM_MODE_CFG_PCM_LRCLKEDGE;
358 break;
359 case SND_SOC_DAIFMT_IB_NF:
360 bclk_pol = MAX98396_PCM_MODE_CFG_PCM_BCLKEDGE;
361 break;
362 case SND_SOC_DAIFMT_IB_IF:
363 bclk_pol = MAX98396_PCM_MODE_CFG_PCM_BCLKEDGE;
364 fsync_pol = MAX98396_PCM_MODE_CFG_PCM_LRCLKEDGE;
365 break;
366
367 default:
368 dev_err(component->dev, "DAI invert mode unsupported\n");
369 return -EINVAL;
370 }
371
372 regmap_update_bits(max98396->regmap,

   373				   MAX98396_R2041_PCM_MODE_CFG,
   374				   MAX98396_PCM_MODE_CFG_PCM_LRCLKEDGE,
   375				   fsync_pol);
   376	
   377		regmap_update_bits(max98396->regmap,
   378				   MAX98396_R2042_PCM_CLK_SETUP,
   379				   MAX98396_PCM_MODE_CFG_PCM_BCLKEDGE,
   380				   bclk_pol);
   381	
   382		/* interface format */
   383		switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
   384		case SND_SOC_DAIFMT_I2S:
   385			format = MAX98396_PCM_FORMAT_I2S;
   386			break;
   387		case SND_SOC_DAIFMT_LEFT_J:
   388			format = MAX98396_PCM_FORMAT_LJ;
   389			break;
   390		case SND_SOC_DAIFMT_DSP_A:
   391			format = MAX98396_PCM_FORMAT_TDM_MODE1;
   392			break;
   393		case SND_SOC_DAIFMT_DSP_B:
   394			format = MAX98396_PCM_FORMAT_TDM_MODE0;
   395			break;
   396		default:
   397			return -EINVAL;
   398		}
   399	
   400		ret = regmap_read(max98396->regmap, MAX98396_R210F_GLOBAL_EN, &status);
   401		if (ret < 0)
   402			return -EINVAL;
   403	
   404		if (status) {
   405			ret = regmap_read(max98396->regmap, MAX98396_R2041_PCM_MODE_CFG, &reg);
   406			if (ret < 0)
   407				return -EINVAL;
 > 408			if (format != (reg & MAX98396_PCM_MODE_CFG_FORMAT_MASK))
   409				update = true;
   410			/* GLOBAL_EN OFF prior to pcm mode change */
   411			if (update)
   412				max98396_global_enable_onoff(max98396->regmap, false);
   413		}
   414	
   415		regmap_update_bits(max98396->regmap,
   416				   MAX98396_R2041_PCM_MODE_CFG,
   417				   MAX98396_PCM_MODE_CFG_FORMAT_MASK,
   418				   format);

419
420 if (status && update)
421 max98396_global_enable_onoff(max98396->regmap, true);
422
423 return 0;
424 }
425

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp