Sundarajan Srinivasan | 86106c3 | 2013-12-19 11:36:07 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 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. |
| 15 | * |
| 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. |
| 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <platform/iomap.h> |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame] | 31 | #include <platform/irqs.h> |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 32 | #include <platform/gpio.h> |
| 33 | #include <reg.h> |
| 34 | #include <target.h> |
| 35 | #include <platform.h> |
| 36 | #include <dload_util.h> |
| 37 | #include <uart_dm.h> |
| 38 | #include <mmc.h> |
| 39 | #include <spmi.h> |
| 40 | #include <board.h> |
| 41 | #include <smem.h> |
| 42 | #include <baseband.h> |
| 43 | #include <dev/keys.h> |
| 44 | #include <pm8x41.h> |
| 45 | #include <crypto5_wrapper.h> |
| 46 | #include <hsusb.h> |
| 47 | #include <clock.h> |
| 48 | #include <partition_parser.h> |
| 49 | #include <scm.h> |
| 50 | #include <platform/clock.h> |
| 51 | #include <platform/gpio.h> |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame] | 52 | #include <platform/timer.h> |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 53 | #include <stdlib.h> |
Channagoud Kadabi | 415a702 | 2013-09-11 10:48:40 -0700 | [diff] [blame] | 54 | #include <ufs.h> |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 55 | |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 56 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 57 | #define PMIC_ARB_OWNER_ID 0 |
| 58 | |
| 59 | #define FASTBOOT_MODE 0x77665500 |
| 60 | |
Sundarajan Srinivasan | 4161b7e | 2013-09-10 13:55:31 -0700 | [diff] [blame] | 61 | #define BOOT_DEVICE_MASK(val) ((val & 0x3E) >>1) |
| 62 | |
Sundarajan Srinivasan | 4431e16 | 2013-12-10 13:16:04 -0800 | [diff] [blame] | 63 | #define SSD_CE_INSTANCE 1 |
| 64 | |
Sundarajan Srinivasan | 86106c3 | 2013-12-19 11:36:07 -0800 | [diff] [blame] | 65 | #define CE2_INSTANCE 2 |
| 66 | #define CE_EE 1 |
| 67 | #define CE_FIFO_SIZE 64 |
| 68 | #define CE_READ_PIPE 3 |
| 69 | #define CE_WRITE_PIPE 2 |
| 70 | #define CE_READ_PIPE_LOCK_GRP 0 |
| 71 | #define CE_WRITE_PIPE_LOCK_GRP 0 |
| 72 | #define CE_ARRAY_SIZE 20 |
| 73 | |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 74 | enum cdp_subtype |
| 75 | { |
| 76 | CDP_SUBTYPE_SMB349 = 0, |
| 77 | CDP_SUBTYPE_9x25_SMB349, |
| 78 | CDP_SUBTYPE_9x25_SMB1357, |
| 79 | CDP_SUBTYPE_9x35, |
Sundarajan Srinivasan | 01e68f1 | 2013-11-01 12:21:52 -0700 | [diff] [blame] | 80 | CDP_SUBTYPE_SMB1357, |
Sundarajan Srinivasan | 0e94a1c | 2013-12-17 10:55:51 -0800 | [diff] [blame] | 81 | CDP_SUBTYPE_SMB350, |
| 82 | CDP_SUBTYPE_9x35_M |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 83 | }; |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame] | 84 | |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 85 | enum mtp_subtype |
| 86 | { |
| 87 | MTP_SUBTYPE_SMB349 = 0, |
| 88 | MTP_SUBTYPE_9x25_SMB349, |
| 89 | MTP_SUBTYPE_9x25_SMB1357, |
| 90 | MTP_SUBTYPE_9x35, |
Sundarajan Srinivasan | 0e94a1c | 2013-12-17 10:55:51 -0800 | [diff] [blame] | 91 | MTP_SUBTYPE_9x35_M |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | enum rcm_subtype |
| 95 | { |
| 96 | RCM_SUBTYPE_SMB349 = 0, |
| 97 | RCM_SUBTYPE_9x25_SMB349, |
| 98 | RCM_SUBTYPE_9x25_SMB1357, |
| 99 | RCM_SUBTYPE_9x35, |
| 100 | RCM_SUBTYPE_SMB1357, |
Sundarajan Srinivasan | 0e94a1c | 2013-12-17 10:55:51 -0800 | [diff] [blame] | 101 | RCM_SUBTYPE_SMB350, |
| 102 | RCM_SUBTYPE_9x35_M |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
Sundarajan Srinivasan | 6ade93e | 2013-11-18 11:07:22 -0800 | [diff] [blame] | 105 | enum liquid_subtype |
| 106 | { |
| 107 | LIQUID_SUBTYPE_STANDALONE = 0, |
| 108 | LIQUID_SUBTYPE_9x25, |
| 109 | }; |
| 110 | |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 111 | static void set_sdc_power_ctrl(void); |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame] | 112 | static uint32_t mmc_pwrctl_base[] = |
| 113 | { MSM_SDC1_BASE, MSM_SDC2_BASE }; |
| 114 | |
| 115 | static uint32_t mmc_sdhci_base[] = |
| 116 | { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE }; |
| 117 | |
| 118 | static uint32_t mmc_sdc_pwrctl_irq[] = |
| 119 | { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ }; |
| 120 | |
| 121 | struct mmc_device *dev; |
Channagoud Kadabi | 415a702 | 2013-09-11 10:48:40 -0700 | [diff] [blame] | 122 | struct ufs_dev ufs_device; |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 123 | |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 124 | extern void ulpi_write(unsigned val, unsigned reg); |
Pavel Nedev | a6c0beb | 2013-11-15 17:20:27 +0200 | [diff] [blame] | 125 | extern int _emmc_recovery_init(void); |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 126 | |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 127 | void target_early_init(void) |
| 128 | { |
| 129 | #if WITH_DEBUG_UART |
Sundarajan Srinivasan | d8b7c6f | 2013-09-13 16:50:22 -0700 | [diff] [blame] | 130 | uart_dm_init(7, 0, BLSP2_UART1_BASE); |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 131 | #endif |
| 132 | } |
| 133 | |
| 134 | /* Return 1 if vol_up pressed */ |
| 135 | static int target_volume_up() |
| 136 | { |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 137 | uint8_t status = 0; |
| 138 | struct pm8x41_gpio gpio; |
| 139 | |
| 140 | /* Configure the GPIO */ |
| 141 | gpio.direction = PM_GPIO_DIR_IN; |
| 142 | gpio.function = 0; |
| 143 | gpio.pull = PM_GPIO_PULL_UP_30; |
| 144 | gpio.vin_sel = 2; |
| 145 | |
| 146 | pm8x41_gpio_config(2, &gpio); |
| 147 | |
Channagoud Kadabi | efcb8ec | 2014-01-02 16:22:38 -0800 | [diff] [blame] | 148 | /* Wait for the pmic gpio config to take effect */ |
| 149 | thread_sleep(1); |
| 150 | |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 151 | /* Get status of P_GPIO_2 */ |
| 152 | pm8x41_gpio_get(2, &status); |
| 153 | |
| 154 | return !status; /* active low */ |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /* Return 1 if vol_down pressed */ |
| 158 | uint32_t target_volume_down() |
| 159 | { |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 160 | return pm8x41_resin_status(); |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | static void target_keystatus() |
| 164 | { |
| 165 | keys_init(); |
| 166 | |
| 167 | if(target_volume_down()) |
| 168 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 169 | |
| 170 | if(target_volume_up()) |
| 171 | keys_post_event(KEY_VOLUMEUP, 1); |
| 172 | } |
| 173 | |
David Ng | 4c2e86d | 2013-09-15 22:03:37 -0700 | [diff] [blame] | 174 | void target_uninit(void) |
| 175 | { |
Sundarajan Srinivasan | 29cb66e | 2013-10-30 18:48:27 -0700 | [diff] [blame] | 176 | if(target_boot_device_emmc()) |
Channagoud Kadabi | 154764f | 2014-01-24 17:45:19 -0800 | [diff] [blame] | 177 | { |
Sundarajan Srinivasan | 29cb66e | 2013-10-30 18:48:27 -0700 | [diff] [blame] | 178 | mmc_put_card_to_sleep(dev); |
Channagoud Kadabi | 154764f | 2014-01-24 17:45:19 -0800 | [diff] [blame] | 179 | sdhci_mode_disable(&dev->host); |
| 180 | } |
Aravind Venkateswaran | dd50c1a | 2014-02-25 14:42:43 -0800 | [diff] [blame^] | 181 | |
| 182 | target_display_shutdown(); |
David Ng | 4c2e86d | 2013-09-15 22:03:37 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 185 | /* Do target specific usb initialization */ |
| 186 | void target_usb_init(void) |
| 187 | { |
| 188 | uint32_t val; |
| 189 | |
| 190 | /* Select and enable external configuration with USB PHY */ |
| 191 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET); |
| 192 | |
| 193 | /* Enable sess_vld */ |
| 194 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 195 | writel(val, USB_GENCONFIG_2); |
| 196 | |
| 197 | /* Enable external vbus configuration in the LINK */ |
| 198 | val = readl(USB_USBCMD); |
| 199 | val |= SESS_VLD_CTRL; |
| 200 | writel(val, USB_USBCMD); |
| 201 | } |
| 202 | |
| 203 | void target_usb_stop(void) |
| 204 | { |
| 205 | /* Disable VBUS mimicing in the controller. */ |
| 206 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR); |
| 207 | } |
| 208 | |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 209 | static void set_sdc_power_ctrl() |
| 210 | { |
| 211 | /* Drive strength configs for sdc pins */ |
| 212 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 213 | { |
| 214 | { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK }, |
| 215 | { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK }, |
| 216 | { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK }, |
| 217 | }; |
| 218 | |
| 219 | /* Pull configs for sdc pins */ |
| 220 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 221 | { |
| 222 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK }, |
| 223 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
| 224 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
Channagoud Kadabi | c14b404 | 2013-09-23 11:20:32 -0700 | [diff] [blame] | 225 | { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK }, |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 226 | }; |
| 227 | |
| 228 | /* Set the drive strength & pull control values */ |
| 229 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 230 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
| 231 | } |
| 232 | |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame] | 233 | void target_sdc_init() |
| 234 | { |
| 235 | struct mmc_config_data config; |
| 236 | |
| 237 | /* Set drive strength & pull ctrl values */ |
| 238 | set_sdc_power_ctrl(); |
| 239 | |
| 240 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame] | 241 | |
| 242 | /* Try slot 1*/ |
| 243 | config.slot = 1; |
Channagoud Kadabi | de9b2d3 | 2013-11-08 13:24:47 -0800 | [diff] [blame] | 244 | config.max_clk_rate = MMC_CLK_192MHZ; |
| 245 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 246 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 247 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame] | 248 | |
| 249 | if (!(dev = mmc_init(&config))) |
| 250 | { |
| 251 | /* Try slot 2 */ |
| 252 | config.slot = 2; |
Channagoud Kadabi | de9b2d3 | 2013-11-08 13:24:47 -0800 | [diff] [blame] | 253 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 254 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 255 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 256 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame] | 257 | |
| 258 | if (!(dev = mmc_init(&config))) |
| 259 | { |
| 260 | dprintf(CRITICAL, "mmc init failed!"); |
| 261 | ASSERT(0); |
| 262 | } |
| 263 | } |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Sundarajan Srinivasan | 4161b7e | 2013-09-10 13:55:31 -0700 | [diff] [blame] | 266 | static uint32_t boot_device; |
| 267 | static uint32_t target_read_boot_config() |
| 268 | { |
| 269 | uint32_t val; |
| 270 | |
| 271 | val = readl(BOOT_CONFIG_REG); |
| 272 | |
| 273 | val = BOOT_DEVICE_MASK(val); |
| 274 | |
| 275 | return val; |
| 276 | } |
| 277 | |
| 278 | uint32_t target_get_boot_device() |
| 279 | { |
| 280 | return boot_device; |
| 281 | } |
| 282 | |
Channagoud Kadabi | 415a702 | 2013-09-11 10:48:40 -0700 | [diff] [blame] | 283 | /* |
| 284 | * Return 1 if boot from emmc else 0 |
| 285 | */ |
| 286 | uint32_t target_boot_device_emmc() |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame] | 287 | { |
Channagoud Kadabi | 415a702 | 2013-09-11 10:48:40 -0700 | [diff] [blame] | 288 | uint32_t boot_dev_type; |
| 289 | |
Sundarajan Srinivasan | 4161b7e | 2013-09-10 13:55:31 -0700 | [diff] [blame] | 290 | boot_dev_type = target_get_boot_device(); |
Channagoud Kadabi | 415a702 | 2013-09-11 10:48:40 -0700 | [diff] [blame] | 291 | |
| 292 | if (boot_dev_type == BOOT_EMMC || boot_dev_type == BOOT_DEFAULT) |
| 293 | boot_dev_type = 1; |
| 294 | else |
| 295 | boot_dev_type = 0; |
| 296 | |
| 297 | return boot_dev_type; |
| 298 | } |
| 299 | |
| 300 | void *target_mmc_device() |
| 301 | { |
| 302 | if (target_boot_device_emmc()) |
| 303 | return (void *) dev; |
| 304 | else |
| 305 | return (void *) &ufs_device; |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 308 | void target_init(void) |
| 309 | { |
| 310 | dprintf(INFO, "target_init()\n"); |
| 311 | |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 312 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 313 | |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 314 | target_keystatus(); |
| 315 | |
Sundarajan Srinivasan | 86106c3 | 2013-12-19 11:36:07 -0800 | [diff] [blame] | 316 | if (target_use_signed_kernel()) |
| 317 | target_crypto_init_params(); |
| 318 | |
Sundarajan Srinivasan | 4161b7e | 2013-09-10 13:55:31 -0700 | [diff] [blame] | 319 | boot_device = target_read_boot_config(); |
| 320 | |
Channagoud Kadabi | 415a702 | 2013-09-11 10:48:40 -0700 | [diff] [blame] | 321 | if (target_boot_device_emmc()) |
| 322 | target_sdc_init(); |
| 323 | else |
| 324 | { |
| 325 | ufs_device.base = UFS_BASE; |
| 326 | ufs_init(&ufs_device); |
| 327 | } |
| 328 | |
| 329 | /* Storage initialization is complete, read the partition table info */ |
| 330 | if (partition_read_table()) |
| 331 | { |
| 332 | dprintf(CRITICAL, "Error reading the partition table info\n"); |
| 333 | ASSERT(0); |
| 334 | } |
| 335 | |
Dhaval Patel | f998627 | 2013-10-18 19:06:05 -0700 | [diff] [blame] | 336 | /* Display splash screen if enabled */ |
| 337 | #if DISPLAY_SPLASH_SCREEN |
| 338 | dprintf(INFO, "Display Init: Start\n"); |
Aravind Venkateswaran | dd50c1a | 2014-02-25 14:42:43 -0800 | [diff] [blame^] | 339 | target_display_init(); |
Dhaval Patel | f998627 | 2013-10-18 19:06:05 -0700 | [diff] [blame] | 340 | dprintf(INFO, "Display Init: Done\n"); |
| 341 | #endif |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Sundarajan Srinivasan | 4431e16 | 2013-12-10 13:16:04 -0800 | [diff] [blame] | 344 | void target_load_ssd_keystore(void) |
| 345 | { |
| 346 | uint64_t ptn; |
| 347 | int index; |
| 348 | uint64_t size; |
| 349 | uint32_t *buffer = NULL; |
| 350 | |
| 351 | if (!target_is_ssd_enabled()) |
| 352 | return; |
| 353 | |
| 354 | index = partition_get_index("ssd"); |
| 355 | |
| 356 | ptn = partition_get_offset(index); |
| 357 | if (ptn == 0){ |
| 358 | dprintf(CRITICAL, "Error: ssd partition not found\n"); |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | size = partition_get_size(index); |
| 363 | if (size == 0) { |
| 364 | dprintf(CRITICAL, "Error: invalid ssd partition size\n"); |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE)); |
| 369 | if (!buffer) { |
| 370 | dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n"); |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | if (mmc_read(ptn, buffer, size)) { |
| 375 | dprintf(CRITICAL, "Error: cannot read data\n"); |
| 376 | free(buffer); |
| 377 | return; |
| 378 | } |
| 379 | |
| 380 | clock_ce_enable(SSD_CE_INSTANCE); |
| 381 | scm_protect_keystore(buffer, size); |
| 382 | clock_ce_disable(SSD_CE_INSTANCE); |
| 383 | free(buffer); |
| 384 | } |
| 385 | |
| 386 | /* Do any target specific intialization needed before entering fastboot mode */ |
| 387 | void target_fastboot_init(void) |
| 388 | { |
Sundarajan Srinivasan | 23301ef | 2013-11-18 17:21:00 -0800 | [diff] [blame] | 389 | /* We are entering fastboot mode, so read partition table */ |
| 390 | mmc_read_partition_table(1); |
| 391 | |
Sundarajan Srinivasan | 4431e16 | 2013-12-10 13:16:04 -0800 | [diff] [blame] | 392 | if (target_is_ssd_enabled()) { |
| 393 | clock_ce_enable(SSD_CE_INSTANCE); |
| 394 | target_load_ssd_keystore(); |
| 395 | } |
| 396 | |
| 397 | } |
| 398 | |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 399 | unsigned board_machtype(void) |
| 400 | { |
| 401 | return LINUX_MACHTYPE_UNKNOWN; |
| 402 | } |
| 403 | |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 404 | /* Detect the target type */ |
| 405 | void target_detect(struct board_data *board) |
| 406 | { |
Channagoud Kadabi | eabb9ad | 2014-02-11 15:34:24 -0800 | [diff] [blame] | 407 | /* This is alreay filled as part of board.c */ |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 410 | void set_cdp_baseband(struct board_data *board) |
| 411 | { |
| 412 | |
| 413 | uint32_t platform_subtype; |
| 414 | platform_subtype = board->platform_subtype; |
| 415 | |
| 416 | switch(platform_subtype) { |
| 417 | case CDP_SUBTYPE_9x25_SMB349: |
| 418 | case CDP_SUBTYPE_9x25_SMB1357: |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 419 | board->baseband = BASEBAND_MDM; |
| 420 | break; |
Sundarajan Srinivasan | 839b520 | 2013-11-12 17:21:07 -0800 | [diff] [blame] | 421 | case CDP_SUBTYPE_9x35: |
Sundarajan Srinivasan | 0e94a1c | 2013-12-17 10:55:51 -0800 | [diff] [blame] | 422 | case CDP_SUBTYPE_9x35_M: |
Sundarajan Srinivasan | 839b520 | 2013-11-12 17:21:07 -0800 | [diff] [blame] | 423 | board->baseband = BASEBAND_MDM2; |
| 424 | break; |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 425 | case CDP_SUBTYPE_SMB349: |
| 426 | case CDP_SUBTYPE_SMB1357: |
Sundarajan Srinivasan | 01e68f1 | 2013-11-01 12:21:52 -0700 | [diff] [blame] | 427 | case CDP_SUBTYPE_SMB350: |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 428 | board->baseband = BASEBAND_APQ; |
| 429 | break; |
| 430 | default: |
| 431 | dprintf(CRITICAL, "CDP platform subtype :%u is not supported\n", |
| 432 | platform_subtype); |
| 433 | ASSERT(0); |
| 434 | }; |
| 435 | |
| 436 | } |
| 437 | |
| 438 | void set_mtp_baseband(struct board_data *board) |
| 439 | { |
| 440 | |
| 441 | uint32_t platform_subtype; |
| 442 | platform_subtype = board->platform_subtype; |
| 443 | |
| 444 | switch(platform_subtype) { |
| 445 | case MTP_SUBTYPE_9x25_SMB349: |
| 446 | case MTP_SUBTYPE_9x25_SMB1357: |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 447 | board->baseband = BASEBAND_MDM; |
| 448 | break; |
Sundarajan Srinivasan | 839b520 | 2013-11-12 17:21:07 -0800 | [diff] [blame] | 449 | case MTP_SUBTYPE_9x35: |
Sundarajan Srinivasan | 0e94a1c | 2013-12-17 10:55:51 -0800 | [diff] [blame] | 450 | case MTP_SUBTYPE_9x35_M: |
Sundarajan Srinivasan | 839b520 | 2013-11-12 17:21:07 -0800 | [diff] [blame] | 451 | board->baseband = BASEBAND_MDM2; |
| 452 | break; |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 453 | case MTP_SUBTYPE_SMB349: |
| 454 | board->baseband = BASEBAND_APQ; |
| 455 | break; |
| 456 | default: |
| 457 | dprintf(CRITICAL, "MTP platform subtype :%u is not supported\n", |
| 458 | platform_subtype); |
| 459 | ASSERT(0); |
| 460 | }; |
| 461 | } |
| 462 | |
| 463 | void set_rcm_baseband(struct board_data *board) |
| 464 | { |
| 465 | uint32_t platform_subtype; |
| 466 | platform_subtype = board->platform_subtype; |
| 467 | |
| 468 | switch(platform_subtype) { |
| 469 | case RCM_SUBTYPE_9x25_SMB349: |
| 470 | case RCM_SUBTYPE_9x25_SMB1357: |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 471 | board->baseband = BASEBAND_MDM; |
| 472 | break; |
Sundarajan Srinivasan | 839b520 | 2013-11-12 17:21:07 -0800 | [diff] [blame] | 473 | case RCM_SUBTYPE_9x35: |
Sundarajan Srinivasan | 0e94a1c | 2013-12-17 10:55:51 -0800 | [diff] [blame] | 474 | case RCM_SUBTYPE_9x35_M: |
Sundarajan Srinivasan | 839b520 | 2013-11-12 17:21:07 -0800 | [diff] [blame] | 475 | board->baseband = BASEBAND_MDM2; |
| 476 | break; |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 477 | case RCM_SUBTYPE_SMB349: |
| 478 | case RCM_SUBTYPE_SMB1357: |
Sundarajan Srinivasan | 01e68f1 | 2013-11-01 12:21:52 -0700 | [diff] [blame] | 479 | case RCM_SUBTYPE_SMB350: |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 480 | board->baseband = BASEBAND_APQ; |
| 481 | break; |
| 482 | default: |
| 483 | dprintf(CRITICAL, "RCM platform subtype :%u is not supported\n", |
| 484 | platform_subtype); |
| 485 | ASSERT(0); |
| 486 | }; |
| 487 | } |
| 488 | |
Sundarajan Srinivasan | 6ade93e | 2013-11-18 11:07:22 -0800 | [diff] [blame] | 489 | void set_liquid_baseband(struct board_data *board) |
| 490 | { |
| 491 | uint32_t platform_subtype; |
| 492 | |
| 493 | platform_subtype = board->platform_subtype; |
| 494 | |
| 495 | switch(platform_subtype) |
| 496 | { |
| 497 | case LIQUID_SUBTYPE_STANDALONE: |
| 498 | board->baseband = BASEBAND_APQ; |
| 499 | break; |
| 500 | case LIQUID_SUBTYPE_9x25: |
| 501 | board->baseband = BASEBAND_MDM; |
| 502 | break; |
| 503 | default: |
| 504 | dprintf(CRITICAL, "Liquid platform subtype :%u is not supported\n",platform_subtype); |
| 505 | ASSERT(0); |
| 506 | } |
| 507 | } |
| 508 | |
Dhaval Patel | f998627 | 2013-10-18 19:06:05 -0700 | [diff] [blame] | 509 | /* Returns 1 if target supports continuous splash screen. */ |
| 510 | int target_cont_splash_screen() |
| 511 | { |
| 512 | switch(board_hardware_id()) |
| 513 | { |
| 514 | case HW_PLATFORM_SURF: |
| 515 | case HW_PLATFORM_MTP: |
| 516 | case HW_PLATFORM_FLUID: |
Dhaval Patel | d0a09e2 | 2013-10-25 10:15:21 -0700 | [diff] [blame] | 517 | case HW_PLATFORM_LIQUID: |
| 518 | dprintf(SPEW, "Target_cont_splash=1\n"); |
Dhaval Patel | f998627 | 2013-10-18 19:06:05 -0700 | [diff] [blame] | 519 | return 1; |
Dhaval Patel | f998627 | 2013-10-18 19:06:05 -0700 | [diff] [blame] | 520 | default: |
| 521 | dprintf(SPEW, "Target_cont_splash=0\n"); |
| 522 | return 0; |
| 523 | } |
| 524 | } |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 525 | |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 526 | /* Detect the modem type */ |
| 527 | void target_baseband_detect(struct board_data *board) |
| 528 | { |
Sundarajan Srinivasan | f5932fb | 2013-08-06 17:26:04 -0700 | [diff] [blame] | 529 | uint32_t platform; |
| 530 | uint32_t platform_subtype; |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 531 | uint32_t platform_hardware; |
Sundarajan Srinivasan | f5932fb | 2013-08-06 17:26:04 -0700 | [diff] [blame] | 532 | |
| 533 | platform = board->platform; |
Sundarajan Srinivasan | f5932fb | 2013-08-06 17:26:04 -0700 | [diff] [blame] | 534 | |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 535 | platform_hardware = board->platform_hw; |
| 536 | |
| 537 | switch(platform_hardware) { |
| 538 | case HW_PLATFORM_SURF: |
| 539 | set_cdp_baseband(board); |
Sundarajan Srinivasan | f5932fb | 2013-08-06 17:26:04 -0700 | [diff] [blame] | 540 | break; |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 541 | case HW_PLATFORM_MTP: |
| 542 | set_mtp_baseband(board); |
| 543 | break; |
| 544 | case HW_PLATFORM_RCM: |
| 545 | set_rcm_baseband(board); |
| 546 | break; |
| 547 | case HW_PLATFORM_LIQUID: |
Sundarajan Srinivasan | 6ade93e | 2013-11-18 11:07:22 -0800 | [diff] [blame] | 548 | set_liquid_baseband(board); |
Sundarajan Srinivasan | f5932fb | 2013-08-06 17:26:04 -0700 | [diff] [blame] | 549 | break; |
Eugene Yasman | 2a46211 | 2013-12-09 09:26:37 +0200 | [diff] [blame] | 550 | case HW_PLATFORM_SBC: |
| 551 | board->baseband = BASEBAND_APQ; |
| 552 | break; |
Sundarajan Srinivasan | f5932fb | 2013-08-06 17:26:04 -0700 | [diff] [blame] | 553 | default: |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 554 | dprintf(CRITICAL, "Platform :%u is not supported\n", |
| 555 | platform_hardware); |
Sundarajan Srinivasan | f5932fb | 2013-08-06 17:26:04 -0700 | [diff] [blame] | 556 | ASSERT(0); |
Ameya Thakur | cfca921 | 2013-09-13 23:51:49 -0700 | [diff] [blame] | 557 | }; |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | unsigned target_baseband() |
| 561 | { |
| 562 | return board_baseband(); |
| 563 | } |
| 564 | |
| 565 | void target_serialno(unsigned char *buf) |
| 566 | { |
| 567 | unsigned int serialno; |
| 568 | if (target_is_emmc_boot()) { |
| 569 | serialno = mmc_get_psn(); |
| 570 | snprintf((char *)buf, 13, "%x", serialno); |
| 571 | } |
| 572 | } |
| 573 | |
Pavel Nedev | a6c0beb | 2013-11-15 17:20:27 +0200 | [diff] [blame] | 574 | int emmc_recovery_init(void) |
| 575 | { |
| 576 | return _emmc_recovery_init(); |
| 577 | } |
| 578 | |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 579 | unsigned check_reboot_mode(void) |
| 580 | { |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 581 | uint32_t restart_reason = 0; |
| 582 | uint32_t restart_reason_addr; |
| 583 | |
| 584 | restart_reason_addr = RESTART_REASON_ADDR; |
| 585 | |
| 586 | /* Read reboot reason and scrub it */ |
| 587 | restart_reason = readl(restart_reason_addr); |
| 588 | writel(0x00, restart_reason_addr); |
| 589 | |
| 590 | return restart_reason; |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | void reboot_device(unsigned reboot_reason) |
| 594 | { |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 595 | uint8_t reset_type = 0; |
| 596 | |
| 597 | /* Write the reboot reason */ |
| 598 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 599 | |
| 600 | if(reboot_reason == FASTBOOT_MODE) |
| 601 | reset_type = PON_PSHOLD_WARM_RESET; |
| 602 | else |
| 603 | reset_type = PON_PSHOLD_HARD_RESET; |
| 604 | |
| 605 | pm8x41_reset_configure(reset_type); |
| 606 | |
| 607 | /* Drop PS_HOLD for MSM */ |
| 608 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 609 | |
| 610 | mdelay(5000); |
| 611 | |
| 612 | dprintf(CRITICAL, "Rebooting failed\n"); |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 613 | } |
Amol Jadi | 0a4c9b4 | 2013-10-11 14:22:11 -0700 | [diff] [blame] | 614 | |
| 615 | /* identify the usb controller to be used for the target */ |
| 616 | const char * target_usb_controller() |
| 617 | { |
| 618 | return "dwc"; |
| 619 | } |
| 620 | |
| 621 | /* mux hs phy to route to dwc controller */ |
| 622 | static void phy_mux_configure_with_jdr() |
| 623 | { |
| 624 | uint32_t val; |
| 625 | |
| 626 | val = readl(COPSS_USB_CONTROL_WITH_JDR); |
| 627 | |
| 628 | /* Note: there are no details regarding this bit in hpg or swi. */ |
| 629 | val |= BIT(8); |
| 630 | |
| 631 | writel(val, COPSS_USB_CONTROL_WITH_JDR); |
| 632 | } |
| 633 | |
| 634 | /* configure hs phy mux if using dwc controller */ |
| 635 | void target_usb_phy_mux_configure(void) |
| 636 | { |
| 637 | if(!strcmp(target_usb_controller(), "dwc")) |
| 638 | { |
| 639 | phy_mux_configure_with_jdr(); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | void target_usb_phy_reset(void) |
| 644 | { |
| 645 | uint32_t val; |
| 646 | |
| 647 | /* SS PHY reset */ |
| 648 | val = readl(GCC_USB3_PHY_BCR) | BIT(0); |
| 649 | writel(val, GCC_USB3_PHY_BCR); |
| 650 | udelay(10); |
| 651 | writel(val & ~BIT(0), GCC_USB3_PHY_BCR); |
| 652 | |
| 653 | /* HS PHY reset */ |
| 654 | /* Note: reg/bit details are not mentioned in hpg or swi. */ |
| 655 | val = readl(COPSS_USB_CONTROL_WITH_JDR) | BIT(11); |
| 656 | writel(val, COPSS_USB_CONTROL_WITH_JDR); |
| 657 | udelay(10); |
| 658 | writel(val & ~BIT(11), COPSS_USB_CONTROL_WITH_JDR); |
Channagoud Kadabi | 70500ea | 2013-10-29 17:33:44 -0700 | [diff] [blame] | 659 | |
| 660 | /* PHY_COMMON reset */ |
| 661 | val = readl(GCC_USB30_PHY_COM_BCR) | BIT(0); |
| 662 | writel(val, GCC_USB30_PHY_COM_BCR); |
| 663 | udelay(10); |
| 664 | writel(val & ~BIT(0), GCC_USB30_PHY_COM_BCR); |
Amol Jadi | 0a4c9b4 | 2013-10-11 14:22:11 -0700 | [diff] [blame] | 665 | } |
Sundarajan Srinivasan | 86106c3 | 2013-12-19 11:36:07 -0800 | [diff] [blame] | 666 | |
Hanumant Singh | 7531194 | 2014-01-29 13:43:53 -0800 | [diff] [blame] | 667 | bool target_warm_boot(void) |
| 668 | { |
| 669 | uint8_t is_cold_boot = pm8x41_get_is_cold_boot(); |
| 670 | if (is_cold_boot) |
| 671 | return false; |
| 672 | else |
| 673 | return true; |
| 674 | } |
Sundarajan Srinivasan | 86106c3 | 2013-12-19 11:36:07 -0800 | [diff] [blame] | 675 | /* Set up params for h/w CE. */ |
| 676 | void target_crypto_init_params() |
| 677 | { |
| 678 | struct crypto_init_params ce_params; |
| 679 | |
| 680 | /* Set up base addresses and instance. */ |
| 681 | ce_params.crypto_instance = CE2_INSTANCE; |
| 682 | ce_params.crypto_base = MSM_CE2_BASE; |
| 683 | ce_params.bam_base = MSM_CE2_BAM_BASE; |
| 684 | |
| 685 | /* Set up BAM config. */ |
| 686 | ce_params.bam_ee = CE_EE; |
| 687 | ce_params.pipes.read_pipe = CE_READ_PIPE; |
| 688 | ce_params.pipes.write_pipe = CE_WRITE_PIPE; |
| 689 | ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP; |
| 690 | ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP; |
| 691 | |
| 692 | /* Assign buffer sizes. */ |
| 693 | ce_params.num_ce = CE_ARRAY_SIZE; |
| 694 | ce_params.read_fifo_size = CE_FIFO_SIZE; |
| 695 | ce_params.write_fifo_size = CE_FIFO_SIZE; |
| 696 | |
| 697 | /* BAM is initialized by TZ for this platform. |
| 698 | * Do not do it again as the initialization address space |
| 699 | * is locked. |
| 700 | */ |
| 701 | ce_params.do_bam_init = 0; |
| 702 | |
| 703 | crypto_init_params(&ce_params); |
| 704 | } |
| 705 | |
| 706 | crypto_engine_type board_ce_type(void) |
| 707 | { |
| 708 | return CRYPTO_ENGINE_TYPE_HW; |
| 709 | } |