blob: 61f29b3c72cdb0ebba906cfbe65efdef493be8df [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>
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080044
45#define PMIC_ARB_CHANNEL_NUM 0
46#define PMIC_ARB_OWNER_ID 0
47
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070048#define TLMM_VOL_UP_BTN_GPIO 72
49
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080050static uint32_t mmc_sdc_base[] =
51 { MSM_SDC1_BASE, MSM_SDC2_BASE };
52
53void target_early_init(void)
54{
55#if WITH_DEBUG_UART
Deepa Dinamanid1823b42013-03-21 11:49:35 -070056 uart_dm_init(2, 0, BLSP1_UART1_BASE);
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080057#endif
58}
59
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070060/* Return 1 if vol_up pressed */
61static int target_volume_up()
62{
63 uint8_t status = 0;
64
65 gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
66
67 /* Get status of GPIO */
68 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
69
70 /* Active low signal. */
71 return !status;
72}
73
74/* Return 1 if vol_down pressed */
75uint32_t target_volume_down()
76{
77 /* Volume down button tied in with PMIC RESIN. */
78 return pm8x41_resin_status();
79}
80
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080081static void target_keystatus()
82{
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070083 keys_init();
84
85 if(target_volume_down())
86 keys_post_event(KEY_VOLUMEDOWN, 1);
87
88 if(target_volume_up())
89 keys_post_event(KEY_VOLUMEUP, 1);
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080090}
91
92void target_init(void)
93{
94 uint32_t base_addr;
95 uint8_t slot;
96
97 dprintf(INFO, "target_init()\n");
98
99 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
100
Deepa Dinamani8ff46f02013-03-20 17:52:14 -0700101 target_keystatus();
102
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800103 /* Trying Slot 1*/
104 slot = 1;
105 base_addr = mmc_sdc_base[slot - 1];
106
107 if (mmc_boot_main(slot, base_addr))
108 {
109 /* Trying Slot 2 next */
110 slot = 2;
111 base_addr = mmc_sdc_base[slot - 1];
112
113 if (mmc_boot_main(slot, base_addr))
114 {
115 dprintf(CRITICAL, "mmc init failed!");
116 ASSERT(0);
117 }
118 }
119}
120
Deepa Dinamani2b795bb2013-03-25 11:31:58 -0700121/* Do any target specific intialization needed before entering fastboot mode */
122void target_fastboot_init(void)
123{
124 /* Set the BOOT_DONE flag in PM8110 */
125 pm8x41_set_boot_done();
126}
127
Deepa Dinamani41803e02013-03-25 11:44:15 -0700128/* Detect the target type */
129void target_detect(struct board_data *board)
130{
131 board->target = LINUX_MACHTYPE_UNKNOWN;
132}
133
134/* Detect the modem type */
135void target_baseband_detect(struct board_data *board)
136{
137 uint32_t platform;
138 uint32_t platform_subtype;
139
140 platform = board->platform;
141 platform_subtype = board->platform_subtype;
142
143 /*
144 * Look for platform subtype if present, else
145 * check for platform type to decide on the
146 * baseband type
147 */
148 switch(platform_subtype)
149 {
150 case HW_PLATFORM_SUBTYPE_UNKNOWN:
151 break;
152 default:
153 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype);
154 ASSERT(0);
155 };
156
157 switch(platform)
158 {
159 case MSM8610:
160 case MSM8110:
161 case MSM8210:
162 case MSM8810:
Deepa Dinamani39345cd2013-04-08 19:46:53 -0700163 case MSM8612:
Deepa Dinamani41803e02013-03-25 11:44:15 -0700164 board->baseband = BASEBAND_MSM;
165 break;
166 default:
167 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
168 ASSERT(0);
169 };
170}
171
172unsigned target_baseband()
173{
174 return board_baseband();
175}
176
Deepa Dinamania6d1b752013-03-25 11:47:20 -0700177void target_serialno(unsigned char *buf)
178{
179 uint32_t serialno;
180 if (target_is_emmc_boot()) {
181 serialno = mmc_get_psn();
182 snprintf((char *)buf, 13, "%x", serialno);
183 }
184}
185
Deepa Dinamani5390e102013-03-25 11:55:31 -0700186unsigned check_reboot_mode(void)
187{
188 uint32_t restart_reason = 0;
189
190 /* Read reboot reason and scrub it */
191 restart_reason = readl(RESTART_REASON_ADDR);
192 writel(0x00, RESTART_REASON_ADDR);
193
194 return restart_reason;
195}
196
Deepa Dinamani172b7e62013-03-25 11:59:21 -0700197void reboot_device(unsigned reboot_reason)
198{
199 writel(reboot_reason, RESTART_REASON_ADDR);
200
201 /* Configure PMIC for warm reset */
202 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
203
204 /* Drop PS_HOLD for MSM */
205 writel(0x00, MPM2_MPM_PS_HOLD);
206
207 mdelay(5000);
208
209 dprintf(CRITICAL, "Rebooting failed\n");
210}
211
Deepa Dinamani004eb322013-03-25 13:20:50 -0700212unsigned target_pause_for_battery_charge(void)
213{
214 uint8_t pon_reason = pm8x41_get_pon_reason();
215
216 /* This function will always return 0 to facilitate
217 * automated testing/reboot with usb connected.
218 * uncomment if this feature is needed.
219 */
220 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
221 * return 1;
222 */
223
224 return 0;
225}
226
Deepa Dinamani98cf8ee2013-03-27 15:16:47 -0700227void target_usb_stop(void)
228{
229 /* Disable VBUS mimicing in the controller. */
230 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
231}
232
233void target_usb_init(void)
234{
235 uint32_t val;
236
237 /* Select and enable external configuration with USB PHY */
238 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
239
240 /* Enable sess_vld */
241 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
242 writel(val, USB_GENCONFIG_2);
243
244 /* Enable external vbus configuration in the LINK */
245 val = readl(USB_USBCMD);
246 val |= SESS_VLD_CTRL;
247 writel(val, USB_USBCMD);
248}
249
250
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800251unsigned board_machtype(void)
252{
Deepa Dinamani2b795bb2013-03-25 11:31:58 -0700253 return 0;
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800254}