1fcfd1436STali Perry // SPDX-License-Identifier: GPL-2.0 2fcfd1436STali Perry /* 3fcfd1436STali Perry * Nuvoton NPCM7xx Clock Generator 4fcfd1436STali Perry * All the clocks are initialized by the bootloader, so this driver allow only 5fcfd1436STali Perry * reading of current settings directly from the hardware. 6fcfd1436STali Perry * 7fcfd1436STali Perry * Copyright (C) 2018 Nuvoton Technologies tali.perry@nuvoton.com 8fcfd1436STali Perry */ 9fcfd1436STali Perry 10fcfd1436STali Perry #include <linux/module.h> 11fcfd1436STali Perry #include <linux/clk-provider.h> 12fcfd1436STali Perry #include <linux/io.h> 13fcfd1436STali Perry #include <linux/kernel.h> 14fcfd1436STali Perry #include <linux/of.h> 15fcfd1436STali Perry #include <linux/of_address.h> 16fcfd1436STali Perry #include <linux/slab.h> 17fcfd1436STali Perry #include <linux/err.h> 18fcfd1436STali Perry #include <linux/bitfield.h> 19fcfd1436STali Perry 20fcfd1436STali Perry #include <dt-bindings/clock/nuvoton,npcm7xx-clock.h> 21fcfd1436STali Perry 22fcfd1436STali Perry struct npcm7xx_clk_pll { 23fcfd1436STali Perry struct clk_hw hw; 24fcfd1436STali Perry void __iomem *pllcon; 25fcfd1436STali Perry u8 flags; 26fcfd1436STali Perry }; 27fcfd1436STali Perry 28fcfd1436STali Perry #define to_npcm7xx_clk_pll(_hw) container_of(_hw, struct npcm7xx_clk_pll, hw) 29fcfd1436STali Perry 30fcfd1436STali Perry #define PLLCON_LOKI BIT(31) 31fcfd1436STali Perry #define PLLCON_LOKS BIT(30) 32fcfd1436STali Perry #define PLLCON_FBDV GENMASK(27, 16) 33fcfd1436STali Perry #define PLLCON_OTDV2 GENMASK(15, 13) 34fcfd1436STali Perry #define PLLCON_PWDEN BIT(12) 35fcfd1436STali Perry #define PLLCON_OTDV1 GENMASK(10, 8) 36fcfd1436STali Perry #define PLLCON_INDV GENMASK(5, 0) 37fcfd1436STali Perry 38fcfd1436STali Perry static unsigned long npcm7xx_clk_pll_recalc_rate(struct clk_hw *hw, 39fcfd1436STali Perry unsigned long parent_rate) 40fcfd1436STali Perry { 41fcfd1436STali Perry struct npcm7xx_clk_pll *pll = to_npcm7xx_clk_pll(hw); 42fcfd1436STali Perry unsigned long fbdv, indv, otdv1, otdv2; 43fcfd1436STali Perry unsigned int val; 44fcfd1436STali Perry u64 ret; 45fcfd1436STali Perry 46fcfd1436STali Perry if (parent_rate == 0) { 47fcfd1436STali Perry pr_err("%s: parent rate is zero", __func__); 48fcfd1436STali Perry return 0; 49fcfd1436STali Perry } 50fcfd1436STali Perry 51fcfd1436STali Perry val = readl_relaxed(pll->pllcon); 52fcfd1436STali Perry 53fcfd1436STali Perry indv = FIELD_GET(PLLCON_INDV, val); 54fcfd1436STali Perry fbdv = FIELD_GET(PLLCON_FBDV, val); 55fcfd1436STali Perry otdv1 = FIELD_GET(PLLCON_OTDV1, val); 56fcfd1436STali Perry otdv2 = FIELD_GET(PLLCON_OTDV2, val); 57fcfd1436STali Perry 58fcfd1436STali Perry ret = (u64)parent_rate * fbdv; 59fcfd1436STali Perry do_div(ret, indv * otdv1 * otdv2); 60fcfd1436STali Perry 61fcfd1436STali Perry return ret; 62fcfd1436STali Perry } 63fcfd1436STali Perry 64fcfd1436STali Perry static const struct clk_ops npcm7xx_clk_pll_ops = { 65fcfd1436STali Perry .recalc_rate = npcm7xx_clk_pll_recalc_rate, 66fcfd1436STali Perry }; 67fcfd1436STali Perry 68fcfd1436STali Perry static struct clk_hw * 69fcfd1436STali Perry npcm7xx_clk_register_pll(void __iomem *pllcon, const char *name, 70fcfd1436STali Perry const char *parent_name, unsigned long flags) 71fcfd1436STali Perry { 72fcfd1436STali Perry struct npcm7xx_clk_pll *pll; 73fcfd1436STali Perry struct clk_init_data init; 74fcfd1436STali Perry struct clk_hw *hw; 75fcfd1436STali Perry int ret; 76fcfd1436STali Perry 77fcfd1436STali Perry pll = kzalloc(sizeof(*pll), GFP_KERNEL); 78fcfd1436STali Perry if (!pll) 79fcfd1436STali Perry return ERR_PTR(-ENOMEM); 80fcfd1436STali Perry 81fcfd1436STali Perry pr_debug("%s reg, name=%s, p=%s\n", __func__, name, parent_name); 82fcfd1436STali Perry 83fcfd1436STali Perry init.name = name; 84fcfd1436STali Perry init.ops = &npcm7xx_clk_pll_ops; 85fcfd1436STali Perry init.parent_names = &parent_name; 86fcfd1436STali Perry init.num_parents = 1; 87fcfd1436STali Perry init.flags = flags; 88fcfd1436STali Perry 89fcfd1436STali Perry pll->pllcon = pllcon; 90fcfd1436STali Perry pll->hw.init = &init; 91fcfd1436STali Perry 92fcfd1436STali Perry hw = &pll->hw; 93fcfd1436STali Perry 94fcfd1436STali Perry ret = clk_hw_register(NULL, hw); 95fcfd1436STali Perry if (ret) { 96fcfd1436STali Perry kfree(pll); 97fcfd1436STali Perry hw = ERR_PTR(ret); 98fcfd1436STali Perry } 99fcfd1436STali Perry 100fcfd1436STali Perry return hw; 101fcfd1436STali Perry } 102fcfd1436STali Perry 103fcfd1436STali Perry #define NPCM7XX_CLKEN1 (0x00) 104fcfd1436STali Perry #define NPCM7XX_CLKEN2 (0x28) 105fcfd1436STali Perry #define NPCM7XX_CLKEN3 (0x30) 106fcfd1436STali Perry #define NPCM7XX_CLKSEL (0x04) 107fcfd1436STali Perry #define NPCM7XX_CLKDIV1 (0x08) 108fcfd1436STali Perry #define NPCM7XX_CLKDIV2 (0x2C) 109fcfd1436STali Perry #define NPCM7XX_CLKDIV3 (0x58) 110fcfd1436STali Perry #define NPCM7XX_PLLCON0 (0x0C) 111fcfd1436STali Perry #define NPCM7XX_PLLCON1 (0x10) 112fcfd1436STali Perry #define NPCM7XX_PLLCON2 (0x54) 113fcfd1436STali Perry #define NPCM7XX_SWRSTR (0x14) 114fcfd1436STali Perry #define NPCM7XX_IRQWAKECON (0x18) 115fcfd1436STali Perry #define NPCM7XX_IRQWAKEFLAG (0x1C) 116fcfd1436STali Perry #define NPCM7XX_IPSRST1 (0x20) 117fcfd1436STali Perry #define NPCM7XX_IPSRST2 (0x24) 118fcfd1436STali Perry #define NPCM7XX_IPSRST3 (0x34) 119fcfd1436STali Perry #define NPCM7XX_WD0RCR (0x38) 120fcfd1436STali Perry #define NPCM7XX_WD1RCR (0x3C) 121fcfd1436STali Perry #define NPCM7XX_WD2RCR (0x40) 122fcfd1436STali Perry #define NPCM7XX_SWRSTC1 (0x44) 123fcfd1436STali Perry #define NPCM7XX_SWRSTC2 (0x48) 124fcfd1436STali Perry #define NPCM7XX_SWRSTC3 (0x4C) 125fcfd1436STali Perry #define NPCM7XX_SWRSTC4 (0x50) 126fcfd1436STali Perry #define NPCM7XX_CORSTC (0x5C) 127fcfd1436STali Perry #define NPCM7XX_PLLCONG (0x60) 128fcfd1436STali Perry #define NPCM7XX_AHBCKFI (0x64) 129fcfd1436STali Perry #define NPCM7XX_SECCNT (0x68) 130fcfd1436STali Perry #define NPCM7XX_CNTR25M (0x6C) 131fcfd1436STali Perry 132fcfd1436STali Perry struct npcm7xx_clk_gate_data { 133fcfd1436STali Perry u32 reg; 134fcfd1436STali Perry u8 bit_idx; 135fcfd1436STali Perry const char *name; 136fcfd1436STali Perry const char *parent_name; 137fcfd1436STali Perry unsigned long flags; 138fcfd1436STali Perry /* 139fcfd1436STali Perry * If this clock is exported via DT, set onecell_idx to constant 140fcfd1436STali Perry * defined in include/dt-bindings/clock/nuvoton, NPCM7XX-clock.h for 141fcfd1436STali Perry * this specific clock. Otherwise, set to -1. 142fcfd1436STali Perry */ 143fcfd1436STali Perry int onecell_idx; 144fcfd1436STali Perry }; 145fcfd1436STali Perry 146fcfd1436STali Perry struct npcm7xx_clk_mux_data { 147fcfd1436STali Perry u8 shift; 148fcfd1436STali Perry u8 mask; 149fcfd1436STali Perry u32 *table; 150fcfd1436STali Perry const char *name; 151fcfd1436STali Perry const char * const *parent_names; 152fcfd1436STali Perry u8 num_parents; 153fcfd1436STali Perry unsigned long flags; 154fcfd1436STali Perry /* 155fcfd1436STali Perry * If this clock is exported via DT, set onecell_idx to constant 156fcfd1436STali Perry * defined in include/dt-bindings/clock/nuvoton, NPCM7XX-clock.h for 157fcfd1436STali Perry * this specific clock. Otherwise, set to -1. 158fcfd1436STali Perry */ 159fcfd1436STali Perry int onecell_idx; 160fcfd1436STali Perry 161fcfd1436STali Perry }; 162fcfd1436STali Perry 163fcfd1436STali Perry struct npcm7xx_clk_div_fixed_data { 164fcfd1436STali Perry u8 mult; 165fcfd1436STali Perry u8 div; 166fcfd1436STali Perry const char *name; 167fcfd1436STali Perry const char *parent_name; 168fcfd1436STali Perry u8 clk_divider_flags; 169fcfd1436STali Perry /* 170fcfd1436STali Perry * If this clock is exported via DT, set onecell_idx to constant 171fcfd1436STali Perry * defined in include/dt-bindings/clock/nuvoton, NPCM7XX-clock.h for 172fcfd1436STali Perry * this specific clock. Otherwise, set to -1. 173fcfd1436STali Perry */ 174fcfd1436STali Perry int onecell_idx; 175fcfd1436STali Perry }; 176fcfd1436STali Perry 177fcfd1436STali Perry 178fcfd1436STali Perry struct npcm7xx_clk_div_data { 179fcfd1436STali Perry u32 reg; 180fcfd1436STali Perry u8 shift; 181fcfd1436STali Perry u8 width; 182fcfd1436STali Perry const char *name; 183fcfd1436STali Perry const char *parent_name; 184fcfd1436STali Perry u8 clk_divider_flags; 185fcfd1436STali Perry unsigned long flags; 186fcfd1436STali Perry /* 187fcfd1436STali Perry * If this clock is exported via DT, set onecell_idx to constant 188fcfd1436STali Perry * defined in include/dt-bindings/clock/nuvoton, NPCM7XX-clock.h for 189fcfd1436STali Perry * this specific clock. Otherwise, set to -1. 190fcfd1436STali Perry */ 191fcfd1436STali Perry int onecell_idx; 192fcfd1436STali Perry }; 193fcfd1436STali Perry 194fcfd1436STali Perry struct npcm7xx_clk_pll_data { 195fcfd1436STali Perry u32 reg; 196fcfd1436STali Perry const char *name; 197fcfd1436STali Perry const char *parent_name; 198fcfd1436STali Perry unsigned long flags; 199fcfd1436STali Perry /* 200fcfd1436STali Perry * If this clock is exported via DT, set onecell_idx to constant 201fcfd1436STali Perry * defined in include/dt-bindings/clock/nuvoton, NPCM7XX-clock.h for 202fcfd1436STali Perry * this specific clock. Otherwise, set to -1. 203fcfd1436STali Perry */ 204fcfd1436STali Perry int onecell_idx; 205fcfd1436STali Perry }; 206fcfd1436STali Perry 207fcfd1436STali Perry /* 208fcfd1436STali Perry * Single copy of strings used to refer to clocks within this driver indexed by 209fcfd1436STali Perry * above enum. 210fcfd1436STali Perry */ 211fcfd1436STali Perry #define NPCM7XX_CLK_S_REFCLK "refclk" 212fcfd1436STali Perry #define NPCM7XX_CLK_S_SYSBYPCK "sysbypck" 213fcfd1436STali Perry #define NPCM7XX_CLK_S_MCBYPCK "mcbypck" 214fcfd1436STali Perry #define NPCM7XX_CLK_S_GFXBYPCK "gfxbypck" 215fcfd1436STali Perry #define NPCM7XX_CLK_S_PLL0 "pll0" 216fcfd1436STali Perry #define NPCM7XX_CLK_S_PLL1 "pll1" 217fcfd1436STali Perry #define NPCM7XX_CLK_S_PLL1_DIV2 "pll1_div2" 218fcfd1436STali Perry #define NPCM7XX_CLK_S_PLL2 "pll2" 219fcfd1436STali Perry #define NPCM7XX_CLK_S_PLL_GFX "pll_gfx" 220fcfd1436STali Perry #define NPCM7XX_CLK_S_PLL2_DIV2 "pll2_div2" 221fcfd1436STali Perry #define NPCM7XX_CLK_S_PIX_MUX "gfx_pixel" 222fcfd1436STali Perry #define NPCM7XX_CLK_S_GPRFSEL_MUX "gprfsel_mux" 223fcfd1436STali Perry #define NPCM7XX_CLK_S_MC_MUX "mc_phy" 224fcfd1436STali Perry #define NPCM7XX_CLK_S_CPU_MUX "cpu" /*AKA system clock.*/ 225fcfd1436STali Perry #define NPCM7XX_CLK_S_MC "mc" 226fcfd1436STali Perry #define NPCM7XX_CLK_S_AXI "axi" /*AKA CLK2*/ 227fcfd1436STali Perry #define NPCM7XX_CLK_S_AHB "ahb" /*AKA CLK4*/ 228fcfd1436STali Perry #define NPCM7XX_CLK_S_CLKOUT_MUX "clkout_mux" 229fcfd1436STali Perry #define NPCM7XX_CLK_S_UART_MUX "uart_mux" 230fcfd1436STali Perry #define NPCM7XX_CLK_S_TIM_MUX "timer_mux" 231fcfd1436STali Perry #define NPCM7XX_CLK_S_SD_MUX "sd_mux" 232fcfd1436STali Perry #define NPCM7XX_CLK_S_GFXM_MUX "gfxm_mux" 233fcfd1436STali Perry #define NPCM7XX_CLK_S_SU_MUX "serial_usb_mux" 234fcfd1436STali Perry #define NPCM7XX_CLK_S_DVC_MUX "dvc_mux" 235fcfd1436STali Perry #define NPCM7XX_CLK_S_GFX_MUX "gfx_mux" 236fcfd1436STali Perry #define NPCM7XX_CLK_S_GFX_PIXEL "gfx_pixel" 237fcfd1436STali Perry #define NPCM7XX_CLK_S_SPI0 "spi0" 238fcfd1436STali Perry #define NPCM7XX_CLK_S_SPI3 "spi3" 239fcfd1436STali Perry #define NPCM7XX_CLK_S_SPIX "spix" 240fcfd1436STali Perry #define NPCM7XX_CLK_S_APB1 "apb1" 241fcfd1436STali Perry #define NPCM7XX_CLK_S_APB2 "apb2" 242fcfd1436STali Perry #define NPCM7XX_CLK_S_APB3 "apb3" 243fcfd1436STali Perry #define NPCM7XX_CLK_S_APB4 "apb4" 244fcfd1436STali Perry #define NPCM7XX_CLK_S_APB5 "apb5" 245fcfd1436STali Perry #define NPCM7XX_CLK_S_TOCK "tock" 246fcfd1436STali Perry #define NPCM7XX_CLK_S_CLKOUT "clkout" 247fcfd1436STali Perry #define NPCM7XX_CLK_S_UART "uart" 248fcfd1436STali Perry #define NPCM7XX_CLK_S_TIMER "timer" 249fcfd1436STali Perry #define NPCM7XX_CLK_S_MMC "mmc" 250fcfd1436STali Perry #define NPCM7XX_CLK_S_SDHC "sdhc" 251fcfd1436STali Perry #define NPCM7XX_CLK_S_ADC "adc" 252fcfd1436STali Perry #define NPCM7XX_CLK_S_GFX "gfx0_gfx1_mem" 253fcfd1436STali Perry #define NPCM7XX_CLK_S_USBIF "serial_usbif" 254fcfd1436STali Perry #define NPCM7XX_CLK_S_USB_HOST "usb_host" 255fcfd1436STali Perry #define NPCM7XX_CLK_S_USB_BRIDGE "usb_bridge" 256fcfd1436STali Perry #define NPCM7XX_CLK_S_PCI "pci" 257fcfd1436STali Perry 258fcfd1436STali Perry static u32 pll_mux_table[] = {0, 1, 2, 3}; 259fcfd1436STali Perry static const char * const pll_mux_parents[] __initconst = { 260fcfd1436STali Perry NPCM7XX_CLK_S_PLL0, 261fcfd1436STali Perry NPCM7XX_CLK_S_PLL1_DIV2, 262fcfd1436STali Perry NPCM7XX_CLK_S_REFCLK, 263fcfd1436STali Perry NPCM7XX_CLK_S_PLL2_DIV2, 264fcfd1436STali Perry }; 265fcfd1436STali Perry 266fcfd1436STali Perry static u32 cpuck_mux_table[] = {0, 1, 2, 3}; 267fcfd1436STali Perry static const char * const cpuck_mux_parents[] __initconst = { 268fcfd1436STali Perry NPCM7XX_CLK_S_PLL0, 269fcfd1436STali Perry NPCM7XX_CLK_S_PLL1_DIV2, 270fcfd1436STali Perry NPCM7XX_CLK_S_REFCLK, 271fcfd1436STali Perry NPCM7XX_CLK_S_SYSBYPCK, 272fcfd1436STali Perry }; 273fcfd1436STali Perry 274fcfd1436STali Perry static u32 pixcksel_mux_table[] = {0, 2}; 275fcfd1436STali Perry static const char * const pixcksel_mux_parents[] __initconst = { 276fcfd1436STali Perry NPCM7XX_CLK_S_PLL_GFX, 277fcfd1436STali Perry NPCM7XX_CLK_S_REFCLK, 278fcfd1436STali Perry }; 279fcfd1436STali Perry 280fcfd1436STali Perry static u32 sucksel_mux_table[] = {2, 3}; 281fcfd1436STali Perry static const char * const sucksel_mux_parents[] __initconst = { 282fcfd1436STali Perry NPCM7XX_CLK_S_REFCLK, 283fcfd1436STali Perry NPCM7XX_CLK_S_PLL2_DIV2, 284fcfd1436STali Perry }; 285fcfd1436STali Perry 286fcfd1436STali Perry static u32 mccksel_mux_table[] = {0, 2, 3}; 287fcfd1436STali Perry static const char * const mccksel_mux_parents[] __initconst = { 288fcfd1436STali Perry NPCM7XX_CLK_S_PLL1_DIV2, 289fcfd1436STali Perry NPCM7XX_CLK_S_REFCLK, 290fcfd1436STali Perry NPCM7XX_CLK_S_MCBYPCK, 291fcfd1436STali Perry }; 292fcfd1436STali Perry 293fcfd1436STali Perry static u32 clkoutsel_mux_table[] = {0, 1, 2, 3, 4}; 294fcfd1436STali Perry static const char * const clkoutsel_mux_parents[] __initconst = { 295fcfd1436STali Perry NPCM7XX_CLK_S_PLL0, 296fcfd1436STali Perry NPCM7XX_CLK_S_PLL1_DIV2, 297fcfd1436STali Perry NPCM7XX_CLK_S_REFCLK, 298fcfd1436STali Perry NPCM7XX_CLK_S_PLL_GFX, // divided by 2 299fcfd1436STali Perry NPCM7XX_CLK_S_PLL2_DIV2, 300fcfd1436STali Perry }; 301fcfd1436STali Perry 302fcfd1436STali Perry static u32 gfxmsel_mux_table[] = {2, 3}; 303fcfd1436STali Perry static const char * const gfxmsel_mux_parents[] __initconst = { 304fcfd1436STali Perry NPCM7XX_CLK_S_REFCLK, 305fcfd1436STali Perry NPCM7XX_CLK_S_PLL2_DIV2, 306fcfd1436STali Perry }; 307fcfd1436STali Perry 308fcfd1436STali Perry static u32 dvcssel_mux_table[] = {2, 3}; 309fcfd1436STali Perry static const char * const dvcssel_mux_parents[] __initconst = { 310fcfd1436STali Perry NPCM7XX_CLK_S_REFCLK, 311fcfd1436STali Perry NPCM7XX_CLK_S_PLL2, 312fcfd1436STali Perry }; 313fcfd1436STali Perry 314fcfd1436STali Perry static const struct npcm7xx_clk_pll_data npcm7xx_plls[] __initconst = { 315fcfd1436STali Perry {NPCM7XX_PLLCON0, NPCM7XX_CLK_S_PLL0, NPCM7XX_CLK_S_REFCLK, 0, -1}, 316fcfd1436STali Perry 317fcfd1436STali Perry {NPCM7XX_PLLCON1, NPCM7XX_CLK_S_PLL1, 318fcfd1436STali Perry NPCM7XX_CLK_S_REFCLK, 0, -1}, 319fcfd1436STali Perry 320fcfd1436STali Perry {NPCM7XX_PLLCON2, NPCM7XX_CLK_S_PLL2, 321fcfd1436STali Perry NPCM7XX_CLK_S_REFCLK, 0, -1}, 322fcfd1436STali Perry 323fcfd1436STali Perry {NPCM7XX_PLLCONG, NPCM7XX_CLK_S_PLL_GFX, 324fcfd1436STali Perry NPCM7XX_CLK_S_REFCLK, 0, -1}, 325fcfd1436STali Perry }; 326fcfd1436STali Perry 327fcfd1436STali Perry static const struct npcm7xx_clk_mux_data npcm7xx_muxes[] __initconst = { 328fcfd1436STali Perry {0, GENMASK(1, 0), cpuck_mux_table, NPCM7XX_CLK_S_CPU_MUX, 329fcfd1436STali Perry cpuck_mux_parents, ARRAY_SIZE(cpuck_mux_parents), CLK_IS_CRITICAL, 330fcfd1436STali Perry NPCM7XX_CLK_CPU}, 331fcfd1436STali Perry 332fcfd1436STali Perry {4, GENMASK(1, 0), pixcksel_mux_table, NPCM7XX_CLK_S_PIX_MUX, 333fcfd1436STali Perry pixcksel_mux_parents, ARRAY_SIZE(pixcksel_mux_parents), 0, 334fcfd1436STali Perry NPCM7XX_CLK_GFX_PIXEL}, 335fcfd1436STali Perry 336fcfd1436STali Perry {6, GENMASK(1, 0), pll_mux_table, NPCM7XX_CLK_S_SD_MUX, 337fcfd1436STali Perry pll_mux_parents, ARRAY_SIZE(pll_mux_parents), 0, -1}, 338fcfd1436STali Perry 339fcfd1436STali Perry {8, GENMASK(1, 0), pll_mux_table, NPCM7XX_CLK_S_UART_MUX, 340fcfd1436STali Perry pll_mux_parents, ARRAY_SIZE(pll_mux_parents), 0, -1}, 341fcfd1436STali Perry 342fcfd1436STali Perry {10, GENMASK(1, 0), sucksel_mux_table, NPCM7XX_CLK_S_SU_MUX, 343fcfd1436STali Perry sucksel_mux_parents, ARRAY_SIZE(sucksel_mux_parents), 0, -1}, 344fcfd1436STali Perry 345fcfd1436STali Perry {12, GENMASK(1, 0), mccksel_mux_table, NPCM7XX_CLK_S_MC_MUX, 346fcfd1436STali Perry mccksel_mux_parents, ARRAY_SIZE(mccksel_mux_parents), 0, -1}, 347fcfd1436STali Perry 348fcfd1436STali Perry {14, GENMASK(1, 0), pll_mux_table, NPCM7XX_CLK_S_TIM_MUX, 349fcfd1436STali Perry pll_mux_parents, ARRAY_SIZE(pll_mux_parents), 0, -1}, 350fcfd1436STali Perry 351fcfd1436STali Perry {16, GENMASK(1, 0), pll_mux_table, NPCM7XX_CLK_S_GFX_MUX, 352fcfd1436STali Perry pll_mux_parents, ARRAY_SIZE(pll_mux_parents), 0, -1}, 353fcfd1436STali Perry 354fcfd1436STali Perry {18, GENMASK(2, 0), clkoutsel_mux_table, NPCM7XX_CLK_S_CLKOUT_MUX, 355fcfd1436STali Perry clkoutsel_mux_parents, ARRAY_SIZE(clkoutsel_mux_parents), 0, -1}, 356fcfd1436STali Perry 357fcfd1436STali Perry {21, GENMASK(1, 0), gfxmsel_mux_table, NPCM7XX_CLK_S_GFXM_MUX, 358fcfd1436STali Perry gfxmsel_mux_parents, ARRAY_SIZE(gfxmsel_mux_parents), 0, -1}, 359fcfd1436STali Perry 360fcfd1436STali Perry {23, GENMASK(1, 0), dvcssel_mux_table, NPCM7XX_CLK_S_DVC_MUX, 361fcfd1436STali Perry dvcssel_mux_parents, ARRAY_SIZE(dvcssel_mux_parents), 0, -1}, 362fcfd1436STali Perry }; 363fcfd1436STali Perry 364fcfd1436STali Perry /* fixed ratio dividers (no register): */ 365fcfd1436STali Perry static const struct npcm7xx_clk_div_fixed_data npcm7xx_divs_fx[] __initconst = { 366fcfd1436STali Perry { 1, 2, NPCM7XX_CLK_S_MC, NPCM7XX_CLK_S_MC_MUX, 0, NPCM7XX_CLK_MC}, 367fcfd1436STali Perry { 1, 2, NPCM7XX_CLK_S_PLL1_DIV2, NPCM7XX_CLK_S_PLL1, 0, -1}, 368fcfd1436STali Perry { 1, 2, NPCM7XX_CLK_S_PLL2_DIV2, NPCM7XX_CLK_S_PLL2, 0, -1}, 369fcfd1436STali Perry }; 370fcfd1436STali Perry 371fcfd1436STali Perry /* configurable dividers: */ 372fcfd1436STali Perry static const struct npcm7xx_clk_div_data npcm7xx_divs[] __initconst = { 373fcfd1436STali Perry {NPCM7XX_CLKDIV1, 28, 3, NPCM7XX_CLK_S_ADC, 374fcfd1436STali Perry NPCM7XX_CLK_S_TIMER, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_ADC}, 375fcfd1436STali Perry /*30-28 ADCCKDIV*/ 376fcfd1436STali Perry {NPCM7XX_CLKDIV1, 26, 2, NPCM7XX_CLK_S_AHB, 377fcfd1436STali Perry NPCM7XX_CLK_S_AXI, 0, CLK_IS_CRITICAL, NPCM7XX_CLK_AHB}, 378fcfd1436STali Perry /*27-26 CLK4DIV*/ 379fcfd1436STali Perry {NPCM7XX_CLKDIV1, 21, 5, NPCM7XX_CLK_S_TIMER, 380fcfd1436STali Perry NPCM7XX_CLK_S_TIM_MUX, 0, 0, NPCM7XX_CLK_TIMER}, 381fcfd1436STali Perry /*25-21 TIMCKDIV*/ 382fcfd1436STali Perry {NPCM7XX_CLKDIV1, 16, 5, NPCM7XX_CLK_S_UART, 383fcfd1436STali Perry NPCM7XX_CLK_S_UART_MUX, 0, 0, NPCM7XX_CLK_UART}, 384fcfd1436STali Perry /*20-16 UARTDIV*/ 385fcfd1436STali Perry {NPCM7XX_CLKDIV1, 11, 5, NPCM7XX_CLK_S_MMC, 386fcfd1436STali Perry NPCM7XX_CLK_S_SD_MUX, 0, 0, NPCM7XX_CLK_MMC}, 387fcfd1436STali Perry /*15-11 MMCCKDIV*/ 388fcfd1436STali Perry {NPCM7XX_CLKDIV1, 6, 5, NPCM7XX_CLK_S_SPI3, 389fcfd1436STali Perry NPCM7XX_CLK_S_AHB, 0, 0, NPCM7XX_CLK_SPI3}, 390fcfd1436STali Perry /*10-6 AHB3CKDIV*/ 391fcfd1436STali Perry {NPCM7XX_CLKDIV1, 2, 4, NPCM7XX_CLK_S_PCI, 392fcfd1436STali Perry NPCM7XX_CLK_S_GFX_MUX, 0, 0, NPCM7XX_CLK_PCI}, 393fcfd1436STali Perry /*5-2 PCICKDIV*/ 394fcfd1436STali Perry {NPCM7XX_CLKDIV1, 0, 1, NPCM7XX_CLK_S_AXI, 395fcfd1436STali Perry NPCM7XX_CLK_S_CPU_MUX, CLK_DIVIDER_POWER_OF_TWO, CLK_IS_CRITICAL, 396fcfd1436STali Perry NPCM7XX_CLK_AXI},/*0 CLK2DIV*/ 397fcfd1436STali Perry 398fcfd1436STali Perry {NPCM7XX_CLKDIV2, 30, 2, NPCM7XX_CLK_S_APB4, 399fcfd1436STali Perry NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB4}, 400fcfd1436STali Perry /*31-30 APB4CKDIV*/ 401fcfd1436STali Perry {NPCM7XX_CLKDIV2, 28, 2, NPCM7XX_CLK_S_APB3, 402fcfd1436STali Perry NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB3}, 403fcfd1436STali Perry /*29-28 APB3CKDIV*/ 404fcfd1436STali Perry {NPCM7XX_CLKDIV2, 26, 2, NPCM7XX_CLK_S_APB2, 405fcfd1436STali Perry NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB2}, 406fcfd1436STali Perry /*27-26 APB2CKDIV*/ 407fcfd1436STali Perry {NPCM7XX_CLKDIV2, 24, 2, NPCM7XX_CLK_S_APB1, 408fcfd1436STali Perry NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB1}, 409fcfd1436STali Perry /*25-24 APB1CKDIV*/ 410fcfd1436STali Perry {NPCM7XX_CLKDIV2, 22, 2, NPCM7XX_CLK_S_APB5, 411fcfd1436STali Perry NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB5}, 412fcfd1436STali Perry /*23-22 APB5CKDIV*/ 413fcfd1436STali Perry {NPCM7XX_CLKDIV2, 16, 5, NPCM7XX_CLK_S_CLKOUT, 414fcfd1436STali Perry NPCM7XX_CLK_S_CLKOUT_MUX, 0, 0, NPCM7XX_CLK_CLKOUT}, 415fcfd1436STali Perry /*20-16 CLKOUTDIV*/ 416fcfd1436STali Perry {NPCM7XX_CLKDIV2, 13, 3, NPCM7XX_CLK_S_GFX, 417fcfd1436STali Perry NPCM7XX_CLK_S_GFX_MUX, 0, 0, NPCM7XX_CLK_GFX}, 418fcfd1436STali Perry /*15-13 GFXCKDIV*/ 419fcfd1436STali Perry {NPCM7XX_CLKDIV2, 8, 5, NPCM7XX_CLK_S_USB_BRIDGE, 420fcfd1436STali Perry NPCM7XX_CLK_S_SU_MUX, 0, 0, NPCM7XX_CLK_SU}, 421fcfd1436STali Perry /*12-8 SUCKDIV*/ 422fcfd1436STali Perry {NPCM7XX_CLKDIV2, 4, 4, NPCM7XX_CLK_S_USB_HOST, 423fcfd1436STali Perry NPCM7XX_CLK_S_SU_MUX, 0, 0, NPCM7XX_CLK_SU48}, 424fcfd1436STali Perry /*7-4 SU48CKDIV*/ 425fcfd1436STali Perry {NPCM7XX_CLKDIV2, 0, 4, NPCM7XX_CLK_S_SDHC, 426fcfd1436STali Perry NPCM7XX_CLK_S_SD_MUX, 0, 0, NPCM7XX_CLK_SDHC} 427fcfd1436STali Perry ,/*3-0 SD1CKDIV*/ 428fcfd1436STali Perry 429fcfd1436STali Perry {NPCM7XX_CLKDIV3, 6, 5, NPCM7XX_CLK_S_SPI0, 430fcfd1436STali Perry NPCM7XX_CLK_S_AHB, 0, 0, NPCM7XX_CLK_SPI0}, 431fcfd1436STali Perry /*10-6 SPI0CKDV*/ 432fcfd1436STali Perry {NPCM7XX_CLKDIV3, 1, 5, NPCM7XX_CLK_S_SPIX, 433fcfd1436STali Perry NPCM7XX_CLK_S_AHB, 0, 0, NPCM7XX_CLK_SPIX}, 434fcfd1436STali Perry /*5-1 SPIXCKDV*/ 435fcfd1436STali Perry 436fcfd1436STali Perry }; 437fcfd1436STali Perry 438fcfd1436STali Perry static const struct npcm7xx_clk_gate_data npcm7xx_gates[] __initconst = { 439fcfd1436STali Perry {NPCM7XX_CLKEN1, 31, "smb1-gate", NPCM7XX_CLK_S_APB2, 0}, 440fcfd1436STali Perry {NPCM7XX_CLKEN1, 30, "smb0-gate", NPCM7XX_CLK_S_APB2, 0}, 441fcfd1436STali Perry {NPCM7XX_CLKEN1, 29, "smb7-gate", NPCM7XX_CLK_S_APB2, 0}, 442fcfd1436STali Perry {NPCM7XX_CLKEN1, 28, "smb6-gate", NPCM7XX_CLK_S_APB2, 0}, 443fcfd1436STali Perry {NPCM7XX_CLKEN1, 27, "adc-gate", NPCM7XX_CLK_S_APB1, 0}, 444fcfd1436STali Perry {NPCM7XX_CLKEN1, 26, "wdt-gate", NPCM7XX_CLK_S_TIMER, 0}, 445fcfd1436STali Perry {NPCM7XX_CLKEN1, 25, "usbdev3-gate", NPCM7XX_CLK_S_AHB, 0}, 446fcfd1436STali Perry {NPCM7XX_CLKEN1, 24, "usbdev6-gate", NPCM7XX_CLK_S_AHB, 0}, 447fcfd1436STali Perry {NPCM7XX_CLKEN1, 23, "usbdev5-gate", NPCM7XX_CLK_S_AHB, 0}, 448fcfd1436STali Perry {NPCM7XX_CLKEN1, 22, "usbdev4-gate", NPCM7XX_CLK_S_AHB, 0}, 449fcfd1436STali Perry {NPCM7XX_CLKEN1, 21, "emc2-gate", NPCM7XX_CLK_S_AHB, 0}, 450fcfd1436STali Perry {NPCM7XX_CLKEN1, 20, "timer5_9-gate", NPCM7XX_CLK_S_APB1, 0}, 451fcfd1436STali Perry {NPCM7XX_CLKEN1, 19, "timer0_4-gate", NPCM7XX_CLK_S_APB1, 0}, 452fcfd1436STali Perry {NPCM7XX_CLKEN1, 18, "pwmm0-gate", NPCM7XX_CLK_S_APB3, 0}, 453fcfd1436STali Perry {NPCM7XX_CLKEN1, 17, "huart-gate", NPCM7XX_CLK_S_UART, 0}, 454fcfd1436STali Perry {NPCM7XX_CLKEN1, 16, "smb5-gate", NPCM7XX_CLK_S_APB2, 0}, 455fcfd1436STali Perry {NPCM7XX_CLKEN1, 15, "smb4-gate", NPCM7XX_CLK_S_APB2, 0}, 456fcfd1436STali Perry {NPCM7XX_CLKEN1, 14, "smb3-gate", NPCM7XX_CLK_S_APB2, 0}, 457fcfd1436STali Perry {NPCM7XX_CLKEN1, 13, "smb2-gate", NPCM7XX_CLK_S_APB2, 0}, 458fcfd1436STali Perry {NPCM7XX_CLKEN1, 12, "mc-gate", NPCM7XX_CLK_S_MC, 0}, 459fcfd1436STali Perry {NPCM7XX_CLKEN1, 11, "uart01-gate", NPCM7XX_CLK_S_APB1, 0}, 460fcfd1436STali Perry {NPCM7XX_CLKEN1, 10, "aes-gate", NPCM7XX_CLK_S_AHB, 0}, 461fcfd1436STali Perry {NPCM7XX_CLKEN1, 9, "peci-gate", NPCM7XX_CLK_S_APB3, 0}, 462fcfd1436STali Perry {NPCM7XX_CLKEN1, 8, "usbdev2-gate", NPCM7XX_CLK_S_AHB, 0}, 463fcfd1436STali Perry {NPCM7XX_CLKEN1, 7, "uart23-gate", NPCM7XX_CLK_S_APB1, 0}, 464fcfd1436STali Perry {NPCM7XX_CLKEN1, 6, "emc1-gate", NPCM7XX_CLK_S_AHB, 0}, 465fcfd1436STali Perry {NPCM7XX_CLKEN1, 5, "usbdev1-gate", NPCM7XX_CLK_S_AHB, 0}, 466fcfd1436STali Perry {NPCM7XX_CLKEN1, 4, "shm-gate", NPCM7XX_CLK_S_AHB, 0}, 467fcfd1436STali Perry /* bit 3 is reserved */ 468fcfd1436STali Perry {NPCM7XX_CLKEN1, 2, "kcs-gate", NPCM7XX_CLK_S_APB1, 0}, 469fcfd1436STali Perry {NPCM7XX_CLKEN1, 1, "spi3-gate", NPCM7XX_CLK_S_AHB, 0}, 470fcfd1436STali Perry {NPCM7XX_CLKEN1, 0, "spi0-gate", NPCM7XX_CLK_S_AHB, 0}, 471fcfd1436STali Perry 472fcfd1436STali Perry {NPCM7XX_CLKEN2, 31, "cp-gate", NPCM7XX_CLK_S_AHB, 0}, 473fcfd1436STali Perry {NPCM7XX_CLKEN2, 30, "tock-gate", NPCM7XX_CLK_S_TOCK, 0}, 474fcfd1436STali Perry /* bit 29 is reserved */ 475fcfd1436STali Perry {NPCM7XX_CLKEN2, 28, "gmac1-gate", NPCM7XX_CLK_S_AHB, 0}, 476fcfd1436STali Perry {NPCM7XX_CLKEN2, 27, "usbif-gate", NPCM7XX_CLK_S_USBIF, 0}, 477fcfd1436STali Perry {NPCM7XX_CLKEN2, 26, "usbhost-gate", NPCM7XX_CLK_S_AHB, 0}, 478fcfd1436STali Perry {NPCM7XX_CLKEN2, 25, "gmac2-gate", NPCM7XX_CLK_S_AHB, 0}, 479fcfd1436STali Perry /* bit 24 is reserved */ 480fcfd1436STali Perry {NPCM7XX_CLKEN2, 23, "pspi2-gate", NPCM7XX_CLK_S_APB5, 0}, 481fcfd1436STali Perry {NPCM7XX_CLKEN2, 22, "pspi1-gate", NPCM7XX_CLK_S_APB5, 0}, 482fcfd1436STali Perry {NPCM7XX_CLKEN2, 21, "3des-gate", NPCM7XX_CLK_S_AHB, 0}, 483fcfd1436STali Perry /* bit 20 is reserved */ 484fcfd1436STali Perry {NPCM7XX_CLKEN2, 19, "siox2-gate", NPCM7XX_CLK_S_APB3, 0}, 485fcfd1436STali Perry {NPCM7XX_CLKEN2, 18, "siox1-gate", NPCM7XX_CLK_S_APB3, 0}, 486fcfd1436STali Perry /* bit 17 is reserved */ 487fcfd1436STali Perry {NPCM7XX_CLKEN2, 16, "fuse-gate", NPCM7XX_CLK_S_APB4, 0}, 488fcfd1436STali Perry /* bit 15 is reserved */ 489fcfd1436STali Perry {NPCM7XX_CLKEN2, 14, "vcd-gate", NPCM7XX_CLK_S_AHB, 0}, 490fcfd1436STali Perry {NPCM7XX_CLKEN2, 13, "ece-gate", NPCM7XX_CLK_S_AHB, 0}, 491fcfd1436STali Perry {NPCM7XX_CLKEN2, 12, "vdma-gate", NPCM7XX_CLK_S_AHB, 0}, 492fcfd1436STali Perry {NPCM7XX_CLKEN2, 11, "ahbpcibrg-gate", NPCM7XX_CLK_S_AHB, 0}, 493fcfd1436STali Perry {NPCM7XX_CLKEN2, 10, "gfxsys-gate", NPCM7XX_CLK_S_APB1, 0}, 494fcfd1436STali Perry {NPCM7XX_CLKEN2, 9, "sdhc-gate", NPCM7XX_CLK_S_AHB, 0}, 495fcfd1436STali Perry {NPCM7XX_CLKEN2, 8, "mmc-gate", NPCM7XX_CLK_S_AHB, 0}, 496fcfd1436STali Perry {NPCM7XX_CLKEN2, 7, "mft7-gate", NPCM7XX_CLK_S_APB4, 0}, 497fcfd1436STali Perry {NPCM7XX_CLKEN2, 6, "mft6-gate", NPCM7XX_CLK_S_APB4, 0}, 498fcfd1436STali Perry {NPCM7XX_CLKEN2, 5, "mft5-gate", NPCM7XX_CLK_S_APB4, 0}, 499fcfd1436STali Perry {NPCM7XX_CLKEN2, 4, "mft4-gate", NPCM7XX_CLK_S_APB4, 0}, 500fcfd1436STali Perry {NPCM7XX_CLKEN2, 3, "mft3-gate", NPCM7XX_CLK_S_APB4, 0}, 501fcfd1436STali Perry {NPCM7XX_CLKEN2, 2, "mft2-gate", NPCM7XX_CLK_S_APB4, 0}, 502fcfd1436STali Perry {NPCM7XX_CLKEN2, 1, "mft1-gate", NPCM7XX_CLK_S_APB4, 0}, 503fcfd1436STali Perry {NPCM7XX_CLKEN2, 0, "mft0-gate", NPCM7XX_CLK_S_APB4, 0}, 504fcfd1436STali Perry 505fcfd1436STali Perry {NPCM7XX_CLKEN3, 31, "gpiom7-gate", NPCM7XX_CLK_S_APB1, 0}, 506fcfd1436STali Perry {NPCM7XX_CLKEN3, 30, "gpiom6-gate", NPCM7XX_CLK_S_APB1, 0}, 507fcfd1436STali Perry {NPCM7XX_CLKEN3, 29, "gpiom5-gate", NPCM7XX_CLK_S_APB1, 0}, 508fcfd1436STali Perry {NPCM7XX_CLKEN3, 28, "gpiom4-gate", NPCM7XX_CLK_S_APB1, 0}, 509fcfd1436STali Perry {NPCM7XX_CLKEN3, 27, "gpiom3-gate", NPCM7XX_CLK_S_APB1, 0}, 510fcfd1436STali Perry {NPCM7XX_CLKEN3, 26, "gpiom2-gate", NPCM7XX_CLK_S_APB1, 0}, 511fcfd1436STali Perry {NPCM7XX_CLKEN3, 25, "gpiom1-gate", NPCM7XX_CLK_S_APB1, 0}, 512fcfd1436STali Perry {NPCM7XX_CLKEN3, 24, "gpiom0-gate", NPCM7XX_CLK_S_APB1, 0}, 513fcfd1436STali Perry {NPCM7XX_CLKEN3, 23, "espi-gate", NPCM7XX_CLK_S_APB2, 0}, 514fcfd1436STali Perry {NPCM7XX_CLKEN3, 22, "smb11-gate", NPCM7XX_CLK_S_APB2, 0}, 515fcfd1436STali Perry {NPCM7XX_CLKEN3, 21, "smb10-gate", NPCM7XX_CLK_S_APB2, 0}, 516fcfd1436STali Perry {NPCM7XX_CLKEN3, 20, "smb9-gate", NPCM7XX_CLK_S_APB2, 0}, 517fcfd1436STali Perry {NPCM7XX_CLKEN3, 19, "smb8-gate", NPCM7XX_CLK_S_APB2, 0}, 518fcfd1436STali Perry {NPCM7XX_CLKEN3, 18, "smb15-gate", NPCM7XX_CLK_S_APB2, 0}, 519fcfd1436STali Perry {NPCM7XX_CLKEN3, 17, "rng-gate", NPCM7XX_CLK_S_APB1, 0}, 520fcfd1436STali Perry {NPCM7XX_CLKEN3, 16, "timer10_14-gate", NPCM7XX_CLK_S_APB1, 0}, 521fcfd1436STali Perry {NPCM7XX_CLKEN3, 15, "pcirc-gate", NPCM7XX_CLK_S_AHB, 0}, 522fcfd1436STali Perry {NPCM7XX_CLKEN3, 14, "sececc-gate", NPCM7XX_CLK_S_AHB, 0}, 523fcfd1436STali Perry {NPCM7XX_CLKEN3, 13, "sha-gate", NPCM7XX_CLK_S_AHB, 0}, 524fcfd1436STali Perry {NPCM7XX_CLKEN3, 12, "smb14-gate", NPCM7XX_CLK_S_APB2, 0}, 525fcfd1436STali Perry /* bit 11 is reserved */ 526fcfd1436STali Perry /* bit 10 is reserved */ 527fcfd1436STali Perry {NPCM7XX_CLKEN3, 9, "pcimbx-gate", NPCM7XX_CLK_S_AHB, 0}, 528fcfd1436STali Perry /* bit 8 is reserved */ 529fcfd1436STali Perry {NPCM7XX_CLKEN3, 7, "usbdev9-gate", NPCM7XX_CLK_S_AHB, 0}, 530fcfd1436STali Perry {NPCM7XX_CLKEN3, 6, "usbdev8-gate", NPCM7XX_CLK_S_AHB, 0}, 531fcfd1436STali Perry {NPCM7XX_CLKEN3, 5, "usbdev7-gate", NPCM7XX_CLK_S_AHB, 0}, 532fcfd1436STali Perry {NPCM7XX_CLKEN3, 4, "usbdev0-gate", NPCM7XX_CLK_S_AHB, 0}, 533fcfd1436STali Perry {NPCM7XX_CLKEN3, 3, "smb13-gate", NPCM7XX_CLK_S_APB2, 0}, 534fcfd1436STali Perry {NPCM7XX_CLKEN3, 2, "spix-gate", NPCM7XX_CLK_S_AHB, 0}, 535fcfd1436STali Perry {NPCM7XX_CLKEN3, 1, "smb12-gate", NPCM7XX_CLK_S_APB2, 0}, 536fcfd1436STali Perry {NPCM7XX_CLKEN3, 0, "pwmm1-gate", NPCM7XX_CLK_S_APB3, 0}, 537fcfd1436STali Perry }; 538fcfd1436STali Perry 539fcfd1436STali Perry static DEFINE_SPINLOCK(npcm7xx_clk_lock); 540fcfd1436STali Perry 541fcfd1436STali Perry static void __init npcm7xx_clk_init(struct device_node *clk_np) 542fcfd1436STali Perry { 543fcfd1436STali Perry struct clk_hw_onecell_data *npcm7xx_clk_data; 544fcfd1436STali Perry void __iomem *clk_base; 545fcfd1436STali Perry struct resource res; 546fcfd1436STali Perry struct clk_hw *hw; 547fcfd1436STali Perry int ret; 548fcfd1436STali Perry int i; 549fcfd1436STali Perry 550fcfd1436STali Perry ret = of_address_to_resource(clk_np, 0, &res); 551fcfd1436STali Perry if (ret) { 552fcfd1436STali Perry pr_err("%s: failed to get resource, ret %d\n", clk_np->name, 553fcfd1436STali Perry ret); 554fcfd1436STali Perry return; 555fcfd1436STali Perry } 556fcfd1436STali Perry 557fcfd1436STali Perry clk_base = ioremap(res.start, resource_size(&res)); 5581646337bSWei Yongjun if (!clk_base) 559fcfd1436STali Perry goto npcm7xx_init_error; 560fcfd1436STali Perry 561*450b6b9bSGustavo A. R. Silva npcm7xx_clk_data = kzalloc(struct_size(npcm7xx_clk_data, hws, 562*450b6b9bSGustavo A. R. Silva NPCM7XX_NUM_CLOCKS), GFP_KERNEL); 563fcfd1436STali Perry if (!npcm7xx_clk_data) 564fcfd1436STali Perry goto npcm7xx_init_np_err; 565fcfd1436STali Perry 566fcfd1436STali Perry npcm7xx_clk_data->num = NPCM7XX_NUM_CLOCKS; 567fcfd1436STali Perry 568fcfd1436STali Perry for (i = 0; i < NPCM7XX_NUM_CLOCKS; i++) 569fcfd1436STali Perry npcm7xx_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER); 570fcfd1436STali Perry 571fcfd1436STali Perry /* Register plls */ 572fcfd1436STali Perry for (i = 0; i < ARRAY_SIZE(npcm7xx_plls); i++) { 573fcfd1436STali Perry const struct npcm7xx_clk_pll_data *pll_data = &npcm7xx_plls[i]; 574fcfd1436STali Perry 575fcfd1436STali Perry hw = npcm7xx_clk_register_pll(clk_base + pll_data->reg, 576fcfd1436STali Perry pll_data->name, pll_data->parent_name, pll_data->flags); 577fcfd1436STali Perry if (IS_ERR(hw)) { 578fcfd1436STali Perry pr_err("npcm7xx_clk: Can't register pll\n"); 579fcfd1436STali Perry goto npcm7xx_init_fail; 580fcfd1436STali Perry } 581fcfd1436STali Perry 582fcfd1436STali Perry if (pll_data->onecell_idx >= 0) 583fcfd1436STali Perry npcm7xx_clk_data->hws[pll_data->onecell_idx] = hw; 584fcfd1436STali Perry } 585fcfd1436STali Perry 586fcfd1436STali Perry /* Register fixed dividers */ 587fcfd1436STali Perry hw = clk_hw_register_fixed_factor(NULL, NPCM7XX_CLK_S_PLL1_DIV2, 588fcfd1436STali Perry NPCM7XX_CLK_S_PLL1, 0, 1, 2); 589fcfd1436STali Perry if (IS_ERR(hw)) { 590fcfd1436STali Perry pr_err("npcm7xx_clk: Can't register fixed div\n"); 591fcfd1436STali Perry goto npcm7xx_init_fail; 592fcfd1436STali Perry } 593fcfd1436STali Perry 594fcfd1436STali Perry hw = clk_hw_register_fixed_factor(NULL, NPCM7XX_CLK_S_PLL2_DIV2, 595fcfd1436STali Perry NPCM7XX_CLK_S_PLL2, 0, 1, 2); 596fcfd1436STali Perry if (IS_ERR(hw)) { 597fcfd1436STali Perry pr_err("npcm7xx_clk: Can't register div2\n"); 598fcfd1436STali Perry goto npcm7xx_init_fail; 599fcfd1436STali Perry } 600fcfd1436STali Perry 601fcfd1436STali Perry /* Register muxes */ 602fcfd1436STali Perry for (i = 0; i < ARRAY_SIZE(npcm7xx_muxes); i++) { 603fcfd1436STali Perry const struct npcm7xx_clk_mux_data *mux_data = &npcm7xx_muxes[i]; 604fcfd1436STali Perry 605fcfd1436STali Perry hw = clk_hw_register_mux_table(NULL, 606fcfd1436STali Perry mux_data->name, 607fcfd1436STali Perry mux_data->parent_names, mux_data->num_parents, 608fcfd1436STali Perry mux_data->flags, clk_base + NPCM7XX_CLKSEL, 609fcfd1436STali Perry mux_data->shift, mux_data->mask, 0, 610fcfd1436STali Perry mux_data->table, &npcm7xx_clk_lock); 611fcfd1436STali Perry 612fcfd1436STali Perry if (IS_ERR(hw)) { 613fcfd1436STali Perry pr_err("npcm7xx_clk: Can't register mux\n"); 614fcfd1436STali Perry goto npcm7xx_init_fail; 615fcfd1436STali Perry } 616fcfd1436STali Perry 617fcfd1436STali Perry if (mux_data->onecell_idx >= 0) 618fcfd1436STali Perry npcm7xx_clk_data->hws[mux_data->onecell_idx] = hw; 619fcfd1436STali Perry } 620fcfd1436STali Perry 621fcfd1436STali Perry /* Register clock dividers specified in npcm7xx_divs */ 622fcfd1436STali Perry for (i = 0; i < ARRAY_SIZE(npcm7xx_divs); i++) { 623fcfd1436STali Perry const struct npcm7xx_clk_div_data *div_data = &npcm7xx_divs[i]; 624fcfd1436STali Perry 625fcfd1436STali Perry hw = clk_hw_register_divider(NULL, div_data->name, 626fcfd1436STali Perry div_data->parent_name, 627fcfd1436STali Perry div_data->flags, 628fcfd1436STali Perry clk_base + div_data->reg, 629fcfd1436STali Perry div_data->shift, div_data->width, 630fcfd1436STali Perry div_data->clk_divider_flags, &npcm7xx_clk_lock); 631fcfd1436STali Perry if (IS_ERR(hw)) { 632fcfd1436STali Perry pr_err("npcm7xx_clk: Can't register div table\n"); 633fcfd1436STali Perry goto npcm7xx_init_fail; 634fcfd1436STali Perry } 635fcfd1436STali Perry 636fcfd1436STali Perry if (div_data->onecell_idx >= 0) 637fcfd1436STali Perry npcm7xx_clk_data->hws[div_data->onecell_idx] = hw; 638fcfd1436STali Perry } 639fcfd1436STali Perry 640fcfd1436STali Perry ret = of_clk_add_hw_provider(clk_np, of_clk_hw_onecell_get, 641fcfd1436STali Perry npcm7xx_clk_data); 642fcfd1436STali Perry if (ret) 643fcfd1436STali Perry pr_err("failed to add DT provider: %d\n", ret); 644fcfd1436STali Perry 645fcfd1436STali Perry of_node_put(clk_np); 646fcfd1436STali Perry 647fcfd1436STali Perry return; 648fcfd1436STali Perry 649fcfd1436STali Perry npcm7xx_init_fail: 650fcfd1436STali Perry kfree(npcm7xx_clk_data->hws); 651fcfd1436STali Perry npcm7xx_init_np_err: 652fcfd1436STali Perry iounmap(clk_base); 653fcfd1436STali Perry npcm7xx_init_error: 654fcfd1436STali Perry of_node_put(clk_np); 655fcfd1436STali Perry } 656fcfd1436STali Perry CLK_OF_DECLARE(npcm7xx_clk_init, "nuvoton,npcm750-clk", npcm7xx_clk_init); 657