blob: 543951e6c3cbfad682fc5991e141fa65e7d9d453 [file] [log] [blame]
Sridhar Parasuram50b9d962015-02-12 11:28:09 -08001/* Copyright (c) 2013-2015, 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
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800288#ifdef MMC_SDHCI_SUPPORT
Sundarajan Srinivasan1215c6f2014-03-21 17:34:29 -0700289 if (platform_boot_dev_isemmc())
Channagoud Kadabi415a7022013-09-11 10:48:40 -0700290 target_sdc_init();
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800291#endif
292#ifdef UFS_SUPPORT
293 if(!platform_boot_dev_isemmc())
Channagoud Kadabi415a7022013-09-11 10:48:40 -0700294 {
295 ufs_device.base = UFS_BASE;
296 ufs_init(&ufs_device);
297 }
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800298#endif
Channagoud Kadabi415a7022013-09-11 10:48:40 -0700299
300 /* Storage initialization is complete, read the partition table info */
301 if (partition_read_table())
302 {
303 dprintf(CRITICAL, "Error reading the partition table info\n");
304 ASSERT(0);
305 }
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700306}
307
Sundarajan Srinivasan4431e162013-12-10 13:16:04 -0800308void target_load_ssd_keystore(void)
309{
310 uint64_t ptn;
311 int index;
312 uint64_t size;
313 uint32_t *buffer = NULL;
314
315 if (!target_is_ssd_enabled())
316 return;
317
318 index = partition_get_index("ssd");
319
320 ptn = partition_get_offset(index);
321 if (ptn == 0){
322 dprintf(CRITICAL, "Error: ssd partition not found\n");
323 return;
324 }
325
326 size = partition_get_size(index);
327 if (size == 0) {
328 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
329 return;
330 }
331
332 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
333 if (!buffer) {
334 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
335 return;
336 }
337
338 if (mmc_read(ptn, buffer, size)) {
339 dprintf(CRITICAL, "Error: cannot read data\n");
340 free(buffer);
341 return;
342 }
343
344 clock_ce_enable(SSD_CE_INSTANCE);
345 scm_protect_keystore(buffer, size);
346 clock_ce_disable(SSD_CE_INSTANCE);
347 free(buffer);
348}
349
350/* Do any target specific intialization needed before entering fastboot mode */
351void target_fastboot_init(void)
352{
Sundarajan Srinivasan23301ef2013-11-18 17:21:00 -0800353 /* We are entering fastboot mode, so read partition table */
354 mmc_read_partition_table(1);
355
Sundarajan Srinivasan4431e162013-12-10 13:16:04 -0800356 if (target_is_ssd_enabled()) {
357 clock_ce_enable(SSD_CE_INSTANCE);
358 target_load_ssd_keystore();
359 }
360
361}
362
Channagoud Kadabi7fe8df62014-02-04 17:08:10 -0800363/* Initialize target specific USB handlers */
364target_usb_iface_t* target_usb30_init()
365{
366 target_usb_iface_t *t_usb_iface;
367
368 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
369 ASSERT(t_usb_iface);
370
371 t_usb_iface->mux_config = target_usb_phy_mux_configure;
372 t_usb_iface->phy_reset = target_usb_phy_reset;
373 t_usb_iface->clock_init = clock_usb30_init;
374 t_usb_iface->vbus_override = 1;
375
376 return t_usb_iface;
377}
378
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700379unsigned board_machtype(void)
380{
381 return LINUX_MACHTYPE_UNKNOWN;
382}
383
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700384/* Detect the target type */
385void target_detect(struct board_data *board)
386{
Channagoud Kadabieabb9ad2014-02-11 15:34:24 -0800387 /* This is alreay filled as part of board.c */
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700388}
389
Ameya Thakurcfca9212013-09-13 23:51:49 -0700390void set_cdp_baseband(struct board_data *board)
391{
392
393 uint32_t platform_subtype;
394 platform_subtype = board->platform_subtype;
395
396 switch(platform_subtype) {
397 case CDP_SUBTYPE_9x25_SMB349:
398 case CDP_SUBTYPE_9x25_SMB1357:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700399 board->baseband = BASEBAND_MDM;
400 break;
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800401 case CDP_SUBTYPE_9x35:
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -0800402 case CDP_SUBTYPE_9x35_M:
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800403 board->baseband = BASEBAND_MDM2;
404 break;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700405 case CDP_SUBTYPE_SMB349:
406 case CDP_SUBTYPE_SMB1357:
Sundarajan Srinivasan01e68f12013-11-01 12:21:52 -0700407 case CDP_SUBTYPE_SMB350:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700408 board->baseband = BASEBAND_APQ;
409 break;
410 default:
411 dprintf(CRITICAL, "CDP platform subtype :%u is not supported\n",
412 platform_subtype);
413 ASSERT(0);
414 };
415
416}
417
418void set_mtp_baseband(struct board_data *board)
419{
420
421 uint32_t platform_subtype;
422 platform_subtype = board->platform_subtype;
423
424 switch(platform_subtype) {
425 case MTP_SUBTYPE_9x25_SMB349:
426 case MTP_SUBTYPE_9x25_SMB1357:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700427 board->baseband = BASEBAND_MDM;
428 break;
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800429 case MTP_SUBTYPE_9x35:
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -0800430 case MTP_SUBTYPE_9x35_M:
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800431 board->baseband = BASEBAND_MDM2;
432 break;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700433 case MTP_SUBTYPE_SMB349:
434 board->baseband = BASEBAND_APQ;
435 break;
436 default:
437 dprintf(CRITICAL, "MTP platform subtype :%u is not supported\n",
438 platform_subtype);
439 ASSERT(0);
440 };
441}
442
443void set_rcm_baseband(struct board_data *board)
444{
445 uint32_t platform_subtype;
446 platform_subtype = board->platform_subtype;
447
448 switch(platform_subtype) {
449 case RCM_SUBTYPE_9x25_SMB349:
450 case RCM_SUBTYPE_9x25_SMB1357:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700451 board->baseband = BASEBAND_MDM;
452 break;
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800453 case RCM_SUBTYPE_9x35:
Sundarajan Srinivasan0e94a1c2013-12-17 10:55:51 -0800454 case RCM_SUBTYPE_9x35_M:
Sundarajan Srinivasan839b5202013-11-12 17:21:07 -0800455 board->baseband = BASEBAND_MDM2;
456 break;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700457 case RCM_SUBTYPE_SMB349:
458 case RCM_SUBTYPE_SMB1357:
Sundarajan Srinivasan01e68f12013-11-01 12:21:52 -0700459 case RCM_SUBTYPE_SMB350:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700460 board->baseband = BASEBAND_APQ;
461 break;
462 default:
463 dprintf(CRITICAL, "RCM platform subtype :%u is not supported\n",
464 platform_subtype);
465 ASSERT(0);
466 };
467}
468
Sundarajan Srinivasan6ade93e2013-11-18 11:07:22 -0800469void set_liquid_baseband(struct board_data *board)
470{
471 uint32_t platform_subtype;
472
473 platform_subtype = board->platform_subtype;
474
475 switch(platform_subtype)
476 {
477 case LIQUID_SUBTYPE_STANDALONE:
478 board->baseband = BASEBAND_APQ;
479 break;
480 case LIQUID_SUBTYPE_9x25:
481 board->baseband = BASEBAND_MDM;
482 break;
483 default:
484 dprintf(CRITICAL, "Liquid platform subtype :%u is not supported\n",platform_subtype);
485 ASSERT(0);
486 }
487}
488
Justin Philipbe9de5c2014-09-17 12:26:49 +0530489static uint8_t splash_override;
Dhaval Patelf9986272013-10-18 19:06:05 -0700490/* Returns 1 if target supports continuous splash screen. */
491int target_cont_splash_screen()
492{
Justin Philipbe9de5c2014-09-17 12:26:49 +0530493 uint8_t splash_screen = 0;
494 if(!splash_override) {
495 switch(board_hardware_id())
496 {
497 case HW_PLATFORM_SURF:
498 case HW_PLATFORM_MTP:
499 case HW_PLATFORM_FLUID:
500 case HW_PLATFORM_LIQUID:
501 dprintf(SPEW, "Target_cont_splash=1\n");
502 splash_screen = 1;
503 break;
504 default:
505 dprintf(SPEW, "Target_cont_splash=0\n");
506 splash_screen = 0;
507 }
Dhaval Patelf9986272013-10-18 19:06:05 -0700508 }
Justin Philipbe9de5c2014-09-17 12:26:49 +0530509 return splash_screen;
510}
511
512void target_force_cont_splash_disable(uint8_t override)
513{
514 splash_override = override;
Dhaval Patelf9986272013-10-18 19:06:05 -0700515}
Ameya Thakurcfca9212013-09-13 23:51:49 -0700516
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700517/* Detect the modem type */
518void target_baseband_detect(struct board_data *board)
519{
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700520 uint32_t platform;
521 uint32_t platform_subtype;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700522 uint32_t platform_hardware;
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700523
524 platform = board->platform;
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700525
Ameya Thakurcfca9212013-09-13 23:51:49 -0700526 platform_hardware = board->platform_hw;
527
528 switch(platform_hardware) {
529 case HW_PLATFORM_SURF:
530 set_cdp_baseband(board);
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700531 break;
Ameya Thakurcfca9212013-09-13 23:51:49 -0700532 case HW_PLATFORM_MTP:
533 set_mtp_baseband(board);
534 break;
535 case HW_PLATFORM_RCM:
536 set_rcm_baseband(board);
537 break;
538 case HW_PLATFORM_LIQUID:
Sundarajan Srinivasan6ade93e2013-11-18 11:07:22 -0800539 set_liquid_baseband(board);
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700540 break;
Eugene Yasman2a462112013-12-09 09:26:37 +0200541 case HW_PLATFORM_SBC:
542 board->baseband = BASEBAND_APQ;
543 break;
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700544 default:
Ameya Thakurcfca9212013-09-13 23:51:49 -0700545 dprintf(CRITICAL, "Platform :%u is not supported\n",
546 platform_hardware);
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700547 ASSERT(0);
Ameya Thakurcfca9212013-09-13 23:51:49 -0700548 };
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700549}
550
551unsigned target_baseband()
552{
553 return board_baseband();
554}
555
556void target_serialno(unsigned char *buf)
557{
558 unsigned int serialno;
559 if (target_is_emmc_boot()) {
560 serialno = mmc_get_psn();
561 snprintf((char *)buf, 13, "%x", serialno);
562 }
563}
564
Pavel Nedeva6c0beb2013-11-15 17:20:27 +0200565int emmc_recovery_init(void)
566{
567 return _emmc_recovery_init();
568}
569
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700570unsigned check_reboot_mode(void)
571{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700572 uint32_t restart_reason = 0;
573 uint32_t restart_reason_addr;
574
575 restart_reason_addr = RESTART_REASON_ADDR;
576
577 /* Read reboot reason and scrub it */
578 restart_reason = readl(restart_reason_addr);
579 writel(0x00, restart_reason_addr);
580
581 return restart_reason;
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700582}
583
584void reboot_device(unsigned reboot_reason)
585{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700586 uint8_t reset_type = 0;
587
588 /* Write the reboot reason */
589 writel(reboot_reason, RESTART_REASON_ADDR);
590
Shashank Mittalc3621fe2014-08-28 15:38:19 -0700591 if(reboot_reason == FASTBOOT_MODE || reboot_reason == RECOVERY_MODE)
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700592 reset_type = PON_PSHOLD_WARM_RESET;
593 else
594 reset_type = PON_PSHOLD_HARD_RESET;
595
596 pm8x41_reset_configure(reset_type);
597
598 /* Drop PS_HOLD for MSM */
599 writel(0x00, MPM2_MPM_PS_HOLD);
600
601 mdelay(5000);
602
603 dprintf(CRITICAL, "Rebooting failed\n");
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700604}
Amol Jadi0a4c9b42013-10-11 14:22:11 -0700605
Sundarajan Srinivasan8a3ecf52014-05-06 11:32:41 -0700606void shutdown_device()
607{
608 dprintf(CRITICAL, "Going down for shutdown.\n");
609
610 /* Configure PMIC for shutdown. */
611 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
612
613 /* Drop PS_HOLD for MSM */
614 writel(0x00, MPM2_MPM_PS_HOLD);
615
616 mdelay(5000);
617
618 dprintf(CRITICAL, "Shutdown failed\n");
619
620 ASSERT(0);
621}
622
Amol Jadi0a4c9b42013-10-11 14:22:11 -0700623/* identify the usb controller to be used for the target */
624const char * target_usb_controller()
625{
626 return "dwc";
627}
628
629/* mux hs phy to route to dwc controller */
630static void phy_mux_configure_with_jdr()
631{
632 uint32_t val;
633
634 val = readl(COPSS_USB_CONTROL_WITH_JDR);
635
636 /* Note: there are no details regarding this bit in hpg or swi. */
637 val |= BIT(8);
638
639 writel(val, COPSS_USB_CONTROL_WITH_JDR);
640}
641
642/* configure hs phy mux if using dwc controller */
643void target_usb_phy_mux_configure(void)
644{
645 if(!strcmp(target_usb_controller(), "dwc"))
646 {
647 phy_mux_configure_with_jdr();
648 }
649}
650
651void target_usb_phy_reset(void)
652{
653 uint32_t val;
654
655 /* SS PHY reset */
656 val = readl(GCC_USB3_PHY_BCR) | BIT(0);
657 writel(val, GCC_USB3_PHY_BCR);
658 udelay(10);
659 writel(val & ~BIT(0), GCC_USB3_PHY_BCR);
660
661 /* HS PHY reset */
662 /* Note: reg/bit details are not mentioned in hpg or swi. */
663 val = readl(COPSS_USB_CONTROL_WITH_JDR) | BIT(11);
664 writel(val, COPSS_USB_CONTROL_WITH_JDR);
665 udelay(10);
666 writel(val & ~BIT(11), COPSS_USB_CONTROL_WITH_JDR);
Channagoud Kadabi70500ea2013-10-29 17:33:44 -0700667
668 /* PHY_COMMON reset */
669 val = readl(GCC_USB30_PHY_COM_BCR) | BIT(0);
670 writel(val, GCC_USB30_PHY_COM_BCR);
671 udelay(10);
672 writel(val & ~BIT(0), GCC_USB30_PHY_COM_BCR);
Amol Jadi0a4c9b42013-10-11 14:22:11 -0700673}
Sundarajan Srinivasan86106c32013-12-19 11:36:07 -0800674
Hanumant Singh75311942014-01-29 13:43:53 -0800675bool target_warm_boot(void)
676{
677 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
678 if (is_cold_boot)
679 return false;
680 else
681 return true;
682}
Sundarajan Srinivasan86106c32013-12-19 11:36:07 -0800683/* Set up params for h/w CE. */
684void target_crypto_init_params()
685{
686 struct crypto_init_params ce_params;
687
688 /* Set up base addresses and instance. */
689 ce_params.crypto_instance = CE2_INSTANCE;
690 ce_params.crypto_base = MSM_CE2_BASE;
691 ce_params.bam_base = MSM_CE2_BAM_BASE;
692
693 /* Set up BAM config. */
694 ce_params.bam_ee = CE_EE;
695 ce_params.pipes.read_pipe = CE_READ_PIPE;
696 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
697 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
698 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
699
700 /* Assign buffer sizes. */
701 ce_params.num_ce = CE_ARRAY_SIZE;
702 ce_params.read_fifo_size = CE_FIFO_SIZE;
703 ce_params.write_fifo_size = CE_FIFO_SIZE;
704
705 /* BAM is initialized by TZ for this platform.
706 * Do not do it again as the initialization address space
707 * is locked.
708 */
709 ce_params.do_bam_init = 0;
710
711 crypto_init_params(&ce_params);
712}
713
714crypto_engine_type board_ce_type(void)
715{
716 return CRYPTO_ENGINE_TYPE_HW;
717}