Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 4 | * Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved. |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 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 Jadi | 2dfe339 | 2011-07-19 16:03:37 -0700 | [diff] [blame] | 33 | #include <reg.h> |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 34 | #include <debug.h> |
| 35 | #include <dev/keys.h> |
Kinson Chik | ea64624 | 2011-09-01 13:53:16 -0700 | [diff] [blame] | 36 | #include <dev/ssbi.h> |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 37 | #include <lib/ptable.h> |
| 38 | #include <dev/flash.h> |
| 39 | #include <smem.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 40 | #include <mmc.h> |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 41 | #include <platform/iomap.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 42 | #include <platform.h> |
Deepa Dinamani | 5e5c21a | 2012-02-16 18:59:57 -0800 | [diff] [blame] | 43 | #include <crypto_hash.h> |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 44 | |
| 45 | #define MSM7X27A_FFA 3351 |
| 46 | #define MSM7X27A_SURF 3352 |
| 47 | #define MSM7X27A_RUMI3 3353 |
Channagoud Kadabi | 4c41c41 | 2011-09-08 15:38:30 +0530 | [diff] [blame] | 48 | #define MSM7X27A_QRD1 3756 |
Channagoud Kadabi | 8110068 | 2011-07-26 16:14:29 +0530 | [diff] [blame] | 49 | #define MSM7X25A_SURF 3772 |
| 50 | #define MSM7X25A_FFA 3771 |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 51 | #define MSM7X27A_EVB 3934 |
Channagoud Kadabi | b33d483 | 2012-02-06 17:10:56 +0530 | [diff] [blame] | 52 | #define MSM7X27A_QRD3 4005 |
Channagoud Kadabi | 81ba110 | 2011-10-01 16:37:59 +0530 | [diff] [blame] | 53 | #define MSM8X25_RUMI3 3871 |
Channagoud Kadabi | 4c41c41 | 2011-09-08 15:38:30 +0530 | [diff] [blame] | 54 | |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 55 | #define MSM8X25_SURF 4037 |
| 56 | #define MSM8X25_EVB 4042 |
Aparna Mallavarapu | ac33298 | 2012-03-18 14:02:38 +0530 | [diff] [blame] | 57 | #define MSM8X25_QRD7 4095 |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 58 | |
Shashank Mittal | ef32541 | 2011-04-01 13:48:26 -0700 | [diff] [blame] | 59 | #define LINUX_MACHTYPE MSM7X27A_SURF |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 60 | |
| 61 | #define VARIABLE_LENGTH 0x10101010 |
| 62 | #define DIFF_START_ADDR 0xF0F0F0F0 |
| 63 | #define NUM_PAGES_PER_BLOCK 0x40 |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 64 | #define RECOVERY_MODE 0x77665502 |
| 65 | #define FOTA_COOKIE 0x64645343 |
| 66 | |
| 67 | unsigned int fota_cookie[1]; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 68 | |
| 69 | static struct ptable flash_ptable; |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 70 | unsigned hw_platform = 0; |
| 71 | unsigned target_msm_id = 0; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 72 | |
Deepa Dinamani | 5e5c21a | 2012-02-16 18:59:57 -0800 | [diff] [blame] | 73 | /* Setting this variable to different values defines the |
| 74 | * behavior of CE engine: |
| 75 | * platform_ce_type = CRYPTO_ENGINE_TYPE_NONE : No CE engine |
| 76 | * platform_ce_type = CRYPTO_ENGINE_TYPE_SW : Software CE engine |
| 77 | * platform_ce_type = CRYPTO_ENGINE_TYPE_HW : Hardware CE engine |
| 78 | * Behavior is determined in the target code. |
| 79 | */ |
| 80 | static crypto_engine_type platform_ce_type = CRYPTO_ENGINE_TYPE_SW; |
| 81 | |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 82 | int machine_is_evb(); |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 83 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 84 | /* for these partitions, start will be offset by either what we get from |
| 85 | * smem, or from the above offset if smem is not useful. Also, we should |
| 86 | * probably have smem_ptable code populate our flash_ptable. |
| 87 | * |
| 88 | * When smem provides us with a full partition table, we can get rid of |
| 89 | * this altogether. |
| 90 | * |
| 91 | */ |
Channagoud Kadabi | e57173d | 2011-12-19 15:42:44 +0530 | [diff] [blame] | 92 | static struct ptentry board_part_list[] = { |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 93 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 94 | .start = 0, |
| 95 | .length = 10 /* In MB */ , |
| 96 | .name = "boot", |
| 97 | }, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 98 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 99 | .start = DIFF_START_ADDR, |
Channagoud Kadabi | 7196188 | 2012-02-09 16:32:41 +0530 | [diff] [blame] | 100 | .length = 253 /* In MB */ , |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 101 | .name = "system", |
| 102 | }, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 103 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 104 | .start = DIFF_START_ADDR, |
| 105 | .length = 40 /* In MB */ , |
| 106 | .name = "cache", |
| 107 | }, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 108 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 109 | .start = DIFF_START_ADDR, |
| 110 | .length = 4 /* In MB */ , |
| 111 | .name = "misc", |
| 112 | }, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 113 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 114 | .start = DIFF_START_ADDR, |
| 115 | .length = VARIABLE_LENGTH, |
| 116 | .name = "userdata", |
| 117 | }, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 118 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 119 | .start = DIFF_START_ADDR, |
| 120 | .length = 4 /* In MB */ , |
| 121 | .name = "persist", |
| 122 | }, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 123 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 124 | .start = DIFF_START_ADDR, |
| 125 | .length = 10 /* In MB */ , |
| 126 | .name = "recovery", |
| 127 | }, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 128 | }; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 129 | |
Channagoud Kadabi | e57173d | 2011-12-19 15:42:44 +0530 | [diff] [blame] | 130 | static int num_parts = sizeof(board_part_list) / sizeof(struct ptentry); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 131 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 132 | void smem_ptable_init(void); |
| 133 | unsigned smem_get_apps_flash_start(void); |
| 134 | |
| 135 | void keypad_init(void); |
| 136 | |
| 137 | int target_is_emmc_boot(void); |
| 138 | |
| 139 | void target_init(void) |
| 140 | { |
| 141 | unsigned offset; |
| 142 | struct flash_info *flash_info; |
| 143 | unsigned total_num_of_blocks; |
| 144 | unsigned next_ptr_start_adr = 0; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 145 | unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive */ |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 146 | int i; |
| 147 | |
| 148 | dprintf(INFO, "target_init()\n"); |
| 149 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 150 | #if (!ENABLE_NANDWRITE) |
| 151 | keys_init(); |
| 152 | keypad_init(); |
| 153 | #endif |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 154 | |
Kinson Chik | ce306ff | 2011-07-08 15:23:33 -0700 | [diff] [blame] | 155 | /* Display splash screen if enabled */ |
| 156 | #if DISPLAY_SPLASH_SCREEN |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 157 | /* EVB platform comes with a new display panel, Until |
| 158 | * support for new panel is added disable splash screen |
| 159 | * for EVB |
| 160 | */ |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 161 | if (!machine_is_evb()) { |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 162 | display_init(); |
| 163 | dprintf(SPEW, "Diplay initialized\n"); |
| 164 | display_image_on_screen(); |
| 165 | } |
Kinson Chik | ce306ff | 2011-07-08 15:23:33 -0700 | [diff] [blame] | 166 | #endif |
| 167 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 168 | if (target_is_emmc_boot()) { |
Amol Jadi | 2dfe339 | 2011-07-19 16:03:37 -0700 | [diff] [blame] | 169 | /* Must wait for modem-up before we can intialize MMC. |
| 170 | */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 171 | while (readl(MSM_SHARED_BASE + 0x14) != 1) ; |
Amol Jadi | 2dfe339 | 2011-07-19 16:03:37 -0700 | [diff] [blame] | 172 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 173 | if (mmc_boot_main(MMC_SLOT, MSM_SDC3_BASE)) { |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 174 | dprintf(CRITICAL, "mmc init failed!"); |
| 175 | ASSERT(0); |
| 176 | } |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | ptable_init(&flash_ptable); |
| 181 | smem_ptable_init(); |
| 182 | |
| 183 | flash_init(); |
| 184 | flash_info = flash_get_info(); |
| 185 | ASSERT(flash_info); |
| 186 | |
| 187 | offset = smem_get_apps_flash_start(); |
| 188 | if (offset == 0xffffffff) |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 189 | while (1) ; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 190 | |
| 191 | total_num_of_blocks = flash_info->num_blocks; |
| 192 | blocks_per_1MB = (1 << 20) / (flash_info->block_size); |
| 193 | |
| 194 | for (i = 0; i < num_parts; i++) { |
| 195 | struct ptentry *ptn = &board_part_list[i]; |
| 196 | unsigned len = ((ptn->length) * blocks_per_1MB); |
| 197 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 198 | if (ptn->start != 0) |
| 199 | ASSERT(ptn->start == DIFF_START_ADDR); |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 200 | |
| 201 | ptn->start = next_ptr_start_adr; |
| 202 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 203 | if (ptn->length == VARIABLE_LENGTH) { |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 204 | unsigned length_for_prt = 0; |
| 205 | unsigned j; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 206 | for (j = i + 1; j < num_parts; j++) { |
| 207 | struct ptentry *temp_ptn = &board_part_list[j]; |
| 208 | ASSERT(temp_ptn->length != VARIABLE_LENGTH); |
| 209 | length_for_prt += |
| 210 | ((temp_ptn->length) * blocks_per_1MB); |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 211 | } |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 212 | len = |
| 213 | (total_num_of_blocks - 1) - (offset + ptn->start + |
| 214 | length_for_prt); |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 215 | ASSERT(len >= 0); |
| 216 | } |
| 217 | next_ptr_start_adr = ptn->start + len; |
| 218 | ptable_add(&flash_ptable, ptn->name, offset + ptn->start, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 219 | len, ptn->flags, TYPE_APPS_PARTITION, |
| 220 | PERM_WRITEABLE); |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | smem_add_modem_partitions(&flash_ptable); |
| 224 | |
| 225 | ptable_dump(&flash_ptable); |
| 226 | flash_set_ptable(&flash_ptable); |
| 227 | } |
| 228 | |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 229 | void board_info(void) |
| 230 | { |
| 231 | struct smem_board_info_v4 board_info_v4; |
| 232 | unsigned int board_info_len = 0; |
| 233 | unsigned smem_status; |
| 234 | unsigned format = 0; |
| 235 | unsigned id = 0; |
| 236 | |
| 237 | if (hw_platform && target_msm_id) |
| 238 | return; |
| 239 | |
| 240 | hw_platform = MSM7X27A_SURF; |
| 241 | target_msm_id = MSM7225A; |
| 242 | |
| 243 | smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 244 | &format, sizeof(format), 0); |
| 245 | if (!smem_status) { |
| 246 | if (format == 4) { |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 247 | board_info_len = sizeof(board_info_v4); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 248 | smem_status = |
| 249 | smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 250 | &board_info_v4, |
| 251 | board_info_len); |
| 252 | if (!smem_status) { |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 253 | id = board_info_v4.board_info_v3.hw_platform; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 254 | target_msm_id = |
| 255 | board_info_v4.board_info_v3.msm_id; |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | |
Channagoud Kadabi | 4c41c41 | 2011-09-08 15:38:30 +0530 | [diff] [blame] | 259 | /* Detect SURF v/s FFA v/s QRD */ |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 260 | if (target_msm_id >= MSM8225 && target_msm_id <= MSM8625) { |
| 261 | switch (id) { |
| 262 | case 0x1: |
| 263 | hw_platform = MSM8X25_SURF; |
| 264 | break; |
| 265 | case 0xC: |
| 266 | hw_platform = MSM8X25_EVB; |
| 267 | break; |
Aparna Mallavarapu | ac33298 | 2012-03-18 14:02:38 +0530 | [diff] [blame] | 268 | case 0xF: |
| 269 | hw_platform = MSM8X25_QRD7; |
| 270 | break; |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 271 | default: |
| 272 | hw_platform = MSM8X25_SURF; |
| 273 | } |
| 274 | } else { |
| 275 | switch (id) { |
| 276 | case 0x1: |
| 277 | /* Set the machine type based on msm ID */ |
| 278 | if (target_msm_id == MSM7225A |
| 279 | || target_msm_id == MSM7625A |
| 280 | || target_msm_id == ESM7225A |
| 281 | || (target_msm_id >= MSM7225AA |
| 282 | && target_msm_id <= ESM7225AA)) |
| 283 | hw_platform = MSM7X25A_SURF; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 284 | else |
| 285 | hw_platform = MSM7X27A_SURF; |
| 286 | break; |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 287 | case 0x2: |
| 288 | if (target_msm_id == MSM7225A |
| 289 | || target_msm_id == MSM7625A |
| 290 | || target_msm_id == ESM7225A |
| 291 | || (target_msm_id >= MSM7225AA |
| 292 | && target_msm_id <= ESM7225AA)) |
| 293 | hw_platform = MSM7X25A_FFA; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 294 | else |
| 295 | hw_platform = MSM7X27A_FFA; |
| 296 | break; |
| 297 | case 0xB: |
Channagoud Kadabi | b33d483 | 2012-02-06 17:10:56 +0530 | [diff] [blame] | 298 | if(target_is_emmc_boot()) |
| 299 | hw_platform = MSM7X27A_QRD1; |
| 300 | else |
| 301 | hw_platform = MSM7X27A_QRD3; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 302 | break; |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 303 | case 0xC: |
| 304 | hw_platform = MSM7X27A_EVB; |
| 305 | break; |
Aparna Mallavarapu | 1c5952f | 2012-03-24 23:17:33 +0530 | [diff] [blame^] | 306 | case 0xF: |
| 307 | hw_platform = MSM7X27A_QRD3; |
| 308 | break; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 309 | default: |
| 310 | if (target_msm_id == MSM7225A |
| 311 | || target_msm_id == MSM7625A |
| 312 | || target_msm_id == ESM7225A |
| 313 | || (target_msm_id >= MSM7225AA |
| 314 | && target_msm_id <= ESM7225AA)) |
| 315 | hw_platform = MSM7X25A_SURF; |
| 316 | else |
| 317 | hw_platform = MSM7X27A_SURF; |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 318 | }; |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 319 | } |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 320 | /* Set msm ID for target variants based on values read from smem */ |
| 321 | switch (target_msm_id) { |
| 322 | case MSM7225A: |
| 323 | case MSM7625A: |
| 324 | case ESM7225A: |
| 325 | case MSM7225AA: |
| 326 | case MSM7625AA: |
| 327 | case ESM7225AA: |
| 328 | target_msm_id = MSM7625A; |
| 329 | break; |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 330 | case MSM8225: |
| 331 | case MSM8625: |
| 332 | target_msm_id = MSM8625; |
| 333 | break; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 334 | default: |
| 335 | target_msm_id = MSM7627A; |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | return; |
| 339 | } |
| 340 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 341 | unsigned board_machtype(void) |
| 342 | { |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 343 | board_info(); |
| 344 | return hw_platform; |
| 345 | } |
| 346 | |
| 347 | unsigned board_msm_id(void) |
| 348 | { |
| 349 | board_info(); |
| 350 | return target_msm_id; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 351 | } |
| 352 | |
Deepa Dinamani | 5e5c21a | 2012-02-16 18:59:57 -0800 | [diff] [blame] | 353 | crypto_engine_type board_ce_type(void) |
| 354 | { |
| 355 | return platform_ce_type; |
| 356 | } |
| 357 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 358 | void reboot_device(unsigned reboot_reason) |
| 359 | { |
| 360 | reboot(reboot_reason); |
| 361 | } |
| 362 | |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 363 | static void check_fota_cookie(void) |
| 364 | { |
| 365 | struct ptentry *ptn; |
| 366 | struct ptable *ptable; |
| 367 | unsigned page_size = flash_page_size(); |
| 368 | unsigned pagemask = page_size - 1; |
| 369 | int n = 0; |
| 370 | |
| 371 | ptable = flash_get_ptable(); |
| 372 | if (ptable == NULL) { |
| 373 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | ptn = ptable_find(ptable, "FOTA"); |
| 378 | if (ptn == NULL) { |
| 379 | dprintf(CRITICAL, "ERROR: No FOTA partition found\n"); |
| 380 | return; |
| 381 | } |
| 382 | n = (sizeof(fota_cookie) + pagemask) & (~pagemask); |
| 383 | |
| 384 | if (flash_read(ptn, 0, fota_cookie, n)) { |
| 385 | dprintf(CRITICAL, "ERROR: flash read fail!\n"); |
| 386 | return; |
| 387 | } |
| 388 | return; |
| 389 | } |
| 390 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 391 | unsigned check_reboot_mode(void) |
| 392 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 393 | unsigned mode[2] = { 0, 0 }; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 394 | unsigned int mode_len = sizeof(mode); |
| 395 | unsigned smem_status; |
| 396 | |
| 397 | smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 398 | &mode, mode_len); |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 399 | |
| 400 | /* |
| 401 | * SMEM value is relied upon on power shutdown. Check either of SMEM |
| 402 | * or FOTA update cookie is set |
| 403 | */ |
| 404 | check_fota_cookie(); |
| 405 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 406 | if ((mode[0] == RECOVERY_MODE) || (fota_cookie[0] == FOTA_COOKIE)) |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 407 | return RECOVERY_MODE; |
| 408 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 409 | if (smem_status) { |
| 410 | dprintf(CRITICAL, |
| 411 | "ERROR: unable to read shared memory for reboot mode\n"); |
| 412 | return 0; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 413 | } |
| 414 | return mode[0]; |
| 415 | } |
| 416 | |
| 417 | static unsigned target_check_power_on_reason(void) |
| 418 | { |
| 419 | unsigned power_on_status = 0; |
| 420 | unsigned int status_len = sizeof(power_on_status); |
| 421 | unsigned smem_status; |
| 422 | |
| 423 | smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 424 | &power_on_status, status_len); |
| 425 | if (smem_status) { |
| 426 | dprintf(CRITICAL, |
| 427 | "ERROR: unable to read shared memory for power on reason\n"); |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | return power_on_status; |
| 431 | } |
| 432 | |
| 433 | unsigned target_pause_for_battery_charge(void) |
| 434 | { |
Ajay Dudani | ba82233 | 2011-11-25 13:37:31 -0800 | [diff] [blame] | 435 | if (target_check_power_on_reason() == PWR_ON_EVENT_WALL_CHG) |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 436 | return 1; |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | void target_battery_charging_enable(unsigned enable, unsigned disconnect) |
| 441 | { |
| 442 | } |
Shashank Mittal | 59392f3 | 2011-05-01 20:49:56 -0700 | [diff] [blame] | 443 | |
| 444 | #if _EMMC_BOOT |
| 445 | void target_serialno(unsigned char *buf) |
| 446 | { |
| 447 | unsigned int serialno; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 448 | serialno = mmc_get_psn(); |
| 449 | sprintf(buf, "%x", serialno); |
Shashank Mittal | 59392f3 | 2011-05-01 20:49:56 -0700 | [diff] [blame] | 450 | } |
Subbaraman Narayanamurthy | 0e445b0 | 2011-06-19 21:34:46 -0700 | [diff] [blame] | 451 | |
| 452 | int emmc_recovery_init(void) |
| 453 | { |
| 454 | int rc; |
| 455 | rc = _emmc_recovery_init(); |
| 456 | return rc; |
| 457 | } |
Shashank Mittal | 59392f3 | 2011-05-01 20:49:56 -0700 | [diff] [blame] | 458 | #endif |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 459 | |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 460 | int machine_is_evb() |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 461 | { |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 462 | int ret = 0; |
| 463 | unsigned mach_type = board_machtype(); |
| 464 | |
| 465 | switch(mach_type) { |
| 466 | case MSM7X27A_EVB: |
| 467 | case MSM8X25_EVB: |
| 468 | ret = 1; |
| 469 | break; |
| 470 | default: |
| 471 | ret = 0; |
| 472 | } |
| 473 | return ret; |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 474 | } |
Aparna Mallavarapu | ac33298 | 2012-03-18 14:02:38 +0530 | [diff] [blame] | 475 | int machine_is_qrd() |
Channagoud Kadabi | b33d483 | 2012-02-06 17:10:56 +0530 | [diff] [blame] | 476 | { |
Aparna Mallavarapu | ac33298 | 2012-03-18 14:02:38 +0530 | [diff] [blame] | 477 | int ret = 0; |
| 478 | unsigned mach_type = board_machtype(); |
Channagoud Kadabi | b33d483 | 2012-02-06 17:10:56 +0530 | [diff] [blame] | 479 | |
Aparna Mallavarapu | ac33298 | 2012-03-18 14:02:38 +0530 | [diff] [blame] | 480 | switch(mach_type) { |
| 481 | case MSM7X27A_QRD1: |
| 482 | case MSM7X27A_QRD3: |
| 483 | case MSM8X25_QRD7: |
| 484 | ret = 1; |
| 485 | break; |
| 486 | default: |
| 487 | ret = 0; |
| 488 | } |
| 489 | return ret; |
Channagoud Kadabi | b33d483 | 2012-02-06 17:10:56 +0530 | [diff] [blame] | 490 | } |
Channagoud Kadabi | 81ba110 | 2011-10-01 16:37:59 +0530 | [diff] [blame] | 491 | int machine_is_8x25() |
| 492 | { |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 493 | int ret = 0; |
| 494 | unsigned mach_type = board_machtype(); |
| 495 | |
| 496 | switch(mach_type) { |
| 497 | case MSM8X25_SURF: |
| 498 | case MSM8X25_EVB: |
Aparna Mallavarapu | ac33298 | 2012-03-18 14:02:38 +0530 | [diff] [blame] | 499 | case MSM8X25_QRD7: |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 500 | ret = 1; |
| 501 | break; |
| 502 | default: |
| 503 | ret = 0; |
| 504 | } |
| 505 | return ret; |
Channagoud Kadabi | 81ba110 | 2011-10-01 16:37:59 +0530 | [diff] [blame] | 506 | } |