blob: 64927a06e25533e5add5b6f40933cd59040c6219 [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 Dinamani7dc3d4b2013-02-08 16:40:38 -080043
44#define PMIC_ARB_CHANNEL_NUM 0
45#define PMIC_ARB_OWNER_ID 0
46
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070047#define TLMM_VOL_UP_BTN_GPIO 72
48
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080049static uint32_t mmc_sdc_base[] =
50 { MSM_SDC1_BASE, MSM_SDC2_BASE };
51
52void target_early_init(void)
53{
54#if WITH_DEBUG_UART
Deepa Dinamanid1823b42013-03-21 11:49:35 -070055 uart_dm_init(2, 0, BLSP1_UART1_BASE);
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080056#endif
57}
58
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070059/* Return 1 if vol_up pressed */
60static int target_volume_up()
61{
62 uint8_t status = 0;
63
64 gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
65
66 /* Get status of GPIO */
67 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
68
69 /* Active low signal. */
70 return !status;
71}
72
73/* Return 1 if vol_down pressed */
74uint32_t target_volume_down()
75{
76 /* Volume down button tied in with PMIC RESIN. */
77 return pm8x41_resin_status();
78}
79
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080080static void target_keystatus()
81{
Deepa Dinamani8ff46f02013-03-20 17:52:14 -070082 keys_init();
83
84 if(target_volume_down())
85 keys_post_event(KEY_VOLUMEDOWN, 1);
86
87 if(target_volume_up())
88 keys_post_event(KEY_VOLUMEUP, 1);
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -080089}
90
91void target_init(void)
92{
93 uint32_t base_addr;
94 uint8_t slot;
95
96 dprintf(INFO, "target_init()\n");
97
98 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
99
Deepa Dinamani8ff46f02013-03-20 17:52:14 -0700100 target_keystatus();
101
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800102 /* Trying Slot 1*/
103 slot = 1;
104 base_addr = mmc_sdc_base[slot - 1];
105
106 if (mmc_boot_main(slot, base_addr))
107 {
108 /* Trying Slot 2 next */
109 slot = 2;
110 base_addr = mmc_sdc_base[slot - 1];
111
112 if (mmc_boot_main(slot, base_addr))
113 {
114 dprintf(CRITICAL, "mmc init failed!");
115 ASSERT(0);
116 }
117 }
118}
119
Deepa Dinamani2b795bb2013-03-25 11:31:58 -0700120/* Do any target specific intialization needed before entering fastboot mode */
121void target_fastboot_init(void)
122{
123 /* Set the BOOT_DONE flag in PM8110 */
124 pm8x41_set_boot_done();
125}
126
Deepa Dinamani41803e02013-03-25 11:44:15 -0700127/* Detect the target type */
128void target_detect(struct board_data *board)
129{
130 board->target = LINUX_MACHTYPE_UNKNOWN;
131}
132
133/* Detect the modem type */
134void target_baseband_detect(struct board_data *board)
135{
136 uint32_t platform;
137 uint32_t platform_subtype;
138
139 platform = board->platform;
140 platform_subtype = board->platform_subtype;
141
142 /*
143 * Look for platform subtype if present, else
144 * check for platform type to decide on the
145 * baseband type
146 */
147 switch(platform_subtype)
148 {
149 case HW_PLATFORM_SUBTYPE_UNKNOWN:
150 break;
151 default:
152 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype);
153 ASSERT(0);
154 };
155
156 switch(platform)
157 {
158 case MSM8610:
159 case MSM8110:
160 case MSM8210:
161 case MSM8810:
162 board->baseband = BASEBAND_MSM;
163 break;
164 default:
165 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
166 ASSERT(0);
167 };
168}
169
170unsigned target_baseband()
171{
172 return board_baseband();
173}
174
Deepa Dinamania6d1b752013-03-25 11:47:20 -0700175void target_serialno(unsigned char *buf)
176{
177 uint32_t serialno;
178 if (target_is_emmc_boot()) {
179 serialno = mmc_get_psn();
180 snprintf((char *)buf, 13, "%x", serialno);
181 }
182}
183
Deepa Dinamani5390e102013-03-25 11:55:31 -0700184unsigned check_reboot_mode(void)
185{
186 uint32_t restart_reason = 0;
187
188 /* Read reboot reason and scrub it */
189 restart_reason = readl(RESTART_REASON_ADDR);
190 writel(0x00, RESTART_REASON_ADDR);
191
192 return restart_reason;
193}
194
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800195unsigned board_machtype(void)
196{
Deepa Dinamani2b795bb2013-03-25 11:31:58 -0700197 return 0;
Deepa Dinamani7dc3d4b2013-02-08 16:40:38 -0800198}