blob: 461bc578b23eddcb319a269a238c8e16e462675d [file] [log] [blame]
Deepa Dinamani554b0622013-05-16 15:00:30 -07001/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * 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.
15 *
16 * 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.
27 */
28
29#include <stdint.h>
30#include <debug.h>
31#include <reg.h>
32#include <mmc.h>
33#include <clock.h>
34#include <platform/clock.h>
Sundarajan Srinivasan09374ed2013-06-18 13:29:32 -070035#include <platform/iomap.h>
Deepa Dinamani554b0622013-05-16 15:00:30 -070036
37void hsusb_clock_init(void)
38{
Sundarajan Srinivasan09374ed2013-06-18 13:29:32 -070039 int ret;
40 struct clk *iclk, *cclk;
41
42 ret = clk_get_set_enable("usb_iface_clk", 0, 1);
43 if(ret)
44 {
45 dprintf(CRITICAL, "failed to set usb_iface_clk ret = %d\n", ret);
46 ASSERT(0);
47 }
48
49 ret = clk_get_set_enable("usb_core_clk", 75000000, 1);
50 if(ret)
51 {
52 dprintf(CRITICAL, "failed to set usb_core_clk ret = %d\n", ret);
53 ASSERT(0);
54 }
55
56 /* Wait for the clocks to be stable since we are disabling soon after. */
57 mdelay(1);
58
59 iclk = clk_get("usb_iface_clk");
60 cclk = clk_get("usb_core_clk");
61
62 clk_disable(iclk);
63 clk_disable(cclk);
64
65 /* Wait for the clock disable to complete. */
66 mdelay(1);
67
68 /* Start the block reset for usb */
69 writel(1, USB_HS_BCR);
70
71 /* Wait for reset to complete. */
72 mdelay(1);
73
74 /* Take usb block out of reset */
75 writel(0, USB_HS_BCR);
76
77 /* Wait for the block to be brought out of reset. */
78 mdelay(1);
79
80 ret = clk_enable(iclk);
81
82 if(ret)
83 {
84 dprintf(CRITICAL, "failed to set usb_iface_clk after async ret = %d\n", ret);
85 ASSERT(0);
86 }
87
88 ret = clk_enable(cclk);
89
90 if(ret)
91 {
92 dprintf(CRITICAL, "failed to set usb_iface_clk after async ret = %d\n", ret);
93 ASSERT(0);
94 }
95
Deepa Dinamani554b0622013-05-16 15:00:30 -070096}
97
98void clock_init_mmc(uint32_t interface)
99{
Sundarajan Srinivasan09374ed2013-06-18 13:29:32 -0700100 char clk_name[64];
101 int ret;
102
103 snprintf(clk_name, 64, "sdc%u_iface_clk", interface);
104
105 /* enable interface clock */
106 ret = clk_get_set_enable(clk_name, 0, 1);
107 if(ret)
108 {
109 dprintf(CRITICAL, "failed to set sdc%u_iface_clk ret = %d\n", interface, ret);
110 ASSERT(0);
111 }
Deepa Dinamani554b0622013-05-16 15:00:30 -0700112}
113
114/* Configure MMC clock */
115void clock_config_mmc(uint32_t interface, uint32_t freq)
116{
Sundarajan Srinivasan09374ed2013-06-18 13:29:32 -0700117 int ret;
118 uint32_t reg;
119 char clk_name[64];
120
121 snprintf(clk_name, 64, "sdc%u_core_clk", interface);
122
Sundarajan Srinivasan09374ed2013-06-18 13:29:32 -0700123 if(freq == MMC_CLK_400KHZ)
124 {
125 ret = clk_get_set_enable(clk_name, 400000, 1);
126 }
127 else if(freq == MMC_CLK_50MHZ)
128 {
129 ret = clk_get_set_enable(clk_name, 50000000, 1);
130 }
131 else if(freq == MMC_CLK_96MHZ)
132 {
133 ret = clk_get_set_enable(clk_name, 100000000, 1);
134 }
135 else if(freq == MMC_CLK_200MHZ)
136 {
137 ret = clk_get_set_enable(clk_name, 200000000, 1);
138 }
139 else
140 {
141 dprintf(CRITICAL, "sdc frequency (%u) is not supported\n", freq);
142 ASSERT(0);
143 }
144
145
146 if(ret)
147 {
148 dprintf(CRITICAL, "failed to set sdc%u_core_clk ret = %d\n", interface, ret);
149 ASSERT(0);
150 }
151
Deepa Dinamani554b0622013-05-16 15:00:30 -0700152}
153
154/* Configure UART clock based on the UART block id*/
155void clock_config_uart_dm(uint8_t id)
156{
Sundarajan Srinivasan09374ed2013-06-18 13:29:32 -0700157 int ret;
158 char iclk[64];
159 char cclk[64];
160
161 snprintf(iclk, 64, "uart%u_iface_clk", id);
162 snprintf(cclk, 64, "uart%u_core_clk", id);
163
164 ret = clk_get_set_enable(iclk, 0, 1);
165 if(ret)
166 {
167 dprintf(CRITICAL, "failed to set uart%u_iface_clk ret = %d\n", id, ret);
168 ASSERT(0);
169 }
170
171 ret = clk_get_set_enable(cclk, 7372800, 1);
172 if(ret)
173 {
174 dprintf(CRITICAL, "failed to set uart%u_core_clk ret = %d\n", id, ret);
175 ASSERT(0);
176 }
Deepa Dinamani554b0622013-05-16 15:00:30 -0700177}
178
179/* Function to asynchronously reset CE (Crypto Engine).
180 * Function assumes that all the CE clocks are off.
181 */
182static void ce_async_reset(uint8_t instance)
183{
184}
185
186void clock_ce_enable(uint8_t instance)
187{
188}
189
190void clock_ce_disable(uint8_t instance)
191{
192}
193
194void clock_config_ce(uint8_t instance)
195{
196 /* Need to enable the clock before disabling since the clk_disable()
197 * has a check to default to nop when the clk_enable() is not called
198 * on that particular clock.
199 */
200 clock_ce_enable(instance);
201
202 clock_ce_disable(instance);
203
204 ce_async_reset(instance);
205
206 clock_ce_enable(instance);
207
208}
Dhaval Patel6dee7ff2013-10-18 19:02:37 -0700209
210void mdp_gdsc_ctrl(uint8_t enable)
211{
212 uint32_t reg = 0;
213 reg = readl(MDP_GDSCR);
214 if (enable) {
215 if (!(reg & GDSC_POWER_ON_BIT)) {
216 reg &= ~(BIT(0) | GDSC_EN_FEW_WAIT_MASK);
217 reg |= GDSC_EN_FEW_WAIT_256_MASK;
218 writel(reg, MDP_GDSCR);
219 while(!(readl(MDP_GDSCR) & (GDSC_POWER_ON_BIT)));
220 } else {
221 dprintf(INFO, "MDP GDSC already enabled\n");
222 }
223 } else {
224 reg |= BIT(0);
225 writel(reg, MDP_GDSCR);
226 while(readl(MDP_GDSCR) & (GDSC_POWER_ON_BIT));
227 }
228}
229
230/* Configure MDP clock */
231void mdp_clock_enable(void)
232{
233 int ret;
234
235 /* Set MDP clock to 240MHz */
236 ret = clk_get_set_enable("mdp_ahb_clk", 0, 1);
237 if(ret)
238 {
239 dprintf(CRITICAL, "failed to set mdp_ahb_clk ret = %d\n", ret);
240 ASSERT(0);
241 }
242
243 ret = clk_get_set_enable("mdss_mdp_clk_src", 240000000, 1);
244 if(ret)
245 {
246 dprintf(CRITICAL, "failed to set mdp_clk_src ret = %d\n", ret);
247 ASSERT(0);
248 }
249
250 ret = clk_get_set_enable("mdss_vsync_clk", 0, 1);
251 if(ret)
252 {
253 dprintf(CRITICAL, "failed to set mdss vsync clk ret = %d\n", ret);
254 ASSERT(0);
255 }
256
257 ret = clk_get_set_enable("mdss_mdp_clk", 0, 1);
258 if(ret)
259 {
260 dprintf(CRITICAL, "failed to set mdp_clk ret = %d\n", ret);
261 ASSERT(0);
262 }
263
264 ret = clk_get_set_enable("mdss_mdp_lut_clk", 0, 1);
265 if(ret)
266 {
267 dprintf(CRITICAL, "failed to set lut_mdp clk ret = %d\n", ret);
268 ASSERT(0);
269 }
270}
271
272void mdp_clock_disable()
273{
274 clk_disable(clk_get("mdss_vsync_clk"));
275 clk_disable(clk_get("mdss_mdp_clk"));
276 clk_disable(clk_get("mdss_mdp_lut_clk"));
277 clk_disable(clk_get("mdss_mdp_clk_src"));
278 clk_disable(clk_get("mdp_ahb_clk"));
279
280}
281
282void mmss_bus_clock_enable(void)
283{
284 int ret;
285 /* Configure MMSSNOC AXI clock */
286 ret = clk_get_set_enable("mmss_mmssnoc_axi_clk", 100000000, 1);
287 if(ret)
288 {
289 dprintf(CRITICAL, "failed to set mmssnoc_axi_clk ret = %d\n", ret);
290 ASSERT(0);
291 }
292
293 /* Configure S0 AXI clock */
294 ret = clk_get_set_enable("mmss_s0_axi_clk", 100000000, 1);
295 if(ret)
296 {
297 dprintf(CRITICAL, "failed to set mmss_s0_axi_clk ret = %d\n", ret);
298 ASSERT(0);
299 }
300
301 /* Configure AXI clock */
302 ret = clk_get_set_enable("mdss_axi_clk", 100000000, 1);
303 if(ret)
304 {
305 dprintf(CRITICAL, "failed to set mdss_axi_clk ret = %d\n", ret);
306 ASSERT(0);
307 }
308}
309
310void mmss_bus_clock_disable(void)
311{
312 /* Disable MDSS AXI clock */
313 clk_disable(clk_get("mdss_axi_clk"));
314
315 /* Disable MMSSNOC S0AXI clock */
316 clk_disable(clk_get("mmss_s0_axi_clk"));
317
318 /* Disable MMSSNOC AXI clock */
319 clk_disable(clk_get("mmss_mmssnoc_axi_clk"));
320}
321
322void mmss_dsi_clock_enable(uint32_t dsi_pixel0_cfg_rcgr, uint32_t dual_dsi,
323 uint8_t pclk0_m, uint8_t pclk0_n, uint8_t pclk0_d)
324{
325 int ret;
326
327 /* Configure Byte clock -autopll- This will not change because
328 byte clock does not need any divider*/
329 writel(0x100, DSI_BYTE0_CFG_RCGR);
330 writel(0x1, DSI_BYTE0_CMD_RCGR);
331 writel(0x1, DSI_BYTE0_CBCR);
332
333 /* Configure Pixel clock */
334 writel(dsi_pixel0_cfg_rcgr, DSI_PIXEL0_CFG_RCGR);
335 writel(0x1, DSI_PIXEL0_CMD_RCGR);
336 writel(0x1, DSI_PIXEL0_CBCR);
337
338 writel(pclk0_m, DSI_PIXEL0_M);
339 writel(pclk0_n, DSI_PIXEL0_N);
340 writel(pclk0_d, DSI_PIXEL0_D);
341
342 /* Configure ESC clock */
343 ret = clk_get_set_enable("mdss_esc0_clk", 0, 1);
344 if(ret)
345 {
346 dprintf(CRITICAL, "failed to set esc0_clk ret = %d\n", ret);
347 ASSERT(0);
348 }
349
350 if (dual_dsi) {
351 /* Configure Byte 1 clock */
352 writel(0x100, DSI_BYTE1_CFG_RCGR);
353 writel(0x1, DSI_BYTE1_CMD_RCGR);
354 writel(0x1, DSI_BYTE1_CBCR);
355
356 /* Configure Pixel clock */
357 writel(dsi_pixel0_cfg_rcgr, DSI_PIXEL1_CFG_RCGR);
358 writel(0x1, DSI_PIXEL1_CMD_RCGR);
359 writel(0x1, DSI_PIXEL1_CBCR);
360
Dhaval Patel4ee51df2013-10-25 12:16:52 -0700361 writel(pclk0_m, DSI_PIXEL1_M);
362 writel(pclk0_n, DSI_PIXEL1_N);
363 writel(pclk0_d, DSI_PIXEL1_D);
Dhaval Patel6dee7ff2013-10-18 19:02:37 -0700364
365 /* Configure ESC clock */
366 ret = clk_get_set_enable("mdss_esc1_clk", 0, 1);
367 if(ret)
368 {
369 dprintf(CRITICAL, "failed to set esc1_clk ret = %d\n", ret);
370 ASSERT(0);
371 }
372 }
373}
374
375void mmss_dsi_clock_disable(uint32_t dual_dsi)
376{
377 /* Disable ESC clock */
378 clk_disable(clk_get("mdss_esc0_clk"));
379 writel(0x0, DSI_BYTE0_CBCR);
380 writel(0x0, DSI_PIXEL0_CBCR);
381
382 if (dual_dsi) {
383 /* Disable ESC clock */
384 clk_disable(clk_get("mdss_esc1_clk"));
385 writel(0x0, DSI_BYTE1_CBCR);
386 writel(0x0, DSI_PIXEL1_CBCR);
387 }
388}