162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Marvell PXA3xxx family clocks 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2014 Robert Jarzmik 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Heavily inspired from former arch/arm/mach-pxa/pxa3xx.c 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * For non-devicetree platforms. Once pxa is fully converted to devicetree, this 1062306a36Sopenharmony_ci * should go away. 1162306a36Sopenharmony_ci */ 1262306a36Sopenharmony_ci#include <linux/io.h> 1362306a36Sopenharmony_ci#include <linux/clk.h> 1462306a36Sopenharmony_ci#include <linux/clk-provider.h> 1562306a36Sopenharmony_ci#include <linux/clkdev.h> 1662306a36Sopenharmony_ci#include <linux/of.h> 1762306a36Sopenharmony_ci#include <linux/soc/pxa/cpu.h> 1862306a36Sopenharmony_ci#include <linux/soc/pxa/smemc.h> 1962306a36Sopenharmony_ci#include <linux/clk/pxa.h> 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#include <dt-bindings/clock/pxa-clock.h> 2262306a36Sopenharmony_ci#include "clk-pxa.h" 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#define KHz 1000 2562306a36Sopenharmony_ci#define MHz (1000 * 1000) 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#define ACCR (0x0000) /* Application Subsystem Clock Configuration Register */ 2862306a36Sopenharmony_ci#define ACSR (0x0004) /* Application Subsystem Clock Status Register */ 2962306a36Sopenharmony_ci#define AICSR (0x0008) /* Application Subsystem Interrupt Control/Status Register */ 3062306a36Sopenharmony_ci#define CKENA (0x000C) /* A Clock Enable Register */ 3162306a36Sopenharmony_ci#define CKENB (0x0010) /* B Clock Enable Register */ 3262306a36Sopenharmony_ci#define CKENC (0x0024) /* C Clock Enable Register */ 3362306a36Sopenharmony_ci#define AC97_DIV (0x0014) /* AC97 clock divisor value register */ 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#define ACCR_XPDIS (1 << 31) /* Core PLL Output Disable */ 3662306a36Sopenharmony_ci#define ACCR_SPDIS (1 << 30) /* System PLL Output Disable */ 3762306a36Sopenharmony_ci#define ACCR_D0CS (1 << 26) /* D0 Mode Clock Select */ 3862306a36Sopenharmony_ci#define ACCR_PCCE (1 << 11) /* Power Mode Change Clock Enable */ 3962306a36Sopenharmony_ci#define ACCR_DDR_D0CS (1 << 7) /* DDR SDRAM clock frequency in D0CS (PXA31x only) */ 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#define ACCR_SMCFS_MASK (0x7 << 23) /* Static Memory Controller Frequency Select */ 4262306a36Sopenharmony_ci#define ACCR_SFLFS_MASK (0x3 << 18) /* Frequency Select for Internal Memory Controller */ 4362306a36Sopenharmony_ci#define ACCR_XSPCLK_MASK (0x3 << 16) /* Core Frequency during Frequency Change */ 4462306a36Sopenharmony_ci#define ACCR_HSS_MASK (0x3 << 14) /* System Bus-Clock Frequency Select */ 4562306a36Sopenharmony_ci#define ACCR_DMCFS_MASK (0x3 << 12) /* Dynamic Memory Controller Clock Frequency Select */ 4662306a36Sopenharmony_ci#define ACCR_XN_MASK (0x7 << 8) /* Core PLL Turbo-Mode-to-Run-Mode Ratio */ 4762306a36Sopenharmony_ci#define ACCR_XL_MASK (0x1f) /* Core PLL Run-Mode-to-Oscillator Ratio */ 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci#define ACCR_SMCFS(x) (((x) & 0x7) << 23) 5062306a36Sopenharmony_ci#define ACCR_SFLFS(x) (((x) & 0x3) << 18) 5162306a36Sopenharmony_ci#define ACCR_XSPCLK(x) (((x) & 0x3) << 16) 5262306a36Sopenharmony_ci#define ACCR_HSS(x) (((x) & 0x3) << 14) 5362306a36Sopenharmony_ci#define ACCR_DMCFS(x) (((x) & 0x3) << 12) 5462306a36Sopenharmony_ci#define ACCR_XN(x) (((x) & 0x7) << 8) 5562306a36Sopenharmony_ci#define ACCR_XL(x) ((x) & 0x1f) 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci/* 5862306a36Sopenharmony_ci * Clock Enable Bit 5962306a36Sopenharmony_ci */ 6062306a36Sopenharmony_ci#define CKEN_LCD 1 /* < LCD Clock Enable */ 6162306a36Sopenharmony_ci#define CKEN_USBH 2 /* < USB host clock enable */ 6262306a36Sopenharmony_ci#define CKEN_CAMERA 3 /* < Camera interface clock enable */ 6362306a36Sopenharmony_ci#define CKEN_NAND 4 /* < NAND Flash Controller Clock Enable */ 6462306a36Sopenharmony_ci#define CKEN_USB2 6 /* < USB 2.0 client clock enable. */ 6562306a36Sopenharmony_ci#define CKEN_DMC 8 /* < Dynamic Memory Controller clock enable */ 6662306a36Sopenharmony_ci#define CKEN_SMC 9 /* < Static Memory Controller clock enable */ 6762306a36Sopenharmony_ci#define CKEN_ISC 10 /* < Internal SRAM Controller clock enable */ 6862306a36Sopenharmony_ci#define CKEN_BOOT 11 /* < Boot rom clock enable */ 6962306a36Sopenharmony_ci#define CKEN_MMC1 12 /* < MMC1 Clock enable */ 7062306a36Sopenharmony_ci#define CKEN_MMC2 13 /* < MMC2 clock enable */ 7162306a36Sopenharmony_ci#define CKEN_KEYPAD 14 /* < Keypand Controller Clock Enable */ 7262306a36Sopenharmony_ci#define CKEN_CIR 15 /* < Consumer IR Clock Enable */ 7362306a36Sopenharmony_ci#define CKEN_USIM0 17 /* < USIM[0] Clock Enable */ 7462306a36Sopenharmony_ci#define CKEN_USIM1 18 /* < USIM[1] Clock Enable */ 7562306a36Sopenharmony_ci#define CKEN_TPM 19 /* < TPM clock enable */ 7662306a36Sopenharmony_ci#define CKEN_UDC 20 /* < UDC clock enable */ 7762306a36Sopenharmony_ci#define CKEN_BTUART 21 /* < BTUART clock enable */ 7862306a36Sopenharmony_ci#define CKEN_FFUART 22 /* < FFUART clock enable */ 7962306a36Sopenharmony_ci#define CKEN_STUART 23 /* < STUART clock enable */ 8062306a36Sopenharmony_ci#define CKEN_AC97 24 /* < AC97 clock enable */ 8162306a36Sopenharmony_ci#define CKEN_TOUCH 25 /* < Touch screen Interface Clock Enable */ 8262306a36Sopenharmony_ci#define CKEN_SSP1 26 /* < SSP1 clock enable */ 8362306a36Sopenharmony_ci#define CKEN_SSP2 27 /* < SSP2 clock enable */ 8462306a36Sopenharmony_ci#define CKEN_SSP3 28 /* < SSP3 clock enable */ 8562306a36Sopenharmony_ci#define CKEN_SSP4 29 /* < SSP4 clock enable */ 8662306a36Sopenharmony_ci#define CKEN_MSL0 30 /* < MSL0 clock enable */ 8762306a36Sopenharmony_ci#define CKEN_PWM0 32 /* < PWM[0] clock enable */ 8862306a36Sopenharmony_ci#define CKEN_PWM1 33 /* < PWM[1] clock enable */ 8962306a36Sopenharmony_ci#define CKEN_I2C 36 /* < I2C clock enable */ 9062306a36Sopenharmony_ci#define CKEN_INTC 38 /* < Interrupt controller clock enable */ 9162306a36Sopenharmony_ci#define CKEN_GPIO 39 /* < GPIO clock enable */ 9262306a36Sopenharmony_ci#define CKEN_1WIRE 40 /* < 1-wire clock enable */ 9362306a36Sopenharmony_ci#define CKEN_HSIO2 41 /* < HSIO2 clock enable */ 9462306a36Sopenharmony_ci#define CKEN_MINI_IM 48 /* < Mini-IM */ 9562306a36Sopenharmony_ci#define CKEN_MINI_LCD 49 /* < Mini LCD */ 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci#define CKEN_MMC3 5 /* < MMC3 Clock Enable */ 9862306a36Sopenharmony_ci#define CKEN_MVED 43 /* < MVED clock enable */ 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci/* Note: GCU clock enable bit differs on PXA300/PXA310 and PXA320 */ 10162306a36Sopenharmony_ci#define CKEN_PXA300_GCU 42 /* Graphics controller clock enable */ 10262306a36Sopenharmony_ci#define CKEN_PXA320_GCU 7 /* Graphics controller clock enable */ 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_cienum { 10662306a36Sopenharmony_ci PXA_CORE_60Mhz = 0, 10762306a36Sopenharmony_ci PXA_CORE_RUN, 10862306a36Sopenharmony_ci PXA_CORE_TURBO, 10962306a36Sopenharmony_ci}; 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_cienum { 11262306a36Sopenharmony_ci PXA_BUS_60Mhz = 0, 11362306a36Sopenharmony_ci PXA_BUS_HSS, 11462306a36Sopenharmony_ci}; 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci/* crystal frequency to HSIO bus frequency multiplier (HSS) */ 11762306a36Sopenharmony_cistatic unsigned char hss_mult[4] = { 8, 12, 16, 24 }; 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci/* crystal frequency to static memory controller multiplier (SMCFS) */ 12062306a36Sopenharmony_cistatic unsigned int smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, }; 12162306a36Sopenharmony_cistatic const char * const get_freq_khz[] = { 12262306a36Sopenharmony_ci "core", "ring_osc_60mhz", "run", "cpll", "system_bus" 12362306a36Sopenharmony_ci}; 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_cistatic void __iomem *clk_regs; 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci/* 12862306a36Sopenharmony_ci * Get the clock frequency as reflected by ACSR and the turbo flag. 12962306a36Sopenharmony_ci * We assume these values have been applied via a fcs. 13062306a36Sopenharmony_ci * If info is not 0 we also display the current settings. 13162306a36Sopenharmony_ci */ 13262306a36Sopenharmony_ciunsigned int pxa3xx_get_clk_frequency_khz(int info) 13362306a36Sopenharmony_ci{ 13462306a36Sopenharmony_ci struct clk *clk; 13562306a36Sopenharmony_ci unsigned long clks[5]; 13662306a36Sopenharmony_ci int i; 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci for (i = 0; i < 5; i++) { 13962306a36Sopenharmony_ci clk = clk_get(NULL, get_freq_khz[i]); 14062306a36Sopenharmony_ci if (IS_ERR(clk)) { 14162306a36Sopenharmony_ci clks[i] = 0; 14262306a36Sopenharmony_ci } else { 14362306a36Sopenharmony_ci clks[i] = clk_get_rate(clk); 14462306a36Sopenharmony_ci clk_put(clk); 14562306a36Sopenharmony_ci } 14662306a36Sopenharmony_ci } 14762306a36Sopenharmony_ci if (info) { 14862306a36Sopenharmony_ci pr_info("RO Mode clock: %ld.%02ldMHz\n", 14962306a36Sopenharmony_ci clks[1] / 1000000, (clks[0] % 1000000) / 10000); 15062306a36Sopenharmony_ci pr_info("Run Mode clock: %ld.%02ldMHz\n", 15162306a36Sopenharmony_ci clks[2] / 1000000, (clks[1] % 1000000) / 10000); 15262306a36Sopenharmony_ci pr_info("Turbo Mode clock: %ld.%02ldMHz\n", 15362306a36Sopenharmony_ci clks[3] / 1000000, (clks[2] % 1000000) / 10000); 15462306a36Sopenharmony_ci pr_info("System bus clock: %ld.%02ldMHz\n", 15562306a36Sopenharmony_ci clks[4] / 1000000, (clks[4] % 1000000) / 10000); 15662306a36Sopenharmony_ci } 15762306a36Sopenharmony_ci return (unsigned int)clks[0] / KHz; 15862306a36Sopenharmony_ci} 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_civoid pxa3xx_clk_update_accr(u32 disable, u32 enable, u32 xclkcfg, u32 mask) 16162306a36Sopenharmony_ci{ 16262306a36Sopenharmony_ci u32 accr = readl(clk_regs + ACCR); 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci accr &= ~disable; 16562306a36Sopenharmony_ci accr |= enable; 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci writel(accr, clk_regs + ACCR); 16862306a36Sopenharmony_ci if (xclkcfg) 16962306a36Sopenharmony_ci __asm__("mcr p14, 0, %0, c6, c0, 0\n" : : "r"(xclkcfg)); 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci while ((readl(clk_regs + ACSR) & mask) != (accr & mask)) 17262306a36Sopenharmony_ci cpu_relax(); 17362306a36Sopenharmony_ci} 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_cistatic unsigned long clk_pxa3xx_ac97_get_rate(struct clk_hw *hw, 17662306a36Sopenharmony_ci unsigned long parent_rate) 17762306a36Sopenharmony_ci{ 17862306a36Sopenharmony_ci unsigned long ac97_div, rate; 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci ac97_div = readl(clk_regs + AC97_DIV); 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci /* This may loose precision for some rates but won't for the 18362306a36Sopenharmony_ci * standard 24.576MHz. 18462306a36Sopenharmony_ci */ 18562306a36Sopenharmony_ci rate = parent_rate / 2; 18662306a36Sopenharmony_ci rate /= ((ac97_div >> 12) & 0x7fff); 18762306a36Sopenharmony_ci rate *= (ac97_div & 0xfff); 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci return rate; 19062306a36Sopenharmony_ci} 19162306a36Sopenharmony_ciPARENTS(clk_pxa3xx_ac97) = { "spll_624mhz" }; 19262306a36Sopenharmony_ciRATE_RO_OPS(clk_pxa3xx_ac97, "ac97"); 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_cistatic unsigned long clk_pxa3xx_smemc_get_rate(struct clk_hw *hw, 19562306a36Sopenharmony_ci unsigned long parent_rate) 19662306a36Sopenharmony_ci{ 19762306a36Sopenharmony_ci unsigned long acsr = readl(clk_regs + ACSR); 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci return (parent_rate / 48) * smcfs_mult[(acsr >> 23) & 0x7] / 20062306a36Sopenharmony_ci pxa3xx_smemc_get_memclkdiv(); 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_ci} 20362306a36Sopenharmony_ciPARENTS(clk_pxa3xx_smemc) = { "spll_624mhz" }; 20462306a36Sopenharmony_ciRATE_RO_OPS(clk_pxa3xx_smemc, "smemc"); 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_cistatic bool pxa3xx_is_ring_osc_forced(void) 20762306a36Sopenharmony_ci{ 20862306a36Sopenharmony_ci unsigned long acsr = readl(clk_regs + ACSR); 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci return acsr & ACCR_D0CS; 21162306a36Sopenharmony_ci} 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_ciPARENTS(pxa3xx_pbus) = { "ring_osc_60mhz", "spll_624mhz" }; 21462306a36Sopenharmony_ciPARENTS(pxa3xx_32Khz_bus) = { "osc_32_768khz", "osc_32_768khz" }; 21562306a36Sopenharmony_ciPARENTS(pxa3xx_13MHz_bus) = { "osc_13mhz", "osc_13mhz" }; 21662306a36Sopenharmony_ciPARENTS(pxa3xx_ac97_bus) = { "ring_osc_60mhz", "ac97" }; 21762306a36Sopenharmony_ciPARENTS(pxa3xx_sbus) = { "ring_osc_60mhz", "system_bus" }; 21862306a36Sopenharmony_ciPARENTS(pxa3xx_smemcbus) = { "ring_osc_60mhz", "smemc" }; 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ci#define CKEN_AB(bit) ((CKEN_ ## bit > 31) ? CKENB : CKENA) 22162306a36Sopenharmony_ci#define PXA3XX_CKEN(dev_id, con_id, parents, mult_lp, div_lp, mult_hp, \ 22262306a36Sopenharmony_ci div_hp, bit, is_lp, flags) \ 22362306a36Sopenharmony_ci PXA_CKEN(dev_id, con_id, bit, parents, mult_lp, div_lp, \ 22462306a36Sopenharmony_ci mult_hp, div_hp, is_lp, CKEN_AB(bit), \ 22562306a36Sopenharmony_ci (CKEN_ ## bit % 32), flags) 22662306a36Sopenharmony_ci#define PXA3XX_PBUS_CKEN(dev_id, con_id, bit, mult_lp, div_lp, \ 22762306a36Sopenharmony_ci mult_hp, div_hp, delay) \ 22862306a36Sopenharmony_ci PXA3XX_CKEN(dev_id, con_id, pxa3xx_pbus_parents, mult_lp, \ 22962306a36Sopenharmony_ci div_lp, mult_hp, div_hp, bit, pxa3xx_is_ring_osc_forced, 0) 23062306a36Sopenharmony_ci#define PXA3XX_CKEN_1RATE(dev_id, con_id, bit, parents) \ 23162306a36Sopenharmony_ci PXA_CKEN_1RATE(dev_id, con_id, bit, parents, \ 23262306a36Sopenharmony_ci CKEN_AB(bit), (CKEN_ ## bit % 32), 0) 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_cistatic struct desc_clk_cken pxa3xx_clocks[] __initdata = { 23562306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa2xx-uart.0", NULL, FFUART, 1, 4, 1, 42, 1), 23662306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa2xx-uart.1", NULL, BTUART, 1, 4, 1, 42, 1), 23762306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa2xx-uart.2", NULL, STUART, 1, 4, 1, 42, 1), 23862306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa2xx-i2c.0", NULL, I2C, 2, 5, 1, 19, 0), 23962306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa27x-udc", NULL, UDC, 1, 4, 1, 13, 5), 24062306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa27x-ohci", NULL, USBH, 1, 4, 1, 13, 0), 24162306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa3xx-u2d", NULL, USB2, 1, 4, 1, 13, 0), 24262306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa27x-pwm.0", NULL, PWM0, 1, 6, 1, 48, 0), 24362306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa27x-pwm.1", NULL, PWM1, 1, 6, 1, 48, 0), 24462306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa2xx-mci.0", NULL, MMC1, 1, 4, 1, 24, 0), 24562306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa2xx-mci.1", NULL, MMC2, 1, 4, 1, 24, 0), 24662306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa2xx-mci.2", NULL, MMC3, 1, 4, 1, 24, 0), 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci PXA3XX_CKEN_1RATE("pxa27x-keypad", NULL, KEYPAD, 24962306a36Sopenharmony_ci pxa3xx_32Khz_bus_parents), 25062306a36Sopenharmony_ci PXA3XX_CKEN_1RATE("pxa3xx-ssp.0", NULL, SSP1, pxa3xx_13MHz_bus_parents), 25162306a36Sopenharmony_ci PXA3XX_CKEN_1RATE("pxa3xx-ssp.1", NULL, SSP2, pxa3xx_13MHz_bus_parents), 25262306a36Sopenharmony_ci PXA3XX_CKEN_1RATE("pxa3xx-ssp.2", NULL, SSP3, pxa3xx_13MHz_bus_parents), 25362306a36Sopenharmony_ci PXA3XX_CKEN_1RATE("pxa3xx-ssp.3", NULL, SSP4, pxa3xx_13MHz_bus_parents), 25462306a36Sopenharmony_ci 25562306a36Sopenharmony_ci PXA3XX_CKEN(NULL, "AC97CLK", pxa3xx_ac97_bus_parents, 1, 4, 1, 1, AC97, 25662306a36Sopenharmony_ci pxa3xx_is_ring_osc_forced, 0), 25762306a36Sopenharmony_ci PXA3XX_CKEN(NULL, "CAMCLK", pxa3xx_sbus_parents, 1, 2, 1, 1, CAMERA, 25862306a36Sopenharmony_ci pxa3xx_is_ring_osc_forced, 0), 25962306a36Sopenharmony_ci PXA3XX_CKEN("pxa2xx-fb", NULL, pxa3xx_sbus_parents, 1, 1, 1, 1, LCD, 26062306a36Sopenharmony_ci pxa3xx_is_ring_osc_forced, 0), 26162306a36Sopenharmony_ci PXA3XX_CKEN("pxa2xx-pcmcia", NULL, pxa3xx_smemcbus_parents, 1, 4, 26262306a36Sopenharmony_ci 1, 1, SMC, pxa3xx_is_ring_osc_forced, CLK_IGNORE_UNUSED), 26362306a36Sopenharmony_ci}; 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_cistatic struct desc_clk_cken pxa300_310_clocks[] __initdata = { 26662306a36Sopenharmony_ci 26762306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa3xx-gcu", NULL, PXA300_GCU, 1, 1, 1, 1, 0), 26862306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa3xx-nand", NULL, NAND, 1, 2, 1, 4, 0), 26962306a36Sopenharmony_ci PXA3XX_CKEN_1RATE("pxa3xx-gpio", NULL, GPIO, pxa3xx_13MHz_bus_parents), 27062306a36Sopenharmony_ci}; 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_cistatic struct desc_clk_cken pxa320_clocks[] __initdata = { 27362306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa3xx-nand", NULL, NAND, 1, 2, 1, 6, 0), 27462306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa3xx-gcu", NULL, PXA320_GCU, 1, 1, 1, 1, 0), 27562306a36Sopenharmony_ci PXA3XX_CKEN_1RATE("pxa3xx-gpio", NULL, GPIO, pxa3xx_13MHz_bus_parents), 27662306a36Sopenharmony_ci}; 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_cistatic struct desc_clk_cken pxa93x_clocks[] __initdata = { 27962306a36Sopenharmony_ci 28062306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa3xx-gcu", NULL, PXA300_GCU, 1, 1, 1, 1, 0), 28162306a36Sopenharmony_ci PXA3XX_PBUS_CKEN("pxa3xx-nand", NULL, NAND, 1, 2, 1, 4, 0), 28262306a36Sopenharmony_ci PXA3XX_CKEN_1RATE("pxa93x-gpio", NULL, GPIO, pxa3xx_13MHz_bus_parents), 28362306a36Sopenharmony_ci}; 28462306a36Sopenharmony_ci 28562306a36Sopenharmony_cistatic unsigned long clk_pxa3xx_system_bus_get_rate(struct clk_hw *hw, 28662306a36Sopenharmony_ci unsigned long parent_rate) 28762306a36Sopenharmony_ci{ 28862306a36Sopenharmony_ci unsigned long acsr = readl(clk_regs + ACSR); 28962306a36Sopenharmony_ci unsigned int hss = (acsr >> 14) & 0x3; 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_ci if (pxa3xx_is_ring_osc_forced()) 29262306a36Sopenharmony_ci return parent_rate; 29362306a36Sopenharmony_ci return parent_rate / 48 * hss_mult[hss]; 29462306a36Sopenharmony_ci} 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_cistatic u8 clk_pxa3xx_system_bus_get_parent(struct clk_hw *hw) 29762306a36Sopenharmony_ci{ 29862306a36Sopenharmony_ci if (pxa3xx_is_ring_osc_forced()) 29962306a36Sopenharmony_ci return PXA_BUS_60Mhz; 30062306a36Sopenharmony_ci else 30162306a36Sopenharmony_ci return PXA_BUS_HSS; 30262306a36Sopenharmony_ci} 30362306a36Sopenharmony_ci 30462306a36Sopenharmony_ciPARENTS(clk_pxa3xx_system_bus) = { "ring_osc_60mhz", "spll_624mhz" }; 30562306a36Sopenharmony_ciMUX_RO_RATE_RO_OPS(clk_pxa3xx_system_bus, "system_bus"); 30662306a36Sopenharmony_ci 30762306a36Sopenharmony_cistatic unsigned long clk_pxa3xx_core_get_rate(struct clk_hw *hw, 30862306a36Sopenharmony_ci unsigned long parent_rate) 30962306a36Sopenharmony_ci{ 31062306a36Sopenharmony_ci return parent_rate; 31162306a36Sopenharmony_ci} 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_cistatic u8 clk_pxa3xx_core_get_parent(struct clk_hw *hw) 31462306a36Sopenharmony_ci{ 31562306a36Sopenharmony_ci unsigned long xclkcfg; 31662306a36Sopenharmony_ci unsigned int t; 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_ci if (pxa3xx_is_ring_osc_forced()) 31962306a36Sopenharmony_ci return PXA_CORE_60Mhz; 32062306a36Sopenharmony_ci 32162306a36Sopenharmony_ci /* Read XCLKCFG register turbo bit */ 32262306a36Sopenharmony_ci __asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg)); 32362306a36Sopenharmony_ci t = xclkcfg & 0x1; 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_ci if (t) 32662306a36Sopenharmony_ci return PXA_CORE_TURBO; 32762306a36Sopenharmony_ci return PXA_CORE_RUN; 32862306a36Sopenharmony_ci} 32962306a36Sopenharmony_ciPARENTS(clk_pxa3xx_core) = { "ring_osc_60mhz", "run", "cpll" }; 33062306a36Sopenharmony_ciMUX_RO_RATE_RO_OPS(clk_pxa3xx_core, "core"); 33162306a36Sopenharmony_ci 33262306a36Sopenharmony_cistatic unsigned long clk_pxa3xx_run_get_rate(struct clk_hw *hw, 33362306a36Sopenharmony_ci unsigned long parent_rate) 33462306a36Sopenharmony_ci{ 33562306a36Sopenharmony_ci unsigned long acsr = readl(clk_regs + ACSR); 33662306a36Sopenharmony_ci unsigned int xn = (acsr & ACCR_XN_MASK) >> 8; 33762306a36Sopenharmony_ci unsigned int t, xclkcfg; 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ci /* Read XCLKCFG register turbo bit */ 34062306a36Sopenharmony_ci __asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg)); 34162306a36Sopenharmony_ci t = xclkcfg & 0x1; 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ci return t ? (parent_rate / xn) * 2 : parent_rate; 34462306a36Sopenharmony_ci} 34562306a36Sopenharmony_ciPARENTS(clk_pxa3xx_run) = { "cpll" }; 34662306a36Sopenharmony_ciRATE_RO_OPS(clk_pxa3xx_run, "run"); 34762306a36Sopenharmony_ci 34862306a36Sopenharmony_cistatic unsigned long clk_pxa3xx_cpll_get_rate(struct clk_hw *hw, 34962306a36Sopenharmony_ci unsigned long parent_rate) 35062306a36Sopenharmony_ci{ 35162306a36Sopenharmony_ci unsigned long acsr = readl(clk_regs + ACSR); 35262306a36Sopenharmony_ci unsigned int xn = (acsr & ACCR_XN_MASK) >> 8; 35362306a36Sopenharmony_ci unsigned int xl = acsr & ACCR_XL_MASK; 35462306a36Sopenharmony_ci unsigned int t, xclkcfg; 35562306a36Sopenharmony_ci 35662306a36Sopenharmony_ci /* Read XCLKCFG register turbo bit */ 35762306a36Sopenharmony_ci __asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg)); 35862306a36Sopenharmony_ci t = xclkcfg & 0x1; 35962306a36Sopenharmony_ci 36062306a36Sopenharmony_ci pr_info("RJK: parent_rate=%lu, xl=%u, xn=%u\n", parent_rate, xl, xn); 36162306a36Sopenharmony_ci return t ? parent_rate * xl * xn : parent_rate * xl; 36262306a36Sopenharmony_ci} 36362306a36Sopenharmony_ciPARENTS(clk_pxa3xx_cpll) = { "osc_13mhz" }; 36462306a36Sopenharmony_ciRATE_RO_OPS(clk_pxa3xx_cpll, "cpll"); 36562306a36Sopenharmony_ci 36662306a36Sopenharmony_cistatic void __init pxa3xx_register_core(void) 36762306a36Sopenharmony_ci{ 36862306a36Sopenharmony_ci clk_register_clk_pxa3xx_cpll(); 36962306a36Sopenharmony_ci clk_register_clk_pxa3xx_run(); 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ci clkdev_pxa_register(CLK_CORE, "core", NULL, 37262306a36Sopenharmony_ci clk_register_clk_pxa3xx_core()); 37362306a36Sopenharmony_ci} 37462306a36Sopenharmony_ci 37562306a36Sopenharmony_cistatic void __init pxa3xx_register_plls(void) 37662306a36Sopenharmony_ci{ 37762306a36Sopenharmony_ci clk_register_fixed_rate(NULL, "osc_13mhz", NULL, 37862306a36Sopenharmony_ci CLK_GET_RATE_NOCACHE, 37962306a36Sopenharmony_ci 13 * MHz); 38062306a36Sopenharmony_ci clkdev_pxa_register(CLK_OSC32k768, "osc_32_768khz", NULL, 38162306a36Sopenharmony_ci clk_register_fixed_rate(NULL, "osc_32_768khz", NULL, 38262306a36Sopenharmony_ci CLK_GET_RATE_NOCACHE, 38362306a36Sopenharmony_ci 32768)); 38462306a36Sopenharmony_ci clk_register_fixed_rate(NULL, "ring_osc_120mhz", NULL, 38562306a36Sopenharmony_ci CLK_GET_RATE_NOCACHE, 38662306a36Sopenharmony_ci 120 * MHz); 38762306a36Sopenharmony_ci clk_register_fixed_rate(NULL, "clk_dummy", NULL, 0, 0); 38862306a36Sopenharmony_ci clk_register_fixed_factor(NULL, "spll_624mhz", "osc_13mhz", 0, 48, 1); 38962306a36Sopenharmony_ci clk_register_fixed_factor(NULL, "ring_osc_60mhz", "ring_osc_120mhz", 39062306a36Sopenharmony_ci 0, 1, 2); 39162306a36Sopenharmony_ci} 39262306a36Sopenharmony_ci 39362306a36Sopenharmony_ci#define DUMMY_CLK(_con_id, _dev_id, _parent) \ 39462306a36Sopenharmony_ci { .con_id = _con_id, .dev_id = _dev_id, .parent = _parent } 39562306a36Sopenharmony_cistruct dummy_clk { 39662306a36Sopenharmony_ci const char *con_id; 39762306a36Sopenharmony_ci const char *dev_id; 39862306a36Sopenharmony_ci const char *parent; 39962306a36Sopenharmony_ci}; 40062306a36Sopenharmony_cistatic struct dummy_clk dummy_clks[] __initdata = { 40162306a36Sopenharmony_ci DUMMY_CLK(NULL, "pxa93x-gpio", "osc_13mhz"), 40262306a36Sopenharmony_ci DUMMY_CLK(NULL, "sa1100-rtc", "osc_32_768khz"), 40362306a36Sopenharmony_ci DUMMY_CLK("UARTCLK", "pxa2xx-ir", "STUART"), 40462306a36Sopenharmony_ci DUMMY_CLK(NULL, "pxa3xx-pwri2c.1", "osc_13mhz"), 40562306a36Sopenharmony_ci}; 40662306a36Sopenharmony_ci 40762306a36Sopenharmony_cistatic void __init pxa3xx_dummy_clocks_init(void) 40862306a36Sopenharmony_ci{ 40962306a36Sopenharmony_ci struct clk *clk; 41062306a36Sopenharmony_ci struct dummy_clk *d; 41162306a36Sopenharmony_ci const char *name; 41262306a36Sopenharmony_ci int i; 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dummy_clks); i++) { 41562306a36Sopenharmony_ci d = &dummy_clks[i]; 41662306a36Sopenharmony_ci name = d->dev_id ? d->dev_id : d->con_id; 41762306a36Sopenharmony_ci clk = clk_register_fixed_factor(NULL, name, d->parent, 0, 1, 1); 41862306a36Sopenharmony_ci clk_register_clkdev(clk, d->con_id, d->dev_id); 41962306a36Sopenharmony_ci } 42062306a36Sopenharmony_ci} 42162306a36Sopenharmony_ci 42262306a36Sopenharmony_cistatic void __init pxa3xx_base_clocks_init(void __iomem *oscc_reg) 42362306a36Sopenharmony_ci{ 42462306a36Sopenharmony_ci struct clk *clk; 42562306a36Sopenharmony_ci 42662306a36Sopenharmony_ci pxa3xx_register_plls(); 42762306a36Sopenharmony_ci pxa3xx_register_core(); 42862306a36Sopenharmony_ci clk_register_clk_pxa3xx_system_bus(); 42962306a36Sopenharmony_ci clk_register_clk_pxa3xx_ac97(); 43062306a36Sopenharmony_ci clk_register_clk_pxa3xx_smemc(); 43162306a36Sopenharmony_ci clk = clk_register_gate(NULL, "CLK_POUT", 43262306a36Sopenharmony_ci "osc_13mhz", 0, oscc_reg, 11, 0, NULL); 43362306a36Sopenharmony_ci clk_register_clkdev(clk, "CLK_POUT", NULL); 43462306a36Sopenharmony_ci clkdev_pxa_register(CLK_OSTIMER, "OSTIMER0", NULL, 43562306a36Sopenharmony_ci clk_register_fixed_factor(NULL, "os-timer0", 43662306a36Sopenharmony_ci "osc_13mhz", 0, 1, 4)); 43762306a36Sopenharmony_ci} 43862306a36Sopenharmony_ci 43962306a36Sopenharmony_ciint __init pxa3xx_clocks_init(void __iomem *regs, void __iomem *oscc_reg) 44062306a36Sopenharmony_ci{ 44162306a36Sopenharmony_ci int ret; 44262306a36Sopenharmony_ci 44362306a36Sopenharmony_ci clk_regs = regs; 44462306a36Sopenharmony_ci pxa3xx_base_clocks_init(oscc_reg); 44562306a36Sopenharmony_ci pxa3xx_dummy_clocks_init(); 44662306a36Sopenharmony_ci ret = clk_pxa_cken_init(pxa3xx_clocks, ARRAY_SIZE(pxa3xx_clocks), regs); 44762306a36Sopenharmony_ci if (ret) 44862306a36Sopenharmony_ci return ret; 44962306a36Sopenharmony_ci if (cpu_is_pxa320()) 45062306a36Sopenharmony_ci return clk_pxa_cken_init(pxa320_clocks, 45162306a36Sopenharmony_ci ARRAY_SIZE(pxa320_clocks), regs); 45262306a36Sopenharmony_ci if (cpu_is_pxa300() || cpu_is_pxa310()) 45362306a36Sopenharmony_ci return clk_pxa_cken_init(pxa300_310_clocks, 45462306a36Sopenharmony_ci ARRAY_SIZE(pxa300_310_clocks), regs); 45562306a36Sopenharmony_ci return clk_pxa_cken_init(pxa93x_clocks, ARRAY_SIZE(pxa93x_clocks), regs); 45662306a36Sopenharmony_ci} 45762306a36Sopenharmony_ci 45862306a36Sopenharmony_cistatic void __init pxa3xx_dt_clocks_init(struct device_node *np) 45962306a36Sopenharmony_ci{ 46062306a36Sopenharmony_ci pxa3xx_clocks_init(ioremap(0x41340000, 0x10), ioremap(0x41350000, 4)); 46162306a36Sopenharmony_ci clk_pxa_dt_common_init(np); 46262306a36Sopenharmony_ci} 46362306a36Sopenharmony_ciCLK_OF_DECLARE(pxa_clks, "marvell,pxa300-clocks", pxa3xx_dt_clocks_init); 464