blob: 65967fb2bc5c5b39a994226642814061b4ae0c1e [file] [log] [blame]
Nagireddy Annemb2d8e9a2019-09-06 17:54:29 +05301/* Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
Aparna Mallavarapuca676882015-01-19 20:39:06 +05302 *
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>
36#include <platform/gpio.h>
37#include <dev/keys.h>
38#include <spmi_v2.h>
39#include <pm8x41.h>
Aparna Mallavarapubc6315e2015-04-11 04:00:43 +053040#include <pm8x41_hw.h>
Aparna Mallavarapuca676882015-01-19 20:39:06 +053041#include <board.h>
42#include <baseband.h>
43#include <hsusb.h>
44#include <scm.h>
45#include <platform/gpio.h>
46#include <platform/gpio.h>
47#include <platform/irqs.h>
48#include <platform/clock.h>
Aparna Mallavarapubc6315e2015-04-11 04:00:43 +053049#include <platform/timer.h>
Aparna Mallavarapuca676882015-01-19 20:39:06 +053050#include <crypto5_wrapper.h>
51#include <partition_parser.h>
52#include <stdlib.h>
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +053053#include <rpm-smd.h>
Aparna Mallavarapubc6315e2015-04-11 04:00:43 +053054#include <spmi.h>
55#include <sdhci_msm.h>
56#include <clock.h>
Parth Dixit6e6bad52015-07-30 19:02:38 +053057#include <boot_device.h>
58#include <secapp_loader.h>
59#include <rpmb.h>
lijuang3606df82015-09-02 21:14:43 +080060#include <smem.h>
Aparna Mallavarapuca676882015-01-19 20:39:06 +053061
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -070062#include "target/display.h"
63
Aparna Mallavarapuca676882015-01-19 20:39:06 +053064#if LONG_PRESS_POWER_ON
65#include <shutdown_detect.h>
66#endif
67
Matthew Qin47dfdb72015-06-10 21:29:11 +080068#if PON_VIB_SUPPORT
69#include <vibrator.h>
70#endif
71
72#if PON_VIB_SUPPORT
73#define VIBRATE_TIME 250
74#endif
75
Aparna Mallavarapuca676882015-01-19 20:39:06 +053076#define PMIC_ARB_CHANNEL_NUM 0
77#define PMIC_ARB_OWNER_ID 0
78#define TLMM_VOL_UP_BTN_GPIO 85
Unnati Gandhife004a92015-06-01 13:06:06 +053079#define TLMM_VOL_UP_BTN_GPIO_8956 113
Parth Dixit720d3b92015-10-30 01:21:34 +053080#define TLMM_VOL_UP_BTN_GPIO_8937 91
Wufengf2e37312016-04-12 16:09:47 +080081#define TLMM_VOL_DOWN_BTN_GPIO 128
Aparna Mallavarapuca676882015-01-19 20:39:06 +053082
83#define FASTBOOT_MODE 0x77665500
Aparna Mallavarapu680a1332015-04-29 19:14:09 +053084#define RECOVERY_MODE 0x77665502
Aparna Mallavarapuca676882015-01-19 20:39:06 +053085#define PON_SOFT_RB_SPARE 0x88F
86
Parth Dixit17b85192016-12-28 15:51:33 +053087#define EXT4_CMDLINE " rootfstype=ext4 root=/dev/mmcblk0p"
88
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +053089#define CE1_INSTANCE 1
90#define CE_EE 1
91#define CE_FIFO_SIZE 64
92#define CE_READ_PIPE 3
93#define CE_WRITE_PIPE 2
94#define CE_READ_PIPE_LOCK_GRP 0
95#define CE_WRITE_PIPE_LOCK_GRP 0
96#define CE_ARRAY_SIZE 20
Wufengf2e37312016-04-12 16:09:47 +080097#define SUB_TYPE_SKUT 0x0A
Vijay Kumar Pendoti0d698842016-09-23 16:23:16 +053098#define SMBCHG_USB_RT_STS 0x21310
99#define USBIN_UV_RT_STS BIT(0)
Umang Agrawal898a1912018-02-13 16:09:10 +0530100#define USBIN_UV_RT_STS_PMI632 BIT(2)
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530101
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530102struct mmc_device *dev;
103
104static uint32_t mmc_pwrctl_base[] =
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530105 { MSM_SDC1_BASE, MSM_SDC2_BASE };
106
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530107static uint32_t mmc_sdhci_base[] =
108 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
109
110static uint32_t mmc_sdc_pwrctl_irq[] =
111 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530112
Umang Agrawal0cad3f22019-05-22 13:16:59 +0530113static int sdm429_pm660_target()
114{
Meng Jiang289a9812019-10-23 15:25:26 +0800115 if ((platform_is_sdm429() && (board_hardware_subtype() == HW_PLATFORM_SUBTYPE_429W_PM660)) || platform_is_sdm429w() || platform_is_sda429w())
Umang Agrawal0cad3f22019-05-22 13:16:59 +0530116 return 1;
117 else
118 return 0;
119}
120
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530121void target_early_init(void)
122{
123#if WITH_DEBUG_UART
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530124 uart_dm_init(2, 0, BLSP1_UART1_BASE);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530125#endif
126}
127
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530128static void set_sdc_power_ctrl()
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530129{
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530130 /* Drive strength configs for sdc pins */
131 struct tlmm_cfgs sdc1_hdrv_cfg[] =
132 {
133 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, 0},
134 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, 0},
135 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK , 0},
136 };
137
138 /* Pull configs for sdc pins */
139 struct tlmm_cfgs sdc1_pull_cfg[] =
140 {
141 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, 0},
142 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0},
143 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0},
144 };
145
Aparna Mallavarapu29138912015-04-13 23:45:35 +0530146 struct tlmm_cfgs sdc1_rclk_cfg[] =
147 {
148 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, 0},
149 };
150
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530151 /* Set the drive strength & pull control values */
152 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
153 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
Aparna Mallavarapu29138912015-04-13 23:45:35 +0530154 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530155}
156
157void target_sdc_init()
158{
159 struct mmc_config_data config;
160
161 /* Set drive strength & pull ctrl values */
162 set_sdc_power_ctrl();
163
164 /* Try slot 1*/
165 config.slot = 1;
166 config.bus_width = DATA_BUS_WIDTH_8BIT;
Aparna Mallavarapu680a1332015-04-29 19:14:09 +0530167 config.max_clk_rate = MMC_CLK_192MHZ;
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530168 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
169 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
170 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
171 config.hs400_support = 1;
172
173 if (!(dev = mmc_init(&config))) {
174 /* Try slot 2 */
175 config.slot = 2;
176 config.max_clk_rate = MMC_CLK_200MHZ;
177 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
178 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
179 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
180 config.hs400_support = 0;
181
182 if (!(dev = mmc_init(&config))) {
183 dprintf(CRITICAL, "mmc init failed!");
184 ASSERT(0);
185 }
186 }
187}
188
189void *target_mmc_device()
190{
191 return (void *) dev;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530192}
193
194/* Return 1 if vol_up pressed */
Rami Butsteine51318a2015-05-27 16:23:17 +0300195int target_volume_up()
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530196{
lijuang2d2b8a02015-06-05 21:34:15 +0800197 static uint8_t first_time = 0;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530198 uint8_t status = 0;
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530199 uint32_t vol_up_gpio;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530200
Unnati Gandhife004a92015-06-01 13:06:06 +0530201 if(platform_is_msm8956())
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530202 vol_up_gpio = TLMM_VOL_UP_BTN_GPIO_8956;
lijuangf6563682018-04-04 20:26:52 +0800203 else if(platform_is_msm8937() || platform_is_msm8917() ||
Meng Jiang289a9812019-10-23 15:25:26 +0800204 platform_is_sdm429() || platform_is_sdm429w() || platform_is_sda429w() || platform_is_sdm439() ||
lijuang5bc5bb82018-10-16 18:39:14 +0800205 platform_is_qm215())
Parth Dixit720d3b92015-10-30 01:21:34 +0530206 vol_up_gpio = TLMM_VOL_UP_BTN_GPIO_8937;
Unnati Gandhife004a92015-06-01 13:06:06 +0530207 else
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530208 vol_up_gpio = TLMM_VOL_UP_BTN_GPIO;
209
lijuang2d2b8a02015-06-05 21:34:15 +0800210 if (!first_time) {
211 gpio_tlmm_config(vol_up_gpio, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530212
lijuang2d2b8a02015-06-05 21:34:15 +0800213 /* Wait for the gpio config to take effect - debounce time */
214 udelay(10000);
215
216 first_time = 1;
217 }
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530218
219 /* Get status of GPIO */
Unnati Gandhie3a5c0e2015-06-14 17:31:07 +0530220 status = gpio_status(vol_up_gpio);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530221
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530222 /* Active low signal. */
Aparna Mallavarapudb938b62015-04-09 01:00:55 +0530223 return !status;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530224}
225
226/* Return 1 if vol_down pressed */
227uint32_t target_volume_down()
228{
Wufengf2e37312016-04-12 16:09:47 +0800229 static bool vol_down_key_init = false;
230
231 if ((board_hardware_id() == HW_PLATFORM_QRD) &&
232 (board_hardware_subtype() == SUB_TYPE_SKUT)) {
233 uint32_t status = 0;
234
235 if (!vol_down_key_init) {
236 gpio_tlmm_config(TLMM_VOL_DOWN_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP,
237 GPIO_2MA, GPIO_ENABLE);
238 /* Wait for the gpio config to take effect - debounce time */
239 thread_sleep(10);
240 vol_down_key_init = true;
241 }
242
243 /* Get status of GPIO */
244 status = gpio_status(TLMM_VOL_DOWN_BTN_GPIO);
245
246 /* Active low signal. */
247 return !status;
248 } else {
249 /* Volume down button tied in with PMIC RESIN. */
250 return pm8x41_resin_status();
251 }
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530252}
253
Parth Dixit300a3b92015-06-19 16:38:12 +0530254uint32_t target_is_pwrkey_pon_reason()
255{
Umang Agrawal898a1912018-02-13 16:09:10 +0530256 uint32_t pmic = target_get_pmic();
Umang Agrawaldff10da2019-05-08 16:14:13 +0530257 uint8_t pon_reason;
258 uint8_t is_cold_boot;
259 bool usb_present_sts;
Umang Agrawal898a1912018-02-13 16:09:10 +0530260
Umang Agrawaldff10da2019-05-08 16:14:13 +0530261 if (pmic == PMIC_IS_PMI632) {
Umang Agrawal898a1912018-02-13 16:09:10 +0530262 pon_reason = pmi632_get_pon_reason();
Umang Agrawaldff10da2019-05-08 16:14:13 +0530263 is_cold_boot = pm8x41_get_is_cold_boot();
Umang Agrawal898a1912018-02-13 16:09:10 +0530264 usb_present_sts = !(USBIN_UV_RT_STS_PMI632 &
Vijay Kumar Pendoti0d698842016-09-23 16:23:16 +0530265 pm8x41_reg_read(SMBCHG_USB_RT_STS));
Umang Agrawaldff10da2019-05-08 16:14:13 +0530266 } else if (pmic == PMIC_IS_PM8916) {
Kiran Gunda4c2bd7a2018-10-23 12:51:08 +0530267 pon_reason = pm8x41_get_pon_reason();
Umang Agrawaldff10da2019-05-08 16:14:13 +0530268 is_cold_boot = pm8x41_get_is_cold_boot();
Kiran Gunda4c2bd7a2018-10-23 12:51:08 +0530269 usb_present_sts = (pon_reason & USB_CHG);
Umang Agrawaldff10da2019-05-08 16:14:13 +0530270 } else if (pmic == PMIC_IS_PM660) {
271 pon_reason = pm660_get_pon_reason();
272 is_cold_boot = pm660_get_is_cold_boot();
273 usb_present_sts = USBIN_PLUGIN_RT_STS &
274 pm8x41_reg_read(SCHG_USB_INT_RT_STS);
275 } else {
Umang Agrawal898a1912018-02-13 16:09:10 +0530276 pon_reason = pm8950_get_pon_reason();
Umang Agrawaldff10da2019-05-08 16:14:13 +0530277 is_cold_boot = pm8x41_get_is_cold_boot();
Umang Agrawal898a1912018-02-13 16:09:10 +0530278 usb_present_sts = !(USBIN_UV_RT_STS &
279 pm8x41_reg_read(SMBCHG_USB_RT_STS));
280 }
281
Umang Agrawaldff10da2019-05-08 16:14:13 +0530282 if (is_cold_boot && ((pon_reason == KPDPWR_N) || (pon_reason == (KPDPWR_N|PON1))))
Parth Dixit300a3b92015-06-19 16:38:12 +0530283 return 1;
Vijay Kumar Pendoti0d698842016-09-23 16:23:16 +0530284 else if ((pon_reason == PON1) && (!usb_present_sts))
285 return 1;
Parth Dixit300a3b92015-06-19 16:38:12 +0530286 else
287 return 0;
288}
289
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530290static void target_keystatus()
291{
292 keys_init();
293
294 if(target_volume_down())
295 keys_post_event(KEY_VOLUMEDOWN, 1);
296
297 if(target_volume_up())
298 keys_post_event(KEY_VOLUMEUP, 1);
299}
300
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530301void target_init(void)
302{
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530303 dprintf(INFO, "target_init()\n");
304
305 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
306
Parth Dixit550ddf32016-11-28 17:00:29 +0530307 if(target_is_pmi_enabled())
Parth Dixit3e6dead2015-12-08 15:04:54 +0530308 {
lijuangf6563682018-04-04 20:26:52 +0800309 if(platform_is_msm8937() || platform_is_msm8917() ||
Meng Jiang289a9812019-10-23 15:25:26 +0800310 platform_is_sdm429() || platform_is_sdm429w() || platform_is_sda429w() || platform_is_sdm439())
Parth Dixit3e6dead2015-12-08 15:04:54 +0530311 {
Parth Dixit550ddf32016-11-28 17:00:29 +0530312 uint8_t pmi_rev = 0;
313 uint32_t pmi_type = 0;
314
Umang Agrawal1b180582018-04-17 18:56:57 +0530315 pmi_type = board_pmic_target(1) & PMIC_TYPE_MASK;
Parth Dixit550ddf32016-11-28 17:00:29 +0530316 if(pmi_type == PMIC_IS_PMI8950)
317 {
318 /* read pmic spare register for rev */
319 pmi_rev = pmi8950_get_pmi_subtype();
320 if(pmi_rev)
321 board_pmi_target_set(1,pmi_rev);
322 }
Parth Dixit3e6dead2015-12-08 15:04:54 +0530323 }
324 }
325
Parth Dixit550ddf32016-11-28 17:00:29 +0530326
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530327 target_keystatus();
328
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530329 target_sdc_init();
330 if (partition_read_table())
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530331 {
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530332 dprintf(CRITICAL, "Error reading the partition table info\n");
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530333 ASSERT(0);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530334 }
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530335
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530336#if LONG_PRESS_POWER_ON
Parth Dixit550ddf32016-11-28 17:00:29 +0530337 if(target_is_pmi_enabled())
338 shutdown_detect();
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530339#endif
Matthew Qin47dfdb72015-06-10 21:29:11 +0800340
341#if PON_VIB_SUPPORT
342 /* turn on vibrator to indicate that phone is booting up to end user */
Umang Agrawal0cad3f22019-05-22 13:16:59 +0530343 if(target_is_pmi_enabled() || platform_is_qm215()
Meng Jiang289a9812019-10-23 15:25:26 +0800344 || platform_is_sdm429w() || platform_is_sda429w() || sdm429_pm660_target())
Parth Dixit550ddf32016-11-28 17:00:29 +0530345 vib_timed_turn_on(VIBRATE_TIME);
Matthew Qin47dfdb72015-06-10 21:29:11 +0800346#endif
347
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530348 if (target_use_signed_kernel())
349 target_crypto_init_params();
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530350
Mayank Grovere2384ad2017-10-26 12:11:17 +0530351 if (VB_M <= target_get_vb_version())
Parth Dixit6e6bad52015-07-30 19:02:38 +0530352 {
Mayank Grover32ba2992017-09-06 11:14:00 +0530353 clock_ce_enable(CE1_INSTANCE);
Parth Dixit6e6bad52015-07-30 19:02:38 +0530354
Mayank Grover32ba2992017-09-06 11:14:00 +0530355 /* Initialize Qseecom */
356 if (qseecom_init() < 0)
357 {
358 dprintf(CRITICAL, "Failed to initialize qseecom\n");
359 ASSERT(0);
360 }
Parth Dixit6e6bad52015-07-30 19:02:38 +0530361
Mayank Grover32ba2992017-09-06 11:14:00 +0530362 /* Start Qseecom */
363 if (qseecom_tz_init() < 0)
364 {
365 dprintf(CRITICAL, "Failed to start qseecom\n");
366 ASSERT(0);
367 }
Parth Dixit6e6bad52015-07-30 19:02:38 +0530368
Mayank Grover32ba2992017-09-06 11:14:00 +0530369 if (rpmb_init() < 0)
370 {
371 dprintf(CRITICAL, "RPMB init failed\n");
372 ASSERT(0);
373 }
Parth Dixitb4b2ffa2015-10-09 15:31:14 +0530374
Mayank Grover32ba2992017-09-06 11:14:00 +0530375 /*
376 * Load the sec app for first time
377 */
378 if (load_sec_app() < 0)
379 {
380 dprintf(CRITICAL, "Failed to load App for verified\n");
381 ASSERT(0);
382 }
Parth Dixit6e6bad52015-07-30 19:02:38 +0530383 }
Parth Dixit5b954e02015-10-17 22:20:31 +0530384
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530385#if SMD_SUPPORT
386 rpm_smd_init();
387#endif
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530388}
389
390void target_serialno(unsigned char *buf)
391{
392 uint32_t serialno;
393 if (target_is_emmc_boot()) {
394 serialno = mmc_get_psn();
395 snprintf((char *)buf, 13, "%x", serialno);
396 }
397}
398
399unsigned board_machtype(void)
400{
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530401 return LINUX_MACHTYPE_UNKNOWN;
402}
403
404/* Detect the target type */
405void target_detect(struct board_data *board)
406{
407 /* This is already filled as part of board.c */
408}
409
410/* Detect the modem type */
411void target_baseband_detect(struct board_data *board)
412{
413 uint32_t platform;
414
415 platform = board->platform;
416
417 switch(platform) {
418 case MSM8952:
419 case MSM8956:
420 case MSM8976:
Parth Dixit4ec3fe22015-10-30 00:44:33 +0530421 case MSM8937:
Parth Dixit660369e2016-05-12 09:53:15 +0530422 case MSM8940:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530423 case MSM8917:
Mayank Grovercd5f0ff2016-10-03 18:08:52 +0530424 case MSM8920:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530425 case MSM8217:
426 case MSM8617:
lijuangf6563682018-04-04 20:26:52 +0800427 case SDM429:
428 case SDM439:
shaoxing0534f8b2019-07-08 19:56:02 +0800429 case SDM429W:
lijuang5c1f4682018-10-09 19:37:36 +0800430 case QM215:
Nagireddy Annemb2d8e9a2019-09-06 17:54:29 +0530431 case QCM2150:
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530432 board->baseband = BASEBAND_MSM;
433 break;
Aparna Mallavarapu815b3242015-04-29 11:08:14 +0530434 case APQ8052:
435 case APQ8056:
436 case APQ8076:
Parth Dixit4ec3fe22015-10-30 00:44:33 +0530437 case APQ8037:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530438 case APQ8017:
lijuang5c8797d2018-04-23 19:10:16 +0800439 case SDA429:
440 case SDA439:
Meng Jiang7f5d74c2019-10-30 15:50:08 +0800441 case SDA429W:
Aparna Mallavarapu815b3242015-04-29 11:08:14 +0530442 board->baseband = BASEBAND_APQ;
443 break;
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530444 default:
445 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
446 ASSERT(0);
447 };
448}
449
450unsigned target_baseband()
451{
452 return board_baseband();
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530453}
454
lijuang395b5e62015-11-19 17:39:44 +0800455int set_download_mode(enum reboot_reason mode)
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530456{
457 int ret = 0;
458 ret = scm_dload_mode(mode);
459
460 pm8x41_clear_pmic_watchdog();
461
462 return ret;
463}
464
465int emmc_recovery_init(void)
466{
467 return _emmc_recovery_init();
468}
469
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530470unsigned target_pause_for_battery_charge(void)
471{
Umang Agrawal898a1912018-02-13 16:09:10 +0530472 uint32_t pmic = target_get_pmic();
Umang Agrawaldff10da2019-05-08 16:14:13 +0530473 uint8_t pon_reason;
474 uint8_t is_cold_boot;
Parth Dixit550ddf32016-11-28 17:00:29 +0530475 bool usb_present_sts = 1; /* don't care by default */
476
Umang Agrawaldff10da2019-05-08 16:14:13 +0530477 if (pmic == PMIC_IS_PM660) {
478 pon_reason = pm660_get_pon_reason();
479 is_cold_boot = pm660_get_is_cold_boot();
480 }
481 else {
482 pon_reason = pm8x41_get_pon_reason();
483 is_cold_boot = pm8x41_get_is_cold_boot();
484 }
485
Umang Agrawal898a1912018-02-13 16:09:10 +0530486 if (target_is_pmi_enabled())
487 {
Umang Agrawaldff10da2019-05-08 16:14:13 +0530488 if (pmic == PMIC_IS_PMI632) {
Umang Agrawal898a1912018-02-13 16:09:10 +0530489 usb_present_sts = !(USBIN_UV_RT_STS_PMI632 &
490 pm8x41_reg_read(SMBCHG_USB_RT_STS));
Umang Agrawaldff10da2019-05-08 16:14:13 +0530491 } else {
Umang Agrawal898a1912018-02-13 16:09:10 +0530492 usb_present_sts = (!(USBIN_UV_RT_STS &
493 pm8x41_reg_read(SMBCHG_USB_RT_STS)));
Umang Agrawaldff10da2019-05-08 16:14:13 +0530494 }
Umang Agrawal898a1912018-02-13 16:09:10 +0530495 }
Kiran Gunda4c2bd7a2018-10-23 12:51:08 +0530496 else {
497 if (pmic == PMIC_IS_PM8916) {
498 usb_present_sts = (pon_reason & USB_CHG);
Umang Agrawalfa9614a2019-05-22 12:05:46 +0530499 } else if (pmic == PMIC_IS_PM660) {
500 usb_present_sts = USBIN_PLUGIN_RT_STS &
501 pm8x41_reg_read(SCHG_USB_INT_RT_STS);
Kiran Gunda4c2bd7a2018-10-23 12:51:08 +0530502 }
503 }
Parth Dixit550ddf32016-11-28 17:00:29 +0530504
Zhenhua Huangb46b9b52015-04-21 19:53:09 +0800505 dprintf(INFO, "%s : pon_reason is:0x%x cold_boot:%d usb_sts:%d\n", __func__,
506 pon_reason, is_cold_boot, usb_present_sts);
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530507 /* In case of fastboot reboot,adb reboot or if we see the power key
508 * pressed we do not want go into charger mode.
509 * fastboot reboot is warm boot with PON hard reset bit not set
510 * adb reboot is a cold boot with PON hard reset bit set
511 */
512 if (is_cold_boot &&
513 (!(pon_reason & HARD_RST)) &&
514 (!(pon_reason & KPDPWR_N)) &&
Zhenhua Huangb46b9b52015-04-21 19:53:09 +0800515 usb_present_sts)
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530516 return 1;
517 else
518 return 0;
519}
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530520
521void target_uninit(void)
522{
c_wufeng8324c042016-01-25 10:37:37 +0800523#if PON_VIB_SUPPORT
Meng Jiang289a9812019-10-23 15:25:26 +0800524 if(target_is_pmi_enabled() || platform_is_sdm429w() || platform_is_sda429w() || sdm429_pm660_target())
Parth Dixit550ddf32016-11-28 17:00:29 +0530525 turn_off_vib_early();
c_wufeng8324c042016-01-25 10:37:37 +0800526#endif
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530527 mmc_put_card_to_sleep(dev);
528 sdhci_mode_disable(&dev->host);
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530529 if (crypto_initialized())
Vijay Kumar Pendotib0f9ba32016-04-15 16:55:30 +0530530 {
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530531 crypto_eng_cleanup();
Vijay Kumar Pendotib0f9ba32016-04-15 16:55:30 +0530532 clock_ce_disable(CE1_INSTANCE);
533 }
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530534
535 if (target_is_ssd_enabled())
536 clock_ce_disable(CE1_INSTANCE);
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530537
Mayank Grovere2384ad2017-10-26 12:11:17 +0530538 if (VB_M <= target_get_vb_version())
Parth Dixit6e6bad52015-07-30 19:02:38 +0530539 {
Mayank Grover32ba2992017-09-06 11:14:00 +0530540 if (is_sec_app_loaded())
Parth Dixit6e6bad52015-07-30 19:02:38 +0530541 {
Mayank Grover32ba2992017-09-06 11:14:00 +0530542 if (send_milestone_call_to_tz() < 0)
543 {
544 dprintf(CRITICAL, "Failed to unload App for rpmb\n");
545 ASSERT(0);
546 }
547 }
548
549 if (rpmb_uninit() < 0)
550 {
551 dprintf(CRITICAL, "RPMB uninit failed\n");
Parth Dixit6e6bad52015-07-30 19:02:38 +0530552 ASSERT(0);
553 }
Parth Dixit6e6bad52015-07-30 19:02:38 +0530554
Mayank Grover32ba2992017-09-06 11:14:00 +0530555 clock_ce_disable(CE1_INSTANCE);
Parth Dixit6e6bad52015-07-30 19:02:38 +0530556 }
Parth Dixit5b954e02015-10-17 22:20:31 +0530557
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530558#if SMD_SUPPORT
559 rpm_smd_uninit();
560#endif
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +0530561}
562
563void target_usb_init(void)
564{
565 uint32_t val;
566
567 /* Select and enable external configuration with USB PHY */
568 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
569
570 /* Enable sess_vld */
571 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
572 writel(val, USB_GENCONFIG_2);
573
574 /* Enable external vbus configuration in the LINK */
575 val = readl(USB_USBCMD);
576 val |= SESS_VLD_CTRL;
577 writel(val, USB_USBCMD);
578}
579
580void target_usb_stop(void)
581{
582 /* Disable VBUS mimicing in the controller. */
583 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
584}
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530585
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700586static uint8_t splash_override;
587/* Returns 1 if target supports continuous splash screen. */
588int target_cont_splash_screen()
589{
590 uint8_t splash_screen = 0;
591 if (!splash_override) {
592 switch (board_hardware_id()) {
593 case HW_PLATFORM_MTP:
594 case HW_PLATFORM_SURF:
Vishnuvardhan Prodduturie116c002015-07-14 17:14:25 +0530595 case HW_PLATFORM_RCM:
feifanz174c82c2015-04-15 18:57:07 +0800596 case HW_PLATFORM_QRD:
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700597 splash_screen = 1;
598 break;
599 default:
600 splash_screen = 0;
601 break;
602 }
603 dprintf(SPEW, "Target_cont_splash=%d\n", splash_screen);
604 }
605 return splash_screen;
606}
607
608void target_force_cont_splash_disable(uint8_t override)
609{
610 splash_override = override;
611}
612
Ray Zhangf95f5b92015-06-25 15:34:29 +0800613uint8_t target_panel_auto_detect_enabled()
614{
615 uint8_t ret = 0;
616
617 switch(board_hardware_id())
618 {
619 case HW_PLATFORM_QRD:
620 ret = platform_is_msm8956() ? 1 : 0;
621 break;
622 case HW_PLATFORM_SURF:
623 case HW_PLATFORM_MTP:
624 default:
625 ret = 0;
626 }
627 return ret;
628}
629
Aparna Mallavarapu1e8b0932015-03-29 23:38:13 +0530630/* Do any target specific intialization needed before entering fastboot mode */
631void target_fastboot_init(void)
632{
633 if (target_is_ssd_enabled()) {
634 clock_ce_enable(CE1_INSTANCE);
635 target_load_ssd_keystore();
636 }
637}
638
639void target_load_ssd_keystore(void)
640{
641 uint64_t ptn;
642 int index;
643 uint64_t size;
644 uint32_t *buffer = NULL;
645
646 if (!target_is_ssd_enabled())
647 return;
648
649 index = partition_get_index("ssd");
650
651 ptn = partition_get_offset(index);
652 if (ptn == 0){
653 dprintf(CRITICAL, "Error: ssd partition not found\n");
654 return;
655 }
656
657 size = partition_get_size(index);
658 if (size == 0) {
659 dprintf(CRITICAL, "Error: invalid ssd partition size\n");
660 return;
661 }
662
663 buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
664 if (!buffer) {
665 dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
666 return;
667 }
668
669 if (mmc_read(ptn, buffer, size)) {
670 dprintf(CRITICAL, "Error: cannot read data\n");
671 free(buffer);
672 return;
673 }
674
675 clock_ce_enable(CE1_INSTANCE);
676 scm_protect_keystore(buffer, size);
677 clock_ce_disable(CE1_INSTANCE);
678 free(buffer);
679}
680
681crypto_engine_type board_ce_type(void)
682{
683 return CRYPTO_ENGINE_TYPE_HW;
684}
685
686/* Set up params for h/w CE. */
687void target_crypto_init_params()
688{
689 struct crypto_init_params ce_params;
690
691 /* Set up base addresses and instance. */
692 ce_params.crypto_instance = CE1_INSTANCE;
693 ce_params.crypto_base = MSM_CE1_BASE;
694 ce_params.bam_base = MSM_CE1_BAM_BASE;
695
696 /* Set up BAM config. */
697 ce_params.bam_ee = CE_EE;
698 ce_params.pipes.read_pipe = CE_READ_PIPE;
699 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
700 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
701 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
702
703 /* Assign buffer sizes. */
704 ce_params.num_ce = CE_ARRAY_SIZE;
705 ce_params.read_fifo_size = CE_FIFO_SIZE;
706 ce_params.write_fifo_size = CE_FIFO_SIZE;
707
708 /* BAM is initialized by TZ for this platform.
709 * Do not do it again as the initialization address space
710 * is locked.
711 */
712 ce_params.do_bam_init = 0;
713
714 crypto_init_params(&ce_params);
715}
lijuang3606df82015-09-02 21:14:43 +0800716
Parth Dixit550ddf32016-11-28 17:00:29 +0530717bool target_is_pmi_enabled(void)
718{
Meng Jiang289a9812019-10-23 15:25:26 +0800719 if (platform_is_qm215() || platform_is_sdm429w() || platform_is_sda429w() || sdm429_pm660_target() ||
Umang Agrawal0cad3f22019-05-22 13:16:59 +0530720 (platform_is_msm8917() && (board_hardware_subtype() ==
721 HW_PLATFORM_SUBTYPE_SAP_NOPMI)))
Parth Dixit550ddf32016-11-28 17:00:29 +0530722 return 0;
723 else
724 return 1;
725}
726
Parth Dixit17b85192016-12-28 15:51:33 +0530727#if _APPEND_CMDLINE
728int get_target_boot_params(const char *cmdline, const char *part, char **buf)
729{
730 int system_ptn_index = -1;
731 uint32_t buflen;
732 int ret = -1;
733
734 if (!cmdline || !part ) {
735 dprintf(CRITICAL, "WARN: Invalid input param\n");
736 return -1;
737 }
738
739 if (!strstr(cmdline, "root=/dev/ram")) /* This check is to handle kdev boot */
740 {
741 if (target_is_emmc_boot()) {
742 buflen = strlen(EXT4_CMDLINE) + sizeof(int) +1;
743 *buf = (char *)malloc(buflen);
744 if(!(*buf)) {
745 dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
746 return -1;
747 }
748 /* Below is for emmc boot */
749 system_ptn_index = partition_get_index(part) + 1; /* Adding +1 as offsets for eMMC start at 1 and NAND at 0 */
750 if (system_ptn_index < 0) {
751 dprintf(CRITICAL,
752 "WARN: Cannot get partition index for %s\n", part);
753 free(*buf);
754 return -1;
755 }
756 snprintf(*buf, buflen, EXT4_CMDLINE"%d", system_ptn_index);
757 ret = 0;
758 }
759 }
760 /*in success case buf will be freed in the calling function of this*/
761 return ret;
762}
763#endif
764
lijuang3606df82015-09-02 21:14:43 +0800765uint32_t target_get_pmic()
766{
lijuangf9859a32018-10-10 12:08:46 +0800767 uint32_t pmi_type = 0;
768
Umang Agrawal898a1912018-02-13 16:09:10 +0530769 if (target_is_pmi_enabled()) {
lijuangf9859a32018-10-10 12:08:46 +0800770 pmi_type = board_pmic_target(1) & PMIC_TYPE_MASK;
Umang Agrawal898a1912018-02-13 16:09:10 +0530771 if (pmi_type == PMIC_IS_PMI632)
772 return PMIC_IS_PMI632;
773 else
774 return PMIC_IS_PMI8950;
lijuangf9859a32018-10-10 12:08:46 +0800775 } else {
Meng Jiang289a9812019-10-23 15:25:26 +0800776 if (platform_is_qm215() || platform_is_sdm429w() || platform_is_sda429w() || sdm429_pm660_target()) {
lijuangf9859a32018-10-10 12:08:46 +0800777 pmi_type = board_pmic_target(0) & PMIC_TYPE_MASK;
778 return pmi_type;
779 }
Umang Agrawal898a1912018-02-13 16:09:10 +0530780 return PMIC_IS_UNKNOWN;
781 }
lijuang3606df82015-09-02 21:14:43 +0800782}
Maria Yu3ce8b632018-03-23 13:26:31 +0530783
784void pmic_reset_configure(uint8_t reset_type)
785{
786 uint32_t pmi_type;
787
788 pmi_type = target_get_pmic();
789 if (pmi_type == PMIC_IS_PMI632) {
790 pmi632_reset_configure(reset_type);
Umang Agrawaldff10da2019-05-08 16:14:13 +0530791 } else if (pmi_type == PMIC_IS_PM660) {
792 pm8x41_reset_configure(reset_type);
Maria Yu3ce8b632018-03-23 13:26:31 +0530793 } else {
794 if(target_is_pmi_enabled()) {
795 pm8994_reset_configure(reset_type);
796 } else {
797 pm8x41_reset_configure(reset_type);
798 }
799 }
800}
801