Skip to contentSkip to conversation

MAINTAINERS: add new entries for Armada 8K cpufreq driver

PATCH New Gregory CLEMENT 3 participants 5 messages Sep 21, 2018 – Sep 24, 2018

Subsystems (2)
lore
Share & tools
lore

Gregory CLEMENT

author maintainer
#0 lore raw

PATCH 1/2 MAINTAINERS: add new entries for Armada 8K cpufreq driver

This new driver belongs to the mvebu family, update the MAINTAINER file to document it.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index a5b256b25905..7e969fbb3626 100644
@@ -1657,6 +1657,7 @@ F:	arch/arm/configs/mvebu_*_defconfig
 F:	arch/arm/mach-mvebu/
 F:	arch/arm64/boot/dts/marvell/armada*
 F:	drivers/cpufreq/armada-37xx-cpufreq.c
+F!	drivers/cpufreq/armada-8k-cpufreq.c
 F:	drivers/cpufreq/mvebu-cpufreq.c
 F:	drivers/irqchip/irq-armada-370-xp.c
 F:	drivers/irqchip/irq-mvebu-*
Signature · 1 line
2.19.0
author maintainer
#1 lore raw

PATCH 2/2 cpufreq: ap806: add cpufreq driver for Armada 8K

Add cpufreq driver for Marvell AP-806 found on Aramda 8K. The AP-806 has DFS (Dynamic Frequency Scaling) with coupled clock domain for two clusters, so this driver will directly use generic cpufreq-dt driver as backend.

Based on the work of Omri Itach <[email protected]>.

---
 drivers/cpufreq/Kconfig.arm         |  11 +++
 drivers/cpufreq/Makefile            |   1 +
 drivers/cpufreq/armada-8k-cpufreq.c | 145 ++++++++++++++++++++++++++++
 3 files changed, 157 insertions(+)
 create mode 100644 drivers/cpufreq/armada-8k-cpufreq.c
drivers/cpufreq/Kconfig.arm +11 -0
index 0cd8eb76ad59..26326918f179 100644
@@ -25,6 +25,17 @@ config ARM_ARMADA_37XX_CPUFREQ
 	  This adds the CPUFreq driver support for Marvell Armada 37xx SoCs.
 	  The Armada 37xx PMU supports 4 frequency and VDD levels.
 
+config ARM_ARMADA_8K_CPUFREQ
+       tristate "Armada 8K CPUFreq driver"
+       depends on ARCH_MVEBU && CPUFREQ_DT
+       help
+         This enables the CPUFreq driver support for Marvell
+	 Armada8k SOCs.
+	 Armada8K device has the AP806 which supports scaling
+	 to any full integer divider.
+
+	 If in doubt, say N.
+
 # big LITTLE core layer and glue drivers
 config ARM_BIG_LITTLE_CPUFREQ
 	tristate "Generic ARM big LITTLE CPUfreq driver"
drivers/cpufreq/Makefile +1 -0
index c1ffeabe4ecf..21f4f56229db 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_ARM_BIG_LITTLE_CPUFREQ)	+= arm_big_little.o
 obj-$(CONFIG_ARM_DT_BL_CPUFREQ)		+= arm_big_little_dt.o
 
 obj-$(CONFIG_ARM_ARMADA_37XX_CPUFREQ)	+= armada-37xx-cpufreq.o
+obj-$(CONFIG_ARM_ARMADA_8K_CPUFREQ)	+= armada-8k-cpufreq.o
 obj-$(CONFIG_ARM_BRCMSTB_AVS_CPUFREQ)	+= brcmstb-avs-cpufreq.o
 obj-$(CONFIG_ACPI_CPPC_CPUFREQ)		+= cppc_cpufreq.o
 obj-$(CONFIG_ARCH_DAVINCI)		+= davinci-cpufreq.o
drivers/cpufreq/armada-8k-cpufreq.c new file +145 -0

145 lines not on this page · raw message

Signature · 1 line
2.19.0
#2 lore raw

PATCH 2/2 cpufreq: ap806: add cpufreq driver for Armada 8K

Hello,

This is not a full review, just a few things I noticed.

Quoted 1 line · Gregory CLEMENT

Add cpufreq driver for Marvell AP-806 found on Aramda 8K.

Armada, not Aramda.

drivers/cpufreq/Kconfig.arm config ARM_ARMADA_37XX_CPUFREQ · line 31

Quoted 4 lines
drivers/cpufreq/Kconfig.arm +4 -0
+config ARM_ARMADA_8K_CPUFREQ
+       tristate "Armada 8K CPUFreq driver"
+       depends on ARCH_MVEBU && CPUFREQ_DT
+       help

Indentation of those items should use one tab, not spaces.

drivers/cpufreq/Kconfig.arm config ARM_ARMADA_37XX_CPUFREQ · line 35

Quoted 4 lines
drivers/cpufreq/Kconfig.arm +4 -0
+         This enables the CPUFreq driver support for Marvell
+	 Armada8k SOCs.
+	 Armada8K device has the AP806 which supports scaling
+	 to any full integer divider.

And for the help text, it should be one tab + two spaces.

drivers/cpufreq/armada-8k-cpufreq.c line 30

Quoted 5 lines
drivers/cpufreq/armada-8k-cpufreq.c new file +5 -0
+/*
+ * Setup the opps list with the divider for the max frequency, that
+ * will be filled at runtime, 0 meaning 100Mhz
+ */
+static int opps_div[] __initdata = {1, 2, 3, 0};

const ?

drivers/cpufreq/armada-8k-cpufreq.c line 38

Quoted 8 lines
drivers/cpufreq/armada-8k-cpufreq.c new file +8 -0
+
+struct opps_array {
+	struct device *cpu_dev;
+	unsigned int freq[ARRAY_SIZE(opps_div)];
+};
+
+/* If the CPUs share the same clock, then they are in the same cluster */
+static void __init aramda_8k_get_sharing_cpus(struct clk *cur_clk,

Typo in function name, it should use armada, not aramda.

drivers/cpufreq/armada-8k-cpufreq.c line 50

Quoted 12 lines
drivers/cpufreq/armada-8k-cpufreq.c new file +12 -0
+				       struct cpumask *cpumask)
+{
+	int cpu;
+
+	for_each_possible_cpu(cpu) {
+		struct device *cpu_dev = get_cpu_device(cpu);
+		struct clk *clk = clk_get(cpu_dev, 0);
+
+		if (IS_ERR(clk))
+			dev_warn(cpu_dev, "Cannot get clock for CPU %d\n", cpu);
+
+		if (clk_is_match(clk, cur_clk))

Is it OK to call clk_is_match() is clk being an error ?

Quoted 31 lines
drivers/cpufreq/armada-8k-cpufreq.c new file +31 -0
+			cpumask_set_cpu(cpu, cpumask);
+	}
+
+}
+
+static int __init armada_8k_cpufreq_init(void)
+{
+	struct opps_array *opps_arrays;
+	struct platform_device *pdev;
+	int ret, cpu, opps_index = 0;
+	unsigned int cur_frequency;
+	struct device_node *node;
+
+	node = of_find_compatible_node(NULL, NULL, "marvell,ap806-cpu-clock");
+	if (!node || !of_device_is_available(node))
+		return -ENODEV;
+
+	opps_arrays = kcalloc(num_possible_cpus(), sizeof(*opps_arrays),
+			      GFP_KERNEL);
+	/*
+	 * For each CPU, this loop registers the operating points
+	 * supported (which are the nominal CPU frequency and full integer
+	 * divisions of it).
+	 */
+	for_each_possible_cpu(cpu) {
+		struct device *cpu_dev;
+		struct cpumask cpus;
+		unsigned int freq;
+		struct clk *clk;
+		int i;
+

drivers/cpufreq/armada-8k-cpufreq.c line 91

Quoted 10 lines
drivers/cpufreq/armada-8k-cpufreq.c new file +10 -0
+		cpu_dev = get_cpu_device(cpu);
+		if (!cpu_dev) {
+			dev_err(cpu_dev, "Cannot get CPU %d\n", cpu);
+			continue;
+		}
+
+		clk = clk_get(cpu_dev, 0);
+		if (IS_ERR(clk)) {
+			dev_err(cpu_dev, "Cannot get clock for CPU %d\n", cpu);
+			return PTR_ERR(clk);

So here you're leaking the memory allocation of opps_array[] and everything that was done during all previous iterations of the loop.

drivers/cpufreq/armada-8k-cpufreq.c line 99

Quoted 8 lines
drivers/cpufreq/armada-8k-cpufreq.c new file +8 -0
+		}
+
+		/* Get nominal (current) CPU frequency */
+		cur_frequency = clk_get_rate(clk);
+		if (!cur_frequency) {
+			dev_err(cpu_dev,
+				"Failed to get clock rate for CPU %d\n", cpu);
+			return -EINVAL;

Ditto.

drivers/cpufreq/armada-8k-cpufreq.c line 110

Quoted 11 lines
drivers/cpufreq/armada-8k-cpufreq.c new file +11 -0
+		}
+
+		opps_arrays[opps_index].cpu_dev = cpu_dev;
+		for (i = 0; i < ARRAY_SIZE(opps_div); i++) {
+			if (opps_div[i])
+				freq = cur_frequency / opps_div[i];
+			else
+				freq = MIN_FREQ;
+
+			ret = dev_pm_opp_add(cpu_dev, freq, 0);
+

Remove this blank line, to have the if (ret) just below the function call.

Review

Quoted 2 lines
(quoted diff) +2 -0
+			if (ret)
+				goto remove_opp;

And add a blank line here instead.

Quoted 6 lines
drivers/cpufreq/armada-8k-cpufreq.c new file +6 -0
+			opps_arrays[opps_index].freq[i] = freq;
+		}
+
+		cpumask_clear(&cpus);
+		aramda_8k_get_sharing_cpus(clk, &cpus);
+		dev_pm_opp_set_sharing_cpus(cpu_dev, &cpus);

drivers/cpufreq/armada-8k-cpufreq.c line 128

Quoted 10 lines
drivers/cpufreq/armada-8k-cpufreq.c new file +10 -0
+	}
+
+	pdev = platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
+	ret = PTR_ERR_OR_ZERO(pdev);
+	if (ret)
+		goto remove_opp;
+	kfree(opps_arrays);
+	return 0;
+remove_opp:
+

Please exchange those two lines: one blank line between the return and the goto label, and no blank line between the goto label and the core of the code.

Quoted 7 lines
drivers/cpufreq/armada-8k-cpufreq.c new file +7 -0
+	for (; opps_index >= 0; opps_index--) {
+		int i = 0;
+
+		while (opps_arrays[opps_index].freq[i]) {
+			dev_pm_opp_remove(opps_arrays[opps_index].cpu_dev,
+					  opps_arrays[opps_index].freq[i]);
+			i++;

drivers/cpufreq/armada-8k-cpufreq.c line 145

Quoted 10 lines
drivers/cpufreq/armada-8k-cpufreq.c new file +10 -0
+		}
+	}
+	kfree(opps_arrays);
+	return ret;
+}
+module_init(armada_8k_cpufreq_init);
+
+MODULE_AUTHOR("Gregory Clement <[email protected]>");
+MODULE_DESCRIPTION("Armada 8K cpufreq driver");
+MODULE_LICENSE("GPL");

Once again, this is not a full review, I haven't reviewed the logic of the driver itself, just a few obvious things I noticed.

Best regards,

Thomas Petazzoni

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
author maintainer
#3 lore raw

PATCH 2/2 cpufreq: ap806: add cpufreq driver for Armada 8K

Hi Thomas,

On sam., sept. 22 2018, Thomas Petazzoni <[email protected]> wrote:

[...]

Quoted 5 lines
Quoted 5 lines
drivers/cpufreq/armada-8k-cpufreq.c new file +5 -0
+{
+	int cpu;
+
+	for_each_possible_cpu(cpu) {
+		struct device *cpu_dev = get_cpu_device(cpu);
Quoted 9 lines

drivers/cpufreq/armada-8k-cpufreq.c line 50

Quoted 6 lines
drivers/cpufreq/armada-8k-cpufreq.c new file +6 -0
+		struct clk *clk = clk_get(cpu_dev, 0);
+
+		if (IS_ERR(clk))
+			dev_warn(cpu_dev, "Cannot get clock for CPU %d\n", cpu);
+
+		if (clk_is_match(clk, cur_clk))

Is it OK to call clk_is_match() is clk being an error ?

yes the function check the validity of the pointers.

[...]

Quoted 2 lines

Once again, this is not a full review, I haven't reviewed the logic of the driver itself, just a few obvious things I noticed.

Thanks for this first level review, I took into account all your remarks.

Gregory

Quoted 8 lines

Best regards,

Thomas Petazzoni

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Signature · 3 lines
Gregory Clement, Bootlin
Embedded Linux and Kernel engineering
http://bootlin.com
#4 lore raw

PATCH 1/2 MAINTAINERS: add new entries for Armada 8K cpufreq driver

In reply to Gregory CLEMENT

Hi Gregory,

Quoted 13 lines · Gregory CLEMENT

This new driver belongs to the mvebu family, update the MAINTAINER file to document it.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +0 -0
index a5b256b25905..7e969fbb3626 100644

MAINTAINERS F: arch/arm/configs/mvebu_*_defconfig · line 1660

Quoted 4 lines
MAINTAINERS +1 -0
@@ -1657,6 +1657,7 @@ F:	arch/arm/configs/mvebu_*_defconfig
 F:	arch/arm/mach-mvebu/
 F:	arch/arm64/boot/dts/marvell/armada*
 F:	drivers/cpufreq/armada-37xx-cpufreq.c
+F!	drivers/cpufreq/armada-8k-cpufreq.c

s/!/:/

baruch

Quoted 3 lines
MAINTAINERS +0 -0
 F:	drivers/cpufreq/mvebu-cpufreq.c
 F:	drivers/irqchip/irq-armada-370-xp.c
 F:	drivers/irqchip/irq-mvebu-*
Signature · 3 lines
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -