blob: e2ee7d5c518e06ac140700dbae9e9caacde9fb1b [file] [log] [blame]
Channagoud Kadabide6bab02015-01-21 10:39:46 -08001/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
Channagoud Kadabied60a8b2014-06-27 15:35:09 -07002 *
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/timer.h>
35#include <platform/clock.h>
36#include <platform/iomap.h>
37#include <pm8x41.h>
38
39void clock_init_mmc(uint32_t interface)
40{
41 char clk_name[64];
42 int ret;
43
44 snprintf(clk_name, sizeof(clk_name), "sdc%u_iface_clk", interface);
45
46 /* enable interface clock */
47 ret = clk_get_set_enable(clk_name, 0, true);
48 if(ret)
49 {
50 dprintf(CRITICAL, "failed to set sdc%u_iface_clk ret = %d\n", interface, ret);
51 ASSERT(0);
52 }
53}
54
55/* Configure MMC clock */
56void clock_config_mmc(uint32_t interface, uint32_t freq)
57{
58 int ret = 0;
59 char clk_name[64];
60
61 snprintf(clk_name, sizeof(clk_name), "sdc%u_core_clk", interface);
62
63 if(freq == MMC_CLK_400KHZ)
64 {
65 ret = clk_get_set_enable(clk_name, 400000, true);
66 }
67 else if(freq == MMC_CLK_50MHZ)
68 {
69 ret = clk_get_set_enable(clk_name, 50000000, true);
70 }
71 else if(freq == MMC_CLK_96MHZ)
72 {
Channagoud Kadabi99d23702015-02-02 20:52:17 -080073 ret = clk_get_set_enable(clk_name, 96000000, true);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070074 }
75 else if(freq == MMC_CLK_192MHZ)
76 {
77 ret = clk_get_set_enable(clk_name, 192000000, true);
78 }
Channagoud Kadabi99d23702015-02-02 20:52:17 -080079 else if(freq == MMC_CLK_400MHZ)
80 {
81 ret = clk_get_set_enable(clk_name, 384000000, 1);
82 }
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070083 else
84 {
85 dprintf(CRITICAL, "sdc frequency (%u) is not supported\n", freq);
86 ASSERT(0);
87 }
88
89 if(ret)
90 {
91 dprintf(CRITICAL, "failed to set sdc%u_core_clk ret = %d\n", interface, ret);
92 ASSERT(0);
93 }
94}
95
96/* Configure UART clock based on the UART block id*/
97void clock_config_uart_dm(uint8_t id)
98{
99 int ret;
100 char iclk[64];
101 char cclk[64];
102
103 snprintf(iclk, sizeof(iclk), "uart%u_iface_clk", id);
104 snprintf(cclk, sizeof(cclk), "uart%u_core_clk", id);
105
106 ret = clk_get_set_enable(iclk, 0, true);
107 if(ret)
108 {
109 dprintf(CRITICAL, "failed to set uart%u_iface_clk ret = %d\n", id, ret);
110 ASSERT(0);
111 }
112
113 ret = clk_get_set_enable(cclk, 7372800, true);
114 if(ret)
115 {
116 dprintf(CRITICAL, "failed to set uart%u_core_clk ret = %d\n", id, ret);
117 ASSERT(0);
118 }
119}
120
121/* Function to asynchronously reset CE (Crypto Engine).
122 * Function assumes that all the CE clocks are off.
123 */
124static void ce_async_reset(uint8_t instance)
125{
126}
127
128void clock_ce_enable(uint8_t instance)
129{
130}
131
132void clock_ce_disable(uint8_t instance)
133{
134}
135
136void clock_config_ce(uint8_t instance)
137{
138 /* Need to enable the clock before disabling since the clk_disable()
139 * has a check to default to nop when the clk_enable() is not called
140 * on that particular clock.
141 */
142 clock_ce_enable(instance);
143
144 clock_ce_disable(instance);
145
146 ce_async_reset(instance);
147
148 clock_ce_enable(instance);
149
150}
151
152void clock_usb30_gdsc_enable(void)
153{
154 uint32_t reg = readl(GCC_USB30_GDSCR);
155
156 reg &= ~(0x1);
157
158 writel(reg, GCC_USB30_GDSCR);
159}
160
161/* enables usb30 clocks */
162void clock_usb30_init(void)
163{
164 int ret;
165
166 ret = clk_get_set_enable("usb30_iface_clk", 0, true);
167 if(ret)
168 {
169 dprintf(CRITICAL, "failed to set usb30_iface_clk. ret = %d\n", ret);
170 ASSERT(0);
171 }
172
173 clock_usb30_gdsc_enable();
174
Channagoud Kadabidf233d22015-02-11 11:56:48 -0800175 ret = clk_get_set_enable("usb30_master_clk", 150000000, true);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700176 if(ret)
177 {
178 dprintf(CRITICAL, "failed to set usb30_master_clk. ret = %d\n", ret);
179 ASSERT(0);
180 }
181
Channagoud Kadabidf233d22015-02-11 11:56:48 -0800182 ret = clk_get_set_enable("gcc_aggre2_usb3_axi_clk", 150000000, true);
183 if (ret)
184 {
185 dprintf(CRITICAL, "failed to set aggre2_usb3_axi_clk, ret = %d\n", ret);
186 ASSERT(0);
187 }
188
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700189 ret = clk_get_set_enable("usb30_phy_aux_clk", 1200000, true);
190 if(ret)
191 {
192 dprintf(CRITICAL, "failed to set usb30_phy_aux_clk. ret = %d\n", ret);
193 ASSERT(0);
194 }
195
196 ret = clk_get_set_enable("usb30_mock_utmi_clk", 60000000, true);
197 if(ret)
198 {
199 dprintf(CRITICAL, "failed to set usb30_mock_utmi_clk ret = %d\n", ret);
200 ASSERT(0);
201 }
202
203 ret = clk_get_set_enable("usb30_sleep_clk", 0, true);
204 if(ret)
205 {
206 dprintf(CRITICAL, "failed to set usb30_sleep_clk ret = %d\n", ret);
207 ASSERT(0);
208 }
209
210 ret = clk_get_set_enable("usb_phy_cfg_ahb2phy_clk", 0, true);
211 if(ret)
212 {
213 dprintf(CRITICAL, "failed to enable usb_phy_cfg_ahb2phy_clk = %d\n", ret);
214 ASSERT(0);
215 }
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700216}
217
218void clock_bumpup_pipe3_clk()
219{
220 int ret = 0;
221
222 ret = clk_get_set_enable("usb30_pipe_clk", 0, true);
223 if(ret)
224 {
225 dprintf(CRITICAL, "failed to set usb30_pipe_clk. ret = %d\n", ret);
226 ASSERT(0);
227 }
228
229 return;
230}
231
232void clock_reset_usb_phy()
233{
234 int ret;
235
236 struct clk *phy_reset_clk = NULL;
237 struct clk *pipe_reset_clk = NULL;
238
239 /* Look if phy com clock is present */
240 phy_reset_clk = clk_get("usb30_phy_reset");
241 ASSERT(phy_reset_clk);
242
243 pipe_reset_clk = clk_get("usb30_pipe_clk");
244 ASSERT(pipe_reset_clk);
245
246 /* ASSERT */
247 ret = clk_reset(phy_reset_clk, CLK_RESET_ASSERT);
248
249 if (ret)
250 {
251 dprintf(CRITICAL, "Failed to assert usb30_phy_reset clk\n");
252 return;
253 }
254
255 ret = clk_reset(pipe_reset_clk, CLK_RESET_ASSERT);
256 if (ret)
257 {
258 dprintf(CRITICAL, "Failed to assert usb30_pipe_clk\n");
259 goto deassert_phy_clk;
260 }
261
262 udelay(100);
263
264 /* DEASSERT */
265 ret = clk_reset(pipe_reset_clk, CLK_RESET_DEASSERT);
266 if (ret)
267 {
268 dprintf(CRITICAL, "Failed to deassert usb_pipe_clk\n");
269 return;
270 }
271
272deassert_phy_clk:
273
274 ret = clk_reset(phy_reset_clk, CLK_RESET_DEASSERT);
275 if (ret)
276 {
277 dprintf(CRITICAL, "Failed to deassert usb30_phy_com_reset clk\n");
278 return;
279 }
280}