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> |
Channagoud Kadabi | 539ef72 | 2012-03-29 16:02:50 +0530 | [diff] [blame] | 42 | #include <target/board.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 43 | #include <platform.h> |
Deepa Dinamani | 5e5c21a | 2012-02-16 18:59:57 -0800 | [diff] [blame] | 44 | #include <crypto_hash.h> |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 45 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 46 | #define VARIABLE_LENGTH 0x10101010 |
| 47 | #define DIFF_START_ADDR 0xF0F0F0F0 |
| 48 | #define NUM_PAGES_PER_BLOCK 0x40 |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 49 | #define RECOVERY_MODE 0x77665502 |
| 50 | #define FOTA_COOKIE 0x64645343 |
| 51 | |
| 52 | unsigned int fota_cookie[1]; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 53 | |
| 54 | static struct ptable flash_ptable; |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 55 | unsigned hw_platform = 0; |
| 56 | unsigned target_msm_id = 0; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 57 | |
Deepa Dinamani | 5e5c21a | 2012-02-16 18:59:57 -0800 | [diff] [blame] | 58 | /* 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 | */ |
| 65 | static crypto_engine_type platform_ce_type = CRYPTO_ENGINE_TYPE_SW; |
| 66 | |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 67 | int machine_is_evb(); |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 68 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 69 | /* 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 Kadabi | e57173d | 2011-12-19 15:42:44 +0530 | [diff] [blame] | 77 | static struct ptentry board_part_list[] = { |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 78 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 79 | .start = 0, |
| 80 | .length = 10 /* In MB */ , |
| 81 | .name = "boot", |
| 82 | }, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 83 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 84 | .start = DIFF_START_ADDR, |
Channagoud Kadabi | 7196188 | 2012-02-09 16:32:41 +0530 | [diff] [blame] | 85 | .length = 253 /* In MB */ , |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 86 | .name = "system", |
| 87 | }, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 88 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 89 | .start = DIFF_START_ADDR, |
| 90 | .length = 40 /* In MB */ , |
| 91 | .name = "cache", |
| 92 | }, |
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 = DIFF_START_ADDR, |
| 95 | .length = 4 /* In MB */ , |
| 96 | .name = "misc", |
| 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, |
| 100 | .length = VARIABLE_LENGTH, |
| 101 | .name = "userdata", |
| 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 = 4 /* In MB */ , |
| 106 | .name = "persist", |
| 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 = 10 /* In MB */ , |
| 111 | .name = "recovery", |
| 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 | |
Channagoud Kadabi | e57173d | 2011-12-19 15:42:44 +0530 | [diff] [blame] | 115 | static int num_parts = sizeof(board_part_list) / sizeof(struct ptentry); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 116 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 117 | void smem_ptable_init(void); |
| 118 | unsigned smem_get_apps_flash_start(void); |
| 119 | |
| 120 | void keypad_init(void); |
| 121 | |
| 122 | int target_is_emmc_boot(void); |
| 123 | |
| 124 | void target_init(void) |
| 125 | { |
| 126 | unsigned offset; |
| 127 | struct flash_info *flash_info; |
| 128 | unsigned total_num_of_blocks; |
| 129 | unsigned next_ptr_start_adr = 0; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 130 | 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] | 131 | int i; |
| 132 | |
| 133 | dprintf(INFO, "target_init()\n"); |
| 134 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 135 | #if (!ENABLE_NANDWRITE) |
| 136 | keys_init(); |
| 137 | keypad_init(); |
| 138 | #endif |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 139 | |
Kinson Chik | ce306ff | 2011-07-08 15:23:33 -0700 | [diff] [blame] | 140 | /* Display splash screen if enabled */ |
| 141 | #if DISPLAY_SPLASH_SCREEN |
Channagoud Kadabi | 539ef72 | 2012-03-29 16:02:50 +0530 | [diff] [blame] | 142 | display_init(); |
| 143 | dprintf(SPEW, "Diplay initialized\n"); |
Kinson Chik | ce306ff | 2011-07-08 15:23:33 -0700 | [diff] [blame] | 144 | #endif |
| 145 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 146 | if (target_is_emmc_boot()) { |
Amol Jadi | 2dfe339 | 2011-07-19 16:03:37 -0700 | [diff] [blame] | 147 | /* Must wait for modem-up before we can intialize MMC. |
| 148 | */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 149 | while (readl(MSM_SHARED_BASE + 0x14) != 1) ; |
Amol Jadi | 2dfe339 | 2011-07-19 16:03:37 -0700 | [diff] [blame] | 150 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 151 | if (mmc_boot_main(MMC_SLOT, MSM_SDC3_BASE)) { |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 152 | dprintf(CRITICAL, "mmc init failed!"); |
| 153 | ASSERT(0); |
| 154 | } |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | 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) |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 167 | while (1) ; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 168 | |
| 169 | total_num_of_blocks = flash_info->num_blocks; |
| 170 | blocks_per_1MB = (1 << 20) / (flash_info->block_size); |
| 171 | |
| 172 | for (i = 0; i < num_parts; i++) { |
| 173 | struct ptentry *ptn = &board_part_list[i]; |
| 174 | unsigned len = ((ptn->length) * blocks_per_1MB); |
| 175 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 176 | if (ptn->start != 0) |
| 177 | ASSERT(ptn->start == DIFF_START_ADDR); |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 178 | |
| 179 | ptn->start = next_ptr_start_adr; |
| 180 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 181 | if (ptn->length == VARIABLE_LENGTH) { |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 182 | unsigned length_for_prt = 0; |
| 183 | unsigned j; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 184 | for (j = i + 1; j < num_parts; j++) { |
| 185 | struct ptentry *temp_ptn = &board_part_list[j]; |
| 186 | ASSERT(temp_ptn->length != VARIABLE_LENGTH); |
| 187 | length_for_prt += |
| 188 | ((temp_ptn->length) * blocks_per_1MB); |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 189 | } |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 190 | len = |
| 191 | (total_num_of_blocks - 1) - (offset + ptn->start + |
| 192 | length_for_prt); |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 193 | ASSERT(len >= 0); |
| 194 | } |
| 195 | next_ptr_start_adr = ptn->start + len; |
| 196 | ptable_add(&flash_ptable, ptn->name, offset + ptn->start, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 197 | len, ptn->flags, TYPE_APPS_PARTITION, |
| 198 | PERM_WRITEABLE); |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | smem_add_modem_partitions(&flash_ptable); |
| 202 | |
| 203 | ptable_dump(&flash_ptable); |
| 204 | flash_set_ptable(&flash_ptable); |
| 205 | } |
| 206 | |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 207 | void board_info(void) |
| 208 | { |
| 209 | struct smem_board_info_v4 board_info_v4; |
| 210 | unsigned int board_info_len = 0; |
| 211 | unsigned smem_status; |
| 212 | unsigned format = 0; |
| 213 | unsigned id = 0; |
| 214 | |
| 215 | if (hw_platform && target_msm_id) |
| 216 | return; |
| 217 | |
| 218 | hw_platform = MSM7X27A_SURF; |
| 219 | target_msm_id = MSM7225A; |
| 220 | |
| 221 | smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 222 | &format, sizeof(format), 0); |
| 223 | if (!smem_status) { |
| 224 | if (format == 4) { |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 225 | board_info_len = sizeof(board_info_v4); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 226 | smem_status = |
| 227 | smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 228 | &board_info_v4, |
| 229 | board_info_len); |
| 230 | if (!smem_status) { |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 231 | id = board_info_v4.board_info_v3.hw_platform; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 232 | target_msm_id = |
| 233 | board_info_v4.board_info_v3.msm_id; |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | |
Channagoud Kadabi | 4c41c41 | 2011-09-08 15:38:30 +0530 | [diff] [blame] | 237 | /* Detect SURF v/s FFA v/s QRD */ |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 238 | if (target_msm_id >= MSM8225 && target_msm_id <= MSM8625) { |
| 239 | switch (id) { |
| 240 | case 0x1: |
| 241 | hw_platform = MSM8X25_SURF; |
| 242 | break; |
Aparna Mallavarapu | 1bb3367 | 2012-04-20 16:07:24 +0530 | [diff] [blame] | 243 | case 0x2: |
| 244 | hw_platform = MSM8X25_FFA; |
| 245 | break; |
Aparna Mallavarapu | bac9a72 | 2012-05-22 10:15:29 +0530 | [diff] [blame] | 246 | case 0x10: |
Aparna Mallavarapu | 287d89c | 2012-05-11 14:27:03 +0530 | [diff] [blame] | 247 | hw_platform = MSM8X25_EVT; |
| 248 | break; |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 249 | case 0xC: |
| 250 | hw_platform = MSM8X25_EVB; |
| 251 | break; |
Aparna Mallavarapu | ac33298 | 2012-03-18 14:02:38 +0530 | [diff] [blame] | 252 | case 0xF: |
| 253 | hw_platform = MSM8X25_QRD7; |
| 254 | break; |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 255 | default: |
| 256 | hw_platform = MSM8X25_SURF; |
| 257 | } |
| 258 | } else { |
| 259 | switch (id) { |
| 260 | case 0x1: |
| 261 | /* Set the machine type based on msm ID */ |
Channagoud Kadabi | bd14e2f | 2012-05-03 22:54:50 +0530 | [diff] [blame] | 262 | if (msm_is_7x25a(target_msm_id)) |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 263 | hw_platform = MSM7X25A_SURF; |
Channagoud Kadabi | 849ad5e | 2012-04-02 23:21:21 +0530 | [diff] [blame] | 264 | else |
| 265 | hw_platform = MSM7X27A_SURF; |
| 266 | break; |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 267 | case 0x2: |
Channagoud Kadabi | bd14e2f | 2012-05-03 22:54:50 +0530 | [diff] [blame] | 268 | if (msm_is_7x25a(target_msm_id)) |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 269 | hw_platform = MSM7X25A_FFA; |
Channagoud Kadabi | 849ad5e | 2012-04-02 23:21:21 +0530 | [diff] [blame] | 270 | else |
| 271 | hw_platform = MSM7X27A_FFA; |
| 272 | break; |
| 273 | case 0xB: |
| 274 | if(target_is_emmc_boot()) |
| 275 | hw_platform = MSM7X27A_QRD1; |
| 276 | else |
| 277 | hw_platform = MSM7X27A_QRD3; |
| 278 | break; |
| 279 | case 0xC: |
| 280 | hw_platform = MSM7X27A_EVB; |
| 281 | break; |
| 282 | case 0xF: |
Channagoud Kadabi | b33d483 | 2012-02-06 17:10:56 +0530 | [diff] [blame] | 283 | hw_platform = MSM7X27A_QRD3; |
Channagoud Kadabi | 849ad5e | 2012-04-02 23:21:21 +0530 | [diff] [blame] | 284 | break; |
| 285 | default: |
Channagoud Kadabi | bd14e2f | 2012-05-03 22:54:50 +0530 | [diff] [blame] | 286 | if (msm_is_7x25a(target_msm_id)) |
Channagoud Kadabi | 849ad5e | 2012-04-02 23:21:21 +0530 | [diff] [blame] | 287 | hw_platform = MSM7X25A_SURF; |
| 288 | else |
| 289 | hw_platform = MSM7X27A_SURF; |
| 290 | }; |
| 291 | } |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 292 | /* Set msm ID for target variants based on values read from smem */ |
| 293 | switch (target_msm_id) { |
| 294 | case MSM7225A: |
| 295 | case MSM7625A: |
| 296 | case ESM7225A: |
| 297 | case MSM7225AA: |
| 298 | case MSM7625AA: |
| 299 | case ESM7225AA: |
Channagoud Kadabi | bd14e2f | 2012-05-03 22:54:50 +0530 | [diff] [blame] | 300 | case MSM7225AB: |
| 301 | case MSM7625AB: |
| 302 | case ESM7225AB: |
Channagoud Kadabi | 647f085 | 2012-06-08 11:51:45 +0530 | [diff] [blame] | 303 | case MSM7125A: |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 304 | target_msm_id = MSM7625A; |
| 305 | break; |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 306 | case MSM8225: |
| 307 | case MSM8625: |
| 308 | target_msm_id = MSM8625; |
| 309 | break; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 310 | default: |
| 311 | target_msm_id = MSM7627A; |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | return; |
| 315 | } |
| 316 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 317 | unsigned board_machtype(void) |
| 318 | { |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 319 | board_info(); |
| 320 | return hw_platform; |
| 321 | } |
| 322 | |
| 323 | unsigned board_msm_id(void) |
| 324 | { |
| 325 | board_info(); |
| 326 | return target_msm_id; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 327 | } |
| 328 | |
Deepa Dinamani | 5e5c21a | 2012-02-16 18:59:57 -0800 | [diff] [blame] | 329 | crypto_engine_type board_ce_type(void) |
| 330 | { |
| 331 | return platform_ce_type; |
| 332 | } |
| 333 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 334 | void reboot_device(unsigned reboot_reason) |
| 335 | { |
| 336 | reboot(reboot_reason); |
| 337 | } |
| 338 | |
Channagoud Kadabi | 16f5095 | 2012-04-02 16:24:07 +0530 | [diff] [blame] | 339 | static int read_from_flash(struct ptentry* ptn, int offset, int size, void *dest) |
| 340 | { |
| 341 | void *buffer = NULL; |
| 342 | unsigned page_size = flash_page_size(); |
| 343 | unsigned page_mask = page_size - 1; |
| 344 | int read_size = (size + page_mask) & (~page_mask); |
| 345 | |
| 346 | buffer = malloc(read_size); |
| 347 | if(!buffer){ |
| 348 | dprintf(CRITICAL, "ERROR : Malloc failed for read_from_flash \n"); |
| 349 | return -1; |
| 350 | } |
| 351 | |
| 352 | if(flash_read(ptn, offset, buffer, read_size)){ |
| 353 | dprintf(CRITICAL, "ERROR : Flash read failed \n"); |
| 354 | return -1; |
| 355 | } |
| 356 | memcpy(dest, buffer, size); |
| 357 | free(buffer); |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | static unsigned int get_fota_cookie_mtd(void) |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 362 | { |
| 363 | struct ptentry *ptn; |
| 364 | struct ptable *ptable; |
Channagoud Kadabi | 16f5095 | 2012-04-02 16:24:07 +0530 | [diff] [blame] | 365 | unsigned int cookie = 0; |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 366 | |
| 367 | ptable = flash_get_ptable(); |
| 368 | if (ptable == NULL) { |
| 369 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
Channagoud Kadabi | 16f5095 | 2012-04-02 16:24:07 +0530 | [diff] [blame] | 370 | return 0; |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | ptn = ptable_find(ptable, "FOTA"); |
| 374 | if (ptn == NULL) { |
| 375 | dprintf(CRITICAL, "ERROR: No FOTA partition found\n"); |
Channagoud Kadabi | 16f5095 | 2012-04-02 16:24:07 +0530 | [diff] [blame] | 376 | return 0; |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 377 | } |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 378 | |
Channagoud Kadabi | 16f5095 | 2012-04-02 16:24:07 +0530 | [diff] [blame] | 379 | if (read_from_flash(ptn, 0, sizeof(unsigned int), &cookie) == -1) { |
| 380 | dprintf(CRITICAL, "ERROR: failed to read fota cookie from flash\n"); |
| 381 | return 0; |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 382 | } |
Channagoud Kadabi | 16f5095 | 2012-04-02 16:24:07 +0530 | [diff] [blame] | 383 | return cookie; |
| 384 | } |
| 385 | |
| 386 | static int read_from_mmc(struct ptentry* ptn, int size, void *dest) |
| 387 | { |
| 388 | void *buffer = NULL; |
| 389 | unsigned sector_mask = 511; |
| 390 | int read_size = (size + sector_mask) & (~sector_mask); |
| 391 | |
| 392 | buffer = malloc(read_size); |
| 393 | if(!buffer){ |
| 394 | dprintf(CRITICAL, "ERROR : Malloc failed for read_from_flash \n"); |
| 395 | return -1; |
| 396 | } |
| 397 | |
| 398 | if(mmc_read(ptn, buffer, read_size)) { |
| 399 | dprintf(CRITICAL, "ERROR : Flash read failed \n"); |
| 400 | return -1; |
| 401 | } |
| 402 | memcpy(dest, buffer, size); |
| 403 | free(buffer); |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | static int get_fota_cookie_mmc(void) |
| 408 | { |
| 409 | unsigned long long ptn = 0; |
| 410 | int index = -1; |
| 411 | unsigned int cookie = 0; |
| 412 | |
| 413 | index = partition_get_index("FOTA"); |
| 414 | ptn = partition_get_offset(index); |
| 415 | |
| 416 | if(ptn == 0) { |
| 417 | dprintf(CRITICAL,"ERROR: FOTA partition not found\n"); |
| 418 | return 0; |
| 419 | } |
| 420 | if(read_from_mmc(ptn, sizeof(unsigned int), &cookie)) { |
| 421 | dprintf(CRITICAL, "ERROR: Cannot read cookie info\n"); |
| 422 | return 0; |
| 423 | } |
| 424 | return cookie; |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 425 | } |
| 426 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 427 | unsigned check_reboot_mode(void) |
| 428 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 429 | unsigned mode[2] = { 0, 0 }; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 430 | unsigned int mode_len = sizeof(mode); |
| 431 | unsigned smem_status; |
Channagoud Kadabi | 16f5095 | 2012-04-02 16:24:07 +0530 | [diff] [blame] | 432 | unsigned int cookie = 0; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 433 | |
| 434 | smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 435 | &mode, mode_len); |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 436 | |
| 437 | /* |
| 438 | * SMEM value is relied upon on power shutdown. Check either of SMEM |
| 439 | * or FOTA update cookie is set |
| 440 | */ |
Channagoud Kadabi | 16f5095 | 2012-04-02 16:24:07 +0530 | [diff] [blame] | 441 | if (target_is_emmc_boot()) |
| 442 | cookie = get_fota_cookie_mmc(); |
| 443 | else |
| 444 | cookie = get_fota_cookie_mtd(); |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 445 | |
Channagoud Kadabi | 16f5095 | 2012-04-02 16:24:07 +0530 | [diff] [blame] | 446 | if ((mode[0] == RECOVERY_MODE) || (cookie == FOTA_COOKIE)) |
Channagoud Kadabi | 16da3a2 | 2011-10-24 20:25:07 +0530 | [diff] [blame] | 447 | return RECOVERY_MODE; |
| 448 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 449 | if (smem_status) { |
| 450 | dprintf(CRITICAL, |
| 451 | "ERROR: unable to read shared memory for reboot mode\n"); |
| 452 | return 0; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 453 | } |
| 454 | return mode[0]; |
| 455 | } |
| 456 | |
| 457 | static unsigned target_check_power_on_reason(void) |
| 458 | { |
| 459 | unsigned power_on_status = 0; |
| 460 | unsigned int status_len = sizeof(power_on_status); |
| 461 | unsigned smem_status; |
| 462 | |
| 463 | smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 464 | &power_on_status, status_len); |
| 465 | if (smem_status) { |
| 466 | dprintf(CRITICAL, |
| 467 | "ERROR: unable to read shared memory for power on reason\n"); |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | return power_on_status; |
| 471 | } |
| 472 | |
| 473 | unsigned target_pause_for_battery_charge(void) |
| 474 | { |
Ajay Dudani | ba82233 | 2011-11-25 13:37:31 -0800 | [diff] [blame] | 475 | if (target_check_power_on_reason() == PWR_ON_EVENT_WALL_CHG) |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 476 | return 1; |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | void target_battery_charging_enable(unsigned enable, unsigned disconnect) |
| 481 | { |
| 482 | } |
Shashank Mittal | 59392f3 | 2011-05-01 20:49:56 -0700 | [diff] [blame] | 483 | |
| 484 | #if _EMMC_BOOT |
| 485 | void target_serialno(unsigned char *buf) |
| 486 | { |
| 487 | unsigned int serialno; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 488 | serialno = mmc_get_psn(); |
| 489 | sprintf(buf, "%x", serialno); |
Shashank Mittal | 59392f3 | 2011-05-01 20:49:56 -0700 | [diff] [blame] | 490 | } |
Subbaraman Narayanamurthy | 0e445b0 | 2011-06-19 21:34:46 -0700 | [diff] [blame] | 491 | |
| 492 | int emmc_recovery_init(void) |
| 493 | { |
| 494 | int rc; |
| 495 | rc = _emmc_recovery_init(); |
| 496 | return rc; |
| 497 | } |
Shashank Mittal | 59392f3 | 2011-05-01 20:49:56 -0700 | [diff] [blame] | 498 | #endif |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 499 | |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 500 | int machine_is_evb() |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 501 | { |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 502 | int ret = 0; |
| 503 | unsigned mach_type = board_machtype(); |
| 504 | |
| 505 | switch(mach_type) { |
| 506 | case MSM7X27A_EVB: |
| 507 | case MSM8X25_EVB: |
Aparna Mallavarapu | 287d89c | 2012-05-11 14:27:03 +0530 | [diff] [blame] | 508 | case MSM8X25_EVT: |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 509 | ret = 1; |
| 510 | break; |
| 511 | default: |
| 512 | ret = 0; |
| 513 | } |
| 514 | return ret; |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 515 | } |
Aparna Mallavarapu | ac33298 | 2012-03-18 14:02:38 +0530 | [diff] [blame] | 516 | int machine_is_qrd() |
Channagoud Kadabi | b33d483 | 2012-02-06 17:10:56 +0530 | [diff] [blame] | 517 | { |
Aparna Mallavarapu | ac33298 | 2012-03-18 14:02:38 +0530 | [diff] [blame] | 518 | int ret = 0; |
| 519 | unsigned mach_type = board_machtype(); |
Channagoud Kadabi | b33d483 | 2012-02-06 17:10:56 +0530 | [diff] [blame] | 520 | |
Aparna Mallavarapu | ac33298 | 2012-03-18 14:02:38 +0530 | [diff] [blame] | 521 | switch(mach_type) { |
| 522 | case MSM7X27A_QRD1: |
| 523 | case MSM7X27A_QRD3: |
| 524 | case MSM8X25_QRD7: |
| 525 | ret = 1; |
| 526 | break; |
| 527 | default: |
| 528 | ret = 0; |
| 529 | } |
| 530 | return ret; |
Channagoud Kadabi | b33d483 | 2012-02-06 17:10:56 +0530 | [diff] [blame] | 531 | } |
Channagoud Kadabi | 81ba110 | 2011-10-01 16:37:59 +0530 | [diff] [blame] | 532 | int machine_is_8x25() |
| 533 | { |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 534 | int ret = 0; |
| 535 | unsigned mach_type = board_machtype(); |
| 536 | |
| 537 | switch(mach_type) { |
| 538 | case MSM8X25_SURF: |
Aparna Mallavarapu | 1bb3367 | 2012-04-20 16:07:24 +0530 | [diff] [blame] | 539 | case MSM8X25_FFA: |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 540 | case MSM8X25_EVB: |
Aparna Mallavarapu | 287d89c | 2012-05-11 14:27:03 +0530 | [diff] [blame] | 541 | case MSM8X25_EVT: |
Aparna Mallavarapu | ac33298 | 2012-03-18 14:02:38 +0530 | [diff] [blame] | 542 | case MSM8X25_QRD7: |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 543 | ret = 1; |
| 544 | break; |
| 545 | default: |
| 546 | ret = 0; |
| 547 | } |
| 548 | return ret; |
Channagoud Kadabi | 81ba110 | 2011-10-01 16:37:59 +0530 | [diff] [blame] | 549 | } |
Channagoud Kadabi | bd14e2f | 2012-05-03 22:54:50 +0530 | [diff] [blame] | 550 | |
| 551 | int msm_is_7x25a(int msm_id) |
| 552 | { |
| 553 | int ret = 0; |
| 554 | |
| 555 | switch (msm_id) { |
| 556 | case MSM7225A: |
| 557 | case MSM7625A: |
| 558 | case ESM7225A: |
| 559 | case MSM7225AA: |
| 560 | case MSM7625AA: |
| 561 | case ESM7225AA: |
| 562 | case MSM7225AB: |
| 563 | case MSM7625AB: |
| 564 | case ESM7225AB: |
Channagoud Kadabi | 647f085 | 2012-06-08 11:51:45 +0530 | [diff] [blame] | 565 | case MSM7125A: |
Channagoud Kadabi | bd14e2f | 2012-05-03 22:54:50 +0530 | [diff] [blame] | 566 | ret = 1; |
| 567 | break; |
| 568 | default: |
| 569 | ret = 0; |
| 570 | }; |
| 571 | return ret; |
| 572 | } |
Amol Jadi | da118b9 | 2012-07-06 19:53:18 -0700 | [diff] [blame] | 573 | |
| 574 | static void target_ulpi_init(void) |
| 575 | { |
| 576 | unsigned int reg; |
| 577 | |
| 578 | ulpi_read(0x31); |
| 579 | dprintf(INFO, " Value of ulpi read 0x31 is %08x\n", reg); |
| 580 | /* todo : the write back value should be calculated according to |
| 581 | * reg &= 0xF3 but sometimes the value that is read initially |
| 582 | * doesnt look right |
| 583 | */ |
| 584 | ulpi_write(0x4A, 0x31); |
| 585 | reg = ulpi_read(0x31); |
| 586 | dprintf(INFO, " Value of ulpi read 0x31 after write is %08x\n", reg); |
| 587 | |
| 588 | reg = ulpi_read(0x32); |
| 589 | dprintf(INFO, " Value of ulpi read 0x32 is %08x\n", reg); |
| 590 | ulpi_write(0x30, 0x32); |
| 591 | reg = ulpi_read(0x32); |
| 592 | dprintf(INFO, " Value of ulpi read 0x32 after write is %08x\n", reg); |
| 593 | |
| 594 | reg = ulpi_read(0x36); |
| 595 | dprintf(INFO, " Value of ulpi read 0x36 is %08x\n", reg); |
| 596 | ulpi_write(reg | 0x2, 0x36); |
| 597 | reg = ulpi_read(0x36); |
| 598 | dprintf(INFO, " Value of ulpi read 0x36 after write is %08x\n", reg); |
| 599 | } |
| 600 | |
| 601 | void target_usb_init(void) |
| 602 | { |
| 603 | target_ulpi_init(); |
| 604 | } |
Channagoud Kadabi | f248846 | 2012-06-12 15:22:48 +0530 | [diff] [blame] | 605 | |
| 606 | int target_cont_splash_screen() |
| 607 | { |
| 608 | int ret = 0; |
| 609 | unsigned mach_type = 0; |
| 610 | |
| 611 | mach_type = board_machtype(); |
| 612 | |
| 613 | switch(mach_type) { |
| 614 | case MSM8X25_EVB: |
| 615 | case MSM8X25_EVT: |
Channagoud Kadabi | cdda0fe | 2012-07-13 11:44:28 +0530 | [diff] [blame^] | 616 | case MSM8X25_QRD7: |
Channagoud Kadabi | f248846 | 2012-06-12 15:22:48 +0530 | [diff] [blame] | 617 | ret = 1; |
| 618 | break; |
| 619 | default: |
| 620 | ret = 0; |
| 621 | }; |
| 622 | return ret; |
| 623 | } |