blob: 5515bb5306ff039b1078195dd8edcb37cbf69a47 [file] [log] [blame]
Deepa Dinamani0e5038f2013-05-16 15:02:16 -07001/* Copyright (c) 2013, 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>
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>
54
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -070055#define PMIC_ARB_CHANNEL_NUM 0
56#define PMIC_ARB_OWNER_ID 0
57
58#define FASTBOOT_MODE 0x77665500
59
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -070060static void set_sdc_power_ctrl(void);
61
62static uint32_t mmc_pwrctl_base[] =
63 { MSM_SDC1_BASE, MSM_SDC2_BASE };
64
65static uint32_t mmc_sdhci_base[] =
66 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
67
68static uint32_t mmc_sdc_pwrctl_irq[] =
69 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
70
71struct mmc_device *dev;
Deepa Dinamani0e5038f2013-05-16 15:02:16 -070072
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -070073extern void ulpi_write(unsigned val, unsigned reg);
74
Deepa Dinamani0e5038f2013-05-16 15:02:16 -070075void target_early_init(void)
76{
77#if WITH_DEBUG_UART
Sundarajan Srinivasan4a204702013-08-12 18:10:17 -070078 uart_dm_init(2, 0, BLSP1_UART1_BASE);
Deepa Dinamani0e5038f2013-05-16 15:02:16 -070079#endif
80}
81
82/* Return 1 if vol_up pressed */
83static int target_volume_up()
84{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -070085 uint8_t status = 0;
86 struct pm8x41_gpio gpio;
87
88 /* Configure the GPIO */
89 gpio.direction = PM_GPIO_DIR_IN;
90 gpio.function = 0;
91 gpio.pull = PM_GPIO_PULL_UP_30;
92 gpio.vin_sel = 2;
93
94 pm8x41_gpio_config(2, &gpio);
95
96 /* Get status of P_GPIO_2 */
97 pm8x41_gpio_get(2, &status);
98
99 return !status; /* active low */
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700100}
101
102/* Return 1 if vol_down pressed */
103uint32_t target_volume_down()
104{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700105 return pm8x41_resin_status();
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700106}
107
108static void target_keystatus()
109{
110 keys_init();
111
112 if(target_volume_down())
113 keys_post_event(KEY_VOLUMEDOWN, 1);
114
115 if(target_volume_up())
116 keys_post_event(KEY_VOLUMEUP, 1);
117}
118
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700119/* Do target specific usb initialization */
120void target_usb_init(void)
121{
122 uint32_t val;
123
124 /* Select and enable external configuration with USB PHY */
125 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
126
127 /* Enable sess_vld */
128 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
129 writel(val, USB_GENCONFIG_2);
130
131 /* Enable external vbus configuration in the LINK */
132 val = readl(USB_USBCMD);
133 val |= SESS_VLD_CTRL;
134 writel(val, USB_USBCMD);
135}
136
137void target_usb_stop(void)
138{
139 /* Disable VBUS mimicing in the controller. */
140 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
141}
142
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700143static void set_sdc_power_ctrl()
144{
145 /* Drive strength configs for sdc pins */
146 struct tlmm_cfgs sdc1_hdrv_cfg[] =
147 {
148 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
149 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
150 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
151 };
152
153 /* Pull configs for sdc pins */
154 struct tlmm_cfgs sdc1_pull_cfg[] =
155 {
156 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
157 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
158 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
159 };
160
161 /* Set the drive strength & pull control values */
162 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
163 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
164}
165
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700166void target_sdc_init()
167{
168 struct mmc_config_data config;
169
170 /* Set drive strength & pull ctrl values */
171 set_sdc_power_ctrl();
172
173 config.bus_width = DATA_BUS_WIDTH_8BIT;
174 config.max_clk_rate = MMC_CLK_200MHZ;
175
176 /* Try slot 1*/
177 config.slot = 1;
178 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
179 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
180 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
181
182 if (!(dev = mmc_init(&config)))
183 {
184 /* Try slot 2 */
185 config.slot = 2;
186 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
187 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
188 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
189
190 if (!(dev = mmc_init(&config)))
191 {
192 dprintf(CRITICAL, "mmc init failed!");
193 ASSERT(0);
194 }
195 }
196
197 /* MMC initialization is complete, read the partition table info */
198 if (partition_read_table())
199 {
200 dprintf(CRITICAL, "Error reading the partition table info\n");
201 ASSERT(0);
202 }
203}
204
205struct mmc_device *target_mmc_device()
206{
207 return dev;
208}
209
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700210void target_init(void)
211{
212 dprintf(INFO, "target_init()\n");
213
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700214 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
215
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700216 target_keystatus();
217
Sundarajan Srinivasanf7ef47f2013-09-05 17:46:24 -0700218 target_sdc_init();
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700219}
220
221unsigned board_machtype(void)
222{
223 return LINUX_MACHTYPE_UNKNOWN;
224}
225
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700226/* Detect the target type */
227void target_detect(struct board_data *board)
228{
229 board->target = LINUX_MACHTYPE_UNKNOWN;
230}
231
232/* Detect the modem type */
233void target_baseband_detect(struct board_data *board)
234{
Sundarajan Srinivasanf5932fb2013-08-06 17:26:04 -0700235 uint32_t platform;
236 uint32_t platform_subtype;
237
238 platform = board->platform;
239 platform_subtype = board->platform_subtype;
240
241 /*
242 * Look for platform subtype if present, else
243 * check for platform type to decide on the
244 * baseband type
245 */
246 switch(platform_subtype) {
247 case HW_PLATFORM_SUBTYPE_UNKNOWN:
248 break;
249
250 default:
251 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype);
252 ASSERT(0);
253 };
254
255 switch(platform) {
256 case APQ8084:
257 board->baseband = BASEBAND_APQ;
258 break;
259 default:
260 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
261 ASSERT(0);
262 }
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700263}
264
Justin Philipd4b293a2014-09-17 12:26:49 +0530265static uint8_t splash_override;
Dhaval Patel25f686e2013-10-18 19:06:05 -0700266/* Returns 1 if target supports continuous splash screen. */
267int target_cont_splash_screen()
268{
Justin Philipd4b293a2014-09-17 12:26:49 +0530269 uint8_t splash_screen = 0;
270 if(!splash_override) {
271 switch(board_hardware_id())
272 {
273 case HW_PLATFORM_SURF:
274 case HW_PLATFORM_MTP:
275 case HW_PLATFORM_FLUID:
276 case HW_PLATFORM_LIQUID:
277 dprintf(SPEW, "Target_cont_splash=1\n");
278 splash_screen = 1;
279 break;
280 default:
281 dprintf(SPEW, "Target_cont_splash=0\n");
282 splash_screen = 0;
283 }
Dhaval Patel25f686e2013-10-18 19:06:05 -0700284 }
Justin Philipd4b293a2014-09-17 12:26:49 +0530285 return splash_screen;
Dhaval Patel25f686e2013-10-18 19:06:05 -0700286}
287
Justin Philipd4b293a2014-09-17 12:26:49 +0530288void target_force_cont_splash_disable(uint8_t override)
289{
290 splash_override = override;
291}
292
293
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700294unsigned target_baseband()
295{
296 return board_baseband();
297}
298
299void target_serialno(unsigned char *buf)
300{
301 unsigned int serialno;
302 if (target_is_emmc_boot()) {
303 serialno = mmc_get_psn();
304 snprintf((char *)buf, 13, "%x", serialno);
305 }
306}
307
308unsigned check_reboot_mode(void)
309{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700310 uint32_t restart_reason = 0;
311 uint32_t restart_reason_addr;
312
313 restart_reason_addr = RESTART_REASON_ADDR;
314
315 /* Read reboot reason and scrub it */
316 restart_reason = readl(restart_reason_addr);
317 writel(0x00, restart_reason_addr);
318
319 return restart_reason;
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700320}
321
322void reboot_device(unsigned reboot_reason)
323{
Sundarajan Srinivasand43b28b2013-06-25 16:59:13 -0700324 uint8_t reset_type = 0;
325
326 /* Write the reboot reason */
327 writel(reboot_reason, RESTART_REASON_ADDR);
328
329 if(reboot_reason == FASTBOOT_MODE)
330 reset_type = PON_PSHOLD_WARM_RESET;
331 else
332 reset_type = PON_PSHOLD_HARD_RESET;
333
334 pm8x41_reset_configure(reset_type);
335
336 /* Drop PS_HOLD for MSM */
337 writel(0x00, MPM2_MPM_PS_HOLD);
338
339 mdelay(5000);
340
341 dprintf(CRITICAL, "Rebooting failed\n");
Deepa Dinamani0e5038f2013-05-16 15:02:16 -0700342}