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