blob: 94f545e07b09a5790dc1df2e7dc93f6f278df085 [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>
18#include <linux/elf.h>
19#include <linux/delay.h>
20#include <linux/err.h>
Stephen Boyd67036532012-01-26 15:43:51 -080021#include <linux/clk.h>
Stephen Boyd3ac20732012-05-03 18:46:08 -070022#include <linux/irq.h>
23#include <linux/interrupt.h>
24#include <linux/reboot.h>
Stephen Boyd4eb885b2011-09-29 01:16:03 -070025
26#include <mach/msm_iomap.h>
Stephen Boyd3ac20732012-05-03 18:46:08 -070027#include <mach/subsystem_restart.h>
28#include <mach/msm_smsm.h>
Stephen Boyd4eb885b2011-09-29 01:16:03 -070029
Stephen Boyd3ac20732012-05-03 18:46:08 -070030#include "modem_notifier.h"
Stephen Boyd4eb885b2011-09-29 01:16:03 -070031#include "peripheral-loader.h"
32#include "scm-pas.h"
Stephen Boyd3ac20732012-05-03 18:46:08 -070033#include "ramdump.h"
Stephen Boyd4eb885b2011-09-29 01:16:03 -070034
35#define MARM_BOOT_CONTROL 0x0010
36#define MARM_RESET (MSM_CLK_CTL_BASE + 0x2BD4)
37#define MAHB0_SFAB_PORT_RESET (MSM_CLK_CTL_BASE + 0x2304)
38#define MARM_CLK_BRANCH_ENA_VOTE (MSM_CLK_CTL_BASE + 0x3000)
39#define MARM_CLK_SRC0_NS (MSM_CLK_CTL_BASE + 0x2BC0)
40#define MARM_CLK_SRC1_NS (MSM_CLK_CTL_BASE + 0x2BC4)
41#define MARM_CLK_SRC_CTL (MSM_CLK_CTL_BASE + 0x2BC8)
42#define MARM_CLK_CTL (MSM_CLK_CTL_BASE + 0x2BCC)
43#define SFAB_MSS_S_HCLK_CTL (MSM_CLK_CTL_BASE + 0x2C00)
44#define MSS_MODEM_CXO_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C44)
45#define MSS_SLP_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C60)
46#define MSS_MARM_SYS_REF_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C64)
47#define MAHB0_CLK_CTL (MSM_CLK_CTL_BASE + 0x2300)
48#define MAHB1_CLK_CTL (MSM_CLK_CTL_BASE + 0x2BE4)
49#define MAHB2_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C20)
50#define MAHB1_NS (MSM_CLK_CTL_BASE + 0x2BE0)
51#define MARM_CLK_FS (MSM_CLK_CTL_BASE + 0x2BD0)
52#define MAHB2_CLK_FS (MSM_CLK_CTL_BASE + 0x2C24)
53#define PLL_ENA_MARM (MSM_CLK_CTL_BASE + 0x3500)
54#define PLL8_STATUS (MSM_CLK_CTL_BASE + 0x3158)
55#define CLK_HALT_MSS_SMPSS_MISC_STATE (MSM_CLK_CTL_BASE + 0x2FDC)
Stephen Boyd3ac20732012-05-03 18:46:08 -070056#define MSS_MODEM_RESET (MSM_CLK_CTL_BASE + 0x2C48)
Stephen Boyd4eb885b2011-09-29 01:16:03 -070057
Stephen Boyd4eb885b2011-09-29 01:16:03 -070058struct modem_data {
59 void __iomem *base;
Stephen Boyd3ac20732012-05-03 18:46:08 -070060 void __iomem *wdog;
Stephen Boyd4eb885b2011-09-29 01:16:03 -070061 unsigned long start_addr;
Stephen Boyd6d67d252011-09-27 11:50:05 -070062 struct pil_device *pil;
Stephen Boyd67036532012-01-26 15:43:51 -080063 struct clk *xo;
Stephen Boyd3ac20732012-05-03 18:46:08 -070064 struct notifier_block notifier;
65 int ignore_smsm_ack;
66 int irq;
Stephen Boyde83a0a22012-06-29 13:51:27 -070067 struct pil_desc pil_desc;
Stephen Boyd3ac20732012-05-03 18:46:08 -070068 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 Boyd4eb885b2011-09-29 01:16:03 -070073};
74
Stephen Boyd06aba622012-03-22 10:59:22 -070075static int make_modem_proxy_votes(struct pil_desc *pil)
Stephen Boyd4eb885b2011-09-29 01:16:03 -070076{
77 int ret;
Stephen Boyd06aba622012-03-22 10:59:22 -070078 struct modem_data *drv = dev_get_drvdata(pil->dev);
Stephen Boyd4eb885b2011-09-29 01:16:03 -070079
Stephen Boyd67036532012-01-26 15:43:51 -080080 ret = clk_prepare_enable(drv->xo);
81 if (ret) {
Stephen Boyd06aba622012-03-22 10:59:22 -070082 dev_err(pil->dev, "Failed to enable XO\n");
Stephen Boyd67036532012-01-26 15:43:51 -080083 return ret;
84 }
Stephen Boyd67036532012-01-26 15:43:51 -080085 return 0;
86}
87
Stephen Boyd06aba622012-03-22 10:59:22 -070088static void remove_modem_proxy_votes(struct pil_desc *pil)
Stephen Boyd67036532012-01-26 15:43:51 -080089{
Stephen Boyd06aba622012-03-22 10:59:22 -070090 struct modem_data *drv = dev_get_drvdata(pil->dev);
Stephen Boyd67036532012-01-26 15:43:51 -080091 clk_disable_unprepare(drv->xo);
Stephen Boyd4eb885b2011-09-29 01:16:03 -070092}
93
Stephen Boyd4eb885b2011-09-29 01:16:03 -070094static 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
103static int modem_reset(struct pil_desc *pil)
104{
105 u32 reg;
106 const struct modem_data *drv = dev_get_drvdata(pil->dev);
107
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700108 /* 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 Boyd3ac20732012-05-03 18:46:08 -0700182static int modem_pil_shutdown(struct pil_desc *pil)
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700183{
184 u32 reg;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700185
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 Boyd4eb885b2011-09-29 01:16:03 -0700218 return 0;
219}
220
221static struct pil_reset_ops pil_modem_ops = {
222 .init_image = modem_init_image,
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700223 .auth_and_reset = modem_reset,
Stephen Boyd3ac20732012-05-03 18:46:08 -0700224 .shutdown = modem_pil_shutdown,
Stephen Boyd06aba622012-03-22 10:59:22 -0700225 .proxy_vote = make_modem_proxy_votes,
226 .proxy_unvote = remove_modem_proxy_votes,
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700227};
228
229static 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
235static int modem_reset_trusted(struct pil_desc *pil)
236{
Stephen Boyd06aba622012-03-22 10:59:22 -0700237 return pas_auth_and_reset(PAS_MODEM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700238}
239
240static int modem_shutdown_trusted(struct pil_desc *pil)
241{
Stephen Boyd06aba622012-03-22 10:59:22 -0700242 return pas_shutdown(PAS_MODEM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700243}
244
245static struct pil_reset_ops pil_modem_ops_trusted = {
246 .init_image = modem_init_image_trusted,
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700247 .auth_and_reset = modem_reset_trusted,
248 .shutdown = modem_shutdown_trusted,
Stephen Boyd06aba622012-03-22 10:59:22 -0700249 .proxy_vote = make_modem_proxy_votes,
250 .proxy_unvote = remove_modem_proxy_votes,
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700251};
252
Stephen Boyd3ac20732012-05-03 18:46:08 -0700253static 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
268static 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
278static 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
294static 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
329static 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 Boyd3e4e9752012-06-27 12:46:32 -0700345static int modem_start(const struct subsys_desc *subsys)
346{
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700347 struct modem_data *drv;
348
349 drv = container_of(subsys, struct modem_data, subsys_desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700350 return pil_boot(&drv->pil_desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700351}
352
353static void modem_stop(const struct subsys_desc *subsys)
354{
355 struct modem_data *drv;
356
357 drv = container_of(subsys, struct modem_data, subsys_desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700358 pil_shutdown(&drv->pil_desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700359}
360
Stephen Boyd3ac20732012-05-03 18:46:08 -0700361static int modem_shutdown(const struct subsys_desc *subsys)
362{
363 struct modem_data *drv;
364
365 drv = container_of(subsys, struct modem_data, subsys_desc);
366 /*
367 * If the modem didn't already crash, setting SMSM_RESET here will help
368 * flush caches etc. The ignore_smsm_ack flag is set to ignore the
369 * SMSM_RESET notification that is generated due to the modem settings
370 * its own SMSM_RESET bit in response to the apps setting the apps
371 * SMSM_RESET bit.
372 */
373 if (!(smsm_get_state(SMSM_MODEM_STATE) & SMSM_RESET)) {
374 drv->ignore_smsm_ack = 1;
375 smsm_reset_modem(SMSM_RESET);
376 }
377
378 /* Disable the modem watchdog to allow clean modem bootup */
379 writel_relaxed(0x0, drv->wdog + 0x8);
380 /*
381 * The write above needs to go through before the modem is powered up
382 * again.
383 */
384 mb();
385 /* Wait here to allow the modem to clean up caches, etc. */
386 msleep(20);
387
Stephen Boyde83a0a22012-06-29 13:51:27 -0700388 pil_shutdown(&drv->pil_desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700389 disable_irq_nosync(drv->irq);
390
391 return 0;
392}
393
394static int modem_powerup(const struct subsys_desc *subsys)
395{
396 struct modem_data *drv;
397 int ret;
398
399 drv = container_of(subsys, struct modem_data, subsys_desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700400 ret = pil_boot(&drv->pil_desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700401 enable_irq(drv->irq);
402
403 return ret;
404}
405
406/* FIXME: Get address, size from PIL */
407static struct ramdump_segment modem_segments[] = {
408 { 0x42F00000, 0x46000000 - 0x42F00000 },
409};
410
411static int modem_ramdump(int enable, const struct subsys_desc *subsys)
412{
413 struct modem_data *drv;
414
415 drv = container_of(subsys, struct modem_data, subsys_desc);
416 if (enable)
417 return do_ramdump(drv->ramdump_dev, modem_segments,
418 ARRAY_SIZE(modem_segments));
419 else
420 return 0;
421}
422
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700423static int __devinit pil_modem_driver_probe(struct platform_device *pdev)
424{
425 struct modem_data *drv;
426 struct resource *res;
427 struct pil_desc *desc;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700428 int ret;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700429
430 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
431 if (!res)
432 return -EINVAL;
433
434 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
435 if (!drv)
436 return -ENOMEM;
437 platform_set_drvdata(pdev, drv);
438
Stephen Boyd3ac20732012-05-03 18:46:08 -0700439 drv->irq = platform_get_irq(pdev, 0);
440 if (drv->irq < 0)
441 return drv->irq;
442
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700443 drv->base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
444 if (!drv->base)
445 return -ENOMEM;
446
Stephen Boydb0895692012-03-23 15:23:10 -0700447 drv->xo = devm_clk_get(&pdev->dev, "xo");
Stephen Boyd67036532012-01-26 15:43:51 -0800448 if (IS_ERR(drv->xo))
449 return PTR_ERR(drv->xo);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700450
Stephen Boyd3ac20732012-05-03 18:46:08 -0700451 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
452 if (!res)
453 return -EINVAL;
454
455 drv->wdog = devm_ioremap(&pdev->dev, res->start, resource_size(res));
456 if (!drv->wdog)
457 return -ENOMEM;
458
Stephen Boyde83a0a22012-06-29 13:51:27 -0700459 desc = &drv->pil_desc;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700460 desc->name = "modem";
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700461 desc->dev = &pdev->dev;
Stephen Boyd6d67d252011-09-27 11:50:05 -0700462 desc->owner = THIS_MODULE;
Stephen Boyd06aba622012-03-22 10:59:22 -0700463 desc->proxy_timeout = 10000;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700464
465 if (pas_supported(PAS_MODEM) > 0) {
466 desc->ops = &pil_modem_ops_trusted;
467 dev_info(&pdev->dev, "using secure boot\n");
468 } else {
469 desc->ops = &pil_modem_ops;
470 dev_info(&pdev->dev, "using non-secure boot\n");
471 }
Stephen Boyde83a0a22012-06-29 13:51:27 -0700472 ret = pil_desc_init(desc);
473 if (ret)
474 return ret;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700475
476 drv->notifier.notifier_call = modem_notif_handler,
477 ret = modem_register_notifier(&drv->notifier);
478 if (ret)
479 goto err_notify;
480
481 drv->subsys_desc.name = "modem";
Stephen Boyd77db8bb2012-06-27 15:15:16 -0700482 drv->subsys_desc.depends_on = "adsp";
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700483 drv->subsys_desc.dev = &pdev->dev;
484 drv->subsys_desc.owner = THIS_MODULE;
485 drv->subsys_desc.start = modem_start;
486 drv->subsys_desc.stop = modem_stop;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700487 drv->subsys_desc.shutdown = modem_shutdown;
488 drv->subsys_desc.powerup = modem_powerup;
489 drv->subsys_desc.ramdump = modem_ramdump;
490 drv->subsys_desc.crash_shutdown = modem_crash_shutdown;
491
492 INIT_WORK(&drv->fatal_work, modem_fatal_fn);
493 INIT_DELAYED_WORK(&drv->unlock_work, modem_unlock_timeout);
494
495 drv->subsys = subsys_register(&drv->subsys_desc);
496 if (IS_ERR(drv->subsys)) {
497 ret = PTR_ERR(drv->subsys);
498 goto err_subsys;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700499 }
Stephen Boyd3ac20732012-05-03 18:46:08 -0700500
Stephen Boydc1a72612012-07-05 14:07:35 -0700501 drv->ramdump_dev = create_ramdump_device("modem", &pdev->dev);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700502 if (!drv->ramdump_dev) {
503 ret = -ENOMEM;
504 goto err_ramdump;
505 }
506
507 ret = devm_request_irq(&pdev->dev, drv->irq, modem_wdog_bite_irq,
508 IRQF_TRIGGER_RISING, "modem_watchdog", drv);
509 if (ret)
510 goto err_irq;
Stephen Boyd6d67d252011-09-27 11:50:05 -0700511 return 0;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700512
513err_irq:
514 destroy_ramdump_device(drv->ramdump_dev);
515err_ramdump:
516 subsys_unregister(drv->subsys);
517err_subsys:
518 modem_unregister_notifier(&drv->notifier);
519err_notify:
Stephen Boyde83a0a22012-06-29 13:51:27 -0700520 pil_desc_release(desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700521 return ret;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700522}
523
524static int __devexit pil_modem_driver_exit(struct platform_device *pdev)
525{
526 struct modem_data *drv = platform_get_drvdata(pdev);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700527
528 destroy_ramdump_device(drv->ramdump_dev);
529 subsys_unregister(drv->subsys);
530 modem_unregister_notifier(&drv->notifier);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700531 pil_desc_release(&drv->pil_desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700532
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700533 return 0;
534}
535
536static struct platform_driver pil_modem_driver = {
537 .probe = pil_modem_driver_probe,
538 .remove = __devexit_p(pil_modem_driver_exit),
539 .driver = {
540 .name = "pil_modem",
541 .owner = THIS_MODULE,
542 },
543};
544
545static int __init pil_modem_init(void)
546{
547 return platform_driver_register(&pil_modem_driver);
548}
549module_init(pil_modem_init);
550
551static void __exit pil_modem_exit(void)
552{
553 platform_driver_unregister(&pil_modem_driver);
554}
555module_exit(pil_modem_exit);
556
557MODULE_DESCRIPTION("Support for booting modem processors");
558MODULE_LICENSE("GPL v2");