blob: 4b5f8b4c7ac353f558d9f5bcc993db86e5fec61c [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>
Channagoud Kadabib14d6d02013-05-15 10:48:59 -070031#include <platform/irqs.h>
Channagoud Kadabi744c8902013-04-02 11:54:53 -070032#include <platform/gpio.h>
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080033#include <reg.h>
34#include <target.h>
35#include <platform.h>
Pavel Nedev03511492013-03-08 19:05:32 -080036#include <dload_util.h>
Deepa Dinamani26e93262012-05-21 17:35:14 -070037#include <uart_dm.h>
Amol Jadi29f95032012-06-22 12:52:54 -070038#include <mmc.h>
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080039#include <spmi.h>
Neeti Desai465491e2012-07-31 12:53:35 -070040#include <board.h>
41#include <smem.h>
42#include <baseband.h>
Deepa Dinamani9a612932012-08-14 16:15:03 -070043#include <dev/keys.h>
44#include <pm8x41.h>
Deepa Dinamanib9a57202012-12-20 18:05:11 -080045#include <crypto5_wrapper.h>
Eugene Yasmana0d18122013-02-26 13:23:05 +020046#include <hsusb.h>
47#include <clock.h>
sundarajan srinivasana098d832013-03-07 12:19:30 -080048#include <partition_parser.h>
49#include <scm.h>
50#include <platform/clock.h>
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070051#include <platform/gpio.h>
Channagoud Kadabif84830c2013-04-19 14:35:47 -070052#include <stdlib.h>
Deepa Dinamanib9a57202012-12-20 18:05:11 -080053
54extern bool target_use_signed_kernel(void);
Channagoud Kadabi744c8902013-04-02 11:54:53 -070055static void set_sdc_power_ctrl();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080056
57static unsigned int target_id;
Deepa Dinamani07f15712013-03-08 17:02:13 -080058static uint32_t pmic_ver;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080059
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070060#if MMC_SDHCI_SUPPORT
61struct mmc_device *dev;
62#endif
63
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080064#define PMIC_ARB_CHANNEL_NUM 0
65#define PMIC_ARB_OWNER_ID 0
66
Deepa Dinamani1e094942012-10-30 15:49:02 -070067#define WDOG_DEBUG_DISABLE_BIT 17
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080068
Channagoud Kadabi974391e2013-10-02 17:32:11 -070069#define CE1_INSTANCE 1
70#define CE2_INSTANCE 2
Deepa Dinamanib9a57202012-12-20 18:05:11 -080071#define CE_EE 1
72#define CE_FIFO_SIZE 64
73#define CE_READ_PIPE 3
74#define CE_WRITE_PIPE 2
Deepa Dinamani809c4282013-07-09 14:06:02 -070075#define CE_READ_PIPE_LOCK_GRP 0
76#define CE_WRITE_PIPE_LOCK_GRP 0
Deepa Dinamanib9a57202012-12-20 18:05:11 -080077#define CE_ARRAY_SIZE 20
78
sundarajan srinivasana098d832013-03-07 12:19:30 -080079#ifdef SSD_ENABLE
80#define SSD_CE_INSTANCE_1 1
81#define SSD_PARTITION_SIZE 8192
82#endif
83
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -070084#define FASTBOOT_MODE 0x77665500
85
Channagoud Kadabic48b3e92013-06-23 16:19:10 -070086#define BOARD_SOC_VERSION1(soc_rev) (soc_rev >= 0x10000 && soc_rev < 0x20000)
87
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070088#if MMC_SDHCI_SUPPORT
89static uint32_t mmc_sdhci_base[] =
90 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE, MSM_SDC4_SDHCI_BASE };
91#endif
92
Deepa Dinamanica5ad852012-05-07 18:19:47 -070093static uint32_t mmc_sdc_base[] =
94 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
95
Channagoud Kadabib14d6d02013-05-15 10:48:59 -070096static uint32_t mmc_sdc_pwrctl_irq[] =
97 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ, SDCC3_PWRCTL_IRQ, SDCC4_PWRCTL_IRQ };
98
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080099void target_early_init(void)
100{
Deepa Dinamanib073ba22012-08-10 11:06:41 -0700101#if WITH_DEBUG_UART
Neeti Desaiac011272012-08-29 18:24:54 -0700102 uart_dm_init(1, 0, BLSP1_UART1_BASE);
Deepa Dinamanib073ba22012-08-10 11:06:41 -0700103#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800104}
105
Deepa Dinamani9a612932012-08-14 16:15:03 -0700106/* Return 1 if vol_up pressed */
107static int target_volume_up()
108{
109 uint8_t status = 0;
110 struct pm8x41_gpio gpio;
111
112 /* CDP vol_up seems to be always grounded. So gpio status is read as 0,
113 * whether key is pressed or not.
114 * Ignore volume_up key on CDP for now.
115 */
116 if (board_hardware_id() == HW_PLATFORM_SURF)
117 return 0;
118
119 /* Configure the GPIO */
120 gpio.direction = PM_GPIO_DIR_IN;
121 gpio.function = 0;
122 gpio.pull = PM_GPIO_PULL_UP_30;
Eugene Yasman6382ee02013-01-16 13:00:56 +0200123 gpio.vin_sel = 2;
Deepa Dinamani9a612932012-08-14 16:15:03 -0700124
125 pm8x41_gpio_config(5, &gpio);
126
Channagoud Kadabi4d7b5302013-08-07 16:34:08 -0700127 /* Wait for the pmic gpio config to take effect */
128 thread_sleep(1);
129
Deepa Dinamani9a612932012-08-14 16:15:03 -0700130 /* Get status of P_GPIO_5 */
131 pm8x41_gpio_get(5, &status);
132
133 return !status; /* active low */
134}
135
136/* Return 1 if vol_down pressed */
Deepa Dinamani66a87962013-02-04 10:39:30 -0800137uint32_t target_volume_down()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700138{
Deepa Dinamani66a87962013-02-04 10:39:30 -0800139 /* Volume down button is tied in with RESIN on MSM8974. */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700140 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700141 return pm8x41_v2_resin_status();
Deepa Dinamani13bfc852013-02-05 17:56:47 -0800142 else
143 return pm8x41_resin_status();
Deepa Dinamani9a612932012-08-14 16:15:03 -0700144}
145
146static void target_keystatus()
147{
148 keys_init();
149
150 if(target_volume_down())
151 keys_post_event(KEY_VOLUMEDOWN, 1);
152
153 if(target_volume_up())
154 keys_post_event(KEY_VOLUMEUP, 1);
155}
156
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800157/* Set up params for h/w CE. */
158void target_crypto_init_params()
159{
160 struct crypto_init_params ce_params;
161
162 /* Set up base addresses and instance. */
Channagoud Kadabi974391e2013-10-02 17:32:11 -0700163 if (platform_is_8x62())
164 {
165 ce_params.crypto_instance = CE1_INSTANCE;
166 ce_params.crypto_base = MSM_CE1_BASE;
167 ce_params.bam_base = MSM_CE1_BAM_BASE;
168 }
169 else
170 {
171 ce_params.crypto_instance = CE2_INSTANCE;
172 ce_params.crypto_base = MSM_CE2_BASE;
173 ce_params.bam_base = MSM_CE2_BAM_BASE;
174 }
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800175
176 /* Set up BAM config. */
Deepa Dinamani809c4282013-07-09 14:06:02 -0700177 ce_params.bam_ee = CE_EE;
178 ce_params.pipes.read_pipe = CE_READ_PIPE;
179 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
180 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
181 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800182
183 /* Assign buffer sizes. */
184 ce_params.num_ce = CE_ARRAY_SIZE;
185 ce_params.read_fifo_size = CE_FIFO_SIZE;
186 ce_params.write_fifo_size = CE_FIFO_SIZE;
187
Deepa Dinamanie505d3d2013-05-14 16:55:38 -0700188 /* BAM is initialized by TZ for this platform.
189 * Do not do it again as the initialization address space
190 * is locked.
191 */
192 ce_params.do_bam_init = 0;
193
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800194 crypto_init_params(&ce_params);
195}
196
197crypto_engine_type board_ce_type(void)
198{
199 return CRYPTO_ENGINE_TYPE_HW;
200}
201
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700202#if MMC_SDHCI_SUPPORT
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700203static void target_mmc_sdhci_init()
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700204{
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700205 struct mmc_config_data config = {0};
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700206 uint32_t soc_ver = 0;
207
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700208 soc_ver = board_soc_version();
209
210 /*
211 * 8974 v1 fluid devices, have a hardware bug
212 * which limits the bus width to 4 bit.
213 */
214 switch(board_hardware_id())
215 {
216 case HW_PLATFORM_FLUID:
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700217 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700218 config.bus_width = DATA_BUS_WIDTH_4BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700219 else
220 config.bus_width = DATA_BUS_WIDTH_8BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700221 break;
222 default:
223 config.bus_width = DATA_BUS_WIDTH_8BIT;
224 };
225
226 config.max_clk_rate = MMC_CLK_200MHZ;
227
228 /* Trying Slot 1*/
229 config.slot = 1;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700230 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
231 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
232 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700233
234 if (!(dev = mmc_init(&config))) {
235 /* Trying Slot 2 next */
236 config.slot = 2;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700237 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
238 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
239 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
240
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700241 if (!(dev = mmc_init(&config))) {
242 dprintf(CRITICAL, "mmc init failed!");
243 ASSERT(0);
244 }
245 }
Channagoud Kadabief5332f2013-05-16 15:23:43 -0700246
247 /*
248 * MMC initialization is complete, read the partition table info
249 */
250 if (partition_read_table()) {
251 dprintf(CRITICAL, "Error reading the partition table info\n");
252 ASSERT(0);
253 }
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700254}
255
Channagoud Kadabi6faaf702013-09-10 15:00:51 -0700256void *target_mmc_device()
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700257{
Channagoud Kadabi6faaf702013-09-10 15:00:51 -0700258 return (void *) dev;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700259}
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700260
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700261#else
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700262static void target_mmc_mci_init()
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800263{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700264 uint32_t base_addr;
265 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800266
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700267 /* Trying Slot 1 */
268 slot = 1;
269 base_addr = mmc_sdc_base[slot - 1];
270
271 if (mmc_boot_main(slot, base_addr))
272 {
273 /* Trying Slot 2 next */
274 slot = 2;
275 base_addr = mmc_sdc_base[slot - 1];
276 if (mmc_boot_main(slot, base_addr)) {
277 dprintf(CRITICAL, "mmc init failed!");
278 ASSERT(0);
279 }
280 }
281}
282
283/*
284 * Function to set the capabilities for the host
285 */
286void target_mmc_caps(struct mmc_host *host)
287{
288 uint32_t soc_ver = 0;
289
290 soc_ver = board_soc_version();
291
292 /*
293 * 8974 v1 fluid devices, have a hardware bug
294 * which limits the bus width to 4 bit.
295 */
296 switch(board_hardware_id())
297 {
298 case HW_PLATFORM_FLUID:
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700299 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700300 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700301 else
302 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700303 break;
304 default:
305 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
306 };
307
308 host->caps.ddr_mode = 1;
309 host->caps.hs200_mode = 1;
310 host->caps.hs_clk_rate = MMC_CLK_96MHZ;
311}
312#endif
313
314
315void target_init(void)
316{
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800317 dprintf(INFO, "target_init()\n");
318
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800319 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800320
Deepa Dinamani07f15712013-03-08 17:02:13 -0800321 /* Save PM8941 version info. */
322 pmic_ver = pm8x41_get_pmic_rev();
323
Deepa Dinamani9a612932012-08-14 16:15:03 -0700324 target_keystatus();
325
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800326 if (target_use_signed_kernel())
327 target_crypto_init_params();
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800328 /* Display splash screen if enabled */
329#if DISPLAY_SPLASH_SCREEN
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800330 dprintf(INFO, "Display Init: Start\n");
Channagoud Kadabia178a502013-09-26 10:59:47 -0700331 if (!platform_is_8x62())
Channagoud Kadabi20e0dd12013-08-06 12:30:51 -0700332 {
333 display_init();
334 }
Channagoud Kadabi8a9c6a22013-02-05 14:43:48 -0800335 dprintf(INFO, "Display Init: Done\n");
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800336#endif
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800337
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700338 /*
339 * Set drive strength & pull ctrl for
340 * emmc
341 */
342 set_sdc_power_ctrl();
343
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700344#if MMC_SDHCI_SUPPORT
345 target_mmc_sdhci_init();
346#else
347 target_mmc_mci_init();
348#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800349}
350
351unsigned board_machtype(void)
352{
353 return target_id;
354}
355
356/* Do any target specific intialization needed before entering fastboot mode */
sundarajan srinivasana098d832013-03-07 12:19:30 -0800357#ifdef SSD_ENABLE
sundarajan srinivasana098d832013-03-07 12:19:30 -0800358static void ssd_load_keystore_from_emmc()
359{
360 uint64_t ptn = 0;
361 int index = -1;
362 uint32_t size = SSD_PARTITION_SIZE;
363 int ret = -1;
364
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700365 uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE,
366 ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE));
367
368 if (!buffer) {
369 dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n");
370 ASSERT(0);
371 }
372
sundarajan srinivasana098d832013-03-07 12:19:30 -0800373 index = partition_get_index("ssd");
374
375 ptn = partition_get_offset(index);
376 if(ptn == 0){
377 dprintf(CRITICAL,"ERROR: ssd parition not found");
378 return;
379 }
380
381 if(mmc_read(ptn, buffer, size)){
382 dprintf(CRITICAL,"ERROR:Cannot read data\n");
383 return;
384 }
385
386 ret = scm_protect_keystore((uint32_t *)&buffer[0],size);
387 if(ret != 0)
388 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed");
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700389
390 free(buffer);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800391}
392#endif
393
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800394void target_fastboot_init(void)
395{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700396 /* Set the BOOT_DONE flag in PM8921 */
Channagoud Kadabia178a502013-09-26 10:59:47 -0700397 if (!platform_is_8x62())
398 pm8x41_set_boot_done();
sundarajan srinivasana098d832013-03-07 12:19:30 -0800399
400#ifdef SSD_ENABLE
401 clock_ce_enable(SSD_CE_INSTANCE_1);
402 ssd_load_keystore_from_emmc();
403#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800404}
Neeti Desai465491e2012-07-31 12:53:35 -0700405
406/* Detect the target type */
407void target_detect(struct board_data *board)
408{
409 board->target = LINUX_MACHTYPE_UNKNOWN;
410}
411
412/* Detect the modem type */
413void target_baseband_detect(struct board_data *board)
414{
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800415 uint32_t platform;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800416
417 platform = board->platform;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800418
419 switch(platform) {
420 case MSM8974:
Deepa Dinamani713a76f2013-05-03 13:17:24 -0700421 case MSM8274:
422 case MSM8674:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700423 case MSM8274AA:
424 case MSM8274AB:
425 case MSM8274AC:
426 case MSM8674AA:
427 case MSM8674AB:
428 case MSM8674AC:
429 case MSM8974AA:
430 case MSM8974AB:
431 case MSM8974AC:
Channagoud Kadabia178a502013-09-26 10:59:47 -0700432 case MSM8262:
433 case MSM8962:
Neeti Desai465491e2012-07-31 12:53:35 -0700434 board->baseband = BASEBAND_MSM;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800435 break;
436 case APQ8074:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700437 case APQ8074AA:
438 case APQ8074AB:
439 case APQ8074AC:
Channagoud Kadabia178a502013-09-26 10:59:47 -0700440 case APQ8062:
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800441 board->baseband = BASEBAND_APQ;
442 break;
443 default:
444 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
445 ASSERT(0);
446 };
Neeti Desai465491e2012-07-31 12:53:35 -0700447}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700448
Deepa Dinamani927a6b62013-03-28 17:05:32 -0700449unsigned target_baseband()
450{
451 return board_baseband();
452}
453
Deepa Dinamani9a612932012-08-14 16:15:03 -0700454void target_serialno(unsigned char *buf)
455{
456 unsigned int serialno;
457 if (target_is_emmc_boot()) {
458 serialno = mmc_get_psn();
459 snprintf((char *)buf, 13, "%x", serialno);
460 }
461}
Amol Jadi6639d452012-08-16 14:51:19 -0700462
463unsigned check_reboot_mode(void)
464{
465 uint32_t restart_reason = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800466 uint32_t soc_ver = 0;
467 uint32_t restart_reason_addr;
468
469 soc_ver = board_soc_version();
470
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700471 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800472 restart_reason_addr = RESTART_REASON_ADDR;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700473 else
474 restart_reason_addr = RESTART_REASON_ADDR_V2;
Amol Jadi6639d452012-08-16 14:51:19 -0700475
476 /* Read reboot reason and scrub it */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800477 restart_reason = readl(restart_reason_addr);
478 writel(0x00, restart_reason_addr);
Amol Jadi6639d452012-08-16 14:51:19 -0700479
480 return restart_reason;
481}
Neeti Desai120b55d2012-08-20 17:15:56 -0700482
483void reboot_device(unsigned reboot_reason)
484{
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800485 uint32_t soc_ver = 0;
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700486 uint8_t reset_type = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800487
488 soc_ver = board_soc_version();
489
Neeti Desai120b55d2012-08-20 17:15:56 -0700490 /* Write the reboot reason */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700491 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800492 writel(reboot_reason, RESTART_REASON_ADDR);
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700493 else
494 writel(reboot_reason, RESTART_REASON_ADDR_V2);
Neeti Desai120b55d2012-08-20 17:15:56 -0700495
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700496 if(reboot_reason == FASTBOOT_MODE)
497 reset_type = PON_PSHOLD_WARM_RESET;
498 else
499 reset_type = PON_PSHOLD_HARD_RESET;
500
Neeti Desai120b55d2012-08-20 17:15:56 -0700501 /* Configure PMIC for warm reset */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700502 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700503 pm8x41_v2_reset_configure(reset_type);
Deepa Dinamani07f15712013-03-08 17:02:13 -0800504 else
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700505 pm8x41_reset_configure(reset_type);
Neeti Desai120b55d2012-08-20 17:15:56 -0700506
Deepa Dinamani1e094942012-10-30 15:49:02 -0700507 /* Disable Watchdog Debug.
508 * Required becuase of a H/W bug which causes the system to
509 * reset partially even for non watchdog resets.
510 */
511 writel(readl(GCC_WDOG_DEBUG) & ~(1 << WDOG_DEBUG_DISABLE_BIT), GCC_WDOG_DEBUG);
512
Deepa Dinamanie0808e52012-11-26 15:22:46 -0800513 dsb();
514
515 /* Wait until the write takes effect. */
516 while(readl(GCC_WDOG_DEBUG) & (1 << WDOG_DEBUG_DISABLE_BIT));
517
Neeti Desai120b55d2012-08-20 17:15:56 -0700518 /* Drop PS_HOLD for MSM */
519 writel(0x00, MPM2_MPM_PS_HOLD);
520
521 mdelay(5000);
522
523 dprintf(CRITICAL, "Rebooting failed\n");
524}
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800525
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300526int set_download_mode(enum dload_mode mode)
Pavel Nedev03511492013-03-08 19:05:32 -0800527{
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300528 dload_util_write_cookie(mode == NORMAL_DLOAD ?
529 DLOAD_MODE_ADDR_V2 : EMERGENCY_DLOAD_MODE_ADDR_V2, mode);
Pavel Nedev03511492013-03-08 19:05:32 -0800530
531 return 0;
532}
533
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700534/* Check if MSM needs VBUS mimic for USB */
535static int target_needs_vbus_mimic()
536{
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700537 if (platform_is_8974())
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700538 return 0;
539
540 return 1;
541}
542
Eugene Yasmana0d18122013-02-26 13:23:05 +0200543/* Do target specific usb initialization */
544void target_usb_init(void)
545{
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700546 uint32_t val;
547
Eugene Yasmana0d18122013-02-26 13:23:05 +0200548 /* Enable secondary USB PHY on DragonBoard8074 */
549 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
550 /* Route ChipIDea to use secondary USB HS port2 */
551 writel_relaxed(1, USB2_PHY_SEL);
552
553 /* Enable access to secondary PHY by clamping the low
554 * voltage interface between DVDD of the PHY and Vddcx
555 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
556 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
557 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
558
559 /* Perform power-on-reset of the PHY.
560 * Delay values are arbitrary */
561 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
562 USB_OTG_HS_PHY_CTRL);
563 thread_sleep(10);
564 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
565 USB_OTG_HS_PHY_CTRL);
566 thread_sleep(10);
567
568 /* Enable HSUSB PHY port for ULPI interface,
569 * then configure related parameters within the PHY */
570 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
571 | 0x8c000004), USB_PORTSC);
572 }
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700573
574 if (target_needs_vbus_mimic())
575 {
576 /* Select and enable external configuration with USB PHY */
577 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
578
579 /* Enable sess_vld */
580 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
581 writel(val, USB_GENCONFIG_2);
582
583 /* Enable external vbus configuration in the LINK */
584 val = readl(USB_USBCMD);
585 val |= SESS_VLD_CTRL;
586 writel(val, USB_USBCMD);
587 }
Eugene Yasmana0d18122013-02-26 13:23:05 +0200588}
589
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800590/* Returns 1 if target supports continuous splash screen. */
591int target_cont_splash_screen()
592{
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800593 switch(board_hardware_id())
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800594 {
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800595 case HW_PLATFORM_SURF:
596 case HW_PLATFORM_MTP:
597 case HW_PLATFORM_FLUID:
Asaf Pensob85263f2013-05-01 10:54:34 +0300598 case HW_PLATFORM_DRAGON:
Kuogee Hsiehdf636eb2013-08-01 14:52:08 -0700599 case HW_PLATFORM_LIQUID:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800600 dprintf(SPEW, "Target_cont_splash=1\n");
601 return 1;
602 break;
603 default:
604 dprintf(SPEW, "Target_cont_splash=0\n");
605 return 0;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800606 }
607}
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800608
609unsigned target_pause_for_battery_charge(void)
610{
611 uint8_t pon_reason = pm8x41_get_pon_reason();
612
613 /* This function will always return 0 to facilitate
614 * automated testing/reboot with usb connected.
615 * uncomment if this feature is needed */
616 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
617 return 1;*/
618
619 return 0;
620}
sundarajan srinivasana098d832013-03-07 12:19:30 -0800621
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700622void target_uninit(void)
sundarajan srinivasana098d832013-03-07 12:19:30 -0800623{
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700624#if MMC_SDHCI_SUPPORT
625 mmc_put_card_to_sleep(dev);
626#else
627 mmc_put_card_to_sleep();
628#endif
sundarajan srinivasana098d832013-03-07 12:19:30 -0800629#ifdef SSD_ENABLE
630 clock_ce_disable(SSD_CE_INSTANCE_1);
631#endif
632}
Deepa Dinamani65df9822013-03-08 13:38:34 -0800633
634void shutdown_device()
635{
636 dprintf(CRITICAL, "Going down for shutdown.\n");
637
638 /* Configure PMIC for shutdown. */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700639 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Deepa Dinamani65df9822013-03-08 13:38:34 -0800640 pm8x41_v2_reset_configure(PON_PSHOLD_SHUTDOWN);
641 else
642 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
643
644 /* Drop PS_HOLD for MSM */
645 writel(0x00, MPM2_MPM_PS_HOLD);
646
647 mdelay(5000);
648
649 dprintf(CRITICAL, "Shutdown failed\n");
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700650}
651
652static void set_sdc_power_ctrl()
653{
Channagoud Kadabi224d8322013-09-27 14:25:22 -0700654 uint8_t tlmm_hdrv_clk = 0;
655 uint32_t platform_id = 0;
656
657 platform_id = board_platform_id();
658
659 switch(platform_id)
660 {
661 case MSM8274AA:
662 case MSM8274AB:
663 case MSM8674AA:
664 case MSM8674AB:
665 case MSM8974AA:
666 case MSM8974AB:
667 if (board_hardware_id() == HW_PLATFORM_MTP)
668 tlmm_hdrv_clk = TLMM_CUR_VAL_10MA;
669 else
670 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
671 break;
672 default:
673 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
674 };
675
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700676 /* Drive strength configs for sdc pins */
677 struct tlmm_cfgs sdc1_hdrv_cfg[] =
678 {
Channagoud Kadabi224d8322013-09-27 14:25:22 -0700679 { SDC1_CLK_HDRV_CTL_OFF, tlmm_hdrv_clk, TLMM_HDRV_MASK },
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700680 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
681 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
682 };
683
684 /* Pull configs for sdc pins */
685 struct tlmm_cfgs sdc1_pull_cfg[] =
686 {
687 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
688 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
689 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
690 };
691
692 /* Set the drive strength & pull control values */
693 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
694 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
695}
Stanimir Varbanovf64a0292013-04-29 11:58:27 +0300696
697int emmc_recovery_init(void)
698{
699 return _emmc_recovery_init();
700}
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700701
702void target_usb_stop(void)
703{
704 uint32_t platform = board_platform_id();
705
706 /* Disable VBUS mimicing in the controller. */
707 if (target_needs_vbus_mimic())
708 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
709}
Amol Jadi4c3229f2013-10-07 14:38:06 -0700710
711/* identify the usb controller to be used for the target */
712const char * target_usb_controller()
713{
714 switch(board_platform_id())
715 {
716 /* use dwc controller for PRO chips (with some exceptions) */
717 case MSM8974AA:
718 case MSM8974AB:
719 case MSM8974AC:
720 /* exceptions based on hardware id */
721 if (board_hardware_id() != HW_PLATFORM_DRAGON)
722 return "dwc";
723 /* fall through to default "ci" for anything that did'nt select "dwc" */
724 default:
725 return "ci";
726 }
727}
Amol Jadi28864bb2013-10-11 14:12:59 -0700728
729/* UTMI MUX configuration to connect PHY to SNPS controller:
730 * Configure primary HS phy mux to use UTMI interface
731 * (connected to usb30 controller).
732 */
733static void tcsr_hs_phy_mux_configure(void)
734{
735 uint32_t reg;
736
737 reg = readl(USB2_PHY_SEL);
738
739 writel(reg | 0x1, USB2_PHY_SEL);
740}
741
742/* configure hs phy mux if using dwc controller */
743void target_usb_phy_mux_configure(void)
744{
745 if(!strcmp(target_usb_controller(), "dwc"))
746 {
747 tcsr_hs_phy_mux_configure();
748 }
749}