blob: cde6b56f90dd5e2ecdfe220b340a589866434382 [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 Dinamani7d6c8972011-12-14 15:16:56 -080052
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080053#define PMIC_ARB_CHANNEL_NUM 0
54#define PMIC_ARB_OWNER_ID 0
55
Deepa Dinamani1e094942012-10-30 15:49:02 -070056#define WDOG_DEBUG_DISABLE_BIT 17
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080057
Deepa Dinamanib9a57202012-12-20 18:05:11 -080058#define CE_INSTANCE 2
59#define CE_EE 1
60#define CE_FIFO_SIZE 64
61#define CE_READ_PIPE 3
62#define CE_WRITE_PIPE 2
63#define CE_ARRAY_SIZE 20
64
sundarajan srinivasana098d832013-03-07 12:19:30 -080065#ifdef SSD_ENABLE
66#define SSD_CE_INSTANCE_1 1
67#define SSD_PARTITION_SIZE 8192
68#endif
69
Deepa Dinamanica5ad852012-05-07 18:19:47 -070070static uint32_t mmc_sdc_base[] =
71 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
72
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080073void target_early_init(void)
74{
Deepa Dinamanib073ba22012-08-10 11:06:41 -070075#if WITH_DEBUG_UART
Neeti Desaiac011272012-08-29 18:24:54 -070076 uart_dm_init(1, 0, BLSP1_UART1_BASE);
Deepa Dinamanib073ba22012-08-10 11:06:41 -070077#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080078}
79
Deepa Dinamani9a612932012-08-14 16:15:03 -070080/* Return 1 if vol_up pressed */
81static int target_volume_up()
82{
83 uint8_t status = 0;
84 struct pm8x41_gpio gpio;
85
86 /* CDP vol_up seems to be always grounded. So gpio status is read as 0,
87 * whether key is pressed or not.
88 * Ignore volume_up key on CDP for now.
89 */
90 if (board_hardware_id() == HW_PLATFORM_SURF)
91 return 0;
92
93 /* Configure the GPIO */
94 gpio.direction = PM_GPIO_DIR_IN;
95 gpio.function = 0;
96 gpio.pull = PM_GPIO_PULL_UP_30;
Eugene Yasman6382ee02013-01-16 13:00:56 +020097 gpio.vin_sel = 2;
Deepa Dinamani9a612932012-08-14 16:15:03 -070098
99 pm8x41_gpio_config(5, &gpio);
100
101 /* Get status of P_GPIO_5 */
102 pm8x41_gpio_get(5, &status);
103
104 return !status; /* active low */
105}
106
107/* Return 1 if vol_down pressed */
Deepa Dinamani66a87962013-02-04 10:39:30 -0800108uint32_t target_volume_down()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700109{
Deepa Dinamani66a87962013-02-04 10:39:30 -0800110 /* Volume down button is tied in with RESIN on MSM8974. */
Deepa Dinamani13bfc852013-02-05 17:56:47 -0800111 if (pm8x41_get_pmic_rev() == PMIC_VERSION_V2)
112 return pm8x41_resin_bark_workaround_status();
113 else
114 return pm8x41_resin_status();
Deepa Dinamani9a612932012-08-14 16:15:03 -0700115}
116
117static void target_keystatus()
118{
119 keys_init();
120
121 if(target_volume_down())
122 keys_post_event(KEY_VOLUMEDOWN, 1);
123
124 if(target_volume_up())
125 keys_post_event(KEY_VOLUMEUP, 1);
126}
127
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800128/* Set up params for h/w CE. */
129void target_crypto_init_params()
130{
131 struct crypto_init_params ce_params;
132
133 /* Set up base addresses and instance. */
134 ce_params.crypto_instance = CE_INSTANCE;
135 ce_params.crypto_base = MSM_CE2_BASE;
136 ce_params.bam_base = MSM_CE2_BAM_BASE;
137
138 /* Set up BAM config. */
139 ce_params.bam_ee = CE_EE;
140 ce_params.pipes.read_pipe = CE_READ_PIPE;
141 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
142
143 /* Assign buffer sizes. */
144 ce_params.num_ce = CE_ARRAY_SIZE;
145 ce_params.read_fifo_size = CE_FIFO_SIZE;
146 ce_params.write_fifo_size = CE_FIFO_SIZE;
147
148 crypto_init_params(&ce_params);
149}
150
151crypto_engine_type board_ce_type(void)
152{
153 return CRYPTO_ENGINE_TYPE_HW;
154}
155
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800156void target_init(void)
157{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700158 uint32_t base_addr;
159 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800160
161 dprintf(INFO, "target_init()\n");
162
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800163 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800164
Deepa Dinamani9a612932012-08-14 16:15:03 -0700165 target_keystatus();
166
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800167 if (target_use_signed_kernel())
168 target_crypto_init_params();
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800169 /* Display splash screen if enabled */
170#if DISPLAY_SPLASH_SCREEN
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800171 dprintf(INFO, "Display Init: Start\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800172 display_init();
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800173 dprintf(INFO, "Display Init: Done\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800174#endif
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800175
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700176 /* Trying Slot 1*/
177 slot = 1;
178 base_addr = mmc_sdc_base[slot - 1];
179 if (mmc_boot_main(slot, base_addr))
180 {
Deepa Dinamanid18b47a2012-06-27 13:06:03 -0700181
182 /* Trying Slot 2 next */
183 slot = 2;
184 base_addr = mmc_sdc_base[slot - 1];
185 if (mmc_boot_main(slot, base_addr)) {
186 dprintf(CRITICAL, "mmc init failed!");
187 ASSERT(0);
188 }
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700189 }
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800190}
191
192unsigned board_machtype(void)
193{
194 return target_id;
195}
196
197/* Do any target specific intialization needed before entering fastboot mode */
sundarajan srinivasana098d832013-03-07 12:19:30 -0800198#ifdef SSD_ENABLE
199static uint32_t buffer[SSD_PARTITION_SIZE] __attribute__ ((aligned(32)));
200static void ssd_load_keystore_from_emmc()
201{
202 uint64_t ptn = 0;
203 int index = -1;
204 uint32_t size = SSD_PARTITION_SIZE;
205 int ret = -1;
206
207 index = partition_get_index("ssd");
208
209 ptn = partition_get_offset(index);
210 if(ptn == 0){
211 dprintf(CRITICAL,"ERROR: ssd parition not found");
212 return;
213 }
214
215 if(mmc_read(ptn, buffer, size)){
216 dprintf(CRITICAL,"ERROR:Cannot read data\n");
217 return;
218 }
219
220 ret = scm_protect_keystore((uint32_t *)&buffer[0],size);
221 if(ret != 0)
222 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed");
223}
224#endif
225
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800226void target_fastboot_init(void)
227{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700228 /* Set the BOOT_DONE flag in PM8921 */
229 pm8x41_set_boot_done();
sundarajan srinivasana098d832013-03-07 12:19:30 -0800230
231#ifdef SSD_ENABLE
232 clock_ce_enable(SSD_CE_INSTANCE_1);
233 ssd_load_keystore_from_emmc();
234#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800235}
Neeti Desai465491e2012-07-31 12:53:35 -0700236
237/* Detect the target type */
238void target_detect(struct board_data *board)
239{
240 board->target = LINUX_MACHTYPE_UNKNOWN;
241}
242
243/* Detect the modem type */
244void target_baseband_detect(struct board_data *board)
245{
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800246 uint32_t platform;
247 uint32_t platform_subtype;
248
249 platform = board->platform;
250 platform_subtype = board->platform_subtype;
251
252 /*
253 * Look for platform subtype if present, else
254 * check for platform type to decide on the
255 * baseband type
256 */
257 switch(platform_subtype) {
258 case HW_PLATFORM_SUBTYPE_UNKNOWN:
259 break;
260 default:
261 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype);
262 ASSERT(0);
263 };
264
265 switch(platform) {
266 case MSM8974:
Neeti Desai465491e2012-07-31 12:53:35 -0700267 board->baseband = BASEBAND_MSM;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800268 break;
269 case APQ8074:
270 board->baseband = BASEBAND_APQ;
271 break;
272 default:
273 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
274 ASSERT(0);
275 };
Neeti Desai465491e2012-07-31 12:53:35 -0700276}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700277
278void target_serialno(unsigned char *buf)
279{
280 unsigned int serialno;
281 if (target_is_emmc_boot()) {
282 serialno = mmc_get_psn();
283 snprintf((char *)buf, 13, "%x", serialno);
284 }
285}
Amol Jadi6639d452012-08-16 14:51:19 -0700286
287unsigned check_reboot_mode(void)
288{
289 uint32_t restart_reason = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800290 uint32_t soc_ver = 0;
291 uint32_t restart_reason_addr;
292
293 soc_ver = board_soc_version();
294
295 if (soc_ver >= BOARD_SOC_VERSION2)
296 restart_reason_addr = RESTART_REASON_ADDR_V2;
297 else
298 restart_reason_addr = RESTART_REASON_ADDR;
Amol Jadi6639d452012-08-16 14:51:19 -0700299
300 /* Read reboot reason and scrub it */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800301 restart_reason = readl(restart_reason_addr);
302 writel(0x00, restart_reason_addr);
Amol Jadi6639d452012-08-16 14:51:19 -0700303
304 return restart_reason;
305}
Neeti Desai120b55d2012-08-20 17:15:56 -0700306
307void reboot_device(unsigned reboot_reason)
308{
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800309 uint32_t soc_ver = 0;
310
311 soc_ver = board_soc_version();
312
Neeti Desai120b55d2012-08-20 17:15:56 -0700313 /* Write the reboot reason */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800314 if (soc_ver >= BOARD_SOC_VERSION2)
315 writel(reboot_reason, RESTART_REASON_ADDR_V2);
316 else
317 writel(reboot_reason, RESTART_REASON_ADDR);
Neeti Desai120b55d2012-08-20 17:15:56 -0700318
319 /* Configure PMIC for warm reset */
320 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
321
Deepa Dinamani1e094942012-10-30 15:49:02 -0700322 /* Disable Watchdog Debug.
323 * Required becuase of a H/W bug which causes the system to
324 * reset partially even for non watchdog resets.
325 */
326 writel(readl(GCC_WDOG_DEBUG) & ~(1 << WDOG_DEBUG_DISABLE_BIT), GCC_WDOG_DEBUG);
327
Deepa Dinamanie0808e52012-11-26 15:22:46 -0800328 dsb();
329
330 /* Wait until the write takes effect. */
331 while(readl(GCC_WDOG_DEBUG) & (1 << WDOG_DEBUG_DISABLE_BIT));
332
Neeti Desai120b55d2012-08-20 17:15:56 -0700333 /* Drop PS_HOLD for MSM */
334 writel(0x00, MPM2_MPM_PS_HOLD);
335
336 mdelay(5000);
337
338 dprintf(CRITICAL, "Rebooting failed\n");
339}
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800340
Eugene Yasmana0d18122013-02-26 13:23:05 +0200341/* Do target specific usb initialization */
342void target_usb_init(void)
343{
344 /* Enable secondary USB PHY on DragonBoard8074 */
345 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
346 /* Route ChipIDea to use secondary USB HS port2 */
347 writel_relaxed(1, USB2_PHY_SEL);
348
349 /* Enable access to secondary PHY by clamping the low
350 * voltage interface between DVDD of the PHY and Vddcx
351 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
352 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
353 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
354
355 /* Perform power-on-reset of the PHY.
356 * Delay values are arbitrary */
357 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
358 USB_OTG_HS_PHY_CTRL);
359 thread_sleep(10);
360 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
361 USB_OTG_HS_PHY_CTRL);
362 thread_sleep(10);
363
364 /* Enable HSUSB PHY port for ULPI interface,
365 * then configure related parameters within the PHY */
366 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
367 | 0x8c000004), USB_PORTSC);
368 }
369}
370
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800371/* Returns 1 if target supports continuous splash screen. */
372int target_cont_splash_screen()
373{
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800374 switch(board_hardware_id())
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800375 {
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800376 case HW_PLATFORM_SURF:
377 case HW_PLATFORM_MTP:
378 case HW_PLATFORM_FLUID:
379 dprintf(SPEW, "Target_cont_splash=1\n");
380 return 1;
381 break;
382 default:
383 dprintf(SPEW, "Target_cont_splash=0\n");
384 return 0;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800385 }
386}
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800387
388unsigned target_pause_for_battery_charge(void)
389{
390 uint8_t pon_reason = pm8x41_get_pon_reason();
391
392 /* This function will always return 0 to facilitate
393 * automated testing/reboot with usb connected.
394 * uncomment if this feature is needed */
395 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
396 return 1;*/
397
398 return 0;
399}
sundarajan srinivasana098d832013-03-07 12:19:30 -0800400
401void target_usb_stop(void)
402{
403#ifdef SSD_ENABLE
404 clock_ce_disable(SSD_CE_INSTANCE_1);
405#endif
406}