Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-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 | 7e72977 | 2013-02-25 11:54:05 -0800 | [diff] [blame] | 36 | #include <platform/gpio.h> |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 37 | #include <spmi.h> |
| 38 | #include <board.h> |
Deepa Dinamani | ff2b9ce | 2013-02-25 11:01:00 -0800 | [diff] [blame] | 39 | #include <smem.h> |
| 40 | #include <baseband.h> |
Deepa Dinamani | 7e72977 | 2013-02-25 11:54:05 -0800 | [diff] [blame] | 41 | #include <dev/keys.h> |
Deepa Dinamani | 058f1cd | 2013-02-25 10:53:01 -0800 | [diff] [blame] | 42 | #include <pm8x41.h> |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 43 | #include <crypto5_wrapper.h> |
Amol Jadi | 85e1919 | 2013-02-28 22:45:04 -0800 | [diff] [blame^] | 44 | #include <hsusb.h> |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 45 | |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 46 | extern bool target_use_signed_kernel(void); |
| 47 | |
| 48 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 49 | #define PMIC_ARB_OWNER_ID 0 |
| 50 | |
| 51 | #define CRYPTO_ENGINE_INSTANCE 1 |
| 52 | #define CRYPTO_ENGINE_EE 1 |
| 53 | #define CRYPTO_ENGINE_FIFO_SIZE 64 |
| 54 | #define CRYPTO_ENGINE_READ_PIPE 3 |
| 55 | #define CRYPTO_ENGINE_WRITE_PIPE 2 |
| 56 | #define CRYPTO_ENGINE_CMD_ARRAY_SIZE 20 |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 57 | |
Deepa Dinamani | 7e72977 | 2013-02-25 11:54:05 -0800 | [diff] [blame] | 58 | #define TLMM_VOL_UP_BTN_GPIO 106 |
| 59 | |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 60 | static uint32_t mmc_sdc_base[] = |
Deepa Dinamani | 7c79d7d | 2013-02-08 13:47:08 -0800 | [diff] [blame] | 61 | { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE }; |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 62 | |
| 63 | void target_early_init(void) |
| 64 | { |
| 65 | #if WITH_DEBUG_UART |
Deepa Dinamani | 0a6c48c | 2013-02-04 15:45:01 -0800 | [diff] [blame] | 66 | uart_dm_init(1, 0, BLSP1_UART2_BASE); |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 67 | #endif |
| 68 | } |
| 69 | |
Deepa Dinamani | 7e72977 | 2013-02-25 11:54:05 -0800 | [diff] [blame] | 70 | /* Return 1 if vol_up pressed */ |
| 71 | static int target_volume_up() |
| 72 | { |
| 73 | uint8_t status = 0; |
| 74 | |
| 75 | gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE); |
| 76 | |
aiquny | 933017c | 2013-03-02 12:48:52 -0800 | [diff] [blame] | 77 | thread_sleep(10); |
| 78 | |
Deepa Dinamani | 7e72977 | 2013-02-25 11:54:05 -0800 | [diff] [blame] | 79 | /* Get status of GPIO */ |
| 80 | status = gpio_status(TLMM_VOL_UP_BTN_GPIO); |
| 81 | |
| 82 | /* Active low signal. */ |
| 83 | return !status; |
| 84 | } |
| 85 | |
| 86 | /* Return 1 if vol_down pressed */ |
| 87 | uint32_t target_volume_down() |
| 88 | { |
| 89 | /* Volume down button tied in with PMIC RESIN. */ |
| 90 | return pm8x41_resin_status(); |
| 91 | } |
| 92 | |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 93 | static void target_keystatus() |
| 94 | { |
Deepa Dinamani | 7e72977 | 2013-02-25 11:54:05 -0800 | [diff] [blame] | 95 | keys_init(); |
| 96 | |
| 97 | if(target_volume_down()) |
| 98 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 99 | |
| 100 | if(target_volume_up()) |
| 101 | keys_post_event(KEY_VOLUMEUP, 1); |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 104 | /* Set up params for h/w CRYPTO_ENGINE. */ |
| 105 | void target_crypto_init_params() |
| 106 | { |
| 107 | struct crypto_init_params ce_params; |
| 108 | |
| 109 | /* Set up base addresses and instance. */ |
| 110 | ce_params.crypto_instance = CRYPTO_ENGINE_INSTANCE; |
| 111 | ce_params.crypto_base = MSM_CE1_BASE; |
| 112 | ce_params.bam_base = MSM_CE1_BAM_BASE; |
| 113 | |
| 114 | /* Set up BAM config. */ |
| 115 | ce_params.bam_ee = CRYPTO_ENGINE_EE; |
| 116 | ce_params.pipes.read_pipe = CRYPTO_ENGINE_READ_PIPE; |
| 117 | ce_params.pipes.write_pipe = CRYPTO_ENGINE_WRITE_PIPE; |
| 118 | |
| 119 | /* Assign buffer sizes. */ |
| 120 | ce_params.num_ce = CRYPTO_ENGINE_CMD_ARRAY_SIZE; |
| 121 | ce_params.read_fifo_size = CRYPTO_ENGINE_FIFO_SIZE; |
| 122 | ce_params.write_fifo_size = CRYPTO_ENGINE_FIFO_SIZE; |
| 123 | |
| 124 | crypto_init_params(&ce_params); |
| 125 | } |
| 126 | |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 127 | void target_init(void) |
| 128 | { |
| 129 | uint32_t base_addr; |
| 130 | uint8_t slot; |
| 131 | |
| 132 | dprintf(INFO, "target_init()\n"); |
| 133 | |
| 134 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 135 | |
| 136 | target_keystatus(); |
| 137 | |
| 138 | /* Trying Slot 1*/ |
| 139 | slot = 1; |
| 140 | base_addr = mmc_sdc_base[slot - 1]; |
| 141 | if (mmc_boot_main(slot, base_addr)) |
| 142 | { |
| 143 | |
| 144 | /* Trying Slot 2 next */ |
| 145 | slot = 2; |
| 146 | base_addr = mmc_sdc_base[slot - 1]; |
| 147 | if (mmc_boot_main(slot, base_addr)) { |
| 148 | dprintf(CRITICAL, "mmc init failed!"); |
| 149 | ASSERT(0); |
| 150 | } |
| 151 | } |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 152 | |
| 153 | if (target_use_signed_kernel()) |
| 154 | target_crypto_init_params(); |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 155 | } |
| 156 | |
Deepa Dinamani | 058f1cd | 2013-02-25 10:53:01 -0800 | [diff] [blame] | 157 | /* Do any target specific intialization needed before entering fastboot mode */ |
| 158 | void target_fastboot_init(void) |
| 159 | { |
| 160 | /* Set the BOOT_DONE flag in PM8026 */ |
| 161 | pm8x41_set_boot_done(); |
| 162 | } |
| 163 | |
Deepa Dinamani | ff2b9ce | 2013-02-25 11:01:00 -0800 | [diff] [blame] | 164 | /* Detect the target type */ |
| 165 | void target_detect(struct board_data *board) |
| 166 | { |
| 167 | board->target = LINUX_MACHTYPE_UNKNOWN; |
| 168 | } |
| 169 | |
| 170 | /* Detect the modem type */ |
| 171 | void target_baseband_detect(struct board_data *board) |
| 172 | { |
| 173 | uint32_t platform; |
| 174 | uint32_t platform_subtype; |
| 175 | |
| 176 | platform = board->platform; |
| 177 | platform_subtype = board->platform_subtype; |
| 178 | |
| 179 | /* |
| 180 | * Look for platform subtype if present, else |
| 181 | * check for platform type to decide on the |
| 182 | * baseband type |
| 183 | */ |
| 184 | switch(platform_subtype) |
| 185 | { |
| 186 | case HW_PLATFORM_SUBTYPE_UNKNOWN: |
| 187 | break; |
| 188 | default: |
| 189 | dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype); |
| 190 | ASSERT(0); |
| 191 | }; |
| 192 | |
| 193 | switch(platform) |
| 194 | { |
| 195 | case MSM8826: |
| 196 | case MSM8626: |
| 197 | case MSM8226: |
| 198 | board->baseband = BASEBAND_MSM; |
| 199 | break; |
| 200 | default: |
| 201 | dprintf(CRITICAL, "Platform type: %u is not supported\n", platform); |
| 202 | ASSERT(0); |
| 203 | }; |
| 204 | } |
| 205 | |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 206 | void target_serialno(unsigned char *buf) |
| 207 | { |
| 208 | uint32_t serialno; |
| 209 | if (target_is_emmc_boot()) { |
| 210 | serialno = mmc_get_psn(); |
| 211 | snprintf((char *)buf, 13, "%x", serialno); |
| 212 | } |
| 213 | } |
| 214 | |
Deepa Dinamani | 8d2bb22 | 2013-02-26 14:03:04 -0800 | [diff] [blame] | 215 | unsigned check_reboot_mode(void) |
| 216 | { |
| 217 | uint32_t restart_reason = 0; |
| 218 | |
| 219 | /* Read reboot reason and scrub it */ |
| 220 | restart_reason = readl(RESTART_REASON_ADDR); |
| 221 | writel(0x00, RESTART_REASON_ADDR); |
| 222 | |
| 223 | return restart_reason; |
| 224 | } |
| 225 | |
Deepa Dinamani | f7c03c1 | 2013-02-26 14:17:20 -0800 | [diff] [blame] | 226 | void reboot_device(unsigned reboot_reason) |
| 227 | { |
| 228 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 229 | |
| 230 | /* Configure PMIC for warm reset */ |
| 231 | pm8x41_reset_configure(PON_PSHOLD_WARM_RESET); |
| 232 | |
| 233 | /* Drop PS_HOLD for MSM */ |
| 234 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 235 | |
| 236 | mdelay(5000); |
| 237 | |
| 238 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 239 | } |
| 240 | |
Deepa Dinamani | 6bb87d5 | 2013-02-26 14:37:36 -0800 | [diff] [blame] | 241 | crypto_engine_type board_ce_type(void) |
| 242 | { |
| 243 | return CRYPTO_ENGINE_TYPE_HW; |
| 244 | } |
| 245 | |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 246 | unsigned board_machtype(void) |
| 247 | { |
| 248 | } |
Amol Jadi | 85e1919 | 2013-02-28 22:45:04 -0800 | [diff] [blame^] | 249 | |
| 250 | void target_usb_init(void) |
| 251 | { |
| 252 | uint32_t val; |
| 253 | |
| 254 | /* Select and enable external configuration with USB PHY */ |
| 255 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET); |
| 256 | |
| 257 | /* Enable sess_vld */ |
| 258 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 259 | writel(val, USB_GENCONFIG_2); |
| 260 | |
| 261 | /* Enable external vbus configuration in the LINK */ |
| 262 | val = readl(USB_USBCMD); |
| 263 | val |= SESS_VLD_CTRL; |
| 264 | writel(val, USB_USBCMD); |
| 265 | } |