blob: d0bdce6b78ef667d116a710526d353f054f66ceb [file] [log] [blame]
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Duy Truongf3ac7b32013-02-13 01:07:28 -08004 * Copyright (c) 2009-2011, The Linux Foundation. All rights reserved.
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -08005 *
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>
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080034#include <debug.h>
35#include <dev/keys.h>
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080036#include <lib/ptable.h>
37#include <dev/flash.h>
Chandan Uddarajude85d3f2010-01-05 16:32:33 -080038#include <smem.h>
Greg Griscod6250552011-06-29 14:40:23 -070039#include <mmc.h>
Subbaraman Narayanamurthy4b43c352010-09-24 13:20:52 -070040#include <platform/iomap.h>
Greg Griscod6250552011-06-29 14:40:23 -070041#include <platform.h>
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080042
Srilakshmi Punurucfb5a462011-02-08 11:55:24 -080043#define LINUX_MACHTYPE_7x27_SURF 2705
44#define LINUX_MACHTYPE_7x27_FFA 2706
45
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080046
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080047#define VARIABLE_LENGTH 0x10101010
48#define DIFF_START_ADDR 0xF0F0F0F0
49#define NUM_PAGES_PER_BLOCK 0x40
50
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080051static struct ptable flash_ptable;
Subbaraman Narayanamurthy31c174e2011-02-04 12:35:09 -080052static unsigned mmc_sdc_base[] = { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE};
Srilakshmi Punurucfb5a462011-02-08 11:55:24 -080053static int hw_platform_type = -1;
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080054
55/* for these partitions, start will be offset by either what we get from
56 * smem, or from the above offset if smem is not useful. Also, we should
57 * probably have smem_ptable code populate our flash_ptable.
58 *
59 * When smem provides us with a full partition table, we can get rid of
60 * this altogether.
61 *
62 */
63static struct ptentry board_part_list[] = {
64 {
65 .start = 0,
Chandan Uddarajua7e8ffe2010-07-27 11:08:31 -070066 .length = 5 /* In MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080067 .name = "boot",
68 },
69 {
Chandan Uddarajua7e8ffe2010-07-27 11:08:31 -070070 .start = DIFF_START_ADDR,
Channagoud Kadabi7252f112011-11-18 14:11:23 +053071 .length = 180 /* In MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080072 .name = "system",
73 },
74 {
Chandan Uddarajua7e8ffe2010-07-27 11:08:31 -070075 .start = DIFF_START_ADDR,
Ajay Dudania5362ef2011-01-28 20:05:15 -080076 .length = 4 /* In MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080077 .name = "cache",
78 },
79 {
Chandan Uddarajua7e8ffe2010-07-27 11:08:31 -070080 .start = DIFF_START_ADDR,
Ajay Dudani81990742011-03-23 17:00:37 -070081 .length = 4 /* In MB */,
Subbaraman Narayanamurthyeb92bcc2010-07-20 14:32:46 -070082 .name = "misc",
83 },
84 {
Chandan Uddarajua7e8ffe2010-07-27 11:08:31 -070085 .start = DIFF_START_ADDR,
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080086 .length = VARIABLE_LENGTH,
87 .name = "userdata",
Chandan Uddarajude85d3f2010-01-05 16:32:33 -080088 },
89 {
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080090 .start = DIFF_START_ADDR,
Chandan Uddaraju49fd6432010-08-12 12:06:54 -070091 .length = 2 /* In MB */,
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080092 .name = "persist",
93 },
94 {
95 .start = DIFF_START_ADDR,
Chandan Uddarajua7e8ffe2010-07-27 11:08:31 -070096 .length = 5 /* In MB */,
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080097 .name = "recovery",
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080098 },
99};
100static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
101
102void smem_ptable_init(void);
103unsigned smem_get_apps_flash_start(void);
104
105void keypad_init(void);
106
David Ngbf2eb3c2009-12-09 23:48:07 -0800107int target_is_emmc_boot(void);
108
Subbaraman Narayanamurthy31c174e2011-02-04 12:35:09 -0800109
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800110void target_init(void)
111{
112 unsigned offset;
113 struct flash_info *flash_info;
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800114 unsigned total_num_of_blocks;
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800115 unsigned next_ptr_start_adr = 0;
Chandan Uddarajua7e8ffe2010-07-27 11:08:31 -0700116 unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive*/
Subbaraman Narayanamurthy31c174e2011-02-04 12:35:09 -0800117 unsigned char slot;
118 unsigned int base_addr;
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800119 int i;
120
121 dprintf(INFO, "target_init()\n");
122
Kinson Chikce306ff2011-07-08 15:23:33 -0700123 /* Display splash screen if enabled */
124#if DISPLAY_SPLASH_SCREEN
125 display_init();
126 dprintf(SPEW, "Diplay initialized\n");
127 display_image_on_screen();
128#endif
129
Chandan Uddaraju852cd2c2009-12-17 14:28:28 -0800130#if (!ENABLE_NANDWRITE)
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800131 keys_init();
132 keypad_init();
Chandan Uddaraju852cd2c2009-12-17 14:28:28 -0800133#endif
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800134
David Ngbf2eb3c2009-12-09 23:48:07 -0800135 if (target_is_emmc_boot())
Ajay Dudani2676ea92010-08-10 07:15:45 -0700136 {
Amol Jadi2dfe3392011-07-19 16:03:37 -0700137 /* Must wait for modem-up before we can intialize MMC.
138 */
139 while (readl(MSM_SHARED_BASE + 0x14) != 1);
140
Subbaraman Narayanamurthy31c174e2011-02-04 12:35:09 -0800141 /* Trying SDC3 first */
142 slot = 3;
143 base_addr = mmc_sdc_base[slot - 1];
144 if(mmc_boot_main(slot, base_addr))
Subbaraman Narayanamurthy4b43c352010-09-24 13:20:52 -0700145 {
Subbaraman Narayanamurthy31c174e2011-02-04 12:35:09 -0800146 /* Trying SDC1 next */
147 slot = 1;
148 base_addr = mmc_sdc_base[slot - 1];
149 if(mmc_boot_main(slot, base_addr))
150 {
151 dprintf(CRITICAL, "mmc init failed!");
152 ASSERT(0);
153 }
Subbaraman Narayanamurthy4b43c352010-09-24 13:20:52 -0700154 }
David Ngbf2eb3c2009-12-09 23:48:07 -0800155 return;
Ajay Dudani2676ea92010-08-10 07:15:45 -0700156 }
David Ngbf2eb3c2009-12-09 23:48:07 -0800157
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800158 ptable_init(&flash_ptable);
159 smem_ptable_init();
160
161 flash_init();
162 flash_info = flash_get_info();
163 ASSERT(flash_info);
164
165 offset = smem_get_apps_flash_start();
166 if (offset == 0xffffffff)
167 while(1);
168
Chandan Uddaraju40605112010-08-09 14:25:08 -0700169 total_num_of_blocks = flash_info->num_blocks;
170 blocks_per_1MB = (1 << 20) / (flash_info->block_size);
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800171
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800172 for (i = 0; i < num_parts; i++) {
173 struct ptentry *ptn = &board_part_list[i];
Chandan Uddarajua7e8ffe2010-07-27 11:08:31 -0700174 unsigned len = ((ptn->length) * blocks_per_1MB);
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800175
Chandan Uddarajua7e8ffe2010-07-27 11:08:31 -0700176 if(ptn->start != 0)
177 ASSERT(ptn->start == DIFF_START_ADDR);
178
179 ptn->start = next_ptr_start_adr;
180
181 if(ptn->length == VARIABLE_LENGTH)
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800182 {
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800183 unsigned length_for_prt = 0;
184 unsigned j;
185 for (j = i+1; j < num_parts; j++)
186 {
187 struct ptentry *temp_ptn = &board_part_list[j];
188 ASSERT(temp_ptn->length != VARIABLE_LENGTH);
Chandan Uddarajua7e8ffe2010-07-27 11:08:31 -0700189 length_for_prt += ((temp_ptn->length) * blocks_per_1MB);
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800190 }
Shashank Mittal04059b72011-03-15 20:37:28 -0700191 len = total_num_of_blocks - (offset + ptn->start + length_for_prt);
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800192 ASSERT(len >= 0);
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800193 }
Chandan Uddarajua7e8ffe2010-07-27 11:08:31 -0700194 next_ptr_start_adr = ptn->start + len;
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800195 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
Shashank Mittal8e49dec2010-03-01 15:19:04 -0800196 len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE);
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800197 }
198
Shashank Mittal8e49dec2010-03-01 15:19:04 -0800199 smem_add_modem_partitions(&flash_ptable);
200
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800201 ptable_dump(&flash_ptable);
202 flash_set_ptable(&flash_ptable);
203}
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800204
205unsigned board_machtype(void)
206{
Srilakshmi Punurucfb5a462011-02-08 11:55:24 -0800207 struct smem_board_info_v2 board_info_v2;
208 unsigned int board_info_len = 0;
209 enum platform platform_type = 0;
210 unsigned smem_status;
211 unsigned format = 0;
212
213 if(hw_platform_type != -1)
214 return hw_platform_type;
215
216 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
217 &format, sizeof(format), 0);
218 if(!smem_status)
219 {
220 if(format == 2)
221 {
222 board_info_len = sizeof(board_info_v2);
223
224 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
225 &board_info_v2, board_info_len);
226 if(!smem_status)
227 {
228 char *build_type = (char *)(board_info_v2.build_id)+ 12;
229 switch (*build_type)
230 {
231 case 'F':
232 hw_platform_type = LINUX_MACHTYPE_7x27_FFA; break;
233 case 'S':
234 hw_platform_type = LINUX_MACHTYPE_7x27_SURF; break;
235 default:
236 hw_platform_type = LINUX_MACHTYPE_7x27_SURF; break;
237 }
238 }
239 }
240 } else {
241 hw_platform_type = LINUX_MACHTYPE_7x27_SURF;
242 }
243 return hw_platform_type;
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800244}
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800245
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800246void reboot_device(unsigned reboot_reason)
247{
248 reboot(reboot_reason);
249}
250
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800251unsigned check_reboot_mode(void)
252{
Chandan Uddaraju8a1d37c2010-01-06 12:04:28 -0800253 unsigned mode[2] = {0, 0};
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800254 unsigned int mode_len = sizeof(mode);
255 unsigned smem_status;
256
257 smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE,
258 &mode, mode_len );
259 if(smem_status)
260 {
261 dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n");
262 return 0;
263 }
Chandan Uddaraju8a1d37c2010-01-06 12:04:28 -0800264 return mode[0];
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800265}
Chandan Uddaraju7f5b9012010-02-06 16:37:48 -0800266
David Ngf773dde2010-07-26 19:55:08 -0700267static unsigned target_check_power_on_reason(void)
268{
269 unsigned power_on_status = 0;
270 unsigned int status_len = sizeof(power_on_status);
271 unsigned smem_status;
272
273 smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO,
274 &power_on_status, status_len);
Ajay Dudani35f686f2011-07-22 13:12:09 -0700275
Subbaraman Narayanamurthybd2424e2011-03-29 15:29:21 -0700276 if (smem_status)
David Ngf773dde2010-07-26 19:55:08 -0700277 {
278 dprintf(CRITICAL, "ERROR: unable to read shared memory for power on reason\n");
279 }
280
281 return power_on_status;
282}
283
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800284#if _EMMC_BOOT
285void target_serialno(unsigned char *buf)
286{
287 unsigned int serialno;
288 serialno = mmc_get_psn();
289 sprintf(buf,"%x",serialno);
290}
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -0700291
292int emmc_recovery_init(void)
293{
294 int rc;
295 rc = _emmc_recovery_init();
296 return rc;
297}
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800298#endif