blob: f2bdc68df430687b66c7d89bb1ed4221e873f3df [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>
sundarajan srinivasana098d832013-03-07 12:19:30 -080045#include <partition_parser.h>
46#include <scm.h>
47#include <platform/clock.h>
Deepa Dinamanib9a57202012-12-20 18:05:11 -080048
49extern bool target_use_signed_kernel(void);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080050
51static unsigned int target_id;
Deepa Dinamani07f15712013-03-08 17:02:13 -080052static uint32_t pmic_ver;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080053
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080054#define PMIC_ARB_CHANNEL_NUM 0
55#define PMIC_ARB_OWNER_ID 0
56
Deepa Dinamani1e094942012-10-30 15:49:02 -070057#define WDOG_DEBUG_DISABLE_BIT 17
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080058
Deepa Dinamanib9a57202012-12-20 18:05:11 -080059#define CE_INSTANCE 2
60#define CE_EE 1
61#define CE_FIFO_SIZE 64
62#define CE_READ_PIPE 3
63#define CE_WRITE_PIPE 2
64#define CE_ARRAY_SIZE 20
65
sundarajan srinivasana098d832013-03-07 12:19:30 -080066#ifdef SSD_ENABLE
67#define SSD_CE_INSTANCE_1 1
68#define SSD_PARTITION_SIZE 8192
69#endif
70
Deepa Dinamanica5ad852012-05-07 18:19:47 -070071static uint32_t mmc_sdc_base[] =
72 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
73
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080074void target_early_init(void)
75{
Deepa Dinamanib073ba22012-08-10 11:06:41 -070076#if WITH_DEBUG_UART
Neeti Desaiac011272012-08-29 18:24:54 -070077 uart_dm_init(1, 0, BLSP1_UART1_BASE);
Deepa Dinamanib073ba22012-08-10 11:06:41 -070078#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080079}
80
Deepa Dinamani9a612932012-08-14 16:15:03 -070081/* Return 1 if vol_up pressed */
82static int target_volume_up()
83{
84 uint8_t status = 0;
85 struct pm8x41_gpio gpio;
86
87 /* CDP vol_up seems to be always grounded. So gpio status is read as 0,
88 * whether key is pressed or not.
89 * Ignore volume_up key on CDP for now.
90 */
91 if (board_hardware_id() == HW_PLATFORM_SURF)
92 return 0;
93
94 /* Configure the GPIO */
95 gpio.direction = PM_GPIO_DIR_IN;
96 gpio.function = 0;
97 gpio.pull = PM_GPIO_PULL_UP_30;
Eugene Yasman6382ee02013-01-16 13:00:56 +020098 gpio.vin_sel = 2;
Deepa Dinamani9a612932012-08-14 16:15:03 -070099
100 pm8x41_gpio_config(5, &gpio);
101
102 /* Get status of P_GPIO_5 */
103 pm8x41_gpio_get(5, &status);
104
105 return !status; /* active low */
106}
107
108/* Return 1 if vol_down pressed */
Deepa Dinamani66a87962013-02-04 10:39:30 -0800109uint32_t target_volume_down()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700110{
Deepa Dinamani66a87962013-02-04 10:39:30 -0800111 /* Volume down button is tied in with RESIN on MSM8974. */
Deepa Dinamani07f15712013-03-08 17:02:13 -0800112 if (pmic_ver == PMIC_VERSION_V2)
Deepa Dinamani13bfc852013-02-05 17:56:47 -0800113 return pm8x41_resin_bark_workaround_status();
114 else
115 return pm8x41_resin_status();
Deepa Dinamani9a612932012-08-14 16:15:03 -0700116}
117
118static void target_keystatus()
119{
120 keys_init();
121
122 if(target_volume_down())
123 keys_post_event(KEY_VOLUMEDOWN, 1);
124
125 if(target_volume_up())
126 keys_post_event(KEY_VOLUMEUP, 1);
127}
128
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800129/* Set up params for h/w CE. */
130void target_crypto_init_params()
131{
132 struct crypto_init_params ce_params;
133
134 /* Set up base addresses and instance. */
135 ce_params.crypto_instance = CE_INSTANCE;
136 ce_params.crypto_base = MSM_CE2_BASE;
137 ce_params.bam_base = MSM_CE2_BAM_BASE;
138
139 /* Set up BAM config. */
140 ce_params.bam_ee = CE_EE;
141 ce_params.pipes.read_pipe = CE_READ_PIPE;
142 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
143
144 /* Assign buffer sizes. */
145 ce_params.num_ce = CE_ARRAY_SIZE;
146 ce_params.read_fifo_size = CE_FIFO_SIZE;
147 ce_params.write_fifo_size = CE_FIFO_SIZE;
148
149 crypto_init_params(&ce_params);
150}
151
152crypto_engine_type board_ce_type(void)
153{
154 return CRYPTO_ENGINE_TYPE_HW;
155}
156
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800157void target_init(void)
158{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700159 uint32_t base_addr;
160 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800161
162 dprintf(INFO, "target_init()\n");
163
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800164 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800165
Deepa Dinamani07f15712013-03-08 17:02:13 -0800166 /* Save PM8941 version info. */
167 pmic_ver = pm8x41_get_pmic_rev();
168
Deepa Dinamani9a612932012-08-14 16:15:03 -0700169 target_keystatus();
170
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800171 if (target_use_signed_kernel())
172 target_crypto_init_params();
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800173 /* Display splash screen if enabled */
174#if DISPLAY_SPLASH_SCREEN
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800175 dprintf(INFO, "Display Init: Start\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800176 display_init();
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800177 dprintf(INFO, "Display Init: Done\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800178#endif
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800179
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700180 /* Trying Slot 1*/
181 slot = 1;
182 base_addr = mmc_sdc_base[slot - 1];
183 if (mmc_boot_main(slot, base_addr))
184 {
Deepa Dinamanid18b47a2012-06-27 13:06:03 -0700185
186 /* Trying Slot 2 next */
187 slot = 2;
188 base_addr = mmc_sdc_base[slot - 1];
189 if (mmc_boot_main(slot, base_addr)) {
190 dprintf(CRITICAL, "mmc init failed!");
191 ASSERT(0);
192 }
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700193 }
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800194}
195
196unsigned board_machtype(void)
197{
198 return target_id;
199}
200
201/* Do any target specific intialization needed before entering fastboot mode */
sundarajan srinivasana098d832013-03-07 12:19:30 -0800202#ifdef SSD_ENABLE
203static uint32_t buffer[SSD_PARTITION_SIZE] __attribute__ ((aligned(32)));
204static void ssd_load_keystore_from_emmc()
205{
206 uint64_t ptn = 0;
207 int index = -1;
208 uint32_t size = SSD_PARTITION_SIZE;
209 int ret = -1;
210
211 index = partition_get_index("ssd");
212
213 ptn = partition_get_offset(index);
214 if(ptn == 0){
215 dprintf(CRITICAL,"ERROR: ssd parition not found");
216 return;
217 }
218
219 if(mmc_read(ptn, buffer, size)){
220 dprintf(CRITICAL,"ERROR:Cannot read data\n");
221 return;
222 }
223
224 ret = scm_protect_keystore((uint32_t *)&buffer[0],size);
225 if(ret != 0)
226 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed");
227}
228#endif
229
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800230void target_fastboot_init(void)
231{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700232 /* Set the BOOT_DONE flag in PM8921 */
233 pm8x41_set_boot_done();
sundarajan srinivasana098d832013-03-07 12:19:30 -0800234
235#ifdef SSD_ENABLE
236 clock_ce_enable(SSD_CE_INSTANCE_1);
237 ssd_load_keystore_from_emmc();
238#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800239}
Neeti Desai465491e2012-07-31 12:53:35 -0700240
241/* Detect the target type */
242void target_detect(struct board_data *board)
243{
244 board->target = LINUX_MACHTYPE_UNKNOWN;
245}
246
247/* Detect the modem type */
248void target_baseband_detect(struct board_data *board)
249{
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800250 uint32_t platform;
251 uint32_t platform_subtype;
252
253 platform = board->platform;
254 platform_subtype = board->platform_subtype;
255
256 /*
257 * Look for platform subtype if present, else
258 * check for platform type to decide on the
259 * baseband type
260 */
261 switch(platform_subtype) {
262 case HW_PLATFORM_SUBTYPE_UNKNOWN:
263 break;
264 default:
265 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype);
266 ASSERT(0);
267 };
268
269 switch(platform) {
270 case MSM8974:
Neeti Desai465491e2012-07-31 12:53:35 -0700271 board->baseband = BASEBAND_MSM;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800272 break;
273 case APQ8074:
274 board->baseband = BASEBAND_APQ;
275 break;
276 default:
277 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
278 ASSERT(0);
279 };
Neeti Desai465491e2012-07-31 12:53:35 -0700280}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700281
282void target_serialno(unsigned char *buf)
283{
284 unsigned int serialno;
285 if (target_is_emmc_boot()) {
286 serialno = mmc_get_psn();
287 snprintf((char *)buf, 13, "%x", serialno);
288 }
289}
Amol Jadi6639d452012-08-16 14:51:19 -0700290
291unsigned check_reboot_mode(void)
292{
293 uint32_t restart_reason = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800294 uint32_t soc_ver = 0;
295 uint32_t restart_reason_addr;
296
297 soc_ver = board_soc_version();
298
299 if (soc_ver >= BOARD_SOC_VERSION2)
300 restart_reason_addr = RESTART_REASON_ADDR_V2;
301 else
302 restart_reason_addr = RESTART_REASON_ADDR;
Amol Jadi6639d452012-08-16 14:51:19 -0700303
304 /* Read reboot reason and scrub it */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800305 restart_reason = readl(restart_reason_addr);
306 writel(0x00, restart_reason_addr);
Amol Jadi6639d452012-08-16 14:51:19 -0700307
308 return restart_reason;
309}
Neeti Desai120b55d2012-08-20 17:15:56 -0700310
311void reboot_device(unsigned reboot_reason)
312{
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800313 uint32_t soc_ver = 0;
314
315 soc_ver = board_soc_version();
316
Neeti Desai120b55d2012-08-20 17:15:56 -0700317 /* Write the reboot reason */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800318 if (soc_ver >= BOARD_SOC_VERSION2)
319 writel(reboot_reason, RESTART_REASON_ADDR_V2);
320 else
321 writel(reboot_reason, RESTART_REASON_ADDR);
Neeti Desai120b55d2012-08-20 17:15:56 -0700322
323 /* Configure PMIC for warm reset */
Deepa Dinamani07f15712013-03-08 17:02:13 -0800324 if (pmic_ver == PMIC_VERSION_V2)
325 pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET);
326 else
327 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
Neeti Desai120b55d2012-08-20 17:15:56 -0700328
Deepa Dinamani1e094942012-10-30 15:49:02 -0700329 /* Disable Watchdog Debug.
330 * Required becuase of a H/W bug which causes the system to
331 * reset partially even for non watchdog resets.
332 */
333 writel(readl(GCC_WDOG_DEBUG) & ~(1 << WDOG_DEBUG_DISABLE_BIT), GCC_WDOG_DEBUG);
334
Deepa Dinamanie0808e52012-11-26 15:22:46 -0800335 dsb();
336
337 /* Wait until the write takes effect. */
338 while(readl(GCC_WDOG_DEBUG) & (1 << WDOG_DEBUG_DISABLE_BIT));
339
Neeti Desai120b55d2012-08-20 17:15:56 -0700340 /* Drop PS_HOLD for MSM */
341 writel(0x00, MPM2_MPM_PS_HOLD);
342
343 mdelay(5000);
344
345 dprintf(CRITICAL, "Rebooting failed\n");
346}
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800347
Eugene Yasmana0d18122013-02-26 13:23:05 +0200348/* Do target specific usb initialization */
349void target_usb_init(void)
350{
351 /* Enable secondary USB PHY on DragonBoard8074 */
352 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
353 /* Route ChipIDea to use secondary USB HS port2 */
354 writel_relaxed(1, USB2_PHY_SEL);
355
356 /* Enable access to secondary PHY by clamping the low
357 * voltage interface between DVDD of the PHY and Vddcx
358 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
359 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
360 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
361
362 /* Perform power-on-reset of the PHY.
363 * Delay values are arbitrary */
364 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
365 USB_OTG_HS_PHY_CTRL);
366 thread_sleep(10);
367 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
368 USB_OTG_HS_PHY_CTRL);
369 thread_sleep(10);
370
371 /* Enable HSUSB PHY port for ULPI interface,
372 * then configure related parameters within the PHY */
373 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
374 | 0x8c000004), USB_PORTSC);
375 }
376}
377
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800378/* Returns 1 if target supports continuous splash screen. */
379int target_cont_splash_screen()
380{
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800381 switch(board_hardware_id())
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800382 {
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800383 case HW_PLATFORM_SURF:
384 case HW_PLATFORM_MTP:
385 case HW_PLATFORM_FLUID:
386 dprintf(SPEW, "Target_cont_splash=1\n");
387 return 1;
388 break;
389 default:
390 dprintf(SPEW, "Target_cont_splash=0\n");
391 return 0;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800392 }
393}
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800394
395unsigned target_pause_for_battery_charge(void)
396{
397 uint8_t pon_reason = pm8x41_get_pon_reason();
398
399 /* This function will always return 0 to facilitate
400 * automated testing/reboot with usb connected.
401 * uncomment if this feature is needed */
402 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
403 return 1;*/
404
405 return 0;
406}
sundarajan srinivasana098d832013-03-07 12:19:30 -0800407
408void target_usb_stop(void)
409{
410#ifdef SSD_ENABLE
411 clock_ce_disable(SSD_CE_INSTANCE_1);
412#endif
413}