blob: 61135f9b5e11f37a6291895202612bcaaebd427c [file] [log] [blame]
Unnati Gandhiea8381d2014-02-24 15:58:22 +05301/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -08002 *
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>
Channagoud Kadabi25e4d932013-05-10 17:54:29 -070031#include <platform/irqs.h>
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080032#include <reg.h>
33#include <target.h>
34#include <platform.h>
35#include <uart_dm.h>
36#include <mmc.h>
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070037#include <platform/gpio.h>
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080038#include <spmi.h>
39#include <board.h>
Deepa Dinamani41803e02013-03-25 11:44:15 -070040#include <smem.h>
41#include <baseband.h>
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070042#include <dev/keys.h>
43#include <pm8x41.h>
Deepa Dinamani98cf8ee2013-03-27 15:16:47 -070044#include <hsusb.h>
richardlb52d3f52013-04-12 17:37:28 -070045#include <kernel/thread.h>
Amol Jadif2139012013-08-23 18:44:10 -070046#include <arch/defines.h>
47#include <stdlib.h>
48#include <scm.h>
49#include <partition_parser.h>
50#include <platform/clock.h>
51#include <platform/timer.h>
Matthew Qin3b5dae52014-03-06 13:20:00 +080052#include <shutdown_detect.h>
Matthew Qin50773f52014-03-06 13:42:35 +080053#include <vibrator.h>
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080054
55#define PMIC_ARB_CHANNEL_NUM 0
56#define PMIC_ARB_OWNER_ID 0
57
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070058#define TLMM_VOL_UP_BTN_GPIO 72
Matthew Qin50773f52014-03-06 13:42:35 +080059#define VIBRATE_TIME 250
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070060
Maria Yu00fd3822013-06-26 10:12:54 +080061enum target_subtype {
62 HW_PLATFORM_SUBTYPE_SKUAA = 1,
63 HW_PLATFORM_SUBTYPE_SKUF = 2,
64 HW_PLATFORM_SUBTYPE_SKUAB = 3,
65};
66
Channagoud Kadabi25e4d932013-05-10 17:54:29 -070067static void set_sdc_power_ctrl(void);
68
69static uint32_t mmc_pwrctl_base[] =
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080070 { MSM_SDC1_BASE, MSM_SDC2_BASE };
71
Channagoud Kadabi25e4d932013-05-10 17:54:29 -070072static uint32_t mmc_sdhci_base[] =
73 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
74
75static uint32_t mmc_sdc_pwrctl_irq[] =
76 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
77
78struct mmc_device *dev;
79
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080080void target_early_init(void)
81{
82#if WITH_DEBUG_UART
Deepa Dinamanid1823b42013-03-21 11:49:35 -070083 uart_dm_init(2, 0, BLSP1_UART1_BASE);
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080084#endif
85}
86
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070087/* Return 1 if vol_up pressed */
88static int target_volume_up()
89{
90 uint8_t status = 0;
91
92 gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
93
richardlb52d3f52013-04-12 17:37:28 -070094 /* Wait for the configuration to complete.*/
95 thread_sleep(1);
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070096 /* Get status of GPIO */
97 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
98
99 /* Active low signal. */
100 return !status;
101}
102
103/* Return 1 if vol_down pressed */
104uint32_t target_volume_down()
105{
106 /* Volume down button tied in with PMIC RESIN. */
107 return pm8x41_resin_status();
108}
109
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800110static void target_keystatus()
111{
Deepa Dinamani8ff46f02013-03-20 17:52:14 -0700112 keys_init();
113
114 if(target_volume_down())
115 keys_post_event(KEY_VOLUMEDOWN, 1);
116
117 if(target_volume_up())
118 keys_post_event(KEY_VOLUMEUP, 1);
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800119}
120
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700121void target_sdc_init()
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800122{
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700123 struct mmc_config_data config;
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800124
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700125 /* Set drive strength & pull ctrl values */
126 set_sdc_power_ctrl();
Deepa Dinamani8ff46f02013-03-20 17:52:14 -0700127
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700128 config.bus_width = DATA_BUS_WIDTH_8BIT;
129 config.max_clk_rate = MMC_CLK_200MHZ;
130
131 /* Try slot 1*/
132 config.slot = 1;
133 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
134 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
135 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
136
137 if (!(dev = mmc_init(&config)))
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800138 {
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700139 /* Try slot 2 */
140 config.slot = 2;
141 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
142 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
143 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800144
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700145 if (!(dev = mmc_init(&config)))
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800146 {
147 dprintf(CRITICAL, "mmc init failed!");
148 ASSERT(0);
149 }
150 }
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700151
152 /* MMC initialization is complete, read the partition table info */
153 if (partition_read_table())
154 {
155 dprintf(CRITICAL, "Error reading the partition table info\n");
156 ASSERT(0);
157 }
158}
159
160void target_init(void)
161{
162 dprintf(INFO, "target_init()\n");
163
164 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
165
166 target_keystatus();
167
168 target_sdc_init();
Matthew Qin3b5dae52014-03-06 13:20:00 +0800169
170 shutdown_detect();
Matthew Qin50773f52014-03-06 13:42:35 +0800171
172 /* turn on vibrator to indicate that phone is booting up to end user */
173 vib_timed_turn_on(VIBRATE_TIME);
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800174}
175
Aparna Mallavarapu2ce9f762013-07-30 15:29:12 +0530176void target_uninit(void)
177{
178 mmc_put_card_to_sleep(dev);
Matthew Qin50773f52014-03-06 13:42:35 +0800179
180 /* wait for the vibrator timer is expried */
181 wait_vib_timeout();
Aparna Mallavarapu31450b82014-09-22 18:36:24 +0530182
183 /* Disable HC mode before jumping to kernel */
184 sdhci_mode_disable(&dev->host);
Aparna Mallavarapu2ce9f762013-07-30 15:29:12 +0530185}
Amol Jadif2139012013-08-23 18:44:10 -0700186
187#define SSD_CE_INSTANCE 1
188
189void target_load_ssd_keystore(void)
190{
191 uint64_t ptn;
192 int index;
193 uint64_t size;
194 uint32_t *buffer;
195
196 if (!target_is_ssd_enabled())
197 return;
198
199 index = partition_get_index("ssd");
200
201 ptn = partition_get_offset(index);
202 if (ptn == 0){
203 dprintf(CRITICAL, "Error: ssd partition not found\n");
204 return;
205 }
206
207 size = partition_get_size(index);
208 if (size == 0) {
209 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
210 return;
211 }
212
213 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
214 if (!buffer) {
215 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
216 return;
217 }
218
219 if (mmc_read(ptn, buffer, size)) {
220 dprintf(CRITICAL, "Error: cannot read data\n");
221 free(buffer);
222 return;
223 }
224
225 clock_ce_enable(SSD_CE_INSTANCE);
226 scm_protect_keystore(buffer, size);
227 clock_ce_disable(SSD_CE_INSTANCE);
228 free(buffer);
229}
230
Deepa Dinamani2b795bb2013-03-25 11:31:58 -0700231/* Do any target specific intialization needed before entering fastboot mode */
232void target_fastboot_init(void)
233{
234 /* Set the BOOT_DONE flag in PM8110 */
235 pm8x41_set_boot_done();
Amol Jadif2139012013-08-23 18:44:10 -0700236
237 if (target_is_ssd_enabled()) {
238 clock_ce_enable(SSD_CE_INSTANCE);
239 target_load_ssd_keystore();
240 }
241
Deepa Dinamani2b795bb2013-03-25 11:31:58 -0700242}
243
Deepa Dinamani41803e02013-03-25 11:44:15 -0700244/* Detect the target type */
245void target_detect(struct board_data *board)
246{
Maria Yuca51ee22013-06-27 21:45:24 +0800247 /*
248 * already fill the board->target on board.c
249 */
250
Deepa Dinamani41803e02013-03-25 11:44:15 -0700251}
252
253/* Detect the modem type */
254void target_baseband_detect(struct board_data *board)
255{
256 uint32_t platform;
257 uint32_t platform_subtype;
258
259 platform = board->platform;
260 platform_subtype = board->platform_subtype;
261
262 /*
263 * Look for platform subtype if present, else
264 * check for platform type to decide on the
265 * baseband type
266 */
267 switch(platform_subtype)
268 {
269 case HW_PLATFORM_SUBTYPE_UNKNOWN:
270 break;
Maria Yu00fd3822013-06-26 10:12:54 +0800271 case HW_PLATFORM_SUBTYPE_SKUAA:
272 break;
273 case HW_PLATFORM_SUBTYPE_SKUF:
274 break;
275 case HW_PLATFORM_SUBTYPE_SKUAB:
276 break;
Deepa Dinamani41803e02013-03-25 11:44:15 -0700277 default:
278 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype);
279 ASSERT(0);
280 };
281
282 switch(platform)
283 {
284 case MSM8610:
285 case MSM8110:
286 case MSM8210:
287 case MSM8810:
Deepa Dinamani39345cd2013-04-08 19:46:53 -0700288 case MSM8612:
David Ng2de18062013-04-19 20:22:16 -0700289 case MSM8212:
290 case MSM8812:
Deepa Dinamanib8534dd2013-09-12 11:02:34 -0700291 case MSM8510:
292 case MSM8512:
Deepa Dinamani41803e02013-03-25 11:44:15 -0700293 board->baseband = BASEBAND_MSM;
294 break;
295 default:
296 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
297 ASSERT(0);
298 };
299}
300
301unsigned target_baseband()
302{
303 return board_baseband();
304}
305
Maunik Shah7a793542015-01-28 16:09:31 +0530306int emmc_recovery_init(void)
307{
308 return _emmc_recovery_init();
309}
310
Deepa Dinamania6d1b752013-03-25 11:47:20 -0700311void target_serialno(unsigned char *buf)
312{
313 uint32_t serialno;
314 if (target_is_emmc_boot()) {
315 serialno = mmc_get_psn();
316 snprintf((char *)buf, 13, "%x", serialno);
317 }
318}
319
Deepa Dinamani5390e102013-03-25 11:55:31 -0700320unsigned check_reboot_mode(void)
321{
322 uint32_t restart_reason = 0;
323
324 /* Read reboot reason and scrub it */
325 restart_reason = readl(RESTART_REASON_ADDR);
326 writel(0x00, RESTART_REASON_ADDR);
327
328 return restart_reason;
329}
330
Deepa Dinamani172b7e62013-03-25 11:59:21 -0700331void reboot_device(unsigned reboot_reason)
332{
Channagoud Kadabi636f9af2013-12-12 14:55:47 -0800333 int ret = 0;
334
Deepa Dinamani172b7e62013-03-25 11:59:21 -0700335 writel(reboot_reason, RESTART_REASON_ADDR);
336
337 /* Configure PMIC for warm reset */
338 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
339
Channagoud Kadabi636f9af2013-12-12 14:55:47 -0800340 ret = scm_halt_pmic_arbiter();
341 if (ret)
342 dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret);
343
Deepa Dinamani172b7e62013-03-25 11:59:21 -0700344 /* Drop PS_HOLD for MSM */
345 writel(0x00, MPM2_MPM_PS_HOLD);
346
347 mdelay(5000);
348
349 dprintf(CRITICAL, "Rebooting failed\n");
350}
351
Justin Philipd4b293a2014-09-17 12:26:49 +0530352static uint8_t splash_override;
353
Terence Hampsonafded262013-06-18 14:48:18 -0400354int target_cont_splash_screen()
355{
Justin Philipd4b293a2014-09-17 12:26:49 +0530356 uint8_t splash_screen = 0;
357 if(!splash_override) {
358 switch(board_hardware_id())
359 {
360 case HW_PLATFORM_QRD:
361 case HW_PLATFORM_MTP:
362 case HW_PLATFORM_SURF:
363 dprintf(SPEW, "Target_cont_splash=1\n");
364 splash_screen = 1;
365 break;
366 default:
367 dprintf(SPEW, "Target_cont_splash=0\n");
368 splash_screen = 0;
369 }
Terence Hampsonafded262013-06-18 14:48:18 -0400370 }
Justin Philipd4b293a2014-09-17 12:26:49 +0530371 return splash_screen;
372}
373
374void target_force_cont_splash_disable(uint8_t override)
375{
376 splash_override = override;
Terence Hampsonafded262013-06-18 14:48:18 -0400377}
378
Deepa Dinamani004eb322013-03-25 13:20:50 -0700379unsigned target_pause_for_battery_charge(void)
380{
381 uint8_t pon_reason = pm8x41_get_pon_reason();
Xu Kaic2e0afc2013-07-19 13:26:36 +0800382 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
383 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
384 pon_reason, is_cold_boot);
385 /*In case of fastboot reboot, adb reboot or if we see the power key
386 * pressed we do not want go into charger mode.
387 * fastboot reboot is warm boot with PON hard reset bit not set
388 * adb reboot is a cold boot with PON hard reset bit set
Deepa Dinamani004eb322013-03-25 13:20:50 -0700389 */
Xu Kaic2e0afc2013-07-19 13:26:36 +0800390 if (is_cold_boot &&
391 (!(pon_reason & HARD_RST)) &&
392 (!(pon_reason & KPDPWR_N)) &&
393 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG)))
394 return 1;
395 else
396 return 0;
Deepa Dinamani004eb322013-03-25 13:20:50 -0700397}
398
Deepa Dinamani98cf8ee2013-03-27 15:16:47 -0700399void target_usb_stop(void)
400{
401 /* Disable VBUS mimicing in the controller. */
402 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
403}
404
405void target_usb_init(void)
406{
407 uint32_t val;
408
409 /* Select and enable external configuration with USB PHY */
410 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
411
412 /* Enable sess_vld */
413 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
414 writel(val, USB_GENCONFIG_2);
415
416 /* Enable external vbus configuration in the LINK */
417 val = readl(USB_USBCMD);
418 val |= SESS_VLD_CTRL;
419 writel(val, USB_USBCMD);
420}
421
422
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800423unsigned board_machtype(void)
424{
Deepa Dinamani2b795bb2013-03-25 11:31:58 -0700425 return 0;
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800426}
Channagoud Kadabie1b75262013-05-08 12:58:39 -0700427
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700428static void set_sdc_power_ctrl()
Channagoud Kadabie1b75262013-05-08 12:58:39 -0700429{
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700430 /* Drive strength configs for sdc pins */
431 struct tlmm_cfgs sdc1_hdrv_cfg[] =
432 {
433 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
434 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
Unnati Gandhiea8381d2014-02-24 15:58:22 +0530435 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK },
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700436 };
437
438 /* Pull configs for sdc pins */
439 struct tlmm_cfgs sdc1_pull_cfg[] =
440 {
441 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
442 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
443 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
444 };
445
446 /* Set the drive strength & pull control values */
447 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
448 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
449}
450
451struct mmc_device *target_mmc_device()
452{
453 return dev;
Channagoud Kadabie1b75262013-05-08 12:58:39 -0700454}
Matthew Qin365bebe2014-03-06 13:11:28 +0800455
456/* Configure PMIC and Drop PS_HOLD for shutdown */
457void shutdown_device()
458{
459 dprintf(CRITICAL, "Going down for shutdown.\n");
460
461 /* Configure PMIC for shutdown */
462 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
463
464 /* Drop PS_HOLD for MSM */
465 writel(0x00, MPM2_MPM_PS_HOLD);
466
467 mdelay(5000);
468
469 dprintf(CRITICAL, "shutdown failed\n");
470
471 ASSERT(0);
472}