blob: 59f7ffd22c94d5ebf083142959708557c5f811b7 [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>
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
Channagoud Kadabi62ac4cb2014-05-13 11:55:38 -070054#define HW_PLATFORM_8994_INTERPOSER 0x3
55
Deepa Dinamanib9a57202012-12-20 18:05:11 -080056extern bool target_use_signed_kernel(void);
Channagoud Kadabi744c8902013-04-02 11:54:53 -070057static void set_sdc_power_ctrl();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080058
59static unsigned int target_id;
Deepa Dinamani07f15712013-03-08 17:02:13 -080060static uint32_t pmic_ver;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080061
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070062#if MMC_SDHCI_SUPPORT
63struct mmc_device *dev;
64#endif
65
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080066#define PMIC_ARB_CHANNEL_NUM 0
67#define PMIC_ARB_OWNER_ID 0
68
Deepa Dinamani1e094942012-10-30 15:49:02 -070069#define WDOG_DEBUG_DISABLE_BIT 17
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080070
Channagoud Kadabia1ef8092014-01-08 12:11:58 -080071#define CE_INSTANCE 2
Deepa Dinamanib9a57202012-12-20 18:05:11 -080072#define CE_EE 1
73#define CE_FIFO_SIZE 64
74#define CE_READ_PIPE 3
75#define CE_WRITE_PIPE 2
Deepa Dinamani809c4282013-07-09 14:06:02 -070076#define CE_READ_PIPE_LOCK_GRP 0
77#define CE_WRITE_PIPE_LOCK_GRP 0
Deepa Dinamanib9a57202012-12-20 18:05:11 -080078#define CE_ARRAY_SIZE 20
79
sundarajan srinivasana098d832013-03-07 12:19:30 -080080#ifdef SSD_ENABLE
81#define SSD_CE_INSTANCE_1 1
82#define SSD_PARTITION_SIZE 8192
83#endif
84
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -070085#define FASTBOOT_MODE 0x77665500
86
Channagoud Kadabic48b3e92013-06-23 16:19:10 -070087#define BOARD_SOC_VERSION1(soc_rev) (soc_rev >= 0x10000 && soc_rev < 0x20000)
88
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -070089#if MMC_SDHCI_SUPPORT
90static uint32_t mmc_sdhci_base[] =
91 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE, MSM_SDC3_SDHCI_BASE, MSM_SDC4_SDHCI_BASE };
92#endif
93
Deepa Dinamanica5ad852012-05-07 18:19:47 -070094static uint32_t mmc_sdc_base[] =
95 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
96
Channagoud Kadabib14d6d02013-05-15 10:48:59 -070097static uint32_t mmc_sdc_pwrctl_irq[] =
98 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ, SDCC3_PWRCTL_IRQ, SDCC4_PWRCTL_IRQ };
99
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800100void target_early_init(void)
101{
Deepa Dinamanib073ba22012-08-10 11:06:41 -0700102#if WITH_DEBUG_UART
Neeti Desaiac011272012-08-29 18:24:54 -0700103 uart_dm_init(1, 0, BLSP1_UART1_BASE);
Deepa Dinamanib073ba22012-08-10 11:06:41 -0700104#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800105}
106
Channagoud Kadabi62ac4cb2014-05-13 11:55:38 -0700107uint32_t target_hw_interposer()
108{
109 return board_hardware_subtype() == HW_PLATFORM_8994_INTERPOSER ? 1 : 0;
110}
111
Deepa Dinamani9a612932012-08-14 16:15:03 -0700112/* Return 1 if vol_up pressed */
113static int target_volume_up()
114{
115 uint8_t status = 0;
116 struct pm8x41_gpio gpio;
117
118 /* CDP vol_up seems to be always grounded. So gpio status is read as 0,
119 * whether key is pressed or not.
120 * Ignore volume_up key on CDP for now.
121 */
122 if (board_hardware_id() == HW_PLATFORM_SURF)
123 return 0;
124
125 /* Configure the GPIO */
126 gpio.direction = PM_GPIO_DIR_IN;
127 gpio.function = 0;
128 gpio.pull = PM_GPIO_PULL_UP_30;
Eugene Yasman6382ee02013-01-16 13:00:56 +0200129 gpio.vin_sel = 2;
Deepa Dinamani9a612932012-08-14 16:15:03 -0700130
131 pm8x41_gpio_config(5, &gpio);
132
Channagoud Kadabi4d7b5302013-08-07 16:34:08 -0700133 /* Wait for the pmic gpio config to take effect */
134 thread_sleep(1);
135
Deepa Dinamani9a612932012-08-14 16:15:03 -0700136 /* Get status of P_GPIO_5 */
137 pm8x41_gpio_get(5, &status);
138
139 return !status; /* active low */
140}
141
142/* Return 1 if vol_down pressed */
Deepa Dinamani66a87962013-02-04 10:39:30 -0800143uint32_t target_volume_down()
Deepa Dinamani9a612932012-08-14 16:15:03 -0700144{
Deepa Dinamani66a87962013-02-04 10:39:30 -0800145 /* Volume down button is tied in with RESIN on MSM8974. */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700146 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Channagoud Kadabi84dcd912013-07-03 15:33:15 -0700147 return pm8x41_v2_resin_status();
Deepa Dinamani13bfc852013-02-05 17:56:47 -0800148 else
149 return pm8x41_resin_status();
Deepa Dinamani9a612932012-08-14 16:15:03 -0700150}
151
152static void target_keystatus()
153{
154 keys_init();
155
156 if(target_volume_down())
157 keys_post_event(KEY_VOLUMEDOWN, 1);
158
159 if(target_volume_up())
160 keys_post_event(KEY_VOLUMEUP, 1);
161}
162
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800163/* Set up params for h/w CE. */
164void target_crypto_init_params()
165{
166 struct crypto_init_params ce_params;
167
168 /* Set up base addresses and instance. */
Channagoud Kadabia1ef8092014-01-08 12:11:58 -0800169 ce_params.crypto_instance = CE_INSTANCE;
170 ce_params.crypto_base = MSM_CE2_BASE;
171 ce_params.bam_base = MSM_CE2_BAM_BASE;
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800172
173 /* Set up BAM config. */
Deepa Dinamani809c4282013-07-09 14:06:02 -0700174 ce_params.bam_ee = CE_EE;
175 ce_params.pipes.read_pipe = CE_READ_PIPE;
176 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
177 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
178 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800179
180 /* Assign buffer sizes. */
181 ce_params.num_ce = CE_ARRAY_SIZE;
182 ce_params.read_fifo_size = CE_FIFO_SIZE;
183 ce_params.write_fifo_size = CE_FIFO_SIZE;
184
Deepa Dinamanie505d3d2013-05-14 16:55:38 -0700185 /* BAM is initialized by TZ for this platform.
186 * Do not do it again as the initialization address space
187 * is locked.
188 */
189 ce_params.do_bam_init = 0;
190
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800191 crypto_init_params(&ce_params);
192}
193
194crypto_engine_type board_ce_type(void)
195{
196 return CRYPTO_ENGINE_TYPE_HW;
197}
198
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700199#if MMC_SDHCI_SUPPORT
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700200static void target_mmc_sdhci_init()
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700201{
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700202 struct mmc_config_data config = {0};
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700203 uint32_t soc_ver = 0;
204
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700205 soc_ver = board_soc_version();
206
207 /*
208 * 8974 v1 fluid devices, have a hardware bug
209 * which limits the bus width to 4 bit.
210 */
211 switch(board_hardware_id())
212 {
213 case HW_PLATFORM_FLUID:
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700214 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700215 config.bus_width = DATA_BUS_WIDTH_4BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700216 else
217 config.bus_width = DATA_BUS_WIDTH_8BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700218 break;
219 default:
220 config.bus_width = DATA_BUS_WIDTH_8BIT;
221 };
222
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700223 /* Trying Slot 1*/
224 config.slot = 1;
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700225 /*
Channagoud Kadabi4d385152014-02-18 11:56:07 -0800226 * For 8974 AC platform the software clock
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700227 * plan recommends to use the following frequencies:
228 * 200 MHz --> 192 MHZ
229 * 400 MHZ --> 384 MHZ
230 * only for emmc slot
231 */
Channagoud Kadabi4d385152014-02-18 11:56:07 -0800232 if (platform_is_8974ac())
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700233 config.max_clk_rate = MMC_CLK_192MHZ;
234 else
235 config.max_clk_rate = MMC_CLK_200MHZ;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700236 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
237 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
238 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
Aparna Mallavarapu25152662014-03-11 13:49:14 +0530239 config.hs400_support = 1;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700240
241 if (!(dev = mmc_init(&config))) {
242 /* Trying Slot 2 next */
243 config.slot = 2;
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700244 config.max_clk_rate = MMC_CLK_200MHZ;
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700245 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
246 config.pwrctl_base = mmc_sdc_base[config.slot - 1];
247 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
248
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700249 if (!(dev = mmc_init(&config))) {
250 dprintf(CRITICAL, "mmc init failed!");
251 ASSERT(0);
252 }
253 }
Channagoud Kadabief5332f2013-05-16 15:23:43 -0700254
255 /*
256 * MMC initialization is complete, read the partition table info
257 */
258 if (partition_read_table()) {
259 dprintf(CRITICAL, "Error reading the partition table info\n");
260 ASSERT(0);
261 }
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700262}
263
Channagoud Kadabi6faaf702013-09-10 15:00:51 -0700264void *target_mmc_device()
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700265{
Channagoud Kadabi6faaf702013-09-10 15:00:51 -0700266 return (void *) dev;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700267}
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700268
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700269#else
Channagoud Kadabib14d6d02013-05-15 10:48:59 -0700270static void target_mmc_mci_init()
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800271{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700272 uint32_t base_addr;
273 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800274
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700275 /* Trying Slot 1 */
276 slot = 1;
277 base_addr = mmc_sdc_base[slot - 1];
278
279 if (mmc_boot_main(slot, base_addr))
280 {
281 /* Trying Slot 2 next */
282 slot = 2;
283 base_addr = mmc_sdc_base[slot - 1];
284 if (mmc_boot_main(slot, base_addr)) {
285 dprintf(CRITICAL, "mmc init failed!");
286 ASSERT(0);
287 }
288 }
289}
290
291/*
292 * Function to set the capabilities for the host
293 */
294void target_mmc_caps(struct mmc_host *host)
295{
296 uint32_t soc_ver = 0;
297
298 soc_ver = board_soc_version();
299
300 /*
301 * 8974 v1 fluid devices, have a hardware bug
302 * which limits the bus width to 4 bit.
303 */
304 switch(board_hardware_id())
305 {
306 case HW_PLATFORM_FLUID:
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700307 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700308 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700309 else
310 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700311 break;
312 default:
313 host->caps.bus_width = MMC_BOOT_BUS_WIDTH_8_BIT;
314 };
315
316 host->caps.ddr_mode = 1;
317 host->caps.hs200_mode = 1;
318 host->caps.hs_clk_rate = MMC_CLK_96MHZ;
319}
320#endif
321
322
323void target_init(void)
324{
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800325 dprintf(INFO, "target_init()\n");
326
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800327 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800328
Deepa Dinamani07f15712013-03-08 17:02:13 -0800329 /* Save PM8941 version info. */
330 pmic_ver = pm8x41_get_pmic_rev();
331
Deepa Dinamani9a612932012-08-14 16:15:03 -0700332 target_keystatus();
333
Deepa Dinamanib9a57202012-12-20 18:05:11 -0800334 if (target_use_signed_kernel())
335 target_crypto_init_params();
336
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700337 /*
338 * Set drive strength & pull ctrl for
339 * emmc
340 */
341 set_sdc_power_ctrl();
342
Channagoud Kadabic1fdc8d2013-04-05 11:29:23 -0700343#if MMC_SDHCI_SUPPORT
344 target_mmc_sdhci_init();
345#else
346 target_mmc_mci_init();
347#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800348}
349
350unsigned board_machtype(void)
351{
352 return target_id;
353}
354
355/* Do any target specific intialization needed before entering fastboot mode */
sundarajan srinivasana098d832013-03-07 12:19:30 -0800356#ifdef SSD_ENABLE
sundarajan srinivasana098d832013-03-07 12:19:30 -0800357static void ssd_load_keystore_from_emmc()
358{
359 uint64_t ptn = 0;
360 int index = -1;
361 uint32_t size = SSD_PARTITION_SIZE;
362 int ret = -1;
363
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700364 uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE,
365 ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE));
366
367 if (!buffer) {
368 dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n");
369 ASSERT(0);
370 }
371
sundarajan srinivasana098d832013-03-07 12:19:30 -0800372 index = partition_get_index("ssd");
373
374 ptn = partition_get_offset(index);
375 if(ptn == 0){
376 dprintf(CRITICAL,"ERROR: ssd parition not found");
377 return;
378 }
379
380 if(mmc_read(ptn, buffer, size)){
381 dprintf(CRITICAL,"ERROR:Cannot read data\n");
382 return;
383 }
384
385 ret = scm_protect_keystore((uint32_t *)&buffer[0],size);
386 if(ret != 0)
387 dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed");
Channagoud Kadabif84830c2013-04-19 14:35:47 -0700388
389 free(buffer);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800390}
391#endif
392
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800393void target_fastboot_init(void)
394{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700395 /* Set the BOOT_DONE flag in PM8921 */
Channagoud Kadabia7ab9312014-01-08 12:11:23 -0800396 pm8x41_set_boot_done();
sundarajan srinivasana098d832013-03-07 12:19:30 -0800397
398#ifdef SSD_ENABLE
399 clock_ce_enable(SSD_CE_INSTANCE_1);
400 ssd_load_keystore_from_emmc();
401#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800402}
Neeti Desai465491e2012-07-31 12:53:35 -0700403
Channagoud Kadabic5537fd2014-02-04 17:07:19 -0800404/* Initialize target specific USB handlers */
405target_usb_iface_t* target_usb30_init()
406{
407 target_usb_iface_t *t_usb_iface;
408
409 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
410 ASSERT(t_usb_iface);
411
412 t_usb_iface->mux_config = target_usb_phy_mux_configure;
413 t_usb_iface->clock_init = clock_usb30_init;
414
415 return t_usb_iface;
416}
417
Neeti Desai465491e2012-07-31 12:53:35 -0700418/* Detect the target type */
419void target_detect(struct board_data *board)
420{
Channagoud Kadabi2018bd12014-02-11 15:37:05 -0800421 /* This property is filled in board.c */
Neeti Desai465491e2012-07-31 12:53:35 -0700422}
423
424/* Detect the modem type */
425void target_baseband_detect(struct board_data *board)
426{
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800427 uint32_t platform;
Channagoud Kadabia7ab9312014-01-08 12:11:23 -0800428 uint32_t platform_subtype;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800429
430 platform = board->platform;
Channagoud Kadabi051f6b92014-01-08 12:16:16 -0800431 platform_subtype = board->platform_subtype;
432
433 /*
434 * Look for platform subtype if present, else
435 * check for platform type to decide on the
436 * baseband type
437 */
438 switch(platform_subtype) {
439 case HW_PLATFORM_SUBTYPE_UNKNOWN:
440 case HW_PLATFORM_SUBTYPE_8974PRO_PM8084:
Channagoud Kadabi62ac4cb2014-05-13 11:55:38 -0700441 case HW_PLATFORM_8994_INTERPOSER:
Channagoud Kadabi051f6b92014-01-08 12:16:16 -0800442 break;
443 default:
444 dprintf(CRITICAL, "Platform Subtype : %u is not supported\n",platform_subtype);
445 ASSERT(0);
446 };
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800447
448 switch(platform) {
449 case MSM8974:
Deepa Dinamani713a76f2013-05-03 13:17:24 -0700450 case MSM8274:
451 case MSM8674:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700452 case MSM8274AA:
453 case MSM8274AB:
454 case MSM8274AC:
455 case MSM8674AA:
456 case MSM8674AB:
457 case MSM8674AC:
458 case MSM8974AA:
459 case MSM8974AB:
460 case MSM8974AC:
Neeti Desai465491e2012-07-31 12:53:35 -0700461 board->baseband = BASEBAND_MSM;
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800462 break;
463 case APQ8074:
Deepa Dinamanicaf9e772013-06-14 12:39:41 -0700464 case APQ8074AA:
465 case APQ8074AB:
466 case APQ8074AC:
Channagoud Kadabif1d44422013-02-21 22:59:35 -0800467 board->baseband = BASEBAND_APQ;
468 break;
469 default:
470 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
471 ASSERT(0);
472 };
Neeti Desai465491e2012-07-31 12:53:35 -0700473}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700474
Deepa Dinamani927a6b62013-03-28 17:05:32 -0700475unsigned target_baseband()
476{
477 return board_baseband();
478}
479
Deepa Dinamani9a612932012-08-14 16:15:03 -0700480void target_serialno(unsigned char *buf)
481{
482 unsigned int serialno;
483 if (target_is_emmc_boot()) {
484 serialno = mmc_get_psn();
485 snprintf((char *)buf, 13, "%x", serialno);
486 }
487}
Amol Jadi6639d452012-08-16 14:51:19 -0700488
489unsigned check_reboot_mode(void)
490{
491 uint32_t restart_reason = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800492 uint32_t soc_ver = 0;
493 uint32_t restart_reason_addr;
494
495 soc_ver = board_soc_version();
496
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700497 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800498 restart_reason_addr = RESTART_REASON_ADDR;
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700499 else
500 restart_reason_addr = RESTART_REASON_ADDR_V2;
Amol Jadi6639d452012-08-16 14:51:19 -0700501
502 /* Read reboot reason and scrub it */
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800503 restart_reason = readl(restart_reason_addr);
504 writel(0x00, restart_reason_addr);
Amol Jadi6639d452012-08-16 14:51:19 -0700505
506 return restart_reason;
507}
Neeti Desai120b55d2012-08-20 17:15:56 -0700508
509void reboot_device(unsigned reboot_reason)
510{
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800511 uint32_t soc_ver = 0;
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700512 uint8_t reset_type = 0;
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800513
514 soc_ver = board_soc_version();
515
Neeti Desai120b55d2012-08-20 17:15:56 -0700516 /* Write the reboot reason */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700517 if (platform_is_8974() && BOARD_SOC_VERSION1(soc_ver))
Channagoud Kadabi8c8587f2013-02-08 12:46:09 -0800518 writel(reboot_reason, RESTART_REASON_ADDR);
Channagoud Kadabic48b3e92013-06-23 16:19:10 -0700519 else
520 writel(reboot_reason, RESTART_REASON_ADDR_V2);
Neeti Desai120b55d2012-08-20 17:15:56 -0700521
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700522 if(reboot_reason == FASTBOOT_MODE)
523 reset_type = PON_PSHOLD_WARM_RESET;
524 else
525 reset_type = PON_PSHOLD_HARD_RESET;
526
Neeti Desai120b55d2012-08-20 17:15:56 -0700527 /* Configure PMIC for warm reset */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700528 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700529 pm8x41_v2_reset_configure(reset_type);
Deepa Dinamani07f15712013-03-08 17:02:13 -0800530 else
Sundarajan Srinivasand00f31d2013-07-19 12:09:15 -0700531 pm8x41_reset_configure(reset_type);
Neeti Desai120b55d2012-08-20 17:15:56 -0700532
533 /* Drop PS_HOLD for MSM */
534 writel(0x00, MPM2_MPM_PS_HOLD);
535
536 mdelay(5000);
537
538 dprintf(CRITICAL, "Rebooting failed\n");
539}
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800540
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300541int set_download_mode(enum dload_mode mode)
Pavel Nedev03511492013-03-08 19:05:32 -0800542{
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300543 dload_util_write_cookie(mode == NORMAL_DLOAD ?
544 DLOAD_MODE_ADDR_V2 : EMERGENCY_DLOAD_MODE_ADDR_V2, mode);
Pavel Nedev03511492013-03-08 19:05:32 -0800545
546 return 0;
547}
548
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700549/* Check if MSM needs VBUS mimic for USB */
550static int target_needs_vbus_mimic()
551{
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700552 if (platform_is_8974())
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700553 return 0;
554
555 return 1;
556}
557
Eugene Yasmana0d18122013-02-26 13:23:05 +0200558/* Do target specific usb initialization */
559void target_usb_init(void)
560{
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700561 uint32_t val;
562
Eugene Yasmana0d18122013-02-26 13:23:05 +0200563 /* Enable secondary USB PHY on DragonBoard8074 */
564 if (board_hardware_id() == HW_PLATFORM_DRAGON) {
565 /* Route ChipIDea to use secondary USB HS port2 */
566 writel_relaxed(1, USB2_PHY_SEL);
567
568 /* Enable access to secondary PHY by clamping the low
569 * voltage interface between DVDD of the PHY and Vddcx
570 * (set bit16 (USB2_PHY_HS2_DIG_CLAMP_N_2) = 1) */
571 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_SEC_CTRL)
572 | 0x00010000, USB_OTG_HS_PHY_SEC_CTRL);
573
574 /* Perform power-on-reset of the PHY.
575 * Delay values are arbitrary */
576 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL)|1,
577 USB_OTG_HS_PHY_CTRL);
578 thread_sleep(10);
579 writel_relaxed(readl_relaxed(USB_OTG_HS_PHY_CTRL) & 0xFFFFFFFE,
580 USB_OTG_HS_PHY_CTRL);
581 thread_sleep(10);
582
583 /* Enable HSUSB PHY port for ULPI interface,
584 * then configure related parameters within the PHY */
585 writel_relaxed(((readl_relaxed(USB_PORTSC) & 0xC0000000)
586 | 0x8c000004), USB_PORTSC);
587 }
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700588
589 if (target_needs_vbus_mimic())
590 {
591 /* Select and enable external configuration with USB PHY */
592 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
593
594 /* Enable sess_vld */
595 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
596 writel(val, USB_GENCONFIG_2);
597
598 /* Enable external vbus configuration in the LINK */
599 val = readl(USB_USBCMD);
600 val |= SESS_VLD_CTRL;
601 writel(val, USB_USBCMD);
602 }
Eugene Yasmana0d18122013-02-26 13:23:05 +0200603}
604
Casey Piper74f8e5c2013-09-05 15:00:30 -0700605uint8_t target_panel_auto_detect_enabled()
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800606{
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800607 switch(board_hardware_id())
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800608 {
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800609 case HW_PLATFORM_SURF:
610 case HW_PLATFORM_MTP:
611 case HW_PLATFORM_FLUID:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800612 return 1;
613 break;
614 default:
Siddhartha Agrawal17a6b832013-02-17 18:36:25 -0800615 return 0;
Casey Piper74f8e5c2013-09-05 15:00:30 -0700616 break;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800617 }
Casey Piper74f8e5c2013-09-05 15:00:30 -0700618 return 0;
619}
620
Casey Piper74f67a32013-11-18 13:26:18 -0800621uint8_t target_is_edp()
622{
623 switch(board_hardware_id())
624 {
625 case HW_PLATFORM_LIQUID:
626 return 1;
627 break;
628 default:
629 return 0;
630 break;
631 }
632 return 0;
633}
634
Casey Piper74f8e5c2013-09-05 15:00:30 -0700635static uint8_t splash_override;
636/* Returns 1 if target supports continuous splash screen. */
637int target_cont_splash_screen()
638{
639 uint8_t splash_screen = 0;
640 if(!splash_override) {
641 switch(board_hardware_id())
642 {
643 case HW_PLATFORM_SURF:
644 case HW_PLATFORM_MTP:
645 case HW_PLATFORM_FLUID:
646 case HW_PLATFORM_DRAGON:
647 case HW_PLATFORM_LIQUID:
648 dprintf(SPEW, "Target_cont_splash=1\n");
649 splash_screen = 1;
650 break;
651 default:
652 dprintf(SPEW, "Target_cont_splash=0\n");
653 splash_screen = 0;
654 }
655 }
656 return splash_screen;
657}
658
659void target_force_cont_splash_disable(uint8_t override)
660{
661 splash_override = override;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800662}
sundarajan srinivasanb5db0a92013-02-12 19:19:27 -0800663
664unsigned target_pause_for_battery_charge(void)
665{
666 uint8_t pon_reason = pm8x41_get_pon_reason();
667
668 /* This function will always return 0 to facilitate
669 * automated testing/reboot with usb connected.
670 * uncomment if this feature is needed */
671 /* if ((pon_reason == USB_CHG) || (pon_reason == DC_CHG))
672 return 1;*/
673
674 return 0;
675}
sundarajan srinivasana098d832013-03-07 12:19:30 -0800676
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700677void target_uninit(void)
sundarajan srinivasana098d832013-03-07 12:19:30 -0800678{
Channagoud Kadabi9faa45b2013-06-18 18:33:02 -0700679#if MMC_SDHCI_SUPPORT
680 mmc_put_card_to_sleep(dev);
681#else
682 mmc_put_card_to_sleep();
683#endif
sundarajan srinivasana098d832013-03-07 12:19:30 -0800684#ifdef SSD_ENABLE
685 clock_ce_disable(SSD_CE_INSTANCE_1);
686#endif
Channagoud Kadabi2095a412013-12-04 12:37:06 -0800687 if (crypto_initialized())
688 crypto_eng_cleanup();
Channagoud Kadabid0115f92014-01-24 17:25:34 -0800689
690 /* Disable HC mode before jumping to kernel */
691 sdhci_mode_disable(&dev->host);
sundarajan srinivasana098d832013-03-07 12:19:30 -0800692}
Deepa Dinamani65df9822013-03-08 13:38:34 -0800693
694void shutdown_device()
695{
696 dprintf(CRITICAL, "Going down for shutdown.\n");
697
698 /* Configure PMIC for shutdown. */
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700699 if (platform_is_8974() && (pmic_ver == PM8X41_VERSION_V2))
Deepa Dinamani65df9822013-03-08 13:38:34 -0800700 pm8x41_v2_reset_configure(PON_PSHOLD_SHUTDOWN);
701 else
702 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
703
704 /* Drop PS_HOLD for MSM */
705 writel(0x00, MPM2_MPM_PS_HOLD);
706
707 mdelay(5000);
708
709 dprintf(CRITICAL, "Shutdown failed\n");
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700710}
711
712static void set_sdc_power_ctrl()
713{
Channagoud Kadabi224d8322013-09-27 14:25:22 -0700714 uint8_t tlmm_hdrv_clk = 0;
715 uint32_t platform_id = 0;
716
717 platform_id = board_platform_id();
718
719 switch(platform_id)
720 {
721 case MSM8274AA:
722 case MSM8274AB:
723 case MSM8674AA:
724 case MSM8674AB:
725 case MSM8974AA:
726 case MSM8974AB:
727 if (board_hardware_id() == HW_PLATFORM_MTP)
728 tlmm_hdrv_clk = TLMM_CUR_VAL_10MA;
729 else
730 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
731 break;
732 default:
733 tlmm_hdrv_clk = TLMM_CUR_VAL_16MA;
734 };
735
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700736 /* Drive strength configs for sdc pins */
737 struct tlmm_cfgs sdc1_hdrv_cfg[] =
738 {
Channagoud Kadabi224d8322013-09-27 14:25:22 -0700739 { SDC1_CLK_HDRV_CTL_OFF, tlmm_hdrv_clk, TLMM_HDRV_MASK },
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700740 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
741 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
742 };
743
744 /* Pull configs for sdc pins */
745 struct tlmm_cfgs sdc1_pull_cfg[] =
746 {
747 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
748 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
749 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
750 };
751
Channagoud Kadabi389cab22013-08-20 15:29:15 -0700752 struct tlmm_cfgs sdc1_rclk_cfg[] =
753 {
754 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK },
755 };
756
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700757 /* Set the drive strength & pull control values */
758 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
759 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
Channagoud Kadabi389cab22013-08-20 15:29:15 -0700760
761 /* RCLK is supported only with 8974 pro, set rclk to pull down
762 * only for 8974 pro targets
763 */
764 if (!platform_is_8974())
765 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
Channagoud Kadabi744c8902013-04-02 11:54:53 -0700766}
Stanimir Varbanovf64a0292013-04-29 11:58:27 +0300767
768int emmc_recovery_init(void)
769{
770 return _emmc_recovery_init();
771}
Channagoud Kadabi6d215b92013-06-23 16:47:07 -0700772
773void target_usb_stop(void)
774{
775 uint32_t platform = board_platform_id();
776
777 /* Disable VBUS mimicing in the controller. */
778 if (target_needs_vbus_mimic())
779 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_CLEAR);
780}
Amol Jadi4c3229f2013-10-07 14:38:06 -0700781
782/* identify the usb controller to be used for the target */
783const char * target_usb_controller()
784{
785 switch(board_platform_id())
786 {
787 /* use dwc controller for PRO chips (with some exceptions) */
788 case MSM8974AA:
789 case MSM8974AB:
790 case MSM8974AC:
791 /* exceptions based on hardware id */
Channagoud Kadabi62ac4cb2014-05-13 11:55:38 -0700792 if (board_hardware_id() != HW_PLATFORM_DRAGON && !target_hw_interposer())
Amol Jadi4c3229f2013-10-07 14:38:06 -0700793 return "dwc";
794 /* fall through to default "ci" for anything that did'nt select "dwc" */
795 default:
796 return "ci";
797 }
798}
Amol Jadi28864bb2013-10-11 14:12:59 -0700799
800/* UTMI MUX configuration to connect PHY to SNPS controller:
801 * Configure primary HS phy mux to use UTMI interface
802 * (connected to usb30 controller).
803 */
804static void tcsr_hs_phy_mux_configure(void)
805{
806 uint32_t reg;
807
808 reg = readl(USB2_PHY_SEL);
809
810 writel(reg | 0x1, USB2_PHY_SEL);
811}
812
813/* configure hs phy mux if using dwc controller */
814void target_usb_phy_mux_configure(void)
815{
816 if(!strcmp(target_usb_controller(), "dwc"))
817 {
818 tcsr_hs_phy_mux_configure();
819 }
820}