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> |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 44 | |
| 45 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 46 | #define PMIC_ARB_OWNER_ID 0 |
| 47 | |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 48 | #define TLMM_VOL_UP_BTN_GPIO 72 |
| 49 | |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 50 | static uint32_t mmc_sdc_base[] = |
| 51 | { MSM_SDC1_BASE, MSM_SDC2_BASE }; |
| 52 | |
| 53 | void target_early_init(void) |
| 54 | { |
| 55 | #if WITH_DEBUG_UART |
Deepa Dinamani | d1823b4 | 2013-03-21 11:49:35 -0700 | [diff] [blame] | 56 | uart_dm_init(2, 0, BLSP1_UART1_BASE); |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 57 | #endif |
| 58 | } |
| 59 | |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 60 | /* Return 1 if vol_up pressed */ |
| 61 | static int target_volume_up() |
| 62 | { |
| 63 | uint8_t status = 0; |
| 64 | |
| 65 | gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE); |
| 66 | |
| 67 | /* Get status of GPIO */ |
| 68 | status = gpio_status(TLMM_VOL_UP_BTN_GPIO); |
| 69 | |
| 70 | /* Active low signal. */ |
| 71 | return !status; |
| 72 | } |
| 73 | |
| 74 | /* Return 1 if vol_down pressed */ |
| 75 | uint32_t target_volume_down() |
| 76 | { |
| 77 | /* Volume down button tied in with PMIC RESIN. */ |
| 78 | return pm8x41_resin_status(); |
| 79 | } |
| 80 | |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 81 | static void target_keystatus() |
| 82 | { |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 83 | keys_init(); |
| 84 | |
| 85 | if(target_volume_down()) |
| 86 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 87 | |
| 88 | if(target_volume_up()) |
| 89 | keys_post_event(KEY_VOLUMEUP, 1); |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void target_init(void) |
| 93 | { |
| 94 | uint32_t base_addr; |
| 95 | uint8_t slot; |
| 96 | |
| 97 | dprintf(INFO, "target_init()\n"); |
| 98 | |
| 99 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 100 | |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 101 | target_keystatus(); |
| 102 | |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 103 | /* Trying Slot 1*/ |
| 104 | slot = 1; |
| 105 | base_addr = mmc_sdc_base[slot - 1]; |
| 106 | |
| 107 | if (mmc_boot_main(slot, base_addr)) |
| 108 | { |
| 109 | /* Trying Slot 2 next */ |
| 110 | slot = 2; |
| 111 | base_addr = mmc_sdc_base[slot - 1]; |
| 112 | |
| 113 | if (mmc_boot_main(slot, base_addr)) |
| 114 | { |
| 115 | dprintf(CRITICAL, "mmc init failed!"); |
| 116 | ASSERT(0); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
Deepa Dinamani | 2b795bb | 2013-03-25 11:31:58 -0700 | [diff] [blame] | 121 | /* Do any target specific intialization needed before entering fastboot mode */ |
| 122 | void target_fastboot_init(void) |
| 123 | { |
| 124 | /* Set the BOOT_DONE flag in PM8110 */ |
| 125 | pm8x41_set_boot_done(); |
| 126 | } |
| 127 | |
Deepa Dinamani | 41803e0 | 2013-03-25 11:44:15 -0700 | [diff] [blame] | 128 | /* Detect the target type */ |
| 129 | void target_detect(struct board_data *board) |
| 130 | { |
| 131 | board->target = LINUX_MACHTYPE_UNKNOWN; |
| 132 | } |
| 133 | |
| 134 | /* Detect the modem type */ |
| 135 | void target_baseband_detect(struct board_data *board) |
| 136 | { |
| 137 | uint32_t platform; |
| 138 | uint32_t platform_subtype; |
| 139 | |
| 140 | platform = board->platform; |
| 141 | platform_subtype = board->platform_subtype; |
| 142 | |
| 143 | /* |
| 144 | * Look for platform subtype if present, else |
| 145 | * check for platform type to decide on the |
| 146 | * baseband type |
| 147 | */ |
| 148 | switch(platform_subtype) |
| 149 | { |
| 150 | case HW_PLATFORM_SUBTYPE_UNKNOWN: |
| 151 | break; |
| 152 | default: |
| 153 | dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype); |
| 154 | ASSERT(0); |
| 155 | }; |
| 156 | |
| 157 | switch(platform) |
| 158 | { |
| 159 | case MSM8610: |
| 160 | case MSM8110: |
| 161 | case MSM8210: |
| 162 | case MSM8810: |
Deepa Dinamani | 39345cd | 2013-04-08 19:46:53 -0700 | [diff] [blame^] | 163 | case MSM8612: |
Deepa Dinamani | 41803e0 | 2013-03-25 11:44:15 -0700 | [diff] [blame] | 164 | board->baseband = BASEBAND_MSM; |
| 165 | break; |
| 166 | default: |
| 167 | dprintf(CRITICAL, "Platform type: %u is not supported\n", platform); |
| 168 | ASSERT(0); |
| 169 | }; |
| 170 | } |
| 171 | |
| 172 | unsigned target_baseband() |
| 173 | { |
| 174 | return board_baseband(); |
| 175 | } |
| 176 | |
Deepa Dinamani | a6d1b75 | 2013-03-25 11:47:20 -0700 | [diff] [blame] | 177 | void target_serialno(unsigned char *buf) |
| 178 | { |
| 179 | uint32_t serialno; |
| 180 | if (target_is_emmc_boot()) { |
| 181 | serialno = mmc_get_psn(); |
| 182 | snprintf((char *)buf, 13, "%x", serialno); |
| 183 | } |
| 184 | } |
| 185 | |
Deepa Dinamani | 5390e10 | 2013-03-25 11:55:31 -0700 | [diff] [blame] | 186 | unsigned check_reboot_mode(void) |
| 187 | { |
| 188 | uint32_t restart_reason = 0; |
| 189 | |
| 190 | /* Read reboot reason and scrub it */ |
| 191 | restart_reason = readl(RESTART_REASON_ADDR); |
| 192 | writel(0x00, RESTART_REASON_ADDR); |
| 193 | |
| 194 | return restart_reason; |
| 195 | } |
| 196 | |
Deepa Dinamani | 172b7e6 | 2013-03-25 11:59:21 -0700 | [diff] [blame] | 197 | void reboot_device(unsigned reboot_reason) |
| 198 | { |
| 199 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 200 | |
| 201 | /* Configure PMIC for warm reset */ |
| 202 | pm8x41_reset_configure(PON_PSHOLD_WARM_RESET); |
| 203 | |
| 204 | /* Drop PS_HOLD for MSM */ |
| 205 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 206 | |
| 207 | mdelay(5000); |
| 208 | |
| 209 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 210 | } |
| 211 | |
Deepa Dinamani | 004eb32 | 2013-03-25 13:20:50 -0700 | [diff] [blame] | 212 | unsigned target_pause_for_battery_charge(void) |
| 213 | { |
| 214 | uint8_t pon_reason = pm8x41_get_pon_reason(); |
| 215 | |
| 216 | /* This function will always return 0 to facilitate |
| 217 | * automated testing/reboot with usb connected. |
| 218 | * uncomment if this feature is needed. |
| 219 | */ |
| 220 | /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG)) |
| 221 | * return 1; |
| 222 | */ |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
Deepa Dinamani | 98cf8ee | 2013-03-27 15:16:47 -0700 | [diff] [blame] | 227 | void target_usb_stop(void) |
| 228 | { |
| 229 | /* Disable VBUS mimicing in the controller. */ |
| 230 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR); |
| 231 | } |
| 232 | |
| 233 | void target_usb_init(void) |
| 234 | { |
| 235 | uint32_t val; |
| 236 | |
| 237 | /* Select and enable external configuration with USB PHY */ |
| 238 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET); |
| 239 | |
| 240 | /* Enable sess_vld */ |
| 241 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 242 | writel(val, USB_GENCONFIG_2); |
| 243 | |
| 244 | /* Enable external vbus configuration in the LINK */ |
| 245 | val = readl(USB_USBCMD); |
| 246 | val |= SESS_VLD_CTRL; |
| 247 | writel(val, USB_USBCMD); |
| 248 | } |
| 249 | |
| 250 | |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 251 | unsigned board_machtype(void) |
| 252 | { |
Deepa Dinamani | 2b795bb | 2013-03-25 11:31:58 -0700 | [diff] [blame] | 253 | return 0; |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 254 | } |