blob: febd022980823923dddc777e99012d9bc1e79681 [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>
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -080058
Channagoud Kadabi27ff9342014-06-16 11:19:29 -070059#define CE_INSTANCE 2
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -070060#define CE_EE 1
61#define CE_FIFO_SIZE 64
62#define CE_READ_PIPE 3
63#define CE_WRITE_PIPE 2
64#define CE_READ_PIPE_LOCK_GRP 0
65#define CE_WRITE_PIPE_LOCK_GRP 0
66#define CE_ARRAY_SIZE 20
67
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -080068#define PMIC_ARB_CHANNEL_NUM 0
69#define PMIC_ARB_OWNER_ID 0
70
71#define FASTBOOT_MODE 0x77665500
72
73#define BOOT_DEVICE_MASK(val) ((val & 0x3E) >>1)
74
75static void set_sdc_power_ctrl(void);
76static uint32_t mmc_pwrctl_base[] =
77 { MSM_SDC1_BASE, MSM_SDC2_BASE };
78
79static uint32_t mmc_sdhci_base[] =
80 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
81
82static uint32_t mmc_sdc_pwrctl_irq[] =
83 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
84
85struct mmc_device *dev;
86struct ufs_dev ufs_device;
87
88extern void ulpi_write(unsigned val, unsigned reg);
89
90void target_early_init(void)
91{
92#if WITH_DEBUG_UART
93 uart_dm_init(2, 0, BLSP1_UART1_BASE);
94#endif
95}
96
97/* Return 1 if vol_up pressed */
98static int target_volume_up()
99{
100 uint8_t status = 0;
101 struct pm8x41_gpio gpio;
102
103 /* Configure the GPIO */
104 gpio.direction = PM_GPIO_DIR_IN;
105 gpio.function = 0;
106 gpio.pull = PM_GPIO_PULL_UP_30;
107 gpio.vin_sel = 2;
108
109 pm8x41_gpio_config(3, &gpio);
110
111 /* Wait for the pmic gpio config to take effect */
112 thread_sleep(1);
113
114 /* Get status of P_GPIO_5 */
115 pm8x41_gpio_get(3, &status);
116
117 return !status; /* active low */
118}
119
120/* Return 1 if vol_down pressed */
121uint32_t target_volume_down()
122{
123 return pm8x41_resin_status();
124}
125
126static void target_keystatus()
127{
128 keys_init();
129
130 if(target_volume_down())
131 keys_post_event(KEY_VOLUMEDOWN, 1);
132
133 if(target_volume_up())
134 keys_post_event(KEY_VOLUMEUP, 1);
135}
136
137void target_uninit(void)
138{
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700139 if (platform_boot_dev_isemmc())
Channagoud Kadabid6a45ea2014-06-02 21:12:51 -0700140 {
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800141 mmc_put_card_to_sleep(dev);
Channagoud Kadabid6a45ea2014-06-02 21:12:51 -0700142 /* Disable HC mode before jumping to kernel */
143 sdhci_mode_disable(&dev->host);
144 }
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700145
146 if (crypto_initialized())
147 crypto_eng_cleanup();
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800148}
149
150/* Do target specific usb initialization */
151void target_usb_init(void)
152{
153 uint32_t val;
154
Sundarajan Srinivasan0ebf2fc2014-04-23 16:45:18 -0700155 if(board_hardware_id() == HW_PLATFORM_DRAGON)
156 {
157 /* Select the QUSB2 PHY */
158 writel(0x1, USB2_PHY_SEL);
159
Joonwoo Park8b309972014-06-09 16:58:38 -0700160 qusb2_phy_reset();
Sundarajan Srinivasan0ebf2fc2014-04-23 16:45:18 -0700161 }
162
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800163 /* Select and enable external configuration with USB PHY */
164 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
165
166 /* Enable sess_vld */
167 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
168 writel(val, USB_GENCONFIG_2);
169
170 /* Enable external vbus configuration in the LINK */
171 val = readl(USB_USBCMD);
172 val |= SESS_VLD_CTRL;
173 writel(val, USB_USBCMD);
174}
175
176void target_usb_stop(void)
177{
178 /* Disable VBUS mimicing in the controller. */
179 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
180}
181
182static void set_sdc_power_ctrl()
183{
184 /* Drive strength configs for sdc pins */
185 struct tlmm_cfgs sdc1_hdrv_cfg[] =
186 {
Channagoud Kadabi95717152014-06-04 17:59:29 -0700187 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800188 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
189 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
190 };
191
192 /* Pull configs for sdc pins */
193 struct tlmm_cfgs sdc1_pull_cfg[] =
194 {
195 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
196 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
197 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
198 };
199
Channagoud Kadabi95717152014-06-04 17:59:29 -0700200 struct tlmm_cfgs sdc1_rclk_cfg[] =
201 {
202 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK },
203 };
204
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800205 /* Set the drive strength & pull control values */
206 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
207 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
Channagoud Kadabi95717152014-06-04 17:59:29 -0700208 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800209}
210
211void target_sdc_init()
212{
Channagoud Kadabia66a6f22014-05-28 17:19:44 -0700213 struct mmc_config_data config = {0};
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800214
215 /* Set drive strength & pull ctrl values */
216 set_sdc_power_ctrl();
217
218 config.bus_width = DATA_BUS_WIDTH_8BIT;
219 config.max_clk_rate = MMC_CLK_192MHZ;
220
221 /* Try slot 1*/
222 config.slot = 1;
223 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
224 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
225 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Channagoud Kadabi6b3a9982014-06-05 12:59:46 -0700226 config.hs400_support = 1;
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800227
228 if (!(dev = mmc_init(&config)))
229 {
230 /* Try slot 2 */
231 config.slot = 2;
232 config.max_clk_rate = MMC_CLK_200MHZ;
233 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
234 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
235 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
236
237 if (!(dev = mmc_init(&config)))
238 {
239 dprintf(CRITICAL, "mmc init failed!");
240 ASSERT(0);
241 }
242 }
243}
244
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800245void *target_mmc_device()
246{
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700247 if (platform_boot_dev_isemmc())
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800248 return (void *) dev;
249 else
250 return (void *) &ufs_device;
251}
252
253void target_init(void)
254{
255 dprintf(INFO, "target_init()\n");
256
257 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
258
259 target_keystatus();
260
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700261
262 if (target_use_signed_kernel())
263 target_crypto_init_params();
264
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700265 platform_read_boot_config();
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800266
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700267 if (platform_boot_dev_isemmc())
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800268 {
269 target_sdc_init();
270 }
271 else
272 {
273 ufs_device.base = UFS_BASE;
274 ufs_init(&ufs_device);
275 }
276
277 /* Storage initialization is complete, read the partition table info */
278 if (partition_read_table())
279 {
280 dprintf(CRITICAL, "Error reading the partition table info\n");
281 ASSERT(0);
282 }
283}
284
285unsigned board_machtype(void)
286{
287 return LINUX_MACHTYPE_UNKNOWN;
288}
289
290/* Detect the target type */
291void target_detect(struct board_data *board)
292{
293 /* This is filled from board.c */
294}
295
296/* Detect the modem type */
297void target_baseband_detect(struct board_data *board)
298{
299 uint32_t platform;
300
301 platform = board->platform;
302
303 switch(platform) {
Channagoud Kadabi44ea30d2014-04-14 13:59:42 -0700304 case MSM8994:
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800305 board->baseband = BASEBAND_MSM;
306 break;
307 default:
308 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
309 ASSERT(0);
310 };
311}
312unsigned target_baseband()
313{
314 return board_baseband();
315}
316
317void target_serialno(unsigned char *buf)
318{
319 unsigned int serialno;
320 if (target_is_emmc_boot()) {
321 serialno = mmc_get_psn();
322 snprintf((char *)buf, 13, "%x", serialno);
323 }
324}
325
326unsigned check_reboot_mode(void)
327{
328 uint32_t restart_reason = 0;
329 uint32_t restart_reason_addr;
330
331 restart_reason_addr = RESTART_REASON_ADDR;
332
333 /* Read reboot reason and scrub it */
334 restart_reason = readl(restart_reason_addr);
335 writel(0x00, restart_reason_addr);
336
337 return restart_reason;
338}
339
340void reboot_device(unsigned reboot_reason)
341{
342 uint8_t reset_type = 0;
343
344 /* Write the reboot reason */
345 writel(reboot_reason, RESTART_REASON_ADDR);
346
347 if(reboot_reason == FASTBOOT_MODE)
348 reset_type = PON_PSHOLD_WARM_RESET;
349 else
350 reset_type = PON_PSHOLD_HARD_RESET;
351
352 pm8x41_reset_configure(reset_type);
353
354 /* Drop PS_HOLD for MSM */
355 writel(0x00, MPM2_MPM_PS_HOLD);
356
357 mdelay(5000);
358
359 dprintf(CRITICAL, "Rebooting failed\n");
360}
361
362int emmc_recovery_init(void)
363{
364 return _emmc_recovery_init();
365}
Channagoud Kadabi3dcc4ed2014-04-10 14:59:41 -0700366
367target_usb_iface_t* target_usb30_init()
368{
369 target_usb_iface_t *t_usb_iface;
370
371 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
372 ASSERT(t_usb_iface);
373
374 t_usb_iface->mux_config = target_usb_phy_mux_configure;
375 t_usb_iface->phy_init = usb30_qmp_phy_init;
376 t_usb_iface->phy_reset = usb30_qmp_phy_reset;
377 t_usb_iface->clock_init = clock_usb30_init;
378 t_usb_iface->vbus_override = 1;
379
380 return t_usb_iface;
381}
382
383/* identify the usb controller to be used for the target */
384const char * target_usb_controller()
385{
386 return "dwc";
387}
388
389/* mux hs phy to route to dwc controller */
390static void phy_mux_configure_with_tcsr()
391{
392 /* As per the hardware team, set the mux for snps controller */
393 RMWREG32(TCSR_PHSS_USB2_PHY_SEL, 0x0, 0x1, 0x1);
394}
395
396/* configure hs phy mux if using dwc controller */
397void target_usb_phy_mux_configure(void)
398{
399 if(!strcmp(target_usb_controller(), "dwc"))
400 {
401 phy_mux_configure_with_tcsr();
402 }
403}
Channagoud Kadabi3c2be1c2014-06-01 18:59:21 -0700404
405uint32_t target_override_pll()
406{
407 return 1;
408}
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700409
410/* Set up params for h/w CE. */
411void target_crypto_init_params()
412{
413 struct crypto_init_params ce_params;
414
415 /* Set up base addresses and instance. */
416 ce_params.crypto_instance = CE_INSTANCE;
Channagoud Kadabi27ff9342014-06-16 11:19:29 -0700417 ce_params.crypto_base = MSM_CE2_BASE;
418 ce_params.bam_base = MSM_CE2_BAM_BASE;
Channagoud Kadabi4b93fd32014-06-04 17:28:03 -0700419
420 /* Set up BAM config. */
421 ce_params.bam_ee = CE_EE;
422 ce_params.pipes.read_pipe = CE_READ_PIPE;
423 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
424 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
425 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
426
427 /* Assign buffer sizes. */
428 ce_params.num_ce = CE_ARRAY_SIZE;
429 ce_params.read_fifo_size = CE_FIFO_SIZE;
430 ce_params.write_fifo_size = CE_FIFO_SIZE;
431
432 /* BAM is initialized by TZ for this platform.
433 * Do not do it again as the initialization address space
434 * is locked.
435 */
436 ce_params.do_bam_init = 0;
437
438 crypto_init_params(&ce_params);
439}
440
441crypto_engine_type board_ce_type(void)
442{
443 return CRYPTO_ENGINE_TYPE_HW;
444}