blob: d60d4770bee4b4258d058bfb35092b01b6bf94bb [file] [log] [blame]
Channagoud Kadabia7ab9312014-01-08 12:11:23 -08001/* Copyright (c) 2012-2014, 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
Channagoud Kadabia1ef8092014-01-08 12:11:58 -080069#define CE_INSTANCE 2
Deepa Dinamanib9a57202012-12-20 18:05:11 -080070#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
Deepa Dinamani9a612932012-08-14 16:15:03 -0700105/* Return 1 if vol_up pressed */
106static int target_volume_up()
107{
108 uint8_t status = 0;
109 struct pm8x41_gpio gpio;
110
111 /* CDP vol_up seems to be always grounded. So gpio status is read as 0,
112 * whether key is pressed or not.
113 * Ignore volume_up key on CDP for now.
114 */
115 if (board_hardware_id() == HW_PLATFORM_SURF)
116 return 0;
117
118 /* Configure the GPIO */
119 gpio.direction = PM_GPIO_DIR_IN;
120 gpio.function = 0;
121 gpio.pull = PM_GPIO_PULL_UP_30;
Eugene Yasman6382ee02013-01-16 13:00:56 +0200122 gpio.vin_sel = 2;
Deepa Dinamani9a612932012-08-14 16:15:03 -0700123
124 pm8x41_gpio_config(5, &gpio);
125
Channagoud Kadabi4d7b5302013-08-07 16:34:08 -0700126 /* Wait for the pmic gpio config to take effect */
127 thread_sleep(1);
128
Deepa Dinamani9a612932012-08-14 16:15:03 -0700129 /* Get status of P_GPIO_5 */
130 pm8x41_gpio_get(5, &status);
131
132 return !status; /* active low */
133}
134
135/* Return 1 if vol_down pressed */
Deepa Dinamani66a87962013-02-04 10:39:30 -0800136uint32_t target_volume_down()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700137{
Deepa Dinamani66a87962013-02-04 10:39:30 -0800138 /* Volume down button is tied in with RESIN on MSM8974. */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700139 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700140 return pm8x41_v2_resin_status();
Deepa Dinamani13bfc852013-02-05 17:56:47 -0800141 else
142 return pm8x41_resin_status();
Deepa Dinamani9a612932012-08-14 16:15:03 -0700143}
144
145static void target_keystatus()
146{
147 keys_init();
148
149 if(target_volume_down())
150 keys_post_event(KEY_VOLUMEDOWN, 1);
151
152 if(target_volume_up())
153 keys_post_event(KEY_VOLUMEUP, 1);
154}
155
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800156/* Set up params for h/w CE. */
157void target_crypto_init_params()
158{
159 struct crypto_init_params ce_params;
160
161 /* Set up base addresses and instance. */
Channagoud Kadabia1ef8092014-01-08 12:11:58 -0800162 ce_params.crypto_instance = CE_INSTANCE;
163 ce_params.crypto_base = MSM_CE2_BASE;
164 ce_params.bam_base = MSM_CE2_BAM_BASE;
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800165
166 /* Set up BAM config. */
Deepa Dinamani809c4282013-07-09 14:06:02 -0700167 ce_params.bam_ee = CE_EE;
168 ce_params.pipes.read_pipe = CE_READ_PIPE;
169 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
170 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
171 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800172
173 /* Assign buffer sizes. */
174 ce_params.num_ce = CE_ARRAY_SIZE;
175 ce_params.read_fifo_size = CE_FIFO_SIZE;
176 ce_params.write_fifo_size = CE_FIFO_SIZE;
177
Deepa Dinamanie505d3d2013-05-14 16:55:38 -0700178 /* BAM is initialized by TZ for this platform.
179 * Do not do it again as the initialization address space
180 * is locked.
181 */
182 ce_params.do_bam_init = 0;
183
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800184 crypto_init_params(&ce_params);
185}
186
187crypto_engine_type board_ce_type(void)
188{
189 return CRYPTO_ENGINE_TYPE_HW;
190}
191
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700192#if MMC_SDHCI_SUPPORT
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700193static void target_mmc_sdhci_init()
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700194{
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700195 struct mmc_config_data config = {0};
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700196 uint32_t soc_ver = 0;
197
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700198 soc_ver = board_soc_version();
199
200 /*
201 * 8974 v1 fluid devices, have a hardware bug
202 * which limits the bus width to 4 bit.
203 */
204 switch(board_hardware_id())
205 {
206 case HW_PLATFORM_FLUID:
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700207 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700208 config.bus_width = DATA_BUS_WIDTH_4BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700209 else
210 config.bus_width = DATA_BUS_WIDTH_8BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700211 break;
212 default:
213 config.bus_width = DATA_BUS_WIDTH_8BIT;
214 };
215
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700216 /* Trying Slot 1*/
217 config.slot = 1;
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700218 /*
219 * For 8974 AC & 8x62 platforms the software clock
220 * plan recommends to use the following frequencies:
221 * 200 MHz --> 192 MHZ
222 * 400 MHZ --> 384 MHZ
223 * only for emmc slot
224 */
225 if (platform_is_8974ac() || platform_is_8x62())
226 config.max_clk_rate = MMC_CLK_192MHZ;
227 else
228 config.max_clk_rate = MMC_CLK_200MHZ;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700229 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
230 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
231 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700232
233 if (!(dev = mmc_init(&config))) {
234 /* Trying Slot 2 next */
235 config.slot = 2;
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700236 config.max_clk_rate = MMC_CLK_200MHZ;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700237 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
238 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
239 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
240
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700241 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
Channagoud Kadabi6faaf702013-09-10 15:00:51 -0700256void *target_mmc_device()
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700257{
Channagoud Kadabi6faaf702013-09-10 15:00:51 -0700258 return (void *) dev;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700259}
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700260
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700261#else
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700262static void target_mmc_mci_init()
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800263{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700264 uint32_t base_addr;
265 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800266
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700267 /* Trying Slot 1 */
268 slot = 1;
269 base_addr = mmc_sdc_base[slot - 1];
270
271 if (mmc_boot_main(slot, base_addr))
272 {
273 /* Trying Slot 2 next */
274 slot = 2;
275 base_addr = mmc_sdc_base[slot - 1];
276 if (mmc_boot_main(slot, base_addr)) {
277 dprintf(CRITICAL, "mmc init failed!");
278 ASSERT(0);
279 }
280 }
281}
282
283/*
284 * Function to set the capabilities for the host
285 */
286void target_mmc_caps(struct mmc_host *host)
287{
288 uint32_t soc_ver = 0;
289
290 soc_ver = board_soc_version();
291
292 /*
293 * 8974 v1 fluid devices, have a hardware bug
294 * which limits the bus width to 4 bit.
295 */
296 switch(board_hardware_id())
297 {
298 case HW_PLATFORM_FLUID:
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700299 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700300 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700301 else
302 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700303 break;
304 default:
305 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
306 };
307
308 host->caps.ddr_mode = 1;
309 host->caps.hs200_mode = 1;
310 host->caps.hs_clk_rate = MMC_CLK_96MHZ;
311}
312#endif
313
314
315void target_init(void)
316{
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800317 dprintf(INFO, "target_init()\n");
318
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800319 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800320
Deepa Dinamani07f15712013-03-08 17:02:13 -0800321 /* Save PM8941 version info. */
322 pmic_ver = pm8x41_get_pmic_rev();
323
Deepa Dinamani9a612932012-08-14 16:15:03 -0700324 target_keystatus();
325
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800326 if (target_use_signed_kernel())
327 target_crypto_init_params();
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800328 /* Display splash screen if enabled */
329#if DISPLAY_SPLASH_SCREEN
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800330 dprintf(INFO, "Display Init: Start\n");
Channagoud Kadabi051f6b92014-01-08 12:16:16 -0800331 display_init();
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800332 dprintf(INFO, "Display Init: Done\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800333#endif
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800334
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700335 /*
336 * Set drive strength & pull ctrl for
337 * emmc
338 */
339 set_sdc_power_ctrl();
340
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700341#if MMC_SDHCI_SUPPORT
342 target_mmc_sdhci_init();
343#else
344 target_mmc_mci_init();
345#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800346}
347
348unsigned board_machtype(void)
349{
350 return target_id;
351}
352
353/* Do any target specific intialization needed before entering fastboot mode */
sundarajan srinivasana098d832013-03-07 12:19:30 -0800354#ifdef SSD_ENABLE
sundarajan srinivasana098d832013-03-07 12:19:30 -0800355static void ssd_load_keystore_from_emmc()
356{
357 uint64_t ptn = 0;
358 int index = -1;
359 uint32_t size = SSD_PARTITION_SIZE;
360 int ret = -1;
361
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700362 uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE,
363 ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE));
364
365 if (!buffer) {
366 dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n");
367 ASSERT(0);
368 }
369
sundarajan srinivasana098d832013-03-07 12:19:30 -0800370 index = partition_get_index("ssd");
371
372 ptn = partition_get_offset(index);
373 if(ptn == 0){
374 dprintf(CRITICAL,"ERROR: ssd parition not found");
375 return;
376 }
377
378 if(mmc_read(ptn, buffer, size)){
379 dprintf(CRITICAL,"ERROR:Cannot read data\n");
380 return;
381 }
382
383 ret = scm_protect_keystore((uint32_t *)&buffer[0],size);
384 if(ret != 0)
385 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed");
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700386
387 free(buffer);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800388}
389#endif
390
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800391void target_fastboot_init(void)
392{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700393 /* Set the BOOT_DONE flag in PM8921 */
Channagoud Kadabia7ab9312014-01-08 12:11:23 -0800394 pm8x41_set_boot_done();
sundarajan srinivasana098d832013-03-07 12:19:30 -0800395
396#ifdef SSD_ENABLE
397 clock_ce_enable(SSD_CE_INSTANCE_1);
398 ssd_load_keystore_from_emmc();
399#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800400}
Neeti Desai465491e2012-07-31 12:53:35 -0700401
402/* Detect the target type */
403void target_detect(struct board_data *board)
404{
Channagoud Kadabi2018bd12014-02-11 15:37:05 -0800405 /* This property is filled in board.c */
Neeti Desai465491e2012-07-31 12:53:35 -0700406}
407
408/* Detect the modem type */
409void target_baseband_detect(struct board_data *board)
410{
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800411 uint32_t platform;
Channagoud Kadabia7ab9312014-01-08 12:11:23 -0800412 uint32_t platform_subtype;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800413
414 platform = board->platform;
Channagoud Kadabi051f6b92014-01-08 12:16:16 -0800415 platform_subtype = board->platform_subtype;
416
417 /*
418 * Look for platform subtype if present, else
419 * check for platform type to decide on the
420 * baseband type
421 */
422 switch(platform_subtype) {
423 case HW_PLATFORM_SUBTYPE_UNKNOWN:
424 case HW_PLATFORM_SUBTYPE_8974PRO_PM8084:
425 break;
426 default:
427 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype);
428 ASSERT(0);
429 };
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800430
431 switch(platform) {
432 case MSM8974:
Deepa Dinamani713a76f2013-05-03 13:17:24 -0700433 case MSM8274:
434 case MSM8674:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700435 case MSM8274AA:
436 case MSM8274AB:
437 case MSM8274AC:
438 case MSM8674AA:
439 case MSM8674AB:
440 case MSM8674AC:
441 case MSM8974AA:
442 case MSM8974AB:
443 case MSM8974AC:
Neeti Desai465491e2012-07-31 12:53:35 -0700444 board->baseband = BASEBAND_MSM;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800445 break;
446 case APQ8074:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700447 case APQ8074AA:
448 case APQ8074AB:
449 case APQ8074AC:
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800450 board->baseband = BASEBAND_APQ;
451 break;
452 default:
453 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
454 ASSERT(0);
455 };
Neeti Desai465491e2012-07-31 12:53:35 -0700456}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700457
Deepa Dinamani927a6b62013-03-28 17:05:32 -0700458unsigned target_baseband()
459{
460 return board_baseband();
461}
462
Deepa Dinamani9a612932012-08-14 16:15:03 -0700463void target_serialno(unsigned char *buf)
464{
465 unsigned int serialno;
466 if (target_is_emmc_boot()) {
467 serialno = mmc_get_psn();
468 snprintf((char *)buf, 13, "%x", serialno);
469 }
470}
Amol Jadi6639d452012-08-16 14:51:19 -0700471
472unsigned check_reboot_mode(void)
473{
474 uint32_t restart_reason = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800475 uint32_t soc_ver = 0;
476 uint32_t restart_reason_addr;
477
478 soc_ver = board_soc_version();
479
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700480 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800481 restart_reason_addr = RESTART_REASON_ADDR;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700482 else
483 restart_reason_addr = RESTART_REASON_ADDR_V2;
Amol Jadi6639d452012-08-16 14:51:19 -0700484
485 /* Read reboot reason and scrub it */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800486 restart_reason = readl(restart_reason_addr);
487 writel(0x00, restart_reason_addr);
Amol Jadi6639d452012-08-16 14:51:19 -0700488
489 return restart_reason;
490}
Neeti Desai120b55d2012-08-20 17:15:56 -0700491
492void reboot_device(unsigned reboot_reason)
493{
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800494 uint32_t soc_ver = 0;
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700495 uint8_t reset_type = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800496
497 soc_ver = board_soc_version();
498
Neeti Desai120b55d2012-08-20 17:15:56 -0700499 /* Write the reboot reason */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700500 if (platform_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
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700505 if(reboot_reason == FASTBOOT_MODE)
506 reset_type = PON_PSHOLD_WARM_RESET;
507 else
508 reset_type = PON_PSHOLD_HARD_RESET;
509
Neeti Desai120b55d2012-08-20 17:15:56 -0700510 /* Configure PMIC for warm reset */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700511 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700512 pm8x41_v2_reset_configure(reset_type);
Deepa Dinamani07f15712013-03-08 17:02:13 -0800513 else
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700514 pm8x41_reset_configure(reset_type);
Neeti Desai120b55d2012-08-20 17:15:56 -0700515
Deepa Dinamani1e094942012-10-30 15:49:02 -0700516 /* Disable Watchdog Debug.
517 * Required becuase of a H/W bug which causes the system to
518 * reset partially even for non watchdog resets.
519 */
520 writel(readl(GCC_WDOG_DEBUG) & ~(1 << WDOG_DEBUG_DISABLE_BIT), GCC_WDOG_DEBUG);
521
Deepa Dinamanie0808e52012-11-26 15:22:46 -0800522 dsb();
523
524 /* Wait until the write takes effect. */
525 while(readl(GCC_WDOG_DEBUG) & (1 << WDOG_DEBUG_DISABLE_BIT));
526
Neeti Desai120b55d2012-08-20 17:15:56 -0700527 /* Drop PS_HOLD for MSM */
528 writel(0x00, MPM2_MPM_PS_HOLD);
529
530 mdelay(5000);
531
532 dprintf(CRITICAL, "Rebooting failed\n");
533}
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800534
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300535int set_download_mode(enum dload_mode mode)
Pavel Nedev03511492013-03-08 19:05:32 -0800536{
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300537 dload_util_write_cookie(mode == NORMAL_DLOAD ?
538 DLOAD_MODE_ADDR_V2 : EMERGENCY_DLOAD_MODE_ADDR_V2, mode);
Pavel Nedev03511492013-03-08 19:05:32 -0800539
540 return 0;
541}
542
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700543/* Check if MSM needs VBUS mimic for USB */
544static int target_needs_vbus_mimic()
545{
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700546 if (platform_is_8974())
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700547 return 0;
548
549 return 1;
550}
551
Eugene Yasmana0d18122013-02-26 13:23:05 +0200552/* Do target specific usb initialization */
553void target_usb_init(void)
554{
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700555 uint32_t val;
556
Eugene Yasmana0d18122013-02-26 13:23:05 +0200557 /* Enable secondary USB PHY on DragonBoard8074 */
558 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
559 /* Route ChipIDea to use secondary USB HS port2 */
560 writel_relaxed(1, USB2_PHY_SEL);
561
562 /* Enable access to secondary PHY by clamping the low
563 * voltage interface between DVDD of the PHY and Vddcx
564 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
565 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
566 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
567
568 /* Perform power-on-reset of the PHY.
569 * Delay values are arbitrary */
570 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
571 USB_OTG_HS_PHY_CTRL);
572 thread_sleep(10);
573 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
574 USB_OTG_HS_PHY_CTRL);
575 thread_sleep(10);
576
577 /* Enable HSUSB PHY port for ULPI interface,
578 * then configure related parameters within the PHY */
579 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
580 | 0x8c000004), USB_PORTSC);
581 }
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700582
583 if (target_needs_vbus_mimic())
584 {
585 /* Select and enable external configuration with USB PHY */
586 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
587
588 /* Enable sess_vld */
589 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
590 writel(val, USB_GENCONFIG_2);
591
592 /* Enable external vbus configuration in the LINK */
593 val = readl(USB_USBCMD);
594 val |= SESS_VLD_CTRL;
595 writel(val, USB_USBCMD);
596 }
Eugene Yasmana0d18122013-02-26 13:23:05 +0200597}
598
Casey Piper74f8e5c2013-09-05 15:00:30 -0700599uint8_t target_panel_auto_detect_enabled()
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800600{
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800601 switch(board_hardware_id())
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800602 {
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800603 case HW_PLATFORM_SURF:
604 case HW_PLATFORM_MTP:
605 case HW_PLATFORM_FLUID:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800606 return 1;
607 break;
608 default:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800609 return 0;
Casey Piper74f8e5c2013-09-05 15:00:30 -0700610 break;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800611 }
Casey Piper74f8e5c2013-09-05 15:00:30 -0700612 return 0;
613}
614
Casey Piper74f67a32013-11-18 13:26:18 -0800615uint8_t target_is_edp()
616{
617 switch(board_hardware_id())
618 {
619 case HW_PLATFORM_LIQUID:
620 return 1;
621 break;
622 default:
623 return 0;
624 break;
625 }
626 return 0;
627}
628
Casey Piper74f8e5c2013-09-05 15:00:30 -0700629static uint8_t splash_override;
630/* Returns 1 if target supports continuous splash screen. */
631int target_cont_splash_screen()
632{
633 uint8_t splash_screen = 0;
634 if(!splash_override) {
635 switch(board_hardware_id())
636 {
637 case HW_PLATFORM_SURF:
638 case HW_PLATFORM_MTP:
639 case HW_PLATFORM_FLUID:
640 case HW_PLATFORM_DRAGON:
641 case HW_PLATFORM_LIQUID:
642 dprintf(SPEW, "Target_cont_splash=1\n");
643 splash_screen = 1;
644 break;
645 default:
646 dprintf(SPEW, "Target_cont_splash=0\n");
647 splash_screen = 0;
648 }
649 }
650 return splash_screen;
651}
652
653void target_force_cont_splash_disable(uint8_t override)
654{
655 splash_override = override;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800656}
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800657
658unsigned target_pause_for_battery_charge(void)
659{
660 uint8_t pon_reason = pm8x41_get_pon_reason();
661
662 /* This function will always return 0 to facilitate
663 * automated testing/reboot with usb connected.
664 * uncomment if this feature is needed */
665 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
666 return 1;*/
667
668 return 0;
669}
sundarajan srinivasana098d832013-03-07 12:19:30 -0800670
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700671void target_uninit(void)
sundarajan srinivasana098d832013-03-07 12:19:30 -0800672{
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700673#if MMC_SDHCI_SUPPORT
674 mmc_put_card_to_sleep(dev);
675#else
676 mmc_put_card_to_sleep();
677#endif
sundarajan srinivasana098d832013-03-07 12:19:30 -0800678#ifdef SSD_ENABLE
679 clock_ce_disable(SSD_CE_INSTANCE_1);
680#endif
Channagoud Kadabi2095a412013-12-04 12:37:06 -0800681 if (crypto_initialized())
682 crypto_eng_cleanup();
Channagoud Kadabid0115f92014-01-24 17:25:34 -0800683
684 /* Disable HC mode before jumping to kernel */
685 sdhci_mode_disable(&dev->host);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800686}
Deepa Dinamani65df9822013-03-08 13:38:34 -0800687
688void shutdown_device()
689{
690 dprintf(CRITICAL, "Going down for shutdown.\n");
691
692 /* Configure PMIC for shutdown. */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700693 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Deepa Dinamani65df9822013-03-08 13:38:34 -0800694 pm8x41_v2_reset_configure(PON_PSHOLD_SHUTDOWN);
695 else
696 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
697
698 /* Drop PS_HOLD for MSM */
699 writel(0x00, MPM2_MPM_PS_HOLD);
700
701 mdelay(5000);
702
703 dprintf(CRITICAL, "Shutdown failed\n");
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700704}
705
706static void set_sdc_power_ctrl()
707{
Channagoud Kadabi224d8322013-09-27 14:25:22 -0700708 uint8_t tlmm_hdrv_clk = 0;
709 uint32_t platform_id = 0;
710
711 platform_id = board_platform_id();
712
713 switch(platform_id)
714 {
715 case MSM8274AA:
716 case MSM8274AB:
717 case MSM8674AA:
718 case MSM8674AB:
719 case MSM8974AA:
720 case MSM8974AB:
721 if (board_hardware_id() == HW_PLATFORM_MTP)
722 tlmm_hdrv_clk = TLMM_CUR_VAL_10MA;
723 else
724 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
725 break;
726 default:
727 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
728 };
729
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700730 /* Drive strength configs for sdc pins */
731 struct tlmm_cfgs sdc1_hdrv_cfg[] =
732 {
Channagoud Kadabi224d8322013-09-27 14:25:22 -0700733 { SDC1_CLK_HDRV_CTL_OFF, tlmm_hdrv_clk, TLMM_HDRV_MASK },
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700734 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
735 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
736 };
737
738 /* Pull configs for sdc pins */
739 struct tlmm_cfgs sdc1_pull_cfg[] =
740 {
741 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
742 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
743 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
744 };
745
Channagoud Kadabi389cab22013-08-20 15:29:15 -0700746 struct tlmm_cfgs sdc1_rclk_cfg[] =
747 {
748 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK },
749 };
750
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700751 /* Set the drive strength & pull control values */
752 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
753 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
Channagoud Kadabi389cab22013-08-20 15:29:15 -0700754
755 /* RCLK is supported only with 8974 pro, set rclk to pull down
756 * only for 8974 pro targets
757 */
758 if (!platform_is_8974())
759 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700760}
Stanimir Varbanovf64a0292013-04-29 11:58:27 +0300761
762int emmc_recovery_init(void)
763{
764 return _emmc_recovery_init();
765}
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700766
767void target_usb_stop(void)
768{
769 uint32_t platform = board_platform_id();
770
771 /* Disable VBUS mimicing in the controller. */
772 if (target_needs_vbus_mimic())
773 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
774}
Amol Jadi4c3229f2013-10-07 14:38:06 -0700775
776/* identify the usb controller to be used for the target */
777const char * target_usb_controller()
778{
779 switch(board_platform_id())
780 {
781 /* use dwc controller for PRO chips (with some exceptions) */
782 case MSM8974AA:
783 case MSM8974AB:
784 case MSM8974AC:
785 /* exceptions based on hardware id */
786 if (board_hardware_id() != HW_PLATFORM_DRAGON)
787 return "dwc";
788 /* fall through to default "ci" for anything that did'nt select "dwc" */
789 default:
790 return "ci";
791 }
792}
Amol Jadi28864bb2013-10-11 14:12:59 -0700793
794/* UTMI MUX configuration to connect PHY to SNPS controller:
795 * Configure primary HS phy mux to use UTMI interface
796 * (connected to usb30 controller).
797 */
798static void tcsr_hs_phy_mux_configure(void)
799{
800 uint32_t reg;
801
802 reg = readl(USB2_PHY_SEL);
803
804 writel(reg | 0x1, USB2_PHY_SEL);
805}
806
807/* configure hs phy mux if using dwc controller */
808void target_usb_phy_mux_configure(void)
809{
810 if(!strcmp(target_usb_controller(), "dwc"))
811 {
812 tcsr_hs_phy_mux_configure();
813 }
814}