blob: 2e6c151c2be0688e58f53b363d0e978e42e8d8b6 [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
Channagoud Kadabi20e0dd12013-08-06 12:30:51 -070054enum hw_platform_subtype
55{
56 HW_PLATFORM_SUBTYPE_CDP_INTERPOSER = 8,
57};
58
Deepa Dinamanib9a57202012-12-20 18:05:11 -080059extern bool target_use_signed_kernel(void);
Channagoud Kadabi744c8902013-04-02 11:54:53 -070060static void set_sdc_power_ctrl();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080061
62static unsigned int target_id;
Deepa Dinamani07f15712013-03-08 17:02:13 -080063static uint32_t pmic_ver;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080064
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070065#if MMC_SDHCI_SUPPORT
66struct mmc_device *dev;
67#endif
68
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080069#define PMIC_ARB_CHANNEL_NUM 0
70#define PMIC_ARB_OWNER_ID 0
71
Deepa Dinamani1e094942012-10-30 15:49:02 -070072#define WDOG_DEBUG_DISABLE_BIT 17
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080073
Deepa Dinamanib9a57202012-12-20 18:05:11 -080074#define CE_INSTANCE 2
75#define CE_EE 1
76#define CE_FIFO_SIZE 64
77#define CE_READ_PIPE 3
78#define CE_WRITE_PIPE 2
Deepa Dinamani809c4282013-07-09 14:06:02 -070079#define CE_READ_PIPE_LOCK_GRP 0
80#define CE_WRITE_PIPE_LOCK_GRP 0
Deepa Dinamanib9a57202012-12-20 18:05:11 -080081#define CE_ARRAY_SIZE 20
82
sundarajan srinivasana098d832013-03-07 12:19:30 -080083#ifdef SSD_ENABLE
84#define SSD_CE_INSTANCE_1 1
85#define SSD_PARTITION_SIZE 8192
86#endif
87
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -070088#define FASTBOOT_MODE 0x77665500
89
Channagoud Kadabic48b3e92013-06-23 16:19:10 -070090#define BOARD_SOC_VERSION1(soc_rev) (soc_rev >= 0x10000 && soc_rev < 0x20000)
91
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070092#if MMC_SDHCI_SUPPORT
93static uint32_t mmc_sdhci_base[] =
94 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE, MSM_SDC4_SDHCI_BASE };
95#endif
96
Deepa Dinamanica5ad852012-05-07 18:19:47 -070097static uint32_t mmc_sdc_base[] =
98 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
99
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700100static uint32_t mmc_sdc_pwrctl_irq[] =
101 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ, SDCC3_PWRCTL_IRQ, SDCC4_PWRCTL_IRQ };
102
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800103void target_early_init(void)
104{
Deepa Dinamanib073ba22012-08-10 11:06:41 -0700105#if WITH_DEBUG_UART
Neeti Desaiac011272012-08-29 18:24:54 -0700106 uart_dm_init(1, 0, BLSP1_UART1_BASE);
Deepa Dinamanib073ba22012-08-10 11:06:41 -0700107#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800108}
109
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700110/* Check for 8974 chip */
111static int target_is_8974()
112{
113 uint32_t platform = board_platform_id();
114 int ret = 0;
115
116 switch(platform)
117 {
118 case APQ8074:
119 case MSM8274:
120 case MSM8674:
121 case MSM8974:
122 ret = 1;
123 break;
124 default:
125 ret = 0;
126 };
127
128 return ret;
129}
130
Deepa Dinamani9a612932012-08-14 16:15:03 -0700131/* Return 1 if vol_up pressed */
132static int target_volume_up()
133{
134 uint8_t status = 0;
135 struct pm8x41_gpio gpio;
136
137 /* CDP vol_up seems to be always grounded. So gpio status is read as 0,
138 * whether key is pressed or not.
139 * Ignore volume_up key on CDP for now.
140 */
141 if (board_hardware_id() == HW_PLATFORM_SURF)
142 return 0;
143
144 /* Configure the GPIO */
145 gpio.direction = PM_GPIO_DIR_IN;
146 gpio.function = 0;
147 gpio.pull = PM_GPIO_PULL_UP_30;
Eugene Yasman6382ee02013-01-16 13:00:56 +0200148 gpio.vin_sel = 2;
Deepa Dinamani9a612932012-08-14 16:15:03 -0700149
150 pm8x41_gpio_config(5, &gpio);
151
Channagoud Kadabi4d7b5302013-08-07 16:34:08 -0700152 /* Wait for the pmic gpio config to take effect */
153 thread_sleep(1);
154
Deepa Dinamani9a612932012-08-14 16:15:03 -0700155 /* Get status of P_GPIO_5 */
156 pm8x41_gpio_get(5, &status);
157
158 return !status; /* active low */
159}
160
161/* Return 1 if vol_down pressed */
Deepa Dinamani66a87962013-02-04 10:39:30 -0800162uint32_t target_volume_down()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700163{
Deepa Dinamani66a87962013-02-04 10:39:30 -0800164 /* Volume down button is tied in with RESIN on MSM8974. */
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700165 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
166 return pm8x41_v2_resin_status();
Deepa Dinamani13bfc852013-02-05 17:56:47 -0800167 else
168 return pm8x41_resin_status();
Deepa Dinamani9a612932012-08-14 16:15:03 -0700169}
170
171static void target_keystatus()
172{
173 keys_init();
174
175 if(target_volume_down())
176 keys_post_event(KEY_VOLUMEDOWN, 1);
177
178 if(target_volume_up())
179 keys_post_event(KEY_VOLUMEUP, 1);
180}
181
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800182/* Set up params for h/w CE. */
183void target_crypto_init_params()
184{
185 struct crypto_init_params ce_params;
186
187 /* Set up base addresses and instance. */
188 ce_params.crypto_instance = CE_INSTANCE;
189 ce_params.crypto_base = MSM_CE2_BASE;
190 ce_params.bam_base = MSM_CE2_BAM_BASE;
191
192 /* Set up BAM config. */
Deepa Dinamani809c4282013-07-09 14:06:02 -0700193 ce_params.bam_ee = CE_EE;
194 ce_params.pipes.read_pipe = CE_READ_PIPE;
195 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
196 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
197 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800198
199 /* Assign buffer sizes. */
200 ce_params.num_ce = CE_ARRAY_SIZE;
201 ce_params.read_fifo_size = CE_FIFO_SIZE;
202 ce_params.write_fifo_size = CE_FIFO_SIZE;
203
Deepa Dinamanie505d3d2013-05-14 16:55:38 -0700204 /* BAM is initialized by TZ for this platform.
205 * Do not do it again as the initialization address space
206 * is locked.
207 */
208 ce_params.do_bam_init = 0;
209
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800210 crypto_init_params(&ce_params);
211}
212
213crypto_engine_type board_ce_type(void)
214{
215 return CRYPTO_ENGINE_TYPE_HW;
216}
217
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700218#if MMC_SDHCI_SUPPORT
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700219static void target_mmc_sdhci_init()
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700220{
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700221 struct mmc_config_data config = {0};
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700222 uint32_t soc_ver = 0;
223
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700224 soc_ver = board_soc_version();
225
226 /*
227 * 8974 v1 fluid devices, have a hardware bug
228 * which limits the bus width to 4 bit.
229 */
230 switch(board_hardware_id())
231 {
232 case HW_PLATFORM_FLUID:
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700233 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700234 config.bus_width = DATA_BUS_WIDTH_4BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700235 else
236 config.bus_width = DATA_BUS_WIDTH_8BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700237 break;
238 default:
239 config.bus_width = DATA_BUS_WIDTH_8BIT;
240 };
241
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700242 /* Trying Slot 1*/
243 config.slot = 1;
Channagoud Kadabi181f1dd2013-08-20 15:28:07 -0700244 /*
245 * For 8974 AC platform the software clock
246 * plan recommends to use the following frequencies:
247 * 200 MHz --> 192 MHZ
248 * 400 MHZ --> 384 MHZ
249 * only for emmc slot
250 */
251 if (platform_is_8974ac())
252 config.max_clk_rate = MMC_CLK_192MHZ;
253 else
254 config.max_clk_rate = MMC_CLK_200MHZ;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700255 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
256 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
257 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700258
259 if (!(dev = mmc_init(&config))) {
260 /* Trying Slot 2 next */
261 config.slot = 2;
Channagoud Kadabi181f1dd2013-08-20 15:28:07 -0700262 config.max_clk_rate = MMC_CLK_200MHZ;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700263 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
264 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
265 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
266
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700267 if (!(dev = mmc_init(&config))) {
268 dprintf(CRITICAL, "mmc init failed!");
269 ASSERT(0);
270 }
271 }
Channagoud Kadabief5332f2013-05-16 15:23:43 -0700272
273 /*
274 * MMC initialization is complete, read the partition table info
275 */
276 if (partition_read_table()) {
277 dprintf(CRITICAL, "Error reading the partition table info\n");
278 ASSERT(0);
279 }
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700280}
281
282struct mmc_device *target_mmc_device()
283{
284 return dev;
285}
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700286
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700287#else
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700288static void target_mmc_mci_init()
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800289{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700290 uint32_t base_addr;
291 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800292
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700293 /* Trying Slot 1 */
294 slot = 1;
295 base_addr = mmc_sdc_base[slot - 1];
296
297 if (mmc_boot_main(slot, base_addr))
298 {
299 /* Trying Slot 2 next */
300 slot = 2;
301 base_addr = mmc_sdc_base[slot - 1];
302 if (mmc_boot_main(slot, base_addr)) {
303 dprintf(CRITICAL, "mmc init failed!");
304 ASSERT(0);
305 }
306 }
307}
308
309/*
310 * Function to set the capabilities for the host
311 */
312void target_mmc_caps(struct mmc_host *host)
313{
314 uint32_t soc_ver = 0;
315
316 soc_ver = board_soc_version();
317
318 /*
319 * 8974 v1 fluid devices, have a hardware bug
320 * which limits the bus width to 4 bit.
321 */
322 switch(board_hardware_id())
323 {
324 case HW_PLATFORM_FLUID:
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700325 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700326 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700327 else
328 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700329 break;
330 default:
331 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
332 };
333
334 host->caps.ddr_mode = 1;
335 host->caps.hs200_mode = 1;
336 host->caps.hs_clk_rate = MMC_CLK_96MHZ;
337}
338#endif
339
340
341void target_init(void)
342{
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800343 dprintf(INFO, "target_init()\n");
344
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800345 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800346
Deepa Dinamani07f15712013-03-08 17:02:13 -0800347 /* Save PM8941 version info. */
348 pmic_ver = pm8x41_get_pmic_rev();
349
Deepa Dinamani9a612932012-08-14 16:15:03 -0700350 target_keystatus();
351
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800352 if (target_use_signed_kernel())
353 target_crypto_init_params();
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800354 /* Display splash screen if enabled */
355#if DISPLAY_SPLASH_SCREEN
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800356 dprintf(INFO, "Display Init: Start\n");
Channagoud Kadabi20e0dd12013-08-06 12:30:51 -0700357 if (board_hardware_subtype() != HW_PLATFORM_SUBTYPE_CDP_INTERPOSER)
358 {
359 display_init();
360 }
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800361 dprintf(INFO, "Display Init: Done\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800362#endif
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800363
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700364 /*
365 * Set drive strength & pull ctrl for
366 * emmc
367 */
368 set_sdc_power_ctrl();
369
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700370#if MMC_SDHCI_SUPPORT
371 target_mmc_sdhci_init();
372#else
373 target_mmc_mci_init();
374#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800375}
376
377unsigned board_machtype(void)
378{
379 return target_id;
380}
381
382/* Do any target specific intialization needed before entering fastboot mode */
sundarajan srinivasana098d832013-03-07 12:19:30 -0800383#ifdef SSD_ENABLE
sundarajan srinivasana098d832013-03-07 12:19:30 -0800384static void ssd_load_keystore_from_emmc()
385{
386 uint64_t ptn = 0;
387 int index = -1;
388 uint32_t size = SSD_PARTITION_SIZE;
389 int ret = -1;
390
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700391 uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE,
392 ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE));
393
394 if (!buffer) {
395 dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n");
396 ASSERT(0);
397 }
398
sundarajan srinivasana098d832013-03-07 12:19:30 -0800399 index = partition_get_index("ssd");
400
401 ptn = partition_get_offset(index);
402 if(ptn == 0){
403 dprintf(CRITICAL,"ERROR: ssd parition not found");
404 return;
405 }
406
407 if(mmc_read(ptn, buffer, size)){
408 dprintf(CRITICAL,"ERROR:Cannot read data\n");
409 return;
410 }
411
412 ret = scm_protect_keystore((uint32_t *)&buffer[0],size);
413 if(ret != 0)
414 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed");
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700415
416 free(buffer);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800417}
418#endif
419
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800420void target_fastboot_init(void)
421{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700422 /* Set the BOOT_DONE flag in PM8921 */
423 pm8x41_set_boot_done();
sundarajan srinivasana098d832013-03-07 12:19:30 -0800424
425#ifdef SSD_ENABLE
426 clock_ce_enable(SSD_CE_INSTANCE_1);
427 ssd_load_keystore_from_emmc();
428#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800429}
Neeti Desai465491e2012-07-31 12:53:35 -0700430
431/* Detect the target type */
432void target_detect(struct board_data *board)
433{
434 board->target = LINUX_MACHTYPE_UNKNOWN;
435}
436
437/* Detect the modem type */
438void target_baseband_detect(struct board_data *board)
439{
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800440 uint32_t platform;
441 uint32_t platform_subtype;
442
443 platform = board->platform;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800444
445 switch(platform) {
446 case MSM8974:
Deepa Dinamani713a76f2013-05-03 13:17:24 -0700447 case MSM8274:
448 case MSM8674:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700449 case MSM8274AA:
450 case MSM8274AB:
451 case MSM8274AC:
452 case MSM8674AA:
453 case MSM8674AB:
454 case MSM8674AC:
455 case MSM8974AA:
456 case MSM8974AB:
457 case MSM8974AC:
Channagoud Kadabi20e0dd12013-08-06 12:30:51 -0700458 case MSMSAMARIUM2:
459 case MSMSAMARIUM9:
Neeti Desai465491e2012-07-31 12:53:35 -0700460 board->baseband = BASEBAND_MSM;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800461 break;
462 case APQ8074:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700463 case APQ8074AA:
464 case APQ8074AB:
465 case APQ8074AC:
Channagoud Kadabi20e0dd12013-08-06 12:30:51 -0700466 case MSMSAMARIUM0:
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800467 board->baseband = BASEBAND_APQ;
468 break;
469 default:
470 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
471 ASSERT(0);
472 };
Neeti Desai465491e2012-07-31 12:53:35 -0700473}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700474
Deepa Dinamani927a6b62013-03-28 17:05:32 -0700475unsigned target_baseband()
476{
477 return board_baseband();
478}
479
Deepa Dinamani9a612932012-08-14 16:15:03 -0700480void target_serialno(unsigned char *buf)
481{
482 unsigned int serialno;
483 if (target_is_emmc_boot()) {
484 serialno = mmc_get_psn();
485 snprintf((char *)buf, 13, "%x", serialno);
486 }
487}
Amol Jadi6639d452012-08-16 14:51:19 -0700488
489unsigned check_reboot_mode(void)
490{
491 uint32_t restart_reason = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800492 uint32_t soc_ver = 0;
493 uint32_t restart_reason_addr;
494
495 soc_ver = board_soc_version();
496
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700497 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800498 restart_reason_addr = RESTART_REASON_ADDR;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700499 else
500 restart_reason_addr = RESTART_REASON_ADDR_V2;
Amol Jadi6639d452012-08-16 14:51:19 -0700501
502 /* Read reboot reason and scrub it */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800503 restart_reason = readl(restart_reason_addr);
504 writel(0x00, restart_reason_addr);
Amol Jadi6639d452012-08-16 14:51:19 -0700505
506 return restart_reason;
507}
Neeti Desai120b55d2012-08-20 17:15:56 -0700508
509void reboot_device(unsigned reboot_reason)
510{
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800511 uint32_t soc_ver = 0;
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700512 uint8_t reset_type = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800513
514 soc_ver = board_soc_version();
515
Neeti Desai120b55d2012-08-20 17:15:56 -0700516 /* Write the reboot reason */
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700517 if (target_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800518 writel(reboot_reason, RESTART_REASON_ADDR);
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700519 else
520 writel(reboot_reason, RESTART_REASON_ADDR_V2);
Neeti Desai120b55d2012-08-20 17:15:56 -0700521
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700522 if(reboot_reason == FASTBOOT_MODE)
523 reset_type = PON_PSHOLD_WARM_RESET;
524 else
525 reset_type = PON_PSHOLD_HARD_RESET;
526
Neeti Desai120b55d2012-08-20 17:15:56 -0700527 /* Configure PMIC for warm reset */
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700528 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700529 pm8x41_v2_reset_configure(reset_type);
Deepa Dinamani07f15712013-03-08 17:02:13 -0800530 else
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700531 pm8x41_reset_configure(reset_type);
Neeti Desai120b55d2012-08-20 17:15:56 -0700532
Deepa Dinamani1e094942012-10-30 15:49:02 -0700533 /* Disable Watchdog Debug.
534 * Required becuase of a H/W bug which causes the system to
535 * reset partially even for non watchdog resets.
536 */
537 writel(readl(GCC_WDOG_DEBUG) & ~(1 << WDOG_DEBUG_DISABLE_BIT), GCC_WDOG_DEBUG);
538
Deepa Dinamanie0808e52012-11-26 15:22:46 -0800539 dsb();
540
541 /* Wait until the write takes effect. */
542 while(readl(GCC_WDOG_DEBUG) & (1 << WDOG_DEBUG_DISABLE_BIT));
543
Neeti Desai120b55d2012-08-20 17:15:56 -0700544 /* Drop PS_HOLD for MSM */
545 writel(0x00, MPM2_MPM_PS_HOLD);
546
547 mdelay(5000);
548
549 dprintf(CRITICAL, "Rebooting failed\n");
550}
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800551
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300552int set_download_mode(enum dload_mode mode)
Pavel Nedev03511492013-03-08 19:05:32 -0800553{
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300554 dload_util_write_cookie(mode == NORMAL_DLOAD ?
555 DLOAD_MODE_ADDR_V2 : EMERGENCY_DLOAD_MODE_ADDR_V2, mode);
Pavel Nedev03511492013-03-08 19:05:32 -0800556
557 return 0;
558}
559
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700560/* Check if MSM needs VBUS mimic for USB */
561static int target_needs_vbus_mimic()
562{
563 if (target_is_8974())
564 return 0;
565
566 return 1;
567}
568
Eugene Yasmana0d18122013-02-26 13:23:05 +0200569/* Do target specific usb initialization */
570void target_usb_init(void)
571{
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700572 uint32_t val;
573
Eugene Yasmana0d18122013-02-26 13:23:05 +0200574 /* Enable secondary USB PHY on DragonBoard8074 */
575 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
576 /* Route ChipIDea to use secondary USB HS port2 */
577 writel_relaxed(1, USB2_PHY_SEL);
578
579 /* Enable access to secondary PHY by clamping the low
580 * voltage interface between DVDD of the PHY and Vddcx
581 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
582 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
583 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
584
585 /* Perform power-on-reset of the PHY.
586 * Delay values are arbitrary */
587 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
588 USB_OTG_HS_PHY_CTRL);
589 thread_sleep(10);
590 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
591 USB_OTG_HS_PHY_CTRL);
592 thread_sleep(10);
593
594 /* Enable HSUSB PHY port for ULPI interface,
595 * then configure related parameters within the PHY */
596 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
597 | 0x8c000004), USB_PORTSC);
598 }
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700599
600 if (target_needs_vbus_mimic())
601 {
602 /* Select and enable external configuration with USB PHY */
603 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
604
605 /* Enable sess_vld */
606 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
607 writel(val, USB_GENCONFIG_2);
608
609 /* Enable external vbus configuration in the LINK */
610 val = readl(USB_USBCMD);
611 val |= SESS_VLD_CTRL;
612 writel(val, USB_USBCMD);
613 }
Eugene Yasmana0d18122013-02-26 13:23:05 +0200614}
615
Casey Piper8ac505c2013-09-05 15:00:30 -0700616uint8_t target_panel_auto_detect_enabled()
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800617{
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800618 switch(board_hardware_id())
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800619 {
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800620 case HW_PLATFORM_SURF:
621 case HW_PLATFORM_MTP:
622 case HW_PLATFORM_FLUID:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800623 return 1;
624 break;
625 default:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800626 return 0;
Casey Piper8ac505c2013-09-05 15:00:30 -0700627 break;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800628 }
Casey Piper8ac505c2013-09-05 15:00:30 -0700629 return 0;
630}
631
Casey Piper3a150202013-11-18 13:26:18 -0800632uint8_t target_is_edp()
633{
634 switch(board_hardware_id())
635 {
636 case HW_PLATFORM_LIQUID:
637 return 1;
638 break;
639 default:
640 return 0;
641 break;
642 }
643 return 0;
644}
645
Casey Piper8ac505c2013-09-05 15:00:30 -0700646static uint8_t splash_override;
647/* Returns 1 if target supports continuous splash screen. */
648int target_cont_splash_screen()
649{
650 uint8_t splash_screen = 0;
651 if(!splash_override) {
652 switch(board_hardware_id())
653 {
654 case HW_PLATFORM_SURF:
655 case HW_PLATFORM_MTP:
656 case HW_PLATFORM_FLUID:
657 case HW_PLATFORM_DRAGON:
658 case HW_PLATFORM_LIQUID:
659 dprintf(SPEW, "Target_cont_splash=1\n");
660 splash_screen = 1;
661 break;
662 default:
663 dprintf(SPEW, "Target_cont_splash=0\n");
664 splash_screen = 0;
665 }
666 }
667 return splash_screen;
668}
669
670void target_force_cont_splash_disable(uint8_t override)
671{
672 splash_override = override;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800673}
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800674
675unsigned target_pause_for_battery_charge(void)
676{
677 uint8_t pon_reason = pm8x41_get_pon_reason();
678
679 /* This function will always return 0 to facilitate
680 * automated testing/reboot with usb connected.
681 * uncomment if this feature is needed */
682 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
683 return 1;*/
684
685 return 0;
686}
sundarajan srinivasana098d832013-03-07 12:19:30 -0800687
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700688void target_uninit(void)
sundarajan srinivasana098d832013-03-07 12:19:30 -0800689{
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700690#if MMC_SDHCI_SUPPORT
691 mmc_put_card_to_sleep(dev);
692#else
693 mmc_put_card_to_sleep();
694#endif
sundarajan srinivasana098d832013-03-07 12:19:30 -0800695#ifdef SSD_ENABLE
696 clock_ce_disable(SSD_CE_INSTANCE_1);
697#endif
Channagoud Kadabif753d902014-01-24 17:25:34 -0800698
699 /* Disable HC mode before jumping to kernel */
700 sdhci_mode_disable(&dev->host);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800701}
Deepa Dinamani65df9822013-03-08 13:38:34 -0800702
703void shutdown_device()
704{
705 dprintf(CRITICAL, "Going down for shutdown.\n");
706
707 /* Configure PMIC for shutdown. */
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700708 if (target_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Deepa Dinamani65df9822013-03-08 13:38:34 -0800709 pm8x41_v2_reset_configure(PON_PSHOLD_SHUTDOWN);
710 else
711 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
712
713 /* Drop PS_HOLD for MSM */
714 writel(0x00, MPM2_MPM_PS_HOLD);
715
716 mdelay(5000);
717
718 dprintf(CRITICAL, "Shutdown failed\n");
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700719}
720
721static void set_sdc_power_ctrl()
722{
Channagoud Kadabi7cb4b6f2013-09-27 14:25:22 -0700723 uint8_t tlmm_hdrv_clk = 0;
724 uint32_t platform_id = 0;
725
726 platform_id = board_platform_id();
727
728 switch(platform_id)
729 {
730 case MSM8274AA:
731 case MSM8274AB:
732 case MSM8674AA:
733 case MSM8674AB:
734 case MSM8974AA:
735 case MSM8974AB:
736 if (board_hardware_id() == HW_PLATFORM_MTP)
737 tlmm_hdrv_clk = TLMM_CUR_VAL_10MA;
738 else
739 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
740 break;
741 default:
742 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
743 };
744
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700745 /* Drive strength configs for sdc pins */
746 struct tlmm_cfgs sdc1_hdrv_cfg[] =
747 {
Channagoud Kadabi7cb4b6f2013-09-27 14:25:22 -0700748 { SDC1_CLK_HDRV_CTL_OFF, tlmm_hdrv_clk, TLMM_HDRV_MASK },
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700749 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
750 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
751 };
752
753 /* Pull configs for sdc pins */
754 struct tlmm_cfgs sdc1_pull_cfg[] =
755 {
756 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
757 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
758 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
759 };
760
Channagoud Kadabi67403492013-08-20 15:29:15 -0700761 struct tlmm_cfgs sdc1_rclk_cfg[] =
762 {
763 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK },
764 };
765
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700766 /* Set the drive strength & pull control values */
767 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
768 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
Channagoud Kadabi67403492013-08-20 15:29:15 -0700769
770 /* RCLK is supported only with 8974 pro, set rclk to pull down
771 * only for 8974 pro targets
772 */
773 if (!platform_is_8974())
774 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700775}
Stanimir Varbanovf64a0292013-04-29 11:58:27 +0300776
777int emmc_recovery_init(void)
778{
779 return _emmc_recovery_init();
780}
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700781
782void target_usb_stop(void)
783{
784 uint32_t platform = board_platform_id();
785
786 /* Disable VBUS mimicing in the controller. */
787 if (target_needs_vbus_mimic())
788 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
789}