fanghuilin / rpms / kernel

Forked from rpms/kernel 3 years ago
Clone
e336be
From 624e057827435de39274c34e20c2d937cb9d4ac3 Mon Sep 17 00:00:00 2001
e336be
From: Peter Robinson <pbrobinson@gmail.com>
e336be
Date: Thu, 31 May 2018 19:08:12 +0100
e336be
Subject: [PATCH] bcm2835: cpufreq: add CPU frequency control driver
e336be
e336be
Signed-off-by: Peter Robinson <pbrobinson@gmail.com>
e336be
---
e336be
 arch/arm/boot/dts/bcm2835-rpi.dtsi |   7 ++
e336be
 arch/arm/boot/dts/bcm2837.dtsi     |  33 +++++++
e336be
 drivers/clk/bcm/Kconfig            |   8 ++
e336be
 drivers/clk/bcm/Makefile           |   1 +
e336be
 drivers/clk/bcm/clk-raspberrypi.c  | 138 +++++++++++++++++++++++++++++
e336be
 5 files changed, 187 insertions(+)
e336be
 create mode 100644 drivers/clk/bcm/clk-raspberrypi.c
e336be
e336be
diff --git a/arch/arm/boot/dts/bcm2835-rpi.dtsi b/arch/arm/boot/dts/bcm2835-rpi.dtsi
e336be
index 6c3cfaa77f3d..e6d1627ec421 100644
e336be
--- a/arch/arm/boot/dts/bcm2835-rpi.dtsi
e336be
+++ b/arch/arm/boot/dts/bcm2835-rpi.dtsi
e336be
@@ -35,6 +35,13 @@
Pablo Greco ee0ebe
 			reg = <0x7e00b840 0x3c>;
e336be
 			interrupts = <0 2>;
e336be
 		};
e336be
+
e336be
+		arm_clk: arm_clk {
e336be
+			compatible = "raspberrypi,bcm2835-cpu";
e336be
+			clocks = <&clocks BCM2835_CLOCK_VPU>;
e336be
+			#clock-cells = <0>;
e336be
+			clock-output-names = "arm";
e336be
+		};
e336be
 	};
e336be
 };
e336be
 
e336be
diff --git a/arch/arm/boot/dts/bcm2837.dtsi b/arch/arm/boot/dts/bcm2837.dtsi
e336be
index 7704bb029605..c24176282a1f 100644
e336be
--- a/arch/arm/boot/dts/bcm2837.dtsi
e336be
+++ b/arch/arm/boot/dts/bcm2837.dtsi
e336be
@@ -38,6 +38,9 @@
e336be
 			reg = <0>;
e336be
 			enable-method = "spin-table";
e336be
 			cpu-release-addr = <0x0 0x000000d8>;
e336be
+			clocks = <&arm_clk>;
e336be
+			clock-names = "cpu";
e336be
+			operating-points-v2 = <&cpu0_opp_table>;
e336be
 		};
e336be
 
e336be
 		cpu1: cpu@1 {
e336be
@@ -46,6 +49,9 @@
e336be
 			reg = <1>;
e336be
 			enable-method = "spin-table";
e336be
 			cpu-release-addr = <0x0 0x000000e0>;
e336be
+			clocks = <&arm_clk>;
e336be
+			clock-names = "cpu";
e336be
+			operating-points-v2 = <&cpu0_opp_table>;
e336be
 		};
e336be
 
e336be
 		cpu2: cpu@2 {
e336be
@@ -54,6 +60,9 @@
e336be
 			reg = <2>;
e336be
 			enable-method = "spin-table";
e336be
 			cpu-release-addr = <0x0 0x000000e8>;
e336be
+			clocks = <&arm_clk>;
e336be
+			clock-names = "cpu";
e336be
+			operating-points-v2 = <&cpu0_opp_table>;
e336be
 		};
e336be
 
e336be
 		cpu3: cpu@3 {
e336be
@@ -62,6 +71,30 @@
e336be
 			reg = <3>;
e336be
 			enable-method = "spin-table";
e336be
 			cpu-release-addr = <0x0 0x000000f0>;
e336be
+			clocks = <&arm_clk>;
e336be
+			clock-names = "cpu";
e336be
+			operating-points-v2 = <&cpu0_opp_table>;
e336be
+		};
e336be
+	};
e336be
+
e336be
+	cpu0_opp_table: opp_table0 {
e336be
+		compatible = "operating-points-v2";
e336be
+		opp-shared;
e336be
+
e336be
+		opp@600000000 {
e336be
+			opp-hz = /bits/ 64 <600000000>;
e336be
+			clock-latency-ns = <355000>;
e336be
+			opp-suspend;
e336be
+		};
e336be
+
e336be
+		opp@900000000 {
e336be
+			opp-hz = /bits/ 64 <900000000>;
e336be
+			clock-latency-ns = <355000>;
e336be
+		};
e336be
+
e336be
+		opp@1200000000 {
e336be
+			opp-hz = /bits/ 64 <1200000000>;
e336be
+			clock-latency-ns = <355000>;
e336be
 		};
e336be
 	};
e336be
 };
e336be
diff --git a/drivers/clk/bcm/Kconfig b/drivers/clk/bcm/Kconfig
e336be
index 4c4bd85f707c..e40bd19da22b 100644
e336be
--- a/drivers/clk/bcm/Kconfig
e336be
+++ b/drivers/clk/bcm/Kconfig
e336be
@@ -63,3 +63,11 @@ config CLK_BCM_SR
e336be
 	default ARCH_BCM_IPROC
e336be
 	help
e336be
 	  Enable common clock framework support for the Broadcom Stingray SoC
e336be
+
e336be
+config CLK_RASPBERRYPI_CPU
e336be
+	bool "Raspberry Pi CPU clock driver"
e336be
+	depends on ARCH_BCM2835 || (COMPILE_TEST && OF)
e336be
+	depends on RASPBERRYPI_FIRMWARE=y
e336be
+	help
e336be
+	  This enables support for the RPi CPU clock which can be adjusted
e336be
+	  via the RPi firmware.
e336be
diff --git a/drivers/clk/bcm/Makefile b/drivers/clk/bcm/Makefile
e336be
index 002661d39128..a028b0a90b6e 100644
e336be
--- a/drivers/clk/bcm/Makefile
e336be
+++ b/drivers/clk/bcm/Makefile
e336be
@@ -8,6 +8,7 @@ obj-$(CONFIG_COMMON_CLK_IPROC)	+= clk-iproc-armpll.o clk-iproc-pll.o clk-iproc-a
e336be
 obj-$(CONFIG_ARCH_BCM2835)	+= clk-bcm2835.o
e336be
 obj-$(CONFIG_ARCH_BCM2835)	+= clk-bcm2835-aux.o
e336be
 obj-$(CONFIG_ARCH_BCM_53573)	+= clk-bcm53573-ilp.o
e336be
+obj-$(CONFIG_CLK_RASPBERRYPI_CPU)	+= clk-raspberrypi.o
e336be
 obj-$(CONFIG_CLK_BCM_CYGNUS)	+= clk-cygnus.o
e336be
 obj-$(CONFIG_CLK_BCM_HR2)	+= clk-hr2.o
e336be
 obj-$(CONFIG_CLK_BCM_NSP)	+= clk-nsp.o
e336be
diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c
e336be
new file mode 100644
e336be
index 000000000000..046efc822a59
e336be
--- /dev/null
e336be
+++ b/drivers/clk/bcm/clk-raspberrypi.c
e336be
@@ -0,0 +1,138 @@
e336be
+// SPDX-License-Identifier: GPL-2.0+
e336be
+/*
e336be
+ * Raspberry Pi CPU clock driver
e336be
+ *
e336be
+ * Copyright (C) 2018 Stefan Wahren <stefan.wahren@i2se.com>
e336be
+ */
e336be
+
e336be
+#include <linux/clk.h>
e336be
+#include <linux/clk-provider.h>
e336be
+#include <linux/device.h>
e336be
+#include <linux/err.h>
e336be
+#include <linux/module.h>
e336be
+#include <linux/of_device.h>
e336be
+#include <linux/platform_device.h>
e336be
+#include <linux/slab.h>
e336be
+#include <soc/bcm2835/raspberrypi-firmware.h>
e336be
+
e336be
+#define VCMSG_ID_ARM_CLOCK 0x000000003	/* Clock/Voltage ID's */
e336be
+
e336be
+struct rpi_cpu_clkgen {
e336be
+	struct clk_hw hw;
e336be
+	struct rpi_firmware *fw;
e336be
+};
e336be
+
e336be
+/* tag part of the message */
e336be
+struct prop {
e336be
+       u32 id;			/* the ID of the clock/voltage to get or set */
e336be
+       u32 val;			/* the value (e.g. rate (in Hz)) to set */
e336be
+} __packed;
e336be
+
e336be
+static int rpi_cpu_clock_property(struct rpi_firmware *fw, u32 tag, u32 *val)
e336be
+{
e336be
+	int ret;
e336be
+	struct prop msg = {
e336be
+		.id = VCMSG_ID_ARM_CLOCK,
e336be
+		.val = *val,
e336be
+	};
e336be
+
e336be
+	ret = rpi_firmware_property(fw, tag, &msg, sizeof(msg));
e336be
+	if (ret)
e336be
+		return ret;
e336be
+
e336be
+	*val = msg.val;
e336be
+
e336be
+	return 0;
e336be
+}
e336be
+
e336be
+static unsigned long rpi_cpu_get_rate(struct clk_hw *hw,
e336be
+				      unsigned long parent_rate)
e336be
+{
e336be
+	struct rpi_cpu_clkgen *cpu = container_of(hw, struct rpi_cpu_clkgen, hw);
e336be
+	u32 rate = 0;
e336be
+
e336be
+	rpi_cpu_clock_property(cpu->fw, RPI_FIRMWARE_GET_CLOCK_RATE, &rate;;
e336be
+
e336be
+	return rate;
e336be
+}
e336be
+
e336be
+static long rpi_cpu_round_rate(struct clk_hw *hw, unsigned long rate,
e336be
+				     unsigned long *parent_rate)
e336be
+{
e336be
+	return rate;
e336be
+}
e336be
+
e336be
+static int rpi_cpu_set_rate(struct clk_hw *hw, unsigned long rate,
e336be
+			    unsigned long parent_rate)
e336be
+{
e336be
+	struct rpi_cpu_clkgen *cpu = container_of(hw, struct rpi_cpu_clkgen, hw);
e336be
+	u32 new_rate = rate;
e336be
+
e336be
+	return rpi_cpu_clock_property(cpu->fw, RPI_FIRMWARE_SET_CLOCK_RATE,
e336be
+				      &new_rate);
e336be
+}
e336be
+
e336be
+static const struct clk_ops rpi_cpu_ops = {
e336be
+	.recalc_rate = rpi_cpu_get_rate,
e336be
+	.round_rate = rpi_cpu_round_rate,
e336be
+	.set_rate = rpi_cpu_set_rate,
e336be
+};
e336be
+
e336be
+static int rpi_cpu_probe(struct platform_device *pdev)
e336be
+{
e336be
+	struct device *dev = &pdev->dev;
e336be
+	struct device_node *fw_node;
e336be
+	struct rpi_cpu_clkgen *cpu;
e336be
+	struct clk_init_data *init;
e336be
+	int ret;
e336be
+
e336be
+	cpu = devm_kzalloc(dev, sizeof(*cpu), GFP_KERNEL);
e336be
+	if (!cpu)
e336be
+		return -ENOMEM;
e336be
+
e336be
+	init = devm_kzalloc(dev, sizeof(*init), GFP_KERNEL);
e336be
+	if (!init)
e336be
+		return -ENOMEM;
e336be
+
e336be
+	fw_node = of_find_compatible_node(NULL, NULL,
e336be
+					  "raspberrypi,bcm2835-firmware");
e336be
+	if (!fw_node) {
e336be
+		dev_err(dev, "Missing firmware node\n");
e336be
+		return -ENOENT;
e336be
+	}
e336be
+
e336be
+	cpu->fw = rpi_firmware_get(fw_node);
e336be
+	of_node_put(fw_node);
e336be
+	if (!cpu->fw)
e336be
+		return -EPROBE_DEFER;
e336be
+
e336be
+	init->name = dev->of_node->name;
e336be
+	init->ops = &rpi_cpu_ops;
e336be
+
e336be
+	cpu->hw.init = init;
e336be
+	ret = devm_clk_hw_register(dev, &cpu->hw);
e336be
+	if (ret)
e336be
+		return ret;
e336be
+
e336be
+	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get,
e336be
+				      &cpu->hw);
e336be
+}
e336be
+
e336be
+static const struct of_device_id rpi_cpu_of_match[] = {
e336be
+	{ .compatible = "raspberrypi,bcm2835-cpu", },
e336be
+	{},
e336be
+};
e336be
+MODULE_DEVICE_TABLE(of, rpi_cpu_of_match);
e336be
+
e336be
+static struct platform_driver rpi_cpu_driver = {
e336be
+	.driver = {
e336be
+		.name = "raspberrypi-cpu",
e336be
+		.of_match_table = rpi_cpu_of_match,
e336be
+	},
e336be
+	.probe		= rpi_cpu_probe,
e336be
+};
e336be
+builtin_platform_driver(rpi_cpu_driver);
e336be
+
e336be
+MODULE_AUTHOR("Stefan Wahren <stefan.wahren@i2se.com>");
e336be
+MODULE_DESCRIPTION("Raspberry Pi CPU clock driver");
e336be
+MODULE_LICENSE("GPL v2");
e336be
-- 
e336be
2.17.0
e336be
e336be
From 40a82f71737891581dcbe45331d15a29dd3e7805 Mon Sep 17 00:00:00 2001
e336be
From: Peter Robinson <pbrobinson@gmail.com>
e336be
Date: Mon, 4 Jun 2018 09:14:10 +0100
e336be
Subject: [PATCH 7/7] add 1.4 ghz OPP for the 3B+
e336be
e336be
Signed-off-by: Peter Robinson <pbrobinson@gmail.com>
e336be
---
e336be
 arch/arm/boot/dts/bcm2837-rpi-3-b-plus.dts | 7 +++++++
e336be
 1 file changed, 7 insertions(+)
e336be
e336be
diff --git a/arch/arm/boot/dts/bcm2837-rpi-3-b-plus.dts b/arch/arm/boot/dts/bcm2837-rpi-3-b-plus.dts
e336be
index 4adb85e66be3..aaefb078f391 100644
e336be
--- a/arch/arm/boot/dts/bcm2837-rpi-3-b-plus.dts
e336be
+++ b/arch/arm/boot/dts/bcm2837-rpi-3-b-plus.dts
e336be
@@ -106,3 +106,10 @@
e336be
 	pinctrl-0 = <&uart1_gpio14>;
e336be
 	status = "okay";
e336be
 };
e336be
+
e336be
+&cpu0_opp_table {
e336be
+	opp@1400000000 {
e336be
+		opp-hz = /bits/ 64 <1400000000>;
e336be
+		clock-latency-ns = <355000>;
e336be
+	};
e336be
+};
e336be
-- 
e336be
2.17.1
e336be
e336be
From d00bd46b40001d3500b8a7207dcfe1d66600e47e Mon Sep 17 00:00:00 2001
e336be
From: Stefan Wahren <stefan.wahren@i2se.com>
e336be
Date: Wed, 26 Sep 2018 21:13:22 +0200
e336be
Subject: [PATCH] ARM: bcm2837: Use CPU0 as cooling device
e336be
e336be
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
e336be
---
e336be
 arch/arm/boot/dts/bcm2837.dtsi | 25 +++++++++++++++++++++++++
e336be
 arch/arm/boot/dts/bcm283x.dtsi |  2 +-
e336be
 2 files changed, 26 insertions(+), 1 deletion(-)
e336be
e336be
diff --git a/arch/arm/boot/dts/bcm2837.dtsi b/arch/arm/boot/dts/bcm2837.dtsi
e336be
index 9cfc553..1590d94 100644
e336be
--- a/arch/arm/boot/dts/bcm2837.dtsi
e336be
+++ b/arch/arm/boot/dts/bcm2837.dtsi
e336be
@@ -1,4 +1,5 @@
e336be
 #include "bcm283x.dtsi"
e336be
+#include <dt-bindings/thermal/thermal.h>
e336be
 
e336be
 / {
e336be
 	compatible = "brcm,bcm2837";
e336be
@@ -47,6 +48,7 @@
e336be
 			clocks = <&arm_clk>;
e336be
 			clock-names = "cpu";
e336be
 			operating-points-v2 = <&cpu0_opp_table>;
e336be
+			#cooling-cells = <2>;
e336be
 		};
e336be
 
e336be
 		cpu1: cpu@1 {
e336be
@@ -58,6 +60,7 @@
e336be
 			clocks = <&arm_clk>;
e336be
 			clock-names = "cpu";
e336be
 			operating-points-v2 = <&cpu0_opp_table>;
e336be
+			#cooling-cells = <2>;
e336be
 		};
e336be
 
e336be
 		cpu2: cpu@2 {
e336be
@@ -69,6 +72,7 @@
e336be
 			clocks = <&arm_clk>;
e336be
 			clock-names = "cpu";
e336be
 			operating-points-v2 = <&cpu0_opp_table>;
e336be
+			#cooling-cells = <2>;
e336be
 		};
e336be
 
e336be
 		cpu3: cpu@3 {
e336be
@@ -80,6 +84,7 @@
e336be
 			clocks = <&arm_clk>;
e336be
 			clock-names = "cpu";
e336be
 			operating-points-v2 = <&cpu0_opp_table>;
e336be
+			#cooling-cells = <2>;
e336be
 		};
e336be
 	};
e336be
 
e336be
@@ -117,6 +122,26 @@
e336be
 
e336be
 &cpu_thermal {
e336be
 	coefficients = <(-538)	412000>;
e336be
+
e336be
+	trips {
e336be
+		cpu_alert0: cpu-alert0 {
e336be
+			temperature	= <70000>;
e336be
+			hysteresis	= <0>;
e336be
+			type		= "passive";
e336be
+		};
e336be
+	};
e336be
+
e336be
+	cooling-maps {
e336be
+		map0 {
e336be
+			trip = <&cpu_alert0>;
e336be
+			cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
e336be
+		};
e336be
+
e336be
+		map1 {
e336be
+			trip = <&cpu_crit>;
e336be
+			cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
e336be
+		};
e336be
+	};
e336be
 };
e336be
 
e336be
 /* enable thermal sensor with the correct compatible property set */
e336be
diff --git a/arch/arm/boot/dts/bcm283x.dtsi b/arch/arm/boot/dts/bcm283x.dtsi
e336be
index 31b2964..2def068 100644
e336be
--- a/arch/arm/boot/dts/bcm283x.dtsi
e336be
+++ b/arch/arm/boot/dts/bcm283x.dtsi
e336be
@@ -38,7 +38,7 @@
e336be
 			thermal-sensors = <&thermal>;
e336be
 
e336be
 			trips {
e336be
-				cpu-crit {
e336be
+				cpu_crit: cpu-crit {
Pablo Greco ee0ebe
 					temperature	= <90000>;
e336be
 					hysteresis	= <0>;
e336be
 					type		= "critical";
e336be
-- 
e336be
2.7.4