18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Marvell PXA3xxx family clocks
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2014 Robert Jarzmik
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Heavily inspired from former arch/arm/mach-pxa/pxa3xx.c
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * For non-devicetree platforms. Once pxa is fully converted to devicetree, this
108c2ecf20Sopenharmony_ci * should go away.
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci#include <linux/io.h>
138c2ecf20Sopenharmony_ci#include <linux/clk.h>
148c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
158c2ecf20Sopenharmony_ci#include <linux/clkdev.h>
168c2ecf20Sopenharmony_ci#include <linux/of.h>
178c2ecf20Sopenharmony_ci#include <mach/smemc.h>
188c2ecf20Sopenharmony_ci#include <mach/pxa3xx-regs.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <dt-bindings/clock/pxa-clock.h>
218c2ecf20Sopenharmony_ci#include "clk-pxa.h"
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define KHz 1000
248c2ecf20Sopenharmony_ci#define MHz (1000 * 1000)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cienum {
278c2ecf20Sopenharmony_ci	PXA_CORE_60Mhz = 0,
288c2ecf20Sopenharmony_ci	PXA_CORE_RUN,
298c2ecf20Sopenharmony_ci	PXA_CORE_TURBO,
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cienum {
338c2ecf20Sopenharmony_ci	PXA_BUS_60Mhz = 0,
348c2ecf20Sopenharmony_ci	PXA_BUS_HSS,
358c2ecf20Sopenharmony_ci};
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/* crystal frequency to HSIO bus frequency multiplier (HSS) */
388c2ecf20Sopenharmony_cistatic unsigned char hss_mult[4] = { 8, 12, 16, 24 };
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/* crystal frequency to static memory controller multiplier (SMCFS) */
418c2ecf20Sopenharmony_cistatic unsigned int smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, };
428c2ecf20Sopenharmony_cistatic unsigned int df_clkdiv[4] = { 1, 2, 4, 1 };
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic const char * const get_freq_khz[] = {
458c2ecf20Sopenharmony_ci	"core", "ring_osc_60mhz", "run", "cpll", "system_bus"
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/*
498c2ecf20Sopenharmony_ci * Get the clock frequency as reflected by ACSR and the turbo flag.
508c2ecf20Sopenharmony_ci * We assume these values have been applied via a fcs.
518c2ecf20Sopenharmony_ci * If info is not 0 we also display the current settings.
528c2ecf20Sopenharmony_ci */
538c2ecf20Sopenharmony_ciunsigned int pxa3xx_get_clk_frequency_khz(int info)
548c2ecf20Sopenharmony_ci{
558c2ecf20Sopenharmony_ci	struct clk *clk;
568c2ecf20Sopenharmony_ci	unsigned long clks[5];
578c2ecf20Sopenharmony_ci	int i;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	for (i = 0; i < 5; i++) {
608c2ecf20Sopenharmony_ci		clk = clk_get(NULL, get_freq_khz[i]);
618c2ecf20Sopenharmony_ci		if (IS_ERR(clk)) {
628c2ecf20Sopenharmony_ci			clks[i] = 0;
638c2ecf20Sopenharmony_ci		} else {
648c2ecf20Sopenharmony_ci			clks[i] = clk_get_rate(clk);
658c2ecf20Sopenharmony_ci			clk_put(clk);
668c2ecf20Sopenharmony_ci		}
678c2ecf20Sopenharmony_ci	}
688c2ecf20Sopenharmony_ci	if (info) {
698c2ecf20Sopenharmony_ci		pr_info("RO Mode clock: %ld.%02ldMHz\n",
708c2ecf20Sopenharmony_ci			clks[1] / 1000000, (clks[0] % 1000000) / 10000);
718c2ecf20Sopenharmony_ci		pr_info("Run Mode clock: %ld.%02ldMHz\n",
728c2ecf20Sopenharmony_ci			clks[2] / 1000000, (clks[1] % 1000000) / 10000);
738c2ecf20Sopenharmony_ci		pr_info("Turbo Mode clock: %ld.%02ldMHz\n",
748c2ecf20Sopenharmony_ci			clks[3] / 1000000, (clks[2] % 1000000) / 10000);
758c2ecf20Sopenharmony_ci		pr_info("System bus clock: %ld.%02ldMHz\n",
768c2ecf20Sopenharmony_ci			clks[4] / 1000000, (clks[4] % 1000000) / 10000);
778c2ecf20Sopenharmony_ci	}
788c2ecf20Sopenharmony_ci	return (unsigned int)clks[0] / KHz;
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistatic unsigned long clk_pxa3xx_ac97_get_rate(struct clk_hw *hw,
828c2ecf20Sopenharmony_ci					     unsigned long parent_rate)
838c2ecf20Sopenharmony_ci{
848c2ecf20Sopenharmony_ci	unsigned long ac97_div, rate;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	ac97_div = AC97_DIV;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	/* This may loose precision for some rates but won't for the
898c2ecf20Sopenharmony_ci	 * standard 24.576MHz.
908c2ecf20Sopenharmony_ci	 */
918c2ecf20Sopenharmony_ci	rate = parent_rate / 2;
928c2ecf20Sopenharmony_ci	rate /= ((ac97_div >> 12) & 0x7fff);
938c2ecf20Sopenharmony_ci	rate *= (ac97_div & 0xfff);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	return rate;
968c2ecf20Sopenharmony_ci}
978c2ecf20Sopenharmony_ciPARENTS(clk_pxa3xx_ac97) = { "spll_624mhz" };
988c2ecf20Sopenharmony_ciRATE_RO_OPS(clk_pxa3xx_ac97, "ac97");
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cistatic unsigned long clk_pxa3xx_smemc_get_rate(struct clk_hw *hw,
1018c2ecf20Sopenharmony_ci					      unsigned long parent_rate)
1028c2ecf20Sopenharmony_ci{
1038c2ecf20Sopenharmony_ci	unsigned long acsr = ACSR;
1048c2ecf20Sopenharmony_ci	unsigned long memclkcfg = __raw_readl(MEMCLKCFG);
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	return (parent_rate / 48)  * smcfs_mult[(acsr >> 23) & 0x7] /
1078c2ecf20Sopenharmony_ci		df_clkdiv[(memclkcfg >> 16) & 0x3];
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ciPARENTS(clk_pxa3xx_smemc) = { "spll_624mhz" };
1108c2ecf20Sopenharmony_ciRATE_RO_OPS(clk_pxa3xx_smemc, "smemc");
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_cistatic bool pxa3xx_is_ring_osc_forced(void)
1138c2ecf20Sopenharmony_ci{
1148c2ecf20Sopenharmony_ci	unsigned long acsr = ACSR;
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci	return acsr & ACCR_D0CS;
1178c2ecf20Sopenharmony_ci}
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ciPARENTS(pxa3xx_pbus) = { "ring_osc_60mhz", "spll_624mhz" };
1208c2ecf20Sopenharmony_ciPARENTS(pxa3xx_32Khz_bus) = { "osc_32_768khz", "osc_32_768khz" };
1218c2ecf20Sopenharmony_ciPARENTS(pxa3xx_13MHz_bus) = { "osc_13mhz", "osc_13mhz" };
1228c2ecf20Sopenharmony_ciPARENTS(pxa3xx_ac97_bus) = { "ring_osc_60mhz", "ac97" };
1238c2ecf20Sopenharmony_ciPARENTS(pxa3xx_sbus) = { "ring_osc_60mhz", "system_bus" };
1248c2ecf20Sopenharmony_ciPARENTS(pxa3xx_smemcbus) = { "ring_osc_60mhz", "smemc" };
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#define CKEN_AB(bit) ((CKEN_ ## bit > 31) ? &CKENB : &CKENA)
1278c2ecf20Sopenharmony_ci#define PXA3XX_CKEN(dev_id, con_id, parents, mult_lp, div_lp, mult_hp,	\
1288c2ecf20Sopenharmony_ci		    div_hp, bit, is_lp, flags)				\
1298c2ecf20Sopenharmony_ci	PXA_CKEN(dev_id, con_id, bit, parents, mult_lp, div_lp,		\
1308c2ecf20Sopenharmony_ci		 mult_hp, div_hp, is_lp,  CKEN_AB(bit),			\
1318c2ecf20Sopenharmony_ci		 (CKEN_ ## bit % 32), flags)
1328c2ecf20Sopenharmony_ci#define PXA3XX_PBUS_CKEN(dev_id, con_id, bit, mult_lp, div_lp,		\
1338c2ecf20Sopenharmony_ci			 mult_hp, div_hp, delay)			\
1348c2ecf20Sopenharmony_ci	PXA3XX_CKEN(dev_id, con_id, pxa3xx_pbus_parents, mult_lp,	\
1358c2ecf20Sopenharmony_ci		    div_lp, mult_hp, div_hp, bit, pxa3xx_is_ring_osc_forced, 0)
1368c2ecf20Sopenharmony_ci#define PXA3XX_CKEN_1RATE(dev_id, con_id, bit, parents)			\
1378c2ecf20Sopenharmony_ci	PXA_CKEN_1RATE(dev_id, con_id, bit, parents,			\
1388c2ecf20Sopenharmony_ci		       CKEN_AB(bit), (CKEN_ ## bit % 32), 0)
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistatic struct desc_clk_cken pxa3xx_clocks[] __initdata = {
1418c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa2xx-uart.0", NULL, FFUART, 1, 4, 1, 42, 1),
1428c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa2xx-uart.1", NULL, BTUART, 1, 4, 1, 42, 1),
1438c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa2xx-uart.2", NULL, STUART, 1, 4, 1, 42, 1),
1448c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa2xx-i2c.0", NULL, I2C, 2, 5, 1, 19, 0),
1458c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa27x-udc", NULL, UDC, 1, 4, 1, 13, 5),
1468c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa27x-ohci", NULL, USBH, 1, 4, 1, 13, 0),
1478c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa3xx-u2d", NULL, USB2, 1, 4, 1, 13, 0),
1488c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa27x-pwm.0", NULL, PWM0, 1, 6, 1, 48, 0),
1498c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa27x-pwm.1", NULL, PWM1, 1, 6, 1, 48, 0),
1508c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa2xx-mci.0", NULL, MMC1, 1, 4, 1, 24, 0),
1518c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa2xx-mci.1", NULL, MMC2, 1, 4, 1, 24, 0),
1528c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa2xx-mci.2", NULL, MMC3, 1, 4, 1, 24, 0),
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	PXA3XX_CKEN_1RATE("pxa27x-keypad", NULL, KEYPAD,
1558c2ecf20Sopenharmony_ci			  pxa3xx_32Khz_bus_parents),
1568c2ecf20Sopenharmony_ci	PXA3XX_CKEN_1RATE("pxa3xx-ssp.0", NULL, SSP1, pxa3xx_13MHz_bus_parents),
1578c2ecf20Sopenharmony_ci	PXA3XX_CKEN_1RATE("pxa3xx-ssp.1", NULL, SSP2, pxa3xx_13MHz_bus_parents),
1588c2ecf20Sopenharmony_ci	PXA3XX_CKEN_1RATE("pxa3xx-ssp.2", NULL, SSP3, pxa3xx_13MHz_bus_parents),
1598c2ecf20Sopenharmony_ci	PXA3XX_CKEN_1RATE("pxa3xx-ssp.3", NULL, SSP4, pxa3xx_13MHz_bus_parents),
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci	PXA3XX_CKEN(NULL, "AC97CLK", pxa3xx_ac97_bus_parents, 1, 4, 1, 1, AC97,
1628c2ecf20Sopenharmony_ci		    pxa3xx_is_ring_osc_forced, 0),
1638c2ecf20Sopenharmony_ci	PXA3XX_CKEN(NULL, "CAMCLK", pxa3xx_sbus_parents, 1, 2, 1, 1, CAMERA,
1648c2ecf20Sopenharmony_ci		    pxa3xx_is_ring_osc_forced, 0),
1658c2ecf20Sopenharmony_ci	PXA3XX_CKEN("pxa2xx-fb", NULL, pxa3xx_sbus_parents, 1, 1, 1, 1, LCD,
1668c2ecf20Sopenharmony_ci		    pxa3xx_is_ring_osc_forced, 0),
1678c2ecf20Sopenharmony_ci	PXA3XX_CKEN("pxa2xx-pcmcia", NULL, pxa3xx_smemcbus_parents, 1, 4,
1688c2ecf20Sopenharmony_ci		    1, 1, SMC, pxa3xx_is_ring_osc_forced, CLK_IGNORE_UNUSED),
1698c2ecf20Sopenharmony_ci};
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_cistatic struct desc_clk_cken pxa300_310_clocks[] __initdata = {
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa3xx-gcu", NULL, PXA300_GCU, 1, 1, 1, 1, 0),
1748c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa3xx-nand", NULL, NAND, 1, 2, 1, 4, 0),
1758c2ecf20Sopenharmony_ci	PXA3XX_CKEN_1RATE("pxa3xx-gpio", NULL, GPIO, pxa3xx_13MHz_bus_parents),
1768c2ecf20Sopenharmony_ci};
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_cistatic struct desc_clk_cken pxa320_clocks[] __initdata = {
1798c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa3xx-nand", NULL, NAND, 1, 2, 1, 6, 0),
1808c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa3xx-gcu", NULL, PXA320_GCU, 1, 1, 1, 1, 0),
1818c2ecf20Sopenharmony_ci	PXA3XX_CKEN_1RATE("pxa3xx-gpio", NULL, GPIO, pxa3xx_13MHz_bus_parents),
1828c2ecf20Sopenharmony_ci};
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_cistatic struct desc_clk_cken pxa93x_clocks[] __initdata = {
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa3xx-gcu", NULL, PXA300_GCU, 1, 1, 1, 1, 0),
1878c2ecf20Sopenharmony_ci	PXA3XX_PBUS_CKEN("pxa3xx-nand", NULL, NAND, 1, 2, 1, 4, 0),
1888c2ecf20Sopenharmony_ci	PXA3XX_CKEN_1RATE("pxa93x-gpio", NULL, GPIO, pxa3xx_13MHz_bus_parents),
1898c2ecf20Sopenharmony_ci};
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_cistatic unsigned long clk_pxa3xx_system_bus_get_rate(struct clk_hw *hw,
1928c2ecf20Sopenharmony_ci					    unsigned long parent_rate)
1938c2ecf20Sopenharmony_ci{
1948c2ecf20Sopenharmony_ci	unsigned long acsr = ACSR;
1958c2ecf20Sopenharmony_ci	unsigned int hss = (acsr >> 14) & 0x3;
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	if (pxa3xx_is_ring_osc_forced())
1988c2ecf20Sopenharmony_ci		return parent_rate;
1998c2ecf20Sopenharmony_ci	return parent_rate / 48 * hss_mult[hss];
2008c2ecf20Sopenharmony_ci}
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_cistatic u8 clk_pxa3xx_system_bus_get_parent(struct clk_hw *hw)
2038c2ecf20Sopenharmony_ci{
2048c2ecf20Sopenharmony_ci	if (pxa3xx_is_ring_osc_forced())
2058c2ecf20Sopenharmony_ci		return PXA_BUS_60Mhz;
2068c2ecf20Sopenharmony_ci	else
2078c2ecf20Sopenharmony_ci		return PXA_BUS_HSS;
2088c2ecf20Sopenharmony_ci}
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ciPARENTS(clk_pxa3xx_system_bus) = { "ring_osc_60mhz", "spll_624mhz" };
2118c2ecf20Sopenharmony_ciMUX_RO_RATE_RO_OPS(clk_pxa3xx_system_bus, "system_bus");
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_cistatic unsigned long clk_pxa3xx_core_get_rate(struct clk_hw *hw,
2148c2ecf20Sopenharmony_ci					      unsigned long parent_rate)
2158c2ecf20Sopenharmony_ci{
2168c2ecf20Sopenharmony_ci	return parent_rate;
2178c2ecf20Sopenharmony_ci}
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistatic u8 clk_pxa3xx_core_get_parent(struct clk_hw *hw)
2208c2ecf20Sopenharmony_ci{
2218c2ecf20Sopenharmony_ci	unsigned long xclkcfg;
2228c2ecf20Sopenharmony_ci	unsigned int t;
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci	if (pxa3xx_is_ring_osc_forced())
2258c2ecf20Sopenharmony_ci		return PXA_CORE_60Mhz;
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	/* Read XCLKCFG register turbo bit */
2288c2ecf20Sopenharmony_ci	__asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg));
2298c2ecf20Sopenharmony_ci	t = xclkcfg & 0x1;
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci	if (t)
2328c2ecf20Sopenharmony_ci		return PXA_CORE_TURBO;
2338c2ecf20Sopenharmony_ci	return PXA_CORE_RUN;
2348c2ecf20Sopenharmony_ci}
2358c2ecf20Sopenharmony_ciPARENTS(clk_pxa3xx_core) = { "ring_osc_60mhz", "run", "cpll" };
2368c2ecf20Sopenharmony_ciMUX_RO_RATE_RO_OPS(clk_pxa3xx_core, "core");
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_cistatic unsigned long clk_pxa3xx_run_get_rate(struct clk_hw *hw,
2398c2ecf20Sopenharmony_ci					     unsigned long parent_rate)
2408c2ecf20Sopenharmony_ci{
2418c2ecf20Sopenharmony_ci	unsigned long acsr = ACSR;
2428c2ecf20Sopenharmony_ci	unsigned int xn = (acsr & ACCR_XN_MASK) >> 8;
2438c2ecf20Sopenharmony_ci	unsigned int t, xclkcfg;
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci	/* Read XCLKCFG register turbo bit */
2468c2ecf20Sopenharmony_ci	__asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg));
2478c2ecf20Sopenharmony_ci	t = xclkcfg & 0x1;
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	return t ? (parent_rate / xn) * 2 : parent_rate;
2508c2ecf20Sopenharmony_ci}
2518c2ecf20Sopenharmony_ciPARENTS(clk_pxa3xx_run) = { "cpll" };
2528c2ecf20Sopenharmony_ciRATE_RO_OPS(clk_pxa3xx_run, "run");
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_cistatic unsigned long clk_pxa3xx_cpll_get_rate(struct clk_hw *hw,
2558c2ecf20Sopenharmony_ci	unsigned long parent_rate)
2568c2ecf20Sopenharmony_ci{
2578c2ecf20Sopenharmony_ci	unsigned long acsr = ACSR;
2588c2ecf20Sopenharmony_ci	unsigned int xn = (acsr & ACCR_XN_MASK) >> 8;
2598c2ecf20Sopenharmony_ci	unsigned int xl = acsr & ACCR_XL_MASK;
2608c2ecf20Sopenharmony_ci	unsigned int t, xclkcfg;
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci	/* Read XCLKCFG register turbo bit */
2638c2ecf20Sopenharmony_ci	__asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg));
2648c2ecf20Sopenharmony_ci	t = xclkcfg & 0x1;
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci	pr_info("RJK: parent_rate=%lu, xl=%u, xn=%u\n", parent_rate, xl, xn);
2678c2ecf20Sopenharmony_ci	return t ? parent_rate * xl * xn : parent_rate * xl;
2688c2ecf20Sopenharmony_ci}
2698c2ecf20Sopenharmony_ciPARENTS(clk_pxa3xx_cpll) = { "osc_13mhz" };
2708c2ecf20Sopenharmony_ciRATE_RO_OPS(clk_pxa3xx_cpll, "cpll");
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_cistatic void __init pxa3xx_register_core(void)
2738c2ecf20Sopenharmony_ci{
2748c2ecf20Sopenharmony_ci	clk_register_clk_pxa3xx_cpll();
2758c2ecf20Sopenharmony_ci	clk_register_clk_pxa3xx_run();
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci	clkdev_pxa_register(CLK_CORE, "core", NULL,
2788c2ecf20Sopenharmony_ci			    clk_register_clk_pxa3xx_core());
2798c2ecf20Sopenharmony_ci}
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_cistatic void __init pxa3xx_register_plls(void)
2828c2ecf20Sopenharmony_ci{
2838c2ecf20Sopenharmony_ci	clk_register_fixed_rate(NULL, "osc_13mhz", NULL,
2848c2ecf20Sopenharmony_ci				CLK_GET_RATE_NOCACHE,
2858c2ecf20Sopenharmony_ci				13 * MHz);
2868c2ecf20Sopenharmony_ci	clkdev_pxa_register(CLK_OSC32k768, "osc_32_768khz", NULL,
2878c2ecf20Sopenharmony_ci			    clk_register_fixed_rate(NULL, "osc_32_768khz", NULL,
2888c2ecf20Sopenharmony_ci						    CLK_GET_RATE_NOCACHE,
2898c2ecf20Sopenharmony_ci						    32768));
2908c2ecf20Sopenharmony_ci	clk_register_fixed_rate(NULL, "ring_osc_120mhz", NULL,
2918c2ecf20Sopenharmony_ci				CLK_GET_RATE_NOCACHE,
2928c2ecf20Sopenharmony_ci				120 * MHz);
2938c2ecf20Sopenharmony_ci	clk_register_fixed_rate(NULL, "clk_dummy", NULL, 0, 0);
2948c2ecf20Sopenharmony_ci	clk_register_fixed_factor(NULL, "spll_624mhz", "osc_13mhz", 0, 48, 1);
2958c2ecf20Sopenharmony_ci	clk_register_fixed_factor(NULL, "ring_osc_60mhz", "ring_osc_120mhz",
2968c2ecf20Sopenharmony_ci				  0, 1, 2);
2978c2ecf20Sopenharmony_ci}
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci#define DUMMY_CLK(_con_id, _dev_id, _parent) \
3008c2ecf20Sopenharmony_ci	{ .con_id = _con_id, .dev_id = _dev_id, .parent = _parent }
3018c2ecf20Sopenharmony_cistruct dummy_clk {
3028c2ecf20Sopenharmony_ci	const char *con_id;
3038c2ecf20Sopenharmony_ci	const char *dev_id;
3048c2ecf20Sopenharmony_ci	const char *parent;
3058c2ecf20Sopenharmony_ci};
3068c2ecf20Sopenharmony_cistatic struct dummy_clk dummy_clks[] __initdata = {
3078c2ecf20Sopenharmony_ci	DUMMY_CLK(NULL, "pxa93x-gpio", "osc_13mhz"),
3088c2ecf20Sopenharmony_ci	DUMMY_CLK(NULL, "sa1100-rtc", "osc_32_768khz"),
3098c2ecf20Sopenharmony_ci	DUMMY_CLK("UARTCLK", "pxa2xx-ir", "STUART"),
3108c2ecf20Sopenharmony_ci	DUMMY_CLK(NULL, "pxa3xx-pwri2c.1", "osc_13mhz"),
3118c2ecf20Sopenharmony_ci};
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_cistatic void __init pxa3xx_dummy_clocks_init(void)
3148c2ecf20Sopenharmony_ci{
3158c2ecf20Sopenharmony_ci	struct clk *clk;
3168c2ecf20Sopenharmony_ci	struct dummy_clk *d;
3178c2ecf20Sopenharmony_ci	const char *name;
3188c2ecf20Sopenharmony_ci	int i;
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(dummy_clks); i++) {
3218c2ecf20Sopenharmony_ci		d = &dummy_clks[i];
3228c2ecf20Sopenharmony_ci		name = d->dev_id ? d->dev_id : d->con_id;
3238c2ecf20Sopenharmony_ci		clk = clk_register_fixed_factor(NULL, name, d->parent, 0, 1, 1);
3248c2ecf20Sopenharmony_ci		clk_register_clkdev(clk, d->con_id, d->dev_id);
3258c2ecf20Sopenharmony_ci	}
3268c2ecf20Sopenharmony_ci}
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_cistatic void __init pxa3xx_base_clocks_init(void)
3298c2ecf20Sopenharmony_ci{
3308c2ecf20Sopenharmony_ci	struct clk *clk;
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	pxa3xx_register_plls();
3338c2ecf20Sopenharmony_ci	pxa3xx_register_core();
3348c2ecf20Sopenharmony_ci	clk_register_clk_pxa3xx_system_bus();
3358c2ecf20Sopenharmony_ci	clk_register_clk_pxa3xx_ac97();
3368c2ecf20Sopenharmony_ci	clk_register_clk_pxa3xx_smemc();
3378c2ecf20Sopenharmony_ci	clk = clk_register_gate(NULL, "CLK_POUT",
3388c2ecf20Sopenharmony_ci				"osc_13mhz", 0, OSCC, 11, 0, NULL);
3398c2ecf20Sopenharmony_ci	clk_register_clkdev(clk, "CLK_POUT", NULL);
3408c2ecf20Sopenharmony_ci	clkdev_pxa_register(CLK_OSTIMER, "OSTIMER0", NULL,
3418c2ecf20Sopenharmony_ci			    clk_register_fixed_factor(NULL, "os-timer0",
3428c2ecf20Sopenharmony_ci						      "osc_13mhz", 0, 1, 4));
3438c2ecf20Sopenharmony_ci}
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ciint __init pxa3xx_clocks_init(void)
3468c2ecf20Sopenharmony_ci{
3478c2ecf20Sopenharmony_ci	int ret;
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci	pxa3xx_base_clocks_init();
3508c2ecf20Sopenharmony_ci	pxa3xx_dummy_clocks_init();
3518c2ecf20Sopenharmony_ci	ret = clk_pxa_cken_init(pxa3xx_clocks, ARRAY_SIZE(pxa3xx_clocks));
3528c2ecf20Sopenharmony_ci	if (ret)
3538c2ecf20Sopenharmony_ci		return ret;
3548c2ecf20Sopenharmony_ci	if (cpu_is_pxa320())
3558c2ecf20Sopenharmony_ci		return clk_pxa_cken_init(pxa320_clocks,
3568c2ecf20Sopenharmony_ci					 ARRAY_SIZE(pxa320_clocks));
3578c2ecf20Sopenharmony_ci	if (cpu_is_pxa300() || cpu_is_pxa310())
3588c2ecf20Sopenharmony_ci		return clk_pxa_cken_init(pxa300_310_clocks,
3598c2ecf20Sopenharmony_ci					 ARRAY_SIZE(pxa300_310_clocks));
3608c2ecf20Sopenharmony_ci	return clk_pxa_cken_init(pxa93x_clocks, ARRAY_SIZE(pxa93x_clocks));
3618c2ecf20Sopenharmony_ci}
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_cistatic void __init pxa3xx_dt_clocks_init(struct device_node *np)
3648c2ecf20Sopenharmony_ci{
3658c2ecf20Sopenharmony_ci	pxa3xx_clocks_init();
3668c2ecf20Sopenharmony_ci	clk_pxa_dt_common_init(np);
3678c2ecf20Sopenharmony_ci}
3688c2ecf20Sopenharmony_ciCLK_OF_DECLARE(pxa_clks, "marvell,pxa300-clocks", pxa3xx_dt_clocks_init);
369