Smita Ghosh | 50a53ac | 2015-02-11 12:33:30 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 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> |
Sridhar Parasuram | dbe91a4 | 2014-12-29 13:45:30 -0800 | [diff] [blame] | 37 | #include <malloc.h> |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 38 | #include <ctype.h> |
| 39 | #include <string.h> |
| 40 | #include <pm8x41.h> |
| 41 | #include <reg.h> |
| 42 | #include <hsusb.h> |
| 43 | #include <mmc.h> |
| 44 | #include <platform/timer.h> |
| 45 | #include <platform/irqs.h> |
| 46 | #include <platform/gpio.h> |
| 47 | #include <platform/clock.h> |
| 48 | #include <qmp_phy.h> |
Joonwoo Park | 39aed06 | 2014-06-09 17:00:07 -0700 | [diff] [blame] | 49 | #include <qusb2_phy.h> |
anisha agarwal | ffb78ab | 2014-11-18 15:20:31 -0800 | [diff] [blame] | 50 | #include <rpm-smd.h> |
| 51 | #include <scm.h> |
Sridhar Parasuram | dbe91a4 | 2014-12-29 13:45:30 -0800 | [diff] [blame] | 52 | #include <spmi.h> |
| 53 | #include <partition_parser.h> |
| 54 | #include <sdhci_msm.h> |
| 55 | #include <uart_dm.h> |
| 56 | #include <boot_device.h> |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 57 | |
| 58 | extern void smem_ptable_init(void); |
| 59 | extern void smem_add_modem_partitions(struct ptable *flash_ptable); |
| 60 | void target_sdc_init(); |
| 61 | |
| 62 | static struct ptable flash_ptable; |
| 63 | |
| 64 | /* PMIC config data */ |
| 65 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 66 | #define PMIC_ARB_OWNER_ID 0 |
| 67 | |
| 68 | /* NANDc BAM pipe numbers */ |
| 69 | #define DATA_CONSUMER_PIPE 0 |
| 70 | #define DATA_PRODUCER_PIPE 1 |
| 71 | #define CMD_PIPE 2 |
| 72 | |
| 73 | /* NANDc BAM pipe groups */ |
| 74 | #define DATA_PRODUCER_PIPE_GRP 0 |
| 75 | #define DATA_CONSUMER_PIPE_GRP 0 |
| 76 | #define CMD_PIPE_GRP 1 |
| 77 | |
| 78 | /* NANDc EE */ |
| 79 | #define QPIC_NAND_EE 0 |
| 80 | |
| 81 | /* NANDc max desc length. */ |
| 82 | #define QPIC_NAND_MAX_DESC_LEN 0x7FFF |
| 83 | |
| 84 | #define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF |
| 85 | |
Smita Ghosh | 50a53ac | 2015-02-11 12:33:30 -0800 | [diff] [blame] | 86 | #define EXT4_CMDLINE " rootwait rootfstype=ext4 root=/dev/mmcblk0p" |
anisha agarwal | ce363dd | 2014-08-26 15:17:09 -0700 | [diff] [blame] | 87 | #define UBI_CMDLINE " rootfstype=ubifs rootflags=bulk_read ubi.fm_autoconvert=1" |
| 88 | |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 89 | struct qpic_nand_init_config config; |
| 90 | |
| 91 | void update_ptable_names(void) |
| 92 | { |
| 93 | uint32_t ptn_index; |
| 94 | struct ptentry *ptentry_ptr = flash_ptable.parts; |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 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 | |
| 103 | for (i = 0; i < len; i++) |
| 104 | { |
| 105 | if (isupper(ptentry_ptr[ptn_index].name[i])) |
| 106 | { |
| 107 | ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /* SBL fills in the last partition length as 0xFFFFFFFF. |
| 112 | * Update the length field based on the number of blocks on the flash. |
| 113 | */ |
| 114 | if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN) |
| 115 | { |
| 116 | ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start; |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | void target_early_init(void) |
| 122 | { |
| 123 | #if WITH_DEBUG_UART |
Channagoud Kadabi | 1b69e48 | 2014-09-23 15:20:22 -0700 | [diff] [blame] | 124 | uart_dm_init(3, 0, BLSP1_UART2_BASE); |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 125 | #endif |
| 126 | } |
| 127 | |
| 128 | int target_is_emmc_boot(void) |
| 129 | { |
| 130 | return platform_boot_dev_isemmc(); |
| 131 | } |
| 132 | |
| 133 | /* init */ |
| 134 | void target_init(void) |
| 135 | { |
| 136 | dprintf(INFO, "target_init()\n"); |
| 137 | |
| 138 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 139 | |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 140 | if (platform_boot_dev_isemmc()) { |
| 141 | target_sdc_init(); |
| 142 | if (partition_read_table()) { |
| 143 | dprintf(CRITICAL, "Error reading the partition table info\n"); |
| 144 | ASSERT(0); |
| 145 | } |
anisha agarwal | 70b8cd1 | 2015-02-02 11:44:46 -0800 | [diff] [blame] | 146 | /* Below setting is to enable EBI2 function selection in TLMM so |
| 147 | that GPIOs can be used for display */ |
| 148 | writel((readl(TLMM_EBI2_EMMC_GPIO_CFG) | EBI2_BOOT_SELECT), TLMM_EBI2_EMMC_GPIO_CFG); |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 149 | } else { |
| 150 | config.pipes.read_pipe = DATA_PRODUCER_PIPE; |
| 151 | config.pipes.write_pipe = DATA_CONSUMER_PIPE; |
| 152 | config.pipes.cmd_pipe = CMD_PIPE; |
| 153 | |
| 154 | config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP; |
| 155 | config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP; |
| 156 | config.pipes.cmd_pipe_grp = CMD_PIPE_GRP; |
| 157 | |
| 158 | config.bam_base = MSM_NAND_BAM_BASE; |
| 159 | config.nand_base = MSM_NAND_BASE; |
| 160 | config.ee = QPIC_NAND_EE; |
| 161 | config.max_desc_len = QPIC_NAND_MAX_DESC_LEN; |
| 162 | |
| 163 | qpic_nand_init(&config); |
| 164 | |
| 165 | ptable_init(&flash_ptable); |
| 166 | smem_ptable_init(); |
| 167 | smem_add_modem_partitions(&flash_ptable); |
| 168 | |
| 169 | update_ptable_names(); |
| 170 | flash_set_ptable(&flash_ptable); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /* reboot */ |
| 175 | void reboot_device(unsigned reboot_reason) |
| 176 | { |
| 177 | /* Write the reboot reason */ |
| 178 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 179 | |
| 180 | /* Configure PMIC for warm reset */ |
| 181 | /* PM 8019 v1 aligns with PM8941 v2. |
| 182 | * This call should be based on the pmic version |
| 183 | * when PM8019 v2 is available. |
| 184 | */ |
Channagoud Kadabi | a85ed6e | 2015-03-23 14:35:16 -0700 | [diff] [blame^] | 185 | if (reboot_reason) |
| 186 | pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET); |
| 187 | else |
| 188 | pm8x41_v2_reset_configure(PON_PSHOLD_HARD_RESET); |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 189 | |
| 190 | /* Drop PS_HOLD for MSM */ |
| 191 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 192 | |
| 193 | mdelay(5000); |
| 194 | |
| 195 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 196 | return; |
| 197 | } |
| 198 | |
| 199 | /* Identify the current target */ |
| 200 | void target_detect(struct board_data *board) |
| 201 | { |
| 202 | /* This property is filled as part of board.c */ |
| 203 | } |
| 204 | |
| 205 | unsigned board_machtype(void) |
| 206 | { |
| 207 | return LINUX_MACHTYPE_UNKNOWN; |
| 208 | } |
| 209 | |
| 210 | /* Identify the baseband being used */ |
| 211 | void target_baseband_detect(struct board_data *board) |
| 212 | { |
| 213 | board->baseband = BASEBAND_MSM; |
| 214 | } |
| 215 | |
Sridhar Parasuram | 1d8c422 | 2014-10-22 13:43:00 -0700 | [diff] [blame] | 216 | void target_serialno(unsigned char *buf) |
| 217 | { |
| 218 | uint32_t serialno; |
| 219 | serialno = board_chip_serial(); |
| 220 | snprintf((char *)buf, 13, "%x", serialno); |
| 221 | } |
| 222 | |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 223 | unsigned check_reboot_mode(void) |
| 224 | { |
| 225 | unsigned restart_reason = 0; |
| 226 | |
| 227 | /* Read reboot reason and scrub it */ |
| 228 | restart_reason = readl(RESTART_REASON_ADDR); |
| 229 | |
| 230 | writel(0x00, RESTART_REASON_ADDR); |
| 231 | |
| 232 | return restart_reason; |
| 233 | } |
| 234 | |
| 235 | int get_target_boot_params(const char *cmdline, const char *part, char *buf, |
| 236 | int buflen) |
| 237 | { |
| 238 | struct ptable *ptable; |
| 239 | int system_ptn_index = -1; |
| 240 | |
anisha agarwal | ce363dd | 2014-08-26 15:17:09 -0700 | [diff] [blame] | 241 | if (!cmdline || !part || !buf || buflen < 0) { |
| 242 | dprintf(CRITICAL, "WARN: Invalid input param\n"); |
| 243 | return -1; |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 244 | } |
| 245 | |
anisha agarwal | ce363dd | 2014-08-26 15:17:09 -0700 | [diff] [blame] | 246 | if (!strstr(cmdline, "root=/dev/ram")) /* This check is to handle kdev boot */ |
| 247 | { |
| 248 | if (!target_is_emmc_boot()) { |
| 249 | /* Below is for NAND boot */ |
| 250 | ptable = flash_get_ptable(); |
| 251 | if (!ptable) { |
| 252 | dprintf(CRITICAL, |
| 253 | "WARN: Cannot get flash partition table\n"); |
| 254 | return -1; |
| 255 | } |
| 256 | |
| 257 | system_ptn_index = ptable_get_index(ptable, part); |
| 258 | if (system_ptn_index < 0) { |
| 259 | dprintf(CRITICAL, |
| 260 | "WARN: Cannot get partition index for %s\n", part); |
| 261 | return -1; |
| 262 | } |
| 263 | /* Adding command line parameters according to target boot type */ |
| 264 | snprintf(buf, buflen, UBI_CMDLINE); |
| 265 | snprintf(buf+strlen(buf), buflen, " root=ubi0:rootfs ubi.mtd=%d", system_ptn_index); |
| 266 | } |
| 267 | else { |
| 268 | /* Below is for emmc boot */ |
anisha agarwal | c49a325 | 2014-10-15 17:37:40 -0700 | [diff] [blame] | 269 | system_ptn_index = partition_get_index(part) + 1; /* Adding +1 as offsets for eMMC start at 1 and NAND at 0 */ |
anisha agarwal | ce363dd | 2014-08-26 15:17:09 -0700 | [diff] [blame] | 270 | if (system_ptn_index < 0) { |
| 271 | dprintf(CRITICAL, |
| 272 | "WARN: Cannot get partition index for %s\n", part); |
| 273 | return -1; |
| 274 | } |
| 275 | snprintf(buf, buflen, EXT4_CMDLINE"%d", system_ptn_index); |
| 276 | } |
anisha agarwal | ce363dd | 2014-08-26 15:17:09 -0700 | [diff] [blame] | 277 | } |
Sridhar Parasuram | dbe91a4 | 2014-12-29 13:45:30 -0800 | [diff] [blame] | 278 | return 0; |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | const char * target_usb_controller() |
| 282 | { |
| 283 | return "dwc"; |
| 284 | } |
| 285 | |
| 286 | static void set_sdc_power_ctrl() |
| 287 | { |
| 288 | /* Drive strength configs for sdc pins */ |
| 289 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 290 | { |
Sridhar Parasuram | dbe91a4 | 2014-12-29 13:45:30 -0800 | [diff] [blame] | 291 | { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, 0 }, |
| 292 | { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, 0 }, |
| 293 | { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK, 0 }, |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 294 | }; |
| 295 | |
| 296 | /* Pull configs for sdc pins */ |
| 297 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 298 | { |
Sridhar Parasuram | dbe91a4 | 2014-12-29 13:45:30 -0800 | [diff] [blame] | 299 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, 0 }, |
| 300 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0 }, |
| 301 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0 }, |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | /* Set the drive strength & pull control values */ |
| 305 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 306 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
| 307 | } |
| 308 | |
| 309 | static struct mmc_device *dev; |
| 310 | |
| 311 | void *target_mmc_device() |
| 312 | { |
| 313 | return (void *) dev; |
| 314 | } |
| 315 | |
| 316 | void target_sdc_init() |
| 317 | { |
| 318 | struct mmc_config_data config; |
| 319 | |
| 320 | /* Set drive strength & pull ctrl values */ |
| 321 | set_sdc_power_ctrl(); |
| 322 | |
| 323 | config.slot = 1; |
Channagoud Kadabi | de17ba8 | 2014-11-12 13:05:57 -0800 | [diff] [blame] | 324 | config.bus_width = DATA_BUS_WIDTH_8BIT; |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 325 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 326 | config.sdhc_base = MSM_SDC1_SDHCI_BASE; |
| 327 | config.pwrctl_base = MSM_SDC1_BASE; |
| 328 | config.pwr_irq = SDCC1_PWRCTL_IRQ; |
| 329 | config.hs400_support = 0; |
Channagoud Kadabi | de17ba8 | 2014-11-12 13:05:57 -0800 | [diff] [blame] | 330 | config.hs200_support = 0; |
Channagoud Kadabi | d23379d | 2014-10-13 11:33:50 -0700 | [diff] [blame] | 331 | config.use_io_switch = 1; |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 332 | |
| 333 | if (!(dev = mmc_init(&config))) { |
| 334 | dprintf(CRITICAL, "mmc init failed!"); |
| 335 | ASSERT(0); |
| 336 | } |
| 337 | } |
| 338 | |
anisha agarwal | 0fc661d | 2014-11-26 11:54:32 -0800 | [diff] [blame] | 339 | int target_cont_splash_screen() |
| 340 | { |
| 341 | /* FOR OEMs - Set cont_splash_screen to keep the splash enable after LK.*/ |
anisha agarwal | 58d25cf | 2014-11-26 12:09:23 -0800 | [diff] [blame] | 342 | return false; |
anisha agarwal | 0fc661d | 2014-11-26 11:54:32 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 345 | void target_uninit(void) |
| 346 | { |
| 347 | if (platform_boot_dev_isemmc()) |
| 348 | { |
| 349 | mmc_put_card_to_sleep(dev); |
| 350 | sdhci_mode_disable(&dev->host); |
| 351 | } |
| 352 | } |
| 353 | |
Joonwoo Park | 39aed06 | 2014-06-09 17:00:07 -0700 | [diff] [blame] | 354 | void target_usb_phy_reset(void) |
| 355 | { |
Joonwoo Park | 39aed06 | 2014-06-09 17:00:07 -0700 | [diff] [blame] | 356 | usb30_qmp_phy_reset(); |
Channagoud Kadabi | 1b69e48 | 2014-09-23 15:20:22 -0700 | [diff] [blame] | 357 | qusb2_phy_reset(); |
Joonwoo Park | 39aed06 | 2014-06-09 17:00:07 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 360 | target_usb_iface_t* target_usb30_init() |
| 361 | { |
| 362 | target_usb_iface_t *t_usb_iface; |
| 363 | |
Sridhar Parasuram | dbe91a4 | 2014-12-29 13:45:30 -0800 | [diff] [blame] | 364 | t_usb_iface = (target_usb_iface_t *) calloc(1, sizeof(target_usb_iface_t)); |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 365 | ASSERT(t_usb_iface); |
| 366 | |
| 367 | t_usb_iface->mux_config = NULL; |
| 368 | t_usb_iface->phy_init = usb30_qmp_phy_init; |
Joonwoo Park | 39aed06 | 2014-06-09 17:00:07 -0700 | [diff] [blame] | 369 | t_usb_iface->phy_reset = target_usb_phy_reset; |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 370 | t_usb_iface->clock_init = clock_usb30_init; |
| 371 | t_usb_iface->vbus_override = 1; |
| 372 | |
| 373 | return t_usb_iface; |
| 374 | } |
Channagoud Kadabi | 1b69e48 | 2014-09-23 15:20:22 -0700 | [diff] [blame] | 375 | |
| 376 | uint32_t target_override_pll() |
| 377 | { |
| 378 | return 1; |
| 379 | } |
Channagoud Kadabi | d23379d | 2014-10-13 11:33:50 -0700 | [diff] [blame] | 380 | |
| 381 | uint32_t target_get_hlos_subtype() |
| 382 | { |
| 383 | return board_hlos_subtype(); |
| 384 | } |