blob: 565b0b2e60fd9914ff18519d8067bc97ff7a7a27 [file] [log] [blame]
Smita Ghosh50a53ac2015-02-11 12:33:30 -08001/* Copyright (c) 2014-2015, 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>
Joonwoo Parke586c2e2014-04-02 11:04:10 -070057
58extern void smem_ptable_init(void);
59extern void smem_add_modem_partitions(struct ptable *flash_ptable);
60void target_sdc_init();
61
62static struct ptable flash_ptable;
63
64/* PMIC config data */
65#define PMIC_ARB_CHANNEL_NUM 0
66#define PMIC_ARB_OWNER_ID 0
67
68/* NANDc BAM pipe numbers */
69#define DATA_CONSUMER_PIPE 0
70#define DATA_PRODUCER_PIPE 1
71#define CMD_PIPE 2
72
73/* NANDc BAM pipe groups */
74#define DATA_PRODUCER_PIPE_GRP 0
75#define DATA_CONSUMER_PIPE_GRP 0
76#define CMD_PIPE_GRP 1
77
78/* NANDc EE */
79#define QPIC_NAND_EE 0
80
81/* NANDc max desc length. */
82#define QPIC_NAND_MAX_DESC_LEN 0x7FFF
83
84#define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF
85
Smita Ghosh50a53ac2015-02-11 12:33:30 -080086#define EXT4_CMDLINE " rootwait rootfstype=ext4 root=/dev/mmcblk0p"
anisha agarwal11df23e2015-06-12 14:37:34 -070087#define UBI_CMDLINE " rootfstype=ubifs rootflags=bulk_read"
anisha agarwalce363dd2014-08-26 15:17:09 -070088
Joonwoo Parke586c2e2014-04-02 11:04:10 -070089struct qpic_nand_init_config config;
90
91void update_ptable_names(void)
92{
93 uint32_t ptn_index;
94 struct ptentry *ptentry_ptr = flash_ptable.parts;
Joonwoo Parke586c2e2014-04-02 11:04:10 -070095 unsigned i;
96 uint32_t len;
97
98 /* Change all names to lower case. */
99 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
100 {
101 len = strlen(ptentry_ptr[ptn_index].name);
102
103 for (i = 0; i < len; i++)
104 {
105 if (isupper(ptentry_ptr[ptn_index].name[i]))
106 {
107 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
108 }
109 }
110
111 /* SBL fills in the last partition length as 0xFFFFFFFF.
112 * Update the length field based on the number of blocks on the flash.
113 */
114 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
115 {
116 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
117 }
118 }
119}
120
121void target_early_init(void)
122{
123#if WITH_DEBUG_UART
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700124 uart_dm_init(3, 0, BLSP1_UART2_BASE);
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700125#endif
126}
127
128int target_is_emmc_boot(void)
129{
130 return platform_boot_dev_isemmc();
131}
132
133/* init */
134void target_init(void)
135{
136 dprintf(INFO, "target_init()\n");
137
Sridhar Parasuram9ed91f32015-07-07 15:37:44 -0700138 pmic_info_populate();
139
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700140 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
141
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700142 if (platform_boot_dev_isemmc()) {
143 target_sdc_init();
144 if (partition_read_table()) {
145 dprintf(CRITICAL, "Error reading the partition table info\n");
146 ASSERT(0);
147 }
anisha agarwal70b8cd12015-02-02 11:44:46 -0800148 /* Below setting is to enable EBI2 function selection in TLMM so
149 that GPIOs can be used for display */
150 writel((readl(TLMM_EBI2_EMMC_GPIO_CFG) | EBI2_BOOT_SELECT), TLMM_EBI2_EMMC_GPIO_CFG);
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700151 } else {
152 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
153 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
154 config.pipes.cmd_pipe = CMD_PIPE;
155
156 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
157 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
158 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
159
160 config.bam_base = MSM_NAND_BAM_BASE;
161 config.nand_base = MSM_NAND_BASE;
162 config.ee = QPIC_NAND_EE;
163 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
164
165 qpic_nand_init(&config);
166
167 ptable_init(&flash_ptable);
168 smem_ptable_init();
169 smem_add_modem_partitions(&flash_ptable);
170
171 update_ptable_names();
172 flash_set_ptable(&flash_ptable);
173 }
174}
175
176/* reboot */
177void reboot_device(unsigned reboot_reason)
178{
179 /* Write the reboot reason */
180 writel(reboot_reason, RESTART_REASON_ADDR);
181
182 /* Configure PMIC for warm reset */
183 /* PM 8019 v1 aligns with PM8941 v2.
184 * This call should be based on the pmic version
185 * when PM8019 v2 is available.
186 */
Channagoud Kadabia85ed6e2015-03-23 14:35:16 -0700187 if (reboot_reason)
188 pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET);
189 else
190 pm8x41_v2_reset_configure(PON_PSHOLD_HARD_RESET);
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700191
192 /* Drop PS_HOLD for MSM */
193 writel(0x00, MPM2_MPM_PS_HOLD);
194
195 mdelay(5000);
196
197 dprintf(CRITICAL, "Rebooting failed\n");
198 return;
199}
200
201/* Identify the current target */
202void target_detect(struct board_data *board)
203{
204 /* This property is filled as part of board.c */
205}
206
207unsigned board_machtype(void)
208{
209 return LINUX_MACHTYPE_UNKNOWN;
210}
211
212/* Identify the baseband being used */
213void target_baseband_detect(struct board_data *board)
214{
215 board->baseband = BASEBAND_MSM;
216}
217
Sridhar Parasuram1d8c4222014-10-22 13:43:00 -0700218void target_serialno(unsigned char *buf)
219{
220 uint32_t serialno;
221 serialno = board_chip_serial();
222 snprintf((char *)buf, 13, "%x", serialno);
223}
224
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700225unsigned check_reboot_mode(void)
226{
227 unsigned restart_reason = 0;
228
229 /* Read reboot reason and scrub it */
230 restart_reason = readl(RESTART_REASON_ADDR);
231
232 writel(0x00, RESTART_REASON_ADDR);
233
234 return restart_reason;
235}
236
vijay kumarff36c312015-08-31 17:12:33 +0530237int get_target_boot_params(const char *cmdline, const char *part, char **buf)
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700238{
239 struct ptable *ptable;
240 int system_ptn_index = -1;
vijay kumarff36c312015-08-31 17:12:33 +0530241 uint32_t buflen;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700242
vijay kumarff36c312015-08-31 17:12:33 +0530243 if (!cmdline || !part ) {
anisha agarwalce363dd2014-08-26 15:17:09 -0700244 dprintf(CRITICAL, "WARN: Invalid input param\n");
245 return -1;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700246 }
247
anisha agarwalce363dd2014-08-26 15:17:09 -0700248 if (!strstr(cmdline, "root=/dev/ram")) /* This check is to handle kdev boot */
249 {
250 if (!target_is_emmc_boot()) {
vijay kumarff36c312015-08-31 17:12:33 +0530251
252 buflen = strlen(UBI_CMDLINE) + strlen(" root=ubi0:rootfs ubi.mtd=") + sizeof(int) + 1;
253 *buf = (char *)malloc(buflen);
254 if(!(*buf)) {
255 dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
256 return -1;
257 }
anisha agarwalce363dd2014-08-26 15:17:09 -0700258 /* Below is for NAND boot */
259 ptable = flash_get_ptable();
260 if (!ptable) {
261 dprintf(CRITICAL,
262 "WARN: Cannot get flash partition table\n");
vijay kumarff36c312015-08-31 17:12:33 +0530263 free(*buf);
anisha agarwalce363dd2014-08-26 15:17:09 -0700264 return -1;
265 }
266
267 system_ptn_index = ptable_get_index(ptable, part);
268 if (system_ptn_index < 0) {
269 dprintf(CRITICAL,
270 "WARN: Cannot get partition index for %s\n", part);
vijay kumarff36c312015-08-31 17:12:33 +0530271 free(*buf);
anisha agarwalce363dd2014-08-26 15:17:09 -0700272 return -1;
273 }
274 /* Adding command line parameters according to target boot type */
vijay kumarff36c312015-08-31 17:12:33 +0530275 snprintf(*buf, buflen, UBI_CMDLINE);
276 snprintf(*buf+strlen(*buf), buflen, " root=ubi0:rootfs ubi.mtd=%d", system_ptn_index);
anisha agarwalce363dd2014-08-26 15:17:09 -0700277 }
278 else {
vijay kumarff36c312015-08-31 17:12:33 +0530279 buflen = strlen("EXT4_CMDLINE") + sizeof(int) +1;
280 *buf = (char *)malloc(buflen);
281 if(!(*buf)) {
282 dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
283 return -1;
284 }
anisha agarwalce363dd2014-08-26 15:17:09 -0700285 /* Below is for emmc boot */
anisha agarwalc49a3252014-10-15 17:37:40 -0700286 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 -0700287 if (system_ptn_index < 0) {
288 dprintf(CRITICAL,
289 "WARN: Cannot get partition index for %s\n", part);
vijay kumarff36c312015-08-31 17:12:33 +0530290 free(*buf);
anisha agarwalce363dd2014-08-26 15:17:09 -0700291 return -1;
292 }
vijay kumarff36c312015-08-31 17:12:33 +0530293 snprintf(*buf, buflen, EXT4_CMDLINE"%d", system_ptn_index);
anisha agarwalce363dd2014-08-26 15:17:09 -0700294 }
anisha agarwalce363dd2014-08-26 15:17:09 -0700295 }
vijay kumarff36c312015-08-31 17:12:33 +0530296 /*in success case buf will be freed in the calling function of this*/
Sridhar Parasuramdbe91a42014-12-29 13:45:30 -0800297 return 0;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700298}
299
300const char * target_usb_controller()
301{
302 return "dwc";
303}
304
305static void set_sdc_power_ctrl()
306{
307 /* Drive strength configs for sdc pins */
308 struct tlmm_cfgs sdc1_hdrv_cfg[] =
309 {
Sridhar Parasuramdbe91a42014-12-29 13:45:30 -0800310 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, 0 },
311 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, 0 },
312 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK, 0 },
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700313 };
314
315 /* Pull configs for sdc pins */
316 struct tlmm_cfgs sdc1_pull_cfg[] =
317 {
Sridhar Parasuramdbe91a42014-12-29 13:45:30 -0800318 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, 0 },
319 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0 },
320 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0 },
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700321 };
322
323 /* Set the drive strength & pull control values */
324 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
325 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
326}
327
328static struct mmc_device *dev;
329
330void *target_mmc_device()
331{
332 return (void *) dev;
333}
334
335void target_sdc_init()
336{
337 struct mmc_config_data config;
338
339 /* Set drive strength & pull ctrl values */
340 set_sdc_power_ctrl();
341
342 config.slot = 1;
Channagoud Kadabide17ba82014-11-12 13:05:57 -0800343 config.bus_width = DATA_BUS_WIDTH_8BIT;
Channagoud Kadabi6608d022015-04-20 11:31:56 -0700344 config.max_clk_rate = MMC_CLK_171MHZ;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700345 config.sdhc_base = MSM_SDC1_SDHCI_BASE;
346 config.pwrctl_base = MSM_SDC1_BASE;
347 config.pwr_irq = SDCC1_PWRCTL_IRQ;
348 config.hs400_support = 0;
Channagoud Kadabide17ba82014-11-12 13:05:57 -0800349 config.hs200_support = 0;
Channagoud Kadabid23379d2014-10-13 11:33:50 -0700350 config.use_io_switch = 1;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700351
352 if (!(dev = mmc_init(&config))) {
353 dprintf(CRITICAL, "mmc init failed!");
354 ASSERT(0);
355 }
356}
357
anisha agarwal0fc661d2014-11-26 11:54:32 -0800358int target_cont_splash_screen()
359{
360 /* FOR OEMs - Set cont_splash_screen to keep the splash enable after LK.*/
anisha agarwal58d25cf2014-11-26 12:09:23 -0800361 return false;
anisha agarwal0fc661d2014-11-26 11:54:32 -0800362}
363
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700364void target_uninit(void)
365{
366 if (platform_boot_dev_isemmc())
367 {
368 mmc_put_card_to_sleep(dev);
369 sdhci_mode_disable(&dev->host);
370 }
371}
372
Joonwoo Park39aed062014-06-09 17:00:07 -0700373void target_usb_phy_reset(void)
374{
Joonwoo Park39aed062014-06-09 17:00:07 -0700375 usb30_qmp_phy_reset();
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700376 qusb2_phy_reset();
Joonwoo Park39aed062014-06-09 17:00:07 -0700377}
378
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700379target_usb_iface_t* target_usb30_init()
380{
381 target_usb_iface_t *t_usb_iface;
382
Sridhar Parasuramdbe91a42014-12-29 13:45:30 -0800383 t_usb_iface = (target_usb_iface_t *) calloc(1, sizeof(target_usb_iface_t));
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700384 ASSERT(t_usb_iface);
385
386 t_usb_iface->mux_config = NULL;
387 t_usb_iface->phy_init = usb30_qmp_phy_init;
Joonwoo Park39aed062014-06-09 17:00:07 -0700388 t_usb_iface->phy_reset = target_usb_phy_reset;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700389 t_usb_iface->clock_init = clock_usb30_init;
390 t_usb_iface->vbus_override = 1;
391
392 return t_usb_iface;
393}
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700394
395uint32_t target_override_pll()
396{
397 return 1;
398}
Channagoud Kadabid23379d2014-10-13 11:33:50 -0700399
400uint32_t target_get_hlos_subtype()
401{
402 return board_hlos_subtype();
403}