blob: fb6d24cfaf901947f3afcab9ba639fe149a7982a [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>
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080052
53#define PMIC_ARB_CHANNEL_NUM 0
54#define PMIC_ARB_OWNER_ID 0
55
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070056#define TLMM_VOL_UP_BTN_GPIO 72
57
Maria Yu00fd3822013-06-26 10:12:54 +080058enum target_subtype {
59 HW_PLATFORM_SUBTYPE_SKUAA = 1,
60 HW_PLATFORM_SUBTYPE_SKUF = 2,
61 HW_PLATFORM_SUBTYPE_SKUAB = 3,
62};
63
Channagoud Kadabi25e4d932013-05-10 17:54:29 -070064static void set_sdc_power_ctrl(void);
65
66static uint32_t mmc_pwrctl_base[] =
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080067 { MSM_SDC1_BASE, MSM_SDC2_BASE };
68
Channagoud Kadabi25e4d932013-05-10 17:54:29 -070069static 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;
76
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080077void target_early_init(void)
78{
79#if WITH_DEBUG_UART
Deepa Dinamanid1823b42013-03-21 11:49:35 -070080 uart_dm_init(2, 0, BLSP1_UART1_BASE);
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080081#endif
82}
83
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070084/* Return 1 if vol_up pressed */
85static int target_volume_up()
86{
87 uint8_t status = 0;
88
89 gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
90
richardlb52d3f52013-04-12 17:37:28 -070091 /* Wait for the configuration to complete.*/
92 thread_sleep(1);
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070093 /* Get status of GPIO */
94 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
95
96 /* Active low signal. */
97 return !status;
98}
99
100/* Return 1 if vol_down pressed */
101uint32_t target_volume_down()
102{
103 /* Volume down button tied in with PMIC RESIN. */
104 return pm8x41_resin_status();
105}
106
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800107static void target_keystatus()
108{
Deepa Dinamani8ff46f02013-03-20 17:52:14 -0700109 keys_init();
110
111 if(target_volume_down())
112 keys_post_event(KEY_VOLUMEDOWN, 1);
113
114 if(target_volume_up())
115 keys_post_event(KEY_VOLUMEUP, 1);
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800116}
117
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700118void target_sdc_init()
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800119{
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700120 struct mmc_config_data config;
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800121
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700122 /* Set drive strength & pull ctrl values */
123 set_sdc_power_ctrl();
Deepa Dinamani8ff46f02013-03-20 17:52:14 -0700124
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700125 config.bus_width = DATA_BUS_WIDTH_8BIT;
126 config.max_clk_rate = MMC_CLK_200MHZ;
127
128 /* Try slot 1*/
129 config.slot = 1;
130 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
131 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
132 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
133
134 if (!(dev = mmc_init(&config)))
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800135 {
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700136 /* Try slot 2 */
137 config.slot = 2;
138 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
139 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
140 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800141
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700142 if (!(dev = mmc_init(&config)))
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800143 {
144 dprintf(CRITICAL, "mmc init failed!");
145 ASSERT(0);
146 }
147 }
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700148
149 /* MMC initialization is complete, read the partition table info */
150 if (partition_read_table())
151 {
152 dprintf(CRITICAL, "Error reading the partition table info\n");
153 ASSERT(0);
154 }
155}
156
157void target_init(void)
158{
159 dprintf(INFO, "target_init()\n");
160
161 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
162
163 target_keystatus();
164
165 target_sdc_init();
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800166}
167
Aparna Mallavarapu2ce9f762013-07-30 15:29:12 +0530168void target_uninit(void)
169{
170 mmc_put_card_to_sleep(dev);
171}
Amol Jadif2139012013-08-23 18:44:10 -0700172
173#define SSD_CE_INSTANCE 1
174
175void target_load_ssd_keystore(void)
176{
177 uint64_t ptn;
178 int index;
179 uint64_t size;
180 uint32_t *buffer;
181
182 if (!target_is_ssd_enabled())
183 return;
184
185 index = partition_get_index("ssd");
186
187 ptn = partition_get_offset(index);
188 if (ptn == 0){
189 dprintf(CRITICAL, "Error: ssd partition not found\n");
190 return;
191 }
192
193 size = partition_get_size(index);
194 if (size == 0) {
195 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
196 return;
197 }
198
199 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
200 if (!buffer) {
201 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
202 return;
203 }
204
205 if (mmc_read(ptn, buffer, size)) {
206 dprintf(CRITICAL, "Error: cannot read data\n");
207 free(buffer);
208 return;
209 }
210
211 clock_ce_enable(SSD_CE_INSTANCE);
212 scm_protect_keystore(buffer, size);
213 clock_ce_disable(SSD_CE_INSTANCE);
214 free(buffer);
215}
216
Deepa Dinamani2b795bb2013-03-25 11:31:58 -0700217/* Do any target specific intialization needed before entering fastboot mode */
218void target_fastboot_init(void)
219{
220 /* Set the BOOT_DONE flag in PM8110 */
221 pm8x41_set_boot_done();
Amol Jadif2139012013-08-23 18:44:10 -0700222
223 if (target_is_ssd_enabled()) {
224 clock_ce_enable(SSD_CE_INSTANCE);
225 target_load_ssd_keystore();
226 }
227
Deepa Dinamani2b795bb2013-03-25 11:31:58 -0700228}
229
Deepa Dinamani41803e02013-03-25 11:44:15 -0700230/* Detect the target type */
231void target_detect(struct board_data *board)
232{
Maria Yuca51ee22013-06-27 21:45:24 +0800233 /*
234 * already fill the board->target on board.c
235 */
236
Deepa Dinamani41803e02013-03-25 11:44:15 -0700237}
238
239/* Detect the modem type */
240void target_baseband_detect(struct board_data *board)
241{
242 uint32_t platform;
243 uint32_t platform_subtype;
244
245 platform = board->platform;
246 platform_subtype = board->platform_subtype;
247
248 /*
249 * Look for platform subtype if present, else
250 * check for platform type to decide on the
251 * baseband type
252 */
253 switch(platform_subtype)
254 {
255 case HW_PLATFORM_SUBTYPE_UNKNOWN:
256 break;
Maria Yu00fd3822013-06-26 10:12:54 +0800257 case HW_PLATFORM_SUBTYPE_SKUAA:
258 break;
259 case HW_PLATFORM_SUBTYPE_SKUF:
260 break;
261 case HW_PLATFORM_SUBTYPE_SKUAB:
262 break;
Deepa Dinamani41803e02013-03-25 11:44:15 -0700263 default:
264 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype);
265 ASSERT(0);
266 };
267
268 switch(platform)
269 {
270 case MSM8610:
271 case MSM8110:
272 case MSM8210:
273 case MSM8810:
Deepa Dinamani39345cd2013-04-08 19:46:53 -0700274 case MSM8612:
David Ng2de18062013-04-19 20:22:16 -0700275 case MSM8212:
276 case MSM8812:
Deepa Dinamanib8534dd2013-09-12 11:02:34 -0700277 case MSM8510:
278 case MSM8512:
Deepa Dinamani41803e02013-03-25 11:44:15 -0700279 board->baseband = BASEBAND_MSM;
280 break;
281 default:
282 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
283 ASSERT(0);
284 };
285}
286
287unsigned target_baseband()
288{
289 return board_baseband();
290}
291
Deepa Dinamania6d1b752013-03-25 11:47:20 -0700292void target_serialno(unsigned char *buf)
293{
294 uint32_t serialno;
295 if (target_is_emmc_boot()) {
296 serialno = mmc_get_psn();
297 snprintf((char *)buf, 13, "%x", serialno);
298 }
299}
300
Deepa Dinamani5390e102013-03-25 11:55:31 -0700301unsigned check_reboot_mode(void)
302{
303 uint32_t restart_reason = 0;
304
305 /* Read reboot reason and scrub it */
306 restart_reason = readl(RESTART_REASON_ADDR);
307 writel(0x00, RESTART_REASON_ADDR);
308
309 return restart_reason;
310}
311
Deepa Dinamani172b7e62013-03-25 11:59:21 -0700312void reboot_device(unsigned reboot_reason)
313{
Channagoud Kadabi636f9af2013-12-12 14:55:47 -0800314 int ret = 0;
315
Deepa Dinamani172b7e62013-03-25 11:59:21 -0700316 writel(reboot_reason, RESTART_REASON_ADDR);
317
318 /* Configure PMIC for warm reset */
319 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
320
Channagoud Kadabi636f9af2013-12-12 14:55:47 -0800321 ret = scm_halt_pmic_arbiter();
322 if (ret)
323 dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret);
324
Deepa Dinamani172b7e62013-03-25 11:59:21 -0700325 /* Drop PS_HOLD for MSM */
326 writel(0x00, MPM2_MPM_PS_HOLD);
327
328 mdelay(5000);
329
330 dprintf(CRITICAL, "Rebooting failed\n");
331}
332
Terence Hampsonafded262013-06-18 14:48:18 -0400333int target_cont_splash_screen()
334{
335 int ret = 0;
Shuo Yanb757da82013-08-09 08:58:24 +0800336
Terence Hampsonafded262013-06-18 14:48:18 -0400337 switch(board_hardware_id())
338 {
Terence Hampsonafded262013-06-18 14:48:18 -0400339 case HW_PLATFORM_QRD:
Terence Hampson0e2f6552013-07-09 15:45:37 -0400340 case HW_PLATFORM_MTP:
341 case HW_PLATFORM_SURF:
342 dprintf(SPEW, "Target_cont_splash=1\n");
343 ret = 1;
344 break;
Terence Hampsonafded262013-06-18 14:48:18 -0400345 default:
346 dprintf(SPEW, "Target_cont_splash=0\n");
347 ret = 0;
348 }
349 return ret;
350}
351
Deepa Dinamani004eb322013-03-25 13:20:50 -0700352unsigned target_pause_for_battery_charge(void)
353{
354 uint8_t pon_reason = pm8x41_get_pon_reason();
Xu Kaic2e0afc2013-07-19 13:26:36 +0800355 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
356 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
357 pon_reason, is_cold_boot);
358 /*In case of fastboot reboot, adb reboot or if we see the power key
359 * pressed we do not want go into charger mode.
360 * fastboot reboot is warm boot with PON hard reset bit not set
361 * adb reboot is a cold boot with PON hard reset bit set
Deepa Dinamani004eb322013-03-25 13:20:50 -0700362 */
Xu Kaic2e0afc2013-07-19 13:26:36 +0800363 if (is_cold_boot &&
364 (!(pon_reason & HARD_RST)) &&
365 (!(pon_reason & KPDPWR_N)) &&
366 ((pon_reason & USB_CHG) || (pon_reason & DC_CHG)))
367 return 1;
368 else
369 return 0;
Deepa Dinamani004eb322013-03-25 13:20:50 -0700370}
371
Deepa Dinamani98cf8ee2013-03-27 15:16:47 -0700372void target_usb_stop(void)
373{
374 /* Disable VBUS mimicing in the controller. */
375 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
376}
377
378void target_usb_init(void)
379{
380 uint32_t val;
381
382 /* Select and enable external configuration with USB PHY */
383 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
384
385 /* Enable sess_vld */
386 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
387 writel(val, USB_GENCONFIG_2);
388
389 /* Enable external vbus configuration in the LINK */
390 val = readl(USB_USBCMD);
391 val |= SESS_VLD_CTRL;
392 writel(val, USB_USBCMD);
393}
394
395
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800396unsigned board_machtype(void)
397{
Deepa Dinamani2b795bb2013-03-25 11:31:58 -0700398 return 0;
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800399}
Channagoud Kadabie1b75262013-05-08 12:58:39 -0700400
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700401static void set_sdc_power_ctrl()
Channagoud Kadabie1b75262013-05-08 12:58:39 -0700402{
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700403 /* Drive strength configs for sdc pins */
404 struct tlmm_cfgs sdc1_hdrv_cfg[] =
405 {
406 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
407 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
Unnati Gandhiea8381d2014-02-24 15:58:22 +0530408 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK },
Channagoud Kadabi25e4d932013-05-10 17:54:29 -0700409 };
410
411 /* Pull configs for sdc pins */
412 struct tlmm_cfgs sdc1_pull_cfg[] =
413 {
414 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
415 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
416 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
417 };
418
419 /* Set the drive strength & pull control values */
420 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
421 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
422}
423
424struct mmc_device *target_mmc_device()
425{
426 return dev;
Channagoud Kadabie1b75262013-05-08 12:58:39 -0700427}