blob: 11a99671fc624a56868d906f3bc6fc57db7d8400 [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 Kadabic48b3e92013-06-23 16:19:10 -070080#define BOARD_SOC_VERSION1(soc_rev) (soc_rev >= 0x10000 && soc_rev < 0x20000)
81
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070082#if MMC_SDHCI_SUPPORT
83static uint32_t mmc_sdhci_base[] =
84 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE, MSM_SDC4_SDHCI_BASE };
85#endif
86
Deepa Dinamanica5ad852012-05-07 18:19:47 -070087static uint32_t mmc_sdc_base[] =
88 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
89
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080090void target_early_init(void)
91{
Deepa Dinamanib073ba22012-08-10 11:06:41 -070092#if WITH_DEBUG_UART
Neeti Desaiac011272012-08-29 18:24:54 -070093 uart_dm_init(1, 0, BLSP1_UART1_BASE);
Deepa Dinamanib073ba22012-08-10 11:06:41 -070094#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080095}
96
Channagoud Kadabic48b3e92013-06-23 16:19:10 -070097/* Check for 8974 chip */
98static int target_is_8974()
99{
100 uint32_t platform = board_platform_id();
101 int ret = 0;
102
103 switch(platform)
104 {
105 case APQ8074:
106 case MSM8274:
107 case MSM8674:
108 case MSM8974:
109 ret = 1;
110 break;
111 default:
112 ret = 0;
113 };
114
115 return ret;
116}
117
Deepa Dinamani9a612932012-08-14 16:15:03 -0700118/* Return 1 if vol_up pressed */
119static int target_volume_up()
120{
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
131 /* Configure the GPIO */
132 gpio.direction = PM_GPIO_DIR_IN;
133 gpio.function = 0;
134 gpio.pull = PM_GPIO_PULL_UP_30;
Eugene Yasman6382ee02013-01-16 13:00:56 +0200135 gpio.vin_sel = 2;
Deepa Dinamani9a612932012-08-14 16:15:03 -0700136
137 pm8x41_gpio_config(5, &gpio);
138
139 /* Get status of P_GPIO_5 */
140 pm8x41_gpio_get(5, &status);
141
142 return !status; /* active low */
143}
144
145/* Return 1 if vol_down pressed */
Deepa Dinamani66a87962013-02-04 10:39:30 -0800146uint32_t target_volume_down()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700147{
Deepa Dinamani66a87962013-02-04 10:39:30 -0800148 /* Volume down button is tied in with RESIN on MSM8974. */
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700149 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
150 return pm8x41_v2_resin_status();
Deepa Dinamani13bfc852013-02-05 17:56:47 -0800151 else
152 return pm8x41_resin_status();
Deepa Dinamani9a612932012-08-14 16:15:03 -0700153}
154
155static void target_keystatus()
156{
157 keys_init();
158
159 if(target_volume_down())
160 keys_post_event(KEY_VOLUMEDOWN, 1);
161
162 if(target_volume_up())
163 keys_post_event(KEY_VOLUMEUP, 1);
164}
165
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800166/* Set up params for h/w CE. */
167void target_crypto_init_params()
168{
169 struct crypto_init_params ce_params;
170
171 /* Set up base addresses and instance. */
172 ce_params.crypto_instance = CE_INSTANCE;
173 ce_params.crypto_base = MSM_CE2_BASE;
174 ce_params.bam_base = MSM_CE2_BAM_BASE;
175
176 /* Set up BAM config. */
177 ce_params.bam_ee = CE_EE;
178 ce_params.pipes.read_pipe = CE_READ_PIPE;
179 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
180
181 /* Assign buffer sizes. */
182 ce_params.num_ce = CE_ARRAY_SIZE;
183 ce_params.read_fifo_size = CE_FIFO_SIZE;
184 ce_params.write_fifo_size = CE_FIFO_SIZE;
185
Deepa Dinamanie505d3d2013-05-14 16:55:38 -0700186 /* BAM is initialized by TZ for this platform.
187 * Do not do it again as the initialization address space
188 * is locked.
189 */
190 ce_params.do_bam_init = 0;
191
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800192 crypto_init_params(&ce_params);
193}
194
195crypto_engine_type board_ce_type(void)
196{
197 return CRYPTO_ENGINE_TYPE_HW;
198}
199
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700200#if MMC_SDHCI_SUPPORT
201static target_mmc_sdhci_init()
202{
203 struct mmc_config_data config;
204 uint32_t soc_ver = 0;
205
206 /* Enable sdhci mode */
207 sdhci_mode_enable(1);
208
209 soc_ver = board_soc_version();
210
211 /*
212 * 8974 v1 fluid devices, have a hardware bug
213 * which limits the bus width to 4 bit.
214 */
215 switch(board_hardware_id())
216 {
217 case HW_PLATFORM_FLUID:
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700218 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700219 config.bus_width = DATA_BUS_WIDTH_4BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700220 else
221 config.bus_width = DATA_BUS_WIDTH_8BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700222 break;
223 default:
224 config.bus_width = DATA_BUS_WIDTH_8BIT;
225 };
226
227 config.max_clk_rate = MMC_CLK_200MHZ;
228
229 /* Trying Slot 1*/
230 config.slot = 1;
231 config.base = mmc_sdhci_base[config.slot - 1];
232
233 if (!(dev = mmc_init(&config))) {
234 /* Trying Slot 2 next */
235 config.slot = 2;
236 config.base = mmc_sdhci_base[config.slot - 1];
237 if (!(dev = mmc_init(&config))) {
238 dprintf(CRITICAL, "mmc init failed!");
239 ASSERT(0);
240 }
241 }
Channagoud Kadabief5332f2013-05-16 15:23:43 -0700242
243 /*
244 * MMC initialization is complete, read the partition table info
245 */
246 if (partition_read_table()) {
247 dprintf(CRITICAL, "Error reading the partition table info\n");
248 ASSERT(0);
249 }
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700250}
251
252struct mmc_device *target_mmc_device()
253{
254 return dev;
255}
256#else
257static target_mmc_mci_init()
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800258{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700259 uint32_t base_addr;
260 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800261
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700262 /* Trying Slot 1 */
263 slot = 1;
264 base_addr = mmc_sdc_base[slot - 1];
265
266 if (mmc_boot_main(slot, base_addr))
267 {
268 /* Trying Slot 2 next */
269 slot = 2;
270 base_addr = mmc_sdc_base[slot - 1];
271 if (mmc_boot_main(slot, base_addr)) {
272 dprintf(CRITICAL, "mmc init failed!");
273 ASSERT(0);
274 }
275 }
276}
277
278/*
279 * Function to set the capabilities for the host
280 */
281void target_mmc_caps(struct mmc_host *host)
282{
283 uint32_t soc_ver = 0;
284
285 soc_ver = board_soc_version();
286
287 /*
288 * 8974 v1 fluid devices, have a hardware bug
289 * which limits the bus width to 4 bit.
290 */
291 switch(board_hardware_id())
292 {
293 case HW_PLATFORM_FLUID:
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700294 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700295 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700296 else
297 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700298 break;
299 default:
300 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
301 };
302
303 host->caps.ddr_mode = 1;
304 host->caps.hs200_mode = 1;
305 host->caps.hs_clk_rate = MMC_CLK_96MHZ;
306}
307#endif
308
309
310void target_init(void)
311{
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800312 dprintf(INFO, "target_init()\n");
313
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800314 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800315
Deepa Dinamani07f15712013-03-08 17:02:13 -0800316 /* Save PM8941 version info. */
317 pmic_ver = pm8x41_get_pmic_rev();
318
Deepa Dinamani9a612932012-08-14 16:15:03 -0700319 target_keystatus();
320
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800321 if (target_use_signed_kernel())
322 target_crypto_init_params();
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800323 /* Display splash screen if enabled */
324#if DISPLAY_SPLASH_SCREEN
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800325 dprintf(INFO, "Display Init: Start\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800326 display_init();
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800327 dprintf(INFO, "Display Init: Done\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800328#endif
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800329
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700330 /*
331 * Set drive strength & pull ctrl for
332 * emmc
333 */
334 set_sdc_power_ctrl();
335
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700336#if MMC_SDHCI_SUPPORT
337 target_mmc_sdhci_init();
338#else
339 target_mmc_mci_init();
340#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800341}
342
343unsigned board_machtype(void)
344{
345 return target_id;
346}
347
348/* Do any target specific intialization needed before entering fastboot mode */
sundarajan srinivasana098d832013-03-07 12:19:30 -0800349#ifdef SSD_ENABLE
sundarajan srinivasana098d832013-03-07 12:19:30 -0800350static void ssd_load_keystore_from_emmc()
351{
352 uint64_t ptn = 0;
353 int index = -1;
354 uint32_t size = SSD_PARTITION_SIZE;
355 int ret = -1;
356
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700357 uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE,
358 ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE));
359
360 if (!buffer) {
361 dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n");
362 ASSERT(0);
363 }
364
sundarajan srinivasana098d832013-03-07 12:19:30 -0800365 index = partition_get_index("ssd");
366
367 ptn = partition_get_offset(index);
368 if(ptn == 0){
369 dprintf(CRITICAL,"ERROR: ssd parition not found");
370 return;
371 }
372
373 if(mmc_read(ptn, buffer, size)){
374 dprintf(CRITICAL,"ERROR:Cannot read data\n");
375 return;
376 }
377
378 ret = scm_protect_keystore((uint32_t *)&buffer[0],size);
379 if(ret != 0)
380 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed");
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700381
382 free(buffer);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800383}
384#endif
385
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800386void target_fastboot_init(void)
387{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700388 /* Set the BOOT_DONE flag in PM8921 */
389 pm8x41_set_boot_done();
sundarajan srinivasana098d832013-03-07 12:19:30 -0800390
391#ifdef SSD_ENABLE
392 clock_ce_enable(SSD_CE_INSTANCE_1);
393 ssd_load_keystore_from_emmc();
394#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800395}
Neeti Desai465491e2012-07-31 12:53:35 -0700396
397/* Detect the target type */
398void target_detect(struct board_data *board)
399{
400 board->target = LINUX_MACHTYPE_UNKNOWN;
401}
402
403/* Detect the modem type */
404void target_baseband_detect(struct board_data *board)
405{
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800406 uint32_t platform;
407 uint32_t platform_subtype;
408
409 platform = board->platform;
410 platform_subtype = board->platform_subtype;
411
412 /*
413 * Look for platform subtype if present, else
414 * check for platform type to decide on the
415 * baseband type
416 */
417 switch(platform_subtype) {
418 case HW_PLATFORM_SUBTYPE_UNKNOWN:
419 break;
Joel Kingead31e82013-04-20 11:26:01 -0700420 case HW_PLATFORM_SUBTYPE_MDM:
421 board->baseband = BASEBAND_MDM;
422 return;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800423 default:
424 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype);
425 ASSERT(0);
426 };
427
428 switch(platform) {
429 case MSM8974:
Deepa Dinamani713a76f2013-05-03 13:17:24 -0700430 case MSM8274:
431 case MSM8674:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700432 case MSM8274AA:
433 case MSM8274AB:
434 case MSM8274AC:
435 case MSM8674AA:
436 case MSM8674AB:
437 case MSM8674AC:
438 case MSM8974AA:
439 case MSM8974AB:
440 case MSM8974AC:
Neeti Desai465491e2012-07-31 12:53:35 -0700441 board->baseband = BASEBAND_MSM;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800442 break;
443 case APQ8074:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700444 case APQ8074AA:
445 case APQ8074AB:
446 case APQ8074AC:
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800447 board->baseband = BASEBAND_APQ;
448 break;
449 default:
450 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
451 ASSERT(0);
452 };
Neeti Desai465491e2012-07-31 12:53:35 -0700453}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700454
Deepa Dinamani927a6b62013-03-28 17:05:32 -0700455unsigned target_baseband()
456{
457 return board_baseband();
458}
459
Deepa Dinamani9a612932012-08-14 16:15:03 -0700460void target_serialno(unsigned char *buf)
461{
462 unsigned int serialno;
463 if (target_is_emmc_boot()) {
464 serialno = mmc_get_psn();
465 snprintf((char *)buf, 13, "%x", serialno);
466 }
467}
Amol Jadi6639d452012-08-16 14:51:19 -0700468
469unsigned check_reboot_mode(void)
470{
471 uint32_t restart_reason = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800472 uint32_t soc_ver = 0;
473 uint32_t restart_reason_addr;
474
475 soc_ver = board_soc_version();
476
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700477 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800478 restart_reason_addr = RESTART_REASON_ADDR;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700479 else
480 restart_reason_addr = RESTART_REASON_ADDR_V2;
Amol Jadi6639d452012-08-16 14:51:19 -0700481
482 /* Read reboot reason and scrub it */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800483 restart_reason = readl(restart_reason_addr);
484 writel(0x00, restart_reason_addr);
Amol Jadi6639d452012-08-16 14:51:19 -0700485
486 return restart_reason;
487}
Neeti Desai120b55d2012-08-20 17:15:56 -0700488
489void reboot_device(unsigned reboot_reason)
490{
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800491 uint32_t soc_ver = 0;
492
493 soc_ver = board_soc_version();
494
Neeti Desai120b55d2012-08-20 17:15:56 -0700495 /* Write the reboot reason */
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700496 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800497 writel(reboot_reason, RESTART_REASON_ADDR);
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700498 else
499 writel(reboot_reason, RESTART_REASON_ADDR_V2);
Neeti Desai120b55d2012-08-20 17:15:56 -0700500
501 /* Configure PMIC for warm reset */
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700502 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Deepa Dinamani07f15712013-03-08 17:02:13 -0800503 pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET);
504 else
505 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
Neeti Desai120b55d2012-08-20 17:15:56 -0700506
Deepa Dinamani1e094942012-10-30 15:49:02 -0700507 /* Disable Watchdog Debug.
508 * Required becuase of a H/W bug which causes the system to
509 * reset partially even for non watchdog resets.
510 */
511 writel(readl(GCC_WDOG_DEBUG) & ~(1 << WDOG_DEBUG_DISABLE_BIT), GCC_WDOG_DEBUG);
512
Deepa Dinamanie0808e52012-11-26 15:22:46 -0800513 dsb();
514
515 /* Wait until the write takes effect. */
516 while(readl(GCC_WDOG_DEBUG) & (1 << WDOG_DEBUG_DISABLE_BIT));
517
Neeti Desai120b55d2012-08-20 17:15:56 -0700518 /* Drop PS_HOLD for MSM */
519 writel(0x00, MPM2_MPM_PS_HOLD);
520
521 mdelay(5000);
522
523 dprintf(CRITICAL, "Rebooting failed\n");
524}
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800525
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300526int set_download_mode(enum dload_mode mode)
Pavel Nedev03511492013-03-08 19:05:32 -0800527{
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300528 dload_util_write_cookie(mode == NORMAL_DLOAD ?
529 DLOAD_MODE_ADDR_V2 : EMERGENCY_DLOAD_MODE_ADDR_V2, mode);
Pavel Nedev03511492013-03-08 19:05:32 -0800530
531 return 0;
532}
533
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700534/* Check if MSM needs VBUS mimic for USB */
535static int target_needs_vbus_mimic()
536{
537 if (target_is_8974())
538 return 0;
539
540 return 1;
541}
542
Eugene Yasmana0d18122013-02-26 13:23:05 +0200543/* Do target specific usb initialization */
544void target_usb_init(void)
545{
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700546 uint32_t val;
547
Eugene Yasmana0d18122013-02-26 13:23:05 +0200548 /* Enable secondary USB PHY on DragonBoard8074 */
549 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
550 /* Route ChipIDea to use secondary USB HS port2 */
551 writel_relaxed(1, USB2_PHY_SEL);
552
553 /* Enable access to secondary PHY by clamping the low
554 * voltage interface between DVDD of the PHY and Vddcx
555 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
556 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
557 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
558
559 /* Perform power-on-reset of the PHY.
560 * Delay values are arbitrary */
561 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
562 USB_OTG_HS_PHY_CTRL);
563 thread_sleep(10);
564 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
565 USB_OTG_HS_PHY_CTRL);
566 thread_sleep(10);
567
568 /* Enable HSUSB PHY port for ULPI interface,
569 * then configure related parameters within the PHY */
570 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
571 | 0x8c000004), USB_PORTSC);
572 }
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700573
574 if (target_needs_vbus_mimic())
575 {
576 /* Select and enable external configuration with USB PHY */
577 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
578
579 /* Enable sess_vld */
580 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
581 writel(val, USB_GENCONFIG_2);
582
583 /* Enable external vbus configuration in the LINK */
584 val = readl(USB_USBCMD);
585 val |= SESS_VLD_CTRL;
586 writel(val, USB_USBCMD);
587 }
Eugene Yasmana0d18122013-02-26 13:23:05 +0200588}
589
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800590/* Returns 1 if target supports continuous splash screen. */
591int target_cont_splash_screen()
592{
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800593 switch(board_hardware_id())
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800594 {
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800595 case HW_PLATFORM_SURF:
596 case HW_PLATFORM_MTP:
597 case HW_PLATFORM_FLUID:
Asaf Pensob85263f2013-05-01 10:54:34 +0300598 case HW_PLATFORM_DRAGON:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800599 dprintf(SPEW, "Target_cont_splash=1\n");
600 return 1;
601 break;
602 default:
603 dprintf(SPEW, "Target_cont_splash=0\n");
604 return 0;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800605 }
606}
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800607
608unsigned target_pause_for_battery_charge(void)
609{
610 uint8_t pon_reason = pm8x41_get_pon_reason();
611
612 /* This function will always return 0 to facilitate
613 * automated testing/reboot with usb connected.
614 * uncomment if this feature is needed */
615 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
616 return 1;*/
617
618 return 0;
619}
sundarajan srinivasana098d832013-03-07 12:19:30 -0800620
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700621void target_uninit(void)
sundarajan srinivasana098d832013-03-07 12:19:30 -0800622{
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700623#if MMC_SDHCI_SUPPORT
624 mmc_put_card_to_sleep(dev);
625#else
626 mmc_put_card_to_sleep();
627#endif
sundarajan srinivasana098d832013-03-07 12:19:30 -0800628#ifdef SSD_ENABLE
629 clock_ce_disable(SSD_CE_INSTANCE_1);
630#endif
631}
Deepa Dinamani65df9822013-03-08 13:38:34 -0800632
633void shutdown_device()
634{
635 dprintf(CRITICAL, "Going down for shutdown.\n");
636
637 /* Configure PMIC for shutdown. */
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700638 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Deepa Dinamani65df9822013-03-08 13:38:34 -0800639 pm8x41_v2_reset_configure(PON_PSHOLD_SHUTDOWN);
640 else
641 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
642
643 /* Drop PS_HOLD for MSM */
644 writel(0x00, MPM2_MPM_PS_HOLD);
645
646 mdelay(5000);
647
648 dprintf(CRITICAL, "Shutdown failed\n");
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700649}
650
651static void set_sdc_power_ctrl()
652{
653 /* Drive strength configs for sdc pins */
654 struct tlmm_cfgs sdc1_hdrv_cfg[] =
655 {
656 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
657 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
658 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
659 };
660
661 /* Pull configs for sdc pins */
662 struct tlmm_cfgs sdc1_pull_cfg[] =
663 {
664 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
665 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
666 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
667 };
668
669 /* Set the drive strength & pull control values */
670 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
671 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
672}
Stanimir Varbanovf64a0292013-04-29 11:58:27 +0300673
674int emmc_recovery_init(void)
675{
676 return _emmc_recovery_init();
677}
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700678
679void target_usb_stop(void)
680{
681 uint32_t platform = board_platform_id();
682
683 /* Disable VBUS mimicing in the controller. */
684 if (target_needs_vbus_mimic())
685 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
686}