blob: 22f3b77c822c236a444f89470b0e0c467079246d [file] [log] [blame]
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -08001/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
2 *
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>
31#include <platform/irqs.h>
32#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>
52#include <platform/timer.h>
53#include <stdlib.h>
54#include <ufs.h>
Sundarajan Srinivasand598b122014-03-21 17:33:29 -070055#include <boot_device.h>
Channagoud Kadabi3dcc4ed2014-04-10 14:59:41 -070056#include <qmp_phy.h>
Joonwoo Park8b309972014-06-09 16:58:38 -070057#include <qusb2_phy.h>
Sundarajan Srinivasan19b95c72014-07-24 16:37:04 -070058#include <rpm-smd.h>
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -080059
Channagoud Kadabi27ff9342014-06-16 11:19:29 -070060#define CE_INSTANCE 2
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -070061#define CE_EE 1
62#define CE_FIFO_SIZE 64
63#define CE_READ_PIPE 3
64#define CE_WRITE_PIPE 2
65#define CE_READ_PIPE_LOCK_GRP 0
66#define CE_WRITE_PIPE_LOCK_GRP 0
67#define CE_ARRAY_SIZE 20
68
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -080069#define PMIC_ARB_CHANNEL_NUM 0
70#define PMIC_ARB_OWNER_ID 0
71
72#define FASTBOOT_MODE 0x77665500
73
74#define BOOT_DEVICE_MASK(val) ((val & 0x3E) >>1)
Aparna Mallavarapu965fac92014-08-04 22:45:01 +053075#define PMIC_WLED_SLAVE_ID 3
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -080076
Channagoud Kadabie804d642014-08-20 17:43:57 -070077static void set_sdc_power_ctrl(uint8_t slot);
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -080078static uint32_t mmc_pwrctl_base[] =
79 { MSM_SDC1_BASE, MSM_SDC2_BASE };
80
81static uint32_t mmc_sdhci_base[] =
82 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
83
84static uint32_t mmc_sdc_pwrctl_irq[] =
85 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
86
87struct mmc_device *dev;
88struct ufs_dev ufs_device;
89
90extern void ulpi_write(unsigned val, unsigned reg);
91
92void target_early_init(void)
93{
94#if WITH_DEBUG_UART
95 uart_dm_init(2, 0, BLSP1_UART1_BASE);
96#endif
97}
98
99/* Return 1 if vol_up pressed */
100static int target_volume_up()
101{
102 uint8_t status = 0;
103 struct pm8x41_gpio gpio;
104
105 /* Configure the GPIO */
106 gpio.direction = PM_GPIO_DIR_IN;
107 gpio.function = 0;
108 gpio.pull = PM_GPIO_PULL_UP_30;
109 gpio.vin_sel = 2;
110
111 pm8x41_gpio_config(3, &gpio);
112
113 /* Wait for the pmic gpio config to take effect */
114 thread_sleep(1);
115
116 /* Get status of P_GPIO_5 */
117 pm8x41_gpio_get(3, &status);
118
119 return !status; /* active low */
120}
121
122/* Return 1 if vol_down pressed */
123uint32_t target_volume_down()
124{
125 return pm8x41_resin_status();
126}
127
128static void target_keystatus()
129{
130 keys_init();
131
132 if(target_volume_down())
133 keys_post_event(KEY_VOLUMEDOWN, 1);
134
135 if(target_volume_up())
136 keys_post_event(KEY_VOLUMEUP, 1);
137}
138
139void target_uninit(void)
140{
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700141 if (platform_boot_dev_isemmc())
Channagoud Kadabid6a45ea2014-06-02 21:12:51 -0700142 {
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800143 mmc_put_card_to_sleep(dev);
Channagoud Kadabid6a45ea2014-06-02 21:12:51 -0700144 /* Disable HC mode before jumping to kernel */
145 sdhci_mode_disable(&dev->host);
146 }
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700147
148 if (crypto_initialized())
149 crypto_eng_cleanup();
Sundarajan Srinivasan19b95c72014-07-24 16:37:04 -0700150
151 rpm_smd_uninit();
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800152}
153
154/* Do target specific usb initialization */
155void target_usb_init(void)
156{
157 uint32_t val;
158
Sundarajan Srinivasan0ebf2fc2014-04-23 16:45:18 -0700159 if(board_hardware_id() == HW_PLATFORM_DRAGON)
160 {
161 /* Select the QUSB2 PHY */
162 writel(0x1, USB2_PHY_SEL);
163
Joonwoo Park8b309972014-06-09 16:58:38 -0700164 qusb2_phy_reset();
Sundarajan Srinivasan0ebf2fc2014-04-23 16:45:18 -0700165 }
166
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800167 /* Enable sess_vld */
168 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
169 writel(val, USB_GENCONFIG_2);
170
171 /* Enable external vbus configuration in the LINK */
172 val = readl(USB_USBCMD);
173 val |= SESS_VLD_CTRL;
174 writel(val, USB_USBCMD);
175}
176
177void target_usb_stop(void)
178{
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800179}
180
Channagoud Kadabie804d642014-08-20 17:43:57 -0700181static void set_sdc_power_ctrl(uint8_t slot)
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800182{
Channagoud Kadabie804d642014-08-20 17:43:57 -0700183 uint32_t reg = 0;
Channagoud Kadabi751fe7a2014-09-04 18:52:24 -0700184 uint8_t clk;
185 uint8_t cmd;
186 uint8_t dat;
Channagoud Kadabie804d642014-08-20 17:43:57 -0700187
188 if (slot == 0x1)
Channagoud Kadabi751fe7a2014-09-04 18:52:24 -0700189 {
190 clk = TLMM_CUR_VAL_16MA;
191 cmd = TLMM_CUR_VAL_8MA;
192 dat = TLMM_CUR_VAL_8MA;
Channagoud Kadabie804d642014-08-20 17:43:57 -0700193 reg = SDC1_HDRV_PULL_CTL;
Channagoud Kadabi751fe7a2014-09-04 18:52:24 -0700194 }
Channagoud Kadabie804d642014-08-20 17:43:57 -0700195 else if (slot == 0x2)
Channagoud Kadabi751fe7a2014-09-04 18:52:24 -0700196 {
197 clk = TLMM_CUR_VAL_16MA;
198 cmd = TLMM_CUR_VAL_10MA;
199 dat = TLMM_CUR_VAL_10MA;
Channagoud Kadabie804d642014-08-20 17:43:57 -0700200 reg = SDC2_HDRV_PULL_CTL;
Channagoud Kadabi751fe7a2014-09-04 18:52:24 -0700201 }
202 else
203 {
204 dprintf(CRITICAL, "Unsupported SDC slot passed\n");
205 return;
206 }
Channagoud Kadabie804d642014-08-20 17:43:57 -0700207
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800208 /* Drive strength configs for sdc pins */
209 struct tlmm_cfgs sdc1_hdrv_cfg[] =
210 {
Channagoud Kadabi751fe7a2014-09-04 18:52:24 -0700211 { SDC1_CLK_HDRV_CTL_OFF, clk, TLMM_HDRV_MASK, reg },
212 { SDC1_CMD_HDRV_CTL_OFF, cmd, TLMM_HDRV_MASK, reg },
213 { SDC1_DATA_HDRV_CTL_OFF, dat, TLMM_HDRV_MASK, reg },
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800214 };
215
216 /* Pull configs for sdc pins */
217 struct tlmm_cfgs sdc1_pull_cfg[] =
218 {
Channagoud Kadabie804d642014-08-20 17:43:57 -0700219 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, reg },
220 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, reg },
221 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, reg },
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800222 };
223
Channagoud Kadabi95717152014-06-04 17:59:29 -0700224 struct tlmm_cfgs sdc1_rclk_cfg[] =
225 {
Channagoud Kadabie804d642014-08-20 17:43:57 -0700226 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, reg },
Channagoud Kadabi95717152014-06-04 17:59:29 -0700227 };
228
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800229 /* Set the drive strength & pull control values */
230 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
231 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
Channagoud Kadabi95717152014-06-04 17:59:29 -0700232 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800233}
234
235void target_sdc_init()
236{
Channagoud Kadabia66a6f22014-05-28 17:19:44 -0700237 struct mmc_config_data config = {0};
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800238
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800239 config.bus_width = DATA_BUS_WIDTH_8BIT;
240 config.max_clk_rate = MMC_CLK_192MHZ;
241
242 /* Try slot 1*/
243 config.slot = 1;
244 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
245 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
246 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Channagoud Kadabi6b3a9982014-06-05 12:59:46 -0700247 config.hs400_support = 1;
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800248
Channagoud Kadabie804d642014-08-20 17:43:57 -0700249 /* Set drive strength & pull ctrl values */
250 set_sdc_power_ctrl(config.slot);
251
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800252 if (!(dev = mmc_init(&config)))
253 {
254 /* Try slot 2 */
255 config.slot = 2;
256 config.max_clk_rate = MMC_CLK_200MHZ;
257 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
258 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
259 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
260
Channagoud Kadabie804d642014-08-20 17:43:57 -0700261 /* Set drive strength & pull ctrl values */
262 set_sdc_power_ctrl(config.slot);
263
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800264 if (!(dev = mmc_init(&config)))
265 {
266 dprintf(CRITICAL, "mmc init failed!");
267 ASSERT(0);
268 }
269 }
270}
271
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800272void *target_mmc_device()
273{
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700274 if (platform_boot_dev_isemmc())
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800275 return (void *) dev;
276 else
277 return (void *) &ufs_device;
278}
279
280void target_init(void)
281{
282 dprintf(INFO, "target_init()\n");
283
284 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
285
286 target_keystatus();
287
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700288
289 if (target_use_signed_kernel())
290 target_crypto_init_params();
291
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700292 platform_read_boot_config();
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800293
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700294 if (platform_boot_dev_isemmc())
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800295 {
296 target_sdc_init();
297 }
298 else
299 {
300 ufs_device.base = UFS_BASE;
301 ufs_init(&ufs_device);
302 }
303
304 /* Storage initialization is complete, read the partition table info */
305 if (partition_read_table())
306 {
307 dprintf(CRITICAL, "Error reading the partition table info\n");
308 ASSERT(0);
309 }
Sundarajan Srinivasan19b95c72014-07-24 16:37:04 -0700310
311 rpm_smd_init();
Aparna Mallavarapu965fac92014-08-04 22:45:01 +0530312
313 /* QPNP WLED init for display backlight */
314 pm8x41_wled_config_slave_id(PMIC_WLED_SLAVE_ID);
315 qpnp_wled_init();
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800316}
317
318unsigned board_machtype(void)
319{
320 return LINUX_MACHTYPE_UNKNOWN;
321}
322
323/* Detect the target type */
324void target_detect(struct board_data *board)
325{
326 /* This is filled from board.c */
327}
328
Dhaval Patel019057a2014-08-12 13:52:25 -0700329/* Returns 1 if target supports continuous splash screen. */
330int target_cont_splash_screen()
331{
332 switch(board_hardware_id())
333 {
334 case HW_PLATFORM_SURF:
335 case HW_PLATFORM_MTP:
336 case HW_PLATFORM_FLUID:
337 dprintf(SPEW, "Target_cont_splash=1\n");
338 return 1;
339 default:
340 dprintf(SPEW, "Target_cont_splash=0\n");
341 return 0;
342 }
343}
344
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800345/* Detect the modem type */
346void target_baseband_detect(struct board_data *board)
347{
348 uint32_t platform;
349
350 platform = board->platform;
351
352 switch(platform) {
Channagoud Kadabi44ea30d2014-04-14 13:59:42 -0700353 case MSM8994:
Channagoud Kadabi23c90ab2014-08-28 15:49:19 -0700354 case MSM8992:
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800355 board->baseband = BASEBAND_MSM;
356 break;
Channagoud Kadabi30ef4452014-07-12 13:03:30 -0700357 case APQ8094:
Channagoud Kadabi23c90ab2014-08-28 15:49:19 -0700358 case APQ8092:
Channagoud Kadabi30ef4452014-07-12 13:03:30 -0700359 board->baseband = BASEBAND_APQ;
360 break;
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800361 default:
362 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
363 ASSERT(0);
364 };
365}
366unsigned target_baseband()
367{
368 return board_baseband();
369}
370
371void target_serialno(unsigned char *buf)
372{
373 unsigned int serialno;
374 if (target_is_emmc_boot()) {
375 serialno = mmc_get_psn();
376 snprintf((char *)buf, 13, "%x", serialno);
377 }
378}
379
380unsigned check_reboot_mode(void)
381{
382 uint32_t restart_reason = 0;
383 uint32_t restart_reason_addr;
384
385 restart_reason_addr = RESTART_REASON_ADDR;
386
387 /* Read reboot reason and scrub it */
388 restart_reason = readl(restart_reason_addr);
389 writel(0x00, restart_reason_addr);
390
391 return restart_reason;
392}
393
394void reboot_device(unsigned reboot_reason)
395{
396 uint8_t reset_type = 0;
397
398 /* Write the reboot reason */
399 writel(reboot_reason, RESTART_REASON_ADDR);
400
401 if(reboot_reason == FASTBOOT_MODE)
402 reset_type = PON_PSHOLD_WARM_RESET;
403 else
404 reset_type = PON_PSHOLD_HARD_RESET;
405
406 pm8x41_reset_configure(reset_type);
407
408 /* Drop PS_HOLD for MSM */
409 writel(0x00, MPM2_MPM_PS_HOLD);
410
411 mdelay(5000);
412
413 dprintf(CRITICAL, "Rebooting failed\n");
414}
415
416int emmc_recovery_init(void)
417{
418 return _emmc_recovery_init();
419}
Channagoud Kadabi3dcc4ed2014-04-10 14:59:41 -0700420
421target_usb_iface_t* target_usb30_init()
422{
423 target_usb_iface_t *t_usb_iface;
424
425 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
426 ASSERT(t_usb_iface);
427
428 t_usb_iface->mux_config = target_usb_phy_mux_configure;
429 t_usb_iface->phy_init = usb30_qmp_phy_init;
430 t_usb_iface->phy_reset = usb30_qmp_phy_reset;
431 t_usb_iface->clock_init = clock_usb30_init;
432 t_usb_iface->vbus_override = 1;
433
434 return t_usb_iface;
435}
436
437/* identify the usb controller to be used for the target */
438const char * target_usb_controller()
439{
Tanya Finkel90abab72014-07-30 09:55:23 +0300440 if(board_hardware_id() == HW_PLATFORM_DRAGON)
441 return "ci";
Channagoud Kadabi3dcc4ed2014-04-10 14:59:41 -0700442 return "dwc";
443}
444
445/* mux hs phy to route to dwc controller */
446static void phy_mux_configure_with_tcsr()
447{
448 /* As per the hardware team, set the mux for snps controller */
449 RMWREG32(TCSR_PHSS_USB2_PHY_SEL, 0x0, 0x1, 0x1);
450}
451
452/* configure hs phy mux if using dwc controller */
453void target_usb_phy_mux_configure(void)
454{
455 if(!strcmp(target_usb_controller(), "dwc"))
456 {
457 phy_mux_configure_with_tcsr();
458 }
459}
Channagoud Kadabi3c2be1c2014-06-01 18:59:21 -0700460
461uint32_t target_override_pll()
462{
463 return 1;
464}
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700465
466/* Set up params for h/w CE. */
467void target_crypto_init_params()
468{
469 struct crypto_init_params ce_params;
470
471 /* Set up base addresses and instance. */
472 ce_params.crypto_instance = CE_INSTANCE;
Channagoud Kadabi27ff9342014-06-16 11:19:29 -0700473 ce_params.crypto_base = MSM_CE2_BASE;
474 ce_params.bam_base = MSM_CE2_BAM_BASE;
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700475
476 /* Set up BAM config. */
477 ce_params.bam_ee = CE_EE;
478 ce_params.pipes.read_pipe = CE_READ_PIPE;
479 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
480 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
481 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
482
483 /* Assign buffer sizes. */
484 ce_params.num_ce = CE_ARRAY_SIZE;
485 ce_params.read_fifo_size = CE_FIFO_SIZE;
486 ce_params.write_fifo_size = CE_FIFO_SIZE;
487
488 /* BAM is initialized by TZ for this platform.
489 * Do not do it again as the initialization address space
490 * is locked.
491 */
492 ce_params.do_bam_init = 0;
493
494 crypto_init_params(&ce_params);
495}
496
497crypto_engine_type board_ce_type(void)
498{
499 return CRYPTO_ENGINE_TYPE_HW;
500}
Channagoud Kadabi84f860f2014-07-01 15:46:09 -0700501
502void shutdown_device()
503{
504 dprintf(CRITICAL, "Going down for shutdown.\n");
505
506 /* Configure PMIC for shutdown. */
507 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
508
509 /* Drop PS_HOLD for MSM */
510 writel(0x00, MPM2_MPM_PS_HOLD);
511
512 mdelay(5000);
513
514 dprintf(CRITICAL, "Shutdown failed\n");
515
516 ASSERT(0);
517}
Sundarajan Srinivasancd3bb3c2014-07-23 12:25:44 -0700518
519void target_fastboot_init(void)
520{
521 /* We are entering fastboot mode, so read partition table */
522 mmc_read_partition_table(1);
523}