Add support for RaspberryPi RP1 PCI device using a DT overlay
Subsystems (10)
Andrea della Porta
maintainerv2 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. Followup 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 4: 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 though the on-board gpio controller.
-PATCHES 5, 6 and 7: preparatory patches that fix the address mapping
translation (especially wrt dma-ranges) and export gpio line naming function.
-PATCH 8 and 9: add clock and gpio device drivers.
-PATCH 10: the devicetree overlay describing the RP1 chipset. Please
note that this patch should be taken by the same maintainer that will also take patch 11, since txeieh dtso is compiled in as binary blob and is closely coupled to the driver.
-PATCH 11: this is the main patch to support RP1 chipset and peripherals
enabling through dtb overlay. The dtso since is intimately coupled with the driver and will be linked in as binary blob in the driver obj. 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 12: add the external clock node (used by RP1) to the main dts.
-PATCH 13: the dtso that can be loaded from userspace to change the gpio
line names.
-PATCH 14: add the relevant kernel CONFIG_ options to defconfig.
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.
Please note that albeit this patchset has no prerequisites in order to be applied cleanly, it still depends on Stanimir's WIP patchset for BCM2712 PCIe controller (see [5]) in order to work at runtime.
Many thanks,
Andrea della Porta
Link:
- [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/
CHANGES IN V2:
NEW ADDITIONS ------------------------------------------------
- Two new yaml schemas, a common one to be included by device bindings representing MFD devices exposed through PCI BARs and a device specific one customized for RP1 chipset.
- Added dtso file containing the gpio-line-names for RP1 gpio controller. The resulting dtbo can be loaded from userspace through configfs.
- Added preparatory patch that exports gpiochip_set_names() symbol, this is required to rename the gpio line from the driver.
MISCELLANEA ---------------------------------------
- Added newly created files to MAINTAINERS.
- Dropped the patch dealing with DTBO section placement, since now we have:
https://lore.kernel.org/all/[email protected]/
which should now be a prerequisite.
- Renamed "bar-bus" to "pci-ep-bus" wherever applicable, for consistency with Bootlin's Microchip patchset.
- Dropped testing patches for macb ethernet.
- Added "-@" option to dtc compiler for rp1.dtso. Symbols exported are needed for loading gpio-line-names dtbo from userspace.
- arm64 defconfig now have both CONFIG_MISC_RP1 and CONFIG_COMMON_CLK_RP1 set to module.
- PCI_DEVICE_ID_RP1_C0 renamed to PCI_DEVICE_ID_RPI_RP1_C0
RP1 misc driver -----------------------------------
- RP1 driver moved to drivers/misc/.
- Cleanups on unused variables and definitions.
- Moved __dtbo_rp1_pci_[begin,end] to an appropriate header file.
- Interrupt number definitions are now local to the driver source code.
- Removed the calls to irq_domain_[activate/decativate]_irq since they are already called by core functions.
- Added myself as module co-author.
- Using pci_resource_n() to dump the BAR aperture.
- Adopted pcim_iomap() managed variant to map the BAR.
- Several cleanups in various error return path.
- CONFIG_OF_IRQ automatically selected when MISC_RP1 is enabled.
GPIO/PINCTRL --------------------------------------
- Removed several macros and definitions as they are now unused.
- Reworked RP1 pinctrl driver to leverage regmap-mmio to access the setup and status registers.
- It's now possible to load a dtb overlay dynamically through configfs in order to set the gpio-line names for RP1 gpio controller.
- Removed unused includes.
- CONFIG_GPIOLIB automatically selected when PINCTRL_RP1 is enabled.
- rp1_iobanks structure declared static.
CLOCKS --------------------------------------
- Renamed "xosc" to "rp1-xosc"
- Registered RP1_CLK_SYS (needed by macb ethernet)
- Dropped unused ref_clock variable.
- Added myself as module co-author.
- Release the spinlock in rp1_clock_set_parent() return path.
DTS -----------------------------------------
- rp1.dtso is now in a patch of its own.
- Reworked the list of self configured clocks, now restricted to PLL_SYS_CORE, PLL_SYS and CLK_SYS.
- Moved clock-rp1-xosc to main DTB for RaspberryPi 5. Removed macb_pclk and macb_hclk, now provided internally by clock controller inside RP1.
- Removed property gpio-line-names, now managed by dtbo loaded from userspace.
- Dropped interrupt and address definitions. Interrupts are replaced by hard-coding the appropriate int number. This impact also the relative yaml schema. As a result, include/dt-bindings/misc/rp1.h is also dropped since it's now empty.
- Minor order fix-up and name changes to adhere more closely to DT coding style. Some cleanups in comment.
BINDINGS
- Dropped assigned-clocks and assigned-clock-rates from RP1 clock binding.
- dt-bindings header files are now named after the binding filename they refer to.
- Represent drive strength as its mA value instead of a positional id, as stated by the common bindings.
Andrea della Porta (14):
dt-bindings: clock: Add RaspberryPi RP1 clock bindings
dt-bindings: pinctrl: Add RaspberryPi RP1 gpio/pinctrl/pinmux bindings
dt-bindings: pci: Add common schema for devices accessible through PCI
BARs
dt-bindings: misc: Add device specific bindings for RaspberryPi RP1
PCI: of_property: Sanitize 32 bit PCI address parsed from DT
of: address: Preserve the flags portion on 1:1 dma-ranges mapping
gpiolib: Export symbol gpiochip_set_names()
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: Add DTS overlay for RP1 gpio line names
arm64: defconfig: Enable RP1 misc/clock/gpio drivers
.../clock/raspberrypi,rp1-clocks.yaml | 62 + .../devicetree/bindings/misc/pci1de4,1.yaml | 110 ++ .../devicetree/bindings/pci/pci-ep-bus.yaml | 69 + .../pinctrl/raspberrypi,rp1-gpio.yaml | 169 ++ MAINTAINERS | 15 + arch/arm64/boot/dts/broadcom/Makefile | 3 +- arch/arm64/boot/dts/broadcom/bcm2712.dtsi | 7 + arch/arm64/boot/dts/broadcom/rp1.dtso | 62 + .../boot/dts/broadcom/rpi-rp1-gpios-5-b.dtso | 62 + arch/arm64/configs/defconfig | 3 + drivers/clk/Kconfig | 9 + drivers/clk/Makefile | 1 + drivers/clk/clk-rp1.c | 1658 +++++++++++++++++ drivers/gpio/gpiolib.c | 3 +- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/rp1/Kconfig | 24 + drivers/misc/rp1/Makefile | 5 + drivers/misc/rp1/rp1-pci.dtso | 8 + drivers/misc/rp1/rp1_pci.c | 365 ++++ drivers/misc/rp1/rp1_pci.h | 14 + drivers/of/address.c | 3 +- drivers/pci/of_property.c | 5 +- drivers/pci/quirks.c | 1 + drivers/pinctrl/Kconfig | 11 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-rp1.c | 860 +++++++++ .../clock/raspberrypi,rp1-clocks.h | 61 + include/linux/gpio/driver.h | 3 + include/linux/pci_ids.h | 3 + 30 files changed, 3595 insertions(+), 4 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/pci/pci-ep-bus.yaml create mode 100644 Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml create mode 100644 arch/arm64/boot/dts/broadcom/rp1.dtso create mode 100644 arch/arm64/boot/dts/broadcom/rpi-rp1-gpios-5-b.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/misc/rp1/rp1_pci.h 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 v2 1/14 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 | 62 +++++++++++++++++++ MAINTAINERS | 6 ++ .../clock/raspberrypi,rp1-clocks.h | 61 ++++++++++++++++++ 3 files changed, 129 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 +62 -0
@@ -0,0 +1,62 @@ +# 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: + - Andrea 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 though 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': + description: + The index in the assigned-clocks is mapped to the output clock as per + definitions in dt-bindings/clock/raspberrypi,rp1-clocks.h. + const: 1 + + clocks: + maxItems: 1 + + clock-names: + const: rp1-xosc + +required: + - compatible + - reg + - '#clock-cells' + - clocks + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/raspberrypi,rp1-clocks.h> + + rp1 { + #address-cells = <2>; + #size-cells = <2>; + + rp1_clocks: clocks@c040018000 { + compatible = "raspberrypi,rp1-clocks"; + reg = <0xc0 0x40018000 0x0 0x10038>; + #clock-cells = <1>; + clocks = <&clk_rp1_xosc>; + clock-names = "rp1-xosc"; + }; + };
MAINTAINERS +6 -0
@@ -19380,6 +19380,12 @@ F: Documentation/devicetree/bindings/media/raspberrypi,pispbe.yaml F: drivers/media/platform/raspberrypi/pisp_be/ F: include/uapi/linux/media/raspberrypi/ +RASPBERRY PI RP1 PCI DRIVER +M: Andrea della Porta <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml +F: include/dt-bindings/clock/rp1.h + RC-CORE / LIRC FRAMEWORK M: Sean Young <[email protected]> L: [email protected]
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 v2 2/14 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 | 169 ++++++++++++++++++ MAINTAINERS | 2 + 2 files changed, 171 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +169 -0
@@ -0,0 +1,169 @@ +# 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: + - Andrea 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. + + Each pin configuration node lists the pin(s) to which it applies, and one or + more of the mux function to select on those pin(s), and their configuration. + The pin configuration and multiplexing supports the generic bindings. + For details on each properties (including the meaning of "pin configuration node"), + you can refer to ./pinctrl-bindings.txt. + +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 + +additionalProperties: + anyOf: + - type: object + additionalProperties: false + 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: + A string (or list of strings) adhering to the pattern "gpio[0-5][0-9]" + function: true + bias-disable: true + bias-pull-down: true + bias-pull-up: true + slew-rate: + description: 0 is slow slew rate, 1 is fast slew rate + enum: [ 0, 1 ] + drive-strength: + enum: [ 2, 4, 8, 12 ] + + - type: object + additionalProperties: + $ref: "#/additionalProperties/anyOf/0" + +allOf: + - $ref: pinctrl.yaml# + +required: + - reg + - compatible + - "#gpio-cells" + - gpio-controller + - interrupts + - "#interrupt-cells" + - interrupt-controller + +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_uart0_14_15: rp1_uart0_14_15 { + pin_txd { + function = "uart0"; + pins = "gpio14"; + bias-disable; + }; + + pin_rxd { + function = "uart0"; + pins = "gpio15"; + bias-pull-up; + }; + }; + }; + };
MAINTAINERS +2 -0
@@ -19384,7 +19384,9 @@ RASPBERRY PI RP1 PCI DRIVER M: Andrea della Porta <[email protected]> S: Maintained F: Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml +F: Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml F: include/dt-bindings/clock/rp1.h +F: include/dt-bindings/misc/rp1.h RC-CORE / LIRC FRAMEWORK M: Sean Young <[email protected]>
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v2 3/14 dt-bindings: pci: Add common schema for devices accessible through PCI BARs
In reply to Andrea della PortaCommon YAML schema for devices that exports internal peripherals through PCI BARs. The BARs are exposed as simple-buses through which the peripherals can be accessed.
This is not intended to be used as a standalone binding, but should be included by device specific bindings.
--- .../devicetree/bindings/pci/pci-ep-bus.yaml | 69 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/pci-ep-bus.yaml
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +69 -0
@@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pci/pci-ep-bus.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Common properties for PCI MFD endpoints with peripherals addressable from BARs. + +maintainers: + - Andrea della Porta <[email protected]> + +description: + Define a generic node representing a PCI endpoint which contains several sub- + peripherals. The peripherals can be accessed through one or more BARs. + This common schema is intended to be referenced from device tree bindings, and + does not represent a device tree binding by itself. + +properties: + "#address-cells": + const: 3 + + "#size-cells": + const: 2 + + ranges: + minItems: 1 + maxItems: 6 + items: + maxItems: 8 + additionalItems: true + items: + - maximum: 5 # The BAR number + - const: 0 + - const: 0 + +patternProperties: + "^pci-ep-bus@[0-5]$": + $ref: '#/$defs/pci-ep-bus' + description: + One node for each BAR used by peripherals contained in the PCI endpoint. + Each node represent a bus on which peripherals are connected. + This allows for some segmentation, e.g. one peripheral is accessible + through BAR0 and another through BAR1, and you don't want the two + peripherals to be able to act on the other BAR. Alternatively, when + different peripherals need to share BARs, you can define only one node + and use 'ranges' property to map all the used BARs. + +required: + - ranges + - '#address-cells' + - '#size-cells' + +$defs: + pci-ep-bus: + type: object + additionalProperties: true + properties: + compatible: + const: simple-bus + dma-ranges: true + ranges: true + "#address-cells": true + "#size-cells": true + required: + - compatible + - ranges + - '#address-cells' + - '#size-cells' +...
MAINTAINERS +1 -0
@@ -19384,6 +19384,7 @@ RASPBERRY PI RP1 PCI DRIVER M: Andrea della Porta <[email protected]> S: Maintained F: Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml +F: Documentation/devicetree/bindings/pci/pci-ep-bus.yaml F: Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml F: include/dt-bindings/clock/rp1.h F: include/dt-bindings/misc/rp1.h
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v2 4/14 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 | 110 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 111 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/pci1de4,1.yaml
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +110 -0
@@ -0,0 +1,110 @@ +# 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: + - Andrea 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 + +patternProperties: + "^pci-ep-bus@[0-2]$": + $ref: '#/$defs/bar-bus' + description: + The bus on which the peripherals are attached, which is addressable + through the BAR. + +unevaluatedProperties: false + +$defs: + bar-bus: + $ref: /schemas/pci/pci-ep-bus.yaml#/$defs/pci-ep-bus + unevaluatedProperties: false + + properties: + "#interrupt-cells": + const: 2 + description: + Specifies respectively the interrupt number and flags as defined + in include/dt-bindings/interrupt-controller/irq.h. + + interrupt-controller: true + + interrupt-parent: + description: + Must be the phandle of this 'pci-ep-bus' node. It will trigger + PCI interrupts on behalf of peripheral generated interrupts. + + patternProperties: + "^clocks(@[0-9a-f]+)?$": + type: object + $ref: /schemas/clock/raspberrypi,rp1-clocks.yaml + + "^ethernet(@[0-9a-f]+)?$": + type: object + $ref: /schemas/net/cdns,macb.yaml + + "^pinctrl(@[0-9a-f]+)?$": + type: object + $ref: /schemas/pinctrl/raspberrypi,rp1-gpio.yaml + + required: + - interrupt-parent + - interrupt-controller + +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>; + + pci_ep_bus: pci-ep-bus@1 { + compatible = "simple-bus"; + ranges = <0xc0 0x40000000 + 0x01 0x00 0x00000000 + 0x00 0x00400000>; + dma-ranges = <0x10 0x00000000 + 0x43000000 0x10 0x00000000 + 0x10 0x00000000>; + #address-cells = <2>; + #size-cells = <2>; + interrupt-controller; + interrupt-parent = <&pci_ep_bus>; + #interrupt-cells = <2>; + + rp1_clocks: clocks@c040018000 { + compatible = "raspberrypi,rp1-clocks"; + reg = <0xc0 0x40018000 0x0 0x10038>; + #clock-cells = <1>; + clocks = <&clk_rp1_xosc>; + clock-names = "rp1-xosc"; + }; + }; + }; + };
MAINTAINERS +1 -0
@@ -19384,6 +19384,7 @@ RASPBERRY PI RP1 PCI DRIVER M: Andrea della Porta <[email protected]> S: Maintained F: Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml +F: Documentation/devicetree/bindings/misc/pci1de4,1.yaml F: Documentation/devicetree/bindings/pci/pci-ep-bus.yaml F: Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml F: include/dt-bindings/clock/rp1.h
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v2 5/14 PCI: of_property: Sanitize 32 bit PCI address parsed from DT
In reply to Andrea della PortaThe of_pci_set_address() function parses devicetree PCI range specifier assuming the address is 'sanitized' at the origin, i.e. without checking whether the incoming address is 32 or 64 bit has specified in the flags.
In this way an address with no OF_PCI_ADDR_SPACE_MEM64 set in the flags could leak through and the upper 32 bits of the address will be set too, and this violates the PCI specs stating that in 32 bit address the upper bits should be zero.
This could cause mapping translation mismatch on PCI devices (e.g. RP1) that are expected to be addressed with a 64 bit address while advertising a 32 bit address in the PCI config region.
Add a check in of_pci_set_address() to set upper 32 bits to zero in case the address has no 64 bit flag set.
---
This patch has not been changed from the first version, discussion is still ongoing here:
https://lore.kernel.org/all/ZwJyk9XouLfd24VG@apocalypse/#t
drivers/pci/of_property.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/pci/of_property.c +4 -1
@@ -60,7 +60,10 @@ static void of_pci_set_address(struct pci_dev *pdev, u32 *prop, u64 addr, prop[0 ] |= flags | reg_num;if (!reloc) { prop[0 ] |=OF_PCI_ADDR_FIELD_NONRELOC ; - prop[1 ] =upper_32_bits (addr); +if (FIELD_GET (OF_PCI_ADDR_FIELD_SS , flags) ==OF_PCI_ADDR_SPACE_MEM64 ) + prop[1 ] =upper_32_bits (addr); +else + prop[1 ] =0 ; prop[2 ] =lower_32_bits (addr); } }
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v2 6/14 of: address: Preserve the flags portion on 1:1 dma-ranges mapping
In reply to Andrea della PortaA missing or empty dma-ranges in a DT node implies a 1:1 mapping for dma translations. In this specific case, the current behaviour is to zero out the entire specifier so that the translation could be carried on as an offset from zero. This includes address specifier that has flags (e.g. PCI ranges).
Once the flags portion has been zeroed, the translation chain is broken since the mapping functions will check the upcoming address specifier against mismatching flags, always failing the 1:1 mapping and its entire purpose of always succeeding.
Set to zero only the address portion while passing the flags through.
---
This patch still lacks an entry in the DT unittest.
drivers/of/address.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/of/address.c +2 -1
@@ -455,7 +455,8 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus, }if (ranges ==NULL || rlen ==0 ) { offset =of_read_number (addr, na); -memset (addr,0 , pna *4 ); +/* copy the address while preserving the flags */ +memset (addr + pbus->flag_cells,0 , (pna - pbus->flag_cells) *4 );pr_debug ("empty ranges; 1:1 translation\n" ); goto finish; }
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v2 7/14 gpiolib: Export symbol gpiochip_set_names()
In reply to Andrea della PortaBeing able to assign gpio line names dynamically is a feature that could be used by drivers that do not have the exact naming (e.g. through the DTB/DTBO) at probing time.
An example of this is the RP1 driver that populates the DT at late time through a DT overlay. In this case a custom overlay can be loaded from userspace with the gpio line names.
Export gpiochip_set_names() to allow refreshing the gpio line names from the driver module.
--- drivers/gpio/gpiolib.c | 3 ++- include/linux/gpio/driver.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/gpio/gpiolib.c +2 -1
@@ -522,7 +522,7 @@ static void gpiochip_set_desc_names(struct gpio_chip *gc)* names belong to the underlying firmware node and should not be released * by the caller. */ -static int gpiochip_set_names (struct gpio_chip *chip) +int gpiochip_set_names (struct gpio_chip *chip) {struct gpio_device *gdev = chip->gpiodev;struct device *dev = &gdev->dev;
@@ -589,6 +589,7 @@ static int gpiochip_set_names(struct gpio_chip *chip)return 0 ; } +EXPORT_SYMBOL (gpiochip_set_names);static unsigned long *gpiochip_allocate_mask (struct gpio_chip *gc) {
include/linux/gpio/driver.h +3 -0
@@ -679,6 +679,9 @@ bool gpiochip_line_is_open_source(struct gpio_chip *gc, unsigned int offset);bool gpiochip_line_is_persistent (struct gpio_chip *gc,unsigned int offset);bool gpiochip_line_is_valid (const struct gpio_chip *gc,unsigned int offset); +/* Assign gpio line names from device property */ +int gpiochip_set_names (struct gpio_chip *chip); +/* get driver data */ void *gpiochip_get_data (struct gpio_chip *gc);
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v2 8/14 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 | 1 + drivers/clk/Kconfig | 9 + drivers/clk/Makefile | 1 + drivers/clk/clk-rp1.c | 1658 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1669 insertions(+) create mode 100644 drivers/clk/clk-rp1.c
MAINTAINERS +1 -0
@@ -19387,6 +19387,7 @@ F: Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml F: Documentation/devicetree/bindings/misc/pci1de4,1.yaml F: Documentation/devicetree/bindings/pci/pci-ep-bus.yaml F: Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml +F: drivers/clk/clk-rp1.c F: include/dt-bindings/clock/rp1.h F: include/dt-bindings/misc/rp1.h
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 PCI || COMPILE_TEST + depends on COMMON_CLK + 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
@@ -68,6 +68,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 +1658 -0
1,658 lines not on this page · raw message
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v2 9/14 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.
---
Please note that checkpatch warning on this patch are unavoidable.
MAINTAINERS | 1 + drivers/pinctrl/Kconfig | 11 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-rp1.c | 860 ++++++++++++++++++++++++++++++++++ 4 files changed, 873 insertions(+) create mode 100644 drivers/pinctrl/pinctrl-rp1.c
MAINTAINERS +1 -0
@@ -19388,6 +19388,7 @@ F: Documentation/devicetree/bindings/misc/pci1de4,1.yaml F: Documentation/devicetree/bindings/pci/pci-ep-bus.yaml F: Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml F: drivers/clk/clk-rp1.c +F: drivers/pinctrl/pinctrl-rp1.c F: include/dt-bindings/clock/rp1.h F: include/dt-bindings/misc/rp1.h
drivers/pinctrl/Kconfig +11 -0
@@ -587,6 +587,17 @@ config PINCTRL_MLXBF3 each pin. This driver can also be built as a module called pinctrl-mlxbf3. +config PINCTRL_RP1 + bool "Pinctrl driver for RP1" + select PINMUX + select PINCONF + select GENERIC_PINCONF + select GPIOLIB + select GPIOLIB_IRQCHIP + 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
@@ -47,6 +47,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 +860 -0
860 lines not on this page · raw message
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v2 10/14 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.
---
NOTE: this patch should be taken by the same maintainer that will take "[PATCH v2 11/14] misc: rp1: RaspberryPi RP1 misc driver", since they are closely related in terms of compiling.
MAINTAINERS | 1 + arch/arm64/boot/dts/broadcom/rp1.dtso | 62 +++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 arch/arm64/boot/dts/broadcom/rp1.dtso
MAINTAINERS +1 -0
@@ -19383,6 +19383,7 @@ F: include/uapi/linux/media/raspberrypi/ RASPBERRY PI RP1 PCI DRIVER M: Andrea della Porta <[email protected]> S: Maintained +F: arch/arm64/boot/dts/broadcom/rp1.dtso F: Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml F: Documentation/devicetree/bindings/misc/pci1de4,1.yaml F: Documentation/devicetree/bindings/pci/pci-ep-bus.yaml
arch/arm64/boot/dts/broadcom/rp1.dtso new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v2 11/14 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.
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.
Since the gpio line names should be provided by the user, there is an interface through configfs that allows the userspace to load a DT overlay that will provide gpio-line-names property. The interface can be invoked like this:
cat rpi-rp1-gpios-5-b.dtbo > /sys/kernel/config/rp1-cfg/gpio_set_names
and is designed to be similar to what users are already used to from distro with downstream kernel.
For reasons why this driver is contained in drivers/misc, 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 | 24 +++ drivers/misc/rp1/Makefile | 5 + drivers/misc/rp1/rp1-pci.dtso | 8 + drivers/misc/rp1/rp1_pci.c | 365 ++++++++++++++++++++++++++++++++++ drivers/misc/rp1/rp1_pci.h | 14 ++ drivers/pci/quirks.c | 1 + include/linux/pci_ids.h | 3 + 10 files changed, 423 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 create mode 100644 drivers/misc/rp1/rp1_pci.h
MAINTAINERS +1 -0
@@ -19389,6 +19389,7 @@ F: Documentation/devicetree/bindings/misc/pci1de4,1.yaml F: Documentation/devicetree/bindings/pci/pci-ep-bus.yaml F: Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml F: drivers/clk/clk-rp1.c +F: drivers/misc/rp1/ F: drivers/pinctrl/pinctrl-rp1.c F: include/dt-bindings/clock/rp1.h F: include/dt-bindings/misc/rp1.h
drivers/misc/Kconfig +1 -0
@@ -628,4 +628,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
@@ -72,3 +72,4 @@ obj-$(CONFIG_TPS6594_PFSM) += tps6594-pfsm.o obj-$(CONFIG_NSM) += nsm.o obj-$(CONFIG_MARVELL_CN10K_DPI) += mrvl_cn10k_dpi.o obj-y += keba/ +obj-$(CONFIG_MISC_RP1) += rp1/
drivers/misc/rp1/Kconfig new file +24 -0
@@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# RaspberryPi RP1 misc device +# + +config MISC_RP1 + tristate "RaspberryPi RP1 PCIe support" + depends on PCI && PCI_QUIRKS + select OF + select OF_IRQ + select OF_OVERLAY + select IRQ_DOMAIN + 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 +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_MISC_RP1) += rp1-pci.o +rp1-pci-objs := rp1_pci.o rp1-pci.dtbo.o + +DTC_FLAGS_rp1-pci += -@
drivers/misc/rp1/rp1-pci.dtso new file +8 -0
@@ -0,0 +1,8 @@ +// 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. + */ + +#include "arm64/broadcom/rp1.dtso"
drivers/misc/rp1/rp1_pci.c new file +365 -0
365 lines not on this page · raw message
drivers/misc/rp1/rp1_pci.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Copyright (c) 2018-24 Raspberry Pi Ltd. +* All rights reserved. +*/ + +#ifndef _RP1_EXTERN_H_ +#define _RP1_EXTERN_H_ + +extern char __dtbo_rp1_pci_begin[]; +extern char __dtbo_rp1_pci_end[]; + +#endif
drivers/pci/quirks.c +1 -0
@@ -6266,6 +6266,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0xa76e, dpc_log_size);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_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
@@ -2611,6 +2611,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
Andrea della Porta
maintainerPATCH v2 12/14 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.dtsi | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm64/boot/dts/broadcom/bcm2712.dtsi +7 -0
@@ -38,6 +38,13 @@ clk_emmc2: clk-emmc2 { clock-frequency = <200000000>; clock-output-names = "emmc2-clock"; }; + + clk_rp1_xosc: clock-rp1-xosc { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-output-names = "rp1-xosc"; + clock-frequency = <50000000>; + }; }; cpus: cpus {
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v2 13/14 arm64: dts: Add DTS overlay for RP1 gpio line names
In reply to Andrea della PortaThis DT overlay contains the gpio-line-names property for RaspberryPi 5.
It's intended to be loaded from userspace leveraging the RP1 driver interface through configfs, as follows:
cat rpi-rp1-gpios-5-b.dtbo > /sys/kernel/config/rp1-cfg/gpio_set_names
--- MAINTAINERS | 1 + arch/arm64/boot/dts/broadcom/Makefile | 3 +- .../boot/dts/broadcom/rpi-rp1-gpios-5-b.dtso | 62 +++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/boot/dts/broadcom/rpi-rp1-gpios-5-b.dtso
MAINTAINERS +1 -0
@@ -19384,6 +19384,7 @@ RASPBERRY PI RP1 PCI DRIVER M: Andrea della Porta <[email protected]> S: Maintained F: arch/arm64/boot/dts/broadcom/rp1.dtso +F: arch/arm64/boot/dts/broadcom/rpi-rp1-gpios-5-b.dtso F: Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml F: Documentation/devicetree/bindings/misc/pci1de4,1.yaml F: Documentation/devicetree/bindings/pci/pci-ep-bus.yaml
arch/arm64/boot/dts/broadcom/Makefile +2 -1
@@ -11,7 +11,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 \ + rpi-rp1-gpios-5-b.dtbo subdir-y += bcmbca subdir-y += northstar2
arch/arm64/boot/dts/broadcom/rpi-rp1-gpios-5-b.dtso new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
2.35.3
Andrea della Porta
maintainerPATCH v2 14/14 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
@@ -609,6 +609,7 @@ CONFIG_PINCTRL_QCM2290=y CONFIG_PINCTRL_QCS404=y CONFIG_PINCTRL_QDF2XXX=y CONFIG_PINCTRL_QDU1000=y +CONFIG_PINCTRL_RP1=y CONFIG_PINCTRL_SA8775P=y CONFIG_PINCTRL_SC7180=y CONFIG_PINCTRL_SC7280=y
@@ -689,6 +690,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
@@ -1270,6 +1272,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 v2 07/14] gpiolib: Export symbol gpiochip_set_names()
In reply to Andrea della PortaQuoted 53 lines · Andrea della Porta
Being able to assign gpio line names dynamically is a feature that could be used by drivers that do not have the exact naming (e.g. through the DTB/DTBO) at probing time.
An example of this is the RP1 driver that populates the DT at late time through a DT overlay. In this case a custom overlay can be loaded from userspace with the gpio line names.Export
gpiochip_set_names()to allow refreshing the gpio line names from the driver module.Signed-off-by Andrea della Porta <[email protected]>--- drivers/gpio/gpiolib.c | 3 ++- include/linux/gpio/driver.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)drivers/gpio/gpiolib.c +2
-1@@ -522,7 +522,7 @@ static void gpiochip_set_desc_names(struct gpio_chip *gc)* names belong to the underlying firmware node and should not be released * by the caller. */ -static int gpiochip_set_names (struct gpio_chip *chip) +int gpiochip_set_names (struct gpio_chip *chip) {struct gpio_device *gdev = chip->gpiodev;struct device *dev = &gdev->dev;@@ -589,6 +589,7 @@ static int gpiochip_set_names(struct gpio_chip *chip)return 0 ; } +EXPORT_SYMBOL (gpiochip_set_names);static unsigned long *gpiochip_allocate_mask (struct gpio_chip *gc) {include/linux/gpio/driver.h +3
-1@@ -679,6 +679,9 @@ bool gpiochip_line_is_open_source(struct gpio_chip *gc, unsigned int offset);bool gpiochip_line_is_persistent (struct gpio_chip *gc,unsigned int offset);bool gpiochip_line_is_valid (const struct gpio_chip *gc,unsigned int offset); +/* Assign gpio line names from device property */ +int gpiochip_set_names (struct gpio_chip *chip); +/* get driver data */ void *gpiochip_get_data (struct gpio_chip *gc); --
Quoted 2 lines
2.35.3
gpiochip_set_names() is definitely not ready to be used after a GPIO chip has been registered. Please take a look at how we handle synchronization of struct gpio_device and struct gpio_desc. You'd probably need to rework that first.
Bartosz
Rob Herring (Arm)
maintainerRe: [PATCH v2 03/14] dt-bindings: pci: Add common schema for devices accessible through PCI BARs
In reply to Andrea della PortaQuoted 7 lines · Andrea della Porta
Common YAML schema for devices that exports internal peripherals through PCI BARs. The BARs are exposed as simple-buses through which the peripherals can be accessed.
This is not intended to be used as a standalone binding, but should be included by device specific bindings.
Quoted 7 lines
Signed-off-by Andrea della Porta <[email protected]>--- .../devicetree/bindings/pci/pci-ep-bus.yaml | 69 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/pci-ep-bus.yaml
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/pci-ep-bus.yaml: 'oneOf' conditional failed, one must be fixed:
'unevaluatedProperties' is a required property
'additionalProperties' is a required property
hint: Either unevaluatedProperties or additionalProperties must be present
from schema $id: http://devicetree.org/meta-schemas/core.yaml#
doc reference errors (make refcheckdocs):
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Re: [PATCH v2 10/14] arm64: dts: rp1: Add support for RaspberryPi's RP1 device
In reply to Andrea della PortaHi Andrea,
Quoted 10 lines · On Mon, 7 Oct 2024 14:39:53 +0200 Andrea della Porta <[email protected]>…
RaspberryPi 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.Signed-off-by Andrea della Porta <[email protected]>---
...
arch/arm64/boot/dts/broadcom/rp1.dtso line 14
Quoted 5 lines
arch/arm64/boot/dts/broadcom/rp1.dtso new file +5
-0+/ { + fragment@0 { + target-path=""; + __overlay__ { + compatible = "pci1de4,1";
The compatible is not needed here. Indeed, it will be added by the PCI core when it scans the bus and adds the missing nodes.
https://elixir.bootlin.com/linux/v6.12-rc2/source/drivers/pci/of_property.c#L383
Quoted 6 lines
arch/arm64/boot/dts/broadcom/rp1.dtso new file +6
-0+ #address-cells = <3>; + #size-cells = <2>; + + pci_ep_bus: pci-ep-bus@1 { + compatible = "simple-bus"; + ranges = <0xc0 0x40000000
arch/arm64/boot/dts/broadcom/rp1.dtso line 30
Quoted 10 lines
arch/arm64/boot/dts/broadcom/rp1.dtso new file +10
-0+ 0x01 0x00 0x00000000 + 0x00 0x00400000>; + dma-ranges = <0x10 0x00000000 + 0x43000000 0x10 0x00000000 + 0x10 0x00000000>; + #address-cells = <2>; + #size-cells = <2>; + interrupt-controller; + interrupt-parent = <&pci_ep_bus>; + #interrupt-cells = <2>;
Not sure this node should be an interrupt controller. The interrupt controller is the PCI device itself (i.e.the node where the overlay is applied).
Best regards,
Hervé
Re: [PATCH v2 11/14] misc: rp1: RaspberryPi RP1 misc driver
In reply to Andrea della PortaHi Andrea,
Nice to see that other PCI drivers will use the DT overlay over PCI feature!
Quoted 40 lines · On Mon, 7 Oct 2024 14:39:54 +0200 Andrea della Porta <[email protected]>…
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.
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.
Since the gpio line names should be provided by the user, there is an interface through configfs that allows the userspace to load a DT overlay that will provide gpio-line-names property. The interface can be invoked like this:
cat rpi-rp1-gpios-5-b.dtbo >
/sys/kernel/config/rp1-cfg/gpio_set_namesand is designed to be similar to what users are already used to from distro with downstream kernel.
For reasons why this driver is contained in
drivers/misc, please check the links.This driver is heavily based on downstream code from RaspberryPi Foundation, and the original author is Phil Elwell.
Signed-off-by Andrea della Porta <[email protected]>
...
drivers/misc/rp1/Makefile line 5
Quoted 8 lines
drivers/misc/rp1/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_MISC_RP1) += rp1-pci.o +rp1-pci-objs := rp1_pci.o rp1-pci.dtbo.o + +DTC_FLAGS_rp1-pci += -@
Why do you need to add the symbol table (-@ option) in your dtbo ?
...
Quoted 118 lines
drivers/misc/rp1/rp1_pci.c new file +112
-0@@ -0,0 +1,365 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2018-24 Raspberry Pi Ltd. +* All rights reserved. +*/ + +#include <linux/clk.h> +#include <linux/clkdev.h> +#include <linux/clk-provider.h> +#include <linux/err.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/irqdomain.h> +#include <linux/module.h> +#include <linux/msi.h> +#include <linux/of_platform.h> +#include <linux/pci.h> +#include <linux/platform_device.h> +#include <linux/reset.h> + +#include "rp1_pci.h" + +#define RP1_DRIVER_NAME "rp1" + +#define RP1_HW_IRQ_MASK GENMASK(5, 0) + +#define REG_SET 0x800 +#define REG_CLR 0xc00 + +/* MSI-X CFG registers start at 0x8 */ +#define MSIX_CFG (x) (0x8 + (4 * (x))) + +#define MSIX_CFG_IACK_EN BIT(3) +#define MSIX_CFG_IACK BIT(2) +#define MSIX_CFG_ENABLE BIT(0) + +/* Address map */ +#define RP1_PCIE_APBS_BASE 0x108000 + +/* Interrupts */ +#define RP1_INT_IO_BANK0 0 +#define RP1_INT_IO_BANK1 1 +#define RP1_INT_IO_BANK2 2 +#define RP1_INT_AUDIO_IN 3 +#define RP1_INT_AUDIO_OUT 4 +#define RP1_INT_PWM0 5 +#define RP1_INT_ETH 6 +#define RP1_INT_I2C0 7 +#define RP1_INT_I2C1 8 +#define RP1_INT_I2C2 9 +#define RP1_INT_I2C3 10 +#define RP1_INT_I2C4 11 +#define RP1_INT_I2C5 12 +#define RP1_INT_I2C6 13 +#define RP1_INT_I2S0 14 +#define RP1_INT_I2S1 15 +#define RP1_INT_I2S2 16 +#define RP1_INT_SDIO0 17 +#define RP1_INT_SDIO1 18 +#define RP1_INT_SPI0 19 +#define RP1_INT_SPI1 20 +#define RP1_INT_SPI2 21 +#define RP1_INT_SPI3 22 +#define RP1_INT_SPI4 23 +#define RP1_INT_SPI5 24 +#define RP1_INT_UART0 25 +#define RP1_INT_TIMER_0 26 +#define RP1_INT_TIMER_1 27 +#define RP1_INT_TIMER_2 28 +#define RP1_INT_TIMER_3 29 +#define RP1_INT_USBHOST0 30 +#define RP1_INT_USBHOST0_0 31 +#define RP1_INT_USBHOST0_1 32 +#define RP1_INT_USBHOST0_2 33 +#define RP1_INT_USBHOST0_3 34 +#define RP1_INT_USBHOST1 35 +#define RP1_INT_USBHOST1_0 36 +#define RP1_INT_USBHOST1_1 37 +#define RP1_INT_USBHOST1_2 38 +#define RP1_INT_USBHOST1_3 39 +#define RP1_INT_DMA 40 +#define RP1_INT_PWM1 41 +#define RP1_INT_UART1 42 +#define RP1_INT_UART2 43 +#define RP1_INT_UART3 44 +#define RP1_INT_UART4 45 +#define RP1_INT_UART5 46 +#define RP1_INT_MIPI0 47 +#define RP1_INT_MIPI1 48 +#define RP1_INT_VIDEO_OUT 49 +#define RP1_INT_PIO_0 50 +#define RP1_INT_PIO_1 51 +#define RP1_INT_ADC_FIFO 52 +#define RP1_INT_PCIE_OUT 53 +#define RP1_INT_SPI6 54 +#define RP1_INT_SPI7 55 +#define RP1_INT_SPI8 56 +#define RP1_INT_SYSCFG 58 +#define RP1_INT_CLOCKS_DEFAULT 59 +#define RP1_INT_VBUSCTRL 60 +#define RP1_INT_PROC_MISC 57 +#define RP1_INT_END 61 + +struct rp1_dev { +struct pci_dev *pdev; +struct device *dev; +struct clk *sys_clk; +struct irq_domain *domain; +struct irq_data *pcie_irqds[64 ]; +void __iomem *bar1; +int ovcs_id;
drivers/misc/rp1/rp1_pci.c line 122
Quoted 10 lines
drivers/misc/rp1/rp1_pci.c new file +10
-0+bool level_triggered_irq[RP1_INT_END ]; +}; + +static void dump_bar (struct pci_dev *pdev,unsigned int bar) +{ +dev_info (&pdev->dev, +"bar%d %pR\n" , + bar, +pci_resource_n (pdev, bar)); +}
Is this dump_bar() really needed ?
...
Quoted 16 lines
drivers/misc/rp1/rp1_pci.c new file +16
-0+static int rp1_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ +struct device *dev = &pdev->dev; +struct device_node *rp1_node; +struct reset_control *reset; +struct rp1_dev *rp1; +int err =0 ; +int i; + + rp1_node =dev_of_node (dev); +if (!rp1_node) { +dev_err (dev,"Missing of_node for device\n" ); +return -EINVAL ; + } + + rp1 =devm_kzalloc (&pdev->dev,sizeof (*rp1),GFP_KERNEL );
drivers/misc/rp1/rp1_pci.c line 267
Quoted 10 lines
drivers/misc/rp1/rp1_pci.c new file +10
-0+if (!rp1) +return -ENOMEM ; + + rp1->pdev = pdev; + rp1->dev = &pdev->dev; + + reset =devm_reset_control_get_optional_exclusive (&pdev->dev,NULL ); +if (IS_ERR (reset)) +return PTR_ERR (reset); +reset_control_reset (reset);
This device is a PCI device.
Seems strange to get the reset control line for a PCI device.
drivers/misc/rp1/rp1_pci.c line 270
Quoted 3 lines
drivers/misc/rp1/rp1_pci.c new file +3
-0+ +dump_bar (pdev,0 ); +dump_bar (pdev,1 );
No sure those 2 dump_bar() calls are really needed.
Quoted 12 lines
drivers/misc/rp1/rp1_pci.c new file +12
-0+ +if (pci_resource_len (pdev,1 ) <=0x10000 ) { +dev_err (&pdev->dev, +"Not initialised - is the firmware running?\n" ); +return -EINVAL ; + } + + err =pcim_enable_device (pdev); +if (err <0 ) { +dev_err (&pdev->dev,"Enabling PCI device has failed: %d" , + err); +return err;
drivers/misc/rp1/rp1_pci.c line 292
Quoted 10 lines
drivers/misc/rp1/rp1_pci.c new file +10
-0+ } + + rp1->bar1 =pcim_iomap (pdev,1 ,0 ); +if (!rp1->bar1) { +dev_err (&pdev->dev,"Cannot map PCI BAR\n" ); +return -EIO ; + } + +u32 dtbo_size = __dtbo_rp1_pci_end - __dtbo_rp1_pci_begin; +void *dtbo_start = __dtbo_rp1_pci_begin;
Those declarations should be move at the beginning of the function.
drivers/misc/rp1/rp1_pci.c line 297
Quoted 5 lines
drivers/misc/rp1/rp1_pci.c new file +5
-0+ + err =of_overlay_fdt_apply (dtbo_start, dtbo_size, &rp1->ovcs_id, rp1_node); +if (err) +return err; +
Maybe applying the overlay should be done after the interrupt controller is ready.
Quoted 38 lines
drivers/misc/rp1/rp1_pci.c new file +38
-0+pci_set_master (pdev); + + err =pci_alloc_irq_vectors (pdev,RP1_INT_END ,RP1_INT_END , +PCI_IRQ_MSIX ); +if (err !=RP1_INT_END ) { +dev_err (&pdev->dev,"pci_alloc_irq_vectors failed - %d\n" , err); + goto err_unload_overlay; + } + +pci_set_drvdata (pdev, rp1); + rp1->domain =irq_domain_add_linear (of_find_node_by_name (NULL ,"pci-ep-bus" ),RP1_INT_END , + &rp1_domain_ops, rp1); + +for (i =0 ; i <RP1_INT_END ; i++) { +int irq =irq_create_mapping (rp1->domain, i); + +if (irq <0 ) { +dev_err (&pdev->dev,"failed to create irq mapping\n" ); + err = irq; + goto err_unload_overlay; + } +irq_set_chip_and_handler (irq, &rp1_irq_chip, handle_level_irq); +irq_set_probe (irq); +irq_set_chained_handler_and_data (pci_irq_vector (pdev, i), + rp1_chained_handle_irq, rp1); + } + + err =of_platform_default_populate (rp1_node,NULL , dev); +if (err) + goto err_unload_overlay; + +return 0 ; + +err_unload_overlay: +of_overlay_remove (&rp1->ovcs_id); + +return err; +}
drivers/misc/rp1/rp1_pci.c line 345
Quoted 10 lines
drivers/misc/rp1/rp1_pci.c new file +10
-0+ +static void rp1_remove (struct pci_dev *pdev) +{ +struct rp1_dev *rp1 =pci_get_drvdata (pdev); +struct device *dev = &pdev->dev; + +of_platform_depopulate (dev); +of_overlay_remove (&rp1->ovcs_id); + +clk_unregister (rp1->sys_clk);
Unless I missed something, rp1->sys_clk is never set in probe(). If this is correct, clk_unregister() should be removed and also the related clk header files.
The interrupt controller created at probe() should be destroyed at remove().
Quoted 2 lines
drivers/misc/rp1/rp1_pci.c new file +2
-0+} +
...
Quoted 10 lines
drivers/misc/rp1/rp1_pci.h new file +4
-0@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Copyright (c) 2018-24 Raspberry Pi Ltd.
drivers/misc/rp1/rp1_pci.h line 14
Quoted 10 lines
drivers/misc/rp1/rp1_pci.h new file +10
-0+* All rights reserved. +*/ + +#ifndef _RP1_EXTERN_H_ +#define _RP1_EXTERN_H_ + +extern char __dtbo_rp1_pci_begin[]; +extern char __dtbo_rp1_pci_end[]; + +#endif
These two symbols are only used by the rp1_pci.c file. Not sure that the rp1_pci.h is needed.
Simply declare the symbols in the rp1_pci.c file.
Best regards,
Hervé
Re: [PATCH v2 03/14] dt-bindings: pci: Add common schema for devices accessible through PCI BARs
In reply to Andrea della PortaQuoted 6 lines · Andrea della Porta
Common YAML schema for devices that exports internal peripherals through PCI BARs. The BARs are exposed as simple-buses through which the peripherals can be accessed.
This is not intended to be used as a standalone binding, but should be included by device specific bindings.
It still has to be tested before posting... Mailing list is not a testing service. My and Rob's machines are not a testing service.
Quoted 14 lines
Signed-off-by Andrea della Porta <[email protected]>--- .../devicetree/bindings/pci/pci-ep-bus.yaml | 69 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/pci-ep-bus.yamlDocumentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +0
-0
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml line 7
Quoted 7 lines
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +7
-0@@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pci/pci-ep-bus.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Common properties for PCI MFD endpoints with peripherals addressable from BARs.
Drop full stop and capitalize it.
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml line 19
Quoted 12 lines
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +12
-0+ +maintainers: + - Andrea della Porta <[email protected]> + +description: + Define a generic node representing a PCI endpoint which contains several sub- + peripherals. The peripherals can be accessed through one or more BARs. + This common schema is intended to be referenced from device tree bindings, and + does not represent a device tree binding by itself. + +properties: + "#address-cells":
Use consistent quotes, either ' or ".
Best regards,
Krzysztof
Re: [PATCH v2 04/14] dt-bindings: misc: Add device specific bindings for RaspberryPi RP1
In reply to Andrea della PortaQuoted 30 lines · Andrea della Porta
The 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.
Signed-off-by Andrea della Porta <[email protected]>--- .../devicetree/bindings/misc/pci1de4,1.yaml | 110 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 111 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/pci1de4,1.yamlDocumentation/devicetree/bindings/misc/pci1de4,1.yaml new file +13
-0@@ -0,0 +1,110 @@ +# 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: + - Andrea della Porta <[email protected]> + +description: + The RaspberryPi RP1 is a PCI multi function device containing
Documentation/devicetree/bindings/misc/pci1de4,1.yaml line 23
Quoted 10 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +10
-0+ 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
Why is this true? This is final schema, not a "common" part.
Quoted 24 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +24
-0+ maxItems: 3 + items: + - const: pci1de4,1 + +patternProperties: + "^pci-ep-bus@[0-2]$": + $ref: '#/$defs/bar-bus' + description: + The bus on which the peripherals are attached, which is addressable + through the BAR. + +unevaluatedProperties: false + +$defs: + bar-bus: + $ref: /schemas/pci/pci-ep-bus.yaml#/$defs/pci-ep-bus + unevaluatedProperties: false + + properties: + "#interrupt-cells": + const: 2 + description: + Specifies respectively the interrupt number and flags as defined + in include/dt-bindings/interrupt-controller/irq.h.
Documentation/devicetree/bindings/misc/pci1de4,1.yaml line 57
Quoted 10 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +10
-0+ + interrupt-controller: true + + interrupt-parent: + description: + Must be the phandle of this 'pci-ep-bus' node. It will trigger + PCI interrupts on behalf of peripheral generated interrupts. + + patternProperties: + "^clocks(@[0-9a-f]+)?$":
Why @ is optional? Your device is fixed, not flexible.
Best regards,
Krzysztof
Re: [PATCH v2 02/14] dt-bindings: pinctrl: Add RaspberryPi RP1 gpio/pinctrl/pinmux bindings
In reply to Andrea della PortaQuoted 27 lines · Andrea della Porta
Add device tree bindings for the gpio/pin/mux controller that is part of the RP1 multi function device, and relative entries in
MAINTAINERSfile.Signed-off-by Andrea della Porta <[email protected]>--- .../pinctrl/raspberrypi,rp1-gpio.yaml | 169 ++++++++++++++++++ MAINTAINERS | 2 + 2 files changed, 171 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yamlDocumentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +11
-0@@ -0,0 +1,169 @@ +# 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: + - Andrea della Porta <[email protected]> +
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml line 21
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +10
-0+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. + + Each pin configuration node lists the pin(s) to which it applies, and one or + more of the mux function to select on those pin(s), and their configuration. + The pin configuration and multiplexing supports the generic bindings. + For details on each properties (including the meaning of "pin configuration node"), + you can refer to ./pinctrl-bindings.txt.
Drop the sentence. pinctrl.yaml defines this already.
Quoted 26 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +26
-0+ +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. +
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml line 57
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +10
-0+ '#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 + +additionalProperties: + anyOf:
Uh, no, I think you got comments on this. You should be specific which nodes you expect, e.g. pins or groups. See other recent bindings for example.
Quoted 18 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +18
-0+ - type: object + additionalProperties: false + 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: + A string (or list of strings) adhering to the pattern "gpio[0-5][0-9]" + function: true + bias-disable: true + bias-pull-down: true
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml line 85
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +10
-0+ bias-pull-up: true + slew-rate: + description: 0 is slow slew rate, 1 is fast slew rate + enum: [ 0, 1 ] + drive-strength: + enum: [ 2, 4, 8, 12 ] + + - type: object + additionalProperties: + $ref: "#/additionalProperties/anyOf/0"
I don't quite get what you wanted to achieve here.
Quoted 60 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +60
-0+ +allOf: + - $ref: pinctrl.yaml# + +required: + - reg + - compatible + - "#gpio-cells" + - gpio-controller + - interrupts + - "#interrupt-cells" + - interrupt-controller + +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
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml line 155
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +10
-0+ "CD1_IO0_MICCLK", // GPIO46 + "2712_WAKE", // GPIO47 + "CD1_IO1_MICDAT1", // GPIO48 + "EN_MAX_USB_CUR", // GPIO49 + "", // GPIO50 + "", // GPIO51 + "", // GPIO52 + ""; // GPIO53 + + rp1_uart0_14_15: rp1_uart0_14_15 {
Underscores are not allowed in node names. Please read DTS coding style.
Drop unused labels.
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml line 160
Quoted 5 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +5
-0+ pin_txd { + function = "uart0"; + pins = "gpio14"; + bias-disable; + };
Best regards,
Krzysztof
Re: [PATCH v2 01/14] dt-bindings: clock: Add RaspberryPi RP1 clock bindings
In reply to Andrea della PortaQuoted 37 lines · Andrea della Porta
Add device tree bindings for the clock generator found in RP1 multi function device, and relative entries in
MAINTAINERSfile.Signed-off-by Andrea della Porta <[email protected]>--- .../clock/raspberrypi,rp1-clocks.yaml | 62 +++++++++++++++++++ MAINTAINERS | 6 ++ .../clock/raspberrypi,rp1-clocks.h | 61 ++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml create mode 100644 include/dt-bindings/clock/raspberrypi,rp1-clocks.hDocumentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +19
-0@@ -0,0 +1,62 @@ +# 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: + - Andrea 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 though 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 +
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml line 29
Quoted 10 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +10
-0+properties: + compatible: + const: raspberrypi,rp1-clocks + + reg: + maxItems: 1 + + '#clock-cells': + description: + The index in the assigned-clocks is mapped to the output clock as per
How assigned-clocks is related to this? Drop.
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml line 30
Quoted 1 line
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +1
-0+ definitions in dt-bindings/clock/raspberrypi,rp1-clocks.h.
Use full paths, so they can be validated. This applies to all your patches.
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml line 37
Quoted 7 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +7
-0+ const: 1 + + clocks: + maxItems: 1 + + clock-names: + const: rp1-xosc
Drop clock-names, redundant. Or just "xosc". Hyphens are not recommended character and rp1 is redundant.
Quoted 8 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +8
-0+ +required: + - compatible + - reg + - '#clock-cells' + - clocks + +additionalProperties: false
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml line 55
Quoted 10 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +10
-0+ +examples: + - | + #include <dt-bindings/clock/raspberrypi,rp1-clocks.h> + + rp1 { + #address-cells = <2>; + #size-cells = <2>; + + rp1_clocks: clocks@c040018000 {
Drop unused label.
Quoted 30 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +7
-0+ compatible = "raspberrypi,rp1-clocks"; + reg = <0xc0 0x40018000 0x0 0x10038>; + #clock-cells = <1>; + clocks = <&clk_rp1_xosc>; + clock-names = "rp1-xosc"; + }; + };MAINTAINERS +6
-0@@ -19380,6 +19380,12 @@ F: Documentation/devicetree/bindings/media/raspberrypi,pispbe.yaml F: drivers/media/platform/raspberrypi/pisp_be/ F: include/uapi/linux/media/raspberrypi/ +RASPBERRY PI RP1 PCI DRIVER +M: Andrea della Porta <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml +F: include/dt-bindings/clock/rp1.h + RC-CORE / LIRC FRAMEWORK M: Sean Young <[email protected]> L: [email protected]include/dt-bindings/clock/raspberrypi,rp1-clocks.h new file +0
-0
include/dt-bindings/clock/raspberrypi,rp1-clocks.h line 1
Quoted 1 line
include/dt-bindings/clock/raspberrypi,rp1-clocks.h new file +1
-0@@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */
Any reason for different license?
include/dt-bindings/clock/raspberrypi,rp1-clocks.h line 4
Quoted 3 lines
include/dt-bindings/clock/raspberrypi,rp1-clocks.h new file +3
-0+/* +* Copyright (C) 2021 Raspberry Pi Ltd. +*/
Best regards,
Krzysztof
Re: [PATCH v2 14/14] arm64: defconfig: Enable RP1 misc/clock/gpio drivers
In reply to Andrea della PortaQuoted 14 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]>--- arch/arm64/configs/defconfig | 3 +++ 1 file changed, 3 insertions(+)arch/arm64/configs/defconfig +0
-0
arch/arm64/configs/defconfig CONFIG_PINCTRL_QCM2290=y · line 612
Quoted 4 lines
arch/arm64/configs/defconfig +1
-0@@ -609,6 +609,7 @@ CONFIG_PINCTRL_QCM2290=y CONFIG_PINCTRL_QCS404=y CONFIG_PINCTRL_QDF2XXX=y CONFIG_PINCTRL_QDU1000=y +CONFIG_PINCTRL_RP1=y
Module, that's not a SoC component.
arch/arm64/configs/defconfig CONFIG_PINCTRL_QCM2290=y · line 614
Quoted 2 lines
arch/arm64/configs/defconfig +0
-0CONFIG_PINCTRL_SA8775P=y CONFIG_PINCTRL_SC7180=y
Best regards,
Krzysztof
Stephen Boyd
maintainerRe: [PATCH v2 08/14] clk: rp1: Add support for clocks provided by RP1
In reply to Andrea della PortaQuoting Andrea della Porta (2024-10-07 05:39:51)
drivers/clk/Kconfig config COMMON_CLK_RK808 · line 93
Quoted 11 lines
drivers/clk/Kconfig +3
-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 PCI || COMPILE_TEST
A better limit would be some ARCH_* config.
drivers/clk/Kconfig config COMMON_CLK_RK808 · line 94
Quoted 1 line
drivers/clk/Kconfig +1
-0+ depends on COMMON_CLK
This is redundant as it's inside the 'if COMMON_CLK'. Please remove this line.
Quoted 14 lines
drivers/clk/Kconfig +5
-0+ 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/clk-rp1.c new file +0
-0
drivers/clk/clk-rp1.c line 9
Quoted 9 lines
drivers/clk/clk-rp1.c new file +9
-0@@ -0,0 +1,1658 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2023 Raspberry Pi Ltd. +* +* Clock driver for RP1 PCIe multifunction chip. +*/ + +#include <linux/clk-provider.h> +#include <linux/clkdev.h>
Drop unused header.
drivers/clk/clk-rp1.c line 10
Quoted 1 line
drivers/clk/clk-rp1.c new file +1
-0+#include <linux/clk.h>
Preferably this include isn't included.
drivers/clk/clk-rp1.c line 16
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+#include <linux/debugfs.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/math64.h> +#include <linux/module.h> +#include <linux/of_device.h>
What is this include for? Should probably be mod_devicetable.h?
drivers/clk/clk-rp1.c line 20
Quoted 4 lines
drivers/clk/clk-rp1.c new file +4
-0+#include <linux/platform_device.h> +#include <linux/slab.h> + +#include <asm/div64.h>
Include math64.h instead?
Quoted 258 lines
drivers/clk/clk-rp1.c new file +258
-0+ +#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_SHIFT 16 +#define PLL_PRIM_DIV1_WIDTH 3 +#define PLL_PRIM_DIV1_MASK GENMASK(PLL_PRIM_DIV1_SHIFT + \ + PLL_PRIM_DIV1_WIDTH - 1, \ + PLL_PRIM_DIV1_SHIFT) +#define PLL_PRIM_DIV2_SHIFT 12 +#define PLL_PRIM_DIV2_WIDTH 3 +#define PLL_PRIM_DIV2_MASK GENMASK(PLL_PRIM_DIV2_SHIFT + \ + PLL_PRIM_DIV2_WIDTH - 1, \ + PLL_PRIM_DIV2_SHIFT) + +#define PLL_SEC_DIV_SHIFT 8 +#define PLL_SEC_DIV_WIDTH 5 +#define PLL_SEC_DIV_MASK GENMASK(PLL_SEC_DIV_SHIFT + \ + PLL_SEC_DIV_WIDTH - 1, \ + PLL_SEC_DIV_SHIFT) + +#define PLL_CS_LOCK BIT(31) +#define PLL_CS_REFDIV_SHIFT 0 + +#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)
drivers/clk/clk-rp1.c line 288
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+#define CLK_CTRL_AUXSRC_SHIFT 5 +#define CLK_CTRL_AUXSRC_WIDTH 5 +#define CLK_CTRL_AUXSRC_MASK GENMASK(CLK_CTRL_AUXSRC_SHIFT + \ + CLK_CTRL_AUXSRC_WIDTH - 1, \ + CLK_CTRL_AUXSRC_SHIFT) +#define CLK_CTRL_SRC_SHIFT 0 +#define CLK_DIV_FRAC_BITS 16 + +#define KHz 1000 +#define MHz (KHz * KHz)
I think we have these macros now. See include/linux/units.h.
Quoted 161 lines
drivers/clk/clk-rp1.c new file +161
-0+#define LOCK_TIMEOUT_NS 100000000 +#define FC_TIMEOUT_NS 100000000 + +#define MAX_CLK_PARENTS 16 + +/* +* Secondary PLL channel output divider table. +* Divider values range from 8 to 19. +* Invalid values default to 19 +*/ +static const struct clk_div_table pll_sec_div_table[] = { + {0x00 ,19 }, + {0x01 ,19 }, + {0x02 ,19 }, + {0x03 ,19 }, + {0x04 ,19 }, + {0x05 ,19 }, + {0x06 ,19 }, + {0x07 ,19 }, + {0x08 ,8 }, + {0x09 ,9 }, + {0x0a ,10 }, + {0x0b ,11 }, + {0x0c ,12 }, + {0x0d ,13 }, + {0x0e ,14 }, + {0x0f ,15 }, + {0x10 ,16 }, + {0x11 ,17 }, + {0x12 ,18 }, + {0x13 ,19 }, + {0x14 ,19 }, + {0x15 ,19 }, + {0x16 ,19 }, + {0x17 ,19 }, + {0x18 ,19 }, + {0x19 ,19 }, + {0x1a ,19 }, + {0x1b ,19 }, + {0x1c ,19 }, + {0x1d ,19 }, + {0x1e ,19 }, + {0x1f ,19 }, + {0 } +}; + +struct rp1_clockman { +struct device *dev; +void __iomem *regs; +spinlock_t regs_lock;/* spinlock for all clocks */ +struct clk_hw *hw_xosc;/* reference clock */ + +/* Must be last */ +struct clk_hw_onecell_data onecell; +}; + +struct rp1_pll_core_data { +const char *name; +u32 cs_reg; +u32 pwr_reg; +u32 fbdiv_int_reg; +u32 fbdiv_frac_reg; +unsigned long flags; +u32 fc0_src; +}; + +struct rp1_pll_data { +const char *name; +const char *source_pll; +u32 ctrl_reg; +unsigned long flags; +u32 fc0_src; +}; + +struct rp1_pll_ph_data { +const char *name; +const char *source_pll; +unsigned int phase; +unsigned int fixed_divider; +u32 ph_reg; +unsigned long flags; +u32 fc0_src; +}; + +struct rp1_pll_divider_data { +const char *name; +const char *source_pll; +u32 sec_reg; +unsigned long flags; +u32 fc0_src; +}; + +struct rp1_clock_data { +const char *name; +const char *const parents[MAX_CLK_PARENTS ]; +int num_std_parents; +int num_aux_parents; +unsigned long flags; +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_pll_core { +struct clk_hw hw; +struct rp1_clockman *clockman; +unsigned long cached_rate; +const struct rp1_pll_core_data *data; +}; + +struct rp1_pll { +struct clk_hw hw; +struct rp1_clockman *clockman; +struct clk_divider div; +unsigned long cached_rate; +const struct rp1_pll_data *data; +}; + +struct rp1_pll_ph { +struct clk_hw hw; +struct rp1_clockman *clockman; +const struct rp1_pll_ph_data *data; +}; + +struct rp1_clock { +struct clk_hw hw; +struct rp1_clockman *clockman; +unsigned long cached_rate; +const struct rp1_clock_data *data; +}; + +struct rp1_clk_change { +struct clk_hw *hw; +unsigned long new_rate; +}; + +struct rp1_clk_desc { +struct clk_hw *(*clk_register)(struct rp1_clockman *clockman, +const void *data); +const void *data; +}; + +static void rp1_debugfs_regset (struct rp1_clockman *clockman,u32 base, +const struct debugfs_reg32 *regs, +size_t nregs,struct dentry *dentry) +{ +struct debugfs_regset32 *regset; + + regset =devm_kzalloc (clockman->dev,sizeof (*regset),GFP_KERNEL ); +if (!regset) +return ; + + regset->regs = regs; + regset->nregs = nregs; + regset->base = clockman->regs + base;
drivers/clk/clk-rp1.c line 459
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ +debugfs_create_regset32 ("regdump" ,0444 , dentry, regset); +} + +static inline u32 set_register_field (u32 reg,u32 val,u32 mask,u32 shift) +{ + reg &= ~mask; + reg |= (val << shift) & mask; +return reg; +}
Can you use FIELD_PREP() and friends?
Quoted 45 lines
drivers/clk/clk-rp1.c new file +45
-0+ +static inline +void clockman_write (struct rp1_clockman *clockman,u32 reg,u32 val) +{ +writel (val, clockman->regs + reg); +} + +static inline u32 clockman_read (struct rp1_clockman *clockman,u32 reg) +{ +return readl (clockman->regs + reg); +} + +static int rp1_pll_core_is_on (struct clk_hw *hw) +{ + struct rp1_pll_core *pll_core = container_of(hw, struct rp1_pll_core, 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_pll_core *pll_core = container_of(hw, struct rp1_pll_core, hw); +struct rp1_clockman *clockman = pll_core->clockman; +const struct rp1_pll_core_data *data = pll_core->data; +u32 fbdiv_frac; +ktime_t timeout; + +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,1 <<PLL_CS_REFDIV_SHIFT ); + } + +/* 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); +
drivers/clk/clk-rp1.c line 514
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+/* Wait for the PLL to lock. */ + timeout =ktime_add_ns (ktime_get (),LOCK_TIMEOUT_NS ); +while (!(clockman_read (clockman, data->cs_reg) &PLL_CS_LOCK )) { +if (ktime_after (ktime_get (), timeout)) { +dev_err (clockman->dev,"%s: can't lock PLL\n" , +clk_hw_get_name (hw)); +return -ETIMEDOUT ; + } +cpu_relax (); + }
Is this readl_poll_timeout()?
Quoted 58 lines
drivers/clk/clk-rp1.c new file +58
-0+ +return 0 ; +} + +static void rp1_pll_core_off (struct clk_hw *hw) +{ + struct rp1_pll_core *pll_core = container_of(hw, struct rp1_pll_core, 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) +{ +unsigned long calc_rate; +u32 fbdiv_int, fbdiv_frac; +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 ; + + calc_rate = + ((u64 )parent_rate * (((u64 )fbdiv_int <<24 ) + fbdiv_frac) + (1 <<23 )) >>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_pll_core *pll_core = container_of(hw, struct rp1_pll_core, 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); +
drivers/clk/clk-rp1.c line 582
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ 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. */
Why is '16' special?
Quoted 18 lines
drivers/clk/clk-rp1.c new file +18
-0+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) | + (1 <<PLL_CS_REFDIV_SHIFT )); +spin_unlock (&clockman->regs_lock); + +return 0 ; +} + +static unsigned long rp1_pll_core_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{
drivers/clk/clk-rp1.c line 610
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ struct rp1_pll_core *pll_core = container_of(hw, struct rp1_pll_core, 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; + + fbdiv_int =clockman_read (clockman, data->fbdiv_int_reg); + fbdiv_frac =clockman_read (clockman, data->fbdiv_frac_reg); + calc_rate = + ((u64 )parent_rate * (((u64 )fbdiv_int <<24 ) + fbdiv_frac) + (1 <<23 )) >>24 ;
Where does '24' come from? Can you simplify this line somehow? Maybe break it up into multiple lines?
drivers/clk/clk-rp1.c line 623
Quoted 13 lines
drivers/clk/clk-rp1.c new file +13
-0+ +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; +long calc_rate; + + calc_rate =get_pll_core_divider (hw, rate, *parent_rate, + &fbdiv_int, &fbdiv_frac); +return calc_rate;
return get_pll_core_divider(...);
Quoted 14 lines
drivers/clk/clk-rp1.c new file +14
-0+} + +static void rp1_pll_core_debug_init (struct clk_hw *hw,struct dentry *dentry) +{ + struct rp1_pll_core *pll_core = container_of(hw, struct rp1_pll_core, hw); +struct rp1_clockman *clockman = pll_core->clockman; +const struct rp1_pll_core_data *data = pll_core->data; +struct debugfs_reg32 *regs; + + regs =devm_kcalloc (clockman->dev,4 ,sizeof (*regs),GFP_KERNEL ); +if (!regs) +return ; + + regs[0 ].name ="cs" ;
drivers/clk/clk-rp1.c line 647
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ regs[0 ].offset = data->cs_reg; + regs[1 ].name ="pwr" ; + regs[1 ].offset = data->pwr_reg; + regs[2 ].name ="fbdiv_int" ; + regs[2 ].offset = data->fbdiv_int_reg; + regs[3 ].name ="fbdiv_frac" ; + regs[3 ].offset = data->fbdiv_frac_reg; + +rp1_debugfs_regset (clockman,0 , regs,4 , dentry); +}
This can go behind CONFIG_DEBUG_FS so it isn't compiled unless debugfs is enabled.
Quoted 110 lines
drivers/clk/clk-rp1.c new file +110
-0+ +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_pll *pll = container_of(hw, struct rp1_pll, 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 =set_register_field (prim, prim_div1,PLL_PRIM_DIV1_MASK , +PLL_PRIM_DIV1_SHIFT ); + prim =set_register_field (prim, prim_div2,PLL_PRIM_DIV2_MASK , +PLL_PRIM_DIV2_SHIFT ); +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_pll *pll = container_of(hw, struct rp1_pll, 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 = (prim &PLL_PRIM_DIV1_MASK ) >>PLL_PRIM_DIV1_SHIFT ; + prim_div2 = (prim &PLL_PRIM_DIV2_MASK ) >>PLL_PRIM_DIV2_SHIFT ; + +if (!prim_div1 || !prim_div2) { +dev_err (clockman->dev,"%s: (%s) zero divider value\n" , + __func__, data->name); +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 void rp1_pll_debug_init (struct clk_hw *hw, +struct dentry *dentry) +{ + struct rp1_pll *pll = container_of(hw, struct rp1_pll, hw); +struct rp1_clockman *clockman = pll->clockman; +const struct rp1_pll_data *data = pll->data; +struct debugfs_reg32 *regs; + + regs =devm_kcalloc (clockman->dev,1 ,sizeof (*regs),GFP_KERNEL ); +if (!regs) +return ; + + regs[0 ].name ="prim" ; + regs[0 ].offset = data->ctrl_reg; + +rp1_debugfs_regset (clockman,0 , regs,1 , dentry); +} + +static int rp1_pll_ph_is_on (struct clk_hw *hw) +{ + struct rp1_pll_ph *pll = container_of(hw, struct rp1_pll_ph, hw); +struct rp1_clockman *clockman = pll->clockman; +const struct rp1_pll_ph_data *data = pll->data; + +return !!(clockman_read (clockman, data->ph_reg) &PLL_PH_EN );
drivers/clk/clk-rp1.c line 767
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+} + +static int rp1_pll_ph_on (struct clk_hw *hw) +{ + struct rp1_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, hw); +struct rp1_clockman *clockman = pll_ph->clockman; +const struct rp1_pll_ph_data *data = pll_ph->data; +u32 ph_reg; + +/* todo: ensure pri/sec is enabled! */
Capitalize TODO, or better yet do it and remove the comment.
Quoted 19 lines
drivers/clk/clk-rp1.c new file +19
-0+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_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, 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 );
drivers/clk/clk-rp1.c line 796
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+spin_unlock (&clockman->regs_lock); +} + +static int rp1_pll_ph_set_rate (struct clk_hw *hw, +unsigned long rate,unsigned long parent_rate) +{ + struct rp1_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, hw); +const struct rp1_pll_ph_data *data = pll_ph->data; + +/* Nothing really to do here! */
Is it read-only? Don't define a set_rate function then and make the rate determination function return the same value all the time.
Quoted 389 lines
drivers/clk/clk-rp1.c new file +389
-0+WARN_ON (data->fixed_divider !=1 && data->fixed_divider !=2 ); +WARN_ON (rate != parent_rate / data->fixed_divider); + +return 0 ; +} + +static unsigned long rp1_pll_ph_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ + struct rp1_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, 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_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, hw); +const struct rp1_pll_ph_data *data = pll_ph->data; + +return *parent_rate / data->fixed_divider; +} + +static void rp1_pll_ph_debug_init (struct clk_hw *hw, +struct dentry *dentry) +{ + struct rp1_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, hw); +const struct rp1_pll_ph_data *data = pll_ph->data; +struct rp1_clockman *clockman = pll_ph->clockman; +struct debugfs_reg32 *regs; + + regs =devm_kcalloc (clockman->dev,1 ,sizeof (*regs),GFP_KERNEL ); +if (!regs) +return ; + + regs[0 ].name ="ph_reg" ; + regs[0 ].offset = data->ph_reg; + +rp1_debugfs_regset (clockman,0 , regs,1 , dentry); +} + +static int rp1_pll_divider_is_on (struct clk_hw *hw) +{ + struct rp1_pll *divider = container_of(hw, struct rp1_pll, 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_pll *divider = container_of(hw, struct rp1_pll, 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_pll *divider = container_of(hw, struct rp1_pll, 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,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_pll *divider = container_of(hw, struct rp1_pll, 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 =set_register_field (sec, div,PLL_SEC_DIV_MASK ,PLL_SEC_DIV_SHIFT ); + +/* Must keep the divider in reset to change the value. */ + sec |=PLL_SEC_RST ; +clockman_write (clockman, data->ctrl_reg, sec); + +// todo: must sleep 10 pll vco cycles + 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 void rp1_pll_divider_debug_init (struct clk_hw *hw,struct dentry *dentry) +{ + struct rp1_pll *divider = container_of(hw, struct rp1_pll, div.hw); +struct rp1_clockman *clockman = divider->clockman; +const struct rp1_pll_data *data = divider->data; +struct debugfs_reg32 *regs; + + regs =devm_kcalloc (clockman->dev,1 ,sizeof (*regs),GFP_KERNEL ); +if (!regs) +return ; + + regs[0 ].name ="sec" ; + regs[0 ].offset = data->ctrl_reg; + +rp1_debugfs_regset (clockman,0 , regs,1 , dentry); +} + +static int rp1_clock_is_on (struct clk_hw *hw) +{ + struct rp1_clock *clock = container_of(hw, struct rp1_clock, 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_clock *clock = container_of(hw, struct rp1_clock, 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_clock *clock = container_of(hw, struct rp1_clock, 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_clock *clock = container_of(hw, struct rp1_clock, 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_clock *clock = container_of(hw, struct rp1_clock, 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 = (ctrl &CLK_CTRL_AUXSRC_MASK ) >>CLK_CTRL_AUXSRC_SHIFT ; + parent += data->num_std_parents; + } + +return parent; +} + +static int rp1_clock_set_parent (struct clk_hw *hw,u8 index) +{ + struct rp1_clock *clock = container_of(hw, struct rp1_clock, 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 =set_register_field (ctrl, index - data->num_std_parents, +CLK_CTRL_AUXSRC_MASK , +CLK_CTRL_AUXSRC_SHIFT ); +/* Set src to aux list */ + ctrl =set_register_field (ctrl,AUX_SEL , data->clk_src_mask, +CLK_CTRL_SRC_SHIFT ); + }else { + ctrl =set_register_field (ctrl, index, data->clk_src_mask, +CLK_CTRL_SRC_SHIFT ); + } + +clockman_write (clockman, data->ctrl_reg, ctrl); +spin_unlock (&clockman->regs_lock); + + sel =rp1_clock_get_parent (hw); +WARN (sel != index,"(%s): Parent index req %u returned back %u\n" , + data->name, 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_clock *clock = container_of(hw, struct rp1_clock, 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 (rate >4000000000ll ,"rate is -ve (%d)\n" , (int )rate); + +if (WARN (!div, +"clk divider calculated as 0! (%s, rate %ld, parent rate %ld)\n" , + data->name, 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_clock *clock = container_of(hw, struct rp1_clock, 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 > clock->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 ;
drivers/clk/clk-rp1.c line 1195
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+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 )) {
Is this flag ever set?
Quoted 58 lines
drivers/clk/clk-rp1.c new file +58
-0+ 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 void rp1_clk_debug_init (struct clk_hw *hw,struct dentry *dentry) +{ + struct rp1_clock *clock = container_of(hw, struct rp1_clock, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; +struct debugfs_reg32 *regs; +int i; + + regs =devm_kcalloc (clockman->dev,4 ,sizeof (*regs),GFP_KERNEL ); +if (!regs) +return ;
drivers/clk/clk-rp1.c line 1263
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ + i =0 ; + regs[i].name ="ctrl" ; + regs[i++].offset = data->ctrl_reg; + regs[i].name ="div_int" ; + regs[i++].offset = data->div_int_reg; + regs[i].name ="div_frac" ; + regs[i++].offset = data->div_frac_reg; + regs[i].name ="sel" ; + regs[i++].offset = data->sel_reg;
This time we get i but earlier it was hard-coded. Please be consistent. I suspect hard-coded is easier to follow so just do that.
drivers/clk/clk-rp1.c line 1265
Quoted 2 lines
drivers/clk/clk-rp1.c new file +2
-0+ +rp1_debugfs_regset (clockman,0 , regs, i, dentry);
I also wonder if regmap could be used? That has debugfs suport to read registers builtin already.
Quoted 52 lines
drivers/clk/clk-rp1.c new file +52
-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, + .debug_init = rp1_pll_core_debug_init, +}; + +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, + .debug_init = rp1_pll_debug_init, +}; + +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, + .set_rate = rp1_pll_ph_set_rate, + .recalc_rate = rp1_pll_ph_recalc_rate, + .round_rate = rp1_pll_ph_round_rate, + .debug_init = rp1_pll_ph_debug_init, +}; + +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, + .debug_init = rp1_pll_divider_debug_init, +}; + +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, + .debug_init = rp1_clk_debug_init, +}; +
drivers/clk/clk-rp1.c line 1327
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+static struct clk_hw *rp1_register_pll_core (struct rp1_clockman *clockman, +const void *data) +{ +const char *ref_clk_name =clk_hw_get_name (clockman->hw_xosc); +const struct rp1_pll_core_data *pll_core_data = data; +struct rp1_pll_core *pll_core; +struct clk_init_data init; +int ret; + +memset (&init,0 ,sizeof (init));
I think struct clk_init_data init = { } is more the style in clk drivers. Please do that instead of calling memset().
Quoted 100 lines
drivers/clk/clk-rp1.c new file +100
-0+ +/* All of the PLL cores derive from the external oscillator. */ + init.parent_names = &ref_clk_name; + init.num_parents =1 ; + init.name = pll_core_data->name; + init.ops = &rp1_pll_core_ops; + init.flags = pll_core_data->flags |CLK_IGNORE_UNUSED |CLK_IS_CRITICAL ; + + pll_core =devm_kzalloc (clockman->dev,sizeof (*pll_core),GFP_KERNEL ); +if (!pll_core) +return NULL ; + + pll_core->clockman = clockman; + pll_core->data = pll_core_data; + pll_core->hw.init = &init; + + ret =devm_clk_hw_register (clockman->dev, &pll_core->hw); +if (ret) +return ERR_PTR (ret); + +return &pll_core->hw; +} + +static struct clk_hw *rp1_register_pll (struct rp1_clockman *clockman, +const void *data) +{ +const struct rp1_pll_data *pll_data = data; +struct rp1_pll *pll; +struct clk_init_data init; +int ret; + +memset (&init,0 ,sizeof (init)); + + init.parent_names = &pll_data->source_pll; + init.num_parents =1 ; + init.name = pll_data->name; + init.ops = &rp1_pll_ops; + init.flags = pll_data->flags |CLK_IGNORE_UNUSED |CLK_IS_CRITICAL ; + + pll =devm_kzalloc (clockman->dev,sizeof (*pll),GFP_KERNEL ); +if (!pll) +return NULL ; + + pll->clockman = clockman; + pll->data = pll_data; + pll->hw.init = &init; + + ret =devm_clk_hw_register (clockman->dev, &pll->hw); +if (ret) +return ERR_PTR (ret); + +return &pll->hw; +} + +static struct clk_hw *rp1_register_pll_ph (struct rp1_clockman *clockman, +const void *data) +{ +const struct rp1_pll_ph_data *ph_data = data; +struct rp1_pll_ph *ph; +struct clk_init_data init; +int ret; + +memset (&init,0 ,sizeof (init)); + + init.parent_names = &ph_data->source_pll; + init.num_parents =1 ; + init.name = ph_data->name; + init.ops = &rp1_pll_ph_ops; + init.flags = ph_data->flags |CLK_IGNORE_UNUSED ; + + ph =devm_kzalloc (clockman->dev,sizeof (*ph),GFP_KERNEL ); +if (!ph) +return NULL ; + + ph->clockman = clockman; + ph->data = ph_data; + ph->hw.init = &init; + + ret =devm_clk_hw_register (clockman->dev, &ph->hw); +if (ret) +return ERR_PTR (ret); + +return &ph->hw; +} + +static struct clk_hw *rp1_register_pll_divider (struct rp1_clockman *clockman, +const void *data) +{ +const struct rp1_pll_data *divider_data = data; +struct rp1_pll *divider; +struct clk_init_data init; +int ret; + +memset (&init,0 ,sizeof (init)); + + init.parent_names = ÷r_data->source_pll; + init.num_parents =1 ; + init.name = divider_data->name; + init.ops = &rp1_pll_divider_ops; + init.flags = divider_data->flags |CLK_IGNORE_UNUSED |CLK_IS_CRITICAL ;
drivers/clk/clk-rp1.c line 1437
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ + divider =devm_kzalloc (clockman->dev,sizeof (*divider),GFP_KERNEL ); +if (!divider) +return NULL ; + + divider->div.reg = clockman->regs + divider_data->ctrl_reg; + divider->div.shift =PLL_SEC_DIV_SHIFT ; + divider->div.width =PLL_SEC_DIV_WIDTH ; + divider->div.flags =CLK_DIVIDER_ROUND_CLOSEST ; + divider->div.flags |=CLK_IS_CRITICAL ;
Is everything critical? The usage of this flag and CLK_IGNORE_UNUSED is suspicious and likely working around some problems elsewhere.
Quoted 109 lines
drivers/clk/clk-rp1.c new file +109
-0+ divider->div.lock = &clockman->regs_lock; + divider->div.hw.init = &init; + divider->div.table = pll_sec_div_table; + + divider->clockman = clockman; + divider->data = divider_data; + + ret =devm_clk_hw_register (clockman->dev, ÷r->div.hw); +if (ret) +return ERR_PTR (ret); + +return ÷r->div.hw; +} + +static struct clk_hw *rp1_register_clock (struct rp1_clockman *clockman, +const void *data) +{ +const struct rp1_clock_data *clock_data = data; +struct rp1_clock *clock; +struct clk_init_data init; +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 && +strcmp ("-" , clock_data->parents[AUX_SEL ]))) +return NULL ; + +memset (&init,0 ,sizeof (init)); + init.parent_names = clock_data->parents; + init.num_parents = clock_data->num_std_parents + + clock_data->num_aux_parents; + init.name = clock_data->name; + init.flags = clock_data->flags |CLK_IGNORE_UNUSED ; + init.ops = &rp1_clk_ops; + + clock =devm_kzalloc (clockman->dev,sizeof (*clock),GFP_KERNEL ); +if (!clock) +return NULL ; + + clock->clockman = clockman; + clock->data = clock_data; + clock->hw.init = &init; + + ret =devm_clk_hw_register (clockman->dev, &clock->hw); +if (ret) +return ERR_PTR (ret); + +return &clock->hw; +} + +/* Assignment helper macros for different clock types. */ +#define _REGISTER (f, ...) { .clk_register = f, .data = __VA_ARGS__ } + +#define REGISTER_PLL_CORE (...) _REGISTER(&rp1_register_pll_core, \ + &(struct rp1_pll_core_data) \ + {__VA_ARGS__}) + +#define REGISTER_PLL (...) _REGISTER(&rp1_register_pll, \ + &(struct rp1_pll_data) \ + {__VA_ARGS__}) + +#define REGISTER_PLL_PH (...) _REGISTER(&rp1_register_pll_ph, \ + &(struct rp1_pll_ph_data) \ + {__VA_ARGS__}) + +#define REGISTER_PLL_DIV (...) _REGISTER(&rp1_register_pll_divider, \ + &(struct rp1_pll_data) \ + {__VA_ARGS__}) + +#define REGISTER_CLK (...) _REGISTER(&rp1_register_clock, \ + &(struct rp1_clock_data) \ + {__VA_ARGS__}) + +static const struct rp1_clk_desc clk_desc_array[] = { + [RP1_PLL_SYS_CORE] = REGISTER_PLL_CORE(.name = "pll_sys_core", + .cs_reg =PLL_SYS_CS , + .pwr_reg =PLL_SYS_PWR , + .fbdiv_int_reg =PLL_SYS_FBDIV_INT , + .fbdiv_frac_reg =PLL_SYS_FBDIV_FRAC , + ), + + [RP1_PLL_AUDIO_CORE] = REGISTER_PLL_CORE(.name = "pll_audio_core", + .cs_reg =PLL_AUDIO_CS , + .pwr_reg =PLL_AUDIO_PWR , + .fbdiv_int_reg =PLL_AUDIO_FBDIV_INT , + .fbdiv_frac_reg =PLL_AUDIO_FBDIV_FRAC , + ), + + [RP1_PLL_VIDEO_CORE] = REGISTER_PLL_CORE(.name = "pll_video_core", + .cs_reg =PLL_VIDEO_CS , + .pwr_reg =PLL_VIDEO_PWR , + .fbdiv_int_reg =PLL_VIDEO_FBDIV_INT , + .fbdiv_frac_reg =PLL_VIDEO_FBDIV_FRAC , + ), + + [RP1_PLL_SYS] = REGISTER_PLL(.name = "pll_sys", + .source_pll ="pll_sys_core" , + .ctrl_reg =PLL_SYS_PRIM , + .fc0_src =FC_NUM (0 ,2 ), + ), + + [RP1_CLK_ETH_TSU] = REGISTER_CLK(.name = "clk_eth_tsu", + .parents = {"rp1-xosc" }, + .num_std_parents =0 , + .num_aux_parents =1 ,
drivers/clk/clk-rp1.c line 1556
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ .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 * MHz, + .fc0_src = FC_NUM(5, 7), + ), + + [RP1_CLK_SYS] = REGISTER_CLK(.name = "clk_sys", + .parents = {"rp1-xosc", "-", "pll_sys"},
Please use struct clk_parent_data or clk_hw directly. Don't use strings to describe parents.
Quoted 22 lines
drivers/clk/clk-rp1.c new file +22
-0+ .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 * MHz, + .fc0_src = FC_NUM(0, 4), + .clk_src_mask = 0x3, + ), + + [RP1_PLL_SYS_PRI_PH] = REGISTER_PLL_PH(.name = "pll_sys_pri_ph", + .source_pll = "pll_sys", + .ph_reg = PLL_SYS_PRIM, + .fixed_divider = 2, + .phase = RP1_PLL_PHASE_0, + .fc0_src = FC_NUM(1, 2), + ), + + [RP1_PLL_SYS_SEC] = REGISTER_PLL_DIV(.name = "pll_sys_sec", + .source_pll = "pll_sys_core", + .ctrl_reg = PLL_SYS_SEC,
drivers/clk/clk-rp1.c line 1588
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ .fc0_src = FC_NUM(2, 2), + ), +}; + +static int rp1_clk_probe (struct platform_device *pdev) +{ +const size_t asize =ARRAY_SIZE (clk_desc_array); +const struct rp1_clk_desc *desc; +struct device *dev = &pdev->dev; +struct rp1_clockman *clockman;
I love the name 'clockman'!
Quoted 11 lines
drivers/clk/clk-rp1.c new file +11
-0+struct clk *clk_xosc; +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;
drivers/clk/clk-rp1.c line 1609
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ + clockman->regs =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (clockman->regs)) +return PTR_ERR (clockman->regs); + + clk_xosc =devm_clk_get_enabled (dev,NULL ); +if (IS_ERR (clk_xosc)) +return PTR_ERR (clk_xosc); + + clockman->hw_xosc =__clk_get_hw (clk_xosc);
Please use struct clk_parent_data::index instead.
drivers/clk/clk-rp1.c line 1618
Quoted 9 lines
drivers/clk/clk-rp1.c new file +9
-0+ clockman->onecell.num = asize; + hws = clockman->onecell.hws; + +for (i =0 ; i < asize; i++) { + desc = &clk_desc_array[i]; +if (desc->clk_register && desc->data) { + hws[i] = desc->clk_register (clockman, desc->data); +if (IS_ERR_OR_NULL (hws[i])) + dev_err(dev, "Unable to register clock: %s\n",
Use dev_err_probe() please.
Quoted 25 lines
drivers/clk/clk-rp1.c new file +25
-0+ 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, +}; + +static int __init rp1_clk_driver_init (void )
drivers/clk/clk-rp1.c line 1653
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+{ +return platform_driver_register (&rp1_clk_driver); +} +postcore_initcall (rp1_clk_driver_init); + +static void __exit rp1_clk_driver_exit(void) +{ +platform_driver_unregister (&rp1_clk_driver); +} +module_exit (rp1_clk_driver_exit);
Can you use module_platform_driver()?
Rob Herring
maintainerRe: [PATCH v2 03/14] dt-bindings: pci: Add common schema for devices accessible through PCI BARs
In reply to Andrea della PortaQuoted 48 lines · Andrea della Porta
Common YAML schema for devices that exports internal peripherals through PCI BARs. The BARs are exposed as simple-buses through which the peripherals can be accessed.
This is not intended to be used as a standalone binding, but should be included by device specific bindings.
Signed-off-by Andrea della Porta <[email protected]>--- .../devicetree/bindings/pci/pci-ep-bus.yaml | 69 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/pci-ep-bus.yamlDocumentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +28
-0@@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pci/pci-ep-bus.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Common properties for PCI MFD endpoints with peripherals addressable from BARs. + +maintainers: + - Andrea della Porta <[email protected]> + +description: + Define a generic node representing a PCI endpoint which contains several sub- + peripherals. The peripherals can be accessed through one or more BARs. + This common schema is intended to be referenced from device tree bindings, and + does not represent a device tree binding by itself. + +properties: + "#address-cells": + const: 3 + + "#size-cells": + const: 2 + + ranges: + minItems: 1 + maxItems: 6 + items:
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml line 38
Quoted 10 lines
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +10
-0+ maxItems: 8 + additionalItems: true + items: + - maximum: 5 # The BAR number + - const: 0 + - const: 0 + +patternProperties: + "^pci-ep-bus@[0-5]$": + $ref: '#/$defs/pci-ep-bus'
This should just be:
additionalProperties: true
properties:
compatible:
const: simple-bus
required:
- compatible
Then the compatible will cause simple-bus.yaml to be applied to this node.
Quoted 20 lines
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +20
-0+ description: + One node for each BAR used by peripherals contained in the PCI endpoint. + Each node represent a bus on which peripherals are connected. + This allows for some segmentation, e.g. one peripheral is accessible + through BAR0 and another through BAR1, and you don't want the two + peripherals to be able to act on the other BAR. Alternatively, when + different peripherals need to share BARs, you can define only one node + and use 'ranges' property to map all the used BARs. + +required: + - ranges + - '#address-cells' + - '#size-cells' + +$defs: + pci-ep-bus: + type: object + additionalProperties: true + properties: + compatible:
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml line 68
Quoted 10 lines
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +10
-0+ const: simple-bus + dma-ranges: true + ranges: true + "#address-cells": true + "#size-cells": true + required: + - compatible + - ranges + - '#address-cells' + - '#size-cells'
All this should be covered by simple-bus.yaml.
Rob
Rob Herring
maintainerRe: [PATCH v2 04/14] dt-bindings: misc: Add device specific bindings for RaspberryPi RP1
In reply to Andrea della PortaQuoted 40 lines · Andrea della Porta
The 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.
Signed-off-by Andrea della Porta <[email protected]>--- .../devicetree/bindings/misc/pci1de4,1.yaml | 110 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 111 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/pci1de4,1.yamlDocumentation/devicetree/bindings/misc/pci1de4,1.yaml new file +23
-0@@ -0,0 +1,110 @@ +# 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: + - Andrea 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
Documentation/devicetree/bindings/misc/pci1de4,1.yaml line 33
Quoted 10 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +10
-0+ maxItems: 3 + items: + - const: pci1de4,1 + +patternProperties: + "^pci-ep-bus@[0-2]$": + $ref: '#/$defs/bar-bus' + description: + The bus on which the peripherals are attached, which is addressable + through the BAR.
No need for this because pci-ep-bus.yaml already has a schema for the child nodes.
Quoted 11 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +11
-0+ +unevaluatedProperties: false + +$defs: + bar-bus: + $ref: /schemas/pci/pci-ep-bus.yaml#/$defs/pci-ep-bus + unevaluatedProperties: false + + properties: + "#interrupt-cells": + const: 2
Documentation/devicetree/bindings/misc/pci1de4,1.yaml line 54
Quoted 10 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +10
-0+ description: + Specifies respectively the interrupt number and flags as defined + in include/dt-bindings/interrupt-controller/irq.h. + + interrupt-controller: true + + interrupt-parent: + description: + Must be the phandle of this 'pci-ep-bus' node. It will trigger + PCI interrupts on behalf of peripheral generated interrupts.
Do you have an interrupt controller per bus? These should be in the parent node I think.
Documentation/devicetree/bindings/misc/pci1de4,1.yaml line 67
Quoted 13 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +13
-0+ + patternProperties: + "^clocks(@[0-9a-f]+)?$": + type: object + $ref: /schemas/clock/raspberrypi,rp1-clocks.yaml + + "^ethernet(@[0-9a-f]+)?$": + type: object + $ref: /schemas/net/cdns,macb.yaml + + "^pinctrl(@[0-9a-f]+)?$": + type: object + $ref: /schemas/pinctrl/raspberrypi,rp1-gpio.yaml
IMO, these child nodes can be omitted. We generally don't define all the child nodes in an SoC.
If you do want to define them, then just do:
additionalProperties: true
properties:
compatible:
contains: the-child-compatible
Quoted 58 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +43
-0+ + required: + - interrupt-parent + - interrupt-controller + +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>; + + pci_ep_bus: pci-ep-bus@1 { + compatible = "simple-bus"; + ranges = <0xc0 0x40000000 + 0x01 0x00 0x00000000 + 0x00 0x00400000>; + dma-ranges = <0x10 0x00000000 + 0x43000000 0x10 0x00000000 + 0x10 0x00000000>; + #address-cells = <2>; + #size-cells = <2>; + interrupt-controller; + interrupt-parent = <&pci_ep_bus>; + #interrupt-cells = <2>; + + rp1_clocks: clocks@c040018000 { + compatible = "raspberrypi,rp1-clocks"; + reg = <0xc0 0x40018000 0x0 0x10038>; + #clock-cells = <1>; + clocks = <&clk_rp1_xosc>; + clock-names = "rp1-xosc"; + }; + }; + }; + };MAINTAINERS +1
-0@@ -19384,6 +19384,7 @@ RASPBERRY PI RP1 PCI DRIVER M: Andrea della Porta <[email protected]> S: Maintained F: Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml +F: Documentation/devicetree/bindings/misc/pci1de4,1.yaml F: Documentation/devicetree/bindings/pci/pci-ep-bus.yaml F: Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml F: include/dt-bindings/clock/rp1.hSignature · 1 line
2.35.3
kernel test robot
build botRe: [PATCH v2 11/14] misc: rp1: RaspberryPi RP1 misc driver
In reply to Andrea della Portakernel test robot noticed the following build errors:
Hi Andrea,
kernel test robot noticed the following build errors:
[auto build test ERROR on robh/for-next]
[also build test ERROR on clk/clk-next char-misc/char-misc-testing char-misc/char-misc-next char-misc/char-misc-linus linus/master v6.12-rc2 next-20241010] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andrea-della-Porta/dt-bindings-clock-Add-RaspberryPi-RP1-clock-bindings/20241007-204440 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next patch link: https://lore.kernel.org/r/c5b072393d2dc157d34f6dbeff6261d142d4de69.1728300190.git.andrea.porta%40suse.com patch subject: [PATCH v2 11/14] misc: rp1: RaspberryPi RP1 misc driver config: alpha-randconfig-r061-20241011 (https://download.01.org/0day-ci/archive/20241011/[email protected]/config) compiler: alpha-linux-gcc (GCC) 13.3.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241011/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/misc/rp1/rp1_pci.c: In function 'rp1_mask_irq':
>> drivers/misc/rp1/rp1_pci.c:139:9: error: implicit declaration of function 'pci_msi_mask_irq'; did you mean 'pci_msix_free_irq'? [-Werror=implicit-function-declaration]
139 | pci_msi_mask_irq(pcie_irqd);
| ^~~~~~~~~~~~~~~~
| pci_msix_free_irq
drivers/misc/rp1/rp1_pci.c: In function 'rp1_unmask_irq':
>> drivers/misc/rp1/rp1_pci.c:147:9: error: implicit declaration of function 'pci_msi_unmask_irq' [-Werror=implicit-function-declaration]
147 | pci_msi_unmask_irq(pcie_irqd);
| ^~~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for GET_FREE_REGION Depends on [n]: SPARSEMEM [=n]
Selected by [y]:
- RESOURCE_KUNIT_TEST [=y] && RUNTIME_TESTING_MENU [=y] && KUNIT [=y]
vim +139 drivers/misc/rp1/rp1_pci.c
133
134 static void rp1_mask_irq(struct irq_data *irqd)
135 {
136 struct rp1_dev *rp1 = irqd->domain->host_data;
137 struct irq_data *pcie_irqd = rp1->pcie_irqds[irqd->hwirq];
138
> 139 pci_msi_mask_irq(pcie_irqd);
140 }
141
142 static void rp1_unmask_irq(struct irq_data *irqd)
143 {
144 struct rp1_dev *rp1 = irqd->domain->host_data;
145 struct irq_data *pcie_irqd = rp1->pcie_irqds[irqd->hwirq];
146
> 147 pci_msi_unmask_irq(pcie_irqd); 148 }
149
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v2 11/14] misc: rp1: RaspberryPi RP1 misc driver
In reply to Andrea della Portakernel test robot noticed the following build warnings:
Hi Andrea,
kernel test robot noticed the following build warnings:
[auto build test WARNING on robh/for-next]
[also build test WARNING on clk/clk-next char-misc/char-misc-testing char-misc/char-misc-next char-misc/char-misc-linus linus/master v6.12-rc2 next-20241010] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andrea-della-Porta/dt-bindings-clock-Add-RaspberryPi-RP1-clock-bindings/20241007-204440 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next patch link: https://lore.kernel.org/r/c5b072393d2dc157d34f6dbeff6261d142d4de69.1728300190.git.andrea.porta%40suse.com patch subject: [PATCH v2 11/14] misc: rp1: RaspberryPi RP1 misc driver config: sparc-kismet-CONFIG_OF_IRQ-CONFIG_MISC_RP1-0-0 (https://download.01.org/0day-ci/archive/20241011/[email protected]/config) reproduce: (https://download.01.org/0day-ci/archive/20241011/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
kismet warnings: (new ones prefixed by >>)
>> kismet: WARNING: unmet direct dependencies detected for OF_IRQ when selected by MISC_RP1
WARNING: unmet direct dependencies detected for OF_IRQ
Depends on [n]: OF [=y] && !SPARC [=y] && IRQ_DOMAIN [=y] Selected by [y]:
- MISC_RP1 [=y] && PCI [=y] && PCI_QUIRKS [=y]
WARNING: unmet direct dependencies detected for GET_FREE_REGION
Depends on [n]: SPARSEMEM [=n]
Selected by [y]:
- RESOURCE_KUNIT_TEST [=y] && RUNTIME_TESTING_MENU [=y] && KUNIT [=y]
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 09/14] pinctrl: rp1: Implement RaspberryPi RP1 gpio support
In reply to Andrea della PortaQuoted 6 lines · Andrea della Porta
The 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.
Signed-off-by Andrea della Porta <[email protected]>
This is a nice driver and I find no issues with it, what causes an issue is gpiochip_set_names() as pointed out by Bartosz. If you can live without the names you can remove that part for now and we can merge the driver, then you can add the names later when we sorted out how to share that function.
Yours,
Linus Walleij
Re: [PATCH v2 09/14] pinctrl: rp1: Implement RaspberryPi RP1 gpio support
Am 11.10.24 um 11:03 schrieb Linus Walleij:
Quoted 7 lines · Andrea della Porta
Quoted 6 lines
The 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.
Quoted 6 lines
Quoted 1 line
Signed-off-by Andrea della Porta <[email protected]>This is a nice driver and I find no issues with it, what causes an issue is
gpiochip_set_names()as pointed out by Bartosz. If you can live without the names you can remove that part for now and we can merge the driver, then you can add the names later when we sorted out how to share that function.
I raised the concerns about missing gpio line names in the first version of patch, without knowing the real efforts.
So I'm fine with Linus' suggestion, because I don't want to delay the upstreaming effort unnecessarily.
Regards
Quoted 3 lines
Yours,
Linus Walleij
Andrea della Porta
maintainerRe: [PATCH v2 01/14] dt-bindings: clock: Add RaspberryPi RP1 clock bindings
In reply to Krzysztof KozlowskiHi Krzysztof,
Quoted 42 lines · Krzysztof Kozlowski
Quoted 41 lines · Andrea della Porta
Add device tree bindings for the clock generator found in RP1 multi function device, and relative entries in
MAINTAINERSfile.Signed-off-by Andrea della Porta <[email protected]>--- .../clock/raspberrypi,rp1-clocks.yaml | 62 +++++++++++++++++++ MAINTAINERS | 6 ++ .../clock/raspberrypi,rp1-clocks.h | 61 ++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml create mode 100644 include/dt-bindings/clock/raspberrypi,rp1-clocks.hDocumentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +23
-0@@ -0,0 +1,62 @@ +# 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: + - Andrea 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 though 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 +
Quoted 8 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml line 29
Quoted 6 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +6
-0+ reg: + maxItems: 1 + + '#clock-cells': + description: + The index in the assigned-clocks is mapped to the output clock as perHow assigned-clocks is related to this? Drop.
This node provides clock for several peripherals, and for minimum functionality at least 3 clocks have to be setup through assigned-clocks (and assigned-clock-rates). That should be done in this same node (the provider of the clocks) because those clocks are shared among peripherals or clock generators, so cannot be described from consumers or we could incur in multiple declaration of the same clock. I dropped the assigned-clocks and assigned-clock-rates from the example section because Conor commented (see the first patchset version) that according to him those properties were not relevant there, maybe I failed to produce a careful explanation about why they are important. What should be the right course of action, then? Just drop that description or leave it as it is (maybe augmenting it with what I've explained here) and add again the dropped properties in the example? I would be inclined to vote for the latter, but I'm not sure...
Quoted 5 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml line 30
Quoted 2 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +1
-0+ definitions in dt-bindings/clock/raspberrypi,rp1-clocks.h.Use full paths, so they can be validated. This applies to all your patches.
Ack.
Quoted 11 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml line 37
Quoted 8 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +7
-0+ const: 1 + + clocks: + maxItems: 1 + + clock-names: + const: rp1-xoscDrop clock-names, redundant. Or just "xosc". Hyphens are not recommended character and rp1 is redundant.
Ack.
Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +12
-0+ +required: + - compatible + - reg + - '#clock-cells' + - clocks + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/raspberrypi,rp1-clocks.h>
Quoted 8 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml line 55
Quoted 6 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +6
-0+ + rp1 { + #address-cells = <2>; + #size-cells = <2>; + + rp1_clocks: clocks@c040018000 {Drop unused label.
Ack.
Quoted 26 lines
Quoted 26 lines
Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml new file +7
-0+ compatible = "raspberrypi,rp1-clocks"; + reg = <0xc0 0x40018000 0x0 0x10038>; + #clock-cells = <1>; + clocks = <&clk_rp1_xosc>; + clock-names = "rp1-xosc"; + }; + };MAINTAINERS +6
-0@@ -19380,6 +19380,12 @@ F: Documentation/devicetree/bindings/media/raspberrypi,pispbe.yaml F: drivers/media/platform/raspberrypi/pisp_be/ F: include/uapi/linux/media/raspberrypi/ +RASPBERRY PI RP1 PCI DRIVER +M: Andrea della Porta <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml +F: include/dt-bindings/clock/rp1.h + RC-CORE / LIRC FRAMEWORK M: Sean Young <[email protected]> L: [email protected]include/dt-bindings/clock/raspberrypi,rp1-clocks.h +0
-0
Quoted 8 lines
include/dt-bindings/clock/raspberrypi,rp1-clocks.h line 1
Quoted 6 lines
new file mode 100644
index 000000000000..b7c1eaa74eaeinclude/dt-bindings/clock/raspberrypi,rp1-clocks.h new file +1
-0@@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ Any reason for different license?
Not really, I'll revert it back to the usual (GPL-2.0-only OR BSD-2-Clause), as the other schemas.
Many thanks,
Andrea
Quoted 8 lines
include/dt-bindings/clock/raspberrypi,rp1-clocks.h line 4
Quoted 4 lines
include/dt-bindings/clock/raspberrypi,rp1-clocks.h new file +3
-0+/* +* Copyright (C) 2021 Raspberry Pi Ltd. +*/ Best regards,
Krzysztof
Andrea della Porta
maintainerRe: [PATCH v2 02/14] dt-bindings: pinctrl: Add RaspberryPi RP1 gpio/pinctrl/pinmux bindings
In reply to Krzysztof KozlowskiHi Krzysztof,
Quoted 32 lines · Krzysztof Kozlowski
Quoted 31 lines · Andrea della Porta
Add device tree bindings for the gpio/pin/mux controller that is part of the RP1 multi function device, and relative entries in
MAINTAINERSfile.Signed-off-by Andrea della Porta <[email protected]>--- .../pinctrl/raspberrypi,rp1-gpio.yaml | 169 ++++++++++++++++++ MAINTAINERS | 2 + 2 files changed, 171 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yamlDocumentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +15
-0@@ -0,0 +1,169 @@ +# 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: + - Andrea 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.
Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml line 21
Quoted 6 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +6
-0+ + Each pin configuration node lists the pin(s) to which it applies, and one or + more of the mux function to select on those pin(s), and their configuration. + The pin configuration and multiplexing supports the generic bindings. + For details on each properties (including the meaning of "pin configuration node"), + you can refer to ./pinctrl-bindings.txt.Drop the sentence.
pinctrl.yamldefines this already.
Just to be sure, by 'sentence' I assume you mean the entire paragraph from "Each pin configuration..." to "...refer to ./pinctrl-bindings.txt.", right?
Quoted 33 lines
Quoted 33 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +32
-0+ +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 +
Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml line 57
Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +4
-0+ interrupt-controller: true + +additionalProperties: + anyOf:Uh, no, I think you got comments on this. You should be specific which nodes you expect, e.g. pins or groups. See other recent bindings for example.
Please see below.
Quoted 23 lines
Quoted 23 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +22
-0+ - type: object + additionalProperties: false + 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: + A string (or list of strings) adhering to the pattern "gpio[0-5][0-9]" + function: true + bias-disable: true + bias-pull-down: true + bias-pull-up: true + slew-rate: + description: 0 is slow slew rate, 1 is fast slew rate + enum: [ 0, 1 ]
Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml line 85
Quoted 6 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +6
-0+ drive-strength: + enum: [ 2, 4, 8, 12 ] + + - type: object + additionalProperties: + $ref: "#/additionalProperties/anyOf/0"I don't quite get what you wanted to achieve here.
This should be a compact way to describe a schema that allows declarations like the following:
rp1_gpio {
...
/* grouped gpios */
rp1_uart0_14_15: rp1_uart0_14_15 {
pin_txd {
function = "uart0";
pins = "gpio14";
bias-disable;
}; pin_rxd {
function = "uart0";
pins = "gpio15";
bias-pull-up;
};};
/* standalone pins */
rp1_i2s0_18_21: rp1_i2s0_18_21 {
function = "i2s0";
pins = "gpio18", "gpio19", "gpio20", "gpio21";
bias-disable;
}; ...
};
that is, both standalone and group pinctrl/pinmux node.
Quoted 74 lines
Quoted 61 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +60
-0+ +allOf: + - $ref: pinctrl.yaml# + +required: + - reg + - compatible + - "#gpio-cells" + - gpio-controller + - interrupts + - "#interrupt-cells" + - interrupt-controller + +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", // GPIO45Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml line 155
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +10
-0+ "CD1_IO0_MICCLK", // GPIO46 + "2712_WAKE", // GPIO47 + "CD1_IO1_MICDAT1", // GPIO48 + "EN_MAX_USB_CUR", // GPIO49 + "", // GPIO50 + "", // GPIO51 + "", // GPIO52 + ""; // GPIO53 + + rp1_uart0_14_15: rp1_uart0_14_15 {Underscores are not allowed in node names. Please read DTS coding style.
Quoted 1 line
Drop unused labels.
Ack.
Many thanks,
Andrea
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml line 160
Quoted 6 lines
Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml new file +5
-0+ pin_txd { + function = "uart0"; + pins = "gpio14"; + bias-disable; + };Best regards,
Krzysztof
Andrea della Porta
maintainerRe: [PATCH v2 03/14] dt-bindings: pci: Add common schema for devices accessible through PCI BARs
In reply to Krzysztof KozlowskiHi Krzysztof,
Quoted 10 lines · Krzysztof Kozlowski
Quoted 6 lines · Andrea della Porta
Common YAML schema for devices that exports internal peripherals through PCI BARs. The BARs are exposed as simple-buses through which the peripherals can be accessed.
This is not intended to be used as a standalone binding, but should be included by device specific bindings.
It still has to be tested before posting... Mailing list is not a testing service. My and Rob's machines are not a testing service.
Sorry about that, I must have missed that file when rechecking all the schemas after rebasing on 6.12-rc1.
Quoted 9 lines
Quoted 9 lines
Signed-off-by Andrea della Porta <[email protected]>--- .../devicetree/bindings/pci/pci-ep-bus.yaml | 69 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/pci-ep-bus.yaml
Quoted 15 lines
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml line 7
Quoted 13 lines
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +7
-0@@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pci/pci-ep-bus.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Common properties for PCI MFD endpoints with peripherals addressable from BARs.Drop full stop and capitalize it.
Ack.
Quoted 15 lines
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml line 19
Quoted 13 lines
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +12
-0+ +maintainers: + - Andrea della Porta <[email protected]> + +description: + Define a generic node representing a PCI endpoint which contains several sub- + peripherals. The peripherals can be accessed through one or more BARs. + This common schema is intended to be referenced from device tree bindings, and + does not represent a device tree binding by itself. + +properties: + "#address-cells":Use consistent quotes, either ' or ".
Ack.
Many thanks,
Andrea
Quoted 4 lines
Best regards,
Krzysztof
Andrea della Porta
maintainerRe: [PATCH v2 03/14] dt-bindings: pci: Add common schema for devices accessible through PCI BARs
In reply to Rob HerringHi Rob,
Quoted 68 lines · Rob Herring
Quoted 48 lines · Andrea della Porta
Common YAML schema for devices that exports internal peripherals through PCI BARs. The BARs are exposed as simple-buses through which the peripherals can be accessed.
This is not intended to be used as a standalone binding, but should be included by device specific bindings.
Signed-off-by Andrea della Porta <[email protected]>--- .../devicetree/bindings/pci/pci-ep-bus.yaml | 69 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/pci-ep-bus.yamlDocumentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +28
-0@@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pci/pci-ep-bus.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Common properties for PCI MFD endpoints with peripherals addressable from BARs. + +maintainers: + - Andrea della Porta <[email protected]> + +description: + Define a generic node representing a PCI endpoint which contains several sub- + peripherals. The peripherals can be accessed through one or more BARs. + This common schema is intended to be referenced from device tree bindings, and + does not represent a device tree binding by itself. + +properties: + "#address-cells": + const: 3 + + "#size-cells": + const: 2 + + ranges: + minItems: 1 + maxItems: 6 + items:Documentation/devicetree/bindings/pci/pci-ep-bus.yaml line 38
Quoted 10 lines
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +10
-0+ maxItems: 8 + additionalItems: true + items: + - maximum: 5 # The BAR number + - const: 0 + - const: 0 + +patternProperties: + "^pci-ep-bus@[0-5]$": + $ref: '#/$defs/pci-ep-bus'This should just be:
additionalProperties: true
properties:
compatible:
const: simple-bus
Quoted 6 lines
required:
- compatibleThen the compatible will cause
simple-bus.yamlto be applied to this node.
Ack.
Quoted 24 lines
Quoted 24 lines
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +24
-0+ description: + One node for each BAR used by peripherals contained in the PCI endpoint. + Each node represent a bus on which peripherals are connected. + This allows for some segmentation, e.g. one peripheral is accessible + through BAR0 and another through BAR1, and you don't want the two + peripherals to be able to act on the other BAR. Alternatively, when + different peripherals need to share BARs, you can define only one node + and use 'ranges' property to map all the used BARs. + +required: + - ranges + - '#address-cells' + - '#size-cells' + +$defs: + pci-ep-bus: + type: object + additionalProperties: true + properties: + compatible: + const: simple-bus + dma-ranges: true + ranges: true + "#address-cells": true
Quoted 8 lines
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml line 68
Quoted 6 lines
Documentation/devicetree/bindings/pci/pci-ep-bus.yaml new file +6
-0+ "#size-cells": true + required: + - compatible + - ranges + - '#address-cells' + - '#size-cells'All this should be covered by
simple-bus.yaml.
Ack.
Many thanks,
Andrea
Quoted 2 lines
Rob
Andrea della Porta
maintainerRe: [PATCH v2 04/14] dt-bindings: misc: Add device specific bindings for RaspberryPi RP1
In reply to Rob HerringHi Rob,
Quoted 46 lines · Rob Herring
Quoted 45 lines · Andrea della Porta
The 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.
Signed-off-by Andrea della Porta <[email protected]>--- .../devicetree/bindings/misc/pci1de4,1.yaml | 110 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 111 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/pci1de4,1.yamlDocumentation/devicetree/bindings/misc/pci1de4,1.yaml new file +28
-0@@ -0,0 +1,110 @@ +# 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: + - Andrea 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 + +patternProperties:
Quoted 8 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml line 33
Quoted 5 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +5
-0+ "^pci-ep-bus@[0-2]$": + $ref: '#/$defs/bar-bus' + description: + The bus on which the peripherals are attached, which is addressable + through the BAR.No need for this because
pci-ep-bus.yamlalready has a schema for the child nodes.
Hmmm... my intention here was to constrain the BARs from 0 to 2, since there are only 3 BARs on RP1 (of which only 1 is currently interesting for peripherals). Also, that bus should have the peripherals on it, hence I've added the clock, ethernet and pinctrl nodes. Do you think it's not reasonable to define all the peripherals on it, or if it's reasonable, is there any other way to accomplish this in a more elegant way than what I proposed in this patch? See also below.
Quoted 18 lines
Quoted 18 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +17
-0+ +unevaluatedProperties: false + +$defs: + bar-bus: + $ref: /schemas/pci/pci-ep-bus.yaml#/$defs/pci-ep-bus + unevaluatedProperties: false + + properties: + "#interrupt-cells": + const: 2 + description: + Specifies respectively the interrupt number and flags as defined + in include/dt-bindings/interrupt-controller/irq.h. + + interrupt-controller: true +
Quoted 8 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml line 54
Quoted 4 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +4
-0+ interrupt-parent: + description: + Must be the phandle of this 'pci-ep-bus' node. It will trigger + PCI interrupts on behalf of peripheral generated interrupts.Do you have an interrupt controller per bus? These should be in the parent node I think.
Ack.
Quoted 19 lines
Quoted 5 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +3
-0+ + patternProperties: + "^clocks(@[0-9a-f]+)?$":Documentation/devicetree/bindings/misc/pci1de4,1.yaml line 67
Quoted 10 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +10
-0+ type: object + $ref: /schemas/clock/raspberrypi,rp1-clocks.yaml + + "^ethernet(@[0-9a-f]+)?$": + type: object + $ref: /schemas/net/cdns,macb.yaml + + "^pinctrl(@[0-9a-f]+)?$": + type: object + $ref: /schemas/pinctrl/raspberrypi,rp1-gpio.yamlIMO, these child nodes can be omitted. We generally don't define all the child nodes in an SoC.
Quoted 7 lines
If you do want to define them, then just do:
additionalProperties: true
properties:
compatible:
contains: the-child-compatible
Right, but since you proposed above to get rid of the pci-ep-bus redeclaration (being it alredy defined in pci-ep-bus.yaml) I'm not sure where to place this. Should I just get rid af it all as you suggest?
Many thanks,
Andrea
Quoted 58 lines
Quoted 58 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +43
-0+ + required: + - interrupt-parent + - interrupt-controller + +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>; + + pci_ep_bus: pci-ep-bus@1 { + compatible = "simple-bus"; + ranges = <0xc0 0x40000000 + 0x01 0x00 0x00000000 + 0x00 0x00400000>; + dma-ranges = <0x10 0x00000000 + 0x43000000 0x10 0x00000000 + 0x10 0x00000000>; + #address-cells = <2>; + #size-cells = <2>; + interrupt-controller; + interrupt-parent = <&pci_ep_bus>; + #interrupt-cells = <2>; + + rp1_clocks: clocks@c040018000 { + compatible = "raspberrypi,rp1-clocks"; + reg = <0xc0 0x40018000 0x0 0x10038>; + #clock-cells = <1>; + clocks = <&clk_rp1_xosc>; + clock-names = "rp1-xosc"; + }; + }; + }; + };MAINTAINERS +1
-0@@ -19384,6 +19384,7 @@ RASPBERRY PI RP1 PCI DRIVER M: Andrea della Porta <[email protected]> S: Maintained F: Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml +F: Documentation/devicetree/bindings/misc/pci1de4,1.yaml F: Documentation/devicetree/bindings/pci/pci-ep-bus.yaml F: Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml F: include/dt-bindings/clock/rp1.hSignature · 1 line
2.35.3
Andrea della Porta
maintainerRe: [PATCH v2 04/14] dt-bindings: misc: Add device specific bindings for RaspberryPi RP1
In reply to Krzysztof KozlowskiHi Krzysztof,
Quoted 35 lines · Krzysztof Kozlowski
Quoted 34 lines · Andrea della Porta
The 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.
Signed-off-by Andrea della Porta <[email protected]>--- .../devicetree/bindings/misc/pci1de4,1.yaml | 110 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 111 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/pci1de4,1.yamlDocumentation/devicetree/bindings/misc/pci1de4,1.yaml new file +17
-0@@ -0,0 +1,110 @@ +# 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: + - Andrea 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. +
Quoted 8 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml line 23
Quoted 6 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +6
-0+allOf: + - $ref: /schemas/pci/pci-ep-bus.yaml + +properties: + compatible: + additionalItems: trueWhy is this true? This is final schema, not a "common" part.
The 'compatible' property I've specified in rp1.dtso is not strictly necessary since it will be added automatically during the dynamic device node creation by the OF subsystem, and will be something like this:
"pci1de4,1", "pciclass,0200000", "pciclass,0200"
I've redefined simply as "pci1de4,1" in the dtso so it can be validated against the relative binding schema, and I opted for a shorter name since the RP1 is not really a simple ethernet controller as advertised by the config space (pciclass=2). The schema definition allows for the "relaxed" extended version, shoudl someone want to use it for resemblance with the dynamically create compatibel string.
Quoted 29 lines
Quoted 29 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +28
-0+ maxItems: 3 + items: + - const: pci1de4,1 + +patternProperties: + "^pci-ep-bus@[0-2]$": + $ref: '#/$defs/bar-bus' + description: + The bus on which the peripherals are attached, which is addressable + through the BAR. + +unevaluatedProperties: false + +$defs: + bar-bus: + $ref: /schemas/pci/pci-ep-bus.yaml#/$defs/pci-ep-bus + unevaluatedProperties: false + + properties: + "#interrupt-cells": + const: 2 + description: + Specifies respectively the interrupt number and flags as defined + in include/dt-bindings/interrupt-controller/irq.h. + + interrupt-controller: true + + interrupt-parent:
Quoted 8 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml line 57
Quoted 6 lines
Documentation/devicetree/bindings/misc/pci1de4,1.yaml new file +6
-0+ description: + Must be the phandle of this 'pci-ep-bus' node. It will trigger + PCI interrupts on behalf of peripheral generated interrupts. + + patternProperties: + "^clocks(@[0-9a-f]+)?$":Why @ is optional? Your device is fixed, not flexible.
Right.
Many thanks,
Andrea
Quoted 4 lines
Best regards,
Krzysztof
Andrea della Porta
maintainerRe: [PATCH v2 08/14] clk: rp1: Add support for clocks provided by RP1
In reply to Stephen BoydHi Stephen,
Quoted 9 lines · Stephen Boyd
Quoting Andrea della Porta (2024-10-07 05:39:51)
Quoted 8 lines
drivers/clk/Kconfig +0
-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.
Quoted 5 lines
drivers/clk/Kconfig config COMMON_CLK_RK808 · line 93
Quoted 3 lines
drivers/clk/Kconfig +3
-0+config COMMON_CLK_RP1 + tristate "Raspberry Pi RP1-based clock support" + depends on PCI || COMPILE_TESTA better limit would be some ARCH_* config.
I've avoided ARCH_BCM2835 since the original intention is for this driver to work (in the future) also for custom PCI cards with RP1 on-board, and not only for Rpi5.
Quoted 5 lines
drivers/clk/Kconfig config COMMON_CLK_RK808 · line 94
Quoted 2 lines
drivers/clk/Kconfig +1
-0+ depends on COMMON_CLKThis is redundant as it's inside the 'if
COMMON_CLK'. Please remove this line.
Ack.
Quoted 18 lines
Quoted 18 lines
drivers/clk/Kconfig +5
-0+ 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/clk-rp1.c new file +3
-0@@ -0,0 +1,1658 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2023 Raspberry Pi Ltd.
Quoted 8 lines
drivers/clk/clk-rp1.c line 9
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+* +* Clock driver for RP1 PCIe multifunction chip. +*/ + +#include <linux/clk-provider.h> +#include <linux/clkdev.h> Drop unused header.
Ack.
Quoted 4 lines
drivers/clk/clk-rp1.c line 10
Quoted 2 lines
drivers/clk/clk-rp1.c new file +1
-0+#include <linux/clk.h> Preferably this include isn't included.
This include is currently needed by devm_clk_get_enabled() to retrieve the xosc. Since that clock is based on a crystal (so it's fixed and always enabled), I'm planning to hardcode it in the driver. This will not only get rid of the devm_clk_get_enabled() call (and hence of the clk.h include), but it'll also simplify the top devicetree. No promise though, I need to check a couple of things first.
Quoted 9 lines
drivers/clk/clk-rp1.c line 16
Quoted 7 lines
drivers/clk/clk-rp1.c new file +6
-0+#include <linux/debugfs.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/math64.h> +#include <linux/module.h> +#include <linux/of_device.h> What is this include for? Should probably be
mod_devicetable.h?
Yes.
Quoted 7 lines
drivers/clk/clk-rp1.c line 20
Quoted 5 lines
drivers/clk/clk-rp1.c new file +4
-0+#include <linux/platform_device.h> +#include <linux/slab.h> + +#include <asm/div64.h> Include
math64.hinstead?
Right, this is redundant, since there is already math64.h included a bunch of lines above.
Quoted 263 lines
Quoted 263 lines
drivers/clk/clk-rp1.c new file +262
-0+ +#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_SHIFT 16 +#define PLL_PRIM_DIV1_WIDTH 3 +#define PLL_PRIM_DIV1_MASK GENMASK(PLL_PRIM_DIV1_SHIFT + \ + PLL_PRIM_DIV1_WIDTH - 1, \ + PLL_PRIM_DIV1_SHIFT) +#define PLL_PRIM_DIV2_SHIFT 12 +#define PLL_PRIM_DIV2_WIDTH 3 +#define PLL_PRIM_DIV2_MASK GENMASK(PLL_PRIM_DIV2_SHIFT + \ + PLL_PRIM_DIV2_WIDTH - 1, \ + PLL_PRIM_DIV2_SHIFT) + +#define PLL_SEC_DIV_SHIFT 8 +#define PLL_SEC_DIV_WIDTH 5 +#define PLL_SEC_DIV_MASK GENMASK(PLL_SEC_DIV_SHIFT + \ + PLL_SEC_DIV_WIDTH - 1, \ + PLL_SEC_DIV_SHIFT) + +#define PLL_CS_LOCK BIT(31) +#define PLL_CS_REFDIV_SHIFT 0 + +#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_SHIFT 5 +#define CLK_CTRL_AUXSRC_WIDTH 5 +#define CLK_CTRL_AUXSRC_MASK GENMASK(CLK_CTRL_AUXSRC_SHIFT + \ + CLK_CTRL_AUXSRC_WIDTH - 1, \
Quoted 8 lines
drivers/clk/clk-rp1.c line 288
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+ CLK_CTRL_AUXSRC_SHIFT) +#define CLK_CTRL_SRC_SHIFT 0 +#define CLK_DIV_FRAC_BITS 16 + +#define KHz 1000 +#define MHz (KHz * KHz)I think we have these macros now. See
include/linux/units.h.
Ack.
Quoted 166 lines
Quoted 166 lines
drivers/clk/clk-rp1.c new file +165
-0+#define LOCK_TIMEOUT_NS 100000000 +#define FC_TIMEOUT_NS 100000000 + +#define MAX_CLK_PARENTS 16 + +/* +* Secondary PLL channel output divider table. +* Divider values range from 8 to 19. +* Invalid values default to 19 +*/ +static const struct clk_div_table pll_sec_div_table[] = { + {0x00 ,19 }, + {0x01 ,19 }, + {0x02 ,19 }, + {0x03 ,19 }, + {0x04 ,19 }, + {0x05 ,19 }, + {0x06 ,19 }, + {0x07 ,19 }, + {0x08 ,8 }, + {0x09 ,9 }, + {0x0a ,10 }, + {0x0b ,11 }, + {0x0c ,12 }, + {0x0d ,13 }, + {0x0e ,14 }, + {0x0f ,15 }, + {0x10 ,16 }, + {0x11 ,17 }, + {0x12 ,18 }, + {0x13 ,19 }, + {0x14 ,19 }, + {0x15 ,19 }, + {0x16 ,19 }, + {0x17 ,19 }, + {0x18 ,19 }, + {0x19 ,19 }, + {0x1a ,19 }, + {0x1b ,19 }, + {0x1c ,19 }, + {0x1d ,19 }, + {0x1e ,19 }, + {0x1f ,19 }, + {0 } +}; + +struct rp1_clockman { +struct device *dev; +void __iomem *regs; +spinlock_t regs_lock;/* spinlock for all clocks */ +struct clk_hw *hw_xosc;/* reference clock */ + +/* Must be last */ +struct clk_hw_onecell_data onecell; +}; + +struct rp1_pll_core_data { +const char *name; +u32 cs_reg; +u32 pwr_reg; +u32 fbdiv_int_reg; +u32 fbdiv_frac_reg; +unsigned long flags; +u32 fc0_src; +}; + +struct rp1_pll_data { +const char *name; +const char *source_pll; +u32 ctrl_reg; +unsigned long flags; +u32 fc0_src; +}; + +struct rp1_pll_ph_data { +const char *name; +const char *source_pll; +unsigned int phase; +unsigned int fixed_divider; +u32 ph_reg; +unsigned long flags; +u32 fc0_src; +}; + +struct rp1_pll_divider_data { +const char *name; +const char *source_pll; +u32 sec_reg; +unsigned long flags; +u32 fc0_src; +}; + +struct rp1_clock_data { +const char *name; +const char *const parents[MAX_CLK_PARENTS ]; +int num_std_parents; +int num_aux_parents; +unsigned long flags; +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_pll_core { +struct clk_hw hw; +struct rp1_clockman *clockman; +unsigned long cached_rate; +const struct rp1_pll_core_data *data; +}; + +struct rp1_pll { +struct clk_hw hw; +struct rp1_clockman *clockman; +struct clk_divider div; +unsigned long cached_rate; +const struct rp1_pll_data *data; +}; + +struct rp1_pll_ph { +struct clk_hw hw; +struct rp1_clockman *clockman; +const struct rp1_pll_ph_data *data; +}; + +struct rp1_clock { +struct clk_hw hw; +struct rp1_clockman *clockman; +unsigned long cached_rate; +const struct rp1_clock_data *data; +}; + +struct rp1_clk_change { +struct clk_hw *hw; +unsigned long new_rate; +}; + +struct rp1_clk_desc { +struct clk_hw *(*clk_register)(struct rp1_clockman *clockman, +const void *data); +const void *data; +}; + +static void rp1_debugfs_regset (struct rp1_clockman *clockman,u32 base, +const struct debugfs_reg32 *regs, +size_t nregs,struct dentry *dentry) +{ +struct debugfs_regset32 *regset; + + regset =devm_kzalloc (clockman->dev,sizeof (*regset),GFP_KERNEL ); +if (!regset) +return ; + + regset->regs = regs; + regset->nregs = nregs; + regset->base = clockman->regs + base; + +debugfs_create_regset32 ("regdump" ,0444 , dentry, regset); +} +
Quoted 8 lines
drivers/clk/clk-rp1.c line 459
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+static inline u32 set_register_field (u32 reg,u32 val,u32 mask,u32 shift) +{ + reg &= ~mask; + reg |= (val << shift) & mask; +return reg; +}Can you use
FIELD_PREP()and friends?
Sure. Except for data->clk_src_mask which is non-constant.
Quoted 50 lines
Quoted 50 lines
drivers/clk/clk-rp1.c new file +49
-0+ +static inline +void clockman_write (struct rp1_clockman *clockman,u32 reg,u32 val) +{ +writel (val, clockman->regs + reg); +} + +static inline u32 clockman_read (struct rp1_clockman *clockman,u32 reg) +{ +return readl (clockman->regs + reg); +} + +static int rp1_pll_core_is_on (struct clk_hw *hw) +{ + struct rp1_pll_core *pll_core = container_of(hw, struct rp1_pll_core, 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_pll_core *pll_core = container_of(hw, struct rp1_pll_core, hw); +struct rp1_clockman *clockman = pll_core->clockman; +const struct rp1_pll_core_data *data = pll_core->data; +u32 fbdiv_frac; +ktime_t timeout; + +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,1 <<PLL_CS_REFDIV_SHIFT ); + } + +/* 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. */ + timeout =ktime_add_ns (ktime_get (),LOCK_TIMEOUT_NS ); +while (!(clockman_read (clockman, data->cs_reg) &PLL_CS_LOCK )) { +if (ktime_after (ktime_get (), timeout)) {
Quoted 8 lines
drivers/clk/clk-rp1.c line 514
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+dev_err (clockman->dev,"%s: can't lock PLL\n" , +clk_hw_get_name (hw)); +return -ETIMEDOUT ; + } +cpu_relax (); + }Is this
readl_poll_timeout()?
Yes. Since you suggested below to use regmap, this will be regmap_read_poll_timeout() instead.
Quoted 63 lines
Quoted 63 lines
drivers/clk/clk-rp1.c new file +62
-0+ +return 0 ; +} + +static void rp1_pll_core_off (struct clk_hw *hw) +{ + struct rp1_pll_core *pll_core = container_of(hw, struct rp1_pll_core, 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) +{ +unsigned long calc_rate; +u32 fbdiv_int, fbdiv_frac; +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 ; + + calc_rate = + ((u64 )parent_rate * (((u64 )fbdiv_int <<24 ) + fbdiv_frac) + (1 <<23 )) >>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_pll_core *pll_core = container_of(hw, struct rp1_pll_core, 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);
Quoted 8 lines
drivers/clk/clk-rp1.c line 582
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+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. */ Why is '16' special?
Adding Raspberry Pi guys to the mail loop hoping they can step in and shed some light, since I don't have the necessary doc/insight to figure it out.
Quoted 24 lines
Quoted 24 lines
drivers/clk/clk-rp1.c new file +23
-0+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) | + (1 <<PLL_CS_REFDIV_SHIFT )); +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_pll_core *pll_core = container_of(hw, struct rp1_pll_core, 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;
Quoted 8 lines
drivers/clk/clk-rp1.c line 610
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+ + fbdiv_int =clockman_read (clockman, data->fbdiv_int_reg); + fbdiv_frac =clockman_read (clockman, data->fbdiv_frac_reg); + calc_rate = + ((u64 )parent_rate * (((u64 )fbdiv_int <<24 ) + fbdiv_frac) + (1 <<23 )) >>24 ;Where does '24' come from? Can you simplify this line somehow? Maybe break it up into multiple lines?
Same as before, we'll need some info from the vendor to explain this. It seems to me that it's some kind of fixed-point calculation about the frequency that takes into account the fractional part in the addition and round it on the result.
Regarding the multi-line split, consider it done.
Quoted 16 lines
Quoted 4 lines
drivers/clk/clk-rp1.c new file +3
-0+ +return calc_rate; +}drivers/clk/clk-rp1.c line 623
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ +static long rp1_pll_core_round_rate (struct clk_hw *hw,unsigned long rate, +unsigned long *parent_rate) +{ +u32 fbdiv_int, fbdiv_frac; +long calc_rate; + + calc_rate =get_pll_core_divider (hw, rate, *parent_rate, + &fbdiv_int, &fbdiv_frac); +return calc_rate;return
get_pll_core_divider(...);
Ack.
Quoted 20 lines
Quoted 20 lines
drivers/clk/clk-rp1.c new file +19
-0+} + +static void rp1_pll_core_debug_init (struct clk_hw *hw,struct dentry *dentry) +{ + struct rp1_pll_core *pll_core = container_of(hw, struct rp1_pll_core, hw); +struct rp1_clockman *clockman = pll_core->clockman; +const struct rp1_pll_core_data *data = pll_core->data; +struct debugfs_reg32 *regs; + + regs =devm_kcalloc (clockman->dev,4 ,sizeof (*regs),GFP_KERNEL ); +if (!regs) +return ; + + regs[0 ].name ="cs" ; + regs[0 ].offset = data->cs_reg; + regs[1 ].name ="pwr" ; + regs[1 ].offset = data->pwr_reg; + regs[2 ].name ="fbdiv_int" ; + regs[2 ].offset = data->fbdiv_int_reg;
Quoted 8 lines
drivers/clk/clk-rp1.c line 647
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+ regs[3 ].name ="fbdiv_frac" ; + regs[3 ].offset = data->fbdiv_frac_reg; + +rp1_debugfs_regset (clockman,0 , regs,4 , dentry); +}This can go behind
CONFIG_DEBUG_FSso it isn't compiled unless debugfs is enabled.
Ack.
Quoted 115 lines
Quoted 115 lines
drivers/clk/clk-rp1.c new file +114
-0+ +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_pll *pll = container_of(hw, struct rp1_pll, 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 =set_register_field (prim, prim_div1,PLL_PRIM_DIV1_MASK , +PLL_PRIM_DIV1_SHIFT ); + prim =set_register_field (prim, prim_div2,PLL_PRIM_DIV2_MASK , +PLL_PRIM_DIV2_SHIFT ); +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_pll *pll = container_of(hw, struct rp1_pll, 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 = (prim &PLL_PRIM_DIV1_MASK ) >>PLL_PRIM_DIV1_SHIFT ; + prim_div2 = (prim &PLL_PRIM_DIV2_MASK ) >>PLL_PRIM_DIV2_SHIFT ; + +if (!prim_div1 || !prim_div2) { +dev_err (clockman->dev,"%s: (%s) zero divider value\n" , + __func__, data->name); +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 void rp1_pll_debug_init (struct clk_hw *hw, +struct dentry *dentry) +{ + struct rp1_pll *pll = container_of(hw, struct rp1_pll, hw); +struct rp1_clockman *clockman = pll->clockman; +const struct rp1_pll_data *data = pll->data; +struct debugfs_reg32 *regs; + + regs =devm_kcalloc (clockman->dev,1 ,sizeof (*regs),GFP_KERNEL ); +if (!regs) +return ; + + regs[0 ].name ="prim" ; + regs[0 ].offset = data->ctrl_reg; + +rp1_debugfs_regset (clockman,0 , regs,1 , dentry); +} + +static int rp1_pll_ph_is_on (struct clk_hw *hw) +{ + struct rp1_pll_ph *pll = container_of(hw, struct rp1_pll_ph, hw); +struct rp1_clockman *clockman = pll->clockman; +const struct rp1_pll_ph_data *data = pll->data; + +return !!(clockman_read (clockman, data->ph_reg) &PLL_PH_EN ); +} + +static int rp1_pll_ph_on (struct clk_hw *hw) +{
Quoted 8 lines
drivers/clk/clk-rp1.c line 767
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+ struct rp1_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, hw); +struct rp1_clockman *clockman = pll_ph->clockman; +const struct rp1_pll_ph_data *data = pll_ph->data; +u32 ph_reg; + +/* todo: ensure pri/sec is enabled! */ Capitalize TODO, or better yet do it and remove the comment.
Ack.
Quoted 25 lines
Quoted 25 lines
drivers/clk/clk-rp1.c new file +24
-0+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_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, 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 int rp1_pll_ph_set_rate (struct clk_hw *hw, +unsigned long rate,unsigned long parent_rate)
Quoted 8 lines
drivers/clk/clk-rp1.c line 796
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+{ + struct rp1_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, hw); +const struct rp1_pll_ph_data *data = pll_ph->data; + +/* Nothing really to do here! */ Is it read-only? Don't define a
set_ratefunction then and make the rate determination function return the same value all the time.
Not 100% sure about it, maybe Raspberry Pi colleagues can explain. By 'rate determination function' you're referring (in this case) to rp1_pll_ph_recalc_rate(), right? If so, that clock type seems to have a fixed divider but teh resulting clock depends on the parent rate, so it has to be calculated.
Quoted 394 lines
Quoted 394 lines
drivers/clk/clk-rp1.c new file +393
-0+WARN_ON (data->fixed_divider !=1 && data->fixed_divider !=2 ); +WARN_ON (rate != parent_rate / data->fixed_divider); + +return 0 ; +} + +static unsigned long rp1_pll_ph_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ + struct rp1_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, 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_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, hw); +const struct rp1_pll_ph_data *data = pll_ph->data; + +return *parent_rate / data->fixed_divider; +} + +static void rp1_pll_ph_debug_init (struct clk_hw *hw, +struct dentry *dentry) +{ + struct rp1_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, hw); +const struct rp1_pll_ph_data *data = pll_ph->data; +struct rp1_clockman *clockman = pll_ph->clockman; +struct debugfs_reg32 *regs; + + regs =devm_kcalloc (clockman->dev,1 ,sizeof (*regs),GFP_KERNEL ); +if (!regs) +return ; + + regs[0 ].name ="ph_reg" ; + regs[0 ].offset = data->ph_reg; + +rp1_debugfs_regset (clockman,0 , regs,1 , dentry); +} + +static int rp1_pll_divider_is_on (struct clk_hw *hw) +{ + struct rp1_pll *divider = container_of(hw, struct rp1_pll, 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_pll *divider = container_of(hw, struct rp1_pll, 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_pll *divider = container_of(hw, struct rp1_pll, 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,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_pll *divider = container_of(hw, struct rp1_pll, 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 =set_register_field (sec, div,PLL_SEC_DIV_MASK ,PLL_SEC_DIV_SHIFT ); + +/* Must keep the divider in reset to change the value. */ + sec |=PLL_SEC_RST ; +clockman_write (clockman, data->ctrl_reg, sec); + +// todo: must sleep 10 pll vco cycles + 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 void rp1_pll_divider_debug_init (struct clk_hw *hw,struct dentry *dentry) +{ + struct rp1_pll *divider = container_of(hw, struct rp1_pll, div.hw); +struct rp1_clockman *clockman = divider->clockman; +const struct rp1_pll_data *data = divider->data; +struct debugfs_reg32 *regs; + + regs =devm_kcalloc (clockman->dev,1 ,sizeof (*regs),GFP_KERNEL ); +if (!regs) +return ; + + regs[0 ].name ="sec" ; + regs[0 ].offset = data->ctrl_reg; + +rp1_debugfs_regset (clockman,0 , regs,1 , dentry); +} + +static int rp1_clock_is_on (struct clk_hw *hw) +{ + struct rp1_clock *clock = container_of(hw, struct rp1_clock, 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_clock *clock = container_of(hw, struct rp1_clock, 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_clock *clock = container_of(hw, struct rp1_clock, 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_clock *clock = container_of(hw, struct rp1_clock, 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_clock *clock = container_of(hw, struct rp1_clock, 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 = (ctrl &CLK_CTRL_AUXSRC_MASK ) >>CLK_CTRL_AUXSRC_SHIFT ; + parent += data->num_std_parents; + } + +return parent; +} + +static int rp1_clock_set_parent (struct clk_hw *hw,u8 index) +{ + struct rp1_clock *clock = container_of(hw, struct rp1_clock, 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 =set_register_field (ctrl, index - data->num_std_parents, +CLK_CTRL_AUXSRC_MASK , +CLK_CTRL_AUXSRC_SHIFT ); +/* Set src to aux list */ + ctrl =set_register_field (ctrl,AUX_SEL , data->clk_src_mask, +CLK_CTRL_SRC_SHIFT ); + }else { + ctrl =set_register_field (ctrl, index, data->clk_src_mask, +CLK_CTRL_SRC_SHIFT ); + } + +clockman_write (clockman, data->ctrl_reg, ctrl); +spin_unlock (&clockman->regs_lock); + + sel =rp1_clock_get_parent (hw); +WARN (sel != index,"(%s): Parent index req %u returned back %u\n" , + data->name, 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_clock *clock = container_of(hw, struct rp1_clock, 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 (rate >4000000000ll ,"rate is -ve (%d)\n" , (int )rate); + +if (WARN (!div, +"clk divider calculated as 0! (%s, rate %ld, parent rate %ld)\n" , + data->name, 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_clock *clock = container_of(hw, struct rp1_clock, 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 > clock->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;
Quoted 8 lines
drivers/clk/clk-rp1.c line 1195
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+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 )) {Is this flag ever set?
Not right now, but it will be used as soon as I'll add the video clocks, so I thought to leave it be to avoid adding it back in the future. For this minimal support is not needed though, so let me know if you want it removed.
Quoted 64 lines
Quoted 64 lines
drivers/clk/clk-rp1.c new file +63
-0+ 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 void rp1_clk_debug_init (struct clk_hw *hw,struct dentry *dentry) +{ + struct rp1_clock *clock = container_of(hw, struct rp1_clock, hw); +struct rp1_clockman *clockman = clock->clockman; +const struct rp1_clock_data *data = clock->data; +struct debugfs_reg32 *regs; +int i; + + regs =devm_kcalloc (clockman->dev,4 ,sizeof (*regs),GFP_KERNEL ); +if (!regs) +return ; + + i =0 ; + regs[i].name ="ctrl" ; + regs[i++].offset = data->ctrl_reg; + regs[i].name ="div_int" ;
Quoted 8 lines
drivers/clk/clk-rp1.c line 1263
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+ regs[i++].offset = data->div_int_reg; + regs[i].name ="div_frac" ; + regs[i++].offset = data->div_frac_reg; + regs[i].name ="sel" ; + regs[i++].offset = data->sel_reg;This time we get i but earlier it was hard-coded. Please be consistent. I suspect hard-coded is easier to follow so just do that.
Ack.
Quoted 6 lines
drivers/clk/clk-rp1.c line 1265
Quoted 3 lines
drivers/clk/clk-rp1.c new file +2
-0+ +rp1_debugfs_regset (clockman,0 , regs, i, dentry);I also wonder if regmap could be used? That has debugfs suport to read registers builtin already.
Good idea.
Quoted 58 lines
Quoted 58 lines
drivers/clk/clk-rp1.c new file +57
-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, + .debug_init = rp1_pll_core_debug_init, +}; + +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, + .debug_init = rp1_pll_debug_init, +}; + +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, + .set_rate = rp1_pll_ph_set_rate, + .recalc_rate = rp1_pll_ph_recalc_rate, + .round_rate = rp1_pll_ph_round_rate, + .debug_init = rp1_pll_ph_debug_init, +}; + +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, + .debug_init = rp1_pll_divider_debug_init, +}; + +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, + .debug_init = rp1_clk_debug_init, +}; + +static struct clk_hw *rp1_register_pll_core (struct rp1_clockman *clockman, +const void *data) +{ +const char *ref_clk_name =clk_hw_get_name (clockman->hw_xosc); +const struct rp1_pll_core_data *pll_core_data = data;
Quoted 8 lines
drivers/clk/clk-rp1.c line 1327
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+struct rp1_pll_core *pll_core; +struct clk_init_data init; +int ret; + +memset (&init,0 ,sizeof (init));I think struct
clk_init_datainit = { } is more the style in clk drivers. Please do that instead of callingmemset().
Ack.
Quoted 106 lines
Quoted 106 lines
drivers/clk/clk-rp1.c new file +105
-0+ +/* All of the PLL cores derive from the external oscillator. */ + init.parent_names = &ref_clk_name; + init.num_parents =1 ; + init.name = pll_core_data->name; + init.ops = &rp1_pll_core_ops; + init.flags = pll_core_data->flags |CLK_IGNORE_UNUSED |CLK_IS_CRITICAL ; + + pll_core =devm_kzalloc (clockman->dev,sizeof (*pll_core),GFP_KERNEL ); +if (!pll_core) +return NULL ; + + pll_core->clockman = clockman; + pll_core->data = pll_core_data; + pll_core->hw.init = &init; + + ret =devm_clk_hw_register (clockman->dev, &pll_core->hw); +if (ret) +return ERR_PTR (ret); + +return &pll_core->hw; +} + +static struct clk_hw *rp1_register_pll (struct rp1_clockman *clockman, +const void *data) +{ +const struct rp1_pll_data *pll_data = data; +struct rp1_pll *pll; +struct clk_init_data init; +int ret; + +memset (&init,0 ,sizeof (init)); + + init.parent_names = &pll_data->source_pll; + init.num_parents =1 ; + init.name = pll_data->name; + init.ops = &rp1_pll_ops; + init.flags = pll_data->flags |CLK_IGNORE_UNUSED |CLK_IS_CRITICAL ; + + pll =devm_kzalloc (clockman->dev,sizeof (*pll),GFP_KERNEL ); +if (!pll) +return NULL ; + + pll->clockman = clockman; + pll->data = pll_data; + pll->hw.init = &init; + + ret =devm_clk_hw_register (clockman->dev, &pll->hw); +if (ret) +return ERR_PTR (ret); + +return &pll->hw; +} + +static struct clk_hw *rp1_register_pll_ph (struct rp1_clockman *clockman, +const void *data) +{ +const struct rp1_pll_ph_data *ph_data = data; +struct rp1_pll_ph *ph; +struct clk_init_data init; +int ret; + +memset (&init,0 ,sizeof (init)); + + init.parent_names = &ph_data->source_pll; + init.num_parents =1 ; + init.name = ph_data->name; + init.ops = &rp1_pll_ph_ops; + init.flags = ph_data->flags |CLK_IGNORE_UNUSED ; + + ph =devm_kzalloc (clockman->dev,sizeof (*ph),GFP_KERNEL ); +if (!ph) +return NULL ; + + ph->clockman = clockman; + ph->data = ph_data; + ph->hw.init = &init; + + ret =devm_clk_hw_register (clockman->dev, &ph->hw); +if (ret) +return ERR_PTR (ret); + +return &ph->hw; +} + +static struct clk_hw *rp1_register_pll_divider (struct rp1_clockman *clockman, +const void *data) +{ +const struct rp1_pll_data *divider_data = data; +struct rp1_pll *divider; +struct clk_init_data init; +int ret; + +memset (&init,0 ,sizeof (init)); + + init.parent_names = ÷r_data->source_pll; + init.num_parents =1 ; + init.name = divider_data->name; + init.ops = &rp1_pll_divider_ops; + init.flags = divider_data->flags |CLK_IGNORE_UNUSED |CLK_IS_CRITICAL ; + + divider =devm_kzalloc (clockman->dev,sizeof (*divider),GFP_KERNEL ); +if (!divider) +return NULL ; +
Quoted 8 lines
drivers/clk/clk-rp1.c line 1437
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+ divider->div.reg = clockman->regs + divider_data->ctrl_reg; + divider->div.shift =PLL_SEC_DIV_SHIFT ; + divider->div.width =PLL_SEC_DIV_WIDTH ; + divider->div.flags =CLK_DIVIDER_ROUND_CLOSEST ; + divider->div.flags |=CLK_IS_CRITICAL ;Is everything critical? The usage of this flag and
CLK_IGNORE_UNUSEDis suspicious and likely working around some problems elsewhere.
Not sure... maybe they wanted to control the enablement through the parent pll_sys_core only? RaspberryPi folks can you please step-in on this?
Quoted 115 lines
Quoted 115 lines
drivers/clk/clk-rp1.c new file +114
-0+ divider->div.lock = &clockman->regs_lock; + divider->div.hw.init = &init; + divider->div.table = pll_sec_div_table; + + divider->clockman = clockman; + divider->data = divider_data; + + ret =devm_clk_hw_register (clockman->dev, ÷r->div.hw); +if (ret) +return ERR_PTR (ret); + +return ÷r->div.hw; +} + +static struct clk_hw *rp1_register_clock (struct rp1_clockman *clockman, +const void *data) +{ +const struct rp1_clock_data *clock_data = data; +struct rp1_clock *clock; +struct clk_init_data init; +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 && +strcmp ("-" , clock_data->parents[AUX_SEL ]))) +return NULL ; + +memset (&init,0 ,sizeof (init)); + init.parent_names = clock_data->parents; + init.num_parents = clock_data->num_std_parents + + clock_data->num_aux_parents; + init.name = clock_data->name; + init.flags = clock_data->flags |CLK_IGNORE_UNUSED ; + init.ops = &rp1_clk_ops; + + clock =devm_kzalloc (clockman->dev,sizeof (*clock),GFP_KERNEL ); +if (!clock) +return NULL ; + + clock->clockman = clockman; + clock->data = clock_data; + clock->hw.init = &init; + + ret =devm_clk_hw_register (clockman->dev, &clock->hw); +if (ret) +return ERR_PTR (ret); + +return &clock->hw; +} + +/* Assignment helper macros for different clock types. */ +#define _REGISTER (f, ...) { .clk_register = f, .data = __VA_ARGS__ } + +#define REGISTER_PLL_CORE (...) _REGISTER(&rp1_register_pll_core, \ + &(struct rp1_pll_core_data) \ + {__VA_ARGS__}) + +#define REGISTER_PLL (...) _REGISTER(&rp1_register_pll, \ + &(struct rp1_pll_data) \ + {__VA_ARGS__}) + +#define REGISTER_PLL_PH (...) _REGISTER(&rp1_register_pll_ph, \ + &(struct rp1_pll_ph_data) \ + {__VA_ARGS__}) + +#define REGISTER_PLL_DIV (...) _REGISTER(&rp1_register_pll_divider, \ + &(struct rp1_pll_data) \ + {__VA_ARGS__}) + +#define REGISTER_CLK (...) _REGISTER(&rp1_register_clock, \ + &(struct rp1_clock_data) \ + {__VA_ARGS__}) + +static const struct rp1_clk_desc clk_desc_array[] = { + [RP1_PLL_SYS_CORE] = REGISTER_PLL_CORE(.name = "pll_sys_core", + .cs_reg =PLL_SYS_CS , + .pwr_reg =PLL_SYS_PWR , + .fbdiv_int_reg =PLL_SYS_FBDIV_INT , + .fbdiv_frac_reg =PLL_SYS_FBDIV_FRAC , + ), + + [RP1_PLL_AUDIO_CORE] = REGISTER_PLL_CORE(.name = "pll_audio_core", + .cs_reg =PLL_AUDIO_CS , + .pwr_reg =PLL_AUDIO_PWR , + .fbdiv_int_reg =PLL_AUDIO_FBDIV_INT , + .fbdiv_frac_reg =PLL_AUDIO_FBDIV_FRAC , + ), + + [RP1_PLL_VIDEO_CORE] = REGISTER_PLL_CORE(.name = "pll_video_core", + .cs_reg =PLL_VIDEO_CS , + .pwr_reg =PLL_VIDEO_PWR , + .fbdiv_int_reg =PLL_VIDEO_FBDIV_INT , + .fbdiv_frac_reg =PLL_VIDEO_FBDIV_FRAC , + ), + + [RP1_PLL_SYS] = REGISTER_PLL(.name = "pll_sys", + .source_pll ="pll_sys_core" , + .ctrl_reg =PLL_SYS_PRIM , + .fc0_src =FC_NUM (0 ,2 ), + ), + + [RP1_CLK_ETH_TSU] = REGISTER_CLK(.name = "clk_eth_tsu", + .parents = {"rp1-xosc" }, + .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 * MHz,
Quoted 8 lines
drivers/clk/clk-rp1.c line 1556
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+ .fc0_src = FC_NUM(5, 7), + ), + + [RP1_CLK_SYS] = REGISTER_CLK(.name = "clk_sys", + .parents = {"rp1-xosc", "-", "pll_sys"},Please use struct
clk_parent_dataorclk_hwdirectly. Don't use strings to describe parents.
Describing parents as as strings allows to directly assign it to struct clk_init_data, as in rp1_register_clock():
const struct rp1_clock_data *clock_data = data;
struct clk_init_data init = { };
...
init.parent_names = clock_data->parents;
otherwise we should create an array and populate from clk_parent_data::name, which is of course feasible but a bit less compact. Are you sure you want to change it?
Quoted 51 lines
Quoted 23 lines
drivers/clk/clk-rp1.c new file +22
-0+ .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 * MHz, + .fc0_src = FC_NUM(0, 4), + .clk_src_mask = 0x3, + ), + + [RP1_PLL_SYS_PRI_PH] = REGISTER_PLL_PH(.name = "pll_sys_pri_ph", + .source_pll = "pll_sys", + .ph_reg = PLL_SYS_PRIM, + .fixed_divider = 2, + .phase = RP1_PLL_PHASE_0, + .fc0_src = FC_NUM(1, 2), + ), + + [RP1_PLL_SYS_SEC] = REGISTER_PLL_DIV(.name = "pll_sys_sec", + .source_pll = "pll_sys_core", + .ctrl_reg = PLL_SYS_SEC,drivers/clk/clk-rp1.c line 1588
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ .fc0_src = FC_NUM(2, 2), + ), +}; + +static int rp1_clk_probe (struct platform_device *pdev) +{ +const size_t asize =ARRAY_SIZE (clk_desc_array); +const struct rp1_clk_desc *desc; +struct device *dev = &pdev->dev; +struct rp1_clockman *clockman;I love the name 'clockman'!
Quoted 15 lines
drivers/clk/clk-rp1.c new file +15
-0+struct clk *clk_xosc; +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);
Quoted 8 lines
drivers/clk/clk-rp1.c line 1609
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+ + clk_xosc =devm_clk_get_enabled (dev,NULL ); +if (IS_ERR (clk_xosc)) +return PTR_ERR (clk_xosc); + + clockman->hw_xosc =__clk_get_hw (clk_xosc);Please use struct
clk_parent_data::indexinstead.
Sorry, I didn't catch what you mean here. Can you please elaborate?
Quoted 11 lines
drivers/clk/clk-rp1.c line 1618
Quoted 10 lines
drivers/clk/clk-rp1.c new file +9
-0+ clockman->onecell.num = asize; + hws = clockman->onecell.hws; + +for (i =0 ; i < asize; i++) { + desc = &clk_desc_array[i]; +if (desc->clk_register && desc->data) { + hws[i] = desc->clk_register (clockman, desc->data); +if (IS_ERR_OR_NULL (hws[i])) + dev_err(dev, "Unable to register clock: %s\n",
Quoted 1 line
Use
dev_err_probe()please.
Ack.
Quoted 30 lines
Quoted 30 lines
drivers/clk/clk-rp1.c new file +29
-0+ 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, +}; + +static int __init rp1_clk_driver_init (void ) +{ +return platform_driver_register (&rp1_clk_driver); +} +postcore_initcall (rp1_clk_driver_init);
Quoted 8 lines
drivers/clk/clk-rp1.c line 1653
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+ +static void __exit rp1_clk_driver_exit(void) +{ +platform_driver_unregister (&rp1_clk_driver); +} +module_exit (rp1_clk_driver_exit);Can you use
module_platform_driver()?
Sure.
Many thanks,
Andrea
Re: [PATCH v2 08/14] clk: rp1: Add support for clocks provided by RP1
Hi Andrea,
Quoted 18 lines · On Wed, 23 Oct 2024 17:36:06 +0200 Andrea della Porta <[email protected]>…
Hi Stephen,
Quoted 9 lines · Stephen Boyd
Quoting Andrea della Porta (2024-10-07 05:39:51)
Quoted 8 lines
drivers/clk/Kconfig +0
-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.Quoted 5 lines
drivers/clk/Kconfig config COMMON_CLK_RK808 · line 93
Quoted 3 lines
drivers/clk/Kconfig +3
-0+config COMMON_CLK_RP1 + tristate "Raspberry Pi RP1-based clock support" + depends on PCI || COMPILE_TESTA better limit would be some ARCH_* config.
Quoted 3 lines
I've avoided
ARCH_BCM2835since the original intention is for this driver to work (in the future) also for custom PCI cards with RP1 on-board, and not only for Rpi5.
Maybe depends on CONFIG_MISC_RP1 ?CONFIG_MISC_RP1 enables the RP1 PCI driver
Best regards,
Hervé
Stephen Boyd
maintainerRe: [PATCH v2 08/14] clk: rp1: Add support for clocks provided by RP1
In reply to Andrea della PortaQuoting Andrea della Porta (2024-10-23 08:36:06)
Quoted 18 lines
Hi Stephen,
Quoted 9 lines · Stephen Boyd
Quoting Andrea della Porta (2024-10-07 05:39:51)
Quoted 8 lines
drivers/clk/Kconfig +0
-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.Quoted 5 lines
drivers/clk/Kconfig config COMMON_CLK_RK808 · line 93
Quoted 3 lines
drivers/clk/Kconfig +3
-0+config COMMON_CLK_RP1 + tristate "Raspberry Pi RP1-based clock support" + depends on PCI || COMPILE_TESTA better limit would be some ARCH_* config.
Quoted 3 lines
I've avoided
ARCH_BCM2835since the original intention is for this driver to work (in the future) also for custom PCI cards with RP1 on-board, and not only for Rpi5.
How will that custom PCI card work? It will need this driver to probe? Is the iomem going to be exposed through some PCI config space?
It's not great to depend on CONFIG_PCI because then the driver is forced to be =m if PCI ever becomes tristate (unlikely, but still makes for bad copy/pasta). I understand this line is trying to limit the availability of the config symbol. Maybe it should simply depend on ARM or ARM64? Or on nothing at all.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
drivers/clk/clk-rp1.c new file +1
-0+#include <linux/clk.h>
Quoted 8 lines
Quoted 1 line
Preferably this include isn't included.
This include is currently needed by
devm_clk_get_enabled()to retrieve the xosc. Since that clock is based on a crystal (so it's fixed and always enabled), I'm planning to hardcode it in the driver. This will not only get rid of thedevm_clk_get_enabled()call (and hence of theclk.hinclude), but it'll also simplify the top devicetree. No promise though, I need to check a couple of things first.
A clk provider (clk-provider.h) should ideally not be a clk consumer (clk.h).
Quoted 14 lines
Quoted 13 lines
drivers/clk/clk-rp1.c line 796
Quoted 10 lines
drivers/clk/clk-rp1.c new file +8
-0+ +static int rp1_pll_ph_set_rate (struct clk_hw *hw, +unsigned long rate,unsigned long parent_rate) +{ + struct rp1_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, hw); +const struct rp1_pll_ph_data *data = pll_ph->data; + +/* Nothing really to do here! */ Is it read-only? Don't define a
set_ratefunction then and make the rate determination function return the same value all the time.
Quoted 3 lines
Not 100% sure about it, maybe Raspberry Pi colleagues can explain. By 'rate determination function' you're referring (in this case) to
rp1_pll_ph_recalc_rate(), right?
Yes.
Quoted 3 lines
If so, that clock type seems to have
a fixed divider but teh resulting clock depends on the parent rate, so it has to be calculated.
Sure, it has to be calculated, but it will return the rate that causes no change to the hardware. When that happens, the set_rate() op should be skipped, and you can see that with clk_divider_ro_ops not having a set_rate() function pointer.
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines
drivers/clk/clk-rp1.c new file +4
-0+static int rp1_clock_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ +struct clk_hw *parent, *best_parent =NULL ;drivers/clk/clk-rp1.c line 1195
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+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 )) {Is this flag ever set?
Quoted 5 lines
Not right now, but it will be used as soon as I'll add the video clocks, so I thought to leave it be to avoid adding it back in the future. For this minimal support is not needed though, so let me know if you want it removed.
Ok sure.
Quoted 23 lines
Quoted 11 lines
Quoted 11 lines
drivers/clk/clk-rp1.c new file +10
-0+ + [RP1_CLK_ETH_TSU] = REGISTER_CLK(.name = "clk_eth_tsu", + .parents = {"rp1-xosc"}, + .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 * MHz,Quoted 8 lines
drivers/clk/clk-rp1.c line 1556
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+ .fc0_src = FC_NUM(5, 7), + ), + + [RP1_CLK_SYS] = REGISTER_CLK(.name = "clk_sys", + .parents = {"rp1-xosc", "-", "pll_sys"},Please use struct
clk_parent_dataorclk_hwdirectly. Don't use strings to describe parents.Describing parents as as strings allows to directly assign it to struct
clk_init_data, as inrp1_register_clock():
Quoted 9 lines
const struct
rp1_clock_data*clock_data= data;
structclk_init_datainit = { };
...
init.parent_names =clock_data->parents;otherwise we should create an array and populate from
clk_parent_data::name, which is of course feasible but a bit less compact. Are you sure you want to change it?
Do not use strings to describe parents. That's the guiding principle here. I agree using strings certainly makes it easy to describe things but that doesn't mean it is acceptable.
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
drivers/clk/clk-rp1.c new file +15
-0+struct clk *clk_xosc; +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);Quoted 8 lines
drivers/clk/clk-rp1.c line 1609
Quoted 6 lines
drivers/clk/clk-rp1.c new file +6
-0+ + clk_xosc =devm_clk_get_enabled (dev,NULL ); +if (IS_ERR (clk_xosc)) +return PTR_ERR (clk_xosc); + + clockman->hw_xosc =__clk_get_hw (clk_xosc);Please use struct
clk_parent_data::indexinstead.
Quoted 2 lines
Sorry, I didn't catch what you mean here. Can you please elaborate?
Don't use __clk_get_hw() at all. Also, don't use clk_get() and friends in clk provider drivers. Use struct clk_parent_data so that the framework can do the work for you at the right time.
Re: [PATCH v2 11/14] misc: rp1: RaspberryPi RP1 misc driver
In reply to Andrea della PortaHi Andrea
Quoted 492 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.
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.
Since the gpio line names should be provided by the user, there is an interface through configfs that allows the userspace to load a DT overlay that will provide gpio-line-names property. The interface can be invoked like this:
cat rpi-rp1-gpios-5-b.dtbo >
/sys/kernel/config/rp1-cfg/gpio_set_namesand is designed to be similar to what users are already used to from distro with downstream kernel.
For reasons why this driver is contained in
drivers/misc, please check the links.This driver is heavily based on downstream code from RaspberryPi Foundation, and the original author is Phil Elwell.
Signed-off-by Andrea della Porta <[email protected]>--- MAINTAINERS | 1 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/rp1/Kconfig | 24 +++ drivers/misc/rp1/Makefile | 5 + drivers/misc/rp1/rp1-pci.dtso | 8 + drivers/misc/rp1/rp1_pci.c | 365 ++++++++++++++++++++++++++++++++++ drivers/misc/rp1/rp1_pci.h | 14 ++ drivers/pci/quirks.c | 1 + include/linux/pci_ids.h | 3 + 10 files changed, 423 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 create mode 100644 drivers/misc/rp1/rp1_pci.hMAINTAINERS +1
-0@@ -19389,6 +19389,7 @@ F: Documentation/devicetree/bindings/misc/pci1de4,1.yaml F: Documentation/devicetree/bindings/pci/pci-ep-bus.yaml F: Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml F: drivers/clk/clk-rp1.c +F: drivers/misc/rp1/ F: drivers/pinctrl/pinctrl-rp1.c F: include/dt-bindings/clock/rp1.h F: include/dt-bindings/misc/rp1.hdrivers/misc/Kconfig +1
-0@@ -628,4 +628,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" endmenudrivers/misc/Makefile +1
-0@@ -72,3 +72,4 @@ obj-$(CONFIG_TPS6594_PFSM) += tps6594-pfsm.o obj-$(CONFIG_NSM) += nsm.o obj-$(CONFIG_MARVELL_CN10K_DPI) += mrvl_cn10k_dpi.o obj-y += keba/ +obj-$(CONFIG_MISC_RP1) += rp1/drivers/misc/rp1/Kconfig new file +24
-0@@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# RaspberryPi RP1 misc device +# + +config MISC_RP1 + tristate "RaspberryPi RP1 PCIe support" + depends on PCI && PCI_QUIRKS + select OF + select OF_IRQ + select OF_OVERLAY + select IRQ_DOMAIN + 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 +5
-0@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_MISC_RP1) += rp1-pci.o +rp1-pci-objs := rp1_pci.o rp1-pci.dtbo.o + +DTC_FLAGS_rp1-pci += -@drivers/misc/rp1/rp1-pci.dtso new file +8
-0@@ -0,0 +1,8 @@ +// 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. + */ + +#include "arm64/broadcom/rp1.dtso"drivers/misc/rp1/rp1_pci.c new file +341
-0@@ -0,0 +1,365 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2018-24 Raspberry Pi Ltd. +* All rights reserved. +*/ + +#include <linux/clk.h> +#include <linux/clkdev.h> +#include <linux/clk-provider.h> +#include <linux/err.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/irqdomain.h> +#include <linux/module.h> +#include <linux/msi.h> +#include <linux/of_platform.h> +#include <linux/pci.h> +#include <linux/platform_device.h> +#include <linux/reset.h> + +#include "rp1_pci.h" + +#define RP1_DRIVER_NAME "rp1" + +#define RP1_HW_IRQ_MASK GENMASK(5, 0) + +#define REG_SET 0x800 +#define REG_CLR 0xc00 + +/* MSI-X CFG registers start at 0x8 */ +#define MSIX_CFG (x) (0x8 + (4 * (x))) + +#define MSIX_CFG_IACK_EN BIT(3) +#define MSIX_CFG_IACK BIT(2) +#define MSIX_CFG_ENABLE BIT(0) + +/* Address map */ +#define RP1_PCIE_APBS_BASE 0x108000 + +/* Interrupts */ +#define RP1_INT_IO_BANK0 0 +#define RP1_INT_IO_BANK1 1 +#define RP1_INT_IO_BANK2 2 +#define RP1_INT_AUDIO_IN 3 +#define RP1_INT_AUDIO_OUT 4 +#define RP1_INT_PWM0 5 +#define RP1_INT_ETH 6 +#define RP1_INT_I2C0 7 +#define RP1_INT_I2C1 8 +#define RP1_INT_I2C2 9 +#define RP1_INT_I2C3 10 +#define RP1_INT_I2C4 11 +#define RP1_INT_I2C5 12 +#define RP1_INT_I2C6 13 +#define RP1_INT_I2S0 14 +#define RP1_INT_I2S1 15 +#define RP1_INT_I2S2 16 +#define RP1_INT_SDIO0 17 +#define RP1_INT_SDIO1 18 +#define RP1_INT_SPI0 19 +#define RP1_INT_SPI1 20 +#define RP1_INT_SPI2 21 +#define RP1_INT_SPI3 22 +#define RP1_INT_SPI4 23 +#define RP1_INT_SPI5 24 +#define RP1_INT_UART0 25 +#define RP1_INT_TIMER_0 26 +#define RP1_INT_TIMER_1 27 +#define RP1_INT_TIMER_2 28 +#define RP1_INT_TIMER_3 29 +#define RP1_INT_USBHOST0 30 +#define RP1_INT_USBHOST0_0 31 +#define RP1_INT_USBHOST0_1 32 +#define RP1_INT_USBHOST0_2 33 +#define RP1_INT_USBHOST0_3 34 +#define RP1_INT_USBHOST1 35 +#define RP1_INT_USBHOST1_0 36 +#define RP1_INT_USBHOST1_1 37 +#define RP1_INT_USBHOST1_2 38 +#define RP1_INT_USBHOST1_3 39 +#define RP1_INT_DMA 40 +#define RP1_INT_PWM1 41 +#define RP1_INT_UART1 42 +#define RP1_INT_UART2 43 +#define RP1_INT_UART3 44 +#define RP1_INT_UART4 45 +#define RP1_INT_UART5 46 +#define RP1_INT_MIPI0 47 +#define RP1_INT_MIPI1 48 +#define RP1_INT_VIDEO_OUT 49 +#define RP1_INT_PIO_0 50 +#define RP1_INT_PIO_1 51 +#define RP1_INT_ADC_FIFO 52 +#define RP1_INT_PCIE_OUT 53 +#define RP1_INT_SPI6 54 +#define RP1_INT_SPI7 55 +#define RP1_INT_SPI8 56 +#define RP1_INT_SYSCFG 58 +#define RP1_INT_CLOCKS_DEFAULT 59 +#define RP1_INT_VBUSCTRL 60 +#define RP1_INT_PROC_MISC 57 +#define RP1_INT_END 61 + +struct rp1_dev { +struct pci_dev *pdev; +struct device *dev; +struct clk *sys_clk; +struct irq_domain *domain; +struct irq_data *pcie_irqds[64 ]; +void __iomem *bar1; +int ovcs_id; +bool level_triggered_irq[RP1_INT_END ]; +}; + +static void dump_bar (struct pci_dev *pdev,unsigned int bar) +{ +dev_info (&pdev->dev, +"bar%d %pR\n" , + bar, +pci_resource_n (pdev, bar)); +} + +static void msix_cfg_set (struct rp1_dev *rp1,unsigned int hwirq,u32 value) +{ +iowrite32 (value, rp1->bar1 +RP1_PCIE_APBS_BASE +REG_SET +MSIX_CFG (hwirq)); +} + +static void msix_cfg_clr (struct rp1_dev *rp1,unsigned int hwirq,u32 value) +{ +iowrite32 (value, rp1->bar1 +RP1_PCIE_APBS_BASE +REG_CLR +MSIX_CFG (hwirq)); +} + +static void rp1_mask_irq (struct irq_data *irqd) +{ +struct rp1_dev *rp1 = irqd->domain->host_data; +struct irq_data *pcie_irqd = rp1->pcie_irqds[irqd->hwirq]; + +pci_msi_mask_irq (pcie_irqd); +} + +static void rp1_unmask_irq (struct irq_data *irqd) +{ +struct rp1_dev *rp1 = irqd->domain->host_data; +struct irq_data *pcie_irqd = rp1->pcie_irqds[irqd->hwirq]; + +pci_msi_unmask_irq (pcie_irqd); +} + +static int rp1_irq_set_type (struct irq_data *irqd,unsigned int type) +{ +struct rp1_dev *rp1 = irqd->domain->host_data; +unsigned int hwirq = (unsigned int )irqd->hwirq; + +switch (type) { +case IRQ_TYPE_LEVEL_HIGH : +dev_dbg (rp1->dev,"MSIX IACK EN for irq %d\n" , hwirq); +msix_cfg_set (rp1, hwirq,MSIX_CFG_IACK_EN ); + rp1->level_triggered_irq[hwirq] = true; +break ; +case IRQ_TYPE_EDGE_RISING : +msix_cfg_clr (rp1, hwirq,MSIX_CFG_IACK_EN ); + rp1->level_triggered_irq[hwirq] = false; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static struct irq_chip rp1_irq_chip = { + .name ="rp1_irq_chip" , + .irq_mask = rp1_mask_irq, + .irq_unmask = rp1_unmask_irq, + .irq_set_type = rp1_irq_set_type, +}; + +static void rp1_chained_handle_irq (struct irq_desc *desc) +{ +unsigned int hwirq = desc->irq_data.hwirq &RP1_HW_IRQ_MASK ; +struct rp1_dev *rp1 =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +int virq; + +chained_irq_enter (chip, desc); + + virq =irq_find_mapping (rp1->domain, hwirq); +generic_handle_irq (virq); +if (rp1->level_triggered_irq[hwirq]) +msix_cfg_set (rp1, hwirq,MSIX_CFG_IACK ); + +chained_irq_exit (chip, desc); +} + +static int rp1_irq_xlate (struct irq_domain *d,struct device_node *node, +const u32 *intspec,unsigned int intsize, +unsigned long *out_hwirq,unsigned int *out_type) +{ +struct rp1_dev *rp1 = d->host_data; +struct irq_data *pcie_irqd; +unsigned long hwirq; +int pcie_irq; +int ret; + + ret =irq_domain_xlate_twocell (d, node, intspec, intsize, + &hwirq, out_type); +if (ret) +return ret; + + pcie_irq =pci_irq_vector (rp1->pdev, hwirq); + pcie_irqd =irq_get_irq_data (pcie_irq); + rp1->pcie_irqds[hwirq] = pcie_irqd; + *out_hwirq = hwirq; + +return 0 ; +} + +static int rp1_irq_activate (struct irq_domain *d,struct irq_data *irqd, +bool reserve) +{ +struct rp1_dev *rp1 = d->host_data; + +msix_cfg_set (rp1, (unsigned int )irqd->hwirq,MSIX_CFG_ENABLE ); + +return 0 ; +} + +static void rp1_irq_deactivate (struct irq_domain *d,struct irq_data *irqd) +{ +struct rp1_dev *rp1 = d->host_data; + +msix_cfg_clr (rp1, (unsigned int )irqd->hwirq,MSIX_CFG_ENABLE ); +} + +static const struct irq_domain_ops rp1_domain_ops = { + .xlate = rp1_irq_xlate, + .activate = rp1_irq_activate, + .deactivate = rp1_irq_deactivate, +}; + +static int rp1_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ +struct device *dev = &pdev->dev; +struct device_node *rp1_node; +struct reset_control *reset; +struct rp1_dev *rp1; +int err =0 ; +int i; + + rp1_node =dev_of_node (dev); +if (!rp1_node) { +dev_err (dev,"Missing of_node for device\n" ); +return -EINVAL ; + } + + rp1 =devm_kzalloc (&pdev->dev,sizeof (*rp1),GFP_KERNEL ); +if (!rp1) +return -ENOMEM ; + + rp1->pdev = pdev; + rp1->dev = &pdev->dev; + + reset =devm_reset_control_get_optional_exclusive (&pdev->dev,NULL ); +if (IS_ERR (reset)) +return PTR_ERR (reset); +reset_control_reset (reset); + +dump_bar (pdev,0 ); +dump_bar (pdev,1 ); + +if (pci_resource_len (pdev,1 ) <=0x10000 ) { +dev_err (&pdev->dev, +"Not initialised - is the firmware running?\n" ); +return -EINVAL ; + } + + err =pcim_enable_device (pdev); +if (err <0 ) { +dev_err (&pdev->dev,"Enabling PCI device has failed: %d" , + err); +return err; + } + + rp1->bar1 =pcim_iomap (pdev,1 ,0 ); +if (!rp1->bar1) { +dev_err (&pdev->dev,"Cannot map PCI BAR\n" ); +return -EIO ; + } + +u32 dtbo_size = __dtbo_rp1_pci_end - __dtbo_rp1_pci_begin; +void *dtbo_start = __dtbo_rp1_pci_begin; + + err =of_overlay_fdt_apply (dtbo_start, dtbo_size, &rp1->ovcs_id, rp1_node); +if (err) +return err; + +pci_set_master (pdev); + + err =pci_alloc_irq_vectors (pdev,RP1_INT_END ,RP1_INT_END , +PCI_IRQ_MSIX ); +if (err !=RP1_INT_END ) { +dev_err (&pdev->dev,"pci_alloc_irq_vectors failed - %d\n" , err); + goto err_unload_overlay; + } + +pci_set_drvdata (pdev, rp1); + rp1->domain =irq_domain_add_linear (of_find_node_by_name (NULL ,"pci-ep-bus" ),RP1_INT_END , + &rp1_domain_ops, rp1); + +for (i =0 ; i <RP1_INT_END ; i++) { +int irq =irq_create_mapping (rp1->domain, i); + +if (irq <0 ) { +dev_err (&pdev->dev,"failed to create irq mapping\n" ); + err = irq; + goto err_unload_overlay; + } +irq_set_chip_and_handler (irq, &rp1_irq_chip, handle_level_irq); +irq_set_probe (irq); +irq_set_chained_handler_and_data (pci_irq_vector (pdev, i), + rp1_chained_handle_irq, rp1); + } + + err =of_platform_default_populate (rp1_node,NULL , dev); +if (err) + goto err_unload_overlay; + +return 0 ; + +err_unload_overlay: +of_overlay_remove (&rp1->ovcs_id); + +return err; +} + +static void rp1_remove (struct pci_dev *pdev) +{ +struct rp1_dev *rp1 =pci_get_drvdata (pdev); +struct device *dev = &pdev->dev; +
drivers/misc/rp1/rp1_pci.c line 351
Quoted 10 lines
drivers/misc/rp1/rp1_pci.c new file +10
-0+of_platform_depopulate (dev); +of_overlay_remove (&rp1->ovcs_id); + +clk_unregister (rp1->sys_clk); +} + +static const struct pci_device_id dev_id_table[] = { + {PCI_DEVICE (PCI_VENDOR_ID_RPI ,PCI_DEVICE_ID_RPI_RP1_C0 ), }, + {0 , } +};
You need a
MODULE_DEVICE_TABLE(pci, dev_id_table);
here in order to load the module for the cases where it isn't built-in. Otherwise you have to manually modprobe the module.
Cheers.
Dave
Quoted 64 lines
drivers/misc/rp1/rp1_pci.c new file +14
-0+ +static struct pci_driver rp1_driver = { + .name =RP1_DRIVER_NAME , + .id_table = dev_id_table, + .probe = rp1_probe, + .remove = rp1_remove, +}; + +module_pci_driver (rp1_driver); + +MODULE_AUTHOR ("Phil Elwell <[email protected]>" ); +MODULE_AUTHOR ("Andrea della Porta <[email protected]>" ); +MODULE_DESCRIPTION ("RP1 wrapper" ); +MODULE_LICENSE ("GPL" );drivers/misc/rp1/rp1_pci.h new file +14
-0@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Copyright (c) 2018-24 Raspberry Pi Ltd. +* All rights reserved. +*/ + +#ifndef _RP1_EXTERN_H_ +#define _RP1_EXTERN_H_ + +extern char __dtbo_rp1_pci_begin[]; +extern char __dtbo_rp1_pci_end[]; + +#endif drivers/pci/quirks.c +1
-0@@ -6266,6 +6266,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0xa76e, dpc_log_size);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_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
-1@@ -2611,6 +2611,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 --2.35.3
Andrea della Porta
maintainerRe: [PATCH v2 11/14] misc: rp1: RaspberryPi RP1 misc driver
Hi Dave,
Quoted 4 lines · Dave Stevenson
Hi Andrea
Quoted 1 line · Andrea della Porta
...
Quoted 11 lines
drivers/misc/rp1/rp1_pci.c line 351
Quoted 4 lines
drivers/misc/rp1/rp1_pci.c new file +4
-0+static const struct pci_device_id dev_id_table[] = { + {PCI_DEVICE (PCI_VENDOR_ID_RPI ,PCI_DEVICE_ID_RPI_RP1_C0 ), }, + {0 , } +};You need a
MODULE_DEVICE_TABLE(pci, dev_id_table);here in order to load the module for the cases where it isn't built-in. Otherwise you have to manually modprobe the module.
Sure, thanks for the heads up!
Regards,
Andrea
Quoted 3 lines
Cheers.
Dave
...
Andrea della Porta
maintainerRe: [PATCH v2 08/14] clk: rp1: Add support for clocks provided by RP1
In reply to Herve CodinaHi Herve,
Quoted 24 lines · Herve Codina
Hi Andrea,
Quoted 18 lines · On Wed, 23 Oct 2024 17:36:06 +0200 Andrea della Porta <[email protected]>…
Hi Stephen,
Quoted 14 lines · Stephen Boyd
Quoting Andrea della Porta (2024-10-07 05:39:51)
drivers/clk/Kconfig config COMMON_CLK_RK808 · line 93
Quoted 11 lines
drivers/clk/Kconfig +3
-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 PCI || COMPILE_TESTA better limit would be some ARCH_* config.
Quoted 6 lines
Quoted 3 lines
I've avoided
ARCH_BCM2835since the original intention is for this driver to work (in the future) also for custom PCI cards with RP1 on-board, and not only for Rpi5.Maybe depends on
CONFIG_MISC_RP1?CONFIG_MISC_RP1enables the RP1 PCI driver
Yep, seems the most logical one, thanks.
Regards,
Andrea
Quoted 3 lines
Best regards,
Hervé
Andrea della Porta
maintainerRe: [PATCH v2 08/14] clk: rp1: Add support for clocks provided by RP1
In reply to Stephen BoydHi Stephen,
Quoted 19 lines · Stephen Boyd
Quoting Andrea della Porta (2024-10-23 08:36:06)
Quoted 18 lines
Hi Stephen,
Quoted 14 lines · Stephen Boyd
Quoting Andrea della Porta (2024-10-07 05:39:51)
drivers/clk/Kconfig config COMMON_CLK_RK808 · line 93
Quoted 11 lines
drivers/clk/Kconfig +3
-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 PCI || COMPILE_TESTA better limit would be some ARCH_* config.
Quoted 5 lines
Quoted 3 lines
I've avoided
ARCH_BCM2835since the original intention is for this driver to work (in the future) also for custom PCI cards with RP1 on-board, and not only for Rpi5.How will that custom PCI card work? It will need this driver to probe?
AFAICT there's no commercially available PCI card slot sporting an RP1 on-board, but this driver should be used to probe and use that card too.
Quoted 1 line
Is the iomem going to be exposed through some PCI config space?
Yes, just as leverage in this driver through BAR1.
Quoted 6 lines
It's not great to depend on
CONFIG_PCIbecause then the driver is forced to be =m if PCI ever becomes tristate (unlikely, but still makes for bad copy/pasta). I understand this line is trying to limit the availability of the config symbol. Maybe it should simply depend on ARM or ARM64? Or on nothing at all.
I see, Herve proposed CONFIG_MISC_RP1 that is enabled whenever this driver is selected, and it makes a lot of sense to me.
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
drivers/clk/clk-rp1.c new file +1
-0+#include <linux/clk.h> Quoted 8 lines
Quoted 1 line
Preferably this include isn't included.
This include is currently needed by
devm_clk_get_enabled()to retrieve the xosc. Since that clock is based on a crystal (so it's fixed and always enabled), I'm planning to hardcode it in the driver. This will not only get rid of thedevm_clk_get_enabled()call (and hence of theclk.hinclude), but it'll also simplify the top devicetree. No promise though, I need to check a couple of things first.
Quoted 2 lines
A clk provider (
clk-provider.h) should ideally not be a clk consumer (clk.h).
Ack.
Quoted 21 lines
Quoted 15 lines
Quoted 14 lines
drivers/clk/clk-rp1.c line 796
Quoted 11 lines
drivers/clk/clk-rp1.c new file +8
-0+ +static int rp1_pll_ph_set_rate (struct clk_hw *hw, +unsigned long rate,unsigned long parent_rate) +{ + struct rp1_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, hw); +const struct rp1_pll_ph_data *data = pll_ph->data; + +/* Nothing really to do here! */ Is it read-only? Don't define a
set_ratefunction then and make the rate determination function return the same value all the time.Quoted 3 lines
Not 100% sure about it, maybe Raspberry Pi colleagues can explain. By 'rate determination function' you're referring (in this case) to
rp1_pll_ph_recalc_rate(), right?Yes.
Quoted 8 lines
Quoted 3 lines
If so, that clock type seems to have
a fixed divider but teh resulting clock depends on the parent rate, so it has to be calculated.Sure, it has to be calculated, but it will return the rate that causes no change to the hardware. When that happens, the
set_rate()op should be skipped, and you can see that withclk_divider_ro_opsnot having aset_rate()function pointer.
Ack.
Quoted 55 lines
Quoted 19 lines
Quoted 18 lines
Quoted 6 lines
drivers/clk/clk-rp1.c new file +4
-0+static int rp1_clock_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ +struct clk_hw *parent, *best_parent =NULL ;drivers/clk/clk-rp1.c line 1195
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+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 )) {Is this flag ever set?
Quoted 5 lines
Not right now, but it will be used as soon as I'll add the video clocks, so I thought to leave it be to avoid adding it back in the future. For this minimal support is not needed though, so let me know if you want it removed.
Ok sure.
Quoted 28 lines
Quoted 11 lines
Quoted 11 lines
drivers/clk/clk-rp1.c new file +10
-0+ + [RP1_CLK_ETH_TSU] = REGISTER_CLK(.name = "clk_eth_tsu", + .parents = {"rp1-xosc"}, + .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 * MHz,Quoted 8 lines
drivers/clk/clk-rp1.c line 1556
Quoted 5 lines
drivers/clk/clk-rp1.c new file +5
-0+ .fc0_src = FC_NUM(5, 7), + ), + + [RP1_CLK_SYS] = REGISTER_CLK(.name = "clk_sys", + .parents = {"rp1-xosc", "-", "pll_sys"},Please use struct
clk_parent_dataorclk_hwdirectly. Don't use strings to describe parents.Describing parents as as strings allows to directly assign it to struct
clk_init_data, as inrp1_register_clock():const struct
rp1_clock_data*clock_data= data;
structclk_init_datainit = { };
...
init.parent_names =clock_data->parents;
Quoted 8 lines
Quoted 4 lines
otherwise we should create an array and populate from
clk_parent_data::name, which is of course feasible but a bit less compact. Are you sure you want to change it?Do not use strings to describe parents. That's the guiding principle here. I agree using strings certainly makes it easy to describe things but that doesn't mean it is acceptable.
Ack.
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 12 lines
drivers/clk/clk-rp1.c new file +11
-0+struct clk *clk_xosc; +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;drivers/clk/clk-rp1.c line 1609
Quoted 10 lines
drivers/clk/clk-rp1.c new file +10
-0+ + clockman->regs =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (clockman->regs)) +return PTR_ERR (clockman->regs); + + clk_xosc =devm_clk_get_enabled (dev,NULL ); +if (IS_ERR (clk_xosc)) +return PTR_ERR (clk_xosc); + + clockman->hw_xosc =__clk_get_hw (clk_xosc);Please use struct
clk_parent_data::indexinstead.
Quoted 6 lines
Quoted 2 lines
Sorry, I didn't catch what you mean here. Can you please elaborate?
Don't use
__clk_get_hw()at all. Also, don't useclk_get()and friends in clk provider drivers. Use structclk_parent_dataso that the framework can do the work for you at the right time.
Ack.
Many thanks,
Andrea
Andrea della Porta
maintainerRe: [PATCH v2 09/14] pinctrl: rp1: Implement RaspberryPi RP1 gpio support
In reply to Linus WalleijHi Linux,
Quoted 7 lines · Linus Walleij
Quoted 5 lines · Andrea della Porta
The 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.
Quoted 7 lines
Quoted 1 line
Signed-off-by Andrea della Porta <[email protected]>This is a nice driver and I find no issues with it, what causes an issue is
gpiochip_set_names()as pointed out by Bartosz. If you can live without the names you can remove that part for now and we can merge the driver, then you can add the names later when we sorted out how to share that function.
Sure, I'll drop the gpio-line-names patch for now.
Many thanks,
Andrea
Quoted 3 lines
Yours,
Linus Walleij
Andrea della Porta
maintainerRe: [PATCH v2 09/14] pinctrl: rp1: Implement RaspberryPi RP1 gpio support
In reply to Stefan WahrenHi Stefan,
Quoted 14 lines · Stefan Wahren
Am 11.10.24 um 11:03 schrieb Linus Walleij:
Quoted 7 lines · Andrea della Porta
Quoted 6 lines
The 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.
Quoted 6 lines
Quoted 1 line
Signed-off-by Andrea della Porta <[email protected]>This is a nice driver and I find no issues with it, what causes an issue is
gpiochip_set_names()as pointed out by Bartosz. If you can live without the names you can remove that part for now and we can merge the driver, then you can add the names later when we sorted out how to share that function.
Quoted 5 lines
I raised the concerns about missing gpio line names in the first version of patch, without knowing the real efforts.
So I'm fine with Linus' suggestion, because I don't want to delay the upstreaming effort unnecessarily.
Perfect, thanks.
Regards,
Andrea
Quoted 6 lines
Regards
Quoted 3 lines
Yours,
Linus Walleij
Andrea della Porta
maintainerRe: [PATCH v2 10/14] arm64: dts: rp1: Add support for RaspberryPi's RP1 device
In reply to Herve CodinaHi Herve,
Quoted 17 lines · Herve Codina
Hi Andrea,
Quoted 10 lines · On Mon, 7 Oct 2024 14:39:53 +0200 Andrea della Porta <[email protected]>…
RaspberryPi 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.Signed-off-by Andrea della Porta <[email protected]>---
...
Quoted 9 lines
arch/arm64/boot/dts/broadcom/rp1.dtso line 14
Quoted 5 lines
arch/arm64/boot/dts/broadcom/rp1.dtso new file +5
-0+/ { + fragment@0 { + target-path=""; + __overlay__ { + compatible = "pci1de4,1";The compatible is not needed here. Indeed, it will be added by the PCI core when it scans the bus and adds the missing nodes.
https://elixir.bootlin.com/linux/v6.12-rc2/source/drivers/pci/of_property.c#L383
Sure, but I've added it so that the dts could be validated.
Quoted 13 lines
Quoted 13 lines
arch/arm64/boot/dts/broadcom/rp1.dtso new file +12
-0+ #address-cells = <3>; + #size-cells = <2>; + + pci_ep_bus: pci-ep-bus@1 { + compatible = "simple-bus"; + ranges = <0xc0 0x40000000 + 0x01 0x00 0x00000000 + 0x00 0x00400000>; + dma-ranges = <0x10 0x00000000 + 0x43000000 0x10 0x00000000 + 0x10 0x00000000>; + #address-cells = <2>;
Quoted 8 lines
arch/arm64/boot/dts/broadcom/rp1.dtso line 30
Quoted 4 lines
arch/arm64/boot/dts/broadcom/rp1.dtso new file +4
-0+ #size-cells = <2>; + interrupt-controller; + interrupt-parent = <&pci_ep_bus>; + #interrupt-cells = <2>;Not sure this node should be an interrupt controller. The interrupt controller is the PCI device itself (i.e.the node where the overlay is applied).
Right.
Many thanks,
Andrea
Quoted 4 lines
Best regards,
Hervé
Andrea della Porta
maintainerRe: [PATCH v2 11/14] misc: rp1: RaspberryPi RP1 misc driver
In reply to Herve CodinaHi Herve,
Quoted 49 lines · Herve Codina
Hi Andrea,
Nice to see that other PCI drivers will use the DT overlay over PCI feature!
Quoted 40 lines · On Mon, 7 Oct 2024 14:39:54 +0200 Andrea della Porta <[email protected]>…
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.
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.
Since the gpio line names should be provided by the user, there is an interface through configfs that allows the userspace to load a DT overlay that will provide gpio-line-names property. The interface can be invoked like this:
cat rpi-rp1-gpios-5-b.dtbo >
/sys/kernel/config/rp1-cfg/gpio_set_namesand is designed to be similar to what users are already used to from distro with downstream kernel.
For reasons why this driver is contained in
drivers/misc, please check the links.This driver is heavily based on downstream code from RaspberryPi Foundation, and the original author is Phil Elwell.
Signed-off-by Andrea della Porta <[email protected]>...
Quoted 9 lines
drivers/misc/rp1/Makefile line 5
Quoted 8 lines
drivers/misc/rp1/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_MISC_RP1) += rp1-pci.o +rp1-pci-objs := rp1_pci.o rp1-pci.dtbo.o + +DTC_FLAGS_rp1-pci += -@Why do you need to add the symbol table (-@ option) in your dtbo ?
This was needed for loading the dtbo for gpio-line-names over the dtbo for RP1, but now that I've dropped that patch it is not needed anymore, so I'll remove that.
Quoted 124 lines
...
Quoted 122 lines
drivers/misc/rp1/rp1_pci.c new file +116
-0@@ -0,0 +1,365 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2018-24 Raspberry Pi Ltd. +* All rights reserved. +*/ + +#include <linux/clk.h> +#include <linux/clkdev.h> +#include <linux/clk-provider.h> +#include <linux/err.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/irqdomain.h> +#include <linux/module.h> +#include <linux/msi.h> +#include <linux/of_platform.h> +#include <linux/pci.h> +#include <linux/platform_device.h> +#include <linux/reset.h> + +#include "rp1_pci.h" + +#define RP1_DRIVER_NAME "rp1" + +#define RP1_HW_IRQ_MASK GENMASK(5, 0) + +#define REG_SET 0x800 +#define REG_CLR 0xc00 + +/* MSI-X CFG registers start at 0x8 */ +#define MSIX_CFG (x) (0x8 + (4 * (x))) + +#define MSIX_CFG_IACK_EN BIT(3) +#define MSIX_CFG_IACK BIT(2) +#define MSIX_CFG_ENABLE BIT(0) + +/* Address map */ +#define RP1_PCIE_APBS_BASE 0x108000 + +/* Interrupts */ +#define RP1_INT_IO_BANK0 0 +#define RP1_INT_IO_BANK1 1 +#define RP1_INT_IO_BANK2 2 +#define RP1_INT_AUDIO_IN 3 +#define RP1_INT_AUDIO_OUT 4 +#define RP1_INT_PWM0 5 +#define RP1_INT_ETH 6 +#define RP1_INT_I2C0 7 +#define RP1_INT_I2C1 8 +#define RP1_INT_I2C2 9 +#define RP1_INT_I2C3 10 +#define RP1_INT_I2C4 11 +#define RP1_INT_I2C5 12 +#define RP1_INT_I2C6 13 +#define RP1_INT_I2S0 14 +#define RP1_INT_I2S1 15 +#define RP1_INT_I2S2 16 +#define RP1_INT_SDIO0 17 +#define RP1_INT_SDIO1 18 +#define RP1_INT_SPI0 19 +#define RP1_INT_SPI1 20 +#define RP1_INT_SPI2 21 +#define RP1_INT_SPI3 22 +#define RP1_INT_SPI4 23 +#define RP1_INT_SPI5 24 +#define RP1_INT_UART0 25 +#define RP1_INT_TIMER_0 26 +#define RP1_INT_TIMER_1 27 +#define RP1_INT_TIMER_2 28 +#define RP1_INT_TIMER_3 29 +#define RP1_INT_USBHOST0 30 +#define RP1_INT_USBHOST0_0 31 +#define RP1_INT_USBHOST0_1 32 +#define RP1_INT_USBHOST0_2 33 +#define RP1_INT_USBHOST0_3 34 +#define RP1_INT_USBHOST1 35 +#define RP1_INT_USBHOST1_0 36 +#define RP1_INT_USBHOST1_1 37 +#define RP1_INT_USBHOST1_2 38 +#define RP1_INT_USBHOST1_3 39 +#define RP1_INT_DMA 40 +#define RP1_INT_PWM1 41 +#define RP1_INT_UART1 42 +#define RP1_INT_UART2 43 +#define RP1_INT_UART3 44 +#define RP1_INT_UART4 45 +#define RP1_INT_UART5 46 +#define RP1_INT_MIPI0 47 +#define RP1_INT_MIPI1 48 +#define RP1_INT_VIDEO_OUT 49 +#define RP1_INT_PIO_0 50 +#define RP1_INT_PIO_1 51 +#define RP1_INT_ADC_FIFO 52 +#define RP1_INT_PCIE_OUT 53 +#define RP1_INT_SPI6 54 +#define RP1_INT_SPI7 55 +#define RP1_INT_SPI8 56 +#define RP1_INT_SYSCFG 58 +#define RP1_INT_CLOCKS_DEFAULT 59 +#define RP1_INT_VBUSCTRL 60 +#define RP1_INT_PROC_MISC 57 +#define RP1_INT_END 61 + +struct rp1_dev { +struct pci_dev *pdev; +struct device *dev; +struct clk *sys_clk; +struct irq_domain *domain; +struct irq_data *pcie_irqds[64 ]; +void __iomem *bar1; +int ovcs_id; +bool level_triggered_irq[RP1_INT_END ]; +}; + +static void dump_bar (struct pci_dev *pdev,unsigned int bar)
Quoted 8 lines
drivers/misc/rp1/rp1_pci.c line 122
Quoted 6 lines
drivers/misc/rp1/rp1_pci.c new file +6
-0+{ +dev_info (&pdev->dev, +"bar%d %pR\n" , + bar, +pci_resource_n (pdev, bar)); +}Is this
dump_bar()really needed ?
Nope. Removed.
Quoted 23 lines
...
Quoted 21 lines
drivers/misc/rp1/rp1_pci.c new file +21
-0+static int rp1_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ +struct device *dev = &pdev->dev; +struct device_node *rp1_node; +struct reset_control *reset; +struct rp1_dev *rp1; +int err =0 ; +int i; + + rp1_node =dev_of_node (dev); +if (!rp1_node) { +dev_err (dev,"Missing of_node for device\n" ); +return -EINVAL ; + } + + rp1 =devm_kzalloc (&pdev->dev,sizeof (*rp1),GFP_KERNEL ); +if (!rp1) +return -ENOMEM ; + + rp1->pdev = pdev; + rp1->dev = &pdev->dev;
Quoted 8 lines
drivers/misc/rp1/rp1_pci.c line 267
Quoted 5 lines
drivers/misc/rp1/rp1_pci.c new file +5
-0+ + reset =devm_reset_control_get_optional_exclusive (&pdev->dev,NULL ); +if (IS_ERR (reset)) +return PTR_ERR (reset); +reset_control_reset (reset);This device is a PCI device.
Seems strange to get the reset control line for a PCI device.
And it isn't declared in teh node either, so right now seems a no-op. Removed.
Quoted 5 lines
drivers/misc/rp1/rp1_pci.c line 270
Quoted 4 lines
drivers/misc/rp1/rp1_pci.c new file +3
-0+ +dump_bar (pdev,0 ); +dump_bar (pdev,1 );No sure those 2
dump_bar()calls are really needed.
Removed as well.
Quoted 16 lines
Quoted 16 lines
drivers/misc/rp1/rp1_pci.c new file +16
-0+ +if (pci_resource_len (pdev,1 ) <=0x10000 ) { +dev_err (&pdev->dev, +"Not initialised - is the firmware running?\n" ); +return -EINVAL ; + } + + err =pcim_enable_device (pdev); +if (err <0 ) { +dev_err (&pdev->dev,"Enabling PCI device has failed: %d" , + err); +return err; + } + + rp1->bar1 =pcim_iomap (pdev,1 ,0 ); +if (!rp1->bar1) {
Quoted 8 lines
drivers/misc/rp1/rp1_pci.c line 292
Quoted 6 lines
drivers/misc/rp1/rp1_pci.c new file +6
-0+dev_err (&pdev->dev,"Cannot map PCI BAR\n" ); +return -EIO ; + } + +u32 dtbo_size = __dtbo_rp1_pci_end - __dtbo_rp1_pci_begin; +void *dtbo_start = __dtbo_rp1_pci_begin;Those declarations should be move at the beginning of the function.
Ack.
Quoted 9 lines
drivers/misc/rp1/rp1_pci.c line 297
Quoted 6 lines
drivers/misc/rp1/rp1_pci.c new file +5
-0+ + err =of_overlay_fdt_apply (dtbo_start, dtbo_size, &rp1->ovcs_id, rp1_node); +if (err) +return err; +Maybe applying the overlay should be done after the interrupt controller is ready.
Right.
Quoted 45 lines
Quoted 45 lines
drivers/misc/rp1/rp1_pci.c new file +44
-0+pci_set_master (pdev); + + err =pci_alloc_irq_vectors (pdev,RP1_INT_END ,RP1_INT_END , +PCI_IRQ_MSIX ); +if (err !=RP1_INT_END ) { +dev_err (&pdev->dev,"pci_alloc_irq_vectors failed - %d\n" , err); + goto err_unload_overlay; + } + +pci_set_drvdata (pdev, rp1); + rp1->domain =irq_domain_add_linear (of_find_node_by_name (NULL ,"pci-ep-bus" ),RP1_INT_END , + &rp1_domain_ops, rp1); + +for (i =0 ; i <RP1_INT_END ; i++) { +int irq =irq_create_mapping (rp1->domain, i); + +if (irq <0 ) { +dev_err (&pdev->dev,"failed to create irq mapping\n" ); + err = irq; + goto err_unload_overlay; + } +irq_set_chip_and_handler (irq, &rp1_irq_chip, handle_level_irq); +irq_set_probe (irq); +irq_set_chained_handler_and_data (pci_irq_vector (pdev, i), + rp1_chained_handle_irq, rp1); + } + + err =of_platform_default_populate (rp1_node,NULL , dev); +if (err) + goto err_unload_overlay; + +return 0 ; + +err_unload_overlay: +of_overlay_remove (&rp1->ovcs_id); + +return err; +} + +static void rp1_remove (struct pci_dev *pdev) +{ +struct rp1_dev *rp1 =pci_get_drvdata (pdev); +struct device *dev = &pdev->dev; +
Quoted 8 lines
drivers/misc/rp1/rp1_pci.c line 345
Quoted 4 lines
drivers/misc/rp1/rp1_pci.c new file +4
-0+of_platform_depopulate (dev); +of_overlay_remove (&rp1->ovcs_id); + +clk_unregister (rp1->sys_clk);Unless I missed something,
rp1->sys_clkis never set inprobe(). If this is correct,clk_unregister()should be removed and also the related clk header files.
Ack.
Quoted 2 lines
The interrupt controller created at
probe()should be destroyed atremove().
Ack.
Quoted 21 lines
Quoted 3 lines
drivers/misc/rp1/rp1_pci.c new file +2
-0+} +...
Quoted 16 lines
drivers/misc/rp1/rp1_pci.h new file +10
-0@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Copyright (c) 2018-24 Raspberry Pi Ltd. +* All rights reserved. +*/ + +#ifndef _RP1_EXTERN_H_ +#define _RP1_EXTERN_H_ +
Quoted 8 lines
drivers/misc/rp1/rp1_pci.h line 14
Quoted 4 lines
drivers/misc/rp1/rp1_pci.h new file +4
-0+extern char __dtbo_rp1_pci_begin[]; +extern char __dtbo_rp1_pci_end[]; + +#endif These two symbols are only used by the
rp1_pci.cfile. Not sure that therp1_pci.his needed.
Simply declare the symbols in therp1_pci.cfile.
I agree with you, and I did exactly as you suggest in the very first submission of this patch, but I received a couple of comments against it, so I've created the new header file.
Many thanks,
Andrea
Quoted 4 lines
Best regards,
Hervé
Andrea della Porta
maintainerRe: [PATCH v2 14/14] arm64: defconfig: Enable RP1 misc/clock/gpio drivers
In reply to Krzysztof KozlowskiHi Krzysztof,
Quoted 10 lines · Krzysztof Kozlowski
Quoted 9 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]>--- arch/arm64/configs/defconfig | 3 +++ 1 file changed, 3 insertions(+)
Quoted 11 lines
arch/arm64/configs/defconfig CONFIG_PINCTRL_QCM2290=y · line 612
Quoted 9 lines
arch/arm64/configs/defconfig +1
-0@@ -609,6 +609,7 @@ CONFIG_PINCTRL_QCM2290=y CONFIG_PINCTRL_QCS404=y CONFIG_PINCTRL_QDF2XXX=y CONFIG_PINCTRL_QDU1000=y +CONFIG_PINCTRL_RP1=yModule, that's not a SoC component.
This driver was born as a builtin only one, indeed it is bool and not tristate in Kconfig and is registered through builtin_platform_driver(). Hence I've set it =y in defconfig. A quick check transforming it to be dynamically loaded as a module confirm that something is not working, and I agree with you that, in theory, this should also be a loadable module. I need some investigation on that though...
Many thanks,
Andrea
Quoted 7 lines
arch/arm64/configs/defconfig CONFIG_PINCTRL_QCM2290=y · line 614
Quoted 3 lines
arch/arm64/configs/defconfig +0
-0CONFIG_PINCTRL_SA8775P=y CONFIG_PINCTRL_SC7180=yBest regards,
Krzysztof
Andrea della Porta
maintainerRe: [PATCH v2 08/14] clk: rp1: Add support for clocks provided by RP1
In reply to Stephen BoydHi Stephen,
Quoted 3 lines · Stephen Boyd
Quoting Andrea della Porta (2024-10-07 05:39:51)
drivers/clk/Kconfig
Quoted 2 lines
drivers/clk/Kconfig +0
-0
Here's below the kind response from RaspberryPi guys...
...
Quoted 8 lines
drivers/clk/Kconfig
Quoted 6 lines
drivers/clk/Kconfig +6
-0+ 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. */Why is '16' special?
16 is a hardware requirement.
The lowest feedback divisor in the PLL is 16, so the minimum output frequency is ref_freq * 16.
...
Quoted 8 lines
Quoted 8 lines
drivers/clk/Kconfig +8
-0+static unsigned long rp1_pll_core_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct rp1_pll_core *pll_core = container_of(hw, struct rp1_pll_core, 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;
Quoted 8 lines
drivers/clk/Kconfig
Quoted 5 lines
drivers/clk/Kconfig +5
-0+ + fbdiv_int = clockman_read(clockman, data->fbdiv_int_reg); + fbdiv_frac = clockman_read(clockman, data->fbdiv_frac_reg); + calc_rate = + ((u64)parent_rate * (((u64)fbdiv_int << 24) + fbdiv_frac) + (1 << 23)) >> 24;Where does '24' come from? Can you simplify this line somehow? Maybe break it up into multiple lines?
The dividers have an 8 bit integer and (optional) 24 bit fractional part to the divider value.
The two parts are split across two registers (int_reg and frac_reg), with the value stored in the bottom bits of both.
...
Quoted 8 lines
Quoted 8 lines
drivers/clk/Kconfig +8
-0+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;
Quoted 8 lines
drivers/clk/Kconfig
Quoted 6 lines
drivers/clk/Kconfig +6
-0+ 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)) {Is this flag ever set?
In future patches more clocks will be added (namely DPI, DSI (x2) and VEC). All have the CLK_SET_RATE_NO_REPARENT flag set.
As those peripherals are sensitive to the accuracy of the clocks, the intent is that the driver will have set the parent, and it isn't expected to change.
...
Quoted 8 lines
drivers/clk/Kconfig
Quoted 5 lines
drivers/clk/Kconfig +5
-0+ divider->div.reg = clockman->regs + divider_data->ctrl_reg; + divider->div.shift = PLL_SEC_DIV_SHIFT; + divider->div.width = PLL_SEC_DIV_WIDTH; + divider->div.flags = CLK_DIVIDER_ROUND_CLOSEST; + divider->div.flags |= CLK_IS_CRITICAL;Is everything critical? The usage of this flag and
CLK_IGNORE_UNUSEDis suspicious and likely working around some problems elsewhere.
the next patchset revision will drop as many of those CRITICAL flags as possible, and all of the IGNORE_UNUSED flags. That was legacy code needed on bcm-clk2835 since some clocks were enabled by the firmware, and therefore disabling them had the potential for locking the firmware up. This does no longer apply to RP1.
...
Many thanks,
Andrea