blob: c51a2607d942a6882e4ed057f2ae0eb20404491b [file] [log] [blame]
Shashank Mittal23b8f422010-04-16 19:27:21 -07001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Ajay Dudanid04110c2011-01-17 23:55:07 -08004 * Copyright (c) 2009-2011, Code Aurora Forum. 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>
35#include <dev/gpio_keypad.h>
36#include <lib/ptable.h>
37#include <dev/flash.h>
38#include <smem.h>
Greg Griscod6250552011-06-29 14:40:23 -070039#include <mmc.h>
40#include <platform/timer.h>
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -070041#include <platform/iomap.h>
Subbaraman Narayanamurthyb0111a12011-02-03 14:24:16 -080042#include <platform/gpio_hw.h>
Ajay Dudanid04110c2011-01-17 23:55:07 -080043#include <baseband.h>
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -070044#include <reg.h>
Greg Griscod6250552011-06-29 14:40:23 -070045#include <platform.h>
Shashank Mittal23b8f422010-04-16 19:27:21 -070046
Shashank Mittal86b21482010-11-15 10:37:34 -080047#define LINUX_MACHTYPE_8660_SURF 2755
48#define LINUX_MACHTYPE_8660_FFA 3017
49#define LINUX_MACHTYPE_8660_FLUID 3124
Ajay Dudani8b3262a2011-01-17 13:55:30 -080050#define LINUX_MACHTYPE_8660_QT 3298
Ajay Dudani16ea8fb2010-11-23 19:15:38 -080051#define LINUX_MACHTYPE_8660_CHARM_SURF 3181
52#define LINUX_MACHTYPE_8660_CHARM_FFA 3199
Ajay Dudani62a0d3e2011-07-01 14:27:31 -070053#define LINUX_MACHTYPE_8x60_DRAGON 3586
Shashank Mittal23b8f422010-04-16 19:27:21 -070054
55void keypad_init(void);
56
57static int emmc_boot = -1; /* set to uninitialized */
58int target_is_emmc_boot(void);
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -070059void debug_led_write(char);
60char debug_led_read();
Shashank Mittalc69512e2010-09-22 16:40:48 -070061uint32_t platform_id_read (void);
Greg Griscod6250552011-06-29 14:40:23 -070062void setup_fpga(void);
Shashank Mittal23b8f422010-04-16 19:27:21 -070063
64void target_init(void)
65{
66
67 dprintf(INFO, "target_init()\n");
68
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -070069 setup_fpga();
Subbaraman Narayanamurthy50d936f2010-09-08 17:09:00 -070070
71 /* Setting Debug LEDs ON */
72 debug_led_write(0xFF);
Chandan Uddarajubedca152010-06-02 23:05:15 -070073#if (!ENABLE_NANDWRITE)
74 keys_init();
75 keypad_init();
76#endif
Subbaraman Narayanamurthy4b43c352010-09-24 13:20:52 -070077 if(mmc_boot_main(MMC_SLOT,MSM_SDC1_BASE))
Shashank Mittal23b8f422010-04-16 19:27:21 -070078 {
79 dprintf(CRITICAL, "mmc init failed!");
80 ASSERT(0);
81 }
82}
83
84unsigned board_machtype(void)
85{
Ajay Dudani16ea8fb2010-11-23 19:15:38 -080086 struct smem_board_info_v5 board_info_v5;
Shashank Mittal2249a072011-02-14 19:24:17 -080087 struct smem_board_info_v6 board_info_v6;
Ajay Dudani16ea8fb2010-11-23 19:15:38 -080088 unsigned int board_info_len = 0;
89 unsigned smem_status = 0;
90 unsigned format = 0;
91 unsigned id = 0;
92 unsigned hw_platform = 0;
93 unsigned fused_chip = 0;
Ajay Dudani295f38b2011-02-25 15:28:07 -080094 unsigned platform_subtype = 0;
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -080095 static unsigned mach_id = -1;
Shashank Mittalc69512e2010-09-22 16:40:48 -070096
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -080097 if(mach_id != -1)
98 return mach_id;
Ajay Dudani16ea8fb2010-11-23 19:15:38 -080099 /* Detect external msm if this is a "fusion" */
100 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
101 &format, sizeof(format), 0);
102 if(!smem_status)
103 {
Shashank Mittal2249a072011-02-14 19:24:17 -0800104 if (format == 5)
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800105 {
106 board_info_len = sizeof(board_info_v5);
107
108 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
109 &board_info_v5, board_info_len);
110 if(!smem_status)
111 {
112 fused_chip = board_info_v5.fused_chip;
Shashank Mittal2249a072011-02-14 19:24:17 -0800113 id = board_info_v5.board_info_v3.hw_platform;
114 }
115 }
116 else if (format == 6)
117 {
118 board_info_len = sizeof(board_info_v6);
119
120 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
121 &board_info_v6, board_info_len);
122 if(!smem_status)
123 {
124 fused_chip = board_info_v6.fused_chip;
125 id = board_info_v6.board_info_v3.hw_platform;
Ajay Dudani295f38b2011-02-25 15:28:07 -0800126 platform_subtype = board_info_v6.platform_subtype;
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800127 }
128 }
129 }
130
131 /* Detect SURF v/s FFA v/s Fluid */
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800132 switch(id)
133 {
134 case 0x1:
135 hw_platform = HW_PLATFORM_SURF;
136 break;
137 case 0x2:
138 hw_platform = HW_PLATFORM_FFA;
139 break;
140 case 0x3:
141 hw_platform = HW_PLATFORM_FLUID;
142 break;
Ajay Dudani8b3262a2011-01-17 13:55:30 -0800143 case 0x6:
144 hw_platform = HW_PLATFORM_QT;
145 break;
Ajay Dudani62a0d3e2011-07-01 14:27:31 -0700146 case 0xA:
147 hw_platform = HW_PLATFORM_DRAGON;
148 break;
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800149 default:
150 /* Writing to Debug LED register and reading back to auto detect
151 SURF and FFA. If we read back, it is SURF */
152 debug_led_write(0xA5);
153
154 if((debug_led_read() & 0xFF) == 0xA5)
155 {
156 debug_led_write(0);
157 hw_platform = HW_PLATFORM_SURF;
158 }
159 else
160 hw_platform = HW_PLATFORM_FFA;
161 };
162
Ajay Dudani295f38b2011-02-25 15:28:07 -0800163 /* Use platform_subtype or fused_chip information to determine machine id */
164 if (format >= 6)
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800165 {
Ajay Dudani295f38b2011-02-25 15:28:07 -0800166 switch(platform_subtype)
167 {
168 case HW_PLATFORM_SUBTYPE_CSFB:
169 case HW_PLATFORM_SUBTYPE_SVLTE2A:
170 if (hw_platform == HW_PLATFORM_SURF)
171 mach_id = LINUX_MACHTYPE_8660_CHARM_SURF;
172 else if (hw_platform == HW_PLATFORM_FFA)
173 mach_id = LINUX_MACHTYPE_8660_CHARM_FFA;
174 break;
175 default:
176 if (hw_platform == HW_PLATFORM_SURF)
177 mach_id = LINUX_MACHTYPE_8660_SURF;
178 else if (hw_platform == HW_PLATFORM_FFA)
179 mach_id = LINUX_MACHTYPE_8660_FFA;
180 else if (hw_platform == HW_PLATFORM_FLUID)
181 mach_id = LINUX_MACHTYPE_8660_FLUID;
182 else if (hw_platform == HW_PLATFORM_QT)
183 mach_id = LINUX_MACHTYPE_8660_QT;
Ajay Dudani62a0d3e2011-07-01 14:27:31 -0700184 else if (hw_platform == HW_PLATFORM_DRAGON)
185 mach_id = LINUX_MACHTYPE_8x60_DRAGON;
Ajay Dudani295f38b2011-02-25 15:28:07 -0800186 }
187 }
188 else if (format == 5)
189 {
190 switch(fused_chip)
191 {
192 case UNKNOWN:
193 if (hw_platform == HW_PLATFORM_SURF)
194 mach_id = LINUX_MACHTYPE_8660_SURF;
195 else if (hw_platform == HW_PLATFORM_FFA)
196 mach_id = LINUX_MACHTYPE_8660_FFA;
197 else if (hw_platform == HW_PLATFORM_FLUID)
198 mach_id = LINUX_MACHTYPE_8660_FLUID;
199 else if (hw_platform == HW_PLATFORM_QT)
200 mach_id = LINUX_MACHTYPE_8660_QT;
Ajay Dudani62a0d3e2011-07-01 14:27:31 -0700201 else if (hw_platform == HW_PLATFORM_DRAGON)
202 mach_id = LINUX_MACHTYPE_8x60_DRAGON;
Ajay Dudani295f38b2011-02-25 15:28:07 -0800203 break;
204
205 case MDM9200:
206 case MDM9600:
207 if (hw_platform == HW_PLATFORM_SURF)
208 mach_id = LINUX_MACHTYPE_8660_CHARM_SURF;
209 else if (hw_platform == HW_PLATFORM_FFA)
210 mach_id = LINUX_MACHTYPE_8660_CHARM_FFA;
211 break;
212
213 default:
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800214 mach_id = LINUX_MACHTYPE_8660_FFA;
Ajay Dudani295f38b2011-02-25 15:28:07 -0800215 }
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800216 }
217
218 return mach_id;
Shashank Mittal23b8f422010-04-16 19:27:21 -0700219}
220
221void reboot_device(unsigned reboot_reason)
222{
Subbaraman Narayanamurthyc6472782010-09-30 12:39:14 -0700223 /* Reset WDG0 counter */
224 writel(1,MSM_WDT0_RST);
225 /* Disable WDG0 */
226 writel(0,MSM_WDT0_EN);
227 /* Set WDG0 bark time */
228 writel(0x31F3,MSM_WDT0_BT);
229 /* Enable WDG0 */
230 writel(3,MSM_WDT0_EN);
231 dmb();
232 /* Enable WDG output */
Subbaraman Narayanamurthy346bdcb2011-02-24 12:02:58 -0800233 secure_writel(3,MSM_TCSR_BASE + TCSR_WDOG_CFG);
Subbaraman Narayanamurthyc6472782010-09-30 12:39:14 -0700234 mdelay(10000);
235 dprintf (CRITICAL, "Rebooting failed\n");
Shashank Mittal23b8f422010-04-16 19:27:21 -0700236 return;
237}
238
239unsigned check_reboot_mode(void)
240{
Ajay Dudani77421292010-10-27 19:34:06 -0700241 unsigned restart_reason = 0;
Ajay Dudani9496f9a2011-02-17 10:45:39 -0800242 void *restart_reason_addr = 0x2A05F65C;
Ajay Dudani77421292010-10-27 19:34:06 -0700243
244 /* Read reboot reason and scrub it */
245 restart_reason = readl(restart_reason_addr);
246 writel(0x00, restart_reason_addr);
247
248 return restart_reason;
Shashank Mittal23b8f422010-04-16 19:27:21 -0700249}
250
251void target_battery_charging_enable(unsigned enable, unsigned disconnect)
252{
253}
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -0700254
255void setup_fpga()
256{
257 writel(0x147, GPIO_CFG133_ADDR);
258 writel(0x144, GPIO_CFG135_ADDR);
259 writel(0x144, GPIO_CFG136_ADDR);
260 writel(0x144, GPIO_CFG137_ADDR);
261 writel(0x144, GPIO_CFG138_ADDR);
262 writel(0x144, GPIO_CFG139_ADDR);
263 writel(0x144, GPIO_CFG140_ADDR);
264 writel(0x144, GPIO_CFG141_ADDR);
265 writel(0x144, GPIO_CFG142_ADDR);
266 writel(0x144, GPIO_CFG143_ADDR);
267 writel(0x144, GPIO_CFG144_ADDR);
268 writel(0x144, GPIO_CFG145_ADDR);
269 writel(0x144, GPIO_CFG146_ADDR);
270 writel(0x144, GPIO_CFG147_ADDR);
271 writel(0x144, GPIO_CFG148_ADDR);
272 writel(0x144, GPIO_CFG149_ADDR);
273 writel(0x144, GPIO_CFG150_ADDR);
274 writel(0x147, GPIO_CFG151_ADDR);
275 writel(0x147, GPIO_CFG152_ADDR);
276 writel(0x147, GPIO_CFG153_ADDR);
277 writel(0x3, GPIO_CFG154_ADDR);
278 writel(0x147, GPIO_CFG155_ADDR);
279 writel(0x147, GPIO_CFG156_ADDR);
280 writel(0x147, GPIO_CFG157_ADDR);
281 writel(0x3, GPIO_CFG158_ADDR);
282
283 writel(0x00000B31, EBI2_CHIP_SELECT_CFG0);
284 writel(0xA3030020, EBI2_XMEM_CS3_CFG1);
285}
286
287void debug_led_write(char val)
288{
289 writeb(val,SURF_DEBUG_LED_ADDR);
290}
291
292char debug_led_read()
293{
294 return readb(SURF_DEBUG_LED_ADDR);
295}
Ajay Dudanid04110c2011-01-17 23:55:07 -0800296
297unsigned target_baseband()
298{
299 struct smem_board_info_v5 board_info_v5;
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800300 struct smem_board_info_v6 board_info_v6;
Ajay Dudanid04110c2011-01-17 23:55:07 -0800301 unsigned int board_info_len = 0;
302 unsigned smem_status = 0;
303 unsigned format = 0;
304 unsigned baseband = BASEBAND_MSM;
305
306 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
307 &format, sizeof(format), 0);
308 if(!smem_status)
309 {
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800310 if (format == 5)
Ajay Dudanid04110c2011-01-17 23:55:07 -0800311 {
312 board_info_len = sizeof(board_info_v5);
313
314 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
315 &board_info_v5, board_info_len);
316 if(!smem_status)
317 {
318 /* Check for LTE fused targets or APQ. Default to MSM */
319 if (board_info_v5.fused_chip == MDM9200)
320 baseband = BASEBAND_CSFB;
321 else if (board_info_v5.fused_chip == MDM9600)
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800322 baseband = BASEBAND_SVLTE2A;
Ajay Dudanid04110c2011-01-17 23:55:07 -0800323 else if (board_info_v5.board_info_v3.msm_id == APQ8060)
324 baseband = BASEBAND_APQ;
325 else
326 baseband = BASEBAND_MSM;
327 }
328 }
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800329 else if (format >= 6)
330 {
331 board_info_len = sizeof(board_info_v6);
Ajay Dudanid04110c2011-01-17 23:55:07 -0800332
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800333 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
334 &board_info_v6, board_info_len);
335 if(!smem_status)
336 {
337 /* Check for LTE fused targets or APQ. Default to MSM */
338 if (board_info_v6.platform_subtype == HW_PLATFORM_SUBTYPE_CSFB)
339 baseband = BASEBAND_CSFB;
340 else if (board_info_v6.platform_subtype == HW_PLATFORM_SUBTYPE_SVLTE2A)
341 baseband = BASEBAND_SVLTE2A;
342 else if (board_info_v6.board_info_v3.msm_id == APQ8060)
343 baseband = BASEBAND_APQ;
344 else
345 baseband = BASEBAND_MSM;
346 }
347 }
348 }
Ajay Dudanid04110c2011-01-17 23:55:07 -0800349 return baseband;
350}
Ajay Dudani59606432011-01-24 18:23:38 -0800351
352static unsigned target_check_power_on_reason(void)
353{
354 unsigned power_on_status = 0;
355 unsigned int status_len = sizeof(power_on_status);
356 unsigned smem_status;
357
358 smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO,
359 &power_on_status, status_len);
360
Subbaraman Narayanamurthybd2424e2011-03-29 15:29:21 -0700361 if (smem_status)
Ajay Dudani59606432011-01-24 18:23:38 -0800362 {
363 dprintf(CRITICAL, "ERROR: unable to read shared memory for power on reason\n");
364 }
365
366 return power_on_status;
367}
368
369unsigned target_pause_for_battery_charge(void)
370{
371 if (target_check_power_on_reason() == PWR_ON_EVENT_USB_CHG)
372 return 1;
373
374 return 0;
375}
Subbaraman Narayanamurthyb0111a12011-02-03 14:24:16 -0800376
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800377void target_serialno(unsigned char *buf)
378{
379 unsigned int serialno;
380 if(target_is_emmc_boot())
381 {
382 serialno = mmc_get_psn();
383 sprintf(buf,"%x",serialno);
384 }
385}
386
Subbaraman Narayanamurthyb0111a12011-02-03 14:24:16 -0800387void hsusb_gpio_init(void)
388{
389 uint32_t func;
390 uint32_t pull;
391 uint32_t dir;
392 uint32_t enable;
393 uint32_t drv;
394
395 /* GPIO 131 and 132 need to be configured for connecting to USB HS PHY */
396
397 func = 0;
398 enable = 1;
399 pull = GPIO_NO_PULL;
400 dir = 2;
401 drv = GPIO_2MA;
402 gpio_tlmm_config(131, func, dir, pull, drv, enable);
403 gpio_set(131, dir);
404
405 func = 0;
406 enable = 1;
407 pull = GPIO_NO_PULL;
408 dir = 1;
409 drv = GPIO_2MA;
410 gpio_tlmm_config(132, func, dir, pull, drv, enable);
411 gpio_set(132, dir);
412
413 return;
414}