18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * pxa910 clock framework source file
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2012 Marvell
58c2ecf20Sopenharmony_ci * Chao Xie <xiechao.mail@gmail.com>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This file is licensed under the terms of the GNU General Public
88c2ecf20Sopenharmony_ci * License version 2. This program is licensed "as is" without any
98c2ecf20Sopenharmony_ci * warranty of any kind, whether express or implied.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/module.h>
138c2ecf20Sopenharmony_ci#include <linux/kernel.h>
148c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
158c2ecf20Sopenharmony_ci#include <linux/io.h>
168c2ecf20Sopenharmony_ci#include <linux/delay.h>
178c2ecf20Sopenharmony_ci#include <linux/err.h>
188c2ecf20Sopenharmony_ci#include <linux/of_address.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <dt-bindings/clock/marvell,pxa910.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#include "clk.h"
238c2ecf20Sopenharmony_ci#include "reset.h"
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define APBC_RTC	0x28
268c2ecf20Sopenharmony_ci#define APBC_TWSI0	0x2c
278c2ecf20Sopenharmony_ci#define APBC_KPC	0x18
288c2ecf20Sopenharmony_ci#define APBC_UART0	0x0
298c2ecf20Sopenharmony_ci#define APBC_UART1	0x4
308c2ecf20Sopenharmony_ci#define APBC_GPIO	0x8
318c2ecf20Sopenharmony_ci#define APBC_PWM0	0xc
328c2ecf20Sopenharmony_ci#define APBC_PWM1	0x10
338c2ecf20Sopenharmony_ci#define APBC_PWM2	0x14
348c2ecf20Sopenharmony_ci#define APBC_PWM3	0x18
358c2ecf20Sopenharmony_ci#define APBC_SSP0	0x1c
368c2ecf20Sopenharmony_ci#define APBC_SSP1	0x20
378c2ecf20Sopenharmony_ci#define APBC_SSP2	0x4c
388c2ecf20Sopenharmony_ci#define APBC_TIMER0	0x30
398c2ecf20Sopenharmony_ci#define APBC_TIMER1	0x44
408c2ecf20Sopenharmony_ci#define APBCP_TWSI1	0x28
418c2ecf20Sopenharmony_ci#define APBCP_UART2	0x1c
428c2ecf20Sopenharmony_ci#define APMU_SDH0	0x54
438c2ecf20Sopenharmony_ci#define APMU_SDH1	0x58
448c2ecf20Sopenharmony_ci#define APMU_USB	0x5c
458c2ecf20Sopenharmony_ci#define APMU_DISP0	0x4c
468c2ecf20Sopenharmony_ci#define APMU_CCIC0	0x50
478c2ecf20Sopenharmony_ci#define APMU_DFC	0x60
488c2ecf20Sopenharmony_ci#define MPMU_UART_PLL	0x14
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistruct pxa910_clk_unit {
518c2ecf20Sopenharmony_ci	struct mmp_clk_unit unit;
528c2ecf20Sopenharmony_ci	void __iomem *mpmu_base;
538c2ecf20Sopenharmony_ci	void __iomem *apmu_base;
548c2ecf20Sopenharmony_ci	void __iomem *apbc_base;
558c2ecf20Sopenharmony_ci	void __iomem *apbcp_base;
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic struct mmp_param_fixed_rate_clk fixed_rate_clks[] = {
598c2ecf20Sopenharmony_ci	{PXA910_CLK_CLK32, "clk32", NULL, 0, 32768},
608c2ecf20Sopenharmony_ci	{PXA910_CLK_VCTCXO, "vctcxo", NULL, 0, 26000000},
618c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1, "pll1", NULL, 0, 624000000},
628c2ecf20Sopenharmony_ci	{PXA910_CLK_USB_PLL, "usb_pll", NULL, 0, 480000000},
638c2ecf20Sopenharmony_ci};
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cistatic struct mmp_param_fixed_factor_clk fixed_factor_clks[] = {
668c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_2, "pll1_2", "pll1", 1, 2, 0},
678c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_4, "pll1_4", "pll1_2", 1, 2, 0},
688c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_8, "pll1_8", "pll1_4", 1, 2, 0},
698c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_16, "pll1_16", "pll1_8", 1, 2, 0},
708c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_6, "pll1_6", "pll1_2", 1, 3, 0},
718c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_12, "pll1_12", "pll1_6", 1, 2, 0},
728c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_24, "pll1_24", "pll1_12", 1, 2, 0},
738c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_48, "pll1_48", "pll1_24", 1, 2, 0},
748c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_96, "pll1_96", "pll1_48", 1, 2, 0},
758c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_192, "pll1_192", "pll1_96", 1, 2, 0},
768c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_13, "pll1_13", "pll1", 1, 13, 0},
778c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_13_1_5, "pll1_13_1_5", "pll1_13", 2, 3, 0},
788c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_2_1_5, "pll1_2_1_5", "pll1_2", 2, 3, 0},
798c2ecf20Sopenharmony_ci	{PXA910_CLK_PLL1_3_16, "pll1_3_16", "pll1", 3, 16, 0},
808c2ecf20Sopenharmony_ci};
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_cistatic struct mmp_clk_factor_masks uart_factor_masks = {
838c2ecf20Sopenharmony_ci	.factor = 2,
848c2ecf20Sopenharmony_ci	.num_mask = 0x1fff,
858c2ecf20Sopenharmony_ci	.den_mask = 0x1fff,
868c2ecf20Sopenharmony_ci	.num_shift = 16,
878c2ecf20Sopenharmony_ci	.den_shift = 0,
888c2ecf20Sopenharmony_ci};
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistatic struct mmp_clk_factor_tbl uart_factor_tbl[] = {
918c2ecf20Sopenharmony_ci	{.num = 8125, .den = 1536},	/*14.745MHZ */
928c2ecf20Sopenharmony_ci};
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistatic void pxa910_pll_init(struct pxa910_clk_unit *pxa_unit)
958c2ecf20Sopenharmony_ci{
968c2ecf20Sopenharmony_ci	struct clk *clk;
978c2ecf20Sopenharmony_ci	struct mmp_clk_unit *unit = &pxa_unit->unit;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	mmp_register_fixed_rate_clks(unit, fixed_rate_clks,
1008c2ecf20Sopenharmony_ci					ARRAY_SIZE(fixed_rate_clks));
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	mmp_register_fixed_factor_clks(unit, fixed_factor_clks,
1038c2ecf20Sopenharmony_ci					ARRAY_SIZE(fixed_factor_clks));
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	clk = mmp_clk_register_factor("uart_pll", "pll1_4",
1068c2ecf20Sopenharmony_ci				CLK_SET_RATE_PARENT,
1078c2ecf20Sopenharmony_ci				pxa_unit->mpmu_base + MPMU_UART_PLL,
1088c2ecf20Sopenharmony_ci				&uart_factor_masks, uart_factor_tbl,
1098c2ecf20Sopenharmony_ci				ARRAY_SIZE(uart_factor_tbl), NULL);
1108c2ecf20Sopenharmony_ci	mmp_clk_add(unit, PXA910_CLK_UART_PLL, clk);
1118c2ecf20Sopenharmony_ci}
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(uart0_lock);
1148c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(uart1_lock);
1158c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(uart2_lock);
1168c2ecf20Sopenharmony_cistatic const char *uart_parent_names[] = {"pll1_3_16", "uart_pll"};
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(ssp0_lock);
1198c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(ssp1_lock);
1208c2ecf20Sopenharmony_cistatic const char *ssp_parent_names[] = {"pll1_96", "pll1_48", "pll1_24", "pll1_12"};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(timer0_lock);
1238c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(timer1_lock);
1248c2ecf20Sopenharmony_cistatic const char *timer_parent_names[] = {"pll1_48", "clk32", "pll1_96"};
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(reset_lock);
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_cistatic struct mmp_param_mux_clk apbc_mux_clks[] = {
1298c2ecf20Sopenharmony_ci	{0, "uart0_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, APBC_UART0, 4, 3, 0, &uart0_lock},
1308c2ecf20Sopenharmony_ci	{0, "uart1_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, APBC_UART1, 4, 3, 0, &uart1_lock},
1318c2ecf20Sopenharmony_ci	{0, "ssp0_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP0, 4, 3, 0, &ssp0_lock},
1328c2ecf20Sopenharmony_ci	{0, "ssp1_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP1, 4, 3, 0, &ssp1_lock},
1338c2ecf20Sopenharmony_ci	{0, "timer0_mux", timer_parent_names, ARRAY_SIZE(timer_parent_names), CLK_SET_RATE_PARENT, APBC_TIMER0, 4, 3, 0, &timer0_lock},
1348c2ecf20Sopenharmony_ci	{0, "timer1_mux", timer_parent_names, ARRAY_SIZE(timer_parent_names), CLK_SET_RATE_PARENT, APBC_TIMER1, 4, 3, 0, &timer1_lock},
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistatic struct mmp_param_mux_clk apbcp_mux_clks[] = {
1388c2ecf20Sopenharmony_ci	{0, "uart2_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, APBCP_UART2, 4, 3, 0, &uart2_lock},
1398c2ecf20Sopenharmony_ci};
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_cistatic struct mmp_param_gate_clk apbc_gate_clks[] = {
1428c2ecf20Sopenharmony_ci	{PXA910_CLK_TWSI0, "twsi0_clk", "pll1_13_1_5", CLK_SET_RATE_PARENT, APBC_TWSI0, 0x3, 0x3, 0x0, 0, &reset_lock},
1438c2ecf20Sopenharmony_ci	{PXA910_CLK_GPIO, "gpio_clk", "vctcxo", CLK_SET_RATE_PARENT, APBC_GPIO, 0x3, 0x3, 0x0, 0, &reset_lock},
1448c2ecf20Sopenharmony_ci	{PXA910_CLK_KPC, "kpc_clk", "clk32", CLK_SET_RATE_PARENT, APBC_KPC, 0x3, 0x3, 0x0, MMP_CLK_GATE_NEED_DELAY, NULL},
1458c2ecf20Sopenharmony_ci	{PXA910_CLK_RTC, "rtc_clk", "clk32", CLK_SET_RATE_PARENT, APBC_RTC, 0x83, 0x83, 0x0, MMP_CLK_GATE_NEED_DELAY, NULL},
1468c2ecf20Sopenharmony_ci	{PXA910_CLK_PWM0, "pwm0_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM0, 0x3, 0x3, 0x0, 0, &reset_lock},
1478c2ecf20Sopenharmony_ci	{PXA910_CLK_PWM1, "pwm1_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM1, 0x3, 0x3, 0x0, 0, &reset_lock},
1488c2ecf20Sopenharmony_ci	{PXA910_CLK_PWM2, "pwm2_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM2, 0x3, 0x3, 0x0, 0, &reset_lock},
1498c2ecf20Sopenharmony_ci	{PXA910_CLK_PWM3, "pwm3_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM3, 0x3, 0x3, 0x0, 0, &reset_lock},
1508c2ecf20Sopenharmony_ci	/* The gate clocks has mux parent. */
1518c2ecf20Sopenharmony_ci	{PXA910_CLK_UART0, "uart0_clk", "uart0_mux", CLK_SET_RATE_PARENT, APBC_UART0, 0x3, 0x3, 0x0, 0, &uart0_lock},
1528c2ecf20Sopenharmony_ci	{PXA910_CLK_UART1, "uart1_clk", "uart1_mux", CLK_SET_RATE_PARENT, APBC_UART1, 0x3, 0x3, 0x0, 0, &uart1_lock},
1538c2ecf20Sopenharmony_ci	{PXA910_CLK_SSP0, "ssp0_clk", "ssp0_mux", CLK_SET_RATE_PARENT, APBC_SSP0, 0x3, 0x3, 0x0, 0, &ssp0_lock},
1548c2ecf20Sopenharmony_ci	{PXA910_CLK_SSP1, "ssp1_clk", "ssp1_mux", CLK_SET_RATE_PARENT, APBC_SSP1, 0x3, 0x3, 0x0, 0, &ssp1_lock},
1558c2ecf20Sopenharmony_ci	{PXA910_CLK_TIMER0, "timer0_clk", "timer0_mux", CLK_SET_RATE_PARENT, APBC_TIMER0, 0x3, 0x3, 0x0, 0, &timer0_lock},
1568c2ecf20Sopenharmony_ci	{PXA910_CLK_TIMER1, "timer1_clk", "timer1_mux", CLK_SET_RATE_PARENT, APBC_TIMER1, 0x3, 0x3, 0x0, 0, &timer1_lock},
1578c2ecf20Sopenharmony_ci};
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_cistatic struct mmp_param_gate_clk apbcp_gate_clks[] = {
1608c2ecf20Sopenharmony_ci	{PXA910_CLK_TWSI1, "twsi1_clk", "pll1_13_1_5", CLK_SET_RATE_PARENT, APBCP_TWSI1, 0x3, 0x3, 0x0, 0, &reset_lock},
1618c2ecf20Sopenharmony_ci	/* The gate clocks has mux parent. */
1628c2ecf20Sopenharmony_ci	{PXA910_CLK_UART2, "uart2_clk", "uart2_mux", CLK_SET_RATE_PARENT, APBCP_UART2, 0x3, 0x3, 0x0, 0, &uart2_lock},
1638c2ecf20Sopenharmony_ci};
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic void pxa910_apb_periph_clk_init(struct pxa910_clk_unit *pxa_unit)
1668c2ecf20Sopenharmony_ci{
1678c2ecf20Sopenharmony_ci	struct mmp_clk_unit *unit = &pxa_unit->unit;
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	mmp_register_mux_clks(unit, apbc_mux_clks, pxa_unit->apbc_base,
1708c2ecf20Sopenharmony_ci				ARRAY_SIZE(apbc_mux_clks));
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci	mmp_register_mux_clks(unit, apbcp_mux_clks, pxa_unit->apbcp_base,
1738c2ecf20Sopenharmony_ci				ARRAY_SIZE(apbcp_mux_clks));
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	mmp_register_gate_clks(unit, apbc_gate_clks, pxa_unit->apbc_base,
1768c2ecf20Sopenharmony_ci				ARRAY_SIZE(apbc_gate_clks));
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	mmp_register_gate_clks(unit, apbcp_gate_clks, pxa_unit->apbcp_base,
1798c2ecf20Sopenharmony_ci				ARRAY_SIZE(apbcp_gate_clks));
1808c2ecf20Sopenharmony_ci}
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(sdh0_lock);
1838c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(sdh1_lock);
1848c2ecf20Sopenharmony_cistatic const char *sdh_parent_names[] = {"pll1_12", "pll1_13"};
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(usb_lock);
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(disp0_lock);
1898c2ecf20Sopenharmony_cistatic const char *disp_parent_names[] = {"pll1_2", "pll1_12"};
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(ccic0_lock);
1928c2ecf20Sopenharmony_cistatic const char *ccic_parent_names[] = {"pll1_2", "pll1_12"};
1938c2ecf20Sopenharmony_cistatic const char *ccic_phy_parent_names[] = {"pll1_6", "pll1_12"};
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_cistatic struct mmp_param_mux_clk apmu_mux_clks[] = {
1968c2ecf20Sopenharmony_ci	{0, "sdh0_mux", sdh_parent_names, ARRAY_SIZE(sdh_parent_names), CLK_SET_RATE_PARENT, APMU_SDH0, 6, 1, 0, &sdh0_lock},
1978c2ecf20Sopenharmony_ci	{0, "sdh1_mux", sdh_parent_names, ARRAY_SIZE(sdh_parent_names), CLK_SET_RATE_PARENT, APMU_SDH1, 6, 1, 0, &sdh1_lock},
1988c2ecf20Sopenharmony_ci	{0, "disp0_mux", disp_parent_names, ARRAY_SIZE(disp_parent_names), CLK_SET_RATE_PARENT, APMU_DISP0, 6, 1, 0, &disp0_lock},
1998c2ecf20Sopenharmony_ci	{0, "ccic0_mux", ccic_parent_names, ARRAY_SIZE(ccic_parent_names), CLK_SET_RATE_PARENT, APMU_CCIC0, 6, 1, 0, &ccic0_lock},
2008c2ecf20Sopenharmony_ci	{0, "ccic0_phy_mux", ccic_phy_parent_names, ARRAY_SIZE(ccic_phy_parent_names), CLK_SET_RATE_PARENT, APMU_CCIC0, 7, 1, 0, &ccic0_lock},
2018c2ecf20Sopenharmony_ci};
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_cistatic struct mmp_param_div_clk apmu_div_clks[] = {
2048c2ecf20Sopenharmony_ci	{0, "ccic0_sphy_div", "ccic0_mux", CLK_SET_RATE_PARENT, APMU_CCIC0, 10, 5, 0, &ccic0_lock},
2058c2ecf20Sopenharmony_ci};
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_cistatic struct mmp_param_gate_clk apmu_gate_clks[] = {
2088c2ecf20Sopenharmony_ci	{PXA910_CLK_DFC, "dfc_clk", "pll1_4", CLK_SET_RATE_PARENT, APMU_DFC, 0x19b, 0x19b, 0x0, 0, NULL},
2098c2ecf20Sopenharmony_ci	{PXA910_CLK_USB, "usb_clk", "usb_pll", 0, APMU_USB, 0x9, 0x9, 0x0, 0, &usb_lock},
2108c2ecf20Sopenharmony_ci	{PXA910_CLK_SPH, "sph_clk", "usb_pll", 0, APMU_USB, 0x12, 0x12, 0x0, 0, &usb_lock},
2118c2ecf20Sopenharmony_ci	/* The gate clocks has mux parent. */
2128c2ecf20Sopenharmony_ci	{PXA910_CLK_SDH0, "sdh0_clk", "sdh0_mux", CLK_SET_RATE_PARENT, APMU_SDH0, 0x1b, 0x1b, 0x0, 0, &sdh0_lock},
2138c2ecf20Sopenharmony_ci	{PXA910_CLK_SDH1, "sdh1_clk", "sdh1_mux", CLK_SET_RATE_PARENT, APMU_SDH1, 0x1b, 0x1b, 0x0, 0, &sdh1_lock},
2148c2ecf20Sopenharmony_ci	{PXA910_CLK_DISP0, "disp0_clk", "disp0_mux", CLK_SET_RATE_PARENT, APMU_DISP0, 0x1b, 0x1b, 0x0, 0, &disp0_lock},
2158c2ecf20Sopenharmony_ci	{PXA910_CLK_CCIC0, "ccic0_clk", "ccic0_mux", CLK_SET_RATE_PARENT, APMU_CCIC0, 0x1b, 0x1b, 0x0, 0, &ccic0_lock},
2168c2ecf20Sopenharmony_ci	{PXA910_CLK_CCIC0_PHY, "ccic0_phy_clk", "ccic0_phy_mux", CLK_SET_RATE_PARENT, APMU_CCIC0, 0x24, 0x24, 0x0, 0, &ccic0_lock},
2178c2ecf20Sopenharmony_ci	{PXA910_CLK_CCIC0_SPHY, "ccic0_sphy_clk", "ccic0_sphy_div", CLK_SET_RATE_PARENT, APMU_CCIC0, 0x300, 0x300, 0x0, 0, &ccic0_lock},
2188c2ecf20Sopenharmony_ci};
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistatic void pxa910_axi_periph_clk_init(struct pxa910_clk_unit *pxa_unit)
2218c2ecf20Sopenharmony_ci{
2228c2ecf20Sopenharmony_ci	struct mmp_clk_unit *unit = &pxa_unit->unit;
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci	mmp_register_mux_clks(unit, apmu_mux_clks, pxa_unit->apmu_base,
2258c2ecf20Sopenharmony_ci				ARRAY_SIZE(apmu_mux_clks));
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	mmp_register_div_clks(unit, apmu_div_clks, pxa_unit->apmu_base,
2288c2ecf20Sopenharmony_ci				ARRAY_SIZE(apmu_div_clks));
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci	mmp_register_gate_clks(unit, apmu_gate_clks, pxa_unit->apmu_base,
2318c2ecf20Sopenharmony_ci				ARRAY_SIZE(apmu_gate_clks));
2328c2ecf20Sopenharmony_ci}
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_cistatic void pxa910_clk_reset_init(struct device_node *np,
2358c2ecf20Sopenharmony_ci				struct pxa910_clk_unit *pxa_unit)
2368c2ecf20Sopenharmony_ci{
2378c2ecf20Sopenharmony_ci	struct mmp_clk_reset_cell *cells;
2388c2ecf20Sopenharmony_ci	int i, base, nr_resets_apbc, nr_resets_apbcp, nr_resets;
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci	nr_resets_apbc = ARRAY_SIZE(apbc_gate_clks);
2418c2ecf20Sopenharmony_ci	nr_resets_apbcp = ARRAY_SIZE(apbcp_gate_clks);
2428c2ecf20Sopenharmony_ci	nr_resets = nr_resets_apbc + nr_resets_apbcp;
2438c2ecf20Sopenharmony_ci	cells = kcalloc(nr_resets, sizeof(*cells), GFP_KERNEL);
2448c2ecf20Sopenharmony_ci	if (!cells)
2458c2ecf20Sopenharmony_ci		return;
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci	base = 0;
2488c2ecf20Sopenharmony_ci	for (i = 0; i < nr_resets_apbc; i++) {
2498c2ecf20Sopenharmony_ci		cells[base + i].clk_id = apbc_gate_clks[i].id;
2508c2ecf20Sopenharmony_ci		cells[base + i].reg =
2518c2ecf20Sopenharmony_ci			pxa_unit->apbc_base + apbc_gate_clks[i].offset;
2528c2ecf20Sopenharmony_ci		cells[base + i].flags = 0;
2538c2ecf20Sopenharmony_ci		cells[base + i].lock = apbc_gate_clks[i].lock;
2548c2ecf20Sopenharmony_ci		cells[base + i].bits = 0x4;
2558c2ecf20Sopenharmony_ci	}
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	base = nr_resets_apbc;
2588c2ecf20Sopenharmony_ci	for (i = 0; i < nr_resets_apbcp; i++) {
2598c2ecf20Sopenharmony_ci		cells[base + i].clk_id = apbcp_gate_clks[i].id;
2608c2ecf20Sopenharmony_ci		cells[base + i].reg =
2618c2ecf20Sopenharmony_ci			pxa_unit->apbc_base + apbc_gate_clks[i].offset;
2628c2ecf20Sopenharmony_ci		cells[base + i].flags = 0;
2638c2ecf20Sopenharmony_ci		cells[base + i].lock = apbc_gate_clks[i].lock;
2648c2ecf20Sopenharmony_ci		cells[base + i].bits = 0x4;
2658c2ecf20Sopenharmony_ci	}
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci	mmp_clk_reset_register(np, cells, nr_resets);
2688c2ecf20Sopenharmony_ci}
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_cistatic void __init pxa910_clk_init(struct device_node *np)
2718c2ecf20Sopenharmony_ci{
2728c2ecf20Sopenharmony_ci	struct pxa910_clk_unit *pxa_unit;
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	pxa_unit = kzalloc(sizeof(*pxa_unit), GFP_KERNEL);
2758c2ecf20Sopenharmony_ci	if (!pxa_unit)
2768c2ecf20Sopenharmony_ci		return;
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	pxa_unit->mpmu_base = of_iomap(np, 0);
2798c2ecf20Sopenharmony_ci	if (!pxa_unit->mpmu_base) {
2808c2ecf20Sopenharmony_ci		pr_err("failed to map mpmu registers\n");
2818c2ecf20Sopenharmony_ci		goto free_memory;
2828c2ecf20Sopenharmony_ci	}
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci	pxa_unit->apmu_base = of_iomap(np, 1);
2858c2ecf20Sopenharmony_ci	if (!pxa_unit->apmu_base) {
2868c2ecf20Sopenharmony_ci		pr_err("failed to map apmu registers\n");
2878c2ecf20Sopenharmony_ci		goto unmap_mpmu_region;
2888c2ecf20Sopenharmony_ci	}
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	pxa_unit->apbc_base = of_iomap(np, 2);
2918c2ecf20Sopenharmony_ci	if (!pxa_unit->apbc_base) {
2928c2ecf20Sopenharmony_ci		pr_err("failed to map apbc registers\n");
2938c2ecf20Sopenharmony_ci		goto unmap_apmu_region;
2948c2ecf20Sopenharmony_ci	}
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	pxa_unit->apbcp_base = of_iomap(np, 3);
2978c2ecf20Sopenharmony_ci	if (!pxa_unit->apbcp_base) {
2988c2ecf20Sopenharmony_ci		pr_err("failed to map apbcp registers\n");
2998c2ecf20Sopenharmony_ci		goto unmap_apbc_region;
3008c2ecf20Sopenharmony_ci	}
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	mmp_clk_init(np, &pxa_unit->unit, PXA910_NR_CLKS);
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci	pxa910_pll_init(pxa_unit);
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci	pxa910_apb_periph_clk_init(pxa_unit);
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci	pxa910_axi_periph_clk_init(pxa_unit);
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci	pxa910_clk_reset_init(np, pxa_unit);
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	return;
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_ciunmap_apbc_region:
3158c2ecf20Sopenharmony_ci	iounmap(pxa_unit->apbc_base);
3168c2ecf20Sopenharmony_ciunmap_apmu_region:
3178c2ecf20Sopenharmony_ci	iounmap(pxa_unit->apmu_base);
3188c2ecf20Sopenharmony_ciunmap_mpmu_region:
3198c2ecf20Sopenharmony_ci	iounmap(pxa_unit->mpmu_base);
3208c2ecf20Sopenharmony_cifree_memory:
3218c2ecf20Sopenharmony_ci	kfree(pxa_unit);
3228c2ecf20Sopenharmony_ci}
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ciCLK_OF_DECLARE(pxa910_clk, "marvell,pxa910-clock", pxa910_clk_init);
325