blob: 3bfb3c0127a38c18b9212d881f2fbb6dcd7c49de [file] [log] [blame]
vijay kumarca1672a2015-04-09 16:45:40 +05301/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2 *
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 <platform/iomap.h>
31#include <reg.h>
32#include <target.h>
33#include <platform.h>
34#include <uart_dm.h>
35#include <platform/gpio.h>
36#include <lib/ptable.h>
37#include <qpic_nand.h>
38#include <dev/keys.h>
39#include <spmi_v2.h>
40#include <pm8x41.h>
41#include <board.h>
42#include <baseband.h>
43#include <hsusb.h>
44#include <scm.h>
45#include <platform/gpio.h>
46#include <platform/gpio.h>
47#include <platform/irqs.h>
48#include <platform/clock.h>
49#include <crypto5_wrapper.h>
50#include <partition_parser.h>
51#include <stdlib.h>
52
53#if LONG_PRESS_POWER_ON
54#include <shutdown_detect.h>
55#endif
56
57#define FASTBOOT_MODE 0x77665500
58#define PON_SOFT_RB_SPARE 0x88F
59
60extern void smem_ptable_init(void);
61extern void smem_add_modem_partitions(struct ptable *flash_ptable);
62
63static struct ptable flash_ptable;
64
65/* PMIC config data */
66#define PMIC_ARB_CHANNEL_NUM 0
67#define PMIC_ARB_OWNER_ID 0
68
69/* NANDc BAM pipe numbers */
70#define DATA_CONSUMER_PIPE 0
71#define DATA_PRODUCER_PIPE 1
72#define CMD_PIPE 2
73
74/* NANDc BAM pipe groups */
75#define DATA_PRODUCER_PIPE_GRP 0
76#define DATA_CONSUMER_PIPE_GRP 0
77#define CMD_PIPE_GRP 1
78
79/* NANDc EE */
80#define QPIC_NAND_EE 0
81
82/* NANDc max desc length. */
83#define QPIC_NAND_MAX_DESC_LEN 0x7FFF
84
85#define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF
vijay kumarfc07e142015-08-31 16:46:41 +053086#define UBI_CMDLINE " rootfstype=ubifs rootflags=bulk_read"
vijay kumarca1672a2015-04-09 16:45:40 +053087
88struct qpic_nand_init_config config;
89
90void update_ptable_names(void)
91{
92 uint32_t ptn_index;
93 struct ptentry *ptentry_ptr = flash_ptable.parts;
94 struct ptentry *boot_ptn;
95 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 for (i = 0; i < len; i++)
103 {
104 if (isupper(ptentry_ptr[ptn_index].name[i]))
105 {
106 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
107 }
108 }
109 /* SBL fills in the last partition length as 0xFFFFFFFF.
110 * Update the length field based on the number of blocks on the flash.*/
111 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
112 {
113 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
114 }
115 }
116}
117
118void target_early_init(void)
119{
120#if WITH_DEBUG_UART
vijay kumar20627da2015-10-01 13:28:58 +0530121 /*BLSP1 and UART5*/
122 uart_dm_init(5, 0, BLSP1_UART5_BASE);
vijay kumarca1672a2015-04-09 16:45:40 +0530123#endif
124}
125
126/* Configure PMIC and Drop PS_HOLD for shutdown */
127void shutdown_device()
128{
129 dprintf(CRITICAL, "Going down for shutdown.\n");
130
131 /* Configure PMIC for shutdown */
132 pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
133
134 /* Drop PS_HOLD for MSM */
135 writel(0x00, MPM2_MPM_PS_HOLD);
136
137 mdelay(5000);
138
139 dprintf(CRITICAL, "shutdown failed\n");
140
141 ASSERT(0);
142}
143
144
145void target_init(void)
146{
147 uint32_t base_addr;
148 uint8_t slot;
149
150 dprintf(INFO, "target_init()\n");
151
152 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
153
154 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
155 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
156 config.pipes.cmd_pipe = CMD_PIPE;
157
158 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
159 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
160 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
161
162 config.bam_base = MSM_NAND_BAM_BASE;
163 config.nand_base = MSM_NAND_BASE;
164 config.ee = QPIC_NAND_EE;
165 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
166
167 qpic_nand_init(&config);
168
169 ptable_init(&flash_ptable);
vijay kumarec490942015-07-23 12:43:54 +0530170 smem_ptable_init();
171 smem_add_modem_partitions(&flash_ptable);
vijay kumarca1672a2015-04-09 16:45:40 +0530172
173 update_ptable_names();
174 flash_set_ptable(&flash_ptable);
175}
176
177/* Identify the current target */
178void target_detect(struct board_data *board)
179{
180 /* This property is filled as part of board.c */
181}
182
183unsigned board_machtype(void)
184{
185}
186
187/* Identify the baseband being used */
188void target_baseband_detect(struct board_data *board)
189{
190 uint32_t platform = board->platform;
191
192 switch(platform)
193 {
vijay kumar20627da2015-10-01 13:28:58 +0530194 case MDMFERMIUM1:
195 case MDMFERMIUM2:
196 case MDMFERMIUM3:
197 case MDMFERMIUM4:
198 case MDMFERMIUM5:
vijay kumarca1672a2015-04-09 16:45:40 +0530199 board->baseband = BASEBAND_MDM;
200 break;
201 default:
202 dprintf(CRITICAL, "Platform type: %u is not supported\n", platform);
203 ASSERT(0);
204 };
205}
206
vijay kumar00c1e792015-09-28 14:48:48 +0530207void target_serialno(unsigned char *buf)
208{
209 uint32_t serialno;
210 serialno = board_chip_serial();
211 snprintf((char *)buf, sizeof(uint32_t)+1, "%x", serialno);
212}
213
vijay kumarca1672a2015-04-09 16:45:40 +0530214unsigned check_reboot_mode(void)
215{
216 uint32_t restart_reason = 0;
217
218 /* Read reboot reason and scrub it */
219 restart_reason = readl(RESTART_REASON_ADDR);
220 writel(0x00, RESTART_REASON_ADDR);
221
222 return restart_reason;
223}
224
vijay kumarfc07e142015-08-31 16:46:41 +0530225int get_target_boot_params(const char *cmdline, const char *part, char **buf)
vijay kumarca1672a2015-04-09 16:45:40 +0530226{
227 struct ptable *ptable;
228 int system_ptn_index = -1;
vijay kumarfc07e142015-08-31 16:46:41 +0530229 uint32_t buflen = strlen(UBI_CMDLINE) + strlen(" root=ubi0:rootfs ubi.mtd=") + sizeof(int) + 1; /* 1 byte for null character*/
230
231 *buf = (char *)malloc(buflen);
232 if(!(*buf)) {
233 dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
234 return -1;
235 }
vijay kumarca1672a2015-04-09 16:45:40 +0530236
237 ptable = flash_get_ptable();
238 if (!ptable) {
239 dprintf(CRITICAL,"WARN: Cannot get flash partition table\n");
vijay kumarfc07e142015-08-31 16:46:41 +0530240 free(*buf);
vijay kumarca1672a2015-04-09 16:45:40 +0530241 return -1;
242 }
243
244 system_ptn_index = ptable_get_index(ptable, part);
245 if (system_ptn_index < 0) {
246 dprintf(CRITICAL,"WARN: Cannot get partition index for %s\n", part);
vijay kumarfc07e142015-08-31 16:46:41 +0530247 free(*buf);
vijay kumarca1672a2015-04-09 16:45:40 +0530248 return -1;
249 }
vijay kumarfc07e142015-08-31 16:46:41 +0530250 /* Adding command line parameters according to target boot type */
251 snprintf(*buf, buflen, UBI_CMDLINE);
252
vijay kumarca1672a2015-04-09 16:45:40 +0530253 /*check if cmdline contains "root=" at the beginning of buffer or
254 * " root=" in the middle of buffer.
255 */
256 if (((!strncmp(cmdline, "root=", strlen("root="))) ||
257 (strstr(cmdline, " root="))))
258 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
259 else
vijay kumarfc07e142015-08-31 16:46:41 +0530260 snprintf(*buf+strlen(*buf), buflen, " root=ubi0:rootfs ubi.mtd=%d", system_ptn_index);
261 /*in success case buf will be freed in the calling function of this*/
vijay kumarca1672a2015-04-09 16:45:40 +0530262 return 0;
263}
264
265void target_usb_init(void)
266{
267 uint32_t val;
268
269 /* Select and enable external configuration with USB PHY */
vijay kumarec490942015-07-23 12:43:54 +0530270 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
vijay kumarca1672a2015-04-09 16:45:40 +0530271
272 /* Enable sess_vld */
273 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
274 writel(val, USB_GENCONFIG_2);
275
276 /* Enable external vbus configuration in the LINK */
277 val = readl(USB_USBCMD);
278 val |= SESS_VLD_CTRL;
279 writel(val, USB_USBCMD);
280}
281
282void target_uninit(void)
283{
284}
285
286void reboot_device(unsigned reboot_reason)
287{
288 /* Write the reboot reason */
289 writel(reboot_reason, RESTART_REASON_ADDR);
290
291 /* Configure PMIC for warm reset */
292 /* PM 8019 v1 aligns with PM8941 v2.
293 * This call should be based on the pmic version
294 * when PM8019 v2 is available.
295 */
296 pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET);
297
298 /* Drop PS_HOLD for MSM */
299 writel(0x00, MPM2_MPM_PS_HOLD);
300
301 mdelay(5000);
302
303 dprintf(CRITICAL, "Rebooting failed\n");
304 return;
305}