Skip to contentSkip to conversation

clk: keystone: syscon-clk: Enable audio reference clock

PATCH Applied Jai Luthra 2 participants 5 messages Jun 15, 2023 – Jun 16, 2023

Subsystems (3)
lore
Share & tools
lore

Jai Luthra

author
#0 lore raw

v3 cover clk: keystone: syscon-clk: Enable audio reference clock

TI's AM62 SoC can optionally provide two audio reference clocks (AUDIO_REFCLKx) to external peripherals. By default the reference clock is looped-back inside the SoC to a mux that goes to McASP AHCLK, but can optionally be enabled as an output to peripherals outside the SoC by setting a bit through CTRL_MMR registers.

This patch series extends the existing syscon-clk driver to support the audio reference clock, and also adds new device tree bindings documentation.

Please apply this on-top-of Andrew's series [1] removing the unnecessary dependency on syscon compatible.

[1]: https://lore.kernel.org/linux-clk/[email protected]/#t

---
Changes in v3:
- Add missing headers for kasprintf/kfree in [PATCH 2/2]
- Add Conor's R-by for [PATCH 1/2]
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Removed "syscon" compatible and rebased on top of [1]
- Moved reg above other properties in bindings yaml
- Link to v1: https://lore.kernel.org/r/[email protected]

Range diff from v2:
1: f1bb6a34efce ! 1: db84010f924d dt-bindings: clock: Add binding documentation for TI Audio REFCLK
@@ Commit message
Add DT bindings for TI's audio reference clocks (REFCLK) present on AM62 SoC.

+ Reviewed-by: Conor Dooley <[email protected]>

## Documentation/devicetree/bindings/clock/ti,am62-audio-refclk.yaml (new) ##
2: bb1b58178bbd ! 2: 06186242572b clk: keystone: syscon-clk: Add support for audio refclk
@@ Commit message

## drivers/clk/keystone/syscon-clk.c ##
+@@
+ */
+
+ #include <linux/clk-provider.h>
++#include <linux/kernel.h>
+ #include <linux/mfd/syscon.h>
+ #include <linux/module.h>
+ #include <linux/platform_device.h>
+ #include <linux/regmap.h>
++#include <linux/slab.h>
+
+ struct ti_syscon_gate_clk_priv {
+ struct clk_hw hw;
@@ drivers/clk/keystone/syscon-clk.c: static const struct clk_ops ti_syscon_gate_clk_ops = {

static struct clk_hw

---
Jai Luthra (2):
dt-bindings: clock: Add binding documentation for TI Audio REFCLK
clk: keystone: syscon-clk: Add support for audio refclk

 .../bindings/clock/ti,am62-audio-refclk.yaml       | 43 +++++++++++++++++++++
 drivers/clk/keystone/syscon-clk.c                  | 45 +++++++++++++++++++---
 2 files changed, 83 insertions(+), 5 deletions(-)

---
base-commit: f9547f8abff52dfb21985057f10744558a7e4cc8
change-id: 20230515-refclk-5b544d314c23

Best regards,

Signature · 7 lines
Jai Luthra <[email protected]>


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#1 lore raw

PATCH v3 1/2 dt-bindings: clock: Add binding documentation for TI Audio REFCLK

Add DT bindings for TI's audio reference clocks (REFCLK) present on AM62 SoC.

---
 .../bindings/clock/ti,am62-audio-refclk.yaml       | 43 ++++++++++++++++++++++
 1 file changed, 43 insertions(+)
Documentation/devicetree/bindings/clock/ti,am62-audio-refclk.yaml new file +43 -0
new file mode 100644
index 000000000000..b2e40bd39a3a
@@ -0,0 +1,43 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/ti,am62-audio-refclk.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TI Audio Reference Clock
+
+maintainers:
+  - Jai Luthra <[email protected]>
+
+properties:
+  compatible:
+    items:
+      - const: ti,am62-audio-refclk
+
+  reg:
+    maxItems: 1
+
+  "#clock-cells":
+    const: 0
+
+  clocks:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - "#clock-cells"
+  - clocks
+
+additionalProperties: false
+
+examples:
+  - |
+    audio_refclk0: clock@82e0 {
+        compatible = "ti,am62-audio-refclk";
+        reg = <0x82e0 0x4>;
+        clocks = <&k3_clks 157 0>;
+        assigned-clocks = <&k3_clks 157 0>;
+        assigned-clock-parents = <&k3_clks 157 8>;
+        #clock-cells = <0>;
+    };
Signature · 7 lines
2.41.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#3 lore raw

PATCH v3 2/2 clk: keystone: syscon-clk: Add support for audio refclk

In reply to Jai Luthra

TI's AM62 SoC can optionally provide two audio reference clocks (AUDIO_REFCLKx) to external peripherals.

By default this reference clock is looped-back inside the SoC to a mux that goes to McASP AHCLK, but can optionally be enabled as an output to peripherals outside the SoC by setting a bit through CTRL_MMR registers.

This bit only controls the direction of the clock, while the parent is a muxed input from sci-clk [1] which may be a configurable PLL or a master clock from one of the McASP instances.

---
 drivers/clk/keystone/syscon-clk.c | 45 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 40 insertions(+), 5 deletions(-)
drivers/clk/keystone/syscon-clk.c +40 -5
index bd5cec0bd12d..d33f74119488 100644
@@ -4,10 +4,12 @@
  */
 
 #include <linux/clk-provider.h>
+#include <linux/kernel.h>
 #include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
+#include <linux/slab.h>
 
 struct ti_syscon_gate_clk_priv {
 	struct clk_hw hw;
@@ -61,21 +63,31 @@ static const struct clk_ops ti_syscon_gate_clk_ops = {
 
 static struct clk_hw
 *ti_syscon_gate_clk_register(struct device *dev, struct regmap *regmap,
+			     const char *parent_name,
 			     const struct ti_syscon_gate_clk_data *data)
 {
 	struct ti_syscon_gate_clk_priv *priv;
 	struct clk_init_data init;
+	char *name = NULL;
 	int ret;
 
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		return ERR_PTR(-ENOMEM);
 
-	init.name = data->name;
 	init.ops = &ti_syscon_gate_clk_ops;
-	init.parent_names = NULL;
-	init.num_parents = 0;
-	init.flags = 0;
+	if (parent_name) {
+		name = kasprintf(GFP_KERNEL, "%s:%s", data->name, parent_name);
+		init.name = name;
+		init.parent_names = &parent_name;
+		init.num_parents = 1;
+		init.flags = CLK_SET_RATE_PARENT;
+	} else {
+		init.name = data->name;
+		init.parent_names = NULL;
+		init.num_parents = 0;
+		init.flags = 0;
+	}
 
 	priv->regmap = regmap;
 	priv->reg = data->offset;
@@ -83,6 +95,10 @@ static struct clk_hw
 	priv->hw.init = &init;
 
 	ret = devm_clk_hw_register(dev, &priv->hw);
+
+	if (name)
+		kfree(init.name);
+
 	if (ret)
 		return ERR_PTR(ret);
 
@@ -94,8 +110,9 @@ static int ti_syscon_gate_clk_probe(struct platform_device *pdev)
 	const struct ti_syscon_gate_clk_data *data, *p;
 	struct clk_hw_onecell_data *hw_data;
 	struct device *dev = &pdev->dev;
+	int num_clks, num_parents, i;
+	const char *parent_name;
 	struct regmap *regmap;
-	int num_clks, i;
 
 	data = device_get_match_data(dev);
 	if (!data)
@@ -110,6 +127,13 @@ static int ti_syscon_gate_clk_probe(struct platform_device *pdev)
 	for (p = data; p->name; p++)
 		num_clks++;
 
+	num_parents = of_clk_get_parent_count(dev->of_node);
+	if (of_device_is_compatible(dev->of_node, "ti,am62-audio-refclk") &&
+	    num_parents == 0) {
+		return dev_err_probe(dev, -EINVAL,
+				     "must specify a parent clock\n");
+	}
+
 	hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, num_clks),
 			       GFP_KERNEL);
 	if (!hw_data)
@@ -117,8 +141,10 @@ static int ti_syscon_gate_clk_probe(struct platform_device *pdev)
 
 	hw_data->num = num_clks;
 
+	parent_name = of_clk_get_parent_name(dev->of_node, 0);
 	for (i = 0; i < num_clks; i++) {
 		hw_data->hws[i] = ti_syscon_gate_clk_register(dev, regmap,
+							      parent_name,
 							      &data[i]);
 		if (IS_ERR(hw_data->hws[i]))
 			dev_warn(dev, "failed to register %s\n",
@@ -166,6 +192,11 @@ static const struct ti_syscon_gate_clk_data am62_clk_data[] = {
 	{ /* Sentinel */ },
 };
 
+static const struct ti_syscon_gate_clk_data am62_audio_clk_data[] = {
+	TI_SYSCON_CLK_GATE("audio_refclk", 0x0, 15),
+	{ /* Sentinel */ },
+};
+
 static const struct of_device_id ti_syscon_gate_clk_ids[] = {
 	{
 		.compatible = "ti,am654-ehrpwm-tbclk",
@@ -179,6 +210,10 @@ static const struct of_device_id ti_syscon_gate_clk_ids[] = {
 		.compatible = "ti,am62-epwm-tbclk",
 		.data = &am62_clk_data,
 	},
+	{
+		.compatible = "ti,am62-audio-refclk",
+		.data = &am62_audio_clk_data,
+	},
 	{ }
 };
 MODULE_DEVICE_TABLE(of, ti_syscon_gate_clk_ids);
Signature · 7 lines
2.41.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Applied
#4 lore raw

Re: [PATCH v3 2/2] clk: keystone: syscon-clk: Add support for audio refclk

Quoting Jai Luthra (2023-06-15 04:55:36)

Quoted 7 lines

TI's AM62 SoC can optionally provide two audio reference clocks (AUDIO_REFCLKx) to external peripherals.

By default this reference clock is looped-back inside the SoC to a mux that goes to McASP AHCLK, but can optionally be enabled as an output to peripherals outside the SoC by setting a bit through CTRL_MMR registers.

Quoted 7 lines

This bit only controls the direction of the clock, while the parent is a muxed input from sci-clk [1] which may be a configurable PLL or a master clock from one of the McASP instances.

---

Applied to clk-next