blob: 7ac1ddc1a1f511c0b353ea3fd34124a6a0ff36bd [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)
75
76static void set_sdc_power_ctrl(void);
77static uint32_t mmc_pwrctl_base[] =
78 { MSM_SDC1_BASE, MSM_SDC2_BASE };
79
80static uint32_t mmc_sdhci_base[] =
81 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
82
83static uint32_t mmc_sdc_pwrctl_irq[] =
84 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
85
86struct mmc_device *dev;
87struct ufs_dev ufs_device;
88
89extern void ulpi_write(unsigned val, unsigned reg);
90
91void target_early_init(void)
92{
93#if WITH_DEBUG_UART
94 uart_dm_init(2, 0, BLSP1_UART1_BASE);
95#endif
96}
97
98/* Return 1 if vol_up pressed */
99static int target_volume_up()
100{
101 uint8_t status = 0;
102 struct pm8x41_gpio gpio;
103
104 /* Configure the GPIO */
105 gpio.direction = PM_GPIO_DIR_IN;
106 gpio.function = 0;
107 gpio.pull = PM_GPIO_PULL_UP_30;
108 gpio.vin_sel = 2;
109
110 pm8x41_gpio_config(3, &gpio);
111
112 /* Wait for the pmic gpio config to take effect */
113 thread_sleep(1);
114
115 /* Get status of P_GPIO_5 */
116 pm8x41_gpio_get(3, &status);
117
118 return !status; /* active low */
119}
120
121/* Return 1 if vol_down pressed */
122uint32_t target_volume_down()
123{
124 return pm8x41_resin_status();
125}
126
127static void target_keystatus()
128{
129 keys_init();
130
131 if(target_volume_down())
132 keys_post_event(KEY_VOLUMEDOWN, 1);
133
134 if(target_volume_up())
135 keys_post_event(KEY_VOLUMEUP, 1);
136}
137
138void target_uninit(void)
139{
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700140 if (platform_boot_dev_isemmc())
Channagoud Kadabid6a45ea2014-06-02 21:12:51 -0700141 {
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800142 mmc_put_card_to_sleep(dev);
Channagoud Kadabid6a45ea2014-06-02 21:12:51 -0700143 /* Disable HC mode before jumping to kernel */
144 sdhci_mode_disable(&dev->host);
145 }
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700146
147 if (crypto_initialized())
148 crypto_eng_cleanup();
Sundarajan Srinivasan19b95c72014-07-24 16:37:04 -0700149
150 rpm_smd_uninit();
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800151}
152
153/* Do target specific usb initialization */
154void target_usb_init(void)
155{
156 uint32_t val;
157
Sundarajan Srinivasan0ebf2fc2014-04-23 16:45:18 -0700158 if(board_hardware_id() == HW_PLATFORM_DRAGON)
159 {
160 /* Select the QUSB2 PHY */
161 writel(0x1, USB2_PHY_SEL);
162
Joonwoo Park8b309972014-06-09 16:58:38 -0700163 qusb2_phy_reset();
Sundarajan Srinivasan0ebf2fc2014-04-23 16:45:18 -0700164 }
165
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800166 /* Select and enable external configuration with USB PHY */
167 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
168
169 /* Enable sess_vld */
170 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
171 writel(val, USB_GENCONFIG_2);
172
173 /* Enable external vbus configuration in the LINK */
174 val = readl(USB_USBCMD);
175 val |= SESS_VLD_CTRL;
176 writel(val, USB_USBCMD);
177}
178
179void target_usb_stop(void)
180{
181 /* Disable VBUS mimicing in the controller. */
182 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
183}
184
185static void set_sdc_power_ctrl()
186{
187 /* Drive strength configs for sdc pins */
188 struct tlmm_cfgs sdc1_hdrv_cfg[] =
189 {
Channagoud Kadabi95717152014-06-04 17:59:29 -0700190 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800191 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
192 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
193 };
194
195 /* Pull configs for sdc pins */
196 struct tlmm_cfgs sdc1_pull_cfg[] =
197 {
198 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
199 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
200 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
201 };
202
Channagoud Kadabi95717152014-06-04 17:59:29 -0700203 struct tlmm_cfgs sdc1_rclk_cfg[] =
204 {
205 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK },
206 };
207
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800208 /* Set the drive strength & pull control values */
209 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
210 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
Channagoud Kadabi95717152014-06-04 17:59:29 -0700211 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800212}
213
214void target_sdc_init()
215{
Channagoud Kadabia66a6f22014-05-28 17:19:44 -0700216 struct mmc_config_data config = {0};
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800217
218 /* Set drive strength & pull ctrl values */
219 set_sdc_power_ctrl();
220
221 config.bus_width = DATA_BUS_WIDTH_8BIT;
222 config.max_clk_rate = MMC_CLK_192MHZ;
223
224 /* Try slot 1*/
225 config.slot = 1;
226 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
227 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
228 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Channagoud Kadabi6b3a9982014-06-05 12:59:46 -0700229 config.hs400_support = 1;
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800230
231 if (!(dev = mmc_init(&config)))
232 {
233 /* Try slot 2 */
234 config.slot = 2;
235 config.max_clk_rate = MMC_CLK_200MHZ;
236 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
237 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
238 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
239
240 if (!(dev = mmc_init(&config)))
241 {
242 dprintf(CRITICAL, "mmc init failed!");
243 ASSERT(0);
244 }
245 }
246}
247
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800248void *target_mmc_device()
249{
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700250 if (platform_boot_dev_isemmc())
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800251 return (void *) dev;
252 else
253 return (void *) &ufs_device;
254}
255
256void target_init(void)
257{
258 dprintf(INFO, "target_init()\n");
259
260 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
261
262 target_keystatus();
263
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700264
265 if (target_use_signed_kernel())
266 target_crypto_init_params();
267
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700268 platform_read_boot_config();
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800269
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700270 if (platform_boot_dev_isemmc())
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800271 {
272 target_sdc_init();
273 }
274 else
275 {
276 ufs_device.base = UFS_BASE;
277 ufs_init(&ufs_device);
278 }
279
280 /* Storage initialization is complete, read the partition table info */
281 if (partition_read_table())
282 {
283 dprintf(CRITICAL, "Error reading the partition table info\n");
284 ASSERT(0);
285 }
Sundarajan Srinivasan19b95c72014-07-24 16:37:04 -0700286
287 rpm_smd_init();
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800288}
289
290unsigned board_machtype(void)
291{
292 return LINUX_MACHTYPE_UNKNOWN;
293}
294
295/* Detect the target type */
296void target_detect(struct board_data *board)
297{
298 /* This is filled from board.c */
299}
300
301/* Detect the modem type */
302void target_baseband_detect(struct board_data *board)
303{
304 uint32_t platform;
305
306 platform = board->platform;
307
308 switch(platform) {
Channagoud Kadabi44ea30d2014-04-14 13:59:42 -0700309 case MSM8994:
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800310 board->baseband = BASEBAND_MSM;
311 break;
Channagoud Kadabi30ef4452014-07-12 13:03:30 -0700312 case APQ8094:
313 board->baseband = BASEBAND_APQ;
314 break;
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800315 default:
316 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
317 ASSERT(0);
318 };
319}
320unsigned target_baseband()
321{
322 return board_baseband();
323}
324
325void target_serialno(unsigned char *buf)
326{
327 unsigned int serialno;
328 if (target_is_emmc_boot()) {
329 serialno = mmc_get_psn();
330 snprintf((char *)buf, 13, "%x", serialno);
331 }
332}
333
334unsigned check_reboot_mode(void)
335{
336 uint32_t restart_reason = 0;
337 uint32_t restart_reason_addr;
338
339 restart_reason_addr = RESTART_REASON_ADDR;
340
341 /* Read reboot reason and scrub it */
342 restart_reason = readl(restart_reason_addr);
343 writel(0x00, restart_reason_addr);
344
345 return restart_reason;
346}
347
348void reboot_device(unsigned reboot_reason)
349{
350 uint8_t reset_type = 0;
351
352 /* Write the reboot reason */
353 writel(reboot_reason, RESTART_REASON_ADDR);
354
355 if(reboot_reason == FASTBOOT_MODE)
356 reset_type = PON_PSHOLD_WARM_RESET;
357 else
358 reset_type = PON_PSHOLD_HARD_RESET;
359
360 pm8x41_reset_configure(reset_type);
361
362 /* Drop PS_HOLD for MSM */
363 writel(0x00, MPM2_MPM_PS_HOLD);
364
365 mdelay(5000);
366
367 dprintf(CRITICAL, "Rebooting failed\n");
368}
369
370int emmc_recovery_init(void)
371{
372 return _emmc_recovery_init();
373}
Channagoud Kadabi3dcc4ed2014-04-10 14:59:41 -0700374
375target_usb_iface_t* target_usb30_init()
376{
377 target_usb_iface_t *t_usb_iface;
378
379 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
380 ASSERT(t_usb_iface);
381
382 t_usb_iface->mux_config = target_usb_phy_mux_configure;
383 t_usb_iface->phy_init = usb30_qmp_phy_init;
384 t_usb_iface->phy_reset = usb30_qmp_phy_reset;
385 t_usb_iface->clock_init = clock_usb30_init;
386 t_usb_iface->vbus_override = 1;
387
388 return t_usb_iface;
389}
390
391/* identify the usb controller to be used for the target */
392const char * target_usb_controller()
393{
394 return "dwc";
395}
396
397/* mux hs phy to route to dwc controller */
398static void phy_mux_configure_with_tcsr()
399{
400 /* As per the hardware team, set the mux for snps controller */
401 RMWREG32(TCSR_PHSS_USB2_PHY_SEL, 0x0, 0x1, 0x1);
402}
403
404/* configure hs phy mux if using dwc controller */
405void target_usb_phy_mux_configure(void)
406{
407 if(!strcmp(target_usb_controller(), "dwc"))
408 {
409 phy_mux_configure_with_tcsr();
410 }
411}
Channagoud Kadabi3c2be1c2014-06-01 18:59:21 -0700412
413uint32_t target_override_pll()
414{
415 return 1;
416}
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700417
418/* Set up params for h/w CE. */
419void target_crypto_init_params()
420{
421 struct crypto_init_params ce_params;
422
423 /* Set up base addresses and instance. */
424 ce_params.crypto_instance = CE_INSTANCE;
Channagoud Kadabi27ff9342014-06-16 11:19:29 -0700425 ce_params.crypto_base = MSM_CE2_BASE;
426 ce_params.bam_base = MSM_CE2_BAM_BASE;
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700427
428 /* Set up BAM config. */
429 ce_params.bam_ee = CE_EE;
430 ce_params.pipes.read_pipe = CE_READ_PIPE;
431 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
432 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
433 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
434
435 /* Assign buffer sizes. */
436 ce_params.num_ce = CE_ARRAY_SIZE;
437 ce_params.read_fifo_size = CE_FIFO_SIZE;
438 ce_params.write_fifo_size = CE_FIFO_SIZE;
439
440 /* BAM is initialized by TZ for this platform.
441 * Do not do it again as the initialization address space
442 * is locked.
443 */
444 ce_params.do_bam_init = 0;
445
446 crypto_init_params(&ce_params);
447}
448
449crypto_engine_type board_ce_type(void)
450{
451 return CRYPTO_ENGINE_TYPE_HW;
452}
Channagoud Kadabi84f860f2014-07-01 15:46:09 -0700453
454void shutdown_device()
455{
456 dprintf(CRITICAL, "Going down for shutdown.\n");
457
458 /* Configure PMIC for shutdown. */
459 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
460
461 /* Drop PS_HOLD for MSM */
462 writel(0x00, MPM2_MPM_PS_HOLD);
463
464 mdelay(5000);
465
466 dprintf(CRITICAL, "Shutdown failed\n");
467
468 ASSERT(0);
469}
Sundarajan Srinivasancd3bb3c2014-07-23 12:25:44 -0700470
471void target_fastboot_init(void)
472{
473 /* We are entering fastboot mode, so read partition table */
474 mmc_read_partition_table(1);
475}