blob: 1d246c7c7eae541e4984f287e8d1fb6d6efe8a3d [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>
Sundarajan Srinivasan1215c6f2014-03-21 17:34:29 -070055#include <boot_device.h>
Deepa Dinamani0e5038f2013-05-16 15:02:16 -070056
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -070057#define PMIC_ARB_CHANNEL_NUM 0
58#define PMIC_ARB_OWNER_ID 0
59
Shashank Mittalc3621fe2014-08-28 15:38:19 -070060#define RECOVERY_MODE 0x77665502
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -070061#define FASTBOOT_MODE 0x77665500
62
Sundarajan Srinivasan4161b7e2013-09-10 13:55:31 -070063#define BOOT_DEVICE_MASK(val) ((val & 0x3E) >>1)
64
Sundarajan Srinivasan4431e162013-12-10 13:16:04 -080065#define SSD_CE_INSTANCE 1
66
Sundarajan Srinivasan86106c32013-12-19 11:36:07 -080067#define CE2_INSTANCE 2
68#define CE_EE 1
69#define CE_FIFO_SIZE 64
70#define CE_READ_PIPE 3
71#define CE_WRITE_PIPE 2
72#define CE_READ_PIPE_LOCK_GRP 0
73#define CE_WRITE_PIPE_LOCK_GRP 0
74#define CE_ARRAY_SIZE 20
75
Ameya Thakurcfca9212013-09-13 23:51:49 -070076enum cdp_subtype
77{
78 CDP_SUBTYPE_SMB349 = 0,
79 CDP_SUBTYPE_9x25_SMB349,
80 CDP_SUBTYPE_9x25_SMB1357,
81 CDP_SUBTYPE_9x35,
Sundarajan Srinivasan01e68f12013-11-01 12:21:52 -070082 CDP_SUBTYPE_SMB1357,
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -080083 CDP_SUBTYPE_SMB350,
84 CDP_SUBTYPE_9x35_M
Ameya Thakurcfca9212013-09-13 23:51:49 -070085};
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -070086
Ameya Thakurcfca9212013-09-13 23:51:49 -070087enum mtp_subtype
88{
89 MTP_SUBTYPE_SMB349 = 0,
90 MTP_SUBTYPE_9x25_SMB349,
91 MTP_SUBTYPE_9x25_SMB1357,
92 MTP_SUBTYPE_9x35,
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -080093 MTP_SUBTYPE_9x35_M
Ameya Thakurcfca9212013-09-13 23:51:49 -070094};
95
96enum rcm_subtype
97{
98 RCM_SUBTYPE_SMB349 = 0,
99 RCM_SUBTYPE_9x25_SMB349,
100 RCM_SUBTYPE_9x25_SMB1357,
101 RCM_SUBTYPE_9x35,
102 RCM_SUBTYPE_SMB1357,
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -0800103 RCM_SUBTYPE_SMB350,
104 RCM_SUBTYPE_9x35_M
Ameya Thakurcfca9212013-09-13 23:51:49 -0700105};
106
Sundarajan Srinivasan6ade93e2013-11-18 11:07:22 -0800107enum liquid_subtype
108{
109 LIQUID_SUBTYPE_STANDALONE = 0,
110 LIQUID_SUBTYPE_9x25,
111};
112
Ameya Thakurcfca9212013-09-13 23:51:49 -0700113static void set_sdc_power_ctrl(void);
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700114static uint32_t mmc_pwrctl_base[] =
115 { MSM_SDC1_BASE, MSM_SDC2_BASE };
116
117static uint32_t mmc_sdhci_base[] =
118 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
119
120static uint32_t mmc_sdc_pwrctl_irq[] =
121 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
122
123struct mmc_device *dev;
Channagoud Kadabi415a7022013-09-11 10:48:40 -0700124struct ufs_dev ufs_device;
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700125
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700126extern void ulpi_write(unsigned val, unsigned reg);
Pavel Nedeva6c0beb2013-11-15 17:20:27 +0200127extern int _emmc_recovery_init(void);
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700128
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700129void target_early_init(void)
130{
131#if WITH_DEBUG_UART
Sundarajan Srinivasand8b7c6f2013-09-13 16:50:22 -0700132 uart_dm_init(7, 0, BLSP2_UART1_BASE);
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700133#endif
134}
135
136/* Return 1 if vol_up pressed */
137static int target_volume_up()
138{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700139 uint8_t status = 0;
140 struct pm8x41_gpio gpio;
141
142 /* Configure the GPIO */
143 gpio.direction = PM_GPIO_DIR_IN;
144 gpio.function = 0;
145 gpio.pull = PM_GPIO_PULL_UP_30;
146 gpio.vin_sel = 2;
147
148 pm8x41_gpio_config(2, &gpio);
149
Channagoud Kadabiefcb8ec2014-01-02 16:22:38 -0800150 /* Wait for the pmic gpio config to take effect */
151 thread_sleep(1);
152
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700153 /* Get status of P_GPIO_2 */
154 pm8x41_gpio_get(2, &status);
155
156 return !status; /* active low */
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700157}
158
159/* Return 1 if vol_down pressed */
160uint32_t target_volume_down()
161{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700162 return pm8x41_resin_status();
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700163}
164
165static void target_keystatus()
166{
167 keys_init();
168
169 if(target_volume_down())
170 keys_post_event(KEY_VOLUMEDOWN, 1);
171
172 if(target_volume_up())
173 keys_post_event(KEY_VOLUMEUP, 1);
174}
175
David Ng4c2e86d2013-09-15 22:03:37 -0700176void target_uninit(void)
177{
Sundarajan Srinivasan1215c6f2014-03-21 17:34:29 -0700178 if(platform_boot_dev_isemmc())
Channagoud Kadabi154764f2014-01-24 17:45:19 -0800179 {
Sundarajan Srinivasan29cb66e2013-10-30 18:48:27 -0700180 mmc_put_card_to_sleep(dev);
Channagoud Kadabi154764f2014-01-24 17:45:19 -0800181 sdhci_mode_disable(&dev->host);
182 }
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];
Aparna Mallavarapu7b1393e2014-03-11 13:45:21 +0530248 config.hs400_support = 1;
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700249
250 if (!(dev = mmc_init(&config)))
251 {
252 /* Try slot 2 */
253 config.slot = 2;
Channagoud Kadabide9b2d32013-11-08 13:24:47 -0800254 config.max_clk_rate = MMC_CLK_200MHZ;
255 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
256 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
257 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700258
259 if (!(dev = mmc_init(&config)))
260 {
261 dprintf(CRITICAL, "mmc init failed!");
262 ASSERT(0);
263 }
264 }
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700265}
266
Channagoud Kadabi415a7022013-09-11 10:48:40 -0700267void *target_mmc_device()
268{
Sundarajan Srinivasan1215c6f2014-03-21 17:34:29 -0700269 if (platform_boot_dev_isemmc())
Channagoud Kadabi415a7022013-09-11 10:48:40 -0700270 return (void *) dev;
271 else
272 return (void *) &ufs_device;
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700273}
274
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700275void target_init(void)
276{
277 dprintf(INFO, "target_init()\n");
278
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700279 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
280
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700281 target_keystatus();
282
Sundarajan Srinivasan86106c32013-12-19 11:36:07 -0800283 if (target_use_signed_kernel())
284 target_crypto_init_params();
285
Sundarajan Srinivasan1215c6f2014-03-21 17:34:29 -0700286 platform_read_boot_config();
Sundarajan Srinivasan4161b7e2013-09-10 13:55:31 -0700287
Sundarajan Srinivasan1215c6f2014-03-21 17:34:29 -0700288 if (platform_boot_dev_isemmc())
Channagoud Kadabi415a7022013-09-11 10:48:40 -0700289 target_sdc_init();
290 else
291 {
292 ufs_device.base = UFS_BASE;
293 ufs_init(&ufs_device);
294 }
295
296 /* Storage initialization is complete, read the partition table info */
297 if (partition_read_table())
298 {
299 dprintf(CRITICAL, "Error reading the partition table info\n");
300 ASSERT(0);
301 }
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700302}
303
Sundarajan Srinivasan4431e162013-12-10 13:16:04 -0800304void target_load_ssd_keystore(void)
305{
306 uint64_t ptn;
307 int index;
308 uint64_t size;
309 uint32_t *buffer = NULL;
310
311 if (!target_is_ssd_enabled())
312 return;
313
314 index = partition_get_index("ssd");
315
316 ptn = partition_get_offset(index);
317 if (ptn == 0){
318 dprintf(CRITICAL, "Error: ssd partition not found\n");
319 return;
320 }
321
322 size = partition_get_size(index);
323 if (size == 0) {
324 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
325 return;
326 }
327
328 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
329 if (!buffer) {
330 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
331 return;
332 }
333
334 if (mmc_read(ptn, buffer, size)) {
335 dprintf(CRITICAL, "Error: cannot read data\n");
336 free(buffer);
337 return;
338 }
339
340 clock_ce_enable(SSD_CE_INSTANCE);
341 scm_protect_keystore(buffer, size);
342 clock_ce_disable(SSD_CE_INSTANCE);
343 free(buffer);
344}
345
346/* Do any target specific intialization needed before entering fastboot mode */
347void target_fastboot_init(void)
348{
Sundarajan Srinivasan23301ef2013-11-18 17:21:00 -0800349 /* We are entering fastboot mode, so read partition table */
350 mmc_read_partition_table(1);
351
Sundarajan Srinivasan4431e162013-12-10 13:16:04 -0800352 if (target_is_ssd_enabled()) {
353 clock_ce_enable(SSD_CE_INSTANCE);
354 target_load_ssd_keystore();
355 }
356
357}
358
Channagoud Kadabi7fe8df62014-02-04 17:08:10 -0800359/* Initialize target specific USB handlers */
360target_usb_iface_t* target_usb30_init()
361{
362 target_usb_iface_t *t_usb_iface;
363
364 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
365 ASSERT(t_usb_iface);
366
367 t_usb_iface->mux_config = target_usb_phy_mux_configure;
368 t_usb_iface->phy_reset = target_usb_phy_reset;
369 t_usb_iface->clock_init = clock_usb30_init;
370 t_usb_iface->vbus_override = 1;
371
372 return t_usb_iface;
373}
374
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700375unsigned board_machtype(void)
376{
377 return LINUX_MACHTYPE_UNKNOWN;
378}
379
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700380/* Detect the target type */
381void target_detect(struct board_data *board)
382{
Channagoud Kadabieabb9ad2014-02-11 15:34:24 -0800383 /* This is alreay filled as part of board.c */
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700384}
385
Ameya Thakurcfca9212013-09-13 23:51:49 -0700386void set_cdp_baseband(struct board_data *board)
387{
388
389 uint32_t platform_subtype;
390 platform_subtype = board->platform_subtype;
391
392 switch(platform_subtype) {
393 case CDP_SUBTYPE_9x25_SMB349:
394 case CDP_SUBTYPE_9x25_SMB1357:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700395 board->baseband = BASEBAND_MDM;
396 break;
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800397 case CDP_SUBTYPE_9x35:
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -0800398 case CDP_SUBTYPE_9x35_M:
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800399 board->baseband = BASEBAND_MDM2;
400 break;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700401 case CDP_SUBTYPE_SMB349:
402 case CDP_SUBTYPE_SMB1357:
Sundarajan Srinivasan01e68f12013-11-01 12:21:52 -0700403 case CDP_SUBTYPE_SMB350:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700404 board->baseband = BASEBAND_APQ;
405 break;
406 default:
407 dprintf(CRITICAL, "CDP platform subtype :%u is not supported\n",
408 platform_subtype);
409 ASSERT(0);
410 };
411
412}
413
414void set_mtp_baseband(struct board_data *board)
415{
416
417 uint32_t platform_subtype;
418 platform_subtype = board->platform_subtype;
419
420 switch(platform_subtype) {
421 case MTP_SUBTYPE_9x25_SMB349:
422 case MTP_SUBTYPE_9x25_SMB1357:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700423 board->baseband = BASEBAND_MDM;
424 break;
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800425 case MTP_SUBTYPE_9x35:
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -0800426 case MTP_SUBTYPE_9x35_M:
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800427 board->baseband = BASEBAND_MDM2;
428 break;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700429 case MTP_SUBTYPE_SMB349:
430 board->baseband = BASEBAND_APQ;
431 break;
432 default:
433 dprintf(CRITICAL, "MTP platform subtype :%u is not supported\n",
434 platform_subtype);
435 ASSERT(0);
436 };
437}
438
439void set_rcm_baseband(struct board_data *board)
440{
441 uint32_t platform_subtype;
442 platform_subtype = board->platform_subtype;
443
444 switch(platform_subtype) {
445 case RCM_SUBTYPE_9x25_SMB349:
446 case RCM_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 RCM_SUBTYPE_9x35:
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -0800450 case RCM_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 RCM_SUBTYPE_SMB349:
454 case RCM_SUBTYPE_SMB1357:
Sundarajan Srinivasan01e68f12013-11-01 12:21:52 -0700455 case RCM_SUBTYPE_SMB350:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700456 board->baseband = BASEBAND_APQ;
457 break;
458 default:
459 dprintf(CRITICAL, "RCM platform subtype :%u is not supported\n",
460 platform_subtype);
461 ASSERT(0);
462 };
463}
464
Sundarajan Srinivasan6ade93e2013-11-18 11:07:22 -0800465void set_liquid_baseband(struct board_data *board)
466{
467 uint32_t platform_subtype;
468
469 platform_subtype = board->platform_subtype;
470
471 switch(platform_subtype)
472 {
473 case LIQUID_SUBTYPE_STANDALONE:
474 board->baseband = BASEBAND_APQ;
475 break;
476 case LIQUID_SUBTYPE_9x25:
477 board->baseband = BASEBAND_MDM;
478 break;
479 default:
480 dprintf(CRITICAL, "Liquid platform subtype :%u is not supported\n",platform_subtype);
481 ASSERT(0);
482 }
483}
484
Dhaval Patelf9986272013-10-18 19:06:05 -0700485/* Returns 1 if target supports continuous splash screen. */
486int target_cont_splash_screen()
487{
488 switch(board_hardware_id())
489 {
490 case HW_PLATFORM_SURF:
491 case HW_PLATFORM_MTP:
492 case HW_PLATFORM_FLUID:
Dhaval Pateld0a09e22013-10-25 10:15:21 -0700493 case HW_PLATFORM_LIQUID:
494 dprintf(SPEW, "Target_cont_splash=1\n");
Dhaval Patelf9986272013-10-18 19:06:05 -0700495 return 1;
Dhaval Patelf9986272013-10-18 19:06:05 -0700496 default:
497 dprintf(SPEW, "Target_cont_splash=0\n");
498 return 0;
499 }
500}
Ameya Thakurcfca9212013-09-13 23:51:49 -0700501
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700502/* Detect the modem type */
503void target_baseband_detect(struct board_data *board)
504{
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700505 uint32_t platform;
506 uint32_t platform_subtype;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700507 uint32_t platform_hardware;
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700508
509 platform = board->platform;
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700510
Ameya Thakurcfca9212013-09-13 23:51:49 -0700511 platform_hardware = board->platform_hw;
512
513 switch(platform_hardware) {
514 case HW_PLATFORM_SURF:
515 set_cdp_baseband(board);
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700516 break;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700517 case HW_PLATFORM_MTP:
518 set_mtp_baseband(board);
519 break;
520 case HW_PLATFORM_RCM:
521 set_rcm_baseband(board);
522 break;
523 case HW_PLATFORM_LIQUID:
Sundarajan Srinivasan6ade93e2013-11-18 11:07:22 -0800524 set_liquid_baseband(board);
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700525 break;
Eugene Yasman2a462112013-12-09 09:26:37 +0200526 case HW_PLATFORM_SBC:
527 board->baseband = BASEBAND_APQ;
528 break;
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700529 default:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700530 dprintf(CRITICAL, "Platform :%u is not supported\n",
531 platform_hardware);
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700532 ASSERT(0);
Ameya Thakurcfca9212013-09-13 23:51:49 -0700533 };
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700534}
535
536unsigned target_baseband()
537{
538 return board_baseband();
539}
540
541void target_serialno(unsigned char *buf)
542{
543 unsigned int serialno;
544 if (target_is_emmc_boot()) {
545 serialno = mmc_get_psn();
546 snprintf((char *)buf, 13, "%x", serialno);
547 }
548}
549
Pavel Nedeva6c0beb2013-11-15 17:20:27 +0200550int emmc_recovery_init(void)
551{
552 return _emmc_recovery_init();
553}
554
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700555unsigned check_reboot_mode(void)
556{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700557 uint32_t restart_reason = 0;
558 uint32_t restart_reason_addr;
559
560 restart_reason_addr = RESTART_REASON_ADDR;
561
562 /* Read reboot reason and scrub it */
563 restart_reason = readl(restart_reason_addr);
564 writel(0x00, restart_reason_addr);
565
566 return restart_reason;
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700567}
568
569void reboot_device(unsigned reboot_reason)
570{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700571 uint8_t reset_type = 0;
572
573 /* Write the reboot reason */
574 writel(reboot_reason, RESTART_REASON_ADDR);
575
Shashank Mittalc3621fe2014-08-28 15:38:19 -0700576 if(reboot_reason == FASTBOOT_MODE || reboot_reason == RECOVERY_MODE)
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700577 reset_type = PON_PSHOLD_WARM_RESET;
578 else
579 reset_type = PON_PSHOLD_HARD_RESET;
580
581 pm8x41_reset_configure(reset_type);
582
583 /* Drop PS_HOLD for MSM */
584 writel(0x00, MPM2_MPM_PS_HOLD);
585
586 mdelay(5000);
587
588 dprintf(CRITICAL, "Rebooting failed\n");
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700589}
Amol Jadi0a4c9b42013-10-11 14:22:11 -0700590
Sundarajan Srinivasan8a3ecf52014-05-06 11:32:41 -0700591void shutdown_device()
592{
593 dprintf(CRITICAL, "Going down for shutdown.\n");
594
595 /* Configure PMIC for shutdown. */
596 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
597
598 /* Drop PS_HOLD for MSM */
599 writel(0x00, MPM2_MPM_PS_HOLD);
600
601 mdelay(5000);
602
603 dprintf(CRITICAL, "Shutdown failed\n");
604
605 ASSERT(0);
606}
607
Amol Jadi0a4c9b42013-10-11 14:22:11 -0700608/* identify the usb controller to be used for the target */
609const char * target_usb_controller()
610{
611 return "dwc";
612}
613
614/* mux hs phy to route to dwc controller */
615static void phy_mux_configure_with_jdr()
616{
617 uint32_t val;
618
619 val = readl(COPSS_USB_CONTROL_WITH_JDR);
620
621 /* Note: there are no details regarding this bit in hpg or swi. */
622 val |= BIT(8);
623
624 writel(val, COPSS_USB_CONTROL_WITH_JDR);
625}
626
627/* configure hs phy mux if using dwc controller */
628void target_usb_phy_mux_configure(void)
629{
630 if(!strcmp(target_usb_controller(), "dwc"))
631 {
632 phy_mux_configure_with_jdr();
633 }
634}
635
636void target_usb_phy_reset(void)
637{
638 uint32_t val;
639
640 /* SS PHY reset */
641 val = readl(GCC_USB3_PHY_BCR) | BIT(0);
642 writel(val, GCC_USB3_PHY_BCR);
643 udelay(10);
644 writel(val & ~BIT(0), GCC_USB3_PHY_BCR);
645
646 /* HS PHY reset */
647 /* Note: reg/bit details are not mentioned in hpg or swi. */
648 val = readl(COPSS_USB_CONTROL_WITH_JDR) | BIT(11);
649 writel(val, COPSS_USB_CONTROL_WITH_JDR);
650 udelay(10);
651 writel(val & ~BIT(11), COPSS_USB_CONTROL_WITH_JDR);
Channagoud Kadabi70500ea2013-10-29 17:33:44 -0700652
653 /* PHY_COMMON reset */
654 val = readl(GCC_USB30_PHY_COM_BCR) | BIT(0);
655 writel(val, GCC_USB30_PHY_COM_BCR);
656 udelay(10);
657 writel(val & ~BIT(0), GCC_USB30_PHY_COM_BCR);
Amol Jadi0a4c9b42013-10-11 14:22:11 -0700658}
Sundarajan Srinivasan86106c32013-12-19 11:36:07 -0800659
Hanumant Singh75311942014-01-29 13:43:53 -0800660bool target_warm_boot(void)
661{
662 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
663 if (is_cold_boot)
664 return false;
665 else
666 return true;
667}
Sundarajan Srinivasan86106c32013-12-19 11:36:07 -0800668/* Set up params for h/w CE. */
669void target_crypto_init_params()
670{
671 struct crypto_init_params ce_params;
672
673 /* Set up base addresses and instance. */
674 ce_params.crypto_instance = CE2_INSTANCE;
675 ce_params.crypto_base = MSM_CE2_BASE;
676 ce_params.bam_base = MSM_CE2_BAM_BASE;
677
678 /* Set up BAM config. */
679 ce_params.bam_ee = CE_EE;
680 ce_params.pipes.read_pipe = CE_READ_PIPE;
681 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
682 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
683 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
684
685 /* Assign buffer sizes. */
686 ce_params.num_ce = CE_ARRAY_SIZE;
687 ce_params.read_fifo_size = CE_FIFO_SIZE;
688 ce_params.write_fifo_size = CE_FIFO_SIZE;
689
690 /* BAM is initialized by TZ for this platform.
691 * Do not do it again as the initialization address space
692 * is locked.
693 */
694 ce_params.do_bam_init = 0;
695
696 crypto_init_params(&ce_params);
697}
698
699crypto_engine_type board_ce_type(void)
700{
701 return CRYPTO_ENGINE_TYPE_HW;
702}