blob: 5ae8341a2c5cd80e88bef934dba408b239b643d6 [file] [log] [blame]
Eugene Yasman6382ee02013-01-16 13:00:56 +02001/* Copyright (c) 2012-2013, 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 Kadabi744c8902013-04-02 11:54:53 -070031#include <platform/gpio.h>
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080032#include <reg.h>
33#include <target.h>
34#include <platform.h>
Pavel Nedev03511492013-03-08 19:05:32 -080035#include <dload_util.h>
Deepa Dinamani26e93262012-05-21 17:35:14 -070036#include <uart_dm.h>
Amol Jadi29f95032012-06-22 12:52:54 -070037#include <mmc.h>
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080038#include <spmi.h>
Neeti Desai465491e2012-07-31 12:53:35 -070039#include <board.h>
40#include <smem.h>
41#include <baseband.h>
Deepa Dinamani9a612932012-08-14 16:15:03 -070042#include <dev/keys.h>
43#include <pm8x41.h>
Deepa Dinamanib9a57202012-12-20 18:05:11 -080044#include <crypto5_wrapper.h>
Eugene Yasmana0d18122013-02-26 13:23:05 +020045#include <hsusb.h>
46#include <clock.h>
sundarajan srinivasana098d832013-03-07 12:19:30 -080047#include <partition_parser.h>
48#include <scm.h>
49#include <platform/clock.h>
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070050#include <platform/gpio.h>
Channagoud Kadabif84830c2013-04-19 14:35:47 -070051#include <stdlib.h>
Deepa Dinamanib9a57202012-12-20 18:05:11 -080052
53extern bool target_use_signed_kernel(void);
Channagoud Kadabi744c8902013-04-02 11:54:53 -070054static void set_sdc_power_ctrl();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080055
56static unsigned int target_id;
Deepa Dinamani07f15712013-03-08 17:02:13 -080057static uint32_t pmic_ver;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080058
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070059#if MMC_SDHCI_SUPPORT
60struct mmc_device *dev;
61#endif
62
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080063#define PMIC_ARB_CHANNEL_NUM 0
64#define PMIC_ARB_OWNER_ID 0
65
Deepa Dinamani1e094942012-10-30 15:49:02 -070066#define WDOG_DEBUG_DISABLE_BIT 17
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080067
Deepa Dinamanib9a57202012-12-20 18:05:11 -080068#define CE_INSTANCE 2
69#define CE_EE 1
70#define CE_FIFO_SIZE 64
71#define CE_READ_PIPE 3
72#define CE_WRITE_PIPE 2
73#define CE_ARRAY_SIZE 20
74
sundarajan srinivasana098d832013-03-07 12:19:30 -080075#ifdef SSD_ENABLE
76#define SSD_CE_INSTANCE_1 1
77#define SSD_PARTITION_SIZE 8192
78#endif
79
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070080#if MMC_SDHCI_SUPPORT
81static uint32_t mmc_sdhci_base[] =
82 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE, MSM_SDC4_SDHCI_BASE };
83#endif
84
Deepa Dinamanica5ad852012-05-07 18:19:47 -070085static uint32_t mmc_sdc_base[] =
86 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
87
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080088void target_early_init(void)
89{
Deepa Dinamanib073ba22012-08-10 11:06:41 -070090#if WITH_DEBUG_UART
Neeti Desaiac011272012-08-29 18:24:54 -070091 uart_dm_init(1, 0, BLSP1_UART1_BASE);
Deepa Dinamanib073ba22012-08-10 11:06:41 -070092#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080093}
94
Deepa Dinamani9a612932012-08-14 16:15:03 -070095/* Return 1 if vol_up pressed */
96static int target_volume_up()
97{
98 uint8_t status = 0;
99 struct pm8x41_gpio gpio;
100
101 /* CDP vol_up seems to be always grounded. So gpio status is read as 0,
102 * whether key is pressed or not.
103 * Ignore volume_up key on CDP for now.
104 */
105 if (board_hardware_id() == HW_PLATFORM_SURF)
106 return 0;
107
108 /* Configure the GPIO */
109 gpio.direction = PM_GPIO_DIR_IN;
110 gpio.function = 0;
111 gpio.pull = PM_GPIO_PULL_UP_30;
Eugene Yasman6382ee02013-01-16 13:00:56 +0200112 gpio.vin_sel = 2;
Deepa Dinamani9a612932012-08-14 16:15:03 -0700113
114 pm8x41_gpio_config(5, &gpio);
115
116 /* Get status of P_GPIO_5 */
117 pm8x41_gpio_get(5, &status);
118
119 return !status; /* active low */
120}
121
122/* Return 1 if vol_down pressed */
Deepa Dinamani66a87962013-02-04 10:39:30 -0800123uint32_t target_volume_down()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700124{
Deepa Dinamani66a87962013-02-04 10:39:30 -0800125 /* Volume down button is tied in with RESIN on MSM8974. */
Deepa Dinamani07f15712013-03-08 17:02:13 -0800126 if (pmic_ver == PMIC_VERSION_V2)
Deepa Dinamani13bfc852013-02-05 17:56:47 -0800127 return pm8x41_resin_bark_workaround_status();
128 else
129 return pm8x41_resin_status();
Deepa Dinamani9a612932012-08-14 16:15:03 -0700130}
131
132static void target_keystatus()
133{
134 keys_init();
135
136 if(target_volume_down())
137 keys_post_event(KEY_VOLUMEDOWN, 1);
138
139 if(target_volume_up())
140 keys_post_event(KEY_VOLUMEUP, 1);
141}
142
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800143/* Set up params for h/w CE. */
144void target_crypto_init_params()
145{
146 struct crypto_init_params ce_params;
147
148 /* Set up base addresses and instance. */
149 ce_params.crypto_instance = CE_INSTANCE;
150 ce_params.crypto_base = MSM_CE2_BASE;
151 ce_params.bam_base = MSM_CE2_BAM_BASE;
152
153 /* Set up BAM config. */
154 ce_params.bam_ee = CE_EE;
155 ce_params.pipes.read_pipe = CE_READ_PIPE;
156 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
157
158 /* Assign buffer sizes. */
159 ce_params.num_ce = CE_ARRAY_SIZE;
160 ce_params.read_fifo_size = CE_FIFO_SIZE;
161 ce_params.write_fifo_size = CE_FIFO_SIZE;
162
Deepa Dinamanie505d3d2013-05-14 16:55:38 -0700163 /* BAM is initialized by TZ for this platform.
164 * Do not do it again as the initialization address space
165 * is locked.
166 */
167 ce_params.do_bam_init = 0;
168
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800169 crypto_init_params(&ce_params);
170}
171
172crypto_engine_type board_ce_type(void)
173{
174 return CRYPTO_ENGINE_TYPE_HW;
175}
176
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700177#if MMC_SDHCI_SUPPORT
178static target_mmc_sdhci_init()
179{
180 struct mmc_config_data config;
181 uint32_t soc_ver = 0;
182
183 /* Enable sdhci mode */
184 sdhci_mode_enable(1);
185
186 soc_ver = board_soc_version();
187
188 /*
189 * 8974 v1 fluid devices, have a hardware bug
190 * which limits the bus width to 4 bit.
191 */
192 switch(board_hardware_id())
193 {
194 case HW_PLATFORM_FLUID:
195 if (soc_ver >= BOARD_SOC_VERSION2)
196 config.bus_width = DATA_BUS_WIDTH_8BIT;
197 else
198 config.bus_width = DATA_BUS_WIDTH_4BIT;
199 break;
200 default:
201 config.bus_width = DATA_BUS_WIDTH_8BIT;
202 };
203
204 config.max_clk_rate = MMC_CLK_200MHZ;
205
206 /* Trying Slot 1*/
207 config.slot = 1;
208 config.base = mmc_sdhci_base[config.slot - 1];
209
210 if (!(dev = mmc_init(&config))) {
211 /* Trying Slot 2 next */
212 config.slot = 2;
213 config.base = mmc_sdhci_base[config.slot - 1];
214 if (!(dev = mmc_init(&config))) {
215 dprintf(CRITICAL, "mmc init failed!");
216 ASSERT(0);
217 }
218 }
Channagoud Kadabief5332f2013-05-16 15:23:43 -0700219
220 /*
221 * MMC initialization is complete, read the partition table info
222 */
223 if (partition_read_table()) {
224 dprintf(CRITICAL, "Error reading the partition table info\n");
225 ASSERT(0);
226 }
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700227}
228
229struct mmc_device *target_mmc_device()
230{
231 return dev;
232}
233#else
234static target_mmc_mci_init()
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800235{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700236 uint32_t base_addr;
237 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800238
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700239 /* Trying Slot 1 */
240 slot = 1;
241 base_addr = mmc_sdc_base[slot - 1];
242
243 if (mmc_boot_main(slot, base_addr))
244 {
245 /* Trying Slot 2 next */
246 slot = 2;
247 base_addr = mmc_sdc_base[slot - 1];
248 if (mmc_boot_main(slot, base_addr)) {
249 dprintf(CRITICAL, "mmc init failed!");
250 ASSERT(0);
251 }
252 }
253}
254
255/*
256 * Function to set the capabilities for the host
257 */
258void target_mmc_caps(struct mmc_host *host)
259{
260 uint32_t soc_ver = 0;
261
262 soc_ver = board_soc_version();
263
264 /*
265 * 8974 v1 fluid devices, have a hardware bug
266 * which limits the bus width to 4 bit.
267 */
268 switch(board_hardware_id())
269 {
270 case HW_PLATFORM_FLUID:
271 if (soc_ver >= BOARD_SOC_VERSION2)
272 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
273 else
274 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT;
275 break;
276 default:
277 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
278 };
279
280 host->caps.ddr_mode = 1;
281 host->caps.hs200_mode = 1;
282 host->caps.hs_clk_rate = MMC_CLK_96MHZ;
283}
284#endif
285
286
287void target_init(void)
288{
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800289 dprintf(INFO, "target_init()\n");
290
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800291 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800292
Deepa Dinamani07f15712013-03-08 17:02:13 -0800293 /* Save PM8941 version info. */
294 pmic_ver = pm8x41_get_pmic_rev();
295
Deepa Dinamani9a612932012-08-14 16:15:03 -0700296 target_keystatus();
297
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800298 if (target_use_signed_kernel())
299 target_crypto_init_params();
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800300 /* Display splash screen if enabled */
301#if DISPLAY_SPLASH_SCREEN
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800302 dprintf(INFO, "Display Init: Start\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800303 display_init();
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800304 dprintf(INFO, "Display Init: Done\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800305#endif
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800306
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700307 /*
308 * Set drive strength & pull ctrl for
309 * emmc
310 */
311 set_sdc_power_ctrl();
312
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700313#if MMC_SDHCI_SUPPORT
314 target_mmc_sdhci_init();
315#else
316 target_mmc_mci_init();
317#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800318}
319
320unsigned board_machtype(void)
321{
322 return target_id;
323}
324
325/* Do any target specific intialization needed before entering fastboot mode */
sundarajan srinivasana098d832013-03-07 12:19:30 -0800326#ifdef SSD_ENABLE
sundarajan srinivasana098d832013-03-07 12:19:30 -0800327static void ssd_load_keystore_from_emmc()
328{
329 uint64_t ptn = 0;
330 int index = -1;
331 uint32_t size = SSD_PARTITION_SIZE;
332 int ret = -1;
333
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700334 uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE,
335 ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE));
336
337 if (!buffer) {
338 dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n");
339 ASSERT(0);
340 }
341
sundarajan srinivasana098d832013-03-07 12:19:30 -0800342 index = partition_get_index("ssd");
343
344 ptn = partition_get_offset(index);
345 if(ptn == 0){
346 dprintf(CRITICAL,"ERROR: ssd parition not found");
347 return;
348 }
349
350 if(mmc_read(ptn, buffer, size)){
351 dprintf(CRITICAL,"ERROR:Cannot read data\n");
352 return;
353 }
354
355 ret = scm_protect_keystore((uint32_t *)&buffer[0],size);
356 if(ret != 0)
357 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed");
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700358
359 free(buffer);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800360}
361#endif
362
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800363void target_fastboot_init(void)
364{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700365 /* Set the BOOT_DONE flag in PM8921 */
366 pm8x41_set_boot_done();
sundarajan srinivasana098d832013-03-07 12:19:30 -0800367
368#ifdef SSD_ENABLE
369 clock_ce_enable(SSD_CE_INSTANCE_1);
370 ssd_load_keystore_from_emmc();
371#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800372}
Neeti Desai465491e2012-07-31 12:53:35 -0700373
374/* Detect the target type */
375void target_detect(struct board_data *board)
376{
377 board->target = LINUX_MACHTYPE_UNKNOWN;
378}
379
380/* Detect the modem type */
381void target_baseband_detect(struct board_data *board)
382{
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800383 uint32_t platform;
384 uint32_t platform_subtype;
385
386 platform = board->platform;
387 platform_subtype = board->platform_subtype;
388
389 /*
390 * Look for platform subtype if present, else
391 * check for platform type to decide on the
392 * baseband type
393 */
394 switch(platform_subtype) {
395 case HW_PLATFORM_SUBTYPE_UNKNOWN:
396 break;
Joel Kingead31e82013-04-20 11:26:01 -0700397 case HW_PLATFORM_SUBTYPE_MDM:
398 board->baseband = BASEBAND_MDM;
399 return;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800400 default:
401 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype);
402 ASSERT(0);
403 };
404
405 switch(platform) {
406 case MSM8974:
Deepa Dinamani713a76f2013-05-03 13:17:24 -0700407 case MSM8274:
408 case MSM8674:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700409 case MSM8274AA:
410 case MSM8274AB:
411 case MSM8274AC:
412 case MSM8674AA:
413 case MSM8674AB:
414 case MSM8674AC:
415 case MSM8974AA:
416 case MSM8974AB:
417 case MSM8974AC:
Neeti Desai465491e2012-07-31 12:53:35 -0700418 board->baseband = BASEBAND_MSM;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800419 break;
420 case APQ8074:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700421 case APQ8074AA:
422 case APQ8074AB:
423 case APQ8074AC:
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800424 board->baseband = BASEBAND_APQ;
425 break;
426 default:
427 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
428 ASSERT(0);
429 };
Neeti Desai465491e2012-07-31 12:53:35 -0700430}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700431
Deepa Dinamani927a6b62013-03-28 17:05:32 -0700432unsigned target_baseband()
433{
434 return board_baseband();
435}
436
Deepa Dinamani9a612932012-08-14 16:15:03 -0700437void target_serialno(unsigned char *buf)
438{
439 unsigned int serialno;
440 if (target_is_emmc_boot()) {
441 serialno = mmc_get_psn();
442 snprintf((char *)buf, 13, "%x", serialno);
443 }
444}
Amol Jadi6639d452012-08-16 14:51:19 -0700445
446unsigned check_reboot_mode(void)
447{
448 uint32_t restart_reason = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800449 uint32_t soc_ver = 0;
450 uint32_t restart_reason_addr;
451
452 soc_ver = board_soc_version();
453
454 if (soc_ver >= BOARD_SOC_VERSION2)
455 restart_reason_addr = RESTART_REASON_ADDR_V2;
456 else
457 restart_reason_addr = RESTART_REASON_ADDR;
Amol Jadi6639d452012-08-16 14:51:19 -0700458
459 /* Read reboot reason and scrub it */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800460 restart_reason = readl(restart_reason_addr);
461 writel(0x00, restart_reason_addr);
Amol Jadi6639d452012-08-16 14:51:19 -0700462
463 return restart_reason;
464}
Neeti Desai120b55d2012-08-20 17:15:56 -0700465
466void reboot_device(unsigned reboot_reason)
467{
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800468 uint32_t soc_ver = 0;
469
470 soc_ver = board_soc_version();
471
Neeti Desai120b55d2012-08-20 17:15:56 -0700472 /* Write the reboot reason */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800473 if (soc_ver >= BOARD_SOC_VERSION2)
474 writel(reboot_reason, RESTART_REASON_ADDR_V2);
475 else
476 writel(reboot_reason, RESTART_REASON_ADDR);
Neeti Desai120b55d2012-08-20 17:15:56 -0700477
478 /* Configure PMIC for warm reset */
Deepa Dinamani07f15712013-03-08 17:02:13 -0800479 if (pmic_ver == PMIC_VERSION_V2)
480 pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET);
481 else
482 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
Neeti Desai120b55d2012-08-20 17:15:56 -0700483
Deepa Dinamani1e094942012-10-30 15:49:02 -0700484 /* Disable Watchdog Debug.
485 * Required becuase of a H/W bug which causes the system to
486 * reset partially even for non watchdog resets.
487 */
488 writel(readl(GCC_WDOG_DEBUG) & ~(1 << WDOG_DEBUG_DISABLE_BIT), GCC_WDOG_DEBUG);
489
Deepa Dinamanie0808e52012-11-26 15:22:46 -0800490 dsb();
491
492 /* Wait until the write takes effect. */
493 while(readl(GCC_WDOG_DEBUG) & (1 << WDOG_DEBUG_DISABLE_BIT));
494
Neeti Desai120b55d2012-08-20 17:15:56 -0700495 /* Drop PS_HOLD for MSM */
496 writel(0x00, MPM2_MPM_PS_HOLD);
497
498 mdelay(5000);
499
500 dprintf(CRITICAL, "Rebooting failed\n");
501}
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800502
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300503int set_download_mode(enum dload_mode mode)
Pavel Nedev03511492013-03-08 19:05:32 -0800504{
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300505 dload_util_write_cookie(mode == NORMAL_DLOAD ?
506 DLOAD_MODE_ADDR_V2 : EMERGENCY_DLOAD_MODE_ADDR_V2, mode);
Pavel Nedev03511492013-03-08 19:05:32 -0800507
508 return 0;
509}
510
Eugene Yasmana0d18122013-02-26 13:23:05 +0200511/* Do target specific usb initialization */
512void target_usb_init(void)
513{
514 /* Enable secondary USB PHY on DragonBoard8074 */
515 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
516 /* Route ChipIDea to use secondary USB HS port2 */
517 writel_relaxed(1, USB2_PHY_SEL);
518
519 /* Enable access to secondary PHY by clamping the low
520 * voltage interface between DVDD of the PHY and Vddcx
521 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
522 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
523 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
524
525 /* Perform power-on-reset of the PHY.
526 * Delay values are arbitrary */
527 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
528 USB_OTG_HS_PHY_CTRL);
529 thread_sleep(10);
530 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
531 USB_OTG_HS_PHY_CTRL);
532 thread_sleep(10);
533
534 /* Enable HSUSB PHY port for ULPI interface,
535 * then configure related parameters within the PHY */
536 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
537 | 0x8c000004), USB_PORTSC);
538 }
539}
540
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800541/* Returns 1 if target supports continuous splash screen. */
542int target_cont_splash_screen()
543{
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800544 switch(board_hardware_id())
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800545 {
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800546 case HW_PLATFORM_SURF:
547 case HW_PLATFORM_MTP:
548 case HW_PLATFORM_FLUID:
Asaf Pensob85263f2013-05-01 10:54:34 +0300549 case HW_PLATFORM_DRAGON:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800550 dprintf(SPEW, "Target_cont_splash=1\n");
551 return 1;
552 break;
553 default:
554 dprintf(SPEW, "Target_cont_splash=0\n");
555 return 0;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800556 }
557}
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800558
559unsigned target_pause_for_battery_charge(void)
560{
561 uint8_t pon_reason = pm8x41_get_pon_reason();
562
563 /* This function will always return 0 to facilitate
564 * automated testing/reboot with usb connected.
565 * uncomment if this feature is needed */
566 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
567 return 1;*/
568
569 return 0;
570}
sundarajan srinivasana098d832013-03-07 12:19:30 -0800571
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700572void target_uninit(void)
sundarajan srinivasana098d832013-03-07 12:19:30 -0800573{
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700574#if MMC_SDHCI_SUPPORT
575 mmc_put_card_to_sleep(dev);
576#else
577 mmc_put_card_to_sleep();
578#endif
sundarajan srinivasana098d832013-03-07 12:19:30 -0800579#ifdef SSD_ENABLE
580 clock_ce_disable(SSD_CE_INSTANCE_1);
581#endif
582}
Deepa Dinamani65df9822013-03-08 13:38:34 -0800583
584void shutdown_device()
585{
586 dprintf(CRITICAL, "Going down for shutdown.\n");
587
588 /* Configure PMIC for shutdown. */
589 if (pmic_ver == PMIC_VERSION_V2)
590 pm8x41_v2_reset_configure(PON_PSHOLD_SHUTDOWN);
591 else
592 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
593
594 /* Drop PS_HOLD for MSM */
595 writel(0x00, MPM2_MPM_PS_HOLD);
596
597 mdelay(5000);
598
599 dprintf(CRITICAL, "Shutdown failed\n");
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700600}
601
602static void set_sdc_power_ctrl()
603{
604 /* Drive strength configs for sdc pins */
605 struct tlmm_cfgs sdc1_hdrv_cfg[] =
606 {
607 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
608 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
609 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
610 };
611
612 /* Pull configs for sdc pins */
613 struct tlmm_cfgs sdc1_pull_cfg[] =
614 {
615 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
616 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
617 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
618 };
619
620 /* Set the drive strength & pull control values */
621 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
622 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
623}
Stanimir Varbanovf64a0292013-04-29 11:58:27 +0300624
625int emmc_recovery_init(void)
626{
627 return _emmc_recovery_init();
628}