blob: e7841c75094646e78bc547b4849c923396c4ff56 [file] [log] [blame]
Shashank Mittal246f8d02011-01-21 17:12:27 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Aparna Mallavarapu332887b2012-10-11 15:51:26 +05304 * Copyright (c) 2009-2012, The Linux Foundation. All rights reserved.
Shashank Mittal246f8d02011-01-21 17:12:27 -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>
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>
Channagoud Kadabi539ef722012-03-29 16:02:50 +053042#include <target/board.h>
Greg Griscod6250552011-06-29 14:40:23 -070043#include <platform.h>
Deepa Dinamani5e5c21a2012-02-16 18:59:57 -080044#include <crypto_hash.h>
Shashank Mittal246f8d02011-01-21 17:12:27 -080045
Shashank Mittal246f8d02011-01-21 17:12:27 -080046#define VARIABLE_LENGTH 0x10101010
47#define DIFF_START_ADDR 0xF0F0F0F0
48#define NUM_PAGES_PER_BLOCK 0x40
Channagoud Kadabi16da3a22011-10-24 20:25:07 +053049#define RECOVERY_MODE 0x77665502
50#define FOTA_COOKIE 0x64645343
51
52unsigned int fota_cookie[1];
Shashank Mittal246f8d02011-01-21 17:12:27 -080053
54static struct ptable flash_ptable;
Shashank Mittalcb25d252011-04-05 12:13:30 -070055unsigned hw_platform = 0;
56unsigned target_msm_id = 0;
Aparna Mallavarapuc1eb99b2012-09-24 20:13:42 +053057unsigned msm_version = 0;
Shashank Mittal246f8d02011-01-21 17:12:27 -080058
Deepa Dinamani5e5c21a2012-02-16 18:59:57 -080059/* Setting this variable to different values defines the
60 * behavior of CE engine:
61 * platform_ce_type = CRYPTO_ENGINE_TYPE_NONE : No CE engine
62 * platform_ce_type = CRYPTO_ENGINE_TYPE_SW : Software CE engine
63 * platform_ce_type = CRYPTO_ENGINE_TYPE_HW : Hardware CE engine
64 * Behavior is determined in the target code.
65 */
66static crypto_engine_type platform_ce_type = CRYPTO_ENGINE_TYPE_SW;
67
Channagoud Kadabi3acfb742011-11-15 18:19:32 +053068int machine_is_evb();
Channagoud Kadabid53664b2011-12-28 16:39:15 +053069
Shashank Mittal246f8d02011-01-21 17:12:27 -080070/* for these partitions, start will be offset by either what we get from
71 * smem, or from the above offset if smem is not useful. Also, we should
72 * probably have smem_ptable code populate our flash_ptable.
73 *
74 * When smem provides us with a full partition table, we can get rid of
75 * this altogether.
76 *
77 */
Channagoud Kadabib3e08032012-09-25 16:04:16 +053078static struct ptentry board_part_list_default[] = {
Shashank Mittal246f8d02011-01-21 17:12:27 -080079 {
Ajay Dudanib01e5062011-12-03 23:23:42 -080080 .start = 0,
81 .length = 10 /* In MB */ ,
82 .name = "boot",
83 },
Shashank Mittal246f8d02011-01-21 17:12:27 -080084 {
Ajay Dudanib01e5062011-12-03 23:23:42 -080085 .start = DIFF_START_ADDR,
Channagoud Kadabi71961882012-02-09 16:32:41 +053086 .length = 253 /* In MB */ ,
Ajay Dudanib01e5062011-12-03 23:23:42 -080087 .name = "system",
88 },
Shashank Mittal246f8d02011-01-21 17:12:27 -080089 {
Ajay Dudanib01e5062011-12-03 23:23:42 -080090 .start = DIFF_START_ADDR,
Channagoud Kadabi2ce67412012-09-11 18:26:27 +053091 .length = 80 /* In MB */ ,
Ajay Dudanib01e5062011-12-03 23:23:42 -080092 .name = "cache",
93 },
Shashank Mittal246f8d02011-01-21 17:12:27 -080094 {
Ajay Dudanib01e5062011-12-03 23:23:42 -080095 .start = DIFF_START_ADDR,
96 .length = 4 /* In MB */ ,
97 .name = "misc",
98 },
Shashank Mittal246f8d02011-01-21 17:12:27 -080099 {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800100 .start = DIFF_START_ADDR,
101 .length = VARIABLE_LENGTH,
102 .name = "userdata",
103 },
Shashank Mittal246f8d02011-01-21 17:12:27 -0800104 {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800105 .start = DIFF_START_ADDR,
106 .length = 4 /* In MB */ ,
107 .name = "persist",
108 },
Shashank Mittal246f8d02011-01-21 17:12:27 -0800109 {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800110 .start = DIFF_START_ADDR,
111 .length = 10 /* In MB */ ,
112 .name = "recovery",
113 },
Shashank Mittal246f8d02011-01-21 17:12:27 -0800114};
Ajay Dudanib01e5062011-12-03 23:23:42 -0800115
Channagoud Kadabib3e08032012-09-25 16:04:16 +0530116/*
117 * SKU3 & SKU PVT devices use the same micron NAND device with different density,
118 * due to this SKU3 partition creation fails as the number of blocks calculated
119 * from flash density is wrong, To avoid this use a different partition table &
120 * move the variable length partition to the end, this way kernel will truncate
121 * the variable length partition & we need not add target checks in the shared
122 * nand driver code.
123 */
124
125static struct ptentry board_part_list_sku3[] = {
126 {
127 .start = 0,
128 .length = 10 /* In MB */ ,
129 .name = "boot",
130 },
131 {
132 .start = DIFF_START_ADDR,
133 .length = 253 /* In MB */ ,
134 .name = "system",
135 },
136 {
137 .start = DIFF_START_ADDR,
138 .length = 80 /* In MB */ ,
139 .name = "cache",
140 },
141 {
142 .start = DIFF_START_ADDR,
143 .length = 4 /* In MB */ ,
144 .name = "misc",
145 },
146 {
147 .start = DIFF_START_ADDR,
148 .length = 4 /* In MB */ ,
149 .name = "persist",
150 },
151 {
152 .start = DIFF_START_ADDR,
153 .length = 10 /* In MB */ ,
154 .name = "recovery",
155 },
156 {
157 .start = DIFF_START_ADDR,
158 .length = VARIABLE_LENGTH,
159 .name = "userdata",
160 },
161};
162
163static int num_parts = sizeof(board_part_list_default) / sizeof(struct ptentry);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800164
Shashank Mittal246f8d02011-01-21 17:12:27 -0800165void smem_ptable_init(void);
166unsigned smem_get_apps_flash_start(void);
167
168void keypad_init(void);
169
170int target_is_emmc_boot(void);
171
172void target_init(void)
173{
174 unsigned offset;
175 struct flash_info *flash_info;
Channagoud Kadabib3e08032012-09-25 16:04:16 +0530176 struct ptentry *board_part_list;
Shashank Mittal246f8d02011-01-21 17:12:27 -0800177 unsigned total_num_of_blocks;
178 unsigned next_ptr_start_adr = 0;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800179 unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive */
Shashank Mittal246f8d02011-01-21 17:12:27 -0800180 int i;
181
182 dprintf(INFO, "target_init()\n");
183
Shashank Mittal246f8d02011-01-21 17:12:27 -0800184#if (!ENABLE_NANDWRITE)
185 keys_init();
186 keypad_init();
187#endif
Shashank Mittal246f8d02011-01-21 17:12:27 -0800188
Kinson Chikce306ff2011-07-08 15:23:33 -0700189 /* Display splash screen if enabled */
190#if DISPLAY_SPLASH_SCREEN
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530191 display_init();
192 dprintf(SPEW, "Diplay initialized\n");
Kinson Chikce306ff2011-07-08 15:23:33 -0700193#endif
194
Ajay Dudanib01e5062011-12-03 23:23:42 -0800195 if (target_is_emmc_boot()) {
Amol Jadi2dfe3392011-07-19 16:03:37 -0700196 /* Must wait for modem-up before we can intialize MMC.
197 */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800198 while (readl(MSM_SHARED_BASE + 0x14) != 1) ;
Amol Jadi2dfe3392011-07-19 16:03:37 -0700199
Ajay Dudanib01e5062011-12-03 23:23:42 -0800200 if (mmc_boot_main(MMC_SLOT, MSM_SDC3_BASE)) {
Shashank Mittal246f8d02011-01-21 17:12:27 -0800201 dprintf(CRITICAL, "mmc init failed!");
202 ASSERT(0);
203 }
204 return;
205 }
206
207 ptable_init(&flash_ptable);
208 smem_ptable_init();
209
210 flash_init();
211 flash_info = flash_get_info();
212 ASSERT(flash_info);
213
214 offset = smem_get_apps_flash_start();
215 if (offset == 0xffffffff)
Ajay Dudanib01e5062011-12-03 23:23:42 -0800216 while (1) ;
Shashank Mittal246f8d02011-01-21 17:12:27 -0800217
218 total_num_of_blocks = flash_info->num_blocks;
219 blocks_per_1MB = (1 << 20) / (flash_info->block_size);
220
Channagoud Kadabib3e08032012-09-25 16:04:16 +0530221 if (target_is_sku3())
222 board_part_list = board_part_list_sku3;
223 else
224 board_part_list = board_part_list_default;
225
Shashank Mittal246f8d02011-01-21 17:12:27 -0800226 for (i = 0; i < num_parts; i++) {
227 struct ptentry *ptn = &board_part_list[i];
228 unsigned len = ((ptn->length) * blocks_per_1MB);
229
Ajay Dudanib01e5062011-12-03 23:23:42 -0800230 if (ptn->start != 0)
231 ASSERT(ptn->start == DIFF_START_ADDR);
Shashank Mittal246f8d02011-01-21 17:12:27 -0800232
233 ptn->start = next_ptr_start_adr;
234
Ajay Dudanib01e5062011-12-03 23:23:42 -0800235 if (ptn->length == VARIABLE_LENGTH) {
Shashank Mittal246f8d02011-01-21 17:12:27 -0800236 unsigned length_for_prt = 0;
237 unsigned j;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800238 for (j = i + 1; j < num_parts; j++) {
239 struct ptentry *temp_ptn = &board_part_list[j];
240 ASSERT(temp_ptn->length != VARIABLE_LENGTH);
241 length_for_prt +=
242 ((temp_ptn->length) * blocks_per_1MB);
Shashank Mittal246f8d02011-01-21 17:12:27 -0800243 }
Ajay Dudanib01e5062011-12-03 23:23:42 -0800244 len =
245 (total_num_of_blocks - 1) - (offset + ptn->start +
246 length_for_prt);
Shashank Mittal246f8d02011-01-21 17:12:27 -0800247 ASSERT(len >= 0);
248 }
249 next_ptr_start_adr = ptn->start + len;
250 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800251 len, ptn->flags, TYPE_APPS_PARTITION,
252 PERM_WRITEABLE);
Shashank Mittal246f8d02011-01-21 17:12:27 -0800253 }
254
255 smem_add_modem_partitions(&flash_ptable);
256
257 ptable_dump(&flash_ptable);
258 flash_set_ptable(&flash_ptable);
259}
Shashank Mittalcb25d252011-04-05 12:13:30 -0700260void board_info(void)
261{
262 struct smem_board_info_v4 board_info_v4;
263 unsigned int board_info_len = 0;
264 unsigned smem_status;
265 unsigned format = 0;
266 unsigned id = 0;
267
268 if (hw_platform && target_msm_id)
269 return;
270
271 hw_platform = MSM7X27A_SURF;
272 target_msm_id = MSM7225A;
273
274 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800275 &format, sizeof(format), 0);
276 if (!smem_status) {
277 if (format == 4) {
Shashank Mittalcb25d252011-04-05 12:13:30 -0700278 board_info_len = sizeof(board_info_v4);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800279 smem_status =
280 smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
281 &board_info_v4,
282 board_info_len);
283 if (!smem_status) {
Shashank Mittalcb25d252011-04-05 12:13:30 -0700284 id = board_info_v4.board_info_v3.hw_platform;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800285 target_msm_id =
286 board_info_v4.board_info_v3.msm_id;
Aparna Mallavarapuc1eb99b2012-09-24 20:13:42 +0530287 msm_version =
288 board_info_v4.board_info_v3.msm_version;
Shashank Mittalcb25d252011-04-05 12:13:30 -0700289 }
290 }
291
Channagoud Kadabi4c41c412011-09-08 15:38:30 +0530292 /* Detect SURF v/s FFA v/s QRD */
Aparna Mallavarapu51879412012-08-27 12:55:50 +0530293 if (target_msm_id >= MSM8225 && target_msm_id <= MSM8625
294 || (target_msm_id == MSM8125A)) {
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530295 switch (id) {
296 case 0x1:
297 hw_platform = MSM8X25_SURF;
298 break;
Aparna Mallavarapu1bb33672012-04-20 16:07:24 +0530299 case 0x2:
300 hw_platform = MSM8X25_FFA;
301 break;
Aparna Mallavarapubac9a722012-05-22 10:15:29 +0530302 case 0x10:
Aparna Mallavarapu287d89c2012-05-11 14:27:03 +0530303 hw_platform = MSM8X25_EVT;
304 break;
Aparna Mallavarapu332887b2012-10-11 15:51:26 +0530305 case 0x11:
306 hw_platform = MSM8X25Q_SKUD;
307 break;
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530308 case 0xC:
309 hw_platform = MSM8X25_EVB;
310 break;
Aparna Mallavarapuac332982012-03-18 14:02:38 +0530311 case 0xF:
312 hw_platform = MSM8X25_QRD7;
313 break;
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530314 default:
315 hw_platform = MSM8X25_SURF;
316 }
317 } else {
318 switch (id) {
319 case 0x1:
320 /* Set the machine type based on msm ID */
Channagoud Kadabibd14e2f2012-05-03 22:54:50 +0530321 if (msm_is_7x25a(target_msm_id))
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530322 hw_platform = MSM7X25A_SURF;
Channagoud Kadabi849ad5e2012-04-02 23:21:21 +0530323 else
324 hw_platform = MSM7X27A_SURF;
325 break;
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530326 case 0x2:
Channagoud Kadabibd14e2f2012-05-03 22:54:50 +0530327 if (msm_is_7x25a(target_msm_id))
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530328 hw_platform = MSM7X25A_FFA;
Channagoud Kadabi849ad5e2012-04-02 23:21:21 +0530329 else
330 hw_platform = MSM7X27A_FFA;
331 break;
332 case 0xB:
333 if(target_is_emmc_boot())
334 hw_platform = MSM7X27A_QRD1;
335 else
336 hw_platform = MSM7X27A_QRD3;
337 break;
338 case 0xC:
339 hw_platform = MSM7X27A_EVB;
340 break;
341 case 0xF:
Channagoud Kadabib33d4832012-02-06 17:10:56 +0530342 hw_platform = MSM7X27A_QRD3;
Channagoud Kadabi849ad5e2012-04-02 23:21:21 +0530343 break;
344 default:
Channagoud Kadabibd14e2f2012-05-03 22:54:50 +0530345 if (msm_is_7x25a(target_msm_id))
Channagoud Kadabi849ad5e2012-04-02 23:21:21 +0530346 hw_platform = MSM7X25A_SURF;
347 else
348 hw_platform = MSM7X27A_SURF;
349 };
350 }
Ajay Dudanib01e5062011-12-03 23:23:42 -0800351 /* Set msm ID for target variants based on values read from smem */
352 switch (target_msm_id) {
353 case MSM7225A:
354 case MSM7625A:
355 case ESM7225A:
356 case MSM7225AA:
357 case MSM7625AA:
358 case ESM7225AA:
Channagoud Kadabibd14e2f2012-05-03 22:54:50 +0530359 case MSM7225AB:
360 case MSM7625AB:
361 case ESM7225AB:
Channagoud Kadabi647f0852012-06-08 11:51:45 +0530362 case MSM7125A:
Ajay Dudanib01e5062011-12-03 23:23:42 -0800363 target_msm_id = MSM7625A;
364 break;
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530365 case MSM8225:
366 case MSM8625:
Aparna Mallavarapu51879412012-08-27 12:55:50 +0530367 case MSM8125A:
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530368 target_msm_id = MSM8625;
369 break;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800370 default:
371 target_msm_id = MSM7627A;
Shashank Mittalcb25d252011-04-05 12:13:30 -0700372 }
373 }
374 return;
375}
376
Shashank Mittal246f8d02011-01-21 17:12:27 -0800377unsigned board_machtype(void)
378{
Shashank Mittalcb25d252011-04-05 12:13:30 -0700379 board_info();
380 return hw_platform;
381}
382
383unsigned board_msm_id(void)
384{
385 board_info();
386 return target_msm_id;
Shashank Mittal246f8d02011-01-21 17:12:27 -0800387}
388
Aparna Mallavarapuc1eb99b2012-09-24 20:13:42 +0530389unsigned board_msm_version(void)
390{
391 board_info();
392 msm_version = (msm_version & 0xffff0000) >> 16;
393 return msm_version;
394}
395
Deepa Dinamani5e5c21a2012-02-16 18:59:57 -0800396crypto_engine_type board_ce_type(void)
397{
398 return platform_ce_type;
399}
400
Shashank Mittal246f8d02011-01-21 17:12:27 -0800401void reboot_device(unsigned reboot_reason)
402{
403 reboot(reboot_reason);
404}
405
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530406static int read_from_flash(struct ptentry* ptn, int offset, int size, void *dest)
407{
408 void *buffer = NULL;
409 unsigned page_size = flash_page_size();
410 unsigned page_mask = page_size - 1;
411 int read_size = (size + page_mask) & (~page_mask);
412
413 buffer = malloc(read_size);
414 if(!buffer){
415 dprintf(CRITICAL, "ERROR : Malloc failed for read_from_flash \n");
416 return -1;
417 }
418
419 if(flash_read(ptn, offset, buffer, read_size)){
420 dprintf(CRITICAL, "ERROR : Flash read failed \n");
421 return -1;
422 }
423 memcpy(dest, buffer, size);
424 free(buffer);
425 return 0;
426}
427
428static unsigned int get_fota_cookie_mtd(void)
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530429{
430 struct ptentry *ptn;
431 struct ptable *ptable;
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530432 unsigned int cookie = 0;
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530433
434 ptable = flash_get_ptable();
435 if (ptable == NULL) {
436 dprintf(CRITICAL, "ERROR: Partition table not found\n");
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530437 return 0;
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530438 }
439
440 ptn = ptable_find(ptable, "FOTA");
441 if (ptn == NULL) {
442 dprintf(CRITICAL, "ERROR: No FOTA partition found\n");
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530443 return 0;
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530444 }
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530445
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530446 if (read_from_flash(ptn, 0, sizeof(unsigned int), &cookie) == -1) {
447 dprintf(CRITICAL, "ERROR: failed to read fota cookie from flash\n");
448 return 0;
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530449 }
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530450 return cookie;
451}
452
453static int read_from_mmc(struct ptentry* ptn, int size, void *dest)
454{
455 void *buffer = NULL;
456 unsigned sector_mask = 511;
457 int read_size = (size + sector_mask) & (~sector_mask);
458
459 buffer = malloc(read_size);
460 if(!buffer){
461 dprintf(CRITICAL, "ERROR : Malloc failed for read_from_flash \n");
462 return -1;
463 }
464
465 if(mmc_read(ptn, buffer, read_size)) {
466 dprintf(CRITICAL, "ERROR : Flash read failed \n");
467 return -1;
468 }
469 memcpy(dest, buffer, size);
470 free(buffer);
471 return 0;
472}
473
474static int get_fota_cookie_mmc(void)
475{
476 unsigned long long ptn = 0;
477 int index = -1;
478 unsigned int cookie = 0;
479
480 index = partition_get_index("FOTA");
481 ptn = partition_get_offset(index);
482
483 if(ptn == 0) {
484 dprintf(CRITICAL,"ERROR: FOTA partition not found\n");
485 return 0;
486 }
487 if(read_from_mmc(ptn, sizeof(unsigned int), &cookie)) {
488 dprintf(CRITICAL, "ERROR: Cannot read cookie info\n");
489 return 0;
490 }
491 return cookie;
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530492}
493
Shashank Mittal246f8d02011-01-21 17:12:27 -0800494unsigned check_reboot_mode(void)
495{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800496 unsigned mode[2] = { 0, 0 };
Shashank Mittal246f8d02011-01-21 17:12:27 -0800497 unsigned int mode_len = sizeof(mode);
498 unsigned smem_status;
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530499 unsigned int cookie = 0;
Shashank Mittal246f8d02011-01-21 17:12:27 -0800500
501 smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800502 &mode, mode_len);
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530503
504 /*
505 * SMEM value is relied upon on power shutdown. Check either of SMEM
506 * or FOTA update cookie is set
507 */
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530508 if (target_is_emmc_boot())
509 cookie = get_fota_cookie_mmc();
510 else
511 cookie = get_fota_cookie_mtd();
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530512
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530513 if ((mode[0] == RECOVERY_MODE) || (cookie == FOTA_COOKIE))
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530514 return RECOVERY_MODE;
515
Ajay Dudanib01e5062011-12-03 23:23:42 -0800516 if (smem_status) {
517 dprintf(CRITICAL,
518 "ERROR: unable to read shared memory for reboot mode\n");
519 return 0;
Shashank Mittal246f8d02011-01-21 17:12:27 -0800520 }
521 return mode[0];
522}
523
524static unsigned target_check_power_on_reason(void)
525{
526 unsigned power_on_status = 0;
527 unsigned int status_len = sizeof(power_on_status);
528 unsigned smem_status;
529
530 smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800531 &power_on_status, status_len);
532 if (smem_status) {
533 dprintf(CRITICAL,
534 "ERROR: unable to read shared memory for power on reason\n");
Shashank Mittal246f8d02011-01-21 17:12:27 -0800535 }
536
537 return power_on_status;
538}
539
540unsigned target_pause_for_battery_charge(void)
541{
Ajay Dudaniba822332011-11-25 13:37:31 -0800542 if (target_check_power_on_reason() == PWR_ON_EVENT_WALL_CHG)
Shashank Mittal246f8d02011-01-21 17:12:27 -0800543 return 1;
544 return 0;
545}
546
547void target_battery_charging_enable(unsigned enable, unsigned disconnect)
548{
549}
Shashank Mittal59392f32011-05-01 20:49:56 -0700550
551#if _EMMC_BOOT
552void target_serialno(unsigned char *buf)
553{
554 unsigned int serialno;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800555 serialno = mmc_get_psn();
556 sprintf(buf, "%x", serialno);
Shashank Mittal59392f32011-05-01 20:49:56 -0700557}
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -0700558
559int emmc_recovery_init(void)
560{
561 int rc;
562 rc = _emmc_recovery_init();
563 return rc;
564}
Shashank Mittal59392f32011-05-01 20:49:56 -0700565#endif
Channagoud Kadabid53664b2011-12-28 16:39:15 +0530566
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530567int machine_is_evb()
Channagoud Kadabid53664b2011-12-28 16:39:15 +0530568{
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530569 int ret = 0;
570 unsigned mach_type = board_machtype();
571
572 switch(mach_type) {
573 case MSM7X27A_EVB:
574 case MSM8X25_EVB:
Aparna Mallavarapu287d89c2012-05-11 14:27:03 +0530575 case MSM8X25_EVT:
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530576 ret = 1;
577 break;
578 default:
579 ret = 0;
580 }
581 return ret;
Channagoud Kadabid53664b2011-12-28 16:39:15 +0530582}
Aparna Mallavarapuac332982012-03-18 14:02:38 +0530583int machine_is_qrd()
Channagoud Kadabib33d4832012-02-06 17:10:56 +0530584{
Aparna Mallavarapuac332982012-03-18 14:02:38 +0530585 int ret = 0;
586 unsigned mach_type = board_machtype();
Channagoud Kadabib33d4832012-02-06 17:10:56 +0530587
Aparna Mallavarapuac332982012-03-18 14:02:38 +0530588 switch(mach_type) {
589 case MSM7X27A_QRD1:
590 case MSM7X27A_QRD3:
591 case MSM8X25_QRD7:
592 ret = 1;
593 break;
594 default:
595 ret = 0;
596 }
597 return ret;
Channagoud Kadabib33d4832012-02-06 17:10:56 +0530598}
Aparna Mallavarapu332887b2012-10-11 15:51:26 +0530599int machine_is_skud()
600{
601 int ret = 0;
602 unsigned mach_type = board_machtype();
603
604 switch(mach_type) {
605 case MSM8X25Q_SKUD:
606 ret = 1;
607 break;
608 default:
609 ret = 0;
610 }
611 return ret;
612}
Channagoud Kadabi81ba1102011-10-01 16:37:59 +0530613int machine_is_8x25()
614{
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530615 int ret = 0;
616 unsigned mach_type = board_machtype();
617
618 switch(mach_type) {
619 case MSM8X25_SURF:
Aparna Mallavarapu1bb33672012-04-20 16:07:24 +0530620 case MSM8X25_FFA:
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530621 case MSM8X25_EVB:
Aparna Mallavarapu287d89c2012-05-11 14:27:03 +0530622 case MSM8X25_EVT:
Aparna Mallavarapuac332982012-03-18 14:02:38 +0530623 case MSM8X25_QRD7:
Aparna Mallavarapu332887b2012-10-11 15:51:26 +0530624 case MSM8X25Q_SKUD:
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530625 ret = 1;
626 break;
627 default:
628 ret = 0;
629 }
630 return ret;
Channagoud Kadabi81ba1102011-10-01 16:37:59 +0530631}
Channagoud Kadabibd14e2f2012-05-03 22:54:50 +0530632
633int msm_is_7x25a(int msm_id)
634{
635 int ret = 0;
636
637 switch (msm_id) {
638 case MSM7225A:
639 case MSM7625A:
640 case ESM7225A:
641 case MSM7225AA:
642 case MSM7625AA:
643 case ESM7225AA:
644 case MSM7225AB:
645 case MSM7625AB:
646 case ESM7225AB:
Channagoud Kadabi647f0852012-06-08 11:51:45 +0530647 case MSM7125A:
Channagoud Kadabibd14e2f2012-05-03 22:54:50 +0530648 ret = 1;
649 break;
650 default:
651 ret = 0;
652 };
653 return ret;
654}
Amol Jadida118b92012-07-06 19:53:18 -0700655
656static void target_ulpi_init(void)
657{
658 unsigned int reg;
659
660 ulpi_read(0x31);
661 dprintf(INFO, " Value of ulpi read 0x31 is %08x\n", reg);
662 /* todo : the write back value should be calculated according to
663 * reg &= 0xF3 but sometimes the value that is read initially
664 * doesnt look right
665 */
666 ulpi_write(0x4A, 0x31);
667 reg = ulpi_read(0x31);
668 dprintf(INFO, " Value of ulpi read 0x31 after write is %08x\n", reg);
669
670 reg = ulpi_read(0x32);
671 dprintf(INFO, " Value of ulpi read 0x32 is %08x\n", reg);
672 ulpi_write(0x30, 0x32);
673 reg = ulpi_read(0x32);
674 dprintf(INFO, " Value of ulpi read 0x32 after write is %08x\n", reg);
675
676 reg = ulpi_read(0x36);
677 dprintf(INFO, " Value of ulpi read 0x36 is %08x\n", reg);
678 ulpi_write(reg | 0x2, 0x36);
679 reg = ulpi_read(0x36);
680 dprintf(INFO, " Value of ulpi read 0x36 after write is %08x\n", reg);
681}
682
683void target_usb_init(void)
684{
685 target_ulpi_init();
686}
Channagoud Kadabif2488462012-06-12 15:22:48 +0530687
688int target_cont_splash_screen()
689{
690 int ret = 0;
691 unsigned mach_type = 0;
692
693 mach_type = board_machtype();
694
695 switch(mach_type) {
696 case MSM8X25_EVB:
697 case MSM8X25_EVT:
Channagoud Kadabicdda0fe2012-07-13 11:44:28 +0530698 case MSM8X25_QRD7:
Channagoud Kadabif2488462012-06-12 15:22:48 +0530699 ret = 1;
700 break;
701 default:
702 ret = 0;
703 };
704 return ret;
705}
Channagoud Kadabib3e08032012-09-25 16:04:16 +0530706
707int target_is_sku3()
708{
709 int ret = 0;
710 unsigned mach_type = 0;
711
712 mach_type = board_machtype();
713
714 switch(mach_type) {
715 case MSM7X27A_QRD3:
716 ret = 1;
717 break;
718 default:
719 ret = 0;
720 };
721 return ret;
722}