18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Zynq clock controller 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2012 - 2013 Xilinx 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Sören Brinkmann <soren.brinkmann@xilinx.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/clk/zynq.h> 118c2ecf20Sopenharmony_ci#include <linux/clk.h> 128c2ecf20Sopenharmony_ci#include <linux/clk-provider.h> 138c2ecf20Sopenharmony_ci#include <linux/of.h> 148c2ecf20Sopenharmony_ci#include <linux/of_address.h> 158c2ecf20Sopenharmony_ci#include <linux/slab.h> 168c2ecf20Sopenharmony_ci#include <linux/string.h> 178c2ecf20Sopenharmony_ci#include <linux/io.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistatic void __iomem *zynq_clkc_base; 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define SLCR_ARMPLL_CTRL (zynq_clkc_base + 0x00) 228c2ecf20Sopenharmony_ci#define SLCR_DDRPLL_CTRL (zynq_clkc_base + 0x04) 238c2ecf20Sopenharmony_ci#define SLCR_IOPLL_CTRL (zynq_clkc_base + 0x08) 248c2ecf20Sopenharmony_ci#define SLCR_PLL_STATUS (zynq_clkc_base + 0x0c) 258c2ecf20Sopenharmony_ci#define SLCR_ARM_CLK_CTRL (zynq_clkc_base + 0x20) 268c2ecf20Sopenharmony_ci#define SLCR_DDR_CLK_CTRL (zynq_clkc_base + 0x24) 278c2ecf20Sopenharmony_ci#define SLCR_DCI_CLK_CTRL (zynq_clkc_base + 0x28) 288c2ecf20Sopenharmony_ci#define SLCR_APER_CLK_CTRL (zynq_clkc_base + 0x2c) 298c2ecf20Sopenharmony_ci#define SLCR_GEM0_CLK_CTRL (zynq_clkc_base + 0x40) 308c2ecf20Sopenharmony_ci#define SLCR_GEM1_CLK_CTRL (zynq_clkc_base + 0x44) 318c2ecf20Sopenharmony_ci#define SLCR_SMC_CLK_CTRL (zynq_clkc_base + 0x48) 328c2ecf20Sopenharmony_ci#define SLCR_LQSPI_CLK_CTRL (zynq_clkc_base + 0x4c) 338c2ecf20Sopenharmony_ci#define SLCR_SDIO_CLK_CTRL (zynq_clkc_base + 0x50) 348c2ecf20Sopenharmony_ci#define SLCR_UART_CLK_CTRL (zynq_clkc_base + 0x54) 358c2ecf20Sopenharmony_ci#define SLCR_SPI_CLK_CTRL (zynq_clkc_base + 0x58) 368c2ecf20Sopenharmony_ci#define SLCR_CAN_CLK_CTRL (zynq_clkc_base + 0x5c) 378c2ecf20Sopenharmony_ci#define SLCR_CAN_MIOCLK_CTRL (zynq_clkc_base + 0x60) 388c2ecf20Sopenharmony_ci#define SLCR_DBG_CLK_CTRL (zynq_clkc_base + 0x64) 398c2ecf20Sopenharmony_ci#define SLCR_PCAP_CLK_CTRL (zynq_clkc_base + 0x68) 408c2ecf20Sopenharmony_ci#define SLCR_FPGA0_CLK_CTRL (zynq_clkc_base + 0x70) 418c2ecf20Sopenharmony_ci#define SLCR_621_TRUE (zynq_clkc_base + 0xc4) 428c2ecf20Sopenharmony_ci#define SLCR_SWDT_CLK_SEL (zynq_clkc_base + 0x204) 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define NUM_MIO_PINS 54 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define DBG_CLK_CTRL_CLKACT_TRC BIT(0) 478c2ecf20Sopenharmony_ci#define DBG_CLK_CTRL_CPU_1XCLKACT BIT(1) 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cienum zynq_clk { 508c2ecf20Sopenharmony_ci armpll, ddrpll, iopll, 518c2ecf20Sopenharmony_ci cpu_6or4x, cpu_3or2x, cpu_2x, cpu_1x, 528c2ecf20Sopenharmony_ci ddr2x, ddr3x, dci, 538c2ecf20Sopenharmony_ci lqspi, smc, pcap, gem0, gem1, fclk0, fclk1, fclk2, fclk3, can0, can1, 548c2ecf20Sopenharmony_ci sdio0, sdio1, uart0, uart1, spi0, spi1, dma, 558c2ecf20Sopenharmony_ci usb0_aper, usb1_aper, gem0_aper, gem1_aper, 568c2ecf20Sopenharmony_ci sdio0_aper, sdio1_aper, spi0_aper, spi1_aper, can0_aper, can1_aper, 578c2ecf20Sopenharmony_ci i2c0_aper, i2c1_aper, uart0_aper, uart1_aper, gpio_aper, lqspi_aper, 588c2ecf20Sopenharmony_ci smc_aper, swdt, dbg_trc, dbg_apb, clk_max}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistatic struct clk *ps_clk; 618c2ecf20Sopenharmony_cistatic struct clk *clks[clk_max]; 628c2ecf20Sopenharmony_cistatic struct clk_onecell_data clk_data; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(armpll_lock); 658c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(ddrpll_lock); 668c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(iopll_lock); 678c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(armclk_lock); 688c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(swdtclk_lock); 698c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(ddrclk_lock); 708c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(dciclk_lock); 718c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(gem0clk_lock); 728c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(gem1clk_lock); 738c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(canclk_lock); 748c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(canmioclk_lock); 758c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(dbgclk_lock); 768c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(aperclk_lock); 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cistatic const char *const armpll_parents[] __initconst = {"armpll_int", 798c2ecf20Sopenharmony_ci "ps_clk"}; 808c2ecf20Sopenharmony_cistatic const char *const ddrpll_parents[] __initconst = {"ddrpll_int", 818c2ecf20Sopenharmony_ci "ps_clk"}; 828c2ecf20Sopenharmony_cistatic const char *const iopll_parents[] __initconst = {"iopll_int", 838c2ecf20Sopenharmony_ci "ps_clk"}; 848c2ecf20Sopenharmony_cistatic const char *gem0_mux_parents[] __initdata = {"gem0_div1", "dummy_name"}; 858c2ecf20Sopenharmony_cistatic const char *gem1_mux_parents[] __initdata = {"gem1_div1", "dummy_name"}; 868c2ecf20Sopenharmony_cistatic const char *const can0_mio_mux2_parents[] __initconst = {"can0_gate", 878c2ecf20Sopenharmony_ci "can0_mio_mux"}; 888c2ecf20Sopenharmony_cistatic const char *const can1_mio_mux2_parents[] __initconst = {"can1_gate", 898c2ecf20Sopenharmony_ci "can1_mio_mux"}; 908c2ecf20Sopenharmony_cistatic const char *dbg_emio_mux_parents[] __initdata = {"dbg_div", 918c2ecf20Sopenharmony_ci "dummy_name"}; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistatic const char *const dbgtrc_emio_input_names[] __initconst = { 948c2ecf20Sopenharmony_ci "trace_emio_clk"}; 958c2ecf20Sopenharmony_cistatic const char *const gem0_emio_input_names[] __initconst = { 968c2ecf20Sopenharmony_ci "gem0_emio_clk"}; 978c2ecf20Sopenharmony_cistatic const char *const gem1_emio_input_names[] __initconst = { 988c2ecf20Sopenharmony_ci "gem1_emio_clk"}; 998c2ecf20Sopenharmony_cistatic const char *const swdt_ext_clk_input_names[] __initconst = { 1008c2ecf20Sopenharmony_ci "swdt_ext_clk"}; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistatic void __init zynq_clk_register_fclk(enum zynq_clk fclk, 1038c2ecf20Sopenharmony_ci const char *clk_name, void __iomem *fclk_ctrl_reg, 1048c2ecf20Sopenharmony_ci const char **parents, int enable) 1058c2ecf20Sopenharmony_ci{ 1068c2ecf20Sopenharmony_ci struct clk *clk; 1078c2ecf20Sopenharmony_ci u32 enable_reg; 1088c2ecf20Sopenharmony_ci char *mux_name; 1098c2ecf20Sopenharmony_ci char *div0_name; 1108c2ecf20Sopenharmony_ci char *div1_name; 1118c2ecf20Sopenharmony_ci spinlock_t *fclk_lock; 1128c2ecf20Sopenharmony_ci spinlock_t *fclk_gate_lock; 1138c2ecf20Sopenharmony_ci void __iomem *fclk_gate_reg = fclk_ctrl_reg + 8; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci fclk_lock = kmalloc(sizeof(*fclk_lock), GFP_KERNEL); 1168c2ecf20Sopenharmony_ci if (!fclk_lock) 1178c2ecf20Sopenharmony_ci goto err; 1188c2ecf20Sopenharmony_ci fclk_gate_lock = kmalloc(sizeof(*fclk_gate_lock), GFP_KERNEL); 1198c2ecf20Sopenharmony_ci if (!fclk_gate_lock) 1208c2ecf20Sopenharmony_ci goto err_fclk_gate_lock; 1218c2ecf20Sopenharmony_ci spin_lock_init(fclk_lock); 1228c2ecf20Sopenharmony_ci spin_lock_init(fclk_gate_lock); 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci mux_name = kasprintf(GFP_KERNEL, "%s_mux", clk_name); 1258c2ecf20Sopenharmony_ci if (!mux_name) 1268c2ecf20Sopenharmony_ci goto err_mux_name; 1278c2ecf20Sopenharmony_ci div0_name = kasprintf(GFP_KERNEL, "%s_div0", clk_name); 1288c2ecf20Sopenharmony_ci if (!div0_name) 1298c2ecf20Sopenharmony_ci goto err_div0_name; 1308c2ecf20Sopenharmony_ci div1_name = kasprintf(GFP_KERNEL, "%s_div1", clk_name); 1318c2ecf20Sopenharmony_ci if (!div1_name) 1328c2ecf20Sopenharmony_ci goto err_div1_name; 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci clk = clk_register_mux(NULL, mux_name, parents, 4, 1358c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, fclk_ctrl_reg, 4, 2, 0, 1368c2ecf20Sopenharmony_ci fclk_lock); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, div0_name, mux_name, 1398c2ecf20Sopenharmony_ci 0, fclk_ctrl_reg, 8, 6, CLK_DIVIDER_ONE_BASED | 1408c2ecf20Sopenharmony_ci CLK_DIVIDER_ALLOW_ZERO, fclk_lock); 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, div1_name, div0_name, 1438c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, fclk_ctrl_reg, 20, 6, 1448c2ecf20Sopenharmony_ci CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, 1458c2ecf20Sopenharmony_ci fclk_lock); 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci clks[fclk] = clk_register_gate(NULL, clk_name, 1488c2ecf20Sopenharmony_ci div1_name, CLK_SET_RATE_PARENT, fclk_gate_reg, 1498c2ecf20Sopenharmony_ci 0, CLK_GATE_SET_TO_DISABLE, fclk_gate_lock); 1508c2ecf20Sopenharmony_ci enable_reg = readl(fclk_gate_reg) & 1; 1518c2ecf20Sopenharmony_ci if (enable && !enable_reg) { 1528c2ecf20Sopenharmony_ci if (clk_prepare_enable(clks[fclk])) 1538c2ecf20Sopenharmony_ci pr_warn("%s: FCLK%u enable failed\n", __func__, 1548c2ecf20Sopenharmony_ci fclk - fclk0); 1558c2ecf20Sopenharmony_ci } 1568c2ecf20Sopenharmony_ci kfree(mux_name); 1578c2ecf20Sopenharmony_ci kfree(div0_name); 1588c2ecf20Sopenharmony_ci kfree(div1_name); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci return; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_cierr_div1_name: 1638c2ecf20Sopenharmony_ci kfree(div0_name); 1648c2ecf20Sopenharmony_cierr_div0_name: 1658c2ecf20Sopenharmony_ci kfree(mux_name); 1668c2ecf20Sopenharmony_cierr_mux_name: 1678c2ecf20Sopenharmony_ci kfree(fclk_gate_lock); 1688c2ecf20Sopenharmony_cierr_fclk_gate_lock: 1698c2ecf20Sopenharmony_ci kfree(fclk_lock); 1708c2ecf20Sopenharmony_cierr: 1718c2ecf20Sopenharmony_ci clks[fclk] = ERR_PTR(-ENOMEM); 1728c2ecf20Sopenharmony_ci} 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_cistatic void __init zynq_clk_register_periph_clk(enum zynq_clk clk0, 1758c2ecf20Sopenharmony_ci enum zynq_clk clk1, const char *clk_name0, 1768c2ecf20Sopenharmony_ci const char *clk_name1, void __iomem *clk_ctrl, 1778c2ecf20Sopenharmony_ci const char **parents, unsigned int two_gates) 1788c2ecf20Sopenharmony_ci{ 1798c2ecf20Sopenharmony_ci struct clk *clk; 1808c2ecf20Sopenharmony_ci char *mux_name; 1818c2ecf20Sopenharmony_ci char *div_name; 1828c2ecf20Sopenharmony_ci spinlock_t *lock; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci lock = kmalloc(sizeof(*lock), GFP_KERNEL); 1858c2ecf20Sopenharmony_ci if (!lock) 1868c2ecf20Sopenharmony_ci goto err; 1878c2ecf20Sopenharmony_ci spin_lock_init(lock); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci mux_name = kasprintf(GFP_KERNEL, "%s_mux", clk_name0); 1908c2ecf20Sopenharmony_ci div_name = kasprintf(GFP_KERNEL, "%s_div", clk_name0); 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci clk = clk_register_mux(NULL, mux_name, parents, 4, 1938c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, clk_ctrl, 4, 2, 0, lock); 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, div_name, mux_name, 0, clk_ctrl, 8, 6, 1968c2ecf20Sopenharmony_ci CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, lock); 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci clks[clk0] = clk_register_gate(NULL, clk_name0, div_name, 1998c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, clk_ctrl, 0, 0, lock); 2008c2ecf20Sopenharmony_ci if (two_gates) 2018c2ecf20Sopenharmony_ci clks[clk1] = clk_register_gate(NULL, clk_name1, div_name, 2028c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, clk_ctrl, 1, 0, lock); 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci kfree(mux_name); 2058c2ecf20Sopenharmony_ci kfree(div_name); 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci return; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cierr: 2108c2ecf20Sopenharmony_ci clks[clk0] = ERR_PTR(-ENOMEM); 2118c2ecf20Sopenharmony_ci if (two_gates) 2128c2ecf20Sopenharmony_ci clks[clk1] = ERR_PTR(-ENOMEM); 2138c2ecf20Sopenharmony_ci} 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_cistatic void __init zynq_clk_setup(struct device_node *np) 2168c2ecf20Sopenharmony_ci{ 2178c2ecf20Sopenharmony_ci int i; 2188c2ecf20Sopenharmony_ci u32 tmp; 2198c2ecf20Sopenharmony_ci int ret; 2208c2ecf20Sopenharmony_ci struct clk *clk; 2218c2ecf20Sopenharmony_ci char *clk_name; 2228c2ecf20Sopenharmony_ci unsigned int fclk_enable = 0; 2238c2ecf20Sopenharmony_ci const char *clk_output_name[clk_max]; 2248c2ecf20Sopenharmony_ci const char *cpu_parents[4]; 2258c2ecf20Sopenharmony_ci const char *periph_parents[4]; 2268c2ecf20Sopenharmony_ci const char *swdt_ext_clk_mux_parents[2]; 2278c2ecf20Sopenharmony_ci const char *can_mio_mux_parents[NUM_MIO_PINS]; 2288c2ecf20Sopenharmony_ci const char *dummy_nm = "dummy_name"; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci pr_info("Zynq clock init\n"); 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci /* get clock output names from DT */ 2338c2ecf20Sopenharmony_ci for (i = 0; i < clk_max; i++) { 2348c2ecf20Sopenharmony_ci if (of_property_read_string_index(np, "clock-output-names", 2358c2ecf20Sopenharmony_ci i, &clk_output_name[i])) { 2368c2ecf20Sopenharmony_ci pr_err("%s: clock output name not in DT\n", __func__); 2378c2ecf20Sopenharmony_ci BUG(); 2388c2ecf20Sopenharmony_ci } 2398c2ecf20Sopenharmony_ci } 2408c2ecf20Sopenharmony_ci cpu_parents[0] = clk_output_name[armpll]; 2418c2ecf20Sopenharmony_ci cpu_parents[1] = clk_output_name[armpll]; 2428c2ecf20Sopenharmony_ci cpu_parents[2] = clk_output_name[ddrpll]; 2438c2ecf20Sopenharmony_ci cpu_parents[3] = clk_output_name[iopll]; 2448c2ecf20Sopenharmony_ci periph_parents[0] = clk_output_name[iopll]; 2458c2ecf20Sopenharmony_ci periph_parents[1] = clk_output_name[iopll]; 2468c2ecf20Sopenharmony_ci periph_parents[2] = clk_output_name[armpll]; 2478c2ecf20Sopenharmony_ci periph_parents[3] = clk_output_name[ddrpll]; 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci of_property_read_u32(np, "fclk-enable", &fclk_enable); 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci /* ps_clk */ 2528c2ecf20Sopenharmony_ci ret = of_property_read_u32(np, "ps-clk-frequency", &tmp); 2538c2ecf20Sopenharmony_ci if (ret) { 2548c2ecf20Sopenharmony_ci pr_warn("ps_clk frequency not specified, using 33 MHz.\n"); 2558c2ecf20Sopenharmony_ci tmp = 33333333; 2568c2ecf20Sopenharmony_ci } 2578c2ecf20Sopenharmony_ci ps_clk = clk_register_fixed_rate(NULL, "ps_clk", NULL, 0, tmp); 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci /* PLLs */ 2608c2ecf20Sopenharmony_ci clk = clk_register_zynq_pll("armpll_int", "ps_clk", SLCR_ARMPLL_CTRL, 2618c2ecf20Sopenharmony_ci SLCR_PLL_STATUS, 0, &armpll_lock); 2628c2ecf20Sopenharmony_ci clks[armpll] = clk_register_mux(NULL, clk_output_name[armpll], 2638c2ecf20Sopenharmony_ci armpll_parents, 2, CLK_SET_RATE_NO_REPARENT, 2648c2ecf20Sopenharmony_ci SLCR_ARMPLL_CTRL, 4, 1, 0, &armpll_lock); 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci clk = clk_register_zynq_pll("ddrpll_int", "ps_clk", SLCR_DDRPLL_CTRL, 2678c2ecf20Sopenharmony_ci SLCR_PLL_STATUS, 1, &ddrpll_lock); 2688c2ecf20Sopenharmony_ci clks[ddrpll] = clk_register_mux(NULL, clk_output_name[ddrpll], 2698c2ecf20Sopenharmony_ci ddrpll_parents, 2, CLK_SET_RATE_NO_REPARENT, 2708c2ecf20Sopenharmony_ci SLCR_DDRPLL_CTRL, 4, 1, 0, &ddrpll_lock); 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci clk = clk_register_zynq_pll("iopll_int", "ps_clk", SLCR_IOPLL_CTRL, 2738c2ecf20Sopenharmony_ci SLCR_PLL_STATUS, 2, &iopll_lock); 2748c2ecf20Sopenharmony_ci clks[iopll] = clk_register_mux(NULL, clk_output_name[iopll], 2758c2ecf20Sopenharmony_ci iopll_parents, 2, CLK_SET_RATE_NO_REPARENT, 2768c2ecf20Sopenharmony_ci SLCR_IOPLL_CTRL, 4, 1, 0, &iopll_lock); 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci /* CPU clocks */ 2798c2ecf20Sopenharmony_ci tmp = readl(SLCR_621_TRUE) & 1; 2808c2ecf20Sopenharmony_ci clk = clk_register_mux(NULL, "cpu_mux", cpu_parents, 4, 2818c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, SLCR_ARM_CLK_CTRL, 4, 2, 0, 2828c2ecf20Sopenharmony_ci &armclk_lock); 2838c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, "cpu_div", "cpu_mux", 0, 2848c2ecf20Sopenharmony_ci SLCR_ARM_CLK_CTRL, 8, 6, CLK_DIVIDER_ONE_BASED | 2858c2ecf20Sopenharmony_ci CLK_DIVIDER_ALLOW_ZERO, &armclk_lock); 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci clks[cpu_6or4x] = clk_register_gate(NULL, clk_output_name[cpu_6or4x], 2888c2ecf20Sopenharmony_ci "cpu_div", CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, 2898c2ecf20Sopenharmony_ci SLCR_ARM_CLK_CTRL, 24, 0, &armclk_lock); 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci clk = clk_register_fixed_factor(NULL, "cpu_3or2x_div", "cpu_div", 0, 2928c2ecf20Sopenharmony_ci 1, 2); 2938c2ecf20Sopenharmony_ci clks[cpu_3or2x] = clk_register_gate(NULL, clk_output_name[cpu_3or2x], 2948c2ecf20Sopenharmony_ci "cpu_3or2x_div", CLK_IGNORE_UNUSED, 2958c2ecf20Sopenharmony_ci SLCR_ARM_CLK_CTRL, 25, 0, &armclk_lock); 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci clk = clk_register_fixed_factor(NULL, "cpu_2x_div", "cpu_div", 0, 1, 2988c2ecf20Sopenharmony_ci 2 + tmp); 2998c2ecf20Sopenharmony_ci clks[cpu_2x] = clk_register_gate(NULL, clk_output_name[cpu_2x], 3008c2ecf20Sopenharmony_ci "cpu_2x_div", CLK_IGNORE_UNUSED, SLCR_ARM_CLK_CTRL, 3018c2ecf20Sopenharmony_ci 26, 0, &armclk_lock); 3028c2ecf20Sopenharmony_ci clk_prepare_enable(clks[cpu_2x]); 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci clk = clk_register_fixed_factor(NULL, "cpu_1x_div", "cpu_div", 0, 1, 3058c2ecf20Sopenharmony_ci 4 + 2 * tmp); 3068c2ecf20Sopenharmony_ci clks[cpu_1x] = clk_register_gate(NULL, clk_output_name[cpu_1x], 3078c2ecf20Sopenharmony_ci "cpu_1x_div", CLK_IGNORE_UNUSED, SLCR_ARM_CLK_CTRL, 27, 3088c2ecf20Sopenharmony_ci 0, &armclk_lock); 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci /* Timers */ 3118c2ecf20Sopenharmony_ci swdt_ext_clk_mux_parents[0] = clk_output_name[cpu_1x]; 3128c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(swdt_ext_clk_input_names); i++) { 3138c2ecf20Sopenharmony_ci int idx = of_property_match_string(np, "clock-names", 3148c2ecf20Sopenharmony_ci swdt_ext_clk_input_names[i]); 3158c2ecf20Sopenharmony_ci if (idx >= 0) 3168c2ecf20Sopenharmony_ci swdt_ext_clk_mux_parents[i + 1] = 3178c2ecf20Sopenharmony_ci of_clk_get_parent_name(np, idx); 3188c2ecf20Sopenharmony_ci else 3198c2ecf20Sopenharmony_ci swdt_ext_clk_mux_parents[i + 1] = dummy_nm; 3208c2ecf20Sopenharmony_ci } 3218c2ecf20Sopenharmony_ci clks[swdt] = clk_register_mux(NULL, clk_output_name[swdt], 3228c2ecf20Sopenharmony_ci swdt_ext_clk_mux_parents, 2, CLK_SET_RATE_PARENT | 3238c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, SLCR_SWDT_CLK_SEL, 0, 1, 0, 3248c2ecf20Sopenharmony_ci &swdtclk_lock); 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci /* DDR clocks */ 3278c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, "ddr2x_div", "ddrpll", 0, 3288c2ecf20Sopenharmony_ci SLCR_DDR_CLK_CTRL, 26, 6, CLK_DIVIDER_ONE_BASED | 3298c2ecf20Sopenharmony_ci CLK_DIVIDER_ALLOW_ZERO, &ddrclk_lock); 3308c2ecf20Sopenharmony_ci clks[ddr2x] = clk_register_gate(NULL, clk_output_name[ddr2x], 3318c2ecf20Sopenharmony_ci "ddr2x_div", 0, SLCR_DDR_CLK_CTRL, 1, 0, &ddrclk_lock); 3328c2ecf20Sopenharmony_ci clk_prepare_enable(clks[ddr2x]); 3338c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, "ddr3x_div", "ddrpll", 0, 3348c2ecf20Sopenharmony_ci SLCR_DDR_CLK_CTRL, 20, 6, CLK_DIVIDER_ONE_BASED | 3358c2ecf20Sopenharmony_ci CLK_DIVIDER_ALLOW_ZERO, &ddrclk_lock); 3368c2ecf20Sopenharmony_ci clks[ddr3x] = clk_register_gate(NULL, clk_output_name[ddr3x], 3378c2ecf20Sopenharmony_ci "ddr3x_div", 0, SLCR_DDR_CLK_CTRL, 0, 0, &ddrclk_lock); 3388c2ecf20Sopenharmony_ci clk_prepare_enable(clks[ddr3x]); 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, "dci_div0", "ddrpll", 0, 3418c2ecf20Sopenharmony_ci SLCR_DCI_CLK_CTRL, 8, 6, CLK_DIVIDER_ONE_BASED | 3428c2ecf20Sopenharmony_ci CLK_DIVIDER_ALLOW_ZERO, &dciclk_lock); 3438c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, "dci_div1", "dci_div0", 3448c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, SLCR_DCI_CLK_CTRL, 20, 6, 3458c2ecf20Sopenharmony_ci CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, 3468c2ecf20Sopenharmony_ci &dciclk_lock); 3478c2ecf20Sopenharmony_ci clks[dci] = clk_register_gate(NULL, clk_output_name[dci], "dci_div1", 3488c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, SLCR_DCI_CLK_CTRL, 0, 0, 3498c2ecf20Sopenharmony_ci &dciclk_lock); 3508c2ecf20Sopenharmony_ci clk_prepare_enable(clks[dci]); 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci /* Peripheral clocks */ 3538c2ecf20Sopenharmony_ci for (i = fclk0; i <= fclk3; i++) { 3548c2ecf20Sopenharmony_ci int enable = !!(fclk_enable & BIT(i - fclk0)); 3558c2ecf20Sopenharmony_ci zynq_clk_register_fclk(i, clk_output_name[i], 3568c2ecf20Sopenharmony_ci SLCR_FPGA0_CLK_CTRL + 0x10 * (i - fclk0), 3578c2ecf20Sopenharmony_ci periph_parents, enable); 3588c2ecf20Sopenharmony_ci } 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_ci zynq_clk_register_periph_clk(lqspi, 0, clk_output_name[lqspi], NULL, 3618c2ecf20Sopenharmony_ci SLCR_LQSPI_CLK_CTRL, periph_parents, 0); 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci zynq_clk_register_periph_clk(smc, 0, clk_output_name[smc], NULL, 3648c2ecf20Sopenharmony_ci SLCR_SMC_CLK_CTRL, periph_parents, 0); 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci zynq_clk_register_periph_clk(pcap, 0, clk_output_name[pcap], NULL, 3678c2ecf20Sopenharmony_ci SLCR_PCAP_CLK_CTRL, periph_parents, 0); 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci zynq_clk_register_periph_clk(sdio0, sdio1, clk_output_name[sdio0], 3708c2ecf20Sopenharmony_ci clk_output_name[sdio1], SLCR_SDIO_CLK_CTRL, 3718c2ecf20Sopenharmony_ci periph_parents, 1); 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci zynq_clk_register_periph_clk(uart0, uart1, clk_output_name[uart0], 3748c2ecf20Sopenharmony_ci clk_output_name[uart1], SLCR_UART_CLK_CTRL, 3758c2ecf20Sopenharmony_ci periph_parents, 1); 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci zynq_clk_register_periph_clk(spi0, spi1, clk_output_name[spi0], 3788c2ecf20Sopenharmony_ci clk_output_name[spi1], SLCR_SPI_CLK_CTRL, 3798c2ecf20Sopenharmony_ci periph_parents, 1); 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(gem0_emio_input_names); i++) { 3828c2ecf20Sopenharmony_ci int idx = of_property_match_string(np, "clock-names", 3838c2ecf20Sopenharmony_ci gem0_emio_input_names[i]); 3848c2ecf20Sopenharmony_ci if (idx >= 0) 3858c2ecf20Sopenharmony_ci gem0_mux_parents[i + 1] = of_clk_get_parent_name(np, 3868c2ecf20Sopenharmony_ci idx); 3878c2ecf20Sopenharmony_ci } 3888c2ecf20Sopenharmony_ci clk = clk_register_mux(NULL, "gem0_mux", periph_parents, 4, 3898c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, SLCR_GEM0_CLK_CTRL, 4, 2, 0, 3908c2ecf20Sopenharmony_ci &gem0clk_lock); 3918c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, "gem0_div0", "gem0_mux", 0, 3928c2ecf20Sopenharmony_ci SLCR_GEM0_CLK_CTRL, 8, 6, CLK_DIVIDER_ONE_BASED | 3938c2ecf20Sopenharmony_ci CLK_DIVIDER_ALLOW_ZERO, &gem0clk_lock); 3948c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, "gem0_div1", "gem0_div0", 3958c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, SLCR_GEM0_CLK_CTRL, 20, 6, 3968c2ecf20Sopenharmony_ci CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, 3978c2ecf20Sopenharmony_ci &gem0clk_lock); 3988c2ecf20Sopenharmony_ci clk = clk_register_mux(NULL, "gem0_emio_mux", gem0_mux_parents, 2, 3998c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, 4008c2ecf20Sopenharmony_ci SLCR_GEM0_CLK_CTRL, 6, 1, 0, 4018c2ecf20Sopenharmony_ci &gem0clk_lock); 4028c2ecf20Sopenharmony_ci clks[gem0] = clk_register_gate(NULL, clk_output_name[gem0], 4038c2ecf20Sopenharmony_ci "gem0_emio_mux", CLK_SET_RATE_PARENT, 4048c2ecf20Sopenharmony_ci SLCR_GEM0_CLK_CTRL, 0, 0, &gem0clk_lock); 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(gem1_emio_input_names); i++) { 4078c2ecf20Sopenharmony_ci int idx = of_property_match_string(np, "clock-names", 4088c2ecf20Sopenharmony_ci gem1_emio_input_names[i]); 4098c2ecf20Sopenharmony_ci if (idx >= 0) 4108c2ecf20Sopenharmony_ci gem1_mux_parents[i + 1] = of_clk_get_parent_name(np, 4118c2ecf20Sopenharmony_ci idx); 4128c2ecf20Sopenharmony_ci } 4138c2ecf20Sopenharmony_ci clk = clk_register_mux(NULL, "gem1_mux", periph_parents, 4, 4148c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, SLCR_GEM1_CLK_CTRL, 4, 2, 0, 4158c2ecf20Sopenharmony_ci &gem1clk_lock); 4168c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, "gem1_div0", "gem1_mux", 0, 4178c2ecf20Sopenharmony_ci SLCR_GEM1_CLK_CTRL, 8, 6, CLK_DIVIDER_ONE_BASED | 4188c2ecf20Sopenharmony_ci CLK_DIVIDER_ALLOW_ZERO, &gem1clk_lock); 4198c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, "gem1_div1", "gem1_div0", 4208c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, SLCR_GEM1_CLK_CTRL, 20, 6, 4218c2ecf20Sopenharmony_ci CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, 4228c2ecf20Sopenharmony_ci &gem1clk_lock); 4238c2ecf20Sopenharmony_ci clk = clk_register_mux(NULL, "gem1_emio_mux", gem1_mux_parents, 2, 4248c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, 4258c2ecf20Sopenharmony_ci SLCR_GEM1_CLK_CTRL, 6, 1, 0, 4268c2ecf20Sopenharmony_ci &gem1clk_lock); 4278c2ecf20Sopenharmony_ci clks[gem1] = clk_register_gate(NULL, clk_output_name[gem1], 4288c2ecf20Sopenharmony_ci "gem1_emio_mux", CLK_SET_RATE_PARENT, 4298c2ecf20Sopenharmony_ci SLCR_GEM1_CLK_CTRL, 0, 0, &gem1clk_lock); 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci tmp = strlen("mio_clk_00x"); 4328c2ecf20Sopenharmony_ci clk_name = kmalloc(tmp, GFP_KERNEL); 4338c2ecf20Sopenharmony_ci for (i = 0; i < NUM_MIO_PINS; i++) { 4348c2ecf20Sopenharmony_ci int idx; 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci snprintf(clk_name, tmp, "mio_clk_%2.2d", i); 4378c2ecf20Sopenharmony_ci idx = of_property_match_string(np, "clock-names", clk_name); 4388c2ecf20Sopenharmony_ci if (idx >= 0) 4398c2ecf20Sopenharmony_ci can_mio_mux_parents[i] = of_clk_get_parent_name(np, 4408c2ecf20Sopenharmony_ci idx); 4418c2ecf20Sopenharmony_ci else 4428c2ecf20Sopenharmony_ci can_mio_mux_parents[i] = dummy_nm; 4438c2ecf20Sopenharmony_ci } 4448c2ecf20Sopenharmony_ci kfree(clk_name); 4458c2ecf20Sopenharmony_ci clk = clk_register_mux(NULL, "can_mux", periph_parents, 4, 4468c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, SLCR_CAN_CLK_CTRL, 4, 2, 0, 4478c2ecf20Sopenharmony_ci &canclk_lock); 4488c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, "can_div0", "can_mux", 0, 4498c2ecf20Sopenharmony_ci SLCR_CAN_CLK_CTRL, 8, 6, CLK_DIVIDER_ONE_BASED | 4508c2ecf20Sopenharmony_ci CLK_DIVIDER_ALLOW_ZERO, &canclk_lock); 4518c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, "can_div1", "can_div0", 4528c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, SLCR_CAN_CLK_CTRL, 20, 6, 4538c2ecf20Sopenharmony_ci CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, 4548c2ecf20Sopenharmony_ci &canclk_lock); 4558c2ecf20Sopenharmony_ci clk = clk_register_gate(NULL, "can0_gate", "can_div1", 4568c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, SLCR_CAN_CLK_CTRL, 0, 0, 4578c2ecf20Sopenharmony_ci &canclk_lock); 4588c2ecf20Sopenharmony_ci clk = clk_register_gate(NULL, "can1_gate", "can_div1", 4598c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, SLCR_CAN_CLK_CTRL, 1, 0, 4608c2ecf20Sopenharmony_ci &canclk_lock); 4618c2ecf20Sopenharmony_ci clk = clk_register_mux(NULL, "can0_mio_mux", 4628c2ecf20Sopenharmony_ci can_mio_mux_parents, 54, CLK_SET_RATE_PARENT | 4638c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, SLCR_CAN_MIOCLK_CTRL, 0, 6, 0, 4648c2ecf20Sopenharmony_ci &canmioclk_lock); 4658c2ecf20Sopenharmony_ci clk = clk_register_mux(NULL, "can1_mio_mux", 4668c2ecf20Sopenharmony_ci can_mio_mux_parents, 54, CLK_SET_RATE_PARENT | 4678c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, SLCR_CAN_MIOCLK_CTRL, 16, 6, 4688c2ecf20Sopenharmony_ci 0, &canmioclk_lock); 4698c2ecf20Sopenharmony_ci clks[can0] = clk_register_mux(NULL, clk_output_name[can0], 4708c2ecf20Sopenharmony_ci can0_mio_mux2_parents, 2, CLK_SET_RATE_PARENT | 4718c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, SLCR_CAN_MIOCLK_CTRL, 6, 1, 0, 4728c2ecf20Sopenharmony_ci &canmioclk_lock); 4738c2ecf20Sopenharmony_ci clks[can1] = clk_register_mux(NULL, clk_output_name[can1], 4748c2ecf20Sopenharmony_ci can1_mio_mux2_parents, 2, CLK_SET_RATE_PARENT | 4758c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, SLCR_CAN_MIOCLK_CTRL, 22, 1, 4768c2ecf20Sopenharmony_ci 0, &canmioclk_lock); 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dbgtrc_emio_input_names); i++) { 4798c2ecf20Sopenharmony_ci int idx = of_property_match_string(np, "clock-names", 4808c2ecf20Sopenharmony_ci dbgtrc_emio_input_names[i]); 4818c2ecf20Sopenharmony_ci if (idx >= 0) 4828c2ecf20Sopenharmony_ci dbg_emio_mux_parents[i + 1] = of_clk_get_parent_name(np, 4838c2ecf20Sopenharmony_ci idx); 4848c2ecf20Sopenharmony_ci } 4858c2ecf20Sopenharmony_ci clk = clk_register_mux(NULL, "dbg_mux", periph_parents, 4, 4868c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, SLCR_DBG_CLK_CTRL, 4, 2, 0, 4878c2ecf20Sopenharmony_ci &dbgclk_lock); 4888c2ecf20Sopenharmony_ci clk = clk_register_divider(NULL, "dbg_div", "dbg_mux", 0, 4898c2ecf20Sopenharmony_ci SLCR_DBG_CLK_CTRL, 8, 6, CLK_DIVIDER_ONE_BASED | 4908c2ecf20Sopenharmony_ci CLK_DIVIDER_ALLOW_ZERO, &dbgclk_lock); 4918c2ecf20Sopenharmony_ci clk = clk_register_mux(NULL, "dbg_emio_mux", dbg_emio_mux_parents, 2, 4928c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, SLCR_DBG_CLK_CTRL, 6, 1, 0, 4938c2ecf20Sopenharmony_ci &dbgclk_lock); 4948c2ecf20Sopenharmony_ci clks[dbg_trc] = clk_register_gate(NULL, clk_output_name[dbg_trc], 4958c2ecf20Sopenharmony_ci "dbg_emio_mux", CLK_SET_RATE_PARENT, SLCR_DBG_CLK_CTRL, 4968c2ecf20Sopenharmony_ci 0, 0, &dbgclk_lock); 4978c2ecf20Sopenharmony_ci clks[dbg_apb] = clk_register_gate(NULL, clk_output_name[dbg_apb], 4988c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_DBG_CLK_CTRL, 1, 0, 4998c2ecf20Sopenharmony_ci &dbgclk_lock); 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci /* leave debug clocks in the state the bootloader set them up to */ 5028c2ecf20Sopenharmony_ci tmp = readl(SLCR_DBG_CLK_CTRL); 5038c2ecf20Sopenharmony_ci if (tmp & DBG_CLK_CTRL_CLKACT_TRC) 5048c2ecf20Sopenharmony_ci if (clk_prepare_enable(clks[dbg_trc])) 5058c2ecf20Sopenharmony_ci pr_warn("%s: trace clk enable failed\n", __func__); 5068c2ecf20Sopenharmony_ci if (tmp & DBG_CLK_CTRL_CPU_1XCLKACT) 5078c2ecf20Sopenharmony_ci if (clk_prepare_enable(clks[dbg_apb])) 5088c2ecf20Sopenharmony_ci pr_warn("%s: debug APB clk enable failed\n", __func__); 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci /* One gated clock for all APER clocks. */ 5118c2ecf20Sopenharmony_ci clks[dma] = clk_register_gate(NULL, clk_output_name[dma], 5128c2ecf20Sopenharmony_ci clk_output_name[cpu_2x], 0, SLCR_APER_CLK_CTRL, 0, 0, 5138c2ecf20Sopenharmony_ci &aperclk_lock); 5148c2ecf20Sopenharmony_ci clks[usb0_aper] = clk_register_gate(NULL, clk_output_name[usb0_aper], 5158c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 2, 0, 5168c2ecf20Sopenharmony_ci &aperclk_lock); 5178c2ecf20Sopenharmony_ci clks[usb1_aper] = clk_register_gate(NULL, clk_output_name[usb1_aper], 5188c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 3, 0, 5198c2ecf20Sopenharmony_ci &aperclk_lock); 5208c2ecf20Sopenharmony_ci clks[gem0_aper] = clk_register_gate(NULL, clk_output_name[gem0_aper], 5218c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 6, 0, 5228c2ecf20Sopenharmony_ci &aperclk_lock); 5238c2ecf20Sopenharmony_ci clks[gem1_aper] = clk_register_gate(NULL, clk_output_name[gem1_aper], 5248c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 7, 0, 5258c2ecf20Sopenharmony_ci &aperclk_lock); 5268c2ecf20Sopenharmony_ci clks[sdio0_aper] = clk_register_gate(NULL, clk_output_name[sdio0_aper], 5278c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 10, 0, 5288c2ecf20Sopenharmony_ci &aperclk_lock); 5298c2ecf20Sopenharmony_ci clks[sdio1_aper] = clk_register_gate(NULL, clk_output_name[sdio1_aper], 5308c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 11, 0, 5318c2ecf20Sopenharmony_ci &aperclk_lock); 5328c2ecf20Sopenharmony_ci clks[spi0_aper] = clk_register_gate(NULL, clk_output_name[spi0_aper], 5338c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 14, 0, 5348c2ecf20Sopenharmony_ci &aperclk_lock); 5358c2ecf20Sopenharmony_ci clks[spi1_aper] = clk_register_gate(NULL, clk_output_name[spi1_aper], 5368c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 15, 0, 5378c2ecf20Sopenharmony_ci &aperclk_lock); 5388c2ecf20Sopenharmony_ci clks[can0_aper] = clk_register_gate(NULL, clk_output_name[can0_aper], 5398c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 16, 0, 5408c2ecf20Sopenharmony_ci &aperclk_lock); 5418c2ecf20Sopenharmony_ci clks[can1_aper] = clk_register_gate(NULL, clk_output_name[can1_aper], 5428c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 17, 0, 5438c2ecf20Sopenharmony_ci &aperclk_lock); 5448c2ecf20Sopenharmony_ci clks[i2c0_aper] = clk_register_gate(NULL, clk_output_name[i2c0_aper], 5458c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 18, 0, 5468c2ecf20Sopenharmony_ci &aperclk_lock); 5478c2ecf20Sopenharmony_ci clks[i2c1_aper] = clk_register_gate(NULL, clk_output_name[i2c1_aper], 5488c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 19, 0, 5498c2ecf20Sopenharmony_ci &aperclk_lock); 5508c2ecf20Sopenharmony_ci clks[uart0_aper] = clk_register_gate(NULL, clk_output_name[uart0_aper], 5518c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 20, 0, 5528c2ecf20Sopenharmony_ci &aperclk_lock); 5538c2ecf20Sopenharmony_ci clks[uart1_aper] = clk_register_gate(NULL, clk_output_name[uart1_aper], 5548c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 21, 0, 5558c2ecf20Sopenharmony_ci &aperclk_lock); 5568c2ecf20Sopenharmony_ci clks[gpio_aper] = clk_register_gate(NULL, clk_output_name[gpio_aper], 5578c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 22, 0, 5588c2ecf20Sopenharmony_ci &aperclk_lock); 5598c2ecf20Sopenharmony_ci clks[lqspi_aper] = clk_register_gate(NULL, clk_output_name[lqspi_aper], 5608c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 23, 0, 5618c2ecf20Sopenharmony_ci &aperclk_lock); 5628c2ecf20Sopenharmony_ci clks[smc_aper] = clk_register_gate(NULL, clk_output_name[smc_aper], 5638c2ecf20Sopenharmony_ci clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 24, 0, 5648c2ecf20Sopenharmony_ci &aperclk_lock); 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(clks); i++) { 5678c2ecf20Sopenharmony_ci if (IS_ERR(clks[i])) { 5688c2ecf20Sopenharmony_ci pr_err("Zynq clk %d: register failed with %ld\n", 5698c2ecf20Sopenharmony_ci i, PTR_ERR(clks[i])); 5708c2ecf20Sopenharmony_ci BUG(); 5718c2ecf20Sopenharmony_ci } 5728c2ecf20Sopenharmony_ci } 5738c2ecf20Sopenharmony_ci 5748c2ecf20Sopenharmony_ci clk_data.clks = clks; 5758c2ecf20Sopenharmony_ci clk_data.clk_num = ARRAY_SIZE(clks); 5768c2ecf20Sopenharmony_ci of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data); 5778c2ecf20Sopenharmony_ci} 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ciCLK_OF_DECLARE(zynq_clkc, "xlnx,ps7-clkc", zynq_clk_setup); 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_civoid __init zynq_clock_init(void) 5828c2ecf20Sopenharmony_ci{ 5838c2ecf20Sopenharmony_ci struct device_node *np; 5848c2ecf20Sopenharmony_ci struct device_node *slcr; 5858c2ecf20Sopenharmony_ci struct resource res; 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci np = of_find_compatible_node(NULL, NULL, "xlnx,ps7-clkc"); 5888c2ecf20Sopenharmony_ci if (!np) { 5898c2ecf20Sopenharmony_ci pr_err("%s: clkc node not found\n", __func__); 5908c2ecf20Sopenharmony_ci goto np_err; 5918c2ecf20Sopenharmony_ci } 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci if (of_address_to_resource(np, 0, &res)) { 5948c2ecf20Sopenharmony_ci pr_err("%pOFn: failed to get resource\n", np); 5958c2ecf20Sopenharmony_ci goto np_err; 5968c2ecf20Sopenharmony_ci } 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ci slcr = of_get_parent(np); 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci if (slcr->data) { 6018c2ecf20Sopenharmony_ci zynq_clkc_base = (__force void __iomem *)slcr->data + res.start; 6028c2ecf20Sopenharmony_ci } else { 6038c2ecf20Sopenharmony_ci pr_err("%pOFn: Unable to get I/O memory\n", np); 6048c2ecf20Sopenharmony_ci of_node_put(slcr); 6058c2ecf20Sopenharmony_ci goto np_err; 6068c2ecf20Sopenharmony_ci } 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci pr_info("%s: clkc starts at %p\n", __func__, zynq_clkc_base); 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_ci of_node_put(slcr); 6118c2ecf20Sopenharmony_ci of_node_put(np); 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci return; 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_cinp_err: 6168c2ecf20Sopenharmony_ci of_node_put(np); 6178c2ecf20Sopenharmony_ci BUG(); 6188c2ecf20Sopenharmony_ci} 619