clk: sunxi-ng: Add support for A83T CCU
Subsystems (4)
v2 cover clk: sunxi-ng: Add support for A83T CCU
Hi everyone,
(Resent with devicetree mailing list CC-ed.) This is v2 of my A83T CCU series. This is for 4.13.
Changes since v1:
- Dropped two patches that were merged
- Added clk core flag to disable caching of clock phases
- Added support for multiple variable pre-dividers
- Merged "pll-periph-ahb1" pre-divider clock into "ahb1" clock with multiple variable pre-dividers
- Introduced new class of phase clocks that return -ENOTSUPP when the clock is in new timing mode
- Force mmc2 clock to new timing mode
- Added back mmc2 output and sample clocks
- Fixed bit ops for forcing audio PLL configuration
- Added requirement for "losc" clock in device tree binding
- Stripped leading 0 in device node name
- Updated subject prefixes for various patches
Patch 1 adds a compatible string for the A83T CCU to the sunxi-ccu bindings.
Patch 2 adds a CLK_GET_PHASE_NOCACHE flag to the clk core, asking it not to cache clock phase values. This is similar to CLK_GET_RATE_NOCACHE. Patch 5 has a compile time dependency on this patch, for the flag value.
Patch 3 adds a new class of phase clocks that check the new timing mode bit, and returns an error if it is set, which indicates the phase delays no longer apply. This is a clean way to signal which timing mode the mmc clock is in, without using any custom functions or callbacks. We don't support runtime switching of modes.
Patch 4 adds support for multiple variable pre-dividers to the sunxi-ng mux class.
Patch 5 adds the driver for the A83T CCU.
Patch 6 adds the CCU device nodes, and fixes up any existing clock phandles in the dtsi, without using the macros.
Patch 7 sets the clock accuracy for the main oscillator.
Patch 8 is for the next -rc2, switch the clock indices from raw numbers to macros we introduced with the driver. This will be updated if more peripherals are introduced in the same cycle.
Let me know what you think.
Cover letter excerpt from v1:
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
Regards
ChenYu
Chen-Yu Tsai (8):
dt-bindings: clock: sunxi-ccu: Add compatible string for A83T CCU
clk: Provide option to query hardware for clk phase
clk: sunxi-ng: Add class of phase clocks supporting MMC new timing
modes
clk: sunxi-ng: Support multiple variable pre-dividers
clk: sunxi-ng: Add driver for A83T CCU
ARM: sun8i: a83t: Add CCU device nodes
ARM: sun8i: a83t: Set clock accuracy for 24MHz oscillator
ARM: sun8i: a83t: Switch to CCU device tree binding macros
.../devicetree/bindings/clock/sunxi-ccu.txt | 2 + arch/arm/boot/dts/sun8i-a83t.dtsi | 19 +- drivers/clk/clk.c | 6 +- drivers/clk/sunxi-ng/Kconfig | 10 + drivers/clk/sunxi-ng/Makefile | 1 + drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 10 +- drivers/clk/sunxi-ng/ccu-sun6i-a31.c | 10 +- drivers/clk/sunxi-ng/ccu-sun8i-a23.c | 10 +- drivers/clk/sunxi-ng/ccu-sun8i-a33.c | 10 +- drivers/clk/sunxi-ng/ccu-sun8i-a83t.c | 911 +++++++++++++++++++++ drivers/clk/sunxi-ng/ccu-sun8i-a83t.h | 64 ++ drivers/clk/sunxi-ng/ccu-sun8i-h3.c | 10 +- drivers/clk/sunxi-ng/ccu-sun8i-r.c | 10 +- drivers/clk/sunxi-ng/ccu-sun8i-v3s.c | 10 +- drivers/clk/sunxi-ng/ccu_mux.c | 15 +- drivers/clk/sunxi-ng/ccu_mux.h | 13 +- drivers/clk/sunxi-ng/ccu_phase.c | 47 ++ drivers/clk/sunxi-ng/ccu_phase.h | 16 + include/dt-bindings/clock/sun8i-a83t-ccu.h | 140 ++++ include/dt-bindings/reset/sun8i-a83t-ccu.h | 98 +++ include/linux/clk-provider.h | 1 + 21 files changed, 1363 insertions(+), 50 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 v2 1/8 dt-bindings: clock: sunxi-ccu: Add compatible string for A83T CCU
The 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.
Like the A80, the SoC does not have a low speed 32.768 kHz oscillator. Unlike the A80, there is no clock input either. The only low speed clock available is the internal oscillator which runs at around 16 MHz, divided by 512, yielding a low speed clock around 31.250 kHz.
--- Documentation/devicetree/bindings/clock/sunxi-ccu.txt | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/clock/sunxi-ccu.txt +2 -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-h3-r-ccu" - "allwinner,sun8i-v3s-ccu"
@@ -18,6 +19,7 @@ Required properties : - clocks: phandle to the oscillators feeding the CCU. Two are needed: - "hosc": the high frequency oscillator (usually at 24MHz) - "losc": the low frequency oscillator (usually at 32kHz) + On the A83T, this is the internal 16MHz oscillator divided by 512 - clock-names: Must contain the clock names described just above - #clock-cells : must contain 1 - #reset-cells : must contain 1
Signature · 1 line
2.11.0
Re: [PATCH v2 1/8] dt-bindings: clock: sunxi-ccu: Add compatible string for A83T CCU
Quoted 8 lines · Chen-Yu Tsai
The 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.
Like the A80, the SoC does not have a low speed 32.768 kHz oscillator. Unlike the A80, there is no clock input either. The only low speed clock available is the internal oscillator which runs at around 16 MHz, divided by 512, yielding a low speed clock around 31.250 kHz.
Quoted 4 lines
Signed-off-by Chen-Yu Tsai <[email protected]>--- Documentation/devicetree/bindings/clock/sunxi-ccu.txt | 2 ++ 1 file changed, 2 insertions(+)
PATCH v2 2/8 clk: Provide option to query hardware for clk phase
In reply to Chen-Yu TsaiOn some hardware, the clk phase is tied to the parent clk's rate and some clk delay programmed into the hardware. As the parent clk rate changes, so does the clk phase.
Add a clk flag specifying not to use the cached clk phase, but always query the hardware for it.
--- drivers/clk/clk.c | 6 +++++- include/linux/clk-provider.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/clk/clk.c +5 -1
@@ -1929,7 +1929,11 @@ static int clk_core_get_phase(struct clk_core *core)int ret;clk_prepare_lock (); - ret = core->phase; +if (core && (core->flags &CLK_GET_PHASE_NOCACHE ) && + core->ops->get_phase) + ret = core->ops->get_phase (core->hw); +else + ret = core->phase;clk_prepare_unlock ();return ret;
include/linux/clk-provider.h +1 -0
@@ -35,6 +35,7 @@#define CLK_IS_CRITICAL BIT(11)/* do not gate, ever */ /* parents need enable during gate/ungate, set rate and re-parent */ #define CLK_OPS_PARENT_ENABLE BIT(12) +#define CLK_GET_PHASE_NOCACHE BIT(13)/* do not use the cached clk phase */ struct clk ;struct clk_hw ;
Signature · 1 line
2.11.0
PATCH v2 3/8 clk: sunxi-ng: Add class of phase clocks supporting MMC new timing modes
In reply to Chen-Yu TsaiThe MMC clocks on newer SoCs, such as the A83T and H3, support the "new timing mode". Under this mode, the output of the clock is divided by 2, and the clock delays no longer apply.
Due to how the clock tree is modeled and setup, we need to model this function in two places, the master mmc clock and the two child phase clocks. In the mmc clock, we can easily model the mode bit as an extra variable post-divider. In the phase clocks, we check the bit and return -ENOTSUPP if the bit is set, signaling that the phase clocks are not to be used.
This patch introduces a class of phase clocks that checks the timing mode bit.
--- drivers/clk/sunxi-ng/ccu_phase.c | 47 ++++++++++++++++++++++++++++++++++++++++ drivers/clk/sunxi-ng/ccu_phase.h | 16 ++++++++++++++ 2 files changed, 63 insertions(+)
drivers/clk/sunxi-ng/ccu_phase.c +47 -0
@@ -8,6 +8,7 @@* the License, or (at your option) any later version. */ +#include <linux/bitops.h> #include <linux/clk-provider.h> #include <linux/spinlock.h>
@@ -124,3 +125,49 @@ const struct clk_ops ccu_phase_ops = { .get_phase = ccu_phase_get_phase, .set_phase = ccu_phase_set_phase, }; + +/* +* The MMC clocks on newer SoCs support the "new timing mode". Under +* this mode, the output of the clock is divided by 2, and the clock +* delays no longer apply. +* +* Due to how the clock tree is modeled and setup, we need to model +* this function in two places, the master mmc clock and the two +* child phase clocks. In the mmc clock, we can easily model the +* mode bit as an extra variable post-divider. In the phase clocks, +* we check the bit and return -ENOTSUPP if the bit is set, signaling +* that the phase clocks are not to be used. +* +* We do not support runtime configuration of the modes. Instead a +* mode is enforced at CCU probe time. +*/ +#define CCU_MMC_NEW_TIMING_MODE BIT(30) + +static int ccu_phase_mmc_new_timing_get_phase (struct clk_hw *hw) +{ +struct ccu_phase *phase =hw_to_ccu_phase (hw); +u32 reg; + + reg =readl (phase->common.base + phase->common.reg); +if (reg &CCU_MMC_NEW_TIMING_MODE ) +return -ENOTSUPP ; + +return ccu_phase_get_phase (hw); +} + +static int ccu_phase_mmc_new_timing_set_phase (struct clk_hw *hw,int degrees) +{ +struct ccu_phase *phase =hw_to_ccu_phase (hw); +u32 reg; + + reg =readl (phase->common.base + phase->common.reg); +if (reg &CCU_MMC_NEW_TIMING_MODE ) +return -ENOTSUPP ; + +return ccu_phase_set_phase (hw, degrees); +} + +const struct clk_ops ccu_phase_mmc_new_timing_ops = { + .get_phase = ccu_phase_mmc_new_timing_get_phase, + .set_phase = ccu_phase_mmc_new_timing_set_phase, +};
drivers/clk/sunxi-ng/ccu_phase.h +16 -0
@@ -38,6 +38,20 @@ struct ccu_phase { } \ } +#define SUNXI_CCU_PHASE_MMC_NEW_TIMING (_struct, _name, _parent, _reg, \ + _shift, _width, _flags) \ + struct ccu_phase _struct = { \ + .shift = _shift, \ + .width = _width, \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT(_name, \ + _parent, \ + &ccu_phase_mmc_new_timing_ops, \ + _flags), \ + } \ + } +static inline struct ccu_phase *hw_to_ccu_phase (struct clk_hw *hw) {struct ccu_common *common =hw_to_ccu_common (hw);
@@ -47,4 +61,6 @@ static inline struct ccu_phase *hw_to_ccu_phase(struct clk_hw *hw)extern const struct clk_ops ccu_phase_ops; +extern const struct clk_ops ccu_phase_mmc_new_timing_ops; +#endif /* _CCU_PHASE_H_ */
Signature · 1 line
2.11.0
Re: [PATCH v2 3/8] clk: sunxi-ng: Add class of phase clocks supporting MMC new timing modes
Hi,
Quoted 11 lines · Chen-Yu Tsai
The MMC clocks on newer SoCs, such as the A83T and H3, support the "new timing mode". Under this mode, the output of the clock is divided by 2, and the clock delays no longer apply.
Due to how the clock tree is modeled and setup, we need to model this function in two places, the master mmc clock and the two child phase clocks. In the mmc clock, we can easily model the mode bit as an extra variable post-divider. In the phase clocks, we check the bit and return
-ENOTSUPPif the bit is set, signaling that the phase clocks are not to be used.
Quoted 2 lines
This patch introduces a class of phase clocks that checks the timing mode bit.
We've been over this quite some times already...
How do you retrieve the mode used in the clock so that you can also switch the MMC driver in the new mode?
And do you prevent that from happening on the DT we already have that use the old clock drivers that do not support this new timing at all?
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/20170503/6acaeeb8/attachment.sig>
Re: [PATCH v2 3/8] clk: sunxi-ng: Add class of phase clocks supporting MMC new timing modes
Hi,
Quoted 14 lines · Maxime Ripard
Hi,
Quoted 11 lines · Chen-Yu Tsai
The MMC clocks on newer SoCs, such as the A83T and H3, support the "new timing mode". Under this mode, the output of the clock is divided by 2, and the clock delays no longer apply.
Due to how the clock tree is modeled and setup, we need to model this function in two places, the master mmc clock and the two child phase clocks. In the mmc clock, we can easily model the mode bit as an extra variable post-divider. In the phase clocks, we check the bit and return
-ENOTSUPPif the bit is set, signaling that the phase clocks are not to be used.
Quoted 7 lines
Quoted 2 lines
This patch introduces a class of phase clocks that checks the timing mode bit.
We've been over this quite some times already...
How do you retrieve the mode used in the clock so that you can also switch the MMC driver in the new mode?
This part is covered. As mentioned above, the phase clks will return -ENOTSUPP if the mmc clk is set in the new timing mode. The MMC driver would try getting the current phase, check if it fails, and if it does, realizes the clk is in new timing mode, and will switch the mmc controller to it as well. I think this semantic fits the hardware well enough, though it might be confusing without the accompanying comments.
See this commit for an example on how it should work.
https://github.com/wens/linux/commit/41e386f1f945a0a135a20a00601b977a001353da
Quoted 2 lines
And do you prevent that from happening on the DT we already have that use the old clock drivers that do not support this new timing at all?
I admit this is not taken care of in this patch. Mostly because there is no existing DT for the A83T to cater to. For the H3 and other SoCs that do, we need some way of asking the CCU to switch the mode.
IIRC the output and sample clocks do not support a phase delay of 0. So what if we design the semantic for this class of clocks as, if phase == 0, switch to new timing mode, otherwise use old timing mode? That would allow us to support this without adding extra functions, and kind of matches what the hardware does. If you're using the new timing mode, the delays in the mmc clk are bypassed.
Regards
ChenYu
Re: [PATCH v2 3/8] clk: sunxi-ng: Add class of phase clocks supporting MMC new timing modes
Quoted 26 lines · Chen-Yu Tsai
Hi,
Quoted 14 lines · Maxime Ripard
Hi,
Quoted 11 lines · Chen-Yu Tsai
The MMC clocks on newer SoCs, such as the A83T and H3, support the "new timing mode". Under this mode, the output of the clock is divided by 2, and the clock delays no longer apply.
Due to how the clock tree is modeled and setup, we need to model this function in two places, the master mmc clock and the two child phase clocks. In the mmc clock, we can easily model the mode bit as an extra variable post-divider. In the phase clocks, we check the bit and return
-ENOTSUPPif the bit is set, signaling that the phase clocks are not to be used.Quoted 7 lines
Quoted 2 lines
This patch introduces a class of phase clocks that checks the timing mode bit.
We've been over this quite some times already...
How do you retrieve the mode used in the clock so that you can also switch the MMC driver in the new mode?
Quoted 6 lines
This part is covered. As mentioned above, the phase clks will return
-ENOTSUPPif the mmc clk is set in the new timing mode. The MMC driver would try getting the current phase, check if it fails, and if it does, realizes the clk is in new timing mode, and will switch the mmc controller to it as well. I think this semantic fits the hardware well enough, though it might be confusing without the accompanying comments.
This is confusing, and impossible to debug without getting your hands in the driver. Triggerring the new mode is also not really something that is rate-based. We might want to switch to it explicitly, without any doubt. This is what we're doing for the A64 for example.
Since some rates can be obtained both in the old and new modes likewise, you don't have that guarantee in the MMC driver and might end up in the old mode, even though you actually want it. And you can't.
Which is why I argued several times for a custom function calls. Every other solutions that we evaluated so far was a hack, at best, and was not entirely predictable and debuggable, which is not a very nice combination.
Quoted 2 lines
See this commit for an example on how it should work.
https://github.com/wens/linux/commit/41e386f1f945a0a135a20a00601b977a001353da
This is unrelated, but it breaks A64. A64 doesn't have the phase clocks at all, and need to be switched to the new mode all the time, without any cooperation from the CCU. Your code will try to change the phase, fail since you don't have any phase clock, and fall back to not using the new mode. I think we need to make a distinction between MMC controllers that can use both the old and new mode (A23, A33, H3, A83T, etc.) and the one that always need to use it (A64 eMMC).
You should also retrieve whether you can use the new mode or not after changing the rate and not at probe time. Each call to clk_set_rate might change that.
Quoted 8 lines
Quoted 2 lines
And do you prevent that from happening on the DT we already have that use the old clock drivers that do not support this new timing at all?
I admit this is not taken care of in this patch. Mostly because there is no existing DT for the A83T to cater to. For the H3 and other SoCs that do, we need some way of asking the CCU to switch the mode.
IIRC the output and sample clocks do not support a phase delay of 0.
That's a weak assumption, since we're not even sure what the phase actually is. My recollection is that it doesn't, but I'm not entirely sure, and both the datasheet and the BSP code are not really clear on that part either.
Quoted 5 lines
So what if we design the semantic for this class of clocks as, if phase == 0, switch to new timing mode, otherwise use old timing mode? That would allow us to support this without adding extra functions, and kind of matches what the hardware does. If you're using the new timing mode, the delays in the mmc clk are bypassed.
To be honest, I have the feeling that it should be a separate discussion.
The whole A83T support has been completely stalled because of a single board's eMMC. This is pretty much a cross-SoC issue, at least 4 other SoCs have that issue already, and we need to deal with this for all of them.
Merging a clock driver without the support for the MMC new mode would just bring us in the same situation than the A33 or H3, which I believe quite good.
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/20170505/fcec826a/attachment.sig>
PATCH v2 4/8 clk: sunxi-ng: Support multiple variable pre-dividers
In reply to Chen-Yu TsaiOn the A83T, the AHB1 clock has a shared pre-divider on the two PLL-PERIPH clock parents. To support such instances of shared pre-dividers, this patch extends the mux clock type to support multiple variable pre-dividers.
As the pre-dividers are only used to calculate the rate, but do not participate in the factorization process, this is fairly straightforward.
--- drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 10 +++++----- drivers/clk/sunxi-ng/ccu-sun6i-a31.c | 10 +++++----- drivers/clk/sunxi-ng/ccu-sun8i-a23.c | 10 +++++----- drivers/clk/sunxi-ng/ccu-sun8i-a33.c | 10 +++++----- drivers/clk/sunxi-ng/ccu-sun8i-h3.c | 10 +++++----- drivers/clk/sunxi-ng/ccu-sun8i-r.c | 10 +++++----- drivers/clk/sunxi-ng/ccu-sun8i-v3s.c | 10 +++++----- drivers/clk/sunxi-ng/ccu_mux.c | 15 ++++++++------- drivers/clk/sunxi-ng/ccu_mux.h | 13 ++++++++----- 9 files changed, 51 insertions(+), 47 deletions(-)
drivers/clk/sunxi-ng/ccu-sun50i-a64.c +5 -5
@@ -211,6 +211,9 @@ static SUNXI_CCU_M(axi_clk, "axi", "cpux", 0x050, 0, 2, 0);static const char *const ahb1_parents[] = {"osc32k" ,"osc24M" ,"axi" ,"pll-periph0" }; +static const struct ccu_mux_var_prediv ahb1_predivs[] = { + { .index =3 , .shift =6 , .width =2 }, +};static struct ccu_div ahb1_clk = { .div =_SUNXI_CCU_DIV_FLAGS (4 ,2 ,CLK_DIVIDER_POWER_OF_TWO ),
@@ -218,11 +221,8 @@ static struct ccu_div ahb1_clk = { .shift = 12, .width = 2, - .variable_prediv = { - .index = 3, - .shift = 6, - .width = 2, - }, + .var_predivs = ahb1_predivs, + .n_var_predivs = ARRAY_SIZE(ahb1_predivs), }, .common = {
drivers/clk/sunxi-ng/ccu-sun6i-a31.c +5 -5
@@ -195,6 +195,9 @@ static SUNXI_CCU_DIV_TABLE(axi_clk, "axi", "cpu",static const char *const ahb1_parents[] = {"osc32k" ,"osc24M" ,"axi" ,"pll-periph" }; +static const struct ccu_mux_var_prediv ahb1_predivs[] = { + { .index =3 , .shift =6 , .width =2 }, +};static struct ccu_div ahb1_clk = { .div =_SUNXI_CCU_DIV_FLAGS (4 ,2 ,CLK_DIVIDER_POWER_OF_TWO ),
@@ -203,11 +206,8 @@ static struct ccu_div ahb1_clk = { .shift = 12, .width = 2, - .variable_prediv = { - .index = 3, - .shift = 6, - .width = 2, - }, + .var_predivs = ahb1_predivs, + .n_var_predivs = ARRAY_SIZE(ahb1_predivs), }, .common = {
drivers/clk/sunxi-ng/ccu-sun8i-a23.c +5 -5
@@ -169,6 +169,9 @@ static SUNXI_CCU_M(axi_clk, "axi", "cpux", 0x050, 0, 2, 0);static const char *const ahb1_parents[] = {"osc32k" ,"osc24M" ,"axi" ,"pll-periph" }; +static const struct ccu_mux_var_prediv ahb1_predivs[] = { + { .index =3 , .shift =6 , .width =2 }, +};static struct ccu_div ahb1_clk = { .div =_SUNXI_CCU_DIV_FLAGS (4 ,2 ,CLK_DIVIDER_POWER_OF_TWO ),
@@ -176,11 +179,8 @@ static struct ccu_div ahb1_clk = { .shift = 12, .width = 2, - .variable_prediv = { - .index = 3, - .shift = 6, - .width = 2, - }, + .var_predivs = ahb1_predivs, + .n_var_predivs = ARRAY_SIZE(ahb1_predivs), }, .common = {
drivers/clk/sunxi-ng/ccu-sun8i-a33.c +5 -5
@@ -180,6 +180,9 @@ static SUNXI_CCU_M(axi_clk, "axi", "cpux", 0x050, 0, 2, 0);static const char *const ahb1_parents[] = {"osc32k" ,"osc24M" ,"axi" ,"pll-periph" }; +static const struct ccu_mux_var_prediv ahb1_predivs[] = { + { .index =3 , .shift =6 , .width =2 }, +};static struct ccu_div ahb1_clk = { .div =_SUNXI_CCU_DIV_FLAGS (4 ,2 ,CLK_DIVIDER_POWER_OF_TWO ),
@@ -187,11 +190,8 @@ static struct ccu_div ahb1_clk = { .shift = 12, .width = 2, - .variable_prediv = { - .index = 3, - .shift = 6, - .width = 2, - }, + .var_predivs = ahb1_predivs, + .n_var_predivs = ARRAY_SIZE(ahb1_predivs), }, .common = {
drivers/clk/sunxi-ng/ccu-sun8i-h3.c +5 -5
@@ -141,6 +141,9 @@ static SUNXI_CCU_M(axi_clk, "axi", "cpux", 0x050, 0, 2, 0);static const char *const ahb1_parents[] = {"osc32k" ,"osc24M" ,"axi" ,"pll-periph0" }; +static const struct ccu_mux_var_prediv ahb1_predivs[] = { + { .index =3 , .shift =6 , .width =2 }, +};static struct ccu_div ahb1_clk = { .div =_SUNXI_CCU_DIV_FLAGS (4 ,2 ,CLK_DIVIDER_POWER_OF_TWO ),
@@ -148,11 +151,8 @@ static struct ccu_div ahb1_clk = { .shift = 12, .width = 2, - .variable_prediv = { - .index = 3, - .shift = 6, - .width = 2, - }, + .var_predivs = ahb1_predivs, + .n_var_predivs = ARRAY_SIZE(ahb1_predivs), }, .common = {
drivers/clk/sunxi-ng/ccu-sun8i-r.c +5 -5
@@ -27,6 +27,9 @@static const char *const ar100_parents[] = {"osc32k" ,"osc24M" ,"pll-periph0" ,"iosc" }; +static const struct ccu_mux_var_prediv ar100_predivs[] = { + { .index =2 , .shift =8 , .width =5 }, +};static struct ccu_div ar100_clk = { .div =_SUNXI_CCU_DIV_FLAGS (4 ,2 ,CLK_DIVIDER_POWER_OF_TWO ),
@@ -35,11 +38,8 @@ static struct ccu_div ar100_clk = { .shift = 16, .width = 2, - .variable_prediv = { - .index = 2, - .shift = 8, - .width = 5, - }, + .var_predivs = ar100_predivs, + .n_var_predivs = ARRAY_SIZE(ar100_predivs), }, .common = {
drivers/clk/sunxi-ng/ccu-sun8i-v3s.c +5 -5
@@ -132,6 +132,9 @@ static SUNXI_CCU_M(axi_clk, "axi", "cpu", 0x050, 0, 2, 0);static const char *const ahb1_parents[] = {"osc32k" ,"osc24M" ,"axi" ,"pll-periph0" }; +static const struct ccu_mux_var_prediv ahb1_predivs[] = { + { .index =3 , .shift =6 , .width =2 }, +};static struct ccu_div ahb1_clk = { .div =_SUNXI_CCU_DIV_FLAGS (4 ,2 ,CLK_DIVIDER_POWER_OF_TWO ),
@@ -139,11 +142,8 @@ static struct ccu_div ahb1_clk = { .shift = 12, .width = 2, - .variable_prediv = { - .index = 3, - .shift = 6, - .width = 2, - }, + .var_predivs = ahb1_predivs, + .n_var_predivs = ARRAY_SIZE(ahb1_predivs), }, .common = {
drivers/clk/sunxi-ng/ccu_mux.c +8 -7
@@ -46,13 +46,14 @@ void ccu_mux_helper_adjust_parent_for_prediv(struct ccu_common *common, prediv = cm->fixed_predivs[i].div;if (common->features &CCU_FEATURE_VARIABLE_PREDIV ) -if (parent_index == cm->variable_prediv.index) { -u8 div; - - div = reg >> cm->variable_prediv.shift; - div &= (1 << cm->variable_prediv.width) -1 ; - prediv = div +1 ; - } +for (i =0 ; i < cm->n_var_predivs; i++) +if (parent_index == cm->var_predivs[i].index) { +u8 div; + + div = reg >> cm->var_predivs[i].shift; + div &= (1 << cm->var_predivs[i].width) -1 ; + prediv = div +1 ; + } *parent_rate = *parent_rate / prediv; }
drivers/clk/sunxi-ng/ccu_mux.h +8 -5
@@ -10,6 +10,12 @@ struct ccu_mux_fixed_prediv {u16 div; }; +struct ccu_mux_var_prediv { +u8 index; +u8 shift; +u8 width; +}; +struct ccu_mux_internal {u8 shift;u8 width;
@@ -18,11 +24,8 @@ struct ccu_mux_internal {const struct ccu_mux_fixed_prediv *fixed_predivs;u8 n_predivs; -struct { -u8 index; -u8 shift; -u8 width; - } variable_prediv; +const struct ccu_mux_var_prediv *var_predivs; +u8 n_var_predivs; };#define _SUNXI_CCU_MUX_TABLE (_shift, _width, _table) \
Signature · 1 line
2.11.0
PATCH v2 5/8 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.
Like the A80, the SoC does not have a low speed 32.768 kHz oscillator. Unlike the A80, there is no clock input either. The only low speed clock available is the internal oscillator which runs at around 16 MHz, divided by 512, yielding a low speed clock around 31.250 kHz.
Also, the MMC2 module clock supports switching to a "new timing" mode. This mode divides the clock output by half, and disables the CCU based clock delays. The MMC controller must be configure to the same mode, and then use its internal clock delays.
This driver does not support runtime switching of the timing modes. Instead, the new timing mode is enforced at probe time. Consumers can check which mode is active by trying to get the current phase delay of the MMC2 phase clocks, which will return -ENOTSUPP if the new timing mode is active.
--- drivers/clk/sunxi-ng/Kconfig | 10 + drivers/clk/sunxi-ng/Makefile | 1 + drivers/clk/sunxi-ng/ccu-sun8i-a83t.c | 911 +++++++++++++++++++++++++++++ drivers/clk/sunxi-ng/ccu-sun8i-a83t.h | 64 ++ include/dt-bindings/clock/sun8i-a83t-ccu.h | 140 +++++ include/dt-bindings/reset/sun8i-a83t-ccu.h | 98 ++++ 6 files changed, 1224 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
@@ -116,6 +116,16 @@ config SUN8I_A33_CCU default MACH_SUN8I depends on MACH_SUN8I || COMPILE_TEST +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_SUN8I_R_CCU) += ccu-sun8i-r.o
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c new file +911 -0
911 lines not on this page · raw message
drivers/clk/sunxi-ng/ccu-sun8i-a83t.h new file +64 -0
64 lines not on this page · raw message
include/dt-bindings/clock/sun8i-a83t-ccu.h new file +140 -0
140 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
PATCH v2 6/8 ARM: 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 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
arch/arm/boot/dts/sun8i-a83t.dtsi +13 -2
@@ -162,13 +162,23 @@ #size-cells = <1>; ranges; + ccu: clock at 1c20000 { + compatible = "allwinner,sun8i-a83t-ccu"; + reg = <0x01c20000 0x400>; + clocks = <&osc24M>, <&osc16Md512>; + clock-names = "hosc", "losc"; + #clock-cells = <1>; + #reset-cells = <1>; + }; + pio: pinctrl at 1c20800 { 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 45>, <&osc24M>, <&osc16Md512>; + clock-names = "apb", "hosc", "losc"; gpio-controller; interrupt-controller; #interrupt-cells = <3>;
@@ -214,7 +224,8 @@ interrupts = <GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>; reg-shift = <2>; reg-io-width = <4>; - clocks = <&osc24M>; + clocks = <&ccu 53>; + resets = <&ccu 40>; status = "disabled"; };
Signature · 1 line
2.11.0
PATCH v2 7/8 ARM: sun8i: a83t: Set clock accuracy for 24MHz oscillator
In reply to Chen-Yu TsaiThe datasheets for Allwinner SoCs set strict requirements on the stability of the external crystal oscillators. Add the accuracy for the main 24MHz oscillator to the device tree.
--- arch/arm/boot/dts/sun8i-a83t.dtsi | 1 + 1 file changed, 1 insertion(+)
arch/arm/boot/dts/sun8i-a83t.dtsi +1 -0
@@ -126,6 +126,7 @@ #clock-cells = <0>; compatible = "fixed-clock"; clock-frequency = <24000000>; + clock-accuracy = <50000>; clock-output-names = "osc24M"; };
Signature · 1 line
2.11.0
PATCH v2 8/8 ARM: sun8i: a83t: Switch to CCU device tree binding macros
In reply to Chen-Yu TsaiNow that the CCU device tree binding headers have been merged, we can use the properly named macros in the device tree, instead of raw numbers.
--- arch/arm/boot/dts/sun8i-a83t.dtsi | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/arm/boot/dts/sun8i-a83t.dtsi +6 -3
@@ -44,6 +44,9 @@ #include <dt-bindings/interrupt-controller/arm-gic.h> +#include <dt-bindings/clock/sun8i-a83t-ccu.h> +#include <dt-bindings/reset/sun8i-a83t-ccu.h> + / { interrupt-parent = <&gic>; #address-cells = <1>;
@@ -178,7 +181,7 @@ <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>, <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>; reg = <0x01c20800 0x400>; - clocks = <&ccu 45>, <&osc24M>, <&osc16Md512>; + clocks = <&ccu CLK_BUS_PIO>, <&osc24M>, <&osc16Md512>; clock-names = "apb", "hosc", "losc"; gpio-controller; interrupt-controller;
@@ -225,8 +228,8 @@ interrupts = <GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>; reg-shift = <2>; reg-io-width = <4>; - clocks = <&ccu 53>; - resets = <&ccu 40>; + clocks = <&ccu CLK_BUS_UART0>; + resets = <&ccu RST_BUS_UART0>; status = "disabled"; };
Signature · 1 line
2.11.0
Quoted 103 lines · Chen-Yu Tsai
Hi everyone,
(Resent with devicetree mailing list CC-ed.) This is v2 of my A83T CCU series. This is for 4.13.
Changes since v1:
- Dropped two patches that were merged
- Added clk core flag to disable caching of clock phases
- Added support for multiple variable pre-dividers
- Merged "pll-periph-ahb1" pre-divider clock into "ahb1" clock with multiple variable pre-dividers
- Introduced new class of phase clocks that return
-ENOTSUPPwhen the clock is in new timing mode- Force mmc2 clock to new timing mode
- Added back mmc2 output and sample clocks
- Fixed bit ops for forcing audio PLL configuration
- Added requirement for "losc" clock in device tree binding
- Stripped leading 0 in device node name
- Updated subject prefixes for various patches
Patch 1 adds a compatible string for the A83T CCU to the sunxi-ccu bindings.
Patch 2 adds a
CLK_GET_PHASE_NOCACHEflag to the clk core, asking it not to cache clock phase values. This is similar toCLK_GET_RATE_NOCACHE. Patch 5 has a compile time dependency on this patch, for the flag value.Patch 3 adds a new class of phase clocks that check the new timing mode bit, and returns an error if it is set, which indicates the phase delays no longer apply. This is a clean way to signal which timing mode the mmc clock is in, without using any custom functions or callbacks. We don't support runtime switching of modes.
Patch 4 adds support for multiple variable pre-dividers to the sunxi-ng mux class.
Patch 5 adds the driver for the A83T CCU.
Patch 6 adds the CCU device nodes, and fixes up any existing clock phandles in the dtsi, without using the macros.
Patch 7 sets the clock accuracy for the main oscillator.
Patch 8 is for the next -rc2, switch the clock indices from raw numbers to macros we introduced with the driver. This will be updated if more peripherals are introduced in the same cycle.
Let me know what you think.
Cover letter excerpt from v1:
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 clockRegards
ChenYuChen-Yu Tsai (8):
dt-bindings: clock: sunxi-ccu: Add compatible string for A83T CCU
clk: Provide option to query hardware for clk phase
clk: sunxi-ng: Add class of phase clocks supporting MMC new timing
modes
clk: sunxi-ng: Support multiple variable pre-dividers
clk: sunxi-ng: Add driver for A83T CCU
ARM: sun8i: a83t: Add CCU device nodes
ARM: sun8i: a83t: Set clock accuracy for 24MHz oscillator
ARM: sun8i: a83t: Switch to CCU device tree binding macros.../devicetree/bindings/clock/sunxi-ccu.txt | 2 + arch/arm/boot/dts/sun8i-a83t.dtsi | 19 +- drivers/clk/clk.c | 6 +- drivers/clk/sunxi-ng/Kconfig | 10 + drivers/clk/sunxi-ng/Makefile | 1 + drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 10 +- drivers/clk/sunxi-ng/ccu-sun6i-a31.c | 10 +- drivers/clk/sunxi-ng/ccu-sun8i-a23.c | 10 +- drivers/clk/sunxi-ng/ccu-sun8i-a33.c | 10 +- drivers/clk/sunxi-ng/ccu-sun8i-a83t.c | 911 +++++++++++++++++++++ drivers/clk/sunxi-ng/ccu-sun8i-a83t.h | 64 ++ drivers/clk/sunxi-ng/ccu-sun8i-h3.c | 10 +- drivers/clk/sunxi-ng/ccu-sun8i-r.c | 10 +- drivers/clk/sunxi-ng/ccu-sun8i-v3s.c | 10 +- drivers/clk/sunxi-ng/ccu_mux.c | 15 +- drivers/clk/sunxi-ng/ccu_mux.h | 13 +- drivers/clk/sunxi-ng/ccu_phase.c | 47 ++ drivers/clk/sunxi-ng/ccu_phase.h | 16 +
Quoted 9 lines
include/dt-bindings/clock/sun8i-a83t-ccu.h | 140 ++++ include/dt-bindings/reset/sun8i-a83t-ccu.h | 98 +++ include/linux/clk-provider.h | 1 + 21 files changed, 1363 insertions(+), 50 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