blob: bb6eb13d6b14eeba89d67a169f39ce35124ebca9 [file] [log] [blame]
vijay kumar7d06bbb2015-11-24 13:04:55 +05301/* Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
Joonwoo Parke586c2e2014-04-02 11:04:10 -07002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <board.h>
31#include <platform.h>
32#include <target.h>
33#include <smem.h>
34#include <baseband.h>
35#include <lib/ptable.h>
36#include <qpic_nand.h>
Sridhar Parasuramdbe91a42014-12-29 13:45:30 -080037#include <malloc.h>
Joonwoo Parke586c2e2014-04-02 11:04:10 -070038#include <ctype.h>
39#include <string.h>
40#include <pm8x41.h>
41#include <reg.h>
42#include <hsusb.h>
43#include <mmc.h>
44#include <platform/timer.h>
45#include <platform/irqs.h>
46#include <platform/gpio.h>
47#include <platform/clock.h>
48#include <qmp_phy.h>
Joonwoo Park39aed062014-06-09 17:00:07 -070049#include <qusb2_phy.h>
anisha agarwalffb78ab2014-11-18 15:20:31 -080050#include <rpm-smd.h>
51#include <scm.h>
Sridhar Parasuramdbe91a42014-12-29 13:45:30 -080052#include <spmi.h>
53#include <partition_parser.h>
54#include <sdhci_msm.h>
55#include <uart_dm.h>
56#include <boot_device.h>
Channagoud Kadabifdfee232015-10-07 11:55:47 -070057#include <qmp_phy.h>
vijay kumar7d06bbb2015-11-24 13:04:55 +053058#include <crypto5_wrapper.h>
Mayank Grover9714e2c2016-12-15 14:48:54 +053059#include <rpm-glink.h>
Joonwoo Parke586c2e2014-04-02 11:04:10 -070060
61extern void smem_ptable_init(void);
62extern void smem_add_modem_partitions(struct ptable *flash_ptable);
63void target_sdc_init();
64
65static struct ptable flash_ptable;
66
67/* PMIC config data */
68#define PMIC_ARB_CHANNEL_NUM 0
69#define PMIC_ARB_OWNER_ID 0
70
71/* NANDc BAM pipe numbers */
72#define DATA_CONSUMER_PIPE 0
73#define DATA_PRODUCER_PIPE 1
74#define CMD_PIPE 2
75
76/* NANDc BAM pipe groups */
77#define DATA_PRODUCER_PIPE_GRP 0
78#define DATA_CONSUMER_PIPE_GRP 0
79#define CMD_PIPE_GRP 1
80
81/* NANDc EE */
82#define QPIC_NAND_EE 0
83
84/* NANDc max desc length. */
85#define QPIC_NAND_MAX_DESC_LEN 0x7FFF
86
87#define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF
88
Smita Ghosh50a53ac2015-02-11 12:33:30 -080089#define EXT4_CMDLINE " rootwait rootfstype=ext4 root=/dev/mmcblk0p"
anisha agarwal11df23e2015-06-12 14:37:34 -070090#define UBI_CMDLINE " rootfstype=ubifs rootflags=bulk_read"
anisha agarwalce363dd2014-08-26 15:17:09 -070091
vijay kumar7d06bbb2015-11-24 13:04:55 +053092#define CE1_INSTANCE 1
93#define CE_EE 1
94#define CE_FIFO_SIZE 64
95#define CE_READ_PIPE 3
96#define CE_WRITE_PIPE 2
97#define CE_READ_PIPE_LOCK_GRP 0
98#define CE_WRITE_PIPE_LOCK_GRP 0
99#define CE_ARRAY_SIZE 20
100#define SUB_TYPE_SKUT 0x0A
101
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700102struct qpic_nand_init_config config;
103
104void update_ptable_names(void)
105{
106 uint32_t ptn_index;
107 struct ptentry *ptentry_ptr = flash_ptable.parts;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700108 unsigned i;
109 uint32_t len;
110
111 /* Change all names to lower case. */
112 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
113 {
114 len = strlen(ptentry_ptr[ptn_index].name);
115
116 for (i = 0; i < len; i++)
117 {
118 if (isupper(ptentry_ptr[ptn_index].name[i]))
119 {
120 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
121 }
122 }
123
124 /* SBL fills in the last partition length as 0xFFFFFFFF.
125 * Update the length field based on the number of blocks on the flash.
126 */
127 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
128 {
129 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
130 }
131 }
132}
133
134void target_early_init(void)
135{
136#if WITH_DEBUG_UART
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700137 uart_dm_init(3, 0, BLSP1_UART2_BASE);
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700138#endif
139}
140
141int target_is_emmc_boot(void)
142{
143 return platform_boot_dev_isemmc();
144}
145
146/* init */
147void target_init(void)
148{
149 dprintf(INFO, "target_init()\n");
150
Sridhar Parasuram9ed91f32015-07-07 15:37:44 -0700151 pmic_info_populate();
152
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700153 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Runmin Wangc16e4f92016-11-18 17:09:53 -0800154 if(!platform_is_sdxhedgehog())
Mayank Grover9714e2c2016-12-15 14:48:54 +0530155 {
Runmin Wangc16e4f92016-11-18 17:09:53 -0800156 rpm_smd_init();
Mayank Grover9714e2c2016-12-15 14:48:54 +0530157 }
158 else
159 {
160 /* Initialize Glink */
161 rpm_glink_init();
162 }
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700163
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700164 if (platform_boot_dev_isemmc()) {
165 target_sdc_init();
166 if (partition_read_table()) {
167 dprintf(CRITICAL, "Error reading the partition table info\n");
168 ASSERT(0);
169 }
anisha agarwal70b8cd12015-02-02 11:44:46 -0800170 /* Below setting is to enable EBI2 function selection in TLMM so
171 that GPIOs can be used for display */
172 writel((readl(TLMM_EBI2_EMMC_GPIO_CFG) | EBI2_BOOT_SELECT), TLMM_EBI2_EMMC_GPIO_CFG);
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700173 } else {
174 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
175 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
176 config.pipes.cmd_pipe = CMD_PIPE;
177
178 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
179 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
180 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
181
182 config.bam_base = MSM_NAND_BAM_BASE;
183 config.nand_base = MSM_NAND_BASE;
184 config.ee = QPIC_NAND_EE;
185 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
186
187 qpic_nand_init(&config);
188
189 ptable_init(&flash_ptable);
190 smem_ptable_init();
191 smem_add_modem_partitions(&flash_ptable);
192
193 update_ptable_names();
194 flash_set_ptable(&flash_ptable);
195 }
vijay kumar7d06bbb2015-11-24 13:04:55 +0530196
197 if (target_use_signed_kernel())
198 target_crypto_init_params();
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700199}
200
P.V. Phani Kumar6b1083d2016-07-19 20:55:04 +0530201static int scm_clear_boot_partition_select()
202{
203 int ret = 0;
204
205 ret = scm_call_atomic2(SCM_SVC_BOOT, WDOG_DEBUG_DISABLE, 1, 0);
206 if (ret)
207 dprintf(CRITICAL, "Failed to disable the wdog debug \n");
208
209 return ret;
210}
211
212/* Trigger reboot */
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700213void reboot_device(unsigned reboot_reason)
214{
P.V. Phani Kumar6b1083d2016-07-19 20:55:04 +0530215 uint8_t reset_type = 0;
216
Runmin Wang7231ec22016-11-18 11:18:41 -0800217 if (platform_is_mdmcalifornium() || platform_is_sdxhedgehog())
P.V. Phani Kumar6b1083d2016-07-19 20:55:04 +0530218 {
219 /* Clear the boot partition select cookie to indicate
220 * its a normal reset and avoid going to download mode */
221 scm_clear_boot_partition_select();
222 }
223
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700224 /* Write the reboot reason */
225 writel(reboot_reason, RESTART_REASON_ADDR);
226
P.V. Phani Kumar6b1083d2016-07-19 20:55:04 +0530227 if(reboot_reason)
228 reset_type = PON_PSHOLD_WARM_RESET;
Channagoud Kadabia85ed6e2015-03-23 14:35:16 -0700229 else
P.V. Phani Kumar6b1083d2016-07-19 20:55:04 +0530230 reset_type = PON_PSHOLD_HARD_RESET;
231
Runmin Wang7231ec22016-11-18 11:18:41 -0800232 if (platform_is_mdmcalifornium() || platform_is_sdxhedgehog())
P.V. Phani Kumar6b1083d2016-07-19 20:55:04 +0530233 {
234 /* PMD9655 is the PMIC used for MDMcalifornium */
235 pm8x41_reset_configure(reset_type);
236 } else {
237 /* Configure PMIC for warm reset */
238 /* PM 8019 v1 aligns with PM8941 v2.
239 * This call should be based on the pmic version
240 * when PM8019 v2 is available.
241 */
242 pm8x41_v2_reset_configure(reset_type);
243 }
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700244
245 /* Drop PS_HOLD for MSM */
246 writel(0x00, MPM2_MPM_PS_HOLD);
247
248 mdelay(5000);
249
250 dprintf(CRITICAL, "Rebooting failed\n");
251 return;
252}
253
254/* Identify the current target */
255void target_detect(struct board_data *board)
256{
257 /* This property is filled as part of board.c */
258}
259
260unsigned board_machtype(void)
261{
262 return LINUX_MACHTYPE_UNKNOWN;
263}
264
265/* Identify the baseband being used */
266void target_baseband_detect(struct board_data *board)
267{
268 board->baseband = BASEBAND_MSM;
269}
270
Sridhar Parasuram1d8c4222014-10-22 13:43:00 -0700271void target_serialno(unsigned char *buf)
272{
273 uint32_t serialno;
274 serialno = board_chip_serial();
275 snprintf((char *)buf, 13, "%x", serialno);
276}
277
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700278unsigned check_reboot_mode(void)
279{
280 unsigned restart_reason = 0;
281
282 /* Read reboot reason and scrub it */
283 restart_reason = readl(RESTART_REASON_ADDR);
284
285 writel(0x00, RESTART_REASON_ADDR);
286
287 return restart_reason;
288}
289
vijay kumarff36c312015-08-31 17:12:33 +0530290int get_target_boot_params(const char *cmdline, const char *part, char **buf)
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700291{
292 struct ptable *ptable;
293 int system_ptn_index = -1;
vijay kumarff36c312015-08-31 17:12:33 +0530294 uint32_t buflen;
Channagoud Kadabifdfee232015-10-07 11:55:47 -0700295 int ret = -1;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700296
vijay kumarff36c312015-08-31 17:12:33 +0530297 if (!cmdline || !part ) {
anisha agarwalce363dd2014-08-26 15:17:09 -0700298 dprintf(CRITICAL, "WARN: Invalid input param\n");
299 return -1;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700300 }
301
anisha agarwalce363dd2014-08-26 15:17:09 -0700302 if (!strstr(cmdline, "root=/dev/ram")) /* This check is to handle kdev boot */
303 {
304 if (!target_is_emmc_boot()) {
vijay kumarff36c312015-08-31 17:12:33 +0530305
306 buflen = strlen(UBI_CMDLINE) + strlen(" root=ubi0:rootfs ubi.mtd=") + sizeof(int) + 1;
307 *buf = (char *)malloc(buflen);
308 if(!(*buf)) {
309 dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
310 return -1;
311 }
anisha agarwalce363dd2014-08-26 15:17:09 -0700312 /* Below is for NAND boot */
313 ptable = flash_get_ptable();
314 if (!ptable) {
315 dprintf(CRITICAL,
316 "WARN: Cannot get flash partition table\n");
vijay kumarff36c312015-08-31 17:12:33 +0530317 free(*buf);
anisha agarwalce363dd2014-08-26 15:17:09 -0700318 return -1;
319 }
320
321 system_ptn_index = ptable_get_index(ptable, part);
322 if (system_ptn_index < 0) {
323 dprintf(CRITICAL,
324 "WARN: Cannot get partition index for %s\n", part);
vijay kumarff36c312015-08-31 17:12:33 +0530325 free(*buf);
anisha agarwalce363dd2014-08-26 15:17:09 -0700326 return -1;
327 }
328 /* Adding command line parameters according to target boot type */
vijay kumarff36c312015-08-31 17:12:33 +0530329 snprintf(*buf, buflen, UBI_CMDLINE);
330 snprintf(*buf+strlen(*buf), buflen, " root=ubi0:rootfs ubi.mtd=%d", system_ptn_index);
Channagoud Kadabifdfee232015-10-07 11:55:47 -0700331 ret = 0;
anisha agarwalce363dd2014-08-26 15:17:09 -0700332 }
333 else {
Channagoud Kadabi9d9b5212015-10-20 17:29:50 -0700334 buflen = strlen(EXT4_CMDLINE) + sizeof(int) +1;
vijay kumarff36c312015-08-31 17:12:33 +0530335 *buf = (char *)malloc(buflen);
336 if(!(*buf)) {
337 dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
338 return -1;
339 }
anisha agarwalce363dd2014-08-26 15:17:09 -0700340 /* Below is for emmc boot */
anisha agarwalc49a3252014-10-15 17:37:40 -0700341 system_ptn_index = partition_get_index(part) + 1; /* Adding +1 as offsets for eMMC start at 1 and NAND at 0 */
anisha agarwalce363dd2014-08-26 15:17:09 -0700342 if (system_ptn_index < 0) {
343 dprintf(CRITICAL,
344 "WARN: Cannot get partition index for %s\n", part);
vijay kumarff36c312015-08-31 17:12:33 +0530345 free(*buf);
anisha agarwalce363dd2014-08-26 15:17:09 -0700346 return -1;
347 }
vijay kumarff36c312015-08-31 17:12:33 +0530348 snprintf(*buf, buflen, EXT4_CMDLINE"%d", system_ptn_index);
Channagoud Kadabifdfee232015-10-07 11:55:47 -0700349 ret = 0;
anisha agarwalce363dd2014-08-26 15:17:09 -0700350 }
anisha agarwalce363dd2014-08-26 15:17:09 -0700351 }
vijay kumarff36c312015-08-31 17:12:33 +0530352 /*in success case buf will be freed in the calling function of this*/
Channagoud Kadabifdfee232015-10-07 11:55:47 -0700353 return ret;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700354}
355
356const char * target_usb_controller()
357{
358 return "dwc";
359}
360
361static void set_sdc_power_ctrl()
362{
363 /* Drive strength configs for sdc pins */
364 struct tlmm_cfgs sdc1_hdrv_cfg[] =
365 {
Sridhar Parasuramdbe91a42014-12-29 13:45:30 -0800366 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, 0 },
367 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, 0 },
368 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK, 0 },
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700369 };
370
371 /* Pull configs for sdc pins */
372 struct tlmm_cfgs sdc1_pull_cfg[] =
373 {
Sridhar Parasuramdbe91a42014-12-29 13:45:30 -0800374 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, 0 },
375 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0 },
376 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0 },
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700377 };
378
379 /* Set the drive strength & pull control values */
380 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
381 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
382}
383
384static struct mmc_device *dev;
385
386void *target_mmc_device()
387{
388 return (void *) dev;
389}
390
391void target_sdc_init()
392{
393 struct mmc_config_data config;
394
395 /* Set drive strength & pull ctrl values */
396 set_sdc_power_ctrl();
397
398 config.slot = 1;
Channagoud Kadabide17ba82014-11-12 13:05:57 -0800399 config.bus_width = DATA_BUS_WIDTH_8BIT;
Channagoud Kadabi6608d022015-04-20 11:31:56 -0700400 config.max_clk_rate = MMC_CLK_171MHZ;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700401 config.sdhc_base = MSM_SDC1_SDHCI_BASE;
402 config.pwrctl_base = MSM_SDC1_BASE;
403 config.pwr_irq = SDCC1_PWRCTL_IRQ;
404 config.hs400_support = 0;
Channagoud Kadabide17ba82014-11-12 13:05:57 -0800405 config.hs200_support = 0;
Channagoud Kadabid23379d2014-10-13 11:33:50 -0700406 config.use_io_switch = 1;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700407
408 if (!(dev = mmc_init(&config))) {
409 dprintf(CRITICAL, "mmc init failed!");
410 ASSERT(0);
411 }
412}
413
anisha agarwal0fc661d2014-11-26 11:54:32 -0800414int target_cont_splash_screen()
415{
416 /* FOR OEMs - Set cont_splash_screen to keep the splash enable after LK.*/
anisha agarwal58d25cf2014-11-26 12:09:23 -0800417 return false;
anisha agarwal0fc661d2014-11-26 11:54:32 -0800418}
419
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700420void target_uninit(void)
421{
422 if (platform_boot_dev_isemmc())
423 {
424 mmc_put_card_to_sleep(dev);
425 sdhci_mode_disable(&dev->host);
426 }
vijay kumar7d06bbb2015-11-24 13:04:55 +0530427
428 if (crypto_initialized())
429 crypto_eng_cleanup();
430
Runmin Wangc16e4f92016-11-18 17:09:53 -0800431 if(!platform_is_sdxhedgehog())
Mayank Grover9714e2c2016-12-15 14:48:54 +0530432 {
Runmin Wangc16e4f92016-11-18 17:09:53 -0800433 rpm_smd_uninit();
Mayank Grover9714e2c2016-12-15 14:48:54 +0530434 }
435 else
436 {
437 /* Tear down glink channels */
438 rpm_glink_uninit();
439 }
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700440}
441
Joonwoo Park39aed062014-06-09 17:00:07 -0700442void target_usb_phy_reset(void)
443{
Channagoud Kadabifdfee232015-10-07 11:55:47 -0700444 /* Reset sequence for californium is different from 9x40, use the reset sequence
445 * from clock driver
446 */
Runmin Wangdc8e9732016-10-06 11:14:08 -0700447 if (platform_is_mdmcalifornium() || platform_is_sdxhedgehog())
448 clock_reset_usb_phy(); // This is the reset function for USB3
Channagoud Kadabifdfee232015-10-07 11:55:47 -0700449 else
450 usb30_qmp_phy_reset();
451
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700452 qusb2_phy_reset();
Joonwoo Park39aed062014-06-09 17:00:07 -0700453}
454
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700455target_usb_iface_t* target_usb30_init()
456{
457 target_usb_iface_t *t_usb_iface;
458
Sridhar Parasuramdbe91a42014-12-29 13:45:30 -0800459 t_usb_iface = (target_usb_iface_t *) calloc(1, sizeof(target_usb_iface_t));
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700460 ASSERT(t_usb_iface);
461
462 t_usb_iface->mux_config = NULL;
Runmin Wangdc8e9732016-10-06 11:14:08 -0700463 if (platform_is_sdxhedgehog())
464 t_usb_iface->phy_init = NULL;
465 else
466 t_usb_iface->phy_init = usb30_qmp_phy_init;
Joonwoo Park39aed062014-06-09 17:00:07 -0700467 t_usb_iface->phy_reset = target_usb_phy_reset;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700468 t_usb_iface->clock_init = clock_usb30_init;
469 t_usb_iface->vbus_override = 1;
470
471 return t_usb_iface;
472}
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700473
474uint32_t target_override_pll()
475{
Runmin Wangdc8e9732016-10-06 11:14:08 -0700476 if (platform_is_mdmcalifornium() || platform_is_sdxhedgehog())
Channagoud Kadabifdfee232015-10-07 11:55:47 -0700477 return 0;
478 else
479 return 1;
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700480}
Channagoud Kadabid23379d2014-10-13 11:33:50 -0700481
482uint32_t target_get_hlos_subtype()
483{
484 return board_hlos_subtype();
485}
Channagoud Kadabifdfee232015-10-07 11:55:47 -0700486
487/* QMP settings are different from californium when compared to v2.0/v1.0 hardware.
488 * Use the QMP settings from target code to keep the common driver clean
489 */
490struct qmp_reg qmp_settings[] =
491{
492 {0x804, 0x01}, /*USB3PHY_PCIE_USB3_PCS_POWER_DOWN_CONTROL */
493 {0xAC, 0x14}, /* QSERDES_COM_SYSCLK_EN_SEL */
494 {0x34, 0x08}, /* QSERDES_COM_BIAS_EN_CLKBUFLR_EN */
495 {0x174, 0x30}, /* QSERDES_COM_CLK_SELECT */
496 {0x3C, 0x06}, /* QSERDES_COM_SYS_CLK_CTRL */
497 {0xB4, 0x00}, /* QSERDES_COM_RESETSM_CNTRL */
498 {0xB8, 0x08}, /* QSERDES_COM_RESETSM_CNTRL2 */
499 {0x194, 0x06}, /* QSERDES_COM_CMN_CONFIG */
500 {0x19c, 0x01}, /* QSERDES_COM_SVS_MODE_CLK_SEL */
501 {0x178, 0x00}, /* QSERDES_COM_HSCLK_SEL */
502 {0xd0, 0x82}, /* QSERDES_COM_DEC_START_MODE0 */
503 {0xdc, 0x55}, /* QSERDES_COM_DIV_FRAC_START1_MODE0 */
504 {0xe0, 0x55}, /* QSERDES_COM_DIV_FRAC_START2_MODE0 */
505 {0xe4, 0x03}, /* QSERDES_COM_DIV_FRAC_START3_MODE0 */
506 {0x78, 0x0b}, /* QSERDES_COM_CP_CTRL_MODE0 */
507 {0x84, 0x16}, /* QSERDES_COM_PLL_RCTRL_MODE0 */
508 {0x90, 0x28}, /* QSERDES_COM_PLL_CCTRL_MODE0 */
509 {0x108, 0x80}, /* QSERDES_COM_INTEGLOOP_GAIN0_MODE0 */
510 {0x10C, 0x00}, /* QSERDES_COM_INTEGLOOP_GAIN1_MODE0 */
511 {0x184, 0x0A}, /* QSERDES_COM_CORECLK_DIV */
512 {0x4c, 0x15}, /* QSERDES_COM_LOCK_CMP1_MODE0 */
513 {0x50, 0x34}, /* QSERDES_COM_LOCK_CMP2_MODE0 */
514 {0x54, 0x00}, /* QSERDES_COM_LOCK_CMP3_MODE0 */
515 {0xC8, 0x00}, /* QSERDES_COM_LOCK_CMP_EN */
516 {0x18c, 0x00}, /* QSERDES_COM_CORE_CLK_EN */
517 {0xcc, 0x00}, /* QSERDES_COM_LOCK_CMP_CFG */
518 {0x128, 0x00}, /* QSERDES_COM_VCO_TUNE_MAP */
519 {0x0C, 0x0A}, /* QSERDES_COM_BG_TIMER */
520 {0x10, 0x01}, /* QSERDES_COM_SSC_EN_CENTER */
521 {0x1c, 0x31}, /* QSERDES_COM_SSC_PER1 */
522 {0x20, 0x01}, /* QSERDES_COM_SSC_PER2 */
523 {0x14, 0x00}, /* QSERDES_COM_SSC_ADJ_PER1 */
524 {0x18, 0x00}, /* QSERDES_COM_SSC_ADJ_PER2 */
525 {0x24, 0xde}, /* QSERDES_COM_SSC_STEP_SIZE1 */
526 {0x28, 0x07}, /* QSERDES_COM_SSC_STEP_SIZE2 */
527 {0x48, 0x0F}, /* USB3PHY_QSERDES_COM_PLL_IVCO */
528 {0x70, 0x0F}, /* USB3PHY_QSERDES_COM_BG_TRIM */
529 {0x100, 0x80}, /* QSERDES_COM_INTEGLOOP_INITVAL */
530
531 /* Rx Settings */
532 {0x440, 0x0b}, /* QSERDES_RX_UCDR_FASTLOCK_FO_GAIN */
533 {0x4d8, 0x02}, /* QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2 */
534 {0x4dc, 0x6c}, /* QSERDES_RX_RX_EQU_ADAPTOR_CNTRL3 */
535 {0x4e0, 0xbb}, /* QSERDES_RX_RX_EQU_ADAPTOR_CNTRL4 */
536 {0x508, 0x77}, /* QSERDES_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1 */
537 {0x50c, 0x80}, /* QSERDES_RX_RX_OFFSET_ADAPTOR_CNTRL2 */
538 {0x514, 0x03}, /* QSERDES_RX_SIGDET_CNTRL */
539 {0x51c, 0x16}, /* QSERDES_RX_SIGDET_DEGLITCH_CNTRL */
540 {0x448, 0x75}, /* QSERDES_RX_UCDR_SO_SATURATION_AND_ENABLE */
541 {0x450, 0x00}, /* QSERDES_RX_UCDR_FASTLOCK_COUNT_LOW */
542 {0x454, 0x00}, /* QSERDES_RX_UCDR_FASTLOCK_COUNT_HIGH */
543 {0x40C, 0x0a}, /* QSERDES_RX_UCDR_FO_GAIN */
544 {0x41C, 0x06}, /* QSERDES_RX_UCDR_SO_GAIN */
545 {0x510, 0x00}, /*QSERDES_RX_SIGDET_ENABLES */
546
547 /* Tx settings */
548 {0x268, 0x45}, /* QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN */
549 {0x2ac, 0x12}, /* QSERDES_TX_RCV_DETECT_LVL_2 */
550 {0x294, 0x06}, /* QSERDES_TX_LANE_MODE */
551 {0x254, 0x00}, /* QSERDES_TX_RES_CODE_LANE_OFFSET */
552
553 /* FLL settings */
554 {0x8c8, 0x83}, /* PCIE_USB3_PCS_FLL_CNTRL2 */
555 {0x8c4, 0x02}, /* PCIE_USB3_PCS_FLL_CNTRL1 */
556 {0x8cc, 0x09}, /* PCIE_USB3_PCS_FLL_CNT_VAL_L */
557 {0x8D0, 0xA2}, /* PCIE_USB3_PCS_FLL_CNT_VAL_H_TOL */
558 {0x8D4, 0x85}, /* PCIE_USB3_PCS_FLL_MAN_CODE */
559
560 /* PCS Settings */
561 {0x880, 0xD1}, /* PCIE_USB3_PCS_LOCK_DETECT_CONFIG1 */
562 {0x884, 0x1F}, /* PCIE_USB3_PCS_LOCK_DETECT_CONFIG2 */
563 {0x888, 0x47}, /* PCIE_USB3_PCS_LOCK_DETECT_CONFIG3 */
564 {0x80C, 0x9F}, /* PCIE_USB3_PCS_TXMGN_V0 */
565 {0x824, 0x17}, /* PCIE_USB3_PCS_TXDEEMPH_M6DB_V0 */
566 {0x828, 0x0F}, /* PCIE_USB3_PCS_TXDEEMPH_M3P5DB_V0 */
567 {0x8B8, 0x75}, /* PCIE_USB3_PCS_RXEQTRAINING_WAIT_TIME */
568 {0x8BC, 0x13}, /* PCIE_USB3_PCS_RXEQTRAINING_RUN_TIME */
569 {0x8B0, 0x86}, /* PCIE_USB3_PCS_LFPS_TX_ECSTART_EQTLOCK */
570 {0x8A0, 0x04}, /* PCIE_USB3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK */
571 {0x88C, 0x44}, /* PCIE_USB3_PCS_TSYNC_RSYNC_TIME */
572 {0x870, 0xE7}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_P1U2_L */
573 {0x874, 0x03}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_P1U2_H */
574 {0x878, 0x40}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_U3_L */
575 {0x87c, 0x00}, /* PCIE_USB3_PCS_RCVR_DTCT_DLY_U3_H */
576 {0x9D8, 0x88}, /* PCIE_USB3_PCS_RX_SIGDET_LVL */
577 {0x808, 0x03}, /* PCIE_USB3_PCS_START_CONTROL */
578 {0x800, 0x00}, /* PCIE_USB3_PCS_SW_RESET */
579};
580
581struct qmp_reg *target_get_qmp_settings()
582{
Runmin Wangdc8e9732016-10-06 11:14:08 -0700583 if (platform_is_mdmcalifornium() || platform_is_sdxhedgehog())
Channagoud Kadabifdfee232015-10-07 11:55:47 -0700584 return qmp_settings;
585 else
586 return NULL;
587}
588
589int target_get_qmp_regsize()
590{
Runmin Wangdc8e9732016-10-06 11:14:08 -0700591 if (platform_is_mdmcalifornium() || platform_is_sdxhedgehog())
Channagoud Kadabifdfee232015-10-07 11:55:47 -0700592 return ARRAY_SIZE(qmp_settings);
593 else
594 return 0;
595}
vijay kumar7d06bbb2015-11-24 13:04:55 +0530596
597crypto_engine_type board_ce_type(void)
598{
599 return CRYPTO_ENGINE_TYPE_HW;
600}
601
602/* Set up params for h/w CE. */
603void target_crypto_init_params()
604{
605 struct crypto_init_params ce_params;
606
607 /* Set up base addresses and instance. */
608 ce_params.crypto_instance = CE1_INSTANCE;
609 ce_params.crypto_base = MSM_CE1_BASE;
610 ce_params.bam_base = MSM_CE1_BAM_BASE;
611
612 /* Set up BAM config. */
613 ce_params.bam_ee = CE_EE;
614 ce_params.pipes.read_pipe = CE_READ_PIPE;
615 ce_params.pipes.write_pipe = CE_WRITE_PIPE;
616 ce_params.pipes.read_pipe_grp = CE_READ_PIPE_LOCK_GRP;
617 ce_params.pipes.write_pipe_grp = CE_WRITE_PIPE_LOCK_GRP;
618
619 /* Assign buffer sizes. */
620 ce_params.num_ce = CE_ARRAY_SIZE;
621 ce_params.read_fifo_size = CE_FIFO_SIZE;
622 ce_params.write_fifo_size = CE_FIFO_SIZE;
623
624 /* BAM is initialized by TZ for this platform.
625 * Do not do it again as the initialization address space
626 * is locked.
627 */
628 ce_params.do_bam_init = 0;
629 crypto_init_params(&ce_params);
630}