Convert imx6 clock to device tree
Subsystems (6)
cover Convert imx6 clock to device tree
As I promised to Arnd, I will convert imx6 clock code to common clock framework and in turn device tree at the earliest time. Here it is.
It's based on Mike's common-clk pre-v3 and Grant's clock device tree binding series.
Along with the conversion to device tree, I feel it's a great idea to introduce '#clock-cells'. With adopting it, I'm using 70 nodes to describe 110 clocks (~35% nodes reduced). However, the current design of '#clock-cells' makes the user a little difficult. For example, when a consumer node references to provider node which is a blob of 4 clocks, it has to fill 4 parameters into the phandle.
usdhc at 02198000 { /* uSDHC3 */
compatible = "fsl,imx6q-usdhc";
reg = <0x02198000 0x4000>;
interrupts = <0 24 0x04>;
clock-input = <&usdhc_clk 2 0 0 0>; <--
clock-input-name = "usdhc3";
};But we actually need to pass only one parameter to point out the index of the clock in the blob. It's a little silly to put a number of meaningless 0 there to fill the length of the phandle parameters. Can we rework the dt core code to make the following one work?
usdhc@02198000 { /* uSDHC3 */
compatible = "fsl,imx6q-usdhc";
reg = <0x02198000 0x4000>;
interrupts = <0 24 0x04>;
clock-input = <&usdhc_clk 2>; <--
clock-input-name = "usdhc3";
};Regards,
Shawn
Shawn Guo (3):
arm/imx6: describe clocks in device tree source arm/imx: add a generic clock implementation for imx arm/imx6: convert clock to device tree
.../devicetree/bindings/clock/clock-imx.txt | 124 ++ arch/arm/boot/dts/imx6q.dtsi | 943 +++++++++- arch/arm/mach-imx/Kconfig | 5 + arch/arm/mach-imx/Makefile | 1 + arch/arm/mach-imx/clock-imx6q.c | 2135 ++++---------------- arch/arm/mach-imx/clock.c | 222 ++ arch/arm/mach-imx/clock.h | 64 + 7 files changed, 1734 insertions(+), 1760 deletions(-)
RFC PATCH 1/3 arm/imx6: describe clocks in device tree source
It adds document for imx clock device tree bindings and then describes imx6 clocks in dts.
--- .../devicetree/bindings/clock/clock-imx.txt | 124 +++ arch/arm/boot/dts/imx6q.dtsi | 943 +++++++++++++++++++- 2 files changed, 1058 insertions(+), 9 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/clock-imx.txt
Documentation/devicetree/bindings/clock/clock-imx.txt new file +124 -0
@@ -0,0 +1,124 @@ +* Device Tree Bindings for Freescale i.MX Clock + +== Clock Gate == + +Required properties: +- imx,clock-gate: It's a two 32-bit integers array. The first + integer specifies the offset of the gate register, and the second + one specifies the bit mask of the gate for this clock. + +== Clock Divider == + +Required properties: +- imx,clock-divider: It's a five 32-bit integers array. The first + integer specifies the offset of the divider register. The second + and the third one specify the shift and width of the pre-divider + bits for the clock, which is not necessarily present and the values + can just be 0. The last two specify the shift and width of the + post-divider bits. + +Optional properties: +- imx,busy-divider: Some imx clocks needs to wait for a busy status + cleared when the clock rate gets changed. This property is a two + 32-bit integers array. The first integer specifies the offset of + the busy register, and the second one specifies the busy bit mask. + +== Clock Multiplexer == + +Required properties: +- imx,clock-multiplexer: It's a three 32-bit integers array. The + first integer specifies the offset of the multiplexer register. + The second and the third one specify the shift and width of the + multiplexer bits for this clock. + +Optional properties: +- imx,busy-multiplexer: Some imx clocks needs to wait for a busy + status cleared when the parent gets changed. This property is a two + 32-bit integers array. The first integer specifies the offset of + the busy register, and the second one specifies the busy bit mask. + +A typical imx clock could have gate, divider, multiplexer, but it's +also very true that a imx clock just has the subset of these three +properties. + +When #clock-cells > 1, this single clock node actually describes +multiple clocks. Thus all the properties under the node should +contains the description for all of the clocks, except properties +clock-input and clock-input-name which are used to describe the +parents of the clock. That means only the clocks sharing the exactly +same parents could possible described by single node. + +Examples: + +pll2_pfd_clk: pll2-pfd { + compatible = "fsl,imx6q-pfd"; + #clock-cells = <3>; + imx,clock-gate = <0x100 0x80>, + <0x100 0x8000>, + <0x100 0x800000>; + imx,clock-divider = <0x100 0 0 0 6>, + <0x100 0 0 8 6>, + <0x100 0 0 16 6>; + clock-input = <&pll_bus_clk 0>; + clock-input-name = "pll2-bus"; + clock-output-name = "pll2-pfd-352m", + "pll2-pfd-594m", + "pll2-pfd-400m"; +}; + +usdhc_clk: usdhc { + compatible = "fsl,imx6q-clock"; + #clock-cells = <4>; + imx,clock-gate = <0x80 0xc>, + <0x80 0x30>, + <0x80 0xc0>, + <0x80 0x300>; + imx,clock-divider = <0x24 0 0 11 3>, + <0x24 0 0 16 3>, + <0x24 0 0 19 3>, + <0x24 0 0 22 3>; + imx,clock-multiplexer = <0x1c 16 1>, + <0x1c 17 1>, + <0x1c 18 1>, + <0x1c 19 1>; + clock-input = <&pll2_pfd_clk 2 0 0>, + <&pll2_pfd_clk 0 0 0>; + clock-input-name = "pll2-pfd-400m", + "pll2-pfd-352m"; + clock-output-name = "usdhc1", + "usdhc2", + "usdhc3", + "usdhc3"; +}; + +usdhc at 02190000 { /* uSDHC1 */ + compatible = "fsl,imx6q-usdhc"; + reg = <0x02190000 0x4000>; + interrupts = <0 22 0x04>; + clock-input = <&usdhc_clk 0 0 0 0>; + clock-input-name = "usdhc1"; +}; + +usdhc at 02194000 { /* uSDHC2 */ + compatible = "fsl,imx6q-usdhc"; + reg = <0x02194000 0x4000>; + interrupts = <0 23 0x04>; + clock-input = <&usdhc_clk 1 0 0 0>; + clock-input-name = "usdhc2"; +}; + +usdhc at 02198000 { /* uSDHC3 */ + compatible = "fsl,imx6q-usdhc"; + reg = <0x02198000 0x4000>; + interrupts = <0 24 0x04>; + clock-input = <&usdhc_clk 2 0 0 0>; + clock-input-name = "usdhc3"; +}; + +usdhc at 0219c000 { /* uSDHC4 */ + compatible = "fsl,imx6q-usdhc"; + reg = <0x0219c000 0x4000>; + interrupts = <0 25 0x04>; + clock-input = <&usdhc_clk 3 0 0 0>; + clock-input-name = "usdhc4"; +};
arch/arm/boot/dts/imx6q.dtsi +934 -9
1,019 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Sascha Hauer
maintainerRFC PATCH 1/3 arm/imx6: describe clocks in device tree source
Quoted 16 lines · Shawn Guo
It adds document for imx clock device tree bindings and then describes imx6 clocks in dts.
Signed-off-by Shawn Guo <[email protected]>--- .../devicetree/bindings/clock/clock-imx.txt | 124 +++ arch/arm/boot/dts/imx6q.dtsi | 943 +++++++++++++++++++- 2 files changed, 1058 insertions(+), 9 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/clock-imx.txtDocumentation/devicetree/bindings/clock/clock-imx.txt new file +0
-0
Documentation/devicetree/bindings/clock/clock-imx.txt line 8
Quoted 8 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +8
-0@@ -0,0 +1,124 @@ +* Device Tree Bindings for Freescale i.MX Clock + +== Clock Gate == + +Required properties: +- imx,clock-gate: It's a two 32-bit integers array. The first + integer specifies the offset of the gate register, and the second + one specifies the bit mask of the gate for this clock.
On i.MX53 we have two bit gates:
00b disable
01b disable in stop mode, enable in run mode
10b reserved
11b enable
I can't find this description in my i.MX6RM, but I suppose it's the same here. Do you have plans for these? Currently only disable and enable seem to be handled.
Quoted 6 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +6
-0+ + pll2_pfd_clk: pll2-pfd { + compatible = "fsl,imx6q-pfd"; + #clock-cells = <3>; + imx,clock-gate = <0x100 0x80>, + <0x100 0x8000>,
Documentation/devicetree/bindings/clock/clock-imx.txt line 67
Quoted 10 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +10
-0+ <0x100 0x800000>; + imx,clock-divider = <0x100 0 0 0 6>, + <0x100 0 0 8 6>, + <0x100 0 0 16 6>; + clock-input = <&pll_bus_clk 0>; + clock-input-name = "pll2-bus"; + clock-output-name = "pll2-pfd-352m", + "pll2-pfd-594m", + "pll2-pfd-400m"; + };
Does this pll simultaneously have three different output frequencies? I'm not familiar with the i.MX6 yet.
Quoted 23 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +23
-0+ + can_root_clk: can-root { + compatible = "fsl,imx6q-clock"; + #clock-cells = <1>; + imx,clock-divider = <0x20 0 0 2 6>; + clock-input = <&pll_usb_clk 0 0>; + clock-input-name = "pll3-usb-otg"; + clock-output-name = "can-root"; + }; + + can_clk: can { + compatible = "fsl,imx6q-clock"; + #clock-cells = <4>; + imx,clock-gate = <0x68 0xc000>, + <0x68 0x30000>, + <0x68 0xc0000>, + <0x68 0x300000>; + clock-input = <&can_root_clk 0>; + clock-input-name = "can-root"; + clock-output-name = "can1", + "can1-serial", + "can2", + "can2-serial";
Documentation/devicetree/bindings/clock/clock-imx.txt line 57
Quoted 10 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +10
-0+ }; + + ecspi_root_clk: ecspi-root { + compatible = "fsl,imx6q-clock"; + #clock-cells = <1>; + imx,clock-divider = <0x38 0 0 19 6>; + clock-input = <&pll3_div_clk 2 0 0>; + clock-input-name = "pll3-60m"; + clock-output-name = "ecspi-root"; + };
I'm not sure you do yourself a favour if you skip all the muxes and assume reset default for them. The ecspi-root parent is a mux The mux seems to be missing in the can clock, uart and probably others.
Quoted 18 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +18
-0+ + ecspi_clk: ecspi { + compatible = "fsl,imx6q-clock"; + #clock-cells = <5>; + imx,clock-gate = <0x6c 0x3>, + <0x6c 0xc>, + <0x6c 0x30>, + <0x6c 0xc0>, + <0x6c 0x300>; + clock-input = <&ecspi_root_clk 0>; + clock-input-name = "ecspi-root"; + clock-output-name = "ecspi1", + "ecspi2", + "ecspi3", + "ecspi4", + "ecspi5"; + }; +
[...]
Documentation/devicetree/bindings/clock/clock-imx.txt
Quoted 13 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +13
-0+ + uart_clk: uart { + compatible = "fsl,imx6q-clock"; + #clock-cells = <2>; + imx,clock-gate = <0x7c 0x3000000>, + <0x7c 0xc000000>; + imx,clock-divider = <0x24 0 0 0 6>, + <0x24 0 0 0 6>; + clock-input = <&pll3_div_clk 1 0 0>; + clock-input-name = "pll3-80m"; + clock-output-name = "uart", + "uart-serial"; + };
This seems wrong. The UARTs have two clocks, the register clock and the baud clock. parent of the baud clock is uart-root (the mux is missing here) and parent of the register clock is the ipg clock. This node only has one parent.
Quoted 10 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +10
-0+ + usboh3_clk: usboh3 { + compatible = "fsl,imx6q-clock"; + #clock-cells = <1>; + imx,clock-gate = <0x80 0x3>; + clock-input = <&ipg_clk 0>; + clock-input-name = "ipg"; + clock-output-name = "usboh3"; + }; +
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
RFC PATCH 1/3 arm/imx6: describe clocks in device tree source
Quoted 28 lines · Sascha Hauer
Quoted 16 lines · Shawn Guo
It adds document for imx clock device tree bindings and then describes imx6 clocks in dts.
Signed-off-by Shawn Guo <[email protected]>--- .../devicetree/bindings/clock/clock-imx.txt | 124 +++ arch/arm/boot/dts/imx6q.dtsi | 943 +++++++++++++++++++- 2 files changed, 1058 insertions(+), 9 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/clock-imx.txtDocumentation/devicetree/bindings/clock/clock-imx.txt new file +0
-0Documentation/devicetree/bindings/clock/clock-imx.txt line 8
Quoted 8 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +8
-0@@ -0,0 +1,124 @@ +* Device Tree Bindings for Freescale i.MX Clock + +== Clock Gate == + +Required properties: +- imx,clock-gate: It's a two 32-bit integers array. The first + integer specifies the offset of the gate register, and the second + one specifies the bit mask of the gate for this clock.On i.MX53 we have two bit gates:
Quoted 9 lines
00b disable
01b disable in stop mode, enable in run mode
10b reserved
11b enableI can't find this description in my i.MX6RM, but I suppose it's the same here. Do you have plans for these? Currently only disable and enable seem to be handled.
Yes, imx6 is same as imx5 on this. It's something missing from clock driver rather than binding. The binding only describes the shift and mask of the gate bits, and the encoding of the bits is left to clock driver. And I plan to add support for cases 01b and 10b when the need occurs.
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +11
-0+ + pll2_pfd_clk: pll2-pfd { + compatible = "fsl,imx6q-pfd"; + #clock-cells = <3>; + imx,clock-gate = <0x100 0x80>, + <0x100 0x8000>, + <0x100 0x800000>; + imx,clock-divider = <0x100 0 0 0 6>, + <0x100 0 0 8 6>, + <0x100 0 0 16 6>; + clock-input = <&pll_bus_clk 0>;
Quoted 9 lines
Documentation/devicetree/bindings/clock/clock-imx.txt line 67
Quoted 5 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +5
-0+ clock-input-name = "pll2-bus"; + clock-output-name = "pll2-pfd-352m", + "pll2-pfd-594m", + "pll2-pfd-400m"; + };Does this pll simultaneously have three different output frequencies? I'm not familiar with the i.MX6 yet.
This is not a PLL. Instead, they are 3 PFDs having the PLL2 as the parent clock.
Quoted 29 lines
Quoted 29 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +29
-0+ + can_root_clk: can-root { + compatible = "fsl,imx6q-clock"; + #clock-cells = <1>; + imx,clock-divider = <0x20 0 0 2 6>; + clock-input = <&pll_usb_clk 0 0>; + clock-input-name = "pll3-usb-otg"; + clock-output-name = "can-root"; + }; + + can_clk: can { + compatible = "fsl,imx6q-clock"; + #clock-cells = <4>; + imx,clock-gate = <0x68 0xc000>, + <0x68 0x30000>, + <0x68 0xc0000>, + <0x68 0x300000>; + clock-input = <&can_root_clk 0>; + clock-input-name = "can-root"; + clock-output-name = "can1", + "can1-serial", + "can2", + "can2-serial"; + }; + + ecspi_root_clk: ecspi-root { + compatible = "fsl,imx6q-clock"; + #clock-cells = <1>; + imx,clock-divider = <0x38 0 0 19 6>;
Quoted 9 lines
Documentation/devicetree/bindings/clock/clock-imx.txt line 57
Quoted 4 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +4
-0+ clock-input = <&pll3_div_clk 2 0 0>; + clock-input-name = "pll3-60m"; + clock-output-name = "ecspi-root"; + };I'm not sure you do yourself a favour if you skip all the muxes and assume reset default for them. The ecspi-root parent is a mux The mux seems to be missing in the can clock, uart and probably others.
I'm looking at IMX6DQRM.pdf 'Rev. B, 07/2011'. I do not see mux for ECSPI_CLK_ROOT as well as other clocks you mentioned. Instead, I can only see divider for these clocks. Can you point out the registers and bits of these muxes you are seeing with these clocks?
Quoted 31 lines
Quoted 18 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +18
-0+ + ecspi_clk: ecspi { + compatible = "fsl,imx6q-clock"; + #clock-cells = <5>; + imx,clock-gate = <0x6c 0x3>, + <0x6c 0xc>, + <0x6c 0x30>, + <0x6c 0xc0>, + <0x6c 0x300>; + clock-input = <&ecspi_root_clk 0>; + clock-input-name = "ecspi-root"; + clock-output-name = "ecspi1", + "ecspi2", + "ecspi3", + "ecspi4", + "ecspi5"; + }; +[...]
Quoted 10 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +10
-0+ + uart_clk: uart { + compatible = "fsl,imx6q-clock"; + #clock-cells = <2>; + imx,clock-gate = <0x7c 0x3000000>, + <0x7c 0xc000000>; + imx,clock-divider = <0x24 0 0 0 6>, + <0x24 0 0 0 6>; + clock-input = <&pll3_div_clk 1 0 0>; + clock-input-name = "pll3-80m";
Quoted 9 lines
Documentation/devicetree/bindings/clock/clock-imx.txt
Quoted 3 lines
Documentation/devicetree/bindings/clock/clock-imx.txt new file +3
-0+ clock-output-name = "uart", + "uart-serial"; + };This seems wrong. The UARTs have two clocks, the register clock and the baud clock. parent of the baud clock is uart-root (the mux is missing here) and parent of the register clock is the ipg clock. This node only has one parent.
Yes, this is wrong. Thanks for catching. But still I do not see mux for uart-root but only divider.
Regards,
Shawn
Sascha Hauer
maintainerRFC PATCH 1/3 arm/imx6: describe clocks in device tree source
Quoted 19 lines · Shawn Guo
Quoted 4 lines · Sascha Hauer
Quoted 3 lines · Shawn Guo
It adds document for imx clock device tree bindings and then describes imx6 clocks in dts.
Quoted 14 lines
arch/arm/boot/dts/imx6q.dtsi line 431
Quoted 9 lines
arch/arm/boot/dts/imx6q.dtsi +9
-0+ + ecspi_root_clk: ecspi-root { + compatible = "fsl,imx6q-clock"; + #clock-cells = <1>; + imx,clock-divider = <0x38 0 0 19 6>; + clock-input = <&pll3_div_clk 2 0 0>; + clock-input-name = "pll3-60m"; + clock-output-name = "ecspi-root"; + };I'm not sure you do yourself a favour if you skip all the muxes and assume reset default for them. The ecspi-root parent is a mux The mux seems to be missing in the can clock, uart and probably others.
Quoted 4 lines
I'm looking at IMX6DQRM.pdf 'Rev. B, 07/2011'. I do not see mux for
ECSPI_CLK_ROOTas well as other clocks you mentioned. Instead, I can only see divider for these clocks. Can you point out the registers and bits of these muxes you are seeing with these clocks?
No, I can't find them either ;) I must have looked into the wrong manual at that moment. Sorry for the noise.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
RFC PATCH 2/3 arm/imx: add a generic clock implementation for imx
In reply to Shawn GuoIt adds a generic clock implementation which applies on several modern imx generations.
--- arch/arm/mach-imx/clock.c | 222 +++++++++++++++++++++++++++++++++++++++++++++ arch/arm/mach-imx/clock.h | 64 +++++++++++++ 2 files changed, 286 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-imx/clock.c create mode 100644 arch/arm/mach-imx/clock.h
arch/arm/mach-imx/clock.c new file +222 -0
@@ -0,0 +1,222 @@ +/* +* Copyright 2011 Freescale Semiconductor, Inc. +* Copyright 2011 Linaro Ltd. +* +* The code contained herein is licensed under the GNU General Public +* License. You may obtain a copy of the GNU General Public License +* Version 2 or later at the following locations: +* +* http://www.opensource.org/licenses/gpl-license.html +* http://www.gnu.org/copyleft/gpl.html +*/ + +#include <linux/init.h> +#include <linux/types.h> +#include <linux/err.h> +#include <linux/clk.h> +#include <linux/io.h> +#include <asm/processor.h> +#include "clock.h" + +int clk_imx_enable (struct clk_hw *hw) +{ +struct clk_imx_gate *g =to_clk_imx (hw)->gate; +u32 val; + +if (!g) +return 0 ; + + val =readl_relaxed (g->reg); +if (g->gate_set_bit) + val &= ~g->mask; +else + val |= g->mask; +writel_relaxed (val, g->reg); + +return 0 ; +} + +void clk_imx_disable (struct clk_hw *hw) +{ +struct clk_imx_gate *g =to_clk_imx (hw)->gate; +u32 val; + +if (!g) +return ; + + val =readl_relaxed (g->reg); +if (g->gate_set_bit) + val |= g->mask; +else + val &= ~g->mask; +writel_relaxed (val, g->reg); +} + +struct clk *clk_imx_get_parent (struct clk_hw *hw) +{ +struct clk_imx_mux *m =to_clk_imx (hw)->mux; +u32 i; + +if (!m) +return to_clk_imx (hw)->parent->clk; + + i =readl_relaxed (m->reg) >> m->shift; + i &= (1 << m->width) -1 ; + +if (i >= m->num_parents) +return ERR_PTR (-EINVAL ); + +return m->parents[i]->clk; +} + +static int clk_imx_busy_wait (struct clk_imx_busy *b) +{ +int timeout =0x100000 ; + +while ((readl_relaxed (b->reg) & b->mask) && --timeout) +cpu_relax (); + +if (unlikely (!timeout)) +return -EBUSY ; + +return 0 ; +} + +static int clk_imx_set_parent (struct clk_hw *hw,struct clk *parent) +{ +struct clk_imx_mux *m =to_clk_imx (hw)->mux; +int i; +u32 val; + +if (!m) +return -EINVAL ; + +for (i =0 ; i < m->num_parents; i++) +if (parent == m->parents[i]->clk) +break ; + +if (i == m->num_parents) +return -EINVAL ; + + val =readl_relaxed (m->reg); + val &= ~(((1 << m->width) -1 ) << m->shift); + val |= i << m->shift; +writel_relaxed (val, m->reg); + +return (m->busy) ?clk_imx_busy_wait (m->busy) :0 ; +} + +static unsigned long clk_imx_recalc_rate (struct clk_hw *hw) +{ +struct clk_imx_div *d =to_clk_imx (hw)->div; +u32 val, pred, podf; + +if (!d) +return clk_get_rate (clk_get_parent (hw->clk)); + + val =readl_relaxed (d->reg); + pred = (val >> d->shift_pred & ((1 << d->width_pred) -1 )) +1 ; + podf = (val >> d->shift_podf & ((1 << d->width_podf) -1 )) +1 ; + +return clk_get_rate (clk_get_parent (hw->clk)) / (pred * podf); +} + +static void calc_pred_podf_dividers (u32 div,u32 *pred,u32 *podf) +{ +u32 min_pred, temp_pred, old_err, err; + +if (div >=512 ) { + *pred =8 ; + *podf =64 ; + }else if (div >=8 ) { + min_pred = (div -1 ) /64 +1 ; + old_err =8 ; +for (temp_pred =8 ; temp_pred >= min_pred; temp_pred--) { + err = div % temp_pred; +if (err ==0 ) { + *pred = temp_pred; +break ; + } + err = temp_pred - err; +if (err < old_err) { + old_err = err; + *pred = temp_pred; + } + } + *podf = (div + *pred -1 ) / *pred; + }else if (div <8 ) { + *pred = div; + *podf =1 ; + } +} + +static long clk_imx_round_rate (struct clk_hw *hw,unsigned long rate) +{ +struct clk_imx_div *d =to_clk_imx (hw)->div; +u32 div, div_max, pred =0 , podf; +unsigned long parent_rate =clk_get_rate (clk_get_parent (hw->clk)); + +if (!d) +return -EINVAL ; + + div = parent_rate / rate; +if (div ==0 || parent_rate % rate) + div++; + +if (d->width_pred) { +calc_pred_podf_dividers (div, &pred, &podf); + div = pred * podf; + }else { + div_max =1 << d->width_podf; +if (div > div_max) + div = div_max; + } + +return parent_rate / div; +} + +static int clk_imx_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long *parent_rate) +{ +struct clk_imx_div *d =to_clk_imx (hw)->div; +u32 val, div, pred =0 , podf; + +if (!d) +return -EINVAL ; + + *parent_rate =clk_get_rate (clk_get_parent (hw->clk)); + + div = *parent_rate / rate; +if (div ==0 ) + div++; + +if ((*parent_rate / div != rate) || div > + (1 << d->width_pred) * (1 << d->width_podf)) +return -EINVAL ; + +if (d->width_pred) { +calc_pred_podf_dividers (div, &pred, &podf); + }else { + pred =1 ; + podf = div; + } + + val =readl_relaxed (d->reg); + val &= ~(((1 << d->width_pred) -1 ) << d->shift_pred); + val &= ~(((1 << d->width_podf) -1 ) << d->shift_podf); + val |= (pred -1 ) << d->shift_pred; + val |= (podf -1 ) << d->shift_podf; +writel_relaxed (val, d->reg); + +return (d->busy) ?clk_imx_busy_wait (d->busy) :0 ; +} + +const struct clk_hw_ops clk_imx_ops = { + .enable = clk_imx_enable, + .disable = clk_imx_disable, + .recalc_rate = clk_imx_recalc_rate, + .round_rate = clk_imx_round_rate, + .set_rate = clk_imx_set_rate, + .get_parent = clk_imx_get_parent, + .set_parent = clk_imx_set_parent, +};
arch/arm/mach-imx/clock.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
1.7.4.1
RFC PATCH 3/3 arm/imx6: convert clock to device tree
In reply to Shawn GuoIt converts imx6 clock code to common clock frame and device tree.
--- arch/arm/mach-imx/Kconfig | 5 + arch/arm/mach-imx/Makefile | 1 + arch/arm/mach-imx/clock-imx6q.c | 2135 +++++++-------------------------------- 3 files changed, 390 insertions(+), 1751 deletions(-)
arch/arm/mach-imx/Kconfig +5 -0
@@ -1,6 +1,9 @@ config IMX_HAVE_DMA_V1 bool +config HAVE_IMX_CLOCK + bool + config HAVE_IMX_GPC bool
@@ -614,7 +617,9 @@ config SOC_IMX6Q select GENERIC_CLK select GENERIC_CLK_DUMMY select GENERIC_CLK_FIXED + select GENERIC_CLK_DIVIDER_FIXED select HAVE_ARM_SCU + select HAVE_IMX_CLOCK select HAVE_IMX_GPC select HAVE_IMX_MMDC select HAVE_IMX_SRC
arch/arm/mach-imx/Makefile +1 -0
@@ -62,6 +62,7 @@ obj-$(CONFIG_MACH_EUKREA_MBIMXSD35_BASEBOARD) += eukrea_mbimxsd35-baseboard.o obj-$(CONFIG_MACH_VPR200) += mach-vpr200.o obj-$(CONFIG_DEBUG_LL) += lluart.o +obj-$(CONFIG_HAVE_IMX_CLOCK) += clock.o obj-$(CONFIG_HAVE_IMX_GPC) += gpc.o obj-$(CONFIG_HAVE_IMX_MMDC) += mmdc.o obj-$(CONFIG_HAVE_IMX_SRC) += src.o
arch/arm/mach-imx/clock-imx6q.c +384 -1751
2,329 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Sascha Hauer
maintainercover Convert imx6 clock to device tree
In reply to Shawn GuoQuoted 2 lines · Shawn Guo
As I promised to Arnd, I will convert imx6 clock code to common clock framework and in turn device tree at the earliest time. Here it is.
Very nice ;) I like the patches.
Is there a way to improve the way how the entities find their base addresses? Currently the C code figures out the base addresses based on compatible. Maybe we could put the crm clocks and anatop clocks into two different nodes instead of putting them all directly under clocks{}.
Could you split the last patch into two, one adding new device tree clock support in a new file and another removing the old clock support? This would help reviewing.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
cover Convert imx6 clock to device tree
Quoted 9 lines · Sascha Hauer
Quoted 2 lines · Shawn Guo
As I promised to Arnd, I will convert imx6 clock code to common clock framework and in turn device tree at the earliest time. Here it is.
Very nice ;) I like the patches.
Is there a way to improve the way how the entities find their base addresses? Currently the C code figures out the base addresses based on compatible.
May I understand the problem with doing that?
Quoted 3 lines
Maybe we could put the crm clocks and anatop clocks into
two different nodes instead of putting them all directly under clocks{}.
I do not quite understand this. Are you suggesting we keep using the static base address definition in C code for ccm and anatop rather than retrieving them from device tree? No, we do not want to do this. So if we need to get the addresses from device tree anyhow, using compatible to find the correct node is the best way to me.
Quoted 4 lines
Could you split the last patch into two, one adding new device tree clock support in a new file and another removing the old clock support? This would help reviewing.
Yes, will do. I would also rename the new file back to clock-imx6q.c in the last patch, because I want to keep using that file name.
Signature · 2 lines
Regards, Shawn
Sascha Hauer
maintainercover Convert imx6 clock to device tree
Quoted 13 lines · Shawn Guo
Quoted 9 lines · Sascha Hauer
Quoted 2 lines · Shawn Guo
As I promised to Arnd, I will convert imx6 clock code to common clock framework and in turn device tree at the earliest time. Here it is.
Very nice ;) I like the patches.
Is there a way to improve the way how the entities find their base addresses? Currently the C code figures out the base addresses based on compatible.
May I understand the problem with doing that?
Quoted 8 lines
Quoted 3 lines
Maybe we could put the crm clocks and anatop clocks into
two different nodes instead of putting them all directly under clocks{}.I do not quite understand this. Are you suggesting we keep using the static base address definition in C code for ccm and anatop rather than retrieving them from device tree? No, we do not want to do this. So if we need to get the addresses from device tree anyhow, using compatible to find the correct node is the best way to me.
What I meant is that currently there are many clock nodes which do have a register offset associated with them, but the base address has to be guessed in C code, like this:
Quoted 16 lines
if (of_device_is_compatible(np, "fsl,imx6q-pll-sys")) {
base = anatop_base;
ops = &pll_sys_ops;
} else if (of_device_is_compatible(np, "fsl,imx6q-pll-usb")) {
base = anatop_base;
ops = &pll_ops;
powerup_set_bit = true;
} else if (of_device_is_compatible(np, "fsl,imx6q-pll-av")) {
base = anatop_base;
ops = &pll_av_ops;
} else if (of_device_is_compatible(np, "fsl,imx6q-pll-enet")) {
base = anatop_base;
ops = &pll_enet_ops;
} else if (of_device_is_compatible(np, "fsl,imx6q-pll")) {
base = anatop_base;
ops = &pll_ops;Quoted 8 lines
} else if (of_device_is_compatible(np, "fsl,imx6q-pfd")) {
base = anatop_base;
ops = &pfd_ops;
gate_set_bit = true;
} else if (of_device_is_compatible(np, "fsl,imx6q-ldb-di-clock")) {
base = ccm_base;
ops = &ldb_di_clk_ops;
}Wouldn't it be possible to arrange the devicetree like this:
ccm at 020c4000 {
compatible = "fsl,imx6q-ccm";
reg = <0x020c4000 0x4000>;
interrupts = <0 87 0x04 0 88 0x04>;
clocks {
/* put ccm clocks here */
}
}
anatop at 020c8000 {
compatible = "fsl,imx6q-anatop";
reg = <0x020c8000 0x1000>;
interrupts = <0 49 0x04 0 54 0x04 0 127 0x04>;
clocks {
/* put anatop clocks here */
}
}Of course this has a high cost on indention levels.
On i.MX6 we only seem to have two base addresses relevant for clocks, but on i.MX5 there are multiple identical PLLs with different base addresses, so guessing the base address would not be possible based on of_device_is_compatible(), we would also have to match the name or some other identification property:
if (is_compatible(np, "fsl,imx5-pll") && np->name == "pll1") base = pll1_base; else if ...
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
cover Convert imx6 clock to device tree
Quoted 52 lines · Sascha Hauer
Quoted 13 lines · Shawn Guo
Quoted 9 lines · Sascha Hauer
Quoted 2 lines · Shawn Guo
As I promised to Arnd, I will convert imx6 clock code to common clock framework and in turn device tree at the earliest time. Here it is.
Very nice ;) I like the patches.
Is there a way to improve the way how the entities find their base addresses? Currently the C code figures out the base addresses based on compatible.
May I understand the problem with doing that?
Quoted 8 lines
Quoted 3 lines
Maybe we could put the crm clocks and anatop clocks into
two different nodes instead of putting them all directly under clocks{}.I do not quite understand this. Are you suggesting we keep using the static base address definition in C code for ccm and anatop rather than retrieving them from device tree? No, we do not want to do this. So if we need to get the addresses from device tree anyhow, using compatible to find the correct node is the best way to me.
What I meant is that currently there are many clock nodes which do have a register offset associated with them, but the base address has to be guessed in C code, like this:
Quoted 16 lines
if (of_device_is_compatible(np, "fsl,imx6q-pll-sys")) { base = anatop_base; ops = &pll_sys_ops; } else if (of_device_is_compatible(np, "fsl,imx6q-pll-usb")) { base = anatop_base; ops = &pll_ops; powerup_set_bit = true; } else if (of_device_is_compatible(np, "fsl,imx6q-pll-av")) { base = anatop_base; ops = &pll_av_ops; } else if (of_device_is_compatible(np, "fsl,imx6q-pll-enet")) { base = anatop_base; ops = &pll_enet_ops; } else if (of_device_is_compatible(np, "fsl,imx6q-pll")) { base = anatop_base; ops = &pll_ops;Quoted 8 lines
} else if (of_device_is_compatible(np, "fsl,imx6q-pfd")) { base = anatop_base; ops = &pfd_ops; gate_set_bit = true; } else if (of_device_is_compatible(np, "fsl,imx6q-ldb-di-clock")) { base = ccm_base; ops = &ldb_di_clk_ops; }
Quoted 1 line
Wouldn't it be possible to arrange the devicetree like this:
Yes, it is possible and actually better. Thanks for the suggestion.
Quoted 19 lines
ccm at 020c4000 {
compatible = "fsl,imx6q-ccm";
reg = <0x020c4000 0x4000>;
interrupts = <0 87 0x04 0 88 0x04>;
clocks {
/* put ccm clocks here */
}
}
anatop at 020c8000 {
compatible = "fsl,imx6q-anatop";
reg = <0x020c8000 0x1000>;
interrupts = <0 49 0x04 0 54 0x04 0 127 0x04>;
clocks {
/* put anatop clocks here */
}
}Quoted 2 lines
Of course this has a high cost on indention levels.
I think I will drop node 'clocks' and list those clock nodes directly under ccm and anatop nodes to save one level indention.
Signature · 2 lines
Regards, Shawn