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> |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -0700 | [diff] [blame] | 47 | |
| 48 | extern void smem_ptable_init(void); |
| 49 | extern void smem_add_modem_partitions(struct ptable *flash_ptable); |
| 50 | |
| 51 | static struct ptable flash_ptable; |
| 52 | |
| 53 | /* PMIC config data */ |
| 54 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 55 | #define PMIC_ARB_OWNER_ID 0 |
| 56 | |
| 57 | /* NANDc BAM pipe numbers */ |
| 58 | #define DATA_CONSUMER_PIPE 0 |
| 59 | #define DATA_PRODUCER_PIPE 1 |
| 60 | #define CMD_PIPE 2 |
| 61 | |
| 62 | /* NANDc BAM pipe groups */ |
| 63 | #define DATA_PRODUCER_PIPE_GRP 0 |
| 64 | #define DATA_CONSUMER_PIPE_GRP 0 |
| 65 | #define CMD_PIPE_GRP 1 |
| 66 | |
| 67 | /* NANDc EE */ |
| 68 | #define QPIC_NAND_EE 0 |
| 69 | |
| 70 | /* NANDc max desc length. */ |
| 71 | #define QPIC_NAND_MAX_DESC_LEN 0x7FFF |
| 72 | |
| 73 | #define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF |
| 74 | |
| 75 | struct qpic_nand_init_config config; |
| 76 | |
Sundarajan Srinivasan | e1b4db7 | 2013-10-29 12:29:15 -0700 | [diff] [blame] | 77 | extern void ulpi_write(unsigned val, unsigned reg); |
| 78 | |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -0700 | [diff] [blame] | 79 | void update_ptable_names(void) |
| 80 | { |
| 81 | uint32_t ptn_index; |
| 82 | struct ptentry *ptentry_ptr = flash_ptable.parts; |
| 83 | struct ptentry *boot_ptn; |
| 84 | unsigned i; |
| 85 | uint32_t len; |
| 86 | |
| 87 | /* Change all names to lower case. */ |
| 88 | for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++) |
| 89 | { |
| 90 | len = strlen(ptentry_ptr[ptn_index].name); |
| 91 | |
| 92 | for (i = 0; i < len; i++) |
| 93 | { |
| 94 | if (isupper(ptentry_ptr[ptn_index].name[i])) |
| 95 | { |
| 96 | ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /* SBL fills in the last partition length as 0xFFFFFFFF. |
| 101 | * Update the length field based on the number of blocks on the flash. |
| 102 | */ |
| 103 | if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN) |
| 104 | { |
| 105 | ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start; |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | void target_early_init(void) |
| 111 | { |
| 112 | #if WITH_DEBUG_UART |
| 113 | uart_dm_init(3, 0, MSM_UART2_BASE); |
| 114 | #endif |
| 115 | } |
| 116 | |
| 117 | /* init */ |
| 118 | void target_init(void) |
| 119 | { |
| 120 | dprintf(INFO, "target_init()\n"); |
| 121 | |
| 122 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 123 | |
| 124 | config.pipes.read_pipe = DATA_PRODUCER_PIPE; |
| 125 | config.pipes.write_pipe = DATA_CONSUMER_PIPE; |
| 126 | config.pipes.cmd_pipe = CMD_PIPE; |
| 127 | |
| 128 | config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP; |
| 129 | config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP; |
| 130 | config.pipes.cmd_pipe_grp = CMD_PIPE_GRP; |
| 131 | |
| 132 | config.bam_base = MSM_NAND_BAM_BASE; |
| 133 | config.nand_base = MSM_NAND_BASE; |
| 134 | config.ee = QPIC_NAND_EE; |
| 135 | config.max_desc_len = QPIC_NAND_MAX_DESC_LEN; |
| 136 | |
| 137 | qpic_nand_init(&config); |
| 138 | |
| 139 | ptable_init(&flash_ptable); |
| 140 | |
| 141 | smem_ptable_init(); |
| 142 | |
| 143 | smem_add_modem_partitions(&flash_ptable); |
| 144 | |
| 145 | update_ptable_names(); |
| 146 | |
| 147 | flash_set_ptable(&flash_ptable); |
| 148 | } |
| 149 | |
Sundarajan Srinivasan | e1b4db7 | 2013-10-29 12:29:15 -0700 | [diff] [blame] | 150 | /* Do target specific usb initialization */ |
| 151 | void target_usb_init(void) |
| 152 | { |
| 153 | uint32_t val; |
| 154 | |
| 155 | /* Select and enable external configuration with USB PHY */ |
| 156 | ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET); |
| 157 | |
| 158 | /* Enable sess_vld */ |
| 159 | val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN; |
| 160 | writel(val, USB_GENCONFIG_2); |
| 161 | |
| 162 | /* Enable external vbus configuration in the LINK */ |
| 163 | val = readl(USB_USBCMD); |
| 164 | val |= SESS_VLD_CTRL; |
| 165 | writel(val, USB_USBCMD); |
| 166 | } |
| 167 | |
Channagoud Kadabi | ffc3260 | 2014-02-04 17:06:41 -0800 | [diff] [blame] | 168 | target_usb_iface_t* target_usb30_init() |
| 169 | { |
| 170 | target_usb_iface_t *t_usb_iface; |
| 171 | |
| 172 | t_usb_iface = calloc(1, sizeof(target_usb_iface_t)); |
| 173 | ASSERT(t_usb_iface); |
| 174 | |
| 175 | t_usb_iface->mux_config = target_usb_phy_mux_configure; |
| 176 | t_usb_iface->phy_init = usb30_qmp_phy_init; |
| 177 | t_usb_iface->phy_reset = usb30_qmp_phy_reset; |
| 178 | t_usb_iface->clock_init = clock_usb30_init; |
| 179 | t_usb_iface->vbus_override = 1; |
| 180 | |
| 181 | return t_usb_iface; |
| 182 | } |
| 183 | |
Sundarajan Srinivasan | b3a99fc | 2014-05-14 23:24:56 -0700 | [diff] [blame^] | 184 | |
| 185 | static int scm_clear_boot_partition_select() |
| 186 | { |
| 187 | int ret = 0; |
| 188 | |
| 189 | ret = scm_call_atomic2(SCM_SVC_BOOT, WDOG_DEBUG_DISABLE, 1, 0); |
| 190 | if (ret) |
| 191 | dprintf(CRITICAL, "Failed to disable the wdog debug \n"); |
| 192 | |
| 193 | return ret; |
| 194 | } |
| 195 | |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -0700 | [diff] [blame] | 196 | /* reboot */ |
| 197 | void reboot_device(unsigned reboot_reason) |
| 198 | { |
Sundarajan Srinivasan | b3a99fc | 2014-05-14 23:24:56 -0700 | [diff] [blame^] | 199 | uint8_t reset_type = 0; |
| 200 | |
| 201 | /* Clear the boot partition select cookie to indicate |
| 202 | * its a normal reset and avoid going to download mode */ |
| 203 | scm_clear_boot_partition_select(); |
| 204 | |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -0700 | [diff] [blame] | 205 | /* Write the reboot reason */ |
| 206 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 207 | |
| 208 | /* Configure PMIC for warm reset */ |
| 209 | /* PM 8019 v1 aligns with PM8941 v2. |
| 210 | * This call should be based on the pmic version |
| 211 | * when PM8019 v2 is available. |
| 212 | */ |
Sundarajan Srinivasan | b3a99fc | 2014-05-14 23:24:56 -0700 | [diff] [blame^] | 213 | if(reboot_reason) |
| 214 | reset_type = PON_PSHOLD_WARM_RESET; |
| 215 | else |
| 216 | reset_type = PON_PSHOLD_HARD_RESET; |
| 217 | |
| 218 | pm8x41_v2_reset_configure(reset_type); |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -0700 | [diff] [blame] | 219 | |
| 220 | /* Drop PS_HOLD for MSM */ |
| 221 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 222 | |
| 223 | mdelay(5000); |
| 224 | |
| 225 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | /* Identify the current target */ |
| 230 | void target_detect(struct board_data *board) |
| 231 | { |
Channagoud Kadabi | e936ded | 2014-02-11 15:38:27 -0800 | [diff] [blame] | 232 | /* This property is filled as part of board.c */ |
Sundarajan Srinivasan | 00c6423 | 2013-07-03 11:12:22 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | unsigned board_machtype(void) |
| 236 | { |
| 237 | return LINUX_MACHTYPE_UNKNOWN; |
| 238 | } |
| 239 | |
| 240 | /* Identify the baseband being used */ |
| 241 | void target_baseband_detect(struct board_data *board) |
| 242 | { |
| 243 | /* Check for baseband variants. Default to MSM */ |
| 244 | if (board->platform_subtype == HW_PLATFORM_SUBTYPE_UNKNOWN) |
| 245 | { |
| 246 | board->baseband = BASEBAND_MSM; |
| 247 | } |
| 248 | else |
| 249 | { |
| 250 | dprintf(CRITICAL, "Could not identify baseband id (%d)\n", |
| 251 | board->platform_subtype); |
| 252 | ASSERT(0); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | unsigned check_reboot_mode(void) |
| 257 | { |
| 258 | unsigned restart_reason = 0; |
| 259 | |
| 260 | /* Read reboot reason and scrub it */ |
| 261 | restart_reason = readl(RESTART_REASON_ADDR); |
| 262 | |
| 263 | writel(0x00, RESTART_REASON_ADDR); |
| 264 | |
| 265 | return restart_reason; |
| 266 | } |
| 267 | |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 268 | int get_target_boot_params(const char *cmdline, const char *part, char *buf, |
| 269 | int buflen) |
| 270 | { |
| 271 | struct ptable *ptable; |
| 272 | int system_ptn_index = -1; |
| 273 | |
| 274 | if (!cmdline || !part || !buf || buflen < 0) { |
| 275 | dprintf(CRITICAL, "WARN: Invalid input param\n"); |
| 276 | return -1; |
| 277 | } |
| 278 | |
| 279 | ptable = flash_get_ptable(); |
| 280 | if (!ptable) { |
| 281 | dprintf(CRITICAL, |
| 282 | "WARN: Cannot get flash partition table\n"); |
| 283 | return -1; |
| 284 | } |
| 285 | |
| 286 | system_ptn_index = ptable_get_index(ptable, part); |
| 287 | if (system_ptn_index < 0) { |
| 288 | dprintf(CRITICAL, |
| 289 | "WARN: Cannot get partition index for %s\n", part); |
| 290 | return -1; |
| 291 | } |
| 292 | |
| 293 | /* |
| 294 | * check if cmdline contains "root=" at the beginning of buffer or |
| 295 | * " root=" in the middle of buffer. |
| 296 | */ |
| 297 | if (((!strncmp(cmdline, "root=", strlen("root="))) || |
| 298 | (strstr(cmdline, " root=")))) |
| 299 | dprintf(DEBUG, "DEBUG: cmdline has root=\n"); |
| 300 | else |
| 301 | snprintf(buf, buflen, " root=/dev/mtdblock%d", |
| 302 | system_ptn_index); |
| 303 | |
| 304 | return 0; |
| 305 | } |
Channagoud Kadabi | ffc3260 | 2014-02-04 17:06:41 -0800 | [diff] [blame] | 306 | |
| 307 | /* identify the usb controller to be used for the target */ |
| 308 | const char * target_usb_controller() |
| 309 | { |
| 310 | return "dwc"; |
| 311 | } |
| 312 | |
| 313 | /* mux hs phy to route to dwc controller */ |
| 314 | static void phy_mux_configure_with_tcsr() |
| 315 | { |
| 316 | /* As per the hardware team, set the mux for snps controller */ |
| 317 | RMWREG32(TCSR_PHSS_USB2_PHY_SEL, 0x0, 0x1, 0x1); |
| 318 | } |
| 319 | |
| 320 | /* configure hs phy mux if using dwc controller */ |
| 321 | void target_usb_phy_mux_configure(void) |
| 322 | { |
| 323 | if(!strcmp(target_usb_controller(), "dwc")) |
| 324 | { |
| 325 | phy_mux_configure_with_tcsr(); |
| 326 | } |
| 327 | } |