Skip to contentSkip to conversation

cpufreq: ti: Fix probe ordering and add device link support for K3 SoCs

PATCH Superseded Akashdeep Kaur 2 participants 8 messages Apr 1 – Apr 2

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover cpufreq: ti: Fix probe ordering and add device link support for K3 SoCs

For K3 SoCs, ti-cpufreq depends on k3-socinfo to provide SoC revision information via soc_device_match(). If ti-cpufreq probes before k3-socinfo, soc_device_match() returns NULL, causing incorrect revision detection and OPP table initialization failures.

Add EPROBE_DEFER handling in ti-cpufreq when soc_device_match() fails for K3 SoCs, ensuring k3-socinfo probes first.

Add device link support via a new DT property "ti,soc-info" in CPU OPP tables. Device links prevent unbinding k3-socinfo while ti-cpufreq is using it.

EPROBE_DEFER handles first-boot probe ordering, while device links provide runtime dependency management.

For backward compatibility, the DT property is optional.

Changes in v2
- Added DT bindings documentation for ti,soc-info property
- Reordered patches: bindings first, then driver changes, then DTS
- Link to v1: https://lore.kernel.org/all/[email protected]/

Testing
- Verified correct probe ordering on AM625, AM62A7, AM62P5 platforms

---

Akashdeep Kaur (6):
cpufreq: ti: Add EPROBE_DEFER for K3 SoCs
dt-bindings: opp: ti-cpu: Add ti,soc-info property
cpufreq: ti: Add device link to k3-socinfo
arm64: dts: ti: k3-am625: Add ti,soc-info to OPP table
arm64: dts: ti: k3-am62a7: Add ti,soc-info to OPP table
arm64: dts: ti: k3-am62p5: Add ti,soc-info to OPP table

 .../opp/operating-points-v2-ti-cpu.yaml       | 11 ++++
 arch/arm64/boot/dts/ti/k3-am625.dtsi          |  1 +
 arch/arm64/boot/dts/ti/k3-am62a7.dtsi         |  1 +
 arch/arm64/boot/dts/ti/k3-am62p5.dtsi         |  1 +
 drivers/cpufreq/ti-cpufreq.c                  | 61 +++++++++++++++++++
 5 files changed, 75 insertions(+)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/6 cpufreq: ti: Add EPROBE_DEFER for K3 SoCs

Defer probe when k3-socinfo hasn't registered the SoC device yet. Fixes incorrect revision detection when ti-cpufreq probes first.

---
 drivers/cpufreq/ti-cpufreq.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/cpufreq/ti-cpufreq.c +9 -0
index 3d1129aeed02..88f7912ef6a8 100644
@@ -441,6 +441,15 @@ static int ti_cpufreq_get_rev(struct ti_cpufreq_data *opp_data,
 		 */
 		*revision_value = 0x1;
 		goto done;
+	} else if (opp_data->soc_data == &am625_soc_data ||
+		   opp_data->soc_data == &am62a7_soc_data ||
+		   opp_data->soc_data == &am62l3_soc_data ||
+		   opp_data->soc_data == &am62p5_soc_data) {
+		/*
+		 * For K3 SoCs, if soc_device_match fails, socinfo hasn't
+		 * probed yet. Defer probe to wait for it.
+		 */
+		return -EPROBE_DEFER;
 	}
 
 	ret = regmap_read(opp_data->syscon, opp_data->soc_data->rev_offset,
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/6 dt-bindings: opp: ti-cpu: Add ti,soc-info property

In reply to Akashdeep Kaur

Add ti,soc-info property to allow OPP tables to reference the SoC info device (chipid) for establishing device link dependencies.

This is used on K3 SoCs (AM625, AM62A7, AM62L3, AM62P5) to ensure proper probe ordering between ti-cpufreq and k3-socinfo drivers. The ti-cpufreq driver depends on k3-socinfo registering the SoC device for revision detection via soc_device_match().

The device link also prevents unbinding k3-socinfo while ti-cpufreq is using it, maintaining system stability.

---
 .../bindings/opp/operating-points-v2-ti-cpu.yaml      | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/devicetree/bindings/opp/operating-points-v2-ti-cpu.yaml +11 -0
index 624d1f3f1382..f318494d5295 100644
@@ -34,6 +34,16 @@ properties:
       points to syscon node representing the control module
       register space of the SoC.
 
+  ti,soc-info:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: |
+      Optional phandle to the SoC info device (chipid). Used on K3 SoCs
+      to establish device link dependencies ensuring proper probe ordering
+      (ti-cpufreq after k3-socinfo) and preventing unbinding of k3-socinfo
+      while the OPP table is in use. This is needed because ti-cpufreq uses
+      soc_device_match() to detect SoC revision information provided by
+      k3-socinfo.
+
   opp-shared: true
 
 patternProperties:
@@ -82,6 +92,7 @@ examples:
     opp-table {
         compatible = "operating-points-v2-ti-cpu";
         syscon = <&scm_conf>;
+        ti,soc-info = <&chipid>;
 
         opp-300000000 {
             opp-hz = /bits/ 64 <300000000>;
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v2 2/6] dt-bindings: opp: ti-cpu: Add ti,soc-info property

Quoted 5 lines · Akashdeep Kaur

Add ti,soc-info property to allow OPP tables to reference the SoC info device (chipid) for establishing device link dependencies.

This is used on K3 SoCs (AM625, AM62A7, AM62L3, AM62P5) to ensure proper probe ordering between ti-cpufreq and k3-socinfo drivers. The ti-cpufreq

Nope, sorry, DT purpose is not to perform probe ordering.

If I change Linux to load k3-socinfo before ti-cpufreq, then the binding becomes invalid?

Not a DT property, drop.

Best regards,
Krzysztof

#4 lore raw

PATCH v2 3/6 cpufreq: ti: Add device link to k3-socinfo

In reply to Akashdeep Kaur

Create explicit device link from CPU device to k3-socinfo when the OPP table specifies ti,soc-info property. This prevents unbinding k3-socinfo while ti-cpufreq is using it for SoC revision detection. This complements the EPROBE_DEFER handling that ensures initial probe ordering.

---
 drivers/cpufreq/ti-cpufreq.c | 52 ++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
drivers/cpufreq/ti-cpufreq.c +52 -0
index 88f7912ef6a8..7bd45b367b36 100644
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/of.h>
+#include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/pm_opp.h>
 #include <linux/regmap.h>
@@ -111,6 +112,7 @@ struct ti_cpufreq_data {
 	struct device_node *opp_node;
 	struct regmap *syscon;
 	const struct ti_cpufreq_soc_data *soc_data;
+	struct device_link *soc_link;
 };
 
 static unsigned long amx3_efuse_xlate(struct ti_cpufreq_data *opp_data,
@@ -542,6 +544,7 @@ static int ti_cpufreq_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	opp_data->soc_data = match->data;
+	platform_set_drvdata(pdev, opp_data);
 
 	opp_data->cpu_dev = get_cpu_device(0);
 	if (!opp_data->cpu_dev) {
@@ -560,6 +563,42 @@ static int ti_cpufreq_probe(struct platform_device *pdev)
 	if (ret)
 		goto fail_put_node;
 
+	/* Create device link to k3-socinfo if specified in DT */
+	if (opp_data->soc_data == &am625_soc_data ||
+	    opp_data->soc_data == &am62a7_soc_data ||
+	    opp_data->soc_data == &am62l3_soc_data ||
+	    opp_data->soc_data == &am62p5_soc_data) {
+		struct device_node *socinfo_np;
+
+		socinfo_np = of_parse_phandle(opp_data->opp_node, "ti,soc-info", 0);
+		if (socinfo_np) {
+			struct platform_device *socinfo_pdev;
+			struct device_link *link;
+
+			socinfo_pdev = of_find_device_by_node(socinfo_np);
+			of_node_put(socinfo_np);
+
+			if (!socinfo_pdev) {
+				ret = -EPROBE_DEFER;
+				goto fail_put_node;
+			}
+
+			if (!socinfo_pdev->dev.driver) {
+				put_device(&socinfo_pdev->dev);
+				ret = -EPROBE_DEFER;
+				goto fail_put_node;
+			}
+
+			link = device_link_add(opp_data->cpu_dev,
+					       &socinfo_pdev->dev,
+					       DL_FLAG_STATELESS);
+			if (link)
+				opp_data->soc_link = link;
+
+			put_device(&socinfo_pdev->dev);
+		}
+	}
+
 	/*
 	 * OPPs determine whether or not they are supported based on
 	 * two metrics:
@@ -600,6 +639,18 @@ static int ti_cpufreq_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static void ti_cpufreq_remove(struct platform_device *pdev)
+{
+	struct ti_cpufreq_data *opp_data = platform_get_drvdata(pdev);
+
+	/*
+	 * Device link is automatically removed with DL_FLAG_AUTOREMOVE_CONSUMER,
+	 * but explicitly delete it for safety.
+	 */
+	if (opp_data && opp_data->soc_link)
+		device_link_del(opp_data->soc_link);
+}
+
 static int __init ti_cpufreq_init(void)
 {
 	const struct of_device_id *match;
@@ -616,6 +667,7 @@ module_init(ti_cpufreq_init);
 
 static struct platform_driver ti_cpufreq_driver = {
 	.probe = ti_cpufreq_probe,
+	.remove = ti_cpufreq_remove,
 	.driver = {
 		.name = "ti-cpufreq",
 	},
Signature · 1 line
2.34.1
#5 lore raw

PATCH v2 4/6 arm64: dts: ti: k3-am625: Add ti,soc-info to OPP table

In reply to Akashdeep Kaur

Link CPU OPP table to k3-socinfo driver for dependency tracking.

---
 arch/arm64/boot/dts/ti/k3-am625.dtsi | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/ti/k3-am625.dtsi +1 -0
index c249883a8a8d..b0020e667882 100644
@@ -109,6 +109,7 @@ a53_opp_table: opp-table {
 		compatible = "operating-points-v2-ti-cpu";
 		opp-shared;
 		syscon = <&opp_efuse_table>;
+		ti,soc-info = <&chipid>;
 
 		opp-200000000 {
 			opp-hz = /bits/ 64 <200000000>;
Signature · 1 line
2.34.1
#6 lore raw

PATCH v2 5/6 arm64: dts: ti: k3-am62a7: Add ti,soc-info to OPP table

In reply to Akashdeep Kaur

Link CPU OPP table to k3-socinfo driver for dependency tracking.

---
 arch/arm64/boot/dts/ti/k3-am62a7.dtsi | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/ti/k3-am62a7.dtsi +1 -0
index b6e5eee99370..6d1459e9ea71 100644
@@ -109,6 +109,7 @@ a53_opp_table: opp-table {
 		compatible = "operating-points-v2-ti-cpu";
 		opp-shared;
 		syscon = <&opp_efuse_table>;
+		ti,soc-info = <&chipid>;
 
 		opp-200000000 {
 			opp-hz = /bits/ 64 <200000000>;
Signature · 1 line
2.34.1
#7 lore raw

PATCH v2 6/6 arm64: dts: ti: k3-am62p5: Add ti,soc-info to OPP table

In reply to Akashdeep Kaur

Link CPU OPP table to k3-socinfo driver for dependency tracking.

---
 arch/arm64/boot/dts/ti/k3-am62p5.dtsi | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/ti/k3-am62p5.dtsi +1 -0
index 8982a7b9f1a6..1a498c5eb3d1 100644
@@ -108,6 +108,7 @@ a53_opp_table: opp-table {
 		compatible = "operating-points-v2-ti-cpu";
 		opp-shared;
 		syscon = <&opp_efuse_table>;
+		ti,soc-info = <&chipid>;
 
 		opp-200000000 {
 			opp-hz = /bits/ 64 <200000000>;
Signature · 1 line
2.34.1