Add support for RaspberryPi RP1 PCI device using a DT overlay
Subsystems (8)
Andrea della Porta
maintainerv9 cover Add support for RaspberryPi RP1 PCI device using a DT overlay
RP1 is an MFD chipset that acts as a south-bridge PCIe endpoint sporting a pletora of subdevices (i.e. Ethernet, USB host controller, I2C, PWM, etc.) whose registers are all reachable starting from an offset from the BAR address. The main point here is that while the RP1 as an endpoint itself is discoverable via usual PCI enumeraiton, the devices it contains are not discoverable and must be declared e.g. via the devicetree.
This patchset is an attempt to provide a minimum infrastructure to allow the RP1 chipset to be discovered and perpherals it contains to be added from a devictree overlay loaded during RP1 PCI endpoint enumeration. To ensure compatibility with downstream, a devicetree already comprising the RP1 node is also provided, so it's not strictly necessary to use the dynamically loaded overlay if the devicetree is already fully defined at the origin.
To achieve this modularity, the RP1 node DT definitions are arranged by file inclusion as per following schema (the arrow points to the includer, see also [9]):
rp1-pci.dtso rp1.dtso
^ ^
| |rp1-common.dtsi ----> rp1-nexus.dtsi ----> bcm2712-rpi-5-b.dts
^
|
bcm2712-rpi-5-b-ovl-rp1.dtsFollowup patches should add support for the several peripherals contained in RP1.
This work is based upon dowstream drivers code and the proposal from RH et al. (see [1] and [2]). A similar approach is also pursued in [3].
The patches are ordered as follows:
-PATCHES 1 to 3: add binding schemas for clock, gpio and RP1 peripherals.
They are needed to support the other peripherals, e.g. the ethernet mac depends on a clock generated by RP1 and the phy is reset through the on-board gpio controller.
-PATCH 4 and 5: add clock and gpio device drivers.
-PATCH 6: the devicetree node describing the RP1 chipset. Please
note that this patch should be taken by the same maintainer that will also take patch 8, since the definition it contains is possibly used by the dtso compiled in as binary blob and is closely coupled to the driver.
-PATCH 7: this is the main patch to support RP1 chipset. It can work
either with a fully defined devicetree (i.e. one that already included the rp1 node since boot time) or with a runtime loaded dtb overlay which is linked as binary blob in the driver obj. This duality is useful to comply with both downstream and upstream needs (see [9]). The real dtso is in devicetree folder while the dtso in driver folder is just a placeholder to include the real dtso.
In this way it is possible to check the dtso against dt-bindings. The reason why drivers/misc has been selected as containing folder for this driver can be seen in [6], [7] and [8].
-PATCH 8: add the external clock node (used by RP1) to the main dts.
-PATCH 9: the fully fledged devictree containing also the rp1 node.
This devicetree is functionally similar to the one downstream is using.
-PATCH 10 (OPTIONAL): this patch introduces a new scenario about how
the rp1 node is specified and loaded in DT. On top of the base DT (without rp1 node), the fw loads this overlay and the end result is the same devicetree as in patch 9, which is then passed to the next stage (either the kernel or u-boot/bootloader).
While this patch is not strictly necessary and can therefore be dropped (see [10]), it's not introducing much extra work and maybe can come in handy while debugging.
-PATCH 11: add the relevant kernel CONFIG_ options to defconfig.
-PATCH 12: enable CONFIG_OF_OVERLAY in order for 'make defconfig'
to produce a configuration valid for the RP1 driver. Without this patch, the user has to explicitly enable it since the misc driver depends on OF_OVERLAY.
This patchset is also a first attempt to be more agnostic wrt hardware description standards such as OF devicetree and ACPI, where 'agnostic' means "using DT in coexistence with ACPI", as been already promoted by e.g. AL (see [4]). Although there's currently no evidence it will also run out of the box on purely ACPI system, it is a first step towards that direction.
Many thanks,
Andrea della Porta
Links:
- [1]: https://lpc.events/event/17/contributions/1421/attachments/1337/2680/LPC2023%20Non-discoverable%20devices%20in%20PCI.pdf
- [2]: https://lore.kernel.org/lkml/[email protected]/t/
- [3]: https://lore.kernel.org/all/[email protected]/#t
- [4]: https://lore.kernel.org/all/[email protected]/
- [5]: https://lore.kernel.org/all/[email protected]/
- [6]: https://lore.kernel.org/all/[email protected]/
- [7]: https://lore.kernel.org/all/[email protected]/
- [8]: https://lore.kernel.org/all/2024081356-mutable-everyday-6f9d@gregkh/
- [9]: https://lore.kernel.org/all/Z87wTfChRC5Ruwc0@apocalypse/
- [10]: https://lore.kernel.org/all/CAMEGJJ0f4YUgdWBhxvQ_dquZHztve9KO7pvQjoDWJ3=zd3cgcg@mail.gmail.com/#t
CHANGES IN V9
PATCH RELATED -------------------------------------------------
- Rebased on next-20250422 to avoid errors while compiling the DTBs against v6.15-rcX.
- Dropped patch 3 from V8 ("Add common schema for devices accessible through PCI BARs") because it's already accepted in upstream tree. The cover letter has been adjusted accordingly.
- Patch 6: Style change: added a blank line in the commit comment.
- Patch 7: Added: Acked-by: Bjorn Helgaas <[email protected]> # quirks.c, pci_ids.h
- Patch 9 and 10: added 'broadcom' to the subject.
- Current patch 9 is now in front of every other dts related patches since it's functionally required for later patches to work.
- Patch 12: Added: Reviewed-by: Stefan Wahren <[email protected]>
BINDINGS ------------------------------------------------------
- File renaming: bcm2712-rpi-5-b.dts is now the fully populated board dts (i.e. the one that includes rp1 node), while the overlay-ready one is now bcm2712-rpi-5-b-ovl-rp1.dts.
- bcm2712-rpi-5-b.dts: Added an explanatory comment about the usage of this file.
RP1 CLOCK DRIVER ------------------------------------
- Implemented the delay needed to ensure the pll vco is stable (was a TODO comment).
RP1 MISC DRIVER -----------------------------------
- rp1_pci.c: Capitalized any IRQ occurrences in message strings.
Andrea della Porta (12):
dt-bindings: clock: Add RaspberryPi RP1 clock bindings
dt-bindings: pinctrl: Add RaspberryPi RP1 gpio/pinctrl/pinmux bindings
dt-bindings: misc: Add device specific bindings for RaspberryPi RP1
clk: rp1: Add support for clocks provided by RP1
pinctrl: rp1: Implement RaspberryPi RP1 gpio support
arm64: dts: rp1: Add support for RaspberryPi's RP1 device
misc: rp1: RaspberryPi RP1 misc driver
arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5
arm64: dts: broadcom: Add board DTS for Rpi5 which includes RP1 node
arm64: dts: broadcom: Add overlay for RP1 device
arm64: defconfig: Enable RP1 misc/clock/gpio drivers
arm64: defconfig: Enable OF_OVERLAY option
.../clock/raspberrypi,rp1-clocks.yaml | 58 + .../devicetree/bindings/misc/pci1de4,1.yaml | 137 ++ .../pinctrl/raspberrypi,rp1-gpio.yaml | 198 +++ MAINTAINERS | 8 + arch/arm64/boot/dts/broadcom/Makefile | 4 +- .../dts/broadcom/bcm2712-rpi-5-b-ovl-rp1.dts | 121 ++ .../boot/dts/broadcom/bcm2712-rpi-5-b.dts | 117 +- arch/arm64/boot/dts/broadcom/rp1-common.dtsi | 42 + arch/arm64/boot/dts/broadcom/rp1-nexus.dtsi | 14 + arch/arm64/boot/dts/broadcom/rp1.dtso | 11 + arch/arm64/configs/defconfig | 4 + drivers/clk/Kconfig | 9 + drivers/clk/Makefile | 1 + drivers/clk/clk-rp1.c | 1510 +++++++++++++++++ drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/rp1/Kconfig | 20 + drivers/misc/rp1/Makefile | 3 + drivers/misc/rp1/rp1-pci.dtso | 25 + drivers/misc/rp1/rp1_pci.c | 333 ++++ drivers/pci/quirks.c | 1 + drivers/pinctrl/Kconfig | 11 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-rp1.c | 790 +++++++++ .../clock/raspberrypi,rp1-clocks.h | 61 + include/linux/pci_ids.h | 3 + 26 files changed, 3376 insertions(+), 108 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml create mode 100644 Documentation/devicetree/bindings/misc/pci1de4,1.yaml create mode 100644 Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml create mode 100644 arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b-ovl-rp1.dts create mode 100644 arch/arm64/boot/dts/broadcom/rp1-common.dtsi create mode 100644 arch/arm64/boot/dts/broadcom/rp1-nexus.dtsi create mode 100644 arch/arm64/boot/dts/broadcom/rp1.dtso create mode 100644 drivers/clk/clk-rp1.c create mode 100644 drivers/misc/rp1/Kconfig create mode 100644 drivers/misc/rp1/Makefile create mode 100644 drivers/misc/rp1/rp1-pci.dtso create mode 100644 drivers/misc/rp1/rp1_pci.c create mode 100644 drivers/pinctrl/pinctrl-rp1.c create mode 100644 include/dt-bindings/clock/raspberrypi,rp1-clocks.h
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v9 1/12 dt-bindings: clock: Add RaspberryPi RP1 clock bindings
Add device tree bindings for the clock generator found in RP1 multi function device, and relative entries in MAINTAINERS file.
--- .../clock/raspberrypi,rp1-clocks.yaml | 58 ++++++++++++++++++ .../clock/raspberrypi,rp1-clocks.h | 61 +++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml create mode 100644 include/dt-bindings/clock/raspberrypi,rp1-clocks.h
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +58 -0
@@ -0,0 +1,58 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/raspberrypi,rp1-clocks.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: RaspberryPi RP1 clock generator + +maintainers: + - A. della Porta <[email protected]> + +description: | + The RP1 contains a clock generator designed as three PLLs (CORE, AUDIO, + VIDEO), and each PLL output can be programmed through dividers to generate + the clocks to drive the sub-peripherals embedded inside the chipset. + + Link to datasheet: + https://datasheets.raspberrypi.com/rp1/rp1-peripherals.pdf + +properties: + compatible: + const: raspberrypi,rp1-clocks + + reg: + maxItems: 1 + + '#clock-cells': + const: 1 + description: + The available clocks are defined in + include/dt-bindings/clock/raspberrypi,rp1-clocks.h. + + clocks: + maxItems: 1 + +required: + - compatible + - reg + - '#clock-cells' + - clocks + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/raspberrypi,rp1-clocks.h> + + rp1 { + #address-cells = <2>; + #size-cells = <2>; + + clocks@c040018000 { + compatible = "raspberrypi,rp1-clocks"; + reg = <0xc0 0x40018000 0x0 0x10038>; + #clock-cells = <1>; + clocks = <&clk_rp1_xosc>; + }; + };
include/dt-bindings/clock/raspberrypi,rp1-clocks.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v9 2/12 dt-bindings: pinctrl: Add RaspberryPi RP1 gpio/pinctrl/pinmux bindings
In reply to Andrea della PortaAdd device tree bindings for the gpio/pin/mux controller that is part of the RP1 multi function device, and relative entries in MAINTAINERS file.
--- .../pinctrl/raspberrypi,rp1-gpio.yaml | 198 ++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +198 -0
@@ -0,0 +1,198 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pinctrl/raspberrypi,rp1-gpio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: RaspberryPi RP1 GPIO/Pinconf/Pinmux Controller submodule + +maintainers: + - A. della Porta <[email protected]> + +description: + The RP1 chipset is a Multi Function Device containing, among other + sub-peripherals, a gpio/pinconf/mux controller whose 54 pins are grouped + into 3 banks. + It works also as an interrupt controller for those gpios. + +properties: + compatible: + const: raspberrypi,rp1-gpio + + reg: + maxItems: 3 + description: One reg specifier for each one of the 3 pin banks. + + '#gpio-cells': + description: The first cell is the pin number and the second cell is used + to specify the flags (see include/dt-bindings/gpio/gpio.h). + const: 2 + + gpio-controller: true + + gpio-ranges: + maxItems: 1 + + gpio-line-names: + maxItems: 54 + + interrupts: + maxItems: 3 + description: One interrupt specifier for each one of the 3 pin banks. + + '#interrupt-cells': + description: + Specifies the Bank number [0, 1, 2] and Flags as defined in + include/dt-bindings/interrupt-controller/irq.h. + const: 2 + + interrupt-controller: true + +patternProperties: + '-state$': + oneOf: + - $ref: '#/$defs/raspberrypi-rp1-state' + - patternProperties: + '-pins$': + $ref: '#/$defs/raspberrypi-rp1-state' + additionalProperties: false + +$defs: + raspberrypi-rp1-state: + allOf: + - $ref: pincfg-node.yaml# + - $ref: pinmux-node.yaml# + + description: + Pin controller client devices use pin configuration subnodes (children + and grandchildren) for desired pin configuration. + Client device subnodes use below standard properties. + + properties: + pins: + description: + List of gpio pins affected by the properties specified in this + subnode. + items: + pattern: '^gpio([0-9]|[1-4][0-9]|5[0-3])$' + + function: + enum: [ alt0, alt1, alt2, alt3, alt4, gpio, alt6, alt7, alt8, none, + aaud, dcd0, dpi, dsi0_te_ext, dsi1_te_ext, dsr0, dtr0, gpclk0, + gpclk1, gpclk2, gpclk3, gpclk4, gpclk5, i2c0, i2c1, i2c2, i2c3, + i2c4, i2c5, i2c6, i2s0, i2s1, i2s2, ir, mic, pcie_clkreq_n, + pio, proc_rio, pwm0, pwm1, ri0, sd0, sd1, spi0, spi1, spi2, + spi3, spi4, spi5, spi6, spi7, spi8, uart0, uart1, uart2, uart3, + uart4, uart5, vbus0, vbus1, vbus2, vbus3 ] + + description: + Specify the alternative function to be configured for the specified + pins. + + bias-disable: true + bias-pull-down: true + bias-pull-up: true + input-enable: true + input-schmitt-enable: true + output-enable: true + output-high: true + output-low: true + slew-rate: + description: 0 is slow slew rate, 1 is fast slew rate + enum: [ 0, 1 ] + drive-strength: + enum: [ 2, 4, 8, 12 ] + + additionalProperties: false + +allOf: + - $ref: pinctrl.yaml# + +required: + - reg + - compatible + - '#gpio-cells' + - gpio-controller + - interrupts + - '#interrupt-cells' + - interrupt-controller + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + rp1 { + #address-cells = <2>; + #size-cells = <2>; + + rp1_gpio: pinctrl@c0400d0000 { + reg = <0xc0 0x400d0000 0x0 0xc000>, + <0xc0 0x400e0000 0x0 0xc000>, + <0xc0 0x400f0000 0x0 0xc000>; + compatible = "raspberrypi,rp1-gpio"; + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupts = <0 IRQ_TYPE_LEVEL_HIGH>, + <1 IRQ_TYPE_LEVEL_HIGH>, + <2 IRQ_TYPE_LEVEL_HIGH>; + gpio-line-names = + "ID_SDA", // GPIO0 + "ID_SCL", // GPIO1 + "GPIO2", "GPIO3", "GPIO4", "GPIO5", "GPIO6", + "GPIO7", "GPIO8", "GPIO9", "GPIO10", "GPIO11", + "GPIO12", "GPIO13", "GPIO14", "GPIO15", "GPIO16", + "GPIO17", "GPIO18", "GPIO19", "GPIO20", "GPIO21", + "GPIO22", "GPIO23", "GPIO24", "GPIO25", "GPIO26", + "GPIO27", + "PCIE_RP1_WAKE", // GPIO28 + "FAN_TACH", // GPIO29 + "HOST_SDA", // GPIO30 + "HOST_SCL", // GPIO31 + "ETH_RST_N", // GPIO32 + "", // GPIO33 + "CD0_IO0_MICCLK", // GPIO34 + "CD0_IO0_MICDAT0", // GPIO35 + "RP1_PCIE_CLKREQ_N", // GPIO36 + "", // GPIO37 + "CD0_SDA", // GPIO38 + "CD0_SCL", // GPIO39 + "CD1_SDA", // GPIO40 + "CD1_SCL", // GPIO41 + "USB_VBUS_EN", // GPIO42 + "USB_OC_N", // GPIO43 + "RP1_STAT_LED", // GPIO44 + "FAN_PWM", // GPIO45 + "CD1_IO0_MICCLK", // GPIO46 + "2712_WAKE", // GPIO47 + "CD1_IO1_MICDAT1", // GPIO48 + "EN_MAX_USB_CUR", // GPIO49 + "", // GPIO50 + "", // GPIO51 + "", // GPIO52 + ""; // GPIO53 + + rp1-i2s0-default-state { + function = "i2s0"; + pins = "gpio18", "gpio19", "gpio20", "gpio21"; + bias-disable; + }; + + rp1-uart0-default-state { + txd-pins { + function = "uart0"; + pins = "gpio14"; + bias-disable; + }; + + rxd-pins { + function = "uart0"; + pins = "gpio15"; + bias-pull-up; + }; + }; + }; + };
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v9 3/12 dt-bindings: misc: Add device specific bindings for RaspberryPi RP1
In reply to Andrea della PortaThe RP1 is a MFD that exposes its peripherals through PCI BARs. This schema is intended as minimal support for the clock generator and gpio controller peripherals which are accessible through BAR1.
--- .../devicetree/bindings/misc/pci1de4,1.yaml | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/pci1de4,1.yaml
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +137 -0
@@ -0,0 +1,137 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/misc/pci1de4,1.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: RaspberryPi RP1 MFD PCI device + +maintainers: + - A. della Porta <[email protected]> + +description: + The RaspberryPi RP1 is a PCI multi function device containing + peripherals ranging from Ethernet to USB controller, I2C, SPI + and others. + The peripherals are accessed by addressing the PCI BAR1 region. + +allOf: + - $ref: /schemas/pci/pci-ep-bus.yaml + +properties: + compatible: + additionalItems: true + maxItems: 3 + items: + - const: pci1de4,1 + + '#interrupt-cells': + const: 2 + description: | + Specifies respectively the interrupt number and flags as defined + in include/dt-bindings/interrupt-controller/irq.h. + Since all interrupts are active high, only IRQ_TYPE_LEVEL_HIGH + and IRQ_TYPE_EDGE_RISING can be specified as type flags. + The supported values for the interrupt number are: + - IO BANK0: 0 + - IO BANK1: 1 + - IO BANK2: 2 + - AUDIO IN: 3 + - AUDIO OUT: 4 + - PWM0: 5 + - ETH: 6 + - I2C0: 7 + - I2C1: 8 + - I2C2: 9 + - I2C3: 10 + - I2C4: 11 + - I2C5: 12 + - I2C6: 13 + - I2S0: 14 + - I2S1: 15 + - I2S2: 16 + - SDIO0: 17 + - SDIO1: 18 + - SPI0: 19 + - SPI1: 20 + - SPI2: 21 + - SPI3: 22 + - SPI4: 23 + - SPI5: 24 + - UART0: 25 + - TIMER0: 26 + - TIMER1: 27 + - TIMER2: 28 + - TIMER3: 29 + - USB HOST0: 30 + - USB HOST0-0: 31 + - USB HOST0-1: 32 + - USB HOST0-2: 33 + - USB HOST0-3: 34 + - USB HOST1: 35 + - USB HOST1-0: 36 + - USB HOST1-1: 37 + - USB HOST1-2: 38 + - USB HOST1-3: 39 + - DMA: 40 + - PWM1: 41 + - UART1: 42 + - UART2: 43 + - UART3: 44 + - UART4: 45 + - UART5: 46 + - MIPI0: 47 + - MIPI1: 48 + - VIDEO OUT: 49 + - PIO0: 50 + - PIO1: 51 + - ADC FIFO: 52 + - PCIE OUT: 53 + - SPI6: 54 + - SPI7: 55 + - SPI8: 56 + - PROC MISC: 57 + - SYSCFG: 58 + - CLOCKS DEFAULT: 59 + - VBUSCTRL: 60 + + interrupt-controller: true + +unevaluatedProperties: false + +required: + - compatible + - '#interrupt-cells' + - interrupt-controller + - pci-ep-bus@1 + +examples: + - | + pci { + #address-cells = <3>; + #size-cells = <2>; + + rp1@0,0 { + compatible = "pci1de4,1"; + ranges = <0x01 0x00 0x00000000 0x82010000 0x00 0x00 0x00 0x400000>; + #address-cells = <3>; + #size-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + + pci_ep_bus: pci-ep-bus@1 { + compatible = "simple-bus"; + ranges = <0x00 0x40000000 0x01 0x00 0x00000000 0x00 0x00400000>; + dma-ranges = <0x10 0x00000000 0x43000000 0x10 0x00000000 0x10 0x00000000>; + #address-cells = <2>; + #size-cells = <2>; + + rp1_clocks: clocks@40018000 { + compatible = "raspberrypi,rp1-clocks"; + reg = <0x00 0x40018000 0x0 0x10038>; + #clock-cells = <1>; + clocks = <&clk_rp1_xosc>; + }; + }; + }; + };
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v9 4/12 clk: rp1: Add support for clocks provided by RP1
In reply to Andrea della PortaRaspberryPi RP1 is an MFD providing, among other peripherals, several clock generators and PLLs that drives the sub-peripherals. Add the driver to support the clock providers.
--- MAINTAINERS | 5 + drivers/clk/Kconfig | 9 + drivers/clk/Makefile | 1 + drivers/clk/clk-rp1.c | 1510 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1525 insertions(+) create mode 100644 drivers/clk/clk-rp1.c
MAINTAINERS +5 -0
@@ -20361,6 +20361,11 @@ S: Maintained F: Documentation/devicetree/bindings/media/raspberrypi,rp1-cfe.yaml F: drivers/media/platform/raspberrypi/rp1-cfe/ +RASPBERRY PI RP1 PCI DRIVER +M: Andrea della Porta <[email protected]> +S: Maintained +F: drivers/clk/clk-rp1.c + RC-CORE / LIRC FRAMEWORK M: Sean Young <[email protected]> L: [email protected]
drivers/clk/Kconfig +9 -0
@@ -88,6 +88,15 @@ config COMMON_CLK_RK808 These multi-function devices have two fixed-rate oscillators, clocked at 32KHz each. Clkout1 is always on, Clkout2 can off by control register. +config COMMON_CLK_RP1 + tristate "Raspberry Pi RP1-based clock support" + depends on MISC_RP1 || COMPILE_TEST + default MISC_RP1 + help + Enable common clock framework support for Raspberry Pi RP1. + This multi-function device has 3 main PLLs and several clock + generators to drive the internal sub-peripherals. + config COMMON_CLK_HI655X tristate "Clock driver for Hi655x" if EXPERT depends on (MFD_HI655X_PMIC || COMPILE_TEST)
drivers/clk/Makefile +1 -0
@@ -84,6 +84,7 @@ obj-$(CONFIG_CLK_LS1028A_PLLDIG) += clk-plldig.o obj-$(CONFIG_COMMON_CLK_PWM) += clk-pwm.o obj-$(CONFIG_CLK_QORIQ) += clk-qoriq.o obj-$(CONFIG_COMMON_CLK_RK808) += clk-rk808.o +obj-$(CONFIG_COMMON_CLK_RP1) += clk-rp1.o obj-$(CONFIG_COMMON_CLK_HI655X) += clk-hi655x.o obj-$(CONFIG_COMMON_CLK_S2MPS11) += clk-s2mps11.o obj-$(CONFIG_COMMON_CLK_SCMI) += clk-scmi.o
drivers/clk/clk-rp1.c new file +1510 -0
1,510 lines not on this page · raw message
Signature · 1 line
2.35.3
Re: [PATCH v9 -next 04/12] clk: rp1: Add support for clocks provided by RP1
Am 22.04.25 um 20:53 schrieb Andrea della Porta:
Quoted 5 lines
RaspberryPi RP1 is an MFD providing, among other peripherals, several clock generators and PLLs that drives the sub-peripherals. Add the driver to support the clock providers.
Signed-off-by Andrea della Porta<[email protected]>
Andrea della Porta
maintainerRe: [PATCH v9 -next 04/12] clk: rp1: Add support for clocks provided by RP1
In reply to Andrea della PortaHi Stephen,
Quoted 3 lines · Andrea della Porta
RaspberryPi RP1 is an MFD providing, among other peripherals, several clock generators and PLLs that drives the sub-peripherals. Add the driver to support the clock providers.
Since subsequent patches in the set depends on this one and as the next merge window is approaching, assuming there are no blockers can I kindly ask if you can merge it on your tree for the upcoming pull request?
This patch should apply cleanly to your clk-next branch except for some fuzz lines on MAINTAINERS. Please let me know if you want me to adjust it.
Many thanks,
Andrea
Quoted 1,577 lines
Signed-off-by Andrea della Porta <[email protected]>--- MAINTAINERS | 5 + drivers/clk/Kconfig | 9 + drivers/clk/Makefile | 1 + drivers/clk/clk-rp1.c | 1510 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1525 insertions(+) create mode 100644 drivers/clk/clk-rp1.cMAINTAINERS +5
-0@@ -20361,6 +20361,11 @@ S: Maintained F: Documentation/devicetree/bindings/media/raspberrypi,rp1-cfe.yaml F: drivers/media/platform/raspberrypi/rp1-cfe/ +RASPBERRY PI RP1 PCI DRIVER +M: Andrea della Porta <[email protected]> +S: Maintained +F: drivers/clk/clk-rp1.c + RC-CORE / LIRC FRAMEWORK M: Sean Young <[email protected]> L: [email protected]drivers/clk/Kconfig +9
-0@@ -88,6 +88,15 @@ config COMMON_CLK_RK808 These multi-function devices have two fixed-rate oscillators, clocked at 32KHz each. Clkout1 is always on, Clkout2 can off by control register. +config COMMON_CLK_RP1 + tristate "Raspberry Pi RP1-based clock support" + depends on MISC_RP1 || COMPILE_TEST + default MISC_RP1 + help + Enable common clock framework support for Raspberry Pi RP1. + This multi-function device has 3 main PLLs and several clock + generators to drive the internal sub-peripherals. + config COMMON_CLK_HI655X tristate "Clock driver for Hi655x" if EXPERT depends on (MFD_HI655X_PMIC || COMPILE_TEST)drivers/clk/Makefile +1
-0@@ -84,6 +84,7 @@ obj-$(CONFIG_CLK_LS1028A_PLLDIG) += clk-plldig.o obj-$(CONFIG_COMMON_CLK_PWM) += clk-pwm.o obj-$(CONFIG_CLK_QORIQ) += clk-qoriq.o obj-$(CONFIG_COMMON_CLK_RK808) += clk-rk808.o +obj-$(CONFIG_COMMON_CLK_RP1) += clk-rp1.o obj-$(CONFIG_COMMON_CLK_HI655X) += clk-hi655x.o obj-$(CONFIG_COMMON_CLK_S2MPS11) += clk-s2mps11.o obj-$(CONFIG_COMMON_CLK_SCMI) += clk-scmi.odrivers/clk/clk-rp1.c new file +1510
-0@@ -0,0 +1,1510 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2023 Raspberry Pi Ltd. +* +* Clock driver for RP1 PCIe multifunction chip. +*/ + +#include <linux/bitfield.h> +#include <linux/clk-provider.h> +#include <linux/regmap.h> +#include <linux/math64.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/units.h> + +#include <dt-bindings/clock/raspberrypi,rp1-clocks.h> + +#define PLL_SYS_OFFSET 0x08000 +#define PLL_SYS_CS (PLL_SYS_OFFSET + 0x00) +#define PLL_SYS_PWR (PLL_SYS_OFFSET + 0x04) +#define PLL_SYS_FBDIV_INT (PLL_SYS_OFFSET + 0x08) +#define PLL_SYS_FBDIV_FRAC (PLL_SYS_OFFSET + 0x0c) +#define PLL_SYS_PRIM (PLL_SYS_OFFSET + 0x10) +#define PLL_SYS_SEC (PLL_SYS_OFFSET + 0x14) + +#define PLL_AUDIO_OFFSET 0x0c000 +#define PLL_AUDIO_CS (PLL_AUDIO_OFFSET + 0x00) +#define PLL_AUDIO_PWR (PLL_AUDIO_OFFSET + 0x04) +#define PLL_AUDIO_FBDIV_INT (PLL_AUDIO_OFFSET + 0x08) +#define PLL_AUDIO_FBDIV_FRAC (PLL_AUDIO_OFFSET + 0x0c) +#define PLL_AUDIO_PRIM (PLL_AUDIO_OFFSET + 0x10) +#define PLL_AUDIO_SEC (PLL_AUDIO_OFFSET + 0x14) +#define PLL_AUDIO_TERN (PLL_AUDIO_OFFSET + 0x18) + +#define PLL_VIDEO_OFFSET 0x10000 +#define PLL_VIDEO_CS (PLL_VIDEO_OFFSET + 0x00) +#define PLL_VIDEO_PWR (PLL_VIDEO_OFFSET + 0x04) +#define PLL_VIDEO_FBDIV_INT (PLL_VIDEO_OFFSET + 0x08) +#define PLL_VIDEO_FBDIV_FRAC (PLL_VIDEO_OFFSET + 0x0c) +#define PLL_VIDEO_PRIM (PLL_VIDEO_OFFSET + 0x10) +#define PLL_VIDEO_SEC (PLL_VIDEO_OFFSET + 0x14) + +#define GPCLK_OE_CTRL 0x00000 + +#define CLK_SYS_OFFSET 0x00014 +#define CLK_SYS_CTRL (CLK_SYS_OFFSET + 0x00) +#define CLK_SYS_DIV_INT (CLK_SYS_OFFSET + 0x04) +#define CLK_SYS_SEL (CLK_SYS_OFFSET + 0x0c) + +#define CLK_SLOW_OFFSET 0x00024 +#define CLK_SLOW_SYS_CTRL (CLK_SLOW_OFFSET + 0x00) +#define CLK_SLOW_SYS_DIV_INT (CLK_SLOW_OFFSET + 0x04) +#define CLK_SLOW_SYS_SEL (CLK_SLOW_OFFSET + 0x0c) + +#define CLK_DMA_OFFSET 0x00044 +#define CLK_DMA_CTRL (CLK_DMA_OFFSET + 0x00) +#define CLK_DMA_DIV_INT (CLK_DMA_OFFSET + 0x04) +#define CLK_DMA_SEL (CLK_DMA_OFFSET + 0x0c) + +#define CLK_UART_OFFSET 0x00054 +#define CLK_UART_CTRL (CLK_UART_OFFSET + 0x00) +#define CLK_UART_DIV_INT (CLK_UART_OFFSET + 0x04) +#define CLK_UART_SEL (CLK_UART_OFFSET + 0x0c) + +#define CLK_ETH_OFFSET 0x00064 +#define CLK_ETH_CTRL (CLK_ETH_OFFSET + 0x00) +#define CLK_ETH_DIV_INT (CLK_ETH_OFFSET + 0x04) +#define CLK_ETH_SEL (CLK_ETH_OFFSET + 0x0c) + +#define CLK_PWM0_OFFSET 0x00074 +#define CLK_PWM0_CTRL (CLK_PWM0_OFFSET + 0x00) +#define CLK_PWM0_DIV_INT (CLK_PWM0_OFFSET + 0x04) +#define CLK_PWM0_DIV_FRAC (CLK_PWM0_OFFSET + 0x08) +#define CLK_PWM0_SEL (CLK_PWM0_OFFSET + 0x0c) + +#define CLK_PWM1_OFFSET 0x00084 +#define CLK_PWM1_CTRL (CLK_PWM1_OFFSET + 0x00) +#define CLK_PWM1_DIV_INT (CLK_PWM1_OFFSET + 0x04) +#define CLK_PWM1_DIV_FRAC (CLK_PWM1_OFFSET + 0x08) +#define CLK_PWM1_SEL (CLK_PWM1_OFFSET + 0x0c) + +#define CLK_AUDIO_IN_OFFSET 0x00094 +#define CLK_AUDIO_IN_CTRL (CLK_AUDIO_IN_OFFSET + 0x00) +#define CLK_AUDIO_IN_DIV_INT (CLK_AUDIO_IN_OFFSET + 0x04) +#define CLK_AUDIO_IN_SEL (CLK_AUDIO_IN_OFFSET + 0x0c) + +#define CLK_AUDIO_OUT_OFFSET 0x000a4 +#define CLK_AUDIO_OUT_CTRL (CLK_AUDIO_OUT_OFFSET + 0x00) +#define CLK_AUDIO_OUT_DIV_INT (CLK_AUDIO_OUT_OFFSET + 0x04) +#define CLK_AUDIO_OUT_SEL (CLK_AUDIO_OUT_OFFSET + 0x0c) + +#define CLK_I2S_OFFSET 0x000b4 +#define CLK_I2S_CTRL (CLK_I2S_OFFSET + 0x00) +#define CLK_I2S_DIV_INT (CLK_I2S_OFFSET + 0x04) +#define CLK_I2S_SEL (CLK_I2S_OFFSET + 0x0c) + +#define CLK_MIPI0_CFG_OFFSET 0x000c4 +#define CLK_MIPI0_CFG_CTRL (CLK_MIPI0_CFG_OFFSET + 0x00) +#define CLK_MIPI0_CFG_DIV_INT (CLK_MIPI0_CFG_OFFSET + 0x04) +#define CLK_MIPI0_CFG_SEL (CLK_MIPI0_CFG_OFFSET + 0x0c) + +#define CLK_MIPI1_CFG_OFFSET 0x000d4 +#define CLK_MIPI1_CFG_CTRL (CLK_MIPI1_CFG_OFFSET + 0x00) +#define CLK_MIPI1_CFG_DIV_INT (CLK_MIPI1_CFG_OFFSET + 0x04) +#define CLK_MIPI1_CFG_SEL (CLK_MIPI1_CFG_OFFSET + 0x0c) + +#define CLK_PCIE_AUX_OFFSET 0x000e4 +#define CLK_PCIE_AUX_CTRL (CLK_PCIE_AUX_OFFSET + 0x00) +#define CLK_PCIE_AUX_DIV_INT (CLK_PCIE_AUX_OFFSET + 0x04) +#define CLK_PCIE_AUX_SEL (CLK_PCIE_AUX_OFFSET + 0x0c) + +#define CLK_USBH0_MICROFRAME_OFFSET 0x000f4 +#define CLK_USBH0_MICROFRAME_CTRL (CLK_USBH0_MICROFRAME_OFFSET + 0x00) +#define CLK_USBH0_MICROFRAME_DIV_INT (CLK_USBH0_MICROFRAME_OFFSET + 0x04) +#define CLK_USBH0_MICROFRAME_SEL (CLK_USBH0_MICROFRAME_OFFSET + 0x0c) + +#define CLK_USBH1_MICROFRAME_OFFSET 0x00104 +#define CLK_USBH1_MICROFRAME_CTRL (CLK_USBH1_MICROFRAME_OFFSET + 0x00) +#define CLK_USBH1_MICROFRAME_DIV_INT (CLK_USBH1_MICROFRAME_OFFSET + 0x04) +#define CLK_USBH1_MICROFRAME_SEL (CLK_USBH1_MICROFRAME_OFFSET + 0x0c) + +#define CLK_USBH0_SUSPEND_OFFSET 0x00114 +#define CLK_USBH0_SUSPEND_CTRL (CLK_USBH0_SUSPEND_OFFSET + 0x00) +#define CLK_USBH0_SUSPEND_DIV_INT (CLK_USBH0_SUSPEND_OFFSET + 0x04) +#define CLK_USBH0_SUSPEND_SEL (CLK_USBH0_SUSPEND_OFFSET + 0x0c) + +#define CLK_USBH1_SUSPEND_OFFSET 0x00124 +#define CLK_USBH1_SUSPEND_CTRL (CLK_USBH1_SUSPEND_OFFSET + 0x00) +#define CLK_USBH1_SUSPEND_DIV_INT (CLK_USBH1_SUSPEND_OFFSET + 0x04) +#define CLK_USBH1_SUSPEND_SEL (CLK_USBH1_SUSPEND_OFFSET + 0x0c) + +#define CLK_ETH_TSU_OFFSET 0x00134 +#define CLK_ETH_TSU_CTRL (CLK_ETH_TSU_OFFSET + 0x00) +#define CLK_ETH_TSU_DIV_INT (CLK_ETH_TSU_OFFSET + 0x04) +#define CLK_ETH_TSU_SEL (CLK_ETH_TSU_OFFSET + 0x0c) + +#define CLK_ADC_OFFSET 0x00144 +#define CLK_ADC_CTRL (CLK_ADC_OFFSET + 0x00) +#define CLK_ADC_DIV_INT (CLK_ADC_OFFSET + 0x04) +#define CLK_ADC_SEL (CLK_ADC_OFFSET + 0x0c) + +#define CLK_SDIO_TIMER_OFFSET 0x00154 +#define CLK_SDIO_TIMER_CTRL (CLK_SDIO_TIMER_OFFSET + 0x00) +#define CLK_SDIO_TIMER_DIV_INT (CLK_SDIO_TIMER_OFFSET + 0x04) +#define CLK_SDIO_TIMER_SEL (CLK_SDIO_TIMER_OFFSET + 0x0c) + +#define CLK_SDIO_ALT_SRC_OFFSET 0x00164 +#define CLK_SDIO_ALT_SRC_CTRL (CLK_SDIO_ALT_SRC_OFFSET + 0x00) +#define CLK_SDIO_ALT_SRC_DIV_INT (CLK_SDIO_ALT_SRC_OFFSET + 0x04) +#define CLK_SDIO_ALT_SRC_SEL (CLK_SDIO_ALT_SRC_OFFSET + 0x0c) + +#define CLK_GP0_OFFSET 0x00174 +#define CLK_GP0_CTRL (CLK_GP0_OFFSET + 0x00) +#define CLK_GP0_DIV_INT (CLK_GP0_OFFSET + 0x04) +#define CLK_GP0_DIV_FRAC (CLK_GP0_OFFSET + 0x08) +#define CLK_GP0_SEL (CLK_GP0_OFFSET + 0x0c) + +#define CLK_GP1_OFFSET 0x00184 +#define CLK_GP1_CTRL (CLK_GP1_OFFSET + 0x00) +#define CLK_GP1_DIV_INT (CLK_GP1_OFFSET + 0x04) +#define CLK_GP1_DIV_FRAC (CLK_GP1_OFFSET + 0x08) +#define CLK_GP1_SEL (CLK_GP1_OFFSET + 0x0c) + +#define CLK_GP2_OFFSET 0x00194 +#define CLK_GP2_CTRL (CLK_GP2_OFFSET + 0x00) +#define CLK_GP2_DIV_INT (CLK_GP2_OFFSET + 0x04) +#define CLK_GP2_DIV_FRAC (CLK_GP2_OFFSET + 0x08) +#define CLK_GP2_SEL (CLK_GP2_OFFSET + 0x0c) + +#define CLK_GP3_OFFSET 0x001a4 +#define CLK_GP3_CTRL (CLK_GP3_OFFSET + 0x00) +#define CLK_GP3_DIV_INT (CLK_GP3_OFFSET + 0x04) +#define CLK_GP3_DIV_FRAC (CLK_GP3_OFFSET + 0x08) +#define CLK_GP3_SEL (CLK_GP3_OFFSET + 0x0c) + +#define CLK_GP4_OFFSET 0x001b4 +#define CLK_GP4_CTRL (CLK_GP4_OFFSET + 0x00) +#define CLK_GP4_DIV_INT (CLK_GP4_OFFSET + 0x04) +#define CLK_GP4_DIV_FRAC (CLK_GP4_OFFSET + 0x08) +#define CLK_GP4_SEL (CLK_GP4_OFFSET + 0x0c) + +#define CLK_GP5_OFFSET 0x001c4 +#define CLK_GP5_CTRL (CLK_GP5_OFFSET + 0x00) +#define CLK_GP5_DIV_INT (CLK_GP5_OFFSET + 0x04) +#define CLK_GP5_DIV_FRAC (CLK_GP5_OFFSET + 0x08) +#define CLK_GP5_SEL (CLK_GP5_OFFSET + 0x0c) + +#define CLK_SYS_RESUS_CTRL 0x0020c + +#define CLK_SLOW_SYS_RESUS_CTRL 0x00214 + +#define FC0_OFFSET 0x0021c +#define FC0_REF_KHZ (FC0_OFFSET + 0x00) +#define FC0_MIN_KHZ (FC0_OFFSET + 0x04) +#define FC0_MAX_KHZ (FC0_OFFSET + 0x08) +#define FC0_DELAY (FC0_OFFSET + 0x0c) +#define FC0_INTERVAL (FC0_OFFSET + 0x10) +#define FC0_SRC (FC0_OFFSET + 0x14) +#define FC0_STATUS (FC0_OFFSET + 0x18) +#define FC0_RESULT (FC0_OFFSET + 0x1c) +#define FC_SIZE 0x20 +#define FC_COUNT 8 +#define FC_NUM (idx, off) ((idx) * 32 + (off)) + +#define AUX_SEL 1 + +#define VIDEO_CLOCKS_OFFSET 0x4000 +#define VIDEO_CLK_VEC_CTRL (VIDEO_CLOCKS_OFFSET + 0x0000) +#define VIDEO_CLK_VEC_DIV_INT (VIDEO_CLOCKS_OFFSET + 0x0004) +#define VIDEO_CLK_VEC_SEL (VIDEO_CLOCKS_OFFSET + 0x000c) +#define VIDEO_CLK_DPI_CTRL (VIDEO_CLOCKS_OFFSET + 0x0010) +#define VIDEO_CLK_DPI_DIV_INT (VIDEO_CLOCKS_OFFSET + 0x0014) +#define VIDEO_CLK_DPI_SEL (VIDEO_CLOCKS_OFFSET + 0x001c) +#define VIDEO_CLK_MIPI0_DPI_CTRL (VIDEO_CLOCKS_OFFSET + 0x0020) +#define VIDEO_CLK_MIPI0_DPI_DIV_INT (VIDEO_CLOCKS_OFFSET + 0x0024) +#define VIDEO_CLK_MIPI0_DPI_DIV_FRAC (VIDEO_CLOCKS_OFFSET + 0x0028) +#define VIDEO_CLK_MIPI0_DPI_SEL (VIDEO_CLOCKS_OFFSET + 0x002c) +#define VIDEO_CLK_MIPI1_DPI_CTRL (VIDEO_CLOCKS_OFFSET + 0x0030) +#define VIDEO_CLK_MIPI1_DPI_DIV_INT (VIDEO_CLOCKS_OFFSET + 0x0034) +#define VIDEO_CLK_MIPI1_DPI_DIV_FRAC (VIDEO_CLOCKS_OFFSET + 0x0038) +#define VIDEO_CLK_MIPI1_DPI_SEL (VIDEO_CLOCKS_OFFSET + 0x003c) + +#define DIV_INT_8BIT_MAX GENMASK(7, 0)/* max divide for most clocks */ +#define DIV_INT_16BIT_MAX GENMASK(15, 0)/* max divide for GPx, PWM */ +#define DIV_INT_24BIT_MAX GENMASK(23, 0)/* max divide for CLK_SYS */ + +#define FC0_STATUS_DONE BIT(4) +#define FC0_STATUS_RUNNING BIT(8) +#define FC0_RESULT_FRAC_SHIFT 5 + +#define PLL_PRIM_DIV1_MASK GENMASK(18, 16) +#define PLL_PRIM_DIV2_MASK GENMASK(14, 12) + +#define PLL_SEC_DIV_MASK GENMASK(12, 8) + +#define PLL_CS_LOCK BIT(31) +#define PLL_CS_REFDIV_MASK BIT(1) + +#define PLL_PWR_PD BIT(0) +#define PLL_PWR_DACPD BIT(1) +#define PLL_PWR_DSMPD BIT(2) +#define PLL_PWR_POSTDIVPD BIT(3) +#define PLL_PWR_4PHASEPD BIT(4) +#define PLL_PWR_VCOPD BIT(5) +#define PLL_PWR_MASK GENMASK(5, 0) + +#define PLL_SEC_RST BIT(16) +#define PLL_SEC_IMPL BIT(31) + +/* PLL phase output for both PRI and SEC */ +#define PLL_PH_EN BIT(4) +#define PLL_PH_PHASE_SHIFT 0 + +#define RP1_PLL_PHASE_0 0 +#define RP1_PLL_PHASE_90 1 +#define RP1_PLL_PHASE_180 2 +#define RP1_PLL_PHASE_270 3 + +/* Clock fields for all clocks */ +#define CLK_CTRL_ENABLE BIT(11) +#define CLK_CTRL_AUXSRC_MASK GENMASK(9, 5) +#define CLK_CTRL_SRC_SHIFT 0 +#define CLK_DIV_FRAC_BITS 16 + +#define LOCK_TIMEOUT_US 100000 +#define LOCK_POLL_DELAY_US 5 + +#define MAX_CLK_PARENTS 16 + +#define PLL_DIV_INVALID 19 +/* +* Secondary PLL channel output divider table. +* Divider values range from 8 to 19, where +* 19 means invalid. +*/ +static const struct clk_div_table pll_sec_div_table[] = { + {0x00 ,PLL_DIV_INVALID }, + {0x01 ,PLL_DIV_INVALID }, + {0x02 ,PLL_DIV_INVALID }, + {0x03 ,PLL_DIV_INVALID }, + {0x04 ,PLL_DIV_INVALID }, + {0x05 ,PLL_DIV_INVALID }, + {0x06 ,PLL_DIV_INVALID }, + {0x07 ,PLL_DIV_INVALID }, + {0x08 ,8 }, + {0x09 ,9 }, + {0x0a ,10 }, + {0x0b ,11 }, + {0x0c ,12 }, + {0x0d ,13 }, + {0x0e ,14 }, + {0x0f ,15 }, + {0x10 ,16 }, + {0x11 ,17 }, + {0x12 ,18 }, + {0x13 ,PLL_DIV_INVALID }, + {0x14 ,PLL_DIV_INVALID }, + {0x15 ,PLL_DIV_INVALID }, + {0x16 ,PLL_DIV_INVALID }, + {0x17 ,PLL_DIV_INVALID }, + {0x18 ,PLL_DIV_INVALID }, + {0x19 ,PLL_DIV_INVALID }, + {0x1a ,PLL_DIV_INVALID }, + {0x1b ,PLL_DIV_INVALID }, + {0x1c ,PLL_DIV_INVALID }, + {0x1d ,PLL_DIV_INVALID }, + {0x1e ,PLL_DIV_INVALID }, + {0x1f ,PLL_DIV_INVALID }, + {0 } +}; + +struct rp1_clockman { +struct device *dev; +void __iomem *regs; +struct regmap *regmap; +spinlock_t regs_lock;/* spinlock for all clocks */ + +/* Must be last */ +struct clk_hw_onecell_data onecell; +}; + +struct rp1_pll_core_data { +u32 cs_reg; +u32 pwr_reg; +u32 fbdiv_int_reg; +u32 fbdiv_frac_reg; +u32 fc0_src; +}; + +struct rp1_pll_data { +u32 ctrl_reg; +u32 fc0_src; +}; + +struct rp1_pll_ph_data { +unsigned int phase; +unsigned int fixed_divider; +u32 ph_reg; +u32 fc0_src; +}; + +struct rp1_pll_divider_data { +u32 sec_reg; +u32 fc0_src; +}; + +struct rp1_clock_data { +int num_std_parents; +int num_aux_parents; +u32 oe_mask; +u32 clk_src_mask; +u32 ctrl_reg; +u32 div_int_reg; +u32 div_frac_reg; +u32 sel_reg; +u32 div_int_max; +unsigned long max_freq; +u32 fc0_src; +}; + +struct rp1_clk_desc { +struct clk_hw *(*clk_register)(struct rp1_clockman *clockman, +struct rp1_clk_desc *desc); +const void *data; +struct clk_hw hw; +struct rp1_clockman *clockman; +unsigned long cached_rate; +struct clk_divider div; +}; + +static inline +void clockman_write (struct rp1_clockman *clockman,u32 reg,u32 val) +{ +regmap_write (clockman->regmap, reg, val); +} + +static inline u32 clockman_read (struct rp1_clockman *clockman,u32 reg) +{ +u32 val; + +regmap_read (clockman->regmap, reg, &val); + +return val; +} + +static int rp1_pll_core_is_on (struct clk_hw *hw) +{ + struct rp1_clk_desc *pll_core = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = pll_core->clockman; +const struct rp1_pll_core_data *data = pll_core->data; +u32 pwr =clockman_read (clockman, data->pwr_reg); + +return (pwr &PLL_PWR_PD ) || (pwr &PLL_PWR_POSTDIVPD ); +} + +static int rp1_pll_core_on (struct clk_hw *hw) +{ + struct rp1_clk_desc *pll_core = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = pll_core->clockman; +const struct rp1_pll_core_data *data = pll_core->data; +u32 fbdiv_frac, val; +int ret; + +spin_lock (&clockman->regs_lock); + +if (!(clockman_read (clockman, data->cs_reg) &PLL_CS_LOCK )) { +/* Reset to a known state. */ +clockman_write (clockman, data->pwr_reg,PLL_PWR_MASK ); +clockman_write (clockman, data->fbdiv_int_reg,20 ); +clockman_write (clockman, data->fbdiv_frac_reg,0 ); +clockman_write (clockman, data->cs_reg,PLL_CS_REFDIV_MASK ); + } + +/* Come out of reset. */ + fbdiv_frac =clockman_read (clockman, data->fbdiv_frac_reg); +clockman_write (clockman, data->pwr_reg, fbdiv_frac ?0 :PLL_PWR_DSMPD ); +spin_unlock (&clockman->regs_lock); + +/* Wait for the PLL to lock. */ + ret =regmap_read_poll_timeout (clockman->regmap, data->cs_reg, val, + val &PLL_CS_LOCK , +LOCK_POLL_DELAY_US ,LOCK_TIMEOUT_US ); +if (ret) +dev_err (clockman->dev,"%s: can't lock PLL\n" , +clk_hw_get_name (hw)); + +return ret; +} + +static void rp1_pll_core_off (struct clk_hw *hw) +{ + struct rp1_clk_desc *pll_core = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = pll_core->clockman; +const struct rp1_pll_core_data *data = pll_core->data; + +spin_lock (&clockman->regs_lock); +clockman_write (clockman, data->pwr_reg,0 ); +spin_unlock (&clockman->regs_lock); +} + +static inline unsigned long get_pll_core_divider (struct clk_hw *hw, +unsigned long rate, +unsigned long parent_rate, +u32 *div_int,u32 *div_frac) +{ +u32 fbdiv_int, fbdiv_frac; +unsigned long calc_rate; +u64 shifted_fbdiv_int; +u64 div_fp64;/* 32.32 fixed point fraction. */ + +/* Factor of reference clock to VCO frequency. */ + div_fp64 = (u64)(rate) <<32 ; + div_fp64 =DIV_ROUND_CLOSEST_ULL (div_fp64, parent_rate); + +/* Round the fractional component at 24 bits. */ + div_fp64 +=1 << (32 -24 -1 ); + + fbdiv_int = div_fp64 >>32 ; + fbdiv_frac = (div_fp64 >> (32 -24 )) &0xffffff ; + + shifted_fbdiv_int = (u64 )fbdiv_int <<24 ; + calc_rate = (u64 )parent_rate * (shifted_fbdiv_int + fbdiv_frac); + calc_rate +=BIT (23 ); + calc_rate >>=24 ; + + *div_int = fbdiv_int; + *div_frac = fbdiv_frac; + +return calc_rate; +} + +static int rp1_pll_core_set_rate (struct clk_hw *hw, +unsigned long rate,unsigned long parent_rate) +{ + struct rp1_clk_desc *pll_core = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = pll_core->clockman; +const struct rp1_pll_core_data *data = pll_core->data; +unsigned long calc_rate; +u32 fbdiv_int, fbdiv_frac; + +/* Disable dividers to start with. */ +spin_lock (&clockman->regs_lock); +clockman_write (clockman, data->fbdiv_int_reg,0 ); +clockman_write (clockman, data->fbdiv_frac_reg,0 ); +spin_unlock (&clockman->regs_lock); + + calc_rate =get_pll_core_divider (hw, rate, parent_rate, + &fbdiv_int, &fbdiv_frac); + +spin_lock (&clockman->regs_lock); +clockman_write (clockman, data->pwr_reg, fbdiv_frac ?0 :PLL_PWR_DSMPD ); +clockman_write (clockman, data->fbdiv_int_reg, fbdiv_int); +clockman_write (clockman, data->fbdiv_frac_reg, fbdiv_frac); +spin_unlock (&clockman->regs_lock); + +/* Check that reference frequency is no greater than VCO / 16. */ +if (WARN_ON_ONCE (parent_rate > (rate /16 ))) +return -ERANGE ; + + pll_core->cached_rate = calc_rate; + +spin_lock (&clockman->regs_lock); +/* Don't need to divide ref unless parent_rate > (output freq / 16) */ +clockman_write (clockman, data->cs_reg, +clockman_read (clockman, data->cs_reg) | +PLL_CS_REFDIV_MASK ); +spin_unlock (&clockman->regs_lock); + +return 0 ; +} + +static unsigned long rp1_pll_core_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ + struct rp1_clk_desc *pll_core = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = pll_core->clockman; +const struct rp1_pll_core_data *data = pll_core->data; +u32 fbdiv_int, fbdiv_frac; +unsigned long calc_rate; +u64 shifted_fbdiv_int; + + fbdiv_int =clockman_read (clockman, data->fbdiv_int_reg); + fbdiv_frac =clockman_read (clockman, data->fbdiv_frac_reg); + + shifted_fbdiv_int = (u64 )fbdiv_int <<24 ; + calc_rate = (u64 )parent_rate * (shifted_fbdiv_int + fbdiv_frac); + calc_rate +=BIT (23 ); + calc_rate >>=24 ; + +return calc_rate; +} + +static long rp1_pll_core_round_rate (struct clk_hw *hw,unsigned long rate, +unsigned long *parent_rate) +{ +u32 fbdiv_int, fbdiv_frac; + +return get_pll_core_divider (hw, rate, *parent_rate, + &fbdiv_int, &fbdiv_frac); +} + +static void get_pll_prim_dividers (unsigned long rate,unsigned long parent_rate, +u32 *divider1,u32 *divider2) +{ +unsigned int div1, div2; +unsigned int best_div1 =7 , best_div2 =7 ; +unsigned long best_rate_diff = +abs_diff (DIV_ROUND_CLOSEST (parent_rate, best_div1 * best_div2), rate); +unsigned long rate_diff, calc_rate; + +for (div1 =1 ; div1 <=7 ; div1++) { +for (div2 =1 ; div2 <= div1; div2++) { + calc_rate =DIV_ROUND_CLOSEST (parent_rate, div1 * div2); + rate_diff =abs_diff (calc_rate, rate); + +if (calc_rate == rate) { + best_div1 = div1; + best_div2 = div2; + goto done; + }else if (rate_diff < best_rate_diff) { + best_div1 = div1; + best_div2 = div2; + best_rate_diff = rate_diff; + } + } + } + +done: + *divider1 = best_div1; + *divider2 = best_div2; +} + +static int rp1_pll_set_rate (struct clk_hw *hw, +unsigned long rate,unsigned long parent_rate) +{ + struct rp1_clk_desc *pll = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = pll->clockman; +const struct rp1_pll_data *data = pll->data; + +u32 prim, prim_div1, prim_div2; + +get_pll_prim_dividers (rate, parent_rate, &prim_div1, &prim_div2); + +spin_lock (&clockman->regs_lock); + prim =clockman_read (clockman, data->ctrl_reg); + prim &= ~PLL_PRIM_DIV1_MASK ; + prim |=FIELD_PREP (PLL_PRIM_DIV1_MASK , prim_div1); + prim &= ~PLL_PRIM_DIV2_MASK ; + prim |=FIELD_PREP (PLL_PRIM_DIV2_MASK , prim_div2); +clockman_write (clockman, data->ctrl_reg, prim); +spin_unlock (&clockman->regs_lock); + +return 0 ; +} + +static unsigned long rp1_pll_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ + struct rp1_clk_desc *pll = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = pll->clockman; +const struct rp1_pll_data *data = pll->data; +u32 prim, prim_div1, prim_div2; + + prim =clockman_read (clockman, data->ctrl_reg); + prim_div1 =FIELD_GET (PLL_PRIM_DIV1_MASK , prim); + prim_div2 =FIELD_GET (PLL_PRIM_DIV2_MASK , prim); + +if (!prim_div1 || !prim_div2) { +dev_err (clockman->dev,"%s: (%s) zero divider value\n" , + __func__,clk_hw_get_name (hw)); +return 0 ; + } + +return DIV_ROUND_CLOSEST (parent_rate, prim_div1 * prim_div2); +} + +static long rp1_pll_round_rate (struct clk_hw *hw,unsigned long rate, +unsigned long *parent_rate) +{ +u32 div1, div2; + +get_pll_prim_dividers (rate, *parent_rate, &div1, &div2); + +return DIV_ROUND_CLOSEST (*parent_rate, div1 * div2); +} + +static int rp1_pll_ph_is_on (struct clk_hw *hw) +{ + struct rp1_clk_desc *pll_ph = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = pll_ph->clockman; +const struct rp1_pll_ph_data *data = pll_ph->data; + +return !!(clockman_read (clockman, data->ph_reg) &PLL_PH_EN ); +} + +static int rp1_pll_ph_on (struct clk_hw *hw) +{ + struct rp1_clk_desc *pll_ph = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = pll_ph->clockman; +const struct rp1_pll_ph_data *data = pll_ph->data; +u32 ph_reg; + +spin_lock (&clockman->regs_lock); + ph_reg =clockman_read (clockman, data->ph_reg); + ph_reg |= data->phase <<PLL_PH_PHASE_SHIFT ; + ph_reg |=PLL_PH_EN ; +clockman_write (clockman, data->ph_reg, ph_reg); +spin_unlock (&clockman->regs_lock); + +return 0 ; +} + +static void rp1_pll_ph_off (struct clk_hw *hw) +{ + struct rp1_clk_desc *pll_ph = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = pll_ph->clockman; +const struct rp1_pll_ph_data *data = pll_ph->data; + +spin_lock (&clockman->regs_lock); +clockman_write (clockman, data->ph_reg, +clockman_read (clockman, data->ph_reg) & ~PLL_PH_EN ); +spin_unlock (&clockman->regs_lock); +} + +static unsigned long rp1_pll_ph_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ + struct rp1_clk_desc *pll_ph = container_of(hw, struct rp1_clk_desc, hw); +const struct rp1_pll_ph_data *data = pll_ph->data; + +return parent_rate / data->fixed_divider; +} + +static long rp1_pll_ph_round_rate (struct clk_hw *hw,unsigned long rate, +unsigned long *parent_rate) +{ + struct rp1_clk_desc *pll_ph = container_of(hw, struct rp1_clk_desc, hw); +const struct rp1_pll_ph_data *data = pll_ph->data; + +return *parent_rate / data->fixed_divider; +} + +static int rp1_pll_divider_is_on (struct clk_hw *hw) +{ + struct rp1_clk_desc *divider = container_of(hw, struct rp1_clk_desc, div.hw); +struct rp1_clockman *clockman = divider->clockman; +const struct rp1_pll_data *data = divider->data; + +return !(clockman_read (clockman, data->ctrl_reg) &PLL_SEC_RST ); +} + +static int rp1_pll_divider_on (struct clk_hw *hw) +{ + struct rp1_clk_desc *divider = container_of(hw, struct rp1_clk_desc, div.hw); +struct rp1_clockman *clockman = divider->clockman; +const struct rp1_pll_data *data = divider->data; + +spin_lock (&clockman->regs_lock); +/* Check the implementation bit is set! */ +WARN_ON (!(clockman_read (clockman, data->ctrl_reg) &PLL_SEC_IMPL )); +clockman_write (clockman, data->ctrl_reg, +clockman_read (clockman, data->ctrl_reg) & ~PLL_SEC_RST ); +spin_unlock (&clockman->regs_lock); + +return 0 ; +} + +static void rp1_pll_divider_off (struct clk_hw *hw) +{ + struct rp1_clk_desc *divider = container_of(hw, struct rp1_clk_desc, div.hw); +struct rp1_clockman *clockman = divider->clockman; +const struct rp1_pll_data *data = divider->data; + +spin_lock (&clockman->regs_lock); +clockman_write (clockman, data->ctrl_reg, +clockman_read (clockman, data->ctrl_reg) |PLL_SEC_RST ); +spin_unlock (&clockman->regs_lock); +} + +static int rp1_pll_divider_set_rate (struct clk_hw *hw, +unsigned long rate, +unsigned long parent_rate) +{ + struct rp1_clk_desc *divider = container_of(hw, struct rp1_clk_desc, div.hw); +struct rp1_clockman *clockman = divider->clockman; +const struct rp1_pll_data *data = divider->data; +u32 div, sec; + + div =DIV_ROUND_UP_ULL (parent_rate, rate); + div =clamp (div,8u ,19u ); + +spin_lock (&clockman->regs_lock); + sec =clockman_read (clockman, data->ctrl_reg); + sec &= ~PLL_SEC_DIV_MASK ; + sec |=FIELD_PREP (PLL_SEC_DIV_MASK , div); + +/* Must keep the divider in reset to change the value. */ + sec |=PLL_SEC_RST ; +clockman_write (clockman, data->ctrl_reg, sec); + +/* must sleep 10 pll vco cycles */ +ndelay (10ULL * div *NSEC_PER_SEC / parent_rate); + + sec &= ~PLL_SEC_RST ; +clockman_write (clockman, data->ctrl_reg, sec); +spin_unlock (&clockman->regs_lock); + +return 0 ; +} + +static unsigned long rp1_pll_divider_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +return clk_divider_ops.recalc_rate (hw, parent_rate); +} + +static long rp1_pll_divider_round_rate (struct clk_hw *hw, +unsigned long rate, +unsigned long *parent_rate) +{ +return clk_divider_ops.round_rate (hw, rate, parent_rate); +} + +static int rp1_clock_is_on (struct clk_hw *hw) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; + +return !!(clockman_read (clockman, data->ctrl_reg) &CLK_CTRL_ENABLE ); +} + +static unsigned long rp1_clock_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; +u64 calc_rate; +u64 div; +u32 frac; + + div =clockman_read (clockman, data->div_int_reg); + frac = (data->div_frac_reg !=0 ) ? +clockman_read (clockman, data->div_frac_reg) :0 ; + +/* If the integer portion of the divider is 0, treat it as 2^16 */ +if (!div) + div =1 <<16 ; + + div = (div <<CLK_DIV_FRAC_BITS ) | (frac >> (32 -CLK_DIV_FRAC_BITS )); + + calc_rate = (u64 )parent_rate <<CLK_DIV_FRAC_BITS ; + calc_rate =div64_u64 (calc_rate, div); + +return calc_rate; +} + +static int rp1_clock_on (struct clk_hw *hw) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; + +spin_lock (&clockman->regs_lock); +clockman_write (clockman, data->ctrl_reg, +clockman_read (clockman, data->ctrl_reg) |CLK_CTRL_ENABLE ); +/* If this is a GPCLK, turn on the output-enable */ +if (data->oe_mask) +clockman_write (clockman,GPCLK_OE_CTRL , +clockman_read (clockman,GPCLK_OE_CTRL ) | data->oe_mask); +spin_unlock (&clockman->regs_lock); + +return 0 ; +} + +static void rp1_clock_off (struct clk_hw *hw) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; + +spin_lock (&clockman->regs_lock); +clockman_write (clockman, data->ctrl_reg, +clockman_read (clockman, data->ctrl_reg) & ~CLK_CTRL_ENABLE ); +/* If this is a GPCLK, turn off the output-enable */ +if (data->oe_mask) +clockman_write (clockman,GPCLK_OE_CTRL , +clockman_read (clockman,GPCLK_OE_CTRL ) & ~data->oe_mask); +spin_unlock (&clockman->regs_lock); +} + +static u32 rp1_clock_choose_div (unsigned long rate,unsigned long parent_rate, +const struct rp1_clock_data *data) +{ +u64 div; + +/* +* Due to earlier rounding, calculated parent_rate may differ from +* expected value. Don't fail on a small discrepancy near unity divide. +*/ +if (!rate || rate > parent_rate + (parent_rate >>CLK_DIV_FRAC_BITS )) +return 0 ; + +/* +* Always express div in fixed-point format for fractional division; +* If no fractional divider is present, the fraction part will be zero. +*/ +if (data->div_frac_reg) { + div = (u64 )parent_rate <<CLK_DIV_FRAC_BITS ; + div =DIV_ROUND_CLOSEST_ULL (div, rate); + }else { + div =DIV_ROUND_CLOSEST_ULL (parent_rate, rate); + div <<=CLK_DIV_FRAC_BITS ; + } + + div =clamp (div, +1ull <<CLK_DIV_FRAC_BITS , + (u64 )data->div_int_max <<CLK_DIV_FRAC_BITS ); + +return div; +} + +static u8 rp1_clock_get_parent (struct clk_hw *hw) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; +u32 sel, ctrl; +u8 parent; + +/* Sel is one-hot, so find the first bit set */ + sel =clockman_read (clockman, data->sel_reg); + parent =ffs (sel) -1 ; + +/* sel == 0 implies the parent clock is not enabled yet. */ +if (!sel) { +/* Read the clock src from the CTRL register instead */ + ctrl =clockman_read (clockman, data->ctrl_reg); + parent = (ctrl & data->clk_src_mask) >>CLK_CTRL_SRC_SHIFT ; + } + +if (parent >= data->num_std_parents) + parent =AUX_SEL ; + +if (parent ==AUX_SEL ) { +/* +* Clock parent is an auxiliary source, so get the parent from +* the AUXSRC register field. +*/ + ctrl =clockman_read (clockman, data->ctrl_reg); + parent =FIELD_GET (CLK_CTRL_AUXSRC_MASK , ctrl); + parent += data->num_std_parents; + } + +return parent; +} + +static int rp1_clock_set_parent (struct clk_hw *hw,u8 index) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; +u32 ctrl, sel; + +spin_lock (&clockman->regs_lock); + ctrl =clockman_read (clockman, data->ctrl_reg); + +if (index >= data->num_std_parents) { +/* This is an aux source request */ +if (index >= data->num_std_parents + data->num_aux_parents) { +spin_unlock (&clockman->regs_lock); +return -EINVAL ; + } + +/* Select parent from aux list */ + ctrl &= ~CLK_CTRL_AUXSRC_MASK ; + ctrl |=FIELD_PREP (CLK_CTRL_AUXSRC_MASK , index - data->num_std_parents); +/* Set src to aux list */ + ctrl &= ~data->clk_src_mask; + ctrl |= (AUX_SEL <<CLK_CTRL_SRC_SHIFT ) & data->clk_src_mask; + }else { + ctrl &= ~data->clk_src_mask; + ctrl |= (index <<CLK_CTRL_SRC_SHIFT ) & data->clk_src_mask; + } + +clockman_write (clockman, data->ctrl_reg, ctrl); +spin_unlock (&clockman->regs_lock); + + sel =rp1_clock_get_parent (hw); +WARN_ONCE (sel != index,"(%s): Parent index req %u returned back %u\n" , +clk_hw_get_name (hw), index, sel); + +return 0 ; +} + +static int rp1_clock_set_rate_and_parent (struct clk_hw *hw, +unsigned long rate, +unsigned long parent_rate, +u8 parent) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; +u32 div =rp1_clock_choose_div (rate, parent_rate, data); + +WARN_ONCE (rate > data->max_freq, +"(%s): Requested rate (%lu) > max rate (%lu)\n" , +clk_hw_get_name (hw), rate, data->max_freq); + +if (WARN_ONCE (!div, +"clk divider calculated as 0! (%s, rate %lu, parent rate %lu)\n" , +clk_hw_get_name (hw), rate, parent_rate)) + div =1 <<CLK_DIV_FRAC_BITS ; + +spin_lock (&clockman->regs_lock); + +clockman_write (clockman, data->div_int_reg, div >>CLK_DIV_FRAC_BITS ); +if (data->div_frac_reg) +clockman_write (clockman, data->div_frac_reg, div << (32 -CLK_DIV_FRAC_BITS )); + +spin_unlock (&clockman->regs_lock); + +if (parent !=0xff ) +rp1_clock_set_parent (hw, parent); + +return 0 ; +} + +static int rp1_clock_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ +return rp1_clock_set_rate_and_parent (hw, rate, parent_rate,0xff ); +} + +static void rp1_clock_choose_div_and_prate (struct clk_hw *hw, +int parent_idx, +unsigned long rate, +unsigned long *prate, +unsigned long *calc_rate) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +const struct rp1_clock_data *data = clock->data; +struct clk_hw *parent; +u32 div; +u64 tmp; + + parent =clk_hw_get_parent_by_index (hw, parent_idx); + + *prate =clk_hw_get_rate (parent); + div =rp1_clock_choose_div (rate, *prate, data); + +if (!div) { + *calc_rate =0 ; +return ; + } + +/* Recalculate to account for rounding errors */ + tmp = (u64)*prate <<CLK_DIV_FRAC_BITS ; + tmp =div_u64 (tmp, div); + +/* +* Prevent overclocks - if all parent choices result in +* a downstream clock in excess of the maximum, then the +* call to set the clock will fail. +*/ +if (tmp > data->max_freq) + *calc_rate =0 ; +else + *calc_rate = tmp; +} + +static int rp1_clock_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ +struct clk_hw *parent, *best_parent =NULL ; +unsigned long best_rate =0 ; +unsigned long best_prate =0 ; +unsigned long best_rate_diff =ULONG_MAX ; +unsigned long prate, calc_rate; +size_t i; + +/* +* If the NO_REPARENT flag is set, try to use existing parent. +*/ +if ((clk_hw_get_flags (hw) &CLK_SET_RATE_NO_REPARENT )) { + i =rp1_clock_get_parent (hw); + parent =clk_hw_get_parent_by_index (hw, i); +if (parent) { +rp1_clock_choose_div_and_prate (hw, i, req->rate, &prate, + &calc_rate); +if (calc_rate >0 ) { + req->best_parent_hw = parent; + req->best_parent_rate = prate; + req->rate = calc_rate; +return 0 ; + } + } + } + +/* +* Select parent clock that results in the closest rate (lower or +* higher) +*/ +for (i =0 ; i <clk_hw_get_num_parents (hw); i++) { + parent =clk_hw_get_parent_by_index (hw, i); +if (!parent) +continue ; + +rp1_clock_choose_div_and_prate (hw, i, req->rate, &prate, + &calc_rate); + +if (abs_diff (calc_rate, req->rate) < best_rate_diff) { + best_parent = parent; + best_prate = prate; + best_rate = calc_rate; + best_rate_diff =abs_diff (calc_rate, req->rate); + +if (best_rate_diff ==0 ) +break ; + } + } + +if (best_rate ==0 ) +return -EINVAL ; + + req->best_parent_hw = best_parent; + req->best_parent_rate = best_prate; + req->rate = best_rate; + +return 0 ; +} + +static const struct clk_ops rp1_pll_core_ops = { + .is_prepared = rp1_pll_core_is_on, + .prepare = rp1_pll_core_on, + .unprepare = rp1_pll_core_off, + .set_rate = rp1_pll_core_set_rate, + .recalc_rate = rp1_pll_core_recalc_rate, + .round_rate = rp1_pll_core_round_rate, +}; + +static const struct clk_ops rp1_pll_ops = { + .set_rate = rp1_pll_set_rate, + .recalc_rate = rp1_pll_recalc_rate, + .round_rate = rp1_pll_round_rate, +}; + +static const struct clk_ops rp1_pll_ph_ops = { + .is_prepared = rp1_pll_ph_is_on, + .prepare = rp1_pll_ph_on, + .unprepare = rp1_pll_ph_off, + .recalc_rate = rp1_pll_ph_recalc_rate, + .round_rate = rp1_pll_ph_round_rate, +}; + +static const struct clk_ops rp1_pll_divider_ops = { + .is_prepared = rp1_pll_divider_is_on, + .prepare = rp1_pll_divider_on, + .unprepare = rp1_pll_divider_off, + .set_rate = rp1_pll_divider_set_rate, + .recalc_rate = rp1_pll_divider_recalc_rate, + .round_rate = rp1_pll_divider_round_rate, +}; + +static const struct clk_ops rp1_clk_ops = { + .is_prepared = rp1_clock_is_on, + .prepare = rp1_clock_on, + .unprepare = rp1_clock_off, + .recalc_rate = rp1_clock_recalc_rate, + .get_parent = rp1_clock_get_parent, + .set_parent = rp1_clock_set_parent, + .set_rate_and_parent = rp1_clock_set_rate_and_parent, + .set_rate = rp1_clock_set_rate, + .determine_rate = rp1_clock_determine_rate, +}; + +static struct clk_hw *rp1_register_pll (struct rp1_clockman *clockman, +struct rp1_clk_desc *desc) +{ +int ret; + + desc->clockman = clockman; + + ret =devm_clk_hw_register (clockman->dev, &desc->hw); + +if (ret) +return ERR_PTR (ret); + +return &desc->hw; +} + +static struct clk_hw *rp1_register_pll_divider (struct rp1_clockman *clockman, +struct rp1_clk_desc *desc) +{ +const struct rp1_pll_data *divider_data = desc->data; +int ret; + + desc->div.reg = clockman->regs + divider_data->ctrl_reg; + desc->div.shift =__ffs (PLL_SEC_DIV_MASK ); + desc->div.width =__ffs (~(PLL_SEC_DIV_MASK >> desc->div.shift)); + desc->div.flags =CLK_DIVIDER_ROUND_CLOSEST ; + desc->div.lock = &clockman->regs_lock; + desc->div.hw.init = desc->hw.init; + desc->div.table = pll_sec_div_table; + + desc->clockman = clockman; + + ret =devm_clk_hw_register (clockman->dev, &desc->div.hw); + +if (ret) +return ERR_PTR (ret); + +return &desc->div.hw; +} + +static struct clk_hw *rp1_register_clock (struct rp1_clockman *clockman, +struct rp1_clk_desc *desc) +{ +const struct rp1_clock_data *clock_data = desc->data; +int ret; + +if (WARN_ON_ONCE (MAX_CLK_PARENTS < + clock_data->num_std_parents + clock_data->num_aux_parents)) +return NULL ; + +/* There must be a gap for the AUX selector */ +if (WARN_ON_ONCE (clock_data->num_std_parents >AUX_SEL && + desc->hw.init->parent_data[AUX_SEL ].index !=-1 )) +return NULL ; + + desc->clockman = clockman; + + ret =devm_clk_hw_register (clockman->dev, &desc->hw); + +if (ret) +return ERR_PTR (ret); + +return &desc->hw; +} + +/* Assignment helper macros for different clock types. */ +#define _REGISTER (f, ...) { .clk_register = f, __VA_ARGS__ } + +#define CLK_DATA (type, ...) .data = &(struct type) { __VA_ARGS__ } + +#define REGISTER_PLL (...) _REGISTER(&rp1_register_pll, \ + __VA_ARGS__) + +#define REGISTER_PLL_DIV (...) _REGISTER(&rp1_register_pll_divider, \ + __VA_ARGS__) + +#define REGISTER_CLK (...) _REGISTER(&rp1_register_clock, \ + __VA_ARGS__) + +static struct rp1_clk_desc pll_sys_core_desc = REGISTER_PLL( + .hw.init =CLK_HW_INIT_PARENTS_DATA ( +"pll_sys_core" , + (const struct clk_parent_data []) { { .index =0 } }, + &rp1_pll_core_ops, +CLK_IS_CRITICAL + ), +CLK_DATA (rp1_pll_core_data , + .cs_reg = PLL_SYS_CS, + .pwr_reg = PLL_SYS_PWR, + .fbdiv_int_reg = PLL_SYS_FBDIV_INT, + .fbdiv_frac_reg = PLL_SYS_FBDIV_FRAC, + ) +); + +static struct rp1_clk_desc pll_audio_core_desc = REGISTER_PLL( + .hw.init =CLK_HW_INIT_PARENTS_DATA ( +"pll_audio_core" , + (const struct clk_parent_data []) { { .index =0 } }, + &rp1_pll_core_ops, +CLK_IS_CRITICAL + ), +CLK_DATA (rp1_pll_core_data , + .cs_reg = PLL_AUDIO_CS, + .pwr_reg = PLL_AUDIO_PWR, + .fbdiv_int_reg = PLL_AUDIO_FBDIV_INT, + .fbdiv_frac_reg = PLL_AUDIO_FBDIV_FRAC, + ) +); + +static struct rp1_clk_desc pll_video_core_desc = REGISTER_PLL( + .hw.init =CLK_HW_INIT_PARENTS_DATA ( +"pll_video_core" , + (const struct clk_parent_data []) { { .index =0 } }, + &rp1_pll_core_ops, +CLK_IS_CRITICAL + ), +CLK_DATA (rp1_pll_core_data , + .cs_reg = PLL_VIDEO_CS, + .pwr_reg = PLL_VIDEO_PWR, + .fbdiv_int_reg = PLL_VIDEO_FBDIV_INT, + .fbdiv_frac_reg = PLL_VIDEO_FBDIV_FRAC, + ) +); + +static struct rp1_clk_desc pll_sys_desc = REGISTER_PLL( + .hw.init =CLK_HW_INIT_PARENTS_DATA ( +"pll_sys" , + (const struct clk_parent_data []) { + { .hw = &pll_sys_core_desc.hw } + }, + &rp1_pll_ops, +0 + ), +CLK_DATA (rp1_pll_data , + .ctrl_reg = PLL_SYS_PRIM, + .fc0_src = FC_NUM(0, 2), + ) +); + +static struct rp1_clk_desc pll_sys_sec_desc = REGISTER_PLL_DIV( + .hw.init =CLK_HW_INIT_PARENTS_DATA ( +"pll_sys_sec" , + (const struct clk_parent_data []) { + { .hw = &pll_sys_core_desc.hw } + }, + &rp1_pll_divider_ops, +0 + ), +CLK_DATA (rp1_pll_data , + .ctrl_reg = PLL_SYS_SEC, + .fc0_src = FC_NUM(2, 2), + ) +); + +static struct rp1_clk_desc clk_eth_tsu_desc = REGISTER_CLK( + .hw.init =CLK_HW_INIT_PARENTS_DATA ( +"clk_eth_tsu" , + (const struct clk_parent_data []) { { .index =0 } }, + &rp1_clk_ops, +0 + ), +CLK_DATA (rp1_clock_data , + .num_std_parents = 0, + .num_aux_parents = 1, + .ctrl_reg = CLK_ETH_TSU_CTRL, + .div_int_reg = CLK_ETH_TSU_DIV_INT, + .sel_reg = CLK_ETH_TSU_SEL, + .div_int_max = DIV_INT_8BIT_MAX, + .max_freq = 50 * HZ_PER_MHZ, + .fc0_src = FC_NUM(5, 7), + ) +); + +static const struct clk_parent_data clk_eth_parents[] = { + { .hw = &pll_sys_sec_desc.div.hw }, + { .hw = &pll_sys_desc.hw }, +}; + +static struct rp1_clk_desc clk_eth_desc = REGISTER_CLK( + .hw.init =CLK_HW_INIT_PARENTS_DATA ( +"clk_eth" , + clk_eth_parents, + &rp1_clk_ops, +0 + ), +CLK_DATA (rp1_clock_data , + .num_std_parents = 0, + .num_aux_parents = 2, + .ctrl_reg = CLK_ETH_CTRL, + .div_int_reg = CLK_ETH_DIV_INT, + .sel_reg = CLK_ETH_SEL, + .div_int_max = DIV_INT_8BIT_MAX, + .max_freq = 125 * HZ_PER_MHZ, + .fc0_src = FC_NUM(4, 6), + ) +); + +static const struct clk_parent_data clk_sys_parents[] = { + { .index =0 }, + { .index =-1 }, + { .hw = &pll_sys_desc.hw }, +}; + +static struct rp1_clk_desc clk_sys_desc = REGISTER_CLK( + .hw.init =CLK_HW_INIT_PARENTS_DATA ( +"clk_sys" , + clk_sys_parents, + &rp1_clk_ops, +CLK_IS_CRITICAL + ), +CLK_DATA (rp1_clock_data , + .num_std_parents = 3, + .num_aux_parents = 0, + .ctrl_reg = CLK_SYS_CTRL, + .div_int_reg = CLK_SYS_DIV_INT, + .sel_reg = CLK_SYS_SEL, + .div_int_max = DIV_INT_24BIT_MAX, + .max_freq = 200 * HZ_PER_MHZ, + .fc0_src = FC_NUM(0, 4), + .clk_src_mask = 0x3, + ) +); + +static struct rp1_clk_desc pll_sys_pri_ph_desc = REGISTER_PLL( + .hw.init =CLK_HW_INIT_PARENTS_DATA ( +"pll_sys_pri_ph" , + (const struct clk_parent_data []) { + { .hw = &pll_sys_desc.hw } + }, + &rp1_pll_ph_ops, +0 + ), +CLK_DATA (rp1_pll_ph_data , + .ph_reg = PLL_SYS_PRIM, + .fixed_divider = 2, + .phase = RP1_PLL_PHASE_0, + .fc0_src = FC_NUM(1, 2), + ) +); + +static struct rp1_clk_desc *const clk_desc_array[] = { + [RP1_PLL_SYS_CORE ] = &pll_sys_core_desc, + [RP1_PLL_AUDIO_CORE ] = &pll_audio_core_desc, + [RP1_PLL_VIDEO_CORE ] = &pll_video_core_desc, + [RP1_PLL_SYS ] = &pll_sys_desc, + [RP1_CLK_ETH_TSU ] = &clk_eth_tsu_desc, + [RP1_CLK_ETH ] = &clk_eth_desc, + [RP1_CLK_SYS ] = &clk_sys_desc, + [RP1_PLL_SYS_PRI_PH ] = &pll_sys_pri_ph_desc, + [RP1_PLL_SYS_SEC ] = &pll_sys_sec_desc, +}; + +static const struct regmap_range rp1_reg_ranges[] = { +regmap_reg_range (PLL_SYS_CS ,PLL_SYS_SEC ), +regmap_reg_range (PLL_AUDIO_CS ,PLL_AUDIO_TERN ), +regmap_reg_range (PLL_VIDEO_CS ,PLL_VIDEO_SEC ), +regmap_reg_range (GPCLK_OE_CTRL ,GPCLK_OE_CTRL ), +regmap_reg_range (CLK_SYS_CTRL ,CLK_SYS_DIV_INT ), +regmap_reg_range (CLK_SYS_SEL ,CLK_SYS_SEL ), +regmap_reg_range (CLK_SLOW_SYS_CTRL ,CLK_SLOW_SYS_DIV_INT ), +regmap_reg_range (CLK_SLOW_SYS_SEL ,CLK_SLOW_SYS_SEL ), +regmap_reg_range (CLK_DMA_CTRL ,CLK_DMA_DIV_INT ), +regmap_reg_range (CLK_DMA_SEL ,CLK_DMA_SEL ), +regmap_reg_range (CLK_UART_CTRL ,CLK_UART_DIV_INT ), +regmap_reg_range (CLK_UART_SEL ,CLK_UART_SEL ), +regmap_reg_range (CLK_ETH_CTRL ,CLK_ETH_DIV_INT ), +regmap_reg_range (CLK_ETH_SEL ,CLK_ETH_SEL ), +regmap_reg_range (CLK_PWM0_CTRL ,CLK_PWM0_SEL ), +regmap_reg_range (CLK_PWM1_CTRL ,CLK_PWM1_SEL ), +regmap_reg_range (CLK_AUDIO_IN_CTRL ,CLK_AUDIO_IN_DIV_INT ), +regmap_reg_range (CLK_AUDIO_IN_SEL ,CLK_AUDIO_IN_SEL ), +regmap_reg_range (CLK_AUDIO_OUT_CTRL ,CLK_AUDIO_OUT_DIV_INT ), +regmap_reg_range (CLK_AUDIO_OUT_SEL ,CLK_AUDIO_OUT_SEL ), +regmap_reg_range (CLK_I2S_CTRL ,CLK_I2S_DIV_INT ), +regmap_reg_range (CLK_I2S_SEL ,CLK_I2S_SEL ), +regmap_reg_range (CLK_MIPI0_CFG_CTRL ,CLK_MIPI0_CFG_DIV_INT ), +regmap_reg_range (CLK_MIPI0_CFG_SEL ,CLK_MIPI0_CFG_SEL ), +regmap_reg_range (CLK_MIPI1_CFG_CTRL ,CLK_MIPI1_CFG_DIV_INT ), +regmap_reg_range (CLK_MIPI1_CFG_SEL ,CLK_MIPI1_CFG_SEL ), +regmap_reg_range (CLK_PCIE_AUX_CTRL ,CLK_PCIE_AUX_DIV_INT ), +regmap_reg_range (CLK_PCIE_AUX_SEL ,CLK_PCIE_AUX_SEL ), +regmap_reg_range (CLK_USBH0_MICROFRAME_CTRL ,CLK_USBH0_MICROFRAME_DIV_INT ), +regmap_reg_range (CLK_USBH0_MICROFRAME_SEL ,CLK_USBH0_MICROFRAME_SEL ), +regmap_reg_range (CLK_USBH1_MICROFRAME_CTRL ,CLK_USBH1_MICROFRAME_DIV_INT ), +regmap_reg_range (CLK_USBH1_MICROFRAME_SEL ,CLK_USBH1_MICROFRAME_SEL ), +regmap_reg_range (CLK_USBH0_SUSPEND_CTRL ,CLK_USBH0_SUSPEND_DIV_INT ), +regmap_reg_range (CLK_USBH0_SUSPEND_SEL ,CLK_USBH0_SUSPEND_SEL ), +regmap_reg_range (CLK_USBH1_SUSPEND_CTRL ,CLK_USBH1_SUSPEND_DIV_INT ), +regmap_reg_range (CLK_USBH1_SUSPEND_SEL ,CLK_USBH1_SUSPEND_SEL ), +regmap_reg_range (CLK_ETH_TSU_CTRL ,CLK_ETH_TSU_DIV_INT ), +regmap_reg_range (CLK_ETH_TSU_SEL ,CLK_ETH_TSU_SEL ), +regmap_reg_range (CLK_ADC_CTRL ,CLK_ADC_DIV_INT ), +regmap_reg_range (CLK_ADC_SEL ,CLK_ADC_SEL ), +regmap_reg_range (CLK_SDIO_TIMER_CTRL ,CLK_SDIO_TIMER_DIV_INT ), +regmap_reg_range (CLK_SDIO_TIMER_SEL ,CLK_SDIO_TIMER_SEL ), +regmap_reg_range (CLK_SDIO_ALT_SRC_CTRL ,CLK_SDIO_ALT_SRC_DIV_INT ), +regmap_reg_range (CLK_SDIO_ALT_SRC_SEL ,CLK_SDIO_ALT_SRC_SEL ), +regmap_reg_range (CLK_GP0_CTRL ,CLK_GP0_SEL ), +regmap_reg_range (CLK_GP1_CTRL ,CLK_GP1_SEL ), +regmap_reg_range (CLK_GP2_CTRL ,CLK_GP2_SEL ), +regmap_reg_range (CLK_GP3_CTRL ,CLK_GP3_SEL ), +regmap_reg_range (CLK_GP4_CTRL ,CLK_GP4_SEL ), +regmap_reg_range (CLK_GP5_CTRL ,CLK_GP5_SEL ), +regmap_reg_range (CLK_SYS_RESUS_CTRL ,CLK_SYS_RESUS_CTRL ), +regmap_reg_range (CLK_SLOW_SYS_RESUS_CTRL ,CLK_SLOW_SYS_RESUS_CTRL ), +regmap_reg_range (FC0_REF_KHZ ,FC0_RESULT ), +regmap_reg_range (VIDEO_CLK_VEC_CTRL ,VIDEO_CLK_VEC_DIV_INT ), +regmap_reg_range (VIDEO_CLK_VEC_SEL ,VIDEO_CLK_DPI_DIV_INT ), +regmap_reg_range (VIDEO_CLK_DPI_SEL ,VIDEO_CLK_MIPI1_DPI_SEL ), +}; + +static const struct regmap_access_table rp1_reg_table = { + .yes_ranges = rp1_reg_ranges, + .n_yes_ranges =ARRAY_SIZE (rp1_reg_ranges), +}; + +static const struct regmap_config rp1_clk_regmap_cfg = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =PLL_VIDEO_SEC , + .name ="rp1-clk" , + .rd_table = &rp1_reg_table, +}; + +static int rp1_clk_probe (struct platform_device *pdev) +{ +const size_t asize =ARRAY_SIZE (clk_desc_array); +struct rp1_clk_desc *desc; +struct device *dev = &pdev->dev; +struct rp1_clockman *clockman; +struct clk_hw **hws; +unsigned int i; + + clockman =devm_kzalloc (dev,struct_size (clockman, onecell.hws, asize), +GFP_KERNEL ); +if (!clockman) +return -ENOMEM ; + +spin_lock_init (&clockman->regs_lock); + clockman->dev = dev; + + clockman->regs =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (clockman->regs)) +return PTR_ERR (clockman->regs); + + clockman->regmap =devm_regmap_init_mmio (dev, clockman->regs, + &rp1_clk_regmap_cfg); +if (IS_ERR (clockman->regmap)) { +dev_err_probe (dev,PTR_ERR (clockman->regmap), +"could not init clock regmap\n" ); +return PTR_ERR (clockman->regmap); + } + + clockman->onecell.num = asize; + hws = clockman->onecell.hws; + +for (i =0 ; i < asize; i++) { + desc = clk_desc_array[i]; +if (desc && desc->clk_register && desc->data) { + hws[i] = desc->clk_register (clockman, desc); +if (IS_ERR_OR_NULL (hws[i])) +dev_err_probe (dev,PTR_ERR (hws[i]), +"Unable to register clock: %s\n" , +clk_hw_get_name (hws[i])); + } + } + +platform_set_drvdata (pdev, clockman); + +return devm_of_clk_add_hw_provider (dev, of_clk_hw_onecell_get, + &clockman->onecell); +} + +static const struct of_device_id rp1_clk_of_match[] = { + { .compatible ="raspberrypi,rp1-clocks" }, + {} +}; +MODULE_DEVICE_TABLE (of, rp1_clk_of_match); + +static struct platform_driver rp1_clk_driver = { + .driver = { + .name ="rp1-clk" , + .of_match_table = rp1_clk_of_match, + }, + .probe = rp1_clk_probe, +}; + +module_platform_driver (rp1_clk_driver); + +MODULE_AUTHOR ("Naushir Patuck <[email protected]>" ); +MODULE_AUTHOR ("Andrea della Porta <[email protected]>" ); +MODULE_DESCRIPTION ("RP1 clock driver" ); +MODULE_LICENSE ("GPL" );Signature · 1 line
2.35.3
Stephen Boyd
maintainerRe: [PATCH v9 -next 04/12] clk: rp1: Add support for clocks provided by RP1
Quoting Andrea della Porta (2025-05-06 13:03:41)
Quoted 7 lines
Hi Stephen,
Quoted 3 lines · Andrea della Porta
RaspberryPi RP1 is an MFD providing, among other peripherals, several clock generators and PLLs that drives the sub-peripherals. Add the driver to support the clock providers.
Quoted 7 lines
Since subsequent patches in the set depends on this one and as the next merge window is approaching, assuming there are no blockers can I kindly ask if you can merge it on your tree for the upcoming pull request?
This patch should apply cleanly to your clk-next branch except for some fuzz lines on
MAINTAINERS. Please let me know if you want me to adjust it.
I need to take the dt-binding header as well so it compiles. What's the plan there? Do you want me to provide a branch with the clk driver and binding header? Or do you want to send a PR to clk tree with the clk driver and the binding header and then base your DTS patches on the binding header and send that to the soc maintainers? I'm also happy to give a Reviewed-by tag if that works for you and then you can just take it through the soc tree.
Andrea della Porta
maintainerRe: [PATCH v9 -next 04/12] clk: rp1: Add support for clocks provided by RP1
Hi Stephen,
Quoted 16 lines · Stephen Boyd
Quoting Andrea della Porta (2025-05-06 13:03:41)
Quoted 7 lines
Hi Stephen,
Quoted 3 lines · Andrea della Porta
RaspberryPi RP1 is an MFD providing, among other peripherals, several clock generators and PLLs that drives the sub-peripherals. Add the driver to support the clock providers.
Quoted 7 lines
Since subsequent patches in the set depends on this one and as the next merge window is approaching, assuming there are no blockers can I kindly ask if you can merge it on your tree for the upcoming pull request?
This patch should apply cleanly to your clk-next branch except for some fuzz lines on
MAINTAINERS. Please let me know if you want me to adjust it.
Quoted 7 lines
I need to take the dt-binding header as well so it compiles. What's the plan there? Do you want me to provide a branch with the clk driver and binding header? Or do you want to send a PR to clk tree with the clk driver and the binding header and then base your DTS patches on the binding header and send that to the soc maintainers? I'm also happy to give a Reviewed-by tag if that works for you and then you can just take it through the soc tree.
Any of those would work for me, but I agree with you, we need a plan because this patchset is crossing the border of several subsystems, and as such there's also other dependencies between patches that will inevitably led to conflicts.
The only decoupled pacthes are the pinctrl driver and its bindings, which I guess could be taken by Linus Walleij, but all others have dependencies on either the bindings (clk driver) or dts (misc driver which embeds the dt overlay, and should be taken by Greg).
So if Florian is willing to take the bindings and since it's already taking many of the patches, it could be reasonable if he takes the entire patchset.
I guess the final decision is up to Florian. Whatever you choose, I'll adjust the patches accordingly but be warned that there will be some (minor) conflicts down the merge path: one being the fact that linux-next bcm2712-rpi-5-b.dts has pcie nodes while Florian's devicetree/next has not. I'll do my best to help fixing those.
Many thanks,
Andrea
-
Stephen Boyd
maintainerRe: [PATCH v9 -next 04/12] clk: rp1: Add support for clocks provided by RP1
In reply to Andrea della PortaQuoting Andrea della Porta (2025-04-22 11:53:13)
Quoted 6 lines
drivers/clk/clk-rp1.c new file +0
-0@@ -0,0 +1,1510 @@
[...]
Quoted 59 lines
drivers/clk/clk-rp1.c new file +59
-0+static u8 rp1_clock_get_parent (struct clk_hw *hw) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; +u32 sel, ctrl; +u8 parent; + +/* Sel is one-hot, so find the first bit set */ + sel =clockman_read (clockman, data->sel_reg); + parent =ffs (sel) -1 ; + +/* sel == 0 implies the parent clock is not enabled yet. */ +if (!sel) { +/* Read the clock src from the CTRL register instead */ + ctrl =clockman_read (clockman, data->ctrl_reg); + parent = (ctrl & data->clk_src_mask) >>CLK_CTRL_SRC_SHIFT ; + } + +if (parent >= data->num_std_parents) + parent =AUX_SEL ; + +if (parent ==AUX_SEL ) { +/* +* Clock parent is an auxiliary source, so get the parent from +* the AUXSRC register field. +*/ + ctrl =clockman_read (clockman, data->ctrl_reg); + parent =FIELD_GET (CLK_CTRL_AUXSRC_MASK , ctrl); + parent += data->num_std_parents; + } + +return parent; +} + +static int rp1_clock_set_parent (struct clk_hw *hw,u8 index) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; +u32 ctrl, sel; + +spin_lock (&clockman->regs_lock); + ctrl =clockman_read (clockman, data->ctrl_reg); + +if (index >= data->num_std_parents) { +/* This is an aux source request */ +if (index >= data->num_std_parents + data->num_aux_parents) { +spin_unlock (&clockman->regs_lock); +return -EINVAL ; + } + +/* Select parent from aux list */ + ctrl &= ~CLK_CTRL_AUXSRC_MASK ; + ctrl |=FIELD_PREP (CLK_CTRL_AUXSRC_MASK , index - data->num_std_parents); +/* Set src to aux list */ + ctrl &= ~data->clk_src_mask; + ctrl |= (AUX_SEL <<CLK_CTRL_SRC_SHIFT ) & data->clk_src_mask; + }else {
drivers/clk/clk-rp1.c line 932
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ ctrl &= ~data->clk_src_mask; + ctrl |= (index <<CLK_CTRL_SRC_SHIFT ) & data->clk_src_mask; + } + +clockman_write (clockman, data->ctrl_reg, ctrl); +spin_unlock (&clockman->regs_lock); + + sel =rp1_clock_get_parent (hw); +WARN_ONCE (sel != index,"(%s): Parent index req %u returned back %u\n" , +clk_hw_get_name (hw), index, sel);
Is this debug code? Why do we need to read back the parent here?
Quoted 7 lines
drivers/clk/clk-rp1.c new file +7
-0+ +return 0 ; +} + +static int rp1_clock_set_rate_and_parent(struct clk_hw *hw, + unsigned long rate, + unsigned long parent_rate,
drivers/clk/clk-rp1.c line 949
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ u8 parent) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; +u32 div =rp1_clock_choose_div (rate, parent_rate, data); + +WARN_ONCE (rate > data->max_freq, +"(%s): Requested rate (%lu) > max rate (%lu)\n" , +clk_hw_get_name (hw), rate, data->max_freq);
If the determine_rate function is implemented properly this is impossible because we round the rate before calling this clk_op.
drivers/clk/clk-rp1.c line 954
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+ +if (WARN_ONCE (!div, +"clk divider calculated as 0! (%s, rate %lu, parent rate %lu)\n" , +clk_hw_get_name (hw), rate, parent_rate)) + div =1 <<CLK_DIV_FRAC_BITS ;
This one also looks weird, does it assume round_rate didn't constrain the incoming rate?
Quoted 162 lines
drivers/clk/clk-rp1.c new file +162
-0+ +spin_lock (&clockman->regs_lock); + +clockman_write (clockman, data->div_int_reg, div >>CLK_DIV_FRAC_BITS ); +if (data->div_frac_reg) +clockman_write (clockman, data->div_frac_reg, div << (32 -CLK_DIV_FRAC_BITS )); + +spin_unlock (&clockman->regs_lock); + +if (parent !=0xff ) +rp1_clock_set_parent (hw, parent); + +return 0 ; +} + +static int rp1_clock_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ +return rp1_clock_set_rate_and_parent (hw, rate, parent_rate,0xff ); +} + +static void rp1_clock_choose_div_and_prate (struct clk_hw *hw, +int parent_idx, +unsigned long rate, +unsigned long *prate, +unsigned long *calc_rate) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +const struct rp1_clock_data *data = clock->data; +struct clk_hw *parent; +u32 div; +u64 tmp; + + parent =clk_hw_get_parent_by_index (hw, parent_idx); + + *prate =clk_hw_get_rate (parent); + div =rp1_clock_choose_div (rate, *prate, data); + +if (!div) { + *calc_rate =0 ; +return ; + } + +/* Recalculate to account for rounding errors */ + tmp = (u64)*prate <<CLK_DIV_FRAC_BITS ; + tmp =div_u64 (tmp, div); + +/* +* Prevent overclocks - if all parent choices result in +* a downstream clock in excess of the maximum, then the +* call to set the clock will fail. +*/ +if (tmp > data->max_freq) + *calc_rate =0 ; +else + *calc_rate = tmp; +} + +static int rp1_clock_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ +struct clk_hw *parent, *best_parent =NULL ; +unsigned long best_rate =0 ; +unsigned long best_prate =0 ; +unsigned long best_rate_diff =ULONG_MAX ; +unsigned long prate, calc_rate; +size_t i; + +/* +* If the NO_REPARENT flag is set, try to use existing parent. +*/ +if ((clk_hw_get_flags (hw) &CLK_SET_RATE_NO_REPARENT )) { + i =rp1_clock_get_parent (hw); + parent =clk_hw_get_parent_by_index (hw, i); +if (parent) { +rp1_clock_choose_div_and_prate (hw, i, req->rate, &prate, + &calc_rate); +if (calc_rate >0 ) { + req->best_parent_hw = parent; + req->best_parent_rate = prate; + req->rate = calc_rate; +return 0 ; + } + } + } + +/* +* Select parent clock that results in the closest rate (lower or +* higher) +*/ +for (i =0 ; i <clk_hw_get_num_parents (hw); i++) { + parent =clk_hw_get_parent_by_index (hw, i); +if (!parent) +continue ; + +rp1_clock_choose_div_and_prate (hw, i, req->rate, &prate, + &calc_rate); + +if (abs_diff (calc_rate, req->rate) < best_rate_diff) { + best_parent = parent; + best_prate = prate; + best_rate = calc_rate; + best_rate_diff =abs_diff (calc_rate, req->rate); + +if (best_rate_diff ==0 ) +break ; + } + } + +if (best_rate ==0 ) +return -EINVAL ; + + req->best_parent_hw = best_parent; + req->best_parent_rate = best_prate; + req->rate = best_rate; + +return 0 ; +} + +static const struct clk_ops rp1_pll_core_ops = { + .is_prepared = rp1_pll_core_is_on, + .prepare = rp1_pll_core_on, + .unprepare = rp1_pll_core_off, + .set_rate = rp1_pll_core_set_rate, + .recalc_rate = rp1_pll_core_recalc_rate, + .round_rate = rp1_pll_core_round_rate, +}; + +static const struct clk_ops rp1_pll_ops = { + .set_rate = rp1_pll_set_rate, + .recalc_rate = rp1_pll_recalc_rate, + .round_rate = rp1_pll_round_rate, +}; + +static const struct clk_ops rp1_pll_ph_ops = { + .is_prepared = rp1_pll_ph_is_on, + .prepare = rp1_pll_ph_on, + .unprepare = rp1_pll_ph_off, + .recalc_rate = rp1_pll_ph_recalc_rate, + .round_rate = rp1_pll_ph_round_rate, +}; + +static const struct clk_ops rp1_pll_divider_ops = { + .is_prepared = rp1_pll_divider_is_on, + .prepare = rp1_pll_divider_on, + .unprepare = rp1_pll_divider_off, + .set_rate = rp1_pll_divider_set_rate, + .recalc_rate = rp1_pll_divider_recalc_rate, + .round_rate = rp1_pll_divider_round_rate, +}; + +static const struct clk_ops rp1_clk_ops = { + .is_prepared = rp1_clock_is_on, + .prepare = rp1_clock_on, + .unprepare = rp1_clock_off, + .recalc_rate = rp1_clock_recalc_rate, + .get_parent = rp1_clock_get_parent, + .set_parent = rp1_clock_set_parent, + .set_rate_and_parent = rp1_clock_set_rate_and_parent, + .set_rate = rp1_clock_set_rate, + .determine_rate = rp1_clock_determine_rate, +};
drivers/clk/clk-rp1.c line 1126
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ +static struct clk_hw *rp1_register_pll (struct rp1_clockman *clockman, +struct rp1_clk_desc *desc) +{ +int ret; + + desc->clockman = clockman; + + ret =devm_clk_hw_register (clockman->dev, &desc->hw); +
Please drop this newline.
Quoted 14 lines
drivers/clk/clk-rp1.c new file +14
-0+if (ret) +return ERR_PTR (ret); + +return &desc->hw; +} + +static struct clk_hw *rp1_register_pll_divider (struct rp1_clockman *clockman, +struct rp1_clk_desc *desc) +{ +const struct rp1_pll_data *divider_data = desc->data; +int ret; + + desc->div.reg = clockman->regs + divider_data->ctrl_reg; + desc->div.shift =__ffs (PLL_SEC_DIV_MASK );
drivers/clk/clk-rp1.c line 1150
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ desc->div.width =__ffs (~(PLL_SEC_DIV_MASK >> desc->div.shift)); + desc->div.flags =CLK_DIVIDER_ROUND_CLOSEST ; + desc->div.lock = &clockman->regs_lock; + desc->div.hw.init = desc->hw.init; + desc->div.table = pll_sec_div_table; + + desc->clockman = clockman; + + ret =devm_clk_hw_register (clockman->dev, &desc->div.hw); +
Please drop this newline.
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+if (ret) +return ERR_PTR (ret); + +return &desc->div.hw; +}
drivers/clk/clk-rp1.c line 1165
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ +static struct clk_hw *rp1_register_clock (struct rp1_clockman *clockman, +struct rp1_clk_desc *desc) +{ +const struct rp1_clock_data *clock_data = desc->data; +int ret; + +if (WARN_ON_ONCE (MAX_CLK_PARENTS < + clock_data->num_std_parents + clock_data->num_aux_parents)) +return NULL ;
Return an error pointer?
drivers/clk/clk-rp1.c line 1169
Quoted 4 lines
drivers/clk/clk-rp1.c new file +4
-0+ +/* There must be a gap for the AUX selector */ +if (WARN_ON_ONCE (clock_data->num_std_parents >AUX_SEL && + desc->hw.init->parent_data[AUX_SEL ].index !=-1 ))
Why is there a gap? Can't the parents that the clk framework sees be
[0, num_std_parents) + [num_std_parents, num_aux_parents + num_std_parents)
without an empty parent in the middle?
Quoted 1 line
+ return NULL;
Return an error pointer?
drivers/clk/clk-rp1.c line 1126
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+ + desc->clockman = clockman; + + ret =devm_clk_hw_register (clockman->dev, &desc->hw); +
Drop this newline please.
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+if (ret) +return ERR_PTR (ret); + +return &desc->hw; +}
[...]
Quoted 18 lines
drivers/clk/clk-rp1.c new file +18
-0+ +static const struct clk_parent_data clk_eth_parents[] = { + { .hw = &pll_sys_sec_desc.div.hw }, + { .hw = &pll_sys_desc.hw }, +}; + +static struct rp1_clk_desc clk_eth_desc = REGISTER_CLK( + .hw.init =CLK_HW_INIT_PARENTS_DATA ( +"clk_eth" , + clk_eth_parents, + &rp1_clk_ops, +0 + ), +CLK_DATA (rp1_clock_data , + .num_std_parents = 0, + .num_aux_parents = 2, + .ctrl_reg = CLK_ETH_CTRL, + .div_int_reg = CLK_ETH_DIV_INT,
drivers/clk/clk-rp1.c line 1316
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ .sel_reg = CLK_ETH_SEL, + .div_int_max = DIV_INT_8BIT_MAX, + .max_freq = 125 * HZ_PER_MHZ, + .fc0_src = FC_NUM(4, 6), + ) +); + +static const struct clk_parent_data clk_sys_parents[] = { + { .index =0 }, + { .index =-1 },
Why is there a gap here?
Quoted 3 lines
drivers/clk/clk-rp1.c new file +3
-0+ { .hw = &pll_sys_desc.hw }, +}; +
[...]
drivers/clk/clk-rp1.c line 1439
Quoted 8 lines
drivers/clk/clk-rp1.c new file +8
-0+ +static const struct regmap_config rp1_clk_regmap_cfg = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =PLL_VIDEO_SEC , + .name ="rp1-clk" , + .rd_table = &rp1_reg_table,
Do you want to set the 'disable_locking' field because you're explicitly locking in this driver?
Quoted 29 lines
drivers/clk/clk-rp1.c new file +29
-0+}; + +static int rp1_clk_probe (struct platform_device *pdev) +{ +const size_t asize =ARRAY_SIZE (clk_desc_array); +struct rp1_clk_desc *desc; +struct device *dev = &pdev->dev; +struct rp1_clockman *clockman; +struct clk_hw **hws; +unsigned int i; + + clockman =devm_kzalloc (dev,struct_size (clockman, onecell.hws, asize), +GFP_KERNEL ); +if (!clockman) +return -ENOMEM ; + +spin_lock_init (&clockman->regs_lock); + clockman->dev = dev; + + clockman->regs =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (clockman->regs)) +return PTR_ERR (clockman->regs); + + clockman->regmap =devm_regmap_init_mmio (dev, clockman->regs, + &rp1_clk_regmap_cfg); +if (IS_ERR (clockman->regmap)) { +dev_err_probe (dev,PTR_ERR (clockman->regmap), +"could not init clock regmap\n" ); +return PTR_ERR (clockman->regmap);
drivers/clk/clk-rp1.c line 1478
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ } + + clockman->onecell.num = asize; + hws = clockman->onecell.hws; + +for (i =0 ; i < asize; i++) { + desc = clk_desc_array[i]; +if (desc && desc->clk_register && desc->data) { + hws[i] = desc->clk_register (clockman, desc); +if (IS_ERR_OR_NULL (hws[i]))
Why is NULL a possible return value?
drivers/clk/clk-rp1.c line 1481
Quoted 3 lines
drivers/clk/clk-rp1.c new file +3
-0+dev_err_probe (dev,PTR_ERR (hws[i]), +"Unable to register clock: %s\n" , +clk_hw_get_name (hws[i]));
We pushed this into the core now so you can drop this. See commit 12a0fd23e870 ("clk: Print an error when clk registration fails").
Quoted 9 lines
drivers/clk/clk-rp1.c new file +9
-0+ } + } + +platform_set_drvdata (pdev, clockman); + +return devm_of_clk_add_hw_provider (dev, of_clk_hw_onecell_get, + &clockman->onecell); +} +
Andrea della Porta
maintainerRe: [PATCH v9 -next 04/12] clk: rp1: Add support for clocks provided by RP1
Hi Stephen,
Quoted 71 lines · Stephen Boyd
Quoting Andrea della Porta (2025-04-22 11:53:13)
Quoted 6 lines
drivers/clk/clk-rp1.c new file +0
-0@@ -0,0 +1,1510 @@[...]
Quoted 63 lines
drivers/clk/clk-rp1.c new file +63
-0+static u8 rp1_clock_get_parent (struct clk_hw *hw) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; +u32 sel, ctrl; +u8 parent; + +/* Sel is one-hot, so find the first bit set */ + sel =clockman_read (clockman, data->sel_reg); + parent =ffs (sel) -1 ; + +/* sel == 0 implies the parent clock is not enabled yet. */ +if (!sel) { +/* Read the clock src from the CTRL register instead */ + ctrl =clockman_read (clockman, data->ctrl_reg); + parent = (ctrl & data->clk_src_mask) >>CLK_CTRL_SRC_SHIFT ; + } + +if (parent >= data->num_std_parents) + parent =AUX_SEL ; + +if (parent ==AUX_SEL ) { +/* +* Clock parent is an auxiliary source, so get the parent from +* the AUXSRC register field. +*/ + ctrl =clockman_read (clockman, data->ctrl_reg); + parent =FIELD_GET (CLK_CTRL_AUXSRC_MASK , ctrl); + parent += data->num_std_parents; + } + +return parent; +} + +static int rp1_clock_set_parent (struct clk_hw *hw,u8 index) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; +u32 ctrl, sel; + +spin_lock (&clockman->regs_lock); + ctrl =clockman_read (clockman, data->ctrl_reg); + +if (index >= data->num_std_parents) { +/* This is an aux source request */ +if (index >= data->num_std_parents + data->num_aux_parents) { +spin_unlock (&clockman->regs_lock); +return -EINVAL ; + } + +/* Select parent from aux list */ + ctrl &= ~CLK_CTRL_AUXSRC_MASK ; + ctrl |=FIELD_PREP (CLK_CTRL_AUXSRC_MASK , index - data->num_std_parents); +/* Set src to aux list */ + ctrl &= ~data->clk_src_mask; + ctrl |= (AUX_SEL <<CLK_CTRL_SRC_SHIFT ) & data->clk_src_mask; + }else { + ctrl &= ~data->clk_src_mask; + ctrl |= (index <<CLK_CTRL_SRC_SHIFT ) & data->clk_src_mask; + } +
Quoted 8 lines
drivers/clk/clk-rp1.c line 932
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+clockman_write (clockman, data->ctrl_reg, ctrl); +spin_unlock (&clockman->regs_lock); + + sel =rp1_clock_get_parent (hw); +WARN_ONCE (sel != index,"(%s): Parent index req %u returned back %u\n" , +clk_hw_get_name (hw), index, sel);Is this debug code? Why do we need to read back the parent here?
This is more of like a sanity check, but I agree that without taking action it is not very helpful. Maybe we can use this check to return an appropriate error code in case the parent check is failing. With appropriate changes, also rp1_clock_set_rate_and_parent() could benefit from that. So I'll drop the WARN and it turn into a conditional return -EINVAL, for the error to be propagated to the CCF.
Quoted 13 lines
Quoted 13 lines
drivers/clk/clk-rp1.c new file +12
-0+ +return 0 ; +} + +static int rp1_clock_set_rate_and_parent (struct clk_hw *hw, +unsigned long rate, +unsigned long parent_rate, +u8 parent) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data;
Quoted 8 lines
drivers/clk/clk-rp1.c line 949
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+u32 div =rp1_clock_choose_div (rate, parent_rate, data); + +WARN_ONCE (rate > data->max_freq, +"(%s): Requested rate (%lu) > max rate (%lu)\n" , +clk_hw_get_name (hw), rate, data->max_freq);If the
determine_ratefunction is implemented properly this is impossible because we round the rate before calling thisclk_op.
Right, rp1_clock_choose_div_and_prate() which is called by rp1_clock_determine_rate() is doing the relevant check on max_freq, so I'll drop this WARN as it should never be true.
Quoted 10 lines
drivers/clk/clk-rp1.c line 954
Quoted 6 lines
drivers/clk/clk-rp1.c new file +5
-0+ +if (WARN_ONCE (!div, +"clk divider calculated as 0! (%s, rate %lu, parent rate %lu)\n" , +clk_hw_get_name (hw), rate, parent_rate)) + div =1 <<CLK_DIV_FRAC_BITS ;This one also looks weird, does it assume
round_ratedidn't constrain the incoming rate?
Indeed, div can be 0 here but rp1_clock_determine_rate() would have returned an error, never reaching this conditional, so I think I can drop it.
Quoted 166 lines
Quoted 166 lines
drivers/clk/clk-rp1.c new file +166
-0+ +spin_lock (&clockman->regs_lock); + +clockman_write (clockman, data->div_int_reg, div >>CLK_DIV_FRAC_BITS ); +if (data->div_frac_reg) +clockman_write (clockman, data->div_frac_reg, div << (32 -CLK_DIV_FRAC_BITS )); + +spin_unlock (&clockman->regs_lock); + +if (parent !=0xff ) +rp1_clock_set_parent (hw, parent); + +return 0 ; +} + +static int rp1_clock_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ +return rp1_clock_set_rate_and_parent (hw, rate, parent_rate,0xff ); +} + +static void rp1_clock_choose_div_and_prate (struct clk_hw *hw, +int parent_idx, +unsigned long rate, +unsigned long *prate, +unsigned long *calc_rate) +{ + struct rp1_clk_desc *clock = container_of(hw, struct rp1_clk_desc, hw); +const struct rp1_clock_data *data = clock->data; +struct clk_hw *parent; +u32 div; +u64 tmp; + + parent =clk_hw_get_parent_by_index (hw, parent_idx); + + *prate =clk_hw_get_rate (parent); + div =rp1_clock_choose_div (rate, *prate, data); + +if (!div) { + *calc_rate =0 ; +return ; + } + +/* Recalculate to account for rounding errors */ + tmp = (u64)*prate <<CLK_DIV_FRAC_BITS ; + tmp =div_u64 (tmp, div); + +/* +* Prevent overclocks - if all parent choices result in +* a downstream clock in excess of the maximum, then the +* call to set the clock will fail. +*/ +if (tmp > data->max_freq) + *calc_rate =0 ; +else + *calc_rate = tmp; +} + +static int rp1_clock_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ +struct clk_hw *parent, *best_parent =NULL ; +unsigned long best_rate =0 ; +unsigned long best_prate =0 ; +unsigned long best_rate_diff =ULONG_MAX ; +unsigned long prate, calc_rate; +size_t i; + +/* +* If the NO_REPARENT flag is set, try to use existing parent. +*/ +if ((clk_hw_get_flags (hw) &CLK_SET_RATE_NO_REPARENT )) { + i =rp1_clock_get_parent (hw); + parent =clk_hw_get_parent_by_index (hw, i); +if (parent) { +rp1_clock_choose_div_and_prate (hw, i, req->rate, &prate, + &calc_rate); +if (calc_rate >0 ) { + req->best_parent_hw = parent; + req->best_parent_rate = prate; + req->rate = calc_rate; +return 0 ; + } + } + } + +/* +* Select parent clock that results in the closest rate (lower or +* higher) +*/ +for (i =0 ; i <clk_hw_get_num_parents (hw); i++) { + parent =clk_hw_get_parent_by_index (hw, i); +if (!parent) +continue ; + +rp1_clock_choose_div_and_prate (hw, i, req->rate, &prate, + &calc_rate); + +if (abs_diff (calc_rate, req->rate) < best_rate_diff) { + best_parent = parent; + best_prate = prate; + best_rate = calc_rate; + best_rate_diff =abs_diff (calc_rate, req->rate); + +if (best_rate_diff ==0 ) +break ; + } + } + +if (best_rate ==0 ) +return -EINVAL ; + + req->best_parent_hw = best_parent; + req->best_parent_rate = best_prate; + req->rate = best_rate; + +return 0 ; +} + +static const struct clk_ops rp1_pll_core_ops = { + .is_prepared = rp1_pll_core_is_on, + .prepare = rp1_pll_core_on, + .unprepare = rp1_pll_core_off, + .set_rate = rp1_pll_core_set_rate, + .recalc_rate = rp1_pll_core_recalc_rate, + .round_rate = rp1_pll_core_round_rate, +}; + +static const struct clk_ops rp1_pll_ops = { + .set_rate = rp1_pll_set_rate, + .recalc_rate = rp1_pll_recalc_rate, + .round_rate = rp1_pll_round_rate, +}; + +static const struct clk_ops rp1_pll_ph_ops = { + .is_prepared = rp1_pll_ph_is_on, + .prepare = rp1_pll_ph_on, + .unprepare = rp1_pll_ph_off, + .recalc_rate = rp1_pll_ph_recalc_rate, + .round_rate = rp1_pll_ph_round_rate, +}; + +static const struct clk_ops rp1_pll_divider_ops = { + .is_prepared = rp1_pll_divider_is_on, + .prepare = rp1_pll_divider_on, + .unprepare = rp1_pll_divider_off, + .set_rate = rp1_pll_divider_set_rate, + .recalc_rate = rp1_pll_divider_recalc_rate, + .round_rate = rp1_pll_divider_round_rate, +}; + +static const struct clk_ops rp1_clk_ops = { + .is_prepared = rp1_clock_is_on, + .prepare = rp1_clock_on, + .unprepare = rp1_clock_off, + .recalc_rate = rp1_clock_recalc_rate, + .get_parent = rp1_clock_get_parent, + .set_parent = rp1_clock_set_parent, + .set_rate_and_parent = rp1_clock_set_rate_and_parent, + .set_rate = rp1_clock_set_rate, + .determine_rate = rp1_clock_determine_rate, +}; + +static struct clk_hw *rp1_register_pll (struct rp1_clockman *clockman, +struct rp1_clk_desc *desc) +{
Quoted 8 lines
drivers/clk/clk-rp1.c line 1126
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+int ret; + + desc->clockman = clockman; + + ret =devm_clk_hw_register (clockman->dev, &desc->hw); +Please drop this newline.
Ack.
Quoted 19 lines
Quoted 19 lines
drivers/clk/clk-rp1.c new file +18
-0+if (ret) +return ERR_PTR (ret); + +return &desc->hw; +} + +static struct clk_hw *rp1_register_pll_divider (struct rp1_clockman *clockman, +struct rp1_clk_desc *desc) +{ +const struct rp1_pll_data *divider_data = desc->data; +int ret; + + desc->div.reg = clockman->regs + divider_data->ctrl_reg; + desc->div.shift =__ffs (PLL_SEC_DIV_MASK ); + desc->div.width =__ffs (~(PLL_SEC_DIV_MASK >> desc->div.shift)); + desc->div.flags =CLK_DIVIDER_ROUND_CLOSEST ; + desc->div.lock = &clockman->regs_lock; + desc->div.hw.init = desc->hw.init;
Quoted 8 lines
drivers/clk/clk-rp1.c line 1150
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+ desc->div.table = pll_sec_div_table; + + desc->clockman = clockman; + + ret =devm_clk_hw_register (clockman->dev, &desc->div.hw); +Please drop this newline.
Ack.
Quoted 10 lines
Quoted 10 lines
drivers/clk/clk-rp1.c new file +9
-0+if (ret) +return ERR_PTR (ret); + +return &desc->div.hw; +} + +static struct clk_hw *rp1_register_clock (struct rp1_clockman *clockman, +struct rp1_clk_desc *desc) +{
Quoted 8 lines
drivers/clk/clk-rp1.c line 1165
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+const struct rp1_clock_data *clock_data = desc->data; +int ret; + +if (WARN_ON_ONCE (MAX_CLK_PARENTS < + clock_data->num_std_parents + clock_data->num_aux_parents)) +return NULL ;Return an error pointer?
Ack.
Quoted 11 lines
drivers/clk/clk-rp1.c line 1169
Quoted 5 lines
drivers/clk/clk-rp1.c new file +4
-0+ +/* There must be a gap for the AUX selector */ +if (WARN_ON_ONCE (clock_data->num_std_parents >AUX_SEL && + desc->hw.init->parent_data[AUX_SEL ].index !=-1 ))Why is there a gap? Can't the parents that the clk framework sees be
[0,
num_std_parents) + [num_std_parents,num_aux_parents+num_std_parents)without an empty parent in the middle?
Not sure why it was done that way. Need to check with Raspberry guys.
Quoted 4 lines
Quoted 2 lines
+ return NULL;
Return an error pointer?
Ack.
Quoted 8 lines
drivers/clk/clk-rp1.c line 1126
Quoted 6 lines
drivers/clk/clk-rp1.c new file +5
-0+ + desc->clockman = clockman; + + ret =devm_clk_hw_register (clockman->dev, &desc->hw); +Drop this newline please.
Ack.
Quoted 29 lines
Quoted 6 lines
drivers/clk/clk-rp1.c new file +5
-0+if (ret) +return ERR_PTR (ret); + +return &desc->hw; +}[...]
Quoted 22 lines
drivers/clk/clk-rp1.c new file +22
-0+ +static const struct clk_parent_data clk_eth_parents[] = { + { .hw = &pll_sys_sec_desc.div.hw }, + { .hw = &pll_sys_desc.hw }, +}; + +static struct rp1_clk_desc clk_eth_desc = REGISTER_CLK( + .hw.init =CLK_HW_INIT_PARENTS_DATA ( +"clk_eth" , + clk_eth_parents, + &rp1_clk_ops, +0 + ), +CLK_DATA (rp1_clock_data , + .num_std_parents = 0, + .num_aux_parents = 2, + .ctrl_reg = CLK_ETH_CTRL, + .div_int_reg = CLK_ETH_DIV_INT, + .sel_reg = CLK_ETH_SEL, + .div_int_max = DIV_INT_8BIT_MAX, + .max_freq = 125 * HZ_PER_MHZ, + .fc0_src = FC_NUM(4, 6),
Quoted 8 lines
drivers/clk/clk-rp1.c line 1316
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+ ) +); + +static const struct clk_parent_data clk_sys_parents[] = { + { .index =0 }, + { .index =-1 },Why is there a gap here?
Same comment as above. Need to check.
Quoted 5 lines
Quoted 4 lines
drivers/clk/clk-rp1.c new file +3
-0+ { .hw = &pll_sys_desc.hw }, +}; +[...]
Quoted 11 lines
drivers/clk/clk-rp1.c line 1439
Quoted 8 lines
drivers/clk/clk-rp1.c new file +8
-0+ +static const struct regmap_config rp1_clk_regmap_cfg = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =PLL_VIDEO_SEC , + .name ="rp1-clk" , + .rd_table = &rp1_reg_table,Do you want to set the '
disable_locking' field because you're explicitly locking in this driver?
Yes, let's avoid redundancy.
Quoted 34 lines
Quoted 34 lines
drivers/clk/clk-rp1.c new file +33
-0+}; + +static int rp1_clk_probe (struct platform_device *pdev) +{ +const size_t asize =ARRAY_SIZE (clk_desc_array); +struct rp1_clk_desc *desc; +struct device *dev = &pdev->dev; +struct rp1_clockman *clockman; +struct clk_hw **hws; +unsigned int i; + + clockman =devm_kzalloc (dev,struct_size (clockman, onecell.hws, asize), +GFP_KERNEL ); +if (!clockman) +return -ENOMEM ; + +spin_lock_init (&clockman->regs_lock); + clockman->dev = dev; + + clockman->regs =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (clockman->regs)) +return PTR_ERR (clockman->regs); + + clockman->regmap =devm_regmap_init_mmio (dev, clockman->regs, + &rp1_clk_regmap_cfg); +if (IS_ERR (clockman->regmap)) { +dev_err_probe (dev,PTR_ERR (clockman->regmap), +"could not init clock regmap\n" ); +return PTR_ERR (clockman->regmap); + } + + clockman->onecell.num = asize; + hws = clockman->onecell.hws;
Quoted 8 lines
drivers/clk/clk-rp1.c line 1478
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+ +for (i =0 ; i < asize; i++) { + desc = clk_desc_array[i]; +if (desc && desc->clk_register && desc->data) { + hws[i] = desc->clk_register (clockman, desc); +if (IS_ERR_OR_NULL (hws[i]))Why is NULL a possible return value?
Right, IS_ERR() would be enough here since devm_clk_hw_register() in the rp1_register*() functions will return an error in faulty cases, and &desc->hw couldn't even be NULL.
Quoted 7 lines
drivers/clk/clk-rp1.c line 1481
Quoted 4 lines
drivers/clk/clk-rp1.c new file +3
-0+dev_err_probe (dev,PTR_ERR (hws[i]), +"Unable to register clock: %s\n" , +clk_hw_get_name (hws[i]));We pushed this into the core now so you can drop this. See commit
12a0fd23e870("clk: Print an error when clk registration fails").
Dropped.
Many thanks,
Andrea
Quoted 10 lines
Quoted 10 lines
drivers/clk/clk-rp1.c new file +9
-0+ } + } + +platform_set_drvdata (pdev, clockman); + +return devm_of_clk_add_hw_provider (dev, of_clk_hw_onecell_get, + &clockman->onecell); +} +
Andrea della Porta
maintainerRe: [PATCH v9 -next 04/12] clk: rp1: Add support for clocks provided by RP1
In reply to Stephen BoydHi Stephen,
Quoted 3 lines · Stephen Boyd
Quoting Andrea della Porta (2025-04-22 11:53:13)
Quoted 2 lines
drivers/clk/clk-rp1.c new file +0
-0
...
Quoted 11 lines
drivers/clk/clk-rp1.c line 1169
Quoted 4 lines
drivers/clk/clk-rp1.c new file +4
-0+ +/* There must be a gap for the AUX selector */ +if (WARN_ON_ONCE (clock_data->num_std_parents >AUX_SEL && + desc->hw.init->parent_data[AUX_SEL ].index !=-1 ))Why is there a gap? Can't the parents that the clk framework sees be
[0,
num_std_parents) + [num_std_parents,num_aux_parents+num_std_parents)without an empty parent in the middle?
The pos 1 in the parent index array is used to select one of the AUX clocks. Besides this, the index maps directly to the value that should be written in hw, avoiding remapping. It's possible to use a numbering scheme like the one you proposed, but in this case we need to complicate the code adding the renumbering where the index is written in hw.
...
Quoted 7 lines
drivers/clk/clk-rp1.c line 1316
Quoted 4 lines
drivers/clk/clk-rp1.c new file +4
-0+ +static const struct clk_parent_data clk_sys_parents[] = { + { .index =0 }, + { .index =-1 },Why is there a gap here?
Same answer as above.
Many thanks,
Andrea
Andrea della Porta
maintainerPATCH v9 5/12 pinctrl: rp1: Implement RaspberryPi RP1 gpio support
In reply to Andrea della PortaThe RP1 is an MFD supporting a gpio controller and /pinmux/pinctrl. Add minimum support for the gpio only portion. The driver is in pinctrl folder since upcoming patches will add the pinmux/pinctrl support where the gpio part can be seen as an addition.
--- MAINTAINERS | 1 + drivers/pinctrl/Kconfig | 11 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-rp1.c | 790 ++++++++++++++++++++++++++++++++++ 4 files changed, 803 insertions(+) create mode 100644 drivers/pinctrl/pinctrl-rp1.c
MAINTAINERS +1 -0
@@ -20365,6 +20365,7 @@ RASPBERRY PI RP1 PCI DRIVER M: Andrea della Porta <[email protected]> S: Maintained F: drivers/clk/clk-rp1.c +F: drivers/pinctrl/pinctrl-rp1.c RC-CORE / LIRC FRAMEWORK M: Sean Young <[email protected]>
drivers/pinctrl/Kconfig +11 -0
@@ -626,6 +626,17 @@ config PINCTRL_MLXBF3 each pin. This driver can also be built as a module called pinctrl-mlxbf3. +config PINCTRL_RP1 + tristate "Pinctrl driver for RP1" + depends on MISC_RP1 + default MISC_RP1 + select PINMUX + select PINCONF + select GENERIC_PINCONF + help + Enable the gpio and pinctrl/mux driver for RaspberryPi RP1 + multi function device. + source "drivers/pinctrl/actions/Kconfig" source "drivers/pinctrl/aspeed/Kconfig" source "drivers/pinctrl/bcm/Kconfig"
drivers/pinctrl/Makefile +1 -0
@@ -49,6 +49,7 @@ obj-$(CONFIG_PINCTRL_PIC32) += pinctrl-pic32.o obj-$(CONFIG_PINCTRL_PISTACHIO) += pinctrl-pistachio.o obj-$(CONFIG_PINCTRL_RK805) += pinctrl-rk805.o obj-$(CONFIG_PINCTRL_ROCKCHIP) += pinctrl-rockchip.o +obj-$(CONFIG_PINCTRL_RP1) += pinctrl-rp1.o obj-$(CONFIG_PINCTRL_SCMI) += pinctrl-scmi.o obj-$(CONFIG_PINCTRL_SINGLE) += pinctrl-single.o obj-$(CONFIG_PINCTRL_ST) += pinctrl-st.o
drivers/pinctrl/pinctrl-rp1.c new file +790 -0
790 lines not on this page · raw message
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v9 6/12 arm64: dts: rp1: Add support for RaspberryPi's RP1 device
In reply to Andrea della PortaRaspberryPi RP1 is a multi function PCI endpoint device that exposes several subperipherals via PCI BAR.
Add a dtb overlay that will be compiled into a binary blob and linked in the RP1 driver.
This overlay offers just minimal support to represent the RP1 device itself, the sub-peripherals will be added by future patches.
--- MAINTAINERS | 1 + arch/arm64/boot/dts/broadcom/rp1-common.dtsi | 42 ++++++++++++++++++++ arch/arm64/boot/dts/broadcom/rp1-nexus.dtsi | 14 +++++++ 3 files changed, 57 insertions(+) create mode 100644 arch/arm64/boot/dts/broadcom/rp1-common.dtsi create mode 100644 arch/arm64/boot/dts/broadcom/rp1-nexus.dtsi
MAINTAINERS +1 -0
@@ -20364,6 +20364,7 @@ F: drivers/media/platform/raspberrypi/rp1-cfe/ RASPBERRY PI RP1 PCI DRIVER M: Andrea della Porta <[email protected]> S: Maintained +F: arch/arm64/boot/dts/broadcom/rp1*.dts* F: drivers/clk/clk-rp1.c F: drivers/pinctrl/pinctrl-rp1.c
arch/arm64/boot/dts/broadcom/rp1-common.dtsi new file +42 -0
42 lines not on this page · raw message
arch/arm64/boot/dts/broadcom/rp1-nexus.dtsi new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) + +rp1_nexus { + compatible = "pci1de4,1"; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x01 0x00 0x00000000 + 0x02000000 0x00 0x00000000 + 0x0 0x400000>; + interrupt-controller; + #interrupt-cells = <2>; + + #include "rp1-common.dtsi" +};
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v9 7/12 misc: rp1: RaspberryPi RP1 misc driver
In reply to Andrea della PortaThe RaspberryPi RP1 is a PCI multi function device containing peripherals ranging from Ethernet to USB controller, I2C, SPI and others.
Implement a bare minimum driver to operate the RP1, leveraging actual OF based driver implementations for the on-board peripherals by loading a devicetree overlay during driver probe if the RP1 node is not already present in the DT.
The peripherals are accessed by mapping MMIO registers starting from PCI BAR1 region.
With the overlay approach we can achieve more generic and agnostic approach to managing this chipset, being that it is a PCI endpoint and could possibly be reused in other hw implementations. The presented approach is also used by Bootlin's Microchip LAN966x patchset (see link) as well, for a similar chipset.
In this case, the inclusion tree for the DT overlay is as follow (the arrow points to the includer):
rp1-pci.dtso <---- rp1-common.dtsi
On the other hand, to ensure compatibility with downstream, this driver can also work with a DT already comprising the RP1 node, so the dynamically loaded overlay will not be used if the DT is already fully defined.
The reason why this driver is contained in drivers/misc has been paved by Bootlin's LAN966X driver, which first used the overlay approach to implement non discoverable peripherals behind a PCI bus. For RP1, the same arguments apply: it's not used as an SoC since the driver code is not running on-chip and is not like an MFD since it does not really need all the MFD infrastructure (shared regs, etc.). So, for this particular use, misc has been proposed and deemed as a good choice. For further details about that please check the links.
This driver is heavily based on downstream code from RaspberryPi Foundation, and the original author is Phil Elwell.
--- MAINTAINERS | 1 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/rp1/Kconfig | 20 ++ drivers/misc/rp1/Makefile | 3 + drivers/misc/rp1/rp1-pci.dtso | 25 +++ drivers/misc/rp1/rp1_pci.c | 333 ++++++++++++++++++++++++++++++++++ drivers/pci/quirks.c | 1 + include/linux/pci_ids.h | 3 + 9 files changed, 388 insertions(+) create mode 100644 drivers/misc/rp1/Kconfig create mode 100644 drivers/misc/rp1/Makefile create mode 100644 drivers/misc/rp1/rp1-pci.dtso create mode 100644 drivers/misc/rp1/rp1_pci.c
MAINTAINERS +1 -0
@@ -20366,6 +20366,7 @@ M: Andrea della Porta <[email protected]> S: Maintained F: arch/arm64/boot/dts/broadcom/rp1*.dts* F: drivers/clk/clk-rp1.c +F: drivers/misc/rp1/ F: drivers/pinctrl/pinctrl-rp1.c RC-CORE / LIRC FRAMEWORK
drivers/misc/Kconfig +1 -0
@@ -660,4 +660,5 @@ source "drivers/misc/uacce/Kconfig" source "drivers/misc/pvpanic/Kconfig" source "drivers/misc/mchp_pci1xxxx/Kconfig" source "drivers/misc/keba/Kconfig" +source "drivers/misc/rp1/Kconfig" endmenu
drivers/misc/Makefile +1 -0
@@ -75,3 +75,4 @@ lan966x-pci-objs := lan966x_pci.o lan966x-pci-objs += lan966x_pci.dtbo.o obj-$(CONFIG_MCHP_LAN966X_PCI) += lan966x-pci.o obj-y += keba/ +obj-$(CONFIG_MISC_RP1) += rp1/
drivers/misc/rp1/Kconfig new file +20 -0
@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# RaspberryPi RP1 misc device +# + +config MISC_RP1 + tristate "RaspberryPi RP1 misc device" + depends on OF_IRQ && OF_OVERLAY && PCI_MSI && PCI_QUIRKS + select PCI_DYNAMIC_OF_NODES + help + Support the RP1 peripheral chip found on Raspberry Pi 5 board. + + This device supports several sub-devices including e.g. Ethernet + controller, USB controller, I2C, SPI and UART. + + The driver is responsible for enabling the DT node once the PCIe + endpoint has been configured, and handling interrupts. + + This driver uses an overlay to load other drivers to support for + RP1 internal sub-devices.
drivers/misc/rp1/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_MISC_RP1) += rp1-pci.o +rp1-pci-objs := rp1_pci.o rp1-pci.dtbo.o
drivers/misc/rp1/rp1-pci.dtso new file +25 -0
@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) + +/* + * The dts overlay is included from the dts directory so + * it can be possible to check it with CHECK_DTBS while + * also compile it from the driver source directory. + */ + +/dts-v1/; +/plugin/; + +/ { + fragment@0 { + target-path=""; + __overlay__ { + compatible = "pci1de4,1"; + #address-cells = <3>; + #size-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + + #include "arm64/broadcom/rp1-common.dtsi" + }; + }; +};
drivers/misc/rp1/rp1_pci.c new file +333 -0
333 lines not on this page · raw message
drivers/pci/quirks.c +1 -0
@@ -6307,6 +6307,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5020, of_pci_make_dev_node);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_XILINX ,0x5021 , of_pci_make_dev_node);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_REDHAT ,0x0005 , of_pci_make_dev_node);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_EFAR ,0x9660 , of_pci_make_dev_node); +DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_RPI ,PCI_DEVICE_ID_RPI_RP1_C0 , of_pci_make_dev_node);/* * Devices known to require a longer delay before first config space access
include/linux/pci_ids.h +3 -0
@@ -2624,6 +2624,9 @@#define PCI_VENDOR_ID_TEKRAM 0x1de1#define PCI_DEVICE_ID_TEKRAM_DC290 0xdc29 +#define PCI_VENDOR_ID_RPI 0x1de4 +#define PCI_DEVICE_ID_RPI_RP1_C0 0x0001 +#define PCI_VENDOR_ID_ALIBABA 0x1ded#define PCI_VENDOR_ID_CXL 0x1e98
Signature · 1 line
2.35.3
Re: [PATCH v9 -next 07/12] misc: rp1: RaspberryPi RP1 misc driver
Quoted 47 lines · Andrea della Porta
The RaspberryPi RP1 is a PCI multi function device containing peripherals ranging from Ethernet to USB controller, I2C, SPI and others.
Implement a bare minimum driver to operate the RP1, leveraging actual OF based driver implementations for the on-board peripherals by loading a devicetree overlay during driver probe if the RP1 node is not already present in the DT.
The peripherals are accessed by mapping MMIO registers starting from PCI BAR1 region.
With the overlay approach we can achieve more generic and agnostic approach to managing this chipset, being that it is a PCI endpoint and could possibly be reused in other hw implementations. The presented approach is also used by Bootlin's Microchip LAN966x patchset (see link) as well, for a similar chipset.
In this case, the inclusion tree for the DT overlay is as follow (the arrow points to the includer):rp1-pci.dtso <----
rp1-common.dtsiOn the other hand, to ensure compatibility with downstream, this driver can also work with a DT already comprising the RP1 node, so the dynamically loaded overlay will not be used if the DT is already fully defined.
The reason why this driver is contained in
drivers/mischas been paved by Bootlin's LAN966X driver, which first used the overlay approach to implement non discoverable peripherals behind a PCI bus. For RP1, the same arguments apply: it's not used as an SoC since the driver code is not running on-chip and is not like an MFD since it does not really need all the MFD infrastructure (shared regs, etc.). So, for this particular use, misc has been proposed and deemed as a good choice. For further details about that please check the links.This driver is heavily based on downstream code from RaspberryPi Foundation, and the original author is Phil Elwell.
Quoted 15 lines
--- MAINTAINERS | 1 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/rp1/Kconfig | 20 ++ drivers/misc/rp1/Makefile | 3 + drivers/misc/rp1/rp1-pci.dtso | 25 +++ drivers/misc/rp1/rp1_pci.c | 333 ++++++++++++++++++++++++++++++++++ drivers/pci/quirks.c | 1 + include/linux/pci_ids.h | 3 + 9 files changed, 388 insertions(+) create mode 100644 drivers/misc/rp1/Kconfig create mode 100644 drivers/misc/rp1/Makefile create mode 100644 drivers/misc/rp1/rp1-pci.dtso create mode 100644 drivers/misc/rp1/rp1_pci.c
Andrea della Porta
maintainerPATCH v9 8/12 arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5
In reply to Andrea della PortaThe RP1 found on Raspberry Pi 5 board needs an external crystal at 50MHz. Add clk_rp1_xosc node to provide that.
--- arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts +7 -0
@@ -16,6 +16,13 @@ chosen: chosen { stdout-path = "serial10:115200n8"; }; + clk_rp1_xosc: clock-50000000 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-output-names = "rp1-xosc"; + clock-frequency = <50000000>; + }; + /* Will be filled by the bootloader */ memory@0 { device_type = "memory";
Signature · 1 line
2.35.3
Andrea della Porta
maintainerRe: [PATCH v9 -next 08/12] arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5
Hi Florian,
Quoted 5 lines · Andrea della Porta
The RP1 found on Raspberry Pi 5 board needs an external crystal at 50MHz. Add
clk_rp1_xoscnode to provide that.Signed-off-by Andrea della Porta <[email protected]>Reviewed-by Florian Fainelli <[email protected]>
A gentle reminder for patches 8 through 12 of this series, which I guess would ideally be taken by you. Since the merge window is approaching, do you think it's feasible to iterate a second pull request to Arnd with my patches too?
With respect to your devicetree/next branch, my patches have the following conflicts:
PATCH 9:
- arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts: &pcie1 and &pcie2 reference at the end, my patch was rebased on linux-next which has them while your devicetree branch has not. This is trivial to fix too.
PATCH 9 and 10:
- arch/arm64/boot/dts/broadcom/Makefile on your branch has a line recently added by Stefan's latest patch for RPi2. The fix is trivial.
PATCH 11 and 12:
- arch/arm64/configs/defconfig: just a couple of fuzz lines.
Please let me know if I should resend those patches adjusted for your tree.
Many thanks,
Andrea
Quoted 25 lines
--- arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts | 7 +++++++ 1 file changed, 7 insertions(+)arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts +7
-0@@ -16,6 +16,13 @@ chosen: chosen { stdout-path = "serial10:115200n8"; }; + clk_rp1_xosc: clock-50000000 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-output-names = "rp1-xosc"; + clock-frequency = <50000000>; + }; + /* Will be filled by the bootloader */ memory@0 { device_type = "memory";Signature · 1 line
2.35.3
Florian Fainelli
maintainerRe: [PATCH v9 -next 08/12] arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5
Quoted 22 lines · Andrea della Porta
Hi Florian,
Quoted 5 lines · Andrea della Porta
The RP1 found on Raspberry Pi 5 board needs an external crystal at 50MHz. Add
clk_rp1_xoscnode to provide that.Signed-off-by Andrea della Porta <[email protected]>Reviewed-by Florian Fainelli <[email protected]>A gentle reminder for patches 8 through 12 of this series, which I guess would ideally be taken by you. Since the merge window is approaching, do you think it's feasible to iterate a second pull request to Arnd with my patches too?
With respect to your devicetree/next branch, my patches have the following conflicts:
PATCH 9:
-arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts: &pcie1 and &pcie2 reference at the end, my patch was rebased on linux-next which has them while your devicetree branch has not. This is trivial to fix too.
Quoted 8 lines
PATCH 9 and 10:
-arch/arm64/boot/dts/broadcom/Makefileon your branch has a line recently added by Stefan's latest patch for RPi2. The fix is trivial.PATCH 11 and 12:
-arch/arm64/configs/defconfig: just a couple of fuzz lines.Please let me know if I should resend those patches adjusted for your tree.
Yes please resend them today or tomorrow so I can send them the following day. Thanks
Signature · 1 line
Florian
Andrea della Porta
maintainerRe: [PATCH v9 -next 08/12] arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5
Hi Florian
Quoted 29 lines · Florian Fainelli
Quoted 26 lines · Andrea della Porta
Hi Florian,
Quoted 5 lines · Andrea della Porta
The RP1 found on Raspberry Pi 5 board needs an external crystal at 50MHz. Add
clk_rp1_xoscnode to provide that.Signed-off-by Andrea della Porta <[email protected]>Reviewed-by Florian Fainelli <[email protected]>A gentle reminder for patches 8 through 12 of this series, which I guess would ideally be taken by you. Since the merge window is approaching, do you think it's feasible to iterate a second pull request to Arnd with my patches too?
With respect to your devicetree/next branch, my patches have the following conflicts:
PATCH 9:
-arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts: &pcie1 and &pcie2 reference at the end, my patch was rebased on linux-next which has them while your devicetree branch has not. This is trivial to fix too.PATCH 9 and 10:
-arch/arm64/boot/dts/broadcom/Makefileon your branch has a line recently added by Stefan's latest patch for RPi2. The fix is trivial.
Quoted 7 lines
Quoted 4 lines
PATCH 11 and 12:
-arch/arm64/configs/defconfig: just a couple of fuzz lines.Please let me know if I should resend those patches adjusted for your tree.
Yes please resend them today or tomorrow so I can send them the following day. Thanks
Sorry, what's the best wasy to provide the updated patch 8 to 12 to you?
1) Resend the entire patchset (V10) with relevant patches updated
2) Send only updated patches 8 through 12 (maybe as an entirely new patchset with only those specific patches)
3) Asking you to pull teh relevant commit from my own git repo
Many thanks,
Andrea
Quoted 3 lines
Signature · 1 line
Florian
Florian Fainelli
maintainerRe: [PATCH v9 -next 08/12] arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5
Quoted 37 lines · Andrea della Porta' via BCM-KERNEL-FEEDBACK-LIST,PDL
Hi Florian
Quoted 34 lines · Florian Fainelli
Quoted 30 lines · Andrea della Porta
Hi Florian,
Quoted 5 lines · Andrea della Porta
The RP1 found on Raspberry Pi 5 board needs an external crystal at 50MHz. Add
clk_rp1_xoscnode to provide that.Signed-off-by Andrea della Porta <[email protected]>Reviewed-by Florian Fainelli <[email protected]>A gentle reminder for patches 8 through 12 of this series, which I guess would ideally be taken by you. Since the merge window is approaching, do you think it's feasible to iterate a second pull request to Arnd with my patches too?
With respect to your devicetree/next branch, my patches have the following conflicts:
PATCH 9:
-arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts: &pcie1 and &pcie2 reference at the end, my patch was rebased on linux-next which has them while your devicetree branch has not. This is trivial to fix too.PATCH 9 and 10:
-arch/arm64/boot/dts/broadcom/Makefileon your branch has a line recently added by Stefan's latest patch for RPi2. The fix is trivial.PATCH 11 and 12:
-arch/arm64/configs/defconfig: just a couple of fuzz lines.Please let me know if I should resend those patches adjusted for your tree.
Quoted 8 lines
Quoted 2 lines
Yes please resend them today or tomorrow so I can send them the following day. Thanks
Sorry, what's the best wasy to provide the updated patch 8 to 12 to you?
1) Resend the entire patchset (V10) with relevant patches updated
2) Send only updated patches 8 through 12 (maybe as an entirely new patchset with only those specific patches)
Either of those two options would work. Maybe let's do option 2) in the interest of keeping the traffic low for people.
Signature · 1 line
Florian
Andrea della Porta
maintainerRe: [PATCH v9 -next 08/12] arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5
Hi Florian,
Quoted 44 lines · Florian Fainelli
Quoted 40 lines · Andrea della Porta' via BCM-KERNEL-FEEDBACK-LIST,PDL
Hi Florian
Quoted 36 lines · Florian Fainelli
Quoted 22 lines · Andrea della Porta
Hi Florian,
Quoted 5 lines · Andrea della Porta
The RP1 found on Raspberry Pi 5 board needs an external crystal at 50MHz. Add
clk_rp1_xoscnode to provide that.Signed-off-by Andrea della Porta <[email protected]>Reviewed-by Florian Fainelli <[email protected]>A gentle reminder for patches 8 through 12 of this series, which I guess would ideally be taken by you. Since the merge window is approaching, do you think it's feasible to iterate a second pull request to Arnd with my patches too?
With respect to your devicetree/next branch, my patches have the following conflicts:
PATCH 9:
-arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts: &pcie1 and &pcie2 reference at the end, my patch was rebased on linux-next which has them while your devicetree branch has not. This is trivial to fix too.Quoted 8 lines
PATCH 9 and 10:
-arch/arm64/boot/dts/broadcom/Makefileon your branch has a line recently added by Stefan's latest patch for RPi2. The fix is trivial.PATCH 11 and 12:
-arch/arm64/configs/defconfig: just a couple of fuzz lines.Please let me know if I should resend those patches adjusted for your tree.
Yes please resend them today or tomorrow so I can send them the following day. Thanks
Quoted 8 lines
Quoted 5 lines
Sorry, what's the best wasy to provide the updated patch 8 to 12 to you?
1) Resend the entire patchset (V10) with relevant patches updated
2) Send only updated patches 8 through 12 (maybe as an entirely new patchset with only those specific patches)Either of those two options would work. Maybe let's do option 2) in the interest of keeping the traffic low for people.
Could you please take a look at this:
https://lore.kernel.org/all/aBxtyvI3LUaM3P00@apocalypse/#t
besides patches 8 through 12, would you like to take also binding patches + clock driver (patches 1 to 4, if Linux Walleij is not willing to take patch 2 himself), and maybe also misc driver and its dts (patches 6 and 7 unless Greg has different ideas)? I know this is almost the entire patchset, but it's getting hard to escape the dependency maze.
I'm open to any alternative solutions, more details in the link above.
Many thanks,
Andrea
Quoted 3 lines
Signature · 1 line
Florian
Florian Fainelli
maintainerRe: [PATCH v9 -next 08/12] arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5
Quoted 58 lines · Andrea della Porta
Hi Florian,
Quoted 44 lines · Florian Fainelli
Quoted 40 lines · Andrea della Porta' via BCM-KERNEL-FEEDBACK-LIST,PDL
Hi Florian
Quoted 36 lines · Florian Fainelli
Quoted 22 lines · Andrea della Porta
Hi Florian,
Quoted 5 lines · Andrea della Porta
The RP1 found on Raspberry Pi 5 board needs an external crystal at 50MHz. Add
clk_rp1_xoscnode to provide that.Signed-off-by Andrea della Porta <[email protected]>Reviewed-by Florian Fainelli <[email protected]>A gentle reminder for patches 8 through 12 of this series, which I guess would ideally be taken by you. Since the merge window is approaching, do you think it's feasible to iterate a second pull request to Arnd with my patches too?
With respect to your devicetree/next branch, my patches have the following conflicts:
PATCH 9:
-arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts: &pcie1 and &pcie2 reference at the end, my patch was rebased on linux-next which has them while your devicetree branch has not. This is trivial to fix too.Quoted 8 lines
PATCH 9 and 10:
-arch/arm64/boot/dts/broadcom/Makefileon your branch has a line recently added by Stefan's latest patch for RPi2. The fix is trivial.PATCH 11 and 12:
-arch/arm64/configs/defconfig: just a couple of fuzz lines.Please let me know if I should resend those patches adjusted for your tree.
Yes please resend them today or tomorrow so I can send them the following day. Thanks
Quoted 8 lines
Quoted 5 lines
Sorry, what's the best wasy to provide the updated patch 8 to 12 to you?
1) Resend the entire patchset (V10) with relevant patches updated
2) Send only updated patches 8 through 12 (maybe as an entirely new patchset with only those specific patches)Either of those two options would work. Maybe let's do option 2) in the interest of keeping the traffic low for people.
Could you please take a look at this:
Quoted 8 lines
https://lore.kernel.org/all/aBxtyvI3LUaM3P00@apocalypse/#t
besides patches 8 through 12, would you like to take also binding patches + clock driver (patches 1 to 4, if Linux Walleij is not willing to take patch 2 himself), and maybe also misc driver and its dts (patches 6 and 7 unless Greg has different ideas)? I know this is almost the entire patchset, but it's getting hard to escape the dependency maze.
I'm open to any alternative solutions, more details in the link above.
If I am taking the whole patchset I would need maintainers to provide the adequate tags. I would prefer to only take the DT changes, with an understanding that drivers wouldn't be active unless the relevant DT entries are present as well.
I am out of the office until the end of this week, so there may be some delay (more than usual) with my responses.
Florian
A message that is not in the archive (sent off-list or not yet received): CAO50JKVF6x_=MUuzjhdK0QotcdUgHysMb9v1g0UvWjaJF2fjDA@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
Andrea della Porta
maintainerRe: [PATCH v9 -next 08/12] arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5
Hi Florian,
Quoted 8 lines · Florian Fainelli
Quoted 5 lines · Andrea della Porta
Hi Florian, to accept the patches, what would work best for you?
1) Send only the relevant updated patches (maybe as an entirely new patchset with
only those specific patches)Only the updated patches work for me. I don't think there is that much coupling between the DT changes and the non-DT changes (other than without DT entries nothing is activated)
It's a little bit more involved than that:
- Patch 7 (misc driver) depends on 6 (RP1 common dts) which in turn depends on 1 (clock binding header). Should be taken by Greg.
- Patch 9 and 10 (board dts) depends on 6 (RP1 common dts) which again depends on 1 (clock binding header). Should be taken by Florian.
- Patch 4 (clock driver) depends on 1 (clock binding header) and should be taken by Stephen.
So patches 6 and 1 are in common between Florian and Greg, while patch 1 is in common between everyone in the pool.
If I uniquely assign the patches in common to one of you, the others won't be able to compile their own branch because they will be missing the dependent patch.
If, on the other hand, I duplicate common patches to each of you to make the kernel compile for veryone, you should remember that there will be conflicts due to duplicated patches among different trees down the merge path.
Any advice about how to proceed is appreciated.
Many thanks,
Andrea
Quoted 2 lines
Florian
Re: [PATCH v9 -next 08/12] arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5
Quoted 10 lines · Andrea della Porta
Hi Florian,
Quoted 7 lines · Florian Fainelli
Quoted 5 lines · Andrea della Porta
Hi Florian, to accept the patches, what would work best for you?
1) Send only the relevant updated patches (maybe as an entirely new patchset with
only those specific patches)
Quoted 6 lines
Quoted 1 line
Only the updated patches work for me. I don't think there is that much coupling between the DT changes and the non-DT changes (other than without DT entries nothing is activated)
It's a little bit more involved than that:
- Patch 7 (misc driver) depends on 6 (RP1 common dts) which in turn depends on 1 (clock binding header). Should be taken by Greg.
Greg gave an Acked-by so I think Florian is good to take that patch. Which leaves us to the clock patches (driver + dt-bindings).
Quoted 7 lines
- Patch 9 and 10 (board dts) depends on 6 (RP1 common dts) which again depends on 1 (clock binding header). Should be taken by Florian.
- Patch 4 (clock driver) depends on 1 (clock binding header) and should be taken by Stephen.
Steven reviewed the patches (driver + dt-binding) so he is waiting for a new version which addresses the review. He offered to either take them and provide a branch that Florian can merge into his branch or provide a Acked-by tag.
@Florian what would you prefer?
Regards,
Matthias
Quoted 19 lines
So patches 6 and 1 are in common between Florian and Greg, while patch 1 is in common between everyone in the pool.
If I uniquely assign the patches in common to one of you, the others won't be able to compile their own branch because they will be missing the dependent patch.
If, on the other hand, I duplicate common patches to each of you to make the kernel compile for veryone, you should remember that there will be conflicts due to duplicated patches among different trees down the merge path.
Any advice about how to proceed is appreciated.
Many thanks,
AndreaQuoted 2 lines
Florian
Florian Fainelli
maintainerRe: [PATCH v9 -next 08/12] arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5
Quoted 26 lines · Matthias Brugger
Quoted 10 lines · Andrea della Porta
Hi Florian,
Quoted 7 lines · Florian Fainelli
Quoted 5 lines · Andrea della Porta
Hi Florian, to accept the patches, what would work best for you?
1) Send only the relevant updated patches (maybe as an entirely new patchset with
only those specific patches)Quoted 6 lines
Quoted 1 line
Only the updated patches work for me. I don't think there is that much coupling between the DT changes and the non-DT changes (other than without DT entries nothing is activated)
It's a little bit more involved than that:
- Patch 7 (misc driver) depends on 6 (RP1 common dts) which in turn depends on 1 (clock binding header). Should be taken by Greg.
Greg gave an Acked-by so I think Florian is good to take that patch. Which leaves us to the clock patches (driver + dt-bindings).
Quoted 4 lines
- Patch 9 and 10 (board dts) depends on 6 (RP1 common dts) which again depends on 1 (clock binding header). Should be taken by Florian.
Quoted 7 lines
Quoted 3 lines
- Patch 4 (clock driver) depends on 1 (clock binding header) and should be taken by Stephen.
Steven reviewed the patches (driver + dt-binding) so he is waiting for a new version which addresses the review. He offered to either take them and provide a branch that Florian can merge into his branch or provide a Acked-by tag.
@Florian what would you prefer?
I am fine either way, it's definitively simpler if I can take all of the patches in the respective Broadcom ARM SoC branches, but pulling a branch from another maintainer's tree works just as well.
Andrea, sorry to ask you this, can you post a v10 and we aim to get that version applied?
Thanks!
Signature · 1 line
Florian
Andrea della Porta
maintainerRe: [PATCH v9 -next 08/12] arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5
Hi Florian,
Quoted 40 lines · Florian Fainelli
Quoted 39 lines · Matthias Brugger
Quoted 11 lines · Andrea della Porta
Hi Florian,
Quoted 8 lines · Florian Fainelli
Quoted 5 lines · Andrea della Porta
Hi Florian, to accept the patches, what would work best for you?
1) Send only the relevant updated patches (maybe as an entirely new patchset with
only those specific patches)Quoted 8 lines
Quoted 3 lines
Only the updated patches work for me. I don't think there is that much coupling between the DT changes and the non-DT changes (other than without DT entries nothing is activated)
It's a little bit more involved than that:
- Patch 7 (misc driver) depends on 6 (RP1 common dts) which in turn depends on 1 (clock binding header). Should be taken by Greg.
Greg gave an Acked-by so I think Florian is good to take that patch. Which leaves us to the clock patches (driver + dt-bindings).
Quoted 7 lines
- Patch 9 and 10 (board dts) depends on 6 (RP1 common dts) which again depends on 1 (clock binding header). Should be taken by Florian.
- Patch 4 (clock driver) depends on 1 (clock binding header) and should be taken by Stephen.
Steven reviewed the patches (driver + dt-binding) so he is waiting for a new version which addresses the review. He offered to either take them and provide a branch that Florian can merge into his branch or provide a Acked-by tag.
Quoted 8 lines
Quoted 1 line
@Florian what would you prefer?
I am fine either way, it's definitively simpler if I can take all of the patches in the respective Broadcom ARM SoC branches, but pulling a branch from another maintainer's tree works just as well.
Andrea, sorry to ask you this, can you post a v10 and we aim to get that version applied?
No problem, just to avoid any confusion I'll summarize what-goes-where with respect to branches in your repo broadcom/stblinux, so I can adapt each patch to the relevant branch:
- dt-binding/DTS (patch 1,2,3,6,8,9,10) -> devicetree/next
- defconfig (patch 11,12) -> defconfig/next
- drivers (patch 4,5,7) -> drivers/next or soc/next?
Also, should I split any patches that have MAINTAINERS changes so you can apply them to your maintainers/next branch? Those are patches 4,5,6,7.
Many thanks,
Andrea
Quoted 3 lines
Thanks!
Signature · 1 line
Florian
Florian Fainelli
maintainerRe: [PATCH v9 -next 08/12] arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5
Quoted 49 lines · Andrea della Porta
Hi Florian,
Quoted 46 lines · Florian Fainelli
Quoted 34 lines · Matthias Brugger
Quoted 11 lines · Andrea della Porta
Hi Florian,
Quoted 8 lines · Florian Fainelli
Quoted 5 lines · Andrea della Porta
Hi Florian, to accept the patches, what would work best for you?
1) Send only the relevant updated patches (maybe as an entirely new patchset with
only those specific patches)Quoted 8 lines
Quoted 3 lines
Only the updated patches work for me. I don't think there is that much coupling between the DT changes and the non-DT changes (other than without DT entries nothing is activated)
It's a little bit more involved than that:
- Patch 7 (misc driver) depends on 6 (RP1 common dts) which in turn depends on 1 (clock binding header). Should be taken by Greg.
Greg gave an Acked-by so I think Florian is good to take that patch. Which leaves us to the clock patches (driver + dt-bindings).
Quoted 7 lines
- Patch 9 and 10 (board dts) depends on 6 (RP1 common dts) which again depends on 1 (clock binding header). Should be taken by Florian.
- Patch 4 (clock driver) depends on 1 (clock binding header) and should be taken by Stephen.
Quoted 6 lines
Steven reviewed the patches (driver + dt-binding) so he is waiting for a new version which addresses the review. He offered to either take them and provide a branch that Florian can merge into his branch or provide a Acked-by tag.
@Florian what would you prefer?
I am fine either way, it's definitively simpler if I can take all of the patches in the respective Broadcom ARM SoC branches, but pulling a branch from another maintainer's tree works just as well.
Quoted 8 lines
Quoted 2 lines
Andrea, sorry to ask you this, can you post a v10 and we aim to get that version applied?
No problem, just to avoid any confusion I'll summarize what-goes-where with respect to branches in your repo broadcom/stblinux, so I can adapt each patch to the relevant branch:
- dt-binding/DTS (patch 1,2,3,6,8,9,10) -> devicetree/next
Ack
Quoted 1 line
- defconfig (patch 11,12) -> defconfig/next
Ack
Quoted 1 line
- drivers (patch 4,5,7) ->
drivers/nextor soc/next?
I will take them in drivers/next.
Quoted 3 lines
Also, should I split any patches that have
MAINTAINERSchanges so you can apply them to your maintainers/next branch? Those are patches 4,5,6,7.
Not sure there is much value in splitting the MAINTAINERS file apart, maybe one initial commit covering all of the entries you are right about to add would do, up to you.
Signature · 1 line
Florian
Andrea della Porta
maintainerPATCH v9 9/12 arm64: dts: broadcom: Add board DTS for Rpi5 which includes RP1 node
In reply to Andrea della PortaAdd the fully populated DTS for RaspberryPi 5 which includes the RP1 node definition. The inclusion tree is as follow (the arrow points to the includer):
rp1-common.dtsi ----> rp1-nexus.dtsi ----> bcm2712-rpi-5-b.dts
^
|
bcm2712-rpi-5-b-ovl-rp1.dtsThis is designed to maximize the compatibility with downstream DT while ensuring that a fully defined DT (one which includes the RP1 node as opposed to load it from overlay at runtime) is present since early boot stage.
Since the preferred board DT is the fully populated one, name it bcm2712-rpi-5-b.dts and move the previous one into bcm2712-rpi-5-b-ovl-rp1.dts.
--- arch/arm64/boot/dts/broadcom/Makefile | 1 + .../dts/broadcom/bcm2712-rpi-5-b-ovl-rp1.dts | 121 +++++++++++++++++ .../boot/dts/broadcom/bcm2712-rpi-5-b.dts | 124 ++---------------- 3 files changed, 132 insertions(+), 114 deletions(-) create mode 100644 arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b-ovl-rp1.dts
arch/arm64/boot/dts/broadcom/Makefile +1 -0
@@ -7,6 +7,7 @@ dtb-$(CONFIG_ARCH_BCM2835) += bcm2711-rpi-400.dtb \ bcm2711-rpi-4-b.dtb \ bcm2711-rpi-cm4-io.dtb \ bcm2712-rpi-5-b.dtb \ + bcm2712-rpi-5-b-ovl-rp1.dtb \ bcm2712-d-rpi-5-b.dtb \ bcm2837-rpi-3-a-plus.dtb \ bcm2837-rpi-3-b.dtb \
arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b-ovl-rp1.dts new file +121 -0
121 lines not on this page · raw message
arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts +10 -114
131 lines not on this page · raw message
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v9 10/12 arm64: dts: broadcom: Add overlay for RP1 device
In reply to Andrea della PortaDefine the RP1 node in an overlay. The inclusion tree is as follow (the arrow points to the includer):
rp1.dtso
^
|rp1-common.dtsi ----> rp1-nexus.dtsi
--- arch/arm64/boot/dts/broadcom/Makefile | 3 ++- arch/arm64/boot/dts/broadcom/rp1.dtso | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/boot/dts/broadcom/rp1.dtso
arch/arm64/boot/dts/broadcom/Makefile +2 -1
@@ -13,7 +13,8 @@ dtb-$(CONFIG_ARCH_BCM2835) += bcm2711-rpi-400.dtb \ bcm2837-rpi-3-b.dtb \ bcm2837-rpi-3-b-plus.dtb \ bcm2837-rpi-cm3-io3.dtb \ - bcm2837-rpi-zero-2-w.dtb + bcm2837-rpi-zero-2-w.dtb \ + rp1.dtbo subdir-y += bcmbca subdir-y += northstar2
arch/arm64/boot/dts/broadcom/rp1.dtso new file +11 -0
@@ -0,0 +1,11 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) + +/dts-v1/; +/plugin/; + +&pcie2 { + #address-cells = <3>; + #size-cells = <2>; + + #include "rp1-nexus.dtsi" +};
Signature · 1 line
2.35.3
Re: [PATCH v9 -next 10/12] arm64: dts: broadcom: Add overlay for RP1 device
Quoted 9 lines · Andrea della Porta
Define the RP1 node in an overlay. The inclusion tree is as follow (the arrow points to the includer):
rp1.dtso ^ |
rp1-common.dtsi---->rp1-nexus.dtsiSigned-off-by Andrea della Porta <[email protected]>
Signature · 1 line
Florian
Andrea della Porta
maintainerPATCH v9 11/12 arm64: defconfig: Enable RP1 misc/clock/gpio drivers
In reply to Andrea della PortaSelect the RP1 drivers needed to operate the PCI endpoint containing several peripherals such as Ethernet and USB Controller. This chip is present on RaspberryPi 5.
--- arch/arm64/configs/defconfig | 3 +++ 1 file changed, 3 insertions(+)
arch/arm64/configs/defconfig +3 -0
@@ -622,6 +622,7 @@ CONFIG_PINCTRL_QCS615=y CONFIG_PINCTRL_QCS8300=y CONFIG_PINCTRL_QDF2XXX=y CONFIG_PINCTRL_QDU1000=y +CONFIG_PINCTRL_RP1=m CONFIG_PINCTRL_SA8775P=y CONFIG_PINCTRL_SC7180=y CONFIG_PINCTRL_SC7280=y
@@ -704,6 +705,7 @@ CONFIG_SENSORS_RASPBERRYPI_HWMON=m CONFIG_SENSORS_SL28CPLD=m CONFIG_SENSORS_INA2XX=m CONFIG_SENSORS_INA3221=m +CONFIG_MISC_RP1=m CONFIG_THERMAL_GOV_POWER_ALLOCATOR=y CONFIG_CPU_THERMAL=y CONFIG_DEVFREQ_THERMAL=y
@@ -1301,6 +1303,7 @@ CONFIG_COMMON_CLK_CS2000_CP=y CONFIG_COMMON_CLK_FSL_SAI=y CONFIG_COMMON_CLK_S2MPS11=y CONFIG_COMMON_CLK_PWM=y +CONFIG_COMMON_CLK_RP1=m CONFIG_COMMON_CLK_RS9_PCIE=y CONFIG_COMMON_CLK_VC3=y CONFIG_COMMON_CLK_VC5=y
Signature · 1 line
2.35.3
Re: [PATCH v9 -next 11/12] arm64: defconfig: Enable RP1 misc/clock/gpio drivers
Quoted 6 lines · Andrea della Porta
Select the RP1 drivers needed to operate the PCI endpoint containing several peripherals such as Ethernet and USB Controller. This chip is present on RaspberryPi 5.
Signed-off-by Andrea della Porta <[email protected]>Reviewed-by Stefan Wahren <[email protected]>
Signature · 1 line
Florian
Andrea della Porta
maintainerPATCH v9 12/12 arm64: defconfig: Enable OF_OVERLAY option
In reply to Andrea della PortaThe RP1 driver uses the infrastructure enabled by OF_OVERLAY config option. Enable that option in defconfig in order to produce a kernel usable on RaspberryPi5 avoiding to enable it separately.
--- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
@@ -1640,6 +1640,7 @@ CONFIG_FPGA_BRIDGE=m CONFIG_ALTERA_FREEZE_BRIDGE=m CONFIG_FPGA_REGION=m CONFIG_OF_FPGA_REGION=m +CONFIG_OF_OVERLAY=y CONFIG_TEE=y CONFIG_OPTEE=y CONFIG_MUX_GPIO=m
Signature · 1 line
2.35.3
Re: [PATCH v9 -next 12/12] arm64: defconfig: Enable OF_OVERLAY option
Quoted 6 lines · Andrea della Porta
The RP1 driver uses the infrastructure enabled by
OF_OVERLAYconfig option. Enable that option in defconfig in order to produce a kernel usable on RaspberryPi5 avoiding to enable it separately.Signed-off-by Andrea della Porta <[email protected]>Reviewed-by Stefan Wahren <[email protected]>
Signature · 1 line
Florian