blob: 807e3bef8ec5438b7f9f03b10d3cca9f602a7e24 [file] [log] [blame]
Channagoud Kadabie936ded2014-02-11 15:38:27 -08001/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Sundarajan Srinivasan00c64232013-07-03 11:12:22 -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>
37#include <ctype.h>
38#include <string.h>
39#include <pm8x41.h>
40#include <reg.h>
41#include <platform/timer.h>
Channagoud Kadabiffc32602014-02-04 17:06:41 -080042#include <platform/clock.h>
Sundarajan Srinivasane1b4db72013-10-29 12:29:15 -070043#include <hsusb.h>
Channagoud Kadabiffc32602014-02-04 17:06:41 -080044#include <bits.h>
45#include <qmp_phy.h>
Sundarajan Srinivasanb3a99fc2014-05-14 23:24:56 -070046#include <scm.h>
Devendra Patelabd51972014-10-21 17:57:33 -070047#include <rpm-smd.h>
Sundarajan Srinivasan00c64232013-07-03 11:12:22 -070048
49extern void smem_ptable_init(void);
50extern void smem_add_modem_partitions(struct ptable *flash_ptable);
51
52static struct ptable flash_ptable;
53
54/* PMIC config data */
55#define PMIC_ARB_CHANNEL_NUM 0
56#define PMIC_ARB_OWNER_ID 0
57
58/* NANDc BAM pipe numbers */
59#define DATA_CONSUMER_PIPE 0
60#define DATA_PRODUCER_PIPE 1
61#define CMD_PIPE 2
62
63/* NANDc BAM pipe groups */
64#define DATA_PRODUCER_PIPE_GRP 0
65#define DATA_CONSUMER_PIPE_GRP 0
66#define CMD_PIPE_GRP 1
67
68/* NANDc EE */
69#define QPIC_NAND_EE 0
70
71/* NANDc max desc length. */
72#define QPIC_NAND_MAX_DESC_LEN 0x7FFF
73
74#define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF
75
76struct qpic_nand_init_config config;
77
Sundarajan Srinivasane1b4db72013-10-29 12:29:15 -070078extern void ulpi_write(unsigned val, unsigned reg);
79
Sundarajan Srinivasan00c64232013-07-03 11:12:22 -070080void update_ptable_names(void)
81{
82 uint32_t ptn_index;
83 struct ptentry *ptentry_ptr = flash_ptable.parts;
84 struct ptentry *boot_ptn;
85 unsigned i;
86 uint32_t len;
87
88 /* Change all names to lower case. */
89 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
90 {
91 len = strlen(ptentry_ptr[ptn_index].name);
92
93 for (i = 0; i < len; i++)
94 {
95 if (isupper(ptentry_ptr[ptn_index].name[i]))
96 {
97 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
98 }
99 }
100
101 /* SBL fills in the last partition length as 0xFFFFFFFF.
102 * Update the length field based on the number of blocks on the flash.
103 */
104 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
105 {
106 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
107 }
108 }
109}
110
111void target_early_init(void)
112{
113#if WITH_DEBUG_UART
114 uart_dm_init(3, 0, MSM_UART2_BASE);
115#endif
116}
117
118/* init */
119void target_init(void)
120{
121 dprintf(INFO, "target_init()\n");
122
123 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
124
125 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
126 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
127 config.pipes.cmd_pipe = CMD_PIPE;
128
129 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
130 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
131 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
132
133 config.bam_base = MSM_NAND_BAM_BASE;
134 config.nand_base = MSM_NAND_BASE;
135 config.ee = QPIC_NAND_EE;
136 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
137
138 qpic_nand_init(&config);
139
140 ptable_init(&flash_ptable);
141
142 smem_ptable_init();
143
144 smem_add_modem_partitions(&flash_ptable);
145
146 update_ptable_names();
147
148 flash_set_ptable(&flash_ptable);
Devendra Patelabd51972014-10-21 17:57:33 -0700149 rpm_smd_init();
Sundarajan Srinivasan00c64232013-07-03 11:12:22 -0700150}
Zohaib Alam929b7fb2014-10-24 15:58:22 -0400151
152int target_cont_splash_screen()
153{
154 /*
155 * FOR OEMs - Set cont_splash_screen to keep the splash enable after LK.
156 * By default: the cont-splash-screen is ON
157 */
Zohaib Alam7b348692014-10-28 13:35:04 -0400158 return false;
Zohaib Alam929b7fb2014-10-24 15:58:22 -0400159}
160
Devendra Patelabd51972014-10-21 17:57:33 -0700161void target_uninit()
162{
Zohaib Alam929b7fb2014-10-24 15:58:22 -0400163#if DISPLAY_SPLASH_SCREEN
164 /* target_display_shutdown will uninitialize it in case of cont-splash */
165 if(target_cont_splash_screen())
166#endif
167 rpm_smd_uninit();
Devendra Patelabd51972014-10-21 17:57:33 -0700168}
Zohaib Alam929b7fb2014-10-24 15:58:22 -0400169
Sundarajan Srinivasane1b4db72013-10-29 12:29:15 -0700170/* Do target specific usb initialization */
171void target_usb_init(void)
172{
173 uint32_t val;
174
175 /* Select and enable external configuration with USB PHY */
176 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
177
178 /* Enable sess_vld */
179 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
180 writel(val, USB_GENCONFIG_2);
181
182 /* Enable external vbus configuration in the LINK */
183 val = readl(USB_USBCMD);
184 val |= SESS_VLD_CTRL;
185 writel(val, USB_USBCMD);
186}
187
Channagoud Kadabiffc32602014-02-04 17:06:41 -0800188target_usb_iface_t* target_usb30_init()
189{
190 target_usb_iface_t *t_usb_iface;
191
192 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
193 ASSERT(t_usb_iface);
194
195 t_usb_iface->mux_config = target_usb_phy_mux_configure;
196 t_usb_iface->phy_init = usb30_qmp_phy_init;
197 t_usb_iface->phy_reset = usb30_qmp_phy_reset;
198 t_usb_iface->clock_init = clock_usb30_init;
199 t_usb_iface->vbus_override = 1;
200
201 return t_usb_iface;
202}
203
Sundarajan Srinivasanb3a99fc2014-05-14 23:24:56 -0700204
205static int scm_clear_boot_partition_select()
206{
207 int ret = 0;
208
209 ret = scm_call_atomic2(SCM_SVC_BOOT, WDOG_DEBUG_DISABLE, 1, 0);
210 if (ret)
211 dprintf(CRITICAL, "Failed to disable the wdog debug \n");
212
213 return ret;
214}
215
Sundarajan Srinivasan00c64232013-07-03 11:12:22 -0700216/* reboot */
217void reboot_device(unsigned reboot_reason)
218{
Sundarajan Srinivasanb3a99fc2014-05-14 23:24:56 -0700219 uint8_t reset_type = 0;
220
221 /* Clear the boot partition select cookie to indicate
222 * its a normal reset and avoid going to download mode */
223 scm_clear_boot_partition_select();
224
Sundarajan Srinivasan00c64232013-07-03 11:12:22 -0700225 /* Write the reboot reason */
226 writel(reboot_reason, RESTART_REASON_ADDR);
227
228 /* Configure PMIC for warm reset */
229 /* PM 8019 v1 aligns with PM8941 v2.
230 * This call should be based on the pmic version
231 * when PM8019 v2 is available.
232 */
Sundarajan Srinivasanb3a99fc2014-05-14 23:24:56 -0700233 if(reboot_reason)
234 reset_type = PON_PSHOLD_WARM_RESET;
235 else
236 reset_type = PON_PSHOLD_HARD_RESET;
237
238 pm8x41_v2_reset_configure(reset_type);
Sundarajan Srinivasan00c64232013-07-03 11:12:22 -0700239
240 /* Drop PS_HOLD for MSM */
241 writel(0x00, MPM2_MPM_PS_HOLD);
242
243 mdelay(5000);
244
245 dprintf(CRITICAL, "Rebooting failed\n");
246 return;
247}
248
249/* Identify the current target */
250void target_detect(struct board_data *board)
251{
Channagoud Kadabie936ded2014-02-11 15:38:27 -0800252 /* This property is filled as part of board.c */
Sundarajan Srinivasan00c64232013-07-03 11:12:22 -0700253}
254
255unsigned board_machtype(void)
256{
257 return LINUX_MACHTYPE_UNKNOWN;
258}
259
260/* Identify the baseband being used */
261void target_baseband_detect(struct board_data *board)
262{
263 /* Check for baseband variants. Default to MSM */
264 if (board->platform_subtype == HW_PLATFORM_SUBTYPE_UNKNOWN)
265 {
266 board->baseband = BASEBAND_MSM;
267 }
268 else
269 {
270 dprintf(CRITICAL, "Could not identify baseband id (%d)\n",
271 board->platform_subtype);
272 ASSERT(0);
273 }
274}
275
276unsigned check_reboot_mode(void)
277{
278 unsigned restart_reason = 0;
279
280 /* Read reboot reason and scrub it */
281 restart_reason = readl(RESTART_REASON_ADDR);
282
283 writel(0x00, RESTART_REASON_ADDR);
284
285 return restart_reason;
286}
287
vijay kumar1dbdd962015-08-31 16:59:02 +0530288int get_target_boot_params(const char *cmdline, const char *part, char **buf)
Joonwoo Park61112782013-10-02 19:50:39 -0700289{
290 struct ptable *ptable;
291 int system_ptn_index = -1;
vijay kumar1dbdd962015-08-31 16:59:02 +0530292 /*allocate buflen for largest string*/
293 uint32_t buflen = strlen(" root=/dev/mtdblock") + sizeof(int) + 1; /*1 character for null termination*/
Joonwoo Park61112782013-10-02 19:50:39 -0700294
vijay kumar1dbdd962015-08-31 16:59:02 +0530295 if (!cmdline || !part ) {
Joonwoo Park61112782013-10-02 19:50:39 -0700296 dprintf(CRITICAL, "WARN: Invalid input param\n");
297 return -1;
298 }
Joonwoo Park61112782013-10-02 19:50:39 -0700299 ptable = flash_get_ptable();
300 if (!ptable) {
301 dprintf(CRITICAL,
302 "WARN: Cannot get flash partition table\n");
303 return -1;
304 }
305
vijay kumar1dbdd962015-08-31 16:59:02 +0530306 *buf = (char *)malloc(buflen);
307 if(!(*buf)) {
308 dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
309 return -1;
310 }
Joonwoo Park61112782013-10-02 19:50:39 -0700311 system_ptn_index = ptable_get_index(ptable, part);
312 if (system_ptn_index < 0) {
313 dprintf(CRITICAL,
314 "WARN: Cannot get partition index for %s\n", part);
vijay kumar1dbdd962015-08-31 16:59:02 +0530315 free(*buf);
Joonwoo Park61112782013-10-02 19:50:39 -0700316 return -1;
317 }
318
319 /*
Smita Solankid23abdd2014-06-05 13:49:28 -0700320 * check if cmdline contains "root="/"ubi.mtd" at the beginning of buffer or
321 * " root="/"ubi.mtd" in the middle of buffer.
Joonwoo Park61112782013-10-02 19:50:39 -0700322 */
Smita Solankid23abdd2014-06-05 13:49:28 -0700323
324 if (strstr(cmdline, "rootfstype=yaffs2")) {
325 if (((!strncmp(cmdline, "root=", strlen("root="))) ||
326 (strstr(cmdline, " root="))))
327 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
328 else
vijay kumar1dbdd962015-08-31 16:59:02 +0530329 snprintf(*buf, buflen, " root=/dev/mtdblock%d",
Smita Solankid23abdd2014-06-05 13:49:28 -0700330 system_ptn_index);
331 } else if (strstr(cmdline, "rootfstype=ubifs")){
332 if (((!strncmp(cmdline, "ubi.mtd=", strlen("ubi.mtd="))) ||
333 (strstr(cmdline, " ubi.mtd="))))
334 dprintf(DEBUG, "DEBUG: cmdline has ubi.mtd=\n");
335 else
vijay kumar1dbdd962015-08-31 16:59:02 +0530336 snprintf(*buf, buflen, " ubi.mtd=%d",
Smita Solankid23abdd2014-06-05 13:49:28 -0700337 system_ptn_index);
338 }
vijay kumar1dbdd962015-08-31 16:59:02 +0530339 /*in success case buf will be freed in the calling function of this*/
Joonwoo Park61112782013-10-02 19:50:39 -0700340 return 0;
341}
Channagoud Kadabiffc32602014-02-04 17:06:41 -0800342
343/* identify the usb controller to be used for the target */
344const char * target_usb_controller()
345{
346 return "dwc";
347}
348
349/* mux hs phy to route to dwc controller */
350static void phy_mux_configure_with_tcsr()
351{
352 /* As per the hardware team, set the mux for snps controller */
353 RMWREG32(TCSR_PHSS_USB2_PHY_SEL, 0x0, 0x1, 0x1);
354}
355
356/* configure hs phy mux if using dwc controller */
357void target_usb_phy_mux_configure(void)
358{
359 if(!strcmp(target_usb_controller(), "dwc"))
360 {
361 phy_mux_configure_with_tcsr();
362 }
363}
Channagoud Kadabid6ded112014-05-12 18:07:24 -0700364
365uint32_t target_override_pll()
366{
367 return board_soc_version() == BOARD_SOC_VERSION2 ? 1 : 0;
368}