blob: e7b6a229e8486a6c60fab7c2ca5b3565fa4d0ef8 [file] [log] [blame]
Deepa Dinamani645e9b12012-12-21 14:23:40 -08001/* Copyright (c) 2012-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 Dinamani7e729772013-02-25 11:54:05 -080036#include <platform/gpio.h>
Deepa Dinamani645e9b12012-12-21 14:23:40 -080037#include <spmi.h>
38#include <board.h>
Deepa Dinamaniff2b9ce2013-02-25 11:01:00 -080039#include <smem.h>
40#include <baseband.h>
Deepa Dinamani7e729772013-02-25 11:54:05 -080041#include <dev/keys.h>
Deepa Dinamani058f1cd2013-02-25 10:53:01 -080042#include <pm8x41.h>
Deepa Dinamani6bb87d52013-02-26 14:37:36 -080043#include <crypto5_wrapper.h>
Amol Jadi85e19192013-02-28 22:45:04 -080044#include <hsusb.h>
Deepa Dinamani645e9b12012-12-21 14:23:40 -080045
Deepa Dinamani6bb87d52013-02-26 14:37:36 -080046extern bool target_use_signed_kernel(void);
47
48#define PMIC_ARB_CHANNEL_NUM 0
49#define PMIC_ARB_OWNER_ID 0
50
51#define CRYPTO_ENGINE_INSTANCE 1
52#define CRYPTO_ENGINE_EE 1
53#define CRYPTO_ENGINE_FIFO_SIZE 64
54#define CRYPTO_ENGINE_READ_PIPE 3
55#define CRYPTO_ENGINE_WRITE_PIPE 2
56#define CRYPTO_ENGINE_CMD_ARRAY_SIZE 20
Deepa Dinamani645e9b12012-12-21 14:23:40 -080057
Deepa Dinamani7e729772013-02-25 11:54:05 -080058#define TLMM_VOL_UP_BTN_GPIO 106
59
Deepa Dinamani645e9b12012-12-21 14:23:40 -080060static uint32_t mmc_sdc_base[] =
Deepa Dinamani7c79d7d2013-02-08 13:47:08 -080061 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE };
Deepa Dinamani645e9b12012-12-21 14:23:40 -080062
63void target_early_init(void)
64{
65#if WITH_DEBUG_UART
Deepa Dinamani0a6c48c2013-02-04 15:45:01 -080066 uart_dm_init(1, 0, BLSP1_UART2_BASE);
Deepa Dinamani645e9b12012-12-21 14:23:40 -080067#endif
68}
69
Deepa Dinamani7e729772013-02-25 11:54:05 -080070/* Return 1 if vol_up pressed */
71static int target_volume_up()
72{
73 uint8_t status = 0;
74
75 gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
76
aiquny933017c2013-03-02 12:48:52 -080077 thread_sleep(10);
78
Deepa Dinamani7e729772013-02-25 11:54:05 -080079 /* Get status of GPIO */
80 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
81
82 /* Active low signal. */
83 return !status;
84}
85
86/* Return 1 if vol_down pressed */
87uint32_t target_volume_down()
88{
89 /* Volume down button tied in with PMIC RESIN. */
90 return pm8x41_resin_status();
91}
92
Deepa Dinamani645e9b12012-12-21 14:23:40 -080093static void target_keystatus()
94{
Deepa Dinamani7e729772013-02-25 11:54:05 -080095 keys_init();
96
97 if(target_volume_down())
98 keys_post_event(KEY_VOLUMEDOWN, 1);
99
100 if(target_volume_up())
101 keys_post_event(KEY_VOLUMEUP, 1);
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800102}
103
Deepa Dinamani6bb87d52013-02-26 14:37:36 -0800104/* Set up params for h/w CRYPTO_ENGINE. */
105void target_crypto_init_params()
106{
107 struct crypto_init_params ce_params;
108
109 /* Set up base addresses and instance. */
110 ce_params.crypto_instance = CRYPTO_ENGINE_INSTANCE;
111 ce_params.crypto_base = MSM_CE1_BASE;
112 ce_params.bam_base = MSM_CE1_BAM_BASE;
113
114 /* Set up BAM config. */
115 ce_params.bam_ee = CRYPTO_ENGINE_EE;
116 ce_params.pipes.read_pipe = CRYPTO_ENGINE_READ_PIPE;
117 ce_params.pipes.write_pipe = CRYPTO_ENGINE_WRITE_PIPE;
118
119 /* Assign buffer sizes. */
120 ce_params.num_ce = CRYPTO_ENGINE_CMD_ARRAY_SIZE;
121 ce_params.read_fifo_size = CRYPTO_ENGINE_FIFO_SIZE;
122 ce_params.write_fifo_size = CRYPTO_ENGINE_FIFO_SIZE;
123
124 crypto_init_params(&ce_params);
125}
126
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800127void target_init(void)
128{
129 uint32_t base_addr;
130 uint8_t slot;
131
132 dprintf(INFO, "target_init()\n");
133
134 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
135
136 target_keystatus();
137
138 /* Trying Slot 1*/
139 slot = 1;
140 base_addr = mmc_sdc_base[slot - 1];
141 if (mmc_boot_main(slot, base_addr))
142 {
143
144 /* Trying Slot 2 next */
145 slot = 2;
146 base_addr = mmc_sdc_base[slot - 1];
147 if (mmc_boot_main(slot, base_addr)) {
148 dprintf(CRITICAL, "mmc init failed!");
149 ASSERT(0);
150 }
151 }
Deepa Dinamani6bb87d52013-02-26 14:37:36 -0800152
153 if (target_use_signed_kernel())
154 target_crypto_init_params();
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800155}
156
Deepa Dinamani058f1cd2013-02-25 10:53:01 -0800157/* Do any target specific intialization needed before entering fastboot mode */
158void target_fastboot_init(void)
159{
160 /* Set the BOOT_DONE flag in PM8026 */
161 pm8x41_set_boot_done();
162}
163
Deepa Dinamaniff2b9ce2013-02-25 11:01:00 -0800164/* Detect the target type */
165void target_detect(struct board_data *board)
166{
167 board->target = LINUX_MACHTYPE_UNKNOWN;
168}
169
170/* Detect the modem type */
171void target_baseband_detect(struct board_data *board)
172{
173 uint32_t platform;
174 uint32_t platform_subtype;
175
176 platform = board->platform;
177 platform_subtype = board->platform_subtype;
178
179 /*
180 * Look for platform subtype if present, else
181 * check for platform type to decide on the
182 * baseband type
183 */
184 switch(platform_subtype)
185 {
186 case HW_PLATFORM_SUBTYPE_UNKNOWN:
187 break;
188 default:
189 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype);
190 ASSERT(0);
191 };
192
193 switch(platform)
194 {
195 case MSM8826:
196 case MSM8626:
197 case MSM8226:
198 board->baseband = BASEBAND_MSM;
199 break;
200 default:
201 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
202 ASSERT(0);
203 };
204}
205
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800206void target_serialno(unsigned char *buf)
207{
208 uint32_t serialno;
209 if (target_is_emmc_boot()) {
210 serialno = mmc_get_psn();
211 snprintf((char *)buf, 13, "%x", serialno);
212 }
213}
214
Deepa Dinamani8d2bb222013-02-26 14:03:04 -0800215unsigned check_reboot_mode(void)
216{
217 uint32_t restart_reason = 0;
218
219 /* Read reboot reason and scrub it */
220 restart_reason = readl(RESTART_REASON_ADDR);
221 writel(0x00, RESTART_REASON_ADDR);
222
223 return restart_reason;
224}
225
Deepa Dinamanif7c03c12013-02-26 14:17:20 -0800226void reboot_device(unsigned reboot_reason)
227{
228 writel(reboot_reason, RESTART_REASON_ADDR);
229
230 /* Configure PMIC for warm reset */
231 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
232
233 /* Drop PS_HOLD for MSM */
234 writel(0x00, MPM2_MPM_PS_HOLD);
235
236 mdelay(5000);
237
238 dprintf(CRITICAL, "Rebooting failed\n");
239}
240
Deepa Dinamani6bb87d52013-02-26 14:37:36 -0800241crypto_engine_type board_ce_type(void)
242{
243 return CRYPTO_ENGINE_TYPE_HW;
244}
245
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800246unsigned board_machtype(void)
247{
248}
Amol Jadi85e19192013-02-28 22:45:04 -0800249
250void target_usb_init(void)
251{
252 uint32_t val;
253
254 /* Select and enable external configuration with USB PHY */
255 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
256
257 /* Enable sess_vld */
258 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
259 writel(val, USB_GENCONFIG_2);
260
261 /* Enable external vbus configuration in the LINK */
262 val = readl(USB_USBCMD);
263 val |= SESS_VLD_CTRL;
264 writel(val, USB_USBCMD);
265}