blob: af2ae1e51db24395aef1ddbbebd0e29666bd4bec [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 Kadabib14d6d02013-05-15 10:48:59 -070031#include <platform/irqs.h>
Channagoud Kadabi744c8902013-04-02 11:54:53 -070032#include <platform/gpio.h>
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080033#include <reg.h>
34#include <target.h>
35#include <platform.h>
Pavel Nedev03511492013-03-08 19:05:32 -080036#include <dload_util.h>
Deepa Dinamani26e93262012-05-21 17:35:14 -070037#include <uart_dm.h>
Amol Jadi29f95032012-06-22 12:52:54 -070038#include <mmc.h>
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080039#include <spmi.h>
Neeti Desai465491e2012-07-31 12:53:35 -070040#include <board.h>
41#include <smem.h>
42#include <baseband.h>
Deepa Dinamani9a612932012-08-14 16:15:03 -070043#include <dev/keys.h>
44#include <pm8x41.h>
Deepa Dinamanib9a57202012-12-20 18:05:11 -080045#include <crypto5_wrapper.h>
Eugene Yasmana0d18122013-02-26 13:23:05 +020046#include <hsusb.h>
47#include <clock.h>
sundarajan srinivasana098d832013-03-07 12:19:30 -080048#include <partition_parser.h>
49#include <scm.h>
50#include <platform/clock.h>
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070051#include <platform/gpio.h>
Channagoud Kadabif84830c2013-04-19 14:35:47 -070052#include <stdlib.h>
Deepa Dinamanib9a57202012-12-20 18:05:11 -080053
54extern bool target_use_signed_kernel(void);
Channagoud Kadabi744c8902013-04-02 11:54:53 -070055static void set_sdc_power_ctrl();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080056
57static unsigned int target_id;
Deepa Dinamani07f15712013-03-08 17:02:13 -080058static uint32_t pmic_ver;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080059
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070060#if MMC_SDHCI_SUPPORT
61struct mmc_device *dev;
62#endif
63
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080064#define PMIC_ARB_CHANNEL_NUM 0
65#define PMIC_ARB_OWNER_ID 0
66
Deepa Dinamani1e094942012-10-30 15:49:02 -070067#define WDOG_DEBUG_DISABLE_BIT 17
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080068
Deepa Dinamanib9a57202012-12-20 18:05:11 -080069#define CE_INSTANCE 2
70#define CE_EE 1
71#define CE_FIFO_SIZE 64
72#define CE_READ_PIPE 3
73#define CE_WRITE_PIPE 2
Deepa Dinamani809c4282013-07-09 14:06:02 -070074#define CE_READ_PIPE_LOCK_GRP 0
75#define CE_WRITE_PIPE_LOCK_GRP 0
Deepa Dinamanib9a57202012-12-20 18:05:11 -080076#define CE_ARRAY_SIZE 20
77
sundarajan srinivasana098d832013-03-07 12:19:30 -080078#ifdef SSD_ENABLE
79#define SSD_CE_INSTANCE_1 1
80#define SSD_PARTITION_SIZE 8192
81#endif
82
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -070083#define FASTBOOT_MODE 0x77665500
84
Channagoud Kadabic48b3e92013-06-23 16:19:10 -070085#define BOARD_SOC_VERSION1(soc_rev) (soc_rev >= 0x10000 && soc_rev < 0x20000)
86
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070087#if MMC_SDHCI_SUPPORT
88static uint32_t mmc_sdhci_base[] =
89 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE, MSM_SDC4_SDHCI_BASE };
90#endif
91
Deepa Dinamanica5ad852012-05-07 18:19:47 -070092static uint32_t mmc_sdc_base[] =
93 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
94
Channagoud Kadabib14d6d02013-05-15 10:48:59 -070095static uint32_t mmc_sdc_pwrctl_irq[] =
96 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ, SDCC3_PWRCTL_IRQ, SDCC4_PWRCTL_IRQ };
97
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080098void target_early_init(void)
99{
Deepa Dinamanib073ba22012-08-10 11:06:41 -0700100#if WITH_DEBUG_UART
Neeti Desaiac011272012-08-29 18:24:54 -0700101 uart_dm_init(1, 0, BLSP1_UART1_BASE);
Deepa Dinamanib073ba22012-08-10 11:06:41 -0700102#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800103}
104
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700105/* Check for 8974 chip */
106static int target_is_8974()
107{
108 uint32_t platform = board_platform_id();
109 int ret = 0;
110
111 switch(platform)
112 {
113 case APQ8074:
114 case MSM8274:
115 case MSM8674:
116 case MSM8974:
117 ret = 1;
118 break;
119 default:
120 ret = 0;
121 };
122
123 return ret;
124}
125
Deepa Dinamani9a612932012-08-14 16:15:03 -0700126/* Return 1 if vol_up pressed */
127static int target_volume_up()
128{
129 uint8_t status = 0;
130 struct pm8x41_gpio gpio;
131
132 /* CDP vol_up seems to be always grounded. So gpio status is read as 0,
133 * whether key is pressed or not.
134 * Ignore volume_up key on CDP for now.
135 */
136 if (board_hardware_id() == HW_PLATFORM_SURF)
137 return 0;
138
139 /* Configure the GPIO */
140 gpio.direction = PM_GPIO_DIR_IN;
141 gpio.function = 0;
142 gpio.pull = PM_GPIO_PULL_UP_30;
Eugene Yasman6382ee02013-01-16 13:00:56 +0200143 gpio.vin_sel = 2;
Deepa Dinamani9a612932012-08-14 16:15:03 -0700144
145 pm8x41_gpio_config(5, &gpio);
146
147 /* Get status of P_GPIO_5 */
148 pm8x41_gpio_get(5, &status);
149
150 return !status; /* active low */
151}
152
153/* Return 1 if vol_down pressed */
Deepa Dinamani66a87962013-02-04 10:39:30 -0800154uint32_t target_volume_down()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700155{
Deepa Dinamani66a87962013-02-04 10:39:30 -0800156 /* Volume down button is tied in with RESIN on MSM8974. */
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700157 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
158 return pm8x41_v2_resin_status();
Deepa Dinamani13bfc852013-02-05 17:56:47 -0800159 else
160 return pm8x41_resin_status();
Deepa Dinamani9a612932012-08-14 16:15:03 -0700161}
162
163static void target_keystatus()
164{
165 keys_init();
166
167 if(target_volume_down())
168 keys_post_event(KEY_VOLUMEDOWN, 1);
169
170 if(target_volume_up())
171 keys_post_event(KEY_VOLUMEUP, 1);
172}
173
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800174/* Set up params for h/w CE. */
175void target_crypto_init_params()
176{
177 struct crypto_init_params ce_params;
178
179 /* Set up base addresses and instance. */
180 ce_params.crypto_instance = CE_INSTANCE;
181 ce_params.crypto_base = MSM_CE2_BASE;
182 ce_params.bam_base = MSM_CE2_BAM_BASE;
183
184 /* Set up BAM config. */
Deepa Dinamani809c4282013-07-09 14:06:02 -0700185 ce_params.bam_ee = CE_EE;
186 ce_params.pipes.read_pipe = CE_READ_PIPE;
187 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
188 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
189 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800190
191 /* Assign buffer sizes. */
192 ce_params.num_ce = CE_ARRAY_SIZE;
193 ce_params.read_fifo_size = CE_FIFO_SIZE;
194 ce_params.write_fifo_size = CE_FIFO_SIZE;
195
Deepa Dinamanie505d3d2013-05-14 16:55:38 -0700196 /* BAM is initialized by TZ for this platform.
197 * Do not do it again as the initialization address space
198 * is locked.
199 */
200 ce_params.do_bam_init = 0;
201
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800202 crypto_init_params(&ce_params);
203}
204
205crypto_engine_type board_ce_type(void)
206{
207 return CRYPTO_ENGINE_TYPE_HW;
208}
209
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700210#if MMC_SDHCI_SUPPORT
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700211static void target_mmc_sdhci_init()
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700212{
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700213 struct mmc_config_data config = {0};
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700214 uint32_t soc_ver = 0;
215
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700216 soc_ver = board_soc_version();
217
218 /*
219 * 8974 v1 fluid devices, have a hardware bug
220 * which limits the bus width to 4 bit.
221 */
222 switch(board_hardware_id())
223 {
224 case HW_PLATFORM_FLUID:
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700225 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700226 config.bus_width = DATA_BUS_WIDTH_4BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700227 else
228 config.bus_width = DATA_BUS_WIDTH_8BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700229 break;
230 default:
231 config.bus_width = DATA_BUS_WIDTH_8BIT;
232 };
233
234 config.max_clk_rate = MMC_CLK_200MHZ;
235
236 /* Trying Slot 1*/
237 config.slot = 1;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700238 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
239 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
240 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700241
242 if (!(dev = mmc_init(&config))) {
243 /* Trying Slot 2 next */
244 config.slot = 2;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700245 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
246 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
247 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
248
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700249 if (!(dev = mmc_init(&config))) {
250 dprintf(CRITICAL, "mmc init failed!");
251 ASSERT(0);
252 }
253 }
Channagoud Kadabief5332f2013-05-16 15:23:43 -0700254
255 /*
256 * MMC initialization is complete, read the partition table info
257 */
258 if (partition_read_table()) {
259 dprintf(CRITICAL, "Error reading the partition table info\n");
260 ASSERT(0);
261 }
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700262}
263
264struct mmc_device *target_mmc_device()
265{
266 return dev;
267}
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700268
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700269#else
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700270static void target_mmc_mci_init()
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800271{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700272 uint32_t base_addr;
273 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800274
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700275 /* Trying Slot 1 */
276 slot = 1;
277 base_addr = mmc_sdc_base[slot - 1];
278
279 if (mmc_boot_main(slot, base_addr))
280 {
281 /* Trying Slot 2 next */
282 slot = 2;
283 base_addr = mmc_sdc_base[slot - 1];
284 if (mmc_boot_main(slot, base_addr)) {
285 dprintf(CRITICAL, "mmc init failed!");
286 ASSERT(0);
287 }
288 }
289}
290
291/*
292 * Function to set the capabilities for the host
293 */
294void target_mmc_caps(struct mmc_host *host)
295{
296 uint32_t soc_ver = 0;
297
298 soc_ver = board_soc_version();
299
300 /*
301 * 8974 v1 fluid devices, have a hardware bug
302 * which limits the bus width to 4 bit.
303 */
304 switch(board_hardware_id())
305 {
306 case HW_PLATFORM_FLUID:
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700307 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700308 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700309 else
310 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700311 break;
312 default:
313 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
314 };
315
316 host->caps.ddr_mode = 1;
317 host->caps.hs200_mode = 1;
318 host->caps.hs_clk_rate = MMC_CLK_96MHZ;
319}
320#endif
321
322
323void target_init(void)
324{
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800325 dprintf(INFO, "target_init()\n");
326
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800327 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800328
Deepa Dinamani07f15712013-03-08 17:02:13 -0800329 /* Save PM8941 version info. */
330 pmic_ver = pm8x41_get_pmic_rev();
331
Deepa Dinamani9a612932012-08-14 16:15:03 -0700332 target_keystatus();
333
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800334 if (target_use_signed_kernel())
335 target_crypto_init_params();
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800336 /* Display splash screen if enabled */
337#if DISPLAY_SPLASH_SCREEN
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800338 dprintf(INFO, "Display Init: Start\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800339 display_init();
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800340 dprintf(INFO, "Display Init: Done\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800341#endif
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800342
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700343 /*
344 * Set drive strength & pull ctrl for
345 * emmc
346 */
347 set_sdc_power_ctrl();
348
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700349#if MMC_SDHCI_SUPPORT
350 target_mmc_sdhci_init();
351#else
352 target_mmc_mci_init();
353#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800354}
355
356unsigned board_machtype(void)
357{
358 return target_id;
359}
360
361/* Do any target specific intialization needed before entering fastboot mode */
sundarajan srinivasana098d832013-03-07 12:19:30 -0800362#ifdef SSD_ENABLE
sundarajan srinivasana098d832013-03-07 12:19:30 -0800363static void ssd_load_keystore_from_emmc()
364{
365 uint64_t ptn = 0;
366 int index = -1;
367 uint32_t size = SSD_PARTITION_SIZE;
368 int ret = -1;
369
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700370 uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE,
371 ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE));
372
373 if (!buffer) {
374 dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n");
375 ASSERT(0);
376 }
377
sundarajan srinivasana098d832013-03-07 12:19:30 -0800378 index = partition_get_index("ssd");
379
380 ptn = partition_get_offset(index);
381 if(ptn == 0){
382 dprintf(CRITICAL,"ERROR: ssd parition not found");
383 return;
384 }
385
386 if(mmc_read(ptn, buffer, size)){
387 dprintf(CRITICAL,"ERROR:Cannot read data\n");
388 return;
389 }
390
391 ret = scm_protect_keystore((uint32_t *)&buffer[0],size);
392 if(ret != 0)
393 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed");
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700394
395 free(buffer);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800396}
397#endif
398
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800399void target_fastboot_init(void)
400{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700401 /* Set the BOOT_DONE flag in PM8921 */
402 pm8x41_set_boot_done();
sundarajan srinivasana098d832013-03-07 12:19:30 -0800403
404#ifdef SSD_ENABLE
405 clock_ce_enable(SSD_CE_INSTANCE_1);
406 ssd_load_keystore_from_emmc();
407#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800408}
Neeti Desai465491e2012-07-31 12:53:35 -0700409
410/* Detect the target type */
411void target_detect(struct board_data *board)
412{
413 board->target = LINUX_MACHTYPE_UNKNOWN;
414}
415
416/* Detect the modem type */
417void target_baseband_detect(struct board_data *board)
418{
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800419 uint32_t platform;
420 uint32_t platform_subtype;
421
422 platform = board->platform;
423 platform_subtype = board->platform_subtype;
424
425 /*
426 * Look for platform subtype if present, else
427 * check for platform type to decide on the
428 * baseband type
429 */
430 switch(platform_subtype) {
431 case HW_PLATFORM_SUBTYPE_UNKNOWN:
Channagoud Kadabiba21fc02013-07-15 18:01:48 -0700432 case HW_PLATFORM_SUBTYPE_8974PRO_PM8084:
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800433 break;
434 default:
435 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype);
436 ASSERT(0);
437 };
438
439 switch(platform) {
440 case MSM8974:
Deepa Dinamani713a76f2013-05-03 13:17:24 -0700441 case MSM8274:
442 case MSM8674:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700443 case MSM8274AA:
444 case MSM8274AB:
445 case MSM8274AC:
446 case MSM8674AA:
447 case MSM8674AB:
448 case MSM8674AC:
449 case MSM8974AA:
450 case MSM8974AB:
451 case MSM8974AC:
Neeti Desai465491e2012-07-31 12:53:35 -0700452 board->baseband = BASEBAND_MSM;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800453 break;
454 case APQ8074:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700455 case APQ8074AA:
456 case APQ8074AB:
457 case APQ8074AC:
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800458 board->baseband = BASEBAND_APQ;
459 break;
460 default:
461 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
462 ASSERT(0);
463 };
Neeti Desai465491e2012-07-31 12:53:35 -0700464}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700465
Deepa Dinamani927a6b62013-03-28 17:05:32 -0700466unsigned target_baseband()
467{
468 return board_baseband();
469}
470
Deepa Dinamani9a612932012-08-14 16:15:03 -0700471void target_serialno(unsigned char *buf)
472{
473 unsigned int serialno;
474 if (target_is_emmc_boot()) {
475 serialno = mmc_get_psn();
476 snprintf((char *)buf, 13, "%x", serialno);
477 }
478}
Amol Jadi6639d452012-08-16 14:51:19 -0700479
480unsigned check_reboot_mode(void)
481{
482 uint32_t restart_reason = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800483 uint32_t soc_ver = 0;
484 uint32_t restart_reason_addr;
485
486 soc_ver = board_soc_version();
487
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700488 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800489 restart_reason_addr = RESTART_REASON_ADDR;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700490 else
491 restart_reason_addr = RESTART_REASON_ADDR_V2;
Amol Jadi6639d452012-08-16 14:51:19 -0700492
493 /* Read reboot reason and scrub it */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800494 restart_reason = readl(restart_reason_addr);
495 writel(0x00, restart_reason_addr);
Amol Jadi6639d452012-08-16 14:51:19 -0700496
497 return restart_reason;
498}
Neeti Desai120b55d2012-08-20 17:15:56 -0700499
500void reboot_device(unsigned reboot_reason)
501{
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800502 uint32_t soc_ver = 0;
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700503 uint8_t reset_type = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800504
505 soc_ver = board_soc_version();
506
Neeti Desai120b55d2012-08-20 17:15:56 -0700507 /* Write the reboot reason */
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700508 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800509 writel(reboot_reason, RESTART_REASON_ADDR);
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700510 else
511 writel(reboot_reason, RESTART_REASON_ADDR_V2);
Neeti Desai120b55d2012-08-20 17:15:56 -0700512
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700513 if(reboot_reason == FASTBOOT_MODE)
514 reset_type = PON_PSHOLD_WARM_RESET;
515 else
516 reset_type = PON_PSHOLD_HARD_RESET;
517
Neeti Desai120b55d2012-08-20 17:15:56 -0700518 /* Configure PMIC for warm reset */
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700519 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700520 pm8x41_v2_reset_configure(reset_type);
Deepa Dinamani07f15712013-03-08 17:02:13 -0800521 else
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700522 pm8x41_reset_configure(reset_type);
Neeti Desai120b55d2012-08-20 17:15:56 -0700523
Deepa Dinamani1e094942012-10-30 15:49:02 -0700524 /* Disable Watchdog Debug.
525 * Required becuase of a H/W bug which causes the system to
526 * reset partially even for non watchdog resets.
527 */
528 writel(readl(GCC_WDOG_DEBUG) & ~(1 << WDOG_DEBUG_DISABLE_BIT), GCC_WDOG_DEBUG);
529
Deepa Dinamanie0808e52012-11-26 15:22:46 -0800530 dsb();
531
532 /* Wait until the write takes effect. */
533 while(readl(GCC_WDOG_DEBUG) & (1 << WDOG_DEBUG_DISABLE_BIT));
534
Neeti Desai120b55d2012-08-20 17:15:56 -0700535 /* Drop PS_HOLD for MSM */
536 writel(0x00, MPM2_MPM_PS_HOLD);
537
538 mdelay(5000);
539
540 dprintf(CRITICAL, "Rebooting failed\n");
541}
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800542
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300543int set_download_mode(enum dload_mode mode)
Pavel Nedev03511492013-03-08 19:05:32 -0800544{
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300545 dload_util_write_cookie(mode == NORMAL_DLOAD ?
546 DLOAD_MODE_ADDR_V2 : EMERGENCY_DLOAD_MODE_ADDR_V2, mode);
Pavel Nedev03511492013-03-08 19:05:32 -0800547
548 return 0;
549}
550
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700551/* Check if MSM needs VBUS mimic for USB */
552static int target_needs_vbus_mimic()
553{
554 if (target_is_8974())
555 return 0;
556
557 return 1;
558}
559
Eugene Yasmana0d18122013-02-26 13:23:05 +0200560/* Do target specific usb initialization */
561void target_usb_init(void)
562{
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700563 uint32_t val;
564
Eugene Yasmana0d18122013-02-26 13:23:05 +0200565 /* Enable secondary USB PHY on DragonBoard8074 */
566 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
567 /* Route ChipIDea to use secondary USB HS port2 */
568 writel_relaxed(1, USB2_PHY_SEL);
569
570 /* Enable access to secondary PHY by clamping the low
571 * voltage interface between DVDD of the PHY and Vddcx
572 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
573 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
574 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
575
576 /* Perform power-on-reset of the PHY.
577 * Delay values are arbitrary */
578 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
579 USB_OTG_HS_PHY_CTRL);
580 thread_sleep(10);
581 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
582 USB_OTG_HS_PHY_CTRL);
583 thread_sleep(10);
584
585 /* Enable HSUSB PHY port for ULPI interface,
586 * then configure related parameters within the PHY */
587 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
588 | 0x8c000004), USB_PORTSC);
589 }
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700590
591 if (target_needs_vbus_mimic())
592 {
593 /* Select and enable external configuration with USB PHY */
594 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
595
596 /* Enable sess_vld */
597 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
598 writel(val, USB_GENCONFIG_2);
599
600 /* Enable external vbus configuration in the LINK */
601 val = readl(USB_USBCMD);
602 val |= SESS_VLD_CTRL;
603 writel(val, USB_USBCMD);
604 }
Eugene Yasmana0d18122013-02-26 13:23:05 +0200605}
606
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800607/* Returns 1 if target supports continuous splash screen. */
608int target_cont_splash_screen()
609{
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800610 switch(board_hardware_id())
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800611 {
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800612 case HW_PLATFORM_SURF:
613 case HW_PLATFORM_MTP:
614 case HW_PLATFORM_FLUID:
Asaf Pensob85263f2013-05-01 10:54:34 +0300615 case HW_PLATFORM_DRAGON:
Kuogee Hsiehdf636eb2013-08-01 14:52:08 -0700616 case HW_PLATFORM_LIQUID:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800617 dprintf(SPEW, "Target_cont_splash=1\n");
618 return 1;
619 break;
620 default:
621 dprintf(SPEW, "Target_cont_splash=0\n");
622 return 0;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800623 }
624}
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800625
626unsigned target_pause_for_battery_charge(void)
627{
628 uint8_t pon_reason = pm8x41_get_pon_reason();
629
630 /* This function will always return 0 to facilitate
631 * automated testing/reboot with usb connected.
632 * uncomment if this feature is needed */
633 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
634 return 1;*/
635
636 return 0;
637}
sundarajan srinivasana098d832013-03-07 12:19:30 -0800638
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700639void target_uninit(void)
sundarajan srinivasana098d832013-03-07 12:19:30 -0800640{
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700641#if MMC_SDHCI_SUPPORT
642 mmc_put_card_to_sleep(dev);
643#else
644 mmc_put_card_to_sleep();
645#endif
sundarajan srinivasana098d832013-03-07 12:19:30 -0800646#ifdef SSD_ENABLE
647 clock_ce_disable(SSD_CE_INSTANCE_1);
648#endif
649}
Deepa Dinamani65df9822013-03-08 13:38:34 -0800650
651void shutdown_device()
652{
653 dprintf(CRITICAL, "Going down for shutdown.\n");
654
655 /* Configure PMIC for shutdown. */
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700656 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Deepa Dinamani65df9822013-03-08 13:38:34 -0800657 pm8x41_v2_reset_configure(PON_PSHOLD_SHUTDOWN);
658 else
659 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
660
661 /* Drop PS_HOLD for MSM */
662 writel(0x00, MPM2_MPM_PS_HOLD);
663
664 mdelay(5000);
665
666 dprintf(CRITICAL, "Shutdown failed\n");
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700667}
668
669static void set_sdc_power_ctrl()
670{
671 /* Drive strength configs for sdc pins */
672 struct tlmm_cfgs sdc1_hdrv_cfg[] =
673 {
674 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
675 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
676 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
677 };
678
679 /* Pull configs for sdc pins */
680 struct tlmm_cfgs sdc1_pull_cfg[] =
681 {
682 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
683 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
684 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
685 };
686
687 /* Set the drive strength & pull control values */
688 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
689 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
690}
Stanimir Varbanovf64a0292013-04-29 11:58:27 +0300691
692int emmc_recovery_init(void)
693{
694 return _emmc_recovery_init();
695}
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700696
697void target_usb_stop(void)
698{
699 uint32_t platform = board_platform_id();
700
701 /* Disable VBUS mimicing in the controller. */
702 if (target_needs_vbus_mimic())
703 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
704}