blob: 9fed9abb58db2697dd7e98807aad52480af524b6 [file] [log] [blame]
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -08001/* 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>
31#include <reg.h>
32#include <target.h>
33#include <platform.h>
34#include <uart_dm.h>
35#include <mmc.h>
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070036#include <platform/gpio.h>
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080037#include <spmi.h>
38#include <board.h>
Deepa Dinamani41803e02013-03-25 11:44:15 -070039#include <smem.h>
40#include <baseband.h>
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070041#include <dev/keys.h>
42#include <pm8x41.h>
Deepa Dinamani98cf8ee2013-03-27 15:16:47 -070043#include <hsusb.h>
richardlb52d3f52013-04-12 17:37:28 -070044#include <kernel/thread.h>
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080045
46#define PMIC_ARB_CHANNEL_NUM 0
47#define PMIC_ARB_OWNER_ID 0
48
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070049#define TLMM_VOL_UP_BTN_GPIO 72
50
Maria Yu00fd3822013-06-26 10:12:54 +080051enum target_subtype {
52 HW_PLATFORM_SUBTYPE_SKUAA = 1,
53 HW_PLATFORM_SUBTYPE_SKUF = 2,
54 HW_PLATFORM_SUBTYPE_SKUAB = 3,
55};
56
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080057static uint32_t mmc_sdc_base[] =
58 { MSM_SDC1_BASE, MSM_SDC2_BASE };
59
60void target_early_init(void)
61{
62#if WITH_DEBUG_UART
Deepa Dinamanid1823b42013-03-21 11:49:35 -070063 uart_dm_init(2, 0, BLSP1_UART1_BASE);
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080064#endif
65}
66
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070067/* Return 1 if vol_up pressed */
68static int target_volume_up()
69{
70 uint8_t status = 0;
71
72 gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
73
richardlb52d3f52013-04-12 17:37:28 -070074 /* Wait for the configuration to complete.*/
75 thread_sleep(1);
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070076 /* Get status of GPIO */
77 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
78
79 /* Active low signal. */
80 return !status;
81}
82
83/* Return 1 if vol_down pressed */
84uint32_t target_volume_down()
85{
86 /* Volume down button tied in with PMIC RESIN. */
87 return pm8x41_resin_status();
88}
89
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080090static void target_keystatus()
91{
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070092 keys_init();
93
94 if(target_volume_down())
95 keys_post_event(KEY_VOLUMEDOWN, 1);
96
97 if(target_volume_up())
98 keys_post_event(KEY_VOLUMEUP, 1);
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080099}
100
101void target_init(void)
102{
103 uint32_t base_addr;
104 uint8_t slot;
105
106 dprintf(INFO, "target_init()\n");
107
108 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
109
Deepa Dinamani8ff46f02013-03-20 17:52:14 -0700110 target_keystatus();
111
Terence Hampsonafded262013-06-18 14:48:18 -0400112 /* Display splash screen if enabled */
113 dprintf(SPEW, "Display Init: Start\n");
114 display_init();
115 dprintf(SPEW, "Display Init: Done\n");
116
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800117 /* Trying Slot 1*/
118 slot = 1;
119 base_addr = mmc_sdc_base[slot - 1];
120
121 if (mmc_boot_main(slot, base_addr))
122 {
123 /* Trying Slot 2 next */
124 slot = 2;
125 base_addr = mmc_sdc_base[slot - 1];
126
127 if (mmc_boot_main(slot, base_addr))
128 {
129 dprintf(CRITICAL, "mmc init failed!");
130 ASSERT(0);
131 }
132 }
133}
134
Deepa Dinamani2b795bb2013-03-25 11:31:58 -0700135/* Do any target specific intialization needed before entering fastboot mode */
136void target_fastboot_init(void)
137{
138 /* Set the BOOT_DONE flag in PM8110 */
139 pm8x41_set_boot_done();
140}
141
Deepa Dinamani41803e02013-03-25 11:44:15 -0700142/* Detect the target type */
143void target_detect(struct board_data *board)
144{
Maria Yuca51ee22013-06-27 21:45:24 +0800145 /*
146 * already fill the board->target on board.c
147 */
148
Deepa Dinamani41803e02013-03-25 11:44:15 -0700149}
150
151/* Detect the modem type */
152void target_baseband_detect(struct board_data *board)
153{
154 uint32_t platform;
155 uint32_t platform_subtype;
156
157 platform = board->platform;
158 platform_subtype = board->platform_subtype;
159
160 /*
161 * Look for platform subtype if present, else
162 * check for platform type to decide on the
163 * baseband type
164 */
165 switch(platform_subtype)
166 {
167 case HW_PLATFORM_SUBTYPE_UNKNOWN:
168 break;
Maria Yu00fd3822013-06-26 10:12:54 +0800169 case HW_PLATFORM_SUBTYPE_SKUAA:
170 break;
171 case HW_PLATFORM_SUBTYPE_SKUF:
172 break;
173 case HW_PLATFORM_SUBTYPE_SKUAB:
174 break;
Deepa Dinamani41803e02013-03-25 11:44:15 -0700175 default:
176 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype);
177 ASSERT(0);
178 };
179
180 switch(platform)
181 {
182 case MSM8610:
183 case MSM8110:
184 case MSM8210:
185 case MSM8810:
Deepa Dinamani39345cd2013-04-08 19:46:53 -0700186 case MSM8612:
David Ng2de18062013-04-19 20:22:16 -0700187 case MSM8212:
188 case MSM8812:
Deepa Dinamani41803e02013-03-25 11:44:15 -0700189 board->baseband = BASEBAND_MSM;
190 break;
191 default:
192 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
193 ASSERT(0);
194 };
195}
196
197unsigned target_baseband()
198{
199 return board_baseband();
200}
201
Deepa Dinamania6d1b752013-03-25 11:47:20 -0700202void target_serialno(unsigned char *buf)
203{
204 uint32_t serialno;
205 if (target_is_emmc_boot()) {
206 serialno = mmc_get_psn();
207 snprintf((char *)buf, 13, "%x", serialno);
208 }
209}
210
Deepa Dinamani5390e102013-03-25 11:55:31 -0700211unsigned check_reboot_mode(void)
212{
213 uint32_t restart_reason = 0;
214
215 /* Read reboot reason and scrub it */
216 restart_reason = readl(RESTART_REASON_ADDR);
217 writel(0x00, RESTART_REASON_ADDR);
218
219 return restart_reason;
220}
221
Deepa Dinamani172b7e62013-03-25 11:59:21 -0700222void reboot_device(unsigned reboot_reason)
223{
224 writel(reboot_reason, RESTART_REASON_ADDR);
225
226 /* Configure PMIC for warm reset */
227 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
228
229 /* Drop PS_HOLD for MSM */
230 writel(0x00, MPM2_MPM_PS_HOLD);
231
232 mdelay(5000);
233
234 dprintf(CRITICAL, "Rebooting failed\n");
235}
236
Terence Hampsonafded262013-06-18 14:48:18 -0400237int target_cont_splash_screen()
238{
239 int ret = 0;
240 switch(board_hardware_id())
241 {
242 case HW_PLATFORM_MTP:
243 case HW_PLATFORM_QRD:
244 case HW_PLATFORM_SURF:
245 dprintf(SPEW, "Target_cont_splash=0\n");
246 ret = 0;
247 default:
248 dprintf(SPEW, "Target_cont_splash=0\n");
249 ret = 0;
250 }
251 return ret;
252}
253
Deepa Dinamani004eb322013-03-25 13:20:50 -0700254unsigned target_pause_for_battery_charge(void)
255{
256 uint8_t pon_reason = pm8x41_get_pon_reason();
Xu Kaic2e0afc2013-07-19 13:26:36 +0800257 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
258 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
259 pon_reason, is_cold_boot);
260 /*In case of fastboot reboot, adb reboot or if we see the power key
261 * pressed we do not want go into charger mode.
262 * fastboot reboot is warm boot with PON hard reset bit not set
263 * adb reboot is a cold boot with PON hard reset bit set
Deepa Dinamani004eb322013-03-25 13:20:50 -0700264 */
Xu Kaic2e0afc2013-07-19 13:26:36 +0800265 if (is_cold_boot &&
266 (!(pon_reason & HARD_RST)) &&
267 (!(pon_reason & KPDPWR_N)) &&
268 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG)))
269 return 1;
270 else
271 return 0;
Deepa Dinamani004eb322013-03-25 13:20:50 -0700272}
273
Deepa Dinamani98cf8ee2013-03-27 15:16:47 -0700274void target_usb_stop(void)
275{
276 /* Disable VBUS mimicing in the controller. */
277 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
278}
279
280void target_usb_init(void)
281{
282 uint32_t val;
283
284 /* Select and enable external configuration with USB PHY */
285 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
286
287 /* Enable sess_vld */
288 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
289 writel(val, USB_GENCONFIG_2);
290
291 /* Enable external vbus configuration in the LINK */
292 val = readl(USB_USBCMD);
293 val |= SESS_VLD_CTRL;
294 writel(val, USB_USBCMD);
295}
296
297
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800298unsigned board_machtype(void)
299{
Deepa Dinamani2b795bb2013-03-25 11:31:58 -0700300 return 0;
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800301}
Channagoud Kadabie1b75262013-05-08 12:58:39 -0700302
303/*
304 * Function to set the capabilities for the host
305 */
306void target_mmc_caps(struct mmc_host *host)
307{
308 host->caps.ddr_mode = 0;
309 host->caps.hs200_mode = 0;
310 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
311 host->caps.hs_clk_rate = MMC_CLK_50MHZ;
312}