Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 1 | /* 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 Park | 39aed06 | 2014-06-09 17:00:07 -0700 | [diff] [blame] | 48 | #include <qusb2_phy.h> |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 49 | |
| 50 | extern void smem_ptable_init(void); |
| 51 | extern void smem_add_modem_partitions(struct ptable *flash_ptable); |
| 52 | void target_sdc_init(); |
| 53 | |
| 54 | static 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 | |
| 78 | struct qpic_nand_init_config config; |
| 79 | |
| 80 | void update_ptable_names(void) |
| 81 | { |
| 82 | uint32_t ptn_index; |
| 83 | struct ptentry *ptentry_ptr = flash_ptable.parts; |
| 84 | struct ptentry *boot_ptn; |
| 85 | unsigned i; |
| 86 | uint32_t len; |
| 87 | |
| 88 | /* Change all names to lower case. */ |
| 89 | for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++) |
| 90 | { |
| 91 | len = strlen(ptentry_ptr[ptn_index].name); |
| 92 | |
| 93 | for (i = 0; i < len; i++) |
| 94 | { |
| 95 | if (isupper(ptentry_ptr[ptn_index].name[i])) |
| 96 | { |
| 97 | ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /* SBL fills in the last partition length as 0xFFFFFFFF. |
| 102 | * Update the length field based on the number of blocks on the flash. |
| 103 | */ |
| 104 | if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN) |
| 105 | { |
| 106 | ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | void target_early_init(void) |
| 112 | { |
| 113 | #if WITH_DEBUG_UART |
| 114 | uart_dm_init(2, 0, BLSP1_UART1_BASE); |
| 115 | #endif |
| 116 | } |
| 117 | |
| 118 | int target_is_emmc_boot(void) |
| 119 | { |
| 120 | return platform_boot_dev_isemmc(); |
| 121 | } |
| 122 | |
| 123 | /* init */ |
| 124 | void target_init(void) |
| 125 | { |
| 126 | dprintf(INFO, "target_init()\n"); |
| 127 | |
| 128 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 129 | |
Joonwoo Park | 419b94c | 2014-05-15 10:51:19 -0700 | [diff] [blame] | 130 | platform_read_boot_config(); |
| 131 | |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 132 | if (platform_boot_dev_isemmc()) { |
| 133 | target_sdc_init(); |
| 134 | if (partition_read_table()) { |
| 135 | dprintf(CRITICAL, "Error reading the partition table info\n"); |
| 136 | ASSERT(0); |
| 137 | } |
| 138 | } else { |
| 139 | config.pipes.read_pipe = DATA_PRODUCER_PIPE; |
| 140 | config.pipes.write_pipe = DATA_CONSUMER_PIPE; |
| 141 | config.pipes.cmd_pipe = CMD_PIPE; |
| 142 | |
| 143 | config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP; |
| 144 | config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP; |
| 145 | config.pipes.cmd_pipe_grp = CMD_PIPE_GRP; |
| 146 | |
| 147 | config.bam_base = MSM_NAND_BAM_BASE; |
| 148 | config.nand_base = MSM_NAND_BASE; |
| 149 | config.ee = QPIC_NAND_EE; |
| 150 | config.max_desc_len = QPIC_NAND_MAX_DESC_LEN; |
| 151 | |
| 152 | qpic_nand_init(&config); |
| 153 | |
| 154 | ptable_init(&flash_ptable); |
| 155 | smem_ptable_init(); |
| 156 | smem_add_modem_partitions(&flash_ptable); |
| 157 | |
| 158 | update_ptable_names(); |
| 159 | flash_set_ptable(&flash_ptable); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /* reboot */ |
| 164 | void reboot_device(unsigned reboot_reason) |
| 165 | { |
| 166 | /* Write the reboot reason */ |
| 167 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 168 | |
| 169 | /* Configure PMIC for warm reset */ |
| 170 | /* PM 8019 v1 aligns with PM8941 v2. |
| 171 | * This call should be based on the pmic version |
| 172 | * when PM8019 v2 is available. |
| 173 | */ |
| 174 | pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET); |
| 175 | |
| 176 | /* Drop PS_HOLD for MSM */ |
| 177 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 178 | |
| 179 | mdelay(5000); |
| 180 | |
| 181 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | /* Identify the current target */ |
| 186 | void target_detect(struct board_data *board) |
| 187 | { |
| 188 | /* This property is filled as part of board.c */ |
| 189 | } |
| 190 | |
| 191 | unsigned board_machtype(void) |
| 192 | { |
| 193 | return LINUX_MACHTYPE_UNKNOWN; |
| 194 | } |
| 195 | |
| 196 | /* Identify the baseband being used */ |
| 197 | void target_baseband_detect(struct board_data *board) |
| 198 | { |
| 199 | board->baseband = BASEBAND_MSM; |
| 200 | } |
| 201 | |
| 202 | unsigned check_reboot_mode(void) |
| 203 | { |
| 204 | unsigned restart_reason = 0; |
| 205 | |
| 206 | /* Read reboot reason and scrub it */ |
| 207 | restart_reason = readl(RESTART_REASON_ADDR); |
| 208 | |
| 209 | writel(0x00, RESTART_REASON_ADDR); |
| 210 | |
| 211 | return restart_reason; |
| 212 | } |
| 213 | |
| 214 | int get_target_boot_params(const char *cmdline, const char *part, char *buf, |
| 215 | int buflen) |
| 216 | { |
| 217 | struct ptable *ptable; |
| 218 | int system_ptn_index = -1; |
| 219 | |
| 220 | if (!target_is_emmc_boot()) { |
| 221 | if (!cmdline || !part || !buf || buflen < 0) { |
| 222 | dprintf(CRITICAL, "WARN: Invalid input param\n"); |
| 223 | return -1; |
| 224 | } |
| 225 | |
| 226 | ptable = flash_get_ptable(); |
| 227 | if (!ptable) { |
| 228 | dprintf(CRITICAL, |
| 229 | "WARN: Cannot get flash partition table\n"); |
| 230 | return -1; |
| 231 | } |
| 232 | |
| 233 | system_ptn_index = ptable_get_index(ptable, part); |
| 234 | if (system_ptn_index < 0) { |
| 235 | dprintf(CRITICAL, |
| 236 | "WARN: Cannot get partition index for %s\n", part); |
| 237 | return -1; |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | * check if cmdline contains "root=" at the beginning of buffer or |
| 242 | * " root=" in the middle of buffer. |
| 243 | */ |
| 244 | if (((!strncmp(cmdline, "root=", strlen("root="))) || |
| 245 | (strstr(cmdline, " root=")))) |
| 246 | dprintf(DEBUG, "DEBUG: cmdline has root=\n"); |
| 247 | else |
| 248 | snprintf(buf, buflen, " root=/dev/mtdblock%d", |
| 249 | system_ptn_index); |
| 250 | } |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | const char * target_usb_controller() |
| 256 | { |
| 257 | return "dwc"; |
| 258 | } |
| 259 | |
| 260 | static void set_sdc_power_ctrl() |
| 261 | { |
| 262 | /* Drive strength configs for sdc pins */ |
| 263 | struct tlmm_cfgs sdc1_hdrv_cfg[] = |
| 264 | { |
| 265 | { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK }, |
| 266 | { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK }, |
| 267 | { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK }, |
| 268 | }; |
| 269 | |
| 270 | /* Pull configs for sdc pins */ |
| 271 | struct tlmm_cfgs sdc1_pull_cfg[] = |
| 272 | { |
| 273 | { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK }, |
| 274 | { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
| 275 | { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK }, |
| 276 | }; |
| 277 | |
| 278 | /* Set the drive strength & pull control values */ |
| 279 | tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg)); |
| 280 | tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg)); |
| 281 | } |
| 282 | |
| 283 | static struct mmc_device *dev; |
| 284 | |
| 285 | void *target_mmc_device() |
| 286 | { |
| 287 | return (void *) dev; |
| 288 | } |
| 289 | |
| 290 | void target_sdc_init() |
| 291 | { |
| 292 | struct mmc_config_data config; |
| 293 | |
| 294 | /* Set drive strength & pull ctrl values */ |
| 295 | set_sdc_power_ctrl(); |
| 296 | |
| 297 | config.slot = 1; |
| 298 | config.bus_width = DATA_BUS_WIDTH_4BIT; |
| 299 | config.max_clk_rate = MMC_CLK_200MHZ; |
| 300 | config.sdhc_base = MSM_SDC1_SDHCI_BASE; |
| 301 | config.pwrctl_base = MSM_SDC1_BASE; |
| 302 | config.pwr_irq = SDCC1_PWRCTL_IRQ; |
| 303 | config.hs400_support = 0; |
| 304 | |
| 305 | if (!(dev = mmc_init(&config))) { |
| 306 | dprintf(CRITICAL, "mmc init failed!"); |
| 307 | ASSERT(0); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | void target_uninit(void) |
| 312 | { |
| 313 | if (platform_boot_dev_isemmc()) |
| 314 | { |
| 315 | mmc_put_card_to_sleep(dev); |
| 316 | sdhci_mode_disable(&dev->host); |
| 317 | } |
| 318 | } |
| 319 | |
Joonwoo Park | 39aed06 | 2014-06-09 17:00:07 -0700 | [diff] [blame] | 320 | void target_usb_phy_reset(void) |
| 321 | { |
| 322 | qusb2_phy_reset(); |
| 323 | usb30_qmp_phy_reset(); |
| 324 | } |
| 325 | |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 326 | target_usb_iface_t* target_usb30_init() |
| 327 | { |
| 328 | target_usb_iface_t *t_usb_iface; |
| 329 | |
| 330 | t_usb_iface = calloc(1, sizeof(target_usb_iface_t)); |
| 331 | ASSERT(t_usb_iface); |
| 332 | |
| 333 | t_usb_iface->mux_config = NULL; |
| 334 | t_usb_iface->phy_init = usb30_qmp_phy_init; |
Joonwoo Park | 39aed06 | 2014-06-09 17:00:07 -0700 | [diff] [blame] | 335 | t_usb_iface->phy_reset = target_usb_phy_reset; |
Joonwoo Park | e586c2e | 2014-04-02 11:04:10 -0700 | [diff] [blame] | 336 | t_usb_iface->clock_init = clock_usb30_init; |
| 337 | t_usb_iface->vbus_override = 1; |
| 338 | |
| 339 | return t_usb_iface; |
| 340 | } |