blob: d38ad44fe0aab72c4e4336ca2a8fc4a87bc975ec [file] [log] [blame]
Paul Walmsley02e19a92008-03-18 15:09:51 +02001/*
2 * OMAP3-specific clock framework functions
3 *
Paul Walmsley542313c2008-07-03 12:24:45 +03004 * Copyright (C) 2007-2008 Texas Instruments, Inc.
Paul Walmsley3c82e222009-07-24 19:44:06 -06005 * Copyright (C) 2007-2009 Nokia Corporation
Paul Walmsley02e19a92008-03-18 15:09:51 +02006 *
7 * Written by Paul Walmsley
Paul Walmsley542313c2008-07-03 12:24:45 +03008 * Testing and integration fixes by Jouni Högander
Paul Walmsley02e19a92008-03-18 15:09:51 +02009 *
10 * Parts of this code are based on code written by
11 * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 */
17#undef DEBUG
18
19#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/device.h>
22#include <linux/list.h>
23#include <linux/errno.h>
24#include <linux/delay.h>
25#include <linux/clk.h>
26#include <linux/io.h>
Paul Walmsley542313c2008-07-03 12:24:45 +030027#include <linux/limits.h>
Russell Kingfbd3bdb2008-09-06 12:13:59 +010028#include <linux/bitops.h>
Paul Walmsley02e19a92008-03-18 15:09:51 +020029
Tony Lindgrence491cf2009-10-20 09:40:47 -070030#include <plat/cpu.h>
31#include <plat/clock.h>
32#include <plat/sram.h>
Paul Walmsley82e9bd52009-12-08 16:18:47 -070033#include <plat/sdrc.h>
Paul Walmsley02e19a92008-03-18 15:09:51 +020034#include <asm/div64.h>
Russell King44dc9d02009-01-19 15:51:11 +000035#include <asm/clkdev.h>
Paul Walmsley02e19a92008-03-18 15:09:51 +020036
Paul Walmsley02e19a92008-03-18 15:09:51 +020037#include "clock.h"
Paul Walmsley82e9bd52009-12-08 16:18:47 -070038#include "clock34xx.h"
39#include "sdrc.h"
Paul Walmsley02e19a92008-03-18 15:09:51 +020040#include "prm.h"
41#include "prm-regbits-34xx.h"
42#include "cm.h"
43#include "cm-regbits-34xx.h"
44
Rajendra Nayak7a66a392009-10-05 13:31:44 -070045/*
46 * DPLL5_FREQ_FOR_USBHOST: USBHOST and USBTLL are the only clocks
47 * that are sourced by DPLL5, and both of these require this clock
48 * to be at 120 MHz for proper operation.
49 */
50#define DPLL5_FREQ_FOR_USBHOST 120000000
51
Paul Walmsley82e9bd52009-12-08 16:18:47 -070052/* needed by omap3_core_dpll_m2_set_rate() */
53struct clk *sdrc_ick_p, *arm_fck_p;
54
Paul Walmsley02e19a92008-03-18 15:09:51 +020055/**
Paul Walmsley3c82e222009-07-24 19:44:06 -060056 * omap3430es2_clk_ssi_find_idlest - return CM_IDLEST info for SSI
57 * @clk: struct clk * being enabled
58 * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
59 * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
60 *
61 * The OMAP3430ES2 SSI target CM_IDLEST bit is at a different shift
62 * from the CM_{I,F}CLKEN bit. Pass back the correct info via
63 * @idlest_reg and @idlest_bit. No return value.
64 */
65static void omap3430es2_clk_ssi_find_idlest(struct clk *clk,
66 void __iomem **idlest_reg,
67 u8 *idlest_bit)
68{
69 u32 r;
70
71 r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
72 *idlest_reg = (__force void __iomem *)r;
73 *idlest_bit = OMAP3430ES2_ST_SSI_IDLE_SHIFT;
74}
75
Paul Walmsley82e9bd52009-12-08 16:18:47 -070076const struct clkops clkops_omap3430es2_ssi_wait = {
77 .enable = omap2_dflt_clk_enable,
78 .disable = omap2_dflt_clk_disable,
79 .find_idlest = omap3430es2_clk_ssi_find_idlest,
80 .find_companion = omap2_clk_dflt_find_companion,
81};
82
Paul Walmsley3c82e222009-07-24 19:44:06 -060083/**
84 * omap3430es2_clk_dss_usbhost_find_idlest - CM_IDLEST info for DSS, USBHOST
85 * @clk: struct clk * being enabled
86 * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
87 * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
88 *
89 * Some OMAP modules on OMAP3 ES2+ chips have both initiator and
90 * target IDLEST bits. For our purposes, we are concerned with the
91 * target IDLEST bits, which exist at a different bit position than
92 * the *CLKEN bit position for these modules (DSS and USBHOST) (The
93 * default find_idlest code assumes that they are at the same
94 * position.) No return value.
95 */
96static void omap3430es2_clk_dss_usbhost_find_idlest(struct clk *clk,
97 void __iomem **idlest_reg,
98 u8 *idlest_bit)
99{
100 u32 r;
101
102 r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
103 *idlest_reg = (__force void __iomem *)r;
104 /* USBHOST_IDLE has same shift */
105 *idlest_bit = OMAP3430ES2_ST_DSS_IDLE_SHIFT;
106}
107
Paul Walmsley82e9bd52009-12-08 16:18:47 -0700108const struct clkops clkops_omap3430es2_dss_usbhost_wait = {
109 .enable = omap2_dflt_clk_enable,
110 .disable = omap2_dflt_clk_disable,
111 .find_idlest = omap3430es2_clk_dss_usbhost_find_idlest,
112 .find_companion = omap2_clk_dflt_find_companion,
113};
114
Paul Walmsley3c82e222009-07-24 19:44:06 -0600115/**
116 * omap3430es2_clk_hsotgusb_find_idlest - return CM_IDLEST info for HSOTGUSB
117 * @clk: struct clk * being enabled
118 * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
119 * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
120 *
121 * The OMAP3430ES2 HSOTGUSB target CM_IDLEST bit is at a different
122 * shift from the CM_{I,F}CLKEN bit. Pass back the correct info via
123 * @idlest_reg and @idlest_bit. No return value.
124 */
125static void omap3430es2_clk_hsotgusb_find_idlest(struct clk *clk,
126 void __iomem **idlest_reg,
127 u8 *idlest_bit)
128{
129 u32 r;
130
131 r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
132 *idlest_reg = (__force void __iomem *)r;
133 *idlest_bit = OMAP3430ES2_ST_HSOTGUSB_IDLE_SHIFT;
134}
135
Paul Walmsley82e9bd52009-12-08 16:18:47 -0700136const struct clkops clkops_omap3430es2_hsotgusb_wait = {
137 .enable = omap2_dflt_clk_enable,
138 .disable = omap2_dflt_clk_disable,
139 .find_idlest = omap3430es2_clk_hsotgusb_find_idlest,
140 .find_companion = omap2_clk_dflt_find_companion,
141};
142
Paul Walmsley82e9bd52009-12-08 16:18:47 -0700143const struct clkops clkops_noncore_dpll_ops = {
144 .enable = omap3_noncore_dpll_enable,
145 .disable = omap3_noncore_dpll_disable,
146};
Paul Walmsley16c90f02009-01-27 19:12:47 -0700147
Paul Walmsley82e9bd52009-12-08 16:18:47 -0700148int omap3_dpll4_set_rate(struct clk *clk, unsigned long rate)
Paul Walmsley16c90f02009-01-27 19:12:47 -0700149{
150 /*
151 * According to the 12-5 CDP code from TI, "Limitation 2.5"
152 * on 3430ES1 prevents us from changing DPLL multipliers or dividers
153 * on DPLL4.
154 */
155 if (omap_rev() == OMAP3430_REV_ES1_0) {
156 printk(KERN_ERR "clock: DPLL4 cannot change rate due to "
157 "silicon 'Limitation 2.5' on 3430ES1.\n");
158 return -EINVAL;
159 }
160 return omap3_noncore_dpll_set_rate(clk, rate);
161}
162
Paul Walmsley542313c2008-07-03 12:24:45 +0300163/* Common clock code */
164
Paul Walmsley02e19a92008-03-18 15:09:51 +0200165/*
Paul Walmsley02e19a92008-03-18 15:09:51 +0200166 * Set clocks for bypass mode for reboot to work.
167 */
168void omap2_clk_prepare_for_reboot(void)
169{
170 /* REVISIT: Not ready for 343x */
171#if 0
172 u32 rate;
173
174 if (vclk == NULL || sclk == NULL)
175 return;
176
177 rate = clk_get_rate(sclk);
178 clk_set_rate(vclk, rate);
179#endif
180}
181
Paul Walmsley82e9bd52009-12-08 16:18:47 -0700182void omap3_clk_lock_dpll5(void)
Rajendra Nayak7a66a392009-10-05 13:31:44 -0700183{
184 struct clk *dpll5_clk;
185 struct clk *dpll5_m2_clk;
186
187 dpll5_clk = clk_get(NULL, "dpll5_ck");
188 clk_set_rate(dpll5_clk, DPLL5_FREQ_FOR_USBHOST);
189 clk_enable(dpll5_clk);
190
191 /* Enable autoidle to allow it to enter low power bypass */
192 omap3_dpll_allow_idle(dpll5_clk);
193
194 /* Program dpll5_m2_clk divider for no division */
195 dpll5_m2_clk = clk_get(NULL, "dpll5_m2_ck");
196 clk_enable(dpll5_m2_clk);
197 clk_set_rate(dpll5_m2_clk, DPLL5_FREQ_FOR_USBHOST);
198
199 clk_disable(dpll5_m2_clk);
200 clk_disable(dpll5_clk);
201 return;
202}
203
Paul Walmsley02e19a92008-03-18 15:09:51 +0200204/* REVISIT: Move this init stuff out into clock.c */
205
206/*
207 * Switch the MPU rate if specified on cmdline.
208 * We cannot do this early until cmdline is parsed.
209 */
Paul Walmsley4680c292010-01-26 20:13:09 -0700210static int __init omap3xxx_clk_arch_init(void)
Paul Walmsley02e19a92008-03-18 15:09:51 +0200211{
Paul Walmsley82e9bd52009-12-08 16:18:47 -0700212 struct clk *osc_sys_ck, *dpll1_ck, *arm_fck, *core_ck;
213 unsigned long osc_sys_rate;
214
Paul Walmsley4680c292010-01-26 20:13:09 -0700215 if (!cpu_is_omap34xx())
216 return 0;
217
Paul Walmsley02e19a92008-03-18 15:09:51 +0200218 if (!mpurate)
219 return -EINVAL;
220
Paul Walmsley82e9bd52009-12-08 16:18:47 -0700221 /* XXX test these for success */
222 dpll1_ck = clk_get(NULL, "dpll1_ck");
223 arm_fck = clk_get(NULL, "arm_fck");
224 core_ck = clk_get(NULL, "core_ck");
225 osc_sys_ck = clk_get(NULL, "osc_sys_ck");
226
Paul Walmsley02e19a92008-03-18 15:09:51 +0200227 /* REVISIT: not yet ready for 343x */
Paul Walmsley82e9bd52009-12-08 16:18:47 -0700228 if (clk_set_rate(dpll1_ck, mpurate))
Sanjeev Premi11b66382009-09-03 20:13:58 +0300229 printk(KERN_ERR "*** Unable to set MPU rate\n");
Paul Walmsley02e19a92008-03-18 15:09:51 +0200230
231 recalculate_root_clocks();
232
Paul Walmsley82e9bd52009-12-08 16:18:47 -0700233 osc_sys_rate = clk_get_rate(osc_sys_ck);
234
235 pr_info("Switched to new clocking rate (Crystal/Core/MPU): "
236 "%ld.%01ld/%ld/%ld MHz\n",
237 (osc_sys_rate / 1000000),
238 ((osc_sys_rate / 100000) % 10),
239 (clk_get_rate(core_ck) / 1000000),
240 (clk_get_rate(arm_fck) / 1000000));
Sanjeev Premi11b66382009-09-03 20:13:58 +0300241
242 calibrate_delay();
Paul Walmsley02e19a92008-03-18 15:09:51 +0200243
244 return 0;
245}
Paul Walmsley4680c292010-01-26 20:13:09 -0700246arch_initcall(omap3xxx_clk_arch_init);
Paul Walmsley82e9bd52009-12-08 16:18:47 -0700247
248