xref: /OK3568_Linux_fs/kernel/drivers/clk/ti/clk-3xxx.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * OMAP3 Clock init
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (C) 2013 Texas Instruments, Inc
5*4882a593Smuzhiyun  *     Tero Kristo (t-kristo@ti.com)
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or
8*4882a593Smuzhiyun  * modify it under the terms of the GNU General Public License as
9*4882a593Smuzhiyun  * published by the Free Software Foundation version 2.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
12*4882a593Smuzhiyun  * kind, whether express or implied; without even the implied warranty
13*4882a593Smuzhiyun  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*4882a593Smuzhiyun  * GNU General Public License for more details.
15*4882a593Smuzhiyun  */
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include <linux/kernel.h>
18*4882a593Smuzhiyun #include <linux/list.h>
19*4882a593Smuzhiyun #include <linux/clk.h>
20*4882a593Smuzhiyun #include <linux/clk-provider.h>
21*4882a593Smuzhiyun #include <linux/clk/ti.h>
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #include "clock.h"
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #define OMAP3430ES2_ST_DSS_IDLE_SHIFT			1
26*4882a593Smuzhiyun #define OMAP3430ES2_ST_HSOTGUSB_IDLE_SHIFT		5
27*4882a593Smuzhiyun #define OMAP3430ES2_ST_SSI_IDLE_SHIFT			8
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #define OMAP34XX_CM_IDLEST_VAL				1
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /*
32*4882a593Smuzhiyun  * In AM35xx IPSS, the {ICK,FCK} enable bits for modules are exported
33*4882a593Smuzhiyun  * in the same register at a bit offset of 0x8. The EN_ACK for ICK is
34*4882a593Smuzhiyun  * at an offset of 4 from ICK enable bit.
35*4882a593Smuzhiyun  */
36*4882a593Smuzhiyun #define AM35XX_IPSS_ICK_MASK			0xF
37*4882a593Smuzhiyun #define AM35XX_IPSS_ICK_EN_ACK_OFFSET		0x4
38*4882a593Smuzhiyun #define AM35XX_IPSS_ICK_FCK_OFFSET		0x8
39*4882a593Smuzhiyun #define AM35XX_IPSS_CLK_IDLEST_VAL		0
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun #define AM35XX_ST_IPSS_SHIFT			5
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun /**
44*4882a593Smuzhiyun  * omap3430es2_clk_ssi_find_idlest - return CM_IDLEST info for SSI
45*4882a593Smuzhiyun  * @clk: struct clk * being enabled
46*4882a593Smuzhiyun  * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
47*4882a593Smuzhiyun  * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
48*4882a593Smuzhiyun  * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
49*4882a593Smuzhiyun  *
50*4882a593Smuzhiyun  * The OMAP3430ES2 SSI target CM_IDLEST bit is at a different shift
51*4882a593Smuzhiyun  * from the CM_{I,F}CLKEN bit.  Pass back the correct info via
52*4882a593Smuzhiyun  * @idlest_reg and @idlest_bit.  No return value.
53*4882a593Smuzhiyun  */
omap3430es2_clk_ssi_find_idlest(struct clk_hw_omap * clk,struct clk_omap_reg * idlest_reg,u8 * idlest_bit,u8 * idlest_val)54*4882a593Smuzhiyun static void omap3430es2_clk_ssi_find_idlest(struct clk_hw_omap *clk,
55*4882a593Smuzhiyun 					    struct clk_omap_reg *idlest_reg,
56*4882a593Smuzhiyun 					    u8 *idlest_bit,
57*4882a593Smuzhiyun 					    u8 *idlest_val)
58*4882a593Smuzhiyun {
59*4882a593Smuzhiyun 	memcpy(idlest_reg, &clk->enable_reg, sizeof(*idlest_reg));
60*4882a593Smuzhiyun 	idlest_reg->offset &= ~0xf0;
61*4882a593Smuzhiyun 	idlest_reg->offset |= 0x20;
62*4882a593Smuzhiyun 	*idlest_bit = OMAP3430ES2_ST_SSI_IDLE_SHIFT;
63*4882a593Smuzhiyun 	*idlest_val = OMAP34XX_CM_IDLEST_VAL;
64*4882a593Smuzhiyun }
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_ssi_wait = {
67*4882a593Smuzhiyun 	.allow_idle	= omap2_clkt_iclk_allow_idle,
68*4882a593Smuzhiyun 	.deny_idle	= omap2_clkt_iclk_deny_idle,
69*4882a593Smuzhiyun 	.find_idlest	= omap3430es2_clk_ssi_find_idlest,
70*4882a593Smuzhiyun 	.find_companion	= omap2_clk_dflt_find_companion,
71*4882a593Smuzhiyun };
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun /**
74*4882a593Smuzhiyun  * omap3430es2_clk_dss_usbhost_find_idlest - CM_IDLEST info for DSS, USBHOST
75*4882a593Smuzhiyun  * @clk: struct clk * being enabled
76*4882a593Smuzhiyun  * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
77*4882a593Smuzhiyun  * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
78*4882a593Smuzhiyun  * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
79*4882a593Smuzhiyun  *
80*4882a593Smuzhiyun  * Some OMAP modules on OMAP3 ES2+ chips have both initiator and
81*4882a593Smuzhiyun  * target IDLEST bits.  For our purposes, we are concerned with the
82*4882a593Smuzhiyun  * target IDLEST bits, which exist at a different bit position than
83*4882a593Smuzhiyun  * the *CLKEN bit position for these modules (DSS and USBHOST) (The
84*4882a593Smuzhiyun  * default find_idlest code assumes that they are at the same
85*4882a593Smuzhiyun  * position.)  No return value.
86*4882a593Smuzhiyun  */
87*4882a593Smuzhiyun static void
omap3430es2_clk_dss_usbhost_find_idlest(struct clk_hw_omap * clk,struct clk_omap_reg * idlest_reg,u8 * idlest_bit,u8 * idlest_val)88*4882a593Smuzhiyun omap3430es2_clk_dss_usbhost_find_idlest(struct clk_hw_omap *clk,
89*4882a593Smuzhiyun 					struct clk_omap_reg *idlest_reg,
90*4882a593Smuzhiyun 					u8 *idlest_bit, u8 *idlest_val)
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun 	memcpy(idlest_reg, &clk->enable_reg, sizeof(*idlest_reg));
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun 	idlest_reg->offset &= ~0xf0;
95*4882a593Smuzhiyun 	idlest_reg->offset |= 0x20;
96*4882a593Smuzhiyun 	/* USBHOST_IDLE has same shift */
97*4882a593Smuzhiyun 	*idlest_bit = OMAP3430ES2_ST_DSS_IDLE_SHIFT;
98*4882a593Smuzhiyun 	*idlest_val = OMAP34XX_CM_IDLEST_VAL;
99*4882a593Smuzhiyun }
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait = {
102*4882a593Smuzhiyun 	.find_idlest	= omap3430es2_clk_dss_usbhost_find_idlest,
103*4882a593Smuzhiyun 	.find_companion	= omap2_clk_dflt_find_companion,
104*4882a593Smuzhiyun };
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_dss_usbhost_wait = {
107*4882a593Smuzhiyun 	.allow_idle	= omap2_clkt_iclk_allow_idle,
108*4882a593Smuzhiyun 	.deny_idle	= omap2_clkt_iclk_deny_idle,
109*4882a593Smuzhiyun 	.find_idlest	= omap3430es2_clk_dss_usbhost_find_idlest,
110*4882a593Smuzhiyun 	.find_companion	= omap2_clk_dflt_find_companion,
111*4882a593Smuzhiyun };
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun /**
114*4882a593Smuzhiyun  * omap3430es2_clk_hsotgusb_find_idlest - return CM_IDLEST info for HSOTGUSB
115*4882a593Smuzhiyun  * @clk: struct clk * being enabled
116*4882a593Smuzhiyun  * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
117*4882a593Smuzhiyun  * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
118*4882a593Smuzhiyun  * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
119*4882a593Smuzhiyun  *
120*4882a593Smuzhiyun  * The OMAP3430ES2 HSOTGUSB target CM_IDLEST bit is at a different
121*4882a593Smuzhiyun  * shift from the CM_{I,F}CLKEN bit.  Pass back the correct info via
122*4882a593Smuzhiyun  * @idlest_reg and @idlest_bit.  No return value.
123*4882a593Smuzhiyun  */
124*4882a593Smuzhiyun static void
omap3430es2_clk_hsotgusb_find_idlest(struct clk_hw_omap * clk,struct clk_omap_reg * idlest_reg,u8 * idlest_bit,u8 * idlest_val)125*4882a593Smuzhiyun omap3430es2_clk_hsotgusb_find_idlest(struct clk_hw_omap *clk,
126*4882a593Smuzhiyun 				     struct clk_omap_reg *idlest_reg,
127*4882a593Smuzhiyun 				     u8 *idlest_bit,
128*4882a593Smuzhiyun 				     u8 *idlest_val)
129*4882a593Smuzhiyun {
130*4882a593Smuzhiyun 	memcpy(idlest_reg, &clk->enable_reg, sizeof(*idlest_reg));
131*4882a593Smuzhiyun 	idlest_reg->offset &= ~0xf0;
132*4882a593Smuzhiyun 	idlest_reg->offset |= 0x20;
133*4882a593Smuzhiyun 	*idlest_bit = OMAP3430ES2_ST_HSOTGUSB_IDLE_SHIFT;
134*4882a593Smuzhiyun 	*idlest_val = OMAP34XX_CM_IDLEST_VAL;
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_hsotgusb_wait = {
138*4882a593Smuzhiyun 	.allow_idle	= omap2_clkt_iclk_allow_idle,
139*4882a593Smuzhiyun 	.deny_idle	= omap2_clkt_iclk_deny_idle,
140*4882a593Smuzhiyun 	.find_idlest	= omap3430es2_clk_hsotgusb_find_idlest,
141*4882a593Smuzhiyun 	.find_companion	= omap2_clk_dflt_find_companion,
142*4882a593Smuzhiyun };
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun /**
145*4882a593Smuzhiyun  * am35xx_clk_find_idlest - return clock ACK info for AM35XX IPSS
146*4882a593Smuzhiyun  * @clk: struct clk * being enabled
147*4882a593Smuzhiyun  * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
148*4882a593Smuzhiyun  * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
149*4882a593Smuzhiyun  * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
150*4882a593Smuzhiyun  *
151*4882a593Smuzhiyun  * The interface clocks on AM35xx IPSS reflects the clock idle status
152*4882a593Smuzhiyun  * in the enable register itsel at a bit offset of 4 from the enable
153*4882a593Smuzhiyun  * bit. A value of 1 indicates that clock is enabled.
154*4882a593Smuzhiyun  */
am35xx_clk_find_idlest(struct clk_hw_omap * clk,struct clk_omap_reg * idlest_reg,u8 * idlest_bit,u8 * idlest_val)155*4882a593Smuzhiyun static void am35xx_clk_find_idlest(struct clk_hw_omap *clk,
156*4882a593Smuzhiyun 				   struct clk_omap_reg *idlest_reg,
157*4882a593Smuzhiyun 				   u8 *idlest_bit,
158*4882a593Smuzhiyun 				   u8 *idlest_val)
159*4882a593Smuzhiyun {
160*4882a593Smuzhiyun 	memcpy(idlest_reg, &clk->enable_reg, sizeof(*idlest_reg));
161*4882a593Smuzhiyun 	*idlest_bit = clk->enable_bit + AM35XX_IPSS_ICK_EN_ACK_OFFSET;
162*4882a593Smuzhiyun 	*idlest_val = AM35XX_IPSS_CLK_IDLEST_VAL;
163*4882a593Smuzhiyun }
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun /**
166*4882a593Smuzhiyun  * am35xx_clk_find_companion - find companion clock to @clk
167*4882a593Smuzhiyun  * @clk: struct clk * to find the companion clock of
168*4882a593Smuzhiyun  * @other_reg: void __iomem ** to return the companion clock CM_*CLKEN va in
169*4882a593Smuzhiyun  * @other_bit: u8 ** to return the companion clock bit shift in
170*4882a593Smuzhiyun  *
171*4882a593Smuzhiyun  * Some clocks don't have companion clocks.  For example, modules with
172*4882a593Smuzhiyun  * only an interface clock (such as HECC) don't have a companion
173*4882a593Smuzhiyun  * clock.  Right now, this code relies on the hardware exporting a bit
174*4882a593Smuzhiyun  * in the correct companion register that indicates that the
175*4882a593Smuzhiyun  * nonexistent 'companion clock' is active.  Future patches will
176*4882a593Smuzhiyun  * associate this type of code with per-module data structures to
177*4882a593Smuzhiyun  * avoid this issue, and remove the casts.  No return value.
178*4882a593Smuzhiyun  */
am35xx_clk_find_companion(struct clk_hw_omap * clk,struct clk_omap_reg * other_reg,u8 * other_bit)179*4882a593Smuzhiyun static void am35xx_clk_find_companion(struct clk_hw_omap *clk,
180*4882a593Smuzhiyun 				      struct clk_omap_reg *other_reg,
181*4882a593Smuzhiyun 				      u8 *other_bit)
182*4882a593Smuzhiyun {
183*4882a593Smuzhiyun 	memcpy(other_reg, &clk->enable_reg, sizeof(*other_reg));
184*4882a593Smuzhiyun 	if (clk->enable_bit & AM35XX_IPSS_ICK_MASK)
185*4882a593Smuzhiyun 		*other_bit = clk->enable_bit + AM35XX_IPSS_ICK_FCK_OFFSET;
186*4882a593Smuzhiyun 	else
187*4882a593Smuzhiyun 	*other_bit = clk->enable_bit - AM35XX_IPSS_ICK_FCK_OFFSET;
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait = {
191*4882a593Smuzhiyun 	.find_idlest	= am35xx_clk_find_idlest,
192*4882a593Smuzhiyun 	.find_companion	= am35xx_clk_find_companion,
193*4882a593Smuzhiyun };
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun /**
196*4882a593Smuzhiyun  * am35xx_clk_ipss_find_idlest - return CM_IDLEST info for IPSS
197*4882a593Smuzhiyun  * @clk: struct clk * being enabled
198*4882a593Smuzhiyun  * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
199*4882a593Smuzhiyun  * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
200*4882a593Smuzhiyun  * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
201*4882a593Smuzhiyun  *
202*4882a593Smuzhiyun  * The IPSS target CM_IDLEST bit is at a different shift from the
203*4882a593Smuzhiyun  * CM_{I,F}CLKEN bit.  Pass back the correct info via @idlest_reg
204*4882a593Smuzhiyun  * and @idlest_bit.  No return value.
205*4882a593Smuzhiyun  */
am35xx_clk_ipss_find_idlest(struct clk_hw_omap * clk,struct clk_omap_reg * idlest_reg,u8 * idlest_bit,u8 * idlest_val)206*4882a593Smuzhiyun static void am35xx_clk_ipss_find_idlest(struct clk_hw_omap *clk,
207*4882a593Smuzhiyun 					struct clk_omap_reg *idlest_reg,
208*4882a593Smuzhiyun 					u8 *idlest_bit,
209*4882a593Smuzhiyun 					u8 *idlest_val)
210*4882a593Smuzhiyun {
211*4882a593Smuzhiyun 	memcpy(idlest_reg, &clk->enable_reg, sizeof(*idlest_reg));
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun 	idlest_reg->offset &= ~0xf0;
214*4882a593Smuzhiyun 	idlest_reg->offset |= 0x20;
215*4882a593Smuzhiyun 	*idlest_bit = AM35XX_ST_IPSS_SHIFT;
216*4882a593Smuzhiyun 	*idlest_val = OMAP34XX_CM_IDLEST_VAL;
217*4882a593Smuzhiyun }
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun const struct clk_hw_omap_ops clkhwops_am35xx_ipss_wait = {
220*4882a593Smuzhiyun 	.allow_idle	= omap2_clkt_iclk_allow_idle,
221*4882a593Smuzhiyun 	.deny_idle	= omap2_clkt_iclk_deny_idle,
222*4882a593Smuzhiyun 	.find_idlest	= am35xx_clk_ipss_find_idlest,
223*4882a593Smuzhiyun 	.find_companion	= omap2_clk_dflt_find_companion,
224*4882a593Smuzhiyun };
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun static struct ti_dt_clk omap3xxx_clks[] = {
227*4882a593Smuzhiyun 	DT_CLK(NULL, "timer_32k_ck", "omap_32k_fck"),
228*4882a593Smuzhiyun 	DT_CLK(NULL, "timer_sys_ck", "sys_ck"),
229*4882a593Smuzhiyun 	{ .node_name = NULL },
230*4882a593Smuzhiyun };
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun static struct ti_dt_clk omap36xx_omap3430es2plus_clks[] = {
233*4882a593Smuzhiyun 	DT_CLK(NULL, "ssi_ssr_fck", "ssi_ssr_fck_3430es2"),
234*4882a593Smuzhiyun 	DT_CLK(NULL, "ssi_sst_fck", "ssi_sst_fck_3430es2"),
235*4882a593Smuzhiyun 	DT_CLK(NULL, "hsotgusb_ick", "hsotgusb_ick_3430es2"),
236*4882a593Smuzhiyun 	DT_CLK(NULL, "ssi_ick", "ssi_ick_3430es2"),
237*4882a593Smuzhiyun 	{ .node_name = NULL },
238*4882a593Smuzhiyun };
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun static struct ti_dt_clk omap3430es1_clks[] = {
241*4882a593Smuzhiyun 	DT_CLK(NULL, "ssi_ssr_fck", "ssi_ssr_fck_3430es1"),
242*4882a593Smuzhiyun 	DT_CLK(NULL, "ssi_sst_fck", "ssi_sst_fck_3430es1"),
243*4882a593Smuzhiyun 	DT_CLK(NULL, "hsotgusb_ick", "hsotgusb_ick_3430es1"),
244*4882a593Smuzhiyun 	DT_CLK(NULL, "ssi_ick", "ssi_ick_3430es1"),
245*4882a593Smuzhiyun 	DT_CLK(NULL, "dss1_alwon_fck", "dss1_alwon_fck_3430es1"),
246*4882a593Smuzhiyun 	DT_CLK(NULL, "dss_ick", "dss_ick_3430es1"),
247*4882a593Smuzhiyun 	{ .node_name = NULL },
248*4882a593Smuzhiyun };
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun static struct ti_dt_clk omap36xx_am35xx_omap3430es2plus_clks[] = {
251*4882a593Smuzhiyun 	DT_CLK(NULL, "dss1_alwon_fck", "dss1_alwon_fck_3430es2"),
252*4882a593Smuzhiyun 	DT_CLK(NULL, "dss_ick", "dss_ick_3430es2"),
253*4882a593Smuzhiyun 	{ .node_name = NULL },
254*4882a593Smuzhiyun };
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun static struct ti_dt_clk am35xx_clks[] = {
257*4882a593Smuzhiyun 	DT_CLK(NULL, "hsotgusb_ick", "hsotgusb_ick_am35xx"),
258*4882a593Smuzhiyun 	DT_CLK(NULL, "hsotgusb_fck", "hsotgusb_fck_am35xx"),
259*4882a593Smuzhiyun 	DT_CLK(NULL, "uart4_ick", "uart4_ick_am35xx"),
260*4882a593Smuzhiyun 	DT_CLK(NULL, "uart4_fck", "uart4_fck_am35xx"),
261*4882a593Smuzhiyun 	{ .node_name = NULL },
262*4882a593Smuzhiyun };
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun static const char *enable_init_clks[] = {
265*4882a593Smuzhiyun 	"sdrc_ick",
266*4882a593Smuzhiyun 	"gpmc_fck",
267*4882a593Smuzhiyun 	"omapctrl_ick",
268*4882a593Smuzhiyun };
269*4882a593Smuzhiyun 
270*4882a593Smuzhiyun enum {
271*4882a593Smuzhiyun 	OMAP3_SOC_AM35XX,
272*4882a593Smuzhiyun 	OMAP3_SOC_OMAP3430_ES1,
273*4882a593Smuzhiyun 	OMAP3_SOC_OMAP3430_ES2_PLUS,
274*4882a593Smuzhiyun 	OMAP3_SOC_OMAP3630,
275*4882a593Smuzhiyun };
276*4882a593Smuzhiyun 
277*4882a593Smuzhiyun /**
278*4882a593Smuzhiyun  * omap3_clk_lock_dpll5 - locks DPLL5
279*4882a593Smuzhiyun  *
280*4882a593Smuzhiyun  * Locks DPLL5 to a pre-defined frequency. This is required for proper
281*4882a593Smuzhiyun  * operation of USB.
282*4882a593Smuzhiyun  */
omap3_clk_lock_dpll5(void)283*4882a593Smuzhiyun void __init omap3_clk_lock_dpll5(void)
284*4882a593Smuzhiyun {
285*4882a593Smuzhiyun 	struct clk *dpll5_clk;
286*4882a593Smuzhiyun 	struct clk *dpll5_m2_clk;
287*4882a593Smuzhiyun 
288*4882a593Smuzhiyun 	/*
289*4882a593Smuzhiyun 	 * Errata sprz319f advisory 2.1 documents a USB host clock drift issue
290*4882a593Smuzhiyun 	 * that can be worked around using specially crafted dpll5 settings
291*4882a593Smuzhiyun 	 * with a dpll5_m2 divider set to 8. Set the dpll5 rate to 8x the USB
292*4882a593Smuzhiyun 	 * host clock rate, its .set_rate handler() will detect that frequency
293*4882a593Smuzhiyun 	 * and use the errata settings.
294*4882a593Smuzhiyun 	 */
295*4882a593Smuzhiyun 	dpll5_clk = clk_get(NULL, "dpll5_ck");
296*4882a593Smuzhiyun 	clk_set_rate(dpll5_clk, OMAP3_DPLL5_FREQ_FOR_USBHOST * 8);
297*4882a593Smuzhiyun 	clk_prepare_enable(dpll5_clk);
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun 	/* Program dpll5_m2_clk divider */
300*4882a593Smuzhiyun 	dpll5_m2_clk = clk_get(NULL, "dpll5_m2_ck");
301*4882a593Smuzhiyun 	clk_prepare_enable(dpll5_m2_clk);
302*4882a593Smuzhiyun 	clk_set_rate(dpll5_m2_clk, OMAP3_DPLL5_FREQ_FOR_USBHOST);
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun 	clk_disable_unprepare(dpll5_m2_clk);
305*4882a593Smuzhiyun 	clk_disable_unprepare(dpll5_clk);
306*4882a593Smuzhiyun }
307*4882a593Smuzhiyun 
omap3xxx_dt_clk_init(int soc_type)308*4882a593Smuzhiyun static int __init omap3xxx_dt_clk_init(int soc_type)
309*4882a593Smuzhiyun {
310*4882a593Smuzhiyun 	if (soc_type == OMAP3_SOC_AM35XX || soc_type == OMAP3_SOC_OMAP3630 ||
311*4882a593Smuzhiyun 	    soc_type == OMAP3_SOC_OMAP3430_ES1 ||
312*4882a593Smuzhiyun 	    soc_type == OMAP3_SOC_OMAP3430_ES2_PLUS)
313*4882a593Smuzhiyun 		ti_dt_clocks_register(omap3xxx_clks);
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun 	if (soc_type == OMAP3_SOC_AM35XX)
316*4882a593Smuzhiyun 		ti_dt_clocks_register(am35xx_clks);
317*4882a593Smuzhiyun 
318*4882a593Smuzhiyun 	if (soc_type == OMAP3_SOC_OMAP3630 || soc_type == OMAP3_SOC_AM35XX ||
319*4882a593Smuzhiyun 	    soc_type == OMAP3_SOC_OMAP3430_ES2_PLUS)
320*4882a593Smuzhiyun 		ti_dt_clocks_register(omap36xx_am35xx_omap3430es2plus_clks);
321*4882a593Smuzhiyun 
322*4882a593Smuzhiyun 	if (soc_type == OMAP3_SOC_OMAP3430_ES1)
323*4882a593Smuzhiyun 		ti_dt_clocks_register(omap3430es1_clks);
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun 	if (soc_type == OMAP3_SOC_OMAP3430_ES2_PLUS ||
326*4882a593Smuzhiyun 	    soc_type == OMAP3_SOC_OMAP3630)
327*4882a593Smuzhiyun 		ti_dt_clocks_register(omap36xx_omap3430es2plus_clks);
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun 	omap2_clk_disable_autoidle_all();
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun 	ti_clk_add_aliases();
332*4882a593Smuzhiyun 
333*4882a593Smuzhiyun 	omap2_clk_enable_init_clocks(enable_init_clks,
334*4882a593Smuzhiyun 				     ARRAY_SIZE(enable_init_clks));
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun 	pr_info("Clocking rate (Crystal/Core/MPU): %ld.%01ld/%ld/%ld MHz\n",
337*4882a593Smuzhiyun 		(clk_get_rate(clk_get_sys(NULL, "osc_sys_ck")) / 1000000),
338*4882a593Smuzhiyun 		(clk_get_rate(clk_get_sys(NULL, "osc_sys_ck")) / 100000) % 10,
339*4882a593Smuzhiyun 		(clk_get_rate(clk_get_sys(NULL, "core_ck")) / 1000000),
340*4882a593Smuzhiyun 		(clk_get_rate(clk_get_sys(NULL, "arm_fck")) / 1000000));
341*4882a593Smuzhiyun 
342*4882a593Smuzhiyun 	if (soc_type != OMAP3_SOC_OMAP3430_ES1)
343*4882a593Smuzhiyun 		omap3_clk_lock_dpll5();
344*4882a593Smuzhiyun 
345*4882a593Smuzhiyun 	return 0;
346*4882a593Smuzhiyun }
347*4882a593Smuzhiyun 
omap3430_dt_clk_init(void)348*4882a593Smuzhiyun int __init omap3430_dt_clk_init(void)
349*4882a593Smuzhiyun {
350*4882a593Smuzhiyun 	return omap3xxx_dt_clk_init(OMAP3_SOC_OMAP3430_ES2_PLUS);
351*4882a593Smuzhiyun }
352*4882a593Smuzhiyun 
omap3630_dt_clk_init(void)353*4882a593Smuzhiyun int __init omap3630_dt_clk_init(void)
354*4882a593Smuzhiyun {
355*4882a593Smuzhiyun 	return omap3xxx_dt_clk_init(OMAP3_SOC_OMAP3630);
356*4882a593Smuzhiyun }
357*4882a593Smuzhiyun 
am35xx_dt_clk_init(void)358*4882a593Smuzhiyun int __init am35xx_dt_clk_init(void)
359*4882a593Smuzhiyun {
360*4882a593Smuzhiyun 	return omap3xxx_dt_clk_init(OMAP3_SOC_AM35XX);
361*4882a593Smuzhiyun }
362