All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/8] ASoC: max98396: Some assorted fixes and additions
@ 2022-06-24 10:47 ` Daniel Mack
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: devicetree, alsa-devel, robh+dt, Daniel Mack

This is a series of some patches that I collected while using the
max98396 driver is a TDM mode setup.

They correct BSEL and PCM mode configs, add support for power supplies
and add some bits to the documentation.

The code is tested in TDM-16 and TDM-8 mode with 32 channel width.


Thanks,
Daniel

Daniel Mack (8):
  ASoC: dt-bindings: max98396: add voltage supplies
  ASoC: dt-bindings: max98396: Add #sound-dai-cells
  ASoC: dt-bindings: max98396: Document adi,bypass-slot-no
  ASoC: max98396: add voltage regulators
  ASoC: max98396: Improve some error prints
  ASoC: max98396: Fix register access for PCM format settings
  ASoC: max98396: Implement DSP speaker monitor
  ASoC: max98396: Fix TDM mode BSEL settings

 .../bindings/sound/adi,max98396.yaml          |  34 ++-
 sound/soc/codecs/max98396.c                   | 265 ++++++++++++++----
 sound/soc/codecs/max98396.h                   |   8 +
 3 files changed, 257 insertions(+), 50 deletions(-)

-- 
2.36.1


^ permalink raw reply	[flat|nested] 34+ messages in thread

* [PATCH 0/8] ASoC: max98396: Some assorted fixes and additions
@ 2022-06-24 10:47 ` Daniel Mack
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: robh+dt, alsa-devel, devicetree, Daniel Mack

This is a series of some patches that I collected while using the
max98396 driver is a TDM mode setup.

They correct BSEL and PCM mode configs, add support for power supplies
and add some bits to the documentation.

The code is tested in TDM-16 and TDM-8 mode with 32 channel width.


Thanks,
Daniel

Daniel Mack (8):
  ASoC: dt-bindings: max98396: add voltage supplies
  ASoC: dt-bindings: max98396: Add #sound-dai-cells
  ASoC: dt-bindings: max98396: Document adi,bypass-slot-no
  ASoC: max98396: add voltage regulators
  ASoC: max98396: Improve some error prints
  ASoC: max98396: Fix register access for PCM format settings
  ASoC: max98396: Implement DSP speaker monitor
  ASoC: max98396: Fix TDM mode BSEL settings

 .../bindings/sound/adi,max98396.yaml          |  34 ++-
 sound/soc/codecs/max98396.c                   | 265 ++++++++++++++----
 sound/soc/codecs/max98396.h                   |   8 +
 3 files changed, 257 insertions(+), 50 deletions(-)

-- 
2.36.1


^ permalink raw reply	[flat|nested] 34+ messages in thread

* [PATCH 1/8] ASoC: dt-bindings: max98396: add voltage supplies
  2022-06-24 10:47 ` Daniel Mack
@ 2022-06-24 10:47   ` Daniel Mack
  -1 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: devicetree, alsa-devel, robh+dt, Daniel Mack

The device is supplied with 3 core voltages (DVVDIO, DVDD, AVDD), and
PVDD and/or VBAT.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 .../bindings/sound/adi,max98396.yaml          | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/adi,max98396.yaml b/Documentation/devicetree/bindings/sound/adi,max98396.yaml
index ec4c10c2598a..a23ac8036e1c 100644
--- a/Documentation/devicetree/bindings/sound/adi,max98396.yaml
+++ b/Documentation/devicetree/bindings/sound/adi,max98396.yaml
@@ -24,6 +24,21 @@ properties:
     maxItems: 1
     description: I2C address of the device.
 
+  avdd-supply:
+    description: A 1.8V supply that powers up the AVDD pin.
+
+  dvdd-supply:
+    description: A 1.2V supply that powers up the DVDD pin.
+
+  dvddio-supply:
+    description: A 1.2V or 1.8V supply that powers up the VDDIO pin.
+
+  pvdd-supply:
+    description: A 3.0V to 20V supply that powers up the PVDD pin.
+
+  vbat-supply:
+    description: A 3.3V to 5.5V supply that powers up the VBAT pin.
+
   adi,vmon-slot-no:
     description: slot number of the voltage sense monitor
     $ref: "/schemas/types.yaml#/definitions/uint32"
@@ -72,6 +87,10 @@ examples:
         max98396: amplifier@39 {
             compatible = "adi,max98396";
             reg = <0x39>;
+            dvdd-supply = <&regulator_1v2>;
+            dvddio-supply = <&regulator_1v8>;
+            avdd-supply = <&regulator_1v8>;
+            pvdd-supply = <&regulator_pvdd>;
             adi,vmon-slot-no = <0>;
             adi,imon-slot-no = <1>;
             reset-gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 1/8] ASoC: dt-bindings: max98396: add voltage supplies
@ 2022-06-24 10:47   ` Daniel Mack
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: robh+dt, alsa-devel, devicetree, Daniel Mack

The device is supplied with 3 core voltages (DVVDIO, DVDD, AVDD), and
PVDD and/or VBAT.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 .../bindings/sound/adi,max98396.yaml          | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/adi,max98396.yaml b/Documentation/devicetree/bindings/sound/adi,max98396.yaml
index ec4c10c2598a..a23ac8036e1c 100644
--- a/Documentation/devicetree/bindings/sound/adi,max98396.yaml
+++ b/Documentation/devicetree/bindings/sound/adi,max98396.yaml
@@ -24,6 +24,21 @@ properties:
     maxItems: 1
     description: I2C address of the device.
 
+  avdd-supply:
+    description: A 1.8V supply that powers up the AVDD pin.
+
+  dvdd-supply:
+    description: A 1.2V supply that powers up the DVDD pin.
+
+  dvddio-supply:
+    description: A 1.2V or 1.8V supply that powers up the VDDIO pin.
+
+  pvdd-supply:
+    description: A 3.0V to 20V supply that powers up the PVDD pin.
+
+  vbat-supply:
+    description: A 3.3V to 5.5V supply that powers up the VBAT pin.
+
   adi,vmon-slot-no:
     description: slot number of the voltage sense monitor
     $ref: "/schemas/types.yaml#/definitions/uint32"
@@ -72,6 +87,10 @@ examples:
         max98396: amplifier@39 {
             compatible = "adi,max98396";
             reg = <0x39>;
+            dvdd-supply = <&regulator_1v2>;
+            dvddio-supply = <&regulator_1v8>;
+            avdd-supply = <&regulator_1v8>;
+            pvdd-supply = <&regulator_pvdd>;
             adi,vmon-slot-no = <0>;
             adi,imon-slot-no = <1>;
             reset-gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 2/8] ASoC: dt-bindings: max98396: Add #sound-dai-cells
  2022-06-24 10:47 ` Daniel Mack
@ 2022-06-24 10:47   ` Daniel Mack
  -1 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: devicetree, alsa-devel, robh+dt, Daniel Mack

Add this mandatory DT property to the yaml documentation.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 Documentation/devicetree/bindings/sound/adi,max98396.yaml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/adi,max98396.yaml b/Documentation/devicetree/bindings/sound/adi,max98396.yaml
index a23ac8036e1c..8887e74b7ea5 100644
--- a/Documentation/devicetree/bindings/sound/adi,max98396.yaml
+++ b/Documentation/devicetree/bindings/sound/adi,max98396.yaml
@@ -72,6 +72,9 @@ properties:
   reset-gpios:
     maxItems: 1
 
+  "#sound-dai-cells":
+    const: 0
+
 required:
   - compatible
   - reg
@@ -94,5 +97,6 @@ examples:
             adi,vmon-slot-no = <0>;
             adi,imon-slot-no = <1>;
             reset-gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
+            #sound-dai-cells: <0>;
         };
     };
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 2/8] ASoC: dt-bindings: max98396: Add #sound-dai-cells
@ 2022-06-24 10:47   ` Daniel Mack
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: robh+dt, alsa-devel, devicetree, Daniel Mack

Add this mandatory DT property to the yaml documentation.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 Documentation/devicetree/bindings/sound/adi,max98396.yaml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/adi,max98396.yaml b/Documentation/devicetree/bindings/sound/adi,max98396.yaml
index a23ac8036e1c..8887e74b7ea5 100644
--- a/Documentation/devicetree/bindings/sound/adi,max98396.yaml
+++ b/Documentation/devicetree/bindings/sound/adi,max98396.yaml
@@ -72,6 +72,9 @@ properties:
   reset-gpios:
     maxItems: 1
 
+  "#sound-dai-cells":
+    const: 0
+
 required:
   - compatible
   - reg
@@ -94,5 +97,6 @@ examples:
             adi,vmon-slot-no = <0>;
             adi,imon-slot-no = <1>;
             reset-gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
+            #sound-dai-cells: <0>;
         };
     };
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 3/8] ASoC: dt-bindings: max98396: Document adi,bypass-slot-no
  2022-06-24 10:47 ` Daniel Mack
@ 2022-06-24 10:47   ` Daniel Mack
  -1 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: devicetree, alsa-devel, robh+dt, Daniel Mack

This property allows to select the PCM data input channel that is
routed to the speaker audio processing bypass path.

The driver already implements this property.

While at it, fix the default value for adi,imon-slot-no.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 .../devicetree/bindings/sound/adi,max98396.yaml       | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/sound/adi,max98396.yaml b/Documentation/devicetree/bindings/sound/adi,max98396.yaml
index 8887e74b7ea5..c848397a7248 100644
--- a/Documentation/devicetree/bindings/sound/adi,max98396.yaml
+++ b/Documentation/devicetree/bindings/sound/adi,max98396.yaml
@@ -51,13 +51,22 @@ properties:
     $ref: "/schemas/types.yaml#/definitions/uint32"
     minimum: 0
     maximum: 15
-    default: 0
+    default: 1
 
   adi,spkfb-slot-no:
     description: slot number of speaker DSP monitor
     $ref: "/schemas/types.yaml#/definitions/uint32"
     minimum: 0
     maximum: 15
+    default: 2
+
+  adi,bypass-slot-no:
+    description:
+      Selects the PCM data input channel that is routed to the speaker
+      audio processing bypass path.
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 15
     default: 0
 
   adi,interleave-mode:
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 3/8] ASoC: dt-bindings: max98396: Document adi,bypass-slot-no
@ 2022-06-24 10:47   ` Daniel Mack
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: robh+dt, alsa-devel, devicetree, Daniel Mack

This property allows to select the PCM data input channel that is
routed to the speaker audio processing bypass path.

The driver already implements this property.

While at it, fix the default value for adi,imon-slot-no.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 .../devicetree/bindings/sound/adi,max98396.yaml       | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/sound/adi,max98396.yaml b/Documentation/devicetree/bindings/sound/adi,max98396.yaml
index 8887e74b7ea5..c848397a7248 100644
--- a/Documentation/devicetree/bindings/sound/adi,max98396.yaml
+++ b/Documentation/devicetree/bindings/sound/adi,max98396.yaml
@@ -51,13 +51,22 @@ properties:
     $ref: "/schemas/types.yaml#/definitions/uint32"
     minimum: 0
     maximum: 15
-    default: 0
+    default: 1
 
   adi,spkfb-slot-no:
     description: slot number of speaker DSP monitor
     $ref: "/schemas/types.yaml#/definitions/uint32"
     minimum: 0
     maximum: 15
+    default: 2
+
+  adi,bypass-slot-no:
+    description:
+      Selects the PCM data input channel that is routed to the speaker
+      audio processing bypass path.
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 15
     default: 0
 
   adi,interleave-mode:
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 4/8] ASoC: max98396: add voltage regulators
  2022-06-24 10:47 ` Daniel Mack
@ 2022-06-24 10:47   ` Daniel Mack
  -1 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: devicetree, alsa-devel, robh+dt, Daniel Mack

The device has up to 5 potentially independent power supplies:
AVDD, DVDD, DVVDIO, VBAT and PVDD. The former 3 are mandatory for the
device to function. One of VBAT and PVDD should also be made available.

Regulators are enabled during probe time and will stay active except when in
suspend mode.

Futher, the chip needs to be informed about the presence of VBAT through a
bit in register 0x20a0.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 sound/soc/codecs/max98396.c | 117 +++++++++++++++++++++++++++++++++++-
 sound/soc/codecs/max98396.h |   7 +++
 2 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c
index 56eb62bb041f..06ac637f2696 100644
--- a/sound/soc/codecs/max98396.c
+++ b/sound/soc/codecs/max98396.c
@@ -5,11 +5,18 @@
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <sound/pcm_params.h>
+#include <linux/regulator/consumer.h>
 #include <sound/soc.h>
 #include <linux/gpio.h>
 #include <sound/tlv.h>
 #include "max98396.h"
 
+static const char * const max98396_core_supplies[MAX98396_NUM_CORE_SUPPLIES] = {
+	"avdd",
+	"dvdd",
+	"dvddio",
+};
+
 static struct reg_default max98396_reg[] = {
 	{MAX98396_R2000_SW_RESET, 0x00},
 	{MAX98396_R2001_INT_RAW1, 0x00},
@@ -1329,6 +1336,12 @@ static int max98396_probe(struct snd_soc_component *component)
 		regmap_write(max98396->regmap,
 			     MAX98397_R2057_PCM_RX_SRC2, 0x10);
 	}
+	/* Supply control */
+	regmap_update_bits(max98396->regmap,
+			   MAX98396_R20A0_AMP_SUPPLY_CTL,
+			   MAX98396_AMP_SUPPLY_NOVBAT,
+			   (max98396->vbat == NULL) ?
+				MAX98396_AMP_SUPPLY_NOVBAT : 0);
 	/* Enable DC blocker */
 	regmap_update_bits(max98396->regmap,
 			   MAX98396_R2092_AMP_DSP_CFG, 1, 1);
@@ -1424,12 +1437,38 @@ static int max98396_suspend(struct device *dev)
 
 	regcache_cache_only(max98396->regmap, true);
 	regcache_mark_dirty(max98396->regmap);
+	regulator_bulk_disable(MAX98396_NUM_CORE_SUPPLIES,
+			       max98396->core_supplies);
+	if (max98396->pvdd)
+		regulator_disable(max98396->pvdd);
+
+	if (max98396->vbat)
+		regulator_disable(max98396->vbat);
+
 	return 0;
 }
 
 static int max98396_resume(struct device *dev)
 {
 	struct max98396_priv *max98396 = dev_get_drvdata(dev);
+	int ret;
+
+	ret = regulator_bulk_enable(MAX98396_NUM_CORE_SUPPLIES,
+				    max98396->core_supplies);
+	if (ret < 0)
+		return ret;
+
+	if (max98396->pvdd) {
+		ret = regulator_enable(max98396->pvdd);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (max98396->vbat) {
+		ret = regulator_enable(max98396->vbat);
+		if (ret < 0)
+			return ret;
+	}
 
 	regcache_cache_only(max98396->regmap, false);
 	max98396_reset(max98396, dev);
@@ -1513,11 +1552,24 @@ static void max98396_read_device_property(struct device *dev,
 		max98396->bypass_slot = 0;
 }
 
+static void max98396_core_supplies_disable(void *priv)
+{
+	struct max98396_priv *max98396 = priv;
+
+	regulator_bulk_disable(MAX98396_NUM_CORE_SUPPLIES,
+			       max98396->core_supplies);
+}
+
+static void max98396_supply_disable(void *r)
+{
+	regulator_disable((struct regulator *) r);
+}
+
 static int max98396_i2c_probe(struct i2c_client *i2c,
 			      const struct i2c_device_id *id)
 {
 	struct max98396_priv *max98396 = NULL;
-	int ret, reg;
+	int i, ret, reg;
 
 	max98396 = devm_kzalloc(&i2c->dev, sizeof(*max98396), GFP_KERNEL);
 
@@ -1543,6 +1595,69 @@ static int max98396_i2c_probe(struct i2c_client *i2c,
 		return ret;
 	}
 
+	/* Obtain regulator supplies */
+	for (i = 0; i < MAX98396_NUM_CORE_SUPPLIES; i++)
+		max98396->core_supplies[i].supply = max98396_core_supplies[i];
+
+	ret = devm_regulator_bulk_get(&i2c->dev, MAX98396_NUM_CORE_SUPPLIES,
+				      max98396->core_supplies);
+	if (ret < 0) {
+		dev_err(&i2c->dev, "Failed to request core supplies: %d\n", ret);
+		return ret;
+	}
+
+	max98396->vbat = devm_regulator_get_optional(&i2c->dev, "vbat");
+	if (IS_ERR(max98396->vbat)) {
+		if (PTR_ERR(max98396->vbat) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+
+		max98396->vbat = NULL;
+	}
+
+	max98396->pvdd = devm_regulator_get_optional(&i2c->dev, "pvdd");
+	if (IS_ERR(max98396->pvdd)) {
+		if (PTR_ERR(max98396->pvdd) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+
+		max98396->pvdd = NULL;
+	}
+
+	ret = regulator_bulk_enable(MAX98396_NUM_CORE_SUPPLIES,
+				    max98396->core_supplies);
+	if (ret < 0) {
+		dev_err(&i2c->dev, "Unable to enable core supplies: %d", ret);
+		return ret;
+	}
+
+	ret = devm_add_action_or_reset(&i2c->dev, max98396_core_supplies_disable,
+				       max98396);
+	if (ret < 0)
+		return ret;
+
+	if (max98396->pvdd) {
+		ret = regulator_enable(max98396->pvdd);
+		if (ret < 0)
+			return ret;
+
+		ret = devm_add_action_or_reset(&i2c->dev,
+					       max98396_supply_disable,
+					       max98396->pvdd);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (max98396->vbat) {
+		ret = regulator_enable(max98396->vbat);
+		if (ret < 0)
+			return ret;
+
+		ret = devm_add_action_or_reset(&i2c->dev,
+					       max98396_supply_disable,
+					       max98396->vbat);
+		if (ret < 0)
+			return ret;
+	}
+
 	/* update interleave mode info */
 	if (device_property_read_bool(&i2c->dev, "adi,interleave_mode"))
 		max98396->interleave_mode = true;
diff --git a/sound/soc/codecs/max98396.h b/sound/soc/codecs/max98396.h
index 694411038597..8fa081f5d2d3 100644
--- a/sound/soc/codecs/max98396.h
+++ b/sound/soc/codecs/max98396.h
@@ -274,6 +274,9 @@
 #define MAX98396_DSP_SPK_SAFE_EN_SHIFT		(5)
 #define MAX98396_DSP_SPK_WB_FLT_EN_SHIFT	(6)
 
+/* MAX98396_R20A0_AMP_SUPPLY_CTL */
+#define MAX98396_AMP_SUPPLY_NOVBAT		(0x1 << 0)
+
 /* MAX98396_R20E0_IV_SENSE_PATH_CFG */
 #define MAX98396_IV_SENSE_DCBLK_EN_MASK		(0x3 << 0)
 #define MAX98396_IV_SENSE_DCBLK_EN_SHIFT	(0)
@@ -291,9 +294,13 @@ enum {
 	CODEC_TYPE_MAX98397,
 };
 
+#define  MAX98396_NUM_CORE_SUPPLIES 3
+
 struct max98396_priv {
 	struct regmap *regmap;
 	struct gpio_desc *reset_gpio;
+	struct regulator_bulk_data core_supplies[MAX98396_NUM_CORE_SUPPLIES];
+	struct regulator *pvdd, *vbat;
 	unsigned int v_slot;
 	unsigned int i_slot;
 	unsigned int bypass_slot;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 4/8] ASoC: max98396: add voltage regulators
@ 2022-06-24 10:47   ` Daniel Mack
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: robh+dt, alsa-devel, devicetree, Daniel Mack

The device has up to 5 potentially independent power supplies:
AVDD, DVDD, DVVDIO, VBAT and PVDD. The former 3 are mandatory for the
device to function. One of VBAT and PVDD should also be made available.

Regulators are enabled during probe time and will stay active except when in
suspend mode.

Futher, the chip needs to be informed about the presence of VBAT through a
bit in register 0x20a0.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 sound/soc/codecs/max98396.c | 117 +++++++++++++++++++++++++++++++++++-
 sound/soc/codecs/max98396.h |   7 +++
 2 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c
index 56eb62bb041f..06ac637f2696 100644
--- a/sound/soc/codecs/max98396.c
+++ b/sound/soc/codecs/max98396.c
@@ -5,11 +5,18 @@
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <sound/pcm_params.h>
+#include <linux/regulator/consumer.h>
 #include <sound/soc.h>
 #include <linux/gpio.h>
 #include <sound/tlv.h>
 #include "max98396.h"
 
+static const char * const max98396_core_supplies[MAX98396_NUM_CORE_SUPPLIES] = {
+	"avdd",
+	"dvdd",
+	"dvddio",
+};
+
 static struct reg_default max98396_reg[] = {
 	{MAX98396_R2000_SW_RESET, 0x00},
 	{MAX98396_R2001_INT_RAW1, 0x00},
@@ -1329,6 +1336,12 @@ static int max98396_probe(struct snd_soc_component *component)
 		regmap_write(max98396->regmap,
 			     MAX98397_R2057_PCM_RX_SRC2, 0x10);
 	}
+	/* Supply control */
+	regmap_update_bits(max98396->regmap,
+			   MAX98396_R20A0_AMP_SUPPLY_CTL,
+			   MAX98396_AMP_SUPPLY_NOVBAT,
+			   (max98396->vbat == NULL) ?
+				MAX98396_AMP_SUPPLY_NOVBAT : 0);
 	/* Enable DC blocker */
 	regmap_update_bits(max98396->regmap,
 			   MAX98396_R2092_AMP_DSP_CFG, 1, 1);
@@ -1424,12 +1437,38 @@ static int max98396_suspend(struct device *dev)
 
 	regcache_cache_only(max98396->regmap, true);
 	regcache_mark_dirty(max98396->regmap);
+	regulator_bulk_disable(MAX98396_NUM_CORE_SUPPLIES,
+			       max98396->core_supplies);
+	if (max98396->pvdd)
+		regulator_disable(max98396->pvdd);
+
+	if (max98396->vbat)
+		regulator_disable(max98396->vbat);
+
 	return 0;
 }
 
 static int max98396_resume(struct device *dev)
 {
 	struct max98396_priv *max98396 = dev_get_drvdata(dev);
+	int ret;
+
+	ret = regulator_bulk_enable(MAX98396_NUM_CORE_SUPPLIES,
+				    max98396->core_supplies);
+	if (ret < 0)
+		return ret;
+
+	if (max98396->pvdd) {
+		ret = regulator_enable(max98396->pvdd);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (max98396->vbat) {
+		ret = regulator_enable(max98396->vbat);
+		if (ret < 0)
+			return ret;
+	}
 
 	regcache_cache_only(max98396->regmap, false);
 	max98396_reset(max98396, dev);
@@ -1513,11 +1552,24 @@ static void max98396_read_device_property(struct device *dev,
 		max98396->bypass_slot = 0;
 }
 
+static void max98396_core_supplies_disable(void *priv)
+{
+	struct max98396_priv *max98396 = priv;
+
+	regulator_bulk_disable(MAX98396_NUM_CORE_SUPPLIES,
+			       max98396->core_supplies);
+}
+
+static void max98396_supply_disable(void *r)
+{
+	regulator_disable((struct regulator *) r);
+}
+
 static int max98396_i2c_probe(struct i2c_client *i2c,
 			      const struct i2c_device_id *id)
 {
 	struct max98396_priv *max98396 = NULL;
-	int ret, reg;
+	int i, ret, reg;
 
 	max98396 = devm_kzalloc(&i2c->dev, sizeof(*max98396), GFP_KERNEL);
 
@@ -1543,6 +1595,69 @@ static int max98396_i2c_probe(struct i2c_client *i2c,
 		return ret;
 	}
 
+	/* Obtain regulator supplies */
+	for (i = 0; i < MAX98396_NUM_CORE_SUPPLIES; i++)
+		max98396->core_supplies[i].supply = max98396_core_supplies[i];
+
+	ret = devm_regulator_bulk_get(&i2c->dev, MAX98396_NUM_CORE_SUPPLIES,
+				      max98396->core_supplies);
+	if (ret < 0) {
+		dev_err(&i2c->dev, "Failed to request core supplies: %d\n", ret);
+		return ret;
+	}
+
+	max98396->vbat = devm_regulator_get_optional(&i2c->dev, "vbat");
+	if (IS_ERR(max98396->vbat)) {
+		if (PTR_ERR(max98396->vbat) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+
+		max98396->vbat = NULL;
+	}
+
+	max98396->pvdd = devm_regulator_get_optional(&i2c->dev, "pvdd");
+	if (IS_ERR(max98396->pvdd)) {
+		if (PTR_ERR(max98396->pvdd) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+
+		max98396->pvdd = NULL;
+	}
+
+	ret = regulator_bulk_enable(MAX98396_NUM_CORE_SUPPLIES,
+				    max98396->core_supplies);
+	if (ret < 0) {
+		dev_err(&i2c->dev, "Unable to enable core supplies: %d", ret);
+		return ret;
+	}
+
+	ret = devm_add_action_or_reset(&i2c->dev, max98396_core_supplies_disable,
+				       max98396);
+	if (ret < 0)
+		return ret;
+
+	if (max98396->pvdd) {
+		ret = regulator_enable(max98396->pvdd);
+		if (ret < 0)
+			return ret;
+
+		ret = devm_add_action_or_reset(&i2c->dev,
+					       max98396_supply_disable,
+					       max98396->pvdd);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (max98396->vbat) {
+		ret = regulator_enable(max98396->vbat);
+		if (ret < 0)
+			return ret;
+
+		ret = devm_add_action_or_reset(&i2c->dev,
+					       max98396_supply_disable,
+					       max98396->vbat);
+		if (ret < 0)
+			return ret;
+	}
+
 	/* update interleave mode info */
 	if (device_property_read_bool(&i2c->dev, "adi,interleave_mode"))
 		max98396->interleave_mode = true;
diff --git a/sound/soc/codecs/max98396.h b/sound/soc/codecs/max98396.h
index 694411038597..8fa081f5d2d3 100644
--- a/sound/soc/codecs/max98396.h
+++ b/sound/soc/codecs/max98396.h
@@ -274,6 +274,9 @@
 #define MAX98396_DSP_SPK_SAFE_EN_SHIFT		(5)
 #define MAX98396_DSP_SPK_WB_FLT_EN_SHIFT	(6)
 
+/* MAX98396_R20A0_AMP_SUPPLY_CTL */
+#define MAX98396_AMP_SUPPLY_NOVBAT		(0x1 << 0)
+
 /* MAX98396_R20E0_IV_SENSE_PATH_CFG */
 #define MAX98396_IV_SENSE_DCBLK_EN_MASK		(0x3 << 0)
 #define MAX98396_IV_SENSE_DCBLK_EN_SHIFT	(0)
@@ -291,9 +294,13 @@ enum {
 	CODEC_TYPE_MAX98397,
 };
 
+#define  MAX98396_NUM_CORE_SUPPLIES 3
+
 struct max98396_priv {
 	struct regmap *regmap;
 	struct gpio_desc *reset_gpio;
+	struct regulator_bulk_data core_supplies[MAX98396_NUM_CORE_SUPPLIES];
+	struct regulator *pvdd, *vbat;
 	unsigned int v_slot;
 	unsigned int i_slot;
 	unsigned int bypass_slot;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 5/8] ASoC: max98396: Improve some error prints
  2022-06-24 10:47 ` Daniel Mack
@ 2022-06-24 10:47   ` Daniel Mack
  -1 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: robh+dt, alsa-devel, devicetree, Daniel Mack

Let's log what actually failed and log at some more places.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 sound/soc/codecs/max98396.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c
index 06ac637f2696..faa81b4bb709 100644
--- a/sound/soc/codecs/max98396.c
+++ b/sound/soc/codecs/max98396.c
@@ -372,7 +372,8 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
 		break;
 
 	default:
-		dev_err(component->dev, "DAI invert mode unsupported\n");
+		dev_err(component->dev, "DAI invert mode %d unsupported\n",
+			fmt & SND_SOC_DAIFMT_INV_MASK);
 		return -EINVAL;
 	}
 
@@ -391,6 +392,8 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
 		format |= MAX98396_PCM_FORMAT_TDM_MODE0;
 		break;
 	default:
+		dev_err(component->dev, "DAI format %d unsupported\n",
+			fmt & SND_SOC_DAIFMT_FORMAT_MASK);
 		return -EINVAL;
 	}
 
@@ -461,8 +464,9 @@ static int max98396_set_clock(struct snd_soc_component *component,
 		/* BCLK configuration */
 		value = max98396_get_bclk_sel(blr_clk_ratio);
 		if (!value) {
-			dev_err(component->dev, "format unsupported %d\n",
-				params_format(params));
+			dev_err(component->dev,
+				"blr_clk_ratio %d unsupported, format %d\n",
+				blr_clk_ratio, params_format(params));
 			return -EINVAL;
 		}
 
@@ -647,7 +651,7 @@ static int max98396_dai_tdm_slot(struct snd_soc_dai *dai,
 		chan_sz = MAX98396_PCM_MODE_CFG_CHANSZ_32;
 		break;
 	default:
-		dev_err(component->dev, "format unsupported %d\n",
+		dev_err(component->dev, "slot width %d unsupported\n",
 			slot_width);
 		return -EINVAL;
 	}
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 5/8] ASoC: max98396: Improve some error prints
@ 2022-06-24 10:47   ` Daniel Mack
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: devicetree, alsa-devel, robh+dt, Daniel Mack

Let's log what actually failed and log at some more places.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 sound/soc/codecs/max98396.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c
index 06ac637f2696..faa81b4bb709 100644
--- a/sound/soc/codecs/max98396.c
+++ b/sound/soc/codecs/max98396.c
@@ -372,7 +372,8 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
 		break;
 
 	default:
-		dev_err(component->dev, "DAI invert mode unsupported\n");
+		dev_err(component->dev, "DAI invert mode %d unsupported\n",
+			fmt & SND_SOC_DAIFMT_INV_MASK);
 		return -EINVAL;
 	}
 
@@ -391,6 +392,8 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
 		format |= MAX98396_PCM_FORMAT_TDM_MODE0;
 		break;
 	default:
+		dev_err(component->dev, "DAI format %d unsupported\n",
+			fmt & SND_SOC_DAIFMT_FORMAT_MASK);
 		return -EINVAL;
 	}
 
@@ -461,8 +464,9 @@ static int max98396_set_clock(struct snd_soc_component *component,
 		/* BCLK configuration */
 		value = max98396_get_bclk_sel(blr_clk_ratio);
 		if (!value) {
-			dev_err(component->dev, "format unsupported %d\n",
-				params_format(params));
+			dev_err(component->dev,
+				"blr_clk_ratio %d unsupported, format %d\n",
+				blr_clk_ratio, params_format(params));
 			return -EINVAL;
 		}
 
@@ -647,7 +651,7 @@ static int max98396_dai_tdm_slot(struct snd_soc_dai *dai,
 		chan_sz = MAX98396_PCM_MODE_CFG_CHANSZ_32;
 		break;
 	default:
-		dev_err(component->dev, "format unsupported %d\n",
+		dev_err(component->dev, "slot width %d unsupported\n",
 			slot_width);
 		return -EINVAL;
 	}
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 6/8] ASoC: max98396: Fix register access for PCM format settings
  2022-06-24 10:47 ` Daniel Mack
@ 2022-06-24 10:47   ` Daniel Mack
  -1 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: devicetree, alsa-devel, robh+dt, Daniel Mack

max98396_dai_set_fmt() modifes register 2041 and touches bits in the mask
0x3a. Make sure to use the right mask for that operation.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 sound/soc/codecs/max98396.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c
index faa81b4bb709..0a1d98279a3e 100644
--- a/sound/soc/codecs/max98396.c
+++ b/sound/soc/codecs/max98396.c
@@ -349,12 +349,15 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
 {
 	struct snd_soc_component *component = codec_dai->component;
 	struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component);
-	unsigned int format = 0;
+	unsigned int format_mask, format = 0;
 	unsigned int bclk_pol = 0;
 	int ret, status;
 	int reg;
 	bool update = false;
 
+	format_mask = MAX98396_PCM_MODE_CFG_FORMAT_MASK |
+		      MAX98396_PCM_MODE_CFG_LRCLKEDGE;
+
 	dev_dbg(component->dev, "%s: fmt 0x%08X\n", __func__, fmt);
 
 	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
@@ -405,7 +408,7 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
 		ret = regmap_read(max98396->regmap, MAX98396_R2041_PCM_MODE_CFG, &reg);
 		if (ret < 0)
 			return -EINVAL;
-		if (format != (reg & MAX98396_PCM_BCLKEDGE_BSEL_MASK)) {
+		if (format != (reg & format_mask)) {
 			update = true;
 		} else {
 			ret = regmap_read(max98396->regmap,
@@ -422,8 +425,7 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
 
 	regmap_update_bits(max98396->regmap,
 			   MAX98396_R2041_PCM_MODE_CFG,
-			   MAX98396_PCM_BCLKEDGE_BSEL_MASK,
-			   format);
+			   format_mask, format);
 
 	regmap_update_bits(max98396->regmap,
 			   MAX98396_R2042_PCM_CLK_SETUP,
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 6/8] ASoC: max98396: Fix register access for PCM format settings
@ 2022-06-24 10:47   ` Daniel Mack
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: robh+dt, alsa-devel, devicetree, Daniel Mack

max98396_dai_set_fmt() modifes register 2041 and touches bits in the mask
0x3a. Make sure to use the right mask for that operation.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 sound/soc/codecs/max98396.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c
index faa81b4bb709..0a1d98279a3e 100644
--- a/sound/soc/codecs/max98396.c
+++ b/sound/soc/codecs/max98396.c
@@ -349,12 +349,15 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
 {
 	struct snd_soc_component *component = codec_dai->component;
 	struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component);
-	unsigned int format = 0;
+	unsigned int format_mask, format = 0;
 	unsigned int bclk_pol = 0;
 	int ret, status;
 	int reg;
 	bool update = false;
 
+	format_mask = MAX98396_PCM_MODE_CFG_FORMAT_MASK |
+		      MAX98396_PCM_MODE_CFG_LRCLKEDGE;
+
 	dev_dbg(component->dev, "%s: fmt 0x%08X\n", __func__, fmt);
 
 	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
@@ -405,7 +408,7 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
 		ret = regmap_read(max98396->regmap, MAX98396_R2041_PCM_MODE_CFG, &reg);
 		if (ret < 0)
 			return -EINVAL;
-		if (format != (reg & MAX98396_PCM_BCLKEDGE_BSEL_MASK)) {
+		if (format != (reg & format_mask)) {
 			update = true;
 		} else {
 			ret = regmap_read(max98396->regmap,
@@ -422,8 +425,7 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
 
 	regmap_update_bits(max98396->regmap,
 			   MAX98396_R2041_PCM_MODE_CFG,
-			   MAX98396_PCM_BCLKEDGE_BSEL_MASK,
-			   format);
+			   format_mask, format);
 
 	regmap_update_bits(max98396->regmap,
 			   MAX98396_R2042_PCM_CLK_SETUP,
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 7/8] ASoC: max98396: Implement DSP speaker monitor
  2022-06-24 10:47 ` Daniel Mack
@ 2022-06-24 10:47   ` Daniel Mack
  -1 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: devicetree, alsa-devel, robh+dt, Daniel Mack

Allow the selection of the TDM slot that is used to send back speaker
monitor data. The DT property adi,spkfb-slot-no can be used to configure
this setting which defaults to 2.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 sound/soc/codecs/max98396.c | 8 ++++++++
 sound/soc/codecs/max98396.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c
index 0a1d98279a3e..f28831f4e74b 100644
--- a/sound/soc/codecs/max98396.c
+++ b/sound/soc/codecs/max98396.c
@@ -1377,6 +1377,9 @@ static int max98396_probe(struct snd_soc_component *component)
 	regmap_write(max98396->regmap,
 		     MAX98396_R2045_PCM_TX_CTRL_2,
 		     max98396->i_slot);
+	regmap_write(max98396->regmap,
+		     MAX98396_R204A_PCM_TX_CTRL_7,
+		     max98396->spkfb_slot);
 
 	if (max98396->v_slot < 8)
 		if (max98396->device_id == CODEC_TYPE_MAX98396)
@@ -1552,6 +1555,11 @@ static void max98396_read_device_property(struct device *dev,
 	else
 		max98396->i_slot = 1;
 
+	if (!device_property_read_u32(dev, "adi,spkfb-slot-no", &value))
+		max98396->spkfb_slot = value & 0xF;
+	else
+		max98396->spkfb_slot = 2;
+
 	if (!device_property_read_u32(dev, "adi,bypass-slot-no", &value))
 		max98396->bypass_slot = value & 0xF;
 	else
diff --git a/sound/soc/codecs/max98396.h b/sound/soc/codecs/max98396.h
index 8fa081f5d2d3..ff330ef61568 100644
--- a/sound/soc/codecs/max98396.h
+++ b/sound/soc/codecs/max98396.h
@@ -303,6 +303,7 @@ struct max98396_priv {
 	struct regulator *pvdd, *vbat;
 	unsigned int v_slot;
 	unsigned int i_slot;
+	unsigned int spkfb_slot;
 	unsigned int bypass_slot;
 	bool interleave_mode;
 	unsigned int ch_size;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 7/8] ASoC: max98396: Implement DSP speaker monitor
@ 2022-06-24 10:47   ` Daniel Mack
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: robh+dt, alsa-devel, devicetree, Daniel Mack

Allow the selection of the TDM slot that is used to send back speaker
monitor data. The DT property adi,spkfb-slot-no can be used to configure
this setting which defaults to 2.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 sound/soc/codecs/max98396.c | 8 ++++++++
 sound/soc/codecs/max98396.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c
index 0a1d98279a3e..f28831f4e74b 100644
--- a/sound/soc/codecs/max98396.c
+++ b/sound/soc/codecs/max98396.c
@@ -1377,6 +1377,9 @@ static int max98396_probe(struct snd_soc_component *component)
 	regmap_write(max98396->regmap,
 		     MAX98396_R2045_PCM_TX_CTRL_2,
 		     max98396->i_slot);
+	regmap_write(max98396->regmap,
+		     MAX98396_R204A_PCM_TX_CTRL_7,
+		     max98396->spkfb_slot);
 
 	if (max98396->v_slot < 8)
 		if (max98396->device_id == CODEC_TYPE_MAX98396)
@@ -1552,6 +1555,11 @@ static void max98396_read_device_property(struct device *dev,
 	else
 		max98396->i_slot = 1;
 
+	if (!device_property_read_u32(dev, "adi,spkfb-slot-no", &value))
+		max98396->spkfb_slot = value & 0xF;
+	else
+		max98396->spkfb_slot = 2;
+
 	if (!device_property_read_u32(dev, "adi,bypass-slot-no", &value))
 		max98396->bypass_slot = value & 0xF;
 	else
diff --git a/sound/soc/codecs/max98396.h b/sound/soc/codecs/max98396.h
index 8fa081f5d2d3..ff330ef61568 100644
--- a/sound/soc/codecs/max98396.h
+++ b/sound/soc/codecs/max98396.h
@@ -303,6 +303,7 @@ struct max98396_priv {
 	struct regulator *pvdd, *vbat;
 	unsigned int v_slot;
 	unsigned int i_slot;
+	unsigned int spkfb_slot;
 	unsigned int bypass_slot;
 	bool interleave_mode;
 	unsigned int ch_size;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 8/8] ASoC: max98396: Fix TDM mode BSEL settings
  2022-06-24 10:47 ` Daniel Mack
@ 2022-06-24 10:47   ` Daniel Mack
  -1 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: devicetree, alsa-devel, robh+dt, Daniel Mack

In TDM mode, the BSEL register value must be set according to table 5 in the
datasheet. This patch adds a lookup function and uses it in
max98396_dai_tdm_slot().

As the first 3 entries can also be used for non-TDM setups, the code now
re-uses the same code for such scenarios.

max98396_set_clock() is folded into its only user for clarity.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 sound/soc/codecs/max98396.c | 124 +++++++++++++++++++++++-------------
 1 file changed, 81 insertions(+), 43 deletions(-)

diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c
index f28831f4e74b..f1657a5f2140 100644
--- a/sound/soc/codecs/max98396.c
+++ b/sound/soc/codecs/max98396.c
@@ -438,47 +438,55 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
 	return 0;
 }
 
-/* BCLKs per LRCLK */
-static const int bclk_sel_table[] = {
-	32, 48, 64, 96, 128, 192, 256, 384, 512, 320,
+/* Refer to table 5 in the datasheet */
+static const struct max98396_pcm_config {
+	int in, out, width, bsel, max_sr;
+} max98396_pcm_configs[] = {
+	{ .in = 2,  .out = 4,  .width = 16, .bsel = 0x2, /*  32 */ .max_sr = 192000  },
+	{ .in = 2,  .out = 6,  .width = 24, .bsel = 0x3, /*  48 */ .max_sr = 192000  },
+	{ .in = 2,  .out = 8,  .width = 32, .bsel = 0x4, /*  64 */ .max_sr = 192000  },
+	{ .in = 3,  .out = 15, .width = 32, .bsel = 0xd, /* 125 */ .max_sr = 192000  },
+	{ .in = 4,  .out = 8,  .width = 16, .bsel = 0x4, /*  64 */ .max_sr = 192000  },
+	{ .in = 4,  .out = 12, .width = 24, .bsel = 0x5, /*  96 */ .max_sr = 192000  },
+	{ .in = 4,  .out = 16, .width = 32, .bsel = 0x6, /* 128 */ .max_sr = 192000  },
+	{ .in = 5,  .out = 15, .width = 24, .bsel = 0xd, /* 125 */ .max_sr = 192000  },
+	{ .in = 7,  .out = 15, .width = 16, .bsel = 0xd, /* 125 */ .max_sr = 192000  },
+	{ .in = 2,  .out = 4,  .width = 16, .bsel = 0x2, /*  32 */ .max_sr = 96000   },
+	{ .in = 2,  .out = 6,  .width = 24, .bsel = 0x3, /*  48 */ .max_sr = 96000   },
+	{ .in = 2,  .out = 8,  .width = 32, .bsel = 0x4, /*  64 */ .max_sr = 96000   },
+	{ .in = 3,  .out = 15, .width = 32, .bsel = 0xd, /* 125 */ .max_sr = 96000   },
+	{ .in = 4,  .out = 8,  .width = 16, .bsel = 0x4, /*  64 */ .max_sr = 96000   },
+	{ .in = 4,  .out = 12, .width = 24, .bsel = 0x5, /*  96 */ .max_sr = 96000   },
+	{ .in = 4,  .out = 16, .width = 32, .bsel = 0x6, /* 128 */ .max_sr = 96000   },
+	{ .in = 5,  .out = 15, .width = 24, .bsel = 0xd, /* 125 */ .max_sr = 96000   },
+	{ .in = 7,  .out = 15, .width = 16, .bsel = 0xd, /* 125 */ .max_sr = 96000   },
+	{ .in = 7,  .out = 31, .width = 32, .bsel = 0xc, /* 250 */ .max_sr = 96000   },
+	{ .in = 8,  .out = 16, .width = 16, .bsel = 0x6, /* 128 */ .max_sr = 96000   },
+	{ .in = 8,  .out = 24, .width = 24, .bsel = 0x7, /* 192 */ .max_sr = 96000   },
+	{ .in = 8,  .out = 32, .width = 32, .bsel = 0x8, /* 256 */ .max_sr = 96000   },
+	{ .in = 10, .out = 31, .width = 24, .bsel = 0xc, /* 250 */ .max_sr = 96000   },
+	{ .in = 15, .out = 31, .width = 16, .bsel = 0xc, /* 250 */ .max_sr = 96000   },
+	{ .in = 16, .out = 32, .width = 16, .bsel = 0x8, /* 256 */ .max_sr = 96000   },
+	{ .in = 7,  .out = 31, .width = 32, .bsel = 0xc, /* 250 */ .max_sr = 48000   },
+	{ .in = 10, .out = 31, .width = 24, .bsel = 0xc, /* 250 */ .max_sr = 48000   },
+	{ .in = 10, .out = 40, .width = 32, .bsel = 0xb, /* 320 */ .max_sr = 48000   },
+	{ .in = 15, .out = 31, .width = 16, .bsel = 0xc, /* 250 */ .max_sr = 48000   },
+	{ .in = 16, .out = 48, .width = 24, .bsel = 0x9, /* 384 */ .max_sr = 48000   },
+	{ .in = 16, .out = 64, .width = 32, .bsel = 0xa, /* 512 */ .max_sr = 48000   },
 };
 
-static int max98396_get_bclk_sel(int bclk)
+static int max98396_pcm_config_index(int in_slots, int out_slots, int width)
 {
 	int i;
-	/* match BCLKs per LRCLK */
-	for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
-		if (bclk_sel_table[i] == bclk)
-			return i + 2;
-	}
-	return 0;
-}
 
-static int max98396_set_clock(struct snd_soc_component *component,
-			      struct snd_pcm_hw_params *params)
-{
-	struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component);
-	/* BCLK/LRCLK ratio calculation */
-	int blr_clk_ratio = params_channels(params) * max98396->ch_size;
-	int value;
-
-	if (!max98396->tdm_mode) {
-		/* BCLK configuration */
-		value = max98396_get_bclk_sel(blr_clk_ratio);
-		if (!value) {
-			dev_err(component->dev,
-				"blr_clk_ratio %d unsupported, format %d\n",
-				blr_clk_ratio, params_format(params));
-			return -EINVAL;
-		}
+	for (i = 0; i < ARRAY_SIZE(max98396_pcm_configs); i++) {
+		const struct max98396_pcm_config *c = &max98396_pcm_configs[i];
 
-		regmap_update_bits(max98396->regmap,
-				   MAX98396_R2042_PCM_CLK_SETUP,
-				   MAX98396_PCM_CLK_SETUP_BSEL_MASK,
-				   value);
+		if (in_slots == c->in && out_slots <= c->out && width == c->width)
+			return i;
 	}
 
-	return 0;
+	return -1;
 }
 
 static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
@@ -489,8 +497,7 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
 	struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component);
 	unsigned int sampling_rate = 0;
 	unsigned int chan_sz = 0;
-	int ret, reg;
-	int status;
+	int ret, reg, status, bsel;
 	bool update = false;
 
 	/* pcm mode configuration */
@@ -510,8 +517,6 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
 		goto err;
 	}
 
-	max98396->ch_size = snd_pcm_format_width(params_format(params));
-
 	dev_dbg(component->dev, "format supported %d",
 		params_format(params));
 
@@ -559,6 +564,33 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
 		goto err;
 	}
 
+	if (max98396->tdm_mode) {
+		if (params_rate(params) > max98396->tdm_max_samplerate) {
+			dev_err(component->dev, "TDM sample rate %d too high",
+				params_rate(params));
+			goto err;
+		}
+	} else {
+		/* BCLK configuration */
+		ret = max98396_pcm_config_index(params_channels(params),
+						params_channels(params),
+						snd_pcm_format_width(params_format(params)));
+		if (ret < 0) {
+			dev_err(component->dev,
+				"no PCM config for %d channels, format %d\n",
+				params_channels(params), params_format(params));
+			goto err;
+		}
+
+		bsel = max98396_pcm_configs[ret].bsel;
+
+		if (params_rate(params) > max98396_pcm_configs[ret].max_sr) {
+			dev_err(component->dev, "sample rate %d too high",
+				params_rate(params));
+			goto err;
+		}
+	}
+
 	ret = regmap_read(max98396->regmap, MAX98396_R210F_GLOBAL_EN, &status);
 	if (ret < 0)
 		goto err;
@@ -604,12 +636,15 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
 				   MAX98396_IVADC_SR_MASK,
 				   sampling_rate << MAX98396_IVADC_SR_SHIFT);
 
-	ret = max98396_set_clock(component, params);
+	regmap_update_bits(max98396->regmap,
+			   MAX98396_R2042_PCM_CLK_SETUP,
+			   MAX98396_PCM_CLK_SETUP_BSEL_MASK,
+			   bsel);
 
 	if (status && update)
 		max98396_global_enable_onoff(max98396->regmap, true);
 
-	return ret;
+	return 0;
 
 err:
 	return -EINVAL;
@@ -634,13 +669,16 @@ static int max98396_dai_tdm_slot(struct snd_soc_dai *dai,
 		max98396->tdm_mode = true;
 
 	/* BCLK configuration */
-	bsel = max98396_get_bclk_sel(slots * slot_width);
-	if (bsel == 0) {
-		dev_err(component->dev, "BCLK %d not supported\n",
-			slots * slot_width);
+	ret = max98396_pcm_config_index(slots, slots, slot_width);
+	if (ret < 0) {
+		dev_err(component->dev, "no TDM config for %d slots %d bits\n",
+			slots, slot_width);
 		return -EINVAL;
 	}
 
+	bsel = max98396_pcm_configs[ret].bsel;
+	max98396->tdm_max_samplerate = max98396_pcm_configs[ret].max_sr;
+
 	/* Channel size configuration */
 	switch (slot_width) {
 	case 16:
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 8/8] ASoC: max98396: Fix TDM mode BSEL settings
@ 2022-06-24 10:47   ` Daniel Mack
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 10:47 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: robh+dt, alsa-devel, devicetree, Daniel Mack

In TDM mode, the BSEL register value must be set according to table 5 in the
datasheet. This patch adds a lookup function and uses it in
max98396_dai_tdm_slot().

As the first 3 entries can also be used for non-TDM setups, the code now
re-uses the same code for such scenarios.

max98396_set_clock() is folded into its only user for clarity.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 sound/soc/codecs/max98396.c | 124 +++++++++++++++++++++++-------------
 1 file changed, 81 insertions(+), 43 deletions(-)

diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c
index f28831f4e74b..f1657a5f2140 100644
--- a/sound/soc/codecs/max98396.c
+++ b/sound/soc/codecs/max98396.c
@@ -438,47 +438,55 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
 	return 0;
 }
 
-/* BCLKs per LRCLK */
-static const int bclk_sel_table[] = {
-	32, 48, 64, 96, 128, 192, 256, 384, 512, 320,
+/* Refer to table 5 in the datasheet */
+static const struct max98396_pcm_config {
+	int in, out, width, bsel, max_sr;
+} max98396_pcm_configs[] = {
+	{ .in = 2,  .out = 4,  .width = 16, .bsel = 0x2, /*  32 */ .max_sr = 192000  },
+	{ .in = 2,  .out = 6,  .width = 24, .bsel = 0x3, /*  48 */ .max_sr = 192000  },
+	{ .in = 2,  .out = 8,  .width = 32, .bsel = 0x4, /*  64 */ .max_sr = 192000  },
+	{ .in = 3,  .out = 15, .width = 32, .bsel = 0xd, /* 125 */ .max_sr = 192000  },
+	{ .in = 4,  .out = 8,  .width = 16, .bsel = 0x4, /*  64 */ .max_sr = 192000  },
+	{ .in = 4,  .out = 12, .width = 24, .bsel = 0x5, /*  96 */ .max_sr = 192000  },
+	{ .in = 4,  .out = 16, .width = 32, .bsel = 0x6, /* 128 */ .max_sr = 192000  },
+	{ .in = 5,  .out = 15, .width = 24, .bsel = 0xd, /* 125 */ .max_sr = 192000  },
+	{ .in = 7,  .out = 15, .width = 16, .bsel = 0xd, /* 125 */ .max_sr = 192000  },
+	{ .in = 2,  .out = 4,  .width = 16, .bsel = 0x2, /*  32 */ .max_sr = 96000   },
+	{ .in = 2,  .out = 6,  .width = 24, .bsel = 0x3, /*  48 */ .max_sr = 96000   },
+	{ .in = 2,  .out = 8,  .width = 32, .bsel = 0x4, /*  64 */ .max_sr = 96000   },
+	{ .in = 3,  .out = 15, .width = 32, .bsel = 0xd, /* 125 */ .max_sr = 96000   },
+	{ .in = 4,  .out = 8,  .width = 16, .bsel = 0x4, /*  64 */ .max_sr = 96000   },
+	{ .in = 4,  .out = 12, .width = 24, .bsel = 0x5, /*  96 */ .max_sr = 96000   },
+	{ .in = 4,  .out = 16, .width = 32, .bsel = 0x6, /* 128 */ .max_sr = 96000   },
+	{ .in = 5,  .out = 15, .width = 24, .bsel = 0xd, /* 125 */ .max_sr = 96000   },
+	{ .in = 7,  .out = 15, .width = 16, .bsel = 0xd, /* 125 */ .max_sr = 96000   },
+	{ .in = 7,  .out = 31, .width = 32, .bsel = 0xc, /* 250 */ .max_sr = 96000   },
+	{ .in = 8,  .out = 16, .width = 16, .bsel = 0x6, /* 128 */ .max_sr = 96000   },
+	{ .in = 8,  .out = 24, .width = 24, .bsel = 0x7, /* 192 */ .max_sr = 96000   },
+	{ .in = 8,  .out = 32, .width = 32, .bsel = 0x8, /* 256 */ .max_sr = 96000   },
+	{ .in = 10, .out = 31, .width = 24, .bsel = 0xc, /* 250 */ .max_sr = 96000   },
+	{ .in = 15, .out = 31, .width = 16, .bsel = 0xc, /* 250 */ .max_sr = 96000   },
+	{ .in = 16, .out = 32, .width = 16, .bsel = 0x8, /* 256 */ .max_sr = 96000   },
+	{ .in = 7,  .out = 31, .width = 32, .bsel = 0xc, /* 250 */ .max_sr = 48000   },
+	{ .in = 10, .out = 31, .width = 24, .bsel = 0xc, /* 250 */ .max_sr = 48000   },
+	{ .in = 10, .out = 40, .width = 32, .bsel = 0xb, /* 320 */ .max_sr = 48000   },
+	{ .in = 15, .out = 31, .width = 16, .bsel = 0xc, /* 250 */ .max_sr = 48000   },
+	{ .in = 16, .out = 48, .width = 24, .bsel = 0x9, /* 384 */ .max_sr = 48000   },
+	{ .in = 16, .out = 64, .width = 32, .bsel = 0xa, /* 512 */ .max_sr = 48000   },
 };
 
-static int max98396_get_bclk_sel(int bclk)
+static int max98396_pcm_config_index(int in_slots, int out_slots, int width)
 {
 	int i;
-	/* match BCLKs per LRCLK */
-	for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
-		if (bclk_sel_table[i] == bclk)
-			return i + 2;
-	}
-	return 0;
-}
 
-static int max98396_set_clock(struct snd_soc_component *component,
-			      struct snd_pcm_hw_params *params)
-{
-	struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component);
-	/* BCLK/LRCLK ratio calculation */
-	int blr_clk_ratio = params_channels(params) * max98396->ch_size;
-	int value;
-
-	if (!max98396->tdm_mode) {
-		/* BCLK configuration */
-		value = max98396_get_bclk_sel(blr_clk_ratio);
-		if (!value) {
-			dev_err(component->dev,
-				"blr_clk_ratio %d unsupported, format %d\n",
-				blr_clk_ratio, params_format(params));
-			return -EINVAL;
-		}
+	for (i = 0; i < ARRAY_SIZE(max98396_pcm_configs); i++) {
+		const struct max98396_pcm_config *c = &max98396_pcm_configs[i];
 
-		regmap_update_bits(max98396->regmap,
-				   MAX98396_R2042_PCM_CLK_SETUP,
-				   MAX98396_PCM_CLK_SETUP_BSEL_MASK,
-				   value);
+		if (in_slots == c->in && out_slots <= c->out && width == c->width)
+			return i;
 	}
 
-	return 0;
+	return -1;
 }
 
 static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
@@ -489,8 +497,7 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
 	struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component);
 	unsigned int sampling_rate = 0;
 	unsigned int chan_sz = 0;
-	int ret, reg;
-	int status;
+	int ret, reg, status, bsel;
 	bool update = false;
 
 	/* pcm mode configuration */
@@ -510,8 +517,6 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
 		goto err;
 	}
 
-	max98396->ch_size = snd_pcm_format_width(params_format(params));
-
 	dev_dbg(component->dev, "format supported %d",
 		params_format(params));
 
@@ -559,6 +564,33 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
 		goto err;
 	}
 
+	if (max98396->tdm_mode) {
+		if (params_rate(params) > max98396->tdm_max_samplerate) {
+			dev_err(component->dev, "TDM sample rate %d too high",
+				params_rate(params));
+			goto err;
+		}
+	} else {
+		/* BCLK configuration */
+		ret = max98396_pcm_config_index(params_channels(params),
+						params_channels(params),
+						snd_pcm_format_width(params_format(params)));
+		if (ret < 0) {
+			dev_err(component->dev,
+				"no PCM config for %d channels, format %d\n",
+				params_channels(params), params_format(params));
+			goto err;
+		}
+
+		bsel = max98396_pcm_configs[ret].bsel;
+
+		if (params_rate(params) > max98396_pcm_configs[ret].max_sr) {
+			dev_err(component->dev, "sample rate %d too high",
+				params_rate(params));
+			goto err;
+		}
+	}
+
 	ret = regmap_read(max98396->regmap, MAX98396_R210F_GLOBAL_EN, &status);
 	if (ret < 0)
 		goto err;
@@ -604,12 +636,15 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
 				   MAX98396_IVADC_SR_MASK,
 				   sampling_rate << MAX98396_IVADC_SR_SHIFT);
 
-	ret = max98396_set_clock(component, params);
+	regmap_update_bits(max98396->regmap,
+			   MAX98396_R2042_PCM_CLK_SETUP,
+			   MAX98396_PCM_CLK_SETUP_BSEL_MASK,
+			   bsel);
 
 	if (status && update)
 		max98396_global_enable_onoff(max98396->regmap, true);
 
-	return ret;
+	return 0;
 
 err:
 	return -EINVAL;
@@ -634,13 +669,16 @@ static int max98396_dai_tdm_slot(struct snd_soc_dai *dai,
 		max98396->tdm_mode = true;
 
 	/* BCLK configuration */
-	bsel = max98396_get_bclk_sel(slots * slot_width);
-	if (bsel == 0) {
-		dev_err(component->dev, "BCLK %d not supported\n",
-			slots * slot_width);
+	ret = max98396_pcm_config_index(slots, slots, slot_width);
+	if (ret < 0) {
+		dev_err(component->dev, "no TDM config for %d slots %d bits\n",
+			slots, slot_width);
 		return -EINVAL;
 	}
 
+	bsel = max98396_pcm_configs[ret].bsel;
+	max98396->tdm_max_samplerate = max98396_pcm_configs[ret].max_sr;
+
 	/* Channel size configuration */
 	switch (slot_width) {
 	case 16:
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [PATCH 8/8] ASoC: max98396: Fix TDM mode BSEL settings
  2022-06-24 10:47   ` Daniel Mack
@ 2022-06-24 11:34     ` Daniel Mack
  -1 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 11:34 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: robh+dt, alsa-devel, devicetree

On 6/24/22 12:47, Daniel Mack wrote:
> In TDM mode, the BSEL register value must be set according to table 5 in the
> datasheet. This patch adds a lookup function and uses it in
> max98396_dai_tdm_slot().
> 
> As the first 3 entries can also be used for non-TDM setups, the code now
> re-uses the same code for such scenarios.
> 
> max98396_set_clock() is folded into its only user for clarity.

Sorry, the following hunk is missing from this patch:

diff --git a/sound/soc/codecs/max98396.h b/sound/soc/codecs/max98396.h
index ff330ef61568..7278c779989a 100644
--- a/sound/soc/codecs/max98396.h
+++ b/sound/soc/codecs/max98396.h
@@ -306,8 +306,8 @@ struct max98396_priv {
        unsigned int spkfb_slot;
        unsigned int bypass_slot;
        bool interleave_mode;
-       unsigned int ch_size;
        bool tdm_mode;
+       int tdm_max_samplerate;
        int device_id;
 };
 #endif


Will include it in the next round.


Thanks,
Daniel


> 
> Signed-off-by: Daniel Mack <daniel@zonque.org>
> ---
>  sound/soc/codecs/max98396.c | 124 +++++++++++++++++++++++-------------
>  1 file changed, 81 insertions(+), 43 deletions(-)
> 
> diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c
> index f28831f4e74b..f1657a5f2140 100644
> --- a/sound/soc/codecs/max98396.c
> +++ b/sound/soc/codecs/max98396.c
> @@ -438,47 +438,55 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
>  	return 0;
>  }
>  
> -/* BCLKs per LRCLK */
> -static const int bclk_sel_table[] = {
> -	32, 48, 64, 96, 128, 192, 256, 384, 512, 320,
> +/* Refer to table 5 in the datasheet */
> +static const struct max98396_pcm_config {
> +	int in, out, width, bsel, max_sr;
> +} max98396_pcm_configs[] = {
> +	{ .in = 2,  .out = 4,  .width = 16, .bsel = 0x2, /*  32 */ .max_sr = 192000  },
> +	{ .in = 2,  .out = 6,  .width = 24, .bsel = 0x3, /*  48 */ .max_sr = 192000  },
> +	{ .in = 2,  .out = 8,  .width = 32, .bsel = 0x4, /*  64 */ .max_sr = 192000  },
> +	{ .in = 3,  .out = 15, .width = 32, .bsel = 0xd, /* 125 */ .max_sr = 192000  },
> +	{ .in = 4,  .out = 8,  .width = 16, .bsel = 0x4, /*  64 */ .max_sr = 192000  },
> +	{ .in = 4,  .out = 12, .width = 24, .bsel = 0x5, /*  96 */ .max_sr = 192000  },
> +	{ .in = 4,  .out = 16, .width = 32, .bsel = 0x6, /* 128 */ .max_sr = 192000  },
> +	{ .in = 5,  .out = 15, .width = 24, .bsel = 0xd, /* 125 */ .max_sr = 192000  },
> +	{ .in = 7,  .out = 15, .width = 16, .bsel = 0xd, /* 125 */ .max_sr = 192000  },
> +	{ .in = 2,  .out = 4,  .width = 16, .bsel = 0x2, /*  32 */ .max_sr = 96000   },
> +	{ .in = 2,  .out = 6,  .width = 24, .bsel = 0x3, /*  48 */ .max_sr = 96000   },
> +	{ .in = 2,  .out = 8,  .width = 32, .bsel = 0x4, /*  64 */ .max_sr = 96000   },
> +	{ .in = 3,  .out = 15, .width = 32, .bsel = 0xd, /* 125 */ .max_sr = 96000   },
> +	{ .in = 4,  .out = 8,  .width = 16, .bsel = 0x4, /*  64 */ .max_sr = 96000   },
> +	{ .in = 4,  .out = 12, .width = 24, .bsel = 0x5, /*  96 */ .max_sr = 96000   },
> +	{ .in = 4,  .out = 16, .width = 32, .bsel = 0x6, /* 128 */ .max_sr = 96000   },
> +	{ .in = 5,  .out = 15, .width = 24, .bsel = 0xd, /* 125 */ .max_sr = 96000   },
> +	{ .in = 7,  .out = 15, .width = 16, .bsel = 0xd, /* 125 */ .max_sr = 96000   },
> +	{ .in = 7,  .out = 31, .width = 32, .bsel = 0xc, /* 250 */ .max_sr = 96000   },
> +	{ .in = 8,  .out = 16, .width = 16, .bsel = 0x6, /* 128 */ .max_sr = 96000   },
> +	{ .in = 8,  .out = 24, .width = 24, .bsel = 0x7, /* 192 */ .max_sr = 96000   },
> +	{ .in = 8,  .out = 32, .width = 32, .bsel = 0x8, /* 256 */ .max_sr = 96000   },
> +	{ .in = 10, .out = 31, .width = 24, .bsel = 0xc, /* 250 */ .max_sr = 96000   },
> +	{ .in = 15, .out = 31, .width = 16, .bsel = 0xc, /* 250 */ .max_sr = 96000   },
> +	{ .in = 16, .out = 32, .width = 16, .bsel = 0x8, /* 256 */ .max_sr = 96000   },
> +	{ .in = 7,  .out = 31, .width = 32, .bsel = 0xc, /* 250 */ .max_sr = 48000   },
> +	{ .in = 10, .out = 31, .width = 24, .bsel = 0xc, /* 250 */ .max_sr = 48000   },
> +	{ .in = 10, .out = 40, .width = 32, .bsel = 0xb, /* 320 */ .max_sr = 48000   },
> +	{ .in = 15, .out = 31, .width = 16, .bsel = 0xc, /* 250 */ .max_sr = 48000   },
> +	{ .in = 16, .out = 48, .width = 24, .bsel = 0x9, /* 384 */ .max_sr = 48000   },
> +	{ .in = 16, .out = 64, .width = 32, .bsel = 0xa, /* 512 */ .max_sr = 48000   },
>  };
>  
> -static int max98396_get_bclk_sel(int bclk)
> +static int max98396_pcm_config_index(int in_slots, int out_slots, int width)
>  {
>  	int i;
> -	/* match BCLKs per LRCLK */
> -	for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
> -		if (bclk_sel_table[i] == bclk)
> -			return i + 2;
> -	}
> -	return 0;
> -}
>  
> -static int max98396_set_clock(struct snd_soc_component *component,
> -			      struct snd_pcm_hw_params *params)
> -{
> -	struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component);
> -	/* BCLK/LRCLK ratio calculation */
> -	int blr_clk_ratio = params_channels(params) * max98396->ch_size;
> -	int value;
> -
> -	if (!max98396->tdm_mode) {
> -		/* BCLK configuration */
> -		value = max98396_get_bclk_sel(blr_clk_ratio);
> -		if (!value) {
> -			dev_err(component->dev,
> -				"blr_clk_ratio %d unsupported, format %d\n",
> -				blr_clk_ratio, params_format(params));
> -			return -EINVAL;
> -		}
> +	for (i = 0; i < ARRAY_SIZE(max98396_pcm_configs); i++) {
> +		const struct max98396_pcm_config *c = &max98396_pcm_configs[i];
>  
> -		regmap_update_bits(max98396->regmap,
> -				   MAX98396_R2042_PCM_CLK_SETUP,
> -				   MAX98396_PCM_CLK_SETUP_BSEL_MASK,
> -				   value);
> +		if (in_slots == c->in && out_slots <= c->out && width == c->width)
> +			return i;
>  	}
>  
> -	return 0;
> +	return -1;
>  }
>  
>  static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
> @@ -489,8 +497,7 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
>  	struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component);
>  	unsigned int sampling_rate = 0;
>  	unsigned int chan_sz = 0;
> -	int ret, reg;
> -	int status;
> +	int ret, reg, status, bsel;
>  	bool update = false;
>  
>  	/* pcm mode configuration */
> @@ -510,8 +517,6 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
>  		goto err;
>  	}
>  
> -	max98396->ch_size = snd_pcm_format_width(params_format(params));
> -
>  	dev_dbg(component->dev, "format supported %d",
>  		params_format(params));
>  
> @@ -559,6 +564,33 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
>  		goto err;
>  	}
>  
> +	if (max98396->tdm_mode) {
> +		if (params_rate(params) > max98396->tdm_max_samplerate) {
> +			dev_err(component->dev, "TDM sample rate %d too high",
> +				params_rate(params));
> +			goto err;
> +		}
> +	} else {
> +		/* BCLK configuration */
> +		ret = max98396_pcm_config_index(params_channels(params),
> +						params_channels(params),
> +						snd_pcm_format_width(params_format(params)));
> +		if (ret < 0) {
> +			dev_err(component->dev,
> +				"no PCM config for %d channels, format %d\n",
> +				params_channels(params), params_format(params));
> +			goto err;
> +		}
> +
> +		bsel = max98396_pcm_configs[ret].bsel;
> +
> +		if (params_rate(params) > max98396_pcm_configs[ret].max_sr) {
> +			dev_err(component->dev, "sample rate %d too high",
> +				params_rate(params));
> +			goto err;
> +		}
> +	}
> +
>  	ret = regmap_read(max98396->regmap, MAX98396_R210F_GLOBAL_EN, &status);
>  	if (ret < 0)
>  		goto err;
> @@ -604,12 +636,15 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
>  				   MAX98396_IVADC_SR_MASK,
>  				   sampling_rate << MAX98396_IVADC_SR_SHIFT);
>  
> -	ret = max98396_set_clock(component, params);
> +	regmap_update_bits(max98396->regmap,
> +			   MAX98396_R2042_PCM_CLK_SETUP,
> +			   MAX98396_PCM_CLK_SETUP_BSEL_MASK,
> +			   bsel);
>  
>  	if (status && update)
>  		max98396_global_enable_onoff(max98396->regmap, true);
>  
> -	return ret;
> +	return 0;
>  
>  err:
>  	return -EINVAL;
> @@ -634,13 +669,16 @@ static int max98396_dai_tdm_slot(struct snd_soc_dai *dai,
>  		max98396->tdm_mode = true;
>  
>  	/* BCLK configuration */
> -	bsel = max98396_get_bclk_sel(slots * slot_width);
> -	if (bsel == 0) {
> -		dev_err(component->dev, "BCLK %d not supported\n",
> -			slots * slot_width);
> +	ret = max98396_pcm_config_index(slots, slots, slot_width);
> +	if (ret < 0) {
> +		dev_err(component->dev, "no TDM config for %d slots %d bits\n",
> +			slots, slot_width);
>  		return -EINVAL;
>  	}
>  
> +	bsel = max98396_pcm_configs[ret].bsel;
> +	max98396->tdm_max_samplerate = max98396_pcm_configs[ret].max_sr;
> +
>  	/* Channel size configuration */
>  	switch (slot_width) {
>  	case 16:


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [PATCH 8/8] ASoC: max98396: Fix TDM mode BSEL settings
@ 2022-06-24 11:34     ` Daniel Mack
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-24 11:34 UTC (permalink / raw)
  To: broonie, ryan.lee.analog; +Cc: devicetree, alsa-devel, robh+dt

On 6/24/22 12:47, Daniel Mack wrote:
> In TDM mode, the BSEL register value must be set according to table 5 in the
> datasheet. This patch adds a lookup function and uses it in
> max98396_dai_tdm_slot().
> 
> As the first 3 entries can also be used for non-TDM setups, the code now
> re-uses the same code for such scenarios.
> 
> max98396_set_clock() is folded into its only user for clarity.

Sorry, the following hunk is missing from this patch:

diff --git a/sound/soc/codecs/max98396.h b/sound/soc/codecs/max98396.h
index ff330ef61568..7278c779989a 100644
--- a/sound/soc/codecs/max98396.h
+++ b/sound/soc/codecs/max98396.h
@@ -306,8 +306,8 @@ struct max98396_priv {
        unsigned int spkfb_slot;
        unsigned int bypass_slot;
        bool interleave_mode;
-       unsigned int ch_size;
        bool tdm_mode;
+       int tdm_max_samplerate;
        int device_id;
 };
 #endif


Will include it in the next round.


Thanks,
Daniel


> 
> Signed-off-by: Daniel Mack <daniel@zonque.org>
> ---
>  sound/soc/codecs/max98396.c | 124 +++++++++++++++++++++++-------------
>  1 file changed, 81 insertions(+), 43 deletions(-)
> 
> diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c
> index f28831f4e74b..f1657a5f2140 100644
> --- a/sound/soc/codecs/max98396.c
> +++ b/sound/soc/codecs/max98396.c
> @@ -438,47 +438,55 @@ static int max98396_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
>  	return 0;
>  }
>  
> -/* BCLKs per LRCLK */
> -static const int bclk_sel_table[] = {
> -	32, 48, 64, 96, 128, 192, 256, 384, 512, 320,
> +/* Refer to table 5 in the datasheet */
> +static const struct max98396_pcm_config {
> +	int in, out, width, bsel, max_sr;
> +} max98396_pcm_configs[] = {
> +	{ .in = 2,  .out = 4,  .width = 16, .bsel = 0x2, /*  32 */ .max_sr = 192000  },
> +	{ .in = 2,  .out = 6,  .width = 24, .bsel = 0x3, /*  48 */ .max_sr = 192000  },
> +	{ .in = 2,  .out = 8,  .width = 32, .bsel = 0x4, /*  64 */ .max_sr = 192000  },
> +	{ .in = 3,  .out = 15, .width = 32, .bsel = 0xd, /* 125 */ .max_sr = 192000  },
> +	{ .in = 4,  .out = 8,  .width = 16, .bsel = 0x4, /*  64 */ .max_sr = 192000  },
> +	{ .in = 4,  .out = 12, .width = 24, .bsel = 0x5, /*  96 */ .max_sr = 192000  },
> +	{ .in = 4,  .out = 16, .width = 32, .bsel = 0x6, /* 128 */ .max_sr = 192000  },
> +	{ .in = 5,  .out = 15, .width = 24, .bsel = 0xd, /* 125 */ .max_sr = 192000  },
> +	{ .in = 7,  .out = 15, .width = 16, .bsel = 0xd, /* 125 */ .max_sr = 192000  },
> +	{ .in = 2,  .out = 4,  .width = 16, .bsel = 0x2, /*  32 */ .max_sr = 96000   },
> +	{ .in = 2,  .out = 6,  .width = 24, .bsel = 0x3, /*  48 */ .max_sr = 96000   },
> +	{ .in = 2,  .out = 8,  .width = 32, .bsel = 0x4, /*  64 */ .max_sr = 96000   },
> +	{ .in = 3,  .out = 15, .width = 32, .bsel = 0xd, /* 125 */ .max_sr = 96000   },
> +	{ .in = 4,  .out = 8,  .width = 16, .bsel = 0x4, /*  64 */ .max_sr = 96000   },
> +	{ .in = 4,  .out = 12, .width = 24, .bsel = 0x5, /*  96 */ .max_sr = 96000   },
> +	{ .in = 4,  .out = 16, .width = 32, .bsel = 0x6, /* 128 */ .max_sr = 96000   },
> +	{ .in = 5,  .out = 15, .width = 24, .bsel = 0xd, /* 125 */ .max_sr = 96000   },
> +	{ .in = 7,  .out = 15, .width = 16, .bsel = 0xd, /* 125 */ .max_sr = 96000   },
> +	{ .in = 7,  .out = 31, .width = 32, .bsel = 0xc, /* 250 */ .max_sr = 96000   },
> +	{ .in = 8,  .out = 16, .width = 16, .bsel = 0x6, /* 128 */ .max_sr = 96000   },
> +	{ .in = 8,  .out = 24, .width = 24, .bsel = 0x7, /* 192 */ .max_sr = 96000   },
> +	{ .in = 8,  .out = 32, .width = 32, .bsel = 0x8, /* 256 */ .max_sr = 96000   },
> +	{ .in = 10, .out = 31, .width = 24, .bsel = 0xc, /* 250 */ .max_sr = 96000   },
> +	{ .in = 15, .out = 31, .width = 16, .bsel = 0xc, /* 250 */ .max_sr = 96000   },
> +	{ .in = 16, .out = 32, .width = 16, .bsel = 0x8, /* 256 */ .max_sr = 96000   },
> +	{ .in = 7,  .out = 31, .width = 32, .bsel = 0xc, /* 250 */ .max_sr = 48000   },
> +	{ .in = 10, .out = 31, .width = 24, .bsel = 0xc, /* 250 */ .max_sr = 48000   },
> +	{ .in = 10, .out = 40, .width = 32, .bsel = 0xb, /* 320 */ .max_sr = 48000   },
> +	{ .in = 15, .out = 31, .width = 16, .bsel = 0xc, /* 250 */ .max_sr = 48000   },
> +	{ .in = 16, .out = 48, .width = 24, .bsel = 0x9, /* 384 */ .max_sr = 48000   },
> +	{ .in = 16, .out = 64, .width = 32, .bsel = 0xa, /* 512 */ .max_sr = 48000   },
>  };
>  
> -static int max98396_get_bclk_sel(int bclk)
> +static int max98396_pcm_config_index(int in_slots, int out_slots, int width)
>  {
>  	int i;
> -	/* match BCLKs per LRCLK */
> -	for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
> -		if (bclk_sel_table[i] == bclk)
> -			return i + 2;
> -	}
> -	return 0;
> -}
>  
> -static int max98396_set_clock(struct snd_soc_component *component,
> -			      struct snd_pcm_hw_params *params)
> -{
> -	struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component);
> -	/* BCLK/LRCLK ratio calculation */
> -	int blr_clk_ratio = params_channels(params) * max98396->ch_size;
> -	int value;
> -
> -	if (!max98396->tdm_mode) {
> -		/* BCLK configuration */
> -		value = max98396_get_bclk_sel(blr_clk_ratio);
> -		if (!value) {
> -			dev_err(component->dev,
> -				"blr_clk_ratio %d unsupported, format %d\n",
> -				blr_clk_ratio, params_format(params));
> -			return -EINVAL;
> -		}
> +	for (i = 0; i < ARRAY_SIZE(max98396_pcm_configs); i++) {
> +		const struct max98396_pcm_config *c = &max98396_pcm_configs[i];
>  
> -		regmap_update_bits(max98396->regmap,
> -				   MAX98396_R2042_PCM_CLK_SETUP,
> -				   MAX98396_PCM_CLK_SETUP_BSEL_MASK,
> -				   value);
> +		if (in_slots == c->in && out_slots <= c->out && width == c->width)
> +			return i;
>  	}
>  
> -	return 0;
> +	return -1;
>  }
>  
>  static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
> @@ -489,8 +497,7 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
>  	struct max98396_priv *max98396 = snd_soc_component_get_drvdata(component);
>  	unsigned int sampling_rate = 0;
>  	unsigned int chan_sz = 0;
> -	int ret, reg;
> -	int status;
> +	int ret, reg, status, bsel;
>  	bool update = false;
>  
>  	/* pcm mode configuration */
> @@ -510,8 +517,6 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
>  		goto err;
>  	}
>  
> -	max98396->ch_size = snd_pcm_format_width(params_format(params));
> -
>  	dev_dbg(component->dev, "format supported %d",
>  		params_format(params));
>  
> @@ -559,6 +564,33 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
>  		goto err;
>  	}
>  
> +	if (max98396->tdm_mode) {
> +		if (params_rate(params) > max98396->tdm_max_samplerate) {
> +			dev_err(component->dev, "TDM sample rate %d too high",
> +				params_rate(params));
> +			goto err;
> +		}
> +	} else {
> +		/* BCLK configuration */
> +		ret = max98396_pcm_config_index(params_channels(params),
> +						params_channels(params),
> +						snd_pcm_format_width(params_format(params)));
> +		if (ret < 0) {
> +			dev_err(component->dev,
> +				"no PCM config for %d channels, format %d\n",
> +				params_channels(params), params_format(params));
> +			goto err;
> +		}
> +
> +		bsel = max98396_pcm_configs[ret].bsel;
> +
> +		if (params_rate(params) > max98396_pcm_configs[ret].max_sr) {
> +			dev_err(component->dev, "sample rate %d too high",
> +				params_rate(params));
> +			goto err;
> +		}
> +	}
> +
>  	ret = regmap_read(max98396->regmap, MAX98396_R210F_GLOBAL_EN, &status);
>  	if (ret < 0)
>  		goto err;
> @@ -604,12 +636,15 @@ static int max98396_dai_hw_params(struct snd_pcm_substream *substream,
>  				   MAX98396_IVADC_SR_MASK,
>  				   sampling_rate << MAX98396_IVADC_SR_SHIFT);
>  
> -	ret = max98396_set_clock(component, params);
> +	regmap_update_bits(max98396->regmap,
> +			   MAX98396_R2042_PCM_CLK_SETUP,
> +			   MAX98396_PCM_CLK_SETUP_BSEL_MASK,
> +			   bsel);
>  
>  	if (status && update)
>  		max98396_global_enable_onoff(max98396->regmap, true);
>  
> -	return ret;
> +	return 0;
>  
>  err:
>  	return -EINVAL;
> @@ -634,13 +669,16 @@ static int max98396_dai_tdm_slot(struct snd_soc_dai *dai,
>  		max98396->tdm_mode = true;
>  
>  	/* BCLK configuration */
> -	bsel = max98396_get_bclk_sel(slots * slot_width);
> -	if (bsel == 0) {
> -		dev_err(component->dev, "BCLK %d not supported\n",
> -			slots * slot_width);
> +	ret = max98396_pcm_config_index(slots, slots, slot_width);
> +	if (ret < 0) {
> +		dev_err(component->dev, "no TDM config for %d slots %d bits\n",
> +			slots, slot_width);
>  		return -EINVAL;
>  	}
>  
> +	bsel = max98396_pcm_configs[ret].bsel;
> +	max98396->tdm_max_samplerate = max98396_pcm_configs[ret].max_sr;
> +
>  	/* Channel size configuration */
>  	switch (slot_width) {
>  	case 16:


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [PATCH 3/8] ASoC: dt-bindings: max98396: Document adi,bypass-slot-no
  2022-06-24 10:47   ` Daniel Mack
@ 2022-06-24 12:42     ` Mark Brown
  -1 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2022-06-24 12:42 UTC (permalink / raw)
  To: Daniel Mack; +Cc: ryan.lee.analog, robh+dt, alsa-devel, devicetree

[-- Attachment #1: Type: text/plain, Size: 297 bytes --]

On Fri, Jun 24, 2022 at 12:47:07PM +0200, Daniel Mack wrote:
> This property allows to select the PCM data input channel that is
> routed to the speaker audio processing bypass path.
> 
> The driver already implements this property.

This really should be runtime sleectable but oh well :(

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 3/8] ASoC: dt-bindings: max98396: Document adi,bypass-slot-no
@ 2022-06-24 12:42     ` Mark Brown
  0 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2022-06-24 12:42 UTC (permalink / raw)
  To: Daniel Mack; +Cc: devicetree, ryan.lee.analog, robh+dt, alsa-devel

[-- Attachment #1: Type: text/plain, Size: 297 bytes --]

On Fri, Jun 24, 2022 at 12:47:07PM +0200, Daniel Mack wrote:
> This property allows to select the PCM data input channel that is
> routed to the speaker audio processing bypass path.
> 
> The driver already implements this property.

This really should be runtime sleectable but oh well :(

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 6/8] ASoC: max98396: Fix register access for PCM format settings
  2022-06-24 10:47   ` Daniel Mack
@ 2022-06-24 12:52     ` Mark Brown
  -1 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2022-06-24 12:52 UTC (permalink / raw)
  To: Daniel Mack; +Cc: ryan.lee.analog, robh+dt, alsa-devel, devicetree

[-- Attachment #1: Type: text/plain, Size: 317 bytes --]

On Fri, Jun 24, 2022 at 12:47:10PM +0200, Daniel Mack wrote:
> max98396_dai_set_fmt() modifes register 2041 and touches bits in the mask
> 0x3a. Make sure to use the right mask for that operation.

This is a fix so should be at the start of the series, ensuring it has
no dependencies on anything else in the series.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 6/8] ASoC: max98396: Fix register access for PCM format settings
@ 2022-06-24 12:52     ` Mark Brown
  0 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2022-06-24 12:52 UTC (permalink / raw)
  To: Daniel Mack; +Cc: devicetree, ryan.lee.analog, robh+dt, alsa-devel

[-- Attachment #1: Type: text/plain, Size: 317 bytes --]

On Fri, Jun 24, 2022 at 12:47:10PM +0200, Daniel Mack wrote:
> max98396_dai_set_fmt() modifes register 2041 and touches bits in the mask
> 0x3a. Make sure to use the right mask for that operation.

This is a fix so should be at the start of the series, ensuring it has
no dependencies on anything else in the series.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 8/8] ASoC: max98396: Fix TDM mode BSEL settings
  2022-06-24 10:47   ` Daniel Mack
@ 2022-06-24 12:54     ` Mark Brown
  -1 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2022-06-24 12:54 UTC (permalink / raw)
  To: Daniel Mack; +Cc: ryan.lee.analog, robh+dt, alsa-devel, devicetree

[-- Attachment #1: Type: text/plain, Size: 261 bytes --]

On Fri, Jun 24, 2022 at 12:47:12PM +0200, Daniel Mack wrote:
> In TDM mode, the BSEL register value must be set according to table 5 in the
> datasheet. This patch adds a lookup function and uses it in
> max98396_dai_tdm_slot().

Similar issue here with fixes.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 8/8] ASoC: max98396: Fix TDM mode BSEL settings
@ 2022-06-24 12:54     ` Mark Brown
  0 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2022-06-24 12:54 UTC (permalink / raw)
  To: Daniel Mack; +Cc: devicetree, ryan.lee.analog, robh+dt, alsa-devel

[-- Attachment #1: Type: text/plain, Size: 261 bytes --]

On Fri, Jun 24, 2022 at 12:47:12PM +0200, Daniel Mack wrote:
> In TDM mode, the BSEL register value must be set according to table 5 in the
> datasheet. This patch adds a lookup function and uses it in
> max98396_dai_tdm_slot().

Similar issue here with fixes.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 2/8] ASoC: dt-bindings: max98396: Add #sound-dai-cells
  2022-06-24 10:47   ` Daniel Mack
@ 2022-06-24 17:26     ` Rob Herring
  -1 siblings, 0 replies; 34+ messages in thread
From: Rob Herring @ 2022-06-24 17:26 UTC (permalink / raw)
  To: Daniel Mack; +Cc: ryan.lee.analog, devicetree, alsa-devel, robh+dt, broonie

On Fri, 24 Jun 2022 12:47:06 +0200, Daniel Mack wrote:
> Add this mandatory DT property to the yaml documentation.
> 
> Signed-off-by: Daniel Mack <daniel@zonque.org>
> ---
>  Documentation/devicetree/bindings/sound/adi,max98396.yaml | 4 ++++
>  1 file changed, 4 insertions(+)
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Error: Documentation/devicetree/bindings/sound/adi,max98396.example.dts:32.33-34 syntax error
FATAL ERROR: Unable to parse input tree
make[1]: *** [scripts/Makefile.lib:383: Documentation/devicetree/bindings/sound/adi,max98396.example.dtb] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1404: dt_binding_check] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/

This check can fail if there are any dependencies. The base for a patch
series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit.


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 2/8] ASoC: dt-bindings: max98396: Add #sound-dai-cells
@ 2022-06-24 17:26     ` Rob Herring
  0 siblings, 0 replies; 34+ messages in thread
From: Rob Herring @ 2022-06-24 17:26 UTC (permalink / raw)
  To: Daniel Mack; +Cc: devicetree, ryan.lee.analog, robh+dt, broonie, alsa-devel

On Fri, 24 Jun 2022 12:47:06 +0200, Daniel Mack wrote:
> Add this mandatory DT property to the yaml documentation.
> 
> Signed-off-by: Daniel Mack <daniel@zonque.org>
> ---
>  Documentation/devicetree/bindings/sound/adi,max98396.yaml | 4 ++++
>  1 file changed, 4 insertions(+)
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Error: Documentation/devicetree/bindings/sound/adi,max98396.example.dts:32.33-34 syntax error
FATAL ERROR: Unable to parse input tree
make[1]: *** [scripts/Makefile.lib:383: Documentation/devicetree/bindings/sound/adi,max98396.example.dtb] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1404: dt_binding_check] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/

This check can fail if there are any dependencies. The base for a patch
series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit.


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: (subset) [PATCH 0/8] ASoC: max98396: Some assorted fixes and additions
  2022-06-24 10:47 ` Daniel Mack
@ 2022-06-27 20:19   ` Mark Brown
  -1 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2022-06-27 20:19 UTC (permalink / raw)
  To: ryan.lee.analog, daniel; +Cc: robh+dt, devicetree, alsa-devel

On Fri, 24 Jun 2022 12:47:04 +0200, Daniel Mack wrote:
> This is a series of some patches that I collected while using the
> max98396 driver is a TDM mode setup.
> 
> They correct BSEL and PCM mode configs, add support for power supplies
> and add some bits to the documentation.
> 
> The code is tested in TDM-16 and TDM-8 mode with 32 channel width.
> 
> [...]

Applied to

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

Thanks!

[1/8] ASoC: dt-bindings: max98396: add voltage supplies
      (no commit info)
[2/8] ASoC: dt-bindings: max98396: Add #sound-dai-cells
      (no commit info)
[3/8] ASoC: dt-bindings: max98396: Document adi,bypass-slot-no
      (no commit info)
[4/8] ASoC: max98396: add voltage regulators
      (no commit info)
[5/8] ASoC: max98396: Improve some error prints
      (no commit info)
[6/8] ASoC: max98396: Fix register access for PCM format settings
      commit: cf5c888539f353cb10e127d3a8754554cacd293a
[7/8] ASoC: max98396: Implement DSP speaker monitor
      (no commit info)

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

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: (subset) [PATCH 0/8] ASoC: max98396: Some assorted fixes and additions
@ 2022-06-27 20:19   ` Mark Brown
  0 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2022-06-27 20:19 UTC (permalink / raw)
  To: ryan.lee.analog, daniel; +Cc: devicetree, alsa-devel, robh+dt

On Fri, 24 Jun 2022 12:47:04 +0200, Daniel Mack wrote:
> This is a series of some patches that I collected while using the
> max98396 driver is a TDM mode setup.
> 
> They correct BSEL and PCM mode configs, add support for power supplies
> and add some bits to the documentation.
> 
> The code is tested in TDM-16 and TDM-8 mode with 32 channel width.
> 
> [...]

Applied to

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

Thanks!

[1/8] ASoC: dt-bindings: max98396: add voltage supplies
      (no commit info)
[2/8] ASoC: dt-bindings: max98396: Add #sound-dai-cells
      (no commit info)
[3/8] ASoC: dt-bindings: max98396: Document adi,bypass-slot-no
      (no commit info)
[4/8] ASoC: max98396: add voltage regulators
      (no commit info)
[5/8] ASoC: max98396: Improve some error prints
      (no commit info)
[6/8] ASoC: max98396: Fix register access for PCM format settings
      commit: cf5c888539f353cb10e127d3a8754554cacd293a
[7/8] ASoC: max98396: Implement DSP speaker monitor
      (no commit info)

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

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: (subset) [PATCH 0/8] ASoC: max98396: Some assorted fixes and additions
  2022-06-27 20:19   ` Mark Brown
@ 2022-06-27 20:26     ` Daniel Mack
  -1 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-27 20:26 UTC (permalink / raw)
  To: Mark Brown, ryan.lee.analog; +Cc: robh+dt, devicetree, alsa-devel

On 6/27/22 22:19, Mark Brown wrote:
> On Fri, 24 Jun 2022 12:47:04 +0200, Daniel Mack wrote:
>> This is a series of some patches that I collected while using the
>> max98396 driver is a TDM mode setup.
>>
>> They correct BSEL and PCM mode configs, add support for power supplies
>> and add some bits to the documentation.
>>
>> The code is tested in TDM-16 and TDM-8 mode with 32 channel width.
>>
>> [...]
> 
> Applied to
> 
>    https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Umm, I was about to send out a new version of this series tomorrow to
address the things you pointed out, and some more detected by the test bots.

Which patches got applied now? I only see "Fix register access for PCM
format settings" in for-next and for-5.19 currently?


Thanks,
Daniel



> Thanks!
> 
> [1/8] ASoC: dt-bindings: max98396: add voltage supplies
>       (no commit info)
> [2/8] ASoC: dt-bindings: max98396: Add #sound-dai-cells
>       (no commit info)
> [3/8] ASoC: dt-bindings: max98396: Document adi,bypass-slot-no
>       (no commit info)
> [4/8] ASoC: max98396: add voltage regulators
>       (no commit info)
> [5/8] ASoC: max98396: Improve some error prints
>       (no commit info)
> [6/8] ASoC: max98396: Fix register access for PCM format settings
>       commit: cf5c888539f353cb10e127d3a8754554cacd293a
> [7/8] ASoC: max98396: Implement DSP speaker monitor
>       (no commit info)
> 
> 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


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: (subset) [PATCH 0/8] ASoC: max98396: Some assorted fixes and additions
@ 2022-06-27 20:26     ` Daniel Mack
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Mack @ 2022-06-27 20:26 UTC (permalink / raw)
  To: Mark Brown, ryan.lee.analog; +Cc: devicetree, alsa-devel, robh+dt

On 6/27/22 22:19, Mark Brown wrote:
> On Fri, 24 Jun 2022 12:47:04 +0200, Daniel Mack wrote:
>> This is a series of some patches that I collected while using the
>> max98396 driver is a TDM mode setup.
>>
>> They correct BSEL and PCM mode configs, add support for power supplies
>> and add some bits to the documentation.
>>
>> The code is tested in TDM-16 and TDM-8 mode with 32 channel width.
>>
>> [...]
> 
> Applied to
> 
>    https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Umm, I was about to send out a new version of this series tomorrow to
address the things you pointed out, and some more detected by the test bots.

Which patches got applied now? I only see "Fix register access for PCM
format settings" in for-next and for-5.19 currently?


Thanks,
Daniel



> Thanks!
> 
> [1/8] ASoC: dt-bindings: max98396: add voltage supplies
>       (no commit info)
> [2/8] ASoC: dt-bindings: max98396: Add #sound-dai-cells
>       (no commit info)
> [3/8] ASoC: dt-bindings: max98396: Document adi,bypass-slot-no
>       (no commit info)
> [4/8] ASoC: max98396: add voltage regulators
>       (no commit info)
> [5/8] ASoC: max98396: Improve some error prints
>       (no commit info)
> [6/8] ASoC: max98396: Fix register access for PCM format settings
>       commit: cf5c888539f353cb10e127d3a8754554cacd293a
> [7/8] ASoC: max98396: Implement DSP speaker monitor
>       (no commit info)
> 
> 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


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: (subset) [PATCH 0/8] ASoC: max98396: Some assorted fixes and additions
  2022-06-27 20:26     ` Daniel Mack
@ 2022-06-27 22:23       ` Mark Brown
  -1 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2022-06-27 22:23 UTC (permalink / raw)
  To: Daniel Mack; +Cc: ryan.lee.analog, robh+dt, devicetree, alsa-devel

[-- Attachment #1: Type: text/plain, Size: 1032 bytes --]

On Mon, Jun 27, 2022 at 10:26:41PM +0200, Daniel Mack wrote:

> Umm, I was about to send out a new version of this series tomorrow to
> address the things you pointed out, and some more detected by the test bots.

> Which patches got applied now? I only see "Fix register access for PCM
> format settings" in for-next and for-5.19 currently?

Yes, the bugfix:

> > [1/8] ASoC: dt-bindings: max98396: add voltage supplies
> >       (no commit info)
> > [2/8] ASoC: dt-bindings: max98396: Add #sound-dai-cells
> >       (no commit info)
> > [3/8] ASoC: dt-bindings: max98396: Document adi,bypass-slot-no
> >       (no commit info)
> > [4/8] ASoC: max98396: add voltage regulators
> >       (no commit info)
> > [5/8] ASoC: max98396: Improve some error prints
> >       (no commit info)
> > [6/8] ASoC: max98396: Fix register access for PCM format settings
> >       commit: cf5c888539f353cb10e127d3a8754554cacd293a
> > [7/8] ASoC: max98396: Implement DSP speaker monitor
> >       (no commit info)

it's the only one listed here too.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: (subset) [PATCH 0/8] ASoC: max98396: Some assorted fixes and additions
@ 2022-06-27 22:23       ` Mark Brown
  0 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2022-06-27 22:23 UTC (permalink / raw)
  To: Daniel Mack; +Cc: devicetree, ryan.lee.analog, robh+dt, alsa-devel

[-- Attachment #1: Type: text/plain, Size: 1032 bytes --]

On Mon, Jun 27, 2022 at 10:26:41PM +0200, Daniel Mack wrote:

> Umm, I was about to send out a new version of this series tomorrow to
> address the things you pointed out, and some more detected by the test bots.

> Which patches got applied now? I only see "Fix register access for PCM
> format settings" in for-next and for-5.19 currently?

Yes, the bugfix:

> > [1/8] ASoC: dt-bindings: max98396: add voltage supplies
> >       (no commit info)
> > [2/8] ASoC: dt-bindings: max98396: Add #sound-dai-cells
> >       (no commit info)
> > [3/8] ASoC: dt-bindings: max98396: Document adi,bypass-slot-no
> >       (no commit info)
> > [4/8] ASoC: max98396: add voltage regulators
> >       (no commit info)
> > [5/8] ASoC: max98396: Improve some error prints
> >       (no commit info)
> > [6/8] ASoC: max98396: Fix register access for PCM format settings
> >       commit: cf5c888539f353cb10e127d3a8754554cacd293a
> > [7/8] ASoC: max98396: Implement DSP speaker monitor
> >       (no commit info)

it's the only one listed here too.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2022-06-27 22:24 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-24 10:47 [PATCH 0/8] ASoC: max98396: Some assorted fixes and additions Daniel Mack
2022-06-24 10:47 ` Daniel Mack
2022-06-24 10:47 ` [PATCH 1/8] ASoC: dt-bindings: max98396: add voltage supplies Daniel Mack
2022-06-24 10:47   ` Daniel Mack
2022-06-24 10:47 ` [PATCH 2/8] ASoC: dt-bindings: max98396: Add #sound-dai-cells Daniel Mack
2022-06-24 10:47   ` Daniel Mack
2022-06-24 17:26   ` Rob Herring
2022-06-24 17:26     ` Rob Herring
2022-06-24 10:47 ` [PATCH 3/8] ASoC: dt-bindings: max98396: Document adi,bypass-slot-no Daniel Mack
2022-06-24 10:47   ` Daniel Mack
2022-06-24 12:42   ` Mark Brown
2022-06-24 12:42     ` Mark Brown
2022-06-24 10:47 ` [PATCH 4/8] ASoC: max98396: add voltage regulators Daniel Mack
2022-06-24 10:47   ` Daniel Mack
2022-06-24 10:47 ` [PATCH 5/8] ASoC: max98396: Improve some error prints Daniel Mack
2022-06-24 10:47   ` Daniel Mack
2022-06-24 10:47 ` [PATCH 6/8] ASoC: max98396: Fix register access for PCM format settings Daniel Mack
2022-06-24 10:47   ` Daniel Mack
2022-06-24 12:52   ` Mark Brown
2022-06-24 12:52     ` Mark Brown
2022-06-24 10:47 ` [PATCH 7/8] ASoC: max98396: Implement DSP speaker monitor Daniel Mack
2022-06-24 10:47   ` Daniel Mack
2022-06-24 10:47 ` [PATCH 8/8] ASoC: max98396: Fix TDM mode BSEL settings Daniel Mack
2022-06-24 10:47   ` Daniel Mack
2022-06-24 11:34   ` Daniel Mack
2022-06-24 11:34     ` Daniel Mack
2022-06-24 12:54   ` Mark Brown
2022-06-24 12:54     ` Mark Brown
2022-06-27 20:19 ` (subset) [PATCH 0/8] ASoC: max98396: Some assorted fixes and additions Mark Brown
2022-06-27 20:19   ` Mark Brown
2022-06-27 20:26   ` Daniel Mack
2022-06-27 20:26     ` Daniel Mack
2022-06-27 22:23     ` Mark Brown
2022-06-27 22:23       ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.