CLK: microchip: Add clkcfg driver for Microchip PolarFire SoC
Subsystems (3)
[email protected]
maintainerv8 cover CLK: microchip: Add clkcfg driver for Microchip PolarFire SoC
From: Conor Dooley <[email protected]>
This patchset adds support for the Microchip PolarFire clkcfg hardware block.
Changes since v7:
* Dropped clock-output-names again (oops)
Changes since v6:
* Dropped clock-output-names *as a required property*
* Dropped if(lock) check on spinlocks, added spinlocks to all read-modify-write register access
* Removed kfree()s on non-dynamically allocated variables
* Use devm_clk_get to get the reference clock
* Account for reserved clock when calculating the size of num_clks
Changes since v5:
* Dropped clock-output-names property
Major changes since v4:
* Adjusted license for microchip,mpfs-clock.h to match microchip,mpfs.yaml
* Corrected the number of clocks to 33 from 32
Major changes since v3:
* Patch reformatted so microchip,mpfs-clock.h is part of device-tree patch
Major changes since v2:
* In mpfs_cfg_clk_set_rate, return immediately if divider_get_val returns <0
* rebased to v5.12-rc1
Major changes since v1:
* Dependency on SOC_MICROCHIP_POLARFIRE
* All references to PFSOC/pfsoc changed to MPFS/mpfs
* Cleaned error handling in _probe
* Re-ordered code to place structs et al at top
Daire McNamara (2):
dt-bindings: clk: microchip: Add Microchip PolarFire host binding
clk: microchip: Add driver for Microchip PolarFire SoC
.../bindings/clock/microchip,mpfs.yaml | 58 +++ drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 2 +- drivers/clk/microchip/Kconfig | 7 + drivers/clk/microchip/Makefile | 6 +- drivers/clk/microchip/clk-mpfs.c | 447 ++++++++++++++++++ .../dt-bindings/clock/microchip,mpfs-clock.h | 45 ++ 7 files changed, 563 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/microchip,mpfs.yaml create mode 100644 drivers/clk/microchip/Kconfig create mode 100644 drivers/clk/microchip/clk-mpfs.c create mode 100644 include/dt-bindings/clock/microchip,mpfs-clock.h
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH v8 1/2 dt-bindings: clk: microchip: Add Microchip PolarFire host binding
From: Daire McNamara <[email protected]>
Add device tree bindings for the Microchip PolarFire system clock controller
--- .../bindings/clock/microchip,mpfs.yaml | 58 +++++++++++++++++++ .../dt-bindings/clock/microchip,mpfs-clock.h | 45 ++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/microchip,mpfs.yaml create mode 100644 include/dt-bindings/clock/microchip,mpfs-clock.h
Documentation/devicetree/bindings/clock/microchip,mpfs.yaml new file +58 -0
@@ -0,0 +1,58 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/microchip,mpfs.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip PolarFire Clock Control Module Binding + +maintainers: + - Daire McNamara <[email protected]> + +description: | + Microchip PolarFire clock control (CLKCFG) is an integrated clock controller, + which gates and enables all peripheral clocks. + + This device tree binding describes 33 gate clocks. Clocks are referenced by + user nodes by the CLKCFG node phandle and the clock index in the group, from + 0 to 32. + +properties: + compatible: + const: microchip,mpfs-clkcfg + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + '#clock-cells': + const: 1 + description: | + The clock consumer should specify the desired clock by having the clock + ID in its "clocks" phandle cell. See include/dt-bindings/clock/microchip,mpfs-clock.h + for the full list of PolarFire clock IDs. + +required: + - compatible + - reg + - clocks + - '#clock-cells' + +additionalProperties: false + +examples: + # Clock Config node: + - | + #include <dt-bindings/clock/microchip,mpfs-clock.h> + soc { + #address-cells = <2>; + #size-cells = <2>; + clkcfg: clock-controller@20002000 { + compatible = "microchip,mpfs-clkcfg"; + reg = <0x0 0x20002000 0x0 0x1000>; + clocks = <&ref>; + #clock-cells = <1>; + }; + };
include/dt-bindings/clock/microchip,mpfs-clock.h new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH v8 2/2 clk: microchip: Add driver for Microchip PolarFire SoC
In reply to [email protected]From: Daire McNamara <[email protected]>
Add support for clock configuration on Microchip PolarFire SoC
--- drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 2 +- drivers/clk/microchip/Kconfig | 7 + drivers/clk/microchip/Makefile | 6 +- drivers/clk/microchip/clk-mpfs.c | 447 +++++++++++++++++++++++++++++++ 5 files changed, 460 insertions(+), 3 deletions(-) create mode 100644 drivers/clk/microchip/Kconfig create mode 100644 drivers/clk/microchip/clk-mpfs.c
drivers/clk/Kconfig +1 -0
@@ -409,6 +409,7 @@ source "drivers/clk/keystone/Kconfig" source "drivers/clk/mediatek/Kconfig" source "drivers/clk/meson/Kconfig" source "drivers/clk/mstar/Kconfig" +source "drivers/clk/microchip/Kconfig" source "drivers/clk/mvebu/Kconfig" source "drivers/clk/pistachio/Kconfig" source "drivers/clk/qcom/Kconfig"
drivers/clk/Makefile +1 -1
@@ -90,7 +90,7 @@ obj-$(CONFIG_ARCH_KEYSTONE) += keystone/ obj-$(CONFIG_MACH_LOONGSON32) += loongson1/ obj-y += mediatek/ obj-$(CONFIG_ARCH_MESON) += meson/ -obj-$(CONFIG_MACH_PIC32) += microchip/ +obj-y += microchip/ ifeq ($(CONFIG_COMMON_CLK), y) obj-$(CONFIG_ARCH_MMP) += mmp/ endif
drivers/clk/microchip/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 + +config MCHP_CLK_MPFS + bool "Clk driver for PolarFire SoC" + depends on (RISCV && SOC_MICROCHIP_POLARFIRE) || COMPILE_TEST + help + Supports Clock Configuration for PolarFire SoC
drivers/clk/microchip/Makefile +4 -2
@@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_COMMON_CLK_PIC32) += clk-core.o -obj-$(CONFIG_PIC32MZDA) += clk-pic32mzda.o + +obj-$(CONFIG_COMMON_CLK_PIC32) += clk-core.o +obj-$(CONFIG_PIC32MZDA) += clk-pic32mzda.o +obj-$(CONFIG_MCHP_CLK_MPFS) += clk-mpfs.o
drivers/clk/microchip/clk-mpfs.c new file +447 -0
447 lines not on this page · raw message
Signature · 1 line
2.33.1
Re: [PATCH v8 2/2] clk: microchip: Add driver for Microchip PolarFire SoC
Hi Conor,
Quoted 9 lines · On Thu, Dec 16, 2021 at 10:41 AM <[email protected]> wrote:
From: Daire McNamara <[email protected]>
Add support for clock configuration on Microchip PolarFire SoC
Co-developed-by Padmarao Bengari <[email protected]>Signed-off-by Padmarao Bengari <[email protected]>Signed-off-by Daire McNamara <[email protected]>Co-developed-by Conor Dooley <[email protected]>Signed-off-by Conor Dooley <[email protected]>
Thanks for the update!
drivers/clk/microchip/clk-mpfs.c line 148
Quoted 6 lines
drivers/clk/microchip/clk-mpfs.c new file +3
-0+static void mpfs_clk_unregister_cfg (struct device *dev,struct clk_hw *hw) +{ +devm_clk_hw_unregister (dev, hw);
Just call devm_clk_hw_unregister() directly from the caller?
Quoted 4 lines
drivers/clk/microchip/clk-mpfs.c new file +3
-0+} +static int mpfs_clk_register_cfgs (struct device *dev,struct mpfs_cfg_hw_clock *cfg_hws, +unsigned int num_clks,struct mpfs_clock_data *data)
drivers/clk/microchip/clk-mpfs.c line 180
Quoted 10 lines
drivers/clk/microchip/clk-mpfs.c new file +10
-0+{ +struct clk_hw *hw; +struct clk *clk_parent; +void __iomem *sys_base = data->base; +unsigned int i, id; + +for (i =0 ; i < num_clks; i++) { +struct mpfs_cfg_hw_clock *cfg_hw = &cfg_hws[i]; + + clk_parent =devm_clk_get (dev,NULL );
Please get the clock once, in mpfs_clk_probe()...
drivers/clk/microchip/clk-mpfs.c line 182
Quoted 2 lines
drivers/clk/microchip/clk-mpfs.c new file +2
-0+if (IS_ERR (clk_parent)) +return -EPROBE_DEFER ;
... and propagate the actual error.
Quoted 41 lines
drivers/clk/microchip/clk-mpfs.c new file +40
-0+ + cfg_hw->cfg.parent =__clk_get_hw (clk_parent); + cfg_hw->hw.init =CLK_HW_INIT_HW (cfg_hw->cfg.name, cfg_hw->cfg.parent, + &mpfs_clk_cfg_ops, cfg_hw->cfg.flags); + hw =mpfs_clk_register_cfg (dev, cfg_hw, sys_base); +if (IS_ERR (hw)) { +dev_err (dev,"failed to register clock %s\n" , cfg_hw->cfg.name); + goto err_clk; + } + + id = cfg_hws[i].cfg.id; + data->hw_data.hws[id] = hw; + } + +return 0 ; + +err_clk: +while (i--) +mpfs_clk_unregister_cfg (dev, data->hw_data.hws[cfg_hws[i].cfg.id]); + +return PTR_ERR (hw); +} +static struct mpfs_periph_hw_clock mpfs_periph_clks[] = { +CLK_PERIPH (CLK_ENVM ,"clk_periph_envm" ,PARENT_CLK (AHB ),0 ,CLK_IS_CRITICAL ), +CLK_PERIPH (CLK_MAC0 ,"clk_periph_mac0" ,PARENT_CLK (AHB ),1 ,0 ), +CLK_PERIPH (CLK_MAC1 ,"clk_periph_mac1" ,PARENT_CLK (AHB ),2 ,0 ), +CLK_PERIPH (CLK_MMC ,"clk_periph_mmc" ,PARENT_CLK (AHB ),3 ,0 ), +CLK_PERIPH (CLK_TIMER ,"clk_periph_timer" ,PARENT_CLK (AHB ),4 ,0 ), +CLK_PERIPH (CLK_MMUART0 ,"clk_periph_mmuart0" ,PARENT_CLK (AHB ),5 ,CLK_IS_CRITICAL ), +CLK_PERIPH (CLK_MMUART1 ,"clk_periph_mmuart1" ,PARENT_CLK (AHB ),6 ,0 ), +CLK_PERIPH (CLK_MMUART2 ,"clk_periph_mmuart2" ,PARENT_CLK (AHB ),7 ,0 ), +CLK_PERIPH (CLK_MMUART3 ,"clk_periph_mmuart3" ,PARENT_CLK (AHB ),8 ,0 ), +CLK_PERIPH (CLK_MMUART4 ,"clk_periph_mmuart4" ,PARENT_CLK (AHB ),9 ,0 ), +CLK_PERIPH (CLK_SPI0 ,"clk_periph_spi0" ,PARENT_CLK (AHB ),10 ,0 ), +CLK_PERIPH (CLK_SPI1 ,"clk_periph_spi1" ,PARENT_CLK (AHB ),11 ,0 ), +CLK_PERIPH (CLK_I2C0 ,"clk_periph_i2c0" ,PARENT_CLK (AHB ),12 ,0 ), +CLK_PERIPH (CLK_I2C1 ,"clk_periph_i2c1" ,PARENT_CLK (AHB ),13 ,0 ), +CLK_PERIPH (CLK_CAN0 ,"clk_periph_can0" ,PARENT_CLK (AHB ),14 ,0 ), +CLK_PERIPH (CLK_CAN1 ,"clk_periph_can1" ,PARENT_CLK (AHB ),15 ,0 ), +CLK_PERIPH (CLK_USB ,"clk_periph_usb" ,PARENT_CLK (AHB ),16 ,0 ),
drivers/clk/microchip/clk-mpfs.c
Quoted 10 lines
drivers/clk/microchip/clk-mpfs.c new file +10
-0+CLK_PERIPH (CLK_RTC ,"clk_periph_rtc" ,PARENT_CLK (AHB ),18 ,0 ), +CLK_PERIPH (CLK_QSPI ,"clk_periph_qspi" ,PARENT_CLK (AHB ),19 ,0 ), +CLK_PERIPH (CLK_GPIO0 ,"clk_periph_gpio0" ,PARENT_CLK (AHB ),20 ,0 ), +CLK_PERIPH (CLK_GPIO1 ,"clk_periph_gpio1" ,PARENT_CLK (AHB ),21 ,0 ), +CLK_PERIPH (CLK_GPIO2 ,"clk_periph_gpio2" ,PARENT_CLK (AHB ),22 ,0 ), +CLK_PERIPH (CLK_DDRC ,"clk_periph_ddrc" ,PARENT_CLK (AHB ),23 ,CLK_IS_CRITICAL ), +CLK_PERIPH (CLK_FIC0 ,"clk_periph_fic0" ,PARENT_CLK (AHB ),24 ,CLK_IS_CRITICAL ), +CLK_PERIPH (CLK_FIC1 ,"clk_periph_fic1" ,PARENT_CLK (AHB ),25 ,CLK_IS_CRITICAL ), +CLK_PERIPH (CLK_FIC2 ,"clk_periph_fic2" ,PARENT_CLK (AHB ),26 ,CLK_IS_CRITICAL ), + CLK_PERIPH(CLK_FIC3, "clk_periph_fic3", PARENT_CLK(AHB), 27, CLK_IS_CRITICAL),
Why were the ficN clocks changed to critical clocks? it seemed to work fine without that before?
drivers/clk/microchip/clk-mpfs.c line 323
Quoted 7 lines
drivers/clk/microchip/clk-mpfs.c new file +7
-0+CLK_PERIPH (CLK_ATHENA ,"clk_periph_athena" ,PARENT_CLK (AHB ),28 ,0 ), + CLK_PERIPH(CLK_CFM, "clk_periph_cfm", PARENT_CLK(AHB), 29, 0), +}; + +static void mpfs_clk_unregister_periph (struct device *dev,struct clk_hw *hw) +{ +devm_clk_hw_unregister (dev, hw);
Just call devm_clk_hw_unregister() directly from the caller?
Quoted 1 line
+}
The above are minor comments, so
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
[email protected]
maintainerRe: [PATCH v8 2/2] clk: microchip: Add driver for Microchip PolarFire SoC
Quoted 30 lines · Geert Uytterhoeven
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 18 lines
drivers/clk/microchip/clk-mpfs.c new file +18
-0+static struct mpfs_periph_hw_clock mpfs_periph_clks[] = { +CLK_PERIPH (CLK_ENVM ,"clk_periph_envm" ,PARENT_CLK (AHB ),0 ,CLK_IS_CRITICAL ), +CLK_PERIPH (CLK_MAC0 ,"clk_periph_mac0" ,PARENT_CLK (AHB ),1 ,0 ), +CLK_PERIPH (CLK_MAC1 ,"clk_periph_mac1" ,PARENT_CLK (AHB ),2 ,0 ), +CLK_PERIPH (CLK_MMC ,"clk_periph_mmc" ,PARENT_CLK (AHB ),3 ,0 ), +CLK_PERIPH (CLK_TIMER ,"clk_periph_timer" ,PARENT_CLK (AHB ),4 ,0 ), +CLK_PERIPH (CLK_MMUART0 ,"clk_periph_mmuart0" ,PARENT_CLK (AHB ),5 ,CLK_IS_CRITICAL ), +CLK_PERIPH (CLK_MMUART1 ,"clk_periph_mmuart1" ,PARENT_CLK (AHB ),6 ,0 ), +CLK_PERIPH (CLK_MMUART2 ,"clk_periph_mmuart2" ,PARENT_CLK (AHB ),7 ,0 ), +CLK_PERIPH (CLK_MMUART3 ,"clk_periph_mmuart3" ,PARENT_CLK (AHB ),8 ,0 ), +CLK_PERIPH (CLK_MMUART4 ,"clk_periph_mmuart4" ,PARENT_CLK (AHB ),9 ,0 ), +CLK_PERIPH (CLK_SPI0 ,"clk_periph_spi0" ,PARENT_CLK (AHB ),10 ,0 ), +CLK_PERIPH (CLK_SPI1 ,"clk_periph_spi1" ,PARENT_CLK (AHB ),11 ,0 ), +CLK_PERIPH (CLK_I2C0 ,"clk_periph_i2c0" ,PARENT_CLK (AHB ),12 ,0 ), +CLK_PERIPH (CLK_I2C1 ,"clk_periph_i2c1" ,PARENT_CLK (AHB ),13 ,0 ), +CLK_PERIPH (CLK_CAN0 ,"clk_periph_can0" ,PARENT_CLK (AHB ),14 ,0 ), +CLK_PERIPH (CLK_CAN1 ,"clk_periph_can1" ,PARENT_CLK (AHB ),15 ,0 ), +CLK_PERIPH (CLK_USB ,"clk_periph_usb" ,PARENT_CLK (AHB ),16 ,0 ),drivers/clk/microchip/clk-mpfs.c line 316
Quoted 10 lines
drivers/clk/microchip/clk-mpfs.c new file +10
-0+CLK_PERIPH (CLK_RTC ,"clk_periph_rtc" ,PARENT_CLK (AHB ),18 ,0 ), +CLK_PERIPH (CLK_QSPI ,"clk_periph_qspi" ,PARENT_CLK (AHB ),19 ,0 ), +CLK_PERIPH (CLK_GPIO0 ,"clk_periph_gpio0" ,PARENT_CLK (AHB ),20 ,0 ), +CLK_PERIPH (CLK_GPIO1 ,"clk_periph_gpio1" ,PARENT_CLK (AHB ),21 ,0 ), +CLK_PERIPH (CLK_GPIO2 ,"clk_periph_gpio2" ,PARENT_CLK (AHB ),22 ,0 ), +CLK_PERIPH (CLK_DDRC ,"clk_periph_ddrc" ,PARENT_CLK (AHB ),23 ,CLK_IS_CRITICAL ), +CLK_PERIPH (CLK_FIC0 ,"clk_periph_fic0" ,PARENT_CLK (AHB ),24 ,CLK_IS_CRITICAL ), +CLK_PERIPH (CLK_FIC1 ,"clk_periph_fic1" ,PARENT_CLK (AHB ),25 ,CLK_IS_CRITICAL ), +CLK_PERIPH (CLK_FIC2 ,"clk_periph_fic2" ,PARENT_CLK (AHB ),26 ,CLK_IS_CRITICAL ), + CLK_PERIPH(CLK_FIC3, "clk_periph_fic3", PARENT_CLK(AHB), 27, CLK_IS_CRITICAL),
Quoted 2 lines
Why were the ficN clocks changed to critical clocks? it seemed to work fine without that before?
Acking the other comments. The fic clocks are the fpga fabric clocks & we found that disabling them could cause a hart to lock up.
Quoted 11 lines
drivers/clk/microchip/clk-mpfs.c line 323
Quoted 8 lines
drivers/clk/microchip/clk-mpfs.c new file +7
-0+CLK_PERIPH (CLK_ATHENA ,"clk_periph_athena" ,PARENT_CLK (AHB ),28 ,0 ), + CLK_PERIPH(CLK_CFM, "clk_periph_cfm", PARENT_CLK(AHB), 29, 0), +}; + +static void mpfs_clk_unregister_periph (struct device *dev,struct clk_hw *hw) +{ +devm_clk_hw_unregister (dev, hw);Just call
devm_clk_hw_unregister()directly from the caller?
Quoted 5 lines
Quoted 1 line
+}
The above are minor comments, so
Reviewed-by Geert Uytterhoeven <[email protected]>Tested-by Geert Uytterhoeven <[email protected]>
cool, thanks :)
Quoted 12 lines
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds