Add rtc refclk support for PolarFire SoC
Subsystems (5)
Conor Dooley
maintainercover Add rtc refclk support for PolarFire SoC
Hey,
As I mentioned in my fixes for 5.18 [0], found out that the reference clock for the rtc is actually missing from the clock driver (and the dt binding).
Currently the mpfs clock driver uses a reference clock called the "msspll", set in the device tree, as the parent for the cpu/axi/ahb (config) clocks. The frequency of the msspll is determined by the FPGA bitstream & the bootloader configures the clock to match the bitstream. The real reference is provided by a 100 or 125 MHz off chip oscillator.
However, the msspll clock is not actually the parent of all clocks on the system - the reference clock for the rtc/mtimer actually has the off chip oscillator as its parent.
This series enables reading the rate of the msspll clock, converts the refclock in the device tree to the external reference & adds the missing rtc reference clock.
I assume it is okay not to add fixes tags for the rtc dt binding? Since the clock was previously missing, the binding is wrong, but idk if that qualifies as a fix?
Clock driver changes depend on the fixes I sent in [0]. Please lmk if you want me to respin into a single series w/ the fixes. Thanks,
Conor.
[0]: https://lore.kernel.org/linux-riscv/[email protected]/
Conor Dooley (7):
dt-bindings: clk: mpfs document msspll dri registers
dt-bindings: clk: mpfs: add defines for two new clocks
dt-bindings: rtc: add refclk to mpfs-rtc
clk: microchip: mpfs: re-parent the configurable clocks
clk: microchip: mpfs: rename sys_base to base
clk: microchip: mpfs: add RTCREF clock control
riscv: dts: microchip: reparent mpfs clocks
.../bindings/clock/microchip,mpfs.yaml | 11 +- .../bindings/rtc/microchip,mfps-rtc.yaml | 14 +- .../microchip/microchip-mpfs-icicle-kit.dts | 2 +- .../boot/dts/microchip/microchip-mpfs.dtsi | 8 +- drivers/clk/microchip/clk-mpfs.c | 205 +++++++++++++++--- .../dt-bindings/clock/microchip,mpfs-clock.h | 5 +- 6 files changed, 199 insertions(+), 46 deletions(-)
Signature · 1 line
2.35.1
Conor Dooley
maintainerPATCH 1/7 dt-bindings: clk: mpfs document msspll dri registers
As there are two sections of registers that are responsible for clock configuration on the PolarFire SoC: add the dynamic reconfiguration interface section to the binding & describe what each of the sections are used for.
--- .../devicetree/bindings/clock/microchip,mpfs.yaml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/clock/microchip,mpfs.yaml +9 -2
@@ -22,7 +22,14 @@ properties: const: microchip,mpfs-clkcfg reg: - maxItems: 1 + items: + - description: | + clock config registers: + These registers contain enable, reset & divider tables for the, cpu, axi, ahb and + rtc/mtimer reference clocks as well as enable and reset for the peripheral clocks. + - description: | + mss pll dri registers: + Block of registers responsible for dynamic reconfiguration of the mss pll clocks: maxItems: 1
@@ -51,7 +58,7 @@ examples: #size-cells = <2>; clkcfg: clock-controller@20002000 { compatible = "microchip,mpfs-clkcfg"; - reg = <0x0 0x20002000 0x0 0x1000>; + reg = <0x0 0x20002000 0x0 0x1000>, <0x0 0x3E001000 0x0 0x1000>; clocks = <&ref>; #clock-cells = <1>; };
Signature · 1 line
2.35.1
Re: [PATCH v1 1/7] dt-bindings: clk: mpfs document msspll dri registers
Quoted 4 lines · Conor Dooley
As there are two sections of registers that are responsible for clock configuration on the PolarFire SoC: add the dynamic reconfiguration interface section to the binding & describe what each of the sections are used for.
(...)
Documentation/devicetree/bindings/clock/microchip,mpfs.yaml properties: · line 32
Quoted 12 lines
reg:
Documentation/devicetree/bindings/clock/microchip,mpfs.yaml +8
-1- maxItems: 1 + items: + - description: | + clock config registers: + These registers contain enable, reset & divider tables for the, cpu, axi, ahb and + rtc/mtimer reference clocks as well as enable and reset for the peripheral clocks. + - description: | + mss pll dri registers: + Block of registers responsible for dynamic reconfiguration of the mss pll
This breaks all of DTS - in and out of tree.
Best regards,
Krzysztof
Conor Dooley
maintainerPATCH 2/7 dt-bindings: clk: mpfs: add defines for two new clocks
In reply to Conor DooleyThe RTC reference and MSSPLL were previously not documented or defined, as they were unused. Add their defines to the PolarFire SoC header.
--- include/dt-bindings/clock/microchip,mpfs-clock.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/dt-bindings/clock/microchip,mpfs-clock.h +4 -1
@@ -1,15 +1,18 @@/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ /* * Daire McNamara,<[email protected]> -* Copyright (C) 2020 Microchip Technology Inc. All rights reserved. +* Copyright (C) 2020-2022 Microchip Technology Inc. All rights reserved. */ #ifndef _DT_BINDINGS_CLK_MICROCHIP_MPFS_H_#define _DT_BINDINGS_CLK_MICROCHIP_MPFS_H_ +#define CLK_MSSPLL 34 +#define CLK_CPU 0#define CLK_AXI 1#define CLK_AHB 2 +#define CLK_RTCREF 33#define CLK_ENVM 3#define CLK_MAC0 4
Signature · 1 line
2.35.1
Conor Dooley
maintainerPATCH 3/7 dt-bindings: rtc: add refclk to mpfs-rtc
In reply to Conor DooleyThe rtc on PolarFire SoC does not use the AHB clock as its reference frequency, but rather a 1 MHz refclk that it shares with MTIMER. Add this second clock to the binding as a required property.
--- .../bindings/rtc/microchip,mfps-rtc.yaml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml +11 -3
@@ -31,11 +31,18 @@ properties: to that of the RTC's count register. clocks: - maxItems: 1 + items: + - description: | + AHB clock + - description: | + Reference clock: divided by the prescaler to create a time-based strobe (typically 1 Hz) + for the calendar counter. By default, the rtc on the PolarFire SoC shares it's reference + with MTIMER so this will be a 1 MHz clock. clock-names: items: - const: rtc + - const: rtcref required: - compatible
@@ -48,11 +55,12 @@ additionalProperties: false examples: - | + #include "dt-bindings/clock/microchip,mpfs-clock.h" rtc@20124000 { compatible = "microchip,mpfs-rtc"; reg = <0x20124000 0x1000>; - clocks = <&clkcfg 21>; - clock-names = "rtc"; + clocks = <&clkcfg CLK_RTC>, <&clkcfg CLK_RTCREF>; + clock-names = "rtc", "rtcref"; interrupts = <80>, <81>; }; ...
Signature · 1 line
2.35.1
Re: [PATCH v1 3/7] dt-bindings: rtc: add refclk to mpfs-rtc
Quoted 15 lines · Conor Dooley
The rtc on PolarFire SoC does not use the AHB clock as its reference frequency, but rather a 1 MHz refclk that it shares with MTIMER. Add this second clock to the binding as a required property.
Reviewed-by Daire McNamara <[email protected]>Signed-off-by Conor Dooley <[email protected]>--- .../bindings/rtc/microchip,mfps-rtc.yaml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml +0
-0
Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml properties: · line 37
Quoted 8 lines
Documentation/devicetree/bindings/rtc/microchip,mfps-rtc.yaml +4
-1@@ -31,11 +31,18 @@ properties: to that of the RTC's count register. clocks: - maxItems: 1 + items: + - description: | + AHB clock + - description: |
Same as your patch #1 - this breaks the ABI.
Best regards,
Krzysztof
Conor Dooley
maintainerPATCH 4/7 clk: microchip: mpfs: re-parent the configurable clocks
In reply to Conor DooleyCurrently the mpfs clock driver uses a reference clock called the "msspll", set in the device tree, as the parent for the cpu/axi/ahb (config) clocks. The frequency of the msspll is determined by the FPGA bitstream & the bootloader configures the clock to match the bitstream. The real reference is provided by a 100 or 125 MHz off chip oscillator.
However, the msspll clock is not actually the parent of all clocks on the system - the reference clock for the rtc/mtimer actually has the off chip oscillator as its parent.
In order to fix this, add support for reading the configuration of the msspll & reparent the "config" clocks so that they are derived from this clock rather than the reference in the device tree.
---
@Stephen/Mike: Is it acceptable to add the recalc rate without a set rate? If not lmk and I will add one.
drivers/clk/microchip/clk-mpfs.c | 151 +++++++++++++++++++++++++++---- 1 file changed, 132 insertions(+), 19 deletions(-)
drivers/clk/microchip/clk-mpfs.c +132 -19
@@ -11,19 +11,46 @@#include <dt-bindings/clock/microchip,mpfs-clock.h> /* address offset of control registers */ +#define REG_MSSPLL_REF_CR 0x08u +#define REG_MSSPLL_POSTDIV_CR 0x10u +#define REG_MSSPLL_SSCG_2_CR 0x2Cu#define REG_CLOCK_CONFIG_CR 0x08u#define REG_SUBBLK_CLOCK_CR 0x84u +#define MSSPLL_FBDIV_SHIFT 0x00u +#define MSSPLL_FBDIV_WIDTH 0x0Cu +#define MSSPLL_REFDIV_SHIFT 0x08u +#define MSSPLL_REFDIV_WIDTH 0x06u +#define MSSPLL_POSTDIV_SHIFT 0x08u +#define MSSPLL_POSTDIV_WIDTH 0x07u +#define MSSPLL_FIXED_DIV 4u +struct mpfs_clock_data {void __iomem *base; +void __iomem *msspll_base;struct clk_hw_onecell_data hw_data; }; +struct mpfs_msspll_hw_clock { +void __iomem *base; +unsigned int id; +u32 reg_offset; +u32 shift; +u32 width; +u32 flags; +struct clk_hw hw; +struct clk_init_data init; +}; + +#define to_mpfs_msspll_clk (_hw) container_of(_hw, struct mpfs_msspll_hw_clock, hw) +struct mpfs_cfg_clock {const struct clk_div_table *table;unsigned int id; +u32 reg_offset;u8 shift;u8 width; +u8 flags; };struct mpfs_cfg_hw_clock {
@@ -54,7 +81,7 @@ struct mpfs_periph_hw_clock {*/ static DEFINE_SPINLOCK (mpfs_clk_lock); -static const struct clk_parent_data mpfs_cfg_parent[] = { +static const struct clk_parent_data mpfs_ext_ref[] = { { .index =0 }, };
@@ -68,6 +95,75 @@ static const struct clk_div_table mpfs_div_ahb_table[] = { { 0, 0 } }; +static unsigned long mpfs_clk_msspll_recalc_rate (struct clk_hw *hw,unsigned long prate) +{ +struct mpfs_msspll_hw_clock *msspll_hw =to_mpfs_msspll_clk (hw); +void __iomem *mult_addr = msspll_hw->base + msspll_hw->reg_offset; +void __iomem *ref_div_addr = msspll_hw->base +REG_MSSPLL_REF_CR ; +void __iomem *postdiv_addr = msspll_hw->base +REG_MSSPLL_POSTDIV_CR ; +u32 mult, ref_div, postdiv; + + mult =readl_relaxed (mult_addr) >>MSSPLL_FBDIV_SHIFT ; + mult &=clk_div_mask (MSSPLL_FBDIV_WIDTH ); + ref_div =readl_relaxed (ref_div_addr) >>MSSPLL_REFDIV_SHIFT ; + ref_div &=clk_div_mask (MSSPLL_REFDIV_WIDTH ); + postdiv =readl_relaxed (postdiv_addr) >>MSSPLL_POSTDIV_SHIFT ; + postdiv &=clk_div_mask (MSSPLL_POSTDIV_WIDTH ); + +return prate * mult / (ref_div *MSSPLL_FIXED_DIV * postdiv); +} + +static const struct clk_ops mpfs_clk_msspll_ops = { + .recalc_rate = mpfs_clk_msspll_recalc_rate, +}; + +#define CLK_PLL (_id, _name, _parent, _shift, _width, _flags, _offset) { \ + .id = _id, \ + .shift = _shift, \ + .width = _width, \ + .reg_offset = _offset, \ + .flags = _flags, \ + .hw.init = CLK_HW_INIT_PARENTS_DATA(_name, _parent, &mpfs_clk_msspll_ops, 0), \ +} + +static struct mpfs_msspll_hw_clock mpfs_msspll_clks[] = { +CLK_PLL (CLK_MSSPLL ,"clk_msspll" , mpfs_ext_ref,MSSPLL_FBDIV_SHIFT , +MSSPLL_FBDIV_WIDTH ,0 ,REG_MSSPLL_SSCG_2_CR ), +}; + +static int mpfs_clk_register_msspll (struct device *dev,struct mpfs_msspll_hw_clock *msspll_hw, +void __iomem *base) +{ + msspll_hw->base = base; + +return devm_clk_hw_register (dev, &msspll_hw->hw); +} + +static int mpfs_clk_register_mssplls (struct device *dev,struct mpfs_msspll_hw_clock *msspll_hws, +unsigned int num_clks,struct mpfs_clock_data *data) +{ +void __iomem *base = data->msspll_base; +unsigned int i; +int ret; + +for (i =0 ; i < num_clks; i++) { +struct mpfs_msspll_hw_clock *msspll_hw = &msspll_hws[i]; + + ret =mpfs_clk_register_msspll (dev, msspll_hw, base); +if (ret) +return dev_err_probe (dev, ret,"failed to register msspll id: %d\n" , +CLK_MSSPLL ); + + data->hw_data.hws[msspll_hw->id] = &msspll_hw->hw; + } + +return 0 ; +} + +/* +* "CFG" clocks +*/ +static unsigned long mpfs_cfg_clk_recalc_rate (struct clk_hw *hw,unsigned long prate) {struct mpfs_cfg_hw_clock *cfg_hw =to_mpfs_cfg_clk (hw);
@@ -75,10 +171,10 @@ static unsigned long mpfs_cfg_clk_recalc_rate(struct clk_hw *hw, unsigned long pvoid __iomem *base_addr = cfg_hw->sys_base;u32 val; - val =readl_relaxed (base_addr +REG_CLOCK_CONFIG_CR ) >> cfg->shift; + val =readl_relaxed (base_addr + cfg->reg_offset) >> cfg->shift; val &=clk_div_mask (cfg->width); -return prate / (1u << val); +return divider_recalc_rate (hw, prate, val, cfg->table, cfg->flags, cfg->width); }static long mpfs_cfg_clk_round_rate (struct clk_hw *hw,unsigned long rate,unsigned long *prate)
@@ -104,11 +200,10 @@ static int mpfs_cfg_clk_set_rate(struct clk_hw *hw, unsigned long rate, unsignedreturn divider_setting;spin_lock_irqsave (&mpfs_clk_lock, flags); - - val =readl_relaxed (base_addr +REG_CLOCK_CONFIG_CR ); + val =readl_relaxed (base_addr + cfg->reg_offset); val &= ~(clk_div_mask (cfg->width) << cfg_hw->cfg.shift); val |= divider_setting << cfg->shift; -writel_relaxed (val, base_addr +REG_CLOCK_CONFIG_CR ); +writel_relaxed (val, base_addr + cfg->reg_offset);spin_unlock_irqrestore (&mpfs_clk_lock, flags);
@@ -121,19 +216,23 @@ static const struct clk_ops mpfs_clk_cfg_ops = { .set_rate = mpfs_cfg_clk_set_rate, }; -#define CLK_CFG (_id, _name, _parent, _shift, _width, _table, _flags) { \ - .cfg.id = _id, \ - .cfg.shift = _shift, \ - .cfg.width = _width, \ - .cfg.table = _table, \ - .hw.init = CLK_HW_INIT_PARENTS_DATA(_name, _parent, &mpfs_clk_cfg_ops, \ - _flags), \ +#define CLK_CFG (_id, _name, _parent, _shift, _width, _table, _flags, _offset) { \ + .cfg.id = _id, \ + .cfg.shift = _shift, \ + .cfg.width = _width, \ + .cfg.table = _table, \ + .cfg.reg_offset = _offset, \ + .cfg.flags = _flags, \ + .hw.init = CLK_HW_INIT(_name, _parent, &mpfs_clk_cfg_ops, 0), \ }static struct mpfs_cfg_hw_clock mpfs_cfg_clks[] = { -CLK_CFG (CLK_CPU ,"clk_cpu" , mpfs_cfg_parent,0 ,2 , mpfs_div_cpu_axi_table,0 ), -CLK_CFG (CLK_AXI ,"clk_axi" , mpfs_cfg_parent,2 ,2 , mpfs_div_cpu_axi_table,0 ), -CLK_CFG (CLK_AHB ,"clk_ahb" , mpfs_cfg_parent,4 ,2 , mpfs_div_ahb_table,0 ), +CLK_CFG (CLK_CPU ,"clk_cpu" ,"clk_msspll" ,0 ,2 , mpfs_div_cpu_axi_table,0 , +REG_CLOCK_CONFIG_CR ), +CLK_CFG (CLK_AXI ,"clk_axi" ,"clk_msspll" ,2 ,2 , mpfs_div_cpu_axi_table,0 , +REG_CLOCK_CONFIG_CR ), +CLK_CFG (CLK_AHB ,"clk_ahb" ,"clk_msspll" ,4 ,2 , mpfs_div_ahb_table,0 , +REG_CLOCK_CONFIG_CR ), }; static int mpfs_clk_register_cfg(struct device *dev, struct mpfs_cfg_hw_clock *cfg_hw,
@@ -159,13 +258,17 @@ static int mpfs_clk_register_cfgs(struct device *dev, struct mpfs_cfg_hw_clock *return dev_err_probe (dev, ret,"failed to register clock id: %d\n" , cfg_hw->cfg.id); - id = cfg_hws[i].cfg.id; + id = cfg_hw->cfg.id; data->hw_data.hws[id] = &cfg_hw->hw; }return 0 ; } +/* +* peripheral clocks - devices connected to axi or ahb buses. +*/ +static int mpfs_periph_clk_enable (struct clk_hw *hw) {struct mpfs_periph_hw_clock *periph_hw =to_mpfs_periph_clk (hw);
@@ -312,8 +415,9 @@ static int mpfs_clk_probe(struct platform_device *pdev)unsigned int num_clks;int ret; -/* CLK_RESERVED is not part of cfg_clks nor periph_clks, so add 1 */ - num_clks =ARRAY_SIZE (mpfs_cfg_clks) +ARRAY_SIZE (mpfs_periph_clks) +1 ; +/* CLK_RESERVED is not part of clock arrays, so add 1 */ + num_clks =ARRAY_SIZE (mpfs_msspll_clks) +ARRAY_SIZE (mpfs_cfg_clks) + +ARRAY_SIZE (mpfs_periph_clks) +1 ; clk_data =devm_kzalloc (dev,struct_size (clk_data, hw_data.hws, num_clks),GFP_KERNEL );if (!clk_data)
@@ -323,8 +427,17 @@ static int mpfs_clk_probe(struct platform_device *pdev)if (IS_ERR (clk_data->base))return PTR_ERR (clk_data->base); + clk_data->msspll_base =devm_platform_ioremap_resource (pdev,1 ); +if (IS_ERR (clk_data->msspll_base)) +return PTR_ERR (clk_data->msspll_base); + clk_data->hw_data.num = num_clks; + ret =mpfs_clk_register_mssplls (dev, mpfs_msspll_clks,ARRAY_SIZE (mpfs_msspll_clks), + clk_data); +if (ret) +return ret; + ret =mpfs_clk_register_cfgs (dev, mpfs_cfg_clks,ARRAY_SIZE (mpfs_cfg_clks), clk_data);if (ret)return ret;
Signature · 1 line
2.35.1
Conor Dooley
maintainerPATCH 5/7 clk: microchip: mpfs: rename sys_base to base
In reply to Conor DooleyHaving added a second set of registers for the msspll, sys_base no longer really makes sense as a variable name. Renaming it to base will make it consistent with mpfs_clock_data & several function arguments.
--- drivers/clk/microchip/clk-mpfs.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/clk/microchip/clk-mpfs.c +15 -15
@@ -55,7 +55,7 @@ struct mpfs_cfg_clock {struct mpfs_cfg_hw_clock {struct mpfs_cfg_clock cfg; -void __iomem *sys_base; +void __iomem *base;struct clk_hw hw;struct clk_init_data init; };
@@ -69,7 +69,7 @@ struct mpfs_periph_clock {struct mpfs_periph_hw_clock {struct mpfs_periph_clock periph; -void __iomem *sys_base; +void __iomem *base;struct clk_hw hw; };
@@ -168,7 +168,7 @@ static unsigned long mpfs_cfg_clk_recalc_rate(struct clk_hw *hw, unsigned long p {struct mpfs_cfg_hw_clock *cfg_hw =to_mpfs_cfg_clk (hw);struct mpfs_cfg_clock *cfg = &cfg_hw->cfg; -void __iomem *base_addr = cfg_hw->sys_base; +void __iomem *base_addr = cfg_hw->base;u32 val; val =readl_relaxed (base_addr + cfg->reg_offset) >> cfg->shift;
@@ -189,7 +189,7 @@ static int mpfs_cfg_clk_set_rate(struct clk_hw *hw, unsigned long rate, unsigned {struct mpfs_cfg_hw_clock *cfg_hw =to_mpfs_cfg_clk (hw);struct mpfs_cfg_clock *cfg = &cfg_hw->cfg; -void __iomem *base_addr = cfg_hw->sys_base; +void __iomem *base_addr = cfg_hw->base;unsigned long flags;u32 val;int divider_setting;
@@ -236,9 +236,9 @@ static struct mpfs_cfg_hw_clock mpfs_cfg_clks[] = { };static int mpfs_clk_register_cfg (struct device *dev,struct mpfs_cfg_hw_clock *cfg_hw, -void __iomem *sys_base) +void __iomem *base) { - cfg_hw->sys_base = sys_base; + cfg_hw->base = base;return devm_clk_hw_register (dev, &cfg_hw->hw); }
@@ -246,14 +246,14 @@ static int mpfs_clk_register_cfg(struct device *dev, struct mpfs_cfg_hw_clock *cstatic int mpfs_clk_register_cfgs (struct device *dev,struct mpfs_cfg_hw_clock *cfg_hws,unsigned int num_clks,struct mpfs_clock_data *data) { -void __iomem *sys_base = data->base; +void __iomem *base = data->base;unsigned int i, id;int ret;for (i =0 ; i < num_clks; i++) {struct mpfs_cfg_hw_clock *cfg_hw = &cfg_hws[i]; - ret =mpfs_clk_register_cfg (dev, cfg_hw, sys_base); + ret =mpfs_clk_register_cfg (dev, cfg_hw, base);if (ret)return dev_err_probe (dev, ret,"failed to register clock id: %d\n" , cfg_hw->cfg.id);
@@ -273,7 +273,7 @@ static int mpfs_periph_clk_enable(struct clk_hw *hw) {struct mpfs_periph_hw_clock *periph_hw =to_mpfs_periph_clk (hw);struct mpfs_periph_clock *periph = &periph_hw->periph; -void __iomem *base_addr = periph_hw->sys_base; +void __iomem *base_addr = periph_hw->base;u32 reg, val;unsigned long flags;
@@ -292,7 +292,7 @@ static void mpfs_periph_clk_disable(struct clk_hw *hw) {struct mpfs_periph_hw_clock *periph_hw =to_mpfs_periph_clk (hw);struct mpfs_periph_clock *periph = &periph_hw->periph; -void __iomem *base_addr = periph_hw->sys_base; +void __iomem *base_addr = periph_hw->base;u32 reg, val;unsigned long flags;
@@ -309,7 +309,7 @@ static int mpfs_periph_clk_is_enabled(struct clk_hw *hw) {struct mpfs_periph_hw_clock *periph_hw =to_mpfs_periph_clk (hw);struct mpfs_periph_clock *periph = &periph_hw->periph; -void __iomem *base_addr = periph_hw->sys_base; +void __iomem *base_addr = periph_hw->base;u32 reg; reg =readl_relaxed (base_addr +REG_SUBBLK_CLOCK_CR );
@@ -379,9 +379,9 @@ static struct mpfs_periph_hw_clock mpfs_periph_clks[] = { };static int mpfs_clk_register_periph (struct device *dev,struct mpfs_periph_hw_clock *periph_hw, -void __iomem *sys_base) +void __iomem *base) { - periph_hw->sys_base = sys_base; + periph_hw->base = base;return devm_clk_hw_register (dev, &periph_hw->hw); }
@@ -389,14 +389,14 @@ static int mpfs_clk_register_periph(struct device *dev, struct mpfs_periph_hw_clstatic int mpfs_clk_register_periphs (struct device *dev,struct mpfs_periph_hw_clock *periph_hws,int num_clks,struct mpfs_clock_data *data) { -void __iomem *sys_base = data->base; +void __iomem *base = data->base;unsigned int i, id;int ret;for (i =0 ; i < num_clks; i++) {struct mpfs_periph_hw_clock *periph_hw = &periph_hws[i]; - ret =mpfs_clk_register_periph (dev, periph_hw, sys_base); + ret =mpfs_clk_register_periph (dev, periph_hw, base);if (ret)return dev_err_probe (dev, ret,"failed to register clock id: %d\n" , periph_hw->periph.id);
Signature · 1 line
2.35.1
Conor Dooley
maintainerPATCH 6/7 clk: microchip: mpfs: add RTCREF clock control
In reply to Conor DooleyThe reference clock used by the PolarFire SoC's onboard rtc was missing from the clock driver. Add this clock at the "config" clock level, with the external reference clock as its parent.
--- drivers/clk/microchip/clk-mpfs.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/clk/microchip/clk-mpfs.c +23 -1
@@ -15,6 +15,7 @@#define REG_MSSPLL_POSTDIV_CR 0x10u#define REG_MSSPLL_SSCG_2_CR 0x2Cu#define REG_CLOCK_CONFIG_CR 0x08u +#define REG_RTC_CLOCK_CR 0x0Cu#define REG_SUBBLK_CLOCK_CR 0x84u#define MSSPLL_FBDIV_SHIFT 0x00u
@@ -95,6 +96,17 @@ static const struct clk_div_table mpfs_div_ahb_table[] = { { 0, 0 } }; +/* +* The only two supported reference clock frequencies for the PolarFire SoC are +* 100 and 125 MHz, as the rtc reference is required to be 1 MHz. +* It therefore only needs to have divider table entries corresponding to +* divide by 100 and 125. +*/ +static const struct clk_div_table mpfs_div_rtcref_table[] = { + {100 ,100 }, {125 ,125 }, + {0 ,0 } +}; +static unsigned long mpfs_clk_msspll_recalc_rate (struct clk_hw *hw,unsigned long prate) {struct mpfs_msspll_hw_clock *msspll_hw =to_mpfs_msspll_clk (hw);
@@ -233,6 +245,16 @@ static struct mpfs_cfg_hw_clock mpfs_cfg_clks[] = { REG_CLOCK_CONFIG_CR), CLK_CFG(CLK_AHB, "clk_ahb", "clk_msspll", 4, 2, mpfs_div_ahb_table, 0, REG_CLOCK_CONFIG_CR), + { + .cfg.id = CLK_RTCREF, + .cfg.shift = 0, + .cfg.width = 12, + .cfg.table = mpfs_div_rtcref_table, + .cfg.reg_offset = REG_RTC_CLOCK_CR, + .cfg.flags = CLK_DIVIDER_ONE_BASED, + .hw.init = + CLK_HW_INIT_PARENTS_DATA("clk_rtcref", mpfs_ext_ref, &mpfs_clk_cfg_ops, 0), + } }; static int mpfs_clk_register_cfg(struct device *dev, struct mpfs_cfg_hw_clock *cfg_hw,
@@ -351,7 +373,7 @@ static struct mpfs_periph_hw_clock mpfs_periph_clks[] = {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_TIMER ,"clk_periph_timer" ,PARENT_CLK (RTCREF ),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),
Signature · 1 line
2.35.1
Conor Dooley
maintainerPATCH 7/7 riscv: dts: microchip: reparent mpfs clocks
In reply to Conor DooleyThe 600M clock in the fabric is not the real reference, replace it with a 125M clock which is the correct value for the icicle kit. Rename the msspllclk node to mssrefclk since this is now the input to, not the output of, the msspll clock. Control of the msspll clock has been moved into the clock configurator, so add the register range for it to the clk configurator. Finally, add a new output of the clock config block which will provide the 1M reference clock for the MTIMER and the rtc.
--- .../boot/dts/microchip/microchip-mpfs-icicle-kit.dts | 2 +- arch/riscv/boot/dts/microchip/microchip-mpfs.dtsi | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/boot/dts/microchip/microchip-mpfs-icicle-kit.dts +1 -1
@@ -45,7 +45,7 @@ ddrc_cache_hi: memory@1000000000 { }; &refclk { - clock-frequency = <600000000>; + clock-frequency = <125000000>; }; &mmuart1 {
arch/riscv/boot/dts/microchip/microchip-mpfs.dtsi +4 -4
@@ -141,7 +141,7 @@ cpu4_intc: interrupt-controller { }; }; - refclk: msspllclk { + refclk: mssrefclk { compatible = "fixed-clock"; #clock-cells = <0>; };
@@ -190,7 +190,7 @@ plic: interrupt-controller@c000000 { clkcfg: clkcfg@20002000 { compatible = "microchip,mpfs-clkcfg"; - reg = <0x0 0x20002000 0x0 0x1000>; + reg = <0x0 0x20002000 0x0 0x1000>, <0x0 0x3E001000 0x0 0x1000>; clocks = <&refclk>; #clock-cells = <1>; };
@@ -393,8 +393,8 @@ rtc: rtc@20124000 { reg = <0x0 0x20124000 0x0 0x1000>; interrupt-parent = <&plic>; interrupts = <80>, <81>; - clocks = <&clkcfg CLK_RTC>; - clock-names = "rtc"; + clocks = <&clkcfg CLK_RTC>, <&clkcfg CLK_RTCREF>; + clock-names = "rtc", "rtcref"; status = "disabled"; };
Signature · 1 line
2.35.1
Quoted 15 lines · Conor Dooley
Hey,
As I mentioned in my fixes for 5.18 [0], found out that the reference clock for the rtc is actually missing from the clock driver (and the dt binding).Currently the mpfs clock driver uses a reference clock called the "msspll", set in the device tree, as the parent for the cpu/axi/ahb (config) clocks. The frequency of the msspll is determined by the FPGA bitstream & the bootloader configures the clock to match the bitstream. The real reference is provided by a 100 or 125 MHz off chip oscillator.
However, the msspll clock is not actually the parent of all clocks on the system - the reference clock for the rtc/mtimer actually has the off chip oscillator as its parent.
Quoted 7 lines
This series enables reading the rate of the msspll clock, converts the refclock in the device tree to the external reference & adds the missing rtc reference clock.
I assume it is okay not to add fixes tags for the rtc dt binding? Since the clock was previously missing, the binding is wrong, but idk if that qualifies as a fix?
Usually ABI breakage, even if accepted, should be be tagged as fix because it is clearly then a break of other peoples' trees...
Best regards,
Krzysztof
Quoted 20 lines · Krzysztof Kozlowski
Quoted 19 lines · Conor Dooley
Hey,
As I mentioned in my fixes for 5.18 [0], found out that the reference clock for the rtc is actually missing from the clock driver (and the dt binding).Currently the mpfs clock driver uses a reference clock called the "msspll", set in the device tree, as the parent for the cpu/axi/ahb (config) clocks. The frequency of the msspll is determined by the FPGA bitstream & the bootloader configures the clock to match the bitstream. The real reference is provided by a 100 or 125 MHz off chip oscillator.
However, the msspll clock is not actually the parent of all clocks on the system - the reference clock for the rtc/mtimer actually has the off chip oscillator as its parent.
This series enables reading the rate of the msspll clock, converts the refclock in the device tree to the external reference & adds the missing rtc reference clock.
Quoted 7 lines
Quoted 3 lines
I assume it is okay not to add fixes tags for the rtc dt binding? Since the clock was previously missing, the binding is wrong, but idk if that qualifies as a fix?
Usually ABI breakage, even if accepted, should be be tagged as fix because it is clearly then a break of other peoples' trees...
That means either a) do something messy in the clock driver or b) mark the whole series as fixes (and roll it into [0]).
The second option seems far more sensible to me, do you agree?
Quoted 27 lines · Conor Dooley
Quoted 24 lines · Krzysztof Kozlowski
Quoted 22 lines · Conor Dooley
Hey,
As I mentioned in my fixes for 5.18 [0], found out that the reference clock for the rtc is actually missing from the clock driver (and the dt binding).Currently the mpfs clock driver uses a reference clock called the "msspll", set in the device tree, as the parent for the cpu/axi/ahb (config) clocks. The frequency of the msspll is determined by the FPGA bitstream & the bootloader configures the clock to match the bitstream. The real reference is provided by a 100 or 125 MHz off chip oscillator.
However, the msspll clock is not actually the parent of all clocks on the system - the reference clock for the rtc/mtimer actually has the off chip oscillator as its parent.
This series enables reading the rate of the msspll clock, converts the refclock in the device tree to the external reference & adds the missing rtc reference clock.
I assume it is okay not to add fixes tags for the rtc dt binding? Since the clock was previously missing, the binding is wrong, but idk if that qualifies as a fix?
Quoted 8 lines
Quoted 3 lines
Usually ABI breakage, even if accepted, should be be tagged as fix because it is clearly then a break of other peoples' trees...
That means either a) do something messy in the clock driver or b) mark the whole series as fixes (and roll it into [0]).
The second option seems far more sensible to me, do you agree?
Having thought some more about it, patches 2, 3 and the rtc part of 7 should be moved into [0] since they're fixing a binding that only arrived in 5.18-rc1.
For the rest, make the second part of the reg optional and if it doesnt exist just return prate for the msspll clock?
Thanks,
Conor.
Quoted 37 lines · Conor Dooley
Quoted 34 lines · Conor Dooley
Quoted 20 lines · Krzysztof Kozlowski
Quoted 19 lines · Conor Dooley
Hey,
As I mentioned in my fixes for 5.18 [0], found out that the reference clock for the rtc is actually missing from the clock driver (and the dt binding).Currently the mpfs clock driver uses a reference clock called the "msspll", set in the device tree, as the parent for the cpu/axi/ahb (config) clocks. The frequency of the msspll is determined by the FPGA bitstream & the bootloader configures the clock to match the bitstream. The real reference is provided by a 100 or 125 MHz off chip oscillator.
However, the msspll clock is not actually the parent of all clocks on the system - the reference clock for the rtc/mtimer actually has the off chip oscillator as its parent.
This series enables reading the rate of the msspll clock, converts the refclock in the device tree to the external reference & adds the missing rtc reference clock.
Quoted 7 lines
Quoted 3 lines
I assume it is okay not to add fixes tags for the rtc dt binding? Since the clock was previously missing, the binding is wrong, but idk if that qualifies as a fix?
Usually ABI breakage, even if accepted, should be be tagged as fix because it is clearly then a break of other peoples' trees...
That means either a) do something messy in the clock driver or b) mark the whole series as fixes (and roll it into [0]).
Quoted 7 lines
Quoted 1 line
The second option seems far more sensible to me, do you agree?
Having thought some more about it, patches 2, 3 and the rtc part of 7 should be moved into [0] since they're fixing a binding that only arrived in 5.18-rc1.
For the rest, make the second part of the reg optional and if it doesnt exist just return prate for the msspll clock?
Ah, so this got into v5.18-rc1? I think I missed that information from the patches description and focused on backporting to stables. Then indeed you could combine all fixes together, mark them with Fixes.
Best regards,
Krzysztof
Quoted 36 lines · Krzysztof Kozlowski
Quoted 35 lines · Conor Dooley
Quoted 33 lines · Conor Dooley
Quoted 20 lines · Krzysztof Kozlowski
Quoted 19 lines · Conor Dooley
Hey,
As I mentioned in my fixes for 5.18 [0], found out that the reference clock for the rtc is actually missing from the clock driver (and the dt binding).Currently the mpfs clock driver uses a reference clock called the "msspll", set in the device tree, as the parent for the cpu/axi/ahb (config) clocks. The frequency of the msspll is determined by the FPGA bitstream & the bootloader configures the clock to match the bitstream. The real reference is provided by a 100 or 125 MHz off chip oscillator.
However, the msspll clock is not actually the parent of all clocks on the system - the reference clock for the rtc/mtimer actually has the off chip oscillator as its parent.
This series enables reading the rate of the msspll clock, converts the refclock in the device tree to the external reference & adds the missing rtc reference clock.
Quoted 7 lines
Quoted 3 lines
I assume it is okay not to add fixes tags for the rtc dt binding? Since the clock was previously missing, the binding is wrong, but idk if that qualifies as a fix?
Usually ABI breakage, even if accepted, should be be tagged as fix because it is clearly then a break of other peoples' trees...
That means either a) do something messy in the clock driver or b) mark the whole series as fixes (and roll it into [0]).
The second option seems far more sensible to me, do you agree?
Quoted 7 lines
Quoted 5 lines
Having thought some more about it, patches 2, 3 and the rtc part of 7 should be moved into [0] since they're fixing a binding that only arrived in 5.18-rc1.
For the rest, make the second part of the reg optional and if it doesnt exist just return prate for the msspll clock?Ah, so this got into v5.18-rc1?
Yeah, so for context he clock driver & relevant the dt-bindings only arrived in 5.18-rc1. The device tree itself has been around (I think) 5.12 but it wasn't bootable until now. The rtc stanza is also new. The clock stanza & "wrong" refclk existed since the device tree was first added.
Quoted 2 lines
I think I missed that information from
the patches description and focused on backporting to stables.
Yeah, zero intention of backporting any of this. Pretty pointless since the board hasn't booted until now anyway.
Quoted 1 line
Then indeed you could combine all fixes together, mark them with Fixes.
I had split the series (plural) since the clock driver change is fairly big, adding a new "layer" of clocks & like 200 lines to a 400 line driver. I will respin then, with the dt binding patches marked as fixes and combined with the other series.
Do I have to maintain backwards compatibility with the device tree
from before the board actually booted mainline? If not, I'll merge
it all into one series, marked as fixes. Otherwise I'll keep the clock changes in this series out of the fixes, mark the second reg entry in the clock binding as optional & handle the old, "naive" dt stanza in the
driver.
Thanks!
Conor.
Quoted 4 lines · Conor Dooley
Do I have to maintain backwards compatibility with the device tree from before the board actually booted mainline? If not, I'll merge it all into one series, marked as fixes.
Usually not, although it is not actually my call. :)
Best regards,
Krzysztof
Quoted 27 lines · Conor Dooley
Quoted 24 lines · Krzysztof Kozlowski
Quoted 22 lines · Conor Dooley
Hey,
As I mentioned in my fixes for 5.18 [0], found out that the reference clock for the rtc is actually missing from the clock driver (and the dt binding).Currently the mpfs clock driver uses a reference clock called the "msspll", set in the device tree, as the parent for the cpu/axi/ahb (config) clocks. The frequency of the msspll is determined by the FPGA bitstream & the bootloader configures the clock to match the bitstream. The real reference is provided by a 100 or 125 MHz off chip oscillator.
However, the msspll clock is not actually the parent of all clocks on the system - the reference clock for the rtc/mtimer actually has the off chip oscillator as its parent.
This series enables reading the rate of the msspll clock, converts the refclock in the device tree to the external reference & adds the missing rtc reference clock.
I assume it is okay not to add fixes tags for the rtc dt binding? Since the clock was previously missing, the binding is wrong, but idk if that qualifies as a fix?
Quoted 8 lines
Quoted 3 lines
Usually ABI breakage, even if accepted, should be be tagged as fix because it is clearly then a break of other peoples' trees...
That means either a) do something messy in the clock driver or b) mark the whole series as fixes (and roll it into [0]).
The second option seems far more sensible to me, do you agree?
I think ate part of my sentence... it should be:
"Usually ABI breakage, even if accepted, should NOT be tagged as fix..."
So usually it should not be a fix.
The binding actually could be backported, because the driver changes bring the real ABI breakage.
Best regards,
Krzysztof