Skip to contentSkip to conversation

cpufreq: mediatek-hw: Add support for Mediatek cpufreq HW driver

PATCH Superseded Hector Yuan 2 participants 5 messages Sep 9, 2020 – Sep 10, 2020

Subsystems (3)

v6 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 cpufreq: mediatek-hw: Add support for Mediatek cpufreq HW driver

The CPUfreq HW present in some Mediatek chipsets offloads the steps necessary for changing the frequency of CPUs. The driver implements the cpufreq driver interface for this hardware engine.

This patch depends on the MT6779 DTS patch submitted by Hanks Chen
https://lkml.org/lkml/2020/8/4/1094

Hector.Yuan (2):
cpufreq: mediatek-hw: Add support for Mediatek cpufreq HW driver
dt-bindings: cpufreq: add bindings for MediaTek cpufreq HW

 .../bindings/cpufreq/cpufreq-mediatek-hw.yaml      |  141 ++++++++++
 drivers/cpufreq/Kconfig.arm                        |   12 +
 drivers/cpufreq/Makefile                           |    1 +
 drivers/cpufreq/mediatek-cpufreq-hw.c              |  283 ++++++++++++++++++++
 4 files changed, 437 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/cpufreq/cpufreq-mediatek-hw.yaml
 create mode 100644 drivers/cpufreq/mediatek-cpufreq-hw.c

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#1 lore raw

PATCH v6 1/2 cpufreq: mediatek-hw: Add support for Mediatek cpufreq HW driver

From: "Hector.Yuan" <[email protected]>

Add MT6779 cpufreq HW support.

---
 drivers/cpufreq/Kconfig.arm           |   12 ++
 drivers/cpufreq/Makefile              |    1 +
 drivers/cpufreq/mediatek-cpufreq-hw.c |  283 +++++++++++++++++++++++++++++++++
 3 files changed, 296 insertions(+)
 create mode 100644 drivers/cpufreq/mediatek-cpufreq-hw.c
drivers/cpufreq/Kconfig.arm +12 -0
index c6cbfc8..8e58c12 100644
@@ -121,6 +121,18 @@ config ARM_MEDIATEK_CPUFREQ
 	help
 	  This adds the CPUFreq driver support for MediaTek SoCs.
 
+config ARM_MEDIATEK_CPUFREQ_HW
+	tristate "MediaTek CPUFreq HW driver"
+	depends on ARCH_MEDIATEK || COMPILE_TEST
+	default m
+	help
+	  Support for the CPUFreq HW driver.
+	  Some MediaTek chipsets have a HW engine to offload the steps
+	  necessary for changing the frequency of the CPUs. Firmware loaded
+	  in this engine exposes a programming interface to the OS.
+	  The driver implements the cpufreq interface for this HW engine.
+	  Say Y if you want to support CPUFreq HW.
+
 config ARM_OMAP2PLUS_CPUFREQ
 	bool "TI OMAP2+"
 	depends on ARCH_OMAP2PLUS
drivers/cpufreq/Makefile +1 -0
index f6670c4..dc1f371 100644
@@ -57,6 +57,7 @@ obj-$(CONFIG_ARM_IMX6Q_CPUFREQ)		+= imx6q-cpufreq.o
 obj-$(CONFIG_ARM_IMX_CPUFREQ_DT)	+= imx-cpufreq-dt.o
 obj-$(CONFIG_ARM_KIRKWOOD_CPUFREQ)	+= kirkwood-cpufreq.o
 obj-$(CONFIG_ARM_MEDIATEK_CPUFREQ)	+= mediatek-cpufreq.o
+obj-$(CONFIG_ARM_MEDIATEK_CPUFREQ_HW)	+= mediatek-cpufreq-hw.o
 obj-$(CONFIG_MACH_MVEBU_V7)		+= mvebu-cpufreq.o
 obj-$(CONFIG_ARM_OMAP2PLUS_CPUFREQ)	+= omap-cpufreq.o
 obj-$(CONFIG_ARM_PXA2xx_CPUFREQ)	+= pxa2xx-cpufreq.o
drivers/cpufreq/mediatek-cpufreq-hw.c new file +283 -0

283 lines not on this page · raw message

Signature · 5 lines
1.7.9.5
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
maintainer
#2 lore raw

drivers/cpufreq/mediatek-cpufreq-hw.c line 59

Quoted 9 lines · Hector Yuan
drivers/cpufreq/mediatek-cpufreq-hw.c new file +9 -0
+static unsigned int mtk_cpufreq_hw_get(unsigned int cpu)
+{
+	struct cpufreq_mtk *c;
+	struct cpufreq_policy *policy;
+	unsigned int index;
+
+	policy = cpufreq_cpu_get_raw(cpu);
+	if (!policy)
+		return 0;

Why didn't you drop policy as we discussed in previous version ?

drivers/cpufreq/mediatek-cpufreq-hw.c line 66

Quoted 6 lines
drivers/cpufreq/mediatek-cpufreq-hw.c new file +6 -0
+	c = mtk_freq_domain_map[cpu];
+
+	index = readl_relaxed(c->reg_bases[REG_PERF_STATE]);
+	index = min(index, LUT_MAX_ENTRIES - 1);
+
+	return policy->freq_table[index].frequency;

policy->freq_table and c->table are same, isn't it ?

drivers/cpufreq/mediatek-cpufreq-hw.c line 279

Quoted 11 lines
drivers/cpufreq/mediatek-cpufreq-hw.c new file +11 -0
+}
+
+static struct platform_driver mtk_cpufreq_hw_driver = {
+	.probe = mtk_cpufreq_hw_driver_probe,
+	.remove = mtk_cpufreq_hw_driver_remove,
+	.driver = {
+		.name = "mtk-cpufreq-hw",
+		.of_match_table = mtk_cpufreq_hw_match,
+	},
+};
+

Remove this blank line.

drivers/cpufreq/mediatek-cpufreq-hw.c line 282

Quoted 3 lines
drivers/cpufreq/mediatek-cpufreq-hw.c new file +3 -0
+module_platform_driver(mtk_cpufreq_hw_driver);
+
+MODULE_DESCRIPTION("mtk CPUFREQ HW Driver");

Maybe write this is "Mediatek cpufreq-hw driver" ?

Quoted 3 lines

+MODULE_LICENSE("GPL v2");

Signature · 1 line
1.7.9.5
Signature · 6 lines
viresh

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#3 lore raw
Quoted 13 lines · Viresh Kumar

drivers/cpufreq/mediatek-cpufreq-hw.c line 59

Quoted 9 lines · Hector Yuan
drivers/cpufreq/mediatek-cpufreq-hw.c new file +9 -0
+static unsigned int mtk_cpufreq_hw_get(unsigned int cpu)
+{
+	struct cpufreq_mtk *c;
+	struct cpufreq_policy *policy;
+	unsigned int index;
+
+	policy = cpufreq_cpu_get_raw(cpu);
+	if (!policy)
+		return 0;

Why didn't you drop policy as we discussed in previous version ?

Sorry I missed that. Thank you.

Quoted 9 lines

drivers/cpufreq/mediatek-cpufreq-hw.c line 66

Quoted 6 lines
drivers/cpufreq/mediatek-cpufreq-hw.c new file +6 -0
+	c = mtk_freq_domain_map[cpu];
+
+	index = readl_relaxed(c->reg_bases[REG_PERF_STATE]);
+	index = min(index, LUT_MAX_ENTRIES - 1);
+
+	return policy->freq_table[index].frequency;

policy->freq_table and c->table are same, isn't it ?

Yes, you are right.

Quoted 5 lines
Quoted 5 lines
drivers/cpufreq/mediatek-cpufreq-hw.c new file +5 -0
+}
+
+static struct platform_driver mtk_cpufreq_hw_driver = {
+	.probe = mtk_cpufreq_hw_driver_probe,
+	.remove = mtk_cpufreq_hw_driver_remove,
Quoted 9 lines

drivers/cpufreq/mediatek-cpufreq-hw.c line 279

Quoted 6 lines
drivers/cpufreq/mediatek-cpufreq-hw.c new file +6 -0
+	.driver = {
+		.name = "mtk-cpufreq-hw",
+		.of_match_table = mtk_cpufreq_hw_match,
+	},
+};
+

Remove this blank line.

OK

Quoted 6 lines

drivers/cpufreq/mediatek-cpufreq-hw.c line 282

Quoted 3 lines
drivers/cpufreq/mediatek-cpufreq-hw.c new file +3 -0
+module_platform_driver(mtk_cpufreq_hw_driver);
+
+MODULE_DESCRIPTION("mtk CPUFREQ HW Driver");

Maybe write this is "Mediatek cpufreq-hw driver" ?

OK

Quoted 4 lines
Quoted 3 lines

+MODULE_LICENSE("GPL v2");

Signature · 1 line
1.7.9.5

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#4 lore raw

PATCH v6 2/2 dt-bindings: cpufreq: add bindings for MediaTek cpufreq HW

In reply to Hector Yuan

From: "Hector.Yuan" <[email protected]>

Add devicetree bindings for MediaTek HW driver.

---
 .../bindings/cpufreq/cpufreq-mediatek-hw.yaml      |  141 ++++++++++++++++++++
 1 file changed, 141 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/cpufreq/cpufreq-mediatek-hw.yaml
Documentation/devicetree/bindings/cpufreq/cpufreq-mediatek-hw.yaml new file +141 -0
new file mode 100644
index 0000000..118a163
@@ -0,0 +1,141 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/cpufreq/cpufreq-mediatek-hw.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek's CPUFREQ Bindings
+
+maintainers:
+  - Hector Yuan <[email protected]>
+
+description:
+  CPUFREQ HW is a hardware engine used by MediaTek
+  SoCs to manage frequency in hardware. It is capable of controlling frequency
+  for multiple clusters.
+
+properties:
+  compatible:
+    const: "mediatek,cpufreq-hw"
+
+  reg:
+    minItems: 1
+    maxItems: 2
+    description: |
+      Addresses and sizes for the memory of the HW bases in each frequency domain.
+
+  reg-names:
+    items:
+      - const: "freq-domain0"
+      - const: "freq-domain1"
+    description: |
+      Frequency domain name. i.e.
+      "freq-domain0", "freq-domain1".
+
+  "#freq-domain-cells":
+    const: 1
+    description: |
+      Number of cells in a freqency domain specifier.
+
+  mtk-freq-domain:
+    maxItems: 1
+    description: |
+      Define this cpu belongs to which frequency domain. i.e.
+      cpu0-3 belong to frequency domain0,
+      cpu4-6 belong to frequency domain1.
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - "#freq-domain-cells"
+
+examples:
+  - |
+    cpus {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            cpu0: cpu@0 {
+                device_type = "cpu";
+                compatible = "arm,cortex-a55";
+                enable-method = "psci";
+                mtk-freq-domain = <&cpufreq_hw 0>;
+                reg = <0x000>;
+            };
+
+            cpu1: cpu@1 {
+                device_type = "cpu";
+                compatible = "arm,cortex-a55";
+                enable-method = "psci";
+                mtk-freq-domain = <&cpufreq_hw 0>;
+                reg = <0x100>;
+            };
+
+            cpu2: cpu@2 {
+                device_type = "cpu";
+                compatible = "arm,cortex-a55";
+                enable-method = "psci";
+                mtk-freq-domain = <&cpufreq_hw 0>;
+                reg = <0x200>;
+            };
+
+            cpu3: cpu@3 {
+                device_type = "cpu";
+                compatible = "arm,cortex-a55";
+                enable-method = "psci";
+                mtk-freq-domain = <&cpufreq_hw 0>;
+                reg = <0x300>;
+            };
+
+            cpu4: cpu@4 {
+                device_type = "cpu";
+                compatible = "arm,cortex-a55";
+                enable-method = "psci";
+                mtk-freq-domain = <&cpufreq_hw 1>;
+                reg = <0x400>;
+            };
+
+            cpu5: cpu@5 {
+                device_type = "cpu";
+                compatible = "arm,cortex-a55";
+                enable-method = "psci";
+                mtk-freq-domain = <&cpufreq_hw 1>;
+                reg = <0x500>;
+            };
+
+            cpu6: cpu@6 {
+                device_type = "cpu";
+                compatible = "arm,cortex-a75";
+                enable-method = "psci";
+                mtk-freq-domain = <&cpufreq_hw 1>;
+                reg = <0x600>;
+            };
+
+            cpu7: cpu@7 {
+                device_type = "cpu";
+                compatible = "arm,cortex-a75";
+                enable-method = "psci";
+                mtk-freq-domain = <&cpufreq_hw 1>;
+                reg = <0x700>;
+            };
+    };
+
+    /* ... */
+
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        cpufreq_hw: cpufreq@11bc00 {
+            compatible = "mediatek,cpufreq-hw";
+            reg = <0 0x11bc10 0 0x8c>,
+               <0 0x11bca0 0 0x8c>;
+            reg-names = "freq-domain0", "freq-domain1";
+            #freq-domain-cells = <1>;
+        };
+    };
+
+
+
+
Signature · 5 lines
1.7.9.5
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek