blob: a214e10df5447c95293e2cf8da1034b7d344f050 [file] [log] [blame]
Amol Jadica4f4c92011-01-13 20:19:34 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
4 * Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
5 *
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 <lib/ptable.h>
35#include <smem.h>
36#include <platform/iomap.h>
Greg Griscod6250552011-06-29 14:40:23 -070037#include <mmc.h>
38#include <platform/timer.h>
Amol Jadica4f4c92011-01-13 20:19:34 -080039#include <reg.h>
Amol Jadi6db9fe32011-04-15 17:19:00 -070040#include <dev/keys.h>
Amol Jadi57abe4c2011-05-24 15:47:27 -070041#include <dev/pm8921.h>
Kinson Chikea646242011-09-01 13:53:16 -070042#include <dev/ssbi.h>
Amol Jadic52c8a32011-07-12 11:27:04 -070043#include <gsbi.h>
Greg Griscod2471ef2011-07-14 13:00:42 -070044#include <target.h>
Greg Grisco1073a5e2011-07-28 18:59:18 -070045#include <platform.h>
Amol Jadica4f4c92011-01-13 20:19:34 -080046
Amol Jadi0c04df82011-10-14 17:40:21 -070047/* 8960 */
Amol Jadica4f4c92011-01-13 20:19:34 -080048#define LINUX_MACHTYPE_8960_SIM 3230
49#define LINUX_MACHTYPE_8960_RUMI3 3231
Shashank Mittald67508a2011-05-06 19:18:42 -070050#define LINUX_MACHTYPE_8960_CDP 3396
51#define LINUX_MACHTYPE_8960_MTP 3397
52#define LINUX_MACHTYPE_8960_FLUID 3398
53#define LINUX_MACHTYPE_8960_APQ 3399
Amir Samuelov6a9871b2011-07-31 14:38:05 +030054#define LINUX_MACHTYPE_8960_LIQUID 3535
Amol Jadi0c04df82011-10-14 17:40:21 -070055
56/* 8930 */
Ajay Dudani8decb502011-09-12 13:39:32 -070057#define LINUX_MACHTYPE_8930_CDP 3727
58#define LINUX_MACHTYPE_8930_MTP 3728
59#define LINUX_MACHTYPE_8930_FLUID 3729
Greg Griscod2471ef2011-07-14 13:00:42 -070060
Amol Jadi0c04df82011-10-14 17:40:21 -070061/* 8064 */
62#define LINUX_MACHTYPE_8064_SIM 3572
63#define LINUX_MACHTYPE_8064_RUMI3 3679
64
Amol Jadicd43ea02011-02-15 20:56:04 -080065extern void dmb(void);
Amol Jadi6db9fe32011-04-15 17:19:00 -070066extern void keypad_init(void);
Greg Griscod2471ef2011-07-14 13:00:42 -070067extern void panel_backlight_on(void);
Amol Jadicd43ea02011-02-15 20:56:04 -080068
Shashank Mittalda89a682011-03-14 19:18:38 -070069static unsigned mmc_sdc_base[] = { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE};
70
Amol Jadi0c04df82011-10-14 17:40:21 -070071static uint32_t platform_id;
72static uint32_t target_id;
73
Amol Jadi57abe4c2011-05-24 15:47:27 -070074static pm8921_dev_t pmic;
75
Amol Jadi0c04df82011-10-14 17:40:21 -070076static void target_detect(void);
77static uint8_t get_uart_gsbi(void);
78
79void target_early_init(void)
80{
81 target_detect();
82
83#if WITH_DEBUG_UART
84 uart_init(get_uart_gsbi());
85#endif
86}
Amol Jadic52c8a32011-07-12 11:27:04 -070087
Shashank Mittal39503262011-07-19 11:41:35 -070088void shutdown_device(void)
89{
90 dprintf(CRITICAL, "Shutdown system.\n");
91 pm8921_config_reset_pwr_off(0);
92
93 /* Actually reset the chip */
94 writel(0, MSM_PSHOLD_CTL_SU);
95 mdelay(5000);
96
97 dprintf (CRITICAL, "Shutdown failed.\n");
98}
99
Amol Jadica4f4c92011-01-13 20:19:34 -0800100void target_init(void)
101{
Shashank Mittalda89a682011-03-14 19:18:38 -0700102 unsigned base_addr;
103 unsigned char slot;
Amol Jadi0c04df82011-10-14 17:40:21 -0700104
Amol Jadica4f4c92011-01-13 20:19:34 -0800105 dprintf(INFO, "target_init()\n");
106
Amol Jadi57abe4c2011-05-24 15:47:27 -0700107 /* Initialize PMIC driver */
Greg Griscod2471ef2011-07-14 13:00:42 -0700108 pmic.read = (pm8921_read_func) &pa1_ssbi2_read_bytes;
109 pmic.write = (pm8921_write_func) &pa1_ssbi2_write_bytes;
Amol Jadi57abe4c2011-05-24 15:47:27 -0700110
111 pm8921_init(&pmic);
Amol Jadi0c04df82011-10-14 17:40:21 -0700112
Amol Jadi6db9fe32011-04-15 17:19:00 -0700113 /* Keypad init */
114 keys_init();
115 keypad_init();
116
Kinson Chikce306ff2011-07-08 15:23:33 -0700117 /* Display splash screen if enabled */
118#if DISPLAY_SPLASH_SCREEN
Amol Jadi0c04df82011-10-14 17:40:21 -0700119 if((platform_id == MSM8960) || (platform_id == MSM8930))
120 {
121 panel_backlight_on();
122 display_init();
123 dprintf(SPEW, "Diplay initialized\n");
124 display_image_on_screen();
125 }
Kinson Chikce306ff2011-07-08 15:23:33 -0700126#endif
127
Shashank Mittalda89a682011-03-14 19:18:38 -0700128 /* Trying Slot 1 first */
129 slot = 1;
130 base_addr = mmc_sdc_base[slot-1];
131 if(mmc_boot_main(slot, base_addr))
Amol Jadica4f4c92011-01-13 20:19:34 -0800132 {
Shashank Mittalda89a682011-03-14 19:18:38 -0700133 /* Trying Slot 3 next */
134 slot = 3;
135 base_addr = mmc_sdc_base[slot-1];
136 if(mmc_boot_main(slot, base_addr))
137 {
138 dprintf(CRITICAL, "mmc init failed!");
139 ASSERT(0);
140 }
Amol Jadica4f4c92011-01-13 20:19:34 -0800141 }
142}
143
144unsigned board_machtype(void)
145{
Amol Jadi0c04df82011-10-14 17:40:21 -0700146 return target_id;
147}
148
149
150void target_detect(void)
151{
Shashank Mittalda89a682011-03-14 19:18:38 -0700152 struct smem_board_info_v6 board_info_v6;
153 unsigned int board_info_len = 0;
154 unsigned smem_status = 0;
155 unsigned format = 0;
Amol Jadi64c58c12011-05-11 13:40:25 -0700156 unsigned id = HW_PLATFORM_UNKNOWN;
Amol Jadica4f4c92011-01-13 20:19:34 -0800157
Shashank Mittald67508a2011-05-06 19:18:42 -0700158
Shashank Mittalda89a682011-03-14 19:18:38 -0700159 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
160 &format, sizeof(format), 0);
161 if(!smem_status)
162 {
Amol Jadi64c58c12011-05-11 13:40:25 -0700163 if (format == 6)
Shashank Mittalda89a682011-03-14 19:18:38 -0700164 {
165 board_info_len = sizeof(board_info_v6);
166
167 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
168 &board_info_v6, board_info_len);
169 if(!smem_status)
170 {
171 id = board_info_v6.board_info_v3.hw_platform;
172 }
173 }
174 }
175
Amol Jadi0c04df82011-10-14 17:40:21 -0700176 platform_id = board_info_v6.board_info_v3.msm_id;
177
Amol Jadi64c58c12011-05-11 13:40:25 -0700178 /* Detect the board we are running on */
Amol Jadi0c04df82011-10-14 17:40:21 -0700179 if (platform_id == MSM8960)
Shashank Mittalda89a682011-03-14 19:18:38 -0700180 {
Ajay Dudani8decb502011-09-12 13:39:32 -0700181 switch(id)
182 {
183 case HW_PLATFORM_SURF:
Amol Jadi0c04df82011-10-14 17:40:21 -0700184 target_id = LINUX_MACHTYPE_8960_CDP;
Ajay Dudani8decb502011-09-12 13:39:32 -0700185 break;
186 case HW_PLATFORM_MTP:
Amol Jadi0c04df82011-10-14 17:40:21 -0700187 target_id = LINUX_MACHTYPE_8960_MTP;
Ajay Dudani8decb502011-09-12 13:39:32 -0700188 break;
189 case HW_PLATFORM_FLUID:
Amol Jadi0c04df82011-10-14 17:40:21 -0700190 target_id = LINUX_MACHTYPE_8960_FLUID;
Ajay Dudani8decb502011-09-12 13:39:32 -0700191 break;
192 case HW_PLATFORM_LIQUID:
Amol Jadi0c04df82011-10-14 17:40:21 -0700193 target_id = LINUX_MACHTYPE_8960_LIQUID;
Ajay Dudani8decb502011-09-12 13:39:32 -0700194 break;
195 default:
Amol Jadi0c04df82011-10-14 17:40:21 -0700196 target_id = LINUX_MACHTYPE_8960_CDP;
Ajay Dudani8decb502011-09-12 13:39:32 -0700197 }
198 }
Amol Jadi0c04df82011-10-14 17:40:21 -0700199 else if (platform_id == MSM8930)
Ajay Dudani8decb502011-09-12 13:39:32 -0700200 {
201 switch(id)
202 {
203 case HW_PLATFORM_SURF:
Amol Jadi0c04df82011-10-14 17:40:21 -0700204 target_id = LINUX_MACHTYPE_8930_CDP;
Ajay Dudani8decb502011-09-12 13:39:32 -0700205 break;
206 case HW_PLATFORM_MTP:
Amol Jadi0c04df82011-10-14 17:40:21 -0700207 target_id = LINUX_MACHTYPE_8930_MTP;
Ajay Dudani8decb502011-09-12 13:39:32 -0700208 break;
209 case HW_PLATFORM_FLUID:
Amol Jadi0c04df82011-10-14 17:40:21 -0700210 target_id = LINUX_MACHTYPE_8930_FLUID;
Ajay Dudani8decb502011-09-12 13:39:32 -0700211 break;
212 default:
Amol Jadi0c04df82011-10-14 17:40:21 -0700213 target_id = LINUX_MACHTYPE_8930_CDP;
Ajay Dudani8decb502011-09-12 13:39:32 -0700214 }
215 }
Amol Jadi0c04df82011-10-14 17:40:21 -0700216 else if (platform_id == APQ8064)
217 {
218 switch(id)
219 {
220 case HW_PLATFORM_SURF:
221 target_id = LINUX_MACHTYPE_8064_SIM;
222 break;
223 default:
224 target_id = LINUX_MACHTYPE_8064_RUMI3;
225 }
226 }
227 else
228 {
229 dprintf(CRITICAL, "platform_id (%d) is not identified.\n", platform_id);
230 ASSERT(0);
231 }
Amol Jadica4f4c92011-01-13 20:19:34 -0800232}
233
234void reboot_device(unsigned reboot_reason)
235{
Shashank Mittal6239b162011-06-28 17:59:33 -0700236 /* Actually reset the chip */
Shashank Mittal39503262011-07-19 11:41:35 -0700237 pm8921_config_reset_pwr_off(1);
Shashank Mittal6239b162011-06-28 17:59:33 -0700238 writel(0, MSM_PSHOLD_CTL_SU);
Amol Jadica4f4c92011-01-13 20:19:34 -0800239 mdelay(10000);
Shashank Mittal39503262011-07-19 11:41:35 -0700240
Amol Jadica4f4c92011-01-13 20:19:34 -0800241 dprintf (CRITICAL, "Rebooting failed\n");
242 return;
243}
244
245unsigned check_reboot_mode(void)
246{
247 unsigned restart_reason = 0;
Amol Jadica4f4c92011-01-13 20:19:34 -0800248
249 /* Read reboot reason and scrub it */
Shashank Mittal0207df72011-06-15 15:20:43 -0700250 restart_reason = readl(RESTART_REASON_ADDR);
251 writel(0x00, RESTART_REASON_ADDR);
Amol Jadica4f4c92011-01-13 20:19:34 -0800252
253 return restart_reason;
254}
255
Ajay Dudani12091e22011-05-06 17:13:23 -0700256void target_serialno(unsigned char *buf)
257{
258 unsigned int serialno;
259 if(target_is_emmc_boot())
260 {
261 serialno = mmc_get_psn();
Ajay Dudanif63d02f2011-10-01 08:29:53 -0700262 snprintf((char *) buf, 13, "%x", serialno);
Ajay Dudani12091e22011-05-06 17:13:23 -0700263 }
264}
265
Amol Jadica4f4c92011-01-13 20:19:34 -0800266void target_battery_charging_enable(unsigned enable, unsigned disconnect)
267{
268}
Amol Jadi57abe4c2011-05-24 15:47:27 -0700269
270/* Do any target specific intialization needed before entering fastboot mode */
271void target_fastboot_init(void)
272{
273 /* Set the BOOT_DONE flag in PM8921 */
274 pm8921_boot_done();
275}
Amol Jadic52c8a32011-07-12 11:27:04 -0700276
Amol Jadi0c04df82011-10-14 17:40:21 -0700277uint8_t get_uart_gsbi(void)
Amol Jadic52c8a32011-07-12 11:27:04 -0700278{
Amol Jadi0c04df82011-10-14 17:40:21 -0700279 switch(target_id)
280 {
281 case LINUX_MACHTYPE_8960_SIM:
282 case LINUX_MACHTYPE_8960_RUMI3:
283 case LINUX_MACHTYPE_8960_CDP:
284 case LINUX_MACHTYPE_8960_MTP:
285 case LINUX_MACHTYPE_8960_FLUID:
286 case LINUX_MACHTYPE_8960_APQ:
287 case LINUX_MACHTYPE_8960_LIQUID:
288
289 return GSBI_ID_5;
290
291 case LINUX_MACHTYPE_8930_CDP:
292 case LINUX_MACHTYPE_8930_MTP:
293 case LINUX_MACHTYPE_8930_FLUID:
294
295 return GSBI_ID_5;
296
297 case LINUX_MACHTYPE_8064_SIM:
298 case LINUX_MACHTYPE_8064_RUMI3:
299
300 return GSBI_ID_3;
301
302 default:
303 dprintf(CRITICAL, "uart gsbi not defined for target: %d\n",
304 target_id);
305
306 ASSERT(0);
307 }
Amol Jadic52c8a32011-07-12 11:27:04 -0700308}