Channagoud Kadabi | e936ded | 2014-02-11 15:38:27 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -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> |
| 37 | #include <ctype.h> |
| 38 | #include <string.h> |
| 39 | #include <pm8x41.h> |
| 40 | #include <reg.h> |
| 41 | #include <platform/timer.h> |
Channagoud Kadabi | ffc3260 | 2014-02-04 17:06:41 -0800 | [diff] [blame] | 42 | #include <platform/clock.h> |
Sundarajan Srinivasan | e1b4db7 | 2013-10-29 12:29:15 -0700 | [diff] [blame] | 43 | #include <hsusb.h> |
Channagoud Kadabi | ffc3260 | 2014-02-04 17:06:41 -0800 | [diff] [blame] | 44 | #include <bits.h> |
| 45 | #include <qmp_phy.h> |
Sundarajan Srinivasan | b3a99fc | 2014-05-14 23:24:56 -0700 | [diff] [blame] | 46 | #include <scm.h> |
Devendra Patel | abd5197 | 2014-10-21 17:57:33 -0700 | [diff] [blame] | 47 | #include <rpm-smd.h> |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -0700 | [diff] [blame] | 48 | |
| 49 | extern void smem_ptable_init(void); |
| 50 | extern void smem_add_modem_partitions(struct ptable *flash_ptable); |
| 51 | |
| 52 | static struct ptable flash_ptable; |
| 53 | |
| 54 | /* PMIC config data */ |
| 55 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 56 | #define PMIC_ARB_OWNER_ID 0 |
| 57 | |
| 58 | /* NANDc BAM pipe numbers */ |
| 59 | #define DATA_CONSUMER_PIPE 0 |
| 60 | #define DATA_PRODUCER_PIPE 1 |
| 61 | #define CMD_PIPE 2 |
| 62 | |
| 63 | /* NANDc BAM pipe groups */ |
| 64 | #define DATA_PRODUCER_PIPE_GRP 0 |
| 65 | #define DATA_CONSUMER_PIPE_GRP 0 |
| 66 | #define CMD_PIPE_GRP 1 |
| 67 | |
| 68 | /* NANDc EE */ |
| 69 | #define QPIC_NAND_EE 0 |
| 70 | |
| 71 | /* NANDc max desc length. */ |
| 72 | #define QPIC_NAND_MAX_DESC_LEN 0x7FFF |
| 73 | |
| 74 | #define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF |
| 75 | |
| 76 | struct qpic_nand_init_config config; |
| 77 | |
Sundarajan Srinivasan | e1b4db7 | 2013-10-29 12:29:15 -0700 | [diff] [blame] | 78 | extern void ulpi_write(unsigned val, unsigned reg); |
| 79 | |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -0700 | [diff] [blame] | 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(3, 0, MSM_UART2_BASE); |
| 115 | #endif |
| 116 | } |
| 117 | |
| 118 | /* init */ |
| 119 | void target_init(void) |
| 120 | { |
| 121 | dprintf(INFO, "target_init()\n"); |
| 122 | |
| 123 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 124 | |
| 125 | config.pipes.read_pipe = DATA_PRODUCER_PIPE; |
| 126 | config.pipes.write_pipe = DATA_CONSUMER_PIPE; |
| 127 | config.pipes.cmd_pipe = CMD_PIPE; |
| 128 | |
| 129 | config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP; |
| 130 | config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP; |
| 131 | config.pipes.cmd_pipe_grp = CMD_PIPE_GRP; |
| 132 | |
| 133 | config.bam_base = MSM_NAND_BAM_BASE; |
| 134 | config.nand_base = MSM_NAND_BASE; |
| 135 | config.ee = QPIC_NAND_EE; |
| 136 | config.max_desc_len = QPIC_NAND_MAX_DESC_LEN; |
| 137 | |
| 138 | qpic_nand_init(&config); |
| 139 | |
| 140 | ptable_init(&flash_ptable); |
| 141 | |
| 142 | smem_ptable_init(); |
| 143 | |
| 144 | smem_add_modem_partitions(&flash_ptable); |
| 145 | |
| 146 | update_ptable_names(); |
| 147 | |
| 148 | flash_set_ptable(&flash_ptable); |
Devendra Patel | abd5197 | 2014-10-21 17:57:33 -0700 | [diff] [blame] | 149 | rpm_smd_init(); |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -0700 | [diff] [blame] | 150 | } |
Zohaib Alam | 929b7fb | 2014-10-24 15:58:22 -0400 | [diff] [blame] | 151 | |
| 152 | int target_cont_splash_screen() |
| 153 | { |
| 154 | /* |
| 155 | * FOR OEMs - Set cont_splash_screen to keep the splash enable after LK. |
| 156 | * By default: the cont-splash-screen is ON |
| 157 | */ |
Zohaib Alam | 7b34869 | 2014-10-28 13:35:04 -0400 | [diff] [blame] | 158 | return false; |
Zohaib Alam | 929b7fb | 2014-10-24 15:58:22 -0400 | [diff] [blame] | 159 | } |
| 160 | |
Devendra Patel | abd5197 | 2014-10-21 17:57:33 -0700 | [diff] [blame] | 161 | void target_uninit() |
| 162 | { |
Zohaib Alam | 929b7fb | 2014-10-24 15:58:22 -0400 | [diff] [blame] | 163 | #if DISPLAY_SPLASH_SCREEN |
| 164 | /* target_display_shutdown will uninitialize it in case of cont-splash */ |
| 165 | if(target_cont_splash_screen()) |
| 166 | #endif |
| 167 | rpm_smd_uninit(); |
Devendra Patel | abd5197 | 2014-10-21 17:57:33 -0700 | [diff] [blame] | 168 | } |
Zohaib Alam | 929b7fb | 2014-10-24 15:58:22 -0400 | [diff] [blame] | 169 | |
Sundarajan Srinivasan | e1b4db7 | 2013-10-29 12:29:15 -0700 | [diff] [blame] | 170 | /* Do target specific usb initialization */ |
| 171 | void target_usb_init(void) |
| 172 | { |
| 173 | uint32_t val; |
| 174 | |
| 175 | /* Select and enable external configuration with USB PHY */ |
| 176 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET); |
| 177 | |
| 178 | /* Enable sess_vld */ |
| 179 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 180 | writel(val, USB_GENCONFIG_2); |
| 181 | |
| 182 | /* Enable external vbus configuration in the LINK */ |
| 183 | val = readl(USB_USBCMD); |
| 184 | val |= SESS_VLD_CTRL; |
| 185 | writel(val, USB_USBCMD); |
| 186 | } |
| 187 | |
Channagoud Kadabi | ffc3260 | 2014-02-04 17:06:41 -0800 | [diff] [blame] | 188 | target_usb_iface_t* target_usb30_init() |
| 189 | { |
| 190 | target_usb_iface_t *t_usb_iface; |
| 191 | |
| 192 | t_usb_iface = calloc(1, sizeof(target_usb_iface_t)); |
| 193 | ASSERT(t_usb_iface); |
| 194 | |
| 195 | t_usb_iface->mux_config = target_usb_phy_mux_configure; |
| 196 | t_usb_iface->phy_init = usb30_qmp_phy_init; |
| 197 | t_usb_iface->phy_reset = usb30_qmp_phy_reset; |
| 198 | t_usb_iface->clock_init = clock_usb30_init; |
| 199 | t_usb_iface->vbus_override = 1; |
| 200 | |
| 201 | return t_usb_iface; |
| 202 | } |
| 203 | |
Sundarajan Srinivasan | b3a99fc | 2014-05-14 23:24:56 -0700 | [diff] [blame] | 204 | |
| 205 | static int scm_clear_boot_partition_select() |
| 206 | { |
| 207 | int ret = 0; |
| 208 | |
| 209 | ret = scm_call_atomic2(SCM_SVC_BOOT, WDOG_DEBUG_DISABLE, 1, 0); |
| 210 | if (ret) |
| 211 | dprintf(CRITICAL, "Failed to disable the wdog debug \n"); |
| 212 | |
| 213 | return ret; |
| 214 | } |
| 215 | |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -0700 | [diff] [blame] | 216 | /* reboot */ |
| 217 | void reboot_device(unsigned reboot_reason) |
| 218 | { |
Sundarajan Srinivasan | b3a99fc | 2014-05-14 23:24:56 -0700 | [diff] [blame] | 219 | uint8_t reset_type = 0; |
| 220 | |
| 221 | /* Clear the boot partition select cookie to indicate |
| 222 | * its a normal reset and avoid going to download mode */ |
| 223 | scm_clear_boot_partition_select(); |
| 224 | |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -0700 | [diff] [blame] | 225 | /* Write the reboot reason */ |
| 226 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 227 | |
| 228 | /* Configure PMIC for warm reset */ |
| 229 | /* PM 8019 v1 aligns with PM8941 v2. |
| 230 | * This call should be based on the pmic version |
| 231 | * when PM8019 v2 is available. |
| 232 | */ |
Sundarajan Srinivasan | b3a99fc | 2014-05-14 23:24:56 -0700 | [diff] [blame] | 233 | if(reboot_reason) |
| 234 | reset_type = PON_PSHOLD_WARM_RESET; |
| 235 | else |
| 236 | reset_type = PON_PSHOLD_HARD_RESET; |
| 237 | |
| 238 | pm8x41_v2_reset_configure(reset_type); |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -0700 | [diff] [blame] | 239 | |
| 240 | /* Drop PS_HOLD for MSM */ |
| 241 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 242 | |
| 243 | mdelay(5000); |
| 244 | |
| 245 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | /* Identify the current target */ |
| 250 | void target_detect(struct board_data *board) |
| 251 | { |
Channagoud Kadabi | e936ded | 2014-02-11 15:38:27 -0800 | [diff] [blame] | 252 | /* This property is filled as part of board.c */ |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | unsigned board_machtype(void) |
| 256 | { |
| 257 | return LINUX_MACHTYPE_UNKNOWN; |
| 258 | } |
| 259 | |
| 260 | /* Identify the baseband being used */ |
| 261 | void target_baseband_detect(struct board_data *board) |
| 262 | { |
| 263 | /* Check for baseband variants. Default to MSM */ |
| 264 | if (board->platform_subtype == HW_PLATFORM_SUBTYPE_UNKNOWN) |
| 265 | { |
| 266 | board->baseband = BASEBAND_MSM; |
| 267 | } |
| 268 | else |
| 269 | { |
| 270 | dprintf(CRITICAL, "Could not identify baseband id (%d)\n", |
| 271 | board->platform_subtype); |
| 272 | ASSERT(0); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | unsigned check_reboot_mode(void) |
| 277 | { |
| 278 | unsigned restart_reason = 0; |
| 279 | |
| 280 | /* Read reboot reason and scrub it */ |
| 281 | restart_reason = readl(RESTART_REASON_ADDR); |
| 282 | |
| 283 | writel(0x00, RESTART_REASON_ADDR); |
| 284 | |
| 285 | return restart_reason; |
| 286 | } |
| 287 | |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 288 | int get_target_boot_params(const char *cmdline, const char *part, char *buf, |
| 289 | int buflen) |
| 290 | { |
| 291 | struct ptable *ptable; |
| 292 | int system_ptn_index = -1; |
| 293 | |
| 294 | if (!cmdline || !part || !buf || buflen < 0) { |
| 295 | dprintf(CRITICAL, "WARN: Invalid input param\n"); |
| 296 | return -1; |
| 297 | } |
| 298 | |
| 299 | ptable = flash_get_ptable(); |
| 300 | if (!ptable) { |
| 301 | dprintf(CRITICAL, |
| 302 | "WARN: Cannot get flash partition table\n"); |
| 303 | return -1; |
| 304 | } |
| 305 | |
| 306 | system_ptn_index = ptable_get_index(ptable, part); |
| 307 | if (system_ptn_index < 0) { |
| 308 | dprintf(CRITICAL, |
| 309 | "WARN: Cannot get partition index for %s\n", part); |
| 310 | return -1; |
| 311 | } |
| 312 | |
| 313 | /* |
Smita Solanki | d23abdd | 2014-06-05 13:49:28 -0700 | [diff] [blame] | 314 | * check if cmdline contains "root="/"ubi.mtd" at the beginning of buffer or |
| 315 | * " root="/"ubi.mtd" in the middle of buffer. |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 316 | */ |
Smita Solanki | d23abdd | 2014-06-05 13:49:28 -0700 | [diff] [blame] | 317 | |
| 318 | if (strstr(cmdline, "rootfstype=yaffs2")) { |
| 319 | if (((!strncmp(cmdline, "root=", strlen("root="))) || |
| 320 | (strstr(cmdline, " root=")))) |
| 321 | dprintf(DEBUG, "DEBUG: cmdline has root=\n"); |
| 322 | else |
| 323 | snprintf(buf, buflen, " root=/dev/mtdblock%d", |
| 324 | system_ptn_index); |
| 325 | } else if (strstr(cmdline, "rootfstype=ubifs")){ |
| 326 | if (((!strncmp(cmdline, "ubi.mtd=", strlen("ubi.mtd="))) || |
| 327 | (strstr(cmdline, " ubi.mtd=")))) |
| 328 | dprintf(DEBUG, "DEBUG: cmdline has ubi.mtd=\n"); |
| 329 | else |
| 330 | snprintf(buf, buflen, " ubi.mtd=%d", |
| 331 | system_ptn_index); |
| 332 | } |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 333 | |
| 334 | return 0; |
| 335 | } |
Channagoud Kadabi | ffc3260 | 2014-02-04 17:06:41 -0800 | [diff] [blame] | 336 | |
| 337 | /* identify the usb controller to be used for the target */ |
| 338 | const char * target_usb_controller() |
| 339 | { |
| 340 | return "dwc"; |
| 341 | } |
| 342 | |
| 343 | /* mux hs phy to route to dwc controller */ |
| 344 | static void phy_mux_configure_with_tcsr() |
| 345 | { |
| 346 | /* As per the hardware team, set the mux for snps controller */ |
| 347 | RMWREG32(TCSR_PHSS_USB2_PHY_SEL, 0x0, 0x1, 0x1); |
| 348 | } |
| 349 | |
| 350 | /* configure hs phy mux if using dwc controller */ |
| 351 | void target_usb_phy_mux_configure(void) |
| 352 | { |
| 353 | if(!strcmp(target_usb_controller(), "dwc")) |
| 354 | { |
| 355 | phy_mux_configure_with_tcsr(); |
| 356 | } |
| 357 | } |
Channagoud Kadabi | d6ded11 | 2014-05-12 18:07:24 -0700 | [diff] [blame] | 358 | |
| 359 | uint32_t target_override_pll() |
| 360 | { |
| 361 | return board_soc_version() == BOARD_SOC_VERSION2 ? 1 : 0; |
| 362 | } |