Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -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. |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -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 | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 38 | #include <smem.h> |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 39 | |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 40 | #define LINUX_MACHTYPE 1007015 |
| 41 | |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 42 | #define VARIABLE_LENGTH 0x10101010 |
| 43 | #define DIFF_START_ADDR 0xF0F0F0F0 |
| 44 | #define NUM_PAGES_PER_BLOCK 0x40 |
| 45 | |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 46 | static struct ptable flash_ptable; |
| 47 | |
| 48 | /* for these partitions, start will be offset by either what we get from |
| 49 | * smem, or from the above offset if smem is not useful. Also, we should |
| 50 | * probably have smem_ptable code populate our flash_ptable. |
| 51 | * |
| 52 | * When smem provides us with a full partition table, we can get rid of |
| 53 | * this altogether. |
| 54 | * |
| 55 | */ |
| 56 | static struct ptentry board_part_list[] = { |
| 57 | { |
| 58 | .start = 0, |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 59 | .length = 5 /* In MB */, |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 60 | .name = "boot", |
| 61 | }, |
| 62 | { |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 63 | .start = DIFF_START_ADDR, |
| 64 | .length = 97 /* In MB */, |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 65 | .name = "system", |
| 66 | }, |
| 67 | { |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 68 | .start = DIFF_START_ADDR, |
| 69 | .length = 1 /* In MB */, |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 70 | .name = "splash", |
| 71 | }, |
| 72 | { |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 73 | .start = DIFF_START_ADDR, |
| 74 | .length = 30 /* In MB */, |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 75 | .name = "cache", |
| 76 | }, |
| 77 | { |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 78 | .start = DIFF_START_ADDR, |
| 79 | .length = 0.5 /* In MB */, |
Subbaraman Narayanamurthy | eb92bcc | 2010-07-20 14:32:46 -0700 | [diff] [blame] | 80 | .name = "misc", |
| 81 | }, |
| 82 | { |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 83 | .start = DIFF_START_ADDR, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 84 | .length = VARIABLE_LENGTH, |
| 85 | .name = "userdata", |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 86 | }, |
| 87 | { |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 88 | .start = DIFF_START_ADDR, |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 89 | .length = 0.5 /* In MB */, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 90 | .name = "persist", |
| 91 | }, |
| 92 | { |
| 93 | .start = DIFF_START_ADDR, |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 94 | .length = 5 /* In MB */, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 95 | .name = "recovery", |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 96 | }, |
| 97 | }; |
| 98 | static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry); |
| 99 | |
| 100 | void smem_ptable_init(void); |
| 101 | unsigned smem_get_apps_flash_start(void); |
| 102 | |
| 103 | void keypad_init(void); |
| 104 | |
David Ng | bf2eb3c | 2009-12-09 23:48:07 -0800 | [diff] [blame] | 105 | int target_is_emmc_boot(void); |
| 106 | |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 107 | void target_init(void) |
| 108 | { |
| 109 | unsigned offset; |
| 110 | struct flash_info *flash_info; |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 111 | unsigned total_num_of_blocks; |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 112 | unsigned next_ptr_start_adr = 0; |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 113 | unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive*/ |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 114 | int i; |
| 115 | |
| 116 | dprintf(INFO, "target_init()\n"); |
| 117 | |
Chandan Uddaraju | 852cd2c | 2009-12-17 14:28:28 -0800 | [diff] [blame] | 118 | #if (!ENABLE_NANDWRITE) |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 119 | keys_init(); |
| 120 | keypad_init(); |
Chandan Uddaraju | 852cd2c | 2009-12-17 14:28:28 -0800 | [diff] [blame] | 121 | #endif |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 122 | |
David Ng | bf2eb3c | 2009-12-09 23:48:07 -0800 | [diff] [blame] | 123 | if (target_is_emmc_boot()) |
| 124 | return; |
| 125 | |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 126 | ptable_init(&flash_ptable); |
| 127 | smem_ptable_init(); |
| 128 | |
| 129 | flash_init(); |
| 130 | flash_info = flash_get_info(); |
| 131 | ASSERT(flash_info); |
| 132 | |
| 133 | offset = smem_get_apps_flash_start(); |
| 134 | if (offset == 0xffffffff) |
| 135 | while(1); |
| 136 | |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 137 | total_num_of_blocks = (flash_info->block_size)/NUM_PAGES_PER_BLOCK; |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 138 | blocks_per_1MB = total_num_of_blocks / |
| 139 | (((flash_info->block_size) * (flash_info->page_size)) >> 20); |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 140 | |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 141 | for (i = 0; i < num_parts; i++) { |
| 142 | struct ptentry *ptn = &board_part_list[i]; |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 143 | unsigned len = ((ptn->length) * blocks_per_1MB); |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 144 | |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 145 | if(ptn->start != 0) |
| 146 | ASSERT(ptn->start == DIFF_START_ADDR); |
| 147 | |
| 148 | ptn->start = next_ptr_start_adr; |
| 149 | |
| 150 | if(ptn->length == VARIABLE_LENGTH) |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 151 | { |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 152 | unsigned length_for_prt = 0; |
| 153 | unsigned j; |
| 154 | for (j = i+1; j < num_parts; j++) |
| 155 | { |
| 156 | struct ptentry *temp_ptn = &board_part_list[j]; |
| 157 | ASSERT(temp_ptn->length != VARIABLE_LENGTH); |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 158 | length_for_prt += ((temp_ptn->length) * blocks_per_1MB); |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 159 | } |
| 160 | len = (total_num_of_blocks - 1) - (offset + ptn->start + length_for_prt); |
| 161 | ASSERT(len >= 0); |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 162 | } |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 163 | next_ptr_start_adr = ptn->start + len; |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 164 | ptable_add(&flash_ptable, ptn->name, offset + ptn->start, |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 165 | len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE); |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 168 | smem_add_modem_partitions(&flash_ptable); |
| 169 | |
Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame] | 170 | ptable_dump(&flash_ptable); |
| 171 | flash_set_ptable(&flash_ptable); |
| 172 | } |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 173 | |
| 174 | unsigned board_machtype(void) |
| 175 | { |
| 176 | return LINUX_MACHTYPE; |
| 177 | } |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 178 | |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 179 | void reboot_device(unsigned reboot_reason) |
| 180 | { |
| 181 | reboot(reboot_reason); |
| 182 | } |
| 183 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 184 | unsigned check_reboot_mode(void) |
| 185 | { |
Chandan Uddaraju | 8a1d37c | 2010-01-06 12:04:28 -0800 | [diff] [blame] | 186 | unsigned mode[2] = {0, 0}; |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 187 | unsigned int mode_len = sizeof(mode); |
| 188 | unsigned smem_status; |
| 189 | |
| 190 | smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE, |
| 191 | &mode, mode_len ); |
| 192 | if(smem_status) |
| 193 | { |
| 194 | dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n"); |
| 195 | return 0; |
| 196 | } |
Chandan Uddaraju | 8a1d37c | 2010-01-06 12:04:28 -0800 | [diff] [blame] | 197 | return mode[0]; |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 198 | } |
Chandan Uddaraju | 7f5b901 | 2010-02-06 16:37:48 -0800 | [diff] [blame] | 199 | |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 200 | static unsigned target_check_power_on_reason(void) |
| 201 | { |
| 202 | unsigned power_on_status = 0; |
| 203 | unsigned int status_len = sizeof(power_on_status); |
| 204 | unsigned smem_status; |
| 205 | |
| 206 | smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO, |
| 207 | &power_on_status, status_len); |
| 208 | if (!smem_status) |
| 209 | { |
| 210 | dprintf(CRITICAL, "ERROR: unable to read shared memory for power on reason\n"); |
| 211 | } |
| 212 | |
| 213 | return power_on_status; |
| 214 | } |
| 215 | |
| 216 | unsigned target_pause_for_battery_charge(void) |
| 217 | { |
| 218 | if (target_check_power_on_reason() == PWR_ON_EVENT_USB_CHG) |
| 219 | return 1; |
| 220 | return 0; |
| 221 | } |
| 222 | |
Chandan Uddaraju | 7f5b901 | 2010-02-06 16:37:48 -0800 | [diff] [blame] | 223 | void target_battery_charging_enable(unsigned enable, unsigned disconnect) |
| 224 | { |
| 225 | } |