blob: 7f73ee3bfaeefd9d68b1af1eb5db72a07d0ec783 [file] [log] [blame]
Shashank Mittal246f8d02011-01-21 17:12:27 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Channagoud Kadabi3acfb742011-11-15 18:19:32 +05304 * Copyright (c) 2009-2012, Code Aurora Forum. 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;
Shashank Mittal246f8d02011-01-21 17:12:27 -080057
Deepa Dinamani5e5c21a2012-02-16 18:59:57 -080058/* Setting this variable to different values defines the
59 * behavior of CE engine:
60 * platform_ce_type = CRYPTO_ENGINE_TYPE_NONE : No CE engine
61 * platform_ce_type = CRYPTO_ENGINE_TYPE_SW : Software CE engine
62 * platform_ce_type = CRYPTO_ENGINE_TYPE_HW : Hardware CE engine
63 * Behavior is determined in the target code.
64 */
65static crypto_engine_type platform_ce_type = CRYPTO_ENGINE_TYPE_SW;
66
Channagoud Kadabi3acfb742011-11-15 18:19:32 +053067int machine_is_evb();
Channagoud Kadabid53664b2011-12-28 16:39:15 +053068
Shashank Mittal246f8d02011-01-21 17:12:27 -080069/* for these partitions, start will be offset by either what we get from
70 * smem, or from the above offset if smem is not useful. Also, we should
71 * probably have smem_ptable code populate our flash_ptable.
72 *
73 * When smem provides us with a full partition table, we can get rid of
74 * this altogether.
75 *
76 */
Channagoud Kadabib3e08032012-09-25 16:04:16 +053077static struct ptentry board_part_list_default[] = {
Shashank Mittal246f8d02011-01-21 17:12:27 -080078 {
Ajay Dudanib01e5062011-12-03 23:23:42 -080079 .start = 0,
80 .length = 10 /* In MB */ ,
81 .name = "boot",
82 },
Shashank Mittal246f8d02011-01-21 17:12:27 -080083 {
Ajay Dudanib01e5062011-12-03 23:23:42 -080084 .start = DIFF_START_ADDR,
Channagoud Kadabi71961882012-02-09 16:32:41 +053085 .length = 253 /* In MB */ ,
Ajay Dudanib01e5062011-12-03 23:23:42 -080086 .name = "system",
87 },
Shashank Mittal246f8d02011-01-21 17:12:27 -080088 {
Ajay Dudanib01e5062011-12-03 23:23:42 -080089 .start = DIFF_START_ADDR,
Channagoud Kadabi2ce67412012-09-11 18:26:27 +053090 .length = 80 /* In MB */ ,
Ajay Dudanib01e5062011-12-03 23:23:42 -080091 .name = "cache",
92 },
Shashank Mittal246f8d02011-01-21 17:12:27 -080093 {
Ajay Dudanib01e5062011-12-03 23:23:42 -080094 .start = DIFF_START_ADDR,
95 .length = 4 /* In MB */ ,
96 .name = "misc",
97 },
Shashank Mittal246f8d02011-01-21 17:12:27 -080098 {
Ajay Dudanib01e5062011-12-03 23:23:42 -080099 .start = DIFF_START_ADDR,
100 .length = VARIABLE_LENGTH,
101 .name = "userdata",
102 },
Shashank Mittal246f8d02011-01-21 17:12:27 -0800103 {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800104 .start = DIFF_START_ADDR,
105 .length = 4 /* In MB */ ,
106 .name = "persist",
107 },
Shashank Mittal246f8d02011-01-21 17:12:27 -0800108 {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800109 .start = DIFF_START_ADDR,
110 .length = 10 /* In MB */ ,
111 .name = "recovery",
112 },
Shashank Mittal246f8d02011-01-21 17:12:27 -0800113};
Ajay Dudanib01e5062011-12-03 23:23:42 -0800114
Channagoud Kadabib3e08032012-09-25 16:04:16 +0530115/*
116 * SKU3 & SKU PVT devices use the same micron NAND device with different density,
117 * due to this SKU3 partition creation fails as the number of blocks calculated
118 * from flash density is wrong, To avoid this use a different partition table &
119 * move the variable length partition to the end, this way kernel will truncate
120 * the variable length partition & we need not add target checks in the shared
121 * nand driver code.
122 */
123
124static struct ptentry board_part_list_sku3[] = {
125 {
126 .start = 0,
127 .length = 10 /* In MB */ ,
128 .name = "boot",
129 },
130 {
131 .start = DIFF_START_ADDR,
132 .length = 253 /* In MB */ ,
133 .name = "system",
134 },
135 {
136 .start = DIFF_START_ADDR,
137 .length = 80 /* In MB */ ,
138 .name = "cache",
139 },
140 {
141 .start = DIFF_START_ADDR,
142 .length = 4 /* In MB */ ,
143 .name = "misc",
144 },
145 {
146 .start = DIFF_START_ADDR,
147 .length = 4 /* In MB */ ,
148 .name = "persist",
149 },
150 {
151 .start = DIFF_START_ADDR,
152 .length = 10 /* In MB */ ,
153 .name = "recovery",
154 },
155 {
156 .start = DIFF_START_ADDR,
157 .length = VARIABLE_LENGTH,
158 .name = "userdata",
159 },
160};
161
162static int num_parts = sizeof(board_part_list_default) / sizeof(struct ptentry);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800163
Shashank Mittal246f8d02011-01-21 17:12:27 -0800164void smem_ptable_init(void);
165unsigned smem_get_apps_flash_start(void);
166
167void keypad_init(void);
168
169int target_is_emmc_boot(void);
170
171void target_init(void)
172{
173 unsigned offset;
174 struct flash_info *flash_info;
Channagoud Kadabib3e08032012-09-25 16:04:16 +0530175 struct ptentry *board_part_list;
Shashank Mittal246f8d02011-01-21 17:12:27 -0800176 unsigned total_num_of_blocks;
177 unsigned next_ptr_start_adr = 0;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800178 unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive */
Shashank Mittal246f8d02011-01-21 17:12:27 -0800179 int i;
180
181 dprintf(INFO, "target_init()\n");
182
Shashank Mittal246f8d02011-01-21 17:12:27 -0800183#if (!ENABLE_NANDWRITE)
184 keys_init();
185 keypad_init();
186#endif
Shashank Mittal246f8d02011-01-21 17:12:27 -0800187
Kinson Chikce306ff2011-07-08 15:23:33 -0700188 /* Display splash screen if enabled */
189#if DISPLAY_SPLASH_SCREEN
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530190 display_init();
191 dprintf(SPEW, "Diplay initialized\n");
Kinson Chikce306ff2011-07-08 15:23:33 -0700192#endif
193
Ajay Dudanib01e5062011-12-03 23:23:42 -0800194 if (target_is_emmc_boot()) {
Amol Jadi2dfe3392011-07-19 16:03:37 -0700195 /* Must wait for modem-up before we can intialize MMC.
196 */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800197 while (readl(MSM_SHARED_BASE + 0x14) != 1) ;
Amol Jadi2dfe3392011-07-19 16:03:37 -0700198
Ajay Dudanib01e5062011-12-03 23:23:42 -0800199 if (mmc_boot_main(MMC_SLOT, MSM_SDC3_BASE)) {
Shashank Mittal246f8d02011-01-21 17:12:27 -0800200 dprintf(CRITICAL, "mmc init failed!");
201 ASSERT(0);
202 }
203 return;
204 }
205
206 ptable_init(&flash_ptable);
207 smem_ptable_init();
208
209 flash_init();
210 flash_info = flash_get_info();
211 ASSERT(flash_info);
212
213 offset = smem_get_apps_flash_start();
214 if (offset == 0xffffffff)
Ajay Dudanib01e5062011-12-03 23:23:42 -0800215 while (1) ;
Shashank Mittal246f8d02011-01-21 17:12:27 -0800216
217 total_num_of_blocks = flash_info->num_blocks;
218 blocks_per_1MB = (1 << 20) / (flash_info->block_size);
219
Channagoud Kadabib3e08032012-09-25 16:04:16 +0530220 if (target_is_sku3())
221 board_part_list = board_part_list_sku3;
222 else
223 board_part_list = board_part_list_default;
224
Shashank Mittal246f8d02011-01-21 17:12:27 -0800225 for (i = 0; i < num_parts; i++) {
226 struct ptentry *ptn = &board_part_list[i];
227 unsigned len = ((ptn->length) * blocks_per_1MB);
228
Ajay Dudanib01e5062011-12-03 23:23:42 -0800229 if (ptn->start != 0)
230 ASSERT(ptn->start == DIFF_START_ADDR);
Shashank Mittal246f8d02011-01-21 17:12:27 -0800231
232 ptn->start = next_ptr_start_adr;
233
Ajay Dudanib01e5062011-12-03 23:23:42 -0800234 if (ptn->length == VARIABLE_LENGTH) {
Shashank Mittal246f8d02011-01-21 17:12:27 -0800235 unsigned length_for_prt = 0;
236 unsigned j;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800237 for (j = i + 1; j < num_parts; j++) {
238 struct ptentry *temp_ptn = &board_part_list[j];
239 ASSERT(temp_ptn->length != VARIABLE_LENGTH);
240 length_for_prt +=
241 ((temp_ptn->length) * blocks_per_1MB);
Shashank Mittal246f8d02011-01-21 17:12:27 -0800242 }
Ajay Dudanib01e5062011-12-03 23:23:42 -0800243 len =
244 (total_num_of_blocks - 1) - (offset + ptn->start +
245 length_for_prt);
Shashank Mittal246f8d02011-01-21 17:12:27 -0800246 ASSERT(len >= 0);
247 }
248 next_ptr_start_adr = ptn->start + len;
249 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800250 len, ptn->flags, TYPE_APPS_PARTITION,
251 PERM_WRITEABLE);
Shashank Mittal246f8d02011-01-21 17:12:27 -0800252 }
253
254 smem_add_modem_partitions(&flash_ptable);
255
256 ptable_dump(&flash_ptable);
257 flash_set_ptable(&flash_ptable);
258}
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;
Shashank Mittalcb25d252011-04-05 12:13:30 -0700287 }
288 }
289
Channagoud Kadabi4c41c412011-09-08 15:38:30 +0530290 /* Detect SURF v/s FFA v/s QRD */
Aparna Mallavarapu51879412012-08-27 12:55:50 +0530291 if (target_msm_id >= MSM8225 && target_msm_id <= MSM8625
292 || (target_msm_id == MSM8125A)) {
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530293 switch (id) {
294 case 0x1:
295 hw_platform = MSM8X25_SURF;
296 break;
Aparna Mallavarapu1bb33672012-04-20 16:07:24 +0530297 case 0x2:
298 hw_platform = MSM8X25_FFA;
299 break;
Aparna Mallavarapubac9a722012-05-22 10:15:29 +0530300 case 0x10:
Aparna Mallavarapu287d89c2012-05-11 14:27:03 +0530301 hw_platform = MSM8X25_EVT;
302 break;
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530303 case 0xC:
304 hw_platform = MSM8X25_EVB;
305 break;
Aparna Mallavarapuac332982012-03-18 14:02:38 +0530306 case 0xF:
307 hw_platform = MSM8X25_QRD7;
308 break;
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530309 default:
310 hw_platform = MSM8X25_SURF;
311 }
312 } else {
313 switch (id) {
314 case 0x1:
315 /* Set the machine type based on msm ID */
Channagoud Kadabibd14e2f2012-05-03 22:54:50 +0530316 if (msm_is_7x25a(target_msm_id))
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530317 hw_platform = MSM7X25A_SURF;
Channagoud Kadabi849ad5e2012-04-02 23:21:21 +0530318 else
319 hw_platform = MSM7X27A_SURF;
320 break;
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530321 case 0x2:
Channagoud Kadabibd14e2f2012-05-03 22:54:50 +0530322 if (msm_is_7x25a(target_msm_id))
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530323 hw_platform = MSM7X25A_FFA;
Channagoud Kadabi849ad5e2012-04-02 23:21:21 +0530324 else
325 hw_platform = MSM7X27A_FFA;
326 break;
327 case 0xB:
328 if(target_is_emmc_boot())
329 hw_platform = MSM7X27A_QRD1;
330 else
331 hw_platform = MSM7X27A_QRD3;
332 break;
333 case 0xC:
334 hw_platform = MSM7X27A_EVB;
335 break;
336 case 0xF:
Channagoud Kadabib33d4832012-02-06 17:10:56 +0530337 hw_platform = MSM7X27A_QRD3;
Channagoud Kadabi849ad5e2012-04-02 23:21:21 +0530338 break;
339 default:
Channagoud Kadabibd14e2f2012-05-03 22:54:50 +0530340 if (msm_is_7x25a(target_msm_id))
Channagoud Kadabi849ad5e2012-04-02 23:21:21 +0530341 hw_platform = MSM7X25A_SURF;
342 else
343 hw_platform = MSM7X27A_SURF;
344 };
345 }
Ajay Dudanib01e5062011-12-03 23:23:42 -0800346 /* Set msm ID for target variants based on values read from smem */
347 switch (target_msm_id) {
348 case MSM7225A:
349 case MSM7625A:
350 case ESM7225A:
351 case MSM7225AA:
352 case MSM7625AA:
353 case ESM7225AA:
Channagoud Kadabibd14e2f2012-05-03 22:54:50 +0530354 case MSM7225AB:
355 case MSM7625AB:
356 case ESM7225AB:
Channagoud Kadabi647f0852012-06-08 11:51:45 +0530357 case MSM7125A:
Ajay Dudanib01e5062011-12-03 23:23:42 -0800358 target_msm_id = MSM7625A;
359 break;
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530360 case MSM8225:
361 case MSM8625:
Aparna Mallavarapu51879412012-08-27 12:55:50 +0530362 case MSM8125A:
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530363 target_msm_id = MSM8625;
364 break;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800365 default:
366 target_msm_id = MSM7627A;
Shashank Mittalcb25d252011-04-05 12:13:30 -0700367 }
368 }
369 return;
370}
371
Shashank Mittal246f8d02011-01-21 17:12:27 -0800372unsigned board_machtype(void)
373{
Shashank Mittalcb25d252011-04-05 12:13:30 -0700374 board_info();
375 return hw_platform;
376}
377
378unsigned board_msm_id(void)
379{
380 board_info();
381 return target_msm_id;
Shashank Mittal246f8d02011-01-21 17:12:27 -0800382}
383
Deepa Dinamani5e5c21a2012-02-16 18:59:57 -0800384crypto_engine_type board_ce_type(void)
385{
386 return platform_ce_type;
387}
388
Shashank Mittal246f8d02011-01-21 17:12:27 -0800389void reboot_device(unsigned reboot_reason)
390{
391 reboot(reboot_reason);
392}
393
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530394static int read_from_flash(struct ptentry* ptn, int offset, int size, void *dest)
395{
396 void *buffer = NULL;
397 unsigned page_size = flash_page_size();
398 unsigned page_mask = page_size - 1;
399 int read_size = (size + page_mask) & (~page_mask);
400
401 buffer = malloc(read_size);
402 if(!buffer){
403 dprintf(CRITICAL, "ERROR : Malloc failed for read_from_flash \n");
404 return -1;
405 }
406
407 if(flash_read(ptn, offset, buffer, read_size)){
408 dprintf(CRITICAL, "ERROR : Flash read failed \n");
409 return -1;
410 }
411 memcpy(dest, buffer, size);
412 free(buffer);
413 return 0;
414}
415
416static unsigned int get_fota_cookie_mtd(void)
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530417{
418 struct ptentry *ptn;
419 struct ptable *ptable;
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530420 unsigned int cookie = 0;
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530421
422 ptable = flash_get_ptable();
423 if (ptable == NULL) {
424 dprintf(CRITICAL, "ERROR: Partition table not found\n");
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530425 return 0;
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530426 }
427
428 ptn = ptable_find(ptable, "FOTA");
429 if (ptn == NULL) {
430 dprintf(CRITICAL, "ERROR: No FOTA partition found\n");
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530431 return 0;
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530432 }
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530433
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530434 if (read_from_flash(ptn, 0, sizeof(unsigned int), &cookie) == -1) {
435 dprintf(CRITICAL, "ERROR: failed to read fota cookie from flash\n");
436 return 0;
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530437 }
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530438 return cookie;
439}
440
441static int read_from_mmc(struct ptentry* ptn, int size, void *dest)
442{
443 void *buffer = NULL;
444 unsigned sector_mask = 511;
445 int read_size = (size + sector_mask) & (~sector_mask);
446
447 buffer = malloc(read_size);
448 if(!buffer){
449 dprintf(CRITICAL, "ERROR : Malloc failed for read_from_flash \n");
450 return -1;
451 }
452
453 if(mmc_read(ptn, buffer, read_size)) {
454 dprintf(CRITICAL, "ERROR : Flash read failed \n");
455 return -1;
456 }
457 memcpy(dest, buffer, size);
458 free(buffer);
459 return 0;
460}
461
462static int get_fota_cookie_mmc(void)
463{
464 unsigned long long ptn = 0;
465 int index = -1;
466 unsigned int cookie = 0;
467
468 index = partition_get_index("FOTA");
469 ptn = partition_get_offset(index);
470
471 if(ptn == 0) {
472 dprintf(CRITICAL,"ERROR: FOTA partition not found\n");
473 return 0;
474 }
475 if(read_from_mmc(ptn, sizeof(unsigned int), &cookie)) {
476 dprintf(CRITICAL, "ERROR: Cannot read cookie info\n");
477 return 0;
478 }
479 return cookie;
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530480}
481
Shashank Mittal246f8d02011-01-21 17:12:27 -0800482unsigned check_reboot_mode(void)
483{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800484 unsigned mode[2] = { 0, 0 };
Shashank Mittal246f8d02011-01-21 17:12:27 -0800485 unsigned int mode_len = sizeof(mode);
486 unsigned smem_status;
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530487 unsigned int cookie = 0;
Shashank Mittal246f8d02011-01-21 17:12:27 -0800488
489 smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800490 &mode, mode_len);
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530491
492 /*
493 * SMEM value is relied upon on power shutdown. Check either of SMEM
494 * or FOTA update cookie is set
495 */
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530496 if (target_is_emmc_boot())
497 cookie = get_fota_cookie_mmc();
498 else
499 cookie = get_fota_cookie_mtd();
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530500
Channagoud Kadabi16f50952012-04-02 16:24:07 +0530501 if ((mode[0] == RECOVERY_MODE) || (cookie == FOTA_COOKIE))
Channagoud Kadabi16da3a22011-10-24 20:25:07 +0530502 return RECOVERY_MODE;
503
Ajay Dudanib01e5062011-12-03 23:23:42 -0800504 if (smem_status) {
505 dprintf(CRITICAL,
506 "ERROR: unable to read shared memory for reboot mode\n");
507 return 0;
Shashank Mittal246f8d02011-01-21 17:12:27 -0800508 }
509 return mode[0];
510}
511
512static unsigned target_check_power_on_reason(void)
513{
514 unsigned power_on_status = 0;
515 unsigned int status_len = sizeof(power_on_status);
516 unsigned smem_status;
517
518 smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800519 &power_on_status, status_len);
520 if (smem_status) {
521 dprintf(CRITICAL,
522 "ERROR: unable to read shared memory for power on reason\n");
Shashank Mittal246f8d02011-01-21 17:12:27 -0800523 }
524
525 return power_on_status;
526}
527
528unsigned target_pause_for_battery_charge(void)
529{
Ajay Dudaniba822332011-11-25 13:37:31 -0800530 if (target_check_power_on_reason() == PWR_ON_EVENT_WALL_CHG)
Shashank Mittal246f8d02011-01-21 17:12:27 -0800531 return 1;
532 return 0;
533}
534
535void target_battery_charging_enable(unsigned enable, unsigned disconnect)
536{
537}
Shashank Mittal59392f32011-05-01 20:49:56 -0700538
539#if _EMMC_BOOT
540void target_serialno(unsigned char *buf)
541{
542 unsigned int serialno;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800543 serialno = mmc_get_psn();
544 sprintf(buf, "%x", serialno);
Shashank Mittal59392f32011-05-01 20:49:56 -0700545}
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -0700546
547int emmc_recovery_init(void)
548{
549 int rc;
550 rc = _emmc_recovery_init();
551 return rc;
552}
Shashank Mittal59392f32011-05-01 20:49:56 -0700553#endif
Channagoud Kadabid53664b2011-12-28 16:39:15 +0530554
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530555int machine_is_evb()
Channagoud Kadabid53664b2011-12-28 16:39:15 +0530556{
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530557 int ret = 0;
558 unsigned mach_type = board_machtype();
559
560 switch(mach_type) {
561 case MSM7X27A_EVB:
562 case MSM8X25_EVB:
Aparna Mallavarapu287d89c2012-05-11 14:27:03 +0530563 case MSM8X25_EVT:
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530564 ret = 1;
565 break;
566 default:
567 ret = 0;
568 }
569 return ret;
Channagoud Kadabid53664b2011-12-28 16:39:15 +0530570}
Aparna Mallavarapuac332982012-03-18 14:02:38 +0530571int machine_is_qrd()
Channagoud Kadabib33d4832012-02-06 17:10:56 +0530572{
Aparna Mallavarapuac332982012-03-18 14:02:38 +0530573 int ret = 0;
574 unsigned mach_type = board_machtype();
Channagoud Kadabib33d4832012-02-06 17:10:56 +0530575
Aparna Mallavarapuac332982012-03-18 14:02:38 +0530576 switch(mach_type) {
577 case MSM7X27A_QRD1:
578 case MSM7X27A_QRD3:
579 case MSM8X25_QRD7:
580 ret = 1;
581 break;
582 default:
583 ret = 0;
584 }
585 return ret;
Channagoud Kadabib33d4832012-02-06 17:10:56 +0530586}
Channagoud Kadabi81ba1102011-10-01 16:37:59 +0530587int machine_is_8x25()
588{
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530589 int ret = 0;
590 unsigned mach_type = board_machtype();
591
592 switch(mach_type) {
593 case MSM8X25_SURF:
Aparna Mallavarapu1bb33672012-04-20 16:07:24 +0530594 case MSM8X25_FFA:
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530595 case MSM8X25_EVB:
Aparna Mallavarapu287d89c2012-05-11 14:27:03 +0530596 case MSM8X25_EVT:
Aparna Mallavarapuac332982012-03-18 14:02:38 +0530597 case MSM8X25_QRD7:
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530598 ret = 1;
599 break;
600 default:
601 ret = 0;
602 }
603 return ret;
Channagoud Kadabi81ba1102011-10-01 16:37:59 +0530604}
Channagoud Kadabibd14e2f2012-05-03 22:54:50 +0530605
606int msm_is_7x25a(int msm_id)
607{
608 int ret = 0;
609
610 switch (msm_id) {
611 case MSM7225A:
612 case MSM7625A:
613 case ESM7225A:
614 case MSM7225AA:
615 case MSM7625AA:
616 case ESM7225AA:
617 case MSM7225AB:
618 case MSM7625AB:
619 case ESM7225AB:
Channagoud Kadabi647f0852012-06-08 11:51:45 +0530620 case MSM7125A:
Channagoud Kadabibd14e2f2012-05-03 22:54:50 +0530621 ret = 1;
622 break;
623 default:
624 ret = 0;
625 };
626 return ret;
627}
Amol Jadida118b92012-07-06 19:53:18 -0700628
629static void target_ulpi_init(void)
630{
631 unsigned int reg;
632
633 ulpi_read(0x31);
634 dprintf(INFO, " Value of ulpi read 0x31 is %08x\n", reg);
635 /* todo : the write back value should be calculated according to
636 * reg &= 0xF3 but sometimes the value that is read initially
637 * doesnt look right
638 */
639 ulpi_write(0x4A, 0x31);
640 reg = ulpi_read(0x31);
641 dprintf(INFO, " Value of ulpi read 0x31 after write is %08x\n", reg);
642
643 reg = ulpi_read(0x32);
644 dprintf(INFO, " Value of ulpi read 0x32 is %08x\n", reg);
645 ulpi_write(0x30, 0x32);
646 reg = ulpi_read(0x32);
647 dprintf(INFO, " Value of ulpi read 0x32 after write is %08x\n", reg);
648
649 reg = ulpi_read(0x36);
650 dprintf(INFO, " Value of ulpi read 0x36 is %08x\n", reg);
651 ulpi_write(reg | 0x2, 0x36);
652 reg = ulpi_read(0x36);
653 dprintf(INFO, " Value of ulpi read 0x36 after write is %08x\n", reg);
654}
655
656void target_usb_init(void)
657{
658 target_ulpi_init();
659}
Channagoud Kadabif2488462012-06-12 15:22:48 +0530660
661int target_cont_splash_screen()
662{
663 int ret = 0;
664 unsigned mach_type = 0;
665
666 mach_type = board_machtype();
667
668 switch(mach_type) {
669 case MSM8X25_EVB:
670 case MSM8X25_EVT:
Channagoud Kadabicdda0fe2012-07-13 11:44:28 +0530671 case MSM8X25_QRD7:
Channagoud Kadabif2488462012-06-12 15:22:48 +0530672 ret = 1;
673 break;
674 default:
675 ret = 0;
676 };
677 return ret;
678}
Channagoud Kadabib3e08032012-09-25 16:04:16 +0530679
680int target_is_sku3()
681{
682 int ret = 0;
683 unsigned mach_type = 0;
684
685 mach_type = board_machtype();
686
687 switch(mach_type) {
688 case MSM7X27A_QRD3:
689 ret = 1;
690 break;
691 default:
692 ret = 0;
693 };
694 return ret;
695}