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 | |
| 40 | #define LINUX_MACHTYPE_SURF 1007016 |
| 41 | #define LINUX_MACHTYPE_FFA 1007017 |
| 42 | #define LINUX_MACHTYPE_FLUID 1007018 |
| 43 | |
| 44 | //Enum values for 7x30 target platforms. |
| 45 | enum platform |
| 46 | { |
| 47 | HW_PLATFORM_UNKNOWN = 0, |
| 48 | HW_PLATFORM_SURF = 1, |
| 49 | HW_PLATFORM_FFA = 2, |
| 50 | HW_PLATFORM_FLUID = 3, |
| 51 | HW_PLATFORM_32BITS = 0x7FFFFFFF |
| 52 | }; |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 53 | |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 54 | #define VARIABLE_LENGTH 0x10101010 |
| 55 | #define DIFF_START_ADDR 0xF0F0F0F0 |
| 56 | #define NUM_PAGES_PER_BLOCK 0x40 |
| 57 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 58 | static struct ptable flash_ptable; |
| 59 | |
| 60 | /* for these partitions, start will be offset by either what we get from |
| 61 | * smem, or from the above offset if smem is not useful. Also, we should |
| 62 | * probably have smem_ptable code populate our flash_ptable. |
| 63 | * |
| 64 | * When smem provides us with a full partition table, we can get rid of |
| 65 | * this altogether. |
| 66 | * |
| 67 | */ |
| 68 | static struct ptentry board_part_list[] = { |
| 69 | { |
| 70 | .start = 0, |
Chandan Uddaraju | 2e2908f | 2010-01-12 13:30:59 -0800 | [diff] [blame] | 71 | .length = 20 /* 5MB */, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 72 | .name = "boot", |
| 73 | }, |
| 74 | { |
Chandan Uddaraju | 2e2908f | 2010-01-12 13:30:59 -0800 | [diff] [blame] | 75 | .start = 20, |
Ajay Dudani | d43419e | 2010-02-10 13:17:39 -0800 | [diff] [blame] | 76 | .length = 420 /* 105MB */, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 77 | .name = "system", |
| 78 | }, |
| 79 | { |
Ajay Dudani | d43419e | 2010-02-10 13:17:39 -0800 | [diff] [blame] | 80 | .start = 440, |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 81 | .length = 20 /* 5MB */, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 82 | .name = "cache", |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 83 | }, |
| 84 | { |
Ajay Dudani | d43419e | 2010-02-10 13:17:39 -0800 | [diff] [blame] | 85 | .start = 460, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 86 | .length = VARIABLE_LENGTH, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 87 | .name = "userdata", |
| 88 | }, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 89 | { |
| 90 | .start = DIFF_START_ADDR, |
Chandan Uddaraju | 535fa09 | 2010-01-26 19:14:48 -0800 | [diff] [blame] | 91 | .length = 12 /* 3MB */, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 92 | .name = "persist", |
| 93 | }, |
| 94 | { |
| 95 | .start = DIFF_START_ADDR, |
| 96 | .length = 20 /* 5MB */, |
| 97 | .name = "recovery", |
| 98 | }, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 99 | }; |
| 100 | static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry); |
| 101 | |
| 102 | void smem_ptable_init(void); |
| 103 | unsigned smem_get_apps_flash_start(void); |
| 104 | |
| 105 | void keypad_init(void); |
| 106 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 107 | static int emmc_boot = -1; /* set to uninitialized */ |
| 108 | int target_is_emmc_boot(void); |
| 109 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 110 | void target_init(void) |
| 111 | { |
| 112 | unsigned offset; |
| 113 | struct flash_info *flash_info; |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 114 | unsigned total_num_of_blocks; |
| 115 | bool start_addr_changed = false; |
| 116 | unsigned next_ptr_start_adr = 0; |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 117 | int i; |
| 118 | |
| 119 | dprintf(INFO, "target_init()\n"); |
| 120 | |
Chandan Uddaraju | a0d26dd | 2009-12-13 01:04:38 -0800 | [diff] [blame] | 121 | #if (!ENABLE_NANDWRITE) |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 122 | keys_init(); |
| 123 | keypad_init(); |
Chandan Uddaraju | a0d26dd | 2009-12-13 01:04:38 -0800 | [diff] [blame] | 124 | #endif |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 125 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 126 | if (target_is_emmc_boot()) |
| 127 | return; |
| 128 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 129 | ptable_init(&flash_ptable); |
| 130 | smem_ptable_init(); |
| 131 | |
| 132 | flash_init(); |
| 133 | flash_info = flash_get_info(); |
| 134 | ASSERT(flash_info); |
| 135 | |
| 136 | offset = smem_get_apps_flash_start(); |
| 137 | if (offset == 0xffffffff) |
| 138 | while(1); |
| 139 | |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 140 | total_num_of_blocks = (flash_info->block_size)/NUM_PAGES_PER_BLOCK; |
| 141 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 142 | for (i = 0; i < num_parts; i++) { |
| 143 | struct ptentry *ptn = &board_part_list[i]; |
| 144 | unsigned len = ptn->length; |
| 145 | |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 146 | if(len == VARIABLE_LENGTH) |
| 147 | { |
| 148 | start_addr_changed = true; |
| 149 | unsigned length_for_prt = 0; |
| 150 | unsigned j; |
| 151 | for (j = i+1; j < num_parts; j++) |
| 152 | { |
| 153 | struct ptentry *temp_ptn = &board_part_list[j]; |
| 154 | ASSERT(temp_ptn->length != VARIABLE_LENGTH); |
| 155 | length_for_prt += temp_ptn->length; |
| 156 | } |
| 157 | len = (total_num_of_blocks - 1) - (offset + ptn->start + length_for_prt); |
| 158 | ASSERT(len >= 0); |
| 159 | next_ptr_start_adr = ptn->start + len; |
| 160 | } |
| 161 | if((ptn->start == DIFF_START_ADDR) && (start_addr_changed)) |
| 162 | { |
| 163 | ASSERT(next_ptr_start_adr); |
| 164 | ptn->start = next_ptr_start_adr; |
| 165 | next_ptr_start_adr = ptn->start + ptn->length; |
| 166 | } |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 167 | ptable_add(&flash_ptable, ptn->name, offset + ptn->start, |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame^] | 168 | len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE); |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame^] | 171 | smem_add_modem_partitions(&flash_ptable); |
| 172 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 173 | ptable_dump(&flash_ptable); |
| 174 | flash_set_ptable(&flash_ptable); |
| 175 | } |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 176 | |
| 177 | unsigned board_machtype(void) |
| 178 | { |
| 179 | struct smem_board_info board_info; |
| 180 | unsigned int board_info_struct_len = sizeof(board_info); |
| 181 | enum platform platform_type = 0; |
| 182 | unsigned smem_status; |
| 183 | |
| 184 | smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 185 | &board_info, board_info_struct_len ); |
| 186 | if(smem_status) |
| 187 | { |
| 188 | dprintf(CRITICAL, "ERROR: unable to read shared memory for Hardware Platform\n"); |
| 189 | } |
| 190 | |
| 191 | if (board_info.format == 3) |
| 192 | { |
| 193 | platform_type = board_info.hw_platform; |
| 194 | switch (platform_type) |
| 195 | { |
| 196 | case HW_PLATFORM_SURF: |
| 197 | return LINUX_MACHTYPE_SURF; |
| 198 | case HW_PLATFORM_FFA: |
| 199 | return LINUX_MACHTYPE_FFA; |
| 200 | case HW_PLATFORM_FLUID: |
| 201 | return LINUX_MACHTYPE_FLUID; |
| 202 | default: |
| 203 | return LINUX_MACHTYPE_SURF; |
| 204 | } |
| 205 | } |
| 206 | return LINUX_MACHTYPE_SURF; |
| 207 | } |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 208 | |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 209 | void reboot_device(unsigned reboot_reason) |
| 210 | { |
| 211 | reboot(reboot_reason); |
| 212 | } |
| 213 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 214 | unsigned check_reboot_mode(void) |
| 215 | { |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 216 | unsigned mode[2] = {0, 0}; |
| 217 | unsigned int mode_len = sizeof(mode); |
| 218 | unsigned smem_status; |
| 219 | |
| 220 | smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE, |
| 221 | &mode, mode_len ); |
| 222 | if(smem_status) |
| 223 | { |
| 224 | dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n"); |
| 225 | return 0; |
| 226 | } |
| 227 | return mode[0]; |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 228 | } |
Chandan Uddaraju | 7f5b901 | 2010-02-06 16:37:48 -0800 | [diff] [blame] | 229 | |
| 230 | void target_battery_charging_enable(unsigned enable, unsigned disconnect) |
| 231 | { |
| 232 | } |