blob: 8ee11c3dca449271219fe16c2ef6af52d3fd7033 [file] [log] [blame]
Shashank Mittal23b8f422010-04-16 19:27:21 -07001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Duy Truongf3ac7b32013-02-13 01:07:28 -08004 * Copyright (c) 2009-2012, The Linux Foundation. All rights reserved.
Shashank Mittal23b8f422010-04-16 19:27:21 -07005 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google, Inc. nor the names of its contributors
16 * may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <debug.h>
34#include <dev/keys.h>
Kinson Chikea646242011-09-01 13:53:16 -070035#include <dev/ssbi.h>
Greg Griscod2471ef2011-07-14 13:00:42 -070036#include <dev/gpio.h>
Shashank Mittal23b8f422010-04-16 19:27:21 -070037#include <lib/ptable.h>
38#include <dev/flash.h>
39#include <smem.h>
Greg Griscod6250552011-06-29 14:40:23 -070040#include <mmc.h>
41#include <platform/timer.h>
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -070042#include <platform/iomap.h>
Amol Jadic52c8a32011-07-12 11:27:04 -070043#include <platform/gpio.h>
Ajay Dudanid04110c2011-01-17 23:55:07 -080044#include <baseband.h>
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -070045#include <reg.h>
Greg Griscod6250552011-06-29 14:40:23 -070046#include <platform.h>
Amol Jadic52c8a32011-07-12 11:27:04 -070047#include <gsbi.h>
Greg Griscod2471ef2011-07-14 13:00:42 -070048#include <platform/scm-io.h>
Wentao Xu8d6150c2011-06-22 11:03:18 -040049#include <platform/machtype.h>
Deepa Dinamani5e5c21a2012-02-16 18:59:57 -080050#include <crypto_hash.h>
Shashank Mittal23b8f422010-04-16 19:27:21 -070051
Ajay Dudanib01e5062011-12-03 23:23:42 -080052static const uint8_t uart_gsbi_id = GSBI_ID_12;
Amol Jadic52c8a32011-07-12 11:27:04 -070053
Deepa Dinamani5e5c21a2012-02-16 18:59:57 -080054/* Setting this variable to different values defines the
55 * behavior of CE engine:
56 * platform_ce_type = CRYPTO_ENGINE_TYPE_NONE : No CE engine
57 * platform_ce_type = CRYPTO_ENGINE_TYPE_SW : Software CE engine
58 * platform_ce_type = CRYPTO_ENGINE_TYPE_HW : Hardware CE engine
59 * Behavior is determined in the target code.
60 */
61static crypto_engine_type platform_ce_type = CRYPTO_ENGINE_TYPE_SW;
62
Shashank Mittal23b8f422010-04-16 19:27:21 -070063void keypad_init(void);
Greg Griscod2471ef2011-07-14 13:00:42 -070064extern void dmb(void);
Shashank Mittal23b8f422010-04-16 19:27:21 -070065
Shashank Mittal23b8f422010-04-16 19:27:21 -070066int target_is_emmc_boot(void);
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -070067void debug_led_write(char);
68char debug_led_read();
Ajay Dudanib01e5062011-12-03 23:23:42 -080069uint32_t platform_id_read(void);
Greg Griscod6250552011-06-29 14:40:23 -070070void setup_fpga(void);
Shashank Mittal6df16072011-07-14 18:44:01 -070071int pm8901_reset_pwr_off(int reset);
72int pm8058_reset_pwr_off(int reset);
73int pm8058_rtc0_alarm_irq_disable(void);
74static void target_shutdown_for_rtc_alarm(void);
Shashank Mittal23b8f422010-04-16 19:27:21 -070075void target_init(void)
76{
Ajay Dudanib01e5062011-12-03 23:23:42 -080077 target_shutdown_for_rtc_alarm();
78 dprintf(INFO, "target_init()\n");
Shashank Mittal23b8f422010-04-16 19:27:21 -070079
Ajay Dudanib01e5062011-12-03 23:23:42 -080080 setup_fpga();
Subbaraman Narayanamurthy50d936f2010-09-08 17:09:00 -070081
Ajay Dudanib01e5062011-12-03 23:23:42 -080082 /* Setting Debug LEDs ON */
83 debug_led_write(0xFF);
Chandan Uddarajubedca152010-06-02 23:05:15 -070084#if (!ENABLE_NANDWRITE)
85 keys_init();
86 keypad_init();
87#endif
Kinson Chikce306ff2011-07-08 15:23:33 -070088
Ajay Dudanib01e5062011-12-03 23:23:42 -080089 /* Display splash screen if enabled */
Kinson Chikce306ff2011-07-08 15:23:33 -070090#if DISPLAY_SPLASH_SCREEN
Ajay Dudanib01e5062011-12-03 23:23:42 -080091 display_init();
92 dprintf(SPEW, "Diplay initialized\n");
93 display_image_on_screen();
Kinson Chikce306ff2011-07-08 15:23:33 -070094#endif
95
Ajay Dudanib01e5062011-12-03 23:23:42 -080096 if (mmc_boot_main(MMC_SLOT, MSM_SDC1_BASE)) {
97 dprintf(CRITICAL, "mmc init failed!");
98 ASSERT(0);
99 }
Shashank Mittal23b8f422010-04-16 19:27:21 -0700100}
101
102unsigned board_machtype(void)
103{
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800104 struct smem_board_info_v5 board_info_v5;
Shashank Mittal2249a072011-02-14 19:24:17 -0800105 struct smem_board_info_v6 board_info_v6;
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800106 unsigned int board_info_len = 0;
107 unsigned smem_status = 0;
108 unsigned format = 0;
109 unsigned id = 0;
110 unsigned hw_platform = 0;
111 unsigned fused_chip = 0;
Ajay Dudani295f38b2011-02-25 15:28:07 -0800112 unsigned platform_subtype = 0;
Greg Griscod2471ef2011-07-14 13:00:42 -0700113 static unsigned mach_id = 0xFFFFFFFF;
Shashank Mittalc69512e2010-09-22 16:40:48 -0700114
Ajay Dudanib01e5062011-12-03 23:23:42 -0800115 if (mach_id != 0xFFFFFFFF)
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800116 return mach_id;
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800117 /* Detect external msm if this is a "fusion" */
118 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800119 &format, sizeof(format), 0);
120 if (!smem_status) {
121 if (format == 5) {
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800122 board_info_len = sizeof(board_info_v5);
123
Ajay Dudanib01e5062011-12-03 23:23:42 -0800124 smem_status =
125 smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
126 &board_info_v5,
127 board_info_len);
128 if (!smem_status) {
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800129 fused_chip = board_info_v5.fused_chip;
Shashank Mittal2249a072011-02-14 19:24:17 -0800130 id = board_info_v5.board_info_v3.hw_platform;
131 }
Ajay Dudanib01e5062011-12-03 23:23:42 -0800132 } else if (format == 6) {
Shashank Mittal2249a072011-02-14 19:24:17 -0800133 board_info_len = sizeof(board_info_v6);
134
Ajay Dudanib01e5062011-12-03 23:23:42 -0800135 smem_status =
136 smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
137 &board_info_v6,
138 board_info_len);
139 if (!smem_status) {
Shashank Mittal2249a072011-02-14 19:24:17 -0800140 fused_chip = board_info_v6.fused_chip;
141 id = board_info_v6.board_info_v3.hw_platform;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800142 platform_subtype =
143 board_info_v6.platform_subtype;
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800144 }
145 }
146 }
147
148 /* Detect SURF v/s FFA v/s Fluid */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800149 switch (id) {
150 case 0x1:
151 hw_platform = HW_PLATFORM_SURF;
152 break;
153 case 0x2:
154 hw_platform = HW_PLATFORM_FFA;
155 break;
156 case 0x3:
157 hw_platform = HW_PLATFORM_FLUID;
158 break;
159 case 0x6:
160 hw_platform = HW_PLATFORM_QT;
161 break;
162 case 0xA:
163 hw_platform = HW_PLATFORM_DRAGON;
164 break;
165 default:
166 /* Writing to Debug LED register and reading back to auto detect
167 SURF and FFA. If we read back, it is SURF */
168 debug_led_write(0xA5);
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800169
Ajay Dudanib01e5062011-12-03 23:23:42 -0800170 if ((debug_led_read() & 0xFF) == 0xA5) {
171 debug_led_write(0);
172 hw_platform = HW_PLATFORM_SURF;
173 } else
174 hw_platform = HW_PLATFORM_FFA;
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800175 };
176
Ajay Dudani295f38b2011-02-25 15:28:07 -0800177 /* Use platform_subtype or fused_chip information to determine machine id */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800178 if (format >= 6) {
179 switch (platform_subtype) {
180 case HW_PLATFORM_SUBTYPE_CSFB:
181 case HW_PLATFORM_SUBTYPE_SVLTE2A:
182 if (hw_platform == HW_PLATFORM_SURF)
183 mach_id = LINUX_MACHTYPE_8660_CHARM_SURF;
184 else if (hw_platform == HW_PLATFORM_FFA)
185 mach_id = LINUX_MACHTYPE_8660_CHARM_FFA;
186 break;
187 default:
188 if (hw_platform == HW_PLATFORM_SURF)
189 mach_id = LINUX_MACHTYPE_8660_SURF;
190 else if (hw_platform == HW_PLATFORM_FFA)
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800191 mach_id = LINUX_MACHTYPE_8660_FFA;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800192 else if (hw_platform == HW_PLATFORM_FLUID)
193 mach_id = LINUX_MACHTYPE_8660_FLUID;
194 else if (hw_platform == HW_PLATFORM_QT)
195 mach_id = LINUX_MACHTYPE_8660_QT;
196 else if (hw_platform == HW_PLATFORM_DRAGON)
197 mach_id = LINUX_MACHTYPE_8x60_DRAGON;
198 }
199 } else if (format == 5) {
200 switch (fused_chip) {
201 case UNKNOWN:
202 if (hw_platform == HW_PLATFORM_SURF)
203 mach_id = LINUX_MACHTYPE_8660_SURF;
204 else if (hw_platform == HW_PLATFORM_FFA)
205 mach_id = LINUX_MACHTYPE_8660_FFA;
206 else if (hw_platform == HW_PLATFORM_FLUID)
207 mach_id = LINUX_MACHTYPE_8660_FLUID;
208 else if (hw_platform == HW_PLATFORM_QT)
209 mach_id = LINUX_MACHTYPE_8660_QT;
210 else if (hw_platform == HW_PLATFORM_DRAGON)
211 mach_id = LINUX_MACHTYPE_8x60_DRAGON;
212 break;
213
214 case MDM9200:
215 case MDM9600:
216 if (hw_platform == HW_PLATFORM_SURF)
217 mach_id = LINUX_MACHTYPE_8660_CHARM_SURF;
218 else if (hw_platform == HW_PLATFORM_FFA)
219 mach_id = LINUX_MACHTYPE_8660_CHARM_FFA;
220 break;
221
222 default:
223 mach_id = LINUX_MACHTYPE_8660_FFA;
Ajay Dudani295f38b2011-02-25 15:28:07 -0800224 }
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800225 }
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800226 return mach_id;
Shashank Mittal23b8f422010-04-16 19:27:21 -0700227}
228
Shashank Mittal6df16072011-07-14 18:44:01 -0700229void shutdown_device()
230{
231 gpio_config_pshold();
232 pm8058_reset_pwr_off(0);
233 pm8901_reset_pwr_off(0);
234
235 writel(0, MSM_PSHOLD_CTL_SU);
236 mdelay(10000);
237 dprintf(CRITICAL, "Shutdown failed\n");
238}
239
Shashank Mittal23b8f422010-04-16 19:27:21 -0700240void reboot_device(unsigned reboot_reason)
241{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800242 /* Reset WDG0 counter */
243 writel(1, MSM_WDT0_RST);
244 /* Disable WDG0 */
245 writel(0, MSM_WDT0_EN);
246 /* Set WDG0 bark time */
247 writel(0x31F3, MSM_WDT0_BT);
248 /* Enable WDG0 */
249 writel(3, MSM_WDT0_EN);
250 dmb();
251 /* Enable WDG output */
252 secure_writel(3, MSM_TCSR_BASE + TCSR_WDOG_CFG);
253 mdelay(10000);
254 dprintf(CRITICAL, "Rebooting failed\n");
255 return;
Shashank Mittal23b8f422010-04-16 19:27:21 -0700256}
257
258unsigned check_reboot_mode(void)
259{
Ajay Dudani77421292010-10-27 19:34:06 -0700260 unsigned restart_reason = 0;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800261 void *restart_reason_addr = (void *)0x2A05F65C;
Ajay Dudani77421292010-10-27 19:34:06 -0700262
263 /* Read reboot reason and scrub it */
264 restart_reason = readl(restart_reason_addr);
265 writel(0x00, restart_reason_addr);
266
267 return restart_reason;
Shashank Mittal23b8f422010-04-16 19:27:21 -0700268}
269
270void target_battery_charging_enable(unsigned enable, unsigned disconnect)
271{
272}
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -0700273
274void setup_fpga()
275{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800276 writel(0x147, GPIO_CFG133_ADDR);
277 writel(0x144, GPIO_CFG135_ADDR);
278 writel(0x144, GPIO_CFG136_ADDR);
279 writel(0x144, GPIO_CFG137_ADDR);
280 writel(0x144, GPIO_CFG138_ADDR);
281 writel(0x144, GPIO_CFG139_ADDR);
282 writel(0x144, GPIO_CFG140_ADDR);
283 writel(0x144, GPIO_CFG141_ADDR);
284 writel(0x144, GPIO_CFG142_ADDR);
285 writel(0x144, GPIO_CFG143_ADDR);
286 writel(0x144, GPIO_CFG144_ADDR);
287 writel(0x144, GPIO_CFG145_ADDR);
288 writel(0x144, GPIO_CFG146_ADDR);
289 writel(0x144, GPIO_CFG147_ADDR);
290 writel(0x144, GPIO_CFG148_ADDR);
291 writel(0x144, GPIO_CFG149_ADDR);
292 writel(0x144, GPIO_CFG150_ADDR);
293 writel(0x147, GPIO_CFG151_ADDR);
294 writel(0x147, GPIO_CFG152_ADDR);
295 writel(0x147, GPIO_CFG153_ADDR);
296 writel(0x3, GPIO_CFG154_ADDR);
297 writel(0x147, GPIO_CFG155_ADDR);
298 writel(0x147, GPIO_CFG156_ADDR);
299 writel(0x147, GPIO_CFG157_ADDR);
300 writel(0x3, GPIO_CFG158_ADDR);
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -0700301
Ajay Dudanib01e5062011-12-03 23:23:42 -0800302 writel(0x00000B31, EBI2_CHIP_SELECT_CFG0);
303 writel(0xA3030020, EBI2_XMEM_CS3_CFG1);
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -0700304}
305
306void debug_led_write(char val)
307{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800308 writeb(val, SURF_DEBUG_LED_ADDR);
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -0700309}
310
311char debug_led_read()
312{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800313 return readb(SURF_DEBUG_LED_ADDR);
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -0700314}
Ajay Dudanid04110c2011-01-17 23:55:07 -0800315
316unsigned target_baseband()
317{
318 struct smem_board_info_v5 board_info_v5;
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800319 struct smem_board_info_v6 board_info_v6;
Ajay Dudanid04110c2011-01-17 23:55:07 -0800320 unsigned int board_info_len = 0;
321 unsigned smem_status = 0;
322 unsigned format = 0;
323 unsigned baseband = BASEBAND_MSM;
324
325 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800326 &format, sizeof(format), 0);
327 if (!smem_status) {
328 if (format == 5) {
Ajay Dudanid04110c2011-01-17 23:55:07 -0800329 board_info_len = sizeof(board_info_v5);
330
Ajay Dudanib01e5062011-12-03 23:23:42 -0800331 smem_status =
332 smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
333 &board_info_v5,
334 board_info_len);
335 if (!smem_status) {
Ajay Dudanid04110c2011-01-17 23:55:07 -0800336 /* Check for LTE fused targets or APQ. Default to MSM */
337 if (board_info_v5.fused_chip == MDM9200)
338 baseband = BASEBAND_CSFB;
339 else if (board_info_v5.fused_chip == MDM9600)
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800340 baseband = BASEBAND_SVLTE2A;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800341 else if (board_info_v5.board_info_v3.msm_id ==
342 APQ8060)
Ajay Dudanid04110c2011-01-17 23:55:07 -0800343 baseband = BASEBAND_APQ;
344 else
345 baseband = BASEBAND_MSM;
346 }
Ajay Dudanib01e5062011-12-03 23:23:42 -0800347 } else if (format >= 6) {
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800348 board_info_len = sizeof(board_info_v6);
Ajay Dudanid04110c2011-01-17 23:55:07 -0800349
Ajay Dudanib01e5062011-12-03 23:23:42 -0800350 smem_status =
351 smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
352 &board_info_v6,
353 board_info_len);
354 if (!smem_status) {
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800355 /* Check for LTE fused targets or APQ. Default to MSM */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800356 if (board_info_v6.platform_subtype ==
357 HW_PLATFORM_SUBTYPE_CSFB)
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800358 baseband = BASEBAND_CSFB;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800359 else if (board_info_v6.platform_subtype ==
360 HW_PLATFORM_SUBTYPE_SVLTE2A)
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800361 baseband = BASEBAND_SVLTE2A;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800362 else if (board_info_v6.board_info_v3.msm_id ==
363 APQ8060)
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800364 baseband = BASEBAND_APQ;
365 else
366 baseband = BASEBAND_MSM;
367 }
368 }
369 }
Ajay Dudanid04110c2011-01-17 23:55:07 -0800370 return baseband;
371}
Ajay Dudani59606432011-01-24 18:23:38 -0800372
Deepa Dinamani5e5c21a2012-02-16 18:59:57 -0800373crypto_engine_type board_ce_type(void)
374{
375
376 struct smem_board_info_v5 board_info_v5;
377 struct smem_board_info_v6 board_info_v6;
378 unsigned int board_info_len = 0;
379 unsigned smem_status = 0;
380 unsigned format = 0;
381
382 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
383 &format, sizeof(format), 0);
384 if (!smem_status) {
385 if (format == 5) {
386 board_info_len = sizeof(board_info_v5);
387
388 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
389 &board_info_v5,
390 board_info_len);
391 if (!smem_status) {
392 if ((board_info_v5.board_info_v3.msm_id == APQ8060) ||
393 (board_info_v5.board_info_v3.msm_id == MSM8660) ||
394 (board_info_v5.board_info_v3.msm_id == MSM8260))
395 platform_ce_type = CRYPTO_ENGINE_TYPE_HW;
396 }
397 } else if (format >= 6) {
398 board_info_len = sizeof(board_info_v6);
399
400 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
401 &board_info_v6,
402 board_info_len);
403 if(!smem_status) {
404 if ((board_info_v6.board_info_v3.msm_id == APQ8060) ||
405 (board_info_v6.board_info_v3.msm_id == MSM8660) ||
406 (board_info_v6.board_info_v3.msm_id == MSM8260))
407 platform_ce_type = CRYPTO_ENGINE_TYPE_HW;
408 }
409 }
410 }
411
412 return platform_ce_type;
413}
414
Ajay Dudani59606432011-01-24 18:23:38 -0800415static unsigned target_check_power_on_reason(void)
416{
417 unsigned power_on_status = 0;
418 unsigned int status_len = sizeof(power_on_status);
419 unsigned smem_status;
420
421 smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800422 &power_on_status, status_len);
Ajay Dudani59606432011-01-24 18:23:38 -0800423
Ajay Dudanib01e5062011-12-03 23:23:42 -0800424 if (smem_status) {
425 dprintf(CRITICAL,
426 "ERROR: unable to read shared memory for power on reason\n");
Ajay Dudani59606432011-01-24 18:23:38 -0800427 }
Ajay Dudanib01e5062011-12-03 23:23:42 -0800428 dprintf(INFO, "Power on reason %u\n", power_on_status);
Ajay Dudani59606432011-01-24 18:23:38 -0800429 return power_on_status;
430}
431
Shashank Mittal6df16072011-07-14 18:44:01 -0700432static void target_shutdown_for_rtc_alarm(void)
433{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800434 if (target_check_power_on_reason() == PWR_ON_EVENT_RTC_ALARM) {
435 dprintf(CRITICAL,
436 "Power on due to RTC alarm. Going to shutdown!!\n");
Shashank Mittal6df16072011-07-14 18:44:01 -0700437 pm8058_rtc0_alarm_irq_disable();
438 shutdown_device();
439 }
440}
441
Ajay Dudani59606432011-01-24 18:23:38 -0800442unsigned target_pause_for_battery_charge(void)
443{
Ajay Dudaniba822332011-11-25 13:37:31 -0800444 if (target_check_power_on_reason() == PWR_ON_EVENT_WALL_CHG)
Ajay Dudani59606432011-01-24 18:23:38 -0800445 return 1;
446
447 return 0;
448}
Subbaraman Narayanamurthyb0111a12011-02-03 14:24:16 -0800449
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800450void target_serialno(unsigned char *buf)
451{
452 unsigned int serialno;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800453 if (target_is_emmc_boot()) {
454 serialno = mmc_get_psn();
455 snprintf((char *)buf, 13, "%x", serialno);
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800456 }
457}
458
Subbaraman Narayanamurthyb0111a12011-02-03 14:24:16 -0800459void hsusb_gpio_init(void)
460{
461 uint32_t func;
462 uint32_t pull;
463 uint32_t dir;
464 uint32_t enable;
465 uint32_t drv;
466
467 /* GPIO 131 and 132 need to be configured for connecting to USB HS PHY */
468
469 func = 0;
470 enable = 1;
471 pull = GPIO_NO_PULL;
472 dir = 2;
473 drv = GPIO_2MA;
474 gpio_tlmm_config(131, func, dir, pull, drv, enable);
475 gpio_set(131, dir);
476
477 func = 0;
478 enable = 1;
479 pull = GPIO_NO_PULL;
480 dir = 1;
481 drv = GPIO_2MA;
482 gpio_tlmm_config(132, func, dir, pull, drv, enable);
483 gpio_set(132, dir);
484
485 return;
486}
Amol Jadic52c8a32011-07-12 11:27:04 -0700487
Amol Jadida118b92012-07-06 19:53:18 -0700488#define USB_CLK 0x00902910
489#define USB_PHY_CLK 0x00902E20
490#define CLK_RESET_ASSERT 0x1
491#define CLK_RESET_DEASSERT 0x0
492#define CLK_RESET(x,y) writel((y), (x));
493
494static int msm_otg_xceiv_reset()
495{
496 CLK_RESET(USB_CLK, CLK_RESET_ASSERT);
497 CLK_RESET(USB_PHY_CLK, CLK_RESET_ASSERT);
498 mdelay(20);
499 CLK_RESET(USB_PHY_CLK, CLK_RESET_DEASSERT);
500 CLK_RESET(USB_CLK, CLK_RESET_DEASSERT);
501 mdelay(20);
502
503 return 0;
504}
505
506static void target_ulpi_init(void)
507{
508 unsigned int reg;
509
510 reg = ulpi_read(0x32);
511 dprintf(INFO, " Value of ulpi read 0x32 is %08x\n", reg);
512 ulpi_write(0x30, 0x32);
513 reg = ulpi_read(0x32);
514 dprintf(INFO, " Value of ulpi read 0x32 after write is %08x\n", reg);
515
516 reg = ulpi_read(0x36);
517 dprintf(INFO, " Value of ulpi read 0x36 is %08x\n", reg);
518 ulpi_write(reg | 0x2, 0x36);
519 reg = ulpi_read(0x36);
520 dprintf(INFO, " Value of ulpi read 0x36 aafter write is %08x\n", reg);
521}
522
523/* Do target specific usb initialization */
524void target_usb_init(void)
525{
526 hsusb_gpio_init();
527
528 msm_otg_xceiv_reset();
529
530 target_ulpi_init();
531}
532
533void target_usb_stop(void)
534{
535 int val;
536 /* Voting down PLL8 */
537 val = readl(0x009034C0);
538 val &= ~(1 << 8);
539 writel(val, 0x009034C0);
540}
541
Amol Jadic52c8a32011-07-12 11:27:04 -0700542uint8_t target_uart_gsbi(void)
543{
544 return uart_gsbi_id;
545}
Shashank Mittal162244e2011-08-08 19:01:25 -0700546
547int emmc_recovery_init(void)
548{
549 int rc;
550 rc = _emmc_recovery_init();
551 return rc;
552}