18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2016 Icenowy Zheng <icenowy@aosc.xyz> 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <linux/clk-provider.h> 78c2ecf20Sopenharmony_ci#include <linux/of_address.h> 88c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include "ccu_common.h" 118c2ecf20Sopenharmony_ci#include "ccu_reset.h" 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include "ccu_div.h" 148c2ecf20Sopenharmony_ci#include "ccu_gate.h" 158c2ecf20Sopenharmony_ci#include "ccu_mp.h" 168c2ecf20Sopenharmony_ci#include "ccu_nm.h" 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#include "ccu-sun8i-r.h" 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistatic const struct clk_parent_data ar100_parents[] = { 218c2ecf20Sopenharmony_ci { .fw_name = "losc" }, 228c2ecf20Sopenharmony_ci { .fw_name = "hosc" }, 238c2ecf20Sopenharmony_ci { .fw_name = "pll-periph" }, 248c2ecf20Sopenharmony_ci { .fw_name = "iosc" }, 258c2ecf20Sopenharmony_ci}; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistatic const struct ccu_mux_var_prediv ar100_predivs[] = { 288c2ecf20Sopenharmony_ci { .index = 2, .shift = 8, .width = 5 }, 298c2ecf20Sopenharmony_ci}; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistatic struct ccu_div ar100_clk = { 328c2ecf20Sopenharmony_ci .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO), 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci .mux = { 358c2ecf20Sopenharmony_ci .shift = 16, 368c2ecf20Sopenharmony_ci .width = 2, 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci .var_predivs = ar100_predivs, 398c2ecf20Sopenharmony_ci .n_var_predivs = ARRAY_SIZE(ar100_predivs), 408c2ecf20Sopenharmony_ci }, 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci .common = { 438c2ecf20Sopenharmony_ci .reg = 0x00, 448c2ecf20Sopenharmony_ci .features = CCU_FEATURE_VARIABLE_PREDIV, 458c2ecf20Sopenharmony_ci .hw.init = CLK_HW_INIT_PARENTS_DATA("ar100", 468c2ecf20Sopenharmony_ci ar100_parents, 478c2ecf20Sopenharmony_ci &ccu_div_ops, 488c2ecf20Sopenharmony_ci 0), 498c2ecf20Sopenharmony_ci }, 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic CLK_FIXED_FACTOR_HW(ahb0_clk, "ahb0", &ar100_clk.common.hw, 1, 1, 0); 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic SUNXI_CCU_M(apb0_clk, "apb0", "ahb0", 0x0c, 0, 2, 0); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci/* 578c2ecf20Sopenharmony_ci * Define the parent as an array that can be reused to save space 588c2ecf20Sopenharmony_ci * instead of having compound literals for each gate. Also have it 598c2ecf20Sopenharmony_ci * non-const so we can change it on the A83T. 608c2ecf20Sopenharmony_ci */ 618c2ecf20Sopenharmony_cistatic const struct clk_hw *apb0_gate_parent[] = { &apb0_clk.common.hw }; 628c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE_HWS(apb0_pio_clk, "apb0-pio", 638c2ecf20Sopenharmony_ci apb0_gate_parent, 0x28, BIT(0), 0); 648c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE_HWS(apb0_ir_clk, "apb0-ir", 658c2ecf20Sopenharmony_ci apb0_gate_parent, 0x28, BIT(1), 0); 668c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE_HWS(apb0_timer_clk, "apb0-timer", 678c2ecf20Sopenharmony_ci apb0_gate_parent, 0x28, BIT(2), 0); 688c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE_HWS(apb0_rsb_clk, "apb0-rsb", 698c2ecf20Sopenharmony_ci apb0_gate_parent, 0x28, BIT(3), 0); 708c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE_HWS(apb0_uart_clk, "apb0-uart", 718c2ecf20Sopenharmony_ci apb0_gate_parent, 0x28, BIT(4), 0); 728c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE_HWS(apb0_i2c_clk, "apb0-i2c", 738c2ecf20Sopenharmony_ci apb0_gate_parent, 0x28, BIT(6), 0); 748c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE_HWS(apb0_twd_clk, "apb0-twd", 758c2ecf20Sopenharmony_ci apb0_gate_parent, 0x28, BIT(7), 0); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic const char * const r_mod0_default_parents[] = { "osc32k", "osc24M" }; 788c2ecf20Sopenharmony_cistatic SUNXI_CCU_MP_WITH_MUX_GATE(ir_clk, "ir", 798c2ecf20Sopenharmony_ci r_mod0_default_parents, 0x54, 808c2ecf20Sopenharmony_ci 0, 4, /* M */ 818c2ecf20Sopenharmony_ci 16, 2, /* P */ 828c2ecf20Sopenharmony_ci 24, 2, /* mux */ 838c2ecf20Sopenharmony_ci BIT(31), /* gate */ 848c2ecf20Sopenharmony_ci 0); 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cistatic const struct clk_parent_data a83t_r_mod0_parents[] = { 878c2ecf20Sopenharmony_ci { .fw_name = "iosc" }, 888c2ecf20Sopenharmony_ci { .fw_name = "hosc" }, 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_cistatic const struct ccu_mux_fixed_prediv a83t_ir_predivs[] = { 918c2ecf20Sopenharmony_ci { .index = 0, .div = 16 }, 928c2ecf20Sopenharmony_ci}; 938c2ecf20Sopenharmony_cistatic struct ccu_mp a83t_ir_clk = { 948c2ecf20Sopenharmony_ci .enable = BIT(31), 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci .m = _SUNXI_CCU_DIV(0, 4), 978c2ecf20Sopenharmony_ci .p = _SUNXI_CCU_DIV(16, 2), 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci .mux = { 1008c2ecf20Sopenharmony_ci .shift = 24, 1018c2ecf20Sopenharmony_ci .width = 2, 1028c2ecf20Sopenharmony_ci .fixed_predivs = a83t_ir_predivs, 1038c2ecf20Sopenharmony_ci .n_predivs = ARRAY_SIZE(a83t_ir_predivs), 1048c2ecf20Sopenharmony_ci }, 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci .common = { 1078c2ecf20Sopenharmony_ci .reg = 0x54, 1088c2ecf20Sopenharmony_ci .features = CCU_FEATURE_VARIABLE_PREDIV, 1098c2ecf20Sopenharmony_ci .hw.init = CLK_HW_INIT_PARENTS_DATA("ir", 1108c2ecf20Sopenharmony_ci a83t_r_mod0_parents, 1118c2ecf20Sopenharmony_ci &ccu_mp_ops, 1128c2ecf20Sopenharmony_ci 0), 1138c2ecf20Sopenharmony_ci }, 1148c2ecf20Sopenharmony_ci}; 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_cistatic struct ccu_common *sun8i_a83t_r_ccu_clks[] = { 1178c2ecf20Sopenharmony_ci &ar100_clk.common, 1188c2ecf20Sopenharmony_ci &apb0_clk.common, 1198c2ecf20Sopenharmony_ci &apb0_pio_clk.common, 1208c2ecf20Sopenharmony_ci &apb0_ir_clk.common, 1218c2ecf20Sopenharmony_ci &apb0_timer_clk.common, 1228c2ecf20Sopenharmony_ci &apb0_rsb_clk.common, 1238c2ecf20Sopenharmony_ci &apb0_uart_clk.common, 1248c2ecf20Sopenharmony_ci &apb0_i2c_clk.common, 1258c2ecf20Sopenharmony_ci &apb0_twd_clk.common, 1268c2ecf20Sopenharmony_ci &a83t_ir_clk.common, 1278c2ecf20Sopenharmony_ci}; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistatic struct ccu_common *sun8i_h3_r_ccu_clks[] = { 1308c2ecf20Sopenharmony_ci &ar100_clk.common, 1318c2ecf20Sopenharmony_ci &apb0_clk.common, 1328c2ecf20Sopenharmony_ci &apb0_pio_clk.common, 1338c2ecf20Sopenharmony_ci &apb0_ir_clk.common, 1348c2ecf20Sopenharmony_ci &apb0_timer_clk.common, 1358c2ecf20Sopenharmony_ci &apb0_uart_clk.common, 1368c2ecf20Sopenharmony_ci &apb0_i2c_clk.common, 1378c2ecf20Sopenharmony_ci &apb0_twd_clk.common, 1388c2ecf20Sopenharmony_ci &ir_clk.common, 1398c2ecf20Sopenharmony_ci}; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_cistatic struct ccu_common *sun50i_a64_r_ccu_clks[] = { 1428c2ecf20Sopenharmony_ci &ar100_clk.common, 1438c2ecf20Sopenharmony_ci &apb0_clk.common, 1448c2ecf20Sopenharmony_ci &apb0_pio_clk.common, 1458c2ecf20Sopenharmony_ci &apb0_ir_clk.common, 1468c2ecf20Sopenharmony_ci &apb0_timer_clk.common, 1478c2ecf20Sopenharmony_ci &apb0_rsb_clk.common, 1488c2ecf20Sopenharmony_ci &apb0_uart_clk.common, 1498c2ecf20Sopenharmony_ci &apb0_i2c_clk.common, 1508c2ecf20Sopenharmony_ci &apb0_twd_clk.common, 1518c2ecf20Sopenharmony_ci &ir_clk.common, 1528c2ecf20Sopenharmony_ci}; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistatic struct clk_hw_onecell_data sun8i_a83t_r_hw_clks = { 1558c2ecf20Sopenharmony_ci .hws = { 1568c2ecf20Sopenharmony_ci [CLK_AR100] = &ar100_clk.common.hw, 1578c2ecf20Sopenharmony_ci [CLK_AHB0] = &ahb0_clk.hw, 1588c2ecf20Sopenharmony_ci [CLK_APB0] = &apb0_clk.common.hw, 1598c2ecf20Sopenharmony_ci [CLK_APB0_PIO] = &apb0_pio_clk.common.hw, 1608c2ecf20Sopenharmony_ci [CLK_APB0_IR] = &apb0_ir_clk.common.hw, 1618c2ecf20Sopenharmony_ci [CLK_APB0_TIMER] = &apb0_timer_clk.common.hw, 1628c2ecf20Sopenharmony_ci [CLK_APB0_RSB] = &apb0_rsb_clk.common.hw, 1638c2ecf20Sopenharmony_ci [CLK_APB0_UART] = &apb0_uart_clk.common.hw, 1648c2ecf20Sopenharmony_ci [CLK_APB0_I2C] = &apb0_i2c_clk.common.hw, 1658c2ecf20Sopenharmony_ci [CLK_APB0_TWD] = &apb0_twd_clk.common.hw, 1668c2ecf20Sopenharmony_ci [CLK_IR] = &a83t_ir_clk.common.hw, 1678c2ecf20Sopenharmony_ci }, 1688c2ecf20Sopenharmony_ci .num = CLK_NUMBER, 1698c2ecf20Sopenharmony_ci}; 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_cistatic struct clk_hw_onecell_data sun8i_h3_r_hw_clks = { 1728c2ecf20Sopenharmony_ci .hws = { 1738c2ecf20Sopenharmony_ci [CLK_AR100] = &ar100_clk.common.hw, 1748c2ecf20Sopenharmony_ci [CLK_AHB0] = &ahb0_clk.hw, 1758c2ecf20Sopenharmony_ci [CLK_APB0] = &apb0_clk.common.hw, 1768c2ecf20Sopenharmony_ci [CLK_APB0_PIO] = &apb0_pio_clk.common.hw, 1778c2ecf20Sopenharmony_ci [CLK_APB0_IR] = &apb0_ir_clk.common.hw, 1788c2ecf20Sopenharmony_ci [CLK_APB0_TIMER] = &apb0_timer_clk.common.hw, 1798c2ecf20Sopenharmony_ci [CLK_APB0_UART] = &apb0_uart_clk.common.hw, 1808c2ecf20Sopenharmony_ci [CLK_APB0_I2C] = &apb0_i2c_clk.common.hw, 1818c2ecf20Sopenharmony_ci [CLK_APB0_TWD] = &apb0_twd_clk.common.hw, 1828c2ecf20Sopenharmony_ci [CLK_IR] = &ir_clk.common.hw, 1838c2ecf20Sopenharmony_ci }, 1848c2ecf20Sopenharmony_ci .num = CLK_NUMBER, 1858c2ecf20Sopenharmony_ci}; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cistatic struct clk_hw_onecell_data sun50i_a64_r_hw_clks = { 1888c2ecf20Sopenharmony_ci .hws = { 1898c2ecf20Sopenharmony_ci [CLK_AR100] = &ar100_clk.common.hw, 1908c2ecf20Sopenharmony_ci [CLK_AHB0] = &ahb0_clk.hw, 1918c2ecf20Sopenharmony_ci [CLK_APB0] = &apb0_clk.common.hw, 1928c2ecf20Sopenharmony_ci [CLK_APB0_PIO] = &apb0_pio_clk.common.hw, 1938c2ecf20Sopenharmony_ci [CLK_APB0_IR] = &apb0_ir_clk.common.hw, 1948c2ecf20Sopenharmony_ci [CLK_APB0_TIMER] = &apb0_timer_clk.common.hw, 1958c2ecf20Sopenharmony_ci [CLK_APB0_RSB] = &apb0_rsb_clk.common.hw, 1968c2ecf20Sopenharmony_ci [CLK_APB0_UART] = &apb0_uart_clk.common.hw, 1978c2ecf20Sopenharmony_ci [CLK_APB0_I2C] = &apb0_i2c_clk.common.hw, 1988c2ecf20Sopenharmony_ci [CLK_APB0_TWD] = &apb0_twd_clk.common.hw, 1998c2ecf20Sopenharmony_ci [CLK_IR] = &ir_clk.common.hw, 2008c2ecf20Sopenharmony_ci }, 2018c2ecf20Sopenharmony_ci .num = CLK_NUMBER, 2028c2ecf20Sopenharmony_ci}; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_cistatic struct ccu_reset_map sun8i_a83t_r_ccu_resets[] = { 2058c2ecf20Sopenharmony_ci [RST_APB0_IR] = { 0xb0, BIT(1) }, 2068c2ecf20Sopenharmony_ci [RST_APB0_TIMER] = { 0xb0, BIT(2) }, 2078c2ecf20Sopenharmony_ci [RST_APB0_RSB] = { 0xb0, BIT(3) }, 2088c2ecf20Sopenharmony_ci [RST_APB0_UART] = { 0xb0, BIT(4) }, 2098c2ecf20Sopenharmony_ci [RST_APB0_I2C] = { 0xb0, BIT(6) }, 2108c2ecf20Sopenharmony_ci}; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_cistatic struct ccu_reset_map sun8i_h3_r_ccu_resets[] = { 2138c2ecf20Sopenharmony_ci [RST_APB0_IR] = { 0xb0, BIT(1) }, 2148c2ecf20Sopenharmony_ci [RST_APB0_TIMER] = { 0xb0, BIT(2) }, 2158c2ecf20Sopenharmony_ci [RST_APB0_UART] = { 0xb0, BIT(4) }, 2168c2ecf20Sopenharmony_ci [RST_APB0_I2C] = { 0xb0, BIT(6) }, 2178c2ecf20Sopenharmony_ci}; 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_cistatic struct ccu_reset_map sun50i_a64_r_ccu_resets[] = { 2208c2ecf20Sopenharmony_ci [RST_APB0_IR] = { 0xb0, BIT(1) }, 2218c2ecf20Sopenharmony_ci [RST_APB0_TIMER] = { 0xb0, BIT(2) }, 2228c2ecf20Sopenharmony_ci [RST_APB0_RSB] = { 0xb0, BIT(3) }, 2238c2ecf20Sopenharmony_ci [RST_APB0_UART] = { 0xb0, BIT(4) }, 2248c2ecf20Sopenharmony_ci [RST_APB0_I2C] = { 0xb0, BIT(6) }, 2258c2ecf20Sopenharmony_ci}; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_cistatic const struct sunxi_ccu_desc sun8i_a83t_r_ccu_desc = { 2288c2ecf20Sopenharmony_ci .ccu_clks = sun8i_a83t_r_ccu_clks, 2298c2ecf20Sopenharmony_ci .num_ccu_clks = ARRAY_SIZE(sun8i_a83t_r_ccu_clks), 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci .hw_clks = &sun8i_a83t_r_hw_clks, 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci .resets = sun8i_a83t_r_ccu_resets, 2348c2ecf20Sopenharmony_ci .num_resets = ARRAY_SIZE(sun8i_a83t_r_ccu_resets), 2358c2ecf20Sopenharmony_ci}; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_cistatic const struct sunxi_ccu_desc sun8i_h3_r_ccu_desc = { 2388c2ecf20Sopenharmony_ci .ccu_clks = sun8i_h3_r_ccu_clks, 2398c2ecf20Sopenharmony_ci .num_ccu_clks = ARRAY_SIZE(sun8i_h3_r_ccu_clks), 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci .hw_clks = &sun8i_h3_r_hw_clks, 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci .resets = sun8i_h3_r_ccu_resets, 2448c2ecf20Sopenharmony_ci .num_resets = ARRAY_SIZE(sun8i_h3_r_ccu_resets), 2458c2ecf20Sopenharmony_ci}; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_cistatic const struct sunxi_ccu_desc sun50i_a64_r_ccu_desc = { 2488c2ecf20Sopenharmony_ci .ccu_clks = sun50i_a64_r_ccu_clks, 2498c2ecf20Sopenharmony_ci .num_ccu_clks = ARRAY_SIZE(sun50i_a64_r_ccu_clks), 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci .hw_clks = &sun50i_a64_r_hw_clks, 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci .resets = sun50i_a64_r_ccu_resets, 2548c2ecf20Sopenharmony_ci .num_resets = ARRAY_SIZE(sun50i_a64_r_ccu_resets), 2558c2ecf20Sopenharmony_ci}; 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_cistatic void __init sunxi_r_ccu_init(struct device_node *node, 2588c2ecf20Sopenharmony_ci const struct sunxi_ccu_desc *desc) 2598c2ecf20Sopenharmony_ci{ 2608c2ecf20Sopenharmony_ci void __iomem *reg; 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci reg = of_io_request_and_map(node, 0, of_node_full_name(node)); 2638c2ecf20Sopenharmony_ci if (IS_ERR(reg)) { 2648c2ecf20Sopenharmony_ci pr_err("%pOF: Could not map the clock registers\n", node); 2658c2ecf20Sopenharmony_ci return; 2668c2ecf20Sopenharmony_ci } 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci sunxi_ccu_probe(node, reg, desc); 2698c2ecf20Sopenharmony_ci} 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_cistatic void __init sun8i_a83t_r_ccu_setup(struct device_node *node) 2728c2ecf20Sopenharmony_ci{ 2738c2ecf20Sopenharmony_ci sunxi_r_ccu_init(node, &sun8i_a83t_r_ccu_desc); 2748c2ecf20Sopenharmony_ci} 2758c2ecf20Sopenharmony_ciCLK_OF_DECLARE(sun8i_a83t_r_ccu, "allwinner,sun8i-a83t-r-ccu", 2768c2ecf20Sopenharmony_ci sun8i_a83t_r_ccu_setup); 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_cistatic void __init sun8i_h3_r_ccu_setup(struct device_node *node) 2798c2ecf20Sopenharmony_ci{ 2808c2ecf20Sopenharmony_ci sunxi_r_ccu_init(node, &sun8i_h3_r_ccu_desc); 2818c2ecf20Sopenharmony_ci} 2828c2ecf20Sopenharmony_ciCLK_OF_DECLARE(sun8i_h3_r_ccu, "allwinner,sun8i-h3-r-ccu", 2838c2ecf20Sopenharmony_ci sun8i_h3_r_ccu_setup); 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_cistatic void __init sun50i_a64_r_ccu_setup(struct device_node *node) 2868c2ecf20Sopenharmony_ci{ 2878c2ecf20Sopenharmony_ci sunxi_r_ccu_init(node, &sun50i_a64_r_ccu_desc); 2888c2ecf20Sopenharmony_ci} 2898c2ecf20Sopenharmony_ciCLK_OF_DECLARE(sun50i_a64_r_ccu, "allwinner,sun50i-a64-r-ccu", 2908c2ecf20Sopenharmony_ci sun50i_a64_r_ccu_setup); 291