Skip to contentSkip to conversation

sound: dt-bindings: cmx655d

PATCH In review Nikola Jelic 3 participants 4 messages Jan 21, 2025 – Jan 22, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 sound: dt-bindings: cmx655d

---
 .../bindings/sound/cml,cmx655d.yaml           | 79 +++++++++++++++++++
 .../devicetree/bindings/sound/cmx655.txt      | 59 ++++++++++++++
 .../devicetree/bindings/vendor-prefixes.yaml  |  2 +
 3 files changed, 140 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/cml,cmx655d.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/cmx655.txt
Documentation/devicetree/bindings/sound/cml,cmx655d.yaml new file +79 -0
new file mode 100644
index 000000000000..ea2cdce80ea3
@@ -0,0 +1,79 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/cml,cmx655d.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CML Micro CMX655D codec
+
+maintainers:
+  - Richard Walton <[email protected]>
+  - Nikola Jelic <[email protected]>
+
+description: |
+  The CMX655D is an ultra-low power voice codec.
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    enum:
+      - cml,cmx655d
+
+  reg:
+    maxItems: 1
+
+  "#sound-dai-cells":
+    const: 0
+
+  reset-gpios:
+    description: GPIO used for codec reset, negative logic
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  interrupt-names:
+    maxItems: 1
+
+  pinctrl-names:
+    maxItems: 1
+
+  pinctr-0:
+    maxItems: 1
+
+  cmx655,classd-oc-reset-attempts:
+    description: Maximum number of times to reset CMX655 class-D
+      following a overcurrent event.
+      Default = 5, >10000 = disable limit.
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 5
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        status = "okay";
+        codec: cmx655 {
+            reg = <0x54>;
+            #sound-dai-cells = <0>;
+            compatible = "cml,cmx655d";
+            reset-gpios = <&gpio 24 1>;
+            interrupt-parent = <&gpio>;
+            interrupts = <25 0x2>;
+            interrupt-names = "irq";
+            pinctrl-names = "default";
+            pinctrl-0 = <&ev6550DHAT_pins>;
+            cmx655,classd-oc-reset-attempts = <5>;
+        };
+
+    };
+...
Documentation/devicetree/bindings/sound/cmx655.txt new file +59 -0

59 lines not on this page · raw message

Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index 5079ca6ce1d1..c471a4b905cf 100644
@@ -308,6 +308,8 @@ patternProperties:
     description: Carl Cloos Schweisstechnik GmbH.
   "^cloudengines,.*":
     description: Cloud Engines, Inc.
+  "^cml,.*":
+    description: CML Micro, Ltd.
   "^cnm,.*":
     description: Chips&Media, Inc.
   "^cnxt,.*":
Signature · 1 line
2.45.2
#1 lore raw

PATCH 2/2 Adding support for the CML's CMX655D audio codec, both i2c and spi connectivity options.

---
 sound/soc/codecs/Kconfig      |   27 +
 sound/soc/codecs/Makefile     |    4 +
 sound/soc/codecs/cmx655.c     | 1179 +++++++++++++++++++++++++++++++++
 sound/soc/codecs/cmx655.h     |  151 +++++
 sound/soc/codecs/cmx655_i2c.c |  135 ++++
 sound/soc/codecs/cmx655_spi.c |  132 ++++
 6 files changed, 1628 insertions(+)
 create mode 100644 sound/soc/codecs/cmx655.c
 create mode 100644 sound/soc/codecs/cmx655.h
 create mode 100644 sound/soc/codecs/cmx655_i2c.c
 create mode 100644 sound/soc/codecs/cmx655_spi.c
sound/soc/codecs/Kconfig +27 -0
index ee35f3aa5521..4f440e849b23 100644
@@ -63,6 +63,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_BT_SCO
 	imply SND_SOC_BD28623
 	imply SND_SOC_CHV3_CODEC
+	imply SND_SOC_CMX655
 	imply SND_SOC_CQ0093VC
 	imply SND_SOC_CROS_EC_CODEC
 	imply SND_SOC_CS35L32
@@ -747,6 +748,32 @@ config SND_SOC_CPCAP
 	tristate "Motorola CPCAP codec"
 	depends on MFD_CPCAP || COMPILE_TEST
 
+config SND_SOC_CMX655D
+	tristate "CMX655D codec"
+	depends on I2C || SPI_MASTER
+	help
+	  Enable support for CML CMX655D audio codec with a speaker and
+	  two microphones. You also need to enable at least one bus
+	  adapter, I2C and/or SPI.
+
+config SND_SOC_CMX655D_I2C
+       tristate "CMX655D codec (I2C)"
+       depends on I2C && SND_SOC_CMX655D
+       default I2C && SND_SOC_CMX655D
+       select REGMAP
+       select REGMAP_I2C
+       help
+         Enable support for CML CMX655D audio codec with I2C control.
+
+config SND_SOC_CMX655D_SPI
+       tristate "CMX655D codec (SPI)"
+       depends on SPI_MASTER && SND_SOC_CMX655D
+       default SPI_MASTER && SND_SOC_CMX655D
+       select REGMAP
+       select REGMAP_SPI
+       help
+         Enable support for CML CMX655D audio codec with SPI control.
+
 config SND_SOC_CQ0093VC
 	tristate
 
sound/soc/codecs/Makefile +4 -0
index d7ad795603c1..85c167283956 100644
@@ -58,6 +58,7 @@ snd-soc-aw88399-y := aw88399.o
 snd-soc-bd28623-y := bd28623.o
 snd-soc-bt-sco-y := bt-sco.o
 snd-soc-chv3-codec-y := chv3-codec.o
+snd-soc-cmx655-y := cmx655.o
 snd-soc-cpcap-y := cpcap.o
 snd-soc-cq93vc-y := cq93vc.o
 snd-soc-cros-ec-codec-y := cros_ec_codec.o
@@ -475,6 +476,9 @@ obj-$(CONFIG_SND_SOC_AW88399)	+= snd-soc-aw88399.o
 obj-$(CONFIG_SND_SOC_BD28623)	+= snd-soc-bd28623.o
 obj-$(CONFIG_SND_SOC_BT_SCO)	+= snd-soc-bt-sco.o
 obj-$(CONFIG_SND_SOC_CHV3_CODEC) += snd-soc-chv3-codec.o
+obj-$(CONFIG_SND_SOC_CMX655D) += snd-soc-cmx655.o
+obj-$(CONFIG_SND_SOC_CMX655D_I2C) += cmx655_i2c.o
+obj-$(CONFIG_SND_SOC_CMX655D_SPI) += cmx655_spi.o
 obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o
 obj-$(CONFIG_SND_SOC_CPCAP)	+= snd-soc-cpcap.o
 obj-$(CONFIG_SND_SOC_CROS_EC_CODEC)	+= snd-soc-cros-ec-codec.o
sound/soc/codecs/cmx655.c new file +1179 -0

1,179 lines not on this page · raw message

sound/soc/codecs/cmx655.h new file +151 -0

151 lines not on this page · raw message

sound/soc/codecs/cmx655_i2c.c new file +135 -0

135 lines not on this page · raw message

sound/soc/codecs/cmx655_spi.c new file +132 -0

132 lines not on this page · raw message

Signature · 1 line
2.45.2
maintainer
#2 lore raw

Re: [PATCH 2/2] Adding support for the CML's CMX655D audio codec, both i2c and spi connectivity options.

On Wed, Jan 22, 2025 at 12:09:03AM +0100, Nikola Jelic wrote:

There's quite a few things here. In general the majority of the issues are ones where the driver isn't following common patterns that other drivers in the subsystem or kernel at large aren't following them, a lot of them are stylistic but there's quite a few that will affect operation too. In some of the more widespread issues I've highlighted examples rather than every single one.

Please submit patches using subject lines reflecting the style for the subsystem, this makes it easier for people to identify relevant patches. Look at what existing commits in the area you're changing are doing and make sure your subject lines visually resemble what they're doing. There's no need to resubmit to fix this alone.

sound/soc/codecs/Kconfig config SND_SOC_CPCAP · line 758

Quoted 8 lines
sound/soc/codecs/Kconfig +8 -0
+config SND_SOC_CMX655D
+	tristate "CMX655D codec"
+	depends on I2C || SPI_MASTER
+	help
+	  Enable support for CML CMX655D audio codec with a speaker and
+	  two microphones. You also need to enable at least one bus
+	  adapter, I2C and/or SPI.
+

There is no point in making this user selectable since it's unusable without a bus, do what all the other multi-bus devices do and make it selected by the per-bus options.

sound/soc/codecs/Makefile obj-$(CONFIG_SND_SOC_AW88399) += snd-soc-aw88399.o · line 481

Quoted 3 lines
sound/soc/codecs/Makefile +3 -0
+obj-$(CONFIG_SND_SOC_CMX655D) += snd-soc-cmx655.o
+obj-$(CONFIG_SND_SOC_CMX655D_I2C) += cmx655_i2c.o
+obj-$(CONFIG_SND_SOC_CMX655D_SPI) += cmx655_spi.o

All the other ASoC modules are snd-soc- ones and we always use - not _ as a separator.

Quoted 5 lines

+/*
+ * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ * Create Regmap
+ * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ */

Please use a normal kernel commenting style.

Quoted 10 lines
sound/soc/codecs/cmx655.c new file +10 -0
+/*
+ * Define volatile regs with function
+ */
+static bool cmx655_volatile_reg(struct device *dev, unsigned int reg)
+{
+	bool ret;
+
+	switch (reg) {
+	case CMX655_COMMAND:
+	case CMX655_SYSCTRL:

sound/soc/codecs/cmx655.c line 132

Quoted 10 lines
sound/soc/codecs/cmx655.c new file +10 -0
+	case CMX655_ISR:
+	case CMX655_ISE:
+		ret = true;
+		break;
+	default:
+		ret = false;
+		break;
+	}
+	return ret;
+};

Please just directly return like other similar regmap functions do, it *probably* doesn't make a difference to the generated code but it makes the code look less standard.

sound/soc/codecs/cmx655.c line 145

Quoted 3 lines
sound/soc/codecs/cmx655.c new file +3 -0
+	.reg_defaults = cmx655_reg_defaults,
+	.num_reg_defaults = ARRAY_SIZE(cmx655_reg_defaults),
+	.cache_type = REGCACHE_RBTREE,

Unless you've got a strong reason to use something else the default should be _MAPLE.

Quoted 1 line

+EXPORT_SYMBOL(cmx655_regmap);

ASoC and regmap are both EXPORT_SYMBOL_GPL, this is unusable without _GPL so you should keep it and all the other exports _GPL too.

Quoted 11 lines

+/*
+ * Get the clock setup the system clock based on clock Id, DAI master mode
+ * and sample rate

+ *      clk_id      - Clock source setting as defined in cmx655.h
+ *      master_mode - Non-zero if the CMX655 is the DAI master
+ *      sr_setting  - Setting for sample rate 0 to 3
+ *      clk_src     - pointer for storing clock source (PLLREF, PLLSEL and
+ *                          CLKSEL bits)
+ *      rdiv        - pointer for storing PLL's RDIV value (13 bits)
+ *      ndiv        - pointer for storing PLL's NDIV value (13 bits)
+ *      pll_ctrl    - pointer for storing PLLCTRL register value (8 bits)
Quoted 1 line

+ */

Again, we have a style for this in the kernel which you should use.

sound/soc/codecs/cmx655.c line 423

Quoted 5 lines
sound/soc/codecs/cmx655.c new file +5 -0
+	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+	case SND_SOC_DAIFMT_CBM_CFM:
+		reg_val = reg_val | CMX655_SAI_MSTR;
+		break;
+	case SND_SOC_DAIFMT_CBS_CFS:

Please use the modern names for these that avoid outdated terminology.

Quoted 4 lines
sound/soc/codecs/cmx655.c new file +4 -0
+static int cmx655_hw_params(struct snd_pcm_substream *stream,
+			    struct snd_pcm_hw_params *hw_params,
+			    struct snd_soc_dai *dai)
+{

sound/soc/codecs/cmx655.c line 552

Quoted 10 lines
sound/soc/codecs/cmx655.c new file +10 -0
+	int ret;
+	struct snd_soc_component *component = dai->component;
+	struct cmx655_data *cmx655_data =
+	    snd_soc_component_get_drvdata(component);
+	struct cmx655_dai_data *cmx655_dai_data = &cmx655_data->dai_data;
+	unsigned int enabled_streams = cmx655_dai_data->enabled_streams;
+
+	if (cmx655_dai_data->best_clk_running) {
+		// Will get here if the clock is in use so don't go stopping it
+		dev_dbg(component->dev, "Clock running. Skipping setup\n");

This is going to result in us just ignoring what the user asked for if the stream is already running. Like with other devices if there's constraints that have been created at runtime they should be advertised to userspace via the constraints interface, if userspace attempts to set something that violates the constraints we should error out.

sound/soc/codecs/cmx655.c line 690

Quoted 12 lines
sound/soc/codecs/cmx655.c new file +11 -0
+static irqreturn_t cmx655_irq_thread(int irq, void *data)
+{
+	struct snd_soc_component *component = data;
+	struct cmx655_data *cmx655_data =
+	    snd_soc_component_get_drvdata(component);
+	unsigned int status;
 
+	status = snd_soc_component_read(component, CMX655_ISR);
+	if (status == 0) {	// Event was not trigged by CMX655 so let the higher level know
+		return IRQ_NONE;
+	}
+	// Thermal protection event ++++++++++++++++++++++++++++++++++++++++++++++++

Again, please write code that looks like kernel code. I'm not pointing out every issue here.

sound/soc/codecs/cmx655.c line 877

Quoted 3 lines
sound/soc/codecs/cmx655.c new file +3 -0
+	SOC_ENUM("Cap_HPF Capture Switch", cmx655_hpf_capture_enum),
+	// Noise gate
+	SOC_SINGLE("Noise_Gate Capture Switch", CMX655_NGCTRL, 7, 1, 0),

Please don't insert random _s into control names, write something that looks like normal text.

sound/soc/codecs/cmx655.c line 879

Quoted 2 lines
sound/soc/codecs/cmx655.c new file +2 -0
+	SOC_SINGLE_TLV("NG_Threshold Capture Volume", CMX655_NGCTRL, 0, 31, 0,
+		       cmx655_ng_thresh),

Please consistently name the noise gate controls to use Noise Gate to help userspace group the controls.

sound/soc/codecs/cmx655.c line 888

Quoted 2 lines
sound/soc/codecs/cmx655.c new file +2 -0
+	SOC_SINGLE_TLV("Pre_Amp Playback Volume", CMX655_PREAMP, 0, 3, 0,
+		       cmx655_pre_amp),

Preamp or Preamplifier.

sound/soc/codecs/cmx655.c line 894

Quoted 1 line
sound/soc/codecs/cmx655.c new file +1 -0
+	SOC_ENUM("Play_HPF Playback Switch", cmx655_hpf_playback_enum),

Play and Playback?

sound/soc/codecs/cmx655.c line 910

Quoted 1 line
sound/soc/codecs/cmx655.c new file +1 -0
+	SOC_SINGLE("Companding_En Switch", CMX655_SAIMUX, 4, 1, 0),

_En is redundant.

sound/soc/codecs/cmx655.c line 911

Quoted 1 line
sound/soc/codecs/cmx655.c new file +1 -0
+	SOC_ENUM("Companding_Type Switch", cmx655_companding_enum),

This is an enumeration not a Switch, this will confuse userspace.

sound/soc/codecs/cmx655_i2c.c line 36

Quoted 3 lines
sound/soc/codecs/cmx655_i2c.c new file +3 -0
+	// Set-up value following the codec reset that will happen in a bit
+	cmx655_data->dai_data.enabled_streams = 0;
+	cmx655_data->dai_data.best_clk_running = false;

You kzalloc()ed the struct.

sound/soc/codecs/cmx655_i2c.c line 67

Quoted 13 lines
sound/soc/codecs/cmx655_i2c.c new file +13 -0
+	if (cmx655_data->reset_gpio) {
+		// Hold reset line
+		gpiod_set_value_cansleep(cmx655_data->reset_gpio, 1);
+		// Time of reset pulse must be greater than 1us
+		// sleep for 10us to 1ms, speed is not critical here
+		usleep_range(10, 1000);
+		// release reset line
+		gpiod_set_value_cansleep(cmx655_data->reset_gpio, 0);
+	} else {
+		dev_dbg(&client->dev, "No reset GPIO, using reset command\n");
+		regmap_write(cmx655_data->regmap, CMX655_COMMAND,
+			     CMX655_CMD_SOFT_RESET);
+	}

This could be factored out into the core, as could the DT parsing.

sound/soc/codecs/cmx655_i2c.c line 91

Quoted 8 lines
sound/soc/codecs/cmx655_i2c.c new file +8 -0
+static void cmx655_i2c_remove(struct i2c_client *client)
+{
+	struct cmx655_data *cmx655_data = i2c_get_clientdata(client);
+	// put codec into reset in GPIO given
+	gpiod_set_value_cansleep(cmx655_data->reset_gpio, 1);
+	// unregister codec
+	cmx655_common_unregister_component(&client->dev);
+};

This will reset the device while it's still exposed to userspace which could go badly.

#3 lore raw
In reply to Nikola Jelic
Quoted 1 line · Nikola Jelic

Please run scripts/checkpatch.pl and fix reported warnings. After that, run also scripts/checkpatch.pl --strict and (probably) fix more warnings. Some warnings can be ignored, especially from --strict run, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.

Please use subject prefixes matching the subsystem. You can get them for example with git log --oneline -- DIRECTORY_OR_FILE on the directory your patch is touching. For bindings, the preferred subjects are explained here:
https://www.kernel.org/doc/html/latest/devicetree/bindings/submitting-patches.html#i-for-patch-submitters

<form letter>
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.

Tools like b4 or scripts/get_maintainer.pl provide you proper list of people, so fix your workflow. Tools might also fail if you work on some ancient tree (don't, instead use mainline) or work on fork of kernel (don't, instead use mainline). Just use b4 and everything should be fine, although remember about b4 prep --auto-to-cc if you added new patches to the patchset.

You missed at least devicetree list (maybe more), so this won't be tested by automated tooling. Performing review on untested code might be a waste of time.

Please kindly resend and include all necessary To/Cc entries. </form letter>

Quoted 3 lines
---
 .../bindings/sound/cml,cmx655d.yaml           | 79 +++++++++++++++++++
 .../devicetree/bindings/sound/cmx655.txt      | 59 ++++++++++++++

No, bindings in text are not allowed anymore.

Best regards,
Krzysztof