1*b7c7b050SIcenowy Zheng // SPDX-License-Identifier: GPL-2.0 2*b7c7b050SIcenowy Zheng /* 3*b7c7b050SIcenowy Zheng * Copyright (c) 2017 Icenowy Zheng <icenowy@aosc.xyz> 4*b7c7b050SIcenowy Zheng */ 5*b7c7b050SIcenowy Zheng 6*b7c7b050SIcenowy Zheng #include <linux/clk-provider.h> 7*b7c7b050SIcenowy Zheng #include <linux/of_address.h> 8*b7c7b050SIcenowy Zheng #include <linux/platform_device.h> 9*b7c7b050SIcenowy Zheng 10*b7c7b050SIcenowy Zheng #include "ccu_common.h" 11*b7c7b050SIcenowy Zheng #include "ccu_reset.h" 12*b7c7b050SIcenowy Zheng 13*b7c7b050SIcenowy Zheng #include "ccu_div.h" 14*b7c7b050SIcenowy Zheng #include "ccu_gate.h" 15*b7c7b050SIcenowy Zheng #include "ccu_mp.h" 16*b7c7b050SIcenowy Zheng #include "ccu_nm.h" 17*b7c7b050SIcenowy Zheng 18*b7c7b050SIcenowy Zheng #include "ccu-sun50i-h6-r.h" 19*b7c7b050SIcenowy Zheng 20*b7c7b050SIcenowy Zheng /* 21*b7c7b050SIcenowy Zheng * Information about AR100 and AHB/APB clocks in R_CCU are gathered from 22*b7c7b050SIcenowy Zheng * clock definitions in the BSP source code. 23*b7c7b050SIcenowy Zheng */ 24*b7c7b050SIcenowy Zheng 25*b7c7b050SIcenowy Zheng static const char * const ar100_r_apb2_parents[] = { "osc24M", "osc32k", 26*b7c7b050SIcenowy Zheng "pll-periph0", "iosc" }; 27*b7c7b050SIcenowy Zheng static const struct ccu_mux_var_prediv ar100_r_apb2_predivs[] = { 28*b7c7b050SIcenowy Zheng { .index = 2, .shift = 0, .width = 5 }, 29*b7c7b050SIcenowy Zheng }; 30*b7c7b050SIcenowy Zheng 31*b7c7b050SIcenowy Zheng static struct ccu_div ar100_clk = { 32*b7c7b050SIcenowy Zheng .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO), 33*b7c7b050SIcenowy Zheng 34*b7c7b050SIcenowy Zheng .mux = { 35*b7c7b050SIcenowy Zheng .shift = 24, 36*b7c7b050SIcenowy Zheng .width = 2, 37*b7c7b050SIcenowy Zheng 38*b7c7b050SIcenowy Zheng .var_predivs = ar100_r_apb2_predivs, 39*b7c7b050SIcenowy Zheng .n_var_predivs = ARRAY_SIZE(ar100_r_apb2_predivs), 40*b7c7b050SIcenowy Zheng }, 41*b7c7b050SIcenowy Zheng 42*b7c7b050SIcenowy Zheng .common = { 43*b7c7b050SIcenowy Zheng .reg = 0x000, 44*b7c7b050SIcenowy Zheng .features = CCU_FEATURE_VARIABLE_PREDIV, 45*b7c7b050SIcenowy Zheng .hw.init = CLK_HW_INIT_PARENTS("ar100", 46*b7c7b050SIcenowy Zheng ar100_r_apb2_parents, 47*b7c7b050SIcenowy Zheng &ccu_div_ops, 48*b7c7b050SIcenowy Zheng 0), 49*b7c7b050SIcenowy Zheng }, 50*b7c7b050SIcenowy Zheng }; 51*b7c7b050SIcenowy Zheng 52*b7c7b050SIcenowy Zheng static CLK_FIXED_FACTOR(r_ahb_clk, "r-ahb", "ar100", 1, 1, 0); 53*b7c7b050SIcenowy Zheng 54*b7c7b050SIcenowy Zheng static struct ccu_div r_apb1_clk = { 55*b7c7b050SIcenowy Zheng .div = _SUNXI_CCU_DIV(0, 2), 56*b7c7b050SIcenowy Zheng 57*b7c7b050SIcenowy Zheng .common = { 58*b7c7b050SIcenowy Zheng .reg = 0x00c, 59*b7c7b050SIcenowy Zheng .hw.init = CLK_HW_INIT("r-apb1", 60*b7c7b050SIcenowy Zheng "r-ahb", 61*b7c7b050SIcenowy Zheng &ccu_div_ops, 62*b7c7b050SIcenowy Zheng 0), 63*b7c7b050SIcenowy Zheng }, 64*b7c7b050SIcenowy Zheng }; 65*b7c7b050SIcenowy Zheng 66*b7c7b050SIcenowy Zheng static struct ccu_div r_apb2_clk = { 67*b7c7b050SIcenowy Zheng .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO), 68*b7c7b050SIcenowy Zheng 69*b7c7b050SIcenowy Zheng .mux = { 70*b7c7b050SIcenowy Zheng .shift = 24, 71*b7c7b050SIcenowy Zheng .width = 2, 72*b7c7b050SIcenowy Zheng 73*b7c7b050SIcenowy Zheng .var_predivs = ar100_r_apb2_predivs, 74*b7c7b050SIcenowy Zheng .n_var_predivs = ARRAY_SIZE(ar100_r_apb2_predivs), 75*b7c7b050SIcenowy Zheng }, 76*b7c7b050SIcenowy Zheng 77*b7c7b050SIcenowy Zheng .common = { 78*b7c7b050SIcenowy Zheng .reg = 0x010, 79*b7c7b050SIcenowy Zheng .features = CCU_FEATURE_VARIABLE_PREDIV, 80*b7c7b050SIcenowy Zheng .hw.init = CLK_HW_INIT_PARENTS("r-apb2", 81*b7c7b050SIcenowy Zheng ar100_r_apb2_parents, 82*b7c7b050SIcenowy Zheng &ccu_div_ops, 83*b7c7b050SIcenowy Zheng 0), 84*b7c7b050SIcenowy Zheng }, 85*b7c7b050SIcenowy Zheng }; 86*b7c7b050SIcenowy Zheng 87*b7c7b050SIcenowy Zheng /* 88*b7c7b050SIcenowy Zheng * Information about the gate/resets are gathered from the clock header file 89*b7c7b050SIcenowy Zheng * in the BSP source code, although most of them are unused. The existence 90*b7c7b050SIcenowy Zheng * of the hardware block is verified with "3.1 Memory Mapping" chapter in 91*b7c7b050SIcenowy Zheng * "Allwinner H6 V200 User Manual V1.1"; and the parent APB buses are verified 92*b7c7b050SIcenowy Zheng * with "3.3.2.1 System Bus Tree" chapter inthe same document. 93*b7c7b050SIcenowy Zheng */ 94*b7c7b050SIcenowy Zheng static SUNXI_CCU_GATE(r_apb1_timer_clk, "r-apb1-timer", "r-apb1", 95*b7c7b050SIcenowy Zheng 0x11c, BIT(0), 0); 96*b7c7b050SIcenowy Zheng static SUNXI_CCU_GATE(r_apb1_twd_clk, "r-apb1-twd", "r-apb1", 97*b7c7b050SIcenowy Zheng 0x12c, BIT(0), 0); 98*b7c7b050SIcenowy Zheng static SUNXI_CCU_GATE(r_apb1_pwm_clk, "r-apb1-pwm", "r-apb1", 99*b7c7b050SIcenowy Zheng 0x13c, BIT(0), 0); 100*b7c7b050SIcenowy Zheng static SUNXI_CCU_GATE(r_apb2_uart_clk, "r-apb2-uart", "r-apb2", 101*b7c7b050SIcenowy Zheng 0x18c, BIT(0), 0); 102*b7c7b050SIcenowy Zheng static SUNXI_CCU_GATE(r_apb2_i2c_clk, "r-apb2-i2c", "r-apb2", 103*b7c7b050SIcenowy Zheng 0x19c, BIT(0), 0); 104*b7c7b050SIcenowy Zheng static SUNXI_CCU_GATE(r_apb1_ir_clk, "r-apb1-ir", "r-apb1", 105*b7c7b050SIcenowy Zheng 0x1cc, BIT(0), 0); 106*b7c7b050SIcenowy Zheng static SUNXI_CCU_GATE(r_apb1_w1_clk, "r-apb1-w1", "r-apb1", 107*b7c7b050SIcenowy Zheng 0x1cc, BIT(0), 0); 108*b7c7b050SIcenowy Zheng 109*b7c7b050SIcenowy Zheng /* Information of IR(RX) mod clock is gathered from BSP source code */ 110*b7c7b050SIcenowy Zheng static const char * const r_mod0_default_parents[] = { "osc32k", "osc24M" }; 111*b7c7b050SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(ir_clk, "ir", 112*b7c7b050SIcenowy Zheng r_mod0_default_parents, 0x1c0, 113*b7c7b050SIcenowy Zheng 0, 5, /* M */ 114*b7c7b050SIcenowy Zheng 8, 2, /* P */ 115*b7c7b050SIcenowy Zheng 24, 1, /* mux */ 116*b7c7b050SIcenowy Zheng BIT(31), /* gate */ 117*b7c7b050SIcenowy Zheng 0); 118*b7c7b050SIcenowy Zheng 119*b7c7b050SIcenowy Zheng /* 120*b7c7b050SIcenowy Zheng * BSP didn't use the 1-wire function at all now, and the information about 121*b7c7b050SIcenowy Zheng * this mod clock is guessed from the IR mod clock above. The existence of 122*b7c7b050SIcenowy Zheng * this mod clock is proven by BSP clock header, and the dividers are verified 123*b7c7b050SIcenowy Zheng * by contents in the 1-wire related chapter of the User Manual. 124*b7c7b050SIcenowy Zheng */ 125*b7c7b050SIcenowy Zheng 126*b7c7b050SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(w1_clk, "w1", 127*b7c7b050SIcenowy Zheng r_mod0_default_parents, 0x1e0, 128*b7c7b050SIcenowy Zheng 0, 5, /* M */ 129*b7c7b050SIcenowy Zheng 8, 2, /* P */ 130*b7c7b050SIcenowy Zheng 24, 1, /* mux */ 131*b7c7b050SIcenowy Zheng BIT(31), /* gate */ 132*b7c7b050SIcenowy Zheng 0); 133*b7c7b050SIcenowy Zheng 134*b7c7b050SIcenowy Zheng static struct ccu_common *sun50i_h6_r_ccu_clks[] = { 135*b7c7b050SIcenowy Zheng &ar100_clk.common, 136*b7c7b050SIcenowy Zheng &r_apb1_clk.common, 137*b7c7b050SIcenowy Zheng &r_apb2_clk.common, 138*b7c7b050SIcenowy Zheng &r_apb1_timer_clk.common, 139*b7c7b050SIcenowy Zheng &r_apb1_twd_clk.common, 140*b7c7b050SIcenowy Zheng &r_apb1_pwm_clk.common, 141*b7c7b050SIcenowy Zheng &r_apb2_uart_clk.common, 142*b7c7b050SIcenowy Zheng &r_apb2_i2c_clk.common, 143*b7c7b050SIcenowy Zheng &r_apb1_ir_clk.common, 144*b7c7b050SIcenowy Zheng &r_apb1_w1_clk.common, 145*b7c7b050SIcenowy Zheng &ir_clk.common, 146*b7c7b050SIcenowy Zheng &w1_clk.common, 147*b7c7b050SIcenowy Zheng }; 148*b7c7b050SIcenowy Zheng 149*b7c7b050SIcenowy Zheng static struct clk_hw_onecell_data sun50i_h6_r_hw_clks = { 150*b7c7b050SIcenowy Zheng .hws = { 151*b7c7b050SIcenowy Zheng [CLK_AR100] = &ar100_clk.common.hw, 152*b7c7b050SIcenowy Zheng [CLK_R_AHB] = &r_ahb_clk.hw, 153*b7c7b050SIcenowy Zheng [CLK_R_APB1] = &r_apb1_clk.common.hw, 154*b7c7b050SIcenowy Zheng [CLK_R_APB2] = &r_apb2_clk.common.hw, 155*b7c7b050SIcenowy Zheng [CLK_R_APB1_TIMER] = &r_apb1_timer_clk.common.hw, 156*b7c7b050SIcenowy Zheng [CLK_R_APB1_TWD] = &r_apb1_twd_clk.common.hw, 157*b7c7b050SIcenowy Zheng [CLK_R_APB1_PWM] = &r_apb1_pwm_clk.common.hw, 158*b7c7b050SIcenowy Zheng [CLK_R_APB2_UART] = &r_apb2_uart_clk.common.hw, 159*b7c7b050SIcenowy Zheng [CLK_R_APB2_I2C] = &r_apb2_i2c_clk.common.hw, 160*b7c7b050SIcenowy Zheng [CLK_R_APB1_IR] = &r_apb1_ir_clk.common.hw, 161*b7c7b050SIcenowy Zheng [CLK_R_APB1_W1] = &r_apb1_w1_clk.common.hw, 162*b7c7b050SIcenowy Zheng [CLK_IR] = &ir_clk.common.hw, 163*b7c7b050SIcenowy Zheng [CLK_W1] = &w1_clk.common.hw, 164*b7c7b050SIcenowy Zheng }, 165*b7c7b050SIcenowy Zheng .num = CLK_NUMBER, 166*b7c7b050SIcenowy Zheng }; 167*b7c7b050SIcenowy Zheng 168*b7c7b050SIcenowy Zheng static struct ccu_reset_map sun50i_h6_r_ccu_resets[] = { 169*b7c7b050SIcenowy Zheng [RST_R_APB1_TIMER] = { 0x11c, BIT(16) }, 170*b7c7b050SIcenowy Zheng [RST_R_APB1_TWD] = { 0x12c, BIT(16) }, 171*b7c7b050SIcenowy Zheng [RST_R_APB1_PWM] = { 0x13c, BIT(16) }, 172*b7c7b050SIcenowy Zheng [RST_R_APB2_UART] = { 0x18c, BIT(16) }, 173*b7c7b050SIcenowy Zheng [RST_R_APB2_I2C] = { 0x19c, BIT(16) }, 174*b7c7b050SIcenowy Zheng [RST_R_APB1_IR] = { 0x1cc, BIT(16) }, 175*b7c7b050SIcenowy Zheng [RST_R_APB1_W1] = { 0x1ec, BIT(16) }, 176*b7c7b050SIcenowy Zheng }; 177*b7c7b050SIcenowy Zheng 178*b7c7b050SIcenowy Zheng static const struct sunxi_ccu_desc sun50i_h6_r_ccu_desc = { 179*b7c7b050SIcenowy Zheng .ccu_clks = sun50i_h6_r_ccu_clks, 180*b7c7b050SIcenowy Zheng .num_ccu_clks = ARRAY_SIZE(sun50i_h6_r_ccu_clks), 181*b7c7b050SIcenowy Zheng 182*b7c7b050SIcenowy Zheng .hw_clks = &sun50i_h6_r_hw_clks, 183*b7c7b050SIcenowy Zheng 184*b7c7b050SIcenowy Zheng .resets = sun50i_h6_r_ccu_resets, 185*b7c7b050SIcenowy Zheng .num_resets = ARRAY_SIZE(sun50i_h6_r_ccu_resets), 186*b7c7b050SIcenowy Zheng }; 187*b7c7b050SIcenowy Zheng 188*b7c7b050SIcenowy Zheng static void __init sunxi_r_ccu_init(struct device_node *node, 189*b7c7b050SIcenowy Zheng const struct sunxi_ccu_desc *desc) 190*b7c7b050SIcenowy Zheng { 191*b7c7b050SIcenowy Zheng void __iomem *reg; 192*b7c7b050SIcenowy Zheng 193*b7c7b050SIcenowy Zheng reg = of_io_request_and_map(node, 0, of_node_full_name(node)); 194*b7c7b050SIcenowy Zheng if (IS_ERR(reg)) { 195*b7c7b050SIcenowy Zheng pr_err("%pOF: Could not map the clock registers\n", node); 196*b7c7b050SIcenowy Zheng return; 197*b7c7b050SIcenowy Zheng } 198*b7c7b050SIcenowy Zheng 199*b7c7b050SIcenowy Zheng sunxi_ccu_probe(node, reg, desc); 200*b7c7b050SIcenowy Zheng } 201*b7c7b050SIcenowy Zheng 202*b7c7b050SIcenowy Zheng static void __init sun50i_h6_r_ccu_setup(struct device_node *node) 203*b7c7b050SIcenowy Zheng { 204*b7c7b050SIcenowy Zheng sunxi_r_ccu_init(node, &sun50i_h6_r_ccu_desc); 205*b7c7b050SIcenowy Zheng } 206*b7c7b050SIcenowy Zheng CLK_OF_DECLARE(sun50i_h6_r_ccu, "allwinner,sun50i-h6-r-ccu", 207*b7c7b050SIcenowy Zheng sun50i_h6_r_ccu_setup); 208