blob: 6d65504cc03d8f9961a9b078089914ee3439e75f [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>
Shashank Mittaled177732011-05-06 19:12:59 -070035
Amol Jadicd43ea02011-02-15 20:56:04 -080036/* Set rate and enable the clock */
Amol Jadic52c8a32011-07-12 11:27:04 -070037void clock_config(uint32_t ns, uint32_t md, uint32_t ns_addr, uint32_t md_addr)
Amol Jadicd43ea02011-02-15 20:56:04 -080038{
Shashank Mittaled177732011-05-06 19:12:59 -070039 unsigned int val = 0;
40
41 /* Activate the reset for the M/N Counter */
42 val = 1 << 7;
43 writel(val, ns_addr);
44
45 /* Write the MD value into the MD register */
Kinson Chike5c93432011-06-17 09:10:29 -070046 if (md_addr != 0x0)
47 writel(md, md_addr);
Shashank Mittaled177732011-05-06 19:12:59 -070048
49 /* Write the ns value, and active reset for M/N Counter, again */
50 val = 1 << 7;
51 val |= ns;
52 writel(val, ns_addr);
53
54 /* De-activate the reset for M/N Counter */
55 val = 1 << 7;
56 val = ~val;
57 val = val & readl(ns_addr);
58 writel(val, ns_addr);
59
60 /* Enable the Clock Root */
61 val = 1 << 11;
62 val = val | readl(ns_addr);
63 writel(val, ns_addr);
64
65 /* Enable the Clock Branch */
66 val = 1 << 9;
67 val = val | readl(ns_addr);
68 writel(val, ns_addr);
69
70 /* Enable the M/N Counter */
71 val = 1 << 8;
72 val = val | readl(ns_addr);
73 writel(val, ns_addr);
Amol Jadicd43ea02011-02-15 20:56:04 -080074}
75
Kinson Chike5c93432011-06-17 09:10:29 -070076/* Write the M,N,D values and enable the MMSS Clocks */
77void config_mmss_clk( uint32_t ns,
78 uint32_t md,
79 uint32_t cc,
80 uint32_t ns_addr,
81 uint32_t md_addr,
82 uint32_t cc_addr){
83 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 */
118 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,
128 USB_XCVR_CLK_MD,
Shashank Mittaled177732011-05-06 19:12:59 -0700129 USB_HS1_XCVR_FS_CLK_NS,
130 USB_HS1_XCVR_FS_CLK_MD);
Amol Jadicd43ea02011-02-15 20:56:04 -0800131}
Amol Jadic52c8a32011-07-12 11:27:04 -0700132
133/* Configure UART clock - based on the gsbi id */
134void clock_config_uart_dm(uint8_t id)
135{
136 /* Enable gsbi_uart_clk */
137 clock_config(UART_DM_CLK_NS_115200,
138 UART_DM_CLK_MD_115200,
139 GSBIn_UART_APPS_NS(id),
140 GSBIn_UART_APPS_MD(id));
141
142
143 /* Enable gsbi_pclk */
144 writel(GSBI_HCLK_CTL_CLK_ENA << GSBI_HCLK_CTL_S, GSBIn_HCLK_CTL(id));
145}
146
147/* Configure i2c clock */
148void clock_config_i2c(uint8_t id, uint32_t freq)
149{
150 uint32_t ns;
151 uint32_t md;
152
153 switch (freq)
154 {
155 case 24000000:
156 ns = I2C_CLK_NS_24MHz;
157 md = I2C_CLK_MD_24MHz;
158 break;
159 default:
160 ASSERT(0);
161 }
162
163 clock_config(ns, md, GSBIn_QUP_APPS_NS(id), GSBIn_QUP_APPS_MD(id));
164
165 /* Enable the GSBI HCLK */
166 writel(GSBI_HCLK_CTL_CLK_ENA << GSBI_HCLK_CTL_S, GSBIn_HCLK_CTL(id));
167}
168
Kinson Chike5c93432011-06-17 09:10:29 -0700169void pll1_enable(void){
170 uint32_t val = 0;
171
172 /* Reset MND divider */
173 val |= (1<<2);
174 writel(val, MM_PLL1_MODE_REG);
175
176 /* Use PLL -- Disable Bypass */
177 val |= (1<<1);
178 writel(val, MM_PLL1_MODE_REG);
179
180 /* Activate PLL out control */
181 val |= 1;
182 writel(val, MM_PLL1_MODE_REG);
183
184 while (!readl(MM_PLL1_STATUS_REG));
185}
186
187void config_mdp_lut_clk(void){
188 /* Force on*/
189 writel(MDP_LUT_VAL, MDP_LUT_CC_REG);
190}
191
192/* Turn on MDP related clocks and pll's for MDP */
193void mdp_clock_init(void)
194{
195 /* Turn on the PLL1, as source for MDP clock */
196 pll1_enable();
197
198 /* Turn on MDP clk */
199 config_mmss_clk(MDP_NS_VAL, MDP_MD_VAL,
200 MDP_CC_VAL, MDP_NS_REG, MDP_MD_REG, MDP_CC_REG);
201
202 /* Seems to lose pixels without this from status 0x051E0048 */
203 config_mdp_lut_clk();
204}
205
206/* Initialize all clocks needed by Display */
207void mmss_clock_init(void){
208 /* Configure Pixel clock */
209 config_mmss_clk(PIXEL_NS_VAL, PIXEL_MD_VAL, PIXEL_CC_VAL, PIXEL_NS_REG, PIXEL_MD_REG, PIXEL_CC_REG);
210
211 /* Configure DSI clock */
212 config_mmss_clk(DSI_NS_VAL, DSI_MD_VAL, DSI_CC_VAL, DSI_NS_REG, DSI_MD_REG, DSI_CC_REG);
213
214 /* Configure Byte clock */
215 config_mmss_clk(BYTE_NS_VAL, 0x0, BYTE_CC_VAL, BYTE_NS_REG, 0x0, BYTE_CC_REG);
216
217 /* Configure ESC clock */
218 config_mmss_clk(ESC_NS_VAL, 0x0, ESC_CC_VAL, ESC_NS_REG, 0x0, ESC_CC_REG);
219}