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