xref: /linux/drivers/clk/mmp/clk-of-pxa168.c (revision e2fd64dd472bea0da332da0cc8e8946d2d3294c4)
13bb16560SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2ab08aefcSChao Xie /*
3ab08aefcSChao Xie  * pxa168 clock framework source file
4ab08aefcSChao Xie  *
5ab08aefcSChao Xie  * Copyright (C) 2012 Marvell
6ab08aefcSChao Xie  * Chao Xie <xiechao.mail@gmail.com>
7ab08aefcSChao Xie  */
8ab08aefcSChao Xie 
9ab08aefcSChao Xie #include <linux/module.h>
10ab08aefcSChao Xie #include <linux/kernel.h>
11ab08aefcSChao Xie #include <linux/spinlock.h>
12ab08aefcSChao Xie #include <linux/io.h>
13ab08aefcSChao Xie #include <linux/delay.h>
14ab08aefcSChao Xie #include <linux/err.h>
15ab08aefcSChao Xie #include <linux/of_address.h>
16ab08aefcSChao Xie 
17ab08aefcSChao Xie #include <dt-bindings/clock/marvell,pxa168.h>
18ab08aefcSChao Xie 
19ab08aefcSChao Xie #include "clk.h"
20ab08aefcSChao Xie #include "reset.h"
21ab08aefcSChao Xie 
22ab08aefcSChao Xie #define APBC_UART0	0x0
23ab08aefcSChao Xie #define APBC_UART1	0x4
24ab08aefcSChao Xie #define APBC_GPIO	0x8
25ab08aefcSChao Xie #define APBC_PWM0	0xc
26ab08aefcSChao Xie #define APBC_PWM1	0x10
27ab08aefcSChao Xie #define APBC_PWM2	0x14
28ab08aefcSChao Xie #define APBC_PWM3	0x18
29a5ff3d8cSDoug Brown #define APBC_RTC	0x28
30a5ff3d8cSDoug Brown #define APBC_TWSI0	0x2c
31a5ff3d8cSDoug Brown #define APBC_KPC	0x30
3224c65a02SChao Xie #define APBC_TIMER	0x34
33a5ff3d8cSDoug Brown #define APBC_AIB	0x3c
34a5ff3d8cSDoug Brown #define APBC_SW_JTAG	0x40
35a5ff3d8cSDoug Brown #define APBC_ONEWIRE	0x48
36a5ff3d8cSDoug Brown #define APBC_TWSI1	0x6c
37a5ff3d8cSDoug Brown #define APBC_UART2	0x70
38a5ff3d8cSDoug Brown #define APBC_AC97	0x84
39ab08aefcSChao Xie #define APBC_SSP0	0x81c
40ab08aefcSChao Xie #define APBC_SSP1	0x820
41ab08aefcSChao Xie #define APBC_SSP2	0x84c
42ab08aefcSChao Xie #define APBC_SSP3	0x858
43ab08aefcSChao Xie #define APBC_SSP4	0x85c
44a5ff3d8cSDoug Brown #define APMU_DISP0	0x4c
45a5ff3d8cSDoug Brown #define APMU_CCIC0	0x50
46ab08aefcSChao Xie #define APMU_SDH0	0x54
47ab08aefcSChao Xie #define APMU_SDH1	0x58
48ab08aefcSChao Xie #define APMU_USB	0x5c
49ab08aefcSChao Xie #define APMU_DFC	0x60
50a5ff3d8cSDoug Brown #define APMU_DMA	0x64
51a5ff3d8cSDoug Brown #define APMU_BUS	0x6c
52a5ff3d8cSDoug Brown #define APMU_GC		0xcc
53a5ff3d8cSDoug Brown #define APMU_SMC	0xd4
54a5ff3d8cSDoug Brown #define APMU_XD		0xdc
55a5ff3d8cSDoug Brown #define APMU_SDH2	0xe0
56a5ff3d8cSDoug Brown #define APMU_SDH3	0xe4
57a5ff3d8cSDoug Brown #define APMU_CF		0xf0
58a5ff3d8cSDoug Brown #define APMU_MSP	0xf4
59a5ff3d8cSDoug Brown #define APMU_CMU	0xf8
60a5ff3d8cSDoug Brown #define APMU_FE		0xfc
61a5ff3d8cSDoug Brown #define APMU_PCIE	0x100
62a5ff3d8cSDoug Brown #define APMU_EPD	0x104
63ab08aefcSChao Xie #define MPMU_UART_PLL	0x14
64ab08aefcSChao Xie 
65ab08aefcSChao Xie struct pxa168_clk_unit {
66ab08aefcSChao Xie 	struct mmp_clk_unit unit;
67ab08aefcSChao Xie 	void __iomem *mpmu_base;
68ab08aefcSChao Xie 	void __iomem *apmu_base;
69ab08aefcSChao Xie 	void __iomem *apbc_base;
70ab08aefcSChao Xie };
71ab08aefcSChao Xie 
72ab08aefcSChao Xie static struct mmp_param_fixed_rate_clk fixed_rate_clks[] = {
73536630ddSStephen Boyd 	{PXA168_CLK_CLK32, "clk32", NULL, 0, 32768},
74536630ddSStephen Boyd 	{PXA168_CLK_VCTCXO, "vctcxo", NULL, 0, 26000000},
75536630ddSStephen Boyd 	{PXA168_CLK_PLL1, "pll1", NULL, 0, 624000000},
76536630ddSStephen Boyd 	{PXA168_CLK_USB_PLL, "usb_pll", NULL, 0, 480000000},
77ab08aefcSChao Xie };
78ab08aefcSChao Xie 
79ab08aefcSChao Xie static struct mmp_param_fixed_factor_clk fixed_factor_clks[] = {
80ab08aefcSChao Xie 	{PXA168_CLK_PLL1_2, "pll1_2", "pll1", 1, 2, 0},
81ab08aefcSChao Xie 	{PXA168_CLK_PLL1_4, "pll1_4", "pll1_2", 1, 2, 0},
82ab08aefcSChao Xie 	{PXA168_CLK_PLL1_8, "pll1_8", "pll1_4", 1, 2, 0},
83ab08aefcSChao Xie 	{PXA168_CLK_PLL1_16, "pll1_16", "pll1_8", 1, 2, 0},
84ab08aefcSChao Xie 	{PXA168_CLK_PLL1_6, "pll1_6", "pll1_2", 1, 3, 0},
85ab08aefcSChao Xie 	{PXA168_CLK_PLL1_12, "pll1_12", "pll1_6", 1, 2, 0},
86ab08aefcSChao Xie 	{PXA168_CLK_PLL1_24, "pll1_24", "pll1_12", 1, 2, 0},
87ab08aefcSChao Xie 	{PXA168_CLK_PLL1_48, "pll1_48", "pll1_24", 1, 2, 0},
88ab08aefcSChao Xie 	{PXA168_CLK_PLL1_96, "pll1_96", "pll1_48", 1, 2, 0},
8924c65a02SChao Xie 	{PXA168_CLK_PLL1_192, "pll1_192", "pll1_96", 1, 2, 0},
90ab08aefcSChao Xie 	{PXA168_CLK_PLL1_13, "pll1_13", "pll1", 1, 13, 0},
91a77a1e2fSDoug Brown 	{PXA168_CLK_PLL1_13_1_5, "pll1_13_1_5", "pll1_13", 1, 5, 0},
92a77a1e2fSDoug Brown 	{PXA168_CLK_PLL1_2_1_5, "pll1_2_1_5", "pll1_2", 1, 5, 0},
93ab08aefcSChao Xie 	{PXA168_CLK_PLL1_3_16, "pll1_3_16", "pll1", 3, 16, 0},
94ac1d62c9SDoug Brown 	{PXA168_CLK_PLL1_2_1_10, "pll1_2_1_10", "pll1_2", 1, 10, 0},
95ac1d62c9SDoug Brown 	{PXA168_CLK_PLL1_2_3_16, "pll1_2_3_16", "pll1_2", 3, 16, 0},
96ac1d62c9SDoug Brown 	{PXA168_CLK_CLK32_2, "clk32_2", "clk32", 1, 2, 0},
97ab08aefcSChao Xie };
98ab08aefcSChao Xie 
99ab08aefcSChao Xie static struct mmp_clk_factor_masks uart_factor_masks = {
100ab08aefcSChao Xie 	.factor = 2,
101ab08aefcSChao Xie 	.num_mask = 0x1fff,
102ab08aefcSChao Xie 	.den_mask = 0x1fff,
103ab08aefcSChao Xie 	.num_shift = 16,
104ab08aefcSChao Xie 	.den_shift = 0,
105ab08aefcSChao Xie };
106ab08aefcSChao Xie 
107ab08aefcSChao Xie static struct mmp_clk_factor_tbl uart_factor_tbl[] = {
108ab08aefcSChao Xie 	{.num = 8125, .den = 1536},	/*14.745MHZ */
109ab08aefcSChao Xie };
110ab08aefcSChao Xie 
111ab08aefcSChao Xie static void pxa168_pll_init(struct pxa168_clk_unit *pxa_unit)
112ab08aefcSChao Xie {
113ab08aefcSChao Xie 	struct clk *clk;
114ab08aefcSChao Xie 	struct mmp_clk_unit *unit = &pxa_unit->unit;
115ab08aefcSChao Xie 
116ab08aefcSChao Xie 	mmp_register_fixed_rate_clks(unit, fixed_rate_clks,
117ab08aefcSChao Xie 					ARRAY_SIZE(fixed_rate_clks));
118ab08aefcSChao Xie 
119ab08aefcSChao Xie 	mmp_register_fixed_factor_clks(unit, fixed_factor_clks,
120ab08aefcSChao Xie 					ARRAY_SIZE(fixed_factor_clks));
121ab08aefcSChao Xie 
122ab08aefcSChao Xie 	clk = mmp_clk_register_factor("uart_pll", "pll1_4",
123ab08aefcSChao Xie 				CLK_SET_RATE_PARENT,
124ab08aefcSChao Xie 				pxa_unit->mpmu_base + MPMU_UART_PLL,
125ab08aefcSChao Xie 				&uart_factor_masks, uart_factor_tbl,
126ab08aefcSChao Xie 				ARRAY_SIZE(uart_factor_tbl), NULL);
127ab08aefcSChao Xie 	mmp_clk_add(unit, PXA168_CLK_UART_PLL, clk);
128ab08aefcSChao Xie }
129ab08aefcSChao Xie 
130ab08aefcSChao Xie static DEFINE_SPINLOCK(uart0_lock);
131ab08aefcSChao Xie static DEFINE_SPINLOCK(uart1_lock);
132ab08aefcSChao Xie static DEFINE_SPINLOCK(uart2_lock);
133*e2fd64ddSDoug Brown static const char * const uart_parent_names[] = {"pll1_3_16", "uart_pll"};
134ab08aefcSChao Xie 
135ab08aefcSChao Xie static DEFINE_SPINLOCK(ssp0_lock);
136ab08aefcSChao Xie static DEFINE_SPINLOCK(ssp1_lock);
137ab08aefcSChao Xie static DEFINE_SPINLOCK(ssp2_lock);
138ab08aefcSChao Xie static DEFINE_SPINLOCK(ssp3_lock);
139ab08aefcSChao Xie static DEFINE_SPINLOCK(ssp4_lock);
140*e2fd64ddSDoug Brown static const char * const ssp_parent_names[] = {"pll1_96", "pll1_48", "pll1_24", "pll1_12"};
141ab08aefcSChao Xie 
14224c65a02SChao Xie static DEFINE_SPINLOCK(timer_lock);
143*e2fd64ddSDoug Brown static const char * const timer_parent_names[] = {"pll1_48", "clk32", "pll1_96", "pll1_192"};
14424c65a02SChao Xie 
145ab08aefcSChao Xie static DEFINE_SPINLOCK(reset_lock);
146ab08aefcSChao Xie 
147ab08aefcSChao Xie static struct mmp_param_mux_clk apbc_mux_clks[] = {
148ab08aefcSChao Xie 	{0, "uart0_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, APBC_UART0, 4, 3, 0, &uart0_lock},
149ab08aefcSChao Xie 	{0, "uart1_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, APBC_UART1, 4, 3, 0, &uart1_lock},
150ab08aefcSChao Xie 	{0, "uart2_mux", uart_parent_names, ARRAY_SIZE(uart_parent_names), CLK_SET_RATE_PARENT, APBC_UART2, 4, 3, 0, &uart2_lock},
151ab08aefcSChao Xie 	{0, "ssp0_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP0, 4, 3, 0, &ssp0_lock},
152ab08aefcSChao Xie 	{0, "ssp1_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP1, 4, 3, 0, &ssp1_lock},
153ab08aefcSChao Xie 	{0, "ssp2_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP2, 4, 3, 0, &ssp2_lock},
154ab08aefcSChao Xie 	{0, "ssp3_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP3, 4, 3, 0, &ssp3_lock},
155ab08aefcSChao Xie 	{0, "ssp4_mux", ssp_parent_names, ARRAY_SIZE(ssp_parent_names), CLK_SET_RATE_PARENT, APBC_SSP4, 4, 3, 0, &ssp4_lock},
15624c65a02SChao Xie 	{0, "timer_mux", timer_parent_names, ARRAY_SIZE(timer_parent_names), CLK_SET_RATE_PARENT, APBC_TIMER, 4, 3, 0, &timer_lock},
157ab08aefcSChao Xie };
158ab08aefcSChao Xie 
159ab08aefcSChao Xie static struct mmp_param_gate_clk apbc_gate_clks[] = {
160ab08aefcSChao Xie 	{PXA168_CLK_TWSI0, "twsi0_clk", "pll1_13_1_5", CLK_SET_RATE_PARENT, APBC_TWSI0, 0x3, 0x3, 0x0, 0, &reset_lock},
161ab08aefcSChao Xie 	{PXA168_CLK_TWSI1, "twsi1_clk", "pll1_13_1_5", CLK_SET_RATE_PARENT, APBC_TWSI1, 0x3, 0x3, 0x0, 0, &reset_lock},
162ab08aefcSChao Xie 	{PXA168_CLK_GPIO, "gpio_clk", "vctcxo", CLK_SET_RATE_PARENT, APBC_GPIO, 0x3, 0x3, 0x0, 0, &reset_lock},
163ab08aefcSChao Xie 	{PXA168_CLK_KPC, "kpc_clk", "clk32", CLK_SET_RATE_PARENT, APBC_KPC, 0x3, 0x3, 0x0, MMP_CLK_GATE_NEED_DELAY, NULL},
164ab08aefcSChao Xie 	{PXA168_CLK_RTC, "rtc_clk", "clk32", CLK_SET_RATE_PARENT, APBC_RTC, 0x83, 0x83, 0x0, MMP_CLK_GATE_NEED_DELAY, NULL},
165ab08aefcSChao Xie 	{PXA168_CLK_PWM0, "pwm0_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM0, 0x3, 0x3, 0x0, 0, &reset_lock},
166ab08aefcSChao Xie 	{PXA168_CLK_PWM1, "pwm1_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM1, 0x3, 0x3, 0x0, 0, &reset_lock},
167ab08aefcSChao Xie 	{PXA168_CLK_PWM2, "pwm2_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM2, 0x3, 0x3, 0x0, 0, &reset_lock},
168ab08aefcSChao Xie 	{PXA168_CLK_PWM3, "pwm3_clk", "pll1_48", CLK_SET_RATE_PARENT, APBC_PWM3, 0x3, 0x3, 0x0, 0, &reset_lock},
169ab08aefcSChao Xie 	/* The gate clocks has mux parent. */
170ab08aefcSChao Xie 	{PXA168_CLK_UART0, "uart0_clk", "uart0_mux", CLK_SET_RATE_PARENT, APBC_UART0, 0x3, 0x3, 0x0, 0, &uart0_lock},
171ab08aefcSChao Xie 	{PXA168_CLK_UART1, "uart1_clk", "uart1_mux", CLK_SET_RATE_PARENT, APBC_UART1, 0x3, 0x3, 0x0, 0, &uart1_lock},
172ab08aefcSChao Xie 	{PXA168_CLK_UART2, "uart2_clk", "uart2_mux", CLK_SET_RATE_PARENT, APBC_UART2, 0x3, 0x3, 0x0, 0, &uart2_lock},
173ab08aefcSChao Xie 	{PXA168_CLK_SSP0, "ssp0_clk", "ssp0_mux", CLK_SET_RATE_PARENT, APBC_SSP0, 0x3, 0x3, 0x0, 0, &ssp0_lock},
174ab08aefcSChao Xie 	{PXA168_CLK_SSP1, "ssp1_clk", "ssp1_mux", CLK_SET_RATE_PARENT, APBC_SSP1, 0x3, 0x3, 0x0, 0, &ssp1_lock},
175ab08aefcSChao Xie 	{PXA168_CLK_SSP2, "ssp2_clk", "ssp2_mux", CLK_SET_RATE_PARENT, APBC_SSP2, 0x3, 0x3, 0x0, 0, &ssp2_lock},
176ab08aefcSChao Xie 	{PXA168_CLK_SSP3, "ssp3_clk", "ssp3_mux", CLK_SET_RATE_PARENT, APBC_SSP3, 0x3, 0x3, 0x0, 0, &ssp3_lock},
177ab08aefcSChao Xie 	{PXA168_CLK_SSP4, "ssp4_clk", "ssp4_mux", CLK_SET_RATE_PARENT, APBC_SSP4, 0x3, 0x3, 0x0, 0, &ssp4_lock},
17824c65a02SChao Xie 	{PXA168_CLK_TIMER, "timer_clk", "timer_mux", CLK_SET_RATE_PARENT, APBC_TIMER, 0x3, 0x3, 0x0, 0, &timer_lock},
179ab08aefcSChao Xie };
180ab08aefcSChao Xie 
181ab08aefcSChao Xie static void pxa168_apb_periph_clk_init(struct pxa168_clk_unit *pxa_unit)
182ab08aefcSChao Xie {
183ab08aefcSChao Xie 	struct mmp_clk_unit *unit = &pxa_unit->unit;
184ab08aefcSChao Xie 
185ab08aefcSChao Xie 	mmp_register_mux_clks(unit, apbc_mux_clks, pxa_unit->apbc_base,
186ab08aefcSChao Xie 				ARRAY_SIZE(apbc_mux_clks));
187ab08aefcSChao Xie 
188ab08aefcSChao Xie 	mmp_register_gate_clks(unit, apbc_gate_clks, pxa_unit->apbc_base,
189ab08aefcSChao Xie 				ARRAY_SIZE(apbc_gate_clks));
190ab08aefcSChao Xie 
191ab08aefcSChao Xie }
192ab08aefcSChao Xie 
193ab08aefcSChao Xie static DEFINE_SPINLOCK(sdh0_lock);
194ab08aefcSChao Xie static DEFINE_SPINLOCK(sdh1_lock);
195*e2fd64ddSDoug Brown static const char * const sdh_parent_names[] = {"pll1_12", "pll1_13"};
196ab08aefcSChao Xie 
197ab08aefcSChao Xie static DEFINE_SPINLOCK(usb_lock);
198ab08aefcSChao Xie 
199ab08aefcSChao Xie static DEFINE_SPINLOCK(disp0_lock);
200*e2fd64ddSDoug Brown static const char * const disp_parent_names[] = {"pll1_2", "pll1_12"};
201ab08aefcSChao Xie 
202ab08aefcSChao Xie static DEFINE_SPINLOCK(ccic0_lock);
203*e2fd64ddSDoug Brown static const char * const ccic_parent_names[] = {"pll1_2", "pll1_12"};
204*e2fd64ddSDoug Brown static const char * const ccic_phy_parent_names[] = {"pll1_6", "pll1_12"};
205ab08aefcSChao Xie 
206ab08aefcSChao Xie static struct mmp_param_mux_clk apmu_mux_clks[] = {
207ab08aefcSChao Xie 	{0, "sdh0_mux", sdh_parent_names, ARRAY_SIZE(sdh_parent_names), CLK_SET_RATE_PARENT, APMU_SDH0, 6, 1, 0, &sdh0_lock},
208ab08aefcSChao Xie 	{0, "sdh1_mux", sdh_parent_names, ARRAY_SIZE(sdh_parent_names), CLK_SET_RATE_PARENT, APMU_SDH1, 6, 1, 0, &sdh1_lock},
209ab08aefcSChao Xie 	{0, "disp0_mux", disp_parent_names, ARRAY_SIZE(disp_parent_names), CLK_SET_RATE_PARENT, APMU_DISP0, 6, 1, 0, &disp0_lock},
210ab08aefcSChao Xie 	{0, "ccic0_mux", ccic_parent_names, ARRAY_SIZE(ccic_parent_names), CLK_SET_RATE_PARENT, APMU_CCIC0, 6, 1, 0, &ccic0_lock},
211ab08aefcSChao Xie 	{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},
212ab08aefcSChao Xie };
213ab08aefcSChao Xie 
214ab08aefcSChao Xie static struct mmp_param_div_clk apmu_div_clks[] = {
215ab08aefcSChao Xie 	{0, "ccic0_sphy_div", "ccic0_mux", CLK_SET_RATE_PARENT, APMU_CCIC0, 10, 5, 0, &ccic0_lock},
216ab08aefcSChao Xie };
217ab08aefcSChao Xie 
218ab08aefcSChao Xie static struct mmp_param_gate_clk apmu_gate_clks[] = {
219ab08aefcSChao Xie 	{PXA168_CLK_DFC, "dfc_clk", "pll1_4", CLK_SET_RATE_PARENT, APMU_DFC, 0x19b, 0x19b, 0x0, 0, NULL},
220ab08aefcSChao Xie 	{PXA168_CLK_USB, "usb_clk", "usb_pll", 0, APMU_USB, 0x9, 0x9, 0x0, 0, &usb_lock},
221ab08aefcSChao Xie 	{PXA168_CLK_SPH, "sph_clk", "usb_pll", 0, APMU_USB, 0x12, 0x12, 0x0, 0, &usb_lock},
222ab08aefcSChao Xie 	/* The gate clocks has mux parent. */
223ab08aefcSChao Xie 	{PXA168_CLK_SDH0, "sdh0_clk", "sdh0_mux", CLK_SET_RATE_PARENT, APMU_SDH0, 0x1b, 0x1b, 0x0, 0, &sdh0_lock},
224ab08aefcSChao Xie 	{PXA168_CLK_SDH1, "sdh1_clk", "sdh1_mux", CLK_SET_RATE_PARENT, APMU_SDH1, 0x1b, 0x1b, 0x0, 0, &sdh1_lock},
225ab08aefcSChao Xie 	{PXA168_CLK_DISP0, "disp0_clk", "disp0_mux", CLK_SET_RATE_PARENT, APMU_DISP0, 0x1b, 0x1b, 0x0, 0, &disp0_lock},
226ab08aefcSChao Xie 	{PXA168_CLK_CCIC0, "ccic0_clk", "ccic0_mux", CLK_SET_RATE_PARENT, APMU_CCIC0, 0x1b, 0x1b, 0x0, 0, &ccic0_lock},
227ab08aefcSChao Xie 	{PXA168_CLK_CCIC0_PHY, "ccic0_phy_clk", "ccic0_phy_mux", CLK_SET_RATE_PARENT, APMU_CCIC0, 0x24, 0x24, 0x0, 0, &ccic0_lock},
228ab08aefcSChao Xie 	{PXA168_CLK_CCIC0_SPHY, "ccic0_sphy_clk", "ccic0_sphy_div", CLK_SET_RATE_PARENT, APMU_CCIC0, 0x300, 0x300, 0x0, 0, &ccic0_lock},
229ab08aefcSChao Xie };
230ab08aefcSChao Xie 
231ab08aefcSChao Xie static void pxa168_axi_periph_clk_init(struct pxa168_clk_unit *pxa_unit)
232ab08aefcSChao Xie {
233ab08aefcSChao Xie 	struct mmp_clk_unit *unit = &pxa_unit->unit;
234ab08aefcSChao Xie 
235ab08aefcSChao Xie 	mmp_register_mux_clks(unit, apmu_mux_clks, pxa_unit->apmu_base,
236ab08aefcSChao Xie 				ARRAY_SIZE(apmu_mux_clks));
237ab08aefcSChao Xie 
238ab08aefcSChao Xie 	mmp_register_div_clks(unit, apmu_div_clks, pxa_unit->apmu_base,
239ab08aefcSChao Xie 				ARRAY_SIZE(apmu_div_clks));
240ab08aefcSChao Xie 
241ab08aefcSChao Xie 	mmp_register_gate_clks(unit, apmu_gate_clks, pxa_unit->apmu_base,
242ab08aefcSChao Xie 				ARRAY_SIZE(apmu_gate_clks));
243ab08aefcSChao Xie }
244ab08aefcSChao Xie 
245ab08aefcSChao Xie static void pxa168_clk_reset_init(struct device_node *np,
246ab08aefcSChao Xie 				struct pxa168_clk_unit *pxa_unit)
247ab08aefcSChao Xie {
248ab08aefcSChao Xie 	struct mmp_clk_reset_cell *cells;
249ab08aefcSChao Xie 	int i, nr_resets;
250ab08aefcSChao Xie 
251ab08aefcSChao Xie 	nr_resets = ARRAY_SIZE(apbc_gate_clks);
252ab08aefcSChao Xie 	cells = kcalloc(nr_resets, sizeof(*cells), GFP_KERNEL);
253ab08aefcSChao Xie 	if (!cells)
254ab08aefcSChao Xie 		return;
255ab08aefcSChao Xie 
256ab08aefcSChao Xie 	for (i = 0; i < nr_resets; i++) {
257ab08aefcSChao Xie 		cells[i].clk_id = apbc_gate_clks[i].id;
258ab08aefcSChao Xie 		cells[i].reg = pxa_unit->apbc_base + apbc_gate_clks[i].offset;
259ab08aefcSChao Xie 		cells[i].flags = 0;
260ab08aefcSChao Xie 		cells[i].lock = apbc_gate_clks[i].lock;
261ab08aefcSChao Xie 		cells[i].bits = 0x4;
262ab08aefcSChao Xie 	}
263ab08aefcSChao Xie 
264ab08aefcSChao Xie 	mmp_clk_reset_register(np, cells, nr_resets);
265ab08aefcSChao Xie }
266ab08aefcSChao Xie 
267ab08aefcSChao Xie static void __init pxa168_clk_init(struct device_node *np)
268ab08aefcSChao Xie {
269ab08aefcSChao Xie 	struct pxa168_clk_unit *pxa_unit;
270ab08aefcSChao Xie 
271ab08aefcSChao Xie 	pxa_unit = kzalloc(sizeof(*pxa_unit), GFP_KERNEL);
272ab08aefcSChao Xie 	if (!pxa_unit)
273ab08aefcSChao Xie 		return;
274ab08aefcSChao Xie 
275ab08aefcSChao Xie 	pxa_unit->mpmu_base = of_iomap(np, 0);
276ab08aefcSChao Xie 	if (!pxa_unit->mpmu_base) {
277ab08aefcSChao Xie 		pr_err("failed to map mpmu registers\n");
278ab08aefcSChao Xie 		return;
279ab08aefcSChao Xie 	}
280ab08aefcSChao Xie 
281ab08aefcSChao Xie 	pxa_unit->apmu_base = of_iomap(np, 1);
282deab0726SWei Yongjun 	if (!pxa_unit->apmu_base) {
283ab08aefcSChao Xie 		pr_err("failed to map apmu registers\n");
284ab08aefcSChao Xie 		return;
285ab08aefcSChao Xie 	}
286ab08aefcSChao Xie 
287ab08aefcSChao Xie 	pxa_unit->apbc_base = of_iomap(np, 2);
288ab08aefcSChao Xie 	if (!pxa_unit->apbc_base) {
289ab08aefcSChao Xie 		pr_err("failed to map apbc registers\n");
290ab08aefcSChao Xie 		return;
291ab08aefcSChao Xie 	}
292ab08aefcSChao Xie 
293ab08aefcSChao Xie 	mmp_clk_init(np, &pxa_unit->unit, PXA168_NR_CLKS);
294ab08aefcSChao Xie 
295ab08aefcSChao Xie 	pxa168_pll_init(pxa_unit);
296ab08aefcSChao Xie 
297ab08aefcSChao Xie 	pxa168_apb_periph_clk_init(pxa_unit);
298ab08aefcSChao Xie 
299ab08aefcSChao Xie 	pxa168_axi_periph_clk_init(pxa_unit);
300ab08aefcSChao Xie 
301ab08aefcSChao Xie 	pxa168_clk_reset_init(np, pxa_unit);
302ab08aefcSChao Xie }
303ab08aefcSChao Xie 
304ab08aefcSChao Xie CLK_OF_DECLARE(pxa168_clk, "marvell,pxa168-clock", pxa168_clk_init);
305