blob: 6d95e8f70e3e0d75f6b11268278603dd2d175872 [file] [log] [blame]
Channagoud Kadabif8ad8e72015-01-06 15:10:13 -08001/* Copyright (c) 2014-2015 The Linux Foundation. All rights reserved.
Channagoud Kadabied60a8b2014-06-27 15:35:09 -07002 *
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 <platform/irqs.h>
32#include <platform/gpio.h>
33#include <reg.h>
34#include <target.h>
35#include <platform.h>
36#include <dload_util.h>
37#include <uart_dm.h>
38#include <mmc.h>
39#include <spmi.h>
40#include <board.h>
41#include <smem.h>
42#include <baseband.h>
43#include <dev/keys.h>
44#include <pm8x41.h>
45#include <crypto5_wrapper.h>
46#include <clock.h>
47#include <partition_parser.h>
48#include <scm.h>
49#include <platform/clock.h>
50#include <platform/gpio.h>
51#include <platform/timer.h>
52#include <stdlib.h>
53#include <ufs.h>
54#include <boot_device.h>
55#include <qmp_phy.h>
Channagoud Kadabi7d308202014-12-22 12:07:04 -080056#include <sdhci_msm.h>
57#include <qusb2_phy.h>
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -080058#include <rpmb.h>
Sridhar Parasuram9f28f672015-03-17 15:40:47 -070059#include <rpm-glink.h>
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070060
Channagoud Kadabi4a870cf2015-01-21 10:39:01 -080061#define CE_INSTANCE 1
62#define CE_EE 1
63#define CE_FIFO_SIZE 64
64#define CE_READ_PIPE 3
65#define CE_WRITE_PIPE 2
66#define CE_READ_PIPE_LOCK_GRP 0
67#define CE_WRITE_PIPE_LOCK_GRP 0
68#define CE_ARRAY_SIZE 20
69
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070070#define PMIC_ARB_CHANNEL_NUM 0
71#define PMIC_ARB_OWNER_ID 0
72
73static void set_sdc_power_ctrl(void);
74static uint32_t mmc_pwrctl_base[] =
75 { MSM_SDC1_BASE, MSM_SDC2_BASE };
76
77static uint32_t mmc_sdhci_base[] =
78 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
79
80static uint32_t mmc_sdc_pwrctl_irq[] =
81 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
82
83struct mmc_device *dev;
84struct ufs_dev ufs_device;
85
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070086void target_early_init(void)
87{
88#if WITH_DEBUG_UART
Channagoud Kadabi35503c42014-11-14 16:22:43 -080089 uart_dm_init(8, 0, BLSP2_UART1_BASE);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070090#endif
91}
92
93/* Return 1 if vol_up pressed */
94static int target_volume_up()
95{
96 uint8_t status = 0;
97 struct pm8x41_gpio gpio;
98
99 /* Configure the GPIO */
100 gpio.direction = PM_GPIO_DIR_IN;
101 gpio.function = 0;
102 gpio.pull = PM_GPIO_PULL_UP_30;
103 gpio.vin_sel = 2;
104
105 pm8x41_gpio_config(2, &gpio);
106
107 /* Wait for the pmic gpio config to take effect */
108 thread_sleep(1);
109
110 /* Get status of P_GPIO_5 */
Channagoud Kadabi99d23702015-02-02 20:52:17 -0800111 pm8x41_gpio_get(2, &status);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700112
113 return !status; /* active low */
114}
115
116/* Return 1 if vol_down pressed */
117uint32_t target_volume_down()
118{
119 return pm8x41_resin_status();
120}
121
122static void target_keystatus()
123{
124 keys_init();
125
126 if(target_volume_down())
127 keys_post_event(KEY_VOLUMEDOWN, 1);
128
129 if(target_volume_up())
130 keys_post_event(KEY_VOLUMEUP, 1);
131}
132
133void target_uninit(void)
134{
135 if (platform_boot_dev_isemmc())
136 {
137 mmc_put_card_to_sleep(dev);
138 /* Disable HC mode before jumping to kernel */
139 sdhci_mode_disable(&dev->host);
140 }
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -0800141
142 if (is_sec_app_loaded())
143 {
144 if (unload_sec_app() < 0)
145 {
146 dprintf(CRITICAL, "Failed to unload App for rpmb\n");
147 ASSERT(0);
148 }
149 }
150
Sridhar Parasuram9f28f672015-03-17 15:40:47 -0700151 /* Tear down glink channels */
152 rpm_glink_uninit();
153
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -0800154 if (rpmb_uninit() < 0)
155 {
156 dprintf(CRITICAL, "RPMB uninit failed\n");
157 ASSERT(0);
158 }
159
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700160}
161
162static void set_sdc_power_ctrl()
163{
164 /* Drive strength configs for sdc pins */
165 struct tlmm_cfgs sdc1_hdrv_cfg[] =
166 {
167 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
168 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
169 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
170 };
171
172 /* Pull configs for sdc pins */
173 struct tlmm_cfgs sdc1_pull_cfg[] =
174 {
175 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
176 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
177 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
178 };
179
180 struct tlmm_cfgs sdc1_rclk_cfg[] =
181 {
182 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
183 };
184
185 /* Set the drive strength & pull control values */
186 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
187 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
188 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
189}
190
191void target_sdc_init()
192{
193 struct mmc_config_data config = {0};
194
195 /* Set drive strength & pull ctrl values */
196 set_sdc_power_ctrl();
197
198 config.bus_width = DATA_BUS_WIDTH_8BIT;
199 config.max_clk_rate = MMC_CLK_192MHZ;
Channagoud Kadabi99d23702015-02-02 20:52:17 -0800200 config.hs400_support = 1;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700201
202 /* Try slot 1*/
203 config.slot = 1;
204 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
205 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
206 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
207
208 if (!(dev = mmc_init(&config)))
209 {
210 /* Try slot 2 */
211 config.slot = 2;
212 config.max_clk_rate = MMC_CLK_200MHZ;
213 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
214 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
215 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
216
217 if (!(dev = mmc_init(&config)))
218 {
219 dprintf(CRITICAL, "mmc init failed!");
220 ASSERT(0);
221 }
222 }
223}
224
225void *target_mmc_device()
226{
227 if (platform_boot_dev_isemmc())
228 return (void *) dev;
229 else
230 return (void *) &ufs_device;
231}
232
233void target_init(void)
234{
235 dprintf(INFO, "target_init()\n");
236
237 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
238
239 target_keystatus();
240
241 if (target_use_signed_kernel())
242 target_crypto_init_params();
243
244 platform_read_boot_config();
245
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800246#ifdef MMC_SDHCI_SUPPORT
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700247 if (platform_boot_dev_isemmc())
248 {
249 target_sdc_init();
250 }
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800251#endif
252#ifdef UFS_SUPPORT
253 if (!platform_boot_dev_isemmc())
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700254 {
255 ufs_device.base = UFS_BASE;
256 ufs_init(&ufs_device);
257 }
Sridhar Parasuram50b9d962015-02-12 11:28:09 -0800258#endif
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700259
260 /* Storage initialization is complete, read the partition table info */
Channagoud Kadabi58a273b2015-02-10 12:56:22 -0800261 mmc_read_partition_table(0);
Channagoud Kadabi2bab29b2015-02-11 13:26:03 -0800262
263 if (rpmb_init() < 0)
264 {
265 dprintf(CRITICAL, "RPMB init failed\n");
266 ASSERT(0);
267 }
Sridhar Parasuram9f28f672015-03-17 15:40:47 -0700268 /* Initialize Glink */
269 rpm_glink_init();
270
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700271}
272
273unsigned board_machtype(void)
274{
275 return LINUX_MACHTYPE_UNKNOWN;
276}
277
278/* Detect the target type */
279void target_detect(struct board_data *board)
280{
281 /* This is filled from board.c */
282}
283
284/* Detect the modem type */
285void target_baseband_detect(struct board_data *board)
286{
287 uint32_t platform;
288
289 platform = board->platform;
290
291 switch(platform) {
Channagoud Kadabi4a4c05e2015-03-30 15:18:58 -0700292 case MSM8996:
Channagoud Kadabi99d23702015-02-02 20:52:17 -0800293 if (board->platform_version == 0x10000)
294 board->baseband = BASEBAND_APQ;
295 else
296 board->baseband = BASEBAND_MSM;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700297 break;
298 default:
299 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
300 ASSERT(0);
301 };
302}
303unsigned target_baseband()
304{
305 return board_baseband();
306}
307
308void target_serialno(unsigned char *buf)
309{
310 unsigned int serialno;
311 if (target_is_emmc_boot()) {
312 serialno = mmc_get_psn();
313 snprintf((char *)buf, 13, "%x", serialno);
314 }
315}
316
317unsigned check_reboot_mode(void)
318{
319 uint32_t restart_reason = 0;
320 uint32_t restart_reason_addr;
321
322 restart_reason_addr = RESTART_REASON_ADDR;
323
324 /* Read reboot reason and scrub it */
325 restart_reason = readl(restart_reason_addr);
326 writel(0x00, restart_reason_addr);
327
328 return restart_reason;
329}
330
331void reboot_device(unsigned reboot_reason)
332{
333 uint8_t reset_type = 0;
334
335 /* Write the reboot reason */
336 writel(reboot_reason, RESTART_REASON_ADDR);
337
338 if(reboot_reason)
339 reset_type = PON_PSHOLD_WARM_RESET;
340 else
341 reset_type = PON_PSHOLD_HARD_RESET;
342
343 pm8x41_reset_configure(reset_type);
344
345 /* Drop PS_HOLD for MSM */
346 writel(0x00, MPM2_MPM_PS_HOLD);
347
348 mdelay(5000);
349
350 dprintf(CRITICAL, "Rebooting failed\n");
351}
352
353int emmc_recovery_init(void)
354{
355 return _emmc_recovery_init();
356}
357
358void target_usb_phy_reset()
359{
360 usb30_qmp_phy_reset();
361 qusb2_phy_reset();
362}
363
364target_usb_iface_t* target_usb30_init()
365{
366 target_usb_iface_t *t_usb_iface;
367
368 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
369 ASSERT(t_usb_iface);
370
371 t_usb_iface->phy_init = usb30_qmp_phy_init;
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700372 t_usb_iface->phy_reset = target_usb_phy_reset;
373 t_usb_iface->clock_init = clock_usb30_init;
374 t_usb_iface->vbus_override = 1;
375
376 return t_usb_iface;
377}
378
379/* identify the usb controller to be used for the target */
380const char * target_usb_controller()
381{
382 return "dwc";
383}
384
385uint32_t target_override_pll()
386{
387 return 1;
388}
389
Channagoud Kadabi4a870cf2015-01-21 10:39:01 -0800390crypto_engine_type board_ce_type(void)
391{
392 return CRYPTO_ENGINE_TYPE_SW;
393}
394
395/* Set up params for h/w CE. */
396void target_crypto_init_params()
397{
398 struct crypto_init_params ce_params;
399
400 /* Set up base addresses and instance. */
401 ce_params.crypto_instance = CE_INSTANCE;
402 ce_params.crypto_base = MSM_CE_BASE;
403 ce_params.bam_base = MSM_CE_BAM_BASE;
404
405 /* Set up BAM config. */
406 ce_params.bam_ee = CE_EE;
407 ce_params.pipes.read_pipe = CE_READ_PIPE;
408 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
409 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
410 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
411
412 /* Assign buffer sizes. */
413 ce_params.num_ce = CE_ARRAY_SIZE;
414 ce_params.read_fifo_size = CE_FIFO_SIZE;
415 ce_params.write_fifo_size = CE_FIFO_SIZE;
416
417 /* BAM is initialized by TZ for this platform.
418 * Do not do it again as the initialization address space
419 * is locked.
420 */
421 ce_params.do_bam_init = 0;
422
423 crypto_init_params(&ce_params);
424}
Channagoud Kadabi083290f2015-03-13 14:18:38 -0700425
426unsigned target_pause_for_battery_charge(void)
427{
428 uint8_t pon_reason = pm8x41_get_pon_reason();
429 uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
430 dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
431 pon_reason, is_cold_boot);
432 /* In case of fastboot reboot,adb reboot or if we see the power key
433 * pressed we do not want go into charger mode.
434 * fastboot reboot is warm boot with PON hard reset bit not set
435 * adb reboot is a cold boot with PON hard reset bit set
436 */
437 if (is_cold_boot &&
438 (!(pon_reason & HARD_RST)) &&
439 (!(pon_reason & KPDPWR_N)) &&
440 ((pon_reason & PON1)))
441 return 1;
442 else
443 return 0;
444}
Channagoud Kadabi23edc0c2015-03-27 18:31:32 -0700445
446int set_download_mode(enum dload_mode mode)
447{
448 int ret = 0;
449 ret = scm_dload_mode(mode);
450
451 return ret;
452}