blob: 026aa5325bdab17c8a4a7021602e466a5cac7e5f [file] [log] [blame]
Deepa Dinamani645e9b12012-12-21 14:23:40 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
2 *
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>
Pavel Nedev16f49232013-04-29 16:15:36 +030034#include <dload_util.h>
Deepa Dinamani645e9b12012-12-21 14:23:40 -080035#include <uart_dm.h>
Channagoud Kadabi3c50c312013-05-02 17:16:03 -070036#include <mmc_sdhci.h>
Deepa Dinamani7e729772013-02-25 11:54:05 -080037#include <platform/gpio.h>
Deepa Dinamani645e9b12012-12-21 14:23:40 -080038#include <spmi.h>
39#include <board.h>
Deepa Dinamaniff2b9ce2013-02-25 11:01:00 -080040#include <smem.h>
41#include <baseband.h>
Deepa Dinamani7e729772013-02-25 11:54:05 -080042#include <dev/keys.h>
Deepa Dinamani058f1cd2013-02-25 10:53:01 -080043#include <pm8x41.h>
Deepa Dinamani6bb87d52013-02-26 14:37:36 -080044#include <crypto5_wrapper.h>
Amol Jadi85e19192013-02-28 22:45:04 -080045#include <hsusb.h>
Deepa Dinamani645e9b12012-12-21 14:23:40 -080046
Deepa Dinamani6bb87d52013-02-26 14:37:36 -080047extern bool target_use_signed_kernel(void);
Channagoud Kadabi3c50c312013-05-02 17:16:03 -070048static void set_sdc_power_ctrl(void);
Deepa Dinamani6bb87d52013-02-26 14:37:36 -080049
50#define PMIC_ARB_CHANNEL_NUM 0
51#define PMIC_ARB_OWNER_ID 0
52
53#define CRYPTO_ENGINE_INSTANCE 1
54#define CRYPTO_ENGINE_EE 1
55#define CRYPTO_ENGINE_FIFO_SIZE 64
56#define CRYPTO_ENGINE_READ_PIPE 3
57#define CRYPTO_ENGINE_WRITE_PIPE 2
58#define CRYPTO_ENGINE_CMD_ARRAY_SIZE 20
Deepa Dinamani645e9b12012-12-21 14:23:40 -080059
Deepa Dinamani7e729772013-02-25 11:54:05 -080060#define TLMM_VOL_UP_BTN_GPIO 106
61
Channagoud Kadabi3c50c312013-05-02 17:16:03 -070062static uint32_t mmc_sdhci_base[] =
63 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE };
64
65struct mmc_device *dev;
Deepa Dinamani645e9b12012-12-21 14:23:40 -080066
67void target_early_init(void)
68{
69#if WITH_DEBUG_UART
Deepa Dinamani0a6c48c2013-02-04 15:45:01 -080070 uart_dm_init(1, 0, BLSP1_UART2_BASE);
Deepa Dinamani645e9b12012-12-21 14:23:40 -080071#endif
72}
73
Deepa Dinamani7e729772013-02-25 11:54:05 -080074/* Return 1 if vol_up pressed */
75static int target_volume_up()
76{
77 uint8_t status = 0;
78
79 gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
80
aiquny933017c2013-03-02 12:48:52 -080081 thread_sleep(10);
82
Deepa Dinamani7e729772013-02-25 11:54:05 -080083 /* Get status of GPIO */
84 status = gpio_status(TLMM_VOL_UP_BTN_GPIO);
85
86 /* Active low signal. */
87 return !status;
88}
89
90/* Return 1 if vol_down pressed */
91uint32_t target_volume_down()
92{
93 /* Volume down button tied in with PMIC RESIN. */
94 return pm8x41_resin_status();
95}
96
Deepa Dinamani645e9b12012-12-21 14:23:40 -080097static void target_keystatus()
98{
Deepa Dinamani7e729772013-02-25 11:54:05 -080099 keys_init();
100
101 if(target_volume_down())
102 keys_post_event(KEY_VOLUMEDOWN, 1);
103
104 if(target_volume_up())
105 keys_post_event(KEY_VOLUMEUP, 1);
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800106}
107
Deepa Dinamani6bb87d52013-02-26 14:37:36 -0800108/* Set up params for h/w CRYPTO_ENGINE. */
109void target_crypto_init_params()
110{
111 struct crypto_init_params ce_params;
112
113 /* Set up base addresses and instance. */
114 ce_params.crypto_instance = CRYPTO_ENGINE_INSTANCE;
115 ce_params.crypto_base = MSM_CE1_BASE;
116 ce_params.bam_base = MSM_CE1_BAM_BASE;
117
118 /* Set up BAM config. */
119 ce_params.bam_ee = CRYPTO_ENGINE_EE;
120 ce_params.pipes.read_pipe = CRYPTO_ENGINE_READ_PIPE;
121 ce_params.pipes.write_pipe = CRYPTO_ENGINE_WRITE_PIPE;
122
123 /* Assign buffer sizes. */
124 ce_params.num_ce = CRYPTO_ENGINE_CMD_ARRAY_SIZE;
125 ce_params.read_fifo_size = CRYPTO_ENGINE_FIFO_SIZE;
126 ce_params.write_fifo_size = CRYPTO_ENGINE_FIFO_SIZE;
127
128 crypto_init_params(&ce_params);
129}
130
Channagoud Kadabi3c50c312013-05-02 17:16:03 -0700131void target_sdc_init()
132{
133 struct mmc_config_data config;
134
135 /*
136 * Set drive strength & pull ctrl for emmc
137 */
138 set_sdc_power_ctrl();
139
140 /* Enable sdhci mode */
141 sdhci_mode_enable(1);
142
143 config.bus_width = DATA_BUS_WIDTH_8BIT;
144 config.max_clk_rate = MMC_CLK_200MHZ;
145
146 /* Trying Slot 1*/
147 config.slot = 1;
148 config.base = mmc_sdhci_base[config.slot - 1];
149 if (!(dev = mmc_init(&config)))
150 {
151 /* Trying Slot 2 next */
152 config.slot = 2;
153 config.base = mmc_sdhci_base[config.slot - 1];
154 if (!(dev = mmc_init(&config))) {
155 dprintf(CRITICAL, "mmc init failed!");
156 ASSERT(0);
157 }
158 }
159
160 /*
161 * MMC initialization is complete, read the partition table info
162 */
163 if (partition_read_table()) {
164 dprintf(CRITICAL, "Error reading the partition table info\n");
165 ASSERT(0);
166 }
167}
168
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800169void target_init(void)
170{
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800171 dprintf(INFO, "target_init()\n");
172
173 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
174
175 target_keystatus();
176
Channagoud Kadabi3c50c312013-05-02 17:16:03 -0700177 target_sdc_init();
Deepa Dinamani6bb87d52013-02-26 14:37:36 -0800178
179 if (target_use_signed_kernel())
180 target_crypto_init_params();
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800181}
182
Deepa Dinamani058f1cd2013-02-25 10:53:01 -0800183/* Do any target specific intialization needed before entering fastboot mode */
184void target_fastboot_init(void)
185{
186 /* Set the BOOT_DONE flag in PM8026 */
187 pm8x41_set_boot_done();
188}
189
Deepa Dinamaniff2b9ce2013-02-25 11:01:00 -0800190/* Detect the target type */
191void target_detect(struct board_data *board)
192{
193 board->target = LINUX_MACHTYPE_UNKNOWN;
194}
195
196/* Detect the modem type */
197void target_baseband_detect(struct board_data *board)
198{
199 uint32_t platform;
200 uint32_t platform_subtype;
201
202 platform = board->platform;
203 platform_subtype = board->platform_subtype;
204
205 /*
206 * Look for platform subtype if present, else
207 * check for platform type to decide on the
208 * baseband type
209 */
210 switch(platform_subtype)
211 {
212 case HW_PLATFORM_SUBTYPE_UNKNOWN:
213 break;
214 default:
215 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype);
216 ASSERT(0);
217 };
218
219 switch(platform)
220 {
221 case MSM8826:
222 case MSM8626:
223 case MSM8226:
Deepa Dinamani7eeecf62013-05-21 12:43:26 -0700224 case MSM8926:
225 case MSM8126:
226 case MSM8326:
Deepa Dinamaniff2b9ce2013-02-25 11:01:00 -0800227 board->baseband = BASEBAND_MSM;
228 break;
Deepa Dinamani7eeecf62013-05-21 12:43:26 -0700229 case APQ8026:
230 board->baseband = BASEBAND_APQ;
231 break;
Deepa Dinamaniff2b9ce2013-02-25 11:01:00 -0800232 default:
233 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
234 ASSERT(0);
235 };
236}
237
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800238void target_serialno(unsigned char *buf)
239{
240 uint32_t serialno;
241 if (target_is_emmc_boot()) {
242 serialno = mmc_get_psn();
243 snprintf((char *)buf, 13, "%x", serialno);
244 }
245}
246
Deepa Dinamani8d2bb222013-02-26 14:03:04 -0800247unsigned check_reboot_mode(void)
248{
249 uint32_t restart_reason = 0;
250
251 /* Read reboot reason and scrub it */
252 restart_reason = readl(RESTART_REASON_ADDR);
253 writel(0x00, RESTART_REASON_ADDR);
254
255 return restart_reason;
256}
257
Deepa Dinamanif7c03c12013-02-26 14:17:20 -0800258void reboot_device(unsigned reboot_reason)
259{
260 writel(reboot_reason, RESTART_REASON_ADDR);
261
262 /* Configure PMIC for warm reset */
263 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
264
265 /* Drop PS_HOLD for MSM */
266 writel(0x00, MPM2_MPM_PS_HOLD);
267
268 mdelay(5000);
269
270 dprintf(CRITICAL, "Rebooting failed\n");
271}
272
Deepa Dinamani6bb87d52013-02-26 14:37:36 -0800273crypto_engine_type board_ce_type(void)
274{
275 return CRYPTO_ENGINE_TYPE_HW;
276}
277
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800278unsigned board_machtype(void)
279{
Deepa Dinamani8d6b4252013-03-06 11:16:41 -0800280 return 0;
281}
282
283void target_usb_stop(void)
284{
285 /* Disable VBUS mimicing in the controller. */
286 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
Deepa Dinamani645e9b12012-12-21 14:23:40 -0800287}
Amol Jadi85e19192013-02-28 22:45:04 -0800288
289void target_usb_init(void)
290{
291 uint32_t val;
292
293 /* Select and enable external configuration with USB PHY */
294 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
295
296 /* Enable sess_vld */
297 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
298 writel(val, USB_GENCONFIG_2);
299
300 /* Enable external vbus configuration in the LINK */
301 val = readl(USB_USBCMD);
302 val |= SESS_VLD_CTRL;
303 writel(val, USB_USBCMD);
304}
Deepa Dinamanicde64572013-02-25 15:02:25 -0800305
306unsigned target_pause_for_battery_charge(void)
307{
308 uint8_t pon_reason = pm8x41_get_pon_reason();
309
310 /* This function will always return 0 to facilitate
311 * automated testing/reboot with usb connected.
312 * uncomment if this feature is needed.
313 */
314 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
315 * return 1;
316 */
317
318 return 0;
319}
Channagoud Kadabida54ca12013-03-29 11:22:15 -0700320
321unsigned target_baseband()
322{
323 return board_baseband();
324}
Stanimir Varbanov7f9d7a72013-04-29 12:05:39 +0300325
326int emmc_recovery_init(void)
327{
Pavel Nedev16f49232013-04-29 16:15:36 +0300328 return _emmc_recovery_init();
329}
330
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300331int set_download_mode(enum dload_mode mode)
Pavel Nedev16f49232013-04-29 16:15:36 +0300332{
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300333 dload_util_write_cookie(mode == NORMAL_DLOAD ?
334 DLOAD_MODE_ADDR : EMERGENCY_DLOAD_MODE_ADDR, mode);
Pavel Nedev16f49232013-04-29 16:15:36 +0300335
336 return 0;
Stanimir Varbanov7f9d7a72013-04-29 12:05:39 +0300337}
Channagoud Kadabi3c50c312013-05-02 17:16:03 -0700338
339static void set_sdc_power_ctrl()
340{
341 /* Drive strength configs for sdc pins */
342 struct tlmm_cfgs sdc1_hdrv_cfg[] =
343 {
344 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
345 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
346 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
347 };
348
349 /* Pull configs for sdc pins */
350 struct tlmm_cfgs sdc1_pull_cfg[] =
351 {
352 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
353 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
354 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
355 };
356
357 /* Set the drive strength & pull control values */
358 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
359 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
360}
361
362struct mmc_device *target_mmc_device()
363{
364 return dev;
365}