lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2014, 2016, The Linux Foundation. All rights reserved. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame] | 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. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 15 | * |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame] | 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. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <platform/iomap.h> |
Channagoud Kadabi | b14d6d0 | 2013-05-15 10:48:59 -0700 | [diff] [blame] | 31 | #include <platform/irqs.h> |
Channagoud Kadabi | 744c890 | 2013-04-02 11:54:53 -0700 | [diff] [blame] | 32 | #include <platform/gpio.h> |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 33 | #include <reg.h> |
vijay kumar | 32856d5 | 2014-08-06 16:18:03 +0530 | [diff] [blame] | 34 | #include <string.h> |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 35 | #include <target.h> |
| 36 | #include <platform.h> |
Pavel Nedev | 0351149 | 2013-03-08 19:05:32 -0800 | [diff] [blame] | 37 | #include <dload_util.h> |
Deepa Dinamani | 26e9326 | 2012-05-21 17:35:14 -0700 | [diff] [blame] | 38 | #include <uart_dm.h> |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 39 | #include <mmc.h> |
Deepa Dinamani | c2a9b36 | 2012-02-23 15:15:54 -0800 | [diff] [blame] | 40 | #include <spmi.h> |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 41 | #include <board.h> |
| 42 | #include <smem.h> |
| 43 | #include <baseband.h> |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 44 | #include <dev/keys.h> |
| 45 | #include <pm8x41.h> |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 46 | #include <crypto5_wrapper.h> |
Eugene Yasman | a0d1812 | 2013-02-26 13:23:05 +0200 | [diff] [blame] | 47 | #include <hsusb.h> |
| 48 | #include <clock.h> |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 49 | #include <partition_parser.h> |
vijay kumar | 32856d5 | 2014-08-06 16:18:03 +0530 | [diff] [blame] | 50 | #include <sdhci_msm.h> |
| 51 | #include <qtimer.h> |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 52 | #include <scm.h> |
| 53 | #include <platform/clock.h> |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 54 | #include <platform/gpio.h> |
Channagoud Kadabi | f84830c | 2013-04-19 14:35:47 -0700 | [diff] [blame] | 55 | #include <stdlib.h> |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 56 | |
Channagoud Kadabi | 62ac4cb | 2014-05-13 11:55:38 -0700 | [diff] [blame] | 57 | #define HW_PLATFORM_8994_INTERPOSER 0x3 |
| 58 | |
vijay kumar | 32856d5 | 2014-08-06 16:18:03 +0530 | [diff] [blame] | 59 | extern int platform_is_8974(); |
| 60 | extern int platform_is_8974ac(); |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 61 | extern bool target_use_signed_kernel(void); |
Channagoud Kadabi | 744c890 | 2013-04-02 11:54:53 -0700 | [diff] [blame] | 62 | static void set_sdc_power_ctrl(); |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 63 | |
| 64 | static unsigned int target_id; |
Deepa Dinamani | 07f1571 | 2013-03-08 17:02:13 -0800 | [diff] [blame] | 65 | static uint32_t pmic_ver; |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 66 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 67 | #if MMC_SDHCI_SUPPORT |
| 68 | struct mmc_device *dev; |
| 69 | #endif |
| 70 | |
Deepa Dinamani | c2a9b36 | 2012-02-23 15:15:54 -0800 | [diff] [blame] | 71 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 72 | #define PMIC_ARB_OWNER_ID 0 |
| 73 | |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame] | 74 | #define WDOG_DEBUG_DISABLE_BIT 17 |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 75 | |
Channagoud Kadabi | a1ef809 | 2014-01-08 12:11:58 -0800 | [diff] [blame] | 76 | #define CE_INSTANCE 2 |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 77 | #define CE_EE 1 |
| 78 | #define CE_FIFO_SIZE 64 |
| 79 | #define CE_READ_PIPE 3 |
| 80 | #define CE_WRITE_PIPE 2 |
Deepa Dinamani | 809c428 | 2013-07-09 14:06:02 -0700 | [diff] [blame] | 81 | #define CE_READ_PIPE_LOCK_GRP 0 |
| 82 | #define CE_WRITE_PIPE_LOCK_GRP 0 |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 83 | #define CE_ARRAY_SIZE 20 |
| 84 | |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 85 | #ifdef SSD_ENABLE |
| 86 | #define SSD_CE_INSTANCE_1 1 |
| 87 | #define SSD_PARTITION_SIZE 8192 |
| 88 | #endif |
| 89 | |
Sundarajan Srinivasan | d00f31d | 2013-07-19 12:09:15 -0700 | [diff] [blame] | 90 | #define FASTBOOT_MODE 0x77665500 |
| 91 | |
Channagoud Kadabi | c48b3e9 | 2013-06-23 16:19:10 -0700 | [diff] [blame] | 92 | #define BOARD_SOC_VERSION1(soc_rev) (soc_rev >= 0x10000 && soc_rev < 0x20000) |
| 93 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 94 | #if MMC_SDHCI_SUPPORT |
| 95 | static uint32_t mmc_sdhci_base[] = |
| 96 | { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE, MSM_SDC4_SDHCI_BASE }; |
| 97 | #endif |
| 98 | |
Deepa Dinamani | ca5ad85 | 2012-05-07 18:19:47 -0700 | [diff] [blame] | 99 | static uint32_t mmc_sdc_base[] = |
| 100 | { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE }; |
| 101 | |
Channagoud Kadabi | b14d6d0 | 2013-05-15 10:48:59 -0700 | [diff] [blame] | 102 | static uint32_t mmc_sdc_pwrctl_irq[] = |
| 103 | { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ, SDCC3_PWRCTL_IRQ, SDCC4_PWRCTL_IRQ }; |
| 104 | |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 105 | void target_early_init(void) |
| 106 | { |
Deepa Dinamani | b073ba2 | 2012-08-10 11:06:41 -0700 | [diff] [blame] | 107 | #if WITH_DEBUG_UART |
Neeti Desai | ac01127 | 2012-08-29 18:24:54 -0700 | [diff] [blame] | 108 | uart_dm_init(1, 0, BLSP1_UART1_BASE); |
Deepa Dinamani | b073ba2 | 2012-08-10 11:06:41 -0700 | [diff] [blame] | 109 | #endif |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Channagoud Kadabi | 62ac4cb | 2014-05-13 11:55:38 -0700 | [diff] [blame] | 112 | uint32_t target_hw_interposer() |
| 113 | { |
| 114 | return board_hardware_subtype() == HW_PLATFORM_8994_INTERPOSER ? 1 : 0; |
| 115 | } |
| 116 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 117 | /* Return 1 if vol_up pressed */ |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 118 | int target_volume_up() |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 119 | { |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 120 | static uint8_t first_time = 0; |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 121 | uint8_t status = 0; |
| 122 | struct pm8x41_gpio gpio; |
| 123 | |
| 124 | /* CDP vol_up seems to be always grounded. So gpio status is read as 0, |
| 125 | * whether key is pressed or not. |
| 126 | * Ignore volume_up key on CDP for now. |
| 127 | */ |
| 128 | if (board_hardware_id() == HW_PLATFORM_SURF) |
| 129 | return 0; |
| 130 | |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 131 | if (!first_time) { |
| 132 | /* Configure the GPIO */ |
| 133 | gpio.direction = PM_GPIO_DIR_IN; |
| 134 | gpio.function = 0; |
| 135 | gpio.pull = PM_GPIO_PULL_UP_30; |
| 136 | gpio.vin_sel = 2; |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 137 | |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 138 | pm8x41_gpio_config(5, &gpio); |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 139 | |
lijuang | 2d2b8a0 | 2015-06-05 21:34:15 +0800 | [diff] [blame] | 140 | /* Wait for the pmic gpio config to take effect */ |
| 141 | udelay(10000); |
| 142 | |
| 143 | first_time = 1; |
| 144 | } |
Channagoud Kadabi | 4d7b530 | 2013-08-07 16:34:08 -0700 | [diff] [blame] | 145 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 146 | /* Get status of P_GPIO_5 */ |
| 147 | pm8x41_gpio_get(5, &status); |
| 148 | |
| 149 | return !status; /* active low */ |
| 150 | } |
| 151 | |
| 152 | /* Return 1 if vol_down pressed */ |
Deepa Dinamani | 66a8796 | 2013-02-04 10:39:30 -0800 | [diff] [blame] | 153 | uint32_t target_volume_down() |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 154 | { |
Deepa Dinamani | 66a8796 | 2013-02-04 10:39:30 -0800 | [diff] [blame] | 155 | /* Volume down button is tied in with RESIN on MSM8974. */ |
Channagoud Kadabi | 0de103c | 2013-09-26 10:44:57 -0700 | [diff] [blame] | 156 | if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2)) |
Channagoud Kadabi | 84dcd91 | 2013-07-03 15:33:15 -0700 | [diff] [blame] | 157 | return pm8x41_v2_resin_status(); |
Deepa Dinamani | 13bfc85 | 2013-02-05 17:56:47 -0800 | [diff] [blame] | 158 | else |
| 159 | return pm8x41_resin_status(); |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | static void target_keystatus() |
| 163 | { |
| 164 | keys_init(); |
| 165 | |
| 166 | if(target_volume_down()) |
| 167 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 168 | |
| 169 | if(target_volume_up()) |
| 170 | keys_post_event(KEY_VOLUMEUP, 1); |
| 171 | } |
| 172 | |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 173 | /* Set up params for h/w CE. */ |
| 174 | void target_crypto_init_params() |
| 175 | { |
| 176 | struct crypto_init_params ce_params; |
| 177 | |
| 178 | /* Set up base addresses and instance. */ |
Channagoud Kadabi | a1ef809 | 2014-01-08 12:11:58 -0800 | [diff] [blame] | 179 | ce_params.crypto_instance = CE_INSTANCE; |
| 180 | ce_params.crypto_base = MSM_CE2_BASE; |
| 181 | ce_params.bam_base = MSM_CE2_BAM_BASE; |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 182 | |
| 183 | /* Set up BAM config. */ |
Deepa Dinamani | 809c428 | 2013-07-09 14:06:02 -0700 | [diff] [blame] | 184 | ce_params.bam_ee = CE_EE; |
| 185 | ce_params.pipes.read_pipe = CE_READ_PIPE; |
| 186 | ce_params.pipes.write_pipe = CE_WRITE_PIPE; |
| 187 | ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP; |
| 188 | ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP; |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 189 | |
| 190 | /* Assign buffer sizes. */ |
| 191 | ce_params.num_ce = CE_ARRAY_SIZE; |
| 192 | ce_params.read_fifo_size = CE_FIFO_SIZE; |
| 193 | ce_params.write_fifo_size = CE_FIFO_SIZE; |
| 194 | |
Deepa Dinamani | e505d3d | 2013-05-14 16:55:38 -0700 | [diff] [blame] | 195 | /* BAM is initialized by TZ for this platform. |
| 196 | * Do not do it again as the initialization address space |
| 197 | * is locked. |
| 198 | */ |
| 199 | ce_params.do_bam_init = 0; |
| 200 | |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 201 | crypto_init_params(&ce_params); |
| 202 | } |
| 203 | |
| 204 | crypto_engine_type board_ce_type(void) |
| 205 | { |
| 206 | return CRYPTO_ENGINE_TYPE_HW; |
| 207 | } |
| 208 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 209 | #if MMC_SDHCI_SUPPORT |
Channagoud Kadabi | b14d6d0 | 2013-05-15 10:48:59 -0700 | [diff] [blame] | 210 | static void target_mmc_sdhci_init() |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 211 | { |
Channagoud Kadabi | b14d6d0 | 2013-05-15 10:48:59 -0700 | [diff] [blame] | 212 | struct mmc_config_data config = {0}; |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 213 | uint32_t soc_ver = 0; |
| 214 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 215 | soc_ver = board_soc_version(); |
| 216 | |
| 217 | /* |
| 218 | * 8974 v1 fluid devices, have a hardware bug |
| 219 | * which limits the bus width to 4 bit. |
| 220 | */ |
| 221 | switch(board_hardware_id()) |
| 222 | { |
| 223 | case HW_PLATFORM_FLUID: |
Channagoud Kadabi | 0de103c | 2013-09-26 10:44:57 -0700 | [diff] [blame] | 224 | if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver)) |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 225 | config.bus_width = DATA_BUS_WIDTH_4BIT; |
Channagoud Kadabi | c48b3e9 | 2013-06-23 16:19:10 -0700 | [diff] [blame] | 226 | else |
| 227 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 228 | break; |
| 229 | default: |
| 230 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
| 231 | }; |
| 232 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 233 | /* Trying Slot 1*/ |
| 234 | config.slot = 1; |
Channagoud Kadabi | bdac709 | 2013-08-20 15:28:07 -0700 | [diff] [blame] | 235 | /* |
Channagoud Kadabi | 4d38515 | 2014-02-18 11:56:07 -0800 | [diff] [blame] | 236 | * For 8974 AC platform the software clock |
Channagoud Kadabi | bdac709 | 2013-08-20 15:28:07 -0700 | [diff] [blame] | 237 | * plan recommends to use the following frequencies: |
| 238 | * 200 MHz --> 192 MHZ |
| 239 | * 400 MHZ --> 384 MHZ |
| 240 | * only for emmc slot |
| 241 | */ |
Channagoud Kadabi | 4d38515 | 2014-02-18 11:56:07 -0800 | [diff] [blame] | 242 | if (platform_is_8974ac()) |
Channagoud Kadabi | bdac709 | 2013-08-20 15:28:07 -0700 | [diff] [blame] | 243 | config.max_clk_rate = MMC_CLK_192MHZ; |
| 244 | else |
| 245 | config.max_clk_rate = MMC_CLK_200MHZ; |
Channagoud Kadabi | b14d6d0 | 2013-05-15 10:48:59 -0700 | [diff] [blame] | 246 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 247 | config.pwrctl_base = mmc_sdc_base[config.slot - 1]; |
| 248 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
Aparna Mallavarapu | 2515266 | 2014-03-11 13:49:14 +0530 | [diff] [blame] | 249 | config.hs400_support = 1; |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 250 | |
| 251 | if (!(dev = mmc_init(&config))) { |
| 252 | /* Trying Slot 2 next */ |
| 253 | config.slot = 2; |
Channagoud Kadabi | bdac709 | 2013-08-20 15:28:07 -0700 | [diff] [blame] | 254 | config.max_clk_rate = MMC_CLK_200MHZ; |
Channagoud Kadabi | b14d6d0 | 2013-05-15 10:48:59 -0700 | [diff] [blame] | 255 | config.sdhc_base = mmc_sdhci_base[config.slot - 1]; |
| 256 | config.pwrctl_base = mmc_sdc_base[config.slot - 1]; |
| 257 | config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1]; |
| 258 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 259 | if (!(dev = mmc_init(&config))) { |
| 260 | dprintf(CRITICAL, "mmc init failed!"); |
| 261 | ASSERT(0); |
| 262 | } |
| 263 | } |
Channagoud Kadabi | ef5332f | 2013-05-16 15:23:43 -0700 | [diff] [blame] | 264 | |
| 265 | /* |
| 266 | * MMC initialization is complete, read the partition table info |
| 267 | */ |
| 268 | if (partition_read_table()) { |
| 269 | dprintf(CRITICAL, "Error reading the partition table info\n"); |
| 270 | ASSERT(0); |
| 271 | } |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Channagoud Kadabi | 6faaf70 | 2013-09-10 15:00:51 -0700 | [diff] [blame] | 274 | void *target_mmc_device() |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 275 | { |
Channagoud Kadabi | 6faaf70 | 2013-09-10 15:00:51 -0700 | [diff] [blame] | 276 | return (void *) dev; |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 277 | } |
Channagoud Kadabi | b14d6d0 | 2013-05-15 10:48:59 -0700 | [diff] [blame] | 278 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 279 | #else |
Channagoud Kadabi | b14d6d0 | 2013-05-15 10:48:59 -0700 | [diff] [blame] | 280 | static void target_mmc_mci_init() |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 281 | { |
Deepa Dinamani | ca5ad85 | 2012-05-07 18:19:47 -0700 | [diff] [blame] | 282 | uint32_t base_addr; |
| 283 | uint8_t slot; |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 284 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 285 | /* Trying Slot 1 */ |
| 286 | slot = 1; |
| 287 | base_addr = mmc_sdc_base[slot - 1]; |
| 288 | |
| 289 | if (mmc_boot_main(slot, base_addr)) |
| 290 | { |
| 291 | /* Trying Slot 2 next */ |
| 292 | slot = 2; |
| 293 | base_addr = mmc_sdc_base[slot - 1]; |
| 294 | if (mmc_boot_main(slot, base_addr)) { |
| 295 | dprintf(CRITICAL, "mmc init failed!"); |
| 296 | ASSERT(0); |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * Function to set the capabilities for the host |
| 303 | */ |
| 304 | void target_mmc_caps(struct mmc_host *host) |
| 305 | { |
| 306 | uint32_t soc_ver = 0; |
| 307 | |
| 308 | soc_ver = board_soc_version(); |
| 309 | |
| 310 | /* |
| 311 | * 8974 v1 fluid devices, have a hardware bug |
| 312 | * which limits the bus width to 4 bit. |
| 313 | */ |
| 314 | switch(board_hardware_id()) |
| 315 | { |
| 316 | case HW_PLATFORM_FLUID: |
Channagoud Kadabi | 0de103c | 2013-09-26 10:44:57 -0700 | [diff] [blame] | 317 | if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver)) |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 318 | host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT; |
Channagoud Kadabi | c48b3e9 | 2013-06-23 16:19:10 -0700 | [diff] [blame] | 319 | else |
| 320 | host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT; |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 321 | break; |
| 322 | default: |
| 323 | host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT; |
| 324 | }; |
| 325 | |
| 326 | host->caps.ddr_mode = 1; |
| 327 | host->caps.hs200_mode = 1; |
| 328 | host->caps.hs_clk_rate = MMC_CLK_96MHZ; |
| 329 | } |
| 330 | #endif |
| 331 | |
| 332 | |
| 333 | void target_init(void) |
| 334 | { |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 335 | dprintf(INFO, "target_init()\n"); |
| 336 | |
Deepa Dinamani | c2a9b36 | 2012-02-23 15:15:54 -0800 | [diff] [blame] | 337 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 338 | |
Deepa Dinamani | 07f1571 | 2013-03-08 17:02:13 -0800 | [diff] [blame] | 339 | /* Save PM8941 version info. */ |
| 340 | pmic_ver = pm8x41_get_pmic_rev(); |
| 341 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 342 | target_keystatus(); |
| 343 | |
Deepa Dinamani | b9a5720 | 2012-12-20 18:05:11 -0800 | [diff] [blame] | 344 | if (target_use_signed_kernel()) |
| 345 | target_crypto_init_params(); |
| 346 | |
Channagoud Kadabi | 744c890 | 2013-04-02 11:54:53 -0700 | [diff] [blame] | 347 | /* |
| 348 | * Set drive strength & pull ctrl for |
| 349 | * emmc |
| 350 | */ |
| 351 | set_sdc_power_ctrl(); |
| 352 | |
Channagoud Kadabi | c1fdc8d | 2013-04-05 11:29:23 -0700 | [diff] [blame] | 353 | #if MMC_SDHCI_SUPPORT |
| 354 | target_mmc_sdhci_init(); |
| 355 | #else |
| 356 | target_mmc_mci_init(); |
| 357 | #endif |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | unsigned board_machtype(void) |
| 361 | { |
| 362 | return target_id; |
| 363 | } |
| 364 | |
| 365 | /* Do any target specific intialization needed before entering fastboot mode */ |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 366 | #ifdef SSD_ENABLE |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 367 | static void ssd_load_keystore_from_emmc() |
| 368 | { |
| 369 | uint64_t ptn = 0; |
| 370 | int index = -1; |
| 371 | uint32_t size = SSD_PARTITION_SIZE; |
| 372 | int ret = -1; |
| 373 | |
Channagoud Kadabi | f84830c | 2013-04-19 14:35:47 -0700 | [diff] [blame] | 374 | uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE, |
| 375 | ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE)); |
| 376 | |
| 377 | if (!buffer) { |
| 378 | dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n"); |
| 379 | ASSERT(0); |
| 380 | } |
| 381 | |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 382 | index = partition_get_index("ssd"); |
| 383 | |
| 384 | ptn = partition_get_offset(index); |
| 385 | if(ptn == 0){ |
| 386 | dprintf(CRITICAL,"ERROR: ssd parition not found"); |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | if(mmc_read(ptn, buffer, size)){ |
| 391 | dprintf(CRITICAL,"ERROR:Cannot read data\n"); |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | ret = scm_protect_keystore((uint32_t *)&buffer[0],size); |
| 396 | if(ret != 0) |
vijay kumar | 32856d5 | 2014-08-06 16:18:03 +0530 | [diff] [blame] | 397 | dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed\n"); |
Channagoud Kadabi | f84830c | 2013-04-19 14:35:47 -0700 | [diff] [blame] | 398 | |
| 399 | free(buffer); |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 400 | } |
| 401 | #endif |
| 402 | |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 403 | void target_fastboot_init(void) |
| 404 | { |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 405 | /* Set the BOOT_DONE flag in PM8921 */ |
Channagoud Kadabi | a7ab931 | 2014-01-08 12:11:23 -0800 | [diff] [blame] | 406 | pm8x41_set_boot_done(); |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 407 | |
| 408 | #ifdef SSD_ENABLE |
| 409 | clock_ce_enable(SSD_CE_INSTANCE_1); |
| 410 | ssd_load_keystore_from_emmc(); |
| 411 | #endif |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 412 | } |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 413 | |
Channagoud Kadabi | c5537fd | 2014-02-04 17:07:19 -0800 | [diff] [blame] | 414 | /* Initialize target specific USB handlers */ |
| 415 | target_usb_iface_t* target_usb30_init() |
| 416 | { |
| 417 | target_usb_iface_t *t_usb_iface; |
| 418 | |
| 419 | t_usb_iface = calloc(1, sizeof(target_usb_iface_t)); |
| 420 | ASSERT(t_usb_iface); |
| 421 | |
| 422 | t_usb_iface->mux_config = target_usb_phy_mux_configure; |
| 423 | t_usb_iface->clock_init = clock_usb30_init; |
| 424 | |
| 425 | return t_usb_iface; |
| 426 | } |
| 427 | |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 428 | /* Detect the target type */ |
| 429 | void target_detect(struct board_data *board) |
| 430 | { |
Channagoud Kadabi | 2018bd1 | 2014-02-11 15:37:05 -0800 | [diff] [blame] | 431 | /* This property is filled in board.c */ |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /* Detect the modem type */ |
| 435 | void target_baseband_detect(struct board_data *board) |
| 436 | { |
Channagoud Kadabi | f1d4442 | 2013-02-21 22:59:35 -0800 | [diff] [blame] | 437 | uint32_t platform; |
Channagoud Kadabi | a7ab931 | 2014-01-08 12:11:23 -0800 | [diff] [blame] | 438 | uint32_t platform_subtype; |
Channagoud Kadabi | f1d4442 | 2013-02-21 22:59:35 -0800 | [diff] [blame] | 439 | |
| 440 | platform = board->platform; |
Channagoud Kadabi | 051f6b9 | 2014-01-08 12:16:16 -0800 | [diff] [blame] | 441 | platform_subtype = board->platform_subtype; |
| 442 | |
| 443 | /* |
| 444 | * Look for platform subtype if present, else |
| 445 | * check for platform type to decide on the |
| 446 | * baseband type |
| 447 | */ |
| 448 | switch(platform_subtype) { |
| 449 | case HW_PLATFORM_SUBTYPE_UNKNOWN: |
| 450 | case HW_PLATFORM_SUBTYPE_8974PRO_PM8084: |
Channagoud Kadabi | 62ac4cb | 2014-05-13 11:55:38 -0700 | [diff] [blame] | 451 | case HW_PLATFORM_8994_INTERPOSER: |
Channagoud Kadabi | 051f6b9 | 2014-01-08 12:16:16 -0800 | [diff] [blame] | 452 | break; |
| 453 | default: |
| 454 | dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype); |
| 455 | ASSERT(0); |
| 456 | }; |
Channagoud Kadabi | f1d4442 | 2013-02-21 22:59:35 -0800 | [diff] [blame] | 457 | |
| 458 | switch(platform) { |
| 459 | case MSM8974: |
Deepa Dinamani | 713a76f | 2013-05-03 13:17:24 -0700 | [diff] [blame] | 460 | case MSM8274: |
| 461 | case MSM8674: |
Deepa Dinamani | caf9e77 | 2013-06-14 12:39:41 -0700 | [diff] [blame] | 462 | case MSM8274AA: |
| 463 | case MSM8274AB: |
| 464 | case MSM8274AC: |
| 465 | case MSM8674AA: |
| 466 | case MSM8674AB: |
| 467 | case MSM8674AC: |
| 468 | case MSM8974AA: |
| 469 | case MSM8974AB: |
| 470 | case MSM8974AC: |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 471 | board->baseband = BASEBAND_MSM; |
Channagoud Kadabi | f1d4442 | 2013-02-21 22:59:35 -0800 | [diff] [blame] | 472 | break; |
| 473 | case APQ8074: |
Deepa Dinamani | caf9e77 | 2013-06-14 12:39:41 -0700 | [diff] [blame] | 474 | case APQ8074AA: |
| 475 | case APQ8074AB: |
| 476 | case APQ8074AC: |
Channagoud Kadabi | f1d4442 | 2013-02-21 22:59:35 -0800 | [diff] [blame] | 477 | board->baseband = BASEBAND_APQ; |
| 478 | break; |
| 479 | default: |
| 480 | dprintf(CRITICAL, "Platform type: %u is not supported\n",platform); |
| 481 | ASSERT(0); |
| 482 | }; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 483 | } |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 484 | |
Deepa Dinamani | 927a6b6 | 2013-03-28 17:05:32 -0700 | [diff] [blame] | 485 | unsigned target_baseband() |
| 486 | { |
| 487 | return board_baseband(); |
| 488 | } |
| 489 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 490 | void target_serialno(unsigned char *buf) |
| 491 | { |
| 492 | unsigned int serialno; |
| 493 | if (target_is_emmc_boot()) { |
| 494 | serialno = mmc_get_psn(); |
| 495 | snprintf((char *)buf, 13, "%x", serialno); |
| 496 | } |
| 497 | } |
Amol Jadi | 6639d45 | 2012-08-16 14:51:19 -0700 | [diff] [blame] | 498 | |
| 499 | unsigned check_reboot_mode(void) |
| 500 | { |
| 501 | uint32_t restart_reason = 0; |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 502 | uint32_t soc_ver = 0; |
| 503 | uint32_t restart_reason_addr; |
| 504 | |
| 505 | soc_ver = board_soc_version(); |
| 506 | |
Channagoud Kadabi | 0de103c | 2013-09-26 10:44:57 -0700 | [diff] [blame] | 507 | if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver)) |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 508 | restart_reason_addr = RESTART_REASON_ADDR; |
Channagoud Kadabi | c48b3e9 | 2013-06-23 16:19:10 -0700 | [diff] [blame] | 509 | else |
| 510 | restart_reason_addr = RESTART_REASON_ADDR_V2; |
Amol Jadi | 6639d45 | 2012-08-16 14:51:19 -0700 | [diff] [blame] | 511 | |
| 512 | /* Read reboot reason and scrub it */ |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 513 | restart_reason = readl(restart_reason_addr); |
| 514 | writel(0x00, restart_reason_addr); |
Amol Jadi | 6639d45 | 2012-08-16 14:51:19 -0700 | [diff] [blame] | 515 | |
| 516 | return restart_reason; |
| 517 | } |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 518 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 519 | int set_download_mode(enum reboot_reason mode) |
| 520 | { |
| 521 | if (mode == NORMAL_DLOAD || mode == EMERGENCY_DLOAD) |
| 522 | dload_util_write_cookie(mode == NORMAL_DLOAD ? |
| 523 | DLOAD_MODE_ADDR_V2 : EMERGENCY_DLOAD_MODE_ADDR_V2, mode); |
| 524 | |
| 525 | return 0; |
| 526 | } |
| 527 | |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 528 | void reboot_device(unsigned reboot_reason) |
| 529 | { |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 530 | uint32_t soc_ver = 0; |
Sundarajan Srinivasan | d00f31d | 2013-07-19 12:09:15 -0700 | [diff] [blame] | 531 | uint8_t reset_type = 0; |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 532 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 533 | /* Set cookie for dload mode */ |
| 534 | if(set_download_mode(reboot_reason)) { |
| 535 | dprintf(CRITICAL, "HALT: set_download_mode not supported\n"); |
| 536 | return; |
| 537 | } |
| 538 | |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 539 | soc_ver = board_soc_version(); |
| 540 | |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 541 | /* Write the reboot reason */ |
Channagoud Kadabi | 0de103c | 2013-09-26 10:44:57 -0700 | [diff] [blame] | 542 | if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver)) |
Channagoud Kadabi | 8c8587f | 2013-02-08 12:46:09 -0800 | [diff] [blame] | 543 | writel(reboot_reason, RESTART_REASON_ADDR); |
Channagoud Kadabi | c48b3e9 | 2013-06-23 16:19:10 -0700 | [diff] [blame] | 544 | else |
| 545 | writel(reboot_reason, RESTART_REASON_ADDR_V2); |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 546 | |
Sundarajan Srinivasan | d00f31d | 2013-07-19 12:09:15 -0700 | [diff] [blame] | 547 | if(reboot_reason == FASTBOOT_MODE) |
| 548 | reset_type = PON_PSHOLD_WARM_RESET; |
| 549 | else |
| 550 | reset_type = PON_PSHOLD_HARD_RESET; |
| 551 | |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 552 | /* Configure PMIC for warm reset */ |
Channagoud Kadabi | 0de103c | 2013-09-26 10:44:57 -0700 | [diff] [blame] | 553 | if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2)) |
Sundarajan Srinivasan | d00f31d | 2013-07-19 12:09:15 -0700 | [diff] [blame] | 554 | pm8x41_v2_reset_configure(reset_type); |
Deepa Dinamani | 07f1571 | 2013-03-08 17:02:13 -0800 | [diff] [blame] | 555 | else |
Sundarajan Srinivasan | d00f31d | 2013-07-19 12:09:15 -0700 | [diff] [blame] | 556 | pm8x41_reset_configure(reset_type); |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 557 | |
| 558 | /* Drop PS_HOLD for MSM */ |
| 559 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 560 | |
| 561 | mdelay(5000); |
| 562 | |
| 563 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 564 | } |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 565 | |
Channagoud Kadabi | 6d215b9 | 2013-06-23 16:47:07 -0700 | [diff] [blame] | 566 | /* Check if MSM needs VBUS mimic for USB */ |
| 567 | static int target_needs_vbus_mimic() |
| 568 | { |
Channagoud Kadabi | 0de103c | 2013-09-26 10:44:57 -0700 | [diff] [blame] | 569 | if (platform_is_8974()) |
Channagoud Kadabi | 6d215b9 | 2013-06-23 16:47:07 -0700 | [diff] [blame] | 570 | return 0; |
| 571 | |
| 572 | return 1; |
| 573 | } |
| 574 | |
Eugene Yasman | a0d1812 | 2013-02-26 13:23:05 +0200 | [diff] [blame] | 575 | /* Do target specific usb initialization */ |
| 576 | void target_usb_init(void) |
| 577 | { |
Channagoud Kadabi | 6d215b9 | 2013-06-23 16:47:07 -0700 | [diff] [blame] | 578 | uint32_t val; |
| 579 | |
Eugene Yasman | a0d1812 | 2013-02-26 13:23:05 +0200 | [diff] [blame] | 580 | /* Enable secondary USB PHY on DragonBoard8074 */ |
| 581 | if (board_hardware_id() == HW_PLATFORM_DRAGON) { |
| 582 | /* Route ChipIDea to use secondary USB HS port2 */ |
| 583 | writel_relaxed(1, USB2_PHY_SEL); |
| 584 | |
| 585 | /* Enable access to secondary PHY by clamping the low |
| 586 | * voltage interface between DVDD of the PHY and Vddcx |
| 587 | * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */ |
| 588 | writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL) |
| 589 | | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL); |
| 590 | |
| 591 | /* Perform power-on-reset of the PHY. |
| 592 | * Delay values are arbitrary */ |
| 593 | writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1, |
| 594 | USB_OTG_HS_PHY_CTRL); |
| 595 | thread_sleep(10); |
| 596 | writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE, |
| 597 | USB_OTG_HS_PHY_CTRL); |
| 598 | thread_sleep(10); |
| 599 | |
| 600 | /* Enable HSUSB PHY port for ULPI interface, |
| 601 | * then configure related parameters within the PHY */ |
| 602 | writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000) |
| 603 | | 0x8c000004), USB_PORTSC); |
| 604 | } |
Channagoud Kadabi | 6d215b9 | 2013-06-23 16:47:07 -0700 | [diff] [blame] | 605 | |
| 606 | if (target_needs_vbus_mimic()) |
| 607 | { |
| 608 | /* Select and enable external configuration with USB PHY */ |
| 609 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET); |
| 610 | |
| 611 | /* Enable sess_vld */ |
| 612 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 613 | writel(val, USB_GENCONFIG_2); |
| 614 | |
| 615 | /* Enable external vbus configuration in the LINK */ |
| 616 | val = readl(USB_USBCMD); |
| 617 | val |= SESS_VLD_CTRL; |
| 618 | writel(val, USB_USBCMD); |
| 619 | } |
Eugene Yasman | a0d1812 | 2013-02-26 13:23:05 +0200 | [diff] [blame] | 620 | } |
| 621 | |
Casey Piper | 74f8e5c | 2013-09-05 15:00:30 -0700 | [diff] [blame] | 622 | uint8_t target_panel_auto_detect_enabled() |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 623 | { |
Siddhartha Agrawal | 17a6b83 | 2013-02-17 18:36:25 -0800 | [diff] [blame] | 624 | switch(board_hardware_id()) |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 625 | { |
Siddhartha Agrawal | 17a6b83 | 2013-02-17 18:36:25 -0800 | [diff] [blame] | 626 | case HW_PLATFORM_SURF: |
| 627 | case HW_PLATFORM_MTP: |
| 628 | case HW_PLATFORM_FLUID: |
Siddhartha Agrawal | 17a6b83 | 2013-02-17 18:36:25 -0800 | [diff] [blame] | 629 | return 1; |
| 630 | break; |
| 631 | default: |
Siddhartha Agrawal | 17a6b83 | 2013-02-17 18:36:25 -0800 | [diff] [blame] | 632 | return 0; |
Casey Piper | 74f8e5c | 2013-09-05 15:00:30 -0700 | [diff] [blame] | 633 | break; |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 634 | } |
Casey Piper | 74f8e5c | 2013-09-05 15:00:30 -0700 | [diff] [blame] | 635 | return 0; |
| 636 | } |
| 637 | |
Casey Piper | 74f67a3 | 2013-11-18 13:26:18 -0800 | [diff] [blame] | 638 | uint8_t target_is_edp() |
| 639 | { |
| 640 | switch(board_hardware_id()) |
| 641 | { |
| 642 | case HW_PLATFORM_LIQUID: |
| 643 | return 1; |
| 644 | break; |
| 645 | default: |
| 646 | return 0; |
| 647 | break; |
| 648 | } |
| 649 | return 0; |
| 650 | } |
| 651 | |
Casey Piper | 74f8e5c | 2013-09-05 15:00:30 -0700 | [diff] [blame] | 652 | static uint8_t splash_override; |
| 653 | /* Returns 1 if target supports continuous splash screen. */ |
| 654 | int target_cont_splash_screen() |
| 655 | { |
| 656 | uint8_t splash_screen = 0; |
| 657 | if(!splash_override) { |
| 658 | switch(board_hardware_id()) |
| 659 | { |
| 660 | case HW_PLATFORM_SURF: |
| 661 | case HW_PLATFORM_MTP: |
| 662 | case HW_PLATFORM_FLUID: |
| 663 | case HW_PLATFORM_DRAGON: |
| 664 | case HW_PLATFORM_LIQUID: |
| 665 | dprintf(SPEW, "Target_cont_splash=1\n"); |
| 666 | splash_screen = 1; |
| 667 | break; |
| 668 | default: |
| 669 | dprintf(SPEW, "Target_cont_splash=0\n"); |
| 670 | splash_screen = 0; |
| 671 | } |
| 672 | } |
| 673 | return splash_screen; |
| 674 | } |
| 675 | |
| 676 | void target_force_cont_splash_disable(uint8_t override) |
| 677 | { |
| 678 | splash_override = override; |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 679 | } |
sundarajan srinivasan | b5db0a9 | 2013-02-12 19:19:27 -0800 | [diff] [blame] | 680 | |
| 681 | unsigned target_pause_for_battery_charge(void) |
| 682 | { |
sundarajan srinivasan | b5db0a9 | 2013-02-12 19:19:27 -0800 | [diff] [blame] | 683 | |
| 684 | /* This function will always return 0 to facilitate |
| 685 | * automated testing/reboot with usb connected. |
| 686 | * uncomment if this feature is needed */ |
| 687 | /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG)) |
| 688 | return 1;*/ |
| 689 | |
| 690 | return 0; |
| 691 | } |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 692 | |
Channagoud Kadabi | 9faa45b | 2013-06-18 18:33:02 -0700 | [diff] [blame] | 693 | void target_uninit(void) |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 694 | { |
Channagoud Kadabi | 9faa45b | 2013-06-18 18:33:02 -0700 | [diff] [blame] | 695 | #if MMC_SDHCI_SUPPORT |
| 696 | mmc_put_card_to_sleep(dev); |
| 697 | #else |
| 698 | mmc_put_card_to_sleep(); |
| 699 | #endif |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 700 | #ifdef SSD_ENABLE |
| 701 | clock_ce_disable(SSD_CE_INSTANCE_1); |
| 702 | #endif |
Channagoud Kadabi | 2095a41 | 2013-12-04 12:37:06 -0800 | [diff] [blame] | 703 | if (crypto_initialized()) |
| 704 | crypto_eng_cleanup(); |
Channagoud Kadabi | d0115f9 | 2014-01-24 17:25:34 -0800 | [diff] [blame] | 705 | |
| 706 | /* Disable HC mode before jumping to kernel */ |
| 707 | sdhci_mode_disable(&dev->host); |
sundarajan srinivasan | a098d83 | 2013-03-07 12:19:30 -0800 | [diff] [blame] | 708 | } |
Deepa Dinamani | 65df982 | 2013-03-08 13:38:34 -0800 | [diff] [blame] | 709 | |
| 710 | void shutdown_device() |
| 711 | { |
| 712 | dprintf(CRITICAL, "Going down for shutdown.\n"); |
| 713 | |
| 714 | /* Configure PMIC for shutdown. */ |
Channagoud Kadabi | 0de103c | 2013-09-26 10:44:57 -0700 | [diff] [blame] | 715 | if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2)) |
Deepa Dinamani | 65df982 | 2013-03-08 13:38:34 -0800 | [diff] [blame] | 716 | pm8x41_v2_reset_configure(PON_PSHOLD_SHUTDOWN); |
| 717 | else |
| 718 | pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN); |
| 719 | |
| 720 | /* Drop PS_HOLD for MSM */ |
| 721 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 722 | |
| 723 | mdelay(5000); |
| 724 | |
| 725 | dprintf(CRITICAL, "Shutdown failed\n"); |
Channagoud Kadabi | 744c890 | 2013-04-02 11:54:53 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | static void set_sdc_power_ctrl() |
| 729 | { |
Channagoud Kadabi | 224d832 | 2013-09-27 14:25:22 -0700 | [diff] [blame] | 730 | uint8_t tlmm_hdrv_clk = 0; |
| 731 | uint32_t platform_id = 0; |
| 732 | |
| 733 | platform_id = board_platform_id(); |
| 734 | |
| 735 | switch(platform_id) |
| 736 | { |
| 737 | case MSM8274AA: |
| 738 | case MSM8274AB: |
| 739 | case MSM8674AA: |
| 740 | case MSM8674AB: |
| 741 | case MSM8974AA: |
| 742 | case MSM8974AB: |
| 743 | if (board_hardware_id() == HW_PLATFORM_MTP) |
| 744 | tlmm_hdrv_clk = TLMM_CUR_VAL_10MA; |
| 745 | else |
| 746 | tlmm_hdrv_clk = TLMM_CUR_VAL_16MA; |
| 747 | break; |
| 748 | default: |
| 749 | tlmm_hdrv_clk = TLMM_CUR_VAL_16MA; |
| 750 | }; |
| 751 | |
Channagoud Kadabi | 744c890 | 2013-04-02 11:54:53 -0700 | [diff] [blame] | 752 | /* Drive strength configs for sdc pins */ |
| 753 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 754 | { |
Channagoud Kadabi | 224d832 | 2013-09-27 14:25:22 -0700 | [diff] [blame] | 755 | { SDC1_CLK_HDRV_CTL_OFF, tlmm_hdrv_clk, TLMM_HDRV_MASK }, |
Channagoud Kadabi | 744c890 | 2013-04-02 11:54:53 -0700 | [diff] [blame] | 756 | { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK }, |
| 757 | { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK }, |
| 758 | }; |
| 759 | |
| 760 | /* Pull configs for sdc pins */ |
| 761 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 762 | { |
| 763 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK }, |
| 764 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
| 765 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
| 766 | }; |
| 767 | |
Channagoud Kadabi | 389cab2 | 2013-08-20 15:29:15 -0700 | [diff] [blame] | 768 | struct tlmm_cfgs sdc1_rclk_cfg[] = |
| 769 | { |
| 770 | { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK }, |
| 771 | }; |
| 772 | |
Channagoud Kadabi | 744c890 | 2013-04-02 11:54:53 -0700 | [diff] [blame] | 773 | /* Set the drive strength & pull control values */ |
| 774 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 775 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
Channagoud Kadabi | 389cab2 | 2013-08-20 15:29:15 -0700 | [diff] [blame] | 776 | |
| 777 | /* RCLK is supported only with 8974 pro, set rclk to pull down |
| 778 | * only for 8974 pro targets |
| 779 | */ |
| 780 | if (!platform_is_8974()) |
| 781 | tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg)); |
Channagoud Kadabi | 744c890 | 2013-04-02 11:54:53 -0700 | [diff] [blame] | 782 | } |
Stanimir Varbanov | f64a029 | 2013-04-29 11:58:27 +0300 | [diff] [blame] | 783 | |
| 784 | int emmc_recovery_init(void) |
| 785 | { |
| 786 | return _emmc_recovery_init(); |
| 787 | } |
Channagoud Kadabi | 6d215b9 | 2013-06-23 16:47:07 -0700 | [diff] [blame] | 788 | |
| 789 | void target_usb_stop(void) |
| 790 | { |
Channagoud Kadabi | 6d215b9 | 2013-06-23 16:47:07 -0700 | [diff] [blame] | 791 | |
| 792 | /* Disable VBUS mimicing in the controller. */ |
| 793 | if (target_needs_vbus_mimic()) |
| 794 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR); |
| 795 | } |
Amol Jadi | 4c3229f | 2013-10-07 14:38:06 -0700 | [diff] [blame] | 796 | |
| 797 | /* identify the usb controller to be used for the target */ |
| 798 | const char * target_usb_controller() |
| 799 | { |
| 800 | switch(board_platform_id()) |
| 801 | { |
| 802 | /* use dwc controller for PRO chips (with some exceptions) */ |
| 803 | case MSM8974AA: |
| 804 | case MSM8974AB: |
| 805 | case MSM8974AC: |
| 806 | /* exceptions based on hardware id */ |
Channagoud Kadabi | 62ac4cb | 2014-05-13 11:55:38 -0700 | [diff] [blame] | 807 | if (board_hardware_id() != HW_PLATFORM_DRAGON && !target_hw_interposer()) |
Amol Jadi | 4c3229f | 2013-10-07 14:38:06 -0700 | [diff] [blame] | 808 | return "dwc"; |
| 809 | /* fall through to default "ci" for anything that did'nt select "dwc" */ |
| 810 | default: |
| 811 | return "ci"; |
| 812 | } |
| 813 | } |
Amol Jadi | 28864bb | 2013-10-11 14:12:59 -0700 | [diff] [blame] | 814 | |
| 815 | /* UTMI MUX configuration to connect PHY to SNPS controller: |
| 816 | * Configure primary HS phy mux to use UTMI interface |
| 817 | * (connected to usb30 controller). |
| 818 | */ |
| 819 | static void tcsr_hs_phy_mux_configure(void) |
| 820 | { |
| 821 | uint32_t reg; |
| 822 | |
| 823 | reg = readl(USB2_PHY_SEL); |
| 824 | |
| 825 | writel(reg | 0x1, USB2_PHY_SEL); |
| 826 | } |
| 827 | |
| 828 | /* configure hs phy mux if using dwc controller */ |
| 829 | void target_usb_phy_mux_configure(void) |
| 830 | { |
| 831 | if(!strcmp(target_usb_controller(), "dwc")) |
| 832 | { |
| 833 | tcsr_hs_phy_mux_configure(); |
| 834 | } |
| 835 | } |
lijuang | 3606df8 | 2015-09-02 21:14:43 +0800 | [diff] [blame] | 836 | |
| 837 | uint32_t target_get_pmic() |
| 838 | { |
| 839 | return PMIC_IS_PM8941; |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 840 | } |