Skip to contentSkip to conversation

ti-cpufreq backport

PATCH In review Chen-Yu Tsai (Moxa) 3 participants 16 messages Sep 9, 2020

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

cover ti-cpufreq backport

Hi everyone,

This is the final part of MOXA's PM / OPP / ti-cpufreq backport series. Part 2, which consisted of OPP / cpufreq-dt cleanups, is abandoned in favor of directly backporting the ti-cpufreq driver.

This part includes a couple of patches to the PM / OPP subsystem to expose required APIs, and deal with the v1/v2 mixed OPP table used by am33xx. The rest are the backport of the ti-cpufreq driver, and fixes for this driver. The fixes were requested by CIP kernel maintainers as part of MOXA's previous attempt to backport ti-cpufreq. They are included as separate patches, as there are quite a few of them spread over multiple kernel releases.

The result is that my BeagleBone Black can run at higher speeds than without the ti-cpufreq driver due to having a better silicon revision.

Please have a look.

Regards
ChenYu

Christophe Jaillet (1):
cpufreq: ti: Fix 'of_node_put' being called twice in error handling
path

Dave Gerlach (6):
PM / OPP: Expose _of_get_opp_desc_node as dev_pm_opp API
Documentation: dt: add bindings for ti-cpufreq
cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime
cpufreq: dt: Don't use generic platdev driver for ti-cpufreq platforms
ARM: omap2plus_defconfig: Enable support for ti-cpufreq
ARM: dts: am33xx: Add updated operating-points-v2 table for cpu

Suman Anna (1):
cpufreq: ti-cpufreq: Fix an incorrect error return value

Viresh Kumar (1):
PM / OPP: Parse clock-latency and voltage-tolerance for v1 bindings

Zumeng Chen (2):
cpufreq: ti-cpufreq: kfree opp_data when failure
cpufreq: ti-cpufreq: add missing of_node_put()

 .../bindings/cpufreq/ti-cpufreq.txt           | 128 ++++++++
 arch/arm/boot/dts/am33xx.dtsi                 |  87 +++++-
 arch/arm/configs/omap2plus_defconfig          |   1 +
 arch/arm/mach-omap2/pm.c                      |   3 +
 drivers/base/power/opp/core.c                 |  25 +-
 drivers/base/power/opp/cpu.c                  |   4 +-
 drivers/base/power/opp/opp.h                  |   6 +
 drivers/cpufreq/Kconfig.arm                   |  11 +
 drivers/cpufreq/Makefile                      |   1 +
 drivers/cpufreq/ti-cpufreq.c                  | 276 ++++++++++++++++++
 include/linux/pm_opp.h                        |   6 +
 11 files changed, 531 insertions(+), 17 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/cpufreq/ti-cpufreq.txt
 create mode 100644 drivers/cpufreq/ti-cpufreq.c
Signature · 1 line
2.28.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5422): https://lists.cip-project.org/g/cip-dev/message/5422
Mute This Topic: https://lists.cip-project.org/mt/76726426/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#1 lore raw

PATCH 1/11 PM / OPP: Parse clock-latency and voltage-tolerance for v1 bindings

From: Viresh Kumar <[email protected]>

V2 bindings have better support for clock-latency and voltage-tolerance and doesn't need special care. To use callbacks, like dev_pm_opp_get_max_{transition|volt}_latency(), irrespective of the bindings, the core needs to know clock-latency/voltage-tolerance for the earlier bindings.

This patch reads clock-latency/voltage-tolerance from the device node, irrespective of the bindings (to keep it simple) and use them only for V1 bindings.

---

This patch is needed because the OPPv2 table does not include clock-latency-ns properties, but instead uses the clock-latency property from OPPv1.

---
 drivers/base/power/opp/core.c | 20 ++++++++++++++++++++
 drivers/base/power/opp/opp.h  |  6 ++++++
 2 files changed, 26 insertions(+)
drivers/base/power/opp/core.c +20 -0
index 1e0a2ddf73323..f983d5d30fa94 100644
@@ -505,6 +505,7 @@ static struct device_opp *_add_device_opp(struct device *dev)
 {
 	struct device_opp *dev_opp;
 	struct device_list_opp *list_dev;
+	struct device_node *np;
 
 	/* Check for existing list for 'dev' first */
 	dev_opp = _find_device_opp(dev);
@@ -527,6 +528,21 @@ static struct device_opp *_add_device_opp(struct device *dev)
 		return NULL;
 	}
 
+	/*
+	 * Only required for backward compatibility with v1 bindings, but isn't
+	 * harmful for other cases. And so we do it unconditionally.
+	 */
+	np = of_node_get(dev->of_node);
+	if (np) {
+		u32 val;
+
+		if (!of_property_read_u32(np, "clock-latency", &val))
+			dev_opp->clock_latency_ns_max = val;
+		of_property_read_u32(np, "voltage-tolerance",
+				     &dev_opp->voltage_tolerance_v1);
+		of_node_put(np);
+	}
+
 	srcu_init_notifier_head(&dev_opp->srcu_head);
 	INIT_LIST_HEAD(&dev_opp->opp_list);
 
@@ -759,6 +775,7 @@ static int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt,
 {
 	struct device_opp *dev_opp;
 	struct dev_pm_opp *new_opp;
+	unsigned long tol;
 	int ret;
 
 	/* Hold our list modification lock here */
@@ -772,7 +789,10 @@ static int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt,
 
 	/* populate the opp table */
 	new_opp->rate = freq;
+	tol = u_volt * dev_opp->voltage_tolerance_v1 / 100;
 	new_opp->u_volt = u_volt;
+	new_opp->u_volt_min = u_volt - tol;
+	new_opp->u_volt_max = u_volt + tol;
 	new_opp->available = true;
 	new_opp->dynamic = dynamic;
 
drivers/base/power/opp/opp.h +6 -0
index 690638ef36ee5..7f0d7c8bfef00 100644
@@ -135,6 +135,8 @@ struct device_list_opp {
  * @dentry:	debugfs dentry pointer of the real device directory (not links).
  * @dentry_name: Name of the real dentry.
  *
+ * @voltage_tolerance_v1: In percentage, for v1 bindings only.
+ *
  * This is an internal data structure maintaining the link to opps attached to
  * a device. This structure is not meant to be shared to users as it is
  * meant for book keeping and private to OPP library.
@@ -153,6 +155,10 @@ struct device_opp {
 
 	struct device_node *np;
 	unsigned long clock_latency_ns_max;
+
+	/* For backward compatibility with v1 bindings */
+	unsigned int voltage_tolerance_v1;
+
 	bool shared_opp;
 	struct dev_pm_opp *suspend_opp;
 
Signature · 1 line
2.28.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5423): https://lists.cip-project.org/g/cip-dev/message/5423
Mute This Topic: https://lists.cip-project.org/mt/76726427/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw

PATCH 2/11 PM / OPP: Expose _of_get_opp_desc_node as dev_pm_opp API

In reply to Chen-Yu Tsai (Moxa)

From: Dave Gerlach <[email protected]>

commit 0764c604c8128f17fd740ff8b1701d0a1301eb7e upstream.

Rename _of_get_opp_desc_node to dev_pm_opp_of_get_opp_desc_node and add it to include/linux/pm_opp.h to allow other drivers, such as platform OPP and cpufreq drivers, to make use of it.

---
 drivers/base/power/opp/core.c | 5 +++--
 drivers/base/power/opp/cpu.c  | 4 ++--
 include/linux/pm_opp.h        | 6 ++++++
 3 files changed, 11 insertions(+), 4 deletions(-)
drivers/base/power/opp/core.c +3 -2
index f983d5d30fa94..c41bf5f1a038d 100644
@@ -1488,7 +1488,7 @@ unlock:
 EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table);
 
 /* Returns opp descriptor node for a device, caller must do of_node_put() */
-struct device_node *_of_get_opp_desc_node(struct device *dev)
+struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
 {
 	/*
 	 * TODO: Support for multiple OPP tables.
@@ -1499,6 +1499,7 @@ struct device_node *_of_get_opp_desc_node(struct device *dev)
 
 	return of_parse_phandle(dev->of_node, "operating-points-v2", 0);
 }
+EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node);
 
 /* Initializes OPP tables based on new bindings */
 static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np)
@@ -1627,7 +1628,7 @@ int dev_pm_opp_of_add_table(struct device *dev)
 	 * OPPs have two version of bindings now. The older one is deprecated,
 	 * try for the new binding first.
 	 */
-	opp_np = _of_get_opp_desc_node(dev);
+	opp_np = dev_pm_opp_of_get_opp_desc_node(dev);
 	if (!opp_np) {
 		/*
 		 * Try old-deprecated bindings for backward compatibility with
drivers/base/power/opp/cpu.c +2 -2
index a0db8b3575f38..29c5b42eff346 100644
@@ -227,7 +227,7 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask
 	int cpu, ret = 0;
 
 	/* Get OPP descriptor node */
-	np = _of_get_opp_desc_node(cpu_dev);
+	np = dev_pm_opp_of_get_opp_desc_node(cpu_dev);
 	if (!np) {
 		dev_dbg(cpu_dev, "%s: Couldn't find cpu_dev node.\n", __func__);
 		return -ENOENT;
@@ -252,7 +252,7 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask
 		}
 
 		/* Get OPP descriptor node */
-		tmp_np = _of_get_opp_desc_node(tcpu_dev);
+		tmp_np = dev_pm_opp_of_get_opp_desc_node(tcpu_dev);
 		if (!tmp_np) {
 			dev_err(tcpu_dev, "%s: Couldn't find tcpu_dev node.\n",
 				__func__);
include/linux/pm_opp.h +6 -0
index 95403d2ccaf56..4a8f5b33d7023 100644
@@ -160,6 +160,7 @@ int dev_pm_opp_of_cpumask_add_table(cpumask_var_t cpumask);
 void dev_pm_opp_of_cpumask_remove_table(cpumask_var_t cpumask);
 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask);
 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask);
+struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
 #else
 static inline int dev_pm_opp_of_add_table(struct device *dev)
 {
@@ -188,6 +189,11 @@ static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_va
 {
 	return -ENOSYS;
 }
+
+static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
+{
+	return NULL;
+}
 #endif
 
 #endif		/* __LINUX_OPP_H__ */
Signature · 1 line
2.28.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5420): https://lists.cip-project.org/g/cip-dev/message/5420
Mute This Topic: https://lists.cip-project.org/mt/76726424/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#3 lore raw

PATCH 3/11 Documentation: dt: add bindings for ti-cpufreq

In reply to Chen-Yu Tsai (Moxa)

From: Dave Gerlach <[email protected]>

commit 953a0f18337406ab041252ce5a62db5d173bee5f upstream.

Add the device tree bindings document for the TI CPUFreq/OPP driver on AM33xx, AM43xx, DRA7xx, and AM57xx SoCs. The operating-points-v2 binding allows us to provide an opp-supported-hw property for each OPP to define when it is available. This driver is responsible for reading and parsing registers to determine which OPPs can be selectively enabled based on the specific SoC in use by matching against the opp-supported-hw data.

---
 .../bindings/cpufreq/ti-cpufreq.txt           | 128 ++++++++++++++++++
 1 file changed, 128 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/cpufreq/ti-cpufreq.txt
Documentation/devicetree/bindings/cpufreq/ti-cpufreq.txt new file +128 -0
new file mode 100644
index 0000000000000..ba0e15ad5bd9d
@@ -0,0 +1,128 @@
+TI CPUFreq and OPP bindings
+================================
+
+Certain TI SoCs, like those in the am335x, am437x, am57xx, and dra7xx
+families support different OPPs depending on the silicon variant in use.
+The ti-cpufreq driver can use revision and an efuse value from the SoC to
+provide the OPP framework with supported hardware information. This is
+used to determine which OPPs from the operating-points-v2 table get enabled
+when it is parsed by the OPP framework.
+
+Required properties:
+--------------------
+In 'cpus' nodes:
+- operating-points-v2: Phandle to the operating-points-v2 table to use.
+
+In 'operating-points-v2' table:
+- compatible: Should be
+	- 'operating-points-v2-ti-cpu' for am335x, am43xx, and dra7xx/am57xx SoCs
+- syscon: A phandle pointing to a syscon node representing the control module
+	  register space of the SoC.
+
+Optional properties:
+--------------------
+For each opp entry in 'operating-points-v2' table:
+- opp-supported-hw: Two bitfields indicating:
+	1. Which revision of the SoC the OPP is supported by
+	2. Which eFuse bits indicate this OPP is available
+
+	A bitwise AND is performed against these values and if any bit
+	matches, the OPP gets enabled.
+
+Example:
+--------
+
+/* From arch/arm/boot/dts/am33xx.dtsi */
+cpus {
+	#address-cells = <1>;
+	#size-cells = <0>;
+	cpu@0 {
+		compatible = "arm,cortex-a8";
+		device_type = "cpu";
+		reg = <0>;
+
+		operating-points-v2 = <&cpu0_opp_table>;
+
+		clocks = <&dpll_mpu_ck>;
+		clock-names = "cpu";
+
+		clock-latency = <300000>; /* From omap-cpufreq driver */
+	};
+};
+
+/*
+ * cpu0 has different OPPs depending on SoC revision and some on revisions
+ * 0x2 and 0x4 have eFuse bits that indicate if they are available or not
+ */
+cpu0_opp_table: opp-table {
+	compatible = "operating-points-v2-ti-cpu";
+	syscon = <&scm_conf>;
+
+	/*
+	 * The three following nodes are marked with opp-suspend
+	 * because they can not be enabled simultaneously on a
+	 * single SoC.
+	 */
+	opp50@300000000 {
+		opp-hz = /bits/ 64 <300000000>;
+		opp-microvolt = <950000 931000 969000>;
+		opp-supported-hw = <0x06 0x0010>;
+		opp-suspend;
+	};
+
+	opp100@275000000 {
+		opp-hz = /bits/ 64 <275000000>;
+		opp-microvolt = <1100000 1078000 1122000>;
+		opp-supported-hw = <0x01 0x00FF>;
+		opp-suspend;
+	};
+
+	opp100@300000000 {
+		opp-hz = /bits/ 64 <300000000>;
+		opp-microvolt = <1100000 1078000 1122000>;
+		opp-supported-hw = <0x06 0x0020>;
+		opp-suspend;
+	};
+
+	opp100@500000000 {
+		opp-hz = /bits/ 64 <500000000>;
+		opp-microvolt = <1100000 1078000 1122000>;
+		opp-supported-hw = <0x01 0xFFFF>;
+	};
+
+	opp100@600000000 {
+		opp-hz = /bits/ 64 <600000000>;
+		opp-microvolt = <1100000 1078000 1122000>;
+		opp-supported-hw = <0x06 0x0040>;
+	};
+
+	opp120@600000000 {
+		opp-hz = /bits/ 64 <600000000>;
+		opp-microvolt = <1200000 1176000 1224000>;
+		opp-supported-hw = <0x01 0xFFFF>;
+	};
+
+	opp120@720000000 {
+		opp-hz = /bits/ 64 <720000000>;
+		opp-microvolt = <1200000 1176000 1224000>;
+		opp-supported-hw = <0x06 0x0080>;
+	};
+
+	oppturbo@720000000 {
+		opp-hz = /bits/ 64 <720000000>;
+		opp-microvolt = <1260000 1234800 1285200>;
+		opp-supported-hw = <0x01 0xFFFF>;
+	};
+
+	oppturbo@800000000 {
+		opp-hz = /bits/ 64 <800000000>;
+		opp-microvolt = <1260000 1234800 1285200>;
+		opp-supported-hw = <0x06 0x0100>;
+	};
+
+	oppnitro@1000000000 {
+		opp-hz = /bits/ 64 <1000000000>;
+		opp-microvolt = <1325000 1298500 1351500>;
+		opp-supported-hw = <0x04 0x0200>;
+	};
+};
Signature · 1 line
2.28.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5419): https://lists.cip-project.org/g/cip-dev/message/5419
Mute This Topic: https://lists.cip-project.org/mt/76726423/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#4 lore raw

PATCH 4/11 cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime

In reply to Chen-Yu Tsai (Moxa)

From: Dave Gerlach <[email protected]>

commit e13cf046cd70894393a1085ca39da7ef751353fb upstream.

Some TI SoCs, like those in the AM335x, AM437x, DRA7x, and AM57x families, have different OPPs available for the MPU depending on which specific variant of the SoC is in use. This can be determined through use of the revision and an eFuse register present in the silicon. Introduce a ti-cpufreq driver that can read the aformentioned values and provide them as version matching data to the opp framework. Through this the opp-supported-hw dt binding that is part of the operating-points-v2 table can be used to indicate availability of OPPs for each device.

This driver also creates the "cpufreq-dt" platform_device after passing the version matching data to the OPP framework so that the cpufreq-dt handles the actual cpufreq implementation. Even without the necessary data to pass the version matching data the driver will still create this device to maintain backwards compatibility with operating-points v1 tables.

---
 drivers/cpufreq/Kconfig.arm  |  11 ++
 drivers/cpufreq/Makefile     |   1 +
 drivers/cpufreq/ti-cpufreq.c | 272 +++++++++++++++++++++++++++++++++++
 3 files changed, 284 insertions(+)
 create mode 100644 drivers/cpufreq/ti-cpufreq.c
drivers/cpufreq/Kconfig.arm +11 -0
index eed1e073d96d7..6b834112d857b 100644
@@ -231,6 +231,17 @@ config ARM_TEGRA124_CPUFREQ
 	help
 	  This adds the CPUFreq driver support for Tegra124 SOCs.
 
+config ARM_TI_CPUFREQ
+	bool "Texas Instruments CPUFreq support"
+	depends on ARCH_OMAP2PLUS
+	help
+	  This driver enables valid OPPs on the running platform based on
+	  values contained within the SoC in use. Enable this in order to
+	  use the cpufreq-dt driver on all Texas Instruments platforms that
+	  provide dt based operating-points-v2 tables with opp-supported-hw
+	  data provided. Required for cpufreq support on AM335x, AM437x,
+	  DRA7x, and AM57x platforms.
+
 config ARM_PXA2xx_CPUFREQ
 	tristate "Intel PXA2xx CPUfreq driver"
 	depends on PXA27x || PXA25x
drivers/cpufreq/Makefile +1 -0
index c0af1a1281c89..6e889596d9a12 100644
@@ -75,6 +75,7 @@ obj-$(CONFIG_ARM_SCPI_CPUFREQ)		+= scpi-cpufreq.o
 obj-$(CONFIG_ARM_SPEAR_CPUFREQ)		+= spear-cpufreq.o
 obj-$(CONFIG_ARM_TEGRA20_CPUFREQ)	+= tegra20-cpufreq.o
 obj-$(CONFIG_ARM_TEGRA124_CPUFREQ)	+= tegra124-cpufreq.o
+obj-$(CONFIG_ARM_TI_CPUFREQ)		+= ti-cpufreq.o
 obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ)	+= vexpress-spc-cpufreq.o
 obj-$(CONFIG_ACPI_CPPC_CPUFREQ) += cppc_cpufreq.o
 
drivers/cpufreq/ti-cpufreq.c new file +272 -0

272 lines not on this page · raw message

Signature · 1 line
2.28.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5421): https://lists.cip-project.org/g/cip-dev/message/5421
Mute This Topic: https://lists.cip-project.org/mt/76726425/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#5 lore raw

Re: [cip-dev] [PATCH 4.4.y-cip 04/11] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime

Hi!

drivers/cpufreq/ti-cpufreq.c line 87

Quoted 12 lines
drivers/cpufreq/ti-cpufreq.c new file +12 -0
+	/*
+	 * The efuse on dra7 and am57 parts contains a specific
+	 * value indicating the highest available OPP.
+	 */
+
+	switch (efuse) {
+	case DRA7_EFUSE_HAS_ALL_MPU_OPP:
+	case DRA7_EFUSE_HAS_HIGH_MPU_OPP:
+		calculated_efuse |= DRA7_EFUSE_HIGH_MPU_OPP;
+	case DRA7_EFUSE_HAS_OD_MPU_OPP:
+		calculated_efuse |= DRA7_EFUSE_OD_MPU_OPP;
+	}

Some kind of fallthrough marking would not be bad.

drivers/cpufreq/ti-cpufreq.c line 256

Quoted 13 lines
drivers/cpufreq/ti-cpufreq.c new file +13 -0
+	ret = ti_cpufreq_get_efuse(opp_data, &version[1]);
+	if (ret)
+		goto fail_put_node;
+
+	of_node_put(opp_data->opp_node);
+
+	ret = PTR_ERR_OR_ZERO(dev_pm_opp_set_supported_hw(opp_data->cpu_dev,
+							  version, VERSION_COUNT));
+	if (ret) {
+		dev_err(opp_data->cpu_dev,
+			"Failed to set supported hardware\n");
+		goto fail_put_node;
+	}

of_node_put() is done twice in the last error path.

Best regards,
Pavel

Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5433): https://lists.cip-project.org/g/cip-dev/message/5433
Mute This Topic: https://lists.cip-project.org/mt/76726425/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#6 lore raw

Re: [cip-dev] [PATCH 4.4.y-cip 04/11] cpufreq: ti: Add cpufreq driver to determine available OPPs at runtime

Hi!

Quoted 7 lines
Quoted 7 lines
drivers/cpufreq/ti-cpufreq.c new file +7 -0
+	ret = ti_cpufreq_get_efuse(opp_data, &version[1]);
+	if (ret)
+		goto fail_put_node;
+
+	of_node_put(opp_data->opp_node);
+
+	ret = PTR_ERR_OR_ZERO(dev_pm_opp_set_supported_hw(opp_data->cpu_dev,
Quoted 8 lines

drivers/cpufreq/ti-cpufreq.c line 256

Quoted 6 lines
drivers/cpufreq/ti-cpufreq.c new file +6 -0
+							  version, VERSION_COUNT));
+	if (ret) {
+		dev_err(opp_data->cpu_dev,
+			"Failed to set supported hardware\n");
+		goto fail_put_node;
+	}

of_node_put() is done twice in the last error path.

Aha, it is fixed in subsequent patches. Sorry for the noise.

Best regards,
Pavel

Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5435): https://lists.cip-project.org/g/cip-dev/message/5435
Mute This Topic: https://lists.cip-project.org/mt/76726425/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#7 lore raw

PATCH 5/11 cpufreq: ti: Fix 'of_node_put' being called twice in error handling path

In reply to Chen-Yu Tsai (Moxa)

From: Christophe Jaillet <[email protected]>

commit 9a6e91d08e7707baa2f824257342ca7efcb199bc upstream.

If 'dev_pm_opp_set_supported_hw()' fails, 'opp_data->opp_node' refcount will be decremented 2 times.
One, just a few lines above, and another one in the error handling path.

Fix it by simply moving the 'of_node_put' call of the normal path.

---
 drivers/cpufreq/ti-cpufreq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpufreq/ti-cpufreq.c +2 -2
index 7ff7ae3c3911c..1c63e96cba1f2 100644
@@ -245,8 +245,6 @@ static int ti_cpufreq_init(void)
 	if (ret)
 		goto fail_put_node;
 
-	of_node_put(opp_data->opp_node);
-
 	ret = PTR_ERR_OR_ZERO(dev_pm_opp_set_supported_hw(opp_data->cpu_dev,
 							  version, VERSION_COUNT));
 	if (ret) {
@@ -255,6 +253,8 @@ static int ti_cpufreq_init(void)
 		goto fail_put_node;
 	}
 
+	of_node_put(opp_data->opp_node);
+
 register_cpufreq_dt:
 	platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
 
Signature · 1 line
2.28.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5427): https://lists.cip-project.org/g/cip-dev/message/5427
Mute This Topic: https://lists.cip-project.org/mt/76726431/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#8 lore raw

PATCH 6/11 cpufreq: ti-cpufreq: kfree opp_data when failure

In reply to Chen-Yu Tsai (Moxa)

From: Zumeng Chen <[email protected]>

commit 05829d9431df1bf6de98679fbcfbad282c1c55a4 upstream.

memory leakage was found by kmemleak. opp_data needs to be freed when failure, including fail_put_node.

unreferenced object 0xccdd4c40 (size 64):
comm "swapper", pid 1, jiffies 4294938465 (age 888.520s) hex dump (first 32 bytes):

    00 7c 00 c1 98 69 d8 ce 00 24 03 ce 00 24 03 ce  .|...i...$...$..
    20 35 23 c1 00 00 00 00 00 00 00 00 00 00 00 00   5#.............
  backtrace:
    [<c028fb64>] kmem_cache_alloc_trace+0x2c4/0x3cc
    [<c076d5f0>] ti_cpufreq_probe+0x6c/0x334
    [<c068d6e4>] platform_drv_probe+0x60/0xc0
    [<c068b384>] driver_probe_device+0x218/0x2c4
    [<c068b5a4>] __device_attach_driver+0xa8/0xdc
    [<c0689340>] bus_for_each_drv+0x70/0xa4
    [<c068b020>] __device_attach+0xc0/0x124
    [<c068b634>] device_initial_probe+0x1c/0x20
    [<c068a3b8>] bus_probe_device+0x94/0x9c
    [<c0688300>] device_add+0x404/0x590
    [<c068d408>] platform_device_add+0x11c/0x230
    [<c068df40>] platform_device_register_full+0x10c/0x128
    [<c076d578>] ti_cpufreq_init+0x44/0x50
    [<c01017c4>] do_one_initcall+0x54/0x180
    [<c0e00fe0>] kernel_init_freeable+0x270/0x33c
    [<c093f2bc>] kernel_init+0x18/0x124
---
 drivers/cpufreq/ti-cpufreq.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/cpufreq/ti-cpufreq.c +4 -1
index 1c63e96cba1f2..36627b2b256f8 100644
@@ -217,7 +217,8 @@ static int ti_cpufreq_init(void)
 	opp_data->cpu_dev = get_cpu_device(0);
 	if (!opp_data->cpu_dev) {
 		pr_err("%s: Failed to get device for CPU0\n", __func__);
-		return -ENODEV;
+		ret = ENODEV;
+		goto free_opp_data;
 	}
 
 	opp_data->opp_node = dev_pm_opp_of_get_opp_desc_node(opp_data->cpu_dev);
@@ -262,6 +263,8 @@ register_cpufreq_dt:
 
 fail_put_node:
 	of_node_put(opp_data->opp_node);
+free_opp_data:
+	kfree(opp_data);
 
 	return ret;
 }
Signature · 1 line
2.28.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5430): https://lists.cip-project.org/g/cip-dev/message/5430
Mute This Topic: https://lists.cip-project.org/mt/76726434/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#9 lore raw

PATCH 7/11 cpufreq: ti-cpufreq: add missing of_node_put()

In reply to Chen-Yu Tsai (Moxa)

From: Zumeng Chen <[email protected]>

commit 248aefdcc3a7e0cfbd014946b4dead63e750e71b upstream.

call of_node_put to release the refcount of np.

---
 drivers/cpufreq/ti-cpufreq.c | 1 +
 1 file changed, 1 insertion(+)
drivers/cpufreq/ti-cpufreq.c +1 -0
index 36627b2b256f8..afbe9db29992d 100644
@@ -205,6 +205,7 @@ static int ti_cpufreq_init(void)
 
 	np = of_find_node_by_path("/");
 	match = of_match_node(ti_cpufreq_of_match, np);
+	of_node_put(np);
 	if (!match)
 		return -ENODEV;
 
Signature · 1 line
2.28.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5424): https://lists.cip-project.org/g/cip-dev/message/5424
Mute This Topic: https://lists.cip-project.org/mt/76726428/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#10 lore raw

PATCH 8/11 cpufreq: ti-cpufreq: Fix an incorrect error return value

In reply to Chen-Yu Tsai (Moxa)

From: Suman Anna <[email protected]>

commit e5d295b06d69a1924665a16a4987be475addd00f upstream.

Commit 05829d9431df ("cpufreq: ti-cpufreq: kfree opp_data when failure") has fixed a memory leak in the failure path, however the patch returned a positive value on get_cpu_device() failure instead of the previous negative value. Fix this incorrect error return value properly.

Fixes 05829d9431df ("cpufreq: ti-cpufreq: kfree opp_data when failure")
Cc 4.14+ <[email protected]> # v4.14+
[[email protected]: Fix commit reference format in commit log]
---
 drivers/cpufreq/ti-cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/ti-cpufreq.c +1 -1
index afbe9db29992d..59777685114d9 100644
@@ -218,7 +218,7 @@ static int ti_cpufreq_init(void)
 	opp_data->cpu_dev = get_cpu_device(0);
 	if (!opp_data->cpu_dev) {
 		pr_err("%s: Failed to get device for CPU0\n", __func__);
-		ret = ENODEV;
+		ret = -ENODEV;
 		goto free_opp_data;
 	}
 
Signature · 1 line
2.28.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5426): https://lists.cip-project.org/g/cip-dev/message/5426
Mute This Topic: https://lists.cip-project.org/mt/76726430/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#11 lore raw

PATCH 9/11 cpufreq: dt: Don't use generic platdev driver for ti-cpufreq platforms

In reply to Chen-Yu Tsai (Moxa)

From: Dave Gerlach <[email protected]>

commit 051bd84bb45bc994b7d762467f60b3bd0c7aa6bc upstream.

Some TI platforms, specifically those in the am33xx, am43xx, dra7xx, and am57xx families of SoCs can make use of the ti-cpufreq driver to selectively enable OPPs based on the exact configuration in use. The ti-cpufreq is given the responsibility of creating the cpufreq-dt platform device when the driver is in use so drop am33xx and dra7xx from the cpufreq-dt-platdev driver so it is not created twice.

---

I kept the original patch subject to make it easier for scripts to match against upstream patches.

---
 arch/arm/mach-omap2/pm.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-omap2/pm.c +3 -0
index 3d876bde8c859..88cb34c608ab8 100644
@@ -281,6 +281,9 @@ static inline void omap_init_cpufreq(void)
 
 	if (!of_have_populated_dt())
 		devinfo.name = "omap-cpufreq";
+	else if (of_machine_is_compatible("ti,am33xx") ||
+		 of_machine_is_compatible("ti,dra7"))
+		return;
 	else
 		devinfo.name = "cpufreq-dt";
 	platform_device_register_full(&devinfo);
Signature · 1 line
2.28.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5428): https://lists.cip-project.org/g/cip-dev/message/5428
Mute This Topic: https://lists.cip-project.org/mt/76726432/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#12 lore raw

PATCH 10/11 ARM: omap2plus_defconfig: Enable support for ti-cpufreq

In reply to Chen-Yu Tsai (Moxa)

From: Dave Gerlach <[email protected]>

commit 69c8ab148006a2ec7ac1a1f08945e95febc1c132 upstream.

AM335x, AM437x, DRA7xx, and AM57xx platforms all now depend on ti-cpufreq driver to enable proper OPPs for use with cpufreq, so enable the same.

---
 arch/arm/configs/omap2plus_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/omap2plus_defconfig +1 -0
index 09ebd37e01e02..c6eec207dcbd8 100644
@@ -69,6 +69,7 @@ CONFIG_CPU_FREQ_GOV_POWERSAVE=y
 CONFIG_CPU_FREQ_GOV_USERSPACE=y
 CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
 CONFIG_CPUFREQ_DT=y
+CONFIG_ARM_TI_CPUFREQ=y
 # CONFIG_ARM_OMAP2PLUS_CPUFREQ is not set
 CONFIG_CPU_IDLE=y
 CONFIG_BINFMT_MISC=y
Signature · 1 line
2.28.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5429): https://lists.cip-project.org/g/cip-dev/message/5429
Mute This Topic: https://lists.cip-project.org/mt/76726433/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#13 lore raw

PATCH 11/11 ARM: dts: am33xx: Add updated operating-points-v2 table for cpu

In reply to Chen-Yu Tsai (Moxa)

From: Dave Gerlach <[email protected]>

commit 72ac40fcb164a3d8fbd1ff13647abe67df26ced5 upstream.

After the ti-cpufreq driver has been added, we can now drop the operating-points table present in am33xx.dtsi for the cpu and add an operating-points-v2 table with all OPPs available for all silicon revisions. Also add necessary data for use by ti-cpufreq to selectively enable the appropriate OPPs at runtime as part of the operating-points table.

Information from AM335x Data Manual, SPRS717i, Revised December 2015, Table 5-7.

---
 arch/arm/boot/dts/am33xx.dtsi | 87 +++++++++++++++++++++++++++++------
 1 file changed, 74 insertions(+), 13 deletions(-)
arch/arm/boot/dts/am33xx.dtsi +74 -13
index 4b40e6d401a03..c256718d75801 100644
@@ -45,19 +45,7 @@
 			device_type = "cpu";
 			reg = <0>;
 
-			/*
-			 * To consider voltage drop between PMIC and SoC,
-			 * tolerance value is reduced to 2% from 4% and
-			 * voltage value is increased as a precaution.
-			 */
-			operating-points = <
-				/* kHz    uV */
-				720000  1285000
-				600000  1225000
-				500000  1125000
-				275000  1125000
-			>;
-			voltage-tolerance = <2>; /* 2 percentage */
+			operating-points-v2 = <&cpu0_opp_table>;
 
 			clocks = <&dpll_mpu_ck>;
 			clock-names = "cpu";
@@ -66,6 +54,79 @@
 		};
 	};
 
+	cpu0_opp_table: opp-table {
+		compatible = "operating-points-v2-ti-cpu";
+		syscon = <&scm_conf>;
+
+		/*
+		 * The three following nodes are marked with opp-suspend
+		 * because the can not be enabled simultaneously on a
+		 * single SoC.
+		 */
+		opp50@300000000 {
+			opp-hz = /bits/ 64 <300000000>;
+			opp-microvolt = <950000 931000 969000>;
+			opp-supported-hw = <0x06 0x0010>;
+			opp-suspend;
+		};
+
+		opp100@275000000 {
+			opp-hz = /bits/ 64 <275000000>;
+			opp-microvolt = <1100000 1078000 1122000>;
+			opp-supported-hw = <0x01 0x00FF>;
+			opp-suspend;
+		};
+
+		opp100@300000000 {
+			opp-hz = /bits/ 64 <300000000>;
+			opp-microvolt = <1100000 1078000 1122000>;
+			opp-supported-hw = <0x06 0x0020>;
+			opp-suspend;
+		};
+
+		opp100@500000000 {
+			opp-hz = /bits/ 64 <500000000>;
+			opp-microvolt = <1100000 1078000 1122000>;
+			opp-supported-hw = <0x01 0xFFFF>;
+		};
+
+		opp100@600000000 {
+			opp-hz = /bits/ 64 <600000000>;
+			opp-microvolt = <1100000 1078000 1122000>;
+			opp-supported-hw = <0x06 0x0040>;
+		};
+
+		opp120@600000000 {
+			opp-hz = /bits/ 64 <600000000>;
+			opp-microvolt = <1200000 1176000 1224000>;
+			opp-supported-hw = <0x01 0xFFFF>;
+		};
+
+		opp120@720000000 {
+			opp-hz = /bits/ 64 <720000000>;
+			opp-microvolt = <1200000 1176000 1224000>;
+			opp-supported-hw = <0x06 0x0080>;
+		};
+
+		oppturbo@720000000 {
+			opp-hz = /bits/ 64 <720000000>;
+			opp-microvolt = <1260000 1234800 1285200>;
+			opp-supported-hw = <0x01 0xFFFF>;
+		};
+
+		oppturbo@800000000 {
+			opp-hz = /bits/ 64 <800000000>;
+			opp-microvolt = <1260000 1234800 1285200>;
+			opp-supported-hw = <0x06 0x0100>;
+		};
+
+		oppnitro@1000000000 {
+			opp-hz = /bits/ 64 <1000000000>;
+			opp-microvolt = <1325000 1298500 1351500>;
+			opp-supported-hw = <0x04 0x0200>;
+		};
+	};
+
 	pmu {
 		compatible = "arm,cortex-a8-pmu";
 		interrupts = <3>;
Signature · 1 line
2.28.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5425): https://lists.cip-project.org/g/cip-dev/message/5425
Mute This Topic: https://lists.cip-project.org/mt/76726429/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#14 lore raw
In reply to Chen-Yu Tsai (Moxa)

Hi!

Quoted 12 lines

This is the final part of MOXA's PM / OPP / ti-cpufreq backport series. Part 2, which consisted of OPP / cpufreq-dt cleanups, is abandoned in favor of directly backporting the ti-cpufreq driver.

This part includes a couple of patches to the PM / OPP subsystem to expose required APIs, and deal with the v1/v2 mixed OPP table used by am33xx. The rest are the backport of the ti-cpufreq driver, and fixes for this driver. The fixes were requested by CIP kernel maintainers as part of MOXA's previous attempt to backport ti-cpufreq. They are included as separate patches, as there are quite a few of them spread over multiple kernel releases.

Quoted 3 lines

The result is that my BeagleBone Black can run at higher speeds than without the ti-cpufreq driver due to having a better silicon revision.

The series looks good to me. I can apply it if it passes testing and there are no other comments.

Best regards,
Pavel

Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5436): https://lists.cip-project.org/g/cip-dev/message/5436
Mute This Topic: https://lists.cip-project.org/mt/76726426/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#15 lore raw

Hi,

Quoted 22 lines

-----Original Message-----
From: Pavel Machek [mailto:[email protected]]
Sent: Wednesday, September 9, 2020 4:04 PM
To: Chen-Yu Tsai (Moxa) <[email protected]>
Cc: iwamatsu nobuhiro(岩松 信洋 □SWC◯ACT) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 4.4.y-cip 00/11] ti-cpufreq backport

Hi!

Quoted 12 lines

This is the final part of MOXA's PM / OPP / ti-cpufreq backport series. Part 2, which consisted of OPP / cpufreq-dt cleanups, is abandoned in favor of directly backporting the ti-cpufreq driver.

This part includes a couple of patches to the PM / OPP subsystem to expose required APIs, and deal with the v1/v2 mixed OPP table used by am33xx. The rest are the backport of the ti-cpufreq driver, and fixes for this driver. The fixes were requested by CIP kernel maintainers as part of MOXA's previous attempt to backport ti-cpufreq. They are included as separate patches, as there are quite a few of them spread over multiple kernel releases.

Quoted 6 lines
Quoted 3 lines

The result is that my BeagleBone Black can run at higher speeds than without the ti-cpufreq driver due to having a better silicon revision.

The series looks good to me. I can apply it if it passes testing and there are no other comments.

This patch series looks good to me too.
So, I applied and pushed.

Quoted 3 lines

Best regards,
Pavel

Best regards,
Nobuhiro

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5438): https://lists.cip-project.org/g/cip-dev/message/5438
Mute This Topic: https://lists.cip-project.org/mt/76726426/4520388
Group Owner: [email protected]
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-