blob: 2bbc017addfa473154284f7be9f158ed3c3320aa [file] [log] [blame]
Eugene Yasman6382ee02013-01-16 13:00:56 +02001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Deepa Dinamani7d6c8972011-12-14 15:16:56 -08002 *
3 * Redistribution and use in source and binary forms, with or without
Deepa Dinamani1e094942012-10-30 15:49:02 -07004 * 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.
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080015 *
Deepa Dinamani1e094942012-10-30 15:49:02 -070016 * 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.
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080027 */
28
29#include <debug.h>
30#include <platform/iomap.h>
31#include <reg.h>
32#include <target.h>
33#include <platform.h>
Deepa Dinamani26e93262012-05-21 17:35:14 -070034#include <uart_dm.h>
Amol Jadi29f95032012-06-22 12:52:54 -070035#include <mmc.h>
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080036#include <spmi.h>
Neeti Desai465491e2012-07-31 12:53:35 -070037#include <board.h>
38#include <smem.h>
39#include <baseband.h>
Deepa Dinamani9a612932012-08-14 16:15:03 -070040#include <dev/keys.h>
41#include <pm8x41.h>
Deepa Dinamanib9a57202012-12-20 18:05:11 -080042#include <crypto5_wrapper.h>
Eugene Yasmana0d18122013-02-26 13:23:05 +020043#include <hsusb.h>
44#include <clock.h>
Deepa Dinamanib9a57202012-12-20 18:05:11 -080045
46extern bool target_use_signed_kernel(void);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080047
48static unsigned int target_id;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080049
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080050#define PMIC_ARB_CHANNEL_NUM 0
51#define PMIC_ARB_OWNER_ID 0
52
Deepa Dinamani1e094942012-10-30 15:49:02 -070053#define WDOG_DEBUG_DISABLE_BIT 17
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080054
Deepa Dinamanib9a57202012-12-20 18:05:11 -080055#define CE_INSTANCE 2
56#define CE_EE 1
57#define CE_FIFO_SIZE 64
58#define CE_READ_PIPE 3
59#define CE_WRITE_PIPE 2
60#define CE_ARRAY_SIZE 20
61
Deepa Dinamanica5ad852012-05-07 18:19:47 -070062static uint32_t mmc_sdc_base[] =
63 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
64
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080065void target_early_init(void)
66{
Deepa Dinamanib073ba22012-08-10 11:06:41 -070067#if WITH_DEBUG_UART
Neeti Desaiac011272012-08-29 18:24:54 -070068 uart_dm_init(1, 0, BLSP1_UART1_BASE);
Deepa Dinamanib073ba22012-08-10 11:06:41 -070069#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080070}
71
Deepa Dinamani9a612932012-08-14 16:15:03 -070072/* Return 1 if vol_up pressed */
73static int target_volume_up()
74{
75 uint8_t status = 0;
76 struct pm8x41_gpio gpio;
77
78 /* CDP vol_up seems to be always grounded. So gpio status is read as 0,
79 * whether key is pressed or not.
80 * Ignore volume_up key on CDP for now.
81 */
82 if (board_hardware_id() == HW_PLATFORM_SURF)
83 return 0;
84
85 /* Configure the GPIO */
86 gpio.direction = PM_GPIO_DIR_IN;
87 gpio.function = 0;
88 gpio.pull = PM_GPIO_PULL_UP_30;
Eugene Yasman6382ee02013-01-16 13:00:56 +020089 gpio.vin_sel = 2;
Deepa Dinamani9a612932012-08-14 16:15:03 -070090
91 pm8x41_gpio_config(5, &gpio);
92
93 /* Get status of P_GPIO_5 */
94 pm8x41_gpio_get(5, &status);
95
96 return !status; /* active low */
97}
98
99/* Return 1 if vol_down pressed */
Deepa Dinamani66a87962013-02-04 10:39:30 -0800100uint32_t target_volume_down()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700101{
Deepa Dinamani66a87962013-02-04 10:39:30 -0800102 /* Volume down button is tied in with RESIN on MSM8974. */
Deepa Dinamani13bfc852013-02-05 17:56:47 -0800103 if (pm8x41_get_pmic_rev() == PMIC_VERSION_V2)
104 return pm8x41_resin_bark_workaround_status();
105 else
106 return pm8x41_resin_status();
Deepa Dinamani9a612932012-08-14 16:15:03 -0700107}
108
109static void target_keystatus()
110{
111 keys_init();
112
113 if(target_volume_down())
114 keys_post_event(KEY_VOLUMEDOWN, 1);
115
116 if(target_volume_up())
117 keys_post_event(KEY_VOLUMEUP, 1);
118}
119
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800120/* Set up params for h/w CE. */
121void target_crypto_init_params()
122{
123 struct crypto_init_params ce_params;
124
125 /* Set up base addresses and instance. */
126 ce_params.crypto_instance = CE_INSTANCE;
127 ce_params.crypto_base = MSM_CE2_BASE;
128 ce_params.bam_base = MSM_CE2_BAM_BASE;
129
130 /* Set up BAM config. */
131 ce_params.bam_ee = CE_EE;
132 ce_params.pipes.read_pipe = CE_READ_PIPE;
133 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
134
135 /* Assign buffer sizes. */
136 ce_params.num_ce = CE_ARRAY_SIZE;
137 ce_params.read_fifo_size = CE_FIFO_SIZE;
138 ce_params.write_fifo_size = CE_FIFO_SIZE;
139
140 crypto_init_params(&ce_params);
141}
142
143crypto_engine_type board_ce_type(void)
144{
145 return CRYPTO_ENGINE_TYPE_HW;
146}
147
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800148void target_init(void)
149{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700150 uint32_t base_addr;
151 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800152
153 dprintf(INFO, "target_init()\n");
154
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800155 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800156
Deepa Dinamani9a612932012-08-14 16:15:03 -0700157 target_keystatus();
158
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800159 if (target_use_signed_kernel())
160 target_crypto_init_params();
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800161 /* Display splash screen if enabled */
162#if DISPLAY_SPLASH_SCREEN
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800163 dprintf(INFO, "Display Init: Start\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800164 display_init();
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800165 dprintf(INFO, "Display Init: Done\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800166#endif
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800167
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700168 /* Trying Slot 1*/
169 slot = 1;
170 base_addr = mmc_sdc_base[slot - 1];
171 if (mmc_boot_main(slot, base_addr))
172 {
Deepa Dinamanid18b47a2012-06-27 13:06:03 -0700173
174 /* Trying Slot 2 next */
175 slot = 2;
176 base_addr = mmc_sdc_base[slot - 1];
177 if (mmc_boot_main(slot, base_addr)) {
178 dprintf(CRITICAL, "mmc init failed!");
179 ASSERT(0);
180 }
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700181 }
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800182}
183
184unsigned board_machtype(void)
185{
186 return target_id;
187}
188
189/* Do any target specific intialization needed before entering fastboot mode */
190void target_fastboot_init(void)
191{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700192 /* Set the BOOT_DONE flag in PM8921 */
193 pm8x41_set_boot_done();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800194}
Neeti Desai465491e2012-07-31 12:53:35 -0700195
196/* Detect the target type */
197void target_detect(struct board_data *board)
198{
199 board->target = LINUX_MACHTYPE_UNKNOWN;
200}
201
202/* Detect the modem type */
203void target_baseband_detect(struct board_data *board)
204{
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800205 uint32_t platform;
206 uint32_t platform_subtype;
207
208 platform = board->platform;
209 platform_subtype = board->platform_subtype;
210
211 /*
212 * Look for platform subtype if present, else
213 * check for platform type to decide on the
214 * baseband type
215 */
216 switch(platform_subtype) {
217 case HW_PLATFORM_SUBTYPE_UNKNOWN:
218 break;
219 default:
220 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype);
221 ASSERT(0);
222 };
223
224 switch(platform) {
225 case MSM8974:
Neeti Desai465491e2012-07-31 12:53:35 -0700226 board->baseband = BASEBAND_MSM;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800227 break;
228 case APQ8074:
229 board->baseband = BASEBAND_APQ;
230 break;
231 default:
232 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
233 ASSERT(0);
234 };
Neeti Desai465491e2012-07-31 12:53:35 -0700235}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700236
237void target_serialno(unsigned char *buf)
238{
239 unsigned int serialno;
240 if (target_is_emmc_boot()) {
241 serialno = mmc_get_psn();
242 snprintf((char *)buf, 13, "%x", serialno);
243 }
244}
Amol Jadi6639d452012-08-16 14:51:19 -0700245
246unsigned check_reboot_mode(void)
247{
248 uint32_t restart_reason = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800249 uint32_t soc_ver = 0;
250 uint32_t restart_reason_addr;
251
252 soc_ver = board_soc_version();
253
254 if (soc_ver >= BOARD_SOC_VERSION2)
255 restart_reason_addr = RESTART_REASON_ADDR_V2;
256 else
257 restart_reason_addr = RESTART_REASON_ADDR;
Amol Jadi6639d452012-08-16 14:51:19 -0700258
259 /* Read reboot reason and scrub it */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800260 restart_reason = readl(restart_reason_addr);
261 writel(0x00, restart_reason_addr);
Amol Jadi6639d452012-08-16 14:51:19 -0700262
263 return restart_reason;
264}
Neeti Desai120b55d2012-08-20 17:15:56 -0700265
266void reboot_device(unsigned reboot_reason)
267{
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800268 uint32_t soc_ver = 0;
269
270 soc_ver = board_soc_version();
271
Neeti Desai120b55d2012-08-20 17:15:56 -0700272 /* Write the reboot reason */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800273 if (soc_ver >= BOARD_SOC_VERSION2)
274 writel(reboot_reason, RESTART_REASON_ADDR_V2);
275 else
276 writel(reboot_reason, RESTART_REASON_ADDR);
Neeti Desai120b55d2012-08-20 17:15:56 -0700277
278 /* Configure PMIC for warm reset */
279 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
280
Deepa Dinamani1e094942012-10-30 15:49:02 -0700281 /* Disable Watchdog Debug.
282 * Required becuase of a H/W bug which causes the system to
283 * reset partially even for non watchdog resets.
284 */
285 writel(readl(GCC_WDOG_DEBUG) & ~(1 << WDOG_DEBUG_DISABLE_BIT), GCC_WDOG_DEBUG);
286
Deepa Dinamanie0808e52012-11-26 15:22:46 -0800287 dsb();
288
289 /* Wait until the write takes effect. */
290 while(readl(GCC_WDOG_DEBUG) & (1 << WDOG_DEBUG_DISABLE_BIT));
291
Neeti Desai120b55d2012-08-20 17:15:56 -0700292 /* Drop PS_HOLD for MSM */
293 writel(0x00, MPM2_MPM_PS_HOLD);
294
295 mdelay(5000);
296
297 dprintf(CRITICAL, "Rebooting failed\n");
298}
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800299
Eugene Yasmana0d18122013-02-26 13:23:05 +0200300/* Do target specific usb initialization */
301void target_usb_init(void)
302{
303 /* Enable secondary USB PHY on DragonBoard8074 */
304 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
305 /* Route ChipIDea to use secondary USB HS port2 */
306 writel_relaxed(1, USB2_PHY_SEL);
307
308 /* Enable access to secondary PHY by clamping the low
309 * voltage interface between DVDD of the PHY and Vddcx
310 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
311 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
312 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
313
314 /* Perform power-on-reset of the PHY.
315 * Delay values are arbitrary */
316 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
317 USB_OTG_HS_PHY_CTRL);
318 thread_sleep(10);
319 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
320 USB_OTG_HS_PHY_CTRL);
321 thread_sleep(10);
322
323 /* Enable HSUSB PHY port for ULPI interface,
324 * then configure related parameters within the PHY */
325 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
326 | 0x8c000004), USB_PORTSC);
327 }
328}
329
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800330/* Returns 1 if target supports continuous splash screen. */
331int target_cont_splash_screen()
332{
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800333 switch(board_hardware_id())
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800334 {
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800335 case HW_PLATFORM_SURF:
336 case HW_PLATFORM_MTP:
337 case HW_PLATFORM_FLUID:
338 dprintf(SPEW, "Target_cont_splash=1\n");
339 return 1;
340 break;
341 default:
342 dprintf(SPEW, "Target_cont_splash=0\n");
343 return 0;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800344 }
345}
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800346
347unsigned target_pause_for_battery_charge(void)
348{
349 uint8_t pon_reason = pm8x41_get_pon_reason();
350
351 /* This function will always return 0 to facilitate
352 * automated testing/reboot with usb connected.
353 * uncomment if this feature is needed */
354 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
355 return 1;*/
356
357 return 0;
358}