Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved. |
| 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> |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 43 | |
| 44 | #define MSM7X27A_FFA 3351 |
| 45 | #define MSM7X27A_SURF 3352 |
| 46 | #define MSM7X27A_RUMI3 3353 |
Channagoud Kadabi | 4c41c41 | 2011-09-08 15:38:30 +0530 | [diff] [blame^] | 47 | #define MSM7X27A_QRD1 3756 |
| 48 | |
Shashank Mittal | ef32541 | 2011-04-01 13:48:26 -0700 | [diff] [blame] | 49 | #define LINUX_MACHTYPE MSM7X27A_SURF |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 50 | |
| 51 | #define VARIABLE_LENGTH 0x10101010 |
| 52 | #define DIFF_START_ADDR 0xF0F0F0F0 |
| 53 | #define NUM_PAGES_PER_BLOCK 0x40 |
| 54 | |
| 55 | static struct ptable flash_ptable; |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 56 | unsigned hw_platform = 0; |
| 57 | unsigned target_msm_id = 0; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 58 | |
| 59 | /* for these partitions, start will be offset by either what we get from |
| 60 | * smem, or from the above offset if smem is not useful. Also, we should |
| 61 | * probably have smem_ptable code populate our flash_ptable. |
| 62 | * |
| 63 | * When smem provides us with a full partition table, we can get rid of |
| 64 | * this altogether. |
| 65 | * |
| 66 | */ |
Channagoud Kadabi | 500afb7 | 2011-07-19 18:24:11 +0530 | [diff] [blame] | 67 | static struct ptentry board_part_list_default[] = { |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 68 | { |
| 69 | .start = 0, |
| 70 | .length = 10 /* In MB */, |
| 71 | .name = "boot", |
| 72 | }, |
| 73 | { |
| 74 | .start = DIFF_START_ADDR, |
Srilakshmi Punuru | 75122c9 | 2011-07-28 19:16:19 +0530 | [diff] [blame] | 75 | .length = 150 /* In MB */, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 76 | .name = "system", |
| 77 | }, |
| 78 | { |
| 79 | .start = DIFF_START_ADDR, |
Shashank Mittal | 561450e | 2011-03-04 19:53:32 -0800 | [diff] [blame] | 80 | .length = 4 /* In MB */, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 81 | .name = "cache", |
| 82 | }, |
| 83 | { |
| 84 | .start = DIFF_START_ADDR, |
Shashank Mittal | 0427627 | 2011-05-06 15:13:45 -0700 | [diff] [blame] | 85 | .length = 4 /* In MB */, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 86 | .name = "misc", |
| 87 | }, |
| 88 | { |
| 89 | .start = DIFF_START_ADDR, |
| 90 | .length = VARIABLE_LENGTH, |
| 91 | .name = "userdata", |
| 92 | }, |
| 93 | { |
| 94 | .start = DIFF_START_ADDR, |
Shashank Mittal | 0427627 | 2011-05-06 15:13:45 -0700 | [diff] [blame] | 95 | .length = 4 /* In MB */, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 96 | .name = "persist", |
| 97 | }, |
| 98 | { |
| 99 | .start = DIFF_START_ADDR, |
Aparna Mallavarapu | 84d39f3 | 2011-05-12 09:34:46 +0530 | [diff] [blame] | 100 | .length = 10 /* In MB */, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 101 | .name = "recovery", |
| 102 | }, |
| 103 | }; |
Channagoud Kadabi | 500afb7 | 2011-07-19 18:24:11 +0530 | [diff] [blame] | 104 | static int num_parts = sizeof(board_part_list_default)/sizeof(struct ptentry); |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 105 | |
Channagoud Kadabi | 500afb7 | 2011-07-19 18:24:11 +0530 | [diff] [blame] | 106 | /* |
| 107 | * Define partition table for Bch ecc NAND and increase the cache partition size |
| 108 | * to 8MB |
| 109 | */ |
| 110 | static struct ptentry board_part_list_bchecc[] = { |
| 111 | { |
| 112 | .start = 0, |
| 113 | .length = 10 /* In MB */, |
| 114 | .name = "boot", |
| 115 | }, |
| 116 | { |
| 117 | .start = DIFF_START_ADDR, |
Channagoud Kadabi | eb50ff4 | 2011-09-13 18:00:48 +0530 | [diff] [blame] | 118 | .length = 150 /* In MB */, |
Channagoud Kadabi | 500afb7 | 2011-07-19 18:24:11 +0530 | [diff] [blame] | 119 | .name = "system", |
| 120 | }, |
| 121 | { |
| 122 | .start = DIFF_START_ADDR, |
| 123 | .length = 8 /* In MB */, |
| 124 | .name = "cache", |
| 125 | }, |
| 126 | { |
| 127 | .start = DIFF_START_ADDR, |
| 128 | .length = 4 /* In MB */, |
| 129 | .name = "misc", |
| 130 | }, |
| 131 | { |
| 132 | .start = DIFF_START_ADDR, |
| 133 | .length = VARIABLE_LENGTH, |
| 134 | .name = "userdata", |
| 135 | }, |
| 136 | { |
| 137 | .start = DIFF_START_ADDR, |
| 138 | .length = 4 /* In MB */, |
| 139 | .name = "persist", |
| 140 | }, |
| 141 | { |
| 142 | .start = DIFF_START_ADDR, |
| 143 | .length = 10 /* In MB */, |
| 144 | .name = "recovery", |
| 145 | }, |
| 146 | }; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 147 | void smem_ptable_init(void); |
| 148 | unsigned smem_get_apps_flash_start(void); |
| 149 | |
| 150 | void keypad_init(void); |
| 151 | |
| 152 | int target_is_emmc_boot(void); |
| 153 | |
| 154 | void target_init(void) |
| 155 | { |
| 156 | unsigned offset; |
| 157 | struct flash_info *flash_info; |
Channagoud Kadabi | 500afb7 | 2011-07-19 18:24:11 +0530 | [diff] [blame] | 158 | struct ptentry *board_part_list; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 159 | unsigned total_num_of_blocks; |
| 160 | unsigned next_ptr_start_adr = 0; |
| 161 | unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive*/ |
| 162 | int i; |
| 163 | |
| 164 | dprintf(INFO, "target_init()\n"); |
| 165 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 166 | #if (!ENABLE_NANDWRITE) |
| 167 | keys_init(); |
| 168 | keypad_init(); |
| 169 | #endif |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 170 | |
Kinson Chik | ce306ff | 2011-07-08 15:23:33 -0700 | [diff] [blame] | 171 | /* Display splash screen if enabled */ |
| 172 | #if DISPLAY_SPLASH_SCREEN |
| 173 | display_init(); |
| 174 | dprintf(SPEW, "Diplay initialized\n"); |
| 175 | display_image_on_screen(); |
| 176 | #endif |
| 177 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 178 | if (target_is_emmc_boot()) |
| 179 | { |
Amol Jadi | 2dfe339 | 2011-07-19 16:03:37 -0700 | [diff] [blame] | 180 | /* Must wait for modem-up before we can intialize MMC. |
| 181 | */ |
| 182 | while (readl(MSM_SHARED_BASE + 0x14) != 1); |
| 183 | |
Aparna Mallavarapu | 5a83b2a | 2011-05-26 18:01:31 +0530 | [diff] [blame] | 184 | if(mmc_boot_main(MMC_SLOT, MSM_SDC3_BASE)) |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 185 | { |
| 186 | dprintf(CRITICAL, "mmc init failed!"); |
| 187 | ASSERT(0); |
| 188 | } |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | ptable_init(&flash_ptable); |
| 193 | smem_ptable_init(); |
| 194 | |
| 195 | flash_init(); |
| 196 | flash_info = flash_get_info(); |
| 197 | ASSERT(flash_info); |
| 198 | |
| 199 | offset = smem_get_apps_flash_start(); |
| 200 | if (offset == 0xffffffff) |
| 201 | while(1); |
| 202 | |
| 203 | total_num_of_blocks = flash_info->num_blocks; |
| 204 | blocks_per_1MB = (1 << 20) / (flash_info->block_size); |
| 205 | |
Channagoud Kadabi | 500afb7 | 2011-07-19 18:24:11 +0530 | [diff] [blame] | 206 | if (flash_ecc_bch_enabled()) |
| 207 | board_part_list = board_part_list_bchecc; |
| 208 | else |
| 209 | board_part_list = board_part_list_default; |
| 210 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 211 | for (i = 0; i < num_parts; i++) { |
| 212 | struct ptentry *ptn = &board_part_list[i]; |
| 213 | unsigned len = ((ptn->length) * blocks_per_1MB); |
| 214 | |
| 215 | if(ptn->start != 0) |
| 216 | ASSERT(ptn->start == DIFF_START_ADDR); |
| 217 | |
| 218 | ptn->start = next_ptr_start_adr; |
| 219 | |
| 220 | if(ptn->length == VARIABLE_LENGTH) |
| 221 | { |
| 222 | unsigned length_for_prt = 0; |
| 223 | unsigned j; |
| 224 | for (j = i+1; j < num_parts; j++) |
| 225 | { |
| 226 | struct ptentry *temp_ptn = &board_part_list[j]; |
| 227 | ASSERT(temp_ptn->length != VARIABLE_LENGTH); |
| 228 | length_for_prt += ((temp_ptn->length) * blocks_per_1MB); |
| 229 | } |
| 230 | len = (total_num_of_blocks - 1) - (offset + ptn->start + length_for_prt); |
| 231 | ASSERT(len >= 0); |
| 232 | } |
| 233 | next_ptr_start_adr = ptn->start + len; |
| 234 | ptable_add(&flash_ptable, ptn->name, offset + ptn->start, |
| 235 | len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE); |
| 236 | } |
| 237 | |
| 238 | smem_add_modem_partitions(&flash_ptable); |
| 239 | |
| 240 | ptable_dump(&flash_ptable); |
| 241 | flash_set_ptable(&flash_ptable); |
| 242 | } |
| 243 | |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 244 | void board_info(void) |
| 245 | { |
| 246 | struct smem_board_info_v4 board_info_v4; |
| 247 | unsigned int board_info_len = 0; |
| 248 | unsigned smem_status; |
| 249 | unsigned format = 0; |
| 250 | unsigned id = 0; |
| 251 | |
| 252 | if (hw_platform && target_msm_id) |
| 253 | return; |
| 254 | |
| 255 | hw_platform = MSM7X27A_SURF; |
| 256 | target_msm_id = MSM7225A; |
| 257 | |
| 258 | smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION, |
| 259 | &format, sizeof(format), 0); |
| 260 | if(!smem_status) |
| 261 | { |
| 262 | if(format == 4) |
| 263 | { |
| 264 | board_info_len = sizeof(board_info_v4); |
| 265 | smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 266 | &board_info_v4, board_info_len); |
| 267 | if(!smem_status) |
| 268 | { |
| 269 | id = board_info_v4.board_info_v3.hw_platform; |
| 270 | target_msm_id = board_info_v4.board_info_v3.msm_id; |
| 271 | } |
| 272 | } |
| 273 | |
Channagoud Kadabi | 4c41c41 | 2011-09-08 15:38:30 +0530 | [diff] [blame^] | 274 | /* Detect SURF v/s FFA v/s QRD */ |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 275 | switch(id) |
| 276 | { |
| 277 | case 0x1: |
| 278 | hw_platform = MSM7X27A_SURF; |
| 279 | break; |
| 280 | case 0x2: |
| 281 | hw_platform = MSM7X27A_FFA; |
| 282 | break; |
Channagoud Kadabi | 4c41c41 | 2011-09-08 15:38:30 +0530 | [diff] [blame^] | 283 | case 0xB: |
| 284 | hw_platform = MSM7X27A_QRD1; |
| 285 | break; |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 286 | default: |
| 287 | hw_platform = MSM7X27A_SURF; |
| 288 | }; |
| 289 | |
| 290 | if ((target_msm_id < MSM7225A) || (target_msm_id > ESM7227A)) |
| 291 | { |
| 292 | target_msm_id = MSM7225A; |
| 293 | } |
| 294 | } |
| 295 | return; |
| 296 | } |
| 297 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 298 | unsigned board_machtype(void) |
| 299 | { |
Shashank Mittal | cb25d25 | 2011-04-05 12:13:30 -0700 | [diff] [blame] | 300 | board_info(); |
| 301 | return hw_platform; |
| 302 | } |
| 303 | |
| 304 | unsigned board_msm_id(void) |
| 305 | { |
| 306 | board_info(); |
| 307 | return target_msm_id; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | void reboot_device(unsigned reboot_reason) |
| 311 | { |
| 312 | reboot(reboot_reason); |
| 313 | } |
| 314 | |
| 315 | unsigned check_reboot_mode(void) |
| 316 | { |
| 317 | unsigned mode[2] = {0, 0}; |
| 318 | unsigned int mode_len = sizeof(mode); |
| 319 | unsigned smem_status; |
| 320 | |
| 321 | smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE, |
| 322 | &mode, mode_len ); |
| 323 | if(smem_status) |
| 324 | { |
| 325 | dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n"); |
| 326 | return 0; |
| 327 | } |
| 328 | return mode[0]; |
| 329 | } |
| 330 | |
| 331 | static unsigned target_check_power_on_reason(void) |
| 332 | { |
| 333 | unsigned power_on_status = 0; |
| 334 | unsigned int status_len = sizeof(power_on_status); |
| 335 | unsigned smem_status; |
| 336 | |
| 337 | smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO, |
| 338 | &power_on_status, status_len); |
Subbaraman Narayanamurthy | bd2424e | 2011-03-29 15:29:21 -0700 | [diff] [blame] | 339 | if (smem_status) |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 340 | { |
| 341 | dprintf(CRITICAL, "ERROR: unable to read shared memory for power on reason\n"); |
| 342 | } |
| 343 | |
| 344 | return power_on_status; |
| 345 | } |
| 346 | |
| 347 | unsigned target_pause_for_battery_charge(void) |
| 348 | { |
| 349 | if (target_check_power_on_reason() == PWR_ON_EVENT_USB_CHG) |
| 350 | return 1; |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | void target_battery_charging_enable(unsigned enable, unsigned disconnect) |
| 355 | { |
| 356 | } |
Shashank Mittal | 59392f3 | 2011-05-01 20:49:56 -0700 | [diff] [blame] | 357 | |
| 358 | #if _EMMC_BOOT |
| 359 | void target_serialno(unsigned char *buf) |
| 360 | { |
| 361 | unsigned int serialno; |
| 362 | serialno = mmc_get_psn(); |
| 363 | sprintf(buf,"%x",serialno); |
| 364 | } |
Subbaraman Narayanamurthy | 0e445b0 | 2011-06-19 21:34:46 -0700 | [diff] [blame] | 365 | |
| 366 | int emmc_recovery_init(void) |
| 367 | { |
| 368 | int rc; |
| 369 | rc = _emmc_recovery_init(); |
| 370 | return rc; |
| 371 | } |
Shashank Mittal | 59392f3 | 2011-05-01 20:49:56 -0700 | [diff] [blame] | 372 | #endif |
| 373 | |