Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in |
| 14 | * the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google, Inc. nor the names of its contributors |
| 17 | * may be used to endorse or promote products derived from this |
| 18 | * software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 31 | * SUCH DAMAGE. |
| 32 | */ |
| 33 | |
| 34 | #include <reg.h> |
| 35 | #include <debug.h> |
| 36 | #include <lib/ptable.h> |
| 37 | #include <dev/flash.h> |
Kinson Chik | 53f8d32 | 2011-08-30 13:39:38 -0700 | [diff] [blame] | 38 | #include <dev/pm8921.h> |
| 39 | #include <dev/ssbi.h> |
Kinson Chik | 175e847 | 2011-09-06 17:01:26 -0700 | [diff] [blame] | 40 | #include <string.h> |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 41 | #include <smem.h> |
| 42 | #include <gsbi.h> |
| 43 | #include <platform/iomap.h> |
| 44 | #include <platform.h> |
| 45 | |
| 46 | #define MDM9X15_CDP 3675 |
| 47 | #define MDM9X15_MTP 3681 |
| 48 | #define LINUX_MACHTYPE MDM9X15_CDP |
| 49 | |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 50 | static struct ptable flash_ptable; |
| 51 | unsigned hw_platform = 0; |
| 52 | unsigned target_msm_id = 0; |
| 53 | |
Kinson Chik | 175e847 | 2011-09-06 17:01:26 -0700 | [diff] [blame] | 54 | /* Partition names for fastboot flash */ |
| 55 | char *apps_ptn_names[] = {"aboot", "boot", "system"}; |
| 56 | /* Partitions should be in this order */ |
| 57 | char *ptable_ptn_names[] = {"APPSBL", "APPS", "EFS2APPS"}; |
| 58 | unsigned ptn_name_count = 3; |
| 59 | unsigned modem_ptn_count = 7; |
| 60 | |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 61 | static const uint8_t uart_gsbi_id = GSBI_ID_4; |
| 62 | |
Kinson Chik | 53f8d32 | 2011-08-30 13:39:38 -0700 | [diff] [blame] | 63 | static pm8921_dev_t pmic; |
| 64 | |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 65 | void smem_ptable_init(void); |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 66 | extern void reboot(unsigned reboot_reason); |
Kinson Chik | 175e847 | 2011-09-06 17:01:26 -0700 | [diff] [blame] | 67 | void update_ptable_apps_partitions(void); |
| 68 | void update_ptable_modem_partitions(void); |
Kinson Chik | 0b1c816 | 2011-08-31 16:31:57 -0700 | [diff] [blame] | 69 | extern int fake_key_get_state(void); |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 70 | |
| 71 | void target_init(void) |
| 72 | { |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 73 | struct flash_info *flash_info; |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 74 | |
| 75 | dprintf(INFO, "target_init()\n"); |
Kinson Chik | 53f8d32 | 2011-08-30 13:39:38 -0700 | [diff] [blame] | 76 | |
| 77 | /* Initialize PMIC driver */ |
| 78 | pmic.read = (pm8921_read_func) &pa1_ssbi2_read_bytes; |
| 79 | pmic.write = (pm8921_write_func) &pa1_ssbi2_write_bytes; |
| 80 | |
| 81 | pm8921_init(&pmic); |
| 82 | |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 83 | ptable_init(&flash_ptable); |
| 84 | smem_ptable_init(); |
| 85 | |
| 86 | flash_init(); |
| 87 | flash_info = flash_get_info(); |
| 88 | ASSERT(flash_info); |
| 89 | |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 90 | smem_add_modem_partitions(&flash_ptable); |
| 91 | |
Kinson Chik | 175e847 | 2011-09-06 17:01:26 -0700 | [diff] [blame] | 92 | /* Update the naming for apps partitions and type */ |
| 93 | update_ptable_apps_partitions(); |
| 94 | |
| 95 | /* Update modem partitions to lower case for fastboot */ |
| 96 | update_ptable_modem_partitions(); |
| 97 | |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 98 | ptable_dump(&flash_ptable); |
| 99 | flash_set_ptable(&flash_ptable); |
| 100 | } |
| 101 | |
| 102 | void board_info(void) |
| 103 | { |
| 104 | struct smem_board_info_v4 board_info_v4; |
| 105 | unsigned int board_info_len = 0; |
| 106 | unsigned smem_status; |
| 107 | unsigned format = 0; |
| 108 | unsigned id = 0; |
| 109 | |
| 110 | if (hw_platform && target_msm_id) |
| 111 | return; |
| 112 | |
| 113 | hw_platform = MDM9X15_CDP; |
| 114 | target_msm_id = MDM9600; |
| 115 | |
| 116 | smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION, |
| 117 | &format, sizeof(format), 0); |
| 118 | if(!smem_status) |
| 119 | { |
| 120 | if(format == 4) |
| 121 | { |
| 122 | board_info_len = sizeof(board_info_v4); |
| 123 | smem_status = smem_read_alloc_entry( |
| 124 | SMEM_BOARD_INFO_LOCATION, |
| 125 | &board_info_v4, board_info_len); |
| 126 | if(!smem_status) |
| 127 | { |
| 128 | id = board_info_v4.board_info_v3.hw_platform; |
| 129 | target_msm_id = |
| 130 | board_info_v4.board_info_v3.msm_id; |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | unsigned board_machtype(void) |
| 138 | { |
| 139 | board_info(); |
| 140 | return hw_platform; |
| 141 | } |
| 142 | |
| 143 | void reboot_device(unsigned reboot_reason) |
| 144 | { |
Kinson Chik | 53f8d32 | 2011-08-30 13:39:38 -0700 | [diff] [blame] | 145 | /* Actually reset the chip */ |
| 146 | pm8921_config_reset_pwr_off(1); |
| 147 | writel(0, MSM_PSHOLD_CTL_SU); |
| 148 | mdelay(10000); |
| 149 | |
| 150 | dprintf (CRITICAL, "Rebooting failed\n"); |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 151 | return; |
| 152 | } |
| 153 | |
| 154 | uint8_t target_uart_gsbi(void) |
| 155 | { |
| 156 | return uart_gsbi_id; |
| 157 | } |
| 158 | |
Kinson Chik | 0b1c816 | 2011-08-31 16:31:57 -0700 | [diff] [blame] | 159 | /* |
| 160 | * Return 1 to trigger to fastboot |
| 161 | */ |
| 162 | int fastboot_trigger(void) { |
| 163 | int ret; |
| 164 | ret = fake_key_get_state(); |
| 165 | /* Want to trigger when dip switch is off */ |
| 166 | return (!ret); |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 167 | } |
Kinson Chik | 175e847 | 2011-09-06 17:01:26 -0700 | [diff] [blame] | 168 | |
| 169 | void update_ptable_modem_partitions(void) |
| 170 | { |
| 171 | uint32_t ptn_index, i = 0; |
| 172 | uint32_t name_size; |
| 173 | struct ptentry * ptentry_ptr = flash_ptable.parts; |
| 174 | |
| 175 | for(ptn_index=0; ptn_index < modem_ptn_count; ptn_index++) |
| 176 | { |
| 177 | name_size = strlen(ptentry_ptr[ptn_index].name); |
| 178 | for(i=0; i < name_size; i++) |
| 179 | { |
| 180 | ptentry_ptr[ptn_index].name[i] = |
| 181 | tolower(ptentry_ptr[ptn_index].name[i]); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | void update_ptable_apps_partitions(void) |
| 187 | { |
| 188 | uint32_t ptn_index, name_index = 0; |
| 189 | uint32_t end = 0xffffffff; |
| 190 | uint32_t name_size = strlen(ptable_ptn_names[name_index]); |
| 191 | struct ptentry * ptentry_ptr = flash_ptable.parts; |
| 192 | |
| 193 | for(ptn_index=0; ptentry_ptr[ptn_index].start != end; ptn_index++) |
| 194 | { |
| 195 | if (!(strncmp(ptentry_ptr[ptn_index].name, |
| 196 | ptable_ptn_names[name_index], name_size))) |
| 197 | { |
| 198 | name_size = strlen(apps_ptn_names[name_index]); |
| 199 | name_size++; /* For null termination */ |
| 200 | |
| 201 | /* Update the partition names to something familiar */ |
| 202 | if (name_size <= MAX_PTENTRY_NAME) |
| 203 | strncpy(ptentry_ptr[ptn_index].name, |
| 204 | apps_ptn_names[name_index], name_size); |
| 205 | |
| 206 | /* Aboot uses modem page layout, leave aboot ptn */ |
| 207 | if (name_index != 0) |
| 208 | ptentry_ptr[ptn_index].type = |
| 209 | TYPE_APPS_PARTITION; |
| 210 | |
| 211 | /* Don't go out of bounds */ |
| 212 | name_index++; |
| 213 | if (name_index >= ptn_name_count) |
| 214 | break; |
| 215 | name_size = strlen(ptable_ptn_names[name_index]); |
| 216 | } |
| 217 | } |
| 218 | } |