blob: 7ef2d3619525520502b7eb63447edc7dc18c7251 [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
Deepa Dinamani809c4282013-07-09 14:06:02 -070073#define CE_READ_PIPE_LOCK_GRP 0
74#define CE_WRITE_PIPE_LOCK_GRP 0
Deepa Dinamanib9a57202012-12-20 18:05:11 -080075#define CE_ARRAY_SIZE 20
76
sundarajan srinivasana098d832013-03-07 12:19:30 -080077#ifdef SSD_ENABLE
78#define SSD_CE_INSTANCE_1 1
79#define SSD_PARTITION_SIZE 8192
80#endif
81
Channagoud Kadabic48b3e92013-06-23 16:19:10 -070082#define BOARD_SOC_VERSION1(soc_rev) (soc_rev >= 0x10000 && soc_rev < 0x20000)
83
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070084#if MMC_SDHCI_SUPPORT
85static uint32_t mmc_sdhci_base[] =
86 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE, MSM_SDC4_SDHCI_BASE };
87#endif
88
Deepa Dinamanica5ad852012-05-07 18:19:47 -070089static uint32_t mmc_sdc_base[] =
90 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
91
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080092void target_early_init(void)
93{
Deepa Dinamanib073ba22012-08-10 11:06:41 -070094#if WITH_DEBUG_UART
Neeti Desaiac011272012-08-29 18:24:54 -070095 uart_dm_init(1, 0, BLSP1_UART1_BASE);
Deepa Dinamanib073ba22012-08-10 11:06:41 -070096#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080097}
98
Channagoud Kadabic48b3e92013-06-23 16:19:10 -070099/* Check for 8974 chip */
100static int target_is_8974()
101{
102 uint32_t platform = board_platform_id();
103 int ret = 0;
104
105 switch(platform)
106 {
107 case APQ8074:
108 case MSM8274:
109 case MSM8674:
110 case MSM8974:
111 ret = 1;
112 break;
113 default:
114 ret = 0;
115 };
116
117 return ret;
118}
119
Deepa Dinamani9a612932012-08-14 16:15:03 -0700120/* Return 1 if vol_up pressed */
121static int target_volume_up()
122{
123 uint8_t status = 0;
124 struct pm8x41_gpio gpio;
125
126 /* CDP vol_up seems to be always grounded. So gpio status is read as 0,
127 * whether key is pressed or not.
128 * Ignore volume_up key on CDP for now.
129 */
130 if (board_hardware_id() == HW_PLATFORM_SURF)
131 return 0;
132
133 /* Configure the GPIO */
134 gpio.direction = PM_GPIO_DIR_IN;
135 gpio.function = 0;
136 gpio.pull = PM_GPIO_PULL_UP_30;
Eugene Yasman6382ee02013-01-16 13:00:56 +0200137 gpio.vin_sel = 2;
Deepa Dinamani9a612932012-08-14 16:15:03 -0700138
139 pm8x41_gpio_config(5, &gpio);
140
141 /* Get status of P_GPIO_5 */
142 pm8x41_gpio_get(5, &status);
143
144 return !status; /* active low */
145}
146
147/* Return 1 if vol_down pressed */
Deepa Dinamani66a87962013-02-04 10:39:30 -0800148uint32_t target_volume_down()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700149{
Deepa Dinamani66a87962013-02-04 10:39:30 -0800150 /* Volume down button is tied in with RESIN on MSM8974. */
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700151 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
152 return pm8x41_v2_resin_status();
Deepa Dinamani13bfc852013-02-05 17:56:47 -0800153 else
154 return pm8x41_resin_status();
Deepa Dinamani9a612932012-08-14 16:15:03 -0700155}
156
157static void target_keystatus()
158{
159 keys_init();
160
161 if(target_volume_down())
162 keys_post_event(KEY_VOLUMEDOWN, 1);
163
164 if(target_volume_up())
165 keys_post_event(KEY_VOLUMEUP, 1);
166}
167
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800168/* Set up params for h/w CE. */
169void target_crypto_init_params()
170{
171 struct crypto_init_params ce_params;
172
173 /* Set up base addresses and instance. */
174 ce_params.crypto_instance = CE_INSTANCE;
175 ce_params.crypto_base = MSM_CE2_BASE;
176 ce_params.bam_base = MSM_CE2_BAM_BASE;
177
178 /* Set up BAM config. */
Deepa Dinamani809c4282013-07-09 14:06:02 -0700179 ce_params.bam_ee = CE_EE;
180 ce_params.pipes.read_pipe = CE_READ_PIPE;
181 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
182 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
183 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800184
185 /* Assign buffer sizes. */
186 ce_params.num_ce = CE_ARRAY_SIZE;
187 ce_params.read_fifo_size = CE_FIFO_SIZE;
188 ce_params.write_fifo_size = CE_FIFO_SIZE;
189
Deepa Dinamanie505d3d2013-05-14 16:55:38 -0700190 /* BAM is initialized by TZ for this platform.
191 * Do not do it again as the initialization address space
192 * is locked.
193 */
194 ce_params.do_bam_init = 0;
195
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800196 crypto_init_params(&ce_params);
197}
198
199crypto_engine_type board_ce_type(void)
200{
201 return CRYPTO_ENGINE_TYPE_HW;
202}
203
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700204#if MMC_SDHCI_SUPPORT
205static target_mmc_sdhci_init()
206{
207 struct mmc_config_data config;
208 uint32_t soc_ver = 0;
209
210 /* Enable sdhci mode */
211 sdhci_mode_enable(1);
212
213 soc_ver = board_soc_version();
214
215 /*
216 * 8974 v1 fluid devices, have a hardware bug
217 * which limits the bus width to 4 bit.
218 */
219 switch(board_hardware_id())
220 {
221 case HW_PLATFORM_FLUID:
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700222 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700223 config.bus_width = DATA_BUS_WIDTH_4BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700224 else
225 config.bus_width = DATA_BUS_WIDTH_8BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700226 break;
227 default:
228 config.bus_width = DATA_BUS_WIDTH_8BIT;
229 };
230
231 config.max_clk_rate = MMC_CLK_200MHZ;
232
233 /* Trying Slot 1*/
234 config.slot = 1;
235 config.base = mmc_sdhci_base[config.slot - 1];
236
237 if (!(dev = mmc_init(&config))) {
238 /* Trying Slot 2 next */
239 config.slot = 2;
240 config.base = mmc_sdhci_base[config.slot - 1];
241 if (!(dev = mmc_init(&config))) {
242 dprintf(CRITICAL, "mmc init failed!");
243 ASSERT(0);
244 }
245 }
Channagoud Kadabief5332f2013-05-16 15:23:43 -0700246
247 /*
248 * MMC initialization is complete, read the partition table info
249 */
250 if (partition_read_table()) {
251 dprintf(CRITICAL, "Error reading the partition table info\n");
252 ASSERT(0);
253 }
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700254}
255
256struct mmc_device *target_mmc_device()
257{
258 return dev;
259}
260#else
261static target_mmc_mci_init()
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800262{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700263 uint32_t base_addr;
264 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800265
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700266 /* Trying Slot 1 */
267 slot = 1;
268 base_addr = mmc_sdc_base[slot - 1];
269
270 if (mmc_boot_main(slot, base_addr))
271 {
272 /* Trying Slot 2 next */
273 slot = 2;
274 base_addr = mmc_sdc_base[slot - 1];
275 if (mmc_boot_main(slot, base_addr)) {
276 dprintf(CRITICAL, "mmc init failed!");
277 ASSERT(0);
278 }
279 }
280}
281
282/*
283 * Function to set the capabilities for the host
284 */
285void target_mmc_caps(struct mmc_host *host)
286{
287 uint32_t soc_ver = 0;
288
289 soc_ver = board_soc_version();
290
291 /*
292 * 8974 v1 fluid devices, have a hardware bug
293 * which limits the bus width to 4 bit.
294 */
295 switch(board_hardware_id())
296 {
297 case HW_PLATFORM_FLUID:
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700298 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700299 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700300 else
301 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700302 break;
303 default:
304 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
305 };
306
307 host->caps.ddr_mode = 1;
308 host->caps.hs200_mode = 1;
309 host->caps.hs_clk_rate = MMC_CLK_96MHZ;
310}
311#endif
312
313
314void target_init(void)
315{
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800316 dprintf(INFO, "target_init()\n");
317
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800318 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800319
Deepa Dinamani07f15712013-03-08 17:02:13 -0800320 /* Save PM8941 version info. */
321 pmic_ver = pm8x41_get_pmic_rev();
322
Deepa Dinamani9a612932012-08-14 16:15:03 -0700323 target_keystatus();
324
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800325 if (target_use_signed_kernel())
326 target_crypto_init_params();
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800327 /* Display splash screen if enabled */
328#if DISPLAY_SPLASH_SCREEN
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800329 dprintf(INFO, "Display Init: Start\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800330 display_init();
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800331 dprintf(INFO, "Display Init: Done\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800332#endif
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800333
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700334 /*
335 * Set drive strength & pull ctrl for
336 * emmc
337 */
338 set_sdc_power_ctrl();
339
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700340#if MMC_SDHCI_SUPPORT
341 target_mmc_sdhci_init();
342#else
343 target_mmc_mci_init();
344#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800345}
346
347unsigned board_machtype(void)
348{
349 return target_id;
350}
351
352/* Do any target specific intialization needed before entering fastboot mode */
sundarajan srinivasana098d832013-03-07 12:19:30 -0800353#ifdef SSD_ENABLE
sundarajan srinivasana098d832013-03-07 12:19:30 -0800354static void ssd_load_keystore_from_emmc()
355{
356 uint64_t ptn = 0;
357 int index = -1;
358 uint32_t size = SSD_PARTITION_SIZE;
359 int ret = -1;
360
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700361 uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE,
362 ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE));
363
364 if (!buffer) {
365 dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n");
366 ASSERT(0);
367 }
368
sundarajan srinivasana098d832013-03-07 12:19:30 -0800369 index = partition_get_index("ssd");
370
371 ptn = partition_get_offset(index);
372 if(ptn == 0){
373 dprintf(CRITICAL,"ERROR: ssd parition not found");
374 return;
375 }
376
377 if(mmc_read(ptn, buffer, size)){
378 dprintf(CRITICAL,"ERROR:Cannot read data\n");
379 return;
380 }
381
382 ret = scm_protect_keystore((uint32_t *)&buffer[0],size);
383 if(ret != 0)
384 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed");
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700385
386 free(buffer);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800387}
388#endif
389
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800390void target_fastboot_init(void)
391{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700392 /* Set the BOOT_DONE flag in PM8921 */
393 pm8x41_set_boot_done();
sundarajan srinivasana098d832013-03-07 12:19:30 -0800394
395#ifdef SSD_ENABLE
396 clock_ce_enable(SSD_CE_INSTANCE_1);
397 ssd_load_keystore_from_emmc();
398#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800399}
Neeti Desai465491e2012-07-31 12:53:35 -0700400
401/* Detect the target type */
402void target_detect(struct board_data *board)
403{
404 board->target = LINUX_MACHTYPE_UNKNOWN;
405}
406
407/* Detect the modem type */
408void target_baseband_detect(struct board_data *board)
409{
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800410 uint32_t platform;
411 uint32_t platform_subtype;
412
413 platform = board->platform;
414 platform_subtype = board->platform_subtype;
415
416 /*
417 * Look for platform subtype if present, else
418 * check for platform type to decide on the
419 * baseband type
420 */
421 switch(platform_subtype) {
422 case HW_PLATFORM_SUBTYPE_UNKNOWN:
423 break;
Joel Kingead31e82013-04-20 11:26:01 -0700424 case HW_PLATFORM_SUBTYPE_MDM:
425 board->baseband = BASEBAND_MDM;
426 return;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800427 default:
428 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype);
429 ASSERT(0);
430 };
431
432 switch(platform) {
433 case MSM8974:
Deepa Dinamani713a76f2013-05-03 13:17:24 -0700434 case MSM8274:
435 case MSM8674:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700436 case MSM8274AA:
437 case MSM8274AB:
438 case MSM8274AC:
439 case MSM8674AA:
440 case MSM8674AB:
441 case MSM8674AC:
442 case MSM8974AA:
443 case MSM8974AB:
444 case MSM8974AC:
Neeti Desai465491e2012-07-31 12:53:35 -0700445 board->baseband = BASEBAND_MSM;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800446 break;
447 case APQ8074:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700448 case APQ8074AA:
449 case APQ8074AB:
450 case APQ8074AC:
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800451 board->baseband = BASEBAND_APQ;
452 break;
453 default:
454 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
455 ASSERT(0);
456 };
Neeti Desai465491e2012-07-31 12:53:35 -0700457}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700458
Deepa Dinamani927a6b62013-03-28 17:05:32 -0700459unsigned target_baseband()
460{
461 return board_baseband();
462}
463
Deepa Dinamani9a612932012-08-14 16:15:03 -0700464void target_serialno(unsigned char *buf)
465{
466 unsigned int serialno;
467 if (target_is_emmc_boot()) {
468 serialno = mmc_get_psn();
469 snprintf((char *)buf, 13, "%x", serialno);
470 }
471}
Amol Jadi6639d452012-08-16 14:51:19 -0700472
473unsigned check_reboot_mode(void)
474{
475 uint32_t restart_reason = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800476 uint32_t soc_ver = 0;
477 uint32_t restart_reason_addr;
478
479 soc_ver = board_soc_version();
480
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700481 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800482 restart_reason_addr = RESTART_REASON_ADDR;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700483 else
484 restart_reason_addr = RESTART_REASON_ADDR_V2;
Amol Jadi6639d452012-08-16 14:51:19 -0700485
486 /* Read reboot reason and scrub it */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800487 restart_reason = readl(restart_reason_addr);
488 writel(0x00, restart_reason_addr);
Amol Jadi6639d452012-08-16 14:51:19 -0700489
490 return restart_reason;
491}
Neeti Desai120b55d2012-08-20 17:15:56 -0700492
493void reboot_device(unsigned reboot_reason)
494{
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800495 uint32_t soc_ver = 0;
496
497 soc_ver = board_soc_version();
498
Neeti Desai120b55d2012-08-20 17:15:56 -0700499 /* Write the reboot reason */
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700500 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800501 writel(reboot_reason, RESTART_REASON_ADDR);
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700502 else
503 writel(reboot_reason, RESTART_REASON_ADDR_V2);
Neeti Desai120b55d2012-08-20 17:15:56 -0700504
505 /* Configure PMIC for warm reset */
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700506 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Deepa Dinamani07f15712013-03-08 17:02:13 -0800507 pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET);
508 else
509 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
Neeti Desai120b55d2012-08-20 17:15:56 -0700510
Deepa Dinamani1e094942012-10-30 15:49:02 -0700511 /* Disable Watchdog Debug.
512 * Required becuase of a H/W bug which causes the system to
513 * reset partially even for non watchdog resets.
514 */
515 writel(readl(GCC_WDOG_DEBUG) & ~(1 << WDOG_DEBUG_DISABLE_BIT), GCC_WDOG_DEBUG);
516
Deepa Dinamanie0808e52012-11-26 15:22:46 -0800517 dsb();
518
519 /* Wait until the write takes effect. */
520 while(readl(GCC_WDOG_DEBUG) & (1 << WDOG_DEBUG_DISABLE_BIT));
521
Neeti Desai120b55d2012-08-20 17:15:56 -0700522 /* Drop PS_HOLD for MSM */
523 writel(0x00, MPM2_MPM_PS_HOLD);
524
525 mdelay(5000);
526
527 dprintf(CRITICAL, "Rebooting failed\n");
528}
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800529
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300530int set_download_mode(enum dload_mode mode)
Pavel Nedev03511492013-03-08 19:05:32 -0800531{
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300532 dload_util_write_cookie(mode == NORMAL_DLOAD ?
533 DLOAD_MODE_ADDR_V2 : EMERGENCY_DLOAD_MODE_ADDR_V2, mode);
Pavel Nedev03511492013-03-08 19:05:32 -0800534
535 return 0;
536}
537
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700538/* Check if MSM needs VBUS mimic for USB */
539static int target_needs_vbus_mimic()
540{
541 if (target_is_8974())
542 return 0;
543
544 return 1;
545}
546
Eugene Yasmana0d18122013-02-26 13:23:05 +0200547/* Do target specific usb initialization */
548void target_usb_init(void)
549{
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700550 uint32_t val;
551
Eugene Yasmana0d18122013-02-26 13:23:05 +0200552 /* Enable secondary USB PHY on DragonBoard8074 */
553 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
554 /* Route ChipIDea to use secondary USB HS port2 */
555 writel_relaxed(1, USB2_PHY_SEL);
556
557 /* Enable access to secondary PHY by clamping the low
558 * voltage interface between DVDD of the PHY and Vddcx
559 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
560 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
561 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
562
563 /* Perform power-on-reset of the PHY.
564 * Delay values are arbitrary */
565 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
566 USB_OTG_HS_PHY_CTRL);
567 thread_sleep(10);
568 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
569 USB_OTG_HS_PHY_CTRL);
570 thread_sleep(10);
571
572 /* Enable HSUSB PHY port for ULPI interface,
573 * then configure related parameters within the PHY */
574 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
575 | 0x8c000004), USB_PORTSC);
576 }
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700577
578 if (target_needs_vbus_mimic())
579 {
580 /* Select and enable external configuration with USB PHY */
581 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
582
583 /* Enable sess_vld */
584 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
585 writel(val, USB_GENCONFIG_2);
586
587 /* Enable external vbus configuration in the LINK */
588 val = readl(USB_USBCMD);
589 val |= SESS_VLD_CTRL;
590 writel(val, USB_USBCMD);
591 }
Eugene Yasmana0d18122013-02-26 13:23:05 +0200592}
593
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800594/* Returns 1 if target supports continuous splash screen. */
595int target_cont_splash_screen()
596{
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800597 switch(board_hardware_id())
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800598 {
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800599 case HW_PLATFORM_SURF:
600 case HW_PLATFORM_MTP:
601 case HW_PLATFORM_FLUID:
Asaf Pensob85263f2013-05-01 10:54:34 +0300602 case HW_PLATFORM_DRAGON:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800603 dprintf(SPEW, "Target_cont_splash=1\n");
604 return 1;
605 break;
606 default:
607 dprintf(SPEW, "Target_cont_splash=0\n");
608 return 0;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800609 }
610}
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800611
612unsigned target_pause_for_battery_charge(void)
613{
614 uint8_t pon_reason = pm8x41_get_pon_reason();
615
616 /* This function will always return 0 to facilitate
617 * automated testing/reboot with usb connected.
618 * uncomment if this feature is needed */
619 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
620 return 1;*/
621
622 return 0;
623}
sundarajan srinivasana098d832013-03-07 12:19:30 -0800624
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700625void target_uninit(void)
sundarajan srinivasana098d832013-03-07 12:19:30 -0800626{
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700627#if MMC_SDHCI_SUPPORT
628 mmc_put_card_to_sleep(dev);
629#else
630 mmc_put_card_to_sleep();
631#endif
sundarajan srinivasana098d832013-03-07 12:19:30 -0800632#ifdef SSD_ENABLE
633 clock_ce_disable(SSD_CE_INSTANCE_1);
634#endif
635}
Deepa Dinamani65df9822013-03-08 13:38:34 -0800636
637void shutdown_device()
638{
639 dprintf(CRITICAL, "Going down for shutdown.\n");
640
641 /* Configure PMIC for shutdown. */
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700642 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Deepa Dinamani65df9822013-03-08 13:38:34 -0800643 pm8x41_v2_reset_configure(PON_PSHOLD_SHUTDOWN);
644 else
645 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
646
647 /* Drop PS_HOLD for MSM */
648 writel(0x00, MPM2_MPM_PS_HOLD);
649
650 mdelay(5000);
651
652 dprintf(CRITICAL, "Shutdown failed\n");
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700653}
654
655static void set_sdc_power_ctrl()
656{
657 /* Drive strength configs for sdc pins */
658 struct tlmm_cfgs sdc1_hdrv_cfg[] =
659 {
660 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
661 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
662 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
663 };
664
665 /* Pull configs for sdc pins */
666 struct tlmm_cfgs sdc1_pull_cfg[] =
667 {
668 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
669 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
670 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
671 };
672
673 /* Set the drive strength & pull control values */
674 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
675 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
676}
Stanimir Varbanovf64a0292013-04-29 11:58:27 +0300677
678int emmc_recovery_init(void)
679{
680 return _emmc_recovery_init();
681}
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700682
683void target_usb_stop(void)
684{
685 uint32_t platform = board_platform_id();
686
687 /* Disable VBUS mimicing in the controller. */
688 if (target_needs_vbus_mimic())
689 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
690}