blob: b5b7185410730a3160f6965e53481f3f2d290e9e [file] [log] [blame]
Shashank Mittal246f8d02011-01-21 17:12:27 -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
Amol Jadi2dfe3392011-07-19 16:03:37 -070033#include <reg.h>
Shashank Mittal246f8d02011-01-21 17:12:27 -080034#include <debug.h>
35#include <dev/keys.h>
Kinson Chikea646242011-09-01 13:53:16 -070036#include <dev/ssbi.h>
Shashank Mittal246f8d02011-01-21 17:12:27 -080037#include <lib/ptable.h>
38#include <dev/flash.h>
39#include <smem.h>
Greg Griscod6250552011-06-29 14:40:23 -070040#include <mmc.h>
Shashank Mittal246f8d02011-01-21 17:12:27 -080041#include <platform/iomap.h>
Greg Griscod6250552011-06-29 14:40:23 -070042#include <platform.h>
Shashank Mittal246f8d02011-01-21 17:12:27 -080043
44#define MSM7X27A_FFA 3351
45#define MSM7X27A_SURF 3352
46#define MSM7X27A_RUMI3 3353
Channagoud Kadabi4c41c412011-09-08 15:38:30 +053047#define MSM7X27A_QRD1 3756
48
Shashank Mittalef325412011-04-01 13:48:26 -070049#define LINUX_MACHTYPE MSM7X27A_SURF
Shashank Mittal246f8d02011-01-21 17:12:27 -080050
51#define VARIABLE_LENGTH 0x10101010
52#define DIFF_START_ADDR 0xF0F0F0F0
53#define NUM_PAGES_PER_BLOCK 0x40
54
55static struct ptable flash_ptable;
Shashank Mittalcb25d252011-04-05 12:13:30 -070056unsigned hw_platform = 0;
57unsigned target_msm_id = 0;
Shashank Mittal246f8d02011-01-21 17:12:27 -080058
59/* for these partitions, start will be offset by either what we get from
60 * smem, or from the above offset if smem is not useful. Also, we should
61 * probably have smem_ptable code populate our flash_ptable.
62 *
63 * When smem provides us with a full partition table, we can get rid of
64 * this altogether.
65 *
66 */
Channagoud Kadabi500afb72011-07-19 18:24:11 +053067static struct ptentry board_part_list_default[] = {
Shashank Mittal246f8d02011-01-21 17:12:27 -080068 {
69 .start = 0,
70 .length = 10 /* In MB */,
71 .name = "boot",
72 },
73 {
74 .start = DIFF_START_ADDR,
Srilakshmi Punuru75122c92011-07-28 19:16:19 +053075 .length = 150 /* In MB */,
Shashank Mittal246f8d02011-01-21 17:12:27 -080076 .name = "system",
77 },
78 {
79 .start = DIFF_START_ADDR,
Shashank Mittal561450e2011-03-04 19:53:32 -080080 .length = 4 /* In MB */,
Shashank Mittal246f8d02011-01-21 17:12:27 -080081 .name = "cache",
82 },
83 {
84 .start = DIFF_START_ADDR,
Shashank Mittal04276272011-05-06 15:13:45 -070085 .length = 4 /* In MB */,
Shashank Mittal246f8d02011-01-21 17:12:27 -080086 .name = "misc",
87 },
88 {
89 .start = DIFF_START_ADDR,
90 .length = VARIABLE_LENGTH,
91 .name = "userdata",
92 },
93 {
94 .start = DIFF_START_ADDR,
Shashank Mittal04276272011-05-06 15:13:45 -070095 .length = 4 /* In MB */,
Shashank Mittal246f8d02011-01-21 17:12:27 -080096 .name = "persist",
97 },
98 {
99 .start = DIFF_START_ADDR,
Aparna Mallavarapu84d39f32011-05-12 09:34:46 +0530100 .length = 10 /* In MB */,
Shashank Mittal246f8d02011-01-21 17:12:27 -0800101 .name = "recovery",
102 },
103};
Channagoud Kadabi500afb72011-07-19 18:24:11 +0530104static int num_parts = sizeof(board_part_list_default)/sizeof(struct ptentry);
Shashank Mittal246f8d02011-01-21 17:12:27 -0800105
Channagoud Kadabi500afb72011-07-19 18:24:11 +0530106/*
107 * Define partition table for Bch ecc NAND and increase the cache partition size
108 * to 8MB
109 */
110static struct ptentry board_part_list_bchecc[] = {
111 {
112 .start = 0,
113 .length = 10 /* In MB */,
114 .name = "boot",
115 },
116 {
117 .start = DIFF_START_ADDR,
Channagoud Kadabieb50ff42011-09-13 18:00:48 +0530118 .length = 150 /* In MB */,
Channagoud Kadabi500afb72011-07-19 18:24:11 +0530119 .name = "system",
120 },
121 {
122 .start = DIFF_START_ADDR,
123 .length = 8 /* In MB */,
124 .name = "cache",
125 },
126 {
127 .start = DIFF_START_ADDR,
128 .length = 4 /* In MB */,
129 .name = "misc",
130 },
131 {
132 .start = DIFF_START_ADDR,
133 .length = VARIABLE_LENGTH,
134 .name = "userdata",
135 },
136 {
137 .start = DIFF_START_ADDR,
138 .length = 4 /* In MB */,
139 .name = "persist",
140 },
141 {
142 .start = DIFF_START_ADDR,
143 .length = 10 /* In MB */,
144 .name = "recovery",
145 },
146};
Shashank Mittal246f8d02011-01-21 17:12:27 -0800147void smem_ptable_init(void);
148unsigned smem_get_apps_flash_start(void);
149
150void keypad_init(void);
151
152int target_is_emmc_boot(void);
153
154void target_init(void)
155{
156 unsigned offset;
157 struct flash_info *flash_info;
Channagoud Kadabi500afb72011-07-19 18:24:11 +0530158 struct ptentry *board_part_list;
Shashank Mittal246f8d02011-01-21 17:12:27 -0800159 unsigned total_num_of_blocks;
160 unsigned next_ptr_start_adr = 0;
161 unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive*/
162 int i;
163
164 dprintf(INFO, "target_init()\n");
165
Shashank Mittal246f8d02011-01-21 17:12:27 -0800166#if (!ENABLE_NANDWRITE)
167 keys_init();
168 keypad_init();
169#endif
Shashank Mittal246f8d02011-01-21 17:12:27 -0800170
Kinson Chikce306ff2011-07-08 15:23:33 -0700171 /* Display splash screen if enabled */
172#if DISPLAY_SPLASH_SCREEN
173 display_init();
174 dprintf(SPEW, "Diplay initialized\n");
175 display_image_on_screen();
176#endif
177
Shashank Mittal246f8d02011-01-21 17:12:27 -0800178 if (target_is_emmc_boot())
179 {
Amol Jadi2dfe3392011-07-19 16:03:37 -0700180 /* Must wait for modem-up before we can intialize MMC.
181 */
182 while (readl(MSM_SHARED_BASE + 0x14) != 1);
183
Aparna Mallavarapu5a83b2a2011-05-26 18:01:31 +0530184 if(mmc_boot_main(MMC_SLOT, MSM_SDC3_BASE))
Shashank Mittal246f8d02011-01-21 17:12:27 -0800185 {
186 dprintf(CRITICAL, "mmc init failed!");
187 ASSERT(0);
188 }
189 return;
190 }
191
192 ptable_init(&flash_ptable);
193 smem_ptable_init();
194
195 flash_init();
196 flash_info = flash_get_info();
197 ASSERT(flash_info);
198
199 offset = smem_get_apps_flash_start();
200 if (offset == 0xffffffff)
201 while(1);
202
203 total_num_of_blocks = flash_info->num_blocks;
204 blocks_per_1MB = (1 << 20) / (flash_info->block_size);
205
Channagoud Kadabi500afb72011-07-19 18:24:11 +0530206 if (flash_ecc_bch_enabled())
207 board_part_list = board_part_list_bchecc;
208 else
209 board_part_list = board_part_list_default;
210
Shashank Mittal246f8d02011-01-21 17:12:27 -0800211 for (i = 0; i < num_parts; i++) {
212 struct ptentry *ptn = &board_part_list[i];
213 unsigned len = ((ptn->length) * blocks_per_1MB);
214
215 if(ptn->start != 0)
216 ASSERT(ptn->start == DIFF_START_ADDR);
217
218 ptn->start = next_ptr_start_adr;
219
220 if(ptn->length == VARIABLE_LENGTH)
221 {
222 unsigned length_for_prt = 0;
223 unsigned j;
224 for (j = i+1; j < num_parts; j++)
225 {
226 struct ptentry *temp_ptn = &board_part_list[j];
227 ASSERT(temp_ptn->length != VARIABLE_LENGTH);
228 length_for_prt += ((temp_ptn->length) * blocks_per_1MB);
229 }
230 len = (total_num_of_blocks - 1) - (offset + ptn->start + length_for_prt);
231 ASSERT(len >= 0);
232 }
233 next_ptr_start_adr = ptn->start + len;
234 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
235 len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE);
236 }
237
238 smem_add_modem_partitions(&flash_ptable);
239
240 ptable_dump(&flash_ptable);
241 flash_set_ptable(&flash_ptable);
242}
243
Shashank Mittalcb25d252011-04-05 12:13:30 -0700244void board_info(void)
245{
246 struct smem_board_info_v4 board_info_v4;
247 unsigned int board_info_len = 0;
248 unsigned smem_status;
249 unsigned format = 0;
250 unsigned id = 0;
251
252 if (hw_platform && target_msm_id)
253 return;
254
255 hw_platform = MSM7X27A_SURF;
256 target_msm_id = MSM7225A;
257
258 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
259 &format, sizeof(format), 0);
260 if(!smem_status)
261 {
262 if(format == 4)
263 {
264 board_info_len = sizeof(board_info_v4);
265 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
266 &board_info_v4, board_info_len);
267 if(!smem_status)
268 {
269 id = board_info_v4.board_info_v3.hw_platform;
270 target_msm_id = board_info_v4.board_info_v3.msm_id;
271 }
272 }
273
Channagoud Kadabi4c41c412011-09-08 15:38:30 +0530274 /* Detect SURF v/s FFA v/s QRD */
Shashank Mittalcb25d252011-04-05 12:13:30 -0700275 switch(id)
276 {
277 case 0x1:
278 hw_platform = MSM7X27A_SURF;
279 break;
280 case 0x2:
281 hw_platform = MSM7X27A_FFA;
282 break;
Channagoud Kadabi4c41c412011-09-08 15:38:30 +0530283 case 0xB:
284 hw_platform = MSM7X27A_QRD1;
285 break;
Shashank Mittalcb25d252011-04-05 12:13:30 -0700286 default:
287 hw_platform = MSM7X27A_SURF;
288 };
289
290 if ((target_msm_id < MSM7225A) || (target_msm_id > ESM7227A))
291 {
292 target_msm_id = MSM7225A;
293 }
294 }
295 return;
296}
297
Shashank Mittal246f8d02011-01-21 17:12:27 -0800298unsigned board_machtype(void)
299{
Shashank Mittalcb25d252011-04-05 12:13:30 -0700300 board_info();
301 return hw_platform;
302}
303
304unsigned board_msm_id(void)
305{
306 board_info();
307 return target_msm_id;
Shashank Mittal246f8d02011-01-21 17:12:27 -0800308}
309
310void reboot_device(unsigned reboot_reason)
311{
312 reboot(reboot_reason);
313}
314
315unsigned check_reboot_mode(void)
316{
317 unsigned mode[2] = {0, 0};
318 unsigned int mode_len = sizeof(mode);
319 unsigned smem_status;
320
321 smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE,
322 &mode, mode_len );
323 if(smem_status)
324 {
325 dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n");
326 return 0;
327 }
328 return mode[0];
329}
330
331static unsigned target_check_power_on_reason(void)
332{
333 unsigned power_on_status = 0;
334 unsigned int status_len = sizeof(power_on_status);
335 unsigned smem_status;
336
337 smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO,
338 &power_on_status, status_len);
Subbaraman Narayanamurthybd2424e2011-03-29 15:29:21 -0700339 if (smem_status)
Shashank Mittal246f8d02011-01-21 17:12:27 -0800340 {
341 dprintf(CRITICAL, "ERROR: unable to read shared memory for power on reason\n");
342 }
343
344 return power_on_status;
345}
346
347unsigned target_pause_for_battery_charge(void)
348{
349 if (target_check_power_on_reason() == PWR_ON_EVENT_USB_CHG)
350 return 1;
351 return 0;
352}
353
354void target_battery_charging_enable(unsigned enable, unsigned disconnect)
355{
356}
Shashank Mittal59392f32011-05-01 20:49:56 -0700357
358#if _EMMC_BOOT
359void target_serialno(unsigned char *buf)
360{
361 unsigned int serialno;
362 serialno = mmc_get_psn();
363 sprintf(buf,"%x",serialno);
364}
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -0700365
366int emmc_recovery_init(void)
367{
368 int rc;
369 rc = _emmc_recovery_init();
370 return rc;
371}
Shashank Mittal59392f32011-05-01 20:49:56 -0700372#endif
373