blob: c27e07a7f17c8b1f6a891594c18e1f6a4c688e3f [file] [log] [blame]
rayz935a2c72014-02-14 13:17:02 +08001/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
Deepa Dinamani645e9b12012-12-21 14:23:40 -08002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <platform/iomap.h>
Channagoud Kadabif6f71742013-05-23 14:05:05 -070031#include <platform/irqs.h>
Deepa Dinamani645e9b12012-12-21 14:23:40 -080032#include <reg.h>
33#include <target.h>
34#include <platform.h>
Pavel Nedev16f49232013-04-29 16:15:36 +030035#include <dload_util.h>
Deepa Dinamani645e9b12012-12-21 14:23:40 -080036#include <uart_dm.h>
Channagoud Kadabi3c50c312013-05-02 17:16:03 -070037#include <mmc_sdhci.h>
Stanimir Varbanovf0650ca2013-07-01 12:30:24 +030038#include <platform/clock.h>
Deepa Dinamani7e729772013-02-25 11:54:05 -080039#include <platform/gpio.h>
Deepa Dinamani645e9b12012-12-21 14:23:40 -080040#include <spmi.h>
41#include <board.h>
Deepa Dinamaniff2b9ce2013-02-25 11:01:00 -080042#include <smem.h>
43#include <baseband.h>
Deepa Dinamani7e729772013-02-25 11:54:05 -080044#include <dev/keys.h>
Deepa Dinamani058f1cd2013-02-25 10:53:01 -080045#include <pm8x41.h>
Deepa Dinamani6bb87d52013-02-26 14:37:36 -080046#include <crypto5_wrapper.h>
Amol Jadi85e19192013-02-28 22:45:04 -080047#include <hsusb.h>
Stanimir Varbanovf0650ca2013-07-01 12:30:24 +030048#include <scm.h>
49#include <stdlib.h>
50#include <partition_parser.h>
Matthew Qin01b50392014-01-24 16:57:37 +080051#include <shutdown_detect.h>
Matthew Qine2afd232014-02-22 07:20:42 +080052#include <vibrator.h>
Deepa Dinamani645e9b12012-12-21 14:23:40 -080053
Deepa Dinamani6bb87d52013-02-26 14:37:36 -080054extern bool target_use_signed_kernel(void);
Channagoud Kadabi3c50c312013-05-02 17:16:03 -070055static void set_sdc_power_ctrl(void);
Deepa Dinamani6bb87d52013-02-26 14:37:36 -080056
57#define PMIC_ARB_CHANNEL_NUM 0
58#define PMIC_ARB_OWNER_ID 0
59
60#define CRYPTO_ENGINE_INSTANCE 1
61#define CRYPTO_ENGINE_EE 1
62#define CRYPTO_ENGINE_FIFO_SIZE 64
63#define CRYPTO_ENGINE_READ_PIPE 3
64#define CRYPTO_ENGINE_WRITE_PIPE 2
Deepa Dinamanibbcf1ca2013-07-09 14:10:57 -070065#define CRYPTO_READ_PIPE_LOCK_GRP 0
66#define CRYPTO_WRITE_PIPE_LOCK_GRP 0
Deepa Dinamani6bb87d52013-02-26 14:37:36 -080067#define CRYPTO_ENGINE_CMD_ARRAY_SIZE 20
Deepa Dinamani645e9b12012-12-21 14:23:40 -080068
Deepa Dinamani7e729772013-02-25 11:54:05 -080069#define TLMM_VOL_UP_BTN_GPIO 106
Matthew Qine2afd232014-02-22 07:20:42 +080070#define VIBRATE_TIME 250
Deepa Dinamani7e729772013-02-25 11:54:05 -080071
Stanimir Varbanovf0650ca2013-07-01 12:30:24 +030072#define SSD_CE_INSTANCE 1
73
Maria Yub8fd0822013-06-26 10:10:45 +080074enum target_subtype {
75 HW_PLATFORM_SUBTYPE_SKUAA = 1,
76 HW_PLATFORM_SUBTYPE_SKUF = 2,
77 HW_PLATFORM_SUBTYPE_SKUAB = 3,
Jie Chengf3d8a3b2013-08-01 15:37:55 +080078 HW_PLATFORM_SUBTYPE_SKUG = 5,
Maria Yub8fd0822013-06-26 10:10:45 +080079};
80
Channagoud Kadabif6f71742013-05-23 14:05:05 -070081static uint32_t mmc_pwrctl_base[] =
82 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE };
83
Channagoud Kadabi3c50c312013-05-02 17:16:03 -070084static uint32_t mmc_sdhci_base[] =
85 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE };
86
Channagoud Kadabif6f71742013-05-23 14:05:05 -070087static uint32_t mmc_sdc_pwrctl_irq[] =
88 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ, SDCC3_PWRCTL_IRQ };
89
Channagoud Kadabi3c50c312013-05-02 17:16:03 -070090struct mmc_device *dev;
Deepa Dinamani645e9b12012-12-21 14:23:40 -080091
Stanimir Varbanovf0650ca2013-07-01 12:30:24 +030092void target_load_ssd_keystore(void)
93{
94 uint64_t ptn;
95 int index;
96 uint64_t size;
97 uint32_t *buffer;
98
99 if (!target_is_ssd_enabled())
100 return;
101
102 index = partition_get_index("ssd");
103
104 ptn = partition_get_offset(index);
105 if (ptn == 0){
106 dprintf(CRITICAL, "Error: ssd partition not found\n");
107 return;
108 }
109
110 size = partition_get_size(index);
111 if (size == 0) {
112 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
113 return;
114 }
115
116 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
117 if (!buffer) {
118 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
119 return;
120 }
121
122 if (mmc_read(ptn, buffer, size)) {
123 dprintf(CRITICAL, "Error: cannot read data\n");
124 free(buffer);
125 return;
126 }
127
128 clock_ce_enable(SSD_CE_INSTANCE);
129 scm_protect_keystore(buffer, size);
130 clock_ce_disable(SSD_CE_INSTANCE);
131 free(buffer);
132}
133
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800134void target_early_init(void)
135{
136#if WITH_DEBUG_UART
Deepa Dinamani0a6c48c2013-02-04 15:45:01 -0800137 uart_dm_init(1, 0, BLSP1_UART2_BASE);
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800138#endif
139}
140
Deepa Dinamani7e729772013-02-25 11:54:05 -0800141/* Return 1 if vol_up pressed */
142static int target_volume_up()
143{
Swetha Chikkaboraiahc9b7bd22015-11-18 17:07:44 +0530144 static uint8_t first_time = 0;
Deepa Dinamani7e729772013-02-25 11:54:05 -0800145 uint8_t status = 0;
146
Swetha Chikkaboraiahc9b7bd22015-11-18 17:07:44 +0530147 if (!first_time) {
148 gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
Deepa Dinamani7e729772013-02-25 11:54:05 -0800149
Swetha Chikkaboraiahc9b7bd22015-11-18 17:07:44 +0530150 /* Wait for the gpio config to take effect - debounce time */
151 udelay(10000);
152 first_time = 1;
153 }
aiquny933017c2013-03-02 12:48:52 -0800154
Deepa Dinamani7e729772013-02-25 11:54:05 -0800155 /* Get status of GPIO */
156 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
157
158 /* Active low signal. */
159 return !status;
160}
161
162/* Return 1 if vol_down pressed */
163uint32_t target_volume_down()
164{
165 /* Volume down button tied in with PMIC RESIN. */
166 return pm8x41_resin_status();
167}
168
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800169static void target_keystatus()
170{
Deepa Dinamani7e729772013-02-25 11:54:05 -0800171 keys_init();
172
173 if(target_volume_down())
174 keys_post_event(KEY_VOLUMEDOWN, 1);
175
176 if(target_volume_up())
177 keys_post_event(KEY_VOLUMEUP, 1);
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800178}
179
Deepa Dinamani6bb87d52013-02-26 14:37:36 -0800180/* Set up params for h/w CRYPTO_ENGINE. */
181void target_crypto_init_params()
182{
183 struct crypto_init_params ce_params;
184
185 /* Set up base addresses and instance. */
186 ce_params.crypto_instance = CRYPTO_ENGINE_INSTANCE;
187 ce_params.crypto_base = MSM_CE1_BASE;
188 ce_params.bam_base = MSM_CE1_BAM_BASE;
189
190 /* Set up BAM config. */
Deepa Dinamanibbcf1ca2013-07-09 14:10:57 -0700191 ce_params.bam_ee = CRYPTO_ENGINE_EE;
192 ce_params.pipes.read_pipe = CRYPTO_ENGINE_READ_PIPE;
193 ce_params.pipes.write_pipe = CRYPTO_ENGINE_WRITE_PIPE;
194 ce_params.pipes.read_pipe_grp = CRYPTO_READ_PIPE_LOCK_GRP;
195 ce_params.pipes.write_pipe_grp = CRYPTO_WRITE_PIPE_LOCK_GRP;
Deepa Dinamani6bb87d52013-02-26 14:37:36 -0800196
197 /* Assign buffer sizes. */
198 ce_params.num_ce = CRYPTO_ENGINE_CMD_ARRAY_SIZE;
199 ce_params.read_fifo_size = CRYPTO_ENGINE_FIFO_SIZE;
200 ce_params.write_fifo_size = CRYPTO_ENGINE_FIFO_SIZE;
201
Stanimir Varbanovf0650ca2013-07-01 12:30:24 +0300202 ce_params.do_bam_init = 0;
203
Deepa Dinamani6bb87d52013-02-26 14:37:36 -0800204 crypto_init_params(&ce_params);
205}
206
Channagoud Kadabi3c50c312013-05-02 17:16:03 -0700207void target_sdc_init()
208{
Channagoud Kadabif6f71742013-05-23 14:05:05 -0700209 struct mmc_config_data config = {0};
Channagoud Kadabi3c50c312013-05-02 17:16:03 -0700210
211 /*
212 * Set drive strength & pull ctrl for emmc
213 */
214 set_sdc_power_ctrl();
215
Channagoud Kadabi3c50c312013-05-02 17:16:03 -0700216 config.bus_width = DATA_BUS_WIDTH_8BIT;
217 config.max_clk_rate = MMC_CLK_200MHZ;
218
219 /* Trying Slot 1*/
220 config.slot = 1;
Channagoud Kadabif6f71742013-05-23 14:05:05 -0700221 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
222 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
223 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Aparna Mallavarapu1957cb42014-03-11 13:47:34 +0530224 config.hs400_support = 0;
Channagoud Kadabif6f71742013-05-23 14:05:05 -0700225
Channagoud Kadabi3c50c312013-05-02 17:16:03 -0700226 if (!(dev = mmc_init(&config)))
227 {
228 /* Trying Slot 2 next */
229 config.slot = 2;
Channagoud Kadabif6f71742013-05-23 14:05:05 -0700230 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
231 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
232 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
233
Channagoud Kadabi3c50c312013-05-02 17:16:03 -0700234 if (!(dev = mmc_init(&config))) {
235 dprintf(CRITICAL, "mmc init failed!");
236 ASSERT(0);
237 }
238 }
239
240 /*
241 * MMC initialization is complete, read the partition table info
242 */
243 if (partition_read_table()) {
244 dprintf(CRITICAL, "Error reading the partition table info\n");
245 ASSERT(0);
246 }
247}
248
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800249void target_init(void)
250{
Sridhar Parasuram32d42ed2015-09-09 12:58:43 -0700251 int ret = 0;
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800252 dprintf(INFO, "target_init()\n");
253
254 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
255
256 target_keystatus();
257
Aparna Mallavarapu63a62252013-08-23 17:59:43 +0530258 target_sdc_init();
Sridhar Parasuram32d42ed2015-09-09 12:58:43 -0700259 clock_ce_enable(SSD_CE_INSTANCE);
260 if (target_use_signed_kernel())
261 target_crypto_init_params();
Aparna Mallavarapu63a62252013-08-23 17:59:43 +0530262
Sridhar Parasuram32d42ed2015-09-09 12:58:43 -0700263#if VERIFIED_BOOT
264 /* Initialize Qseecom */
265 ret = qseecom_init();
266
267 if (ret < 0)
268 {
269 dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret);
270 ASSERT(0);
271 }
272
273 /* Start Qseecom */
274 ret = qseecom_tz_init();
275
276 if (ret < 0)
277 {
278 dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret);
279 ASSERT(0);
280 }
281
282 /*
283 * Load the sec app for first time
284 */
285 if (load_sec_app() < 0)
286 {
287 dprintf(CRITICAL, "Failed to load App for verified\n");
288 ASSERT(0);
289 }
290#endif
Matthew Qin01b50392014-01-24 16:57:37 +0800291 shutdown_detect();
292
Matthew Qine2afd232014-02-22 07:20:42 +0800293 /* turn on vibrator to indicate that phone is booting up to end user */
294 vib_timed_turn_on(VIBRATE_TIME);
295
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800296}
297
Deepa Dinamani058f1cd2013-02-25 10:53:01 -0800298/* Do any target specific intialization needed before entering fastboot mode */
299void target_fastboot_init(void)
300{
301 /* Set the BOOT_DONE flag in PM8026 */
302 pm8x41_set_boot_done();
Stanimir Varbanovf0650ca2013-07-01 12:30:24 +0300303
304 if (target_is_ssd_enabled()) {
305 clock_ce_enable(SSD_CE_INSTANCE);
306 target_load_ssd_keystore();
307 }
Deepa Dinamani058f1cd2013-02-25 10:53:01 -0800308}
309
Deepa Dinamaniff2b9ce2013-02-25 11:01:00 -0800310/* Detect the target type */
311void target_detect(struct board_data *board)
312{
Maria Yuca51ee22013-06-27 21:45:24 +0800313 /*
314 * already fill the board->target on board.c
315 */
Deepa Dinamaniff2b9ce2013-02-25 11:01:00 -0800316}
317
318/* Detect the modem type */
319void target_baseband_detect(struct board_data *board)
320{
321 uint32_t platform;
322 uint32_t platform_subtype;
323
324 platform = board->platform;
325 platform_subtype = board->platform_subtype;
326
327 /*
328 * Look for platform subtype if present, else
329 * check for platform type to decide on the
330 * baseband type
331 */
332 switch(platform_subtype)
333 {
334 case HW_PLATFORM_SUBTYPE_UNKNOWN:
335 break;
Maria Yub8fd0822013-06-26 10:10:45 +0800336 case HW_PLATFORM_SUBTYPE_SKUAA:
337 break;
338 case HW_PLATFORM_SUBTYPE_SKUF:
339 break;
340 case HW_PLATFORM_SUBTYPE_SKUAB:
341 break;
Jie Chengf3d8a3b2013-08-01 15:37:55 +0800342 case HW_PLATFORM_SUBTYPE_SKUG:
343 break;
Deepa Dinamaniff2b9ce2013-02-25 11:01:00 -0800344 default:
345 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype);
346 ASSERT(0);
347 };
348
349 switch(platform)
350 {
351 case MSM8826:
352 case MSM8626:
353 case MSM8226:
Deepa Dinamani7eeecf62013-05-21 12:43:26 -0700354 case MSM8926:
355 case MSM8126:
356 case MSM8326:
Deepa Dinamanicd795aa2013-09-05 16:30:53 -0700357 case MSM8528:
358 case MSM8628:
359 case MSM8228:
360 case MSM8928:
361 case MSM8128:
Deepa Dinamaniff2b9ce2013-02-25 11:01:00 -0800362 board->baseband = BASEBAND_MSM;
363 break;
Deepa Dinamani7eeecf62013-05-21 12:43:26 -0700364 case APQ8026:
Deepa Dinamanicd795aa2013-09-05 16:30:53 -0700365 case APQ8028:
Deepa Dinamani7eeecf62013-05-21 12:43:26 -0700366 board->baseband = BASEBAND_APQ;
367 break;
Deepa Dinamaniff2b9ce2013-02-25 11:01:00 -0800368 default:
369 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
370 ASSERT(0);
371 };
372}
373
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800374void target_serialno(unsigned char *buf)
375{
376 uint32_t serialno;
377 if (target_is_emmc_boot()) {
378 serialno = mmc_get_psn();
379 snprintf((char *)buf, 13, "%x", serialno);
380 }
381}
382
Deepa Dinamani8d2bb222013-02-26 14:03:04 -0800383unsigned check_reboot_mode(void)
384{
385 uint32_t restart_reason = 0;
386
387 /* Read reboot reason and scrub it */
388 restart_reason = readl(RESTART_REASON_ADDR);
389 writel(0x00, RESTART_REASON_ADDR);
390
391 return restart_reason;
392}
393
Deepa Dinamanif7c03c12013-02-26 14:17:20 -0800394void reboot_device(unsigned reboot_reason)
395{
Channagoud Kadabi559dcda2014-02-25 15:28:08 -0800396 int ret = 0;
397
Deepa Dinamanif7c03c12013-02-26 14:17:20 -0800398 writel(reboot_reason, RESTART_REASON_ADDR);
399
400 /* Configure PMIC for warm reset */
401 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
402
Channagoud Kadabi559dcda2014-02-25 15:28:08 -0800403 ret = scm_halt_pmic_arbiter();
404 if (ret)
405 dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret);
406
Deepa Dinamanif7c03c12013-02-26 14:17:20 -0800407 /* Drop PS_HOLD for MSM */
408 writel(0x00, MPM2_MPM_PS_HOLD);
409
410 mdelay(5000);
411
412 dprintf(CRITICAL, "Rebooting failed\n");
413}
414
Matthew Qin7dc113b2014-02-21 10:34:09 +0800415/* Configure PMIC and Drop PS_HOLD for shutdown */
416void shutdown_device()
417{
418 dprintf(CRITICAL, "Going down for shutdown.\n");
419
420 /* Configure PMIC for shutdown */
421 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
422
423 /* Drop PS_HOLD for MSM */
424 writel(0x00, MPM2_MPM_PS_HOLD);
425
426 mdelay(5000);
427
428 dprintf(CRITICAL, "shutdown failed\n");
429
430 ASSERT(0);
431}
432
Deepa Dinamani6bb87d52013-02-26 14:37:36 -0800433crypto_engine_type board_ce_type(void)
434{
435 return CRYPTO_ENGINE_TYPE_HW;
436}
437
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800438unsigned board_machtype(void)
439{
Deepa Dinamani8d6b4252013-03-06 11:16:41 -0800440 return 0;
441}
442
443void target_usb_stop(void)
444{
445 /* Disable VBUS mimicing in the controller. */
446 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800447}
Amol Jadi85e19192013-02-28 22:45:04 -0800448
Channagoud Kadabie3a695a2013-06-18 18:35:00 -0700449void target_uninit(void)
450{
Matthew Qine2afd232014-02-22 07:20:42 +0800451 /* wait for the vibrator timer is expried */
452 wait_vib_timeout();
453
Channagoud Kadabie3a695a2013-06-18 18:35:00 -0700454 mmc_put_card_to_sleep(dev);
Stanimir Varbanovf0650ca2013-07-01 12:30:24 +0300455
Sridhar Parasuram32d42ed2015-09-09 12:58:43 -0700456 clock_ce_disable(SSD_CE_INSTANCE);
Channagoud Kadabid727a772013-12-04 12:38:27 -0800457 if (crypto_initialized())
458 crypto_eng_cleanup();
Sundarajan Srinivasan2a60d632014-05-08 16:36:25 -0700459
Sridhar Parasuram32d42ed2015-09-09 12:58:43 -0700460#if VERIFIED_BOOT
461 if (is_sec_app_loaded())
462 {
463 if (send_milestone_call_to_tz() < 0)
464 {
465 dprintf(CRITICAL, "Failed to send milestone call\n");
466 ASSERT(0);
467 }
468 }
469#endif
Channagoud Kadabie3a695a2013-06-18 18:35:00 -0700470}
471
Amol Jadi85e19192013-02-28 22:45:04 -0800472void target_usb_init(void)
473{
474 uint32_t val;
475
476 /* Select and enable external configuration with USB PHY */
477 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
478
479 /* Enable sess_vld */
480 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
481 writel(val, USB_GENCONFIG_2);
482
483 /* Enable external vbus configuration in the LINK */
484 val = readl(USB_USBCMD);
485 val |= SESS_VLD_CTRL;
486 writel(val, USB_USBCMD);
487}
Deepa Dinamanicde64572013-02-25 15:02:25 -0800488
Pradeep Jilagamcd51b522013-10-29 13:08:51 +0530489uint8_t target_panel_auto_detect_enabled()
490{
Aravind Venkateswaranc2923702013-12-18 17:50:35 -0800491 uint8_t ret = 0;
rayz935a2c72014-02-14 13:17:02 +0800492 uint32_t hw_subtype = board_hardware_subtype();
Aravind Venkateswaranc2923702013-12-18 17:50:35 -0800493
Pradeep Jilagamcd51b522013-10-29 13:08:51 +0530494 switch(board_hardware_id())
495 {
496 case HW_PLATFORM_QRD:
rayz935a2c72014-02-14 13:17:02 +0800497 if (hw_subtype != HW_PLATFORM_SUBTYPE_SKUF
498 && hw_subtype != HW_PLATFORM_SUBTYPE_SKUG) {
499 /* Enable autodetect for 8x26 DVT boards only */
500 if (((board_target_id() >> 16) & 0xFF) == 0x2)
501 ret = 1;
502 else
503 ret = 0;
504 }
Aravind Venkateswaranc2923702013-12-18 17:50:35 -0800505 break;
Pradeep Jilagamcd51b522013-10-29 13:08:51 +0530506 case HW_PLATFORM_SURF:
507 case HW_PLATFORM_MTP:
508 default:
Aravind Venkateswaranc2923702013-12-18 17:50:35 -0800509 ret = 0;
Pradeep Jilagamcd51b522013-10-29 13:08:51 +0530510 }
Aravind Venkateswaranc2923702013-12-18 17:50:35 -0800511 return ret;
Pradeep Jilagamcd51b522013-10-29 13:08:51 +0530512}
513
514static uint8_t splash_override;
Ray Zhang743e5032013-05-25 23:25:39 +0800515/* Returns 1 if target supports continuous splash screen. */
516int target_cont_splash_screen()
517{
Pradeep Jilagamcd51b522013-10-29 13:08:51 +0530518 uint8_t splash_screen = 0;
519 if(!splash_override) {
520 switch(board_hardware_id())
521 {
522 case HW_PLATFORM_MTP:
523 case HW_PLATFORM_QRD:
524 case HW_PLATFORM_SURF:
525 dprintf(SPEW, "Target_cont_splash=1\n");
526 splash_screen = 1;
527 break;
528 default:
529 dprintf(SPEW, "Target_cont_splash=0\n");
530 splash_screen = 0;
531 }
532 }
533 return splash_screen;
534}
535
536void target_force_cont_splash_disable(uint8_t override)
537{
538 splash_override = override;
Ray Zhang743e5032013-05-25 23:25:39 +0800539}
540
Deepa Dinamanicde64572013-02-25 15:02:25 -0800541unsigned target_pause_for_battery_charge(void)
542{
543 uint8_t pon_reason = pm8x41_get_pon_reason();
Ameya Thakur06041312013-06-25 13:46:21 -0700544 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
Ameya Thakur531e59a2013-07-17 16:53:53 -0700545 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
546 pon_reason, is_cold_boot);
Ameya Thakura8711dc2013-07-19 17:52:51 -0700547 /* In case of fastboot reboot,adb reboot or if we see the power key
548 * pressed we do not want go into charger mode.
Ameya Thakur531e59a2013-07-17 16:53:53 -0700549 * fastboot reboot is warm boot with PON hard reset bit not set
550 * adb reboot is a cold boot with PON hard reset bit set
551 */
Ameya Thakura8711dc2013-07-19 17:52:51 -0700552 if (is_cold_boot &&
553 (!(pon_reason & HARD_RST)) &&
554 (!(pon_reason & KPDPWR_N)) &&
Ameya Thakur531e59a2013-07-17 16:53:53 -0700555 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG)))
556 return 1;
557 else
558 return 0;
Deepa Dinamanicde64572013-02-25 15:02:25 -0800559}
Channagoud Kadabida54ca12013-03-29 11:22:15 -0700560
561unsigned target_baseband()
562{
563 return board_baseband();
564}
Stanimir Varbanov7f9d7a72013-04-29 12:05:39 +0300565
566int emmc_recovery_init(void)
567{
Pavel Nedev16f49232013-04-29 16:15:36 +0300568 return _emmc_recovery_init();
569}
570
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300571int set_download_mode(enum dload_mode mode)
Pavel Nedev16f49232013-04-29 16:15:36 +0300572{
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300573 dload_util_write_cookie(mode == NORMAL_DLOAD ?
574 DLOAD_MODE_ADDR : EMERGENCY_DLOAD_MODE_ADDR, mode);
Pavel Nedev16f49232013-04-29 16:15:36 +0300575
Xiaocheng Li9ddc84a2013-09-14 17:32:00 +0800576 pm8x41_clear_pmic_watchdog();
577
Pavel Nedev16f49232013-04-29 16:15:36 +0300578 return 0;
Stanimir Varbanov7f9d7a72013-04-29 12:05:39 +0300579}
Channagoud Kadabi3c50c312013-05-02 17:16:03 -0700580
581static void set_sdc_power_ctrl()
582{
583 /* Drive strength configs for sdc pins */
584 struct tlmm_cfgs sdc1_hdrv_cfg[] =
585 {
Channagoud Kadabi9d4acea2014-01-03 16:18:54 -0800586 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
Channagoud Kadabi3c50c312013-05-02 17:16:03 -0700587 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
Channagoud Kadabi9d4acea2014-01-03 16:18:54 -0800588 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK },
Channagoud Kadabi3c50c312013-05-02 17:16:03 -0700589 };
590
591 /* Pull configs for sdc pins */
592 struct tlmm_cfgs sdc1_pull_cfg[] =
593 {
594 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
595 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
596 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
597 };
598
599 /* Set the drive strength & pull control values */
600 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
601 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
602}
603
604struct mmc_device *target_mmc_device()
605{
606 return dev;
607}