Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. |
| 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> |
| 31 | #include <platform/irqs.h> |
| 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> |
| 52 | #include <platform/timer.h> |
| 53 | #include <stdlib.h> |
vijay kumar | 4e5859e | 2014-09-22 17:49:02 +0530 | [diff] [blame^] | 54 | #include <string.h> |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 55 | #include <ufs.h> |
Sundarajan Srinivasan | d598b12 | 2014-03-21 17:33:29 -0700 | [diff] [blame] | 56 | #include <boot_device.h> |
Channagoud Kadabi | 3dcc4ed | 2014-04-10 14:59:41 -0700 | [diff] [blame] | 57 | #include <qmp_phy.h> |
Joonwoo Park | 8b30997 | 2014-06-09 16:58:38 -0700 | [diff] [blame] | 58 | #include <qusb2_phy.h> |
Sundarajan Srinivasan | 19b95c7 | 2014-07-24 16:37:04 -0700 | [diff] [blame] | 59 | #include <rpm-smd.h> |
vijay kumar | 4e5859e | 2014-09-22 17:49:02 +0530 | [diff] [blame^] | 60 | #include <sdhci_msm.h> |
| 61 | #include <pm8x41_wled.h> |
| 62 | #include <qpnp_wled.h> |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 63 | |
Channagoud Kadabi | 27ff934 | 2014-06-16 11:19:29 -0700 | [diff] [blame] | 64 | #define CE_INSTANCE 2 |
Channagoud Kadabi | 4b93fd3 | 2014-06-04 17:28:03 -0700 | [diff] [blame] | 65 | #define CE_EE 1 |
| 66 | #define CE_FIFO_SIZE 64 |
| 67 | #define CE_READ_PIPE 3 |
| 68 | #define CE_WRITE_PIPE 2 |
| 69 | #define CE_READ_PIPE_LOCK_GRP 0 |
| 70 | #define CE_WRITE_PIPE_LOCK_GRP 0 |
| 71 | #define CE_ARRAY_SIZE 20 |
| 72 | |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 73 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 74 | #define PMIC_ARB_OWNER_ID 0 |
| 75 | |
| 76 | #define FASTBOOT_MODE 0x77665500 |
| 77 | |
Aparna Mallavarapu | 965fac9 | 2014-08-04 22:45:01 +0530 | [diff] [blame] | 78 | #define PMIC_WLED_SLAVE_ID 3 |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 79 | |
Channagoud Kadabi | e804d64 | 2014-08-20 17:43:57 -0700 | [diff] [blame] | 80 | static void set_sdc_power_ctrl(uint8_t slot); |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 81 | static uint32_t mmc_pwrctl_base[] = |
| 82 | { MSM_SDC1_BASE, MSM_SDC2_BASE }; |
| 83 | |
| 84 | static uint32_t mmc_sdhci_base[] = |
| 85 | { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE }; |
| 86 | |
| 87 | static uint32_t mmc_sdc_pwrctl_irq[] = |
| 88 | { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ }; |
| 89 | |
| 90 | struct mmc_device *dev; |
| 91 | struct ufs_dev ufs_device; |
| 92 | |
| 93 | extern void ulpi_write(unsigned val, unsigned reg); |
Sridhar Parasuram | 39419a3 | 2014-09-12 18:11:05 -0700 | [diff] [blame] | 94 | extern int platform_is_msm8994(); |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 95 | |
| 96 | void target_early_init(void) |
| 97 | { |
| 98 | #if WITH_DEBUG_UART |
| 99 | uart_dm_init(2, 0, BLSP1_UART1_BASE); |
| 100 | #endif |
| 101 | } |
| 102 | |
| 103 | /* Return 1 if vol_up pressed */ |
| 104 | static int target_volume_up() |
| 105 | { |
| 106 | uint8_t status = 0; |
| 107 | struct pm8x41_gpio gpio; |
| 108 | |
| 109 | /* Configure the GPIO */ |
| 110 | gpio.direction = PM_GPIO_DIR_IN; |
| 111 | gpio.function = 0; |
| 112 | gpio.pull = PM_GPIO_PULL_UP_30; |
| 113 | gpio.vin_sel = 2; |
| 114 | |
| 115 | pm8x41_gpio_config(3, &gpio); |
| 116 | |
| 117 | /* Wait for the pmic gpio config to take effect */ |
| 118 | thread_sleep(1); |
| 119 | |
| 120 | /* Get status of P_GPIO_5 */ |
| 121 | pm8x41_gpio_get(3, &status); |
| 122 | |
| 123 | return !status; /* active low */ |
| 124 | } |
| 125 | |
| 126 | /* Return 1 if vol_down pressed */ |
| 127 | uint32_t target_volume_down() |
| 128 | { |
| 129 | return pm8x41_resin_status(); |
| 130 | } |
| 131 | |
| 132 | static void target_keystatus() |
| 133 | { |
| 134 | keys_init(); |
| 135 | |
| 136 | if(target_volume_down()) |
| 137 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 138 | |
| 139 | if(target_volume_up()) |
| 140 | keys_post_event(KEY_VOLUMEUP, 1); |
| 141 | } |
| 142 | |
| 143 | void target_uninit(void) |
| 144 | { |
Sundarajan Srinivasan | d598b12 | 2014-03-21 17:33:29 -0700 | [diff] [blame] | 145 | if (platform_boot_dev_isemmc()) |
Channagoud Kadabi | d6a45ea | 2014-06-02 21:12:51 -0700 | [diff] [blame] | 146 | { |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 147 | mmc_put_card_to_sleep(dev); |
Channagoud Kadabi | d6a45ea | 2014-06-02 21:12:51 -0700 | [diff] [blame] | 148 | /* Disable HC mode before jumping to kernel */ |
| 149 | sdhci_mode_disable(&dev->host); |
| 150 | } |
Channagoud Kadabi | 4b93fd3 | 2014-06-04 17:28:03 -0700 | [diff] [blame] | 151 | |
| 152 | if (crypto_initialized()) |
| 153 | crypto_eng_cleanup(); |
Sundarajan Srinivasan | 19b95c7 | 2014-07-24 16:37:04 -0700 | [diff] [blame] | 154 | |
| 155 | rpm_smd_uninit(); |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /* Do target specific usb initialization */ |
| 159 | void target_usb_init(void) |
| 160 | { |
| 161 | uint32_t val; |
| 162 | |
Sundarajan Srinivasan | 0ebf2fc | 2014-04-23 16:45:18 -0700 | [diff] [blame] | 163 | if(board_hardware_id() == HW_PLATFORM_DRAGON) |
| 164 | { |
| 165 | /* Select the QUSB2 PHY */ |
| 166 | writel(0x1, USB2_PHY_SEL); |
| 167 | |
Joonwoo Park | 8b30997 | 2014-06-09 16:58:38 -0700 | [diff] [blame] | 168 | qusb2_phy_reset(); |
Sundarajan Srinivasan | 0ebf2fc | 2014-04-23 16:45:18 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 171 | /* Enable sess_vld */ |
| 172 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 173 | writel(val, USB_GENCONFIG_2); |
| 174 | |
| 175 | /* Enable external vbus configuration in the LINK */ |
| 176 | val = readl(USB_USBCMD); |
| 177 | val |= SESS_VLD_CTRL; |
| 178 | writel(val, USB_USBCMD); |
| 179 | } |
| 180 | |
| 181 | void target_usb_stop(void) |
| 182 | { |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 183 | } |
| 184 | |
Channagoud Kadabi | e804d64 | 2014-08-20 17:43:57 -0700 | [diff] [blame] | 185 | static void set_sdc_power_ctrl(uint8_t slot) |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 186 | { |
Channagoud Kadabi | e804d64 | 2014-08-20 17:43:57 -0700 | [diff] [blame] | 187 | uint32_t reg = 0; |
Channagoud Kadabi | 751fe7a | 2014-09-04 18:52:24 -0700 | [diff] [blame] | 188 | uint8_t clk; |
| 189 | uint8_t cmd; |
| 190 | uint8_t dat; |
Channagoud Kadabi | e804d64 | 2014-08-20 17:43:57 -0700 | [diff] [blame] | 191 | |
| 192 | if (slot == 0x1) |
Channagoud Kadabi | 751fe7a | 2014-09-04 18:52:24 -0700 | [diff] [blame] | 193 | { |
| 194 | clk = TLMM_CUR_VAL_16MA; |
| 195 | cmd = TLMM_CUR_VAL_8MA; |
| 196 | dat = TLMM_CUR_VAL_8MA; |
Channagoud Kadabi | e804d64 | 2014-08-20 17:43:57 -0700 | [diff] [blame] | 197 | reg = SDC1_HDRV_PULL_CTL; |
Channagoud Kadabi | 751fe7a | 2014-09-04 18:52:24 -0700 | [diff] [blame] | 198 | } |
Channagoud Kadabi | e804d64 | 2014-08-20 17:43:57 -0700 | [diff] [blame] | 199 | else if (slot == 0x2) |
Channagoud Kadabi | 751fe7a | 2014-09-04 18:52:24 -0700 | [diff] [blame] | 200 | { |
| 201 | clk = TLMM_CUR_VAL_16MA; |
| 202 | cmd = TLMM_CUR_VAL_10MA; |
| 203 | dat = TLMM_CUR_VAL_10MA; |
Channagoud Kadabi | e804d64 | 2014-08-20 17:43:57 -0700 | [diff] [blame] | 204 | reg = SDC2_HDRV_PULL_CTL; |
Channagoud Kadabi | 751fe7a | 2014-09-04 18:52:24 -0700 | [diff] [blame] | 205 | } |
| 206 | else |
| 207 | { |
| 208 | dprintf(CRITICAL, "Unsupported SDC slot passed\n"); |
| 209 | return; |
| 210 | } |
Channagoud Kadabi | e804d64 | 2014-08-20 17:43:57 -0700 | [diff] [blame] | 211 | |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 212 | /* Drive strength configs for sdc pins */ |
| 213 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 214 | { |
Channagoud Kadabi | 751fe7a | 2014-09-04 18:52:24 -0700 | [diff] [blame] | 215 | { SDC1_CLK_HDRV_CTL_OFF, clk, TLMM_HDRV_MASK, reg }, |
| 216 | { SDC1_CMD_HDRV_CTL_OFF, cmd, TLMM_HDRV_MASK, reg }, |
| 217 | { SDC1_DATA_HDRV_CTL_OFF, dat, TLMM_HDRV_MASK, reg }, |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | /* Pull configs for sdc pins */ |
| 221 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 222 | { |
Channagoud Kadabi | e804d64 | 2014-08-20 17:43:57 -0700 | [diff] [blame] | 223 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, reg }, |
| 224 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, reg }, |
| 225 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, reg }, |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 226 | }; |
| 227 | |
Channagoud Kadabi | 9571715 | 2014-06-04 17:59:29 -0700 | [diff] [blame] | 228 | struct tlmm_cfgs sdc1_rclk_cfg[] = |
| 229 | { |
Channagoud Kadabi | e804d64 | 2014-08-20 17:43:57 -0700 | [diff] [blame] | 230 | { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, reg }, |
Channagoud Kadabi | 9571715 | 2014-06-04 17:59:29 -0700 | [diff] [blame] | 231 | }; |
| 232 | |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 233 | /* Set the drive strength & pull control values */ |
| 234 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 235 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
Channagoud Kadabi | 9571715 | 2014-06-04 17:59:29 -0700 | [diff] [blame] | 236 | tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg)); |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void target_sdc_init() |
| 240 | { |
Channagoud Kadabi | a66a6f2 | 2014-05-28 17:19:44 -0700 | [diff] [blame] | 241 | struct mmc_config_data config = {0}; |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 242 | |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 243 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
| 244 | config.max_clk_rate = MMC_CLK_192MHZ; |
| 245 | |
| 246 | /* Try slot 1*/ |
| 247 | config.slot = 1; |
| 248 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 249 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 250 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
Channagoud Kadabi | 6b3a998 | 2014-06-05 12:59:46 -0700 | [diff] [blame] | 251 | config.hs400_support = 1; |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 252 | |
Channagoud Kadabi | e804d64 | 2014-08-20 17:43:57 -0700 | [diff] [blame] | 253 | /* Set drive strength & pull ctrl values */ |
| 254 | set_sdc_power_ctrl(config.slot); |
| 255 | |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 256 | if (!(dev = mmc_init(&config))) |
| 257 | { |
| 258 | /* Try slot 2 */ |
| 259 | config.slot = 2; |
| 260 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 261 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 262 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 263 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 264 | |
Channagoud Kadabi | e804d64 | 2014-08-20 17:43:57 -0700 | [diff] [blame] | 265 | /* Set drive strength & pull ctrl values */ |
| 266 | set_sdc_power_ctrl(config.slot); |
| 267 | |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 268 | if (!(dev = mmc_init(&config))) |
| 269 | { |
| 270 | dprintf(CRITICAL, "mmc init failed!"); |
| 271 | ASSERT(0); |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 276 | void *target_mmc_device() |
| 277 | { |
Sundarajan Srinivasan | d598b12 | 2014-03-21 17:33:29 -0700 | [diff] [blame] | 278 | if (platform_boot_dev_isemmc()) |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 279 | return (void *) dev; |
| 280 | else |
| 281 | return (void *) &ufs_device; |
| 282 | } |
| 283 | |
| 284 | void target_init(void) |
| 285 | { |
| 286 | dprintf(INFO, "target_init()\n"); |
| 287 | |
| 288 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 289 | |
| 290 | target_keystatus(); |
| 291 | |
Channagoud Kadabi | 4b93fd3 | 2014-06-04 17:28:03 -0700 | [diff] [blame] | 292 | |
| 293 | if (target_use_signed_kernel()) |
| 294 | target_crypto_init_params(); |
| 295 | |
Sundarajan Srinivasan | d598b12 | 2014-03-21 17:33:29 -0700 | [diff] [blame] | 296 | platform_read_boot_config(); |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 297 | |
Sundarajan Srinivasan | d598b12 | 2014-03-21 17:33:29 -0700 | [diff] [blame] | 298 | if (platform_boot_dev_isemmc()) |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 299 | { |
| 300 | target_sdc_init(); |
| 301 | } |
| 302 | else |
| 303 | { |
| 304 | ufs_device.base = UFS_BASE; |
| 305 | ufs_init(&ufs_device); |
| 306 | } |
| 307 | |
| 308 | /* Storage initialization is complete, read the partition table info */ |
| 309 | if (partition_read_table()) |
| 310 | { |
| 311 | dprintf(CRITICAL, "Error reading the partition table info\n"); |
| 312 | ASSERT(0); |
| 313 | } |
Sundarajan Srinivasan | 19b95c7 | 2014-07-24 16:37:04 -0700 | [diff] [blame] | 314 | |
| 315 | rpm_smd_init(); |
Aparna Mallavarapu | 965fac9 | 2014-08-04 22:45:01 +0530 | [diff] [blame] | 316 | |
| 317 | /* QPNP WLED init for display backlight */ |
| 318 | pm8x41_wled_config_slave_id(PMIC_WLED_SLAVE_ID); |
| 319 | qpnp_wled_init(); |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | unsigned board_machtype(void) |
| 323 | { |
| 324 | return LINUX_MACHTYPE_UNKNOWN; |
| 325 | } |
| 326 | |
| 327 | /* Detect the target type */ |
| 328 | void target_detect(struct board_data *board) |
| 329 | { |
| 330 | /* This is filled from board.c */ |
| 331 | } |
| 332 | |
Dhaval Patel | 019057a | 2014-08-12 13:52:25 -0700 | [diff] [blame] | 333 | /* Returns 1 if target supports continuous splash screen. */ |
| 334 | int target_cont_splash_screen() |
| 335 | { |
| 336 | switch(board_hardware_id()) |
| 337 | { |
| 338 | case HW_PLATFORM_SURF: |
| 339 | case HW_PLATFORM_MTP: |
| 340 | case HW_PLATFORM_FLUID: |
| 341 | dprintf(SPEW, "Target_cont_splash=1\n"); |
| 342 | return 1; |
| 343 | default: |
| 344 | dprintf(SPEW, "Target_cont_splash=0\n"); |
| 345 | return 0; |
| 346 | } |
| 347 | } |
| 348 | |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 349 | /* Detect the modem type */ |
| 350 | void target_baseband_detect(struct board_data *board) |
| 351 | { |
| 352 | uint32_t platform; |
| 353 | |
| 354 | platform = board->platform; |
| 355 | |
| 356 | switch(platform) { |
Channagoud Kadabi | 44ea30d | 2014-04-14 13:59:42 -0700 | [diff] [blame] | 357 | case MSM8994: |
Channagoud Kadabi | 23c90ab | 2014-08-28 15:49:19 -0700 | [diff] [blame] | 358 | case MSM8992: |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 359 | board->baseband = BASEBAND_MSM; |
| 360 | break; |
Channagoud Kadabi | 30ef445 | 2014-07-12 13:03:30 -0700 | [diff] [blame] | 361 | case APQ8094: |
Channagoud Kadabi | 23c90ab | 2014-08-28 15:49:19 -0700 | [diff] [blame] | 362 | case APQ8092: |
Channagoud Kadabi | 30ef445 | 2014-07-12 13:03:30 -0700 | [diff] [blame] | 363 | board->baseband = BASEBAND_APQ; |
| 364 | break; |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 365 | default: |
| 366 | dprintf(CRITICAL, "Platform type: %u is not supported\n",platform); |
| 367 | ASSERT(0); |
| 368 | }; |
| 369 | } |
| 370 | unsigned target_baseband() |
| 371 | { |
| 372 | return board_baseband(); |
| 373 | } |
| 374 | |
| 375 | void target_serialno(unsigned char *buf) |
| 376 | { |
| 377 | unsigned int serialno; |
| 378 | if (target_is_emmc_boot()) { |
| 379 | serialno = mmc_get_psn(); |
| 380 | snprintf((char *)buf, 13, "%x", serialno); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | unsigned check_reboot_mode(void) |
| 385 | { |
| 386 | uint32_t restart_reason = 0; |
| 387 | uint32_t restart_reason_addr; |
| 388 | |
Sridhar Parasuram | 39419a3 | 2014-09-12 18:11:05 -0700 | [diff] [blame] | 389 | if (platform_is_msm8994()) |
| 390 | restart_reason_addr = RESTART_REASON_ADDR; |
| 391 | else |
| 392 | restart_reason_addr = RESTART_REASON_ADDR2; |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 393 | |
| 394 | /* Read reboot reason and scrub it */ |
| 395 | restart_reason = readl(restart_reason_addr); |
| 396 | writel(0x00, restart_reason_addr); |
| 397 | |
| 398 | return restart_reason; |
| 399 | } |
| 400 | |
| 401 | void reboot_device(unsigned reboot_reason) |
| 402 | { |
| 403 | uint8_t reset_type = 0; |
| 404 | |
| 405 | /* Write the reboot reason */ |
| 406 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 407 | |
| 408 | if(reboot_reason == FASTBOOT_MODE) |
| 409 | reset_type = PON_PSHOLD_WARM_RESET; |
| 410 | else |
| 411 | reset_type = PON_PSHOLD_HARD_RESET; |
| 412 | |
| 413 | pm8x41_reset_configure(reset_type); |
| 414 | |
| 415 | /* Drop PS_HOLD for MSM */ |
| 416 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 417 | |
| 418 | mdelay(5000); |
| 419 | |
| 420 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 421 | } |
| 422 | |
| 423 | int emmc_recovery_init(void) |
| 424 | { |
| 425 | return _emmc_recovery_init(); |
| 426 | } |
Channagoud Kadabi | 3dcc4ed | 2014-04-10 14:59:41 -0700 | [diff] [blame] | 427 | |
| 428 | target_usb_iface_t* target_usb30_init() |
| 429 | { |
| 430 | target_usb_iface_t *t_usb_iface; |
| 431 | |
| 432 | t_usb_iface = calloc(1, sizeof(target_usb_iface_t)); |
| 433 | ASSERT(t_usb_iface); |
| 434 | |
| 435 | t_usb_iface->mux_config = target_usb_phy_mux_configure; |
| 436 | t_usb_iface->phy_init = usb30_qmp_phy_init; |
| 437 | t_usb_iface->phy_reset = usb30_qmp_phy_reset; |
| 438 | t_usb_iface->clock_init = clock_usb30_init; |
| 439 | t_usb_iface->vbus_override = 1; |
| 440 | |
| 441 | return t_usb_iface; |
| 442 | } |
| 443 | |
| 444 | /* identify the usb controller to be used for the target */ |
| 445 | const char * target_usb_controller() |
| 446 | { |
Tanya Finkel | 90abab7 | 2014-07-30 09:55:23 +0300 | [diff] [blame] | 447 | if(board_hardware_id() == HW_PLATFORM_DRAGON) |
| 448 | return "ci"; |
Channagoud Kadabi | 3dcc4ed | 2014-04-10 14:59:41 -0700 | [diff] [blame] | 449 | return "dwc"; |
| 450 | } |
| 451 | |
| 452 | /* mux hs phy to route to dwc controller */ |
| 453 | static void phy_mux_configure_with_tcsr() |
| 454 | { |
| 455 | /* As per the hardware team, set the mux for snps controller */ |
| 456 | RMWREG32(TCSR_PHSS_USB2_PHY_SEL, 0x0, 0x1, 0x1); |
| 457 | } |
| 458 | |
| 459 | /* configure hs phy mux if using dwc controller */ |
| 460 | void target_usb_phy_mux_configure(void) |
| 461 | { |
| 462 | if(!strcmp(target_usb_controller(), "dwc")) |
| 463 | { |
| 464 | phy_mux_configure_with_tcsr(); |
| 465 | } |
| 466 | } |
Channagoud Kadabi | 3c2be1c | 2014-06-01 18:59:21 -0700 | [diff] [blame] | 467 | |
| 468 | uint32_t target_override_pll() |
| 469 | { |
| 470 | return 1; |
| 471 | } |
Channagoud Kadabi | 4b93fd3 | 2014-06-04 17:28:03 -0700 | [diff] [blame] | 472 | |
| 473 | /* Set up params for h/w CE. */ |
| 474 | void target_crypto_init_params() |
| 475 | { |
| 476 | struct crypto_init_params ce_params; |
| 477 | |
| 478 | /* Set up base addresses and instance. */ |
| 479 | ce_params.crypto_instance = CE_INSTANCE; |
Channagoud Kadabi | 27ff934 | 2014-06-16 11:19:29 -0700 | [diff] [blame] | 480 | ce_params.crypto_base = MSM_CE2_BASE; |
| 481 | ce_params.bam_base = MSM_CE2_BAM_BASE; |
Channagoud Kadabi | 4b93fd3 | 2014-06-04 17:28:03 -0700 | [diff] [blame] | 482 | |
| 483 | /* Set up BAM config. */ |
| 484 | ce_params.bam_ee = CE_EE; |
| 485 | ce_params.pipes.read_pipe = CE_READ_PIPE; |
| 486 | ce_params.pipes.write_pipe = CE_WRITE_PIPE; |
| 487 | ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP; |
| 488 | ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP; |
| 489 | |
| 490 | /* Assign buffer sizes. */ |
| 491 | ce_params.num_ce = CE_ARRAY_SIZE; |
| 492 | ce_params.read_fifo_size = CE_FIFO_SIZE; |
| 493 | ce_params.write_fifo_size = CE_FIFO_SIZE; |
| 494 | |
| 495 | /* BAM is initialized by TZ for this platform. |
| 496 | * Do not do it again as the initialization address space |
| 497 | * is locked. |
| 498 | */ |
| 499 | ce_params.do_bam_init = 0; |
| 500 | |
| 501 | crypto_init_params(&ce_params); |
| 502 | } |
| 503 | |
| 504 | crypto_engine_type board_ce_type(void) |
| 505 | { |
| 506 | return CRYPTO_ENGINE_TYPE_HW; |
| 507 | } |
Channagoud Kadabi | 84f860f | 2014-07-01 15:46:09 -0700 | [diff] [blame] | 508 | |
| 509 | void shutdown_device() |
| 510 | { |
| 511 | dprintf(CRITICAL, "Going down for shutdown.\n"); |
| 512 | |
| 513 | /* Configure PMIC for shutdown. */ |
| 514 | pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN); |
| 515 | |
| 516 | /* Drop PS_HOLD for MSM */ |
| 517 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 518 | |
| 519 | mdelay(5000); |
| 520 | |
| 521 | dprintf(CRITICAL, "Shutdown failed\n"); |
| 522 | |
| 523 | ASSERT(0); |
| 524 | } |
Sundarajan Srinivasan | cd3bb3c | 2014-07-23 12:25:44 -0700 | [diff] [blame] | 525 | |
| 526 | void target_fastboot_init(void) |
| 527 | { |
| 528 | /* We are entering fastboot mode, so read partition table */ |
| 529 | mmc_read_partition_table(1); |
| 530 | } |