blob: a7309f170b13c8c96a2a43f496aec6e6c188846a [file] [log] [blame]
Joonwoo Parke586c2e2014-04-02 11:04:10 -07001/* Copyright (c) 2014, 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 <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 <hsusb.h>
42#include <mmc.h>
43#include <platform/timer.h>
44#include <platform/irqs.h>
45#include <platform/gpio.h>
46#include <platform/clock.h>
47#include <qmp_phy.h>
Joonwoo Park39aed062014-06-09 17:00:07 -070048#include <qusb2_phy.h>
Joonwoo Parke586c2e2014-04-02 11:04:10 -070049
50extern void smem_ptable_init(void);
51extern void smem_add_modem_partitions(struct ptable *flash_ptable);
52void target_sdc_init();
53
54static struct ptable flash_ptable;
55
56/* PMIC config data */
57#define PMIC_ARB_CHANNEL_NUM 0
58#define PMIC_ARB_OWNER_ID 0
59
60/* NANDc BAM pipe numbers */
61#define DATA_CONSUMER_PIPE 0
62#define DATA_PRODUCER_PIPE 1
63#define CMD_PIPE 2
64
65/* NANDc BAM pipe groups */
66#define DATA_PRODUCER_PIPE_GRP 0
67#define DATA_CONSUMER_PIPE_GRP 0
68#define CMD_PIPE_GRP 1
69
70/* NANDc EE */
71#define QPIC_NAND_EE 0
72
73/* NANDc max desc length. */
74#define QPIC_NAND_MAX_DESC_LEN 0x7FFF
75
76#define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF
77
anisha agarwalce363dd2014-08-26 15:17:09 -070078#define EXT4_CMDLINE " rootfstype=ext4 root=/dev/mmcblk0p"
79#define UBI_CMDLINE " rootfstype=ubifs rootflags=bulk_read ubi.fm_autoconvert=1"
80
Joonwoo Parke586c2e2014-04-02 11:04:10 -070081struct qpic_nand_init_config config;
82
83void update_ptable_names(void)
84{
85 uint32_t ptn_index;
86 struct ptentry *ptentry_ptr = flash_ptable.parts;
87 struct ptentry *boot_ptn;
88 unsigned i;
89 uint32_t len;
90
91 /* Change all names to lower case. */
92 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
93 {
94 len = strlen(ptentry_ptr[ptn_index].name);
95
96 for (i = 0; i < len; i++)
97 {
98 if (isupper(ptentry_ptr[ptn_index].name[i]))
99 {
100 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
101 }
102 }
103
104 /* SBL fills in the last partition length as 0xFFFFFFFF.
105 * Update the length field based on the number of blocks on the flash.
106 */
107 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
108 {
109 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
110 }
111 }
112}
113
114void target_early_init(void)
115{
116#if WITH_DEBUG_UART
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700117 uart_dm_init(3, 0, BLSP1_UART2_BASE);
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700118#endif
119}
120
121int target_is_emmc_boot(void)
122{
123 return platform_boot_dev_isemmc();
124}
125
126/* init */
127void target_init(void)
128{
129 dprintf(INFO, "target_init()\n");
130
131 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
132
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700133 if (platform_boot_dev_isemmc()) {
134 target_sdc_init();
135 if (partition_read_table()) {
136 dprintf(CRITICAL, "Error reading the partition table info\n");
137 ASSERT(0);
138 }
139 } else {
140 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
141 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
142 config.pipes.cmd_pipe = CMD_PIPE;
143
144 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
145 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
146 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
147
148 config.bam_base = MSM_NAND_BAM_BASE;
149 config.nand_base = MSM_NAND_BASE;
150 config.ee = QPIC_NAND_EE;
151 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
152
153 qpic_nand_init(&config);
154
155 ptable_init(&flash_ptable);
156 smem_ptable_init();
157 smem_add_modem_partitions(&flash_ptable);
158
159 update_ptable_names();
160 flash_set_ptable(&flash_ptable);
161 }
162}
163
164/* reboot */
165void reboot_device(unsigned reboot_reason)
166{
167 /* Write the reboot reason */
168 writel(reboot_reason, RESTART_REASON_ADDR);
169
170 /* Configure PMIC for warm reset */
171 /* PM 8019 v1 aligns with PM8941 v2.
172 * This call should be based on the pmic version
173 * when PM8019 v2 is available.
174 */
175 pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET);
176
177 /* Drop PS_HOLD for MSM */
178 writel(0x00, MPM2_MPM_PS_HOLD);
179
180 mdelay(5000);
181
182 dprintf(CRITICAL, "Rebooting failed\n");
183 return;
184}
185
186/* Identify the current target */
187void target_detect(struct board_data *board)
188{
189 /* This property is filled as part of board.c */
190}
191
192unsigned board_machtype(void)
193{
194 return LINUX_MACHTYPE_UNKNOWN;
195}
196
197/* Identify the baseband being used */
198void target_baseband_detect(struct board_data *board)
199{
200 board->baseband = BASEBAND_MSM;
201}
202
203unsigned check_reboot_mode(void)
204{
205 unsigned restart_reason = 0;
206
207 /* Read reboot reason and scrub it */
208 restart_reason = readl(RESTART_REASON_ADDR);
209
210 writel(0x00, RESTART_REASON_ADDR);
211
212 return restart_reason;
213}
214
215int get_target_boot_params(const char *cmdline, const char *part, char *buf,
216 int buflen)
217{
218 struct ptable *ptable;
219 int system_ptn_index = -1;
220
anisha agarwalce363dd2014-08-26 15:17:09 -0700221 if (!cmdline || !part || !buf || buflen < 0) {
222 dprintf(CRITICAL, "WARN: Invalid input param\n");
223 return -1;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700224 }
225
anisha agarwalce363dd2014-08-26 15:17:09 -0700226 if (!strstr(cmdline, "root=/dev/ram")) /* This check is to handle kdev boot */
227 {
228 if (!target_is_emmc_boot()) {
229 /* Below is for NAND boot */
230 ptable = flash_get_ptable();
231 if (!ptable) {
232 dprintf(CRITICAL,
233 "WARN: Cannot get flash partition table\n");
234 return -1;
235 }
236
237 system_ptn_index = ptable_get_index(ptable, part);
238 if (system_ptn_index < 0) {
239 dprintf(CRITICAL,
240 "WARN: Cannot get partition index for %s\n", part);
241 return -1;
242 }
243 /* Adding command line parameters according to target boot type */
244 snprintf(buf, buflen, UBI_CMDLINE);
245 snprintf(buf+strlen(buf), buflen, " root=ubi0:rootfs ubi.mtd=%d", system_ptn_index);
246 }
247 else {
248 /* Below is for emmc boot */
anisha agarwalc49a3252014-10-15 17:37:40 -0700249 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 -0700250 if (system_ptn_index < 0) {
251 dprintf(CRITICAL,
252 "WARN: Cannot get partition index for %s\n", part);
253 return -1;
254 }
255 snprintf(buf, buflen, EXT4_CMDLINE"%d", system_ptn_index);
256 }
257
258 return 0;
259 }
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700260}
261
262const char * target_usb_controller()
263{
264 return "dwc";
265}
266
267static void set_sdc_power_ctrl()
268{
269 /* Drive strength configs for sdc pins */
270 struct tlmm_cfgs sdc1_hdrv_cfg[] =
271 {
272 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
273 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
274 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK },
275 };
276
277 /* Pull configs for sdc pins */
278 struct tlmm_cfgs sdc1_pull_cfg[] =
279 {
280 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK },
281 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
282 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK },
283 };
284
285 /* Set the drive strength & pull control values */
286 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
287 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
288}
289
290static struct mmc_device *dev;
291
292void *target_mmc_device()
293{
294 return (void *) dev;
295}
296
297void target_sdc_init()
298{
299 struct mmc_config_data config;
300
301 /* Set drive strength & pull ctrl values */
302 set_sdc_power_ctrl();
303
304 config.slot = 1;
Channagoud Kadabide17ba82014-11-12 13:05:57 -0800305 config.bus_width = DATA_BUS_WIDTH_8BIT;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700306 config.max_clk_rate = MMC_CLK_200MHZ;
307 config.sdhc_base = MSM_SDC1_SDHCI_BASE;
308 config.pwrctl_base = MSM_SDC1_BASE;
309 config.pwr_irq = SDCC1_PWRCTL_IRQ;
310 config.hs400_support = 0;
Channagoud Kadabide17ba82014-11-12 13:05:57 -0800311 config.hs200_support = 0;
Channagoud Kadabid23379d2014-10-13 11:33:50 -0700312 config.use_io_switch = 1;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700313
314 if (!(dev = mmc_init(&config))) {
315 dprintf(CRITICAL, "mmc init failed!");
316 ASSERT(0);
317 }
318}
319
320void target_uninit(void)
321{
322 if (platform_boot_dev_isemmc())
323 {
324 mmc_put_card_to_sleep(dev);
325 sdhci_mode_disable(&dev->host);
326 }
327}
328
Joonwoo Park39aed062014-06-09 17:00:07 -0700329void target_usb_phy_reset(void)
330{
Joonwoo Park39aed062014-06-09 17:00:07 -0700331 usb30_qmp_phy_reset();
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700332 qusb2_phy_reset();
Joonwoo Park39aed062014-06-09 17:00:07 -0700333}
334
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700335target_usb_iface_t* target_usb30_init()
336{
337 target_usb_iface_t *t_usb_iface;
338
339 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
340 ASSERT(t_usb_iface);
341
342 t_usb_iface->mux_config = NULL;
343 t_usb_iface->phy_init = usb30_qmp_phy_init;
Joonwoo Park39aed062014-06-09 17:00:07 -0700344 t_usb_iface->phy_reset = target_usb_phy_reset;
Joonwoo Parke586c2e2014-04-02 11:04:10 -0700345 t_usb_iface->clock_init = clock_usb30_init;
346 t_usb_iface->vbus_override = 1;
347
348 return t_usb_iface;
349}
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700350
351uint32_t target_override_pll()
352{
353 return 1;
354}
Channagoud Kadabid23379d2014-10-13 11:33:50 -0700355
356uint32_t target_get_hlos_subtype()
357{
358 return board_hlos_subtype();
359}