From e8f4892e53e98464af631aaa7d79d8c50a2933eb Mon Sep 17 00:00:00 2001 From: Peter Robinson Date: Mon, 4 Jun 2018 07:24:58 +0100 Subject: Initial support for Raspberry Pi cpufreq driver --- ...-cpufreq-add-CPU-frequency-control-driver.patch | 273 +++++++++++++++++++++ kernel-aarch64-debug.config | 1 + kernel-aarch64.config | 1 + kernel-armv7hl-debug.config | 1 + kernel-armv7hl-lpae-debug.config | 1 + kernel-armv7hl-lpae.config | 1 + kernel-armv7hl.config | 1 + kernel.spec | 5 + rebase-notes.txt | 1 + 9 files changed, 285 insertions(+) create mode 100644 bcm2835-cpufreq-add-CPU-frequency-control-driver.patch diff --git a/bcm2835-cpufreq-add-CPU-frequency-control-driver.patch b/bcm2835-cpufreq-add-CPU-frequency-control-driver.patch new file mode 100644 index 000000000..b087998cb --- /dev/null +++ b/bcm2835-cpufreq-add-CPU-frequency-control-driver.patch @@ -0,0 +1,273 @@ +From 624e057827435de39274c34e20c2d937cb9d4ac3 Mon Sep 17 00:00:00 2001 +From: Peter Robinson +Date: Thu, 31 May 2018 19:08:12 +0100 +Subject: [PATCH] bcm2835: cpufreq: add CPU frequency control driver + +Signed-off-by: Peter Robinson +--- + arch/arm/boot/dts/bcm2835-rpi.dtsi | 7 ++ + arch/arm/boot/dts/bcm2837.dtsi | 33 +++++++ + drivers/clk/bcm/Kconfig | 8 ++ + drivers/clk/bcm/Makefile | 1 + + drivers/clk/bcm/clk-raspberrypi.c | 138 +++++++++++++++++++++++++++++ + 5 files changed, 187 insertions(+) + create mode 100644 drivers/clk/bcm/clk-raspberrypi.c + +diff --git a/arch/arm/boot/dts/bcm2835-rpi.dtsi b/arch/arm/boot/dts/bcm2835-rpi.dtsi +index 6c3cfaa77f3d..e6d1627ec421 100644 +--- a/arch/arm/boot/dts/bcm2835-rpi.dtsi ++++ b/arch/arm/boot/dts/bcm2835-rpi.dtsi +@@ -35,6 +35,13 @@ + reg = <0x7e00b840 0xf>; + interrupts = <0 2>; + }; ++ ++ arm_clk: arm_clk { ++ compatible = "raspberrypi,bcm2835-cpu"; ++ clocks = <&clocks BCM2835_CLOCK_VPU>; ++ #clock-cells = <0>; ++ clock-output-names = "arm"; ++ }; + }; + }; + +diff --git a/arch/arm/boot/dts/bcm2837.dtsi b/arch/arm/boot/dts/bcm2837.dtsi +index 7704bb029605..c24176282a1f 100644 +--- a/arch/arm/boot/dts/bcm2837.dtsi ++++ b/arch/arm/boot/dts/bcm2837.dtsi +@@ -38,6 +38,9 @@ + reg = <0>; + enable-method = "spin-table"; + cpu-release-addr = <0x0 0x000000d8>; ++ clocks = <&arm_clk>; ++ clock-names = "cpu"; ++ operating-points-v2 = <&cpu0_opp_table>; + }; + + cpu1: cpu@1 { +@@ -46,6 +49,9 @@ + reg = <1>; + enable-method = "spin-table"; + cpu-release-addr = <0x0 0x000000e0>; ++ clocks = <&arm_clk>; ++ clock-names = "cpu"; ++ operating-points-v2 = <&cpu0_opp_table>; + }; + + cpu2: cpu@2 { +@@ -54,6 +60,9 @@ + reg = <2>; + enable-method = "spin-table"; + cpu-release-addr = <0x0 0x000000e8>; ++ clocks = <&arm_clk>; ++ clock-names = "cpu"; ++ operating-points-v2 = <&cpu0_opp_table>; + }; + + cpu3: cpu@3 { +@@ -62,6 +71,30 @@ + reg = <3>; + enable-method = "spin-table"; + cpu-release-addr = <0x0 0x000000f0>; ++ clocks = <&arm_clk>; ++ clock-names = "cpu"; ++ operating-points-v2 = <&cpu0_opp_table>; ++ }; ++ }; ++ ++ cpu0_opp_table: opp_table0 { ++ compatible = "operating-points-v2"; ++ opp-shared; ++ ++ opp@600000000 { ++ opp-hz = /bits/ 64 <600000000>; ++ clock-latency-ns = <355000>; ++ opp-suspend; ++ }; ++ ++ opp@900000000 { ++ opp-hz = /bits/ 64 <900000000>; ++ clock-latency-ns = <355000>; ++ }; ++ ++ opp@1200000000 { ++ opp-hz = /bits/ 64 <1200000000>; ++ clock-latency-ns = <355000>; + }; + }; + }; +diff --git a/drivers/clk/bcm/Kconfig b/drivers/clk/bcm/Kconfig +index 4c4bd85f707c..e40bd19da22b 100644 +--- a/drivers/clk/bcm/Kconfig ++++ b/drivers/clk/bcm/Kconfig +@@ -63,3 +63,11 @@ config CLK_BCM_SR + default ARCH_BCM_IPROC + help + Enable common clock framework support for the Broadcom Stingray SoC ++ ++config CLK_RASPBERRYPI_CPU ++ bool "Raspberry Pi CPU clock driver" ++ depends on ARCH_BCM2835 || (COMPILE_TEST && OF) ++ depends on RASPBERRYPI_FIRMWARE=y ++ help ++ This enables support for the RPi CPU clock which can be adjusted ++ via the RPi firmware. +diff --git a/drivers/clk/bcm/Makefile b/drivers/clk/bcm/Makefile +index 002661d39128..a028b0a90b6e 100644 +--- a/drivers/clk/bcm/Makefile ++++ b/drivers/clk/bcm/Makefile +@@ -8,6 +8,7 @@ obj-$(CONFIG_COMMON_CLK_IPROC) += clk-iproc-armpll.o clk-iproc-pll.o clk-iproc-a + obj-$(CONFIG_ARCH_BCM2835) += clk-bcm2835.o + obj-$(CONFIG_ARCH_BCM2835) += clk-bcm2835-aux.o + obj-$(CONFIG_ARCH_BCM_53573) += clk-bcm53573-ilp.o ++obj-$(CONFIG_CLK_RASPBERRYPI_CPU) += clk-raspberrypi.o + obj-$(CONFIG_CLK_BCM_CYGNUS) += clk-cygnus.o + obj-$(CONFIG_CLK_BCM_HR2) += clk-hr2.o + obj-$(CONFIG_CLK_BCM_NSP) += clk-nsp.o +diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c +new file mode 100644 +index 000000000000..046efc822a59 +--- /dev/null ++++ b/drivers/clk/bcm/clk-raspberrypi.c +@@ -0,0 +1,138 @@ ++// SPDX-License-Identifier: GPL-2.0+ ++/* ++ * Raspberry Pi CPU clock driver ++ * ++ * Copyright (C) 2018 Stefan Wahren ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define VCMSG_ID_ARM_CLOCK 0x000000003 /* Clock/Voltage ID's */ ++ ++struct rpi_cpu_clkgen { ++ struct clk_hw hw; ++ struct rpi_firmware *fw; ++}; ++ ++/* tag part of the message */ ++struct prop { ++ u32 id; /* the ID of the clock/voltage to get or set */ ++ u32 val; /* the value (e.g. rate (in Hz)) to set */ ++} __packed; ++ ++static int rpi_cpu_clock_property(struct rpi_firmware *fw, u32 tag, u32 *val) ++{ ++ int ret; ++ struct prop msg = { ++ .id = VCMSG_ID_ARM_CLOCK, ++ .val = *val, ++ }; ++ ++ ret = rpi_firmware_property(fw, tag, &msg, sizeof(msg)); ++ if (ret) ++ return ret; ++ ++ *val = msg.val; ++ ++ return 0; ++} ++ ++static unsigned long rpi_cpu_get_rate(struct clk_hw *hw, ++ unsigned long parent_rate) ++{ ++ struct rpi_cpu_clkgen *cpu = container_of(hw, struct rpi_cpu_clkgen, hw); ++ u32 rate = 0; ++ ++ rpi_cpu_clock_property(cpu->fw, RPI_FIRMWARE_GET_CLOCK_RATE, &rate); ++ ++ return rate; ++} ++ ++static long rpi_cpu_round_rate(struct clk_hw *hw, unsigned long rate, ++ unsigned long *parent_rate) ++{ ++ return rate; ++} ++ ++static int rpi_cpu_set_rate(struct clk_hw *hw, unsigned long rate, ++ unsigned long parent_rate) ++{ ++ struct rpi_cpu_clkgen *cpu = container_of(hw, struct rpi_cpu_clkgen, hw); ++ u32 new_rate = rate; ++ ++ return rpi_cpu_clock_property(cpu->fw, RPI_FIRMWARE_SET_CLOCK_RATE, ++ &new_rate); ++} ++ ++static const struct clk_ops rpi_cpu_ops = { ++ .recalc_rate = rpi_cpu_get_rate, ++ .round_rate = rpi_cpu_round_rate, ++ .set_rate = rpi_cpu_set_rate, ++}; ++ ++static int rpi_cpu_probe(struct platform_device *pdev) ++{ ++ struct device *dev = &pdev->dev; ++ struct device_node *fw_node; ++ struct rpi_cpu_clkgen *cpu; ++ struct clk_init_data *init; ++ int ret; ++ ++ cpu = devm_kzalloc(dev, sizeof(*cpu), GFP_KERNEL); ++ if (!cpu) ++ return -ENOMEM; ++ ++ init = devm_kzalloc(dev, sizeof(*init), GFP_KERNEL); ++ if (!init) ++ return -ENOMEM; ++ ++ fw_node = of_find_compatible_node(NULL, NULL, ++ "raspberrypi,bcm2835-firmware"); ++ if (!fw_node) { ++ dev_err(dev, "Missing firmware node\n"); ++ return -ENOENT; ++ } ++ ++ cpu->fw = rpi_firmware_get(fw_node); ++ of_node_put(fw_node); ++ if (!cpu->fw) ++ return -EPROBE_DEFER; ++ ++ init->name = dev->of_node->name; ++ init->ops = &rpi_cpu_ops; ++ ++ cpu->hw.init = init; ++ ret = devm_clk_hw_register(dev, &cpu->hw); ++ if (ret) ++ return ret; ++ ++ return of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get, ++ &cpu->hw); ++} ++ ++static const struct of_device_id rpi_cpu_of_match[] = { ++ { .compatible = "raspberrypi,bcm2835-cpu", }, ++ {}, ++}; ++MODULE_DEVICE_TABLE(of, rpi_cpu_of_match); ++ ++static struct platform_driver rpi_cpu_driver = { ++ .driver = { ++ .name = "raspberrypi-cpu", ++ .of_match_table = rpi_cpu_of_match, ++ }, ++ .probe = rpi_cpu_probe, ++}; ++builtin_platform_driver(rpi_cpu_driver); ++ ++MODULE_AUTHOR("Stefan Wahren "); ++MODULE_DESCRIPTION("Raspberry Pi CPU clock driver"); ++MODULE_LICENSE("GPL v2"); +-- +2.17.0 + diff --git a/kernel-aarch64-debug.config b/kernel-aarch64-debug.config index 79872f45a..3fd70ca24 100644 --- a/kernel-aarch64-debug.config +++ b/kernel-aarch64-debug.config @@ -918,6 +918,7 @@ CONFIG_CLEANCACHE=y CONFIG_CLKDEV_LOOKUP=y # CONFIG_CLK_HSDK is not set # CONFIG_CLK_QORIQ is not set +CONFIG_CLK_RASPBERRYPI_CPU=y CONFIG_CLK_SP810=y CONFIG_CLKSRC_VERSATILE=y CONFIG_CLK_VEXPRESS_OSC=y diff --git a/kernel-aarch64.config b/kernel-aarch64.config index b635706df..dd0ff6467 100644 --- a/kernel-aarch64.config +++ b/kernel-aarch64.config @@ -918,6 +918,7 @@ CONFIG_CLEANCACHE=y CONFIG_CLKDEV_LOOKUP=y # CONFIG_CLK_HSDK is not set # CONFIG_CLK_QORIQ is not set +CONFIG_CLK_RASPBERRYPI_CPU=y CONFIG_CLK_SP810=y CONFIG_CLKSRC_VERSATILE=y CONFIG_CLK_VEXPRESS_OSC=y diff --git a/kernel-armv7hl-debug.config b/kernel-armv7hl-debug.config index ab8a752bf..61c6171b2 100644 --- a/kernel-armv7hl-debug.config +++ b/kernel-armv7hl-debug.config @@ -958,6 +958,7 @@ CONFIG_CIFS_XATTR=y CONFIG_CLEANCACHE=y # CONFIG_CLK_HSDK is not set # CONFIG_CLK_QORIQ is not set +CONFIG_CLK_RASPBERRYPI_CPU=y CONFIG_CLK_SP810=y CONFIG_CLKSRC_VERSATILE=y CONFIG_CLK_TWL6040=m diff --git a/kernel-armv7hl-lpae-debug.config b/kernel-armv7hl-lpae-debug.config index 171bce527..8cf12a5a6 100644 --- a/kernel-armv7hl-lpae-debug.config +++ b/kernel-armv7hl-lpae-debug.config @@ -929,6 +929,7 @@ CONFIG_CIFS_XATTR=y CONFIG_CLEANCACHE=y # CONFIG_CLK_HSDK is not set # CONFIG_CLK_QORIQ is not set +CONFIG_CLK_RASPBERRYPI_CPU=y CONFIG_CLK_SP810=y CONFIG_CLKSRC_VERSATILE=y CONFIG_CLK_VEXPRESS_OSC=y diff --git a/kernel-armv7hl-lpae.config b/kernel-armv7hl-lpae.config index 652cebfb8..40507ccba 100644 --- a/kernel-armv7hl-lpae.config +++ b/kernel-armv7hl-lpae.config @@ -928,6 +928,7 @@ CONFIG_CIFS_XATTR=y CONFIG_CLEANCACHE=y # CONFIG_CLK_HSDK is not set # CONFIG_CLK_QORIQ is not set +CONFIG_CLK_RASPBERRYPI_CPU=y CONFIG_CLK_SP810=y CONFIG_CLKSRC_VERSATILE=y CONFIG_CLK_VEXPRESS_OSC=y diff --git a/kernel-armv7hl.config b/kernel-armv7hl.config index 5aa160c69..5418f671f 100644 --- a/kernel-armv7hl.config +++ b/kernel-armv7hl.config @@ -957,6 +957,7 @@ CONFIG_CIFS_XATTR=y CONFIG_CLEANCACHE=y # CONFIG_CLK_HSDK is not set # CONFIG_CLK_QORIQ is not set +CONFIG_CLK_RASPBERRYPI_CPU=y CONFIG_CLK_SP810=y CONFIG_CLKSRC_VERSATILE=y CONFIG_CLK_TWL6040=m diff --git a/kernel.spec b/kernel.spec index 3376abbc2..671215dd5 100644 --- a/kernel.spec +++ b/kernel.spec @@ -605,6 +605,8 @@ Patch330: bcm2837-rpi-initial-3plus-support.patch Patch332: bcm2837-enable-pmu.patch Patch333: bcm2837-lan78xx-fixes.patch +Patch335: bcm2835-cpufreq-add-CPU-frequency-control-driver.patch + # 400 - IBM (ppc/s390x) patches # 500 - Temp fixes/CVEs etc @@ -1854,6 +1856,9 @@ fi # # %changelog +* Sun Jun 3 2018 Peter Robinson +- Initial support for Raspberry Pi cpufreq driver + * Thu May 31 2018 Justin M. Forbes - 4.17.0-0.rc7.git2.1 - Linux v4.17-rc7-43-gdd52cb879063 diff --git a/rebase-notes.txt b/rebase-notes.txt index 27c0aeb92..ce643d917 100644 --- a/rebase-notes.txt +++ b/rebase-notes.txt @@ -1,6 +1,7 @@ Linux 4.17 rebase notes: - Turn off MTD + JFFS2 + extra infiniband options - Back out kernel-bootwrapper changes for power commit f360f7278a753796aec58ade5b149d12e49f8bc1 +- Drop CONFIG_CLK_RASPBERRYPI_CPU and bcm2835-cpufreq-add-CPU-frequency-control-driver.patch Linux 4.16 rebase notes: - Consider turning off all the IMA features? -- cgit From c882c6b527e008727a8d9d7b12069b197e816a9e Mon Sep 17 00:00:00 2001 From: Peter Robinson Date: Mon, 4 Jun 2018 10:07:56 +0100 Subject: add in freqency for the RPi 3B+ to suppoer 1.4ghz, stop dmesg spew --- ...-cpufreq-add-CPU-frequency-control-driver.patch | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bcm2835-cpufreq-add-CPU-frequency-control-driver.patch b/bcm2835-cpufreq-add-CPU-frequency-control-driver.patch index b087998cb..1ab2c7750 100644 --- a/bcm2835-cpufreq-add-CPU-frequency-control-driver.patch +++ b/bcm2835-cpufreq-add-CPU-frequency-control-driver.patch @@ -271,3 +271,31 @@ index 000000000000..046efc822a59 -- 2.17.0 +From 40a82f71737891581dcbe45331d15a29dd3e7805 Mon Sep 17 00:00:00 2001 +From: Peter Robinson +Date: Mon, 4 Jun 2018 09:14:10 +0100 +Subject: [PATCH 7/7] add 1.4 ghz OPP for the 3B+ + +Signed-off-by: Peter Robinson +--- + arch/arm/boot/dts/bcm2837-rpi-3-b-plus.dts | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/arch/arm/boot/dts/bcm2837-rpi-3-b-plus.dts b/arch/arm/boot/dts/bcm2837-rpi-3-b-plus.dts +index 4adb85e66be3..aaefb078f391 100644 +--- a/arch/arm/boot/dts/bcm2837-rpi-3-b-plus.dts ++++ b/arch/arm/boot/dts/bcm2837-rpi-3-b-plus.dts +@@ -106,3 +106,10 @@ + pinctrl-0 = <&uart1_gpio14>; + status = "okay"; + }; ++ ++&cpu0_opp_table { ++ opp@1400000000 { ++ opp-hz = /bits/ 64 <1400000000>; ++ clock-latency-ns = <355000>; ++ }; ++}; +-- +2.17.1 + -- cgit From 1ae48fff502e48163dafcf6f2d7fce8dbc4e3771 Mon Sep 17 00:00:00 2001 From: "Justin M. Forbes" Date: Mon, 4 Jun 2018 09:38:46 -0500 Subject: Linux v4.17 --- configs/fedora/generic/arm/CONFIG_CLK_RASPBERRYPI_CPU | 1 + kernel.spec | 14 +++++++++----- sources | 4 +--- 3 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 configs/fedora/generic/arm/CONFIG_CLK_RASPBERRYPI_CPU diff --git a/configs/fedora/generic/arm/CONFIG_CLK_RASPBERRYPI_CPU b/configs/fedora/generic/arm/CONFIG_CLK_RASPBERRYPI_CPU new file mode 100644 index 000000000..566c678d3 --- /dev/null +++ b/configs/fedora/generic/arm/CONFIG_CLK_RASPBERRYPI_CPU @@ -0,0 +1 @@ +CONFIG_CLK_RASPBERRYPI_CPU=y diff --git a/kernel.spec b/kernel.spec index 671215dd5..2981f4b6e 100644 --- a/kernel.spec +++ b/kernel.spec @@ -6,7 +6,7 @@ Summary: The Linux kernel # For a stable, released kernel, released_kernel should be 1. For rawhide # and/or a kernel built from an rc or git snapshot, released_kernel should # be 0. -%global released_kernel 0 +%global released_kernel 1 # Sign modules on x86. Make sure the config files match this setting if more # architectures are added. @@ -48,7 +48,7 @@ Summary: The Linux kernel # base_sublevel is the kernel version we're starting with and patching # on top of -- for example, 3.1-rc7-git1 starts with a 3.0 base, # which yields a base_sublevel of 0. -%define base_sublevel 16 +%define base_sublevel 17 ## If this is a released kernel ## %if 0%{?released_kernel} @@ -67,9 +67,9 @@ Summary: The Linux kernel # The next upstream release sublevel (base_sublevel+1) %define upstream_sublevel %(echo $((%{base_sublevel} + 1))) # The rc snapshot level -%global rcrev 7 +%global rcrev 0 # The git snapshot level -%define gitrev 2 +%define gitrev 0 # Set rpm version accordingly %define rpmversion 4.%{upstream_sublevel}.0 %endif @@ -122,7 +122,7 @@ Summary: The Linux kernel # Set debugbuildsenabled to 1 for production (build separate debug kernels) # and 0 for rawhide (all kernels are debug kernels). # See also 'make debug' and 'make release'. -%define debugbuildsenabled 0 +%define debugbuildsenabled 1 %if %{with_verbose} %define make_opts V=1 @@ -1856,6 +1856,10 @@ fi # # %changelog +* Mon Jun 04 2018 Justin M. Forbes - 4.17.0-1 +- Linux v4.17 +- Disable debugging options. + * Sun Jun 3 2018 Peter Robinson - Initial support for Raspberry Pi cpufreq driver diff --git a/sources b/sources index fa28b9d41..0144b07e0 100644 --- a/sources +++ b/sources @@ -1,3 +1 @@ -SHA512 (linux-4.16.tar.xz) = ab47849314b177d0eec9dbf261f33972b0d89fb92fb0650130ffa7abc2f36c0fab2d06317dc1683c51a472a9a631573a9b1e7258d6281a2ee189897827f14662 -SHA512 (patch-4.17-rc7.xz) = 1b6f4c32d9ca79ef1b140fff3a49b493e575f36a10098c40d76f7904abff71175eb0448bb46941631ddf4f879bd50f384e7373009ef563abf7e057483a7be36d -SHA512 (patch-4.17-rc7-git2.xz) = ab1f6652eb86569917d1d5d75aa4684cae7f2ac209d9969c1a6aaf9441907441edc4152495bf2b6244daa174aa5b9d78c6eb6005e617dd12fba274c6a3095262 +SHA512 (linux-4.17.tar.xz) = 4d9de340a26155a89ea8773131c76220cc2057f2b5d031b467b60e8b14c1842518e2d60a863d8c695f0f7640f3f18d43826201984a238dade857b6cef79837db -- cgit