Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2013, 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> |
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> |
| 54 | |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 55 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 56 | #define PMIC_ARB_OWNER_ID 0 |
| 57 | |
| 58 | #define FASTBOOT_MODE 0x77665500 |
| 59 | |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame^] | 60 | static void set_sdc_power_ctrl(void); |
| 61 | |
| 62 | static uint32_t mmc_pwrctl_base[] = |
| 63 | { MSM_SDC1_BASE, MSM_SDC2_BASE }; |
| 64 | |
| 65 | static uint32_t mmc_sdhci_base[] = |
| 66 | { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE }; |
| 67 | |
| 68 | static uint32_t mmc_sdc_pwrctl_irq[] = |
| 69 | { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ }; |
| 70 | |
| 71 | struct mmc_device *dev; |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 72 | |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 73 | extern void ulpi_write(unsigned val, unsigned reg); |
| 74 | |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 75 | void target_early_init(void) |
| 76 | { |
| 77 | #if WITH_DEBUG_UART |
Sundarajan Srinivasan | 4a20470 | 2013-08-12 18:10:17 -0700 | [diff] [blame] | 78 | uart_dm_init(2, 0, BLSP1_UART1_BASE); |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 79 | #endif |
| 80 | } |
| 81 | |
| 82 | /* Return 1 if vol_up pressed */ |
| 83 | static int target_volume_up() |
| 84 | { |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 85 | uint8_t status = 0; |
| 86 | struct pm8x41_gpio gpio; |
| 87 | |
| 88 | /* Configure the GPIO */ |
| 89 | gpio.direction = PM_GPIO_DIR_IN; |
| 90 | gpio.function = 0; |
| 91 | gpio.pull = PM_GPIO_PULL_UP_30; |
| 92 | gpio.vin_sel = 2; |
| 93 | |
| 94 | pm8x41_gpio_config(2, &gpio); |
| 95 | |
| 96 | /* Get status of P_GPIO_2 */ |
| 97 | pm8x41_gpio_get(2, &status); |
| 98 | |
| 99 | return !status; /* active low */ |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /* Return 1 if vol_down pressed */ |
| 103 | uint32_t target_volume_down() |
| 104 | { |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 105 | return pm8x41_resin_status(); |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static void target_keystatus() |
| 109 | { |
| 110 | keys_init(); |
| 111 | |
| 112 | if(target_volume_down()) |
| 113 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 114 | |
| 115 | if(target_volume_up()) |
| 116 | keys_post_event(KEY_VOLUMEUP, 1); |
| 117 | } |
| 118 | |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 119 | /* Do target specific usb initialization */ |
| 120 | void target_usb_init(void) |
| 121 | { |
| 122 | uint32_t val; |
| 123 | |
| 124 | /* Select and enable external configuration with USB PHY */ |
| 125 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET); |
| 126 | |
| 127 | /* Enable sess_vld */ |
| 128 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 129 | writel(val, USB_GENCONFIG_2); |
| 130 | |
| 131 | /* Enable external vbus configuration in the LINK */ |
| 132 | val = readl(USB_USBCMD); |
| 133 | val |= SESS_VLD_CTRL; |
| 134 | writel(val, USB_USBCMD); |
| 135 | } |
| 136 | |
| 137 | void target_usb_stop(void) |
| 138 | { |
| 139 | /* Disable VBUS mimicing in the controller. */ |
| 140 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR); |
| 141 | } |
| 142 | |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 143 | static void set_sdc_power_ctrl() |
| 144 | { |
| 145 | /* Drive strength configs for sdc pins */ |
| 146 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 147 | { |
| 148 | { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK }, |
| 149 | { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK }, |
| 150 | { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK }, |
| 151 | }; |
| 152 | |
| 153 | /* Pull configs for sdc pins */ |
| 154 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 155 | { |
| 156 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK }, |
| 157 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
| 158 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
| 159 | }; |
| 160 | |
| 161 | /* Set the drive strength & pull control values */ |
| 162 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 163 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
| 164 | } |
| 165 | |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame^] | 166 | void target_sdc_init() |
| 167 | { |
| 168 | struct mmc_config_data config; |
| 169 | |
| 170 | /* Set drive strength & pull ctrl values */ |
| 171 | set_sdc_power_ctrl(); |
| 172 | |
| 173 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
| 174 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 175 | |
| 176 | /* Try slot 1*/ |
| 177 | config.slot = 1; |
| 178 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 179 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 180 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 181 | |
| 182 | if (!(dev = mmc_init(&config))) |
| 183 | { |
| 184 | /* Try slot 2 */ |
| 185 | config.slot = 2; |
| 186 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 187 | config.pwrctl_base = mmc_pwrctl_base[config.slot - 1]; |
| 188 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 189 | |
| 190 | if (!(dev = mmc_init(&config))) |
| 191 | { |
| 192 | dprintf(CRITICAL, "mmc init failed!"); |
| 193 | ASSERT(0); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /* MMC initialization is complete, read the partition table info */ |
| 198 | if (partition_read_table()) |
| 199 | { |
| 200 | dprintf(CRITICAL, "Error reading the partition table info\n"); |
| 201 | ASSERT(0); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | struct mmc_device *target_mmc_device() |
| 206 | { |
| 207 | return dev; |
| 208 | } |
| 209 | |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 210 | void target_init(void) |
| 211 | { |
| 212 | dprintf(INFO, "target_init()\n"); |
| 213 | |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 214 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 215 | |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 216 | target_keystatus(); |
| 217 | |
Sundarajan Srinivasan | f7ef47f | 2013-09-05 17:46:24 -0700 | [diff] [blame^] | 218 | target_sdc_init(); |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | unsigned board_machtype(void) |
| 222 | { |
| 223 | return LINUX_MACHTYPE_UNKNOWN; |
| 224 | } |
| 225 | |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 226 | /* Detect the target type */ |
| 227 | void target_detect(struct board_data *board) |
| 228 | { |
| 229 | board->target = LINUX_MACHTYPE_UNKNOWN; |
| 230 | } |
| 231 | |
| 232 | /* Detect the modem type */ |
| 233 | void target_baseband_detect(struct board_data *board) |
| 234 | { |
Sundarajan Srinivasan | f5932fb | 2013-08-06 17:26:04 -0700 | [diff] [blame] | 235 | uint32_t platform; |
| 236 | uint32_t platform_subtype; |
| 237 | |
| 238 | platform = board->platform; |
| 239 | platform_subtype = board->platform_subtype; |
| 240 | |
| 241 | /* |
| 242 | * Look for platform subtype if present, else |
| 243 | * check for platform type to decide on the |
| 244 | * baseband type |
| 245 | */ |
| 246 | switch(platform_subtype) { |
| 247 | case HW_PLATFORM_SUBTYPE_UNKNOWN: |
| 248 | break; |
| 249 | |
| 250 | default: |
| 251 | dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype); |
| 252 | ASSERT(0); |
| 253 | }; |
| 254 | |
| 255 | switch(platform) { |
| 256 | case APQ8084: |
| 257 | board->baseband = BASEBAND_APQ; |
| 258 | break; |
| 259 | default: |
| 260 | dprintf(CRITICAL, "Platform type: %u is not supported\n",platform); |
| 261 | ASSERT(0); |
| 262 | } |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | unsigned target_baseband() |
| 266 | { |
| 267 | return board_baseband(); |
| 268 | } |
| 269 | |
| 270 | void target_serialno(unsigned char *buf) |
| 271 | { |
| 272 | unsigned int serialno; |
| 273 | if (target_is_emmc_boot()) { |
| 274 | serialno = mmc_get_psn(); |
| 275 | snprintf((char *)buf, 13, "%x", serialno); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | unsigned check_reboot_mode(void) |
| 280 | { |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 281 | uint32_t restart_reason = 0; |
| 282 | uint32_t restart_reason_addr; |
| 283 | |
| 284 | restart_reason_addr = RESTART_REASON_ADDR; |
| 285 | |
| 286 | /* Read reboot reason and scrub it */ |
| 287 | restart_reason = readl(restart_reason_addr); |
| 288 | writel(0x00, restart_reason_addr); |
| 289 | |
| 290 | return restart_reason; |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | void reboot_device(unsigned reboot_reason) |
| 294 | { |
Sundarajan Srinivasan | d43b28b | 2013-06-25 16:59:13 -0700 | [diff] [blame] | 295 | uint8_t reset_type = 0; |
| 296 | |
| 297 | /* Write the reboot reason */ |
| 298 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 299 | |
| 300 | if(reboot_reason == FASTBOOT_MODE) |
| 301 | reset_type = PON_PSHOLD_WARM_RESET; |
| 302 | else |
| 303 | reset_type = PON_PSHOLD_HARD_RESET; |
| 304 | |
| 305 | pm8x41_reset_configure(reset_type); |
| 306 | |
| 307 | /* Drop PS_HOLD for MSM */ |
| 308 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 309 | |
| 310 | mdelay(5000); |
| 311 | |
| 312 | dprintf(CRITICAL, "Rebooting failed\n"); |
Deepa Dinamani | 0e5038f | 2013-05-16 15:02:16 -0700 | [diff] [blame] | 313 | } |