Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [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> |
| 31 | #include <reg.h> |
| 32 | #include <target.h> |
| 33 | #include <platform.h> |
| 34 | #include <uart_dm.h> |
| 35 | #include <mmc.h> |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 36 | #include <platform/gpio.h> |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 37 | #include <spmi.h> |
| 38 | #include <board.h> |
Deepa Dinamani | 41803e0 | 2013-03-25 11:44:15 -0700 | [diff] [blame] | 39 | #include <smem.h> |
| 40 | #include <baseband.h> |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 41 | #include <dev/keys.h> |
| 42 | #include <pm8x41.h> |
Deepa Dinamani | 98cf8ee | 2013-03-27 15:16:47 -0700 | [diff] [blame] | 43 | #include <hsusb.h> |
richardl | b52d3f5 | 2013-04-12 17:37:28 -0700 | [diff] [blame] | 44 | #include <kernel/thread.h> |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 45 | |
| 46 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 47 | #define PMIC_ARB_OWNER_ID 0 |
| 48 | |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 49 | #define TLMM_VOL_UP_BTN_GPIO 72 |
| 50 | |
Maria Yu | 00fd382 | 2013-06-26 10:12:54 +0800 | [diff] [blame] | 51 | enum target_subtype { |
| 52 | HW_PLATFORM_SUBTYPE_SKUAA = 1, |
| 53 | HW_PLATFORM_SUBTYPE_SKUF = 2, |
| 54 | HW_PLATFORM_SUBTYPE_SKUAB = 3, |
| 55 | }; |
| 56 | |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 57 | static uint32_t mmc_sdc_base[] = |
| 58 | { MSM_SDC1_BASE, MSM_SDC2_BASE }; |
| 59 | |
| 60 | void target_early_init(void) |
| 61 | { |
| 62 | #if WITH_DEBUG_UART |
Deepa Dinamani | d1823b4 | 2013-03-21 11:49:35 -0700 | [diff] [blame] | 63 | uart_dm_init(2, 0, BLSP1_UART1_BASE); |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 64 | #endif |
| 65 | } |
| 66 | |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 67 | /* Return 1 if vol_up pressed */ |
| 68 | static int target_volume_up() |
| 69 | { |
| 70 | uint8_t status = 0; |
| 71 | |
| 72 | gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE); |
| 73 | |
richardl | b52d3f5 | 2013-04-12 17:37:28 -0700 | [diff] [blame] | 74 | /* Wait for the configuration to complete.*/ |
| 75 | thread_sleep(1); |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 76 | /* Get status of GPIO */ |
| 77 | status = gpio_status(TLMM_VOL_UP_BTN_GPIO); |
| 78 | |
| 79 | /* Active low signal. */ |
| 80 | return !status; |
| 81 | } |
| 82 | |
| 83 | /* Return 1 if vol_down pressed */ |
| 84 | uint32_t target_volume_down() |
| 85 | { |
| 86 | /* Volume down button tied in with PMIC RESIN. */ |
| 87 | return pm8x41_resin_status(); |
| 88 | } |
| 89 | |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 90 | static void target_keystatus() |
| 91 | { |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 92 | keys_init(); |
| 93 | |
| 94 | if(target_volume_down()) |
| 95 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 96 | |
| 97 | if(target_volume_up()) |
| 98 | keys_post_event(KEY_VOLUMEUP, 1); |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void target_init(void) |
| 102 | { |
| 103 | uint32_t base_addr; |
| 104 | uint8_t slot; |
| 105 | |
| 106 | dprintf(INFO, "target_init()\n"); |
| 107 | |
| 108 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 109 | |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 110 | target_keystatus(); |
| 111 | |
Terence Hampson | afded26 | 2013-06-18 14:48:18 -0400 | [diff] [blame] | 112 | /* Display splash screen if enabled */ |
| 113 | dprintf(SPEW, "Display Init: Start\n"); |
| 114 | display_init(); |
| 115 | dprintf(SPEW, "Display Init: Done\n"); |
| 116 | |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 117 | /* Trying Slot 1*/ |
| 118 | slot = 1; |
| 119 | base_addr = mmc_sdc_base[slot - 1]; |
| 120 | |
| 121 | if (mmc_boot_main(slot, base_addr)) |
| 122 | { |
| 123 | /* Trying Slot 2 next */ |
| 124 | slot = 2; |
| 125 | base_addr = mmc_sdc_base[slot - 1]; |
| 126 | |
| 127 | if (mmc_boot_main(slot, base_addr)) |
| 128 | { |
| 129 | dprintf(CRITICAL, "mmc init failed!"); |
| 130 | ASSERT(0); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
Deepa Dinamani | 2b795bb | 2013-03-25 11:31:58 -0700 | [diff] [blame] | 135 | /* Do any target specific intialization needed before entering fastboot mode */ |
| 136 | void target_fastboot_init(void) |
| 137 | { |
| 138 | /* Set the BOOT_DONE flag in PM8110 */ |
| 139 | pm8x41_set_boot_done(); |
| 140 | } |
| 141 | |
Deepa Dinamani | 41803e0 | 2013-03-25 11:44:15 -0700 | [diff] [blame] | 142 | /* Detect the target type */ |
| 143 | void target_detect(struct board_data *board) |
| 144 | { |
Maria Yu | ca51ee2 | 2013-06-27 21:45:24 +0800 | [diff] [blame] | 145 | /* |
| 146 | * already fill the board->target on board.c |
| 147 | */ |
| 148 | |
Deepa Dinamani | 41803e0 | 2013-03-25 11:44:15 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /* Detect the modem type */ |
| 152 | void target_baseband_detect(struct board_data *board) |
| 153 | { |
| 154 | uint32_t platform; |
| 155 | uint32_t platform_subtype; |
| 156 | |
| 157 | platform = board->platform; |
| 158 | platform_subtype = board->platform_subtype; |
| 159 | |
| 160 | /* |
| 161 | * Look for platform subtype if present, else |
| 162 | * check for platform type to decide on the |
| 163 | * baseband type |
| 164 | */ |
| 165 | switch(platform_subtype) |
| 166 | { |
| 167 | case HW_PLATFORM_SUBTYPE_UNKNOWN: |
| 168 | break; |
Maria Yu | 00fd382 | 2013-06-26 10:12:54 +0800 | [diff] [blame] | 169 | case HW_PLATFORM_SUBTYPE_SKUAA: |
| 170 | break; |
| 171 | case HW_PLATFORM_SUBTYPE_SKUF: |
| 172 | break; |
| 173 | case HW_PLATFORM_SUBTYPE_SKUAB: |
| 174 | break; |
Deepa Dinamani | 41803e0 | 2013-03-25 11:44:15 -0700 | [diff] [blame] | 175 | default: |
| 176 | dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype); |
| 177 | ASSERT(0); |
| 178 | }; |
| 179 | |
| 180 | switch(platform) |
| 181 | { |
| 182 | case MSM8610: |
| 183 | case MSM8110: |
| 184 | case MSM8210: |
| 185 | case MSM8810: |
Deepa Dinamani | 39345cd | 2013-04-08 19:46:53 -0700 | [diff] [blame] | 186 | case MSM8612: |
David Ng | 2de1806 | 2013-04-19 20:22:16 -0700 | [diff] [blame] | 187 | case MSM8212: |
| 188 | case MSM8812: |
Deepa Dinamani | 41803e0 | 2013-03-25 11:44:15 -0700 | [diff] [blame] | 189 | board->baseband = BASEBAND_MSM; |
| 190 | break; |
| 191 | default: |
| 192 | dprintf(CRITICAL, "Platform type: %u is not supported\n", platform); |
| 193 | ASSERT(0); |
| 194 | }; |
| 195 | } |
| 196 | |
| 197 | unsigned target_baseband() |
| 198 | { |
| 199 | return board_baseband(); |
| 200 | } |
| 201 | |
Deepa Dinamani | a6d1b75 | 2013-03-25 11:47:20 -0700 | [diff] [blame] | 202 | void target_serialno(unsigned char *buf) |
| 203 | { |
| 204 | uint32_t serialno; |
| 205 | if (target_is_emmc_boot()) { |
| 206 | serialno = mmc_get_psn(); |
| 207 | snprintf((char *)buf, 13, "%x", serialno); |
| 208 | } |
| 209 | } |
| 210 | |
Deepa Dinamani | 5390e10 | 2013-03-25 11:55:31 -0700 | [diff] [blame] | 211 | unsigned check_reboot_mode(void) |
| 212 | { |
| 213 | uint32_t restart_reason = 0; |
| 214 | |
| 215 | /* Read reboot reason and scrub it */ |
| 216 | restart_reason = readl(RESTART_REASON_ADDR); |
| 217 | writel(0x00, RESTART_REASON_ADDR); |
| 218 | |
| 219 | return restart_reason; |
| 220 | } |
| 221 | |
Deepa Dinamani | 172b7e6 | 2013-03-25 11:59:21 -0700 | [diff] [blame] | 222 | void reboot_device(unsigned reboot_reason) |
| 223 | { |
| 224 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 225 | |
| 226 | /* Configure PMIC for warm reset */ |
| 227 | pm8x41_reset_configure(PON_PSHOLD_WARM_RESET); |
| 228 | |
| 229 | /* Drop PS_HOLD for MSM */ |
| 230 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 231 | |
| 232 | mdelay(5000); |
| 233 | |
| 234 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 235 | } |
| 236 | |
Terence Hampson | afded26 | 2013-06-18 14:48:18 -0400 | [diff] [blame] | 237 | int target_cont_splash_screen() |
| 238 | { |
| 239 | int ret = 0; |
| 240 | switch(board_hardware_id()) |
| 241 | { |
| 242 | case HW_PLATFORM_MTP: |
| 243 | case HW_PLATFORM_QRD: |
| 244 | case HW_PLATFORM_SURF: |
| 245 | dprintf(SPEW, "Target_cont_splash=0\n"); |
| 246 | ret = 0; |
| 247 | default: |
| 248 | dprintf(SPEW, "Target_cont_splash=0\n"); |
| 249 | ret = 0; |
| 250 | } |
| 251 | return ret; |
| 252 | } |
| 253 | |
Deepa Dinamani | 004eb32 | 2013-03-25 13:20:50 -0700 | [diff] [blame] | 254 | unsigned target_pause_for_battery_charge(void) |
| 255 | { |
| 256 | uint8_t pon_reason = pm8x41_get_pon_reason(); |
Xu Kai | c2e0afc | 2013-07-19 13:26:36 +0800 | [diff] [blame^] | 257 | uint8_t is_cold_boot = pm8x41_get_is_cold_boot(); |
| 258 | dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__, |
| 259 | pon_reason, is_cold_boot); |
| 260 | /*In case of fastboot reboot, adb reboot or if we see the power key |
| 261 | * pressed we do not want go into charger mode. |
| 262 | * fastboot reboot is warm boot with PON hard reset bit not set |
| 263 | * adb reboot is a cold boot with PON hard reset bit set |
Deepa Dinamani | 004eb32 | 2013-03-25 13:20:50 -0700 | [diff] [blame] | 264 | */ |
Xu Kai | c2e0afc | 2013-07-19 13:26:36 +0800 | [diff] [blame^] | 265 | if (is_cold_boot && |
| 266 | (!(pon_reason & HARD_RST)) && |
| 267 | (!(pon_reason & KPDPWR_N)) && |
| 268 | ((pon_reason & USB_CHG) || (pon_reason & DC_CHG))) |
| 269 | return 1; |
| 270 | else |
| 271 | return 0; |
Deepa Dinamani | 004eb32 | 2013-03-25 13:20:50 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Deepa Dinamani | 98cf8ee | 2013-03-27 15:16:47 -0700 | [diff] [blame] | 274 | void target_usb_stop(void) |
| 275 | { |
| 276 | /* Disable VBUS mimicing in the controller. */ |
| 277 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR); |
| 278 | } |
| 279 | |
| 280 | void target_usb_init(void) |
| 281 | { |
| 282 | uint32_t val; |
| 283 | |
| 284 | /* Select and enable external configuration with USB PHY */ |
| 285 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET); |
| 286 | |
| 287 | /* Enable sess_vld */ |
| 288 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 289 | writel(val, USB_GENCONFIG_2); |
| 290 | |
| 291 | /* Enable external vbus configuration in the LINK */ |
| 292 | val = readl(USB_USBCMD); |
| 293 | val |= SESS_VLD_CTRL; |
| 294 | writel(val, USB_USBCMD); |
| 295 | } |
| 296 | |
| 297 | |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 298 | unsigned board_machtype(void) |
| 299 | { |
Deepa Dinamani | 2b795bb | 2013-03-25 11:31:58 -0700 | [diff] [blame] | 300 | return 0; |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 301 | } |
Channagoud Kadabi | e1b7526 | 2013-05-08 12:58:39 -0700 | [diff] [blame] | 302 | |
| 303 | /* |
| 304 | * Function to set the capabilities for the host |
| 305 | */ |
| 306 | void target_mmc_caps(struct mmc_host *host) |
| 307 | { |
| 308 | host->caps.ddr_mode = 0; |
| 309 | host->caps.hs200_mode = 0; |
| 310 | host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT; |
| 311 | host->caps.hs_clk_rate = MMC_CLK_50MHZ; |
| 312 | } |