Skip to contentSkip to conversation

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

PATCH Superseded Akashdeep Kaur 2 participants 9 messages Mar 30 – Apr 1

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

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.

---

Akashdeep Kaur (5):
cpufreq: ti: Add EPROBE_DEFER for K3 SoCs
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
cpufreq: ti: Add device link to k3-socinfo

 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          | 57 +++++++++++++++++++++++++++
 4 files changed, 60 insertions(+)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/5 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 2/5 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
#3 lore raw

PATCH 3/5 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
#5 lore raw

PATCH 4/5 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
#6 lore raw

PATCH 5/5 cpufreq: ti: Add device link to k3-socinfo

In reply to Akashdeep Kaur

Create explicit device link when OPP table has ti,soc-info property. Prevents unbinding k3-socinfo while ti-cpufreq is using it.

---
 drivers/cpufreq/ti-cpufreq.c | 48 ++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
drivers/cpufreq/ti-cpufreq.c +48 -0
index 88f7912ef6a8..60c34b0da0c5 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,14 @@ 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);
+
+	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 +663,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
#4 lore raw

Re: [PATCH 3/5] arm64: dts: ti: k3-am62a7: Add ti,soc-info to OPP table

In reply to Akashdeep Kaur
Quoted 12 lines · 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 +0 -0
index b6e5eee99370..6d1459e9ea71 100644

arch/arm64/boot/dts/ti/k3-am62a7.dtsi a53_opp_table: opp-table { · line 112

Quoted 4 lines
arch/arm64/boot/dts/ti/k3-am62a7.dtsi +1 -0
@@ -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>;

You should have tested this before sending. It obviously fails checks.

Best regards,
Krzysztof

#7 lore raw

Re: [PATCH 5/5] cpufreq: ti: Add device link to k3-socinfo

In reply to Akashdeep Kaur
Quoted 4 lines · Akashdeep Kaur
drivers/cpufreq/ti-cpufreq.c +0 -0
 	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)

drivers/cpufreq/ti-cpufreq.c static int ti_cpufreq_probe(struct platform_device *pdev) · line 573

Quoted 10 lines
drivers/cpufreq/ti-cpufreq.c +8 -0
 		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);

Undocumented ABI.

Best regards,
Krzysztof

#8 lore raw

Re: [PATCH 5/5] cpufreq: ti: Add device link to k3-socinfo

Hi Krzysztof,

Quoted 7 lines · Krzysztof Kozlowski
Quoted 6 lines · Akashdeep Kaur
  	opp_data->cpu_dev = get_cpu_device(0);
  	if (!opp_data->cpu_dev) {
drivers/cpufreq/ti-cpufreq.c +0 -0
@@ -560,6 +563,42 @@ static int ti_cpufreq_probe(struct platform_device *pdev)
  	if (ret)
  		goto fail_put_node;
 
Quoted 10 lines

drivers/cpufreq/ti-cpufreq.c static int ti_cpufreq_probe(struct platform_device *pdev) · line 573

Quoted 8 lines
drivers/cpufreq/ti-cpufreq.c +8 -0
+	/* 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);

Undocumented ABI.

Added missing patch in next version, thanks for pointing this out.

Regards,
Akashdeep Kaur

Quoted 3 lines

Best regards,
Krzysztof