clk: sunxi-ng: Add support for A83T CCU
Subsystems (4)
cover clk: sunxi-ng: Add support for A83T CCU
Hi everyone,
This is yet another series that adds support for the A83T CCU. The A83T CCU has a mix of new styled (like the A80) clocks at old (like A3x) offsets. Some differences include:
- D1/D2 style PLL clocks
- divisible audio module clocks
- new timing mode for mmc2 module clock
Patch 1 fixes the mp style clock to take into account pre-dividers for the .set_rate and .recalc_rate callbacks.
Patch 2 makes the gate clocks support common pre-dividers. This is used to make the HSIC 12M clock have the right clock rate.
Patch 3 adds a compatible string for the A83T CCU to the sunxi-ccu bindings.
Patch 4 adds the driver for the A83T CCU.
Patch 5 adds the CCU device nodes, and fixes up any existing clock phandles in the dtsi.
Let me know what you think.
Regards
ChenYu
Chen-Yu Tsai (5):
clk: sunxi-ng: mp: Adjust parent rate for pre-dividers
clk: sunxi-ng: gate: Support common pre-dividers
clk: sunxi-ng: Add compatible string for A83T CCU to bindings
clk: sunxi-ng: Add driver for A83T CCU
ARM: dts: sun8i-a83t: Add CCU device nodes
.../devicetree/bindings/clock/sunxi-ccu.txt | 1 + arch/arm/boot/dts/sun8i-a83t.dtsi | 18 +- drivers/clk/sunxi-ng/Kconfig | 10 + drivers/clk/sunxi-ng/Makefile | 1 + drivers/clk/sunxi-ng/ccu-sun8i-a83t.c | 898 +++++++++++++++++++++ drivers/clk/sunxi-ng/ccu-sun8i-a83t.h | 65 ++ drivers/clk/sunxi-ng/ccu_gate.c | 47 ++ drivers/clk/sunxi-ng/ccu_mp.c | 8 + include/dt-bindings/clock/sun8i-a83t-ccu.h | 138 ++++ include/dt-bindings/reset/sun8i-a83t-ccu.h | 98 +++ 10 files changed, 1282 insertions(+), 2 deletions(-) create mode 100644 drivers/clk/sunxi-ng/ccu-sun8i-a83t.c create mode 100644 drivers/clk/sunxi-ng/ccu-sun8i-a83t.h create mode 100644 include/dt-bindings/clock/sun8i-a83t-ccu.h create mode 100644 include/dt-bindings/reset/sun8i-a83t-ccu.h
Signature · 1 line
2.11.0
PATCH 1/5 clk: sunxi-ng: mp: Adjust parent rate for pre-dividers
The MP style clocks support an mux with pre-dividers. While the driver correctly accounted for them in the .determine_rate callback, it did not in the .recalc_rate and .set_rate callbacks.
This means when calculating the factors in the .set_rate callback, they would be off by a factor of the active pre-divider. Same goes for reading back the clock rate after it is set.
---
Maybe we want to Cc stable for this one?
drivers/clk/sunxi-ng/ccu_mp.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/clk/sunxi-ng/ccu_mp.c +8 -0
@@ -85,6 +85,10 @@ static unsigned long ccu_mp_recalc_rate(struct clk_hw *hw,unsigned int m, p;u32 reg; +/* Adjust parent_rate according to pre-dividers */ +ccu_mux_helper_adjust_parent_for_prediv (&cmp->common, &cmp->mux, +-1 , &parent_rate); + reg =readl (cmp->common.base + cmp->common.reg); m = reg >> cmp->m.shift;
@@ -117,6 +121,10 @@ static int ccu_mp_set_rate(struct clk_hw *hw, unsigned long rate,unsigned int m, p;u32 reg; +/* Adjust parent_rate according to pre-dividers */ +ccu_mux_helper_adjust_parent_for_prediv (&cmp->common, &cmp->mux, +-1 , &parent_rate); + max_m = cmp->m.max ?:1 << cmp->m.width; max_p = cmp->p.max ?:1 << ((1 << cmp->p.width) -1 );
Signature · 1 line
2.11.0
Re: [PATCH 1/5] clk: sunxi-ng: mp: Adjust parent rate for pre-dividers
Quoted 8 lines · Chen-Yu Tsai
The MP style clocks support an mux with pre-dividers. While the driver correctly accounted for them in the .determine_rate callback, it did not in the .recalc_rate and .set_rate callbacks.
This means when calculating the factors in the .set_rate callback, they would be off by a factor of the active pre-divider. Same goes for reading back the clock rate after it is set.
Quoted 5 lines
Fixes 2ab836db5097 ("clk: sunxi-ng: Add M-P factor clock support")Signed-off-by Chen-Yu Tsai <[email protected]>---
Maybe we want to Cc stable for this one?
I've applied it and added the Cc.
Thanks!
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170214/1643bd2a/attachment.sig>
PATCH 2/5 clk: sunxi-ng: gate: Support common pre-dividers
In reply to Chen-Yu TsaiSome clock gates have a pre-divider between the source input and the gate itself. A notable example is the HSIC 12 MHz clock found on the A83T, which has the 24 MHz main oscillator as its input, and a /2 pre-divider.
--- drivers/clk/sunxi-ng/ccu_gate.c | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
drivers/clk/sunxi-ng/ccu_gate.c +47 -0
@@ -75,8 +75,55 @@ static int ccu_gate_is_enabled(struct clk_hw *hw)return ccu_gate_helper_is_enabled (&cg->common, cg->enable); } +static unsigned long ccu_gate_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct ccu_gate *cg =hw_to_ccu_gate (hw); +unsigned long rate = parent_rate; + +if (cg->common.features &CCU_FEATURE_ALL_PREDIV ) + rate /= cg->common.prediv; + +return rate; +} + +static long ccu_gate_round_rate (struct clk_hw *hw,unsigned long rate, +unsigned long *prate) +{ +struct ccu_gate *cg =hw_to_ccu_gate (hw); +int div =1 ; + +if (cg->common.features &CCU_FEATURE_ALL_PREDIV ) + div = cg->common.prediv; + +if (clk_hw_get_flags (hw) &CLK_SET_RATE_PARENT ) { +unsigned long best_parent = rate; + +if (cg->common.features &CCU_FEATURE_ALL_PREDIV ) + best_parent *= div; + *prate =clk_hw_round_rate (clk_hw_get_parent (hw), best_parent); + } + +return *prate / div; +} + +static int ccu_gate_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ +/* +* We must report success but we can do so unconditionally because +* clk_factor_round_rate returns values that ensure this call is a +* nop. +*/ + +return 0 ; +} +const struct clk_ops ccu_gate_ops = { .disable = ccu_gate_disable, .enable = ccu_gate_enable, .is_enabled = ccu_gate_is_enabled, + .round_rate = ccu_gate_round_rate, + .set_rate = ccu_gate_set_rate, + .recalc_rate = ccu_gate_recalc_rate, };
Signature · 1 line
2.11.0
Maxime Ripard
AppliedRe: [PATCH 2/5] clk: sunxi-ng: gate: Support common pre-dividers
Quoted 6 lines · Chen-Yu Tsai
Some clock gates have a pre-divider between the source input and the gate itself. A notable example is the HSIC 12 MHz clock found on the A83T, which has the 24 MHz main oscillator as its input, and a /2 pre-divider.
Signed-off-by Chen-Yu Tsai <[email protected]>
Applied, thanks!
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170214/1967bfcd/attachment-0001.sig>
PATCH 3/5 clk: sunxi-ng: Add compatible string for A83T CCU to bindings
In reply to Chen-Yu TsaiThe A83T clock control unit is a hybrid of some new style clock designs from the A80, and old style layout from the other Allwinner SoCs.
--- Documentation/devicetree/bindings/clock/sunxi-ccu.txt | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/clock/sunxi-ccu.txt +1 -0
@@ -6,6 +6,7 @@ Required properties : - "allwinner,sun6i-a31-ccu" - "allwinner,sun8i-a23-ccu" - "allwinner,sun8i-a33-ccu" + - "allwinner,sun8i-a83t-ccu" - "allwinner,sun8i-h3-ccu" - "allwinner,sun8i-v3s-ccu" - "allwinner,sun9i-a80-ccu"
Signature · 1 line
2.11.0
PATCH 4/5 clk: sunxi-ng: Add driver for A83T CCU
In reply to Chen-Yu TsaiThe A83T clock control unit is a hybrid of some new style clock designs from the A80, and old style layout from the other Allwinner SoCs.
The mmc2 module clock supports a new timing mode. This mode outputs the clock at half the set rate, and moves the output and sample delays into the mmc controller. The mmc controller must also be set to use the new timing mode. In this patch we force the mmc2 module clock to the new mode, and drop the output and sample phase clocks for it.
--- drivers/clk/sunxi-ng/Kconfig | 10 + drivers/clk/sunxi-ng/Makefile | 1 + drivers/clk/sunxi-ng/ccu-sun8i-a83t.c | 898 +++++++++++++++++++++++++++++ drivers/clk/sunxi-ng/ccu-sun8i-a83t.h | 65 +++ include/dt-bindings/clock/sun8i-a83t-ccu.h | 138 +++++ include/dt-bindings/reset/sun8i-a83t-ccu.h | 98 ++++ 6 files changed, 1210 insertions(+) create mode 100644 drivers/clk/sunxi-ng/ccu-sun8i-a83t.c create mode 100644 drivers/clk/sunxi-ng/ccu-sun8i-a83t.h create mode 100644 include/dt-bindings/clock/sun8i-a83t-ccu.h create mode 100644 include/dt-bindings/reset/sun8i-a83t-ccu.h
drivers/clk/sunxi-ng/Kconfig +10 -0
@@ -109,6 +109,16 @@ config SUN8I_A33_CCU select SUNXI_CCU_PHASE default MACH_SUN8I +config SUN8I_A83T_CCU + bool "Support for the Allwinner A83T CCU" + select SUNXI_CCU_DIV + select SUNXI_CCU_GATE + select SUNXI_CCU_NKMP + select SUNXI_CCU_NM + select SUNXI_CCU_MP + select SUNXI_CCU_PHASE + default MACH_SUN8I + config SUN8I_H3_CCU bool "Support for the Allwinner H3 CCU" select SUNXI_CCU_DIV
drivers/clk/sunxi-ng/Makefile +1 -0
@@ -23,6 +23,7 @@ obj-$(CONFIG_SUN5I_CCU) += ccu-sun5i.o obj-$(CONFIG_SUN6I_A31_CCU) += ccu-sun6i-a31.o obj-$(CONFIG_SUN8I_A23_CCU) += ccu-sun8i-a23.o obj-$(CONFIG_SUN8I_A33_CCU) += ccu-sun8i-a33.o +obj-$(CONFIG_SUN8I_A83T_CCU) += ccu-sun8i-a83t.o obj-$(CONFIG_SUN8I_H3_CCU) += ccu-sun8i-h3.o obj-$(CONFIG_SUN8I_V3S_CCU) += ccu-sun8i-v3s.o obj-$(CONFIG_SUN9I_A80_CCU) += ccu-sun9i-a80.o
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c new file +898 -0
898 lines not on this page · raw message
drivers/clk/sunxi-ng/ccu-sun8i-a83t.h new file +65 -0
65 lines not on this page · raw message
include/dt-bindings/clock/sun8i-a83t-ccu.h new file +138 -0
138 lines not on this page · raw message
include/dt-bindings/reset/sun8i-a83t-ccu.h new file +98 -0
98 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH 4/5] clk: sunxi-ng: Add driver for A83T CCU
Quoted 1 line · Chen-Yu Tsai
+/* Some PLLs are input * N / div1 / P. Model them as NKMP with no K */
Is that even working?
I'm not quite sure we want to do that. We might model it as a NP clock with a variable prediv?
Quoted 8 lines
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c new file +8
-0+/* Use a separate clock for the pre-divider on the AHB1 PLL-PERIPH input */ +static SUNXI_CCU_M(pll_periph_ahb1_clk, "pll-periph-ahb1", "pll-periph", + 0x054, 6, 2, 0); + +static const char *const ahb1_parents[] = {"osc16M-d512" ,"osc24M" , +"pll-periph-ahb1" , +"pll-periph-ahb1" }; +static struct ccu_div ahb1_clk = {
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c line 249
Quoted 10 lines
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c new file +10
-0+ .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO), + .mux = _SUNXI_CCU_MUX(12, 2), + .common = { + .reg = 0x054, + .hw.init =CLK_HW_INIT_PARENTS ("ahb1" , + ahb1_parents, + &ccu_div_ops, + 0), + }, +};
What's different from a pre divider only for a given index here?
Quoted 10 lines
+/*
+ * MMC2 supports what's called the "new timing mode". The CCU and the MMC
+ * controller must be in sync about which mode is used. The new mode moves
+ * the clock delay controls (and possibly the delay lines) into the MMC
+ * block. Also, the output of the clock is divided by 2. The output and
+ * sample phase clocks are unused under this mode.
+ *
+ * This new mode seems to be preferred. Hence we force this clock to the
+ * new mode. And we don't add the phase clocks.
+ */
I'm sorry, but I said this several times, this isn't working. We should model it properly, and not hack this around in the clock driver.
As you say in your comment, the MMC driver needs to be aware about which mode is used, in order to also set a bit in one of its registers accordingly, and modify its sampling behaviour.
The new timing is preferred, but our previous clock implementations didn't hardcode it, so we can't even rely on that behaviour to always write it in our driver.
This is not something specific to the A83T, but is found in all the SoCs since the A23, so we need to come up with a good solution to address that.
I'm not sure what a good solution would be though. One would be to just have a private function of our own to switch in the new mode (if relevant, because only the MMC2 controllers have it), but that would lead to troubles with !sunxi-ng. Not something we can't deal with, but some extra precautions should be taken (make sure to protect the call through an ifdef / IS_DEFINED, check that the sunxi-ng driver has been probed, etc.)
Or we could introduce a new clk_ops function pointer, but I'm not sure if Mike and Stephen are going to be happy with that.
Thanks,
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170214/8bfdcb83/attachment-0001.sig>
Re: [PATCH 4/5] clk: sunxi-ng: Add driver for A83T CCU
Quoted 4 lines · Maxime Ripard
Quoted 1 line · Chen-Yu Tsai
+/* Some PLLs are input * N / div1 / P. Model them as NKMP with no K */
Is that even working?
Looking at the nkmp clock code, only .recalc_rate will work properly though. Maybe I could fix up the code so it handles zero width factors.
Quoted 2 lines
I'm not quite sure we want to do that. We might model it as a NP clock with a variable prediv?
There's no NP clock type yet. And a problem with a variable prediv is that it doesn't participate in factor calculation. It's effectively fixed.
I did this for the A80 as well though. Fixing up the NKMP clock might be easier.
Quoted 13 lines
Quoted 13 lines
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c new file +12
-0+/* Use a separate clock for the pre-divider on the AHB1 PLL-PERIPH input */ +static SUNXI_CCU_M(pll_periph_ahb1_clk, "pll-periph-ahb1", "pll-periph", + 0x054, 6, 2, 0); + +static const char *const ahb1_parents[] = {"osc16M-d512" ,"osc24M" , +"pll-periph-ahb1" , +"pll-periph-ahb1" }; +static struct ccu_div ahb1_clk = { + .div =_SUNXI_CCU_DIV_FLAGS (4 ,2 ,CLK_DIVIDER_POWER_OF_TWO ), + .mux =_SUNXI_CCU_MUX (12 ,2 ), + .common = { + .reg =0x054 ,
Quoted 8 lines
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c line 249
Quoted 6 lines
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c new file +6
-0+ .hw.init = CLK_HW_INIT_PARENTS("ahb1", + ahb1_parents, + &ccu_div_ops, + 0), + }, +};What's different from a pre divider only for a given index here?
The variable pre-divider is shared for both pll-periph mux inputs. This is one way to handle it. The other would be to extend ccu_mux to handle multiple variable pre-dividers. I don't really want to do that if this is the only instance that needs it though.
Quoted 16 lines
Quoted 11 lines
+/*
+ * MMC2 supports what's called the "new timing mode". The CCU and the MMC
+ * controller must be in sync about which mode is used. The new mode moves
+ * the clock delay controls (and possibly the delay lines) into the MMC
+ * block. Also, the output of the clock is divided by 2. The output and
+ * sample phase clocks are unused under this mode.
+ *
+ * This new mode seems to be preferred. Hence we force this clock to the
+ * new mode. And we don't add the phase clocks.
+ */I'm sorry, but I said this several times, this isn't working. We should model it properly, and not hack this around in the clock driver.
Quoted 7 lines
As you say in your comment, the MMC driver needs to be aware about which mode is used, in order to also set a bit in one of its registers accordingly, and modify its sampling behaviour.
The new timing is preferred, but our previous clock implementations didn't hardcode it, so we can't even rely on that behaviour to always write it in our driver.
Correct. With the A83T there has never been a merged clock driver though. I realize this is a one off thing.
Quoted 11 lines
This is not something specific to the A83T, but is found in all the SoCs since the A23, so we need to come up with a good solution to address that.
I'm not sure what a good solution would be though. One would be to just have a private function of our own to switch in the new mode (if relevant, because only the MMC2 controllers have it), but that would lead to troubles with !sunxi-ng. Not something we can't deal with, but some extra precautions should be taken (make sure to protect the call through an ifdef /
IS_DEFINED, check that the sunxi-ng driver has been probed, etc.)
If the custom function route is acceptable, I'll come up with something.
Regards
ChenYu
Quoted 11 lines
Or we could introduce a new
clk_opsfunction pointer, but I'm not sure if Mike and Stephen are going to be happy with that.Thanks,
Maxime--
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
Re: [PATCH 4/5] clk: sunxi-ng: Add driver for A83T CCU
Quoted 10 lines · Chen-Yu Tsai
Quoted 4 lines · Maxime Ripard
Quoted 1 line · Chen-Yu Tsai
+/* Some PLLs are input * N / div1 / P. Model them as NKMP with no K */
Is that even working?
Looking at the nkmp clock code, only .recalc_rate will work properly though. Maybe I could fix up the code so it handles zero width factors.
Quoted 8 lines
Quoted 2 lines
I'm not quite sure we want to do that. We might model it as a NP clock with a variable prediv?
There's no NP clock type yet. And a problem with a variable prediv is that it doesn't participate in factor calculation. It's effectively fixed.
I did this for the A80 as well though. Fixing up the NKMP clock might be easier.
Then maybe we just need a NMP clock type then. What I'm really afraid of is that we'll just end up in a clk-factors situation that was simply impossible to maintain without breaking anything, hence why we had different clock types then.
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c new file +12
-0+/* Use a separate clock for the pre-divider on the AHB1 PLL-PERIPH input */ +static SUNXI_CCU_M(pll_periph_ahb1_clk, "pll-periph-ahb1", "pll-periph", + 0x054, 6, 2, 0); + +static const char *const ahb1_parents[] = {"osc16M-d512" ,"osc24M" , +"pll-periph-ahb1" , +"pll-periph-ahb1" }; +static struct ccu_div ahb1_clk = { + .div =_SUNXI_CCU_DIV_FLAGS (4 ,2 ,CLK_DIVIDER_POWER_OF_TWO ), + .mux =_SUNXI_CCU_MUX (12 ,2 ), + .common = { + .reg =0x054 ,Quoted 8 lines
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c line 249
Quoted 6 lines
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c new file +6
-0+ .hw.init = CLK_HW_INIT_PARENTS("ahb1", + ahb1_parents, + &ccu_div_ops, + 0), + }, +};What's different from a pre divider only for a given index here?
Quoted 4 lines
The variable pre-divider is shared for both pll-periph mux inputs. This is one way to handle it. The other would be to extend
ccu_muxto handle multiple variable pre-dividers. I don't really want to do that if this is the only instance that needs it though.
Every addition we made was only needed by one instance at first :)
We are working that way for fixed pre-dividers already, I don't see why we can't have it for variable ones too.
Quoted 38 lines
Quoted 15 lines
Quoted 10 lines
+/*
+ * MMC2 supports what's called the "new timing mode". The CCU and the MMC
+ * controller must be in sync about which mode is used. The new mode moves
+ * the clock delay controls (and possibly the delay lines) into the MMC
+ * block. Also, the output of the clock is divided by 2. The output and
+ * sample phase clocks are unused under this mode.
+ *
+ * This new mode seems to be preferred. Hence we force this clock to the
+ * new mode. And we don't add the phase clocks.
+ */I'm sorry, but I said this several times, this isn't working. We should model it properly, and not hack this around in the clock driver.
Quoted 7 lines
As you say in your comment, the MMC driver needs to be aware about which mode is used, in order to also set a bit in one of its registers accordingly, and modify its sampling behaviour.
The new timing is preferred, but our previous clock implementations didn't hardcode it, so we can't even rely on that behaviour to always write it in our driver.
Correct. With the A83T there has never been a merged clock driver though. I realize this is a one off thing.
Quoted 11 lines
This is not something specific to the A83T, but is found in all the SoCs since the A23, so we need to come up with a good solution to address that.
I'm not sure what a good solution would be though. One would be to just have a private function of our own to switch in the new mode (if relevant, because only the MMC2 controllers have it), but that would lead to troubles with !sunxi-ng. Not something we can't deal with, but some extra precautions should be taken (make sure to protect the call through an ifdef /
IS_DEFINED, check that the sunxi-ng driver has been probed, etc.)
Quoted 1 line
If the custom function route is acceptable, I'll come up with something.
I think it would be a great start yes. I'll try to discuss it with Mike and Stephen at ELC and see what they think about that.
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170215/ef3f162e/attachment-0001.sig>
Re: [PATCH 4/5] clk: sunxi-ng: Add driver for A83T CCU
Quoted 42 lines · Maxime Ripard
Quoted 41 lines · Chen-Yu Tsai
Quoted 16 lines · Maxime Ripard
Quoted 10 lines · Chen-Yu Tsai
+/*
+ * MMC2 supports what's called the "new timing mode". The CCU and the MMC
+ * controller must be in sync about which mode is used. The new mode moves
+ * the clock delay controls (and possibly the delay lines) into the MMC
+ * block. Also, the output of the clock is divided by 2. The output and
+ * sample phase clocks are unused under this mode.
+ *
+ * This new mode seems to be preferred. Hence we force this clock to the
+ * new mode. And we don't add the phase clocks.
+ */I'm sorry, but I said this several times, this isn't working. We should model it properly, and not hack this around in the clock driver.
Quoted 7 lines
As you say in your comment, the MMC driver needs to be aware about which mode is used, in order to also set a bit in one of its registers accordingly, and modify its sampling behaviour.
The new timing is preferred, but our previous clock implementations didn't hardcode it, so we can't even rely on that behaviour to always write it in our driver.
Correct. With the A83T there has never been a merged clock driver though. I realize this is a one off thing.
Quoted 11 lines
This is not something specific to the A83T, but is found in all the SoCs since the A23, so we need to come up with a good solution to address that.
I'm not sure what a good solution would be though. One would be to just have a private function of our own to switch in the new mode (if relevant, because only the MMC2 controllers have it), but that would lead to troubles with !sunxi-ng. Not something we can't deal with, but some extra precautions should be taken (make sure to protect the call through an ifdef /
IS_DEFINED, check that the sunxi-ng driver has been probed, etc.)
Quoted 5 lines
Quoted 1 line
If the custom function route is acceptable, I'll come up with something.
I think it would be a great start yes. I'll try to discuss it with Mike and Stephen at ELC and see what they think about that.
I didn't hear anything at ELC. Can someone explain what the issue is? Could something like clk_get_phase() + clk_get_rate() tell us if we're in one mode vs. the other?
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH 4/5] clk: sunxi-ng: Add driver for A83T CCU
Hi Stephen
Quoted 43 lines · Stephen Boyd
Quoted 42 lines · Maxime Ripard
Quoted 41 lines · Chen-Yu Tsai
Quoted 16 lines · Maxime Ripard
Quoted 10 lines · Chen-Yu Tsai
+/*
+ * MMC2 supports what's called the "new timing mode". The CCU and the MMC
+ * controller must be in sync about which mode is used. The new mode moves
+ * the clock delay controls (and possibly the delay lines) into the MMC
+ * block. Also, the output of the clock is divided by 2. The output and
+ * sample phase clocks are unused under this mode.
+ *
+ * This new mode seems to be preferred. Hence we force this clock to the
+ * new mode. And we don't add the phase clocks.
+ */I'm sorry, but I said this several times, this isn't working. We should model it properly, and not hack this around in the clock driver.
Quoted 7 lines
As you say in your comment, the MMC driver needs to be aware about which mode is used, in order to also set a bit in one of its registers accordingly, and modify its sampling behaviour.
The new timing is preferred, but our previous clock implementations didn't hardcode it, so we can't even rely on that behaviour to always write it in our driver.
Correct. With the A83T there has never been a merged clock driver though. I realize this is a one off thing.
Quoted 11 lines
This is not something specific to the A83T, but is found in all the SoCs since the A23, so we need to come up with a good solution to address that.
I'm not sure what a good solution would be though. One would be to just have a private function of our own to switch in the new mode (if relevant, because only the MMC2 controllers have it), but that would lead to troubles with !sunxi-ng. Not something we can't deal with, but some extra precautions should be taken (make sure to protect the call through an ifdef /
IS_DEFINED, check that the sunxi-ng driver has been probed, etc.)
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
If the custom function route is acceptable, I'll come up with something.
I think it would be a great start yes. I'll try to discuss it with Mike and Stephen at ELC and see what they think about that.
I didn't hear anything at ELC.
Yeah, sorry, I ended up discussing this with Mike.
Quoted 3 lines
Can someone explain what the issue is? Could something like
clk_get_phase()+clk_get_rate()tell us if we're in one mode vs. the other?
So we have two modes of operation for that clock, old vs new (I know, I didn't pick the names).
The old mode is what we support right now. It has a combination of a linear multiplier and divider, plus some phase controls.
The new mode however disables the phase controls and adds post-divider of 2 on the rate.
We cannot really rely on the rate itself, since there's a huge overlap between the rates we can obtain in the old and new modes. Same thing for the phase, having a 0 deg phase is achieved both in the old and new modes.
To make things worse, the new mode is only available on one out of three MMC controllers (and associated clocks), and that MMC controller needs to set a bit as well to switch to the new mode if needed. So we definitely needs some synchronisation there, and also to be able to retrieve if the mode switching is available, and if we're already using that mode.
Mike agreed that the easiest way forward was to use a custom function.
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170303/09254849/attachment.sig>
Re: [PATCH 4/5] clk: sunxi-ng: Add driver for A83T CCU
Quoted 20 lines · Maxime Ripard
Quoted 3 lines · Stephen Boyd
Can someone explain what the issue is? Could something like
clk_get_phase()+clk_get_rate()tell us if we're in one mode vs. the other?So we have two modes of operation for that clock, old vs new (I know, I didn't pick the names).
The old mode is what we support right now. It has a combination of a linear multiplier and divider, plus some phase controls.
The new mode however disables the phase controls and adds post-divider of 2 on the rate.
We cannot really rely on the rate itself, since there's a huge overlap between the rates we can obtain in the old and new modes. Same thing for the phase, having a 0 deg phase is achieved both in the old and new modes.
Quoted 9 lines
To make things worse, the new mode is only available on one out of three MMC controllers (and associated clocks), and that MMC controller needs to set a bit as well to switch to the new mode if needed. So we definitely needs some synchronisation there, and also to be able to retrieve if the mode switching is available, and if we're already using that mode.
Mike agreed that the easiest way forward was to use a custom function.
Ok. Is there any need to change the mode dynamically at runtime? Or could it be decided once at clk driver probe time/boot time and detected via set_phase() failing when we're in the new mode? At least, it sounds like set_phase() should bail out there because it doesn't exist, although it could be argued that setting the phase to something it already is set to is valid and shouldn't return an error.
I'm not saying I'm opposed to the custom function, just thinking of alternatives if MMC maintainers don't agree with the custom function.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH 4/5] clk: sunxi-ng: Add driver for A83T CCU
Hi Stephen,
Quoted 28 lines · Stephen Boyd
Quoted 27 lines · Maxime Ripard
Quoted 3 lines · Stephen Boyd
Can someone explain what the issue is? Could something like
clk_get_phase()+clk_get_rate()tell us if we're in one mode vs. the other?So we have two modes of operation for that clock, old vs new (I know, I didn't pick the names).
The old mode is what we support right now. It has a combination of a linear multiplier and divider, plus some phase controls.
The new mode however disables the phase controls and adds post-divider of 2 on the rate.
We cannot really rely on the rate itself, since there's a huge overlap between the rates we can obtain in the old and new modes. Same thing for the phase, having a 0 deg phase is achieved both in the old and new modes.
To make things worse, the new mode is only available on one out of three MMC controllers (and associated clocks), and that MMC controller needs to set a bit as well to switch to the new mode if needed. So we definitely needs some synchronisation there, and also to be able to retrieve if the mode switching is available, and if we're already using that mode.
Quoted 5 lines
Quoted 1 line
Mike agreed that the easiest way forward was to use a custom function.
Ok. Is there any need to change the mode dynamically at runtime? Or could it be decided once at clk driver probe time/boot time and detected via
set_phase()failing when we're in the new mode?
One thing I forgot to mention is that we also still have to support the old DTs that use our old clock drivers, that will probably never get to see this new mode. So the first thing we need is being able to tell whether that mode is supported and if it's already enabled.
And if it's supported, and not enabled, enable it, both in the clock and MMC drivers.
Quoted 4 lines
At least, it sounds like
set_phase()should bail out there because it doesn't exist, although it could be argued that setting the phase to something it already is set to is valid and shouldn't return an error.
Yep, once the new mode is set (disregarding how we do it), we should prevent any clk_set_phase != 0. We'll also need to adjust the reported clock rate.
Quoted 3 lines
I'm not saying I'm opposed to the custom function, just thinking of alternatives if MMC maintainers don't agree with the custom function.
Ok, thanks!
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170307/3c5f8057/attachment.sig>
Re: [PATCH 4/5] clk: sunxi-ng: Add driver for A83T CCU
In reply to Maxime RipardQuoted 17 lines · Maxime Ripard
Quoted 16 lines · Chen-Yu Tsai
Quoted 4 lines · Maxime Ripard
Quoted 1 line · Chen-Yu Tsai
+/* Some PLLs are input * N / div1 / P. Model them as NKMP with no K */
Is that even working?
Looking at the nkmp clock code, only .recalc_rate will work properly though. Maybe I could fix up the code so it handles zero width factors.
Quoted 2 lines
I'm not quite sure we want to do that. We might model it as a NP clock with a variable prediv?
There's no NP clock type yet. And a problem with a variable prediv is that it doesn't participate in factor calculation. It's effectively fixed.
Quoted 7 lines
Quoted 2 lines
I did this for the A80 as well though. Fixing up the NKMP clock might be easier.
Then maybe we just need a NMP clock type then. What I'm really afraid of is that we'll just end up in a clk-factors situation that was simply impossible to maintain without breaking anything, hence why we had different clock types then.
Upon further review, I think it will work. I did notice a discrepancy between .set_rate and .round_rate though. Will send fixes later.
About the old clk-factors situation, I'm not exactly sure what part you're referring to. To me it seems the "factors" bits are mostly the same. Differences are mostly with parent-specific pre-dividers, clock post-dividers, and non-standard factors. The first is nicely handled by the new mux wrapper, the second is currently only used with NK types, and the last is currently only supported by single factor divider or multiplier clocks with tables.
Non-standard factors are probably the trickiest one, but given we will support full factor tables for some of the tricky CPU PLLs, this is probably solved, even if not implemented yet.
I'll start with the NP style clocks, which only use P when the output is under a certain frequency.
Regards
ChenYu
Quoted 81 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c new file +12
-0+/* Use a separate clock for the pre-divider on the AHB1 PLL-PERIPH input */ +static SUNXI_CCU_M(pll_periph_ahb1_clk, "pll-periph-ahb1", "pll-periph", + 0x054, 6, 2, 0); + +static const char *const ahb1_parents[] = {"osc16M-d512" ,"osc24M" , +"pll-periph-ahb1" , +"pll-periph-ahb1" }; +static struct ccu_div ahb1_clk = { + .div =_SUNXI_CCU_DIV_FLAGS (4 ,2 ,CLK_DIVIDER_POWER_OF_TWO ), + .mux =_SUNXI_CCU_MUX (12 ,2 ), + .common = { + .reg =0x054 ,Quoted 8 lines
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c line 249
Quoted 6 lines
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c new file +6
-0+ .hw.init = CLK_HW_INIT_PARENTS("ahb1", + ahb1_parents, + &ccu_div_ops, + 0), + }, +};What's different from a pre divider only for a given index here?
Quoted 4 lines
The variable pre-divider is shared for both pll-periph mux inputs. This is one way to handle it. The other would be to extend
ccu_muxto handle multiple variable pre-dividers. I don't really want to do that if this is the only instance that needs it though.Every addition we made was only needed by one instance at first :)
We are working that way for fixed pre-dividers already, I don't see why we can't have it for variable ones too.
Quoted 38 lines
Quoted 15 lines
Quoted 10 lines
+/*
+ * MMC2 supports what's called the "new timing mode". The CCU and the MMC
+ * controller must be in sync about which mode is used. The new mode moves
+ * the clock delay controls (and possibly the delay lines) into the MMC
+ * block. Also, the output of the clock is divided by 2. The output and
+ * sample phase clocks are unused under this mode.
+ *
+ * This new mode seems to be preferred. Hence we force this clock to the
+ * new mode. And we don't add the phase clocks.
+ */I'm sorry, but I said this several times, this isn't working. We should model it properly, and not hack this around in the clock driver.
Quoted 7 lines
As you say in your comment, the MMC driver needs to be aware about which mode is used, in order to also set a bit in one of its registers accordingly, and modify its sampling behaviour.
The new timing is preferred, but our previous clock implementations didn't hardcode it, so we can't even rely on that behaviour to always write it in our driver.
Correct. With the A83T there has never been a merged clock driver though. I realize this is a one off thing.
Quoted 11 lines
This is not something specific to the A83T, but is found in all the SoCs since the A23, so we need to come up with a good solution to address that.
I'm not sure what a good solution would be though. One would be to just have a private function of our own to switch in the new mode (if relevant, because only the MMC2 controllers have it), but that would lead to troubles with !sunxi-ng. Not something we can't deal with, but some extra precautions should be taken (make sure to protect the call through an ifdef /
IS_DEFINED, check that the sunxi-ng driver has been probed, etc.)Quoted 1 line
If the custom function route is acceptable, I'll come up with something.
I think it would be a great start yes. I'll try to discuss it with Mike and Stephen at ELC and see what they think about that.
Maxime
--
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
Re: [PATCH 4/5] clk: sunxi-ng: Add driver for A83T CCU
Hi Chen-Yu,
Quoted 27 lines · Chen-Yu Tsai
Quoted 17 lines · Maxime Ripard
Quoted 16 lines · Chen-Yu Tsai
Quoted 4 lines · Maxime Ripard
Quoted 1 line · Chen-Yu Tsai
+/* Some PLLs are input * N / div1 / P. Model them as NKMP with no K */
Is that even working?
Looking at the nkmp clock code, only .recalc_rate will work properly though. Maybe I could fix up the code so it handles zero width factors.
Quoted 2 lines
I'm not quite sure we want to do that. We might model it as a NP clock with a variable prediv?
There's no NP clock type yet. And a problem with a variable prediv is that it doesn't participate in factor calculation. It's effectively fixed.
Quoted 7 lines
Quoted 2 lines
I did this for the A80 as well though. Fixing up the NKMP clock might be easier.
Then maybe we just need a NMP clock type then. What I'm really afraid of is that we'll just end up in a clk-factors situation that was simply impossible to maintain without breaking anything, hence why we had different clock types then.
Quoted 5 lines
Upon further review, I think it will work. I did notice a discrepancy between .set_rate and .round_rate though. Will send fixes later.
About the old clk-factors situation, I'm not exactly sure what part you're referring to.
We need to be able to support old DTs, which will still use the old clock code. Whatever solution we come up with need to take that into account.
Quoted 7 lines
To me it seems the "factors" bits are mostly the same. Differences are mostly with parent-specific pre-dividers, clock post-dividers, and non-standard factors. The first is nicely handled by the new mux wrapper, the second is currently only used with NK types, and the last is currently only supported by single factor divider or multiplier clocks with tables.
Quoted 6 lines
Non-standard factors are probably the trickiest one, but given we will support full factor tables for some of the tricky CPU PLLs, this is probably solved, even if not implemented yet.
I'll start with the NP style clocks, which only use P when the output is under a certain frequency.
Do we need to use a P factor? I mean, we can just create a custom clock for that, I'd realy don't want to cripple the generic code for a completely non-generic problem.
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170326/c2e28624/attachment-0001.sig>
Re: [PATCH 4/5] clk: sunxi-ng: Add driver for A83T CCU
Quoted 51 lines · Maxime Ripard
Hi Chen-Yu,
Quoted 27 lines · Chen-Yu Tsai
Quoted 17 lines · Maxime Ripard
Quoted 16 lines · Chen-Yu Tsai
Quoted 4 lines · Maxime Ripard
Quoted 1 line · Chen-Yu Tsai
+/* Some PLLs are input * N / div1 / P. Model them as NKMP with no K */
Is that even working?
Looking at the nkmp clock code, only .recalc_rate will work properly though. Maybe I could fix up the code so it handles zero width factors.
Quoted 2 lines
I'm not quite sure we want to do that. We might model it as a NP clock with a variable prediv?
There's no NP clock type yet. And a problem with a variable prediv is that it doesn't participate in factor calculation. It's effectively fixed.
Quoted 7 lines
Quoted 2 lines
I did this for the A80 as well though. Fixing up the NKMP clock might be easier.
Then maybe we just need a NMP clock type then. What I'm really afraid of is that we'll just end up in a clk-factors situation that was simply impossible to maintain without breaking anything, hence why we had different clock types then.
Quoted 5 lines
Upon further review, I think it will work. I did notice a discrepancy between .set_rate and .round_rate though. Will send fixes later.
About the old clk-factors situation, I'm not exactly sure what part you're referring to.
We need to be able to support old DTs, which will still use the old clock code. Whatever solution we come up with need to take that into account.
Quoted 11 lines
To me it seems the "factors" bits are mostly the same. Differences are mostly with parent-specific pre-dividers, clock post-dividers, and non-standard factors. The first is nicely handled by the new mux wrapper, the second is currently only used with NK types, and the last is currently only supported by single factor divider or multiplier clocks with tables.
Non-standard factors are probably the trickiest one, but given we will support full factor tables for some of the tricky CPU PLLs, this is probably solved, even if not implemented yet.
Quoted 6 lines
Quoted 2 lines
I'll start with the NP style clocks, which only use P when the output is under a certain frequency.
Do we need to use a P factor? I mean, we can just create a custom clock for that, I'd realy don't want to cripple the generic code for a completely non-generic problem.
I'm not sure. AFAIK the vendor BSP cpufreq doesn't use frequencies low enough to require the P divider, so we could just ignore it. But then we need to make sure it's set to 1 at probe time, while keeping the output frequency usable, which would kind of bloat the probe function. FYI I'm in favor of doing it this way.
ChenYu
Re: [PATCH 4/5] clk: sunxi-ng: Add driver for A83T CCU
Quoted 18 lines · Chen-Yu Tsai
Quoted 11 lines
Quoted 11 lines
To me it seems the "factors" bits are mostly the same. Differences are mostly with parent-specific pre-dividers, clock post-dividers, and non-standard factors. The first is nicely handled by the new mux wrapper, the second is currently only used with NK types, and the last is currently only supported by single factor divider or multiplier clocks with tables.
Non-standard factors are probably the trickiest one, but given we will support full factor tables for some of the tricky CPU PLLs, this is probably solved, even if not implemented yet.
Quoted 6 lines
Quoted 2 lines
I'll start with the NP style clocks, which only use P when the output is under a certain frequency.
Do we need to use a P factor? I mean, we can just create a custom clock for that, I'd realy don't want to cripple the generic code for a completely non-generic problem.
Quoted 5 lines
I'm not sure. AFAIK the vendor BSP cpufreq doesn't use frequencies low enough to require the P divider, so we could just ignore it. But then we need to make sure it's set to 1 at probe time, while keeping the output frequency usable, which would kind of bloat the probe function. FYI I'm in favor of doing it this way.
Hmmm, I don't know why I replied that anymore, I thought you were still talking about MMC, while you were clearly talking about CPU_PLLs...
The question still remains though. If we're not using P yet, and if the BSP doesn't either, then we can just hardcode it.
We can always come up with something later if we need to use it, either an NP-class, or a table. The only thing we need to care about would be to pay attention to what the P factor already is, before forcing it to 1. If it's set to 4, that would mean multiplying the CPU clock by 4, which is probably not such a great idea.
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170403/59f79643/attachment-0001.sig>
PATCH 5/5 ARM: dts: sun8i-a83t: Add CCU device nodes
In reply to Chen-Yu TsaiNow that we have support for the A83T CCU, add a device node for it, and replace any existing placeholder clock phandles with the correct ones.
--- arch/arm/boot/dts/sun8i-a83t.dtsi | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
arch/arm/boot/dts/sun8i-a83t.dtsi +16 -2
@@ -47,7 +47,9 @@ #include <dt-bindings/interrupt-controller/arm-gic.h> +#include <dt-bindings/clock/sun8i-a83t-ccu.h> #include <dt-bindings/pinctrl/sun4i-a10.h> +#include <dt-bindings/reset/sun8i-a83t-ccu.h> / { interrupt-parent = <&gic>;
@@ -123,6 +125,7 @@ #clock-cells = <0>; compatible = "fixed-clock"; clock-frequency = <24000000>; + clock-accuracy = <50000>; clock-output-names = "osc24M"; };
@@ -154,13 +157,23 @@ #size-cells = <1>; ranges; + ccu: clock at 01c20000 { + compatible = "allwinner,sun8i-a83t-ccu"; + reg = <0x01c20000 0x400>; + clocks = <&osc24M>, <&osc16Md512>; + clock-names = "hosc", "losc"; + #clock-cells = <1>; + #reset-cells = <1>; + }; + pio: pinctrl at 01c20800 { compatible = "allwinner,sun8i-a83t-pinctrl"; interrupts = <GIC_SPI 15 IRQ_TYPE_LEVEL_HIGH>, <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>, <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>; reg = <0x01c20800 0x400>; - clocks = <&osc24M>; + clocks = <&ccu CLK_BUS_PIO>, <&osc24M>, <&osc16Md512>; + clock-names = "apb", "hosc", "losc"; gpio-controller; interrupt-controller; #interrupt-cells = <3>;
@@ -206,7 +219,8 @@ interrupts = <GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>; reg-shift = <2>; reg-io-width = <4>; - clocks = <&osc24M>; + clocks = <&ccu CLK_BUS_UART0>; + resets = <&ccu RST_BUS_UART0>; status = "disabled"; };
Signature · 1 line
2.11.0