blob: aad77e0d43c7f07585516f526d18c99d56f2cbc2 [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.
5 * Copyright (C) 2007-2008 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
Russell Kinga09e64f2008-08-05 16:14:15 +010030#include <mach/clock.h>
31#include <mach/sram.h>
Paul Walmsley02e19a92008-03-18 15:09:51 +020032#include <asm/div64.h>
Russell King44dc9d02009-01-19 15:51:11 +000033#include <asm/clkdev.h>
Paul Walmsley02e19a92008-03-18 15:09:51 +020034
35#include "memory.h"
36#include "clock.h"
Paul Walmsley02e19a92008-03-18 15:09:51 +020037#include "prm.h"
38#include "prm-regbits-34xx.h"
39#include "cm.h"
40#include "cm-regbits-34xx.h"
41
Russell King548d8492008-11-04 14:02:46 +000042static const struct clkops clkops_noncore_dpll_ops;
43
44#include "clock34xx.h"
45
Russell King44dc9d02009-01-19 15:51:11 +000046struct omap_clk {
47 u32 cpu;
48 struct clk_lookup lk;
49};
50
51#define CLK(dev, con, ck, cp) \
52 { \
53 .cpu = cp, \
54 .lk = { \
55 .dev_id = dev, \
56 .con_id = con, \
57 .clk = ck, \
58 }, \
59 }
60
61#define CK_343X (1 << 0)
62#define CK_3430ES1 (1 << 1)
63#define CK_3430ES2 (1 << 2)
64
65static struct omap_clk omap34xx_clks[] = {
66 CLK(NULL, "omap_32k_fck", &omap_32k_fck, CK_343X),
67 CLK(NULL, "virt_12m_ck", &virt_12m_ck, CK_343X),
68 CLK(NULL, "virt_13m_ck", &virt_13m_ck, CK_343X),
69 CLK(NULL, "virt_16_8m_ck", &virt_16_8m_ck, CK_3430ES2),
70 CLK(NULL, "virt_19_2m_ck", &virt_19_2m_ck, CK_343X),
71 CLK(NULL, "virt_26m_ck", &virt_26m_ck, CK_343X),
72 CLK(NULL, "virt_38_4m_ck", &virt_38_4m_ck, CK_343X),
73 CLK(NULL, "osc_sys_ck", &osc_sys_ck, CK_343X),
74 CLK(NULL, "sys_ck", &sys_ck, CK_343X),
75 CLK(NULL, "sys_altclk", &sys_altclk, CK_343X),
76 CLK(NULL, "mcbsp_clks", &mcbsp_clks, CK_343X),
77 CLK(NULL, "sys_clkout1", &sys_clkout1, CK_343X),
78 CLK(NULL, "dpll1_ck", &dpll1_ck, CK_343X),
79 CLK(NULL, "dpll1_x2_ck", &dpll1_x2_ck, CK_343X),
80 CLK(NULL, "dpll1_x2m2_ck", &dpll1_x2m2_ck, CK_343X),
81 CLK(NULL, "dpll2_ck", &dpll2_ck, CK_343X),
82 CLK(NULL, "dpll2_m2_ck", &dpll2_m2_ck, CK_343X),
83 CLK(NULL, "dpll3_ck", &dpll3_ck, CK_343X),
84 CLK(NULL, "core_ck", &core_ck, CK_343X),
85 CLK(NULL, "dpll3_x2_ck", &dpll3_x2_ck, CK_343X),
86 CLK(NULL, "dpll3_m2_ck", &dpll3_m2_ck, CK_343X),
87 CLK(NULL, "dpll3_m2x2_ck", &dpll3_m2x2_ck, CK_343X),
88 CLK(NULL, "dpll3_m3_ck", &dpll3_m3_ck, CK_343X),
89 CLK(NULL, "dpll3_m3x2_ck", &dpll3_m3x2_ck, CK_343X),
90 CLK(NULL, "emu_core_alwon_ck", &emu_core_alwon_ck, CK_343X),
91 CLK(NULL, "dpll4_ck", &dpll4_ck, CK_343X),
92 CLK(NULL, "dpll4_x2_ck", &dpll4_x2_ck, CK_343X),
93 CLK(NULL, "omap_96m_alwon_fck", &omap_96m_alwon_fck, CK_343X),
94 CLK(NULL, "omap_96m_fck", &omap_96m_fck, CK_343X),
95 CLK(NULL, "cm_96m_fck", &cm_96m_fck, CK_343X),
96 CLK(NULL, "virt_omap_54m_fck", &virt_omap_54m_fck, CK_343X),
97 CLK(NULL, "omap_54m_fck", &omap_54m_fck, CK_343X),
98 CLK(NULL, "omap_48m_fck", &omap_48m_fck, CK_343X),
99 CLK(NULL, "omap_12m_fck", &omap_12m_fck, CK_343X),
100 CLK(NULL, "dpll4_m2_ck", &dpll4_m2_ck, CK_343X),
101 CLK(NULL, "dpll4_m2x2_ck", &dpll4_m2x2_ck, CK_343X),
102 CLK(NULL, "dpll4_m3_ck", &dpll4_m3_ck, CK_343X),
103 CLK(NULL, "dpll4_m3x2_ck", &dpll4_m3x2_ck, CK_343X),
104 CLK(NULL, "dpll4_m4_ck", &dpll4_m4_ck, CK_343X),
105 CLK(NULL, "dpll4_m4x2_ck", &dpll4_m4x2_ck, CK_343X),
106 CLK(NULL, "dpll4_m5_ck", &dpll4_m5_ck, CK_343X),
107 CLK(NULL, "dpll4_m5x2_ck", &dpll4_m5x2_ck, CK_343X),
108 CLK(NULL, "dpll4_m6_ck", &dpll4_m6_ck, CK_343X),
109 CLK(NULL, "dpll4_m6x2_ck", &dpll4_m6x2_ck, CK_343X),
110 CLK(NULL, "emu_per_alwon_ck", &emu_per_alwon_ck, CK_343X),
111 CLK(NULL, "dpll5_ck", &dpll5_ck, CK_3430ES2),
112 CLK(NULL, "dpll5_m2_ck", &dpll5_m2_ck, CK_3430ES2),
113 CLK(NULL, "omap_120m_fck", &omap_120m_fck, CK_3430ES2),
114 CLK(NULL, "clkout2_src_ck", &clkout2_src_ck, CK_343X),
115 CLK(NULL, "sys_clkout2", &sys_clkout2, CK_343X),
116 CLK(NULL, "corex2_fck", &corex2_fck, CK_343X),
117 CLK(NULL, "dpll1_fck", &dpll1_fck, CK_343X),
118 CLK(NULL, "mpu_ck", &mpu_ck, CK_343X),
119 CLK(NULL, "arm_fck", &arm_fck, CK_343X),
120 CLK(NULL, "emu_mpu_alwon_ck", &emu_mpu_alwon_ck, CK_343X),
121 CLK(NULL, "dpll2_fck", &dpll2_fck, CK_343X),
122 CLK(NULL, "iva2_ck", &iva2_ck, CK_343X),
123 CLK(NULL, "l3_ick", &l3_ick, CK_343X),
124 CLK(NULL, "l4_ick", &l4_ick, CK_343X),
125 CLK(NULL, "rm_ick", &rm_ick, CK_343X),
126 CLK(NULL, "gfx_l3_ck", &gfx_l3_ck, CK_3430ES1),
127 CLK(NULL, "gfx_l3_fck", &gfx_l3_fck, CK_3430ES1),
128 CLK(NULL, "gfx_l3_ick", &gfx_l3_ick, CK_3430ES1),
129 CLK(NULL, "gfx_cg1_ck", &gfx_cg1_ck, CK_3430ES1),
130 CLK(NULL, "gfx_cg2_ck", &gfx_cg2_ck, CK_3430ES1),
131 CLK(NULL, "sgx_fck", &sgx_fck, CK_3430ES2),
132 CLK(NULL, "sgx_ick", &sgx_ick, CK_3430ES2),
133 CLK(NULL, "d2d_26m_fck", &d2d_26m_fck, CK_3430ES1),
134 CLK(NULL, "gpt10_fck", &gpt10_fck, CK_343X),
135 CLK(NULL, "gpt11_fck", &gpt11_fck, CK_343X),
136 CLK(NULL, "cpefuse_fck", &cpefuse_fck, CK_3430ES2),
137 CLK(NULL, "ts_fck", &ts_fck, CK_3430ES2),
138 CLK(NULL, "usbtll_fck", &usbtll_fck, CK_3430ES2),
139 CLK(NULL, "core_96m_fck", &core_96m_fck, CK_343X),
Russell King6f7607c2009-01-28 10:22:50 +0000140 CLK("mmci-omap-hs.2", "fck", &mmchs3_fck, CK_3430ES2),
141 CLK("mmci-omap-hs.1", "fck", &mmchs2_fck, CK_343X),
Russell King44dc9d02009-01-19 15:51:11 +0000142 CLK(NULL, "mspro_fck", &mspro_fck, CK_343X),
Russell King6f7607c2009-01-28 10:22:50 +0000143 CLK("mmci-omap-hs.0", "fck", &mmchs1_fck, CK_343X),
Russell King1d14de02009-01-19 21:02:29 +0000144 CLK("i2c_omap.3", "fck", &i2c3_fck, CK_343X),
145 CLK("i2c_omap.2", "fck", &i2c2_fck, CK_343X),
146 CLK("i2c_omap.1", "fck", &i2c1_fck, CK_343X),
Russell Kingb820ce42009-01-23 10:26:46 +0000147 CLK("omap-mcbsp.5", "fck", &mcbsp5_fck, CK_343X),
148 CLK("omap-mcbsp.1", "fck", &mcbsp1_fck, CK_343X),
Russell King44dc9d02009-01-19 15:51:11 +0000149 CLK(NULL, "core_48m_fck", &core_48m_fck, CK_343X),
Russell King1b5715e2009-01-19 20:49:37 +0000150 CLK("omap2_mcspi.4", "fck", &mcspi4_fck, CK_343X),
151 CLK("omap2_mcspi.3", "fck", &mcspi3_fck, CK_343X),
152 CLK("omap2_mcspi.2", "fck", &mcspi2_fck, CK_343X),
153 CLK("omap2_mcspi.1", "fck", &mcspi1_fck, CK_343X),
Russell King44dc9d02009-01-19 15:51:11 +0000154 CLK(NULL, "uart2_fck", &uart2_fck, CK_343X),
155 CLK(NULL, "uart1_fck", &uart1_fck, CK_343X),
156 CLK(NULL, "fshostusb_fck", &fshostusb_fck, CK_3430ES1),
157 CLK(NULL, "core_12m_fck", &core_12m_fck, CK_343X),
Russell Kingcc51c9d2009-01-22 10:12:04 +0000158 CLK("omap_hdq.0", "fck", &hdq_fck, CK_343X),
Russell King44dc9d02009-01-19 15:51:11 +0000159 CLK(NULL, "ssi_ssr_fck", &ssi_ssr_fck, CK_343X),
160 CLK(NULL, "ssi_sst_fck", &ssi_sst_fck, CK_343X),
161 CLK(NULL, "core_l3_ick", &core_l3_ick, CK_343X),
162 CLK(NULL, "hsotgusb_ick", &hsotgusb_ick, CK_343X),
163 CLK(NULL, "sdrc_ick", &sdrc_ick, CK_343X),
164 CLK(NULL, "gpmc_fck", &gpmc_fck, CK_343X),
165 CLK(NULL, "security_l3_ick", &security_l3_ick, CK_343X),
166 CLK(NULL, "pka_ick", &pka_ick, CK_343X),
167 CLK(NULL, "core_l4_ick", &core_l4_ick, CK_343X),
168 CLK(NULL, "usbtll_ick", &usbtll_ick, CK_3430ES2),
Russell King6f7607c2009-01-28 10:22:50 +0000169 CLK("mmci-omap-hs.2", "ick", &mmchs3_ick, CK_3430ES2),
Russell King44dc9d02009-01-19 15:51:11 +0000170 CLK(NULL, "icr_ick", &icr_ick, CK_343X),
171 CLK(NULL, "aes2_ick", &aes2_ick, CK_343X),
172 CLK(NULL, "sha12_ick", &sha12_ick, CK_343X),
173 CLK(NULL, "des2_ick", &des2_ick, CK_343X),
Russell King6f7607c2009-01-28 10:22:50 +0000174 CLK("mmci-omap-hs.1", "ick", &mmchs2_ick, CK_343X),
175 CLK("mmci-omap-hs.0", "ick", &mmchs1_ick, CK_343X),
Russell King44dc9d02009-01-19 15:51:11 +0000176 CLK(NULL, "mspro_ick", &mspro_ick, CK_343X),
Russell Kingcc51c9d2009-01-22 10:12:04 +0000177 CLK("omap_hdq.0", "ick", &hdq_ick, CK_343X),
Russell King1b5715e2009-01-19 20:49:37 +0000178 CLK("omap2_mcspi.4", "ick", &mcspi4_ick, CK_343X),
179 CLK("omap2_mcspi.3", "ick", &mcspi3_ick, CK_343X),
180 CLK("omap2_mcspi.2", "ick", &mcspi2_ick, CK_343X),
181 CLK("omap2_mcspi.1", "ick", &mcspi1_ick, CK_343X),
Russell King1d14de02009-01-19 21:02:29 +0000182 CLK("i2c_omap.3", "ick", &i2c3_ick, CK_343X),
183 CLK("i2c_omap.2", "ick", &i2c2_ick, CK_343X),
184 CLK("i2c_omap.1", "ick", &i2c1_ick, CK_343X),
Russell King44dc9d02009-01-19 15:51:11 +0000185 CLK(NULL, "uart2_ick", &uart2_ick, CK_343X),
186 CLK(NULL, "uart1_ick", &uart1_ick, CK_343X),
187 CLK(NULL, "gpt11_ick", &gpt11_ick, CK_343X),
188 CLK(NULL, "gpt10_ick", &gpt10_ick, CK_343X),
Russell Kingb820ce42009-01-23 10:26:46 +0000189 CLK("omap-mcbsp.5", "ick", &mcbsp5_ick, CK_343X),
190 CLK("omap-mcbsp.1", "ick", &mcbsp1_ick, CK_343X),
Russell King44dc9d02009-01-19 15:51:11 +0000191 CLK(NULL, "fac_ick", &fac_ick, CK_3430ES1),
192 CLK(NULL, "mailboxes_ick", &mailboxes_ick, CK_343X),
193 CLK(NULL, "omapctrl_ick", &omapctrl_ick, CK_343X),
194 CLK(NULL, "ssi_l4_ick", &ssi_l4_ick, CK_343X),
195 CLK(NULL, "ssi_ick", &ssi_ick, CK_343X),
196 CLK(NULL, "usb_l4_ick", &usb_l4_ick, CK_3430ES1),
197 CLK(NULL, "security_l4_ick2", &security_l4_ick2, CK_343X),
198 CLK(NULL, "aes1_ick", &aes1_ick, CK_343X),
Russell Kingeeec7c82009-01-19 20:58:56 +0000199 CLK("omap_rng", "ick", &rng_ick, CK_343X),
Russell King44dc9d02009-01-19 15:51:11 +0000200 CLK(NULL, "sha11_ick", &sha11_ick, CK_343X),
201 CLK(NULL, "des1_ick", &des1_ick, CK_343X),
202 CLK(NULL, "dss1_alwon_fck", &dss1_alwon_fck, CK_343X),
203 CLK(NULL, "dss_tv_fck", &dss_tv_fck, CK_343X),
204 CLK(NULL, "dss_96m_fck", &dss_96m_fck, CK_343X),
205 CLK(NULL, "dss2_alwon_fck", &dss2_alwon_fck, CK_343X),
206 CLK(NULL, "dss_ick", &dss_ick, CK_343X),
207 CLK(NULL, "cam_mclk", &cam_mclk, CK_343X),
208 CLK(NULL, "cam_ick", &cam_ick, CK_343X),
Sergio Aguirre6c8fe0b2009-01-27 19:13:09 -0700209 CLK(NULL, "csi2_96m_fck", &csi2_96m_fck, CK_343X),
Russell King44dc9d02009-01-19 15:51:11 +0000210 CLK(NULL, "usbhost_120m_fck", &usbhost_120m_fck, CK_3430ES2),
211 CLK(NULL, "usbhost_48m_fck", &usbhost_48m_fck, CK_3430ES2),
212 CLK(NULL, "usbhost_ick", &usbhost_ick, CK_3430ES2),
Russell King44dc9d02009-01-19 15:51:11 +0000213 CLK(NULL, "usim_fck", &usim_fck, CK_3430ES2),
214 CLK(NULL, "gpt1_fck", &gpt1_fck, CK_343X),
215 CLK(NULL, "wkup_32k_fck", &wkup_32k_fck, CK_343X),
216 CLK(NULL, "gpio1_dbck", &gpio1_dbck, CK_343X),
Russell King39a80c72009-01-19 20:44:33 +0000217 CLK("omap_wdt", "fck", &wdt2_fck, CK_343X),
Russell King44dc9d02009-01-19 15:51:11 +0000218 CLK(NULL, "wkup_l4_ick", &wkup_l4_ick, CK_343X),
219 CLK(NULL, "usim_ick", &usim_ick, CK_3430ES2),
Russell King39a80c72009-01-19 20:44:33 +0000220 CLK("omap_wdt", "ick", &wdt2_ick, CK_343X),
Russell King44dc9d02009-01-19 15:51:11 +0000221 CLK(NULL, "wdt1_ick", &wdt1_ick, CK_343X),
222 CLK(NULL, "gpio1_ick", &gpio1_ick, CK_343X),
223 CLK(NULL, "omap_32ksync_ick", &omap_32ksync_ick, CK_343X),
224 CLK(NULL, "gpt12_ick", &gpt12_ick, CK_343X),
225 CLK(NULL, "gpt1_ick", &gpt1_ick, CK_343X),
226 CLK(NULL, "per_96m_fck", &per_96m_fck, CK_343X),
227 CLK(NULL, "per_48m_fck", &per_48m_fck, CK_343X),
228 CLK(NULL, "uart3_fck", &uart3_fck, CK_343X),
229 CLK(NULL, "gpt2_fck", &gpt2_fck, CK_343X),
230 CLK(NULL, "gpt3_fck", &gpt3_fck, CK_343X),
231 CLK(NULL, "gpt4_fck", &gpt4_fck, CK_343X),
232 CLK(NULL, "gpt5_fck", &gpt5_fck, CK_343X),
233 CLK(NULL, "gpt6_fck", &gpt6_fck, CK_343X),
234 CLK(NULL, "gpt7_fck", &gpt7_fck, CK_343X),
235 CLK(NULL, "gpt8_fck", &gpt8_fck, CK_343X),
236 CLK(NULL, "gpt9_fck", &gpt9_fck, CK_343X),
237 CLK(NULL, "per_32k_alwon_fck", &per_32k_alwon_fck, CK_343X),
238 CLK(NULL, "gpio6_dbck", &gpio6_dbck, CK_343X),
239 CLK(NULL, "gpio5_dbck", &gpio5_dbck, CK_343X),
240 CLK(NULL, "gpio4_dbck", &gpio4_dbck, CK_343X),
241 CLK(NULL, "gpio3_dbck", &gpio3_dbck, CK_343X),
242 CLK(NULL, "gpio2_dbck", &gpio2_dbck, CK_343X),
243 CLK(NULL, "wdt3_fck", &wdt3_fck, CK_343X),
244 CLK(NULL, "per_l4_ick", &per_l4_ick, CK_343X),
245 CLK(NULL, "gpio6_ick", &gpio6_ick, CK_343X),
246 CLK(NULL, "gpio5_ick", &gpio5_ick, CK_343X),
247 CLK(NULL, "gpio4_ick", &gpio4_ick, CK_343X),
248 CLK(NULL, "gpio3_ick", &gpio3_ick, CK_343X),
249 CLK(NULL, "gpio2_ick", &gpio2_ick, CK_343X),
250 CLK(NULL, "wdt3_ick", &wdt3_ick, CK_343X),
251 CLK(NULL, "uart3_ick", &uart3_ick, CK_343X),
252 CLK(NULL, "gpt9_ick", &gpt9_ick, CK_343X),
253 CLK(NULL, "gpt8_ick", &gpt8_ick, CK_343X),
254 CLK(NULL, "gpt7_ick", &gpt7_ick, CK_343X),
255 CLK(NULL, "gpt6_ick", &gpt6_ick, CK_343X),
256 CLK(NULL, "gpt5_ick", &gpt5_ick, CK_343X),
257 CLK(NULL, "gpt4_ick", &gpt4_ick, CK_343X),
258 CLK(NULL, "gpt3_ick", &gpt3_ick, CK_343X),
259 CLK(NULL, "gpt2_ick", &gpt2_ick, CK_343X),
Russell Kingb820ce42009-01-23 10:26:46 +0000260 CLK("omap-mcbsp.2", "ick", &mcbsp2_ick, CK_343X),
261 CLK("omap-mcbsp.3", "ick", &mcbsp3_ick, CK_343X),
262 CLK("omap-mcbsp.4", "ick", &mcbsp4_ick, CK_343X),
263 CLK("omap-mcbsp.2", "fck", &mcbsp2_fck, CK_343X),
264 CLK("omap-mcbsp.3", "fck", &mcbsp3_fck, CK_343X),
265 CLK("omap-mcbsp.4", "fck", &mcbsp4_fck, CK_343X),
Russell King44dc9d02009-01-19 15:51:11 +0000266 CLK(NULL, "emu_src_ck", &emu_src_ck, CK_343X),
267 CLK(NULL, "pclk_fck", &pclk_fck, CK_343X),
268 CLK(NULL, "pclkx2_fck", &pclkx2_fck, CK_343X),
269 CLK(NULL, "atclk_fck", &atclk_fck, CK_343X),
270 CLK(NULL, "traceclk_src_fck", &traceclk_src_fck, CK_343X),
271 CLK(NULL, "traceclk_fck", &traceclk_fck, CK_343X),
272 CLK(NULL, "sr1_fck", &sr1_fck, CK_343X),
273 CLK(NULL, "sr2_fck", &sr2_fck, CK_343X),
274 CLK(NULL, "sr_l4_ick", &sr_l4_ick, CK_343X),
275 CLK(NULL, "secure_32k_fck", &secure_32k_fck, CK_343X),
276 CLK(NULL, "gpt12_fck", &gpt12_fck, CK_343X),
277 CLK(NULL, "wdt1_fck", &wdt1_fck, CK_343X),
278};
279
Paul Walmsley542313c2008-07-03 12:24:45 +0300280/* CM_AUTOIDLE_PLL*.AUTO_* bit values */
281#define DPLL_AUTOIDLE_DISABLE 0x0
282#define DPLL_AUTOIDLE_LOW_POWER_STOP 0x1
283
284#define MAX_DPLL_WAIT_TRIES 1000000
Paul Walmsley02e19a92008-03-18 15:09:51 +0200285
286/**
287 * omap3_dpll_recalc - recalculate DPLL rate
288 * @clk: DPLL struct clk
289 *
290 * Recalculate and propagate the DPLL rate.
291 */
292static void omap3_dpll_recalc(struct clk *clk)
293{
294 clk->rate = omap2_get_dpll_rate(clk);
Paul Walmsley02e19a92008-03-18 15:09:51 +0200295}
296
Paul Walmsley542313c2008-07-03 12:24:45 +0300297/* _omap3_dpll_write_clken - write clken_bits arg to a DPLL's enable bits */
298static void _omap3_dpll_write_clken(struct clk *clk, u8 clken_bits)
299{
300 const struct dpll_data *dd;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300301 u32 v;
Paul Walmsley542313c2008-07-03 12:24:45 +0300302
303 dd = clk->dpll_data;
304
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300305 v = __raw_readl(dd->control_reg);
306 v &= ~dd->enable_mask;
307 v |= clken_bits << __ffs(dd->enable_mask);
308 __raw_writel(v, dd->control_reg);
Paul Walmsley542313c2008-07-03 12:24:45 +0300309}
310
311/* _omap3_wait_dpll_status: wait for a DPLL to enter a specific state */
312static int _omap3_wait_dpll_status(struct clk *clk, u8 state)
313{
314 const struct dpll_data *dd;
315 int i = 0;
316 int ret = -EINVAL;
Paul Walmsley542313c2008-07-03 12:24:45 +0300317
318 dd = clk->dpll_data;
319
Paul Walmsleyc1bd7aa2009-01-28 12:08:17 -0700320 state <<= __ffs(dd->idlest_mask);
Paul Walmsley542313c2008-07-03 12:24:45 +0300321
Paul Walmsleyc1bd7aa2009-01-28 12:08:17 -0700322 while (((__raw_readl(dd->idlest_reg) & dd->idlest_mask) != state) &&
Paul Walmsley542313c2008-07-03 12:24:45 +0300323 i < MAX_DPLL_WAIT_TRIES) {
324 i++;
325 udelay(1);
326 }
327
328 if (i == MAX_DPLL_WAIT_TRIES) {
329 printk(KERN_ERR "clock: %s failed transition to '%s'\n",
330 clk->name, (state) ? "locked" : "bypassed");
331 } else {
332 pr_debug("clock: %s transition to '%s' in %d loops\n",
333 clk->name, (state) ? "locked" : "bypassed", i);
334
335 ret = 0;
336 }
337
338 return ret;
339}
340
Paul Walmsley16c90f02009-01-27 19:12:47 -0700341/* From 3430 TRM ES2 4.7.6.2 */
342static u16 _omap3_dpll_compute_freqsel(struct clk *clk, u8 n)
343{
344 unsigned long fint;
345 u16 f = 0;
346
347 fint = clk->parent->rate / (n + 1);
348
349 pr_debug("clock: fint is %lu\n", fint);
350
351 if (fint >= 750000 && fint <= 1000000)
352 f = 0x3;
353 else if (fint > 1000000 && fint <= 1250000)
354 f = 0x4;
355 else if (fint > 1250000 && fint <= 1500000)
356 f = 0x5;
357 else if (fint > 1500000 && fint <= 1750000)
358 f = 0x6;
359 else if (fint > 1750000 && fint <= 2100000)
360 f = 0x7;
361 else if (fint > 7500000 && fint <= 10000000)
362 f = 0xB;
363 else if (fint > 10000000 && fint <= 12500000)
364 f = 0xC;
365 else if (fint > 12500000 && fint <= 15000000)
366 f = 0xD;
367 else if (fint > 15000000 && fint <= 17500000)
368 f = 0xE;
369 else if (fint > 17500000 && fint <= 21000000)
370 f = 0xF;
371 else
372 pr_debug("clock: unknown freqsel setting for %d\n", n);
373
374 return f;
375}
376
Paul Walmsley542313c2008-07-03 12:24:45 +0300377/* Non-CORE DPLL (e.g., DPLLs that do not control SDRC) clock functions */
378
379/*
380 * _omap3_noncore_dpll_lock - instruct a DPLL to lock and wait for readiness
381 * @clk: pointer to a DPLL struct clk
382 *
383 * Instructs a non-CORE DPLL to lock. Waits for the DPLL to report
384 * readiness before returning. Will save and restore the DPLL's
385 * autoidle state across the enable, per the CDP code. If the DPLL
386 * locked successfully, return 0; if the DPLL did not lock in the time
387 * allotted, or DPLL3 was passed in, return -EINVAL.
388 */
389static int _omap3_noncore_dpll_lock(struct clk *clk)
390{
391 u8 ai;
392 int r;
393
394 if (clk == &dpll3_ck)
395 return -EINVAL;
396
397 pr_debug("clock: locking DPLL %s\n", clk->name);
398
399 ai = omap3_dpll_autoidle_read(clk);
400
401 _omap3_dpll_write_clken(clk, DPLL_LOCKED);
402
403 if (ai) {
404 /*
405 * If no downstream clocks are enabled, CM_IDLEST bit
406 * may never become active, so don't wait for DPLL to lock.
407 */
408 r = 0;
409 omap3_dpll_allow_idle(clk);
410 } else {
411 r = _omap3_wait_dpll_status(clk, 1);
412 omap3_dpll_deny_idle(clk);
413 };
414
415 return r;
416}
417
418/*
419 * omap3_noncore_dpll_bypass - instruct a DPLL to bypass and wait for readiness
420 * @clk: pointer to a DPLL struct clk
421 *
422 * Instructs a non-CORE DPLL to enter low-power bypass mode. In
423 * bypass mode, the DPLL's rate is set equal to its parent clock's
424 * rate. Waits for the DPLL to report readiness before returning.
425 * Will save and restore the DPLL's autoidle state across the enable,
426 * per the CDP code. If the DPLL entered bypass mode successfully,
427 * return 0; if the DPLL did not enter bypass in the time allotted, or
428 * DPLL3 was passed in, or the DPLL does not support low-power bypass,
429 * return -EINVAL.
430 */
431static int _omap3_noncore_dpll_bypass(struct clk *clk)
432{
433 int r;
434 u8 ai;
435
436 if (clk == &dpll3_ck)
437 return -EINVAL;
438
439 if (!(clk->dpll_data->modes & (1 << DPLL_LOW_POWER_BYPASS)))
440 return -EINVAL;
441
442 pr_debug("clock: configuring DPLL %s for low-power bypass\n",
443 clk->name);
444
445 ai = omap3_dpll_autoidle_read(clk);
446
447 _omap3_dpll_write_clken(clk, DPLL_LOW_POWER_BYPASS);
448
449 r = _omap3_wait_dpll_status(clk, 0);
450
451 if (ai)
452 omap3_dpll_allow_idle(clk);
453 else
454 omap3_dpll_deny_idle(clk);
455
456 return r;
457}
458
459/*
460 * _omap3_noncore_dpll_stop - instruct a DPLL to stop
461 * @clk: pointer to a DPLL struct clk
462 *
463 * Instructs a non-CORE DPLL to enter low-power stop. Will save and
464 * restore the DPLL's autoidle state across the stop, per the CDP
465 * code. If DPLL3 was passed in, or the DPLL does not support
466 * low-power stop, return -EINVAL; otherwise, return 0.
467 */
468static int _omap3_noncore_dpll_stop(struct clk *clk)
469{
470 u8 ai;
471
472 if (clk == &dpll3_ck)
473 return -EINVAL;
474
475 if (!(clk->dpll_data->modes & (1 << DPLL_LOW_POWER_STOP)))
476 return -EINVAL;
477
478 pr_debug("clock: stopping DPLL %s\n", clk->name);
479
480 ai = omap3_dpll_autoidle_read(clk);
481
482 _omap3_dpll_write_clken(clk, DPLL_LOW_POWER_STOP);
483
484 if (ai)
485 omap3_dpll_allow_idle(clk);
486 else
487 omap3_dpll_deny_idle(clk);
488
489 return 0;
490}
491
492/**
493 * omap3_noncore_dpll_enable - instruct a DPLL to enter bypass or lock mode
494 * @clk: pointer to a DPLL struct clk
495 *
496 * Instructs a non-CORE DPLL to enable, e.g., to enter bypass or lock.
497 * The choice of modes depends on the DPLL's programmed rate: if it is
498 * the same as the DPLL's parent clock, it will enter bypass;
499 * otherwise, it will enter lock. This code will wait for the DPLL to
500 * indicate readiness before returning, unless the DPLL takes too long
501 * to enter the target state. Intended to be used as the struct clk's
502 * enable function. If DPLL3 was passed in, or the DPLL does not
503 * support low-power stop, or if the DPLL took too long to enter
504 * bypass or lock, return -EINVAL; otherwise, return 0.
505 */
506static int omap3_noncore_dpll_enable(struct clk *clk)
507{
508 int r;
509
510 if (clk == &dpll3_ck)
511 return -EINVAL;
512
Paul Walmsley16c90f02009-01-27 19:12:47 -0700513 if (clk->parent->rate == omap2_get_dpll_rate(clk))
Paul Walmsley542313c2008-07-03 12:24:45 +0300514 r = _omap3_noncore_dpll_bypass(clk);
515 else
516 r = _omap3_noncore_dpll_lock(clk);
517
518 return r;
519}
520
521/**
522 * omap3_noncore_dpll_enable - instruct a DPLL to enter bypass or lock mode
523 * @clk: pointer to a DPLL struct clk
524 *
525 * Instructs a non-CORE DPLL to enable, e.g., to enter bypass or lock.
526 * The choice of modes depends on the DPLL's programmed rate: if it is
527 * the same as the DPLL's parent clock, it will enter bypass;
528 * otherwise, it will enter lock. This code will wait for the DPLL to
529 * indicate readiness before returning, unless the DPLL takes too long
530 * to enter the target state. Intended to be used as the struct clk's
531 * enable function. If DPLL3 was passed in, or the DPLL does not
532 * support low-power stop, or if the DPLL took too long to enter
533 * bypass or lock, return -EINVAL; otherwise, return 0.
534 */
535static void omap3_noncore_dpll_disable(struct clk *clk)
536{
537 if (clk == &dpll3_ck)
538 return;
539
540 _omap3_noncore_dpll_stop(clk);
541}
542
Paul Walmsley16c90f02009-01-27 19:12:47 -0700543
544/* Non-CORE DPLL rate set code */
545
546/*
547 * omap3_noncore_dpll_program - set non-core DPLL M,N values directly
548 * @clk: struct clk * of DPLL to set
549 * @m: DPLL multiplier to set
550 * @n: DPLL divider to set
551 * @freqsel: FREQSEL value to set
552 *
553 * Program the DPLL with the supplied M, N values, and wait for the DPLL to
554 * lock.. Returns -EINVAL upon error, or 0 upon success.
555 */
556static int omap3_noncore_dpll_program(struct clk *clk, u16 m, u8 n, u16 freqsel)
557{
558 struct dpll_data *dd = clk->dpll_data;
559 u32 v;
560
561 /* 3430 ES2 TRM: 4.7.6.9 DPLL Programming Sequence */
562 _omap3_noncore_dpll_bypass(clk);
563
Paul Walmsleyf0587b62009-01-28 12:08:11 -0700564 /* Set jitter correction */
565 v = __raw_readl(dd->control_reg);
566 v &= ~dd->freqsel_mask;
567 v |= freqsel << __ffs(dd->freqsel_mask);
568 __raw_writel(v, dd->control_reg);
569
570 /* Set DPLL multiplier, divider */
Paul Walmsley16c90f02009-01-27 19:12:47 -0700571 v = __raw_readl(dd->mult_div1_reg);
572 v &= ~(dd->mult_mask | dd->div1_mask);
Paul Walmsley16c90f02009-01-27 19:12:47 -0700573 v |= m << __ffs(dd->mult_mask);
Paul Walmsleyf0587b62009-01-28 12:08:11 -0700574 v |= (n - 1) << __ffs(dd->div1_mask);
Paul Walmsley16c90f02009-01-27 19:12:47 -0700575 __raw_writel(v, dd->mult_div1_reg);
576
577 /* We let the clock framework set the other output dividers later */
578
579 /* REVISIT: Set ramp-up delay? */
580
581 _omap3_noncore_dpll_lock(clk);
582
583 return 0;
584}
585
586/**
587 * omap3_noncore_dpll_set_rate - set non-core DPLL rate
588 * @clk: struct clk * of DPLL to set
589 * @rate: rounded target rate
590 *
591 * Program the DPLL with the rounded target rate. Returns -EINVAL upon
592 * error, or 0 upon success.
593 */
594static int omap3_noncore_dpll_set_rate(struct clk *clk, unsigned long rate)
595{
596 u16 freqsel;
597 struct dpll_data *dd;
598
599 if (!clk || !rate)
600 return -EINVAL;
601
602 dd = clk->dpll_data;
603 if (!dd)
604 return -EINVAL;
605
606 if (rate == omap2_get_dpll_rate(clk))
607 return 0;
608
609 if (dd->last_rounded_rate != rate)
610 omap2_dpll_round_rate(clk, rate);
611
612 if (dd->last_rounded_rate == 0)
613 return -EINVAL;
614
615 freqsel = _omap3_dpll_compute_freqsel(clk, dd->last_rounded_n);
616 if (!freqsel)
617 WARN_ON(1);
618
619 omap3_noncore_dpll_program(clk, dd->last_rounded_m, dd->last_rounded_n,
620 freqsel);
621
622 omap3_dpll_recalc(clk);
623
624 return 0;
625}
626
627static int omap3_dpll4_set_rate(struct clk *clk, unsigned long rate)
628{
629 /*
630 * According to the 12-5 CDP code from TI, "Limitation 2.5"
631 * on 3430ES1 prevents us from changing DPLL multipliers or dividers
632 * on DPLL4.
633 */
634 if (omap_rev() == OMAP3430_REV_ES1_0) {
635 printk(KERN_ERR "clock: DPLL4 cannot change rate due to "
636 "silicon 'Limitation 2.5' on 3430ES1.\n");
637 return -EINVAL;
638 }
639 return omap3_noncore_dpll_set_rate(clk, rate);
640}
641
Russell King548d8492008-11-04 14:02:46 +0000642static const struct clkops clkops_noncore_dpll_ops = {
643 .enable = &omap3_noncore_dpll_enable,
644 .disable = &omap3_noncore_dpll_disable,
645};
646
Paul Walmsley16c90f02009-01-27 19:12:47 -0700647/* DPLL autoidle read/set code */
648
649
Paul Walmsley542313c2008-07-03 12:24:45 +0300650/**
651 * omap3_dpll_autoidle_read - read a DPLL's autoidle bits
652 * @clk: struct clk * of the DPLL to read
653 *
654 * Return the DPLL's autoidle bits, shifted down to bit 0. Returns
655 * -EINVAL if passed a null pointer or if the struct clk does not
656 * appear to refer to a DPLL.
657 */
658static u32 omap3_dpll_autoidle_read(struct clk *clk)
659{
660 const struct dpll_data *dd;
661 u32 v;
662
663 if (!clk || !clk->dpll_data)
664 return -EINVAL;
665
666 dd = clk->dpll_data;
667
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300668 v = __raw_readl(dd->autoidle_reg);
Paul Walmsley542313c2008-07-03 12:24:45 +0300669 v &= dd->autoidle_mask;
670 v >>= __ffs(dd->autoidle_mask);
671
672 return v;
673}
674
675/**
676 * omap3_dpll_allow_idle - enable DPLL autoidle bits
677 * @clk: struct clk * of the DPLL to operate on
678 *
679 * Enable DPLL automatic idle control. This automatic idle mode
680 * switching takes effect only when the DPLL is locked, at least on
681 * OMAP3430. The DPLL will enter low-power stop when its downstream
682 * clocks are gated. No return value.
683 */
684static void omap3_dpll_allow_idle(struct clk *clk)
685{
686 const struct dpll_data *dd;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300687 u32 v;
Paul Walmsley542313c2008-07-03 12:24:45 +0300688
689 if (!clk || !clk->dpll_data)
690 return;
691
692 dd = clk->dpll_data;
693
694 /*
695 * REVISIT: CORE DPLL can optionally enter low-power bypass
696 * by writing 0x5 instead of 0x1. Add some mechanism to
697 * optionally enter this mode.
698 */
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300699 v = __raw_readl(dd->autoidle_reg);
700 v &= ~dd->autoidle_mask;
701 v |= DPLL_AUTOIDLE_LOW_POWER_STOP << __ffs(dd->autoidle_mask);
702 __raw_writel(v, dd->autoidle_reg);
Paul Walmsley542313c2008-07-03 12:24:45 +0300703}
704
705/**
706 * omap3_dpll_deny_idle - prevent DPLL from automatically idling
707 * @clk: struct clk * of the DPLL to operate on
708 *
709 * Disable DPLL automatic idle control. No return value.
710 */
711static void omap3_dpll_deny_idle(struct clk *clk)
712{
713 const struct dpll_data *dd;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300714 u32 v;
Paul Walmsley542313c2008-07-03 12:24:45 +0300715
716 if (!clk || !clk->dpll_data)
717 return;
718
719 dd = clk->dpll_data;
720
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300721 v = __raw_readl(dd->autoidle_reg);
722 v &= ~dd->autoidle_mask;
723 v |= DPLL_AUTOIDLE_DISABLE << __ffs(dd->autoidle_mask);
724 __raw_writel(v, dd->autoidle_reg);
Paul Walmsley542313c2008-07-03 12:24:45 +0300725}
726
727/* Clock control for DPLL outputs */
728
Paul Walmsley02e19a92008-03-18 15:09:51 +0200729/**
730 * omap3_clkoutx2_recalc - recalculate DPLL X2 output virtual clock rate
731 * @clk: DPLL output struct clk
732 *
733 * Using parent clock DPLL data, look up DPLL state. If locked, set our
734 * rate to the dpll_clk * 2; otherwise, just use dpll_clk.
735 */
736static void omap3_clkoutx2_recalc(struct clk *clk)
737{
738 const struct dpll_data *dd;
739 u32 v;
740 struct clk *pclk;
741
742 /* Walk up the parents of clk, looking for a DPLL */
743 pclk = clk->parent;
744 while (pclk && !pclk->dpll_data)
745 pclk = pclk->parent;
746
747 /* clk does not have a DPLL as a parent? */
748 WARN_ON(!pclk);
749
750 dd = pclk->dpll_data;
751
752 WARN_ON(!dd->control_reg || !dd->enable_mask);
753
754 v = __raw_readl(dd->control_reg) & dd->enable_mask;
755 v >>= __ffs(dd->enable_mask);
756 if (v != DPLL_LOCKED)
757 clk->rate = clk->parent->rate;
758 else
759 clk->rate = clk->parent->rate * 2;
Paul Walmsley02e19a92008-03-18 15:09:51 +0200760}
761
Paul Walmsley542313c2008-07-03 12:24:45 +0300762/* Common clock code */
763
Paul Walmsley02e19a92008-03-18 15:09:51 +0200764/*
765 * As it is structured now, this will prevent an OMAP2/3 multiboot
766 * kernel from compiling. This will need further attention.
767 */
768#if defined(CONFIG_ARCH_OMAP3)
769
770static struct clk_functions omap2_clk_functions = {
771 .clk_enable = omap2_clk_enable,
772 .clk_disable = omap2_clk_disable,
773 .clk_round_rate = omap2_clk_round_rate,
774 .clk_set_rate = omap2_clk_set_rate,
775 .clk_set_parent = omap2_clk_set_parent,
776 .clk_disable_unused = omap2_clk_disable_unused,
777};
778
779/*
780 * Set clocks for bypass mode for reboot to work.
781 */
782void omap2_clk_prepare_for_reboot(void)
783{
784 /* REVISIT: Not ready for 343x */
785#if 0
786 u32 rate;
787
788 if (vclk == NULL || sclk == NULL)
789 return;
790
791 rate = clk_get_rate(sclk);
792 clk_set_rate(vclk, rate);
793#endif
794}
795
796/* REVISIT: Move this init stuff out into clock.c */
797
798/*
799 * Switch the MPU rate if specified on cmdline.
800 * We cannot do this early until cmdline is parsed.
801 */
802static int __init omap2_clk_arch_init(void)
803{
804 if (!mpurate)
805 return -EINVAL;
806
807 /* REVISIT: not yet ready for 343x */
808#if 0
809 if (omap2_select_table_rate(&virt_prcm_set, mpurate))
810 printk(KERN_ERR "Could not find matching MPU rate\n");
811#endif
812
813 recalculate_root_clocks();
814
815 printk(KERN_INFO "Switched to new clocking rate (Crystal/DPLL3/MPU): "
816 "%ld.%01ld/%ld/%ld MHz\n",
817 (osc_sys_ck.rate / 1000000), (osc_sys_ck.rate / 100000) % 10,
818 (core_ck.rate / 1000000), (dpll1_fck.rate / 1000000)) ;
819
820 return 0;
821}
822arch_initcall(omap2_clk_arch_init);
823
824int __init omap2_clk_init(void)
825{
826 /* struct prcm_config *prcm; */
Russell King44dc9d02009-01-19 15:51:11 +0000827 struct omap_clk *c;
Paul Walmsley02e19a92008-03-18 15:09:51 +0200828 /* u32 clkrate; */
829 u32 cpu_clkflg;
830
Paul Walmsley02e19a92008-03-18 15:09:51 +0200831 if (cpu_is_omap34xx()) {
832 cpu_mask = RATE_IN_343X;
Russell King44dc9d02009-01-19 15:51:11 +0000833 cpu_clkflg = CK_343X;
Paul Walmsley02e19a92008-03-18 15:09:51 +0200834
835 /*
836 * Update this if there are further clock changes between ES2
837 * and production parts
838 */
Lauri Leukkunen84a34342008-12-10 17:36:31 -0800839 if (omap_rev() == OMAP3430_REV_ES1_0) {
Paul Walmsley02e19a92008-03-18 15:09:51 +0200840 /* No 3430ES1-only rates exist, so no RATE_IN_3430ES1 */
Russell King44dc9d02009-01-19 15:51:11 +0000841 cpu_clkflg |= CK_3430ES1;
Paul Walmsley02e19a92008-03-18 15:09:51 +0200842 } else {
843 cpu_mask |= RATE_IN_3430ES2;
Russell King44dc9d02009-01-19 15:51:11 +0000844 cpu_clkflg |= CK_3430ES2;
Paul Walmsley02e19a92008-03-18 15:09:51 +0200845 }
846 }
847
848 clk_init(&omap2_clk_functions);
849
Russell King44dc9d02009-01-19 15:51:11 +0000850 for (c = omap34xx_clks; c < omap34xx_clks + ARRAY_SIZE(omap34xx_clks); c++)
851 if (c->cpu & cpu_clkflg) {
852 clkdev_add(&c->lk);
853 clk_register(c->lk.clk);
854 omap2_init_clk_clkdm(c->lk.clk);
Paul Walmsley333943b2008-08-19 11:08:45 +0300855 }
Paul Walmsley02e19a92008-03-18 15:09:51 +0200856
857 /* REVISIT: Not yet ready for OMAP3 */
858#if 0
859 /* Check the MPU rate set by bootloader */
860 clkrate = omap2_get_dpll_rate_24xx(&dpll_ck);
861 for (prcm = rate_table; prcm->mpu_speed; prcm++) {
862 if (!(prcm->flags & cpu_mask))
863 continue;
864 if (prcm->xtal_speed != sys_ck.rate)
865 continue;
866 if (prcm->dpll_speed <= clkrate)
867 break;
868 }
869 curr_prcm_set = prcm;
870#endif
871
872 recalculate_root_clocks();
873
Roman Tereshonkov3760d312008-03-13 21:35:09 +0200874 printk(KERN_INFO "Clocking rate (Crystal/DPLL/ARM core): "
Paul Walmsley02e19a92008-03-18 15:09:51 +0200875 "%ld.%01ld/%ld/%ld MHz\n",
876 (osc_sys_ck.rate / 1000000), (osc_sys_ck.rate / 100000) % 10,
Roman Tereshonkov3760d312008-03-13 21:35:09 +0200877 (core_ck.rate / 1000000), (arm_fck.rate / 1000000));
Paul Walmsley02e19a92008-03-18 15:09:51 +0200878
879 /*
880 * Only enable those clocks we will need, let the drivers
881 * enable other clocks as necessary
882 */
883 clk_enable_init_clocks();
884
885 /* Avoid sleeping during omap2_clk_prepare_for_reboot() */
886 /* REVISIT: not yet ready for 343x */
887#if 0
888 vclk = clk_get(NULL, "virt_prcm_set");
889 sclk = clk_get(NULL, "sys_ck");
890#endif
891 return 0;
892}
893
894#endif