blob: 73043df0bd6fc9fe43bd6605f12b7f44014b421c [file] [log] [blame]
lijuang395b5e62015-11-19 17:39:44 +08001/* Copyright (c) 2012-2014, 2016, The Linux Foundation. All rights reserved.
Deepa Dinamani7d6c8972011-12-14 15:16:56 -08002 *
3 * Redistribution and use in source and binary forms, with or without
Deepa Dinamani1e094942012-10-30 15:49:02 -07004 * 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 Dinamani7d6c8972011-12-14 15:16:56 -080015 *
Deepa Dinamani1e094942012-10-30 15:49:02 -070016 * 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 Dinamani7d6c8972011-12-14 15:16:56 -080027 */
28
29#include <debug.h>
30#include <platform/iomap.h>
Channagoud Kadabib14d6d02013-05-15 10:48:59 -070031#include <platform/irqs.h>
Channagoud Kadabi744c8902013-04-02 11:54:53 -070032#include <platform/gpio.h>
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080033#include <reg.h>
vijay kumar32856d52014-08-06 16:18:03 +053034#include <string.h>
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080035#include <target.h>
36#include <platform.h>
Pavel Nedev03511492013-03-08 19:05:32 -080037#include <dload_util.h>
Deepa Dinamani26e93262012-05-21 17:35:14 -070038#include <uart_dm.h>
Amol Jadi29f95032012-06-22 12:52:54 -070039#include <mmc.h>
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080040#include <spmi.h>
Neeti Desai465491e2012-07-31 12:53:35 -070041#include <board.h>
42#include <smem.h>
43#include <baseband.h>
Deepa Dinamani9a612932012-08-14 16:15:03 -070044#include <dev/keys.h>
45#include <pm8x41.h>
Deepa Dinamanib9a57202012-12-20 18:05:11 -080046#include <crypto5_wrapper.h>
Eugene Yasmana0d18122013-02-26 13:23:05 +020047#include <hsusb.h>
48#include <clock.h>
sundarajan srinivasana098d832013-03-07 12:19:30 -080049#include <partition_parser.h>
vijay kumar32856d52014-08-06 16:18:03 +053050#include <sdhci_msm.h>
51#include <qtimer.h>
sundarajan srinivasana098d832013-03-07 12:19:30 -080052#include <scm.h>
53#include <platform/clock.h>
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070054#include <platform/gpio.h>
Channagoud Kadabif84830c2013-04-19 14:35:47 -070055#include <stdlib.h>
Deepa Dinamanib9a57202012-12-20 18:05:11 -080056
Channagoud Kadabi62ac4cb2014-05-13 11:55:38 -070057#define HW_PLATFORM_8994_INTERPOSER 0x3
58
vijay kumar32856d52014-08-06 16:18:03 +053059extern int platform_is_8974();
60extern int platform_is_8974ac();
Deepa Dinamanib9a57202012-12-20 18:05:11 -080061extern bool target_use_signed_kernel(void);
Channagoud Kadabi744c8902013-04-02 11:54:53 -070062static void set_sdc_power_ctrl();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080063
64static unsigned int target_id;
Deepa Dinamani07f15712013-03-08 17:02:13 -080065static uint32_t pmic_ver;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080066
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070067#if MMC_SDHCI_SUPPORT
68struct mmc_device *dev;
69#endif
70
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080071#define PMIC_ARB_CHANNEL_NUM 0
72#define PMIC_ARB_OWNER_ID 0
73
Deepa Dinamani1e094942012-10-30 15:49:02 -070074#define WDOG_DEBUG_DISABLE_BIT 17
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080075
Channagoud Kadabia1ef8092014-01-08 12:11:58 -080076#define CE_INSTANCE 2
Deepa Dinamanib9a57202012-12-20 18:05:11 -080077#define CE_EE 1
78#define CE_FIFO_SIZE 64
79#define CE_READ_PIPE 3
80#define CE_WRITE_PIPE 2
Deepa Dinamani809c4282013-07-09 14:06:02 -070081#define CE_READ_PIPE_LOCK_GRP 0
82#define CE_WRITE_PIPE_LOCK_GRP 0
Deepa Dinamanib9a57202012-12-20 18:05:11 -080083#define CE_ARRAY_SIZE 20
84
sundarajan srinivasana098d832013-03-07 12:19:30 -080085#ifdef SSD_ENABLE
86#define SSD_CE_INSTANCE_1 1
87#define SSD_PARTITION_SIZE 8192
88#endif
89
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -070090#define FASTBOOT_MODE 0x77665500
91
Channagoud Kadabic48b3e92013-06-23 16:19:10 -070092#define BOARD_SOC_VERSION1(soc_rev) (soc_rev >= 0x10000 && soc_rev < 0x20000)
93
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070094#if MMC_SDHCI_SUPPORT
95static 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 Dinamanica5ad852012-05-07 18:19:47 -070099static uint32_t mmc_sdc_base[] =
100 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
101
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700102static uint32_t mmc_sdc_pwrctl_irq[] =
103 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ, SDCC3_PWRCTL_IRQ, SDCC4_PWRCTL_IRQ };
104
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800105void target_early_init(void)
106{
Deepa Dinamanib073ba22012-08-10 11:06:41 -0700107#if WITH_DEBUG_UART
Neeti Desaiac011272012-08-29 18:24:54 -0700108 uart_dm_init(1, 0, BLSP1_UART1_BASE);
Deepa Dinamanib073ba22012-08-10 11:06:41 -0700109#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800110}
111
Channagoud Kadabi62ac4cb2014-05-13 11:55:38 -0700112uint32_t target_hw_interposer()
113{
114 return board_hardware_subtype() == HW_PLATFORM_8994_INTERPOSER ? 1 : 0;
115}
116
Deepa Dinamani9a612932012-08-14 16:15:03 -0700117/* Return 1 if vol_up pressed */
lijuang2d2b8a02015-06-05 21:34:15 +0800118int target_volume_up()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700119{
lijuang2d2b8a02015-06-05 21:34:15 +0800120 static uint8_t first_time = 0;
Deepa Dinamani9a612932012-08-14 16:15:03 -0700121 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
lijuang2d2b8a02015-06-05 21:34:15 +0800131 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 Dinamani9a612932012-08-14 16:15:03 -0700137
lijuang2d2b8a02015-06-05 21:34:15 +0800138 pm8x41_gpio_config(5, &gpio);
Deepa Dinamani9a612932012-08-14 16:15:03 -0700139
lijuang2d2b8a02015-06-05 21:34:15 +0800140 /* Wait for the pmic gpio config to take effect */
141 udelay(10000);
142
143 first_time = 1;
144 }
Channagoud Kadabi4d7b5302013-08-07 16:34:08 -0700145
Deepa Dinamani9a612932012-08-14 16:15:03 -0700146 /* 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 Dinamani66a87962013-02-04 10:39:30 -0800153uint32_t target_volume_down()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700154{
Deepa Dinamani66a87962013-02-04 10:39:30 -0800155 /* Volume down button is tied in with RESIN on MSM8974. */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700156 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700157 return pm8x41_v2_resin_status();
Deepa Dinamani13bfc852013-02-05 17:56:47 -0800158 else
159 return pm8x41_resin_status();
Deepa Dinamani9a612932012-08-14 16:15:03 -0700160}
161
162static 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 Dinamanib9a57202012-12-20 18:05:11 -0800173/* Set up params for h/w CE. */
174void target_crypto_init_params()
175{
176 struct crypto_init_params ce_params;
177
178 /* Set up base addresses and instance. */
Channagoud Kadabia1ef8092014-01-08 12:11:58 -0800179 ce_params.crypto_instance = CE_INSTANCE;
180 ce_params.crypto_base = MSM_CE2_BASE;
181 ce_params.bam_base = MSM_CE2_BAM_BASE;
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800182
183 /* Set up BAM config. */
Deepa Dinamani809c4282013-07-09 14:06:02 -0700184 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 Dinamanib9a57202012-12-20 18:05:11 -0800189
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 Dinamanie505d3d2013-05-14 16:55:38 -0700195 /* 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 Dinamanib9a57202012-12-20 18:05:11 -0800201 crypto_init_params(&ce_params);
202}
203
204crypto_engine_type board_ce_type(void)
205{
206 return CRYPTO_ENGINE_TYPE_HW;
207}
208
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700209#if MMC_SDHCI_SUPPORT
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700210static void target_mmc_sdhci_init()
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700211{
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700212 struct mmc_config_data config = {0};
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700213 uint32_t soc_ver = 0;
214
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700215 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 Kadabi0de103c2013-09-26 10:44:57 -0700224 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700225 config.bus_width = DATA_BUS_WIDTH_4BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700226 else
227 config.bus_width = DATA_BUS_WIDTH_8BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700228 break;
229 default:
230 config.bus_width = DATA_BUS_WIDTH_8BIT;
231 };
232
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700233 /* Trying Slot 1*/
234 config.slot = 1;
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700235 /*
Channagoud Kadabi4d385152014-02-18 11:56:07 -0800236 * For 8974 AC platform the software clock
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700237 * plan recommends to use the following frequencies:
238 * 200 MHz --> 192 MHZ
239 * 400 MHZ --> 384 MHZ
240 * only for emmc slot
241 */
Channagoud Kadabi4d385152014-02-18 11:56:07 -0800242 if (platform_is_8974ac())
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700243 config.max_clk_rate = MMC_CLK_192MHZ;
244 else
245 config.max_clk_rate = MMC_CLK_200MHZ;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700246 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 Mallavarapu25152662014-03-11 13:49:14 +0530249 config.hs400_support = 1;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700250
251 if (!(dev = mmc_init(&config))) {
252 /* Trying Slot 2 next */
253 config.slot = 2;
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700254 config.max_clk_rate = MMC_CLK_200MHZ;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700255 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 Kadabic1fdc8d2013-04-05 11:29:23 -0700259 if (!(dev = mmc_init(&config))) {
260 dprintf(CRITICAL, "mmc init failed!");
261 ASSERT(0);
262 }
263 }
Channagoud Kadabief5332f2013-05-16 15:23:43 -0700264
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 Kadabic1fdc8d2013-04-05 11:29:23 -0700272}
273
Channagoud Kadabi6faaf702013-09-10 15:00:51 -0700274void *target_mmc_device()
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700275{
Channagoud Kadabi6faaf702013-09-10 15:00:51 -0700276 return (void *) dev;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700277}
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700278
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700279#else
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700280static void target_mmc_mci_init()
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800281{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700282 uint32_t base_addr;
283 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800284
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700285 /* 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 */
304void 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 Kadabi0de103c2013-09-26 10:44:57 -0700317 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700318 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700319 else
320 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700321 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
333void target_init(void)
334{
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800335 dprintf(INFO, "target_init()\n");
336
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800337 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800338
Deepa Dinamani07f15712013-03-08 17:02:13 -0800339 /* Save PM8941 version info. */
340 pmic_ver = pm8x41_get_pmic_rev();
341
Deepa Dinamani9a612932012-08-14 16:15:03 -0700342 target_keystatus();
343
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800344 if (target_use_signed_kernel())
345 target_crypto_init_params();
346
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700347 /*
348 * Set drive strength & pull ctrl for
349 * emmc
350 */
351 set_sdc_power_ctrl();
352
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700353#if MMC_SDHCI_SUPPORT
354 target_mmc_sdhci_init();
355#else
356 target_mmc_mci_init();
357#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800358}
359
360unsigned board_machtype(void)
361{
362 return target_id;
363}
364
365/* Do any target specific intialization needed before entering fastboot mode */
sundarajan srinivasana098d832013-03-07 12:19:30 -0800366#ifdef SSD_ENABLE
sundarajan srinivasana098d832013-03-07 12:19:30 -0800367static 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 Kadabif84830c2013-04-19 14:35:47 -0700374 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 srinivasana098d832013-03-07 12:19:30 -0800382 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 kumar32856d52014-08-06 16:18:03 +0530397 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed\n");
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700398
399 free(buffer);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800400}
401#endif
402
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800403void target_fastboot_init(void)
404{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700405 /* Set the BOOT_DONE flag in PM8921 */
Channagoud Kadabia7ab9312014-01-08 12:11:23 -0800406 pm8x41_set_boot_done();
sundarajan srinivasana098d832013-03-07 12:19:30 -0800407
408#ifdef SSD_ENABLE
409 clock_ce_enable(SSD_CE_INSTANCE_1);
410 ssd_load_keystore_from_emmc();
411#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800412}
Neeti Desai465491e2012-07-31 12:53:35 -0700413
Channagoud Kadabic5537fd2014-02-04 17:07:19 -0800414/* Initialize target specific USB handlers */
415target_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 Desai465491e2012-07-31 12:53:35 -0700428/* Detect the target type */
429void target_detect(struct board_data *board)
430{
Channagoud Kadabi2018bd12014-02-11 15:37:05 -0800431 /* This property is filled in board.c */
Neeti Desai465491e2012-07-31 12:53:35 -0700432}
433
434/* Detect the modem type */
435void target_baseband_detect(struct board_data *board)
436{
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800437 uint32_t platform;
Channagoud Kadabia7ab9312014-01-08 12:11:23 -0800438 uint32_t platform_subtype;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800439
440 platform = board->platform;
Channagoud Kadabi051f6b92014-01-08 12:16:16 -0800441 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 Kadabi62ac4cb2014-05-13 11:55:38 -0700451 case HW_PLATFORM_8994_INTERPOSER:
Channagoud Kadabi051f6b92014-01-08 12:16:16 -0800452 break;
453 default:
454 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype);
455 ASSERT(0);
456 };
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800457
458 switch(platform) {
459 case MSM8974:
Deepa Dinamani713a76f2013-05-03 13:17:24 -0700460 case MSM8274:
461 case MSM8674:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700462 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 Desai465491e2012-07-31 12:53:35 -0700471 board->baseband = BASEBAND_MSM;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800472 break;
473 case APQ8074:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700474 case APQ8074AA:
475 case APQ8074AB:
476 case APQ8074AC:
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800477 board->baseband = BASEBAND_APQ;
478 break;
479 default:
480 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
481 ASSERT(0);
482 };
Neeti Desai465491e2012-07-31 12:53:35 -0700483}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700484
Deepa Dinamani927a6b62013-03-28 17:05:32 -0700485unsigned target_baseband()
486{
487 return board_baseband();
488}
489
Deepa Dinamani9a612932012-08-14 16:15:03 -0700490void 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 Jadi6639d452012-08-16 14:51:19 -0700498
499unsigned check_reboot_mode(void)
500{
501 uint32_t restart_reason = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800502 uint32_t soc_ver = 0;
503 uint32_t restart_reason_addr;
504
505 soc_ver = board_soc_version();
506
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700507 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800508 restart_reason_addr = RESTART_REASON_ADDR;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700509 else
510 restart_reason_addr = RESTART_REASON_ADDR_V2;
Amol Jadi6639d452012-08-16 14:51:19 -0700511
512 /* Read reboot reason and scrub it */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800513 restart_reason = readl(restart_reason_addr);
514 writel(0x00, restart_reason_addr);
Amol Jadi6639d452012-08-16 14:51:19 -0700515
516 return restart_reason;
517}
Neeti Desai120b55d2012-08-20 17:15:56 -0700518
lijuang395b5e62015-11-19 17:39:44 +0800519int 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 Desai120b55d2012-08-20 17:15:56 -0700528void reboot_device(unsigned reboot_reason)
529{
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800530 uint32_t soc_ver = 0;
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700531 uint8_t reset_type = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800532
lijuang395b5e62015-11-19 17:39:44 +0800533 /* 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 Kadabi8c8587f2013-02-08 12:46:09 -0800539 soc_ver = board_soc_version();
540
Neeti Desai120b55d2012-08-20 17:15:56 -0700541 /* Write the reboot reason */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700542 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800543 writel(reboot_reason, RESTART_REASON_ADDR);
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700544 else
545 writel(reboot_reason, RESTART_REASON_ADDR_V2);
Neeti Desai120b55d2012-08-20 17:15:56 -0700546
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700547 if(reboot_reason == FASTBOOT_MODE)
548 reset_type = PON_PSHOLD_WARM_RESET;
549 else
550 reset_type = PON_PSHOLD_HARD_RESET;
551
Neeti Desai120b55d2012-08-20 17:15:56 -0700552 /* Configure PMIC for warm reset */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700553 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700554 pm8x41_v2_reset_configure(reset_type);
Deepa Dinamani07f15712013-03-08 17:02:13 -0800555 else
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700556 pm8x41_reset_configure(reset_type);
Neeti Desai120b55d2012-08-20 17:15:56 -0700557
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 Agrawal7ac6d512013-01-22 18:39:50 -0800565
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700566/* Check if MSM needs VBUS mimic for USB */
567static int target_needs_vbus_mimic()
568{
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700569 if (platform_is_8974())
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700570 return 0;
571
572 return 1;
573}
574
Eugene Yasmana0d18122013-02-26 13:23:05 +0200575/* Do target specific usb initialization */
576void target_usb_init(void)
577{
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700578 uint32_t val;
579
Eugene Yasmana0d18122013-02-26 13:23:05 +0200580 /* 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 Kadabi6d215b92013-06-23 16:47:07 -0700605
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 Yasmana0d18122013-02-26 13:23:05 +0200620}
621
Casey Piper74f8e5c2013-09-05 15:00:30 -0700622uint8_t target_panel_auto_detect_enabled()
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800623{
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800624 switch(board_hardware_id())
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800625 {
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800626 case HW_PLATFORM_SURF:
627 case HW_PLATFORM_MTP:
628 case HW_PLATFORM_FLUID:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800629 return 1;
630 break;
631 default:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800632 return 0;
Casey Piper74f8e5c2013-09-05 15:00:30 -0700633 break;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800634 }
Casey Piper74f8e5c2013-09-05 15:00:30 -0700635 return 0;
636}
637
Casey Piper74f67a32013-11-18 13:26:18 -0800638uint8_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 Piper74f8e5c2013-09-05 15:00:30 -0700652static uint8_t splash_override;
653/* Returns 1 if target supports continuous splash screen. */
654int 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
676void target_force_cont_splash_disable(uint8_t override)
677{
678 splash_override = override;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800679}
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800680
681unsigned target_pause_for_battery_charge(void)
682{
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800683
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 srinivasana098d832013-03-07 12:19:30 -0800692
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700693void target_uninit(void)
sundarajan srinivasana098d832013-03-07 12:19:30 -0800694{
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700695#if MMC_SDHCI_SUPPORT
696 mmc_put_card_to_sleep(dev);
697#else
698 mmc_put_card_to_sleep();
699#endif
sundarajan srinivasana098d832013-03-07 12:19:30 -0800700#ifdef SSD_ENABLE
701 clock_ce_disable(SSD_CE_INSTANCE_1);
702#endif
Channagoud Kadabi2095a412013-12-04 12:37:06 -0800703 if (crypto_initialized())
704 crypto_eng_cleanup();
Channagoud Kadabid0115f92014-01-24 17:25:34 -0800705
706 /* Disable HC mode before jumping to kernel */
707 sdhci_mode_disable(&dev->host);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800708}
Deepa Dinamani65df9822013-03-08 13:38:34 -0800709
710void shutdown_device()
711{
712 dprintf(CRITICAL, "Going down for shutdown.\n");
713
714 /* Configure PMIC for shutdown. */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700715 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Deepa Dinamani65df9822013-03-08 13:38:34 -0800716 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 Kadabi744c8902013-04-02 11:54:53 -0700726}
727
728static void set_sdc_power_ctrl()
729{
Channagoud Kadabi224d8322013-09-27 14:25:22 -0700730 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 Kadabi744c8902013-04-02 11:54:53 -0700752 /* Drive strength configs for sdc pins */
753 struct tlmm_cfgs sdc1_hdrv_cfg[] =
754 {
Channagoud Kadabi224d8322013-09-27 14:25:22 -0700755 { SDC1_CLK_HDRV_CTL_OFF, tlmm_hdrv_clk, TLMM_HDRV_MASK },
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700756 { 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 Kadabi389cab22013-08-20 15:29:15 -0700768 struct tlmm_cfgs sdc1_rclk_cfg[] =
769 {
770 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK },
771 };
772
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700773 /* 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 Kadabi389cab22013-08-20 15:29:15 -0700776
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 Kadabi744c8902013-04-02 11:54:53 -0700782}
Stanimir Varbanovf64a0292013-04-29 11:58:27 +0300783
784int emmc_recovery_init(void)
785{
786 return _emmc_recovery_init();
787}
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700788
789void target_usb_stop(void)
790{
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700791
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 Jadi4c3229f2013-10-07 14:38:06 -0700796
797/* identify the usb controller to be used for the target */
798const 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 Kadabi62ac4cb2014-05-13 11:55:38 -0700807 if (board_hardware_id() != HW_PLATFORM_DRAGON && !target_hw_interposer())
Amol Jadi4c3229f2013-10-07 14:38:06 -0700808 return "dwc";
809 /* fall through to default "ci" for anything that did'nt select "dwc" */
810 default:
811 return "ci";
812 }
813}
Amol Jadi28864bb2013-10-11 14:12:59 -0700814
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 */
819static 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 */
829void target_usb_phy_mux_configure(void)
830{
831 if(!strcmp(target_usb_controller(), "dwc"))
832 {
833 tcsr_hs_phy_mux_configure();
834 }
835}
lijuang3606df82015-09-02 21:14:43 +0800836
837uint32_t target_get_pmic()
838{
839 return PMIC_IS_PM8941;
lijuang395b5e62015-11-19 17:39:44 +0800840}