blob: 00b5024ea51887777c1aa1eadbc641b0020ce851 [file] [log] [blame]
Stephen Boyd67036532012-01-26 15:43:51 -08001/* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
Stephen Boyd4eb885b2011-09-29 01:16:03 -07002 *
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 Boyd4eb885b2011-09-29 01:16:03 -070018#include <linux/delay.h>
19#include <linux/err.h>
Stephen Boyd67036532012-01-26 15:43:51 -080020#include <linux/clk.h>
Stephen Boyd3ac20732012-05-03 18:46:08 -070021#include <linux/irq.h>
22#include <linux/interrupt.h>
23#include <linux/reboot.h>
Stephen Boyd4eb885b2011-09-29 01:16:03 -070024
25#include <mach/msm_iomap.h>
Stephen Boyd3ac20732012-05-03 18:46:08 -070026#include <mach/subsystem_restart.h>
27#include <mach/msm_smsm.h>
Stephen Boyd4eb885b2011-09-29 01:16:03 -070028
Stephen Boyd3ac20732012-05-03 18:46:08 -070029#include "modem_notifier.h"
Stephen Boyd4eb885b2011-09-29 01:16:03 -070030#include "peripheral-loader.h"
31#include "scm-pas.h"
Stephen Boyd3ac20732012-05-03 18:46:08 -070032#include "ramdump.h"
Stephen Boyd4eb885b2011-09-29 01:16:03 -070033
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 Boyd3ac20732012-05-03 18:46:08 -070055#define MSS_MODEM_RESET (MSM_CLK_CTL_BASE + 0x2C48)
Stephen Boyd4eb885b2011-09-29 01:16:03 -070056
Stephen Boyd4eb885b2011-09-29 01:16:03 -070057struct modem_data {
58 void __iomem *base;
Stephen Boyd3ac20732012-05-03 18:46:08 -070059 void __iomem *wdog;
Stephen Boyd6d67d252011-09-27 11:50:05 -070060 struct pil_device *pil;
Stephen Boyd67036532012-01-26 15:43:51 -080061 struct clk *xo;
Stephen Boyd3ac20732012-05-03 18:46:08 -070062 struct notifier_block notifier;
63 int ignore_smsm_ack;
64 int irq;
Stephen Boyde83a0a22012-06-29 13:51:27 -070065 struct pil_desc pil_desc;
Stephen Boyd3ac20732012-05-03 18:46:08 -070066 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 Boyd4eb885b2011-09-29 01:16:03 -070071};
72
Stephen Boyd06aba622012-03-22 10:59:22 -070073static int make_modem_proxy_votes(struct pil_desc *pil)
Stephen Boyd4eb885b2011-09-29 01:16:03 -070074{
75 int ret;
Stephen Boyd06aba622012-03-22 10:59:22 -070076 struct modem_data *drv = dev_get_drvdata(pil->dev);
Stephen Boyd4eb885b2011-09-29 01:16:03 -070077
Stephen Boyd67036532012-01-26 15:43:51 -080078 ret = clk_prepare_enable(drv->xo);
79 if (ret) {
Stephen Boyd06aba622012-03-22 10:59:22 -070080 dev_err(pil->dev, "Failed to enable XO\n");
Stephen Boyd67036532012-01-26 15:43:51 -080081 return ret;
82 }
Stephen Boyd67036532012-01-26 15:43:51 -080083 return 0;
84}
85
Stephen Boyd06aba622012-03-22 10:59:22 -070086static void remove_modem_proxy_votes(struct pil_desc *pil)
Stephen Boyd67036532012-01-26 15:43:51 -080087{
Stephen Boyd06aba622012-03-22 10:59:22 -070088 struct modem_data *drv = dev_get_drvdata(pil->dev);
Stephen Boyd67036532012-01-26 15:43:51 -080089 clk_disable_unprepare(drv->xo);
Stephen Boyd4eb885b2011-09-29 01:16:03 -070090}
91
Stephen Boyd4eb885b2011-09-29 01:16:03 -070092static int modem_reset(struct pil_desc *pil)
93{
94 u32 reg;
95 const struct modem_data *drv = dev_get_drvdata(pil->dev);
Stephen Boyd3030c252012-08-08 17:24:05 -070096 unsigned long start_addr = pil_get_entry_addr(pil);
Stephen Boyd4eb885b2011-09-29 01:16:03 -070097
Stephen Boyd4eb885b2011-09-29 01:16:03 -070098 /* 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 Boyd3030c252012-08-08 17:24:05 -0700161 writel_relaxed(start_addr | 0x1, drv->base + MARM_BOOT_CONTROL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700162
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 Boyd3ac20732012-05-03 18:46:08 -0700172static int modem_pil_shutdown(struct pil_desc *pil)
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700173{
174 u32 reg;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700175
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 Boyd4eb885b2011-09-29 01:16:03 -0700208 return 0;
209}
210
211static struct pil_reset_ops pil_modem_ops = {
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700212 .auth_and_reset = modem_reset,
Stephen Boyd3ac20732012-05-03 18:46:08 -0700213 .shutdown = modem_pil_shutdown,
Stephen Boyd06aba622012-03-22 10:59:22 -0700214 .proxy_vote = make_modem_proxy_votes,
215 .proxy_unvote = remove_modem_proxy_votes,
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700216};
217
218static 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
224static int modem_reset_trusted(struct pil_desc *pil)
225{
Stephen Boyd06aba622012-03-22 10:59:22 -0700226 return pas_auth_and_reset(PAS_MODEM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700227}
228
229static int modem_shutdown_trusted(struct pil_desc *pil)
230{
Stephen Boyd06aba622012-03-22 10:59:22 -0700231 return pas_shutdown(PAS_MODEM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700232}
233
234static struct pil_reset_ops pil_modem_ops_trusted = {
235 .init_image = modem_init_image_trusted,
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700236 .auth_and_reset = modem_reset_trusted,
237 .shutdown = modem_shutdown_trusted,
Stephen Boyd06aba622012-03-22 10:59:22 -0700238 .proxy_vote = make_modem_proxy_votes,
239 .proxy_unvote = remove_modem_proxy_votes,
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700240};
241
Stephen Boyd3ac20732012-05-03 18:46:08 -0700242static 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
257static 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
267static 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
283static 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
318static 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 Boyd3e4e9752012-06-27 12:46:32 -0700334static int modem_start(const struct subsys_desc *subsys)
335{
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700336 struct modem_data *drv;
337
338 drv = container_of(subsys, struct modem_data, subsys_desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700339 return pil_boot(&drv->pil_desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700340}
341
342static 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 Boyde83a0a22012-06-29 13:51:27 -0700347 pil_shutdown(&drv->pil_desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700348}
349
Stephen Boyd3ac20732012-05-03 18:46:08 -0700350static 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 Boyde83a0a22012-06-29 13:51:27 -0700377 pil_shutdown(&drv->pil_desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700378 disable_irq_nosync(drv->irq);
379
380 return 0;
381}
382
383static 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 Boyde83a0a22012-06-29 13:51:27 -0700389 ret = pil_boot(&drv->pil_desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700390 enable_irq(drv->irq);
391
392 return ret;
393}
394
395/* FIXME: Get address, size from PIL */
396static struct ramdump_segment modem_segments[] = {
397 { 0x42F00000, 0x46000000 - 0x42F00000 },
398};
399
400static 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 Boyd4eb885b2011-09-29 01:16:03 -0700412static 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 Boyd3ac20732012-05-03 18:46:08 -0700417 int ret;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700418
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 Boyd3ac20732012-05-03 18:46:08 -0700428 drv->irq = platform_get_irq(pdev, 0);
429 if (drv->irq < 0)
430 return drv->irq;
431
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700432 drv->base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
433 if (!drv->base)
434 return -ENOMEM;
435
Stephen Boydb0895692012-03-23 15:23:10 -0700436 drv->xo = devm_clk_get(&pdev->dev, "xo");
Stephen Boyd67036532012-01-26 15:43:51 -0800437 if (IS_ERR(drv->xo))
438 return PTR_ERR(drv->xo);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700439
Stephen Boyd3ac20732012-05-03 18:46:08 -0700440 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 Boyde83a0a22012-06-29 13:51:27 -0700448 desc = &drv->pil_desc;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700449 desc->name = "modem";
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700450 desc->dev = &pdev->dev;
Stephen Boyd6d67d252011-09-27 11:50:05 -0700451 desc->owner = THIS_MODULE;
Stephen Boyd06aba622012-03-22 10:59:22 -0700452 desc->proxy_timeout = 10000;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700453
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 Boyde83a0a22012-06-29 13:51:27 -0700461 ret = pil_desc_init(desc);
462 if (ret)
463 return ret;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700464
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 Boyd77db8bb2012-06-27 15:15:16 -0700471 drv->subsys_desc.depends_on = "adsp";
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700472 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 Boyd3ac20732012-05-03 18:46:08 -0700476 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 Boyd4eb885b2011-09-29 01:16:03 -0700488 }
Stephen Boyd3ac20732012-05-03 18:46:08 -0700489
Stephen Boydc1a72612012-07-05 14:07:35 -0700490 drv->ramdump_dev = create_ramdump_device("modem", &pdev->dev);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700491 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 Boyd6d67d252011-09-27 11:50:05 -0700500 return 0;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700501
502err_irq:
503 destroy_ramdump_device(drv->ramdump_dev);
504err_ramdump:
505 subsys_unregister(drv->subsys);
506err_subsys:
507 modem_unregister_notifier(&drv->notifier);
508err_notify:
Stephen Boyde83a0a22012-06-29 13:51:27 -0700509 pil_desc_release(desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700510 return ret;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700511}
512
513static int __devexit pil_modem_driver_exit(struct platform_device *pdev)
514{
515 struct modem_data *drv = platform_get_drvdata(pdev);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700516
517 destroy_ramdump_device(drv->ramdump_dev);
518 subsys_unregister(drv->subsys);
519 modem_unregister_notifier(&drv->notifier);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700520 pil_desc_release(&drv->pil_desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700521
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700522 return 0;
523}
524
525static 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
534static int __init pil_modem_init(void)
535{
536 return platform_driver_register(&pil_modem_driver);
537}
538module_init(pil_modem_init);
539
540static void __exit pil_modem_exit(void)
541{
542 platform_driver_unregister(&pil_modem_driver);
543}
544module_exit(pil_modem_exit);
545
546MODULE_DESCRIPTION("Support for booting modem processors");
547MODULE_LICENSE("GPL v2");