Skip to contentSkip to conversation

Add cpufreq driver for Tegra194

PATCH Superseded Sumit Gupta 4 participants 10 messages Jun 26, 2020 – Jul 13, 2020

Subsystems (3)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add cpufreq driver for Tegra194

The patch series adds cpufreq driver for Tegra194 SOC. Incorporated the feedback on previous version patchset. Please consider this patch series for merging in 5.9.

v3[3] -> v4
- Open code LOOP_FOR_EACH_CPU_OF_CLUSTER macro[Viresh]
- Delete unused funciton map_freq_to_ndiv[Viresh, kernel test bot]
- Remove flush_workqueue from free_resources[Viresh]

v2[2] -> v3
- Set same policy for all cpus in a cluster[Viresh].
- Add compatible string for CPU Complex under cpus node[Thierry].
- Add reference to bpmp node under cpus node[Thierry].
- Bind cpufreq driver to CPU Complex compatible string[Thierry].
- Remove patch to get bpmp data as now using cpus node to get that[Thierry].

v1[1] -> v2:
- Remove cpufreq_lock mutex from tegra194_cpufreq_set_target [Viresh].
- Remove CPUFREQ_ASYNC_NOTIFICATION flag [Viresh].
- Remove redundant _begin|end() call from tegra194_cpufreq_set_target.
- Rename opp_table to freq_table [Viresh].

Sumit Gupta (4):
dt-bindings: arm: Add t194 ccplex compatible and bpmp property
arm64: tegra: Add t194 ccplex compatible and bpmp property
cpufreq: Add Tegra194 cpufreq driver
arm64: defconfig: Enable CONFIG_ARM_TEGRA194_CPUFREQ

 Documentation/devicetree/bindings/arm/cpus.yaml |   9 +
 arch/arm64/boot/dts/nvidia/tegra194.dtsi        |   2 +
 arch/arm64/configs/defconfig                    |   1 +
 drivers/cpufreq/Kconfig.arm                     |   6 +
 drivers/cpufreq/Makefile                        |   1 +
 drivers/cpufreq/tegra194-cpufreq.c              | 396 ++++++++++++++++++++++++
 6 files changed, 415 insertions(+)
 create mode 100644 drivers/cpufreq/tegra194-cpufreq.c

[1] https://marc.info/?t=157539452300001&r=1&w=2
[2] https://marc.info/?l=linux-tegra&m=158602857106213&w=2
[3] https://marc.info/?l=linux-pm&m=159283376010084&w=2

Signature · 1 line
2.7.4
#1 lore raw

PATCH v4 1/4 dt-bindings: arm: Add t194 ccplex compatible and bpmp property

To do frequency scaling on all CPUs within T194 CPU Complex, we need to query BPMP for data on valid operating points. Document a compatible string under 'cpus' node to represent the CPU Complex for binding drivers like cpufreq which don't have their node or CPU Complex node to bind to. Also, document a property to point to the BPMP device that can be queried for all CPUs.

---
 Documentation/devicetree/bindings/arm/cpus.yaml | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/arm/cpus.yaml +9 -0
index a018147..737b55e 100644
@@ -162,6 +162,7 @@ properties:
       - nvidia,tegra132-denver
       - nvidia,tegra186-denver
       - nvidia,tegra194-carmel
+      - nvidia,tegra194-ccplex
       - qcom,krait
       - qcom,kryo
       - qcom,kryo260
@@ -255,6 +256,14 @@ properties:
 
       where voltage is in V, frequency is in MHz.
 
+  nvidia,bpmp:
+    $ref: '/schemas/types.yaml#/definitions/phandle'
+    descrption: |
+      Specifies the bpmp node that needs to be queried to get
+      operating point data for all CPUs.
+
+      Optional for NVIDIA Tegra194 Carmel CPUs
+
   power-domains:
     $ref: '/schemas/types.yaml#/definitions/phandle-array'
     description:
Signature · 1 line
2.7.4
#2 lore raw

Re: [TEGRA194_CPUFREQ PATCH v4 1/4] dt-bindings: arm: Add t194 ccplex compatible and bpmp property

Quoted 25 lines · Sumit Gupta

To do frequency scaling on all CPUs within T194 CPU Complex, we need to query BPMP for data on valid operating points. Document a compatible string under 'cpus' node to represent the CPU Complex for binding drivers like cpufreq which don't have their node or CPU Complex node to bind to. Also, document a property to point to the BPMP device that can be queried for all CPUs.

---
 Documentation/devicetree/bindings/arm/cpus.yaml | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/arm/cpus.yaml +1 -0
index a018147..737b55e 100644
@@ -162,6 +162,7 @@ properties:
       - nvidia,tegra132-denver
       - nvidia,tegra186-denver
       - nvidia,tegra194-carmel
+      - nvidia,tegra194-ccplex
       - qcom,krait
       - qcom,kryo
       - qcom,kryo260

Documentation/devicetree/bindings/arm/cpus.yaml properties: · line 265

Quoted 10 lines
Documentation/devicetree/bindings/arm/cpus.yaml +7 -0
@@ -255,6 +256,14 @@ properties:
 
       where voltage is in V, frequency is in MHz.
 
+  nvidia,bpmp:
+    $ref: '/schemas/types.yaml#/definitions/phandle'
+    descrption: |
+      Specifies the bpmp node that needs to be queried to get
+      operating point data for all CPUs.
+
+      Optional for NVIDIA Tegra194 Carmel CPUs

Hi,

The code (next patches) suggests, that the property is relevant for Tegra194 only. If it is required for compatible=tegra194-ccplex, then maybe you can mark it so (there is already similar constraint described in the file, just before the example section).

Best Regards,
Michał Mirosław

maintainer
#3 lore raw

Re: [TEGRA194_CPUFREQ PATCH v4 1/4] dt-bindings: arm: Add t194 ccplex compatible and bpmp property

In reply to Sumit Gupta
Quoted 7 lines · Sumit Gupta

To do frequency scaling on all CPUs within T194 CPU Complex, we need to query BPMP for data on valid operating points. Document a compatible string under 'cpus' node to represent the CPU Complex for binding drivers like cpufreq which don't have their node or CPU Complex node to bind to. Also, document a property to point to the BPMP device that can be queried for all CPUs.

Quoted 5 lines
---
 Documentation/devicetree/bindings/arm/cpus.yaml | 9 +++++++++
 1 file changed, 9 insertions(+)

My bot found errors running 'make dt_binding_check' on your patch:

/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/arm/cpus.yaml: properties:nvidia,bpmp: Additional properties are not allowed ('descrption' was unexpected)
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/arm/cpus.yaml: properties:nvidia,bpmp: 'descrption' is not one of ['$ref', 'additionalItems', 'additionalProperties', 'allOf', 'anyOf', 'const', 'contains', 'default', 'dependencies', 'deprecated', 'description', 'else', 'enum', 'exclusiveMaximum', 'exclusiveMinimum', 'items', 'if', 'minItems', 'minimum', 'maxItems', 'maximum', 'multipleOf', 'not', 'oneOf', 'pattern', 'patternProperties', 'properties', 'required', 'then', 'type', 'typeSize', 'unevaluatedProperties', 'uniqueItems'] /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/arm/cpus.yaml: properties:nvidia,bpmp: {'$ref': '/schemas/types.yaml#/definitions/phandle', 'descrption': 'Specifies the bpmp node that needs to be queried to get\noperating point data for all CPUs.\n\nOptional for NVIDIA Tegra194 Carmel CPUs\n'} is not valid under any of the given schemas (Possible causes of the failure):
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/arm/cpus.yaml: properties:nvidia,bpmp: 'description' is a required property

Documentation/devicetree/bindings/Makefile:20: recipe for target 'Documentation/devicetree/bindings/arm/cpus.example.dts' failed make[1]: *** [Documentation/devicetree/bindings/arm/cpus.example.dts] Error 1
make[1]: *** Waiting for unfinished jobs....
Makefile:1347: recipe for target 'dt_binding_check' failed
make: *** [dt_binding_check] Error 2

See https://patchwork.ozlabs.org/patch/1317775

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure dt-schema is up to date:

pip3 install git+https://github.com/devicetree-org/dt-schema.git@master --upgrade

Please check and re-submit.

#4 lore raw

PATCH v4 2/4 arm64: tegra: Add t194 ccplex compatible and bpmp property

In reply to Sumit Gupta

On Tegra194, data on valid operating points for the CPUs needs to be queried from BPMP. In T194, there is no node representing CPU complex. So, add compatible string to the 'cpus' node instead of using dummy node to bind cpufreq driver. Also, add reference to the BPMP instance for the CPU complex.

---
 arch/arm64/boot/dts/nvidia/tegra194.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/nvidia/tegra194.dtsi +2 -0
index 7c9511a..0abf287 100644
@@ -1764,6 +1764,8 @@
 	};
 
 	cpus {
+		compatible = "nvidia,tegra194-ccplex";
+		nvidia,bpmp = <&bpmp>;
 		#address-cells = <1>;
 		#size-cells = <0>;
 
Signature · 1 line
2.7.4
#5 lore raw

PATCH v4 3/4 cpufreq: Add Tegra194 cpufreq driver

In reply to Sumit Gupta

Add support for CPU frequency scaling on Tegra194. The frequency of each core can be adjusted by writing a clock divisor value to a MSR on the core. The range of valid divisors is queried from the BPMP.

---
 drivers/cpufreq/Kconfig.arm        |   6 +
 drivers/cpufreq/Makefile           |   1 +
 drivers/cpufreq/tegra194-cpufreq.c | 396 +++++++++++++++++++++++++++++++++++++
 3 files changed, 403 insertions(+)
 create mode 100644 drivers/cpufreq/tegra194-cpufreq.c
drivers/cpufreq/Kconfig.arm +6 -0
index 15c1a12..f3d8f09 100644
@@ -314,6 +314,12 @@ config ARM_TEGRA186_CPUFREQ
 	help
 	  This adds the CPUFreq driver support for Tegra186 SOCs.
 
+config ARM_TEGRA194_CPUFREQ
+	tristate "Tegra194 CPUFreq support"
+	depends on ARCH_TEGRA && TEGRA_BPMP
+	help
+	  This adds CPU frequency driver support for Tegra194 SOCs.
+
 config ARM_TI_CPUFREQ
 	bool "Texas Instruments CPUFreq support"
 	depends on ARCH_OMAP2PLUS
drivers/cpufreq/Makefile +1 -0
index f6670c4..66b5563 100644
@@ -83,6 +83,7 @@ obj-$(CONFIG_ARM_TANGO_CPUFREQ)		+= tango-cpufreq.o
 obj-$(CONFIG_ARM_TEGRA20_CPUFREQ)	+= tegra20-cpufreq.o
 obj-$(CONFIG_ARM_TEGRA124_CPUFREQ)	+= tegra124-cpufreq.o
 obj-$(CONFIG_ARM_TEGRA186_CPUFREQ)	+= tegra186-cpufreq.o
+obj-$(CONFIG_ARM_TEGRA194_CPUFREQ)	+= tegra194-cpufreq.o
 obj-$(CONFIG_ARM_TI_CPUFREQ)		+= ti-cpufreq.o
 obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ)	+= vexpress-spc-cpufreq.o
 
drivers/cpufreq/tegra194-cpufreq.c new file +396 -0

396 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#6 lore raw

Re: [TEGRA194_CPUFREQ PATCH v4 3/4] cpufreq: Add Tegra194 cpufreq driver

Quoted 17 lines · Sumit Gupta
drivers/cpufreq/tegra194-cpufreq.c new file +17 -0
+static int tegra194_cpufreq_probe(struct platform_device *pdev)
+{
+	struct tegra194_cpufreq_data *data;
+	struct tegra_bpmp *bpmp;
+	int err, i;
+
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->num_clusters = MAX_CLUSTERS;
+	data->tables = devm_kcalloc(&pdev->dev, data->num_clusters,
+				    sizeof(*data->tables), GFP_KERNEL);
+	if (!data->tables)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, data);

drivers/cpufreq/tegra194-cpufreq.c line 342

Quoted 10 lines
drivers/cpufreq/tegra194-cpufreq.c new file +10 -0
+
+	bpmp = tegra_bpmp_get(&pdev->dev);
+	if (IS_ERR(bpmp))
+		return PTR_ERR(bpmp);
+
+	read_counters_wq = alloc_workqueue("read_counters_wq", __WQ_LEGACY, 1);
+	if (!read_counters_wq) {
+		dev_err(&pdev->dev, "fail to create_workqueue\n");
+		err = -EINVAL;
+		goto put_bpmp;

This will call destroy_workqueue() eventually and it will crash your kernel.

Apart from this, this stuff looks okay. Don't resend the patch just yet (and if required, send only this patch using --in-reply-to flag for git send email). Lets wait for an Ack from Rob for the first two patches.

Quoted 2 lines
(quoted diff) +2 -0
+	}
+
Signature · 1 line
viresh
#7 lore raw

Re: [TEGRA194_CPUFREQ PATCH v4 3/4] cpufreq: Add Tegra194 cpufreq driver

Quoted 35 lines · Sumit Gupta
Quoted 17 lines
drivers/cpufreq/tegra194-cpufreq.c new file +17 -0
+static int tegra194_cpufreq_probe(struct platform_device *pdev)
+{
+     struct tegra194_cpufreq_data *data;
+     struct tegra_bpmp *bpmp;
+     int err, i;
+
+     data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+     if (!data)
+             return -ENOMEM;
+
+     data->num_clusters = MAX_CLUSTERS;
+     data->tables = devm_kcalloc(&pdev->dev, data->num_clusters,
+                                 sizeof(*data->tables), GFP_KERNEL);
+     if (!data->tables)
+             return -ENOMEM;
+
+     platform_set_drvdata(pdev, data);

drivers/cpufreq/tegra194-cpufreq.c line 342

Quoted 10 lines
drivers/cpufreq/tegra194-cpufreq.c new file +10 -0
+
+     bpmp = tegra_bpmp_get(&pdev->dev);
+     if (IS_ERR(bpmp))
+             return PTR_ERR(bpmp);
+
+     read_counters_wq = alloc_workqueue("read_counters_wq", __WQ_LEGACY, 1);
+     if (!read_counters_wq) {
+             dev_err(&pdev->dev, "fail to create_workqueue\n");
+             err = -EINVAL;
+             goto put_bpmp;

This will call destroy_workqueue() eventually and it will crash your kernel.

Quoted 5 lines

Apart from this, this stuff looks okay. Don't resend the patch just yet (and if required, send only this patch using --in-reply-to flag for git send email). Lets wait for an Ack from Rob for the first two patches.

Sorry for the delayed response as i was on PTO.
Thank you for the feedback.

Have posted a v5 based on v4 patch set.

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+     }
+

--
viresh

#8 lore raw

PATCH v4 4/4 arm64: defconfig: Enable CONFIG_ARM_TEGRA194_CPUFREQ

In reply to Sumit Gupta

Enable Tegra194 CPU frequency scaling support by default.

---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index f9d378d..385bd35 100644
@@ -91,6 +91,7 @@ CONFIG_ARM_QCOM_CPUFREQ_NVMEM=y
 CONFIG_ARM_QCOM_CPUFREQ_HW=y
 CONFIG_ARM_RASPBERRYPI_CPUFREQ=m
 CONFIG_ARM_TEGRA186_CPUFREQ=y
+CONFIG_ARM_TEGRA194_CPUFREQ=y
 CONFIG_QORIQ_CPUFREQ=y
 CONFIG_ARM_SCPI_PROTOCOL=y
 CONFIG_RASPBERRYPI_FIRMWARE=y
Signature · 1 line
2.7.4
maintainer
#9 lore raw

Re: [TEGRA194_CPUFREQ PATCH v4 4/4] arm64: defconfig: Enable CONFIG_ARM_TEGRA194_CPUFREQ

Quoted 12 lines · Sumit Gupta

Enable Tegra194 CPU frequency scaling support by default.

---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +0 -0
index f9d378d..385bd35 100644

arch/arm64/configs/defconfig CONFIG_ARM_QCOM_CPUFREQ_NVMEM=y · line 97

Quoted 7 lines
arch/arm64/configs/defconfig +1 -0
@@ -91,6 +91,7 @@ CONFIG_ARM_QCOM_CPUFREQ_NVMEM=y
 CONFIG_ARM_QCOM_CPUFREQ_HW=y
 CONFIG_ARM_RASPBERRYPI_CPUFREQ=m
 CONFIG_ARM_TEGRA186_CPUFREQ=y
+CONFIG_ARM_TEGRA194_CPUFREQ=y
 CONFIG_QORIQ_CPUFREQ=y
 CONFIG_ARM_SCPI_PROTOCOL=y
 CONFIG_RASPBERRYPI_FIRMWARE=y

Instead of this, maybe you can rather add a default y thing in the Kconfig itself as this is a single platform driver.

Signature · 1 line
viresh