blob: 6b61f987000539f8af8b224db56b01577e4407a6 [file] [log] [blame]
Sundarajan Srinivasan86106c32013-12-19 11:36:07 -08001/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Deepa Dinamani0e5038f2013-05-16 15:02:16 -07002 *
3 * Redistribution and use in source and binary forms, with or without
4 * 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.
15 *
16 * 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.
27 */
28
29#include <debug.h>
30#include <platform/iomap.h>
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -070031#include <platform/irqs.h>
Deepa Dinamani0e5038f2013-05-16 15:02:16 -070032#include <platform/gpio.h>
33#include <reg.h>
34#include <target.h>
35#include <platform.h>
36#include <dload_util.h>
37#include <uart_dm.h>
38#include <mmc.h>
39#include <spmi.h>
40#include <board.h>
41#include <smem.h>
42#include <baseband.h>
43#include <dev/keys.h>
44#include <pm8x41.h>
45#include <crypto5_wrapper.h>
46#include <hsusb.h>
47#include <clock.h>
48#include <partition_parser.h>
49#include <scm.h>
50#include <platform/clock.h>
51#include <platform/gpio.h>
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -070052#include <platform/timer.h>
Deepa Dinamani0e5038f2013-05-16 15:02:16 -070053#include <stdlib.h>
Channagoud Kadabi415a7022013-09-11 10:48:40 -070054#include <ufs.h>
Deepa Dinamani0e5038f2013-05-16 15:02:16 -070055
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -070056#define PMIC_ARB_CHANNEL_NUM 0
57#define PMIC_ARB_OWNER_ID 0
58
59#define FASTBOOT_MODE 0x77665500
60
Sundarajan Srinivasan4161b7e2013-09-10 13:55:31 -070061#define BOOT_DEVICE_MASK(val) ((val & 0x3E) >>1)
62
Sundarajan Srinivasan4431e162013-12-10 13:16:04 -080063#define SSD_CE_INSTANCE 1
64
Sundarajan Srinivasan86106c32013-12-19 11:36:07 -080065#define CE2_INSTANCE 2
66#define CE_EE 1
67#define CE_FIFO_SIZE 64
68#define CE_READ_PIPE 3
69#define CE_WRITE_PIPE 2
70#define CE_READ_PIPE_LOCK_GRP 0
71#define CE_WRITE_PIPE_LOCK_GRP 0
72#define CE_ARRAY_SIZE 20
73
Ameya Thakurcfca9212013-09-13 23:51:49 -070074enum cdp_subtype
75{
76 CDP_SUBTYPE_SMB349 = 0,
77 CDP_SUBTYPE_9x25_SMB349,
78 CDP_SUBTYPE_9x25_SMB1357,
79 CDP_SUBTYPE_9x35,
Sundarajan Srinivasan01e68f12013-11-01 12:21:52 -070080 CDP_SUBTYPE_SMB1357,
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -080081 CDP_SUBTYPE_SMB350,
82 CDP_SUBTYPE_9x35_M
Ameya Thakurcfca9212013-09-13 23:51:49 -070083};
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -070084
Ameya Thakurcfca9212013-09-13 23:51:49 -070085enum mtp_subtype
86{
87 MTP_SUBTYPE_SMB349 = 0,
88 MTP_SUBTYPE_9x25_SMB349,
89 MTP_SUBTYPE_9x25_SMB1357,
90 MTP_SUBTYPE_9x35,
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -080091 MTP_SUBTYPE_9x35_M
Ameya Thakurcfca9212013-09-13 23:51:49 -070092};
93
94enum rcm_subtype
95{
96 RCM_SUBTYPE_SMB349 = 0,
97 RCM_SUBTYPE_9x25_SMB349,
98 RCM_SUBTYPE_9x25_SMB1357,
99 RCM_SUBTYPE_9x35,
100 RCM_SUBTYPE_SMB1357,
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -0800101 RCM_SUBTYPE_SMB350,
102 RCM_SUBTYPE_9x35_M
Ameya Thakurcfca9212013-09-13 23:51:49 -0700103};
104
Sundarajan Srinivasan6ade93e2013-11-18 11:07:22 -0800105enum liquid_subtype
106{
107 LIQUID_SUBTYPE_STANDALONE = 0,
108 LIQUID_SUBTYPE_9x25,
109};
110
Ameya Thakurcfca9212013-09-13 23:51:49 -0700111static void set_sdc_power_ctrl(void);
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700112static uint32_t mmc_pwrctl_base[] =
113 { MSM_SDC1_BASE, MSM_SDC2_BASE };
114
115static uint32_t mmc_sdhci_base[] =
116 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
117
118static uint32_t mmc_sdc_pwrctl_irq[] =
119 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
120
121struct mmc_device *dev;
Channagoud Kadabi415a7022013-09-11 10:48:40 -0700122struct ufs_dev ufs_device;
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700123
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700124extern void ulpi_write(unsigned val, unsigned reg);
Pavel Nedeva6c0beb2013-11-15 17:20:27 +0200125extern int _emmc_recovery_init(void);
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700126
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700127void target_early_init(void)
128{
129#if WITH_DEBUG_UART
Sundarajan Srinivasand8b7c6f2013-09-13 16:50:22 -0700130 uart_dm_init(7, 0, BLSP2_UART1_BASE);
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700131#endif
132}
133
134/* Return 1 if vol_up pressed */
135static int target_volume_up()
136{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700137 uint8_t status = 0;
138 struct pm8x41_gpio gpio;
139
140 /* Configure the GPIO */
141 gpio.direction = PM_GPIO_DIR_IN;
142 gpio.function = 0;
143 gpio.pull = PM_GPIO_PULL_UP_30;
144 gpio.vin_sel = 2;
145
146 pm8x41_gpio_config(2, &gpio);
147
Channagoud Kadabiefcb8ec2014-01-02 16:22:38 -0800148 /* Wait for the pmic gpio config to take effect */
149 thread_sleep(1);
150
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700151 /* Get status of P_GPIO_2 */
152 pm8x41_gpio_get(2, &status);
153
154 return !status; /* active low */
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700155}
156
157/* Return 1 if vol_down pressed */
158uint32_t target_volume_down()
159{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700160 return pm8x41_resin_status();
Deepa Dinamani0e5038f2013-05-16 15:02:16 -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
David Ng4c2e86d2013-09-15 22:03:37 -0700174void target_uninit(void)
175{
Sundarajan Srinivasan29cb66e2013-10-30 18:48:27 -0700176 if(target_boot_device_emmc())
Channagoud Kadabi154764f2014-01-24 17:45:19 -0800177 {
Sundarajan Srinivasan29cb66e2013-10-30 18:48:27 -0700178 mmc_put_card_to_sleep(dev);
Channagoud Kadabi154764f2014-01-24 17:45:19 -0800179 sdhci_mode_disable(&dev->host);
180 }
Aravind Venkateswarandd50c1a2014-02-25 14:42:43 -0800181
182 target_display_shutdown();
David Ng4c2e86d2013-09-15 22:03:37 -0700183}
184
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700185/* Do target specific usb initialization */
186void target_usb_init(void)
187{
188 uint32_t val;
189
190 /* Select and enable external configuration with USB PHY */
191 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
192
193 /* Enable sess_vld */
194 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
195 writel(val, USB_GENCONFIG_2);
196
197 /* Enable external vbus configuration in the LINK */
198 val = readl(USB_USBCMD);
199 val |= SESS_VLD_CTRL;
200 writel(val, USB_USBCMD);
201}
202
203void target_usb_stop(void)
204{
205 /* Disable VBUS mimicing in the controller. */
206 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
207}
208
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700209static void set_sdc_power_ctrl()
210{
211 /* Drive strength configs for sdc pins */
212 struct tlmm_cfgs sdc1_hdrv_cfg[] =
213 {
214 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
215 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
216 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
217 };
218
219 /* Pull configs for sdc pins */
220 struct tlmm_cfgs sdc1_pull_cfg[] =
221 {
222 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
223 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
224 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
Channagoud Kadabic14b4042013-09-23 11:20:32 -0700225 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK },
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700226 };
227
228 /* Set the drive strength & pull control values */
229 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
230 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
231}
232
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700233void target_sdc_init()
234{
235 struct mmc_config_data config;
236
237 /* Set drive strength & pull ctrl values */
238 set_sdc_power_ctrl();
239
240 config.bus_width = DATA_BUS_WIDTH_8BIT;
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700241
242 /* Try slot 1*/
243 config.slot = 1;
Channagoud Kadabide9b2d32013-11-08 13:24:47 -0800244 config.max_clk_rate = MMC_CLK_192MHZ;
245 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
246 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
247 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700248
249 if (!(dev = mmc_init(&config)))
250 {
251 /* Try slot 2 */
252 config.slot = 2;
Channagoud Kadabide9b2d32013-11-08 13:24:47 -0800253 config.max_clk_rate = MMC_CLK_200MHZ;
254 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
255 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
256 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700257
258 if (!(dev = mmc_init(&config)))
259 {
260 dprintf(CRITICAL, "mmc init failed!");
261 ASSERT(0);
262 }
263 }
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700264}
265
Sundarajan Srinivasan4161b7e2013-09-10 13:55:31 -0700266static uint32_t boot_device;
267static uint32_t target_read_boot_config()
268{
269 uint32_t val;
270
271 val = readl(BOOT_CONFIG_REG);
272
273 val = BOOT_DEVICE_MASK(val);
274
275 return val;
276}
277
278uint32_t target_get_boot_device()
279{
280 return boot_device;
281}
282
Channagoud Kadabi415a7022013-09-11 10:48:40 -0700283/*
284 * Return 1 if boot from emmc else 0
285 */
286uint32_t target_boot_device_emmc()
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700287{
Channagoud Kadabi415a7022013-09-11 10:48:40 -0700288 uint32_t boot_dev_type;
289
Sundarajan Srinivasan4161b7e2013-09-10 13:55:31 -0700290 boot_dev_type = target_get_boot_device();
Channagoud Kadabi415a7022013-09-11 10:48:40 -0700291
292 if (boot_dev_type == BOOT_EMMC || boot_dev_type == BOOT_DEFAULT)
293 boot_dev_type = 1;
294 else
295 boot_dev_type = 0;
296
297 return boot_dev_type;
298}
299
300void *target_mmc_device()
301{
302 if (target_boot_device_emmc())
303 return (void *) dev;
304 else
305 return (void *) &ufs_device;
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700306}
307
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700308void target_init(void)
309{
310 dprintf(INFO, "target_init()\n");
311
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700312 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
313
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700314 target_keystatus();
315
Sundarajan Srinivasan86106c32013-12-19 11:36:07 -0800316 if (target_use_signed_kernel())
317 target_crypto_init_params();
318
Sundarajan Srinivasan4161b7e2013-09-10 13:55:31 -0700319 boot_device = target_read_boot_config();
320
Channagoud Kadabi415a7022013-09-11 10:48:40 -0700321 if (target_boot_device_emmc())
322 target_sdc_init();
323 else
324 {
325 ufs_device.base = UFS_BASE;
326 ufs_init(&ufs_device);
327 }
328
329 /* Storage initialization is complete, read the partition table info */
330 if (partition_read_table())
331 {
332 dprintf(CRITICAL, "Error reading the partition table info\n");
333 ASSERT(0);
334 }
335
Dhaval Patelf9986272013-10-18 19:06:05 -0700336 /* Display splash screen if enabled */
337#if DISPLAY_SPLASH_SCREEN
338 dprintf(INFO, "Display Init: Start\n");
Aravind Venkateswarandd50c1a2014-02-25 14:42:43 -0800339 target_display_init();
Dhaval Patelf9986272013-10-18 19:06:05 -0700340 dprintf(INFO, "Display Init: Done\n");
341#endif
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700342}
343
Sundarajan Srinivasan4431e162013-12-10 13:16:04 -0800344void target_load_ssd_keystore(void)
345{
346 uint64_t ptn;
347 int index;
348 uint64_t size;
349 uint32_t *buffer = NULL;
350
351 if (!target_is_ssd_enabled())
352 return;
353
354 index = partition_get_index("ssd");
355
356 ptn = partition_get_offset(index);
357 if (ptn == 0){
358 dprintf(CRITICAL, "Error: ssd partition not found\n");
359 return;
360 }
361
362 size = partition_get_size(index);
363 if (size == 0) {
364 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
365 return;
366 }
367
368 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
369 if (!buffer) {
370 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
371 return;
372 }
373
374 if (mmc_read(ptn, buffer, size)) {
375 dprintf(CRITICAL, "Error: cannot read data\n");
376 free(buffer);
377 return;
378 }
379
380 clock_ce_enable(SSD_CE_INSTANCE);
381 scm_protect_keystore(buffer, size);
382 clock_ce_disable(SSD_CE_INSTANCE);
383 free(buffer);
384}
385
386/* Do any target specific intialization needed before entering fastboot mode */
387void target_fastboot_init(void)
388{
Sundarajan Srinivasan23301ef2013-11-18 17:21:00 -0800389 /* We are entering fastboot mode, so read partition table */
390 mmc_read_partition_table(1);
391
Sundarajan Srinivasan4431e162013-12-10 13:16:04 -0800392 if (target_is_ssd_enabled()) {
393 clock_ce_enable(SSD_CE_INSTANCE);
394 target_load_ssd_keystore();
395 }
396
397}
398
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700399unsigned board_machtype(void)
400{
401 return LINUX_MACHTYPE_UNKNOWN;
402}
403
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700404/* Detect the target type */
405void target_detect(struct board_data *board)
406{
Channagoud Kadabieabb9ad2014-02-11 15:34:24 -0800407 /* This is alreay filled as part of board.c */
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700408}
409
Ameya Thakurcfca9212013-09-13 23:51:49 -0700410void set_cdp_baseband(struct board_data *board)
411{
412
413 uint32_t platform_subtype;
414 platform_subtype = board->platform_subtype;
415
416 switch(platform_subtype) {
417 case CDP_SUBTYPE_9x25_SMB349:
418 case CDP_SUBTYPE_9x25_SMB1357:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700419 board->baseband = BASEBAND_MDM;
420 break;
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800421 case CDP_SUBTYPE_9x35:
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -0800422 case CDP_SUBTYPE_9x35_M:
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800423 board->baseband = BASEBAND_MDM2;
424 break;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700425 case CDP_SUBTYPE_SMB349:
426 case CDP_SUBTYPE_SMB1357:
Sundarajan Srinivasan01e68f12013-11-01 12:21:52 -0700427 case CDP_SUBTYPE_SMB350:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700428 board->baseband = BASEBAND_APQ;
429 break;
430 default:
431 dprintf(CRITICAL, "CDP platform subtype :%u is not supported\n",
432 platform_subtype);
433 ASSERT(0);
434 };
435
436}
437
438void set_mtp_baseband(struct board_data *board)
439{
440
441 uint32_t platform_subtype;
442 platform_subtype = board->platform_subtype;
443
444 switch(platform_subtype) {
445 case MTP_SUBTYPE_9x25_SMB349:
446 case MTP_SUBTYPE_9x25_SMB1357:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700447 board->baseband = BASEBAND_MDM;
448 break;
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800449 case MTP_SUBTYPE_9x35:
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -0800450 case MTP_SUBTYPE_9x35_M:
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800451 board->baseband = BASEBAND_MDM2;
452 break;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700453 case MTP_SUBTYPE_SMB349:
454 board->baseband = BASEBAND_APQ;
455 break;
456 default:
457 dprintf(CRITICAL, "MTP platform subtype :%u is not supported\n",
458 platform_subtype);
459 ASSERT(0);
460 };
461}
462
463void set_rcm_baseband(struct board_data *board)
464{
465 uint32_t platform_subtype;
466 platform_subtype = board->platform_subtype;
467
468 switch(platform_subtype) {
469 case RCM_SUBTYPE_9x25_SMB349:
470 case RCM_SUBTYPE_9x25_SMB1357:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700471 board->baseband = BASEBAND_MDM;
472 break;
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800473 case RCM_SUBTYPE_9x35:
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -0800474 case RCM_SUBTYPE_9x35_M:
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800475 board->baseband = BASEBAND_MDM2;
476 break;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700477 case RCM_SUBTYPE_SMB349:
478 case RCM_SUBTYPE_SMB1357:
Sundarajan Srinivasan01e68f12013-11-01 12:21:52 -0700479 case RCM_SUBTYPE_SMB350:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700480 board->baseband = BASEBAND_APQ;
481 break;
482 default:
483 dprintf(CRITICAL, "RCM platform subtype :%u is not supported\n",
484 platform_subtype);
485 ASSERT(0);
486 };
487}
488
Sundarajan Srinivasan6ade93e2013-11-18 11:07:22 -0800489void set_liquid_baseband(struct board_data *board)
490{
491 uint32_t platform_subtype;
492
493 platform_subtype = board->platform_subtype;
494
495 switch(platform_subtype)
496 {
497 case LIQUID_SUBTYPE_STANDALONE:
498 board->baseband = BASEBAND_APQ;
499 break;
500 case LIQUID_SUBTYPE_9x25:
501 board->baseband = BASEBAND_MDM;
502 break;
503 default:
504 dprintf(CRITICAL, "Liquid platform subtype :%u is not supported\n",platform_subtype);
505 ASSERT(0);
506 }
507}
508
Dhaval Patelf9986272013-10-18 19:06:05 -0700509/* Returns 1 if target supports continuous splash screen. */
510int target_cont_splash_screen()
511{
512 switch(board_hardware_id())
513 {
514 case HW_PLATFORM_SURF:
515 case HW_PLATFORM_MTP:
516 case HW_PLATFORM_FLUID:
Dhaval Pateld0a09e22013-10-25 10:15:21 -0700517 case HW_PLATFORM_LIQUID:
518 dprintf(SPEW, "Target_cont_splash=1\n");
Dhaval Patelf9986272013-10-18 19:06:05 -0700519 return 1;
Dhaval Patelf9986272013-10-18 19:06:05 -0700520 default:
521 dprintf(SPEW, "Target_cont_splash=0\n");
522 return 0;
523 }
524}
Ameya Thakurcfca9212013-09-13 23:51:49 -0700525
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700526/* Detect the modem type */
527void target_baseband_detect(struct board_data *board)
528{
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700529 uint32_t platform;
530 uint32_t platform_subtype;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700531 uint32_t platform_hardware;
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700532
533 platform = board->platform;
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700534
Ameya Thakurcfca9212013-09-13 23:51:49 -0700535 platform_hardware = board->platform_hw;
536
537 switch(platform_hardware) {
538 case HW_PLATFORM_SURF:
539 set_cdp_baseband(board);
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700540 break;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700541 case HW_PLATFORM_MTP:
542 set_mtp_baseband(board);
543 break;
544 case HW_PLATFORM_RCM:
545 set_rcm_baseband(board);
546 break;
547 case HW_PLATFORM_LIQUID:
Sundarajan Srinivasan6ade93e2013-11-18 11:07:22 -0800548 set_liquid_baseband(board);
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700549 break;
Eugene Yasman2a462112013-12-09 09:26:37 +0200550 case HW_PLATFORM_SBC:
551 board->baseband = BASEBAND_APQ;
552 break;
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700553 default:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700554 dprintf(CRITICAL, "Platform :%u is not supported\n",
555 platform_hardware);
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700556 ASSERT(0);
Ameya Thakurcfca9212013-09-13 23:51:49 -0700557 };
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700558}
559
560unsigned target_baseband()
561{
562 return board_baseband();
563}
564
565void target_serialno(unsigned char *buf)
566{
567 unsigned int serialno;
568 if (target_is_emmc_boot()) {
569 serialno = mmc_get_psn();
570 snprintf((char *)buf, 13, "%x", serialno);
571 }
572}
573
Pavel Nedeva6c0beb2013-11-15 17:20:27 +0200574int emmc_recovery_init(void)
575{
576 return _emmc_recovery_init();
577}
578
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700579unsigned check_reboot_mode(void)
580{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700581 uint32_t restart_reason = 0;
582 uint32_t restart_reason_addr;
583
584 restart_reason_addr = RESTART_REASON_ADDR;
585
586 /* Read reboot reason and scrub it */
587 restart_reason = readl(restart_reason_addr);
588 writel(0x00, restart_reason_addr);
589
590 return restart_reason;
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700591}
592
593void reboot_device(unsigned reboot_reason)
594{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700595 uint8_t reset_type = 0;
596
597 /* Write the reboot reason */
598 writel(reboot_reason, RESTART_REASON_ADDR);
599
600 if(reboot_reason == FASTBOOT_MODE)
601 reset_type = PON_PSHOLD_WARM_RESET;
602 else
603 reset_type = PON_PSHOLD_HARD_RESET;
604
605 pm8x41_reset_configure(reset_type);
606
607 /* Drop PS_HOLD for MSM */
608 writel(0x00, MPM2_MPM_PS_HOLD);
609
610 mdelay(5000);
611
612 dprintf(CRITICAL, "Rebooting failed\n");
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700613}
Amol Jadi0a4c9b42013-10-11 14:22:11 -0700614
615/* identify the usb controller to be used for the target */
616const char * target_usb_controller()
617{
618 return "dwc";
619}
620
621/* mux hs phy to route to dwc controller */
622static void phy_mux_configure_with_jdr()
623{
624 uint32_t val;
625
626 val = readl(COPSS_USB_CONTROL_WITH_JDR);
627
628 /* Note: there are no details regarding this bit in hpg or swi. */
629 val |= BIT(8);
630
631 writel(val, COPSS_USB_CONTROL_WITH_JDR);
632}
633
634/* configure hs phy mux if using dwc controller */
635void target_usb_phy_mux_configure(void)
636{
637 if(!strcmp(target_usb_controller(), "dwc"))
638 {
639 phy_mux_configure_with_jdr();
640 }
641}
642
643void target_usb_phy_reset(void)
644{
645 uint32_t val;
646
647 /* SS PHY reset */
648 val = readl(GCC_USB3_PHY_BCR) | BIT(0);
649 writel(val, GCC_USB3_PHY_BCR);
650 udelay(10);
651 writel(val & ~BIT(0), GCC_USB3_PHY_BCR);
652
653 /* HS PHY reset */
654 /* Note: reg/bit details are not mentioned in hpg or swi. */
655 val = readl(COPSS_USB_CONTROL_WITH_JDR) | BIT(11);
656 writel(val, COPSS_USB_CONTROL_WITH_JDR);
657 udelay(10);
658 writel(val & ~BIT(11), COPSS_USB_CONTROL_WITH_JDR);
Channagoud Kadabi70500ea2013-10-29 17:33:44 -0700659
660 /* PHY_COMMON reset */
661 val = readl(GCC_USB30_PHY_COM_BCR) | BIT(0);
662 writel(val, GCC_USB30_PHY_COM_BCR);
663 udelay(10);
664 writel(val & ~BIT(0), GCC_USB30_PHY_COM_BCR);
Amol Jadi0a4c9b42013-10-11 14:22:11 -0700665}
Sundarajan Srinivasan86106c32013-12-19 11:36:07 -0800666
Hanumant Singh75311942014-01-29 13:43:53 -0800667bool target_warm_boot(void)
668{
669 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
670 if (is_cold_boot)
671 return false;
672 else
673 return true;
674}
Sundarajan Srinivasan86106c32013-12-19 11:36:07 -0800675/* Set up params for h/w CE. */
676void target_crypto_init_params()
677{
678 struct crypto_init_params ce_params;
679
680 /* Set up base addresses and instance. */
681 ce_params.crypto_instance = CE2_INSTANCE;
682 ce_params.crypto_base = MSM_CE2_BASE;
683 ce_params.bam_base = MSM_CE2_BAM_BASE;
684
685 /* Set up BAM config. */
686 ce_params.bam_ee = CE_EE;
687 ce_params.pipes.read_pipe = CE_READ_PIPE;
688 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
689 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
690 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
691
692 /* Assign buffer sizes. */
693 ce_params.num_ce = CE_ARRAY_SIZE;
694 ce_params.read_fifo_size = CE_FIFO_SIZE;
695 ce_params.write_fifo_size = CE_FIFO_SIZE;
696
697 /* BAM is initialized by TZ for this platform.
698 * Do not do it again as the initialization address space
699 * is locked.
700 */
701 ce_params.do_bam_init = 0;
702
703 crypto_init_params(&ce_params);
704}
705
706crypto_engine_type board_ce_type(void)
707{
708 return CRYPTO_ENGINE_TYPE_HW;
709}