Add imx8ulp clock & reset driver support
Subsystems (5)
v2 cover Add imx8ulp clock & reset driver support
This patchset adds the clock & reset driver support for i.MX8ULP. For some of the PCC slot, As there is a SWRST control bit share the same pcc register for peripheral reset ccontrol. To simplify the case, register the pcc reset controller driver when pcc clock driver is registered.
Patch 1/9 for the dt-bindings part is send out for review previously with the dts patchset:
https://patchwork.kernel.org/project/linux-arm-kernel/cover/[email protected]/
Shawn suggests to send out the clock driver part firstly, so this patch is included in this patchset for now.
v2 changes:
- remove the useless clocks & clock-names from the dt-binding doc
- remove the redundant fixed clock register.
Anson Huang (1):
clk: imx: disable i.mx7ulp composite clock during initialization
Jacky Bai (8):
dt-bindings: clock: Add imx8ulp clock support
clk: imx: Update the pllv4 to support imx8ulp
clk: imx: Update the compsite driver to support imx8ulp
clk: imx: Add 'CLK_SET_RATE_NO_REPARENT' for composite-7ulp
clk: imx: disable the pfd when set pfdv2 clock rate
clk: imx: Update the pfdv2 for 8ulp specific support
clk: imx: Add clock driver for imx8ulp
clk: imx: Add the pcc reset controller support on imx8ulp
.../bindings/clock/imx8ulp-clock.yaml | 71 +++ drivers/clk/imx/Kconfig | 7 + drivers/clk/imx/Makefile | 2 + drivers/clk/imx/clk-composite-7ulp.c | 87 ++- drivers/clk/imx/clk-imx7ulp.c | 20 +- drivers/clk/imx/clk-imx8ulp.c | 568 ++++++++++++++++++ drivers/clk/imx/clk-pfdv2.c | 22 +- drivers/clk/imx/clk-pllv4.c | 34 +- drivers/clk/imx/clk.h | 24 +- include/dt-bindings/clock/imx8ulp-clock.h | 258 ++++++++ include/dt-bindings/reset/imx8ulp-pcc-reset.h | 59 ++ 11 files changed, 1120 insertions(+), 32 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/imx8ulp-clock.yaml create mode 100644 drivers/clk/imx/clk-imx8ulp.c create mode 100644 include/dt-bindings/clock/imx8ulp-clock.h create mode 100644 include/dt-bindings/reset/imx8ulp-pcc-reset.h
Signature · 1 line
2.26.2
PATCH v2 1/9 dt-bindings: clock: Add imx8ulp clock support
Add the clock dt-binding file for i.MX8ULP.
For pcc node, it will also be used as a reset controller, so add the '#reset-cells' property description and add the pcc reset IDs.
---
v2 changes:
- removed the redundant clocks & clock-names property
v1 changes:
- Move this patch from dts patchset into this patchset
--- .../bindings/clock/imx8ulp-clock.yaml | 71 +++++ include/dt-bindings/clock/imx8ulp-clock.h | 258 ++++++++++++++++++ include/dt-bindings/reset/imx8ulp-pcc-reset.h | 59 ++++ 3 files changed, 388 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/imx8ulp-clock.yaml create mode 100644 include/dt-bindings/clock/imx8ulp-clock.h create mode 100644 include/dt-bindings/reset/imx8ulp-pcc-reset.h
Documentation/devicetree/bindings/clock/imx8ulp-clock.yaml new file +71 -0
@@ -0,0 +1,71 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/imx8ulp-clock.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP i.MX8ULP Clock Control Module Binding + +maintainers: + - Jacky Bai <[email protected]> + +description: | + On i.MX8ULP, The clock sources generation, distribution and management is + under the control of several CGCs & PCCs modules. The CGC modules generate + and distribute clocks on the device. PCC modules control software reset, + clock selection, optional division and clock gating mode for peripherals. + +properties: + compatible: + enum: + - fsl,imx8ulp-cgc1 + - fsl,imx8ulp-cgc2 + - fsl,imx8ulp-pcc3 + - fsl,imx8ulp-pcc4 + - fsl,imx8ulp-pcc5 + + reg: + maxItems: 1 + + '#clock-cells': + const: 1 + + '#reset-cells': + const: 1 + +required: + - compatible + - reg + - '#clock-cells' + +allOf: + - if: + properties: + compatible: + contains: + enum: + - fsl,imx8ulp-pcc3 + - fsl,imx8ulp-pcc4 + - fsl,imx8ulp-pcc5 + then: + required: + - '#reset-cells' + +additionalProperties: false + +examples: + # Clock Control Module node: + - | + clock-controller@292c0000 { + compatible = "fsl,imx8ulp-cgc1"; + reg = <0x292c0000 0x10000>; + #clock-cells = <1>; + }; + + - | + clock-controller@292d0000 { + compatible = "fsl,imx8ulp-pcc3"; + reg = <0x292d0000 0x10000>; + #clock-cells = <1>; + #reset-cells = <1>; + };
include/dt-bindings/clock/imx8ulp-clock.h new file +258 -0
258 lines not on this page · raw message
include/dt-bindings/reset/imx8ulp-pcc-reset.h new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
2.26.2
Rob Herring
maintainerRe: [PATCH v2 1/9] dt-bindings: clock: Add imx8ulp clock support
Quoted 70 lines · Jacky Bai
Add the clock dt-binding file for i.MX8ULP.
For pcc node, it will also be used as a reset controller, so add the '#reset-cells' property description and add the pcc reset IDs.
Signed-off-by Jacky Bai <[email protected]>---
v2 changes:
- removed the redundant clocks & clock-names propertyv1 changes:
- Move this patch from dts patchset into this patchset--- .../bindings/clock/imx8ulp-clock.yaml | 71 +++++ include/dt-bindings/clock/imx8ulp-clock.h | 258 ++++++++++++++++++ include/dt-bindings/reset/imx8ulp-pcc-reset.h | 59 ++++ 3 files changed, 388 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/imx8ulp-clock.yaml create mode 100644 include/dt-bindings/clock/imx8ulp-clock.h create mode 100644 include/dt-bindings/reset/imx8ulp-pcc-reset.hDocumentation/devicetree/bindings/clock/imx8ulp-clock.yaml new file +42
-0@@ -0,0 +1,71 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/imx8ulp-clock.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP i.MX8ULP Clock Control Module Binding + +maintainers: + - Jacky Bai <[email protected]> + +description: | + On i.MX8ULP, The clock sources generation, distribution and management is + under the control of several CGCs & PCCs modules. The CGC modules generate + and distribute clocks on the device. PCC modules control software reset, + clock selection, optional division and clock gating mode for peripherals. + +properties: + compatible: + enum: + - fsl,imx8ulp-cgc1 + - fsl,imx8ulp-cgc2 + - fsl,imx8ulp-pcc3 + - fsl,imx8ulp-pcc4 + - fsl,imx8ulp-pcc5 + + reg: + maxItems: 1 + + '#clock-cells': + const: 1 + + '#reset-cells': + const: 1 + +required: + - compatible + - reg + - '#clock-cells' + +allOf: + - if:
Documentation/devicetree/bindings/clock/imx8ulp-clock.yaml line 52
Quoted 10 lines
Documentation/devicetree/bindings/clock/imx8ulp-clock.yaml new file +10
-0+ properties: + compatible: + contains: + enum: + - fsl,imx8ulp-pcc3 + - fsl,imx8ulp-pcc4 + - fsl,imx8ulp-pcc5 + then: + required: + - '#reset-cells'
And #reset-cells is optional for a CGC? I think this should be 2 schema files. There's nothing really shared any more than any other clock/reset controller.
Quoted 19 lines
Documentation/devicetree/bindings/clock/imx8ulp-clock.yaml new file +19
-0+ +additionalProperties: false + +examples: + # Clock Control Module node: + - | + clock-controller@292c0000 { + compatible = "fsl,imx8ulp-cgc1"; + reg = <0x292c0000 0x10000>; + #clock-cells = <1>; + }; + + - | + clock-controller@292d0000 { + compatible = "fsl,imx8ulp-pcc3"; + reg = <0x292d0000 0x10000>; + #clock-cells = <1>; + #reset-cells = <1>; + };
RE: [PATCH v2 1/9] dt-bindings: clock: Add imx8ulp clock support
Quoted 35 lines
Subject: Re: [PATCH v2 1/9] dt-bindings: clock: Add imx8ulp clock support
Quoted 32 lines · Jacky Bai
Add the clock dt-binding file for i.MX8ULP.
For pcc node, it will also be used as a reset controller, so add the '#reset-cells' property description and add the pcc reset IDs.
Signed-off-by Jacky Bai <[email protected]>---
v2 changes:
- removed the redundant clocks & clock-names propertyv1 changes:
- Move this patch from dts patchset into this patchset--- .../bindings/clock/imx8ulp-clock.yaml | 71 +++++ include/dt-bindings/clock/imx8ulp-clock.h | 258 ++++++++++++++++++ include/dt-bindings/reset/imx8ulp-pcc-reset.h | 59 ++++ 3 files changed, 388 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/imx8ulp-clock.yaml create mode 100644 include/dt-bindings/clock/imx8ulp-clock.h create mode 100644 include/dt-bindings/reset/imx8ulp-pcc-reset.hdiff --git
a/Documentation/devicetree/bindings/clock/imx8ulp-clock.yamlb/Documentation/devicetree/bindings/clock/imx8ulp-clock.yamlnew file mode 100644
index 000000000000..9a075de1086aDocumentation/devicetree/bindings/clock/imx8ulp-clock.yaml new file +2
-0@@ -0,0 +1,71 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) %YAML 1.2 +---
...
Quoted 19 lines
Quoted 19 lines
Documentation/devicetree/bindings/clock/imx8ulp-clock.yaml new file +19
-0+ + '#clock-cells': + const: 1 + + '#reset-cells': + const: 1 + +required: + - compatible + - reg + - '#clock-cells' + +allOf: + - if: + properties: + compatible: + contains: + enum: + - fsl,imx8ulp-pcc3
Quoted 9 lines
Documentation/devicetree/bindings/clock/imx8ulp-clock.yaml line 52
Quoted 5 lines
Documentation/devicetree/bindings/clock/imx8ulp-clock.yaml new file +5
-0+ - fsl,imx8ulp-pcc4 + - fsl,imx8ulp-pcc5 + then: + required: + - '#reset-cells'And #reset-cells is optional for a CGC? I think this should be 2 schema files. There's nothing really shared any more than any other clock/reset controller.
The CGC is a root clock generator, has no reset function, only the PCC HW modules have reset control for peripherals. Do you suggest to spit into two schema files, one for CGCs, and another one for PCCs?
Thanks.
BR
Quoted 19 lines
Quoted 19 lines
Documentation/devicetree/bindings/clock/imx8ulp-clock.yaml new file +19
-0+ +additionalProperties: false + +examples: + # Clock Control Module node: + - | + clock-controller@292c0000 { + compatible = "fsl,imx8ulp-cgc1"; + reg = <0x292c0000 0x10000>; + #clock-cells = <1>; + }; + + - | + clock-controller@292d0000 { + compatible = "fsl,imx8ulp-pcc3"; + reg = <0x292d0000 0x10000>; + #clock-cells = <1>; + #reset-cells = <1>; + };
PATCH v2 2/9 clk: imx: Update the pllv4 to support imx8ulp
In reply to Jacky BaiThe PLLs used on i.MX8ULP is mostly the same as on i.MX7ULP, except the PLL register offset is changed. Change the PLLv4 driver for code reuse on i.MX7ULP and i.MX8ULP.
---
v2 changes: no
--- drivers/clk/imx/clk-imx7ulp.c | 4 ++-- drivers/clk/imx/clk-pllv4.c | 34 +++++++++++++++++++++++++--------- drivers/clk/imx/clk.h | 9 +++++++-- 3 files changed, 34 insertions(+), 13 deletions(-)
drivers/clk/imx/clk-imx7ulp.c +2 -2
@@ -78,8 +78,8 @@ static void __init imx7ulp_clk_scg1_init(struct device_node *np) hws[IMX7ULP_CLK_SPLL_PRE_DIV ] =imx_clk_hw_divider_flags ("spll_pre_div" ,"spll_pre_sel" , base +0x608 ,8 ,3 ,CLK_SET_RATE_GATE );/* name parent_name base */ - hws[IMX7ULP_CLK_APLL ] =imx_clk_hw_pllv4 ("apll" ,"apll_pre_div" , base +0x500 ); - hws[IMX7ULP_CLK_SPLL ] =imx_clk_hw_pllv4 ("spll" ,"spll_pre_div" , base +0x600 ); + hws[IMX7ULP_CLK_APLL ] =imx_clk_hw_pllv4 (IMX_PLLV4_IMX7ULP ,"apll" ,"apll_pre_div" , base +0x500 ); + hws[IMX7ULP_CLK_SPLL ] =imx_clk_hw_pllv4 (IMX_PLLV4_IMX7ULP ,"spll" ,"spll_pre_div" , base +0x600 );/* APLL PFDs */ hws[IMX7ULP_CLK_APLL_PFD0 ] =imx_clk_hw_pfdv2 ("apll_pfd0" ,"apll" , base +0x50c ,0 );
drivers/clk/imx/clk-pllv4.c +25 -9
@@ -23,14 +23,17 @@/* PLL Configuration Register (xPLLCFG) */ #define PLL_CFG_OFFSET 0x08 +#define IMX8ULP_PLL_CFG_OFFSET 0x10#define BP_PLL_MULT 16#define BM_PLL_MULT (0x7f << 16)/* PLL Numerator Register (xPLLNUM) */ #define PLL_NUM_OFFSET 0x10 +#define IMX8ULP_PLL_NUM_OFFSET 0x1c/* PLL Denominator Register (xPLLDENOM) */ #define PLL_DENOM_OFFSET 0x14 +#define IMX8ULP_PLL_DENOM_OFFSET 0x18#define MAX_MFD 0x3fffffff#define DEFAULT_MFD 1000000
@@ -38,6 +41,9 @@struct clk_pllv4 {struct clk_hw hw;void __iomem *base; +u32 cfg_offset; +u32 num_offset; +u32 denom_offset; };/* Valid PLL MULT Table */
@@ -72,12 +78,12 @@ static unsigned long clk_pllv4_recalc_rate(struct clk_hw *hw,u32 mult, mfn, mfd;u64 temp64; - mult =readl_relaxed (pll->base +PLL_CFG_OFFSET ); + mult =readl_relaxed (pll->base + pll->cfg_offset); mult &=BM_PLL_MULT ; mult >>=BP_PLL_MULT ; - mfn =readl_relaxed (pll->base +PLL_NUM_OFFSET ); - mfd =readl_relaxed (pll->base +PLL_DENOM_OFFSET ); + mfn =readl_relaxed (pll->base + pll->num_offset); + mfd =readl_relaxed (pll->base + pll->denom_offset); temp64 = parent_rate; temp64 *= mfn;do_div (temp64, mfd);
@@ -165,13 +171,13 @@ static int clk_pllv4_set_rate(struct clk_hw *hw, unsigned long rate,do_div (temp64, parent_rate); mfn = temp64; - val =readl_relaxed (pll->base +PLL_CFG_OFFSET ); + val =readl_relaxed (pll->base + pll->cfg_offset); val &= ~BM_PLL_MULT ; val |= mult <<BP_PLL_MULT ; -writel_relaxed (val, pll->base +PLL_CFG_OFFSET ); +writel_relaxed (val, pll->base + pll->cfg_offset); -writel_relaxed (mfn, pll->base +PLL_NUM_OFFSET ); -writel_relaxed (mfd, pll->base +PLL_DENOM_OFFSET ); +writel_relaxed (mfn, pll->base + pll->num_offset); +writel_relaxed (mfd, pll->base + pll->denom_offset);return 0 ; }
@@ -207,8 +213,8 @@ static const struct clk_ops clk_pllv4_ops = { .is_prepared = clk_pllv4_is_prepared, }; -struct clk_hw *imx_clk_hw_pllv4 (const char *name,const char *parent_name, -void __iomem *base) +struct clk_hw *imx_clk_hw_pllv4 (enum imx_pllv4_type type,const char *name, +const char *parent_name,void __iomem *base) {struct clk_pllv4 *pll;struct clk_hw *hw;
@@ -221,6 +227,16 @@ struct clk_hw *imx_clk_hw_pllv4(const char *name, const char *parent_name, pll->base = base; +if (type ==IMX_PLLV4_IMX8ULP ) { + pll->cfg_offset =IMX8ULP_PLL_CFG_OFFSET ; + pll->num_offset =IMX8ULP_PLL_NUM_OFFSET ; + pll->denom_offset =IMX8ULP_PLL_DENOM_OFFSET ; + }else { + pll->cfg_offset =PLL_CFG_OFFSET ; + pll->num_offset =PLL_NUM_OFFSET ; + pll->denom_offset =PLL_DENOM_OFFSET ; + } + init.name = name; init.ops = &clk_pllv4_ops; init.parent_names = &parent_name;
drivers/clk/imx/clk.h +7 -2
@@ -42,6 +42,11 @@ enum imx_pll14xx_type { PLL_1443X, }; +enum imx_pllv4_type { +IMX_PLLV4_IMX7ULP , +IMX_PLLV4_IMX8ULP , +}; +/* NOTE: Rate table should be kept sorted in descending order. */ struct imx_pll14xx_rate_table {unsigned int rate;
@@ -191,8 +196,8 @@ struct clk_hw *imx_clk_hw_pllv3(enum imx_pllv3_type type, const char *name, .kdiv = (_k), \ } -struct clk_hw *imx_clk_hw_pllv4 (const char *name,const char *parent_name, -void __iomem *base); +struct clk_hw *imx_clk_hw_pllv4 (enum imx_pllv4_type type,const char *name, +const char *parent_name,void __iomem *base); struct clk_hw *clk_hw_register_gate2(struct device *dev, const char *name, const char *parent_name, unsigned long flags,
Signature · 1 line
2.26.2
PATCH v2 3/9 clk: imx: Update the compsite driver to support imx8ulp
In reply to Jacky BaiOn i.MX8ULP, some peripherals have a sw_rst control resides in the per device PCC clock control register, all others are same as i.MX7ULP, so update the 7ulp clock composite driver to support i.MX8ULP to maxmimize the code reuse.
---
v2 changs: no
--- drivers/clk/imx/clk-composite-7ulp.c | 61 ++++++++++++++++++++++++++-- drivers/clk/imx/clk.h | 6 +++ 2 files changed, 64 insertions(+), 3 deletions(-)
drivers/clk/imx/clk-composite-7ulp.c +58 -3
@@ -22,11 +22,50 @@#define PCG_PCD_WIDTH 3#define PCG_PCD_MASK 0x7 -struct clk_hw *imx7ulp_clk_hw_composite (const char *name, +#define SW_RST BIT(28) + +static int pcc_gate_enable (struct clk_hw *hw) +{ +struct clk_gate *gate =to_clk_gate (hw); +u32 val; +int ret; + + ret = clk_gate_ops.enable (hw); +if (ret) +return ret; + +/* +* release the sw reset for peripherals associated with +* with this pcc clock. +*/ + val =readl (gate->reg); + val |=SW_RST ; +writel (val, gate->reg); + +return 0 ; +} + +static void pcc_gate_disable (struct clk_hw *hw) +{ + clk_gate_ops.disable (hw); +} + +static int pcc_gate_is_enabled (struct clk_hw *hw) +{ +return clk_gate_ops.is_enabled (hw); +} + +static const struct clk_ops pcc_gate_ops = { + .enable = pcc_gate_enable, + .disable = pcc_gate_disable, + .is_enabled = pcc_gate_is_enabled, +}; + +static struct clk_hw *imx_ulp_clk_hw_composite (const char *name,const char *const *parent_names,int num_parents,bool mux_present,bool rate_present,bool gate_present, -void __iomem *reg) +void __iomem *reg,bool has_swrst) {struct clk_hw *mux_hw =NULL , *fd_hw =NULL , *gate_hw =NULL ;struct clk_fractional_divider *fd =NULL ;
@@ -76,7 +115,7 @@ struct clk_hw *imx7ulp_clk_hw_composite(const char *name, hw =clk_hw_register_composite (NULL , name, parent_names, num_parents, mux_hw, &clk_mux_ops, fd_hw, &clk_fractional_divider_ops, gate_hw, - &clk_gate_ops,CLK_SET_RATE_GATE | + has_swrst ? &pcc_gate_ops : &clk_gate_ops,CLK_SET_RATE_GATE |CLK_SET_PARENT_GATE );if (IS_ERR (hw)) {kfree (mux);
@@ -86,3 +125,19 @@ struct clk_hw *imx7ulp_clk_hw_composite(const char *name,return hw; } + +struct clk_hw *imx7ulp_clk_hw_composite (const char *name,const char *const *parent_names, +int num_parents,bool mux_present,bool rate_present, +bool gate_present,void __iomem *reg) +{ +return imx_ulp_clk_hw_composite (name, parent_names, num_parents, mux_present, rate_present, + gate_present, reg, false); +} + +struct clk_hw *imx8ulp_clk_hw_composite (const char *name,const char *const *parent_names, +int num_parents,bool mux_present,bool rate_present, +bool gate_present,void __iomem *reg,bool has_swrst) +{ +return imx_ulp_clk_hw_composite (name, parent_names, num_parents, mux_present, rate_present, + gate_present, reg, has_swrst); +}
drivers/clk/imx/clk.h +6 -0
@@ -237,6 +237,12 @@ struct clk_hw *imx7ulp_clk_hw_composite(const char *name, bool rate_present, bool gate_present, void __iomem *reg); +struct clk_hw *imx8ulp_clk_hw_composite (const char *name, +const char *const *parent_names, +int num_parents,bool mux_present, +bool rate_present,bool gate_present, +void __iomem *reg,bool has_swrst); +struct clk_hw *imx_clk_hw_fixup_divider (const char *name,const char *parent,void __iomem *reg,u8 shift,u8 width,void (*fixup)(u32 *val));
Signature · 1 line
2.26.2
PATCH v2 4/9 clk: imx: disable i.mx7ulp composite clock during initialization
In reply to Jacky BaiFrom: Anson Huang <[email protected]>
i.MX7ULP peripheral clock ONLY allow parent/rate to be changed with clock gated, however, during clock tree initialization, the peripheral clock could be enabled by bootloader, but the prepare count in clock tree is still zero, so clock core driver will allow parent/rate changed even with CLK_SET_RATE_GATE/CLK_SET_PARENT_GATE set, but the change will fail due to HW NOT allow parent/rate change with clock enabled. It will cause clock HW status mismatch with clock tree info and lead to function issue. Below is an example:
usdhc0's pcc clock value is 0xC5000000 during kernel boot up, it means usdhc0 clock is enabled, its parent is APLL_PFD1. In DT file, the usdhc0 clock settings are as below:
assigned-clocks = <&pcc2 IMX7ULP_CLK_USDHC0>; assigned-clock-parents = <&scg1 IMX7ULP_CLK_NIC1_DIV>;
when kernel boot up, the clock tree info is as below, but the usdhc0 PCC register is still 0xC5000000, which means its parent is still from APLL_PFD1, which is incorrect and cause usdhc0 NOT work.
nic1_clk 2 2 0 176000000 0 0 50000
usdhc0 0 0 0 176000000 0 0 50000
After making sure the peripheral clock is disabled during clock tree initialization, the usdhc0 is working, and this change is necessary for all i.MX7ULP peripheral clocks.
---
v2 changes: no
--- drivers/clk/imx/clk-composite-7ulp.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/clk/imx/clk-composite-7ulp.c +14 -0
@@ -8,6 +8,7 @@#include <linux/bits.h> #include <linux/clk-provider.h> #include <linux/err.h> +#include <linux/io.h> #include <linux/slab.h> #include "clk.h"
@@ -72,6 +73,7 @@ static struct clk_hw *imx_ulp_clk_hw_composite(const char *name,struct clk_gate *gate =NULL ;struct clk_mux *mux =NULL ;struct clk_hw *hw; +u32 val;if (mux_present) { mux =kzalloc (sizeof (*mux),GFP_KERNEL );
@@ -110,6 +112,18 @@ static struct clk_hw *imx_ulp_clk_hw_composite(const char *name, gate_hw = &gate->hw; gate->reg = reg; gate->bit_idx =PCG_CGC_SHIFT ; +/* +* make sure clock is gated during clock tree initialization, +* the HW ONLY allow clock parent/rate changed with clock gated, +* during clock tree initialization, clocks could be enabled +* by bootloader, so the HW status will mismatch with clock tree +* prepare count, then clock core driver will allow parent/rate +* change since the prepare count is zero, but HW actually +* prevent the parent/rate change due to the clock is enabled. +*/ + val =readl_relaxed (reg); + val &= ~(1 <<PCG_CGC_SHIFT ); +writel_relaxed (val, reg); } hw = clk_hw_register_composite(NULL, name, parent_names, num_parents,
Signature · 1 line
2.26.2
PATCH v2 5/9 clk: imx: Add 'CLK_SET_RATE_NO_REPARENT' for composite-7ulp
In reply to Jacky BaiFor the imx_composite-7ulp clock type, The clock parent should be changed explicitly by end user of this clock, if the the 'CLK_SET_RATE_NO_REPARENT' flag is not set, when user want to set a clock frequency that can NOT get from HW accurately, then the clock's parent will be switch to another clock parent sometimes. This is NOT what we expected and introduced some additional debug effort, so add the 'CLK_SET_RATE_NO_REPARENT' to avoid such unexpected result.
---
v2 changs: no
--- drivers/clk/imx/clk-composite-7ulp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/imx/clk-composite-7ulp.c +1 -1
@@ -130,7 +130,7 @@ static struct clk_hw *imx_ulp_clk_hw_composite(const char *name, mux_hw, &clk_mux_ops, fd_hw, &clk_fractional_divider_ops, gate_hw, has_swrst ? &pcc_gate_ops : &clk_gate_ops,CLK_SET_RATE_GATE | - CLK_SET_PARENT_GATE); + CLK_SET_PARENT_GATE | CLK_SET_RATE_NO_REPARENT);if (IS_ERR (hw)) {kfree (mux);kfree (fd);
Signature · 1 line
2.26.2
PATCH v2 6/9 clk: imx: disable the pfd when set pfdv2 clock rate
In reply to Jacky BaiIt is possible that a PFD is enabled in HW but not in SW. That means the enable count & prepare count of the PFD clock is '0', so the 'CLK_SET_RATE' flag can do nothing when the rate is changed while the PFD is hw enabled. In order to safely change the pfd rate, we can disable the PFD directly if it is hw enabled but not used by SW end user.
---
v2 changs: no
--- drivers/clk/imx/clk-pfdv2.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/clk/imx/clk-pfdv2.c +11 -2
@@ -161,8 +161,17 @@ static int clk_pfdv2_set_rate(struct clk_hw *hw, unsigned long rate,if (!rate)return -EINVAL ; -/* PFD can NOT change rate without gating */ -WARN_ON (clk_pfdv2_is_enabled (hw)); +/* +* PFD can NOT change rate without gating. +* as the PFDs may enabled in HW by default but no +* consumer used it, the enable count is '0', so the +* 'SET_RATE_GATE' can NOT help on blocking the set_rate +* ops especially for 'assigned-clock-xxx'. In order +* to simplify the case, just disable the PFD if it is +* enabled in HW but not in SW. +*/ +if (clk_pfdv2_is_enabled (hw)) +clk_pfdv2_disable (hw); tmp = tmp *18 + rate /2 ;do_div (tmp, rate);
Signature · 1 line
2.26.2
PATCH v2 7/9 clk: imx: Update the pfdv2 for 8ulp specific support
In reply to Jacky BaiOn i.MX8ULP, the 'CLK_SET_RATE_PARENT' flag should NOT be set and according to the laest RM, the PFD divider value range seems will be changed in the future, so update the pfdv2 to include the specific support for i.MX8ULP.
---
v2 changs: no
--- drivers/clk/imx/clk-imx7ulp.c | 16 ++++++++-------- drivers/clk/imx/clk-pfdv2.c | 9 ++++++--- drivers/clk/imx/clk.h | 9 +++++++-- 3 files changed, 21 insertions(+), 13 deletions(-)
drivers/clk/imx/clk-imx7ulp.c +8 -8
@@ -82,16 +82,16 @@ static void __init imx7ulp_clk_scg1_init(struct device_node *np) hws[IMX7ULP_CLK_SPLL ] =imx_clk_hw_pllv4 (IMX_PLLV4_IMX7ULP ,"spll" ,"spll_pre_div" , base +0x600 );/* APLL PFDs */ - hws[IMX7ULP_CLK_APLL_PFD0 ] =imx_clk_hw_pfdv2 ("apll_pfd0" ,"apll" , base +0x50c ,0 ); - hws[IMX7ULP_CLK_APLL_PFD1 ] =imx_clk_hw_pfdv2 ("apll_pfd1" ,"apll" , base +0x50c ,1 ); - hws[IMX7ULP_CLK_APLL_PFD2 ] =imx_clk_hw_pfdv2 ("apll_pfd2" ,"apll" , base +0x50c ,2 ); - hws[IMX7ULP_CLK_APLL_PFD3 ] =imx_clk_hw_pfdv2 ("apll_pfd3" ,"apll" , base +0x50c ,3 ); + hws[IMX7ULP_CLK_APLL_PFD0 ] =imx_clk_hw_pfdv2 (IMX_PFDV2_IMX7ULP ,"apll_pfd0" ,"apll" , base +0x50c ,0 ); + hws[IMX7ULP_CLK_APLL_PFD1 ] =imx_clk_hw_pfdv2 (IMX_PFDV2_IMX7ULP ,"apll_pfd1" ,"apll" , base +0x50c ,1 ); + hws[IMX7ULP_CLK_APLL_PFD2 ] =imx_clk_hw_pfdv2 (IMX_PFDV2_IMX7ULP ,"apll_pfd2" ,"apll" , base +0x50c ,2 ); + hws[IMX7ULP_CLK_APLL_PFD3 ] =imx_clk_hw_pfdv2 (IMX_PFDV2_IMX7ULP ,"apll_pfd3" ,"apll" , base +0x50c ,3 );/* SPLL PFDs */ - hws[IMX7ULP_CLK_SPLL_PFD0 ] =imx_clk_hw_pfdv2 ("spll_pfd0" ,"spll" , base +0x60C ,0 ); - hws[IMX7ULP_CLK_SPLL_PFD1 ] =imx_clk_hw_pfdv2 ("spll_pfd1" ,"spll" , base +0x60C ,1 ); - hws[IMX7ULP_CLK_SPLL_PFD2 ] =imx_clk_hw_pfdv2 ("spll_pfd2" ,"spll" , base +0x60C ,2 ); - hws[IMX7ULP_CLK_SPLL_PFD3 ] =imx_clk_hw_pfdv2 ("spll_pfd3" ,"spll" , base +0x60C ,3 ); + hws[IMX7ULP_CLK_SPLL_PFD0 ] =imx_clk_hw_pfdv2 (IMX_PFDV2_IMX7ULP ,"spll_pfd0" ,"spll" , base +0x60C ,0 ); + hws[IMX7ULP_CLK_SPLL_PFD1 ] =imx_clk_hw_pfdv2 (IMX_PFDV2_IMX7ULP ,"spll_pfd1" ,"spll" , base +0x60C ,1 ); + hws[IMX7ULP_CLK_SPLL_PFD2 ] =imx_clk_hw_pfdv2 (IMX_PFDV2_IMX7ULP ,"spll_pfd2" ,"spll" , base +0x60C ,2 ); + hws[IMX7ULP_CLK_SPLL_PFD3 ] =imx_clk_hw_pfdv2 (IMX_PFDV2_IMX7ULP ,"spll_pfd3" ,"spll" , base +0x60C ,3 );/* PLL Mux */ hws[IMX7ULP_CLK_APLL_PFD_SEL ] =imx_clk_hw_mux_flags ("apll_pfd_sel" , base +0x508 ,14 ,2 , apll_pfd_sels,ARRAY_SIZE (apll_pfd_sels),CLK_SET_RATE_PARENT |CLK_SET_PARENT_GATE );
drivers/clk/imx/clk-pfdv2.c +6 -3
@@ -200,8 +200,8 @@ static const struct clk_ops clk_pfdv2_ops = { .is_enabled = clk_pfdv2_is_enabled, }; -struct clk_hw *imx_clk_hw_pfdv2 (const char *name,const char *parent_name, -void __iomem *reg,u8 idx) +struct clk_hw *imx_clk_hw_pfdv2 (enum imx_pfdv2_type type,const char *name, +const char *parent_name,void __iomem *reg,u8 idx) {struct clk_init_data init;struct clk_pfdv2 *pfd;
@@ -223,7 +223,10 @@ struct clk_hw *imx_clk_hw_pfdv2(const char *name, const char *parent_name, init.ops = &clk_pfdv2_ops; init.parent_names = &parent_name; init.num_parents =1 ; - init.flags =CLK_SET_RATE_GATE |CLK_SET_RATE_PARENT ; +if (type ==IMX_PFDV2_IMX7ULP ) + init.flags =CLK_SET_RATE_GATE |CLK_SET_RATE_PARENT ; +else + init.flags =CLK_SET_RATE_GATE ; pfd->hw.init = &init;
drivers/clk/imx/clk.h +7 -2
@@ -47,6 +47,11 @@ enum imx_pllv4_type { IMX_PLLV4_IMX8ULP, }; +enum imx_pfdv2_type { +IMX_PFDV2_IMX7ULP , +IMX_PFDV2_IMX8ULP , +}; +/* NOTE: Rate table should be kept sorted in descending order. */ struct imx_pll14xx_rate_table {unsigned int rate;
@@ -220,8 +225,8 @@ struct clk_hw *imx_clk_hw_gate_exclusive(const char *name, const char *parent,struct clk_hw *imx_clk_hw_pfd (const char *name,const char *parent_name,void __iomem *reg,u8 idx); -struct clk_hw *imx_clk_hw_pfdv2 (const char *name,const char *parent_name, -void __iomem *reg,u8 idx); +struct clk_hw *imx_clk_hw_pfdv2 (enum imx_pfdv2_type type,const char *name, +const char *parent_name,void __iomem *reg,u8 idx); struct clk_hw *imx_clk_hw_busy_divider(const char *name, const char *parent_name, void __iomem *reg, u8 shift, u8 width,
Signature · 1 line
2.26.2
PATCH v2 8/9 clk: imx: Add clock driver for imx8ulp
In reply to Jacky BaiAdd clock driver for i.MX8ULP.
---
v2 changes:
- remove the redundent fixed sosc, fosc etc clock register
--- drivers/clk/imx/Kconfig | 6 + drivers/clk/imx/Makefile | 2 + drivers/clk/imx/clk-imx8ulp.c | 459 ++++++++++++++++++++++++++++++++++ 3 files changed, 467 insertions(+) create mode 100644 drivers/clk/imx/clk-imx8ulp.c
drivers/clk/imx/Kconfig +6 -0
@@ -98,3 +98,9 @@ config CLK_IMX8QXP select MXC_CLK_SCU help Build the driver for IMX8QXP SCU based clocks. + +config CLK_IMX8ULP + tristate "IMX8ULP CCM Clock Driver" + depends on ARCH_MXC || COMPILE_TEST + help + Build the driver for i.MX8ULP CCM Clock Driver
drivers/clk/imx/Makefile +2 -0
@@ -31,6 +31,8 @@ clk-imx-scu-$(CONFIG_CLK_IMX8QXP) += clk-scu.o clk-imx8qxp.o \ clk-imx8qxp-rsrc.o clk-imx8qm-rsrc.o clk-imx-lpcg-scu-$(CONFIG_CLK_IMX8QXP) += clk-lpcg-scu.o clk-imx8qxp-lpcg.o +obj-$(CONFIG_CLK_IMX8ULP) += clk-imx8ulp.o + obj-$(CONFIG_CLK_IMX1) += clk-imx1.o obj-$(CONFIG_CLK_IMX25) += clk-imx25.o obj-$(CONFIG_CLK_IMX27) += clk-imx27.o
drivers/clk/imx/clk-imx8ulp.c new file +459 -0
459 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 9/9 clk: imx: Add the pcc reset controller support on imx8ulp
In reply to Jacky BaiOn i.MX8ULP, for some of the PCCs, it has a peripheral SW RST bit resides in the same registers as the clock controller. So add this SW RST controller support alongs with the pcc clock initialization.
the reset and clock shared the same register, to avoid accessing the same register by reset control and clock control concurrently, locking is necessary, so reuse the imx_ccm_lock spinlock to simplify the code.
---
v2 changes:
- add 'Suggested-by' as suggested by Victor Liu
--- drivers/clk/imx/Kconfig | 1 + drivers/clk/imx/clk-composite-7ulp.c | 10 +++ drivers/clk/imx/clk-imx8ulp.c | 115 ++++++++++++++++++++++++++- 3 files changed, 123 insertions(+), 3 deletions(-)
drivers/clk/imx/Kconfig +1 -0
@@ -102,5 +102,6 @@ config CLK_IMX8QXP config CLK_IMX8ULP tristate "IMX8ULP CCM Clock Driver" depends on ARCH_MXC || COMPILE_TEST + select RESET_CONTROLLER help Build the driver for i.MX8ULP CCM Clock Driver
drivers/clk/imx/clk-composite-7ulp.c +10 -0
@@ -28,6 +28,7 @@static int pcc_gate_enable (struct clk_hw *hw) {struct clk_gate *gate =to_clk_gate (hw); +unsigned long flags;u32 val;int ret;
@@ -35,6 +36,7 @@ static int pcc_gate_enable(struct clk_hw *hw)if (ret)return ret; +spin_lock_irqsave (gate->lock, flags);/* * release the sw reset for peripherals associated with * with this pcc clock.
@@ -43,6 +45,8 @@ static int pcc_gate_enable(struct clk_hw *hw) val |=SW_RST ;writel (val, gate->reg); +spin_unlock_irqrestore (gate->lock, flags); +return 0 ; }
@@ -83,6 +87,8 @@ static struct clk_hw *imx_ulp_clk_hw_composite(const char *name, mux->reg = reg; mux->shift =PCG_PCS_SHIFT ; mux->mask =PCG_PCS_MASK ; +if (has_swrst) + mux->lock = &imx_ccm_lock; }if (rate_present) {
@@ -100,6 +106,8 @@ static struct clk_hw *imx_ulp_clk_hw_composite(const char *name, fd->nwidth =PCG_PCD_WIDTH ; fd->nmask =PCG_PCD_MASK ; fd->flags =CLK_FRAC_DIVIDER_ZERO_BASED ; +if (has_swrst) + fd->lock = &imx_ccm_lock; }if (gate_present) {
@@ -112,6 +120,8 @@ static struct clk_hw *imx_ulp_clk_hw_composite(const char *name, gate_hw = &gate->hw; gate->reg = reg; gate->bit_idx =PCG_CGC_SHIFT ; +if (has_swrst) + gate->lock = &imx_ccm_lock;/* * make sure clock is gated during clock tree initialization, * the HW ONLY allow clock parent/rate changed with clock gated,
drivers/clk/imx/clk-imx8ulp.c +112 -3
160 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v2 9/9] clk: imx: Add the pcc reset controller support on imx8ulp
Hi Jacky,
Quoted 25 lines · Jacky Bai
On i.MX8ULP, for some of the PCCs, it has a peripheral SW RST bit resides in the same registers as the clock controller. So add this SW RST controller support alongs with the pcc clock initialization.
the reset and clock shared the same register, to avoid accessing the same register by reset control and clock control concurrently, locking is necessary, so reuse the
imx_ccm_lockspinlock to simplify the code.Suggested-by Liu Ying <[email protected]>Signed-off-by Jacky Bai <[email protected]>---
v2 changes:
- add 'Suggested-by' as suggested by Victor Liu--- drivers/clk/imx/Kconfig | 1 + drivers/clk/imx/clk-composite-7ulp.c | 10 +++ drivers/clk/imx/clk-imx8ulp.c | 115 ++++++++++++++++++++++++++- 3 files changed, 123 insertions(+), 3 deletions(-)drivers/clk/imx/Kconfig +0
-0
drivers/clk/imx/Kconfig config CLK_IMX8QXP · line 105
Quoted 4 lines
drivers/clk/imx/Kconfig +1
-0@@ -102,5 +102,6 @@ config CLK_IMX8QXP config CLK_IMX8ULP tristate "IMX8ULP CCM Clock Driver" depends on ARCH_MXC || COMPILE_TEST + select RESET_CONTROLLER
This shouldn't be required anymore, devm_reset_controller_register() has a stub since commit 48a74b1147f7 ("reset: Add compile-test stubs").
[...]
Quoted 13 lines
drivers/clk/imx/clk-imx8ulp.c +1
-0@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/of_device.h> #include <linux/platform_device.h> +#include <linux/reset-controller.h> #include <linux/slab.h> #include "clk.h"
drivers/clk/imx/clk-imx8ulp.c static const char * const nic_per_divplat[] = { "nic_per_divplat" }; · line 56
Quoted 8 lines
drivers/clk/imx/clk-imx8ulp.c +5
-0@@ -48,6 +49,98 @@ static const char * const nic_per_divplat[] = { "nic_per_divplat" };static const char *const lpav_axi_div[] = {"lpav_axi_div" };static const char *const lpav_bus_div[] = {"lpav_bus_div" }; +struct pcc_reset_dev { +void __iomem *base; +struct reset_controller_dev rcdev; +const u32 *resets; +spinlock_t *lock;
I'd add a comment to this lock, stating that it is set to imx_ccm_lock and protects access to registers shared with clock control.
With these addressed,
regards
Philipp
RE: [PATCH v2 9/9] clk: imx: Add the pcc reset controller support on imx8ulp
Quoted 26 lines
Subject: Re: [PATCH v2 9/9] clk: imx: Add the pcc reset controller support on imx8ulp
Hi Jacky,
Quoted 10 lines · Jacky Bai
On i.MX8ULP, for some of the PCCs, it has a peripheral SW RST bit resides in the same registers as the clock controller. So add this SW RST controller support alongs with the pcc clock initialization.
the reset and clock shared the same register, to avoid accessing the same register by reset control and clock control concurrently, locking is necessary, so reuse the
imx_ccm_lockspinlock to simplify the code.Suggested-by Liu Ying <[email protected]>Signed-off-by Jacky Bai <[email protected]>Quoted 7 lines
---
v2 changes:
- add 'Suggested-by' as suggested by Victor Liu--- drivers/clk/imx/Kconfig | 1 + drivers/clk/imx/clk-composite-7ulp.c | 10 +++ drivers/clk/imx/clk-imx8ulp.c | 115++++++++++++++++++++++++++-
Quoted 2 lines
3 files changed, 123 insertions(+), 3 deletions(-)
Quoted 12 lines
drivers/clk/imx/Kconfig config CLK_IMX8QXP config CLK_IMX8ULP · line 104
Quoted 8 lines
drivers/clk/imx/Kconfig index renamed from drivers/clk/imx/Kconfig +0
-0
b81d6437ed95..0d1e3a6ac32a100644drivers/clk/imx/Kconfig +1
-0@@ -102,5 +102,6 @@ config CLK_IMX8QXP config CLK_IMX8ULP tristate "IMX8ULP CCM Clock Driver" depends on ARCH_MXC || COMPILE_TEST + select RESET_CONTROLLERThis shouldn't be required anymore,
devm_reset_controller_register()has a stub since commit48a74b1147f7("reset: Add compile-test stubs").
So we don't need to select 'RESET_CONTROLLER' explicitly, right?
Quoted 19 lines
[...]
Quoted 18 lines
(quoted diff) +0
-0
b/drivers/clk/imx/clk-imx8ulp.cindex6aad04114658..ea596cd6855a100644drivers/clk/imx/clk-imx8ulp.c +1
-0@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/of_device.h> #include <linux/platform_device.h> +#include <linux/reset-controller.h> #include <linux/slab.h> #include "clk.h" @@ -48,6 +49,98 @@ static const char * const nic_per_divplat[] = { "nic_per_divplat" }; static const char * const lpav_axi_div[] = {"lpav_axi_div" };static const char *const lpav_bus_div[] = {"lpav_bus_div" };
Quoted 9 lines
drivers/clk/imx/clk-imx8ulp.c static const char * const nic_per_divplat[] = { "nic_per_divplat" }; · line 56
Quoted 5 lines
drivers/clk/imx/clk-imx8ulp.c +5
-0+struct pcc_reset_dev { +void __iomem *base; +struct reset_controller_dev rcdev; +const u32 *resets; +spinlock_t *lock;I'd add a comment to this lock, stating that it is set to
imx_ccm_lockand protects access to registers shared with clock control.
Ok, will add some comments, thx.
BR
Jacky Bai
Quoted 6 lines
With these addressed,
Reviewed-by Philipp Zabel <[email protected]>regards
Philipp
Philipp Zabel
maintainerRe: [PATCH v2 9/9] clk: imx: Add the pcc reset controller support on imx8ulp
On Mon, 2021-08-23 at 23:58 +0000, Jacky Bai wrote:
[...]
Quoted 12 lines
Quoted 11 lines
drivers/clk/imx/Kconfig config CLK_IMX8QXP config CLK_IMX8ULP · line 104
Quoted 8 lines
drivers/clk/imx/Kconfig index renamed from drivers/clk/imx/Kconfig +0
-0
b81d6437ed95..0d1e3a6ac32a100644drivers/clk/imx/Kconfig +1
-0@@ -102,5 +102,6 @@ config CLK_IMX8QXP config CLK_IMX8ULP tristate "IMX8ULP CCM Clock Driver" depends on ARCH_MXC || COMPILE_TEST + select RESET_CONTROLLERThis shouldn't be required anymore,
devm_reset_controller_register()has a stub since commit48a74b1147f7("reset: Add compile-test stubs").
Quoted 1 line
So we don't need to select '
RESET_CONTROLLER' explicitly, right?
Right.
regards
Philipp