blob: 1b4a11ec87de311798899abf3a09c1e4f98f554f [file] [log] [blame]
Amol Jadicd43ea02011-02-15 20:56:04 -08001/*
2 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 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 copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of Code Aurora nor
12 * the names of its contributors may be used to endorse or promote
13 * products derived from this software without specific prior written
14 * permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <reg.h>
31#include <platform/iomap.h>
Amol Jadic52c8a32011-07-12 11:27:04 -070032#include <platform/clock.h>
33#include <uart_dm.h>
34#include <gsbi.h>
Amol Jadi82254562011-06-27 11:25:48 -070035#include <mmc.h>
Shashank Mittaled177732011-05-06 19:12:59 -070036
Amol Jadicd43ea02011-02-15 20:56:04 -080037/* Set rate and enable the clock */
Amol Jadic52c8a32011-07-12 11:27:04 -070038void clock_config(uint32_t ns, uint32_t md, uint32_t ns_addr, uint32_t md_addr)
Amol Jadicd43ea02011-02-15 20:56:04 -080039{
Shashank Mittaled177732011-05-06 19:12:59 -070040 unsigned int val = 0;
41
42 /* Activate the reset for the M/N Counter */
43 val = 1 << 7;
44 writel(val, ns_addr);
45
46 /* Write the MD value into the MD register */
Kinson Chike5c93432011-06-17 09:10:29 -070047 if (md_addr != 0x0)
48 writel(md, md_addr);
Shashank Mittaled177732011-05-06 19:12:59 -070049
50 /* Write the ns value, and active reset for M/N Counter, again */
51 val = 1 << 7;
52 val |= ns;
53 writel(val, ns_addr);
54
55 /* De-activate the reset for M/N Counter */
56 val = 1 << 7;
57 val = ~val;
58 val = val & readl(ns_addr);
59 writel(val, ns_addr);
60
61 /* Enable the Clock Root */
62 val = 1 << 11;
63 val = val | readl(ns_addr);
64 writel(val, ns_addr);
65
66 /* Enable the Clock Branch */
67 val = 1 << 9;
68 val = val | readl(ns_addr);
69 writel(val, ns_addr);
70
71 /* Enable the M/N Counter */
72 val = 1 << 8;
73 val = val | readl(ns_addr);
74 writel(val, ns_addr);
Amol Jadicd43ea02011-02-15 20:56:04 -080075}
76
Kinson Chike5c93432011-06-17 09:10:29 -070077/* Write the M,N,D values and enable the MMSS Clocks */
Ajay Dudanib01e5062011-12-03 23:23:42 -080078void config_mmss_clk(uint32_t ns,
79 uint32_t md,
80 uint32_t cc,
81 uint32_t ns_addr, uint32_t md_addr, uint32_t cc_addr)
82{
Kinson Chike5c93432011-06-17 09:10:29 -070083 unsigned int val = 0;
84
85 clock_config(ns, md, ns_addr, md_addr);
86
87 /* Enable MND counter */
88 val = cc | (1 << 5);
89 val = val | readl(cc_addr);
90 writel(val, cc_addr);
91
92 /* Enable the root of the clock tree */
93 val = 1 << 2;
94 val = val | readl(cc_addr);
95 writel(val, cc_addr);
96
97 /* Enable the Pixel Clock */
98 val = 1 << 0;
99 val = val | readl(cc_addr);
100 writel(val, cc_addr);
101
102 /* Force On */
103 val = 1 << 31;
104 val = val | readl(cc_addr);
105 writel(val, cc_addr);
106}
107
Shashank Mittaled177732011-05-06 19:12:59 -0700108void pll8_enable(void)
Amol Jadicd43ea02011-02-15 20:56:04 -0800109{
Shashank Mittaled177732011-05-06 19:12:59 -0700110 unsigned int curr_value = 0;
111
112 /* Vote for PLL8 to be enabled */
113 curr_value = readl(MSM_BOOT_PLL_ENABLE_SC0);
114 curr_value |= (1 << 8);
115 writel(curr_value, MSM_BOOT_PLL_ENABLE_SC0);
116
117 /* Proceed only after PLL is enabled */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800118 while (!(readl(MSM_BOOT_PLL8_STATUS) & (1 << 16))) ;
Amol Jadicd43ea02011-02-15 20:56:04 -0800119}
120
121void hsusb_clock_init(void)
122{
Shashank Mittaled177732011-05-06 19:12:59 -0700123 /* TODO: Enable pll8 here */
124 /* Setup USB AHB clock */
125
Shashank Mittaled177732011-05-06 19:12:59 -0700126 /* Setup XCVR clock */
Amol Jadic52c8a32011-07-12 11:27:04 -0700127 clock_config(USB_XCVR_CLK_NS,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800128 USB_XCVR_CLK_MD,
129 USB_HS1_XCVR_FS_CLK_NS, USB_HS1_XCVR_FS_CLK_MD);
Amol Jadicd43ea02011-02-15 20:56:04 -0800130}
Amol Jadic52c8a32011-07-12 11:27:04 -0700131
132/* Configure UART clock - based on the gsbi id */
133void clock_config_uart_dm(uint8_t id)
134{
135 /* Enable gsbi_uart_clk */
136 clock_config(UART_DM_CLK_NS_115200,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800137 UART_DM_CLK_MD_115200,
138 GSBIn_UART_APPS_NS(id), GSBIn_UART_APPS_MD(id));
Amol Jadic52c8a32011-07-12 11:27:04 -0700139
140 /* Enable gsbi_pclk */
141 writel(GSBI_HCLK_CTL_CLK_ENA << GSBI_HCLK_CTL_S, GSBIn_HCLK_CTL(id));
142}
143
144/* Configure i2c clock */
145void clock_config_i2c(uint8_t id, uint32_t freq)
146{
147 uint32_t ns;
148 uint32_t md;
149
Ajay Dudanib01e5062011-12-03 23:23:42 -0800150 switch (freq) {
Amol Jadic52c8a32011-07-12 11:27:04 -0700151 case 24000000:
152 ns = I2C_CLK_NS_24MHz;
153 md = I2C_CLK_MD_24MHz;
154 break;
155 default:
156 ASSERT(0);
157 }
158
159 clock_config(ns, md, GSBIn_QUP_APPS_NS(id), GSBIn_QUP_APPS_MD(id));
160
161 /* Enable the GSBI HCLK */
162 writel(GSBI_HCLK_CTL_CLK_ENA << GSBI_HCLK_CTL_S, GSBIn_HCLK_CTL(id));
163}
164
Ajay Dudanib01e5062011-12-03 23:23:42 -0800165void pll1_enable(void)
166{
Kinson Chike5c93432011-06-17 09:10:29 -0700167 uint32_t val = 0;
168
169 /* Reset MND divider */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800170 val |= (1 << 2);
Kinson Chike5c93432011-06-17 09:10:29 -0700171 writel(val, MM_PLL1_MODE_REG);
172
173 /* Use PLL -- Disable Bypass */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800174 val |= (1 << 1);
Kinson Chike5c93432011-06-17 09:10:29 -0700175 writel(val, MM_PLL1_MODE_REG);
176
177 /* Activate PLL out control */
178 val |= 1;
179 writel(val, MM_PLL1_MODE_REG);
180
Ajay Dudanib01e5062011-12-03 23:23:42 -0800181 while (!readl(MM_PLL1_STATUS_REG)) ;
Kinson Chike5c93432011-06-17 09:10:29 -0700182}
183
Amol Jadi82254562011-06-27 11:25:48 -0700184void config_mdp_lut_clk(void)
185{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800186 /* Force on */
Kinson Chike5c93432011-06-17 09:10:29 -0700187 writel(MDP_LUT_VAL, MDP_LUT_CC_REG);
188}
189
190/* Turn on MDP related clocks and pll's for MDP */
191void mdp_clock_init(void)
192{
193 /* Turn on the PLL1, as source for MDP clock */
194 pll1_enable();
195
196 /* Turn on MDP clk */
197 config_mmss_clk(MDP_NS_VAL, MDP_MD_VAL,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800198 MDP_CC_VAL, MDP_NS_REG, MDP_MD_REG, MDP_CC_REG);
Kinson Chike5c93432011-06-17 09:10:29 -0700199
200 /* Seems to lose pixels without this from status 0x051E0048 */
201 config_mdp_lut_clk();
202}
203
204/* Initialize all clocks needed by Display */
Amol Jadi82254562011-06-27 11:25:48 -0700205void mmss_clock_init(void)
206{
Kinson Chike5c93432011-06-17 09:10:29 -0700207 /* Configure Pixel clock */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800208 config_mmss_clk(PIXEL_NS_VAL, PIXEL_MD_VAL, PIXEL_CC_VAL, PIXEL_NS_REG,
209 PIXEL_MD_REG, PIXEL_CC_REG);
Kinson Chike5c93432011-06-17 09:10:29 -0700210
211 /* Configure DSI clock */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800212 config_mmss_clk(DSI_NS_VAL, DSI_MD_VAL, DSI_CC_VAL, DSI_NS_REG,
213 DSI_MD_REG, DSI_CC_REG);
Kinson Chike5c93432011-06-17 09:10:29 -0700214
215 /* Configure Byte clock */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800216 config_mmss_clk(BYTE_NS_VAL, 0x0, BYTE_CC_VAL, BYTE_NS_REG, 0x0,
217 BYTE_CC_REG);
Kinson Chike5c93432011-06-17 09:10:29 -0700218
219 /* Configure ESC clock */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800220 config_mmss_clk(ESC_NS_VAL, 0x0, ESC_CC_VAL, ESC_NS_REG, 0x0,
221 ESC_CC_REG);
Kinson Chike5c93432011-06-17 09:10:29 -0700222}
Amol Jadi82254562011-06-27 11:25:48 -0700223
224/* Intialize MMC clock */
225void clock_init_mmc(uint32_t interface)
226{
227 /* Nothing to be done. */
228}
229
230/* Configure MMC clock */
231void clock_config_mmc(uint32_t interface, uint32_t freq)
232{
233 uint32_t reg = 0;
234
Ajay Dudanib01e5062011-12-03 23:23:42 -0800235 switch (freq) {
Amol Jadi82254562011-06-27 11:25:48 -0700236 case MMC_CLK_400KHZ:
237 clock_config(SDC_CLK_NS_400KHZ,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800238 SDC_CLK_MD_400KHZ,
239 SDC_NS(interface), SDC_MD(interface));
Amol Jadi82254562011-06-27 11:25:48 -0700240 break;
241 case MMC_CLK_48MHZ:
Ajay Dudanib01e5062011-12-03 23:23:42 -0800242 case MMC_CLK_50MHZ: /* Max supported is 48MHZ */
Amol Jadi82254562011-06-27 11:25:48 -0700243 clock_config(SDC_CLK_NS_48MHZ,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800244 SDC_CLK_MD_48MHZ,
245 SDC_NS(interface), SDC_MD(interface));
Amol Jadi82254562011-06-27 11:25:48 -0700246 break;
247 default:
248 ASSERT(0);
249
250 }
251
252 reg |= MMC_BOOT_MCI_CLK_ENABLE;
253 reg |= MMC_BOOT_MCI_CLK_ENA_FLOW;
254 reg |= MMC_BOOT_MCI_CLK_IN_FEEDBACK;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800255 writel(reg, MMC_BOOT_MCI_CLK);
Amol Jadi82254562011-06-27 11:25:48 -0700256}
Shashank Mittal1fcde7a2011-07-25 13:41:50 -0700257
258/* Configure crypto engine clock */
259void ce_clock_init(void)
260{
261 /* Enable HCLK for CE1 */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800262 writel((1 << 4), CE1_HCLK_CTL);
Shashank Mittal1fcde7a2011-07-25 13:41:50 -0700263 /* Enable core clk for CE1 */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800264 writel((1 << 4), CE1_CORE_CLK_CTL);
Shashank Mittal1fcde7a2011-07-25 13:41:50 -0700265 return;
266}