blob: 8de21edfe3a7430df931b6be72f7340a6a12ba34 [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 Srinivasan00c64232013-07-03 11:12:22 -070046
47extern void smem_ptable_init(void);
48extern void smem_add_modem_partitions(struct ptable *flash_ptable);
49
50static struct ptable flash_ptable;
51
52/* PMIC config data */
53#define PMIC_ARB_CHANNEL_NUM 0
54#define PMIC_ARB_OWNER_ID 0
55
56/* NANDc BAM pipe numbers */
57#define DATA_CONSUMER_PIPE 0
58#define DATA_PRODUCER_PIPE 1
59#define CMD_PIPE 2
60
61/* NANDc BAM pipe groups */
62#define DATA_PRODUCER_PIPE_GRP 0
63#define DATA_CONSUMER_PIPE_GRP 0
64#define CMD_PIPE_GRP 1
65
66/* NANDc EE */
67#define QPIC_NAND_EE 0
68
69/* NANDc max desc length. */
70#define QPIC_NAND_MAX_DESC_LEN 0x7FFF
71
72#define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF
73
74struct qpic_nand_init_config config;
75
Sundarajan Srinivasane1b4db72013-10-29 12:29:15 -070076extern void ulpi_write(unsigned val, unsigned reg);
77
Sundarajan Srinivasan00c64232013-07-03 11:12:22 -070078void update_ptable_names(void)
79{
80 uint32_t ptn_index;
81 struct ptentry *ptentry_ptr = flash_ptable.parts;
82 struct ptentry *boot_ptn;
83 unsigned i;
84 uint32_t len;
85
86 /* Change all names to lower case. */
87 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
88 {
89 len = strlen(ptentry_ptr[ptn_index].name);
90
91 for (i = 0; i < len; i++)
92 {
93 if (isupper(ptentry_ptr[ptn_index].name[i]))
94 {
95 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
96 }
97 }
98
99 /* SBL fills in the last partition length as 0xFFFFFFFF.
100 * Update the length field based on the number of blocks on the flash.
101 */
102 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
103 {
104 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
105 }
106 }
107}
108
109void target_early_init(void)
110{
111#if WITH_DEBUG_UART
112 uart_dm_init(3, 0, MSM_UART2_BASE);
113#endif
114}
115
116/* init */
117void target_init(void)
118{
119 dprintf(INFO, "target_init()\n");
120
121 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
122
123 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
124 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
125 config.pipes.cmd_pipe = CMD_PIPE;
126
127 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
128 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
129 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
130
131 config.bam_base = MSM_NAND_BAM_BASE;
132 config.nand_base = MSM_NAND_BASE;
133 config.ee = QPIC_NAND_EE;
134 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
135
136 qpic_nand_init(&config);
137
138 ptable_init(&flash_ptable);
139
140 smem_ptable_init();
141
142 smem_add_modem_partitions(&flash_ptable);
143
144 update_ptable_names();
145
146 flash_set_ptable(&flash_ptable);
147}
148
Sundarajan Srinivasane1b4db72013-10-29 12:29:15 -0700149/* Do target specific usb initialization */
150void target_usb_init(void)
151{
152 uint32_t val;
153
154 /* Select and enable external configuration with USB PHY */
155 ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
156
157 /* Enable sess_vld */
158 val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
159 writel(val, USB_GENCONFIG_2);
160
161 /* Enable external vbus configuration in the LINK */
162 val = readl(USB_USBCMD);
163 val |= SESS_VLD_CTRL;
164 writel(val, USB_USBCMD);
165}
166
Channagoud Kadabiffc32602014-02-04 17:06:41 -0800167target_usb_iface_t* target_usb30_init()
168{
169 target_usb_iface_t *t_usb_iface;
170
171 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
172 ASSERT(t_usb_iface);
173
174 t_usb_iface->mux_config = target_usb_phy_mux_configure;
175 t_usb_iface->phy_init = usb30_qmp_phy_init;
176 t_usb_iface->phy_reset = usb30_qmp_phy_reset;
177 t_usb_iface->clock_init = clock_usb30_init;
178 t_usb_iface->vbus_override = 1;
179
180 return t_usb_iface;
181}
182
Sundarajan Srinivasan00c64232013-07-03 11:12:22 -0700183/* reboot */
184void reboot_device(unsigned reboot_reason)
185{
186 /* Write the reboot reason */
187 writel(reboot_reason, RESTART_REASON_ADDR);
188
189 /* Configure PMIC for warm reset */
190 /* PM 8019 v1 aligns with PM8941 v2.
191 * This call should be based on the pmic version
192 * when PM8019 v2 is available.
193 */
194 pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET);
195
196 /* Drop PS_HOLD for MSM */
197 writel(0x00, MPM2_MPM_PS_HOLD);
198
199 mdelay(5000);
200
201 dprintf(CRITICAL, "Rebooting failed\n");
202 return;
203}
204
205/* Identify the current target */
206void target_detect(struct board_data *board)
207{
Channagoud Kadabie936ded2014-02-11 15:38:27 -0800208 /* This property is filled as part of board.c */
Sundarajan Srinivasan00c64232013-07-03 11:12:22 -0700209}
210
211unsigned board_machtype(void)
212{
213 return LINUX_MACHTYPE_UNKNOWN;
214}
215
216/* Identify the baseband being used */
217void target_baseband_detect(struct board_data *board)
218{
219 /* Check for baseband variants. Default to MSM */
220 if (board->platform_subtype == HW_PLATFORM_SUBTYPE_UNKNOWN)
221 {
222 board->baseband = BASEBAND_MSM;
223 }
224 else
225 {
226 dprintf(CRITICAL, "Could not identify baseband id (%d)\n",
227 board->platform_subtype);
228 ASSERT(0);
229 }
230}
231
232unsigned check_reboot_mode(void)
233{
234 unsigned restart_reason = 0;
235
236 /* Read reboot reason and scrub it */
237 restart_reason = readl(RESTART_REASON_ADDR);
238
239 writel(0x00, RESTART_REASON_ADDR);
240
241 return restart_reason;
242}
243
Joonwoo Park61112782013-10-02 19:50:39 -0700244int get_target_boot_params(const char *cmdline, const char *part, char *buf,
245 int buflen)
246{
247 struct ptable *ptable;
248 int system_ptn_index = -1;
249
250 if (!cmdline || !part || !buf || buflen < 0) {
251 dprintf(CRITICAL, "WARN: Invalid input param\n");
252 return -1;
253 }
254
255 ptable = flash_get_ptable();
256 if (!ptable) {
257 dprintf(CRITICAL,
258 "WARN: Cannot get flash partition table\n");
259 return -1;
260 }
261
262 system_ptn_index = ptable_get_index(ptable, part);
263 if (system_ptn_index < 0) {
264 dprintf(CRITICAL,
265 "WARN: Cannot get partition index for %s\n", part);
266 return -1;
267 }
268
269 /*
270 * check if cmdline contains "root=" at the beginning of buffer or
271 * " root=" in the middle of buffer.
272 */
273 if (((!strncmp(cmdline, "root=", strlen("root="))) ||
274 (strstr(cmdline, " root="))))
275 dprintf(DEBUG, "DEBUG: cmdline has root=\n");
276 else
277 snprintf(buf, buflen, " root=/dev/mtdblock%d",
278 system_ptn_index);
279
280 return 0;
281}
Channagoud Kadabiffc32602014-02-04 17:06:41 -0800282
283/* identify the usb controller to be used for the target */
284const char * target_usb_controller()
285{
286 return "dwc";
287}
288
289/* mux hs phy to route to dwc controller */
290static void phy_mux_configure_with_tcsr()
291{
292 /* As per the hardware team, set the mux for snps controller */
293 RMWREG32(TCSR_PHSS_USB2_PHY_SEL, 0x0, 0x1, 0x1);
294}
295
296/* configure hs phy mux if using dwc controller */
297void target_usb_phy_mux_configure(void)
298{
299 if(!strcmp(target_usb_controller(), "dwc"))
300 {
301 phy_mux_configure_with_tcsr();
302 }
303}
Channagoud Kadabid6ded112014-05-12 18:07:24 -0700304
305uint32_t target_override_pll()
306{
307 return board_soc_version() == BOARD_SOC_VERSION2 ? 1 : 0;
308}