Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
Amol Jadi | da118b9 | 2012-07-06 19:53:18 -0700 | [diff] [blame] | 4 | * Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved. |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [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> |
Kinson Chik | ea64624 | 2011-09-01 13:53:16 -0700 | [diff] [blame] | 35 | #include <dev/ssbi.h> |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 36 | #include <dev/gpio.h> |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [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> |
| 41 | #include <platform/timer.h> |
Subbaraman Narayanamurthy | f9b6e0d | 2010-09-08 16:51:43 -0700 | [diff] [blame] | 42 | #include <platform/iomap.h> |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 43 | #include <platform/gpio.h> |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 44 | #include <baseband.h> |
Subbaraman Narayanamurthy | f9b6e0d | 2010-09-08 16:51:43 -0700 | [diff] [blame] | 45 | #include <reg.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 46 | #include <platform.h> |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 47 | #include <gsbi.h> |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 48 | #include <platform/scm-io.h> |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 49 | #include <platform/machtype.h> |
Deepa Dinamani | 5e5c21a | 2012-02-16 18:59:57 -0800 | [diff] [blame] | 50 | #include <crypto_hash.h> |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 51 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 52 | static const uint8_t uart_gsbi_id = GSBI_ID_12; |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 53 | |
Deepa Dinamani | 5e5c21a | 2012-02-16 18:59:57 -0800 | [diff] [blame] | 54 | /* Setting this variable to different values defines the |
| 55 | * behavior of CE engine: |
| 56 | * platform_ce_type = CRYPTO_ENGINE_TYPE_NONE : No CE engine |
| 57 | * platform_ce_type = CRYPTO_ENGINE_TYPE_SW : Software CE engine |
| 58 | * platform_ce_type = CRYPTO_ENGINE_TYPE_HW : Hardware CE engine |
| 59 | * Behavior is determined in the target code. |
| 60 | */ |
| 61 | static crypto_engine_type platform_ce_type = CRYPTO_ENGINE_TYPE_SW; |
| 62 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 63 | void keypad_init(void); |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 64 | extern void dmb(void); |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 65 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 66 | int target_is_emmc_boot(void); |
Subbaraman Narayanamurthy | f9b6e0d | 2010-09-08 16:51:43 -0700 | [diff] [blame] | 67 | void debug_led_write(char); |
| 68 | char debug_led_read(); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 69 | uint32_t platform_id_read(void); |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 70 | void setup_fpga(void); |
Shashank Mittal | 6df1607 | 2011-07-14 18:44:01 -0700 | [diff] [blame] | 71 | int pm8901_reset_pwr_off(int reset); |
| 72 | int pm8058_reset_pwr_off(int reset); |
| 73 | int pm8058_rtc0_alarm_irq_disable(void); |
| 74 | static void target_shutdown_for_rtc_alarm(void); |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 75 | void target_init(void) |
| 76 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 77 | target_shutdown_for_rtc_alarm(); |
| 78 | dprintf(INFO, "target_init()\n"); |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 79 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 80 | setup_fpga(); |
Subbaraman Narayanamurthy | 50d936f | 2010-09-08 17:09:00 -0700 | [diff] [blame] | 81 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 82 | /* Setting Debug LEDs ON */ |
| 83 | debug_led_write(0xFF); |
Chandan Uddaraju | bedca15 | 2010-06-02 23:05:15 -0700 | [diff] [blame] | 84 | #if (!ENABLE_NANDWRITE) |
| 85 | keys_init(); |
| 86 | keypad_init(); |
| 87 | #endif |
Kinson Chik | ce306ff | 2011-07-08 15:23:33 -0700 | [diff] [blame] | 88 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 89 | /* Display splash screen if enabled */ |
Kinson Chik | ce306ff | 2011-07-08 15:23:33 -0700 | [diff] [blame] | 90 | #if DISPLAY_SPLASH_SCREEN |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 91 | display_init(); |
| 92 | dprintf(SPEW, "Diplay initialized\n"); |
| 93 | display_image_on_screen(); |
Kinson Chik | ce306ff | 2011-07-08 15:23:33 -0700 | [diff] [blame] | 94 | #endif |
| 95 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 96 | if (mmc_boot_main(MMC_SLOT, MSM_SDC1_BASE)) { |
| 97 | dprintf(CRITICAL, "mmc init failed!"); |
| 98 | ASSERT(0); |
| 99 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | unsigned board_machtype(void) |
| 103 | { |
Ajay Dudani | 16ea8fb | 2010-11-23 19:15:38 -0800 | [diff] [blame] | 104 | struct smem_board_info_v5 board_info_v5; |
Shashank Mittal | 2249a07 | 2011-02-14 19:24:17 -0800 | [diff] [blame] | 105 | struct smem_board_info_v6 board_info_v6; |
Ajay Dudani | 16ea8fb | 2010-11-23 19:15:38 -0800 | [diff] [blame] | 106 | unsigned int board_info_len = 0; |
| 107 | unsigned smem_status = 0; |
| 108 | unsigned format = 0; |
| 109 | unsigned id = 0; |
| 110 | unsigned hw_platform = 0; |
| 111 | unsigned fused_chip = 0; |
Ajay Dudani | 295f38b | 2011-02-25 15:28:07 -0800 | [diff] [blame] | 112 | unsigned platform_subtype = 0; |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 113 | static unsigned mach_id = 0xFFFFFFFF; |
Shashank Mittal | c69512e | 2010-09-22 16:40:48 -0700 | [diff] [blame] | 114 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 115 | if (mach_id != 0xFFFFFFFF) |
Subbaraman Narayanamurthy | 8f0b045 | 2011-03-11 18:30:10 -0800 | [diff] [blame] | 116 | return mach_id; |
Ajay Dudani | 16ea8fb | 2010-11-23 19:15:38 -0800 | [diff] [blame] | 117 | /* Detect external msm if this is a "fusion" */ |
| 118 | smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 119 | &format, sizeof(format), 0); |
| 120 | if (!smem_status) { |
| 121 | if (format == 5) { |
Ajay Dudani | 16ea8fb | 2010-11-23 19:15:38 -0800 | [diff] [blame] | 122 | board_info_len = sizeof(board_info_v5); |
| 123 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 124 | smem_status = |
| 125 | smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 126 | &board_info_v5, |
| 127 | board_info_len); |
| 128 | if (!smem_status) { |
Ajay Dudani | 16ea8fb | 2010-11-23 19:15:38 -0800 | [diff] [blame] | 129 | fused_chip = board_info_v5.fused_chip; |
Shashank Mittal | 2249a07 | 2011-02-14 19:24:17 -0800 | [diff] [blame] | 130 | id = board_info_v5.board_info_v3.hw_platform; |
| 131 | } |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 132 | } else if (format == 6) { |
Shashank Mittal | 2249a07 | 2011-02-14 19:24:17 -0800 | [diff] [blame] | 133 | board_info_len = sizeof(board_info_v6); |
| 134 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 135 | smem_status = |
| 136 | smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 137 | &board_info_v6, |
| 138 | board_info_len); |
| 139 | if (!smem_status) { |
Shashank Mittal | 2249a07 | 2011-02-14 19:24:17 -0800 | [diff] [blame] | 140 | fused_chip = board_info_v6.fused_chip; |
| 141 | id = board_info_v6.board_info_v3.hw_platform; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 142 | platform_subtype = |
| 143 | board_info_v6.platform_subtype; |
Ajay Dudani | 16ea8fb | 2010-11-23 19:15:38 -0800 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /* Detect SURF v/s FFA v/s Fluid */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 149 | switch (id) { |
| 150 | case 0x1: |
| 151 | hw_platform = HW_PLATFORM_SURF; |
| 152 | break; |
| 153 | case 0x2: |
| 154 | hw_platform = HW_PLATFORM_FFA; |
| 155 | break; |
| 156 | case 0x3: |
| 157 | hw_platform = HW_PLATFORM_FLUID; |
| 158 | break; |
| 159 | case 0x6: |
| 160 | hw_platform = HW_PLATFORM_QT; |
| 161 | break; |
| 162 | case 0xA: |
| 163 | hw_platform = HW_PLATFORM_DRAGON; |
| 164 | break; |
| 165 | default: |
| 166 | /* Writing to Debug LED register and reading back to auto detect |
| 167 | SURF and FFA. If we read back, it is SURF */ |
| 168 | debug_led_write(0xA5); |
Ajay Dudani | 16ea8fb | 2010-11-23 19:15:38 -0800 | [diff] [blame] | 169 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 170 | if ((debug_led_read() & 0xFF) == 0xA5) { |
| 171 | debug_led_write(0); |
| 172 | hw_platform = HW_PLATFORM_SURF; |
| 173 | } else |
| 174 | hw_platform = HW_PLATFORM_FFA; |
Ajay Dudani | 16ea8fb | 2010-11-23 19:15:38 -0800 | [diff] [blame] | 175 | }; |
| 176 | |
Ajay Dudani | 295f38b | 2011-02-25 15:28:07 -0800 | [diff] [blame] | 177 | /* Use platform_subtype or fused_chip information to determine machine id */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 178 | if (format >= 6) { |
| 179 | switch (platform_subtype) { |
| 180 | case HW_PLATFORM_SUBTYPE_CSFB: |
| 181 | case HW_PLATFORM_SUBTYPE_SVLTE2A: |
| 182 | if (hw_platform == HW_PLATFORM_SURF) |
| 183 | mach_id = LINUX_MACHTYPE_8660_CHARM_SURF; |
| 184 | else if (hw_platform == HW_PLATFORM_FFA) |
| 185 | mach_id = LINUX_MACHTYPE_8660_CHARM_FFA; |
| 186 | break; |
| 187 | default: |
| 188 | if (hw_platform == HW_PLATFORM_SURF) |
| 189 | mach_id = LINUX_MACHTYPE_8660_SURF; |
| 190 | else if (hw_platform == HW_PLATFORM_FFA) |
Ajay Dudani | 16ea8fb | 2010-11-23 19:15:38 -0800 | [diff] [blame] | 191 | mach_id = LINUX_MACHTYPE_8660_FFA; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 192 | else if (hw_platform == HW_PLATFORM_FLUID) |
| 193 | mach_id = LINUX_MACHTYPE_8660_FLUID; |
| 194 | else if (hw_platform == HW_PLATFORM_QT) |
| 195 | mach_id = LINUX_MACHTYPE_8660_QT; |
| 196 | else if (hw_platform == HW_PLATFORM_DRAGON) |
| 197 | mach_id = LINUX_MACHTYPE_8x60_DRAGON; |
| 198 | } |
| 199 | } else if (format == 5) { |
| 200 | switch (fused_chip) { |
| 201 | case UNKNOWN: |
| 202 | if (hw_platform == HW_PLATFORM_SURF) |
| 203 | mach_id = LINUX_MACHTYPE_8660_SURF; |
| 204 | else if (hw_platform == HW_PLATFORM_FFA) |
| 205 | mach_id = LINUX_MACHTYPE_8660_FFA; |
| 206 | else if (hw_platform == HW_PLATFORM_FLUID) |
| 207 | mach_id = LINUX_MACHTYPE_8660_FLUID; |
| 208 | else if (hw_platform == HW_PLATFORM_QT) |
| 209 | mach_id = LINUX_MACHTYPE_8660_QT; |
| 210 | else if (hw_platform == HW_PLATFORM_DRAGON) |
| 211 | mach_id = LINUX_MACHTYPE_8x60_DRAGON; |
| 212 | break; |
| 213 | |
| 214 | case MDM9200: |
| 215 | case MDM9600: |
| 216 | if (hw_platform == HW_PLATFORM_SURF) |
| 217 | mach_id = LINUX_MACHTYPE_8660_CHARM_SURF; |
| 218 | else if (hw_platform == HW_PLATFORM_FFA) |
| 219 | mach_id = LINUX_MACHTYPE_8660_CHARM_FFA; |
| 220 | break; |
| 221 | |
| 222 | default: |
| 223 | mach_id = LINUX_MACHTYPE_8660_FFA; |
Ajay Dudani | 295f38b | 2011-02-25 15:28:07 -0800 | [diff] [blame] | 224 | } |
Ajay Dudani | 16ea8fb | 2010-11-23 19:15:38 -0800 | [diff] [blame] | 225 | } |
Ajay Dudani | 16ea8fb | 2010-11-23 19:15:38 -0800 | [diff] [blame] | 226 | return mach_id; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Shashank Mittal | 6df1607 | 2011-07-14 18:44:01 -0700 | [diff] [blame] | 229 | void shutdown_device() |
| 230 | { |
| 231 | gpio_config_pshold(); |
| 232 | pm8058_reset_pwr_off(0); |
| 233 | pm8901_reset_pwr_off(0); |
| 234 | |
| 235 | writel(0, MSM_PSHOLD_CTL_SU); |
| 236 | mdelay(10000); |
| 237 | dprintf(CRITICAL, "Shutdown failed\n"); |
| 238 | } |
| 239 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 240 | void reboot_device(unsigned reboot_reason) |
| 241 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 242 | /* Reset WDG0 counter */ |
| 243 | writel(1, MSM_WDT0_RST); |
| 244 | /* Disable WDG0 */ |
| 245 | writel(0, MSM_WDT0_EN); |
| 246 | /* Set WDG0 bark time */ |
| 247 | writel(0x31F3, MSM_WDT0_BT); |
| 248 | /* Enable WDG0 */ |
| 249 | writel(3, MSM_WDT0_EN); |
| 250 | dmb(); |
| 251 | /* Enable WDG output */ |
| 252 | secure_writel(3, MSM_TCSR_BASE + TCSR_WDOG_CFG); |
| 253 | mdelay(10000); |
| 254 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 255 | return; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | unsigned check_reboot_mode(void) |
| 259 | { |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 260 | unsigned restart_reason = 0; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 261 | void *restart_reason_addr = (void *)0x2A05F65C; |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 262 | |
| 263 | /* Read reboot reason and scrub it */ |
| 264 | restart_reason = readl(restart_reason_addr); |
| 265 | writel(0x00, restart_reason_addr); |
| 266 | |
| 267 | return restart_reason; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | void target_battery_charging_enable(unsigned enable, unsigned disconnect) |
| 271 | { |
| 272 | } |
Subbaraman Narayanamurthy | f9b6e0d | 2010-09-08 16:51:43 -0700 | [diff] [blame] | 273 | |
| 274 | void setup_fpga() |
| 275 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 276 | writel(0x147, GPIO_CFG133_ADDR); |
| 277 | writel(0x144, GPIO_CFG135_ADDR); |
| 278 | writel(0x144, GPIO_CFG136_ADDR); |
| 279 | writel(0x144, GPIO_CFG137_ADDR); |
| 280 | writel(0x144, GPIO_CFG138_ADDR); |
| 281 | writel(0x144, GPIO_CFG139_ADDR); |
| 282 | writel(0x144, GPIO_CFG140_ADDR); |
| 283 | writel(0x144, GPIO_CFG141_ADDR); |
| 284 | writel(0x144, GPIO_CFG142_ADDR); |
| 285 | writel(0x144, GPIO_CFG143_ADDR); |
| 286 | writel(0x144, GPIO_CFG144_ADDR); |
| 287 | writel(0x144, GPIO_CFG145_ADDR); |
| 288 | writel(0x144, GPIO_CFG146_ADDR); |
| 289 | writel(0x144, GPIO_CFG147_ADDR); |
| 290 | writel(0x144, GPIO_CFG148_ADDR); |
| 291 | writel(0x144, GPIO_CFG149_ADDR); |
| 292 | writel(0x144, GPIO_CFG150_ADDR); |
| 293 | writel(0x147, GPIO_CFG151_ADDR); |
| 294 | writel(0x147, GPIO_CFG152_ADDR); |
| 295 | writel(0x147, GPIO_CFG153_ADDR); |
| 296 | writel(0x3, GPIO_CFG154_ADDR); |
| 297 | writel(0x147, GPIO_CFG155_ADDR); |
| 298 | writel(0x147, GPIO_CFG156_ADDR); |
| 299 | writel(0x147, GPIO_CFG157_ADDR); |
| 300 | writel(0x3, GPIO_CFG158_ADDR); |
Subbaraman Narayanamurthy | f9b6e0d | 2010-09-08 16:51:43 -0700 | [diff] [blame] | 301 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 302 | writel(0x00000B31, EBI2_CHIP_SELECT_CFG0); |
| 303 | writel(0xA3030020, EBI2_XMEM_CS3_CFG1); |
Subbaraman Narayanamurthy | f9b6e0d | 2010-09-08 16:51:43 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | void debug_led_write(char val) |
| 307 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 308 | writeb(val, SURF_DEBUG_LED_ADDR); |
Subbaraman Narayanamurthy | f9b6e0d | 2010-09-08 16:51:43 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | char debug_led_read() |
| 312 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 313 | return readb(SURF_DEBUG_LED_ADDR); |
Subbaraman Narayanamurthy | f9b6e0d | 2010-09-08 16:51:43 -0700 | [diff] [blame] | 314 | } |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 315 | |
| 316 | unsigned target_baseband() |
| 317 | { |
| 318 | struct smem_board_info_v5 board_info_v5; |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 319 | struct smem_board_info_v6 board_info_v6; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 320 | unsigned int board_info_len = 0; |
| 321 | unsigned smem_status = 0; |
| 322 | unsigned format = 0; |
| 323 | unsigned baseband = BASEBAND_MSM; |
| 324 | |
| 325 | smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 326 | &format, sizeof(format), 0); |
| 327 | if (!smem_status) { |
| 328 | if (format == 5) { |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 329 | board_info_len = sizeof(board_info_v5); |
| 330 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 331 | smem_status = |
| 332 | smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 333 | &board_info_v5, |
| 334 | board_info_len); |
| 335 | if (!smem_status) { |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 336 | /* Check for LTE fused targets or APQ. Default to MSM */ |
| 337 | if (board_info_v5.fused_chip == MDM9200) |
| 338 | baseband = BASEBAND_CSFB; |
| 339 | else if (board_info_v5.fused_chip == MDM9600) |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 340 | baseband = BASEBAND_SVLTE2A; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 341 | else if (board_info_v5.board_info_v3.msm_id == |
| 342 | APQ8060) |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 343 | baseband = BASEBAND_APQ; |
| 344 | else |
| 345 | baseband = BASEBAND_MSM; |
| 346 | } |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 347 | } else if (format >= 6) { |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 348 | board_info_len = sizeof(board_info_v6); |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 349 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 350 | smem_status = |
| 351 | smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 352 | &board_info_v6, |
| 353 | board_info_len); |
| 354 | if (!smem_status) { |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 355 | /* Check for LTE fused targets or APQ. Default to MSM */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 356 | if (board_info_v6.platform_subtype == |
| 357 | HW_PLATFORM_SUBTYPE_CSFB) |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 358 | baseband = BASEBAND_CSFB; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 359 | else if (board_info_v6.platform_subtype == |
| 360 | HW_PLATFORM_SUBTYPE_SVLTE2A) |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 361 | baseband = BASEBAND_SVLTE2A; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 362 | else if (board_info_v6.board_info_v3.msm_id == |
| 363 | APQ8060) |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 364 | baseband = BASEBAND_APQ; |
| 365 | else |
| 366 | baseband = BASEBAND_MSM; |
| 367 | } |
| 368 | } |
| 369 | } |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 370 | return baseband; |
| 371 | } |
Ajay Dudani | 5960643 | 2011-01-24 18:23:38 -0800 | [diff] [blame] | 372 | |
Deepa Dinamani | 5e5c21a | 2012-02-16 18:59:57 -0800 | [diff] [blame] | 373 | crypto_engine_type board_ce_type(void) |
| 374 | { |
| 375 | |
| 376 | struct smem_board_info_v5 board_info_v5; |
| 377 | struct smem_board_info_v6 board_info_v6; |
| 378 | unsigned int board_info_len = 0; |
| 379 | unsigned smem_status = 0; |
| 380 | unsigned format = 0; |
| 381 | |
| 382 | smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION, |
| 383 | &format, sizeof(format), 0); |
| 384 | if (!smem_status) { |
| 385 | if (format == 5) { |
| 386 | board_info_len = sizeof(board_info_v5); |
| 387 | |
| 388 | smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 389 | &board_info_v5, |
| 390 | board_info_len); |
| 391 | if (!smem_status) { |
| 392 | if ((board_info_v5.board_info_v3.msm_id == APQ8060) || |
| 393 | (board_info_v5.board_info_v3.msm_id == MSM8660) || |
| 394 | (board_info_v5.board_info_v3.msm_id == MSM8260)) |
| 395 | platform_ce_type = CRYPTO_ENGINE_TYPE_HW; |
| 396 | } |
| 397 | } else if (format >= 6) { |
| 398 | board_info_len = sizeof(board_info_v6); |
| 399 | |
| 400 | smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 401 | &board_info_v6, |
| 402 | board_info_len); |
| 403 | if(!smem_status) { |
| 404 | if ((board_info_v6.board_info_v3.msm_id == APQ8060) || |
| 405 | (board_info_v6.board_info_v3.msm_id == MSM8660) || |
| 406 | (board_info_v6.board_info_v3.msm_id == MSM8260)) |
| 407 | platform_ce_type = CRYPTO_ENGINE_TYPE_HW; |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | return platform_ce_type; |
| 413 | } |
| 414 | |
Ajay Dudani | 5960643 | 2011-01-24 18:23:38 -0800 | [diff] [blame] | 415 | static unsigned target_check_power_on_reason(void) |
| 416 | { |
| 417 | unsigned power_on_status = 0; |
| 418 | unsigned int status_len = sizeof(power_on_status); |
| 419 | unsigned smem_status; |
| 420 | |
| 421 | smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 422 | &power_on_status, status_len); |
Ajay Dudani | 5960643 | 2011-01-24 18:23:38 -0800 | [diff] [blame] | 423 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 424 | if (smem_status) { |
| 425 | dprintf(CRITICAL, |
| 426 | "ERROR: unable to read shared memory for power on reason\n"); |
Ajay Dudani | 5960643 | 2011-01-24 18:23:38 -0800 | [diff] [blame] | 427 | } |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 428 | dprintf(INFO, "Power on reason %u\n", power_on_status); |
Ajay Dudani | 5960643 | 2011-01-24 18:23:38 -0800 | [diff] [blame] | 429 | return power_on_status; |
| 430 | } |
| 431 | |
Shashank Mittal | 6df1607 | 2011-07-14 18:44:01 -0700 | [diff] [blame] | 432 | static void target_shutdown_for_rtc_alarm(void) |
| 433 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 434 | if (target_check_power_on_reason() == PWR_ON_EVENT_RTC_ALARM) { |
| 435 | dprintf(CRITICAL, |
| 436 | "Power on due to RTC alarm. Going to shutdown!!\n"); |
Shashank Mittal | 6df1607 | 2011-07-14 18:44:01 -0700 | [diff] [blame] | 437 | pm8058_rtc0_alarm_irq_disable(); |
| 438 | shutdown_device(); |
| 439 | } |
| 440 | } |
| 441 | |
Ajay Dudani | 5960643 | 2011-01-24 18:23:38 -0800 | [diff] [blame] | 442 | unsigned target_pause_for_battery_charge(void) |
| 443 | { |
Ajay Dudani | ba82233 | 2011-11-25 13:37:31 -0800 | [diff] [blame] | 444 | if (target_check_power_on_reason() == PWR_ON_EVENT_WALL_CHG) |
Ajay Dudani | 5960643 | 2011-01-24 18:23:38 -0800 | [diff] [blame] | 445 | return 1; |
| 446 | |
| 447 | return 0; |
| 448 | } |
Subbaraman Narayanamurthy | b0111a1 | 2011-02-03 14:24:16 -0800 | [diff] [blame] | 449 | |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 450 | void target_serialno(unsigned char *buf) |
| 451 | { |
| 452 | unsigned int serialno; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 453 | if (target_is_emmc_boot()) { |
| 454 | serialno = mmc_get_psn(); |
| 455 | snprintf((char *)buf, 13, "%x", serialno); |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 456 | } |
| 457 | } |
| 458 | |
Subbaraman Narayanamurthy | b0111a1 | 2011-02-03 14:24:16 -0800 | [diff] [blame] | 459 | void hsusb_gpio_init(void) |
| 460 | { |
| 461 | uint32_t func; |
| 462 | uint32_t pull; |
| 463 | uint32_t dir; |
| 464 | uint32_t enable; |
| 465 | uint32_t drv; |
| 466 | |
| 467 | /* GPIO 131 and 132 need to be configured for connecting to USB HS PHY */ |
| 468 | |
| 469 | func = 0; |
| 470 | enable = 1; |
| 471 | pull = GPIO_NO_PULL; |
| 472 | dir = 2; |
| 473 | drv = GPIO_2MA; |
| 474 | gpio_tlmm_config(131, func, dir, pull, drv, enable); |
| 475 | gpio_set(131, dir); |
| 476 | |
| 477 | func = 0; |
| 478 | enable = 1; |
| 479 | pull = GPIO_NO_PULL; |
| 480 | dir = 1; |
| 481 | drv = GPIO_2MA; |
| 482 | gpio_tlmm_config(132, func, dir, pull, drv, enable); |
| 483 | gpio_set(132, dir); |
| 484 | |
| 485 | return; |
| 486 | } |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 487 | |
Amol Jadi | da118b9 | 2012-07-06 19:53:18 -0700 | [diff] [blame] | 488 | #define USB_CLK 0x00902910 |
| 489 | #define USB_PHY_CLK 0x00902E20 |
| 490 | #define CLK_RESET_ASSERT 0x1 |
| 491 | #define CLK_RESET_DEASSERT 0x0 |
| 492 | #define CLK_RESET(x,y) writel((y), (x)); |
| 493 | |
| 494 | static int msm_otg_xceiv_reset() |
| 495 | { |
| 496 | CLK_RESET(USB_CLK, CLK_RESET_ASSERT); |
| 497 | CLK_RESET(USB_PHY_CLK, CLK_RESET_ASSERT); |
| 498 | mdelay(20); |
| 499 | CLK_RESET(USB_PHY_CLK, CLK_RESET_DEASSERT); |
| 500 | CLK_RESET(USB_CLK, CLK_RESET_DEASSERT); |
| 501 | mdelay(20); |
| 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | static void target_ulpi_init(void) |
| 507 | { |
| 508 | unsigned int reg; |
| 509 | |
| 510 | reg = ulpi_read(0x32); |
| 511 | dprintf(INFO, " Value of ulpi read 0x32 is %08x\n", reg); |
| 512 | ulpi_write(0x30, 0x32); |
| 513 | reg = ulpi_read(0x32); |
| 514 | dprintf(INFO, " Value of ulpi read 0x32 after write is %08x\n", reg); |
| 515 | |
| 516 | reg = ulpi_read(0x36); |
| 517 | dprintf(INFO, " Value of ulpi read 0x36 is %08x\n", reg); |
| 518 | ulpi_write(reg | 0x2, 0x36); |
| 519 | reg = ulpi_read(0x36); |
| 520 | dprintf(INFO, " Value of ulpi read 0x36 aafter write is %08x\n", reg); |
| 521 | } |
| 522 | |
| 523 | /* Do target specific usb initialization */ |
| 524 | void target_usb_init(void) |
| 525 | { |
| 526 | hsusb_gpio_init(); |
| 527 | |
| 528 | msm_otg_xceiv_reset(); |
| 529 | |
| 530 | target_ulpi_init(); |
| 531 | } |
| 532 | |
| 533 | void target_usb_stop(void) |
| 534 | { |
| 535 | int val; |
| 536 | /* Voting down PLL8 */ |
| 537 | val = readl(0x009034C0); |
| 538 | val &= ~(1 << 8); |
| 539 | writel(val, 0x009034C0); |
| 540 | } |
| 541 | |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 542 | uint8_t target_uart_gsbi(void) |
| 543 | { |
| 544 | return uart_gsbi_id; |
| 545 | } |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 546 | |
| 547 | int emmc_recovery_init(void) |
| 548 | { |
| 549 | int rc; |
| 550 | rc = _emmc_recovery_init(); |
| 551 | return rc; |
| 552 | } |