Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 4 | * Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved. |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -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 | |
| 33 | #include <debug.h> |
| 34 | #include <dev/keys.h> |
| 35 | #include <dev/gpio_keypad.h> |
| 36 | #include <lib/ptable.h> |
| 37 | #include <dev/flash.h> |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 38 | #include <smem.h> |
| 39 | |
Chandan Uddaraju | d086459 | 2010-05-21 18:22:00 -0700 | [diff] [blame] | 40 | #define LINUX_MACHTYPE_7x30_SURF 1007016 |
| 41 | #define LINUX_MACHTYPE_7x30_FFA 1007017 |
| 42 | #define LINUX_MACHTYPE_7x30_FLUID 1007018 |
| 43 | #define LINUX_MACHTYPE_8x55_SURF 2768 |
| 44 | #define LINUX_MACHTYPE_8x55_FFA 2769 |
| 45 | #define LINUX_MACHTYPE_8x55_SVLTE_FFA 2863 |
| 46 | #define LINUX_MACHTYPE_8x55_SVLTE_SURF 2864 |
Chandan Uddaraju | f759be3 | 2010-03-17 19:04:16 -0700 | [diff] [blame] | 47 | |
| 48 | #define MSM8255_ID 74 |
| 49 | #define MSM8655_ID 75 |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 50 | |
| 51 | //Enum values for 7x30 target platforms. |
| 52 | enum platform |
| 53 | { |
| 54 | HW_PLATFORM_UNKNOWN = 0, |
| 55 | HW_PLATFORM_SURF = 1, |
| 56 | HW_PLATFORM_FFA = 2, |
| 57 | HW_PLATFORM_FLUID = 3, |
Chandan Uddaraju | d086459 | 2010-05-21 18:22:00 -0700 | [diff] [blame] | 58 | HW_PLATFORM_SVLTE = 4, |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 59 | HW_PLATFORM_32BITS = 0x7FFFFFFF |
| 60 | }; |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 61 | |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 62 | #define VARIABLE_LENGTH 0x10101010 |
| 63 | #define DIFF_START_ADDR 0xF0F0F0F0 |
| 64 | #define NUM_PAGES_PER_BLOCK 0x40 |
| 65 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 66 | static struct ptable flash_ptable; |
Chandan Uddaraju | 1434a60 | 2010-03-08 17:13:38 -0800 | [diff] [blame] | 67 | static int hw_platform_type = -1; |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 68 | |
| 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 | */ |
| 77 | static struct ptentry board_part_list[] = { |
| 78 | { |
| 79 | .start = 0, |
Chandan Uddaraju | d56669f | 2010-04-19 22:15:06 -0700 | [diff] [blame] | 80 | .length = 5 /* In MB */, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 81 | .name = "boot", |
| 82 | }, |
| 83 | { |
Chandan Uddaraju | d56669f | 2010-04-19 22:15:06 -0700 | [diff] [blame] | 84 | .start = DIFF_START_ADDR, |
| 85 | .length = 105 /* In MB */, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 86 | .name = "system", |
| 87 | }, |
| 88 | { |
Chandan Uddaraju | d56669f | 2010-04-19 22:15:06 -0700 | [diff] [blame] | 89 | .start = DIFF_START_ADDR, |
| 90 | .length = 5 /* In MB */, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 91 | .name = "cache", |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 92 | }, |
| 93 | { |
Chandan Uddaraju | d56669f | 2010-04-19 22:15:06 -0700 | [diff] [blame] | 94 | .start = DIFF_START_ADDR, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 95 | .length = VARIABLE_LENGTH, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 96 | .name = "userdata", |
| 97 | }, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 98 | { |
| 99 | .start = DIFF_START_ADDR, |
Chandan Uddaraju | d56669f | 2010-04-19 22:15:06 -0700 | [diff] [blame] | 100 | .length = 3 /* In MB */, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 101 | .name = "persist", |
| 102 | }, |
| 103 | { |
| 104 | .start = DIFF_START_ADDR, |
Chandan Uddaraju | d56669f | 2010-04-19 22:15:06 -0700 | [diff] [blame] | 105 | .length = 5 /* In MB */, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 106 | .name = "recovery", |
| 107 | }, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 108 | }; |
| 109 | static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry); |
| 110 | |
| 111 | void smem_ptable_init(void); |
| 112 | unsigned smem_get_apps_flash_start(void); |
| 113 | |
| 114 | void keypad_init(void); |
| 115 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 116 | static int emmc_boot = -1; /* set to uninitialized */ |
| 117 | int target_is_emmc_boot(void); |
Chandan Uddaraju | 1434a60 | 2010-03-08 17:13:38 -0800 | [diff] [blame] | 118 | static int platform_version = -1; |
Chandan Uddaraju | f759be3 | 2010-03-17 19:04:16 -0700 | [diff] [blame] | 119 | static int target_msm_id = -1; |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 120 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 121 | void target_init(void) |
| 122 | { |
| 123 | unsigned offset; |
| 124 | struct flash_info *flash_info; |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 125 | unsigned total_num_of_blocks; |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 126 | unsigned next_ptr_start_adr = 0; |
Chandan Uddaraju | d56669f | 2010-04-19 22:15:06 -0700 | [diff] [blame] | 127 | unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive*/ |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 128 | int i; |
| 129 | |
| 130 | dprintf(INFO, "target_init()\n"); |
| 131 | |
Chandan Uddaraju | a0d26dd | 2009-12-13 01:04:38 -0800 | [diff] [blame] | 132 | #if (!ENABLE_NANDWRITE) |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 133 | keys_init(); |
| 134 | keypad_init(); |
Chandan Uddaraju | a0d26dd | 2009-12-13 01:04:38 -0800 | [diff] [blame] | 135 | #endif |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 136 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 137 | if (target_is_emmc_boot()) |
| 138 | return; |
| 139 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 140 | ptable_init(&flash_ptable); |
| 141 | smem_ptable_init(); |
| 142 | |
| 143 | flash_init(); |
| 144 | flash_info = flash_get_info(); |
| 145 | ASSERT(flash_info); |
| 146 | |
| 147 | offset = smem_get_apps_flash_start(); |
| 148 | if (offset == 0xffffffff) |
| 149 | while(1); |
| 150 | |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 151 | total_num_of_blocks = (flash_info->block_size)/NUM_PAGES_PER_BLOCK; |
Chandan Uddaraju | d56669f | 2010-04-19 22:15:06 -0700 | [diff] [blame] | 152 | blocks_per_1MB = total_num_of_blocks / |
| 153 | (((flash_info->block_size) * (flash_info->page_size)) >> 20); |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 154 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 155 | for (i = 0; i < num_parts; i++) { |
| 156 | struct ptentry *ptn = &board_part_list[i]; |
Chandan Uddaraju | d56669f | 2010-04-19 22:15:06 -0700 | [diff] [blame] | 157 | unsigned len = ((ptn->length) * blocks_per_1MB); |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 158 | |
Chandan Uddaraju | d56669f | 2010-04-19 22:15:06 -0700 | [diff] [blame] | 159 | if(ptn->start != 0) |
| 160 | ASSERT(ptn->start == DIFF_START_ADDR); |
| 161 | |
| 162 | ptn->start = next_ptr_start_adr; |
| 163 | |
| 164 | if(ptn->length == VARIABLE_LENGTH) |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 165 | { |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 166 | unsigned length_for_prt = 0; |
| 167 | unsigned j; |
| 168 | for (j = i+1; j < num_parts; j++) |
| 169 | { |
| 170 | struct ptentry *temp_ptn = &board_part_list[j]; |
| 171 | ASSERT(temp_ptn->length != VARIABLE_LENGTH); |
Chandan Uddaraju | d56669f | 2010-04-19 22:15:06 -0700 | [diff] [blame] | 172 | length_for_prt += ((temp_ptn->length) * blocks_per_1MB); |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 173 | } |
| 174 | len = (total_num_of_blocks - 1) - (offset + ptn->start + length_for_prt); |
| 175 | ASSERT(len >= 0); |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 176 | } |
Chandan Uddaraju | d56669f | 2010-04-19 22:15:06 -0700 | [diff] [blame] | 177 | next_ptr_start_adr = ptn->start + len; |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 178 | ptable_add(&flash_ptable, ptn->name, offset + ptn->start, |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 179 | len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE); |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 182 | smem_add_modem_partitions(&flash_ptable); |
| 183 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 184 | ptable_dump(&flash_ptable); |
| 185 | flash_set_ptable(&flash_ptable); |
| 186 | } |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 187 | |
Chandan Uddaraju | 1434a60 | 2010-03-08 17:13:38 -0800 | [diff] [blame] | 188 | int target_platform_version(void) |
| 189 | { |
| 190 | return platform_version; |
| 191 | } |
| 192 | |
Chandan Uddaraju | f759be3 | 2010-03-17 19:04:16 -0700 | [diff] [blame] | 193 | int target_is_msm8x55(void) |
| 194 | { |
| 195 | if ((target_msm_id == MSM8255_ID) || |
| 196 | (target_msm_id == MSM8655_ID)) |
| 197 | return 1; |
| 198 | else |
| 199 | return 0; |
| 200 | } |
| 201 | |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 202 | unsigned board_machtype(void) |
| 203 | { |
Chandan Uddaraju | 1434a60 | 2010-03-08 17:13:38 -0800 | [diff] [blame] | 204 | struct smem_board_info_v4 board_info_v4; |
| 205 | unsigned int board_info_len = 0; |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 206 | enum platform platform_type = 0; |
| 207 | unsigned smem_status; |
Chandan Uddaraju | 1434a60 | 2010-03-08 17:13:38 -0800 | [diff] [blame] | 208 | unsigned format = 0; |
| 209 | if(hw_platform_type != -1) |
| 210 | return hw_platform_type; |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 211 | |
Chandan Uddaraju | 1434a60 | 2010-03-08 17:13:38 -0800 | [diff] [blame] | 212 | smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION, |
| 213 | &format, sizeof(format), 0); |
Chandan Uddaraju | f759be3 | 2010-03-17 19:04:16 -0700 | [diff] [blame] | 214 | if(!smem_status) |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 215 | { |
Chandan Uddaraju | f759be3 | 2010-03-17 19:04:16 -0700 | [diff] [blame] | 216 | if ((format == 3) || (format == 4)) |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 217 | { |
Chandan Uddaraju | f759be3 | 2010-03-17 19:04:16 -0700 | [diff] [blame] | 218 | if (format == 4) |
| 219 | board_info_len = sizeof(board_info_v4); |
| 220 | else |
| 221 | board_info_len = sizeof(board_info_v4.board_info_v3); |
Chandan Uddaraju | 1434a60 | 2010-03-08 17:13:38 -0800 | [diff] [blame] | 222 | |
Chandan Uddaraju | f759be3 | 2010-03-17 19:04:16 -0700 | [diff] [blame] | 223 | smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 224 | &board_info_v4, board_info_len); |
| 225 | if(!smem_status) |
| 226 | { |
| 227 | if(format == 4) |
| 228 | platform_version = board_info_v4.platform_version; |
| 229 | |
| 230 | platform_type = board_info_v4.board_info_v3.hw_platform; |
| 231 | target_msm_id = board_info_v4.board_info_v3.msm_id; |
| 232 | switch (platform_type) |
| 233 | { |
| 234 | case HW_PLATFORM_SURF: |
| 235 | hw_platform_type = ((target_is_msm8x55()) ? |
| 236 | LINUX_MACHTYPE_8x55_SURF : LINUX_MACHTYPE_7x30_SURF); break; |
| 237 | case HW_PLATFORM_FFA: |
| 238 | hw_platform_type = ((target_is_msm8x55()) ? |
| 239 | LINUX_MACHTYPE_8x55_FFA : LINUX_MACHTYPE_7x30_FFA); break; |
| 240 | case HW_PLATFORM_FLUID: |
| 241 | hw_platform_type = LINUX_MACHTYPE_7x30_FLUID; break; |
Chandan Uddaraju | d086459 | 2010-05-21 18:22:00 -0700 | [diff] [blame] | 242 | case HW_PLATFORM_SVLTE: |
| 243 | hw_platform_type = LINUX_MACHTYPE_8x55_SVLTE_FFA; break; |
Chandan Uddaraju | f759be3 | 2010-03-17 19:04:16 -0700 | [diff] [blame] | 244 | default: |
| 245 | hw_platform_type = ((target_is_msm8x55()) ? |
| 246 | LINUX_MACHTYPE_8x55_SURF : LINUX_MACHTYPE_7x30_SURF); break; |
| 247 | } |
| 248 | return hw_platform_type; |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | hw_platform_type = LINUX_MACHTYPE_7x30_SURF; |
Chandan Uddaraju | 1434a60 | 2010-03-08 17:13:38 -0800 | [diff] [blame] | 253 | return hw_platform_type; |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 254 | } |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 255 | |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 256 | void reboot_device(unsigned reboot_reason) |
| 257 | { |
| 258 | reboot(reboot_reason); |
| 259 | } |
| 260 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 261 | unsigned check_reboot_mode(void) |
| 262 | { |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 263 | unsigned mode[2] = {0, 0}; |
| 264 | unsigned int mode_len = sizeof(mode); |
| 265 | unsigned smem_status; |
| 266 | |
| 267 | smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE, |
| 268 | &mode, mode_len ); |
| 269 | if(smem_status) |
| 270 | { |
| 271 | dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n"); |
| 272 | return 0; |
| 273 | } |
| 274 | return mode[0]; |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 275 | } |
Chandan Uddaraju | 7f5b901 | 2010-02-06 16:37:48 -0800 | [diff] [blame] | 276 | |
| 277 | void target_battery_charging_enable(unsigned enable, unsigned disconnect) |
| 278 | { |
| 279 | } |