blob: 6563791dfbadc63d5b84c94746702c9422d2aacb [file] [log] [blame]
Channagoud Kadabi634ac6d2012-12-12 18:13:56 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Deepa Dinamanica5ad852012-05-07 18:19:47 -07002 *
3 * Redistribution and use in source and binary forms, with or without
Deepa Dinamani32bfad02012-11-02 12:15:05 -07004 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
Deepa Dinamanica5ad852012-05-07 18:19:47 -070015 *
Deepa Dinamani32bfad02012-11-02 12:15:05 -070016 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Deepa Dinamanica5ad852012-05-07 18:19:47 -070027 */
28
Amol Jadi29f95032012-06-22 12:52:54 -070029#include <err.h>
30#include <assert.h>
Deepa Dinamanica5ad852012-05-07 18:19:47 -070031#include <debug.h>
32#include <reg.h>
Deepa Dinamani32bfad02012-11-02 12:15:05 -070033#include <platform/timer.h>
Deepa Dinamanica5ad852012-05-07 18:19:47 -070034#include <platform/iomap.h>
Deepa Dinamanica5ad852012-05-07 18:19:47 -070035#include <mmc.h>
Amol Jadi29f95032012-06-22 12:52:54 -070036#include <clock.h>
37#include <platform/clock.h>
Channagoud Kadabi634ac6d2012-12-12 18:13:56 -080038#include <blsp_qup.h>
Deepa Dinamanica5ad852012-05-07 18:19:47 -070039
Amol Jadi29f95032012-06-22 12:52:54 -070040void hsusb_clock_init(void)
41{
42 int ret;
Deepa Dinamani0687ecd2012-08-10 16:00:26 -070043 struct clk *iclk, *cclk;
Amol Jadi29f95032012-06-22 12:52:54 -070044
45 ret = clk_get_set_enable("usb_iface_clk", 0, 1);
46 if(ret)
47 {
48 dprintf(CRITICAL, "failed to set usb_iface_clk ret = %d\n", ret);
49 ASSERT(0);
50 }
51
52 ret = clk_get_set_enable("usb_core_clk", 75000000, 1);
53 if(ret)
54 {
55 dprintf(CRITICAL, "failed to set usb_core_clk ret = %d\n", ret);
56 ASSERT(0);
57 }
Deepa Dinamani0687ecd2012-08-10 16:00:26 -070058
59 mdelay(20);
60
61 iclk = clk_get("usb_iface_clk");
62 cclk = clk_get("usb_core_clk");
63
64 /* Disable USB all clock init */
65 writel(0, USB_BOOT_CLOCK_CTL);
66
67 clk_disable(iclk);
68 clk_disable(cclk);
69
70 mdelay(20);
71
72 /* Start the block reset for usb */
73 writel(1, USB_HS_BCR);
74
75 mdelay(20);
76
77 /* Take usb block out of reset */
Deepa Dinamani32bfad02012-11-02 12:15:05 -070078 writel(0, USB_HS_BCR);
Deepa Dinamani0687ecd2012-08-10 16:00:26 -070079
80 mdelay(20);
81
82 ret = clk_enable(iclk);
Deepa Dinamani32bfad02012-11-02 12:15:05 -070083
Deepa Dinamani0687ecd2012-08-10 16:00:26 -070084 if(ret)
85 {
86 dprintf(CRITICAL, "failed to set usb_iface_clk after async ret = %d\n", ret);
87 ASSERT(0);
88 }
89
90 ret = clk_enable(cclk);
91
92 if(ret)
93 {
94 dprintf(CRITICAL, "failed to set usb_iface_clk after async ret = %d\n", ret);
95 ASSERT(0);
96 }
97
Amol Jadi29f95032012-06-22 12:52:54 -070098}
Deepa Dinamanica5ad852012-05-07 18:19:47 -070099
100void clock_init_mmc(uint32_t interface)
101{
Deepa Dinamanib10c0e42012-08-10 14:36:24 -0700102 char clk_name[64];
Amol Jadi29f95032012-06-22 12:52:54 -0700103 int ret;
104
Deepa Dinamanib10c0e42012-08-10 14:36:24 -0700105 snprintf(clk_name, 64, "sdc%u_iface_clk", interface);
106
Amol Jadi29f95032012-06-22 12:52:54 -0700107 /* enable interface clock */
Deepa Dinamanib10c0e42012-08-10 14:36:24 -0700108 ret = clk_get_set_enable(clk_name, 0, 1);
Amol Jadi29f95032012-06-22 12:52:54 -0700109 if(ret)
110 {
111 dprintf(CRITICAL, "failed to set sdc1_iface_clk ret = %d\n", ret);
112 ASSERT(0);
113 }
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700114}
115
116/* Configure MMC clock */
117void clock_config_mmc(uint32_t interface, uint32_t freq)
118{
Amol Jadi29f95032012-06-22 12:52:54 -0700119 int ret;
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700120 uint32_t reg;
Deepa Dinamanib10c0e42012-08-10 14:36:24 -0700121 char clk_name[64];
122
123 snprintf(clk_name, 64, "sdc%u_core_clk", interface);
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700124
Channagoud Kadabi96518412013-03-14 16:38:41 -0700125 /* Disalbe MCI_CLK before changing the sdcc clock */
126 mmc_boot_mci_clk_disable();
127
Amol Jadi29f95032012-06-22 12:52:54 -0700128 if(freq == MMC_CLK_400KHZ)
129 {
Deepa Dinamanib10c0e42012-08-10 14:36:24 -0700130 ret = clk_get_set_enable(clk_name, 400000, 1);
Amol Jadi29f95032012-06-22 12:52:54 -0700131 }
132 else if(freq == MMC_CLK_50MHZ)
133 {
Neeti Desaiddc771b2012-08-28 18:17:04 -0700134 ret = clk_get_set_enable(clk_name, 50000000, 1);
Amol Jadi29f95032012-06-22 12:52:54 -0700135 }
136 else
137 {
138 dprintf(CRITICAL, "sdc frequency (%d) is not supported\n", freq);
139 ASSERT(0);
140 }
141
142
143 if(ret)
144 {
145 dprintf(CRITICAL, "failed to set sdc1_core_clk ret = %d\n", ret);
146 ASSERT(0);
147 }
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700148
Channagoud Kadabi96518412013-03-14 16:38:41 -0700149 /* Enalbe MCI clock */
150 mmc_boot_mci_clk_enable();
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700151}
152
Deepa Dinamani26e93262012-05-21 17:35:14 -0700153/* Configure UART clock based on the UART block id*/
154void clock_config_uart_dm(uint8_t id)
155{
Amol Jadi29f95032012-06-22 12:52:54 -0700156 int ret;
Deepa Dinamani26e93262012-05-21 17:35:14 -0700157
Neeti Desaiac011272012-08-29 18:24:54 -0700158
159 ret = clk_get_set_enable("uart2_iface_clk", 0, 1);
160 if(ret)
161 {
162 dprintf(CRITICAL, "failed to set uart2_iface_clk ret = %d\n", ret);
163 ASSERT(0);
164 }
165
166 ret = clk_get_set_enable("uart2_core_clk", 7372800, 1);
Amol Jadi29f95032012-06-22 12:52:54 -0700167 if(ret)
168 {
169 dprintf(CRITICAL, "failed to set uart1_core_clk ret = %d\n", ret);
170 ASSERT(0);
171 }
Deepa Dinamani26e93262012-05-21 17:35:14 -0700172}
Deepa Dinamani32bfad02012-11-02 12:15:05 -0700173
174/* Function to asynchronously reset CE.
175 * Function assumes that all the CE clocks are off.
176 */
177static void ce_async_reset(uint8_t instance)
178{
179 if (instance == 1)
180 {
181 /* TODO: Add support for instance 1. */
182 dprintf(CRITICAL, "CE instance not supported instance = %d", instance);
183 ASSERT(0);
184 }
185 else if (instance == 2)
186 {
187 /* Start the block reset for CE */
188 writel(1, GCC_CE2_BCR);
189
190 udelay(2);
191
192 /* Take CE block out of reset */
193 writel(0, GCC_CE2_BCR);
194
195 udelay(2);
196 }
197 else
198 {
199 dprintf(CRITICAL, "CE instance not supported instance = %d", instance);
200 ASSERT(0);
201 }
202}
203
sundarajan srinivasan6aaa50c2013-02-27 14:18:57 -0800204void clock_ce_enable(uint8_t instance)
Deepa Dinamani32bfad02012-11-02 12:15:05 -0700205{
206 int ret;
207 char clk_name[64];
208
209 snprintf(clk_name, 64, "ce%u_src_clk", instance);
210 ret = clk_get_set_enable(clk_name, 100000000, 1);
211 if(ret)
212 {
213 dprintf(CRITICAL, "failed to set ce_src_clk ret = %d\n", ret);
214 ASSERT(0);
215 }
216
217 snprintf(clk_name, 64, "ce%u_core_clk", instance);
218 ret = clk_get_set_enable(clk_name, 0, 1);
219 if(ret)
220 {
221 dprintf(CRITICAL, "failed to set ce_core_clk ret = %d\n", ret);
222 ASSERT(0);
223 }
224
225 snprintf(clk_name, 64, "ce%u_ahb_clk", instance);
226 ret = clk_get_set_enable(clk_name, 0, 1);
227 if(ret)
228 {
229 dprintf(CRITICAL, "failed to set ce_ahb_clk ret = %d\n", ret);
230 ASSERT(0);
231 }
232
233 snprintf(clk_name, 64, "ce%u_axi_clk", instance);
234 ret = clk_get_set_enable(clk_name, 0, 1);
235 if(ret)
236 {
237 dprintf(CRITICAL, "failed to set ce_axi_clk ret = %d\n", ret);
238 ASSERT(0);
239 }
240
241 /* Wait for 48 * #pipes cycles.
242 * This is necessary as immediately after an access control reset (boot up)
243 * or a debug re-enable, the Crypto core sequentially clears its internal
244 * pipe key storage memory. If pipe key initialization writes are attempted
245 * during this time, they may be overwritten by the internal clearing logic.
246 */
247 udelay(1);
248}
249
sundarajan srinivasan6aaa50c2013-02-27 14:18:57 -0800250void clock_ce_disable(uint8_t instance)
Deepa Dinamani32bfad02012-11-02 12:15:05 -0700251{
252 struct clk *ahb_clk;
253 struct clk *cclk;
254 struct clk *axi_clk;
255 struct clk *src_clk;
256 char clk_name[64];
257
258 snprintf(clk_name, 64, "ce%u_src_clk", instance);
259 src_clk = clk_get(clk_name);
260
261 snprintf(clk_name, 64, "ce%u_ahb_clk", instance);
262 ahb_clk = clk_get(clk_name);
263
264 snprintf(clk_name, 64, "ce%u_axi_clk", instance);
265 axi_clk = clk_get(clk_name);
266
267 snprintf(clk_name, 64, "ce%u_core_clk", instance);
268 cclk = clk_get(clk_name);
269
270 clk_disable(ahb_clk);
271 clk_disable(axi_clk);
272 clk_disable(cclk);
273 clk_disable(src_clk);
274
275 /* Some delay for the clocks to stabalize. */
276 udelay(1);
277}
278
279void clock_config_ce(uint8_t instance)
280{
281 /* Need to enable the clock before disabling since the clk_disable()
282 * has a check to default to nop when the clk_enable() is not called
283 * on that particular clock.
284 */
285 clock_ce_enable(instance);
286
287 clock_ce_disable(instance);
288
289 ce_async_reset(instance);
290
291 clock_ce_enable(instance);
sundarajan srinivasan6aaa50c2013-02-27 14:18:57 -0800292
Deepa Dinamani32bfad02012-11-02 12:15:05 -0700293}
Channagoud Kadabi634ac6d2012-12-12 18:13:56 -0800294
295void clock_config_blsp_i2c(uint8_t blsp_id, uint8_t qup_id)
296{
297 uint8_t ret = 0;
298 char clk_name[64];
299
300 struct clk *qup_clk;
301
302 snprintf(clk_name, 64, "blsp%u_ahb_clk", blsp_id);
303
304 ret = clk_get_set_enable(clk_name, 0 , 1);
305
306 if (ret) {
307 dprintf(CRITICAL, "Failed to enable %s clock\n", clk_name);
308 return;
309 }
310
311 snprintf(clk_name, 64, "blsp%u_qup%u_i2c_apps_clk", blsp_id,
312 (qup_id + 1));
313
314 qup_clk = clk_get(clk_name);
315
316 if (!qup_clk) {
317 dprintf(CRITICAL, "Failed to get %s\n", clk_name);
318 return;
319 }
320
321 ret = clk_enable(qup_clk);
322
323 if (ret) {
324 dprintf(CRITICAL, "Failed to enable %s\n", clk_name);
325 return;
326 }
327}
Siddhartha Agrawalacdaf5b2013-01-22 18:14:53 -0800328
329void mdp_gdsc_ctrl(uint8_t enable)
330{
331 uint32_t reg = 0;
332 reg = readl(MDP_GDSCR);
333 if (enable) {
Siddhartha Agrawal267fc3f2013-03-25 17:03:50 -0700334 if (reg & 0x1) {
335 reg &= ~(BIT(0) | GDSC_EN_FEW_WAIT_MASK);
336 reg |= GDSC_EN_FEW_WAIT_256_MASK;
337 writel(reg, MDP_GDSCR);
338 }
Siddhartha Agrawalacdaf5b2013-01-22 18:14:53 -0800339
340 while(readl(MDP_GDSCR) & ((GDSC_POWER_ON_BIT) | (GDSC_POWER_ON_STATUS_BIT)));
341 } else
342 ASSERT(1);
343}
344
345/* Configure MDP clock */
346void mdp_clock_init(void)
347{
348 int ret;
349
350 /* Set MDP clock to 200MHz */
351 ret = clk_get_set_enable("mdp_ahb_clk", 0, 1);
352 if(ret)
353 {
354 dprintf(CRITICAL, "failed to set mdp_ahb_clk ret = %d\n", ret);
355 ASSERT(0);
356 }
357
358 ret = clk_get_set_enable("mdss_mdp_clk_src", 75000000, 1);
359 if(ret)
360 {
361 dprintf(CRITICAL, "failed to set mdp_clk_src ret = %d\n", ret);
362 ASSERT(0);
363 }
364
365 ret = clk_get_set_enable("mdss_mdp_clk", 0, 1);
366 if(ret)
367 {
368 dprintf(CRITICAL, "failed to set mdp_clk ret = %d\n", ret);
369 ASSERT(0);
370 }
371
372 ret = clk_get_set_enable("mdss_mdp_lut_clk", 0, 1);
373 if(ret)
374 {
375 dprintf(CRITICAL, "failed to set lut_mdp clk ret = %d\n", ret);
376 ASSERT(0);
377 }
378}
379
380/* Initialize all clocks needed by Display */
381void mmss_clock_init(void)
382{
383 int ret;
384
385 /* Configure Byte clock */
386 writel(0x100, DSI_BYTE0_CFG_RCGR);
387 writel(0x1, DSI_BYTE0_CMD_RCGR);
388 writel(0x1, DSI_BYTE0_CBCR);
389
390 /* Configure ESC clock */
391 ret = clk_get_set_enable("mdss_esc0_clk", 0, 1);
392 if(ret)
393 {
394 dprintf(CRITICAL, "failed to set esc0_clk ret = %d\n", ret);
395 ASSERT(0);
396 }
397
398 /* Configure MMSSNOC AXI clock */
399 ret = clk_get_set_enable("mmss_mmssnoc_axi_clk", 100000000, 1);
400 if(ret)
401 {
402 dprintf(CRITICAL, "failed to set mmssnoc_axi_clk ret = %d\n", ret);
403 ASSERT(0);
404 }
405
406 /* Configure MMSSNOC AXI clock */
407 ret = clk_get_set_enable("mmss_s0_axi_clk", 100000000, 1);
408 if(ret)
409 {
410 dprintf(CRITICAL, "failed to set mmss_s0_axi_clk ret = %d\n", ret);
411 ASSERT(0);
412 }
413
414 /* Configure AXI clock */
415 ret = clk_get_set_enable("mdss_axi_clk", 100000000, 1);
416 if(ret)
417 {
418 dprintf(CRITICAL, "failed to set mdss_axi_clk ret = %d\n", ret);
419 ASSERT(0);
420 }
421
422 /* Configure Pixel clock */
423 writel(0x102, DSI_PIXEL0_CFG_RCGR);
424 writel(0x1, DSI_PIXEL0_CMD_RCGR);
425 writel(0x1, DSI_PIXEL0_CBCR);
426}