Eugene Yasman | 6382ee0 | 2013-01-16 13:00:56 +0200 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame] | 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 15 | * |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame] | 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <platform/iomap.h> |
| 31 | #include <reg.h> |
| 32 | #include <target.h> |
| 33 | #include <platform.h> |
Deepa Dinamani | 26e9326 | 2012-05-21 17:35:14 -0700 | [diff] [blame] | 34 | #include <uart_dm.h> |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 35 | #include <mmc.h> |
Deepa Dinamani | c2a9b36 | 2012-02-23 15:15:54 -0800 | [diff] [blame] | 36 | #include <spmi.h> |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 37 | #include <board.h> |
| 38 | #include <smem.h> |
| 39 | #include <baseband.h> |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 40 | #include <dev/keys.h> |
| 41 | #include <pm8x41.h> |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 42 | #include <crypto5_wrapper.h> |
| 43 | |
| 44 | extern bool target_use_signed_kernel(void); |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 45 | |
| 46 | static unsigned int target_id; |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 47 | |
Deepa Dinamani | c2a9b36 | 2012-02-23 15:15:54 -0800 | [diff] [blame] | 48 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 49 | #define PMIC_ARB_OWNER_ID 0 |
| 50 | |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame] | 51 | #define WDOG_DEBUG_DISABLE_BIT 17 |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 52 | |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 53 | #define CE_INSTANCE 2 |
| 54 | #define CE_EE 1 |
| 55 | #define CE_FIFO_SIZE 64 |
| 56 | #define CE_READ_PIPE 3 |
| 57 | #define CE_WRITE_PIPE 2 |
| 58 | #define CE_ARRAY_SIZE 20 |
| 59 | |
Deepa Dinamani | ca5ad85 | 2012-05-07 18:19:47 -0700 | [diff] [blame] | 60 | static uint32_t mmc_sdc_base[] = |
| 61 | { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE }; |
| 62 | |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 63 | void target_early_init(void) |
| 64 | { |
Deepa Dinamani | b073ba2 | 2012-08-10 11:06:41 -0700 | [diff] [blame] | 65 | #if WITH_DEBUG_UART |
Neeti Desai | ac01127 | 2012-08-29 18:24:54 -0700 | [diff] [blame] | 66 | uart_dm_init(1, 0, BLSP1_UART1_BASE); |
Deepa Dinamani | b073ba2 | 2012-08-10 11:06:41 -0700 | [diff] [blame] | 67 | #endif |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 70 | /* Return 1 if vol_up pressed */ |
| 71 | static int target_volume_up() |
| 72 | { |
| 73 | uint8_t status = 0; |
| 74 | struct pm8x41_gpio gpio; |
| 75 | |
| 76 | /* CDP vol_up seems to be always grounded. So gpio status is read as 0, |
| 77 | * whether key is pressed or not. |
| 78 | * Ignore volume_up key on CDP for now. |
| 79 | */ |
| 80 | if (board_hardware_id() == HW_PLATFORM_SURF) |
| 81 | return 0; |
| 82 | |
| 83 | /* Configure the GPIO */ |
| 84 | gpio.direction = PM_GPIO_DIR_IN; |
| 85 | gpio.function = 0; |
| 86 | gpio.pull = PM_GPIO_PULL_UP_30; |
Eugene Yasman | 6382ee0 | 2013-01-16 13:00:56 +0200 | [diff] [blame] | 87 | gpio.vin_sel = 2; |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 88 | |
| 89 | pm8x41_gpio_config(5, &gpio); |
| 90 | |
| 91 | /* Get status of P_GPIO_5 */ |
| 92 | pm8x41_gpio_get(5, &status); |
| 93 | |
| 94 | return !status; /* active low */ |
| 95 | } |
| 96 | |
| 97 | /* Return 1 if vol_down pressed */ |
Deepa Dinamani | 66a8796 | 2013-02-04 10:39:30 -0800 | [diff] [blame] | 98 | uint32_t target_volume_down() |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 99 | { |
Deepa Dinamani | 66a8796 | 2013-02-04 10:39:30 -0800 | [diff] [blame] | 100 | /* Volume down button is tied in with RESIN on MSM8974. */ |
Deepa Dinamani | 13bfc85 | 2013-02-05 17:56:47 -0800 | [diff] [blame] | 101 | if (pm8x41_get_pmic_rev() == PMIC_VERSION_V2) |
| 102 | return pm8x41_resin_bark_workaround_status(); |
| 103 | else |
| 104 | return pm8x41_resin_status(); |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static void target_keystatus() |
| 108 | { |
| 109 | keys_init(); |
| 110 | |
| 111 | if(target_volume_down()) |
| 112 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 113 | |
| 114 | if(target_volume_up()) |
| 115 | keys_post_event(KEY_VOLUMEUP, 1); |
| 116 | } |
| 117 | |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 118 | /* Set up params for h/w CE. */ |
| 119 | void target_crypto_init_params() |
| 120 | { |
| 121 | struct crypto_init_params ce_params; |
| 122 | |
| 123 | /* Set up base addresses and instance. */ |
| 124 | ce_params.crypto_instance = CE_INSTANCE; |
| 125 | ce_params.crypto_base = MSM_CE2_BASE; |
| 126 | ce_params.bam_base = MSM_CE2_BAM_BASE; |
| 127 | |
| 128 | /* Set up BAM config. */ |
| 129 | ce_params.bam_ee = CE_EE; |
| 130 | ce_params.pipes.read_pipe = CE_READ_PIPE; |
| 131 | ce_params.pipes.write_pipe = CE_WRITE_PIPE; |
| 132 | |
| 133 | /* Assign buffer sizes. */ |
| 134 | ce_params.num_ce = CE_ARRAY_SIZE; |
| 135 | ce_params.read_fifo_size = CE_FIFO_SIZE; |
| 136 | ce_params.write_fifo_size = CE_FIFO_SIZE; |
| 137 | |
| 138 | crypto_init_params(&ce_params); |
| 139 | } |
| 140 | |
| 141 | crypto_engine_type board_ce_type(void) |
| 142 | { |
| 143 | return CRYPTO_ENGINE_TYPE_HW; |
| 144 | } |
| 145 | |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 146 | void target_init(void) |
| 147 | { |
Deepa Dinamani | ca5ad85 | 2012-05-07 18:19:47 -0700 | [diff] [blame] | 148 | uint32_t base_addr; |
| 149 | uint8_t slot; |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 150 | |
| 151 | dprintf(INFO, "target_init()\n"); |
| 152 | |
Deepa Dinamani | c2a9b36 | 2012-02-23 15:15:54 -0800 | [diff] [blame] | 153 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 154 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 155 | target_keystatus(); |
| 156 | |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 157 | if (target_use_signed_kernel()) |
| 158 | target_crypto_init_params(); |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 159 | /* Display splash screen if enabled */ |
| 160 | #if DISPLAY_SPLASH_SCREEN |
Channagoud Kadabi | 8a9c6a2 | 2013-02-05 14:43:48 -0800 | [diff] [blame] | 161 | dprintf(INFO, "Display Init: Start\n"); |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 162 | display_init(); |
Channagoud Kadabi | 8a9c6a2 | 2013-02-05 14:43:48 -0800 | [diff] [blame] | 163 | dprintf(INFO, "Display Init: Done\n"); |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 164 | #endif |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 165 | |
Deepa Dinamani | ca5ad85 | 2012-05-07 18:19:47 -0700 | [diff] [blame] | 166 | /* Trying Slot 1*/ |
| 167 | slot = 1; |
| 168 | base_addr = mmc_sdc_base[slot - 1]; |
| 169 | if (mmc_boot_main(slot, base_addr)) |
| 170 | { |
Deepa Dinamani | d18b47a | 2012-06-27 13:06:03 -0700 | [diff] [blame] | 171 | |
| 172 | /* Trying Slot 2 next */ |
| 173 | slot = 2; |
| 174 | base_addr = mmc_sdc_base[slot - 1]; |
| 175 | if (mmc_boot_main(slot, base_addr)) { |
| 176 | dprintf(CRITICAL, "mmc init failed!"); |
| 177 | ASSERT(0); |
| 178 | } |
Deepa Dinamani | ca5ad85 | 2012-05-07 18:19:47 -0700 | [diff] [blame] | 179 | } |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | unsigned board_machtype(void) |
| 183 | { |
| 184 | return target_id; |
| 185 | } |
| 186 | |
| 187 | /* Do any target specific intialization needed before entering fastboot mode */ |
| 188 | void target_fastboot_init(void) |
| 189 | { |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 190 | /* Set the BOOT_DONE flag in PM8921 */ |
| 191 | pm8x41_set_boot_done(); |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 192 | } |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 193 | |
| 194 | /* Detect the target type */ |
| 195 | void target_detect(struct board_data *board) |
| 196 | { |
| 197 | board->target = LINUX_MACHTYPE_UNKNOWN; |
| 198 | } |
| 199 | |
| 200 | /* Detect the modem type */ |
| 201 | void target_baseband_detect(struct board_data *board) |
| 202 | { |
| 203 | /* Check for baseband variants. Default to MSM */ |
| 204 | if (board->platform_subtype == HW_PLATFORM_SUBTYPE_MDM) |
| 205 | board->baseband = BASEBAND_MDM; |
| 206 | else |
| 207 | board->baseband = BASEBAND_MSM; |
| 208 | } |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 209 | |
| 210 | void target_serialno(unsigned char *buf) |
| 211 | { |
| 212 | unsigned int serialno; |
| 213 | if (target_is_emmc_boot()) { |
| 214 | serialno = mmc_get_psn(); |
| 215 | snprintf((char *)buf, 13, "%x", serialno); |
| 216 | } |
| 217 | } |
Amol Jadi | 6639d45 | 2012-08-16 14:51:19 -0700 | [diff] [blame] | 218 | |
| 219 | unsigned check_reboot_mode(void) |
| 220 | { |
| 221 | uint32_t restart_reason = 0; |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 222 | uint32_t soc_ver = 0; |
| 223 | uint32_t restart_reason_addr; |
| 224 | |
| 225 | soc_ver = board_soc_version(); |
| 226 | |
| 227 | if (soc_ver >= BOARD_SOC_VERSION2) |
| 228 | restart_reason_addr = RESTART_REASON_ADDR_V2; |
| 229 | else |
| 230 | restart_reason_addr = RESTART_REASON_ADDR; |
Amol Jadi | 6639d45 | 2012-08-16 14:51:19 -0700 | [diff] [blame] | 231 | |
| 232 | /* Read reboot reason and scrub it */ |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 233 | restart_reason = readl(restart_reason_addr); |
| 234 | writel(0x00, restart_reason_addr); |
Amol Jadi | 6639d45 | 2012-08-16 14:51:19 -0700 | [diff] [blame] | 235 | |
| 236 | return restart_reason; |
| 237 | } |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 238 | |
| 239 | void reboot_device(unsigned reboot_reason) |
| 240 | { |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 241 | uint32_t soc_ver = 0; |
| 242 | |
| 243 | soc_ver = board_soc_version(); |
| 244 | |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 245 | /* Write the reboot reason */ |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 246 | if (soc_ver >= BOARD_SOC_VERSION2) |
| 247 | writel(reboot_reason, RESTART_REASON_ADDR_V2); |
| 248 | else |
| 249 | writel(reboot_reason, RESTART_REASON_ADDR); |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 250 | |
| 251 | /* Configure PMIC for warm reset */ |
| 252 | pm8x41_reset_configure(PON_PSHOLD_WARM_RESET); |
| 253 | |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame] | 254 | /* Disable Watchdog Debug. |
| 255 | * Required becuase of a H/W bug which causes the system to |
| 256 | * reset partially even for non watchdog resets. |
| 257 | */ |
| 258 | writel(readl(GCC_WDOG_DEBUG) & ~(1 << WDOG_DEBUG_DISABLE_BIT), GCC_WDOG_DEBUG); |
| 259 | |
Deepa Dinamani | e0808e5 | 2012-11-26 15:22:46 -0800 | [diff] [blame] | 260 | dsb(); |
| 261 | |
| 262 | /* Wait until the write takes effect. */ |
| 263 | while(readl(GCC_WDOG_DEBUG) & (1 << WDOG_DEBUG_DISABLE_BIT)); |
| 264 | |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 265 | /* Drop PS_HOLD for MSM */ |
| 266 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 267 | |
| 268 | mdelay(5000); |
| 269 | |
| 270 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 271 | } |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 272 | |
| 273 | /* Returns 1 if target supports continuous splash screen. */ |
| 274 | int target_cont_splash_screen() |
| 275 | { |
| 276 | switch(board_platform_id()) |
| 277 | { |
| 278 | case HW_PLATFORM_SURF: |
| 279 | case HW_PLATFORM_FFA: |
| 280 | default: |
| 281 | return 0; |
| 282 | } |
| 283 | } |
sundarajan srinivasan | b5db0a9 | 2013-02-12 19:19:27 -0800 | [diff] [blame] | 284 | |
| 285 | unsigned target_pause_for_battery_charge(void) |
| 286 | { |
| 287 | uint8_t pon_reason = pm8x41_get_pon_reason(); |
| 288 | |
| 289 | /* This function will always return 0 to facilitate |
| 290 | * automated testing/reboot with usb connected. |
| 291 | * uncomment if this feature is needed */ |
| 292 | /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG)) |
| 293 | return 1;*/ |
| 294 | |
| 295 | return 0; |
| 296 | } |