Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved. |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/ioport.h> |
| 18 | #include <linux/elf.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/err.h> |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 21 | #include <linux/clk.h> |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 22 | #include <linux/irq.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/reboot.h> |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 25 | |
| 26 | #include <mach/msm_iomap.h> |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 27 | #include <mach/subsystem_restart.h> |
| 28 | #include <mach/msm_smsm.h> |
| 29 | #include <mach/peripheral-loader.h> |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 30 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 31 | #include "modem_notifier.h" |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 32 | #include "peripheral-loader.h" |
| 33 | #include "scm-pas.h" |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 34 | #include "ramdump.h" |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 35 | |
| 36 | #define MARM_BOOT_CONTROL 0x0010 |
| 37 | #define MARM_RESET (MSM_CLK_CTL_BASE + 0x2BD4) |
| 38 | #define MAHB0_SFAB_PORT_RESET (MSM_CLK_CTL_BASE + 0x2304) |
| 39 | #define MARM_CLK_BRANCH_ENA_VOTE (MSM_CLK_CTL_BASE + 0x3000) |
| 40 | #define MARM_CLK_SRC0_NS (MSM_CLK_CTL_BASE + 0x2BC0) |
| 41 | #define MARM_CLK_SRC1_NS (MSM_CLK_CTL_BASE + 0x2BC4) |
| 42 | #define MARM_CLK_SRC_CTL (MSM_CLK_CTL_BASE + 0x2BC8) |
| 43 | #define MARM_CLK_CTL (MSM_CLK_CTL_BASE + 0x2BCC) |
| 44 | #define SFAB_MSS_S_HCLK_CTL (MSM_CLK_CTL_BASE + 0x2C00) |
| 45 | #define MSS_MODEM_CXO_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C44) |
| 46 | #define MSS_SLP_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C60) |
| 47 | #define MSS_MARM_SYS_REF_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C64) |
| 48 | #define MAHB0_CLK_CTL (MSM_CLK_CTL_BASE + 0x2300) |
| 49 | #define MAHB1_CLK_CTL (MSM_CLK_CTL_BASE + 0x2BE4) |
| 50 | #define MAHB2_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C20) |
| 51 | #define MAHB1_NS (MSM_CLK_CTL_BASE + 0x2BE0) |
| 52 | #define MARM_CLK_FS (MSM_CLK_CTL_BASE + 0x2BD0) |
| 53 | #define MAHB2_CLK_FS (MSM_CLK_CTL_BASE + 0x2C24) |
| 54 | #define PLL_ENA_MARM (MSM_CLK_CTL_BASE + 0x3500) |
| 55 | #define PLL8_STATUS (MSM_CLK_CTL_BASE + 0x3158) |
| 56 | #define CLK_HALT_MSS_SMPSS_MISC_STATE (MSM_CLK_CTL_BASE + 0x2FDC) |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 57 | #define MSS_MODEM_RESET (MSM_CLK_CTL_BASE + 0x2C48) |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 58 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 59 | struct modem_data { |
| 60 | void __iomem *base; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 61 | void __iomem *wdog; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 62 | unsigned long start_addr; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 63 | struct pil_device *pil; |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 64 | struct clk *xo; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 65 | struct notifier_block notifier; |
| 66 | int ignore_smsm_ack; |
| 67 | int irq; |
| 68 | struct subsys_device *subsys; |
| 69 | struct subsys_desc subsys_desc; |
| 70 | struct delayed_work unlock_work; |
| 71 | struct work_struct fatal_work; |
| 72 | struct ramdump_device *ramdump_dev; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 75 | static int make_modem_proxy_votes(struct pil_desc *pil) |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 76 | { |
| 77 | int ret; |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 78 | struct modem_data *drv = dev_get_drvdata(pil->dev); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 79 | |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 80 | ret = clk_prepare_enable(drv->xo); |
| 81 | if (ret) { |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 82 | dev_err(pil->dev, "Failed to enable XO\n"); |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 83 | return ret; |
| 84 | } |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 88 | static void remove_modem_proxy_votes(struct pil_desc *pil) |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 89 | { |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 90 | struct modem_data *drv = dev_get_drvdata(pil->dev); |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 91 | clk_disable_unprepare(drv->xo); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 94 | static int modem_init_image(struct pil_desc *pil, const u8 *metadata, |
| 95 | size_t size) |
| 96 | { |
| 97 | const struct elf32_hdr *ehdr = (struct elf32_hdr *)metadata; |
| 98 | struct modem_data *drv = dev_get_drvdata(pil->dev); |
| 99 | drv->start_addr = ehdr->e_entry; |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | static int modem_reset(struct pil_desc *pil) |
| 104 | { |
| 105 | u32 reg; |
| 106 | const struct modem_data *drv = dev_get_drvdata(pil->dev); |
| 107 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 108 | /* Put modem AHB0,1,2 clocks into reset */ |
| 109 | writel_relaxed(BIT(0) | BIT(1), MAHB0_SFAB_PORT_RESET); |
| 110 | writel_relaxed(BIT(7), MAHB1_CLK_CTL); |
| 111 | writel_relaxed(BIT(7), MAHB2_CLK_CTL); |
| 112 | |
| 113 | /* Vote for pll8 on behalf of the modem */ |
| 114 | reg = readl_relaxed(PLL_ENA_MARM); |
| 115 | reg |= BIT(8); |
| 116 | writel_relaxed(reg, PLL_ENA_MARM); |
| 117 | |
| 118 | /* Wait for PLL8 to enable */ |
| 119 | while (!(readl_relaxed(PLL8_STATUS) & BIT(16))) |
| 120 | cpu_relax(); |
| 121 | |
| 122 | /* Set MAHB1 divider to Div-5 to run MAHB1,2 and sfab at 79.8 Mhz*/ |
| 123 | writel_relaxed(0x4, MAHB1_NS); |
| 124 | |
| 125 | /* Vote for modem AHB1 and 2 clocks to be on on behalf of the modem */ |
| 126 | reg = readl_relaxed(MARM_CLK_BRANCH_ENA_VOTE); |
| 127 | reg |= BIT(0) | BIT(1); |
| 128 | writel_relaxed(reg, MARM_CLK_BRANCH_ENA_VOTE); |
| 129 | |
| 130 | /* Source marm_clk off of PLL8 */ |
| 131 | reg = readl_relaxed(MARM_CLK_SRC_CTL); |
| 132 | if ((reg & 0x1) == 0) { |
| 133 | writel_relaxed(0x3, MARM_CLK_SRC1_NS); |
| 134 | reg |= 0x1; |
| 135 | } else { |
| 136 | writel_relaxed(0x3, MARM_CLK_SRC0_NS); |
| 137 | reg &= ~0x1; |
| 138 | } |
| 139 | writel_relaxed(reg | 0x2, MARM_CLK_SRC_CTL); |
| 140 | |
| 141 | /* |
| 142 | * Force core on and periph on signals to remain active during halt |
| 143 | * for marm_clk and mahb2_clk |
| 144 | */ |
| 145 | writel_relaxed(0x6F, MARM_CLK_FS); |
| 146 | writel_relaxed(0x6F, MAHB2_CLK_FS); |
| 147 | |
| 148 | /* |
| 149 | * Enable all of the marm_clk branches, cxo sourced marm branches, |
| 150 | * and sleep clock branches |
| 151 | */ |
| 152 | writel_relaxed(0x10, MARM_CLK_CTL); |
| 153 | writel_relaxed(0x10, MAHB0_CLK_CTL); |
| 154 | writel_relaxed(0x10, SFAB_MSS_S_HCLK_CTL); |
| 155 | writel_relaxed(0x10, MSS_MODEM_CXO_CLK_CTL); |
| 156 | writel_relaxed(0x10, MSS_SLP_CLK_CTL); |
| 157 | writel_relaxed(0x10, MSS_MARM_SYS_REF_CLK_CTL); |
| 158 | |
| 159 | /* Wait for above clocks to be turned on */ |
| 160 | while (readl_relaxed(CLK_HALT_MSS_SMPSS_MISC_STATE) & (BIT(7) | BIT(8) | |
| 161 | BIT(9) | BIT(10) | BIT(4) | BIT(6))) |
| 162 | cpu_relax(); |
| 163 | |
| 164 | /* Take MAHB0,1,2 clocks out of reset */ |
| 165 | writel_relaxed(0x0, MAHB2_CLK_CTL); |
| 166 | writel_relaxed(0x0, MAHB1_CLK_CTL); |
| 167 | writel_relaxed(0x0, MAHB0_SFAB_PORT_RESET); |
| 168 | mb(); |
| 169 | |
| 170 | /* Setup exception vector table base address */ |
| 171 | writel_relaxed(drv->start_addr | 0x1, drv->base + MARM_BOOT_CONTROL); |
| 172 | |
| 173 | /* Wait for vector table to be setup */ |
| 174 | mb(); |
| 175 | |
| 176 | /* Bring modem out of reset */ |
| 177 | writel_relaxed(0x0, MARM_RESET); |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 182 | static int modem_pil_shutdown(struct pil_desc *pil) |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 183 | { |
| 184 | u32 reg; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 185 | |
| 186 | /* Put modem into reset */ |
| 187 | writel_relaxed(0x1, MARM_RESET); |
| 188 | mb(); |
| 189 | |
| 190 | /* Put modem AHB0,1,2 clocks into reset */ |
| 191 | writel_relaxed(BIT(0) | BIT(1), MAHB0_SFAB_PORT_RESET); |
| 192 | writel_relaxed(BIT(7), MAHB1_CLK_CTL); |
| 193 | writel_relaxed(BIT(7), MAHB2_CLK_CTL); |
| 194 | mb(); |
| 195 | |
| 196 | /* |
| 197 | * Disable all of the marm_clk branches, cxo sourced marm branches, |
| 198 | * and sleep clock branches |
| 199 | */ |
| 200 | writel_relaxed(0x0, MARM_CLK_CTL); |
| 201 | writel_relaxed(0x0, MAHB0_CLK_CTL); |
| 202 | writel_relaxed(0x0, SFAB_MSS_S_HCLK_CTL); |
| 203 | writel_relaxed(0x0, MSS_MODEM_CXO_CLK_CTL); |
| 204 | writel_relaxed(0x0, MSS_SLP_CLK_CTL); |
| 205 | writel_relaxed(0x0, MSS_MARM_SYS_REF_CLK_CTL); |
| 206 | |
| 207 | /* Disable marm_clk */ |
| 208 | reg = readl_relaxed(MARM_CLK_SRC_CTL); |
| 209 | reg &= ~0x2; |
| 210 | writel_relaxed(reg, MARM_CLK_SRC_CTL); |
| 211 | |
| 212 | /* Clear modem's votes for ahb clocks */ |
| 213 | writel_relaxed(0x0, MARM_CLK_BRANCH_ENA_VOTE); |
| 214 | |
| 215 | /* Clear modem's votes for PLLs */ |
| 216 | writel_relaxed(0x0, PLL_ENA_MARM); |
| 217 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static struct pil_reset_ops pil_modem_ops = { |
| 222 | .init_image = modem_init_image, |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 223 | .auth_and_reset = modem_reset, |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 224 | .shutdown = modem_pil_shutdown, |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 225 | .proxy_vote = make_modem_proxy_votes, |
| 226 | .proxy_unvote = remove_modem_proxy_votes, |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | static int modem_init_image_trusted(struct pil_desc *pil, const u8 *metadata, |
| 230 | size_t size) |
| 231 | { |
| 232 | return pas_init_image(PAS_MODEM, metadata, size); |
| 233 | } |
| 234 | |
| 235 | static int modem_reset_trusted(struct pil_desc *pil) |
| 236 | { |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 237 | return pas_auth_and_reset(PAS_MODEM); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static int modem_shutdown_trusted(struct pil_desc *pil) |
| 241 | { |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 242 | return pas_shutdown(PAS_MODEM); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static struct pil_reset_ops pil_modem_ops_trusted = { |
| 246 | .init_image = modem_init_image_trusted, |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 247 | .auth_and_reset = modem_reset_trusted, |
| 248 | .shutdown = modem_shutdown_trusted, |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 249 | .proxy_vote = make_modem_proxy_votes, |
| 250 | .proxy_unvote = remove_modem_proxy_votes, |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 251 | }; |
| 252 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 253 | static void modem_crash_shutdown(const struct subsys_desc *subsys) |
| 254 | { |
| 255 | struct modem_data *drv; |
| 256 | |
| 257 | /* If modem hasn't already crashed, send SMSM_RESET. */ |
| 258 | drv = container_of(subsys, struct modem_data, subsys_desc); |
| 259 | if (!(smsm_get_state(SMSM_MODEM_STATE) & SMSM_RESET)) { |
| 260 | modem_unregister_notifier(&drv->notifier); |
| 261 | smsm_reset_modem(SMSM_RESET); |
| 262 | } |
| 263 | |
| 264 | /* Wait to allow the modem to clean up caches etc. */ |
| 265 | mdelay(5); |
| 266 | } |
| 267 | |
| 268 | static irqreturn_t modem_wdog_bite_irq(int irq, void *dev_id) |
| 269 | { |
| 270 | struct modem_data *drv = dev_id; |
| 271 | |
| 272 | schedule_work(&drv->fatal_work); |
| 273 | disable_irq_nosync(drv->irq); |
| 274 | |
| 275 | return IRQ_HANDLED; |
| 276 | } |
| 277 | |
| 278 | static void modem_unlock_timeout(struct work_struct *work) |
| 279 | { |
| 280 | struct modem_data *drv; |
| 281 | struct delayed_work *dwork = to_delayed_work(work); |
| 282 | |
| 283 | pr_crit("Timeout waiting for modem to unlock.\n"); |
| 284 | |
| 285 | drv = container_of(dwork, struct modem_data, unlock_work); |
| 286 | /* The unlock didn't work, clear the reset */ |
| 287 | writel_relaxed(0x0, MSS_MODEM_RESET); |
| 288 | mb(); |
| 289 | |
| 290 | subsystem_restart_dev(drv->subsys); |
| 291 | enable_irq(drv->irq); |
| 292 | } |
| 293 | |
| 294 | static void modem_fatal_fn(struct work_struct *work) |
| 295 | { |
| 296 | u32 modem_state; |
| 297 | u32 panic_smsm_states = SMSM_RESET | SMSM_SYSTEM_DOWNLOAD; |
| 298 | u32 reset_smsm_states = SMSM_SYSTEM_REBOOT_USR | SMSM_SYSTEM_PWRDWN_USR; |
| 299 | struct modem_data *drv; |
| 300 | |
| 301 | drv = container_of(work, struct modem_data, fatal_work); |
| 302 | |
| 303 | pr_err("Watchdog bite received from modem!\n"); |
| 304 | |
| 305 | modem_state = smsm_get_state(SMSM_MODEM_STATE); |
| 306 | pr_err("Modem SMSM state = 0x%x!\n", modem_state); |
| 307 | |
| 308 | if (modem_state == 0 || modem_state & panic_smsm_states) { |
| 309 | subsystem_restart_dev(drv->subsys); |
| 310 | enable_irq(drv->irq); |
| 311 | } else if (modem_state & reset_smsm_states) { |
| 312 | pr_err("User-invoked system reset/powerdown."); |
| 313 | kernel_restart(NULL); |
| 314 | } else { |
| 315 | unsigned long timeout = msecs_to_jiffies(6000); |
| 316 | |
| 317 | pr_err("Modem AHB locked up. Trying to free up modem!\n"); |
| 318 | |
| 319 | writel_relaxed(0x3, MSS_MODEM_RESET); |
| 320 | /* |
| 321 | * If we are still alive (allowing for the 5 second |
| 322 | * delayed-panic-reboot), the modem is either still wedged or |
| 323 | * SMSM didn't come through. Force panic in that case. |
| 324 | */ |
| 325 | schedule_delayed_work(&drv->unlock_work, timeout); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | static int modem_notif_handler(struct notifier_block *nb, unsigned long code, |
| 330 | void *p) |
| 331 | { |
| 332 | struct modem_data *drv = container_of(nb, struct modem_data, notifier); |
| 333 | |
| 334 | if (code == MODEM_NOTIFIER_START_RESET) { |
| 335 | if (drv->ignore_smsm_ack) { |
| 336 | drv->ignore_smsm_ack = 0; |
| 337 | } else { |
| 338 | pr_err("Modem error fatal'ed."); |
| 339 | subsystem_restart_dev(drv->subsys); |
| 340 | } |
| 341 | } |
| 342 | return NOTIFY_DONE; |
| 343 | } |
| 344 | |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame^] | 345 | static int modem_start(const struct subsys_desc *subsys) |
| 346 | { |
| 347 | void *ret; |
| 348 | struct modem_data *drv; |
| 349 | |
| 350 | drv = container_of(subsys, struct modem_data, subsys_desc); |
| 351 | ret = pil_get("modem"); |
| 352 | if (IS_ERR(ret)) |
| 353 | return PTR_ERR(ret); |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | static void modem_stop(const struct subsys_desc *subsys) |
| 358 | { |
| 359 | struct modem_data *drv; |
| 360 | |
| 361 | drv = container_of(subsys, struct modem_data, subsys_desc); |
| 362 | pil_put(drv->pil); |
| 363 | } |
| 364 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 365 | static int modem_shutdown(const struct subsys_desc *subsys) |
| 366 | { |
| 367 | struct modem_data *drv; |
| 368 | |
| 369 | drv = container_of(subsys, struct modem_data, subsys_desc); |
| 370 | /* |
| 371 | * If the modem didn't already crash, setting SMSM_RESET here will help |
| 372 | * flush caches etc. The ignore_smsm_ack flag is set to ignore the |
| 373 | * SMSM_RESET notification that is generated due to the modem settings |
| 374 | * its own SMSM_RESET bit in response to the apps setting the apps |
| 375 | * SMSM_RESET bit. |
| 376 | */ |
| 377 | if (!(smsm_get_state(SMSM_MODEM_STATE) & SMSM_RESET)) { |
| 378 | drv->ignore_smsm_ack = 1; |
| 379 | smsm_reset_modem(SMSM_RESET); |
| 380 | } |
| 381 | |
| 382 | /* Disable the modem watchdog to allow clean modem bootup */ |
| 383 | writel_relaxed(0x0, drv->wdog + 0x8); |
| 384 | /* |
| 385 | * The write above needs to go through before the modem is powered up |
| 386 | * again. |
| 387 | */ |
| 388 | mb(); |
| 389 | /* Wait here to allow the modem to clean up caches, etc. */ |
| 390 | msleep(20); |
| 391 | |
| 392 | pil_force_shutdown("modem"); |
| 393 | disable_irq_nosync(drv->irq); |
| 394 | |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | static int modem_powerup(const struct subsys_desc *subsys) |
| 399 | { |
| 400 | struct modem_data *drv; |
| 401 | int ret; |
| 402 | |
| 403 | drv = container_of(subsys, struct modem_data, subsys_desc); |
| 404 | ret = pil_force_boot("modem"); |
| 405 | enable_irq(drv->irq); |
| 406 | |
| 407 | return ret; |
| 408 | } |
| 409 | |
| 410 | /* FIXME: Get address, size from PIL */ |
| 411 | static struct ramdump_segment modem_segments[] = { |
| 412 | { 0x42F00000, 0x46000000 - 0x42F00000 }, |
| 413 | }; |
| 414 | |
| 415 | static int modem_ramdump(int enable, const struct subsys_desc *subsys) |
| 416 | { |
| 417 | struct modem_data *drv; |
| 418 | |
| 419 | drv = container_of(subsys, struct modem_data, subsys_desc); |
| 420 | if (enable) |
| 421 | return do_ramdump(drv->ramdump_dev, modem_segments, |
| 422 | ARRAY_SIZE(modem_segments)); |
| 423 | else |
| 424 | return 0; |
| 425 | } |
| 426 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 427 | static int __devinit pil_modem_driver_probe(struct platform_device *pdev) |
| 428 | { |
| 429 | struct modem_data *drv; |
| 430 | struct resource *res; |
| 431 | struct pil_desc *desc; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 432 | int ret; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 433 | |
| 434 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 435 | if (!res) |
| 436 | return -EINVAL; |
| 437 | |
| 438 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 439 | if (!drv) |
| 440 | return -ENOMEM; |
| 441 | platform_set_drvdata(pdev, drv); |
| 442 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 443 | drv->irq = platform_get_irq(pdev, 0); |
| 444 | if (drv->irq < 0) |
| 445 | return drv->irq; |
| 446 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 447 | drv->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
| 448 | if (!drv->base) |
| 449 | return -ENOMEM; |
| 450 | |
Stephen Boyd | b089569 | 2012-03-23 15:23:10 -0700 | [diff] [blame] | 451 | drv->xo = devm_clk_get(&pdev->dev, "xo"); |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 452 | if (IS_ERR(drv->xo)) |
| 453 | return PTR_ERR(drv->xo); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 454 | |
| 455 | desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL); |
| 456 | if (!desc) |
| 457 | return -ENOMEM; |
| 458 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 459 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 460 | if (!res) |
| 461 | return -EINVAL; |
| 462 | |
| 463 | drv->wdog = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
| 464 | if (!drv->wdog) |
| 465 | return -ENOMEM; |
| 466 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 467 | desc->name = "modem"; |
| 468 | desc->depends_on = "q6"; |
| 469 | desc->dev = &pdev->dev; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 470 | desc->owner = THIS_MODULE; |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 471 | desc->proxy_timeout = 10000; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 472 | |
| 473 | if (pas_supported(PAS_MODEM) > 0) { |
| 474 | desc->ops = &pil_modem_ops_trusted; |
| 475 | dev_info(&pdev->dev, "using secure boot\n"); |
| 476 | } else { |
| 477 | desc->ops = &pil_modem_ops; |
| 478 | dev_info(&pdev->dev, "using non-secure boot\n"); |
| 479 | } |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 480 | drv->pil = msm_pil_register(desc); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 481 | if (IS_ERR(drv->pil)) |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 482 | return PTR_ERR(drv->pil); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 483 | |
| 484 | drv->notifier.notifier_call = modem_notif_handler, |
| 485 | ret = modem_register_notifier(&drv->notifier); |
| 486 | if (ret) |
| 487 | goto err_notify; |
| 488 | |
| 489 | drv->subsys_desc.name = "modem"; |
Stephen Boyd | 3e4e975 | 2012-06-27 12:46:32 -0700 | [diff] [blame^] | 490 | drv->subsys_desc.depends_on = "q6"; |
| 491 | drv->subsys_desc.dev = &pdev->dev; |
| 492 | drv->subsys_desc.owner = THIS_MODULE; |
| 493 | drv->subsys_desc.start = modem_start; |
| 494 | drv->subsys_desc.stop = modem_stop; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 495 | drv->subsys_desc.shutdown = modem_shutdown; |
| 496 | drv->subsys_desc.powerup = modem_powerup; |
| 497 | drv->subsys_desc.ramdump = modem_ramdump; |
| 498 | drv->subsys_desc.crash_shutdown = modem_crash_shutdown; |
| 499 | |
| 500 | INIT_WORK(&drv->fatal_work, modem_fatal_fn); |
| 501 | INIT_DELAYED_WORK(&drv->unlock_work, modem_unlock_timeout); |
| 502 | |
| 503 | drv->subsys = subsys_register(&drv->subsys_desc); |
| 504 | if (IS_ERR(drv->subsys)) { |
| 505 | ret = PTR_ERR(drv->subsys); |
| 506 | goto err_subsys; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 507 | } |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 508 | |
| 509 | drv->ramdump_dev = create_ramdump_device("modem"); |
| 510 | if (!drv->ramdump_dev) { |
| 511 | ret = -ENOMEM; |
| 512 | goto err_ramdump; |
| 513 | } |
| 514 | |
| 515 | ret = devm_request_irq(&pdev->dev, drv->irq, modem_wdog_bite_irq, |
| 516 | IRQF_TRIGGER_RISING, "modem_watchdog", drv); |
| 517 | if (ret) |
| 518 | goto err_irq; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 519 | return 0; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 520 | |
| 521 | err_irq: |
| 522 | destroy_ramdump_device(drv->ramdump_dev); |
| 523 | err_ramdump: |
| 524 | subsys_unregister(drv->subsys); |
| 525 | err_subsys: |
| 526 | modem_unregister_notifier(&drv->notifier); |
| 527 | err_notify: |
| 528 | msm_pil_unregister(drv->pil); |
| 529 | return ret; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | static int __devexit pil_modem_driver_exit(struct platform_device *pdev) |
| 533 | { |
| 534 | struct modem_data *drv = platform_get_drvdata(pdev); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 535 | |
| 536 | destroy_ramdump_device(drv->ramdump_dev); |
| 537 | subsys_unregister(drv->subsys); |
| 538 | modem_unregister_notifier(&drv->notifier); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 539 | msm_pil_unregister(drv->pil); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame] | 540 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | static struct platform_driver pil_modem_driver = { |
| 545 | .probe = pil_modem_driver_probe, |
| 546 | .remove = __devexit_p(pil_modem_driver_exit), |
| 547 | .driver = { |
| 548 | .name = "pil_modem", |
| 549 | .owner = THIS_MODULE, |
| 550 | }, |
| 551 | }; |
| 552 | |
| 553 | static int __init pil_modem_init(void) |
| 554 | { |
| 555 | return platform_driver_register(&pil_modem_driver); |
| 556 | } |
| 557 | module_init(pil_modem_init); |
| 558 | |
| 559 | static void __exit pil_modem_exit(void) |
| 560 | { |
| 561 | platform_driver_unregister(&pil_modem_driver); |
| 562 | } |
| 563 | module_exit(pil_modem_exit); |
| 564 | |
| 565 | MODULE_DESCRIPTION("Support for booting modem processors"); |
| 566 | MODULE_LICENSE("GPL v2"); |