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> |
| 54 | #include <ufs.h> |
Sundarajan Srinivasan | d598b12 | 2014-03-21 17:33:29 -0700 | [diff] [blame] | 55 | #include <boot_device.h> |
Channagoud Kadabi | 3dcc4ed | 2014-04-10 14:59:41 -0700 | [diff] [blame] | 56 | #include <qmp_phy.h> |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 57 | |
| 58 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 59 | #define PMIC_ARB_OWNER_ID 0 |
| 60 | |
| 61 | #define FASTBOOT_MODE 0x77665500 |
| 62 | |
| 63 | #define BOOT_DEVICE_MASK(val) ((val & 0x3E) >>1) |
| 64 | |
| 65 | static void set_sdc_power_ctrl(void); |
| 66 | static uint32_t mmc_pwrctl_base[] = |
| 67 | { MSM_SDC1_BASE, MSM_SDC2_BASE }; |
| 68 | |
| 69 | static uint32_t mmc_sdhci_base[] = |
| 70 | { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE }; |
| 71 | |
| 72 | static uint32_t mmc_sdc_pwrctl_irq[] = |
| 73 | { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ }; |
| 74 | |
| 75 | struct mmc_device *dev; |
| 76 | struct ufs_dev ufs_device; |
| 77 | |
| 78 | extern void ulpi_write(unsigned val, unsigned reg); |
| 79 | |
| 80 | void target_early_init(void) |
| 81 | { |
| 82 | #if WITH_DEBUG_UART |
| 83 | uart_dm_init(2, 0, BLSP1_UART1_BASE); |
| 84 | #endif |
| 85 | } |
| 86 | |
| 87 | /* Return 1 if vol_up pressed */ |
| 88 | static int target_volume_up() |
| 89 | { |
| 90 | uint8_t status = 0; |
| 91 | struct pm8x41_gpio gpio; |
| 92 | |
| 93 | /* Configure the GPIO */ |
| 94 | gpio.direction = PM_GPIO_DIR_IN; |
| 95 | gpio.function = 0; |
| 96 | gpio.pull = PM_GPIO_PULL_UP_30; |
| 97 | gpio.vin_sel = 2; |
| 98 | |
| 99 | pm8x41_gpio_config(3, &gpio); |
| 100 | |
| 101 | /* Wait for the pmic gpio config to take effect */ |
| 102 | thread_sleep(1); |
| 103 | |
| 104 | /* Get status of P_GPIO_5 */ |
| 105 | pm8x41_gpio_get(3, &status); |
| 106 | |
| 107 | return !status; /* active low */ |
| 108 | } |
| 109 | |
| 110 | /* Return 1 if vol_down pressed */ |
| 111 | uint32_t target_volume_down() |
| 112 | { |
| 113 | return pm8x41_resin_status(); |
| 114 | } |
| 115 | |
| 116 | static void target_keystatus() |
| 117 | { |
| 118 | keys_init(); |
| 119 | |
| 120 | if(target_volume_down()) |
| 121 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 122 | |
| 123 | if(target_volume_up()) |
| 124 | keys_post_event(KEY_VOLUMEUP, 1); |
| 125 | } |
| 126 | |
| 127 | void target_uninit(void) |
| 128 | { |
Sundarajan Srinivasan | d598b12 | 2014-03-21 17:33:29 -0700 | [diff] [blame] | 129 | if (platform_boot_dev_isemmc()) |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 130 | mmc_put_card_to_sleep(dev); |
| 131 | } |
| 132 | |
| 133 | /* Do target specific usb initialization */ |
| 134 | void target_usb_init(void) |
| 135 | { |
| 136 | uint32_t val; |
| 137 | |
Sundarajan Srinivasan | 0ebf2fc | 2014-04-23 16:45:18 -0700 | [diff] [blame] | 138 | if(board_hardware_id() == HW_PLATFORM_DRAGON) |
| 139 | { |
| 140 | /* Select the QUSB2 PHY */ |
| 141 | writel(0x1, USB2_PHY_SEL); |
| 142 | |
| 143 | /* Block Reset */ |
| 144 | val = readl(GCC_QUSB2_PHY_BCR) | BIT(0); |
| 145 | writel(val, GCC_QUSB2_PHY_BCR); |
| 146 | udelay(10); |
| 147 | writel(val & ~BIT(0), GCC_QUSB2_PHY_BCR); |
| 148 | |
| 149 | /* Deassert POWERDOWN by clearing bit 0 to enable the PHY */ |
| 150 | val = readl(QUSB2PHY_PORT_POWERDOWN); |
| 151 | writel(val & ~BIT(0), QUSB2PHY_PORT_POWERDOWN); |
| 152 | udelay(10); |
| 153 | |
| 154 | /* set CLAMP_N_EN and FREEZIO_N */ |
| 155 | writel(0x22, QUSB2PHY_PORT_POWERDOWN); |
| 156 | } |
| 157 | |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 158 | /* Select and enable external configuration with USB PHY */ |
| 159 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET); |
| 160 | |
| 161 | /* Enable sess_vld */ |
| 162 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 163 | writel(val, USB_GENCONFIG_2); |
| 164 | |
| 165 | /* Enable external vbus configuration in the LINK */ |
| 166 | val = readl(USB_USBCMD); |
| 167 | val |= SESS_VLD_CTRL; |
| 168 | writel(val, USB_USBCMD); |
| 169 | } |
| 170 | |
| 171 | void target_usb_stop(void) |
| 172 | { |
| 173 | /* Disable VBUS mimicing in the controller. */ |
| 174 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR); |
| 175 | } |
| 176 | |
| 177 | static void set_sdc_power_ctrl() |
| 178 | { |
| 179 | /* Drive strength configs for sdc pins */ |
| 180 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 181 | { |
| 182 | { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK }, |
| 183 | { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK }, |
| 184 | { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK }, |
| 185 | }; |
| 186 | |
| 187 | /* Pull configs for sdc pins */ |
| 188 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 189 | { |
| 190 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK }, |
| 191 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
| 192 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
| 193 | }; |
| 194 | |
| 195 | /* Set the drive strength & pull control values */ |
| 196 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 197 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
| 198 | } |
| 199 | |
| 200 | void target_sdc_init() |
| 201 | { |
Channagoud Kadabi | a66a6f2 | 2014-05-28 17:19:44 -0700 | [diff] [blame] | 202 | struct mmc_config_data config = {0}; |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 203 | |
| 204 | /* Set drive strength & pull ctrl values */ |
| 205 | set_sdc_power_ctrl(); |
| 206 | |
| 207 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
| 208 | config.max_clk_rate = MMC_CLK_192MHZ; |
| 209 | |
| 210 | /* Try slot 1*/ |
| 211 | config.slot = 1; |
| 212 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 213 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 214 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 215 | |
| 216 | if (!(dev = mmc_init(&config))) |
| 217 | { |
| 218 | /* Try slot 2 */ |
| 219 | config.slot = 2; |
| 220 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 221 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 222 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 223 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 224 | |
| 225 | if (!(dev = mmc_init(&config))) |
| 226 | { |
| 227 | dprintf(CRITICAL, "mmc init failed!"); |
| 228 | ASSERT(0); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 233 | void *target_mmc_device() |
| 234 | { |
Sundarajan Srinivasan | d598b12 | 2014-03-21 17:33:29 -0700 | [diff] [blame] | 235 | if (platform_boot_dev_isemmc()) |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 236 | return (void *) dev; |
| 237 | else |
| 238 | return (void *) &ufs_device; |
| 239 | } |
| 240 | |
| 241 | void target_init(void) |
| 242 | { |
| 243 | dprintf(INFO, "target_init()\n"); |
| 244 | |
| 245 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 246 | |
| 247 | target_keystatus(); |
| 248 | |
Sundarajan Srinivasan | d598b12 | 2014-03-21 17:33:29 -0700 | [diff] [blame] | 249 | platform_read_boot_config(); |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 250 | |
Sundarajan Srinivasan | d598b12 | 2014-03-21 17:33:29 -0700 | [diff] [blame] | 251 | if (platform_boot_dev_isemmc()) |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 252 | { |
| 253 | target_sdc_init(); |
| 254 | } |
| 255 | else |
| 256 | { |
| 257 | ufs_device.base = UFS_BASE; |
| 258 | ufs_init(&ufs_device); |
| 259 | } |
| 260 | |
| 261 | /* Storage initialization is complete, read the partition table info */ |
| 262 | if (partition_read_table()) |
| 263 | { |
| 264 | dprintf(CRITICAL, "Error reading the partition table info\n"); |
| 265 | ASSERT(0); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | unsigned board_machtype(void) |
| 270 | { |
| 271 | return LINUX_MACHTYPE_UNKNOWN; |
| 272 | } |
| 273 | |
| 274 | /* Detect the target type */ |
| 275 | void target_detect(struct board_data *board) |
| 276 | { |
| 277 | /* This is filled from board.c */ |
| 278 | } |
| 279 | |
| 280 | /* Detect the modem type */ |
| 281 | void target_baseband_detect(struct board_data *board) |
| 282 | { |
| 283 | uint32_t platform; |
| 284 | |
| 285 | platform = board->platform; |
| 286 | |
| 287 | switch(platform) { |
Channagoud Kadabi | 44ea30d | 2014-04-14 13:59:42 -0700 | [diff] [blame] | 288 | case MSM8994: |
Channagoud Kadabi | 0f3a4f7 | 2014-02-06 13:22:07 -0800 | [diff] [blame] | 289 | board->baseband = BASEBAND_MSM; |
| 290 | break; |
| 291 | default: |
| 292 | dprintf(CRITICAL, "Platform type: %u is not supported\n",platform); |
| 293 | ASSERT(0); |
| 294 | }; |
| 295 | } |
| 296 | unsigned target_baseband() |
| 297 | { |
| 298 | return board_baseband(); |
| 299 | } |
| 300 | |
| 301 | void target_serialno(unsigned char *buf) |
| 302 | { |
| 303 | unsigned int serialno; |
| 304 | if (target_is_emmc_boot()) { |
| 305 | serialno = mmc_get_psn(); |
| 306 | snprintf((char *)buf, 13, "%x", serialno); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | unsigned check_reboot_mode(void) |
| 311 | { |
| 312 | uint32_t restart_reason = 0; |
| 313 | uint32_t restart_reason_addr; |
| 314 | |
| 315 | restart_reason_addr = RESTART_REASON_ADDR; |
| 316 | |
| 317 | /* Read reboot reason and scrub it */ |
| 318 | restart_reason = readl(restart_reason_addr); |
| 319 | writel(0x00, restart_reason_addr); |
| 320 | |
| 321 | return restart_reason; |
| 322 | } |
| 323 | |
| 324 | void reboot_device(unsigned reboot_reason) |
| 325 | { |
| 326 | uint8_t reset_type = 0; |
| 327 | |
| 328 | /* Write the reboot reason */ |
| 329 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 330 | |
| 331 | if(reboot_reason == FASTBOOT_MODE) |
| 332 | reset_type = PON_PSHOLD_WARM_RESET; |
| 333 | else |
| 334 | reset_type = PON_PSHOLD_HARD_RESET; |
| 335 | |
| 336 | pm8x41_reset_configure(reset_type); |
| 337 | |
| 338 | /* Drop PS_HOLD for MSM */ |
| 339 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 340 | |
| 341 | mdelay(5000); |
| 342 | |
| 343 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 344 | } |
| 345 | |
| 346 | int emmc_recovery_init(void) |
| 347 | { |
| 348 | return _emmc_recovery_init(); |
| 349 | } |
Channagoud Kadabi | 3dcc4ed | 2014-04-10 14:59:41 -0700 | [diff] [blame] | 350 | |
| 351 | target_usb_iface_t* target_usb30_init() |
| 352 | { |
| 353 | target_usb_iface_t *t_usb_iface; |
| 354 | |
| 355 | t_usb_iface = calloc(1, sizeof(target_usb_iface_t)); |
| 356 | ASSERT(t_usb_iface); |
| 357 | |
| 358 | t_usb_iface->mux_config = target_usb_phy_mux_configure; |
| 359 | t_usb_iface->phy_init = usb30_qmp_phy_init; |
| 360 | t_usb_iface->phy_reset = usb30_qmp_phy_reset; |
| 361 | t_usb_iface->clock_init = clock_usb30_init; |
| 362 | t_usb_iface->vbus_override = 1; |
| 363 | |
| 364 | return t_usb_iface; |
| 365 | } |
| 366 | |
| 367 | /* identify the usb controller to be used for the target */ |
| 368 | const char * target_usb_controller() |
| 369 | { |
| 370 | return "dwc"; |
| 371 | } |
| 372 | |
| 373 | /* mux hs phy to route to dwc controller */ |
| 374 | static void phy_mux_configure_with_tcsr() |
| 375 | { |
| 376 | /* As per the hardware team, set the mux for snps controller */ |
| 377 | RMWREG32(TCSR_PHSS_USB2_PHY_SEL, 0x0, 0x1, 0x1); |
| 378 | } |
| 379 | |
| 380 | /* configure hs phy mux if using dwc controller */ |
| 381 | void target_usb_phy_mux_configure(void) |
| 382 | { |
| 383 | if(!strcmp(target_usb_controller(), "dwc")) |
| 384 | { |
| 385 | phy_mux_configure_with_tcsr(); |
| 386 | } |
| 387 | } |
Channagoud Kadabi | 3c2be1c | 2014-06-01 18:59:21 -0700 | [diff] [blame^] | 388 | |
| 389 | uint32_t target_override_pll() |
| 390 | { |
| 391 | return 1; |
| 392 | } |