blob: 7e6a28ea72476e9f2ca3248f8dd71e6559d73fea [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>
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -080057
58#define PMIC_ARB_CHANNEL_NUM 0
59#define PMIC_ARB_OWNER_ID 0
60
61#define FASTBOOT_MODE 0x77665500
62
63#define BOOT_DEVICE_MASK(val) ((val & 0x3E) >>1)
64
65static void set_sdc_power_ctrl(void);
66static uint32_t mmc_pwrctl_base[] =
67 { MSM_SDC1_BASE, MSM_SDC2_BASE };
68
69static uint32_t mmc_sdhci_base[] =
70 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
71
72static uint32_t mmc_sdc_pwrctl_irq[] =
73 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
74
75struct mmc_device *dev;
76struct ufs_dev ufs_device;
77
78extern void ulpi_write(unsigned val, unsigned reg);
79
80void target_early_init(void)
81{
82#if WITH_DEBUG_UART
83 uart_dm_init(2, 0, BLSP1_UART1_BASE);
84#endif
85}
86
87/* Return 1 if vol_up pressed */
88static int target_volume_up()
89{
90 uint8_t status = 0;
91 struct pm8x41_gpio gpio;
92
93 /* Configure the GPIO */
94 gpio.direction = PM_GPIO_DIR_IN;
95 gpio.function = 0;
96 gpio.pull = PM_GPIO_PULL_UP_30;
97 gpio.vin_sel = 2;
98
99 pm8x41_gpio_config(3, &gpio);
100
101 /* Wait for the pmic gpio config to take effect */
102 thread_sleep(1);
103
104 /* Get status of P_GPIO_5 */
105 pm8x41_gpio_get(3, &status);
106
107 return !status; /* active low */
108}
109
110/* Return 1 if vol_down pressed */
111uint32_t target_volume_down()
112{
113 return pm8x41_resin_status();
114}
115
116static void target_keystatus()
117{
118 keys_init();
119
120 if(target_volume_down())
121 keys_post_event(KEY_VOLUMEDOWN, 1);
122
123 if(target_volume_up())
124 keys_post_event(KEY_VOLUMEUP, 1);
125}
126
127void target_uninit(void)
128{
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700129 if (platform_boot_dev_isemmc())
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800130 mmc_put_card_to_sleep(dev);
131}
132
133/* Do target specific usb initialization */
134void target_usb_init(void)
135{
136 uint32_t val;
137
Sundarajan Srinivasan0ebf2fc2014-04-23 16:45:18 -0700138 if(board_hardware_id() == HW_PLATFORM_DRAGON)
139 {
140 /* Select the QUSB2 PHY */
141 writel(0x1, USB2_PHY_SEL);
142
143 /* Block Reset */
144 val = readl(GCC_QUSB2_PHY_BCR) | BIT(0);
145 writel(val, GCC_QUSB2_PHY_BCR);
146 udelay(10);
147 writel(val & ~BIT(0), GCC_QUSB2_PHY_BCR);
148
149 /* Deassert POWERDOWN by clearing bit 0 to enable the PHY */
150 val = readl(QUSB2PHY_PORT_POWERDOWN);
151 writel(val & ~BIT(0), QUSB2PHY_PORT_POWERDOWN);
152 udelay(10);
153
154 /* set CLAMP_N_EN and FREEZIO_N */
155 writel(0x22, QUSB2PHY_PORT_POWERDOWN);
156 }
157
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800158 /* Select and enable external configuration with USB PHY */
159 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
160
161 /* Enable sess_vld */
162 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
163 writel(val, USB_GENCONFIG_2);
164
165 /* Enable external vbus configuration in the LINK */
166 val = readl(USB_USBCMD);
167 val |= SESS_VLD_CTRL;
168 writel(val, USB_USBCMD);
169}
170
171void target_usb_stop(void)
172{
173 /* Disable VBUS mimicing in the controller. */
174 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
175}
176
177static void set_sdc_power_ctrl()
178{
179 /* Drive strength configs for sdc pins */
180 struct tlmm_cfgs sdc1_hdrv_cfg[] =
181 {
182 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
183 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
184 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
185 };
186
187 /* Pull configs for sdc pins */
188 struct tlmm_cfgs sdc1_pull_cfg[] =
189 {
190 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
191 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
192 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
193 };
194
195 /* Set the drive strength & pull control values */
196 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
197 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
198}
199
200void target_sdc_init()
201{
Channagoud Kadabia66a6f22014-05-28 17:19:44 -0700202 struct mmc_config_data config = {0};
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800203
204 /* Set drive strength & pull ctrl values */
205 set_sdc_power_ctrl();
206
207 config.bus_width = DATA_BUS_WIDTH_8BIT;
208 config.max_clk_rate = MMC_CLK_192MHZ;
209
210 /* Try slot 1*/
211 config.slot = 1;
212 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
213 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
214 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
215
216 if (!(dev = mmc_init(&config)))
217 {
218 /* Try slot 2 */
219 config.slot = 2;
220 config.max_clk_rate = MMC_CLK_200MHZ;
221 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
222 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
223 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
224
225 if (!(dev = mmc_init(&config)))
226 {
227 dprintf(CRITICAL, "mmc init failed!");
228 ASSERT(0);
229 }
230 }
231}
232
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800233void *target_mmc_device()
234{
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700235 if (platform_boot_dev_isemmc())
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800236 return (void *) dev;
237 else
238 return (void *) &ufs_device;
239}
240
241void target_init(void)
242{
243 dprintf(INFO, "target_init()\n");
244
245 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
246
247 target_keystatus();
248
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700249 platform_read_boot_config();
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800250
Sundarajan Srinivasand598b122014-03-21 17:33:29 -0700251 if (platform_boot_dev_isemmc())
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800252 {
253 target_sdc_init();
254 }
255 else
256 {
257 ufs_device.base = UFS_BASE;
258 ufs_init(&ufs_device);
259 }
260
261 /* Storage initialization is complete, read the partition table info */
262 if (partition_read_table())
263 {
264 dprintf(CRITICAL, "Error reading the partition table info\n");
265 ASSERT(0);
266 }
267}
268
269unsigned board_machtype(void)
270{
271 return LINUX_MACHTYPE_UNKNOWN;
272}
273
274/* Detect the target type */
275void target_detect(struct board_data *board)
276{
277 /* This is filled from board.c */
278}
279
280/* Detect the modem type */
281void target_baseband_detect(struct board_data *board)
282{
283 uint32_t platform;
284
285 platform = board->platform;
286
287 switch(platform) {
Channagoud Kadabi44ea30d2014-04-14 13:59:42 -0700288 case MSM8994:
Channagoud Kadabi0f3a4f72014-02-06 13:22:07 -0800289 board->baseband = BASEBAND_MSM;
290 break;
291 default:
292 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
293 ASSERT(0);
294 };
295}
296unsigned target_baseband()
297{
298 return board_baseband();
299}
300
301void target_serialno(unsigned char *buf)
302{
303 unsigned int serialno;
304 if (target_is_emmc_boot()) {
305 serialno = mmc_get_psn();
306 snprintf((char *)buf, 13, "%x", serialno);
307 }
308}
309
310unsigned check_reboot_mode(void)
311{
312 uint32_t restart_reason = 0;
313 uint32_t restart_reason_addr;
314
315 restart_reason_addr = RESTART_REASON_ADDR;
316
317 /* Read reboot reason and scrub it */
318 restart_reason = readl(restart_reason_addr);
319 writel(0x00, restart_reason_addr);
320
321 return restart_reason;
322}
323
324void reboot_device(unsigned reboot_reason)
325{
326 uint8_t reset_type = 0;
327
328 /* Write the reboot reason */
329 writel(reboot_reason, RESTART_REASON_ADDR);
330
331 if(reboot_reason == FASTBOOT_MODE)
332 reset_type = PON_PSHOLD_WARM_RESET;
333 else
334 reset_type = PON_PSHOLD_HARD_RESET;
335
336 pm8x41_reset_configure(reset_type);
337
338 /* Drop PS_HOLD for MSM */
339 writel(0x00, MPM2_MPM_PS_HOLD);
340
341 mdelay(5000);
342
343 dprintf(CRITICAL, "Rebooting failed\n");
344}
345
346int emmc_recovery_init(void)
347{
348 return _emmc_recovery_init();
349}
Channagoud Kadabi3dcc4ed2014-04-10 14:59:41 -0700350
351target_usb_iface_t* target_usb30_init()
352{
353 target_usb_iface_t *t_usb_iface;
354
355 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
356 ASSERT(t_usb_iface);
357
358 t_usb_iface->mux_config = target_usb_phy_mux_configure;
359 t_usb_iface->phy_init = usb30_qmp_phy_init;
360 t_usb_iface->phy_reset = usb30_qmp_phy_reset;
361 t_usb_iface->clock_init = clock_usb30_init;
362 t_usb_iface->vbus_override = 1;
363
364 return t_usb_iface;
365}
366
367/* identify the usb controller to be used for the target */
368const char * target_usb_controller()
369{
370 return "dwc";
371}
372
373/* mux hs phy to route to dwc controller */
374static void phy_mux_configure_with_tcsr()
375{
376 /* As per the hardware team, set the mux for snps controller */
377 RMWREG32(TCSR_PHSS_USB2_PHY_SEL, 0x0, 0x1, 0x1);
378}
379
380/* configure hs phy mux if using dwc controller */
381void target_usb_phy_mux_configure(void)
382{
383 if(!strcmp(target_usb_controller(), "dwc"))
384 {
385 phy_mux_configure_with_tcsr();
386 }
387}
Channagoud Kadabi3c2be1c2014-06-01 18:59:21 -0700388
389uint32_t target_override_pll()
390{
391 return 1;
392}