blob: 29334c5b77acbb58bcabb40cb1ad08d94378db81 [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>
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -070039#include <platform/iomap.h>
Subbaraman Narayanamurthyb0111a12011-02-03 14:24:16 -080040#include <platform/gpio_hw.h>
Ajay Dudanid04110c2011-01-17 23:55:07 -080041#include <baseband.h>
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -070042#include <reg.h>
Shashank Mittal23b8f422010-04-16 19:27:21 -070043
Shashank Mittal86b21482010-11-15 10:37:34 -080044#define LINUX_MACHTYPE_8660_SURF 2755
45#define LINUX_MACHTYPE_8660_FFA 3017
46#define LINUX_MACHTYPE_8660_FLUID 3124
Ajay Dudani8b3262a2011-01-17 13:55:30 -080047#define LINUX_MACHTYPE_8660_QT 3298
Ajay Dudani16ea8fb2010-11-23 19:15:38 -080048#define LINUX_MACHTYPE_8660_CHARM_SURF 3181
49#define LINUX_MACHTYPE_8660_CHARM_FFA 3199
Shashank Mittal23b8f422010-04-16 19:27:21 -070050
51void keypad_init(void);
52
53static int emmc_boot = -1; /* set to uninitialized */
54int target_is_emmc_boot(void);
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -070055void debug_led_write(char);
56char debug_led_read();
Shashank Mittalc69512e2010-09-22 16:40:48 -070057uint32_t platform_id_read (void);
Shashank Mittal23b8f422010-04-16 19:27:21 -070058
59void target_init(void)
60{
61
62 dprintf(INFO, "target_init()\n");
63
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -070064 setup_fpga();
Subbaraman Narayanamurthy50d936f2010-09-08 17:09:00 -070065
66 /* Setting Debug LEDs ON */
67 debug_led_write(0xFF);
Chandan Uddarajubedca152010-06-02 23:05:15 -070068#if (!ENABLE_NANDWRITE)
69 keys_init();
70 keypad_init();
71#endif
Subbaraman Narayanamurthy4b43c352010-09-24 13:20:52 -070072 if(mmc_boot_main(MMC_SLOT,MSM_SDC1_BASE))
Shashank Mittal23b8f422010-04-16 19:27:21 -070073 {
74 dprintf(CRITICAL, "mmc init failed!");
75 ASSERT(0);
76 }
77}
78
79unsigned board_machtype(void)
80{
Ajay Dudani16ea8fb2010-11-23 19:15:38 -080081 struct smem_board_info_v5 board_info_v5;
Shashank Mittal2249a072011-02-14 19:24:17 -080082 struct smem_board_info_v6 board_info_v6;
Ajay Dudani16ea8fb2010-11-23 19:15:38 -080083 unsigned int board_info_len = 0;
84 unsigned smem_status = 0;
85 unsigned format = 0;
86 unsigned id = 0;
87 unsigned hw_platform = 0;
88 unsigned fused_chip = 0;
Ajay Dudani295f38b2011-02-25 15:28:07 -080089 unsigned platform_subtype = 0;
Ajay Dudani16ea8fb2010-11-23 19:15:38 -080090 unsigned mach_id = LINUX_MACHTYPE_8660_FFA;
Shashank Mittalc69512e2010-09-22 16:40:48 -070091
Ajay Dudani16ea8fb2010-11-23 19:15:38 -080092 /* Detect external msm if this is a "fusion" */
93 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
94 &format, sizeof(format), 0);
95 if(!smem_status)
96 {
Shashank Mittal2249a072011-02-14 19:24:17 -080097 if (format == 5)
Ajay Dudani16ea8fb2010-11-23 19:15:38 -080098 {
99 board_info_len = sizeof(board_info_v5);
100
101 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
102 &board_info_v5, board_info_len);
103 if(!smem_status)
104 {
105 fused_chip = board_info_v5.fused_chip;
Shashank Mittal2249a072011-02-14 19:24:17 -0800106 id = board_info_v5.board_info_v3.hw_platform;
107 }
108 }
109 else if (format == 6)
110 {
111 board_info_len = sizeof(board_info_v6);
112
113 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
114 &board_info_v6, board_info_len);
115 if(!smem_status)
116 {
117 fused_chip = board_info_v6.fused_chip;
118 id = board_info_v6.board_info_v3.hw_platform;
Ajay Dudani295f38b2011-02-25 15:28:07 -0800119 platform_subtype = board_info_v6.platform_subtype;
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800120 }
121 }
122 }
123
124 /* Detect SURF v/s FFA v/s Fluid */
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800125 switch(id)
126 {
127 case 0x1:
128 hw_platform = HW_PLATFORM_SURF;
129 break;
130 case 0x2:
131 hw_platform = HW_PLATFORM_FFA;
132 break;
133 case 0x3:
134 hw_platform = HW_PLATFORM_FLUID;
135 break;
Ajay Dudani8b3262a2011-01-17 13:55:30 -0800136 case 0x6:
137 hw_platform = HW_PLATFORM_QT;
138 break;
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800139 default:
140 /* Writing to Debug LED register and reading back to auto detect
141 SURF and FFA. If we read back, it is SURF */
142 debug_led_write(0xA5);
143
144 if((debug_led_read() & 0xFF) == 0xA5)
145 {
146 debug_led_write(0);
147 hw_platform = HW_PLATFORM_SURF;
148 }
149 else
150 hw_platform = HW_PLATFORM_FFA;
151 };
152
Ajay Dudani295f38b2011-02-25 15:28:07 -0800153 /* Use platform_subtype or fused_chip information to determine machine id */
154 if (format >= 6)
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800155 {
Ajay Dudani295f38b2011-02-25 15:28:07 -0800156 switch(platform_subtype)
157 {
158 case HW_PLATFORM_SUBTYPE_CSFB:
159 case HW_PLATFORM_SUBTYPE_SVLTE2A:
160 if (hw_platform == HW_PLATFORM_SURF)
161 mach_id = LINUX_MACHTYPE_8660_CHARM_SURF;
162 else if (hw_platform == HW_PLATFORM_FFA)
163 mach_id = LINUX_MACHTYPE_8660_CHARM_FFA;
164 break;
165 default:
166 if (hw_platform == HW_PLATFORM_SURF)
167 mach_id = LINUX_MACHTYPE_8660_SURF;
168 else if (hw_platform == HW_PLATFORM_FFA)
169 mach_id = LINUX_MACHTYPE_8660_FFA;
170 else if (hw_platform == HW_PLATFORM_FLUID)
171 mach_id = LINUX_MACHTYPE_8660_FLUID;
172 else if (hw_platform == HW_PLATFORM_QT)
173 mach_id = LINUX_MACHTYPE_8660_QT;
174 }
175 }
176 else if (format == 5)
177 {
178 switch(fused_chip)
179 {
180 case UNKNOWN:
181 if (hw_platform == HW_PLATFORM_SURF)
182 mach_id = LINUX_MACHTYPE_8660_SURF;
183 else if (hw_platform == HW_PLATFORM_FFA)
184 mach_id = LINUX_MACHTYPE_8660_FFA;
185 else if (hw_platform == HW_PLATFORM_FLUID)
186 mach_id = LINUX_MACHTYPE_8660_FLUID;
187 else if (hw_platform == HW_PLATFORM_QT)
188 mach_id = LINUX_MACHTYPE_8660_QT;
189 break;
190
191 case MDM9200:
192 case MDM9600:
193 if (hw_platform == HW_PLATFORM_SURF)
194 mach_id = LINUX_MACHTYPE_8660_CHARM_SURF;
195 else if (hw_platform == HW_PLATFORM_FFA)
196 mach_id = LINUX_MACHTYPE_8660_CHARM_FFA;
197 break;
198
199 default:
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800200 mach_id = LINUX_MACHTYPE_8660_FFA;
Ajay Dudani295f38b2011-02-25 15:28:07 -0800201 }
Ajay Dudani16ea8fb2010-11-23 19:15:38 -0800202 }
203
204 return mach_id;
Shashank Mittal23b8f422010-04-16 19:27:21 -0700205}
206
207void reboot_device(unsigned reboot_reason)
208{
Subbaraman Narayanamurthyc6472782010-09-30 12:39:14 -0700209 /* Reset WDG0 counter */
210 writel(1,MSM_WDT0_RST);
211 /* Disable WDG0 */
212 writel(0,MSM_WDT0_EN);
213 /* Set WDG0 bark time */
214 writel(0x31F3,MSM_WDT0_BT);
215 /* Enable WDG0 */
216 writel(3,MSM_WDT0_EN);
217 dmb();
218 /* Enable WDG output */
219 writel(3,MSM_TCSR_BASE + TCSR_WDOG_CFG);
220 mdelay(10000);
221 dprintf (CRITICAL, "Rebooting failed\n");
Shashank Mittal23b8f422010-04-16 19:27:21 -0700222 return;
223}
224
225unsigned check_reboot_mode(void)
226{
Ajay Dudani77421292010-10-27 19:34:06 -0700227 unsigned restart_reason = 0;
Ajay Dudani9496f9a2011-02-17 10:45:39 -0800228 void *restart_reason_addr = 0x2A05F65C;
Ajay Dudani77421292010-10-27 19:34:06 -0700229
230 /* Read reboot reason and scrub it */
231 restart_reason = readl(restart_reason_addr);
232 writel(0x00, restart_reason_addr);
233
234 return restart_reason;
Shashank Mittal23b8f422010-04-16 19:27:21 -0700235}
236
237void target_battery_charging_enable(unsigned enable, unsigned disconnect)
238{
239}
Subbaraman Narayanamurthyf9b6e0d2010-09-08 16:51:43 -0700240
241void setup_fpga()
242{
243 writel(0x147, GPIO_CFG133_ADDR);
244 writel(0x144, GPIO_CFG135_ADDR);
245 writel(0x144, GPIO_CFG136_ADDR);
246 writel(0x144, GPIO_CFG137_ADDR);
247 writel(0x144, GPIO_CFG138_ADDR);
248 writel(0x144, GPIO_CFG139_ADDR);
249 writel(0x144, GPIO_CFG140_ADDR);
250 writel(0x144, GPIO_CFG141_ADDR);
251 writel(0x144, GPIO_CFG142_ADDR);
252 writel(0x144, GPIO_CFG143_ADDR);
253 writel(0x144, GPIO_CFG144_ADDR);
254 writel(0x144, GPIO_CFG145_ADDR);
255 writel(0x144, GPIO_CFG146_ADDR);
256 writel(0x144, GPIO_CFG147_ADDR);
257 writel(0x144, GPIO_CFG148_ADDR);
258 writel(0x144, GPIO_CFG149_ADDR);
259 writel(0x144, GPIO_CFG150_ADDR);
260 writel(0x147, GPIO_CFG151_ADDR);
261 writel(0x147, GPIO_CFG152_ADDR);
262 writel(0x147, GPIO_CFG153_ADDR);
263 writel(0x3, GPIO_CFG154_ADDR);
264 writel(0x147, GPIO_CFG155_ADDR);
265 writel(0x147, GPIO_CFG156_ADDR);
266 writel(0x147, GPIO_CFG157_ADDR);
267 writel(0x3, GPIO_CFG158_ADDR);
268
269 writel(0x00000B31, EBI2_CHIP_SELECT_CFG0);
270 writel(0xA3030020, EBI2_XMEM_CS3_CFG1);
271}
272
273void debug_led_write(char val)
274{
275 writeb(val,SURF_DEBUG_LED_ADDR);
276}
277
278char debug_led_read()
279{
280 return readb(SURF_DEBUG_LED_ADDR);
281}
Ajay Dudanid04110c2011-01-17 23:55:07 -0800282
283unsigned target_baseband()
284{
285 struct smem_board_info_v5 board_info_v5;
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800286 struct smem_board_info_v6 board_info_v6;
Ajay Dudanid04110c2011-01-17 23:55:07 -0800287 unsigned int board_info_len = 0;
288 unsigned smem_status = 0;
289 unsigned format = 0;
290 unsigned baseband = BASEBAND_MSM;
291
292 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
293 &format, sizeof(format), 0);
294 if(!smem_status)
295 {
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800296 if (format == 5)
Ajay Dudanid04110c2011-01-17 23:55:07 -0800297 {
298 board_info_len = sizeof(board_info_v5);
299
300 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
301 &board_info_v5, board_info_len);
302 if(!smem_status)
303 {
304 /* Check for LTE fused targets or APQ. Default to MSM */
305 if (board_info_v5.fused_chip == MDM9200)
306 baseband = BASEBAND_CSFB;
307 else if (board_info_v5.fused_chip == MDM9600)
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800308 baseband = BASEBAND_SVLTE2A;
Ajay Dudanid04110c2011-01-17 23:55:07 -0800309 else if (board_info_v5.board_info_v3.msm_id == APQ8060)
310 baseband = BASEBAND_APQ;
311 else
312 baseband = BASEBAND_MSM;
313 }
314 }
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800315 else if (format >= 6)
316 {
317 board_info_len = sizeof(board_info_v6);
Ajay Dudanid04110c2011-01-17 23:55:07 -0800318
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800319 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
320 &board_info_v6, board_info_len);
321 if(!smem_status)
322 {
323 /* Check for LTE fused targets or APQ. Default to MSM */
324 if (board_info_v6.platform_subtype == HW_PLATFORM_SUBTYPE_CSFB)
325 baseband = BASEBAND_CSFB;
326 else if (board_info_v6.platform_subtype == HW_PLATFORM_SUBTYPE_SVLTE2A)
327 baseband = BASEBAND_SVLTE2A;
328 else if (board_info_v6.board_info_v3.msm_id == APQ8060)
329 baseband = BASEBAND_APQ;
330 else
331 baseband = BASEBAND_MSM;
332 }
333 }
334 }
Ajay Dudanid04110c2011-01-17 23:55:07 -0800335 return baseband;
336}
Ajay Dudani59606432011-01-24 18:23:38 -0800337
338static unsigned target_check_power_on_reason(void)
339{
340 unsigned power_on_status = 0;
341 unsigned int status_len = sizeof(power_on_status);
342 unsigned smem_status;
343
344 smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO,
345 &power_on_status, status_len);
346
347 if (!smem_status)
348 {
349 dprintf(CRITICAL, "ERROR: unable to read shared memory for power on reason\n");
350 }
351
352 return power_on_status;
353}
354
355unsigned target_pause_for_battery_charge(void)
356{
357 if (target_check_power_on_reason() == PWR_ON_EVENT_USB_CHG)
358 return 1;
359
360 return 0;
361}
Subbaraman Narayanamurthyb0111a12011-02-03 14:24:16 -0800362
363void hsusb_gpio_init(void)
364{
365 uint32_t func;
366 uint32_t pull;
367 uint32_t dir;
368 uint32_t enable;
369 uint32_t drv;
370
371 /* GPIO 131 and 132 need to be configured for connecting to USB HS PHY */
372
373 func = 0;
374 enable = 1;
375 pull = GPIO_NO_PULL;
376 dir = 2;
377 drv = GPIO_2MA;
378 gpio_tlmm_config(131, func, dir, pull, drv, enable);
379 gpio_set(131, dir);
380
381 func = 0;
382 enable = 1;
383 pull = GPIO_NO_PULL;
384 dir = 1;
385 drv = GPIO_2MA;
386 gpio_tlmm_config(132, func, dir, pull, drv, enable);
387 gpio_set(132, dir);
388
389 return;
390}