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