18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * pxa168 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,pxa168.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	0x30
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_TIMER	0x34
368c2ecf20Sopenharmony_ci#define APBC_SSP0	0x81c
378c2ecf20Sopenharmony_ci#define APBC_SSP1	0x820
388c2ecf20Sopenharmony_ci#define APBC_SSP2	0x84c
398c2ecf20Sopenharmony_ci#define APBC_SSP3	0x858
408c2ecf20Sopenharmony_ci#define APBC_SSP4	0x85c
418c2ecf20Sopenharmony_ci#define APBC_TWSI1	0x6c
428c2ecf20Sopenharmony_ci#define APBC_UART2	0x70
438c2ecf20Sopenharmony_ci#define APMU_SDH0	0x54
448c2ecf20Sopenharmony_ci#define APMU_SDH1	0x58
458c2ecf20Sopenharmony_ci#define APMU_USB	0x5c
468c2ecf20Sopenharmony_ci#define APMU_DISP0	0x4c
478c2ecf20Sopenharmony_ci#define APMU_CCIC0	0x50
488c2ecf20Sopenharmony_ci#define APMU_DFC	0x60
498c2ecf20Sopenharmony_ci#define MPMU_UART_PLL	0x14
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistruct pxa168_clk_unit {
528c2ecf20Sopenharmony_ci	struct mmp_clk_unit unit;
538c2ecf20Sopenharmony_ci	void __iomem *mpmu_base;
548c2ecf20Sopenharmony_ci	void __iomem *apmu_base;
558c2ecf20Sopenharmony_ci	void __iomem *apbc_base;
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic struct mmp_param_fixed_rate_clk fixed_rate_clks[] = {
598c2ecf20Sopenharmony_ci	{PXA168_CLK_CLK32, "clk32", NULL, 0, 32768},
608c2ecf20Sopenharmony_ci	{PXA168_CLK_VCTCXO, "vctcxo", NULL, 0, 26000000},
618c2ecf20Sopenharmony_ci	{PXA168_CLK_PLL1, "pll1", NULL, 0, 624000000},
628c2ecf20Sopenharmony_ci	{PXA168_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	{PXA168_CLK_PLL1_2, "pll1_2", "pll1", 1, 2, 0},
678c2ecf20Sopenharmony_ci	{PXA168_CLK_PLL1_4, "pll1_4", "pll1_2", 1, 2, 0},
688c2ecf20Sopenharmony_ci	{PXA168_CLK_PLL1_8, "pll1_8", "pll1_4", 1, 2, 0},
698c2ecf20Sopenharmony_ci	{PXA168_CLK_PLL1_16, "pll1_16", "pll1_8", 1, 2, 0},
708c2ecf20Sopenharmony_ci	{PXA168_CLK_PLL1_6, "pll1_6", "pll1_2", 1, 3, 0},
718c2ecf20Sopenharmony_ci	{PXA168_CLK_PLL1_12, "pll1_12", "pll1_6", 1, 2, 0},
728c2ecf20Sopenharmony_ci	{PXA168_CLK_PLL1_24, "pll1_24", "pll1_12", 1, 2, 0},
738c2ecf20Sopenharmony_ci	{PXA168_CLK_PLL1_48, "pll1_48", "pll1_24", 1, 2, 0},
748c2ecf20Sopenharmony_ci	{PXA168_CLK_PLL1_96, "pll1_96", "pll1_48", 1, 2, 0},
758c2ecf20Sopenharmony_ci	{PXA168_CLK_PLL1_192, "pll1_192", "pll1_96", 1, 2, 0},
768c2ecf20Sopenharmony_ci	{PXA168_CLK_PLL1_13, "pll1_13", "pll1", 1, 13, 0},
778c2ecf20Sopenharmony_ci	{PXA168_CLK_PLL1_13_1_5, "pll1_13_1_5", "pll1_13", 2, 3, 0},
788c2ecf20Sopenharmony_ci	{PXA168_CLK_PLL1_2_1_5, "pll1_2_1_5", "pll1_2", 2, 3, 0},
798c2ecf20Sopenharmony_ci	{PXA168_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 pxa168_pll_init(struct pxa168_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, PXA168_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 DEFINE_SPINLOCK(ssp2_lock);
1218c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(ssp3_lock);
1228c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(ssp4_lock);
1238c2ecf20Sopenharmony_cistatic const char *ssp_parent_names[] = {"pll1_96", "pll1_48", "pll1_24", "pll1_12"};
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(timer_lock);
1268c2ecf20Sopenharmony_cistatic const char *timer_parent_names[] = {"pll1_48", "clk32", "pll1_96", "pll1_192"};
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(reset_lock);
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_cistatic struct mmp_param_mux_clk apbc_mux_clks[] = {
1318c2ecf20Sopenharmony_ci	{0, "uart0_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, APBC_UART0, 4, 3, 0, &uart0_lock},
1328c2ecf20Sopenharmony_ci	{0, "uart1_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, APBC_UART1, 4, 3, 0, &uart1_lock},
1338c2ecf20Sopenharmony_ci	{0, "uart2_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, APBC_UART2, 4, 3, 0, &uart2_lock},
1348c2ecf20Sopenharmony_ci	{0, "ssp0_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP0, 4, 3, 0, &ssp0_lock},
1358c2ecf20Sopenharmony_ci	{0, "ssp1_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP1, 4, 3, 0, &ssp1_lock},
1368c2ecf20Sopenharmony_ci	{0, "ssp2_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP2, 4, 3, 0, &ssp2_lock},
1378c2ecf20Sopenharmony_ci	{0, "ssp3_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP3, 4, 3, 0, &ssp3_lock},
1388c2ecf20Sopenharmony_ci	{0, "ssp4_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP4, 4, 3, 0, &ssp4_lock},
1398c2ecf20Sopenharmony_ci	{0, "timer_mux", timer_parent_names, ARRAY_SIZE(timer_parent_names), CLK_SET_RATE_PARENT, APBC_TIMER, 4, 3, 0, &timer_lock},
1408c2ecf20Sopenharmony_ci};
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_cistatic struct mmp_param_gate_clk apbc_gate_clks[] = {
1438c2ecf20Sopenharmony_ci	{PXA168_CLK_TWSI0, "twsi0_clk", "pll1_13_1_5", CLK_SET_RATE_PARENT, APBC_TWSI0, 0x3, 0x3, 0x0, 0, &reset_lock},
1448c2ecf20Sopenharmony_ci	{PXA168_CLK_TWSI1, "twsi1_clk", "pll1_13_1_5", CLK_SET_RATE_PARENT, APBC_TWSI1, 0x3, 0x3, 0x0, 0, &reset_lock},
1458c2ecf20Sopenharmony_ci	{PXA168_CLK_GPIO, "gpio_clk", "vctcxo", CLK_SET_RATE_PARENT, APBC_GPIO, 0x3, 0x3, 0x0, 0, &reset_lock},
1468c2ecf20Sopenharmony_ci	{PXA168_CLK_KPC, "kpc_clk", "clk32", CLK_SET_RATE_PARENT, APBC_KPC, 0x3, 0x3, 0x0, MMP_CLK_GATE_NEED_DELAY, NULL},
1478c2ecf20Sopenharmony_ci	{PXA168_CLK_RTC, "rtc_clk", "clk32", CLK_SET_RATE_PARENT, APBC_RTC, 0x83, 0x83, 0x0, MMP_CLK_GATE_NEED_DELAY, NULL},
1488c2ecf20Sopenharmony_ci	{PXA168_CLK_PWM0, "pwm0_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM0, 0x3, 0x3, 0x0, 0, &reset_lock},
1498c2ecf20Sopenharmony_ci	{PXA168_CLK_PWM1, "pwm1_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM1, 0x3, 0x3, 0x0, 0, &reset_lock},
1508c2ecf20Sopenharmony_ci	{PXA168_CLK_PWM2, "pwm2_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM2, 0x3, 0x3, 0x0, 0, &reset_lock},
1518c2ecf20Sopenharmony_ci	{PXA168_CLK_PWM3, "pwm3_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM3, 0x3, 0x3, 0x0, 0, &reset_lock},
1528c2ecf20Sopenharmony_ci	/* The gate clocks has mux parent. */
1538c2ecf20Sopenharmony_ci	{PXA168_CLK_UART0, "uart0_clk", "uart0_mux", CLK_SET_RATE_PARENT, APBC_UART0, 0x3, 0x3, 0x0, 0, &uart0_lock},
1548c2ecf20Sopenharmony_ci	{PXA168_CLK_UART1, "uart1_clk", "uart1_mux", CLK_SET_RATE_PARENT, APBC_UART1, 0x3, 0x3, 0x0, 0, &uart1_lock},
1558c2ecf20Sopenharmony_ci	{PXA168_CLK_UART2, "uart2_clk", "uart2_mux", CLK_SET_RATE_PARENT, APBC_UART2, 0x3, 0x3, 0x0, 0, &uart2_lock},
1568c2ecf20Sopenharmony_ci	{PXA168_CLK_SSP0, "ssp0_clk", "ssp0_mux", CLK_SET_RATE_PARENT, APBC_SSP0, 0x3, 0x3, 0x0, 0, &ssp0_lock},
1578c2ecf20Sopenharmony_ci	{PXA168_CLK_SSP1, "ssp1_clk", "ssp1_mux", CLK_SET_RATE_PARENT, APBC_SSP1, 0x3, 0x3, 0x0, 0, &ssp1_lock},
1588c2ecf20Sopenharmony_ci	{PXA168_CLK_SSP2, "ssp2_clk", "ssp2_mux", CLK_SET_RATE_PARENT, APBC_SSP2, 0x3, 0x3, 0x0, 0, &ssp2_lock},
1598c2ecf20Sopenharmony_ci	{PXA168_CLK_SSP3, "ssp3_clk", "ssp3_mux", CLK_SET_RATE_PARENT, APBC_SSP3, 0x3, 0x3, 0x0, 0, &ssp3_lock},
1608c2ecf20Sopenharmony_ci	{PXA168_CLK_SSP4, "ssp4_clk", "ssp4_mux", CLK_SET_RATE_PARENT, APBC_SSP4, 0x3, 0x3, 0x0, 0, &ssp4_lock},
1618c2ecf20Sopenharmony_ci	{PXA168_CLK_TIMER, "timer_clk", "timer_mux", CLK_SET_RATE_PARENT, APBC_TIMER, 0x3, 0x3, 0x0, 0, &timer_lock},
1628c2ecf20Sopenharmony_ci};
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_cistatic void pxa168_apb_periph_clk_init(struct pxa168_clk_unit *pxa_unit)
1658c2ecf20Sopenharmony_ci{
1668c2ecf20Sopenharmony_ci	struct mmp_clk_unit *unit = &pxa_unit->unit;
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	mmp_register_mux_clks(unit, apbc_mux_clks, pxa_unit->apbc_base,
1698c2ecf20Sopenharmony_ci				ARRAY_SIZE(apbc_mux_clks));
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	mmp_register_gate_clks(unit, apbc_gate_clks, pxa_unit->apbc_base,
1728c2ecf20Sopenharmony_ci				ARRAY_SIZE(apbc_gate_clks));
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci}
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(sdh0_lock);
1778c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(sdh1_lock);
1788c2ecf20Sopenharmony_cistatic const char *sdh_parent_names[] = {"pll1_12", "pll1_13"};
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(usb_lock);
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(disp0_lock);
1838c2ecf20Sopenharmony_cistatic const char *disp_parent_names[] = {"pll1_2", "pll1_12"};
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(ccic0_lock);
1868c2ecf20Sopenharmony_cistatic const char *ccic_parent_names[] = {"pll1_2", "pll1_12"};
1878c2ecf20Sopenharmony_cistatic const char *ccic_phy_parent_names[] = {"pll1_6", "pll1_12"};
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cistatic struct mmp_param_mux_clk apmu_mux_clks[] = {
1908c2ecf20Sopenharmony_ci	{0, "sdh0_mux", sdh_parent_names, ARRAY_SIZE(sdh_parent_names), CLK_SET_RATE_PARENT, APMU_SDH0, 6, 1, 0, &sdh0_lock},
1918c2ecf20Sopenharmony_ci	{0, "sdh1_mux", sdh_parent_names, ARRAY_SIZE(sdh_parent_names), CLK_SET_RATE_PARENT, APMU_SDH1, 6, 1, 0, &sdh1_lock},
1928c2ecf20Sopenharmony_ci	{0, "disp0_mux", disp_parent_names, ARRAY_SIZE(disp_parent_names), CLK_SET_RATE_PARENT, APMU_DISP0, 6, 1, 0, &disp0_lock},
1938c2ecf20Sopenharmony_ci	{0, "ccic0_mux", ccic_parent_names, ARRAY_SIZE(ccic_parent_names), CLK_SET_RATE_PARENT, APMU_CCIC0, 6, 1, 0, &ccic0_lock},
1948c2ecf20Sopenharmony_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},
1958c2ecf20Sopenharmony_ci};
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_cistatic struct mmp_param_div_clk apmu_div_clks[] = {
1988c2ecf20Sopenharmony_ci	{0, "ccic0_sphy_div", "ccic0_mux", CLK_SET_RATE_PARENT, APMU_CCIC0, 10, 5, 0, &ccic0_lock},
1998c2ecf20Sopenharmony_ci};
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_cistatic struct mmp_param_gate_clk apmu_gate_clks[] = {
2028c2ecf20Sopenharmony_ci	{PXA168_CLK_DFC, "dfc_clk", "pll1_4", CLK_SET_RATE_PARENT, APMU_DFC, 0x19b, 0x19b, 0x0, 0, NULL},
2038c2ecf20Sopenharmony_ci	{PXA168_CLK_USB, "usb_clk", "usb_pll", 0, APMU_USB, 0x9, 0x9, 0x0, 0, &usb_lock},
2048c2ecf20Sopenharmony_ci	{PXA168_CLK_SPH, "sph_clk", "usb_pll", 0, APMU_USB, 0x12, 0x12, 0x0, 0, &usb_lock},
2058c2ecf20Sopenharmony_ci	/* The gate clocks has mux parent. */
2068c2ecf20Sopenharmony_ci	{PXA168_CLK_SDH0, "sdh0_clk", "sdh0_mux", CLK_SET_RATE_PARENT, APMU_SDH0, 0x1b, 0x1b, 0x0, 0, &sdh0_lock},
2078c2ecf20Sopenharmony_ci	{PXA168_CLK_SDH1, "sdh1_clk", "sdh1_mux", CLK_SET_RATE_PARENT, APMU_SDH1, 0x1b, 0x1b, 0x0, 0, &sdh1_lock},
2088c2ecf20Sopenharmony_ci	{PXA168_CLK_DISP0, "disp0_clk", "disp0_mux", CLK_SET_RATE_PARENT, APMU_DISP0, 0x1b, 0x1b, 0x0, 0, &disp0_lock},
2098c2ecf20Sopenharmony_ci	{PXA168_CLK_CCIC0, "ccic0_clk", "ccic0_mux", CLK_SET_RATE_PARENT, APMU_CCIC0, 0x1b, 0x1b, 0x0, 0, &ccic0_lock},
2108c2ecf20Sopenharmony_ci	{PXA168_CLK_CCIC0_PHY, "ccic0_phy_clk", "ccic0_phy_mux", CLK_SET_RATE_PARENT, APMU_CCIC0, 0x24, 0x24, 0x0, 0, &ccic0_lock},
2118c2ecf20Sopenharmony_ci	{PXA168_CLK_CCIC0_SPHY, "ccic0_sphy_clk", "ccic0_sphy_div", CLK_SET_RATE_PARENT, APMU_CCIC0, 0x300, 0x300, 0x0, 0, &ccic0_lock},
2128c2ecf20Sopenharmony_ci};
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_cistatic void pxa168_axi_periph_clk_init(struct pxa168_clk_unit *pxa_unit)
2158c2ecf20Sopenharmony_ci{
2168c2ecf20Sopenharmony_ci	struct mmp_clk_unit *unit = &pxa_unit->unit;
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci	mmp_register_mux_clks(unit, apmu_mux_clks, pxa_unit->apmu_base,
2198c2ecf20Sopenharmony_ci				ARRAY_SIZE(apmu_mux_clks));
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci	mmp_register_div_clks(unit, apmu_div_clks, pxa_unit->apmu_base,
2228c2ecf20Sopenharmony_ci				ARRAY_SIZE(apmu_div_clks));
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci	mmp_register_gate_clks(unit, apmu_gate_clks, pxa_unit->apmu_base,
2258c2ecf20Sopenharmony_ci				ARRAY_SIZE(apmu_gate_clks));
2268c2ecf20Sopenharmony_ci}
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cistatic void pxa168_clk_reset_init(struct device_node *np,
2298c2ecf20Sopenharmony_ci				struct pxa168_clk_unit *pxa_unit)
2308c2ecf20Sopenharmony_ci{
2318c2ecf20Sopenharmony_ci	struct mmp_clk_reset_cell *cells;
2328c2ecf20Sopenharmony_ci	int i, nr_resets;
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	nr_resets = ARRAY_SIZE(apbc_gate_clks);
2358c2ecf20Sopenharmony_ci	cells = kcalloc(nr_resets, sizeof(*cells), GFP_KERNEL);
2368c2ecf20Sopenharmony_ci	if (!cells)
2378c2ecf20Sopenharmony_ci		return;
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci	for (i = 0; i < nr_resets; i++) {
2408c2ecf20Sopenharmony_ci		cells[i].clk_id = apbc_gate_clks[i].id;
2418c2ecf20Sopenharmony_ci		cells[i].reg = pxa_unit->apbc_base + apbc_gate_clks[i].offset;
2428c2ecf20Sopenharmony_ci		cells[i].flags = 0;
2438c2ecf20Sopenharmony_ci		cells[i].lock = apbc_gate_clks[i].lock;
2448c2ecf20Sopenharmony_ci		cells[i].bits = 0x4;
2458c2ecf20Sopenharmony_ci	}
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci	mmp_clk_reset_register(np, cells, nr_resets);
2488c2ecf20Sopenharmony_ci}
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_cistatic void __init pxa168_clk_init(struct device_node *np)
2518c2ecf20Sopenharmony_ci{
2528c2ecf20Sopenharmony_ci	struct pxa168_clk_unit *pxa_unit;
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci	pxa_unit = kzalloc(sizeof(*pxa_unit), GFP_KERNEL);
2558c2ecf20Sopenharmony_ci	if (!pxa_unit)
2568c2ecf20Sopenharmony_ci		return;
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci	pxa_unit->mpmu_base = of_iomap(np, 0);
2598c2ecf20Sopenharmony_ci	if (!pxa_unit->mpmu_base) {
2608c2ecf20Sopenharmony_ci		pr_err("failed to map mpmu registers\n");
2618c2ecf20Sopenharmony_ci		kfree(pxa_unit);
2628c2ecf20Sopenharmony_ci		return;
2638c2ecf20Sopenharmony_ci	}
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	pxa_unit->apmu_base = of_iomap(np, 1);
2668c2ecf20Sopenharmony_ci	if (!pxa_unit->apmu_base) {
2678c2ecf20Sopenharmony_ci		pr_err("failed to map apmu registers\n");
2688c2ecf20Sopenharmony_ci		kfree(pxa_unit);
2698c2ecf20Sopenharmony_ci		return;
2708c2ecf20Sopenharmony_ci	}
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci	pxa_unit->apbc_base = of_iomap(np, 2);
2738c2ecf20Sopenharmony_ci	if (!pxa_unit->apbc_base) {
2748c2ecf20Sopenharmony_ci		pr_err("failed to map apbc registers\n");
2758c2ecf20Sopenharmony_ci		kfree(pxa_unit);
2768c2ecf20Sopenharmony_ci		return;
2778c2ecf20Sopenharmony_ci	}
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	mmp_clk_init(np, &pxa_unit->unit, PXA168_NR_CLKS);
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	pxa168_pll_init(pxa_unit);
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	pxa168_apb_periph_clk_init(pxa_unit);
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	pxa168_axi_periph_clk_init(pxa_unit);
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci	pxa168_clk_reset_init(np, pxa_unit);
2888c2ecf20Sopenharmony_ci}
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ciCLK_OF_DECLARE(pxa168_clk, "marvell,pxa168-clock", pxa168_clk_init);
291