blob: fca135849489292e2f497db52bbc8127c0fb5fea [file] [log] [blame]
Brian Swetland9a477532009-01-01 11:40:02 -08001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
Shashank Mittal52525ff2010-04-13 11:11:10 -07005 * Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved.
6 *
Brian Swetland9a477532009-01-01 11:40:02 -08007 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <debug.h>
32#include <reg.h>
33
34#include <platform/iomap.h>
Brian Swetland9a477532009-01-01 11:40:02 -080035#define ACPU_CLK 0 /* Applications processor clock */
36#define ADM_CLK 1 /* Applications data mover clock */
37#define ADSP_CLK 2 /* ADSP clock */
38#define EBI1_CLK 3 /* External bus interface 1 clock */
39#define EBI2_CLK 4 /* External bus interface 2 clock */
40#define ECODEC_CLK 5 /* External CODEC clock */
41#define EMDH_CLK 6 /* External MDDI host clock */
42#define GP_CLK 7 /* General purpose clock */
43#define GRP_CLK 8 /* Graphics clock */
44#define I2C_CLK 9 /* I2C clock */
45#define ICODEC_RX_CLK 10 /* Internal CODEX RX clock */
46#define ICODEC_TX_CLK 11 /* Internal CODEX TX clock */
47#define IMEM_CLK 12 /* Internal graphics memory clock */
48#define MDC_CLK 13 /* MDDI client clock */
49#define MDP_CLK 14 /* Mobile display processor clock */
50#define PBUS_CLK 15 /* Peripheral bus clock */
51#define PCM_CLK 16 /* PCM clock */
52#define PMDH_CLK 17 /* Primary MDDI host clock */
53#define SDAC_CLK 18 /* Stereo DAC clock */
54#define SDC1_CLK 19 /* Secure Digital Card clocks */
55#define SDC1_PCLK 20
56#define SDC2_CLK 21
57#define SDC2_PCLK 22
58#define SDC3_CLK 23
59#define SDC3_PCLK 24
60#define SDC4_CLK 25
61#define SDC4_PCLK 26
62#define TSIF_CLK 27 /* Transport Stream Interface clocks */
63#define TSIF_REF_CLK 28
64#define TV_DAC_CLK 29 /* TV clocks */
65#define TV_ENC_CLK 30
66#define UART1_CLK 31 /* UART clocks */
67#define UART2_CLK 32
68#define UART3_CLK 33
69#define UART1DM_CLK 34
70#define UART2DM_CLK 35
71#define USB_HS_CLK 36 /* High speed USB core clock */
72#define USB_HS_PCLK 37 /* High speed USB pbus clock */
73#define USB_OTG_CLK 38 /* Full speed USB clock */
74#define VDC_CLK 39 /* Video controller clock */
75#define VFE_CLK 40 /* Camera / Video Front End clock */
76#define VFE_MDC_CLK 41 /* VFE MDDI client clock */
77
78/* qsd8k adds... */
79#define MDP_LCDC_PCLK_CLK 42
80#define MDP_LCDC_PAD_PCLK_CLK 43
81#define MDP_VSYNC_CLK 44
82
Chandan Uddaraju0af34822010-10-07 14:46:58 -070083#define P_USB_HS_CORE_CLK 53 /* High speed USB 1 core clock */
Shashank Mittal37040832010-08-24 15:57:57 -070084/* msm7x30 adds... */
Chandan Uddarajuc009e4d2010-09-08 17:06:45 -070085#define PMDH_P_CLK 82
Shashank Mittal37040832010-08-24 15:57:57 -070086#define MDP_P_CLK 86
87
Brian Swetland9a477532009-01-01 11:40:02 -080088enum {
89 PCOM_CMD_IDLE = 0x0,
90 PCOM_CMD_DONE,
91 PCOM_RESET_APPS,
92 PCOM_RESET_CHIP,
93 PCOM_CONFIG_NAND_MPU,
94 PCOM_CONFIG_USB_CLKS,
95 PCOM_GET_POWER_ON_STATUS,
96 PCOM_GET_WAKE_UP_STATUS,
97 PCOM_GET_BATT_LEVEL,
98 PCOM_CHG_IS_CHARGING,
99 PCOM_POWER_DOWN,
100 PCOM_USB_PIN_CONFIG,
101 PCOM_USB_PIN_SEL,
102 PCOM_SET_RTC_ALARM,
103 PCOM_NV_READ,
104 PCOM_NV_WRITE,
105 PCOM_GET_UUID_HIGH,
106 PCOM_GET_UUID_LOW,
107 PCOM_GET_HW_ENTROPY,
108 PCOM_RPC_GPIO_TLMM_CONFIG_REMOTE,
109 PCOM_CLKCTL_RPC_ENABLE,
110 PCOM_CLKCTL_RPC_DISABLE,
111 PCOM_CLKCTL_RPC_RESET,
112 PCOM_CLKCTL_RPC_SET_FLAGS,
113 PCOM_CLKCTL_RPC_SET_RATE,
114 PCOM_CLKCTL_RPC_MIN_RATE,
115 PCOM_CLKCTL_RPC_MAX_RATE,
116 PCOM_CLKCTL_RPC_RATE,
117 PCOM_CLKCTL_RPC_PLL_REQUEST,
118 PCOM_CLKCTL_RPC_ENABLED,
119 PCOM_VREG_SWITCH,
120 PCOM_VREG_SET_LEVEL,
121 PCOM_GPIO_TLMM_CONFIG_GROUP,
122 PCOM_GPIO_TLMM_UNCONFIG_GROUP,
123 PCOM_NV_READ_HIGH_BITS,
124 PCOM_NV_WRITE_HIGH_BITS,
Shashank Mittal37040832010-08-24 15:57:57 -0700125 PCOM_RPC_GPIO_TLMM_CONFIG_EX = 0x25,
Chandan Uddaraju7f5b9012010-02-06 16:37:48 -0800126 PCOM_RESERVED_101 = 0x65,
127 PCOM_MSM_HSUSB_PHY_RESET,
128 PCOM_GET_BATT_MV_LEVEL,
129 PCOM_CHG_USB_IS_PC_CONNECTED,
130 PCOM_CHG_USB_IS_CHARGER_CONNECTED,
131 PCOM_CHG_USB_IS_DISCONNECTED,
132 PCOM_CHG_USB_I_AVAILABLE,
Brian Swetland9a477532009-01-01 11:40:02 -0800133 PCOM_NUM_CMDS,
134};
135
136enum {
137 PCOM_INVALID_STATUS = 0x0,
138 PCOM_READY,
139 PCOM_CMD_RUNNING,
140 PCOM_CMD_SUCCESS,
141 PCOM_CMD_FAIL,
142};
143
Ajay Dudani232ce812009-12-02 00:14:11 -0800144#ifndef PLATFORM_MSM7X30
Brian Swetland9a477532009-01-01 11:40:02 -0800145#define MSM_A2M_INT(n) (MSM_CSR_BASE + 0x400 + (n) * 4)
Ajay Dudani232ce812009-12-02 00:14:11 -0800146#endif
Brian Swetland9a477532009-01-01 11:40:02 -0800147static inline void notify_other_proc_comm(void)
148{
Ajay Dudani232ce812009-12-02 00:14:11 -0800149#ifndef PLATFORM_MSM7X30
150 writel(1, MSM_A2M_INT(6));
151#else
152 writel(1<<6, (MSM_GCC_BASE + 0x8));
153#endif
Brian Swetland9a477532009-01-01 11:40:02 -0800154}
155
156#define APP_COMMAND (MSM_SHARED_BASE + 0x00)
157#define APP_STATUS (MSM_SHARED_BASE + 0x04)
158#define APP_DATA1 (MSM_SHARED_BASE + 0x08)
159#define APP_DATA2 (MSM_SHARED_BASE + 0x0C)
160
161#define MDM_COMMAND (MSM_SHARED_BASE + 0x10)
162#define MDM_STATUS (MSM_SHARED_BASE + 0x14)
163#define MDM_DATA1 (MSM_SHARED_BASE + 0x18)
164#define MDM_DATA2 (MSM_SHARED_BASE + 0x1C)
165
166int msm_proc_comm(unsigned cmd, unsigned *data1, unsigned *data2)
167{
168 int ret = -1;
169 unsigned status;
170
171// dprintf(INFO, "proc_comm(%d,%d,%d)\n",
172// cmd, data1 ? *data1 : 0, data2 ? *data2 : 0);
173 while (readl(MDM_STATUS) != PCOM_READY) {
174 /* XXX check for A9 reset */
175 }
176
177 writel(cmd, APP_COMMAND);
178 if (data1)
179 writel(*data1, APP_DATA1);
180 if (data2)
181 writel(*data2, APP_DATA2);
182
183// dprintf(INFO, "proc_comm tx\n");
184 notify_other_proc_comm();
185 while (readl(APP_COMMAND) != PCOM_CMD_DONE) {
186 /* XXX check for A9 reset */
187 }
188
189 status = readl(APP_STATUS);
190// dprintf(INFO, "proc_comm status %d\n", status);
191
192 if (status != PCOM_CMD_FAIL) {
193 if (data1)
194 *data1 = readl(APP_DATA1);
195 if (data2)
196 *data2 = readl(APP_DATA2);
197 ret = 0;
198 }
199
200 return ret;
201}
202
203static int clock_enable(unsigned id)
204{
205 return msm_proc_comm(PCOM_CLKCTL_RPC_ENABLE, &id, 0);
206}
207
208static int clock_disable(unsigned id)
209{
210 return msm_proc_comm(PCOM_CLKCTL_RPC_DISABLE, &id, 0);
211}
212
213static int clock_set_rate(unsigned id, unsigned rate)
214{
215 return msm_proc_comm(PCOM_CLKCTL_RPC_SET_RATE, &id, &rate);
216}
217
Shashank Mittal52525ff2010-04-13 11:11:10 -0700218static int clock_get_rate(unsigned id)
219{
220 if (msm_proc_comm(PCOM_CLKCTL_RPC_RATE, &id, 0)) {
221 return -1;
222 } else {
223 return (int) id;
224 }
225}
226
Ajay Dudani7d605522010-10-01 19:52:37 -0700227void usb_clock_init()
228{
229 clock_enable(USB_HS_PCLK);
230 clock_enable(USB_HS_CLK);
Chandan Uddaraju0af34822010-10-07 14:46:58 -0700231 clock_enable(P_USB_HS_CORE_CLK);
Ajay Dudani7d605522010-10-01 19:52:37 -0700232}
233
Brian Swetland9a477532009-01-01 11:40:02 -0800234void lcdc_clock_init(unsigned rate)
235{
Shashank Mittal37040832010-08-24 15:57:57 -0700236 clock_set_rate(MDP_LCDC_PCLK_CLK, rate);
Brian Swetland9a477532009-01-01 11:40:02 -0800237 clock_enable(MDP_LCDC_PCLK_CLK);
238 clock_enable(MDP_LCDC_PAD_PCLK_CLK);
Shashank Mittal37040832010-08-24 15:57:57 -0700239}
Brian Swetland9a477532009-01-01 11:40:02 -0800240
Shashank Mittal37040832010-08-24 15:57:57 -0700241void mdp_clock_init (unsigned rate)
242{
243 clock_set_rate(MDP_CLK, rate);
Brian Swetland9a477532009-01-01 11:40:02 -0800244 clock_enable(MDP_CLK);
Shashank Mittal37040832010-08-24 15:57:57 -0700245 clock_enable(MDP_P_CLK);
Brian Swetland9a477532009-01-01 11:40:02 -0800246}
247
248void uart3_clock_init(void)
249{
250 clock_enable(UART3_CLK);
251 clock_set_rate(UART3_CLK, 19200000 / 4);
252}
Brian Swetland977224f2009-01-02 01:33:04 -0800253
Shashank Mittal1ddc04c2010-12-21 14:39:07 -0800254void uart2_clock_init(void)
255{
256 clock_enable(UART2_CLK);
257 clock_set_rate(UART2_CLK, 19200000);
258}
259
Shashank Mittal2fad67f2011-04-08 19:45:10 -0700260void uart1_clock_init(void)
261{
262 clock_enable(UART1_CLK);
263 clock_set_rate(UART1_CLK, 19200000 / 4);
264}
265
Dima Zavin36785e32009-01-28 17:26:43 -0800266void mddi_clock_init(unsigned num, unsigned rate)
267{
268 unsigned clock_id;
269
270 if (num == 0)
271 clock_id = PMDH_CLK;
272 else
273 clock_id = EMDH_CLK;
274
275 clock_enable(clock_id);
276 clock_set_rate(clock_id, rate);
Chandan Uddarajuc009e4d2010-09-08 17:06:45 -0700277#ifdef PLATFORM_MSM7X30
278 clock_enable (PMDH_P_CLK);
279#endif
Dima Zavin36785e32009-01-28 17:26:43 -0800280}
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800281
282void reboot(unsigned reboot_reason)
283{
284 msm_proc_comm(PCOM_RESET_CHIP, &reboot_reason, 0);
285 for (;;) ;
286}
Chandan Uddaraju7f5b9012010-02-06 16:37:48 -0800287
288/* Apps processor calls this API to tell modem processor that a PC USB
289 * is connected return true if the USB HOST PC charger charging is
290 * supported */
291int charger_usb_is_pc_connected(void)
292{
293 unsigned charging_supported = 0;
294 unsigned m = 0;
295 msm_proc_comm(PCOM_CHG_USB_IS_PC_CONNECTED, &charging_supported, &m);
296 return charging_supported;
297}
298
299/* Apps processor calls this API to tell modem processor that a USB Wall
300 * charger is connected returns true if the USB WALL charger charging is
301 * supported */
302int charger_usb_is_charger_connected(void)
303{
304 unsigned charging_supported = 0;
305 unsigned m = 0;
306 msm_proc_comm(PCOM_CHG_USB_IS_CHARGER_CONNECTED, &charging_supported, &m);
307 return charging_supported;
308}
309
310/* Apps processor calls this API to tell modem processor that a USB cable is
311 * disconnected return true is charging is supported in the system */
312int charger_usb_disconnected(void)
313{
314 unsigned charging_supported = 0;
315 unsigned m = 0;
316 msm_proc_comm(PCOM_CHG_USB_IS_DISCONNECTED, &charging_supported, &m);
317 return charging_supported;
318}
319
320/* current parameter passed is the amount of current that the charger needs
321 * to draw from USB */
322int charger_usb_i(unsigned current)
323{
324 unsigned charging_supported = 0;
325 msm_proc_comm(PCOM_CHG_USB_I_AVAILABLE, &current, &charging_supported);
326 return charging_supported;
327}
Shashank Mittal52525ff2010-04-13 11:11:10 -0700328
329int mmc_clock_enable_disable (unsigned id, unsigned enable)
330{
331 if(enable)
332 {
333 return clock_enable(id); //Enable mmc clock rate
334 }
335 else
336 {
337 return clock_disable(id); //Disable mmc clock rate
338 }
339}
340
341int mmc_clock_set_rate(unsigned id, unsigned rate)
342{
343 return clock_set_rate(id, rate); //Set mmc clock rate
344}
345
346int mmc_clock_get_rate(unsigned id)
347{
348 return clock_get_rate(id); //Get mmc clock rate
349}
350
Shashank Mittal37040832010-08-24 15:57:57 -0700351int gpio_tlmm_config(unsigned config, unsigned disable)
352{
353 return msm_proc_comm(PCOM_RPC_GPIO_TLMM_CONFIG_EX, &config, &disable);
354}
355
356int vreg_set_level(unsigned id, unsigned mv)
357{
358 return msm_proc_comm(PCOM_VREG_SET_LEVEL, &id, &mv);
359}
360
361int vreg_enable(unsigned id)
362{
363 int enable = 1;
364 return msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
365
366}
367
368int vreg_disable(unsigned id)
369{
370 int enable = 0;
371 return msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
372}