blob: a7e0ca8ec3da4ab2fb58f89ce3cf4a3920581a66 [file] [log] [blame]
Channagoud Kadabia7ab9312014-01-08 12:11:23 -08001/* Copyright (c) 2012-2014, 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>
vijay kumar32856d52014-08-06 16:18:03 +053034#include <string.h>
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080035#include <target.h>
36#include <platform.h>
Pavel Nedev03511492013-03-08 19:05:32 -080037#include <dload_util.h>
Deepa Dinamani26e93262012-05-21 17:35:14 -070038#include <uart_dm.h>
Amol Jadi29f95032012-06-22 12:52:54 -070039#include <mmc.h>
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080040#include <spmi.h>
Neeti Desai465491e2012-07-31 12:53:35 -070041#include <board.h>
42#include <smem.h>
43#include <baseband.h>
Deepa Dinamani9a612932012-08-14 16:15:03 -070044#include <dev/keys.h>
45#include <pm8x41.h>
Deepa Dinamanib9a57202012-12-20 18:05:11 -080046#include <crypto5_wrapper.h>
Eugene Yasmana0d18122013-02-26 13:23:05 +020047#include <hsusb.h>
48#include <clock.h>
sundarajan srinivasana098d832013-03-07 12:19:30 -080049#include <partition_parser.h>
vijay kumar32856d52014-08-06 16:18:03 +053050#include <sdhci_msm.h>
51#include <qtimer.h>
sundarajan srinivasana098d832013-03-07 12:19:30 -080052#include <scm.h>
53#include <platform/clock.h>
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070054#include <platform/gpio.h>
Channagoud Kadabif84830c2013-04-19 14:35:47 -070055#include <stdlib.h>
Deepa Dinamanib9a57202012-12-20 18:05:11 -080056
Channagoud Kadabi62ac4cb2014-05-13 11:55:38 -070057#define HW_PLATFORM_8994_INTERPOSER 0x3
58
vijay kumar32856d52014-08-06 16:18:03 +053059extern int platform_is_8974();
60extern int platform_is_8974ac();
Deepa Dinamanib9a57202012-12-20 18:05:11 -080061extern bool target_use_signed_kernel(void);
Channagoud Kadabi744c8902013-04-02 11:54:53 -070062static void set_sdc_power_ctrl();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080063
64static unsigned int target_id;
Deepa Dinamani07f15712013-03-08 17:02:13 -080065static uint32_t pmic_ver;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080066
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070067#if MMC_SDHCI_SUPPORT
68struct mmc_device *dev;
69#endif
70
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080071#define PMIC_ARB_CHANNEL_NUM 0
72#define PMIC_ARB_OWNER_ID 0
73
Deepa Dinamani1e094942012-10-30 15:49:02 -070074#define WDOG_DEBUG_DISABLE_BIT 17
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080075
Channagoud Kadabia1ef8092014-01-08 12:11:58 -080076#define CE_INSTANCE 2
Deepa Dinamanib9a57202012-12-20 18:05:11 -080077#define CE_EE 1
78#define CE_FIFO_SIZE 64
79#define CE_READ_PIPE 3
80#define CE_WRITE_PIPE 2
Deepa Dinamani809c4282013-07-09 14:06:02 -070081#define CE_READ_PIPE_LOCK_GRP 0
82#define CE_WRITE_PIPE_LOCK_GRP 0
Deepa Dinamanib9a57202012-12-20 18:05:11 -080083#define CE_ARRAY_SIZE 20
84
sundarajan srinivasana098d832013-03-07 12:19:30 -080085#ifdef SSD_ENABLE
86#define SSD_CE_INSTANCE_1 1
87#define SSD_PARTITION_SIZE 8192
88#endif
89
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -070090#define FASTBOOT_MODE 0x77665500
91
Channagoud Kadabic48b3e92013-06-23 16:19:10 -070092#define BOARD_SOC_VERSION1(soc_rev) (soc_rev >= 0x10000 && soc_rev < 0x20000)
93
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070094#if MMC_SDHCI_SUPPORT
95static uint32_t mmc_sdhci_base[] =
96 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE, MSM_SDC4_SDHCI_BASE };
97#endif
98
Deepa Dinamanica5ad852012-05-07 18:19:47 -070099static uint32_t mmc_sdc_base[] =
100 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
101
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700102static uint32_t mmc_sdc_pwrctl_irq[] =
103 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ, SDCC3_PWRCTL_IRQ, SDCC4_PWRCTL_IRQ };
104
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800105void target_early_init(void)
106{
Deepa Dinamanib073ba22012-08-10 11:06:41 -0700107#if WITH_DEBUG_UART
Neeti Desaiac011272012-08-29 18:24:54 -0700108 uart_dm_init(1, 0, BLSP1_UART1_BASE);
Deepa Dinamanib073ba22012-08-10 11:06:41 -0700109#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800110}
111
Channagoud Kadabi62ac4cb2014-05-13 11:55:38 -0700112uint32_t target_hw_interposer()
113{
114 return board_hardware_subtype() == HW_PLATFORM_8994_INTERPOSER ? 1 : 0;
115}
116
Deepa Dinamani9a612932012-08-14 16:15:03 -0700117/* Return 1 if vol_up pressed */
118static int target_volume_up()
119{
120 uint8_t status = 0;
121 struct pm8x41_gpio gpio;
122
123 /* CDP vol_up seems to be always grounded. So gpio status is read as 0,
124 * whether key is pressed or not.
125 * Ignore volume_up key on CDP for now.
126 */
127 if (board_hardware_id() == HW_PLATFORM_SURF)
128 return 0;
129
130 /* Configure the GPIO */
131 gpio.direction = PM_GPIO_DIR_IN;
132 gpio.function = 0;
133 gpio.pull = PM_GPIO_PULL_UP_30;
Eugene Yasman6382ee02013-01-16 13:00:56 +0200134 gpio.vin_sel = 2;
Deepa Dinamani9a612932012-08-14 16:15:03 -0700135
136 pm8x41_gpio_config(5, &gpio);
137
Channagoud Kadabi4d7b5302013-08-07 16:34:08 -0700138 /* Wait for the pmic gpio config to take effect */
139 thread_sleep(1);
140
Deepa Dinamani9a612932012-08-14 16:15:03 -0700141 /* Get status of P_GPIO_5 */
142 pm8x41_gpio_get(5, &status);
143
144 return !status; /* active low */
145}
146
147/* Return 1 if vol_down pressed */
Deepa Dinamani66a87962013-02-04 10:39:30 -0800148uint32_t target_volume_down()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700149{
Deepa Dinamani66a87962013-02-04 10:39:30 -0800150 /* Volume down button is tied in with RESIN on MSM8974. */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700151 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700152 return pm8x41_v2_resin_status();
Deepa Dinamani13bfc852013-02-05 17:56:47 -0800153 else
154 return pm8x41_resin_status();
Deepa Dinamani9a612932012-08-14 16:15:03 -0700155}
156
157static void target_keystatus()
158{
159 keys_init();
160
161 if(target_volume_down())
162 keys_post_event(KEY_VOLUMEDOWN, 1);
163
164 if(target_volume_up())
165 keys_post_event(KEY_VOLUMEUP, 1);
166}
167
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800168/* Set up params for h/w CE. */
169void target_crypto_init_params()
170{
171 struct crypto_init_params ce_params;
172
173 /* Set up base addresses and instance. */
Channagoud Kadabia1ef8092014-01-08 12:11:58 -0800174 ce_params.crypto_instance = CE_INSTANCE;
175 ce_params.crypto_base = MSM_CE2_BASE;
176 ce_params.bam_base = MSM_CE2_BAM_BASE;
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800177
178 /* Set up BAM config. */
Deepa Dinamani809c4282013-07-09 14:06:02 -0700179 ce_params.bam_ee = CE_EE;
180 ce_params.pipes.read_pipe = CE_READ_PIPE;
181 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
182 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
183 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800184
185 /* Assign buffer sizes. */
186 ce_params.num_ce = CE_ARRAY_SIZE;
187 ce_params.read_fifo_size = CE_FIFO_SIZE;
188 ce_params.write_fifo_size = CE_FIFO_SIZE;
189
Deepa Dinamanie505d3d2013-05-14 16:55:38 -0700190 /* BAM is initialized by TZ for this platform.
191 * Do not do it again as the initialization address space
192 * is locked.
193 */
194 ce_params.do_bam_init = 0;
195
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800196 crypto_init_params(&ce_params);
197}
198
199crypto_engine_type board_ce_type(void)
200{
201 return CRYPTO_ENGINE_TYPE_HW;
202}
203
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700204#if MMC_SDHCI_SUPPORT
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700205static void target_mmc_sdhci_init()
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700206{
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700207 struct mmc_config_data config = {0};
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700208 uint32_t soc_ver = 0;
209
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700210 soc_ver = board_soc_version();
211
212 /*
213 * 8974 v1 fluid devices, have a hardware bug
214 * which limits the bus width to 4 bit.
215 */
216 switch(board_hardware_id())
217 {
218 case HW_PLATFORM_FLUID:
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700219 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700220 config.bus_width = DATA_BUS_WIDTH_4BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700221 else
222 config.bus_width = DATA_BUS_WIDTH_8BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700223 break;
224 default:
225 config.bus_width = DATA_BUS_WIDTH_8BIT;
226 };
227
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700228 /* Trying Slot 1*/
229 config.slot = 1;
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700230 /*
Channagoud Kadabi4d385152014-02-18 11:56:07 -0800231 * For 8974 AC platform the software clock
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700232 * plan recommends to use the following frequencies:
233 * 200 MHz --> 192 MHZ
234 * 400 MHZ --> 384 MHZ
235 * only for emmc slot
236 */
Channagoud Kadabi4d385152014-02-18 11:56:07 -0800237 if (platform_is_8974ac())
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700238 config.max_clk_rate = MMC_CLK_192MHZ;
239 else
240 config.max_clk_rate = MMC_CLK_200MHZ;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700241 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
242 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
243 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Aparna Mallavarapu25152662014-03-11 13:49:14 +0530244 config.hs400_support = 1;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700245
246 if (!(dev = mmc_init(&config))) {
247 /* Trying Slot 2 next */
248 config.slot = 2;
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700249 config.max_clk_rate = MMC_CLK_200MHZ;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700250 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
251 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
252 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
253
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700254 if (!(dev = mmc_init(&config))) {
255 dprintf(CRITICAL, "mmc init failed!");
256 ASSERT(0);
257 }
258 }
Channagoud Kadabief5332f2013-05-16 15:23:43 -0700259
260 /*
261 * MMC initialization is complete, read the partition table info
262 */
263 if (partition_read_table()) {
264 dprintf(CRITICAL, "Error reading the partition table info\n");
265 ASSERT(0);
266 }
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700267}
268
Channagoud Kadabi6faaf702013-09-10 15:00:51 -0700269void *target_mmc_device()
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700270{
Channagoud Kadabi6faaf702013-09-10 15:00:51 -0700271 return (void *) dev;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700272}
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700273
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700274#else
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700275static void target_mmc_mci_init()
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800276{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700277 uint32_t base_addr;
278 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800279
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700280 /* Trying Slot 1 */
281 slot = 1;
282 base_addr = mmc_sdc_base[slot - 1];
283
284 if (mmc_boot_main(slot, base_addr))
285 {
286 /* Trying Slot 2 next */
287 slot = 2;
288 base_addr = mmc_sdc_base[slot - 1];
289 if (mmc_boot_main(slot, base_addr)) {
290 dprintf(CRITICAL, "mmc init failed!");
291 ASSERT(0);
292 }
293 }
294}
295
296/*
297 * Function to set the capabilities for the host
298 */
299void target_mmc_caps(struct mmc_host *host)
300{
301 uint32_t soc_ver = 0;
302
303 soc_ver = board_soc_version();
304
305 /*
306 * 8974 v1 fluid devices, have a hardware bug
307 * which limits the bus width to 4 bit.
308 */
309 switch(board_hardware_id())
310 {
311 case HW_PLATFORM_FLUID:
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700312 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700313 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700314 else
315 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700316 break;
317 default:
318 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
319 };
320
321 host->caps.ddr_mode = 1;
322 host->caps.hs200_mode = 1;
323 host->caps.hs_clk_rate = MMC_CLK_96MHZ;
324}
325#endif
326
327
328void target_init(void)
329{
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800330 dprintf(INFO, "target_init()\n");
331
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800332 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800333
Deepa Dinamani07f15712013-03-08 17:02:13 -0800334 /* Save PM8941 version info. */
335 pmic_ver = pm8x41_get_pmic_rev();
336
Deepa Dinamani9a612932012-08-14 16:15:03 -0700337 target_keystatus();
338
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800339 if (target_use_signed_kernel())
340 target_crypto_init_params();
341
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700342 /*
343 * Set drive strength & pull ctrl for
344 * emmc
345 */
346 set_sdc_power_ctrl();
347
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700348#if MMC_SDHCI_SUPPORT
349 target_mmc_sdhci_init();
350#else
351 target_mmc_mci_init();
352#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800353}
354
355unsigned board_machtype(void)
356{
357 return target_id;
358}
359
360/* Do any target specific intialization needed before entering fastboot mode */
sundarajan srinivasana098d832013-03-07 12:19:30 -0800361#ifdef SSD_ENABLE
sundarajan srinivasana098d832013-03-07 12:19:30 -0800362static void ssd_load_keystore_from_emmc()
363{
364 uint64_t ptn = 0;
365 int index = -1;
366 uint32_t size = SSD_PARTITION_SIZE;
367 int ret = -1;
368
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700369 uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE,
370 ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE));
371
372 if (!buffer) {
373 dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n");
374 ASSERT(0);
375 }
376
sundarajan srinivasana098d832013-03-07 12:19:30 -0800377 index = partition_get_index("ssd");
378
379 ptn = partition_get_offset(index);
380 if(ptn == 0){
381 dprintf(CRITICAL,"ERROR: ssd parition not found");
382 return;
383 }
384
385 if(mmc_read(ptn, buffer, size)){
386 dprintf(CRITICAL,"ERROR:Cannot read data\n");
387 return;
388 }
389
390 ret = scm_protect_keystore((uint32_t *)&buffer[0],size);
391 if(ret != 0)
vijay kumar32856d52014-08-06 16:18:03 +0530392 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed\n");
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700393
394 free(buffer);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800395}
396#endif
397
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800398void target_fastboot_init(void)
399{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700400 /* Set the BOOT_DONE flag in PM8921 */
Channagoud Kadabia7ab9312014-01-08 12:11:23 -0800401 pm8x41_set_boot_done();
sundarajan srinivasana098d832013-03-07 12:19:30 -0800402
403#ifdef SSD_ENABLE
404 clock_ce_enable(SSD_CE_INSTANCE_1);
405 ssd_load_keystore_from_emmc();
406#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800407}
Neeti Desai465491e2012-07-31 12:53:35 -0700408
Channagoud Kadabic5537fd2014-02-04 17:07:19 -0800409/* Initialize target specific USB handlers */
410target_usb_iface_t* target_usb30_init()
411{
412 target_usb_iface_t *t_usb_iface;
413
414 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
415 ASSERT(t_usb_iface);
416
417 t_usb_iface->mux_config = target_usb_phy_mux_configure;
418 t_usb_iface->clock_init = clock_usb30_init;
419
420 return t_usb_iface;
421}
422
Neeti Desai465491e2012-07-31 12:53:35 -0700423/* Detect the target type */
424void target_detect(struct board_data *board)
425{
Channagoud Kadabi2018bd12014-02-11 15:37:05 -0800426 /* This property is filled in board.c */
Neeti Desai465491e2012-07-31 12:53:35 -0700427}
428
429/* Detect the modem type */
430void target_baseband_detect(struct board_data *board)
431{
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800432 uint32_t platform;
Channagoud Kadabia7ab9312014-01-08 12:11:23 -0800433 uint32_t platform_subtype;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800434
435 platform = board->platform;
Channagoud Kadabi051f6b92014-01-08 12:16:16 -0800436 platform_subtype = board->platform_subtype;
437
438 /*
439 * Look for platform subtype if present, else
440 * check for platform type to decide on the
441 * baseband type
442 */
443 switch(platform_subtype) {
444 case HW_PLATFORM_SUBTYPE_UNKNOWN:
445 case HW_PLATFORM_SUBTYPE_8974PRO_PM8084:
Channagoud Kadabi62ac4cb2014-05-13 11:55:38 -0700446 case HW_PLATFORM_8994_INTERPOSER:
Channagoud Kadabi051f6b92014-01-08 12:16:16 -0800447 break;
448 default:
449 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype);
450 ASSERT(0);
451 };
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800452
453 switch(platform) {
454 case MSM8974:
Deepa Dinamani713a76f2013-05-03 13:17:24 -0700455 case MSM8274:
456 case MSM8674:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700457 case MSM8274AA:
458 case MSM8274AB:
459 case MSM8274AC:
460 case MSM8674AA:
461 case MSM8674AB:
462 case MSM8674AC:
463 case MSM8974AA:
464 case MSM8974AB:
465 case MSM8974AC:
Neeti Desai465491e2012-07-31 12:53:35 -0700466 board->baseband = BASEBAND_MSM;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800467 break;
468 case APQ8074:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700469 case APQ8074AA:
470 case APQ8074AB:
471 case APQ8074AC:
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800472 board->baseband = BASEBAND_APQ;
473 break;
474 default:
475 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
476 ASSERT(0);
477 };
Neeti Desai465491e2012-07-31 12:53:35 -0700478}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700479
Deepa Dinamani927a6b62013-03-28 17:05:32 -0700480unsigned target_baseband()
481{
482 return board_baseband();
483}
484
Deepa Dinamani9a612932012-08-14 16:15:03 -0700485void target_serialno(unsigned char *buf)
486{
487 unsigned int serialno;
488 if (target_is_emmc_boot()) {
489 serialno = mmc_get_psn();
490 snprintf((char *)buf, 13, "%x", serialno);
491 }
492}
Amol Jadi6639d452012-08-16 14:51:19 -0700493
494unsigned check_reboot_mode(void)
495{
496 uint32_t restart_reason = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800497 uint32_t soc_ver = 0;
498 uint32_t restart_reason_addr;
499
500 soc_ver = board_soc_version();
501
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700502 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800503 restart_reason_addr = RESTART_REASON_ADDR;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700504 else
505 restart_reason_addr = RESTART_REASON_ADDR_V2;
Amol Jadi6639d452012-08-16 14:51:19 -0700506
507 /* Read reboot reason and scrub it */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800508 restart_reason = readl(restart_reason_addr);
509 writel(0x00, restart_reason_addr);
Amol Jadi6639d452012-08-16 14:51:19 -0700510
511 return restart_reason;
512}
Neeti Desai120b55d2012-08-20 17:15:56 -0700513
514void reboot_device(unsigned reboot_reason)
515{
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800516 uint32_t soc_ver = 0;
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700517 uint8_t reset_type = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800518
519 soc_ver = board_soc_version();
520
Neeti Desai120b55d2012-08-20 17:15:56 -0700521 /* Write the reboot reason */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700522 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800523 writel(reboot_reason, RESTART_REASON_ADDR);
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700524 else
525 writel(reboot_reason, RESTART_REASON_ADDR_V2);
Neeti Desai120b55d2012-08-20 17:15:56 -0700526
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700527 if(reboot_reason == FASTBOOT_MODE)
528 reset_type = PON_PSHOLD_WARM_RESET;
529 else
530 reset_type = PON_PSHOLD_HARD_RESET;
531
Neeti Desai120b55d2012-08-20 17:15:56 -0700532 /* Configure PMIC for warm reset */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700533 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700534 pm8x41_v2_reset_configure(reset_type);
Deepa Dinamani07f15712013-03-08 17:02:13 -0800535 else
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700536 pm8x41_reset_configure(reset_type);
Neeti Desai120b55d2012-08-20 17:15:56 -0700537
538 /* Drop PS_HOLD for MSM */
539 writel(0x00, MPM2_MPM_PS_HOLD);
540
541 mdelay(5000);
542
543 dprintf(CRITICAL, "Rebooting failed\n");
544}
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800545
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300546int set_download_mode(enum dload_mode mode)
Pavel Nedev03511492013-03-08 19:05:32 -0800547{
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300548 dload_util_write_cookie(mode == NORMAL_DLOAD ?
549 DLOAD_MODE_ADDR_V2 : EMERGENCY_DLOAD_MODE_ADDR_V2, mode);
Pavel Nedev03511492013-03-08 19:05:32 -0800550
551 return 0;
552}
553
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700554/* Check if MSM needs VBUS mimic for USB */
555static int target_needs_vbus_mimic()
556{
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700557 if (platform_is_8974())
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700558 return 0;
559
560 return 1;
561}
562
Eugene Yasmana0d18122013-02-26 13:23:05 +0200563/* Do target specific usb initialization */
564void target_usb_init(void)
565{
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700566 uint32_t val;
567
Eugene Yasmana0d18122013-02-26 13:23:05 +0200568 /* Enable secondary USB PHY on DragonBoard8074 */
569 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
570 /* Route ChipIDea to use secondary USB HS port2 */
571 writel_relaxed(1, USB2_PHY_SEL);
572
573 /* Enable access to secondary PHY by clamping the low
574 * voltage interface between DVDD of the PHY and Vddcx
575 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
576 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
577 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
578
579 /* Perform power-on-reset of the PHY.
580 * Delay values are arbitrary */
581 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
582 USB_OTG_HS_PHY_CTRL);
583 thread_sleep(10);
584 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
585 USB_OTG_HS_PHY_CTRL);
586 thread_sleep(10);
587
588 /* Enable HSUSB PHY port for ULPI interface,
589 * then configure related parameters within the PHY */
590 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
591 | 0x8c000004), USB_PORTSC);
592 }
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700593
594 if (target_needs_vbus_mimic())
595 {
596 /* Select and enable external configuration with USB PHY */
597 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
598
599 /* Enable sess_vld */
600 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
601 writel(val, USB_GENCONFIG_2);
602
603 /* Enable external vbus configuration in the LINK */
604 val = readl(USB_USBCMD);
605 val |= SESS_VLD_CTRL;
606 writel(val, USB_USBCMD);
607 }
Eugene Yasmana0d18122013-02-26 13:23:05 +0200608}
609
Casey Piper74f8e5c2013-09-05 15:00:30 -0700610uint8_t target_panel_auto_detect_enabled()
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800611{
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800612 switch(board_hardware_id())
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800613 {
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800614 case HW_PLATFORM_SURF:
615 case HW_PLATFORM_MTP:
616 case HW_PLATFORM_FLUID:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800617 return 1;
618 break;
619 default:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800620 return 0;
Casey Piper74f8e5c2013-09-05 15:00:30 -0700621 break;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800622 }
Casey Piper74f8e5c2013-09-05 15:00:30 -0700623 return 0;
624}
625
Casey Piper74f67a32013-11-18 13:26:18 -0800626uint8_t target_is_edp()
627{
628 switch(board_hardware_id())
629 {
630 case HW_PLATFORM_LIQUID:
631 return 1;
632 break;
633 default:
634 return 0;
635 break;
636 }
637 return 0;
638}
639
Casey Piper74f8e5c2013-09-05 15:00:30 -0700640static uint8_t splash_override;
641/* Returns 1 if target supports continuous splash screen. */
642int target_cont_splash_screen()
643{
644 uint8_t splash_screen = 0;
645 if(!splash_override) {
646 switch(board_hardware_id())
647 {
648 case HW_PLATFORM_SURF:
649 case HW_PLATFORM_MTP:
650 case HW_PLATFORM_FLUID:
651 case HW_PLATFORM_DRAGON:
652 case HW_PLATFORM_LIQUID:
653 dprintf(SPEW, "Target_cont_splash=1\n");
654 splash_screen = 1;
655 break;
656 default:
657 dprintf(SPEW, "Target_cont_splash=0\n");
658 splash_screen = 0;
659 }
660 }
661 return splash_screen;
662}
663
664void target_force_cont_splash_disable(uint8_t override)
665{
666 splash_override = override;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800667}
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800668
669unsigned target_pause_for_battery_charge(void)
670{
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800671
672 /* This function will always return 0 to facilitate
673 * automated testing/reboot with usb connected.
674 * uncomment if this feature is needed */
675 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
676 return 1;*/
677
678 return 0;
679}
sundarajan srinivasana098d832013-03-07 12:19:30 -0800680
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700681void target_uninit(void)
sundarajan srinivasana098d832013-03-07 12:19:30 -0800682{
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700683#if MMC_SDHCI_SUPPORT
684 mmc_put_card_to_sleep(dev);
685#else
686 mmc_put_card_to_sleep();
687#endif
sundarajan srinivasana098d832013-03-07 12:19:30 -0800688#ifdef SSD_ENABLE
689 clock_ce_disable(SSD_CE_INSTANCE_1);
690#endif
Channagoud Kadabi2095a412013-12-04 12:37:06 -0800691 if (crypto_initialized())
692 crypto_eng_cleanup();
Channagoud Kadabid0115f92014-01-24 17:25:34 -0800693
694 /* Disable HC mode before jumping to kernel */
695 sdhci_mode_disable(&dev->host);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800696}
Deepa Dinamani65df9822013-03-08 13:38:34 -0800697
698void shutdown_device()
699{
700 dprintf(CRITICAL, "Going down for shutdown.\n");
701
702 /* Configure PMIC for shutdown. */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700703 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Deepa Dinamani65df9822013-03-08 13:38:34 -0800704 pm8x41_v2_reset_configure(PON_PSHOLD_SHUTDOWN);
705 else
706 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
707
708 /* Drop PS_HOLD for MSM */
709 writel(0x00, MPM2_MPM_PS_HOLD);
710
711 mdelay(5000);
712
713 dprintf(CRITICAL, "Shutdown failed\n");
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700714}
715
716static void set_sdc_power_ctrl()
717{
Channagoud Kadabi224d8322013-09-27 14:25:22 -0700718 uint8_t tlmm_hdrv_clk = 0;
719 uint32_t platform_id = 0;
720
721 platform_id = board_platform_id();
722
723 switch(platform_id)
724 {
725 case MSM8274AA:
726 case MSM8274AB:
727 case MSM8674AA:
728 case MSM8674AB:
729 case MSM8974AA:
730 case MSM8974AB:
731 if (board_hardware_id() == HW_PLATFORM_MTP)
732 tlmm_hdrv_clk = TLMM_CUR_VAL_10MA;
733 else
734 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
735 break;
736 default:
737 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
738 };
739
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700740 /* Drive strength configs for sdc pins */
741 struct tlmm_cfgs sdc1_hdrv_cfg[] =
742 {
Channagoud Kadabi224d8322013-09-27 14:25:22 -0700743 { SDC1_CLK_HDRV_CTL_OFF, tlmm_hdrv_clk, TLMM_HDRV_MASK },
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700744 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
745 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
746 };
747
748 /* Pull configs for sdc pins */
749 struct tlmm_cfgs sdc1_pull_cfg[] =
750 {
751 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
752 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
753 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
754 };
755
Channagoud Kadabi389cab22013-08-20 15:29:15 -0700756 struct tlmm_cfgs sdc1_rclk_cfg[] =
757 {
758 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK },
759 };
760
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700761 /* Set the drive strength & pull control values */
762 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
763 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
Channagoud Kadabi389cab22013-08-20 15:29:15 -0700764
765 /* RCLK is supported only with 8974 pro, set rclk to pull down
766 * only for 8974 pro targets
767 */
768 if (!platform_is_8974())
769 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700770}
Stanimir Varbanovf64a0292013-04-29 11:58:27 +0300771
772int emmc_recovery_init(void)
773{
774 return _emmc_recovery_init();
775}
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700776
777void target_usb_stop(void)
778{
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700779
780 /* Disable VBUS mimicing in the controller. */
781 if (target_needs_vbus_mimic())
782 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
783}
Amol Jadi4c3229f2013-10-07 14:38:06 -0700784
785/* identify the usb controller to be used for the target */
786const char * target_usb_controller()
787{
788 switch(board_platform_id())
789 {
790 /* use dwc controller for PRO chips (with some exceptions) */
791 case MSM8974AA:
792 case MSM8974AB:
793 case MSM8974AC:
794 /* exceptions based on hardware id */
Channagoud Kadabi62ac4cb2014-05-13 11:55:38 -0700795 if (board_hardware_id() != HW_PLATFORM_DRAGON && !target_hw_interposer())
Amol Jadi4c3229f2013-10-07 14:38:06 -0700796 return "dwc";
797 /* fall through to default "ci" for anything that did'nt select "dwc" */
798 default:
799 return "ci";
800 }
801}
Amol Jadi28864bb2013-10-11 14:12:59 -0700802
803/* UTMI MUX configuration to connect PHY to SNPS controller:
804 * Configure primary HS phy mux to use UTMI interface
805 * (connected to usb30 controller).
806 */
807static void tcsr_hs_phy_mux_configure(void)
808{
809 uint32_t reg;
810
811 reg = readl(USB2_PHY_SEL);
812
813 writel(reg | 0x1, USB2_PHY_SEL);
814}
815
816/* configure hs phy mux if using dwc controller */
817void target_usb_phy_mux_configure(void)
818{
819 if(!strcmp(target_usb_controller(), "dwc"))
820 {
821 tcsr_hs_phy_mux_configure();
822 }
823}