clk: sunxi-ng: Add support for A83T CCU
Subsystems (4)
v4 cover clk: sunxi-ng: Add support for A83T CCU
Hi everyone,
This is v4 of my A83T CCU series. This is for 4.13.
Changes since v3:
- Dropped predivider for new timing mode on mmc2 clock. Replaced with a TODO note for new timing mode support. This is the last trace of new timing mode code.
- Simplified PLL_CPUx clocks into multiplier clocks, just like we did for the A80. At probe time the extra P dividers are forced to /1. These P dividers should only be used for clock rates under 288 MHz, and never used by the boot loader or the BSP kernel.
Changes since v2:
- Dropped patches "clk: Provide option to query hardware for clk phase" and "clk: sunxi-ng: Add class of phase clocks supporting MMC new timing modes".
- Dropped support for MMC new timing mode. This will be added later with MMC support. The goal for this series is to get clk support for the A83t in. This is long overdue.
- Explicitly include ccu_mux.h and select SUNXI_CCU_MUX
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 support for multiple variable pre-dividers to the sunxi-ng mux class.
Patch 3 adds the driver for the A83T CCU.
Patch 4 adds the CCU device nodes, and fixes up any existing clock phandles in the dtsi, without using the macros.
Patch 5 sets the clock accuracy for the main oscillator.
Patch 6 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 (6):
dt-bindings: clock: sunxi-ccu: Add compatible string for A83T CCU
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/sunxi-ng/Kconfig | 11 + 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 | 922 +++++++++++++++++++++ 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 +- include/dt-bindings/clock/sun8i-a83t-ccu.h | 140 ++++ include/dt-bindings/reset/sun8i-a83t-ccu.h | 98 +++ 17 files changed, 1306 insertions(+), 49 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 v4 1/6 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
PATCH v4 2/6 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 v4 3/6 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 | 11 + drivers/clk/sunxi-ng/Makefile | 1 + drivers/clk/sunxi-ng/ccu-sun8i-a83t.c | 922 +++++++++++++++++++++++++++++ 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, 1236 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 +11 -0
@@ -116,6 +116,17 @@ 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_MP + select SUNXI_CCU_MUX + select SUNXI_CCU_NKMP + select SUNXI_CCU_NM + 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_DE2_CCU) += ccu-sun8i-de2.o
drivers/clk/sunxi-ng/ccu-sun8i-a83t.c new file +922 -0
922 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 v4 4/6 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 v4 5/6 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 v4 6/6 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
Hi,
Quoted 3 lines · Chen-Yu Tsai
Hi everyone,
This is v4 of my A83T CCU series. This is for 4.13.
Applied the patches 1-5. Can you resubmit patch 6 after 4.13-rc1 ?
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/20170519/5cbaa70a/attachment.sig>