blob: adaccfd58658f0f48a2fddf2f75de86cda9a4321 [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 agarwalce363dd2014-08-26 15:17:09 -070087#define UBI_CMDLINE " rootfstype=ubifs rootflags=bulk_read ubi.fm_autoconvert=1"
88
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
138 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
139
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700140 if (platform_boot_dev_isemmc()) {
141 target_sdc_init();
142 if (partition_read_table()) {
143 dprintf(CRITICAL, "Error reading the partition table info\n");
144 ASSERT(0);
145 }
anisha agarwal70b8cd12015-02-02 11:44:46 -0800146 /* Below setting is to enable EBI2 function selection in TLMM so
147 that GPIOs can be used for display */
148 writel((readl(TLMM_EBI2_EMMC_GPIO_CFG) | EBI2_BOOT_SELECT), TLMM_EBI2_EMMC_GPIO_CFG);
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700149 } else {
150 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
151 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
152 config.pipes.cmd_pipe = CMD_PIPE;
153
154 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
155 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
156 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
157
158 config.bam_base = MSM_NAND_BAM_BASE;
159 config.nand_base = MSM_NAND_BASE;
160 config.ee = QPIC_NAND_EE;
161 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
162
163 qpic_nand_init(&config);
164
165 ptable_init(&flash_ptable);
166 smem_ptable_init();
167 smem_add_modem_partitions(&flash_ptable);
168
169 update_ptable_names();
170 flash_set_ptable(&flash_ptable);
171 }
172}
173
174/* reboot */
175void reboot_device(unsigned reboot_reason)
176{
177 /* Write the reboot reason */
178 writel(reboot_reason, RESTART_REASON_ADDR);
179
180 /* Configure PMIC for warm reset */
181 /* PM 8019 v1 aligns with PM8941 v2.
182 * This call should be based on the pmic version
183 * when PM8019 v2 is available.
184 */
185 pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET);
186
187 /* Drop PS_HOLD for MSM */
188 writel(0x00, MPM2_MPM_PS_HOLD);
189
190 mdelay(5000);
191
192 dprintf(CRITICAL, "Rebooting failed\n");
193 return;
194}
195
196/* Identify the current target */
197void target_detect(struct board_data *board)
198{
199 /* This property is filled as part of board.c */
200}
201
202unsigned board_machtype(void)
203{
204 return LINUX_MACHTYPE_UNKNOWN;
205}
206
207/* Identify the baseband being used */
208void target_baseband_detect(struct board_data *board)
209{
210 board->baseband = BASEBAND_MSM;
211}
212
Sridhar Parasuram1d8c4222014-10-22 13:43:00 -0700213void target_serialno(unsigned char *buf)
214{
215 uint32_t serialno;
216 serialno = board_chip_serial();
217 snprintf((char *)buf, 13, "%x", serialno);
218}
219
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700220unsigned check_reboot_mode(void)
221{
222 unsigned restart_reason = 0;
223
224 /* Read reboot reason and scrub it */
225 restart_reason = readl(RESTART_REASON_ADDR);
226
227 writel(0x00, RESTART_REASON_ADDR);
228
229 return restart_reason;
230}
231
232int get_target_boot_params(const char *cmdline, const char *part, char *buf,
233 int buflen)
234{
235 struct ptable *ptable;
236 int system_ptn_index = -1;
237
anisha agarwalce363dd2014-08-26 15:17:09 -0700238 if (!cmdline || !part || !buf || buflen < 0) {
239 dprintf(CRITICAL, "WARN: Invalid input param\n");
240 return -1;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700241 }
242
anisha agarwalce363dd2014-08-26 15:17:09 -0700243 if (!strstr(cmdline, "root=/dev/ram")) /* This check is to handle kdev boot */
244 {
245 if (!target_is_emmc_boot()) {
246 /* Below is for NAND boot */
247 ptable = flash_get_ptable();
248 if (!ptable) {
249 dprintf(CRITICAL,
250 "WARN: Cannot get flash partition table\n");
251 return -1;
252 }
253
254 system_ptn_index = ptable_get_index(ptable, part);
255 if (system_ptn_index < 0) {
256 dprintf(CRITICAL,
257 "WARN: Cannot get partition index for %s\n", part);
258 return -1;
259 }
260 /* Adding command line parameters according to target boot type */
261 snprintf(buf, buflen, UBI_CMDLINE);
262 snprintf(buf+strlen(buf), buflen, " root=ubi0:rootfs ubi.mtd=%d", system_ptn_index);
263 }
264 else {
265 /* Below is for emmc boot */
anisha agarwalc49a3252014-10-15 17:37:40 -0700266 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 -0700267 if (system_ptn_index < 0) {
268 dprintf(CRITICAL,
269 "WARN: Cannot get partition index for %s\n", part);
270 return -1;
271 }
272 snprintf(buf, buflen, EXT4_CMDLINE"%d", system_ptn_index);
273 }
anisha agarwalce363dd2014-08-26 15:17:09 -0700274 }
Sridhar Parasuramdbe91a42014-12-29 13:45:30 -0800275 return 0;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700276}
277
278const char * target_usb_controller()
279{
280 return "dwc";
281}
282
283static void set_sdc_power_ctrl()
284{
285 /* Drive strength configs for sdc pins */
286 struct tlmm_cfgs sdc1_hdrv_cfg[] =
287 {
Sridhar Parasuramdbe91a42014-12-29 13:45:30 -0800288 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, 0 },
289 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, 0 },
290 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK, 0 },
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700291 };
292
293 /* Pull configs for sdc pins */
294 struct tlmm_cfgs sdc1_pull_cfg[] =
295 {
Sridhar Parasuramdbe91a42014-12-29 13:45:30 -0800296 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, 0 },
297 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0 },
298 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0 },
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700299 };
300
301 /* Set the drive strength & pull control values */
302 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
303 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
304}
305
306static struct mmc_device *dev;
307
308void *target_mmc_device()
309{
310 return (void *) dev;
311}
312
313void target_sdc_init()
314{
315 struct mmc_config_data config;
316
317 /* Set drive strength & pull ctrl values */
318 set_sdc_power_ctrl();
319
320 config.slot = 1;
Channagoud Kadabide17ba82014-11-12 13:05:57 -0800321 config.bus_width = DATA_BUS_WIDTH_8BIT;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700322 config.max_clk_rate = MMC_CLK_200MHZ;
323 config.sdhc_base = MSM_SDC1_SDHCI_BASE;
324 config.pwrctl_base = MSM_SDC1_BASE;
325 config.pwr_irq = SDCC1_PWRCTL_IRQ;
326 config.hs400_support = 0;
Channagoud Kadabide17ba82014-11-12 13:05:57 -0800327 config.hs200_support = 0;
Channagoud Kadabid23379d2014-10-13 11:33:50 -0700328 config.use_io_switch = 1;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700329
330 if (!(dev = mmc_init(&config))) {
331 dprintf(CRITICAL, "mmc init failed!");
332 ASSERT(0);
333 }
334}
335
anisha agarwal0fc661d2014-11-26 11:54:32 -0800336int target_cont_splash_screen()
337{
338 /* FOR OEMs - Set cont_splash_screen to keep the splash enable after LK.*/
anisha agarwal58d25cf2014-11-26 12:09:23 -0800339 return false;
anisha agarwal0fc661d2014-11-26 11:54:32 -0800340}
341
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700342void target_uninit(void)
343{
344 if (platform_boot_dev_isemmc())
345 {
346 mmc_put_card_to_sleep(dev);
347 sdhci_mode_disable(&dev->host);
348 }
349}
350
Joonwoo Park39aed062014-06-09 17:00:07 -0700351void target_usb_phy_reset(void)
352{
Joonwoo Park39aed062014-06-09 17:00:07 -0700353 usb30_qmp_phy_reset();
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700354 qusb2_phy_reset();
Joonwoo Park39aed062014-06-09 17:00:07 -0700355}
356
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700357target_usb_iface_t* target_usb30_init()
358{
359 target_usb_iface_t *t_usb_iface;
360
Sridhar Parasuramdbe91a42014-12-29 13:45:30 -0800361 t_usb_iface = (target_usb_iface_t *) calloc(1, sizeof(target_usb_iface_t));
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700362 ASSERT(t_usb_iface);
363
364 t_usb_iface->mux_config = NULL;
365 t_usb_iface->phy_init = usb30_qmp_phy_init;
Joonwoo Park39aed062014-06-09 17:00:07 -0700366 t_usb_iface->phy_reset = target_usb_phy_reset;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700367 t_usb_iface->clock_init = clock_usb30_init;
368 t_usb_iface->vbus_override = 1;
369
370 return t_usb_iface;
371}
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700372
373uint32_t target_override_pll()
374{
375 return 1;
376}
Channagoud Kadabid23379d2014-10-13 11:33:50 -0700377
378uint32_t target_get_hlos_subtype()
379{
380 return board_hlos_subtype();
381}