19c92ab61SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2cdb8b80bSIcenowy Zheng /* 3cdb8b80bSIcenowy Zheng * Copyright (c) 2016 Icenowy Zheng <icenowy@aosc.xyz> 4cdb8b80bSIcenowy Zheng */ 5cdb8b80bSIcenowy Zheng 6cdb8b80bSIcenowy Zheng #include <linux/clk-provider.h> 7cdb8b80bSIcenowy Zheng #include <linux/of_address.h> 8cdb8b80bSIcenowy Zheng #include <linux/platform_device.h> 9cdb8b80bSIcenowy Zheng 10cdb8b80bSIcenowy Zheng #include "ccu_common.h" 11cdb8b80bSIcenowy Zheng #include "ccu_reset.h" 12cdb8b80bSIcenowy Zheng 13cdb8b80bSIcenowy Zheng #include "ccu_div.h" 14cdb8b80bSIcenowy Zheng #include "ccu_gate.h" 15cdb8b80bSIcenowy Zheng #include "ccu_mp.h" 16cdb8b80bSIcenowy Zheng #include "ccu_nm.h" 17cdb8b80bSIcenowy Zheng 18cdb8b80bSIcenowy Zheng #include "ccu-sun8i-r.h" 19cdb8b80bSIcenowy Zheng 206873d207SChen-Yu Tsai static const struct clk_parent_data ar100_parents[] = { 216873d207SChen-Yu Tsai { .fw_name = "losc" }, 226873d207SChen-Yu Tsai { .fw_name = "hosc" }, 236873d207SChen-Yu Tsai { .fw_name = "pll-periph" }, 246873d207SChen-Yu Tsai { .fw_name = "iosc" }, 256873d207SChen-Yu Tsai }; 266873d207SChen-Yu Tsai 2713e0dde8SChen-Yu Tsai static const struct ccu_mux_var_prediv ar100_predivs[] = { 2813e0dde8SChen-Yu Tsai { .index = 2, .shift = 8, .width = 5 }, 2913e0dde8SChen-Yu Tsai }; 30cdb8b80bSIcenowy Zheng 31cdb8b80bSIcenowy Zheng static struct ccu_div ar100_clk = { 32cdb8b80bSIcenowy Zheng .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO), 33cdb8b80bSIcenowy Zheng 34cdb8b80bSIcenowy Zheng .mux = { 35cdb8b80bSIcenowy Zheng .shift = 16, 36cdb8b80bSIcenowy Zheng .width = 2, 37cdb8b80bSIcenowy Zheng 3813e0dde8SChen-Yu Tsai .var_predivs = ar100_predivs, 3913e0dde8SChen-Yu Tsai .n_var_predivs = ARRAY_SIZE(ar100_predivs), 40cdb8b80bSIcenowy Zheng }, 41cdb8b80bSIcenowy Zheng 42cdb8b80bSIcenowy Zheng .common = { 43cdb8b80bSIcenowy Zheng .reg = 0x00, 44cdb8b80bSIcenowy Zheng .features = CCU_FEATURE_VARIABLE_PREDIV, 456873d207SChen-Yu Tsai .hw.init = CLK_HW_INIT_PARENTS_DATA("ar100", 46cdb8b80bSIcenowy Zheng ar100_parents, 47cdb8b80bSIcenowy Zheng &ccu_div_ops, 48cdb8b80bSIcenowy Zheng 0), 49cdb8b80bSIcenowy Zheng }, 50cdb8b80bSIcenowy Zheng }; 51cdb8b80bSIcenowy Zheng 5245d0706eSChen-Yu Tsai static CLK_FIXED_FACTOR_HW(ahb0_clk, "ahb0", &ar100_clk.common.hw, 1, 1, 0); 53cdb8b80bSIcenowy Zheng 54*47d64fefSSamuel Holland static SUNXI_CCU_M(apb0_clk, "apb0", "ahb0", 0x0c, 0, 2, 0); 555a90c14cSChen-Yu Tsai 5689f27fb2SChen-Yu Tsai /* 5789f27fb2SChen-Yu Tsai * Define the parent as an array that can be reused to save space 5889f27fb2SChen-Yu Tsai * instead of having compound literals for each gate. Also have it 5989f27fb2SChen-Yu Tsai * non-const so we can change it on the A83T. 6089f27fb2SChen-Yu Tsai */ 6189f27fb2SChen-Yu Tsai static const struct clk_hw *apb0_gate_parent[] = { &apb0_clk.common.hw }; 6289f27fb2SChen-Yu Tsai static SUNXI_CCU_GATE_HWS(apb0_pio_clk, "apb0-pio", 6389f27fb2SChen-Yu Tsai apb0_gate_parent, 0x28, BIT(0), 0); 6489f27fb2SChen-Yu Tsai static SUNXI_CCU_GATE_HWS(apb0_ir_clk, "apb0-ir", 6589f27fb2SChen-Yu Tsai apb0_gate_parent, 0x28, BIT(1), 0); 6689f27fb2SChen-Yu Tsai static SUNXI_CCU_GATE_HWS(apb0_timer_clk, "apb0-timer", 6789f27fb2SChen-Yu Tsai apb0_gate_parent, 0x28, BIT(2), 0); 6889f27fb2SChen-Yu Tsai static SUNXI_CCU_GATE_HWS(apb0_rsb_clk, "apb0-rsb", 6989f27fb2SChen-Yu Tsai apb0_gate_parent, 0x28, BIT(3), 0); 7089f27fb2SChen-Yu Tsai static SUNXI_CCU_GATE_HWS(apb0_uart_clk, "apb0-uart", 7189f27fb2SChen-Yu Tsai apb0_gate_parent, 0x28, BIT(4), 0); 7289f27fb2SChen-Yu Tsai static SUNXI_CCU_GATE_HWS(apb0_i2c_clk, "apb0-i2c", 7389f27fb2SChen-Yu Tsai apb0_gate_parent, 0x28, BIT(6), 0); 7489f27fb2SChen-Yu Tsai static SUNXI_CCU_GATE_HWS(apb0_twd_clk, "apb0-twd", 7589f27fb2SChen-Yu Tsai apb0_gate_parent, 0x28, BIT(7), 0); 76cdb8b80bSIcenowy Zheng 7737cabc74SIcenowy Zheng static const char * const r_mod0_default_parents[] = { "osc32k", "osc24M" }; 78cdb8b80bSIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(ir_clk, "ir", 79cdb8b80bSIcenowy Zheng r_mod0_default_parents, 0x54, 80cdb8b80bSIcenowy Zheng 0, 4, /* M */ 81cdb8b80bSIcenowy Zheng 16, 2, /* P */ 82cdb8b80bSIcenowy Zheng 24, 2, /* mux */ 83cdb8b80bSIcenowy Zheng BIT(31), /* gate */ 84cdb8b80bSIcenowy Zheng 0); 85cdb8b80bSIcenowy Zheng 866873d207SChen-Yu Tsai static const struct clk_parent_data a83t_r_mod0_parents[] = { 876873d207SChen-Yu Tsai { .fw_name = "iosc" }, 886873d207SChen-Yu Tsai { .fw_name = "hosc" }, 896873d207SChen-Yu Tsai }; 905a90c14cSChen-Yu Tsai static const struct ccu_mux_fixed_prediv a83t_ir_predivs[] = { 915a90c14cSChen-Yu Tsai { .index = 0, .div = 16 }, 925a90c14cSChen-Yu Tsai }; 935a90c14cSChen-Yu Tsai static struct ccu_mp a83t_ir_clk = { 945a90c14cSChen-Yu Tsai .enable = BIT(31), 955a90c14cSChen-Yu Tsai 965a90c14cSChen-Yu Tsai .m = _SUNXI_CCU_DIV(0, 4), 975a90c14cSChen-Yu Tsai .p = _SUNXI_CCU_DIV(16, 2), 985a90c14cSChen-Yu Tsai 995a90c14cSChen-Yu Tsai .mux = { 1005a90c14cSChen-Yu Tsai .shift = 24, 1015a90c14cSChen-Yu Tsai .width = 2, 1025a90c14cSChen-Yu Tsai .fixed_predivs = a83t_ir_predivs, 1035a90c14cSChen-Yu Tsai .n_predivs = ARRAY_SIZE(a83t_ir_predivs), 1045a90c14cSChen-Yu Tsai }, 1055a90c14cSChen-Yu Tsai 1065a90c14cSChen-Yu Tsai .common = { 1075a90c14cSChen-Yu Tsai .reg = 0x54, 1085a90c14cSChen-Yu Tsai .features = CCU_FEATURE_VARIABLE_PREDIV, 1096873d207SChen-Yu Tsai .hw.init = CLK_HW_INIT_PARENTS_DATA("ir", 1105a90c14cSChen-Yu Tsai a83t_r_mod0_parents, 1115a90c14cSChen-Yu Tsai &ccu_mp_ops, 1125a90c14cSChen-Yu Tsai 0), 1135a90c14cSChen-Yu Tsai }, 1145a90c14cSChen-Yu Tsai }; 1155a90c14cSChen-Yu Tsai 1165a90c14cSChen-Yu Tsai static struct ccu_common *sun8i_a83t_r_ccu_clks[] = { 1176873d207SChen-Yu Tsai &ar100_clk.common, 118*47d64fefSSamuel Holland &apb0_clk.common, 1195a90c14cSChen-Yu Tsai &apb0_pio_clk.common, 1205a90c14cSChen-Yu Tsai &apb0_ir_clk.common, 1215a90c14cSChen-Yu Tsai &apb0_timer_clk.common, 1225a90c14cSChen-Yu Tsai &apb0_rsb_clk.common, 1235a90c14cSChen-Yu Tsai &apb0_uart_clk.common, 1245a90c14cSChen-Yu Tsai &apb0_i2c_clk.common, 1255a90c14cSChen-Yu Tsai &apb0_twd_clk.common, 1265a90c14cSChen-Yu Tsai &a83t_ir_clk.common, 1275a90c14cSChen-Yu Tsai }; 1285a90c14cSChen-Yu Tsai 129cdb8b80bSIcenowy Zheng static struct ccu_common *sun8i_h3_r_ccu_clks[] = { 130cdb8b80bSIcenowy Zheng &ar100_clk.common, 131cdb8b80bSIcenowy Zheng &apb0_clk.common, 132cdb8b80bSIcenowy Zheng &apb0_pio_clk.common, 133cdb8b80bSIcenowy Zheng &apb0_ir_clk.common, 134cdb8b80bSIcenowy Zheng &apb0_timer_clk.common, 135cdb8b80bSIcenowy Zheng &apb0_uart_clk.common, 136cdb8b80bSIcenowy Zheng &apb0_i2c_clk.common, 137cdb8b80bSIcenowy Zheng &apb0_twd_clk.common, 138cdb8b80bSIcenowy Zheng &ir_clk.common, 139cdb8b80bSIcenowy Zheng }; 140cdb8b80bSIcenowy Zheng 141cdb8b80bSIcenowy Zheng static struct ccu_common *sun50i_a64_r_ccu_clks[] = { 142cdb8b80bSIcenowy Zheng &ar100_clk.common, 143cdb8b80bSIcenowy Zheng &apb0_clk.common, 144cdb8b80bSIcenowy Zheng &apb0_pio_clk.common, 145cdb8b80bSIcenowy Zheng &apb0_ir_clk.common, 146cdb8b80bSIcenowy Zheng &apb0_timer_clk.common, 147cdb8b80bSIcenowy Zheng &apb0_rsb_clk.common, 148cdb8b80bSIcenowy Zheng &apb0_uart_clk.common, 149cdb8b80bSIcenowy Zheng &apb0_i2c_clk.common, 150cdb8b80bSIcenowy Zheng &apb0_twd_clk.common, 151cdb8b80bSIcenowy Zheng &ir_clk.common, 152cdb8b80bSIcenowy Zheng }; 153cdb8b80bSIcenowy Zheng 1545a90c14cSChen-Yu Tsai static struct clk_hw_onecell_data sun8i_a83t_r_hw_clks = { 1555a90c14cSChen-Yu Tsai .hws = { 1566873d207SChen-Yu Tsai [CLK_AR100] = &ar100_clk.common.hw, 1575a90c14cSChen-Yu Tsai [CLK_AHB0] = &ahb0_clk.hw, 158*47d64fefSSamuel Holland [CLK_APB0] = &apb0_clk.common.hw, 1595a90c14cSChen-Yu Tsai [CLK_APB0_PIO] = &apb0_pio_clk.common.hw, 1605a90c14cSChen-Yu Tsai [CLK_APB0_IR] = &apb0_ir_clk.common.hw, 1615a90c14cSChen-Yu Tsai [CLK_APB0_TIMER] = &apb0_timer_clk.common.hw, 1625a90c14cSChen-Yu Tsai [CLK_APB0_RSB] = &apb0_rsb_clk.common.hw, 1635a90c14cSChen-Yu Tsai [CLK_APB0_UART] = &apb0_uart_clk.common.hw, 1645a90c14cSChen-Yu Tsai [CLK_APB0_I2C] = &apb0_i2c_clk.common.hw, 1655a90c14cSChen-Yu Tsai [CLK_APB0_TWD] = &apb0_twd_clk.common.hw, 1665a90c14cSChen-Yu Tsai [CLK_IR] = &a83t_ir_clk.common.hw, 1675a90c14cSChen-Yu Tsai }, 1685a90c14cSChen-Yu Tsai .num = CLK_NUMBER, 1695a90c14cSChen-Yu Tsai }; 1705a90c14cSChen-Yu Tsai 171cdb8b80bSIcenowy Zheng static struct clk_hw_onecell_data sun8i_h3_r_hw_clks = { 172cdb8b80bSIcenowy Zheng .hws = { 173cdb8b80bSIcenowy Zheng [CLK_AR100] = &ar100_clk.common.hw, 174cdb8b80bSIcenowy Zheng [CLK_AHB0] = &ahb0_clk.hw, 175cdb8b80bSIcenowy Zheng [CLK_APB0] = &apb0_clk.common.hw, 176cdb8b80bSIcenowy Zheng [CLK_APB0_PIO] = &apb0_pio_clk.common.hw, 177cdb8b80bSIcenowy Zheng [CLK_APB0_IR] = &apb0_ir_clk.common.hw, 178cdb8b80bSIcenowy Zheng [CLK_APB0_TIMER] = &apb0_timer_clk.common.hw, 179cdb8b80bSIcenowy Zheng [CLK_APB0_UART] = &apb0_uart_clk.common.hw, 180cdb8b80bSIcenowy Zheng [CLK_APB0_I2C] = &apb0_i2c_clk.common.hw, 181cdb8b80bSIcenowy Zheng [CLK_APB0_TWD] = &apb0_twd_clk.common.hw, 182cdb8b80bSIcenowy Zheng [CLK_IR] = &ir_clk.common.hw, 183cdb8b80bSIcenowy Zheng }, 184cdb8b80bSIcenowy Zheng .num = CLK_NUMBER, 185cdb8b80bSIcenowy Zheng }; 186cdb8b80bSIcenowy Zheng 187cdb8b80bSIcenowy Zheng static struct clk_hw_onecell_data sun50i_a64_r_hw_clks = { 188cdb8b80bSIcenowy Zheng .hws = { 189cdb8b80bSIcenowy Zheng [CLK_AR100] = &ar100_clk.common.hw, 190cdb8b80bSIcenowy Zheng [CLK_AHB0] = &ahb0_clk.hw, 191cdb8b80bSIcenowy Zheng [CLK_APB0] = &apb0_clk.common.hw, 192cdb8b80bSIcenowy Zheng [CLK_APB0_PIO] = &apb0_pio_clk.common.hw, 193cdb8b80bSIcenowy Zheng [CLK_APB0_IR] = &apb0_ir_clk.common.hw, 194cdb8b80bSIcenowy Zheng [CLK_APB0_TIMER] = &apb0_timer_clk.common.hw, 195cdb8b80bSIcenowy Zheng [CLK_APB0_RSB] = &apb0_rsb_clk.common.hw, 196cdb8b80bSIcenowy Zheng [CLK_APB0_UART] = &apb0_uart_clk.common.hw, 197cdb8b80bSIcenowy Zheng [CLK_APB0_I2C] = &apb0_i2c_clk.common.hw, 198cdb8b80bSIcenowy Zheng [CLK_APB0_TWD] = &apb0_twd_clk.common.hw, 199cdb8b80bSIcenowy Zheng [CLK_IR] = &ir_clk.common.hw, 200cdb8b80bSIcenowy Zheng }, 201cdb8b80bSIcenowy Zheng .num = CLK_NUMBER, 202cdb8b80bSIcenowy Zheng }; 203cdb8b80bSIcenowy Zheng 2045a90c14cSChen-Yu Tsai static struct ccu_reset_map sun8i_a83t_r_ccu_resets[] = { 2055a90c14cSChen-Yu Tsai [RST_APB0_IR] = { 0xb0, BIT(1) }, 2065a90c14cSChen-Yu Tsai [RST_APB0_TIMER] = { 0xb0, BIT(2) }, 2075a90c14cSChen-Yu Tsai [RST_APB0_RSB] = { 0xb0, BIT(3) }, 2085a90c14cSChen-Yu Tsai [RST_APB0_UART] = { 0xb0, BIT(4) }, 2095a90c14cSChen-Yu Tsai [RST_APB0_I2C] = { 0xb0, BIT(6) }, 2105a90c14cSChen-Yu Tsai }; 2115a90c14cSChen-Yu Tsai 212cdb8b80bSIcenowy Zheng static struct ccu_reset_map sun8i_h3_r_ccu_resets[] = { 213cdb8b80bSIcenowy Zheng [RST_APB0_IR] = { 0xb0, BIT(1) }, 214cdb8b80bSIcenowy Zheng [RST_APB0_TIMER] = { 0xb0, BIT(2) }, 215cdb8b80bSIcenowy Zheng [RST_APB0_UART] = { 0xb0, BIT(4) }, 216cdb8b80bSIcenowy Zheng [RST_APB0_I2C] = { 0xb0, BIT(6) }, 217cdb8b80bSIcenowy Zheng }; 218cdb8b80bSIcenowy Zheng 219cdb8b80bSIcenowy Zheng static struct ccu_reset_map sun50i_a64_r_ccu_resets[] = { 220cdb8b80bSIcenowy Zheng [RST_APB0_IR] = { 0xb0, BIT(1) }, 221cdb8b80bSIcenowy Zheng [RST_APB0_TIMER] = { 0xb0, BIT(2) }, 222cdb8b80bSIcenowy Zheng [RST_APB0_RSB] = { 0xb0, BIT(3) }, 223cdb8b80bSIcenowy Zheng [RST_APB0_UART] = { 0xb0, BIT(4) }, 224cdb8b80bSIcenowy Zheng [RST_APB0_I2C] = { 0xb0, BIT(6) }, 225cdb8b80bSIcenowy Zheng }; 226cdb8b80bSIcenowy Zheng 2275a90c14cSChen-Yu Tsai static const struct sunxi_ccu_desc sun8i_a83t_r_ccu_desc = { 2285a90c14cSChen-Yu Tsai .ccu_clks = sun8i_a83t_r_ccu_clks, 2295a90c14cSChen-Yu Tsai .num_ccu_clks = ARRAY_SIZE(sun8i_a83t_r_ccu_clks), 2305a90c14cSChen-Yu Tsai 2315a90c14cSChen-Yu Tsai .hw_clks = &sun8i_a83t_r_hw_clks, 2325a90c14cSChen-Yu Tsai 2335a90c14cSChen-Yu Tsai .resets = sun8i_a83t_r_ccu_resets, 2345a90c14cSChen-Yu Tsai .num_resets = ARRAY_SIZE(sun8i_a83t_r_ccu_resets), 2355a90c14cSChen-Yu Tsai }; 2365a90c14cSChen-Yu Tsai 237cdb8b80bSIcenowy Zheng static const struct sunxi_ccu_desc sun8i_h3_r_ccu_desc = { 238cdb8b80bSIcenowy Zheng .ccu_clks = sun8i_h3_r_ccu_clks, 239cdb8b80bSIcenowy Zheng .num_ccu_clks = ARRAY_SIZE(sun8i_h3_r_ccu_clks), 240cdb8b80bSIcenowy Zheng 241cdb8b80bSIcenowy Zheng .hw_clks = &sun8i_h3_r_hw_clks, 242cdb8b80bSIcenowy Zheng 243cdb8b80bSIcenowy Zheng .resets = sun8i_h3_r_ccu_resets, 244cdb8b80bSIcenowy Zheng .num_resets = ARRAY_SIZE(sun8i_h3_r_ccu_resets), 245cdb8b80bSIcenowy Zheng }; 246cdb8b80bSIcenowy Zheng 247cdb8b80bSIcenowy Zheng static const struct sunxi_ccu_desc sun50i_a64_r_ccu_desc = { 248cdb8b80bSIcenowy Zheng .ccu_clks = sun50i_a64_r_ccu_clks, 249cdb8b80bSIcenowy Zheng .num_ccu_clks = ARRAY_SIZE(sun50i_a64_r_ccu_clks), 250cdb8b80bSIcenowy Zheng 251cdb8b80bSIcenowy Zheng .hw_clks = &sun50i_a64_r_hw_clks, 252cdb8b80bSIcenowy Zheng 253cdb8b80bSIcenowy Zheng .resets = sun50i_a64_r_ccu_resets, 254cdb8b80bSIcenowy Zheng .num_resets = ARRAY_SIZE(sun50i_a64_r_ccu_resets), 255cdb8b80bSIcenowy Zheng }; 256cdb8b80bSIcenowy Zheng 257cdb8b80bSIcenowy Zheng static void __init sunxi_r_ccu_init(struct device_node *node, 258cdb8b80bSIcenowy Zheng const struct sunxi_ccu_desc *desc) 259cdb8b80bSIcenowy Zheng { 260cdb8b80bSIcenowy Zheng void __iomem *reg; 261cdb8b80bSIcenowy Zheng 262cdb8b80bSIcenowy Zheng reg = of_io_request_and_map(node, 0, of_node_full_name(node)); 263cdb8b80bSIcenowy Zheng if (IS_ERR(reg)) { 26416673931SRob Herring pr_err("%pOF: Could not map the clock registers\n", node); 265cdb8b80bSIcenowy Zheng return; 266cdb8b80bSIcenowy Zheng } 267cdb8b80bSIcenowy Zheng 268cdb8b80bSIcenowy Zheng sunxi_ccu_probe(node, reg, desc); 269cdb8b80bSIcenowy Zheng } 270cdb8b80bSIcenowy Zheng 2715a90c14cSChen-Yu Tsai static void __init sun8i_a83t_r_ccu_setup(struct device_node *node) 2725a90c14cSChen-Yu Tsai { 2735a90c14cSChen-Yu Tsai sunxi_r_ccu_init(node, &sun8i_a83t_r_ccu_desc); 2745a90c14cSChen-Yu Tsai } 2755a90c14cSChen-Yu Tsai CLK_OF_DECLARE(sun8i_a83t_r_ccu, "allwinner,sun8i-a83t-r-ccu", 2765a90c14cSChen-Yu Tsai sun8i_a83t_r_ccu_setup); 2775a90c14cSChen-Yu Tsai 278cdb8b80bSIcenowy Zheng static void __init sun8i_h3_r_ccu_setup(struct device_node *node) 279cdb8b80bSIcenowy Zheng { 280cdb8b80bSIcenowy Zheng sunxi_r_ccu_init(node, &sun8i_h3_r_ccu_desc); 281cdb8b80bSIcenowy Zheng } 282cdb8b80bSIcenowy Zheng CLK_OF_DECLARE(sun8i_h3_r_ccu, "allwinner,sun8i-h3-r-ccu", 283cdb8b80bSIcenowy Zheng sun8i_h3_r_ccu_setup); 284cdb8b80bSIcenowy Zheng 285cdb8b80bSIcenowy Zheng static void __init sun50i_a64_r_ccu_setup(struct device_node *node) 286cdb8b80bSIcenowy Zheng { 287cdb8b80bSIcenowy Zheng sunxi_r_ccu_init(node, &sun50i_a64_r_ccu_desc); 288cdb8b80bSIcenowy Zheng } 289cdb8b80bSIcenowy Zheng CLK_OF_DECLARE(sun50i_a64_r_ccu, "allwinner,sun50i-a64-r-ccu", 290cdb8b80bSIcenowy Zheng sun50i_a64_r_ccu_setup); 291