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 | |
| 345 | static int modem_shutdown(const struct subsys_desc *subsys) |
| 346 | { |
| 347 | struct modem_data *drv; |
| 348 | |
| 349 | drv = container_of(subsys, struct modem_data, subsys_desc); |
| 350 | /* |
| 351 | * If the modem didn't already crash, setting SMSM_RESET here will help |
| 352 | * flush caches etc. The ignore_smsm_ack flag is set to ignore the |
| 353 | * SMSM_RESET notification that is generated due to the modem settings |
| 354 | * its own SMSM_RESET bit in response to the apps setting the apps |
| 355 | * SMSM_RESET bit. |
| 356 | */ |
| 357 | if (!(smsm_get_state(SMSM_MODEM_STATE) & SMSM_RESET)) { |
| 358 | drv->ignore_smsm_ack = 1; |
| 359 | smsm_reset_modem(SMSM_RESET); |
| 360 | } |
| 361 | |
| 362 | /* Disable the modem watchdog to allow clean modem bootup */ |
| 363 | writel_relaxed(0x0, drv->wdog + 0x8); |
| 364 | /* |
| 365 | * The write above needs to go through before the modem is powered up |
| 366 | * again. |
| 367 | */ |
| 368 | mb(); |
| 369 | /* Wait here to allow the modem to clean up caches, etc. */ |
| 370 | msleep(20); |
| 371 | |
| 372 | pil_force_shutdown("modem"); |
| 373 | disable_irq_nosync(drv->irq); |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | static int modem_powerup(const struct subsys_desc *subsys) |
| 379 | { |
| 380 | struct modem_data *drv; |
| 381 | int ret; |
| 382 | |
| 383 | drv = container_of(subsys, struct modem_data, subsys_desc); |
| 384 | ret = pil_force_boot("modem"); |
| 385 | enable_irq(drv->irq); |
| 386 | |
| 387 | return ret; |
| 388 | } |
| 389 | |
| 390 | /* FIXME: Get address, size from PIL */ |
| 391 | static struct ramdump_segment modem_segments[] = { |
| 392 | { 0x42F00000, 0x46000000 - 0x42F00000 }, |
| 393 | }; |
| 394 | |
| 395 | static int modem_ramdump(int enable, const struct subsys_desc *subsys) |
| 396 | { |
| 397 | struct modem_data *drv; |
| 398 | |
| 399 | drv = container_of(subsys, struct modem_data, subsys_desc); |
| 400 | if (enable) |
| 401 | return do_ramdump(drv->ramdump_dev, modem_segments, |
| 402 | ARRAY_SIZE(modem_segments)); |
| 403 | else |
| 404 | return 0; |
| 405 | } |
| 406 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 407 | static int __devinit pil_modem_driver_probe(struct platform_device *pdev) |
| 408 | { |
| 409 | struct modem_data *drv; |
| 410 | struct resource *res; |
| 411 | struct pil_desc *desc; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame^] | 412 | int ret; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 413 | |
| 414 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 415 | if (!res) |
| 416 | return -EINVAL; |
| 417 | |
| 418 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 419 | if (!drv) |
| 420 | return -ENOMEM; |
| 421 | platform_set_drvdata(pdev, drv); |
| 422 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame^] | 423 | drv->irq = platform_get_irq(pdev, 0); |
| 424 | if (drv->irq < 0) |
| 425 | return drv->irq; |
| 426 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 427 | drv->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
| 428 | if (!drv->base) |
| 429 | return -ENOMEM; |
| 430 | |
Stephen Boyd | b089569 | 2012-03-23 15:23:10 -0700 | [diff] [blame] | 431 | drv->xo = devm_clk_get(&pdev->dev, "xo"); |
Stephen Boyd | 6703653 | 2012-01-26 15:43:51 -0800 | [diff] [blame] | 432 | if (IS_ERR(drv->xo)) |
| 433 | return PTR_ERR(drv->xo); |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 434 | |
| 435 | desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL); |
| 436 | if (!desc) |
| 437 | return -ENOMEM; |
| 438 | |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame^] | 439 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 440 | if (!res) |
| 441 | return -EINVAL; |
| 442 | |
| 443 | drv->wdog = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
| 444 | if (!drv->wdog) |
| 445 | return -ENOMEM; |
| 446 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 447 | desc->name = "modem"; |
| 448 | desc->depends_on = "q6"; |
| 449 | desc->dev = &pdev->dev; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 450 | desc->owner = THIS_MODULE; |
Stephen Boyd | 06aba62 | 2012-03-22 10:59:22 -0700 | [diff] [blame] | 451 | desc->proxy_timeout = 10000; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 452 | |
| 453 | if (pas_supported(PAS_MODEM) > 0) { |
| 454 | desc->ops = &pil_modem_ops_trusted; |
| 455 | dev_info(&pdev->dev, "using secure boot\n"); |
| 456 | } else { |
| 457 | desc->ops = &pil_modem_ops; |
| 458 | dev_info(&pdev->dev, "using non-secure boot\n"); |
| 459 | } |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 460 | drv->pil = msm_pil_register(desc); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame^] | 461 | if (IS_ERR(drv->pil)) |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 462 | return PTR_ERR(drv->pil); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame^] | 463 | |
| 464 | drv->notifier.notifier_call = modem_notif_handler, |
| 465 | ret = modem_register_notifier(&drv->notifier); |
| 466 | if (ret) |
| 467 | goto err_notify; |
| 468 | |
| 469 | drv->subsys_desc.name = "modem"; |
| 470 | drv->subsys_desc.shutdown = modem_shutdown; |
| 471 | drv->subsys_desc.powerup = modem_powerup; |
| 472 | drv->subsys_desc.ramdump = modem_ramdump; |
| 473 | drv->subsys_desc.crash_shutdown = modem_crash_shutdown; |
| 474 | |
| 475 | INIT_WORK(&drv->fatal_work, modem_fatal_fn); |
| 476 | INIT_DELAYED_WORK(&drv->unlock_work, modem_unlock_timeout); |
| 477 | |
| 478 | drv->subsys = subsys_register(&drv->subsys_desc); |
| 479 | if (IS_ERR(drv->subsys)) { |
| 480 | ret = PTR_ERR(drv->subsys); |
| 481 | goto err_subsys; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 482 | } |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame^] | 483 | |
| 484 | drv->ramdump_dev = create_ramdump_device("modem"); |
| 485 | if (!drv->ramdump_dev) { |
| 486 | ret = -ENOMEM; |
| 487 | goto err_ramdump; |
| 488 | } |
| 489 | |
| 490 | ret = devm_request_irq(&pdev->dev, drv->irq, modem_wdog_bite_irq, |
| 491 | IRQF_TRIGGER_RISING, "modem_watchdog", drv); |
| 492 | if (ret) |
| 493 | goto err_irq; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 494 | return 0; |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame^] | 495 | |
| 496 | err_irq: |
| 497 | destroy_ramdump_device(drv->ramdump_dev); |
| 498 | err_ramdump: |
| 499 | subsys_unregister(drv->subsys); |
| 500 | err_subsys: |
| 501 | modem_unregister_notifier(&drv->notifier); |
| 502 | err_notify: |
| 503 | msm_pil_unregister(drv->pil); |
| 504 | return ret; |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | static int __devexit pil_modem_driver_exit(struct platform_device *pdev) |
| 508 | { |
| 509 | struct modem_data *drv = platform_get_drvdata(pdev); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame^] | 510 | |
| 511 | destroy_ramdump_device(drv->ramdump_dev); |
| 512 | subsys_unregister(drv->subsys); |
| 513 | modem_unregister_notifier(&drv->notifier); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 514 | msm_pil_unregister(drv->pil); |
Stephen Boyd | 3ac2073 | 2012-05-03 18:46:08 -0700 | [diff] [blame^] | 515 | |
Stephen Boyd | 4eb885b | 2011-09-29 01:16:03 -0700 | [diff] [blame] | 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | static struct platform_driver pil_modem_driver = { |
| 520 | .probe = pil_modem_driver_probe, |
| 521 | .remove = __devexit_p(pil_modem_driver_exit), |
| 522 | .driver = { |
| 523 | .name = "pil_modem", |
| 524 | .owner = THIS_MODULE, |
| 525 | }, |
| 526 | }; |
| 527 | |
| 528 | static int __init pil_modem_init(void) |
| 529 | { |
| 530 | return platform_driver_register(&pil_modem_driver); |
| 531 | } |
| 532 | module_init(pil_modem_init); |
| 533 | |
| 534 | static void __exit pil_modem_exit(void) |
| 535 | { |
| 536 | platform_driver_unregister(&pil_modem_driver); |
| 537 | } |
| 538 | module_exit(pil_modem_exit); |
| 539 | |
| 540 | MODULE_DESCRIPTION("Support for booting modem processors"); |
| 541 | MODULE_LICENSE("GPL v2"); |