Skip to contentSkip to conversation

ASoC: simple-card-utils: support system-clock-id DT property

PATCH In review Sen Wang 4 participants 9 messages May 15 – Jun 16

Subsystems (4)
lore
Share & tools
lore

Sen Wang

author
#0 lore raw

v2 cover ASoC: simple-card-utils: support system-clock-id DT property

Adding an optional, u32 system-clock-id DT property into the generic machine driver so clocking topology info can be exposed in DT.

Sen Wang (2):
dt-bindings: sound: simple-card: add system-clock-id property
ASoC: simple-card-utils: support system-clock-id DT property

 Documentation/devicetree/bindings/sound/audio-graph-port.yaml |  2 +
 Documentation/devicetree/bindings/sound/simple-card.yaml      | 10 +++++++
 include/sound/simple_card_utils.h                              |  1 +
 sound/soc/generic/simple-card-utils.c                         | 13 +++++----
 4 files changed, 21 insertions(+), 5 deletions(-)

---
base-commit: f5ffe03e0678 (linux-next)

author
#1 lore raw

PATCH v2 1/2 dt-bindings: sound: simple-card: add system-clock-id property

Document the new optional "system-clock-id" u32 property for cpu/codec sub-nodes in simple-audio-card and audio-graph-card.

The property maps directly to the clk_id argument of snd_soc_dai_set_sysclk(). When absent the existing default of 0 is used, so no existing DT is affected. CPU and codec sub-nodes are parsed independently; each side may carry a different value to select different clock sources on the two DAIs within the same dai-link.

---
changes in V2:
- Newly added (V1 is RFC)

Documentation/devicetree/bindings/sound/audio-graph-port.yaml +2 -0
index d1cbfc5edd3a..8094a76b9b4a 100644
@@ -67,6 +67,8 @@ definitions:
         $ref: simple-card.yaml#/definitions/system-clock-direction-out
       system-clock-fixed:
         $ref: simple-card.yaml#/definitions/system-clock-fixed
+      system-clock-id:
+        $ref: simple-card.yaml#/definitions/system-clock-id
 
       dai-format:
         description: audio format.
Documentation/devicetree/bindings/sound/simple-card.yaml +10 -0
index a14716b2732f..47a02d340d5e 100644
@@ -49,6 +49,14 @@ definitions:
       single fixed sampling rate.
     $ref: /schemas/types.yaml#/definitions/flag
 
+  system-clock-id:
+    description:
+      Selects which system clock to configure via set_sysclk(). Corresponds
+      to the clk_id argument of snd_soc_dai_set_sysclk(). When absent the
+      driver default (0) is used. CPU and codec sub-nodes are parsed
+      independently so each side may carry a different value.
+    $ref: /schemas/types.yaml#/definitions/uint32
+
   mclk-fs:
     description: |
       Multiplication factor between stream rate and codec mclk.
@@ -135,6 +143,8 @@ definitions:
         $ref: "#/definitions/system-clock-direction-out"
       system-clock-fixed:
         $ref: "#/definitions/system-clock-fixed"
+      system-clock-id:
+        $ref: "#/definitions/system-clock-id"
     required:
       - sound-dai
 
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: sound: simple-card: add system-clock-id property

Quoted 5 lines · Sen Wang

Document the new optional "system-clock-id" u32 property for cpu/codec sub-nodes in simple-audio-card and audio-graph-card.

The property maps directly to the clk_id argument of snd_soc_dai_set_sysclk(). When absent the existing default of 0 is

That's driver argument in bindings. Poor way to start discussion. Please describe the hardware instead.

Quoted 3 lines

used, so no existing DT is affected. CPU and codec sub-nodes are parsed independently; each side may carry a different value to select different clock sources on the two DAIs within the same dai-link.

Again, nothing about the hardware here.

Quoted 24 lines

---
changes in V2:
- Newly added (V1 is RFC)

Documentation/devicetree/bindings/sound/audio-graph-port.yaml +2 -0
index d1cbfc5edd3a..8094a76b9b4a 100644
@@ -67,6 +67,8 @@ definitions:
         $ref: simple-card.yaml#/definitions/system-clock-direction-out
       system-clock-fixed:
         $ref: simple-card.yaml#/definitions/system-clock-fixed
+      system-clock-id:
+        $ref: simple-card.yaml#/definitions/system-clock-id
 
       dai-format:
         description: audio format.
Documentation/devicetree/bindings/sound/simple-card.yaml +0 -0
index a14716b2732f..47a02d340d5e 100644

Documentation/devicetree/bindings/sound/simple-card.yaml definitions: · line 55

Quoted 7 lines
Documentation/devicetree/bindings/sound/simple-card.yaml +4 -0
@@ -49,6 +49,14 @@ definitions:
       single fixed sampling rate.
     $ref: /schemas/types.yaml#/definitions/flag
 
+  system-clock-id:
+    description:
+      Selects which system clock to configure via set_sysclk(). Corresponds
+      to the clk_id argument of snd_soc_dai_set_sysclk(). When absent the

So now driver APIs are part of binding :/. No.

You should have built on top or use previous discussion instead of making new mistakes:
https://lore.kernel.org/linux-devicetree/[email protected]/

Best regards,
Krzysztof

author
#3 lore raw

Re: [PATCH v2 1/2] dt-bindings: sound: simple-card: add system-clock-id property

Quoted 3 lines · Krzysztof Kozlowski
Quoted 2 lines · Sen Wang

Document the new optional "system-clock-id" u32 property for cpu/codec sub-nodes in simple-audio-card and audio-graph-card.

(snip)

Quoted 6 lines

So now driver APIs are part of binding :/. No.

You should have built on top or use previous discussion instead of making new mistakes:
https://lore.kernel.org/linux-devicetree/[email protected]/

Thanks for your insight Krzysztof, definitely failed my due diligence in finding previous discussions :/.

Let me see if I can do some refactor in ASoC clks instead.

Best,
Sen Wang

author
#4 lore raw

PATCH v2 2/2 ASoC: simple-card-utils: support system-clock-id DT property

In reply to Sen Wang

The generic machine driver never had a mechanism to adjust for various clk_ids that is tailored for individual codec & cpu peripheral driver. simple_util_dai_init() has hardcoded 0, thus making non-default clock IDs unreachable from DTS. Boards needing a specific clk_id have had no choice but to write dedicated machine drivers.

Add an optional "system-clock-id" u32 property to the cpu/codec sub-node and use it in all three set_sysclk() call sites. When absent clk_id stays 0, preserving identical behavior for all existing boards.

And since simple_util_parse_clk() is invoked once per sub-node, per-DAI independence can be preserved as cpu and codec sub-nodes carry independent clk_id values.

E.g., the following dts topology would be supported:

cpu { system-clock-id = <6>; }
codec { system-clock-id = <1>; }

---

Apologies Morimoto-san, when finalizing the patch I realize a few more places need to be changed, can you kindly re-review and give your acked-by?

Changes in v2:
- Adopted sysclk func changes for mclk cases
- Links to v1 (RFC):
https://lore.kernel.org/all/[email protected]/

include/sound/simple_card_utils.h +1 -0
index 915e6ae5f68d..f221fba92e5e 100644
@@ -26,6 +26,7 @@ struct simple_util_dai {
 	const char *name;
 	unsigned int sysclk;
 	int clk_direction;
+	int clk_id;
 	int slots;
 	int slot_width;
 	unsigned int tx_slot_mask;
sound/soc/generic/simple-card-utils.c +13 -5
index 4cf3a5395763..ce7e960db5e9 100644
@@ -290,6 +290,9 @@ int simple_util_parse_clk(struct device *dev,
 	if (of_property_read_bool(node, "system-clock-direction-out"))
 		simple_dai->clk_direction = SND_SOC_CLOCK_OUT;
 
+	if (!of_property_read_u32(node, "system-clock-id", &val))
+		simple_dai->clk_id = val;
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(simple_util_parse_clk);
@@ -506,14 +509,16 @@ int simple_util_hw_params(struct snd_pcm_substream *substream,
 			/* CPU first */
 			for_each_rtd_cpu_dais(rtd, i, sdai) {
 				pdai = simple_props_to_dai_cpu(props, i);
-				ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, pdai->clk_direction);
+				ret = snd_soc_dai_set_sysclk(sdai, pdai->clk_id,
+						mclk, pdai->clk_direction);
 				if (ret && ret != -ENOTSUPP)
 					goto end;
 			}
 
 			for_each_rtd_codec_dais(rtd, i, sdai) {
 				pdai = simple_props_to_dai_codec(props, i);
-				ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, pdai->clk_direction);
+				ret = snd_soc_dai_set_sysclk(sdai, pdai->clk_id,
+						mclk, pdai->clk_direction);
 				if (ret && ret != -ENOTSUPP)
 					goto end;
 			}
@@ -521,14 +526,16 @@ int simple_util_hw_params(struct snd_pcm_substream *substream,
 			/* default: codec first */
 			for_each_rtd_codec_dais(rtd, i, sdai) {
 				pdai = simple_props_to_dai_codec(props, i);
-				ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, pdai->clk_direction);
+				ret = snd_soc_dai_set_sysclk(sdai, pdai->clk_id,
+						mclk, pdai->clk_direction);
 				if (ret && ret != -ENOTSUPP)
 					goto end;
 			}
 
 			for_each_rtd_cpu_dais(rtd, i, sdai) {
 				pdai = simple_props_to_dai_cpu(props, i);
-				ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, pdai->clk_direction);
+				ret = snd_soc_dai_set_sysclk(sdai, pdai->clk_id,
+						mclk, pdai->clk_direction);
 				if (ret && ret != -ENOTSUPP)
 					goto end;
 			}
@@ -587,7 +594,8 @@ static int simple_init_dai(struct simple_util_priv *priv,
 		return 0;
 
 	if (simple_dai->sysclk) {
-		ret = snd_soc_dai_set_sysclk(dai, 0, simple_dai->sysclk,
+		ret = snd_soc_dai_set_sysclk(dai, simple_dai->clk_id,
+					     simple_dai->sysclk,
 					     simple_dai->clk_direction);
 		if (ret && ret != -ENOTSUPP) {
 			dev_err(dai->dev, "simple-card: set_sysclk error\n");
#5 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The commit introduces asymmetric sysclk configuration by failing to update `clk_id` in the…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The commit introduces asymmetric sysclk configuration by failing to update clk_id in the shutdown path, leading to incorrect hardware states and resource leaks. --

commit fb04cb3ea63c6e1c03c9835d2530dab5d343394b
Author: Sen Wang <[email protected]>

ASoC: simple-card-utils: support system-clock-id DT property

This commit adds an optional system-clock-id DT property to the cpu/codec sub-nodes. It updates simple_util_parse_clk(), simple_util_hw_params(), and simple_init_dai() to read and use this clock ID instead of hardcoding 0.

Quoted 4 lines
sound/soc/generic/simple-card-utils.c +0 -0
index e5cb602fd2487..441f68df85220 100644

[ ... ]

sound/soc/generic/simple-card-utils.c int simple_util_hw_params(struct snd_pcm_substream *substream, · line 513

Quoted 7 lines
sound/soc/generic/simple-card-utils.c +2 -1
@@ -506,14 +509,16 @@ int simple_util_hw_params(struct snd_pcm_substream *substream,
 			/* CPU first */
 			for_each_rtd_cpu_dais(rtd, i, sdai) {
 				pdai = simple_props_to_dai_cpu(props, i);
-				ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, pdai->clk_direction);
+				ret = snd_soc_dai_set_sysclk(sdai, pdai->clk_id,
+						mclk, pdai->clk_direction);

Does the teardown path in simple_util_shutdown() also need to be updated to use clk_id?

It currently hardcodes 0 when disabling the clock:

sound/soc/generic/simple-card-utils.c:simple_util_shutdown() {
	...
	for_each_prop_dai_cpu(props, i, dai) {
		struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, i);

		if (props->mclk_fs && !dai->clk_fixed && !snd_soc_dai_active(cpu_dai))
			snd_soc_dai_set_sysclk(cpu_dai, 0, 0, dai->clk_direction);
	...
}

If a device is configured with a non-zero system-clock-id, will the shutdown path disable the wrong clock, leaving the intended clock running?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author
#6 lore raw
In reply to Sen Wang
Quoted 3 lines · Sen Wang

Adding an optional, u32 system-clock-id DT property into the generic machine driver so clocking topology info can be exposed in DT.

Sorry folks, Sashiko has caught a major bug in my patch. No need to review this. Will send out a V3.

Best,
Sen Wang

#7 lore raw
In reply to Sen Wang

Hi,

Quoted 3 lines · On Fri, 15 May 2026 11:13:56 -0500 Sen Wang <[email protected]> wrote:

Adding an optional, u32 system-clock-id DT property into the generic machine driver so clocking topology info can be exposed in DT.

while having this binding would solve some of my problem. I am wondering whether is the right approach. What about modelling the clocks involved using the clk framework, so let some more codecs/dais be clock provider. So things can be configured that way.
E.g. tlv320aic32x4-clk.c

Same for set_div() which is also unavailable in these generic cards.

Regards,
Andreas

Quoted 12 lines

Sen Wang (2):
dt-bindings: sound: simple-card: add system-clock-id property
ASoC: simple-card-utils: support system-clock-id DT property

 Documentation/devicetree/bindings/sound/audio-graph-port.yaml |  2 +
 Documentation/devicetree/bindings/sound/simple-card.yaml      | 10 +++++++
 include/sound/simple_card_utils.h                              |  1 +
 sound/soc/generic/simple-card-utils.c                         | 13 +++++----
 4 files changed, 21 insertions(+), 5 deletions(-)

---
base-commit: f5ffe03e0678 (linux-next)

author
#8 lore raw
Quoted 8 lines · Andreas Kemnade

Hi,

Quoted 3 lines · On Fri, 15 May 2026 11:13:56 -0500 Sen Wang <[email protected]> wrote:

Adding an optional, u32 system-clock-id DT property into the generic machine driver so clocking topology info can be exposed in DT.

Quoted 8 lines

while having this binding would solve some of my problem. I am wondering whether is the right approach. What about modelling the clocks involved using the clk framework, so let some more codecs/dais be clock provider. So things can be configured that way.
E.g. tlv320aic32x4-clk.c

Same for set_div() which is also unavailable in these generic cards.

Hi Andreas, just got back from break, sorry for the delayed message.

I agree with you, in retrospect, this patch is indeed a hasty patch that only covers up the legacy clk-id scheme rather than adapting the modern clk framework.

Modeling individual cpu/codec DAI clocks does seem to be the way to go,
not the one patch fix-all solution I'd hope for, but I still wanted to see if I can reuse the existing CCF patterns for drivers with clk-id/div-id as an alternative.

Best,
Sen Wang