blob: 83982068bcdb84e53c1af894833be7e3758c9a9c [file] [log] [blame]
Seemanta Dutta4e2d49c2013-04-05 16:28:11 -07001/* Copyright (c) 2010-2013, The Linux Foundation. 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
Stephen Boyd3ac20732012-05-03 18:46:08 -070025#include <mach/subsystem_restart.h>
26#include <mach/msm_smsm.h>
Seemanta Dutta4e2d49c2013-04-05 16:28:11 -070027#include <mach/ramdump.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"
32
33#define MARM_BOOT_CONTROL 0x0010
Stephen Boyde24edf52012-07-12 17:46:19 -070034#define MARM_RESET 0x2BD4
35#define MAHB0_SFAB_PORT_RESET 0x2304
36#define MARM_CLK_BRANCH_ENA_VOTE 0x3000
37#define MARM_CLK_SRC0_NS 0x2BC0
38#define MARM_CLK_SRC1_NS 0x2BC4
39#define MARM_CLK_SRC_CTL 0x2BC8
40#define MARM_CLK_CTL 0x2BCC
41#define SFAB_MSS_S_HCLK_CTL 0x2C00
42#define MSS_MODEM_CXO_CLK_CTL 0x2C44
43#define MSS_SLP_CLK_CTL 0x2C60
44#define MSS_MARM_SYS_REF_CLK_CTL 0x2C64
45#define MAHB0_CLK_CTL 0x2300
46#define MAHB1_CLK_CTL 0x2BE4
47#define MAHB2_CLK_CTL 0x2C20
48#define MAHB1_NS 0x2BE0
49#define MARM_CLK_FS 0x2BD0
50#define MAHB2_CLK_FS 0x2C24
51#define PLL_ENA_MARM 0x3500
52#define PLL8_STATUS 0x3158
53#define CLK_HALT_MSS_SMPSS_MISC_STATE 0x2FDC
54#define MSS_MODEM_RESET 0x2C48
Stephen Boyd4eb885b2011-09-29 01:16:03 -070055
Stephen Boyd4eb885b2011-09-29 01:16:03 -070056struct modem_data {
57 void __iomem *base;
Stephen Boyd3ac20732012-05-03 18:46:08 -070058 void __iomem *wdog;
Stephen Boyde24edf52012-07-12 17:46:19 -070059 void __iomem *cbase;
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);
Tianyi Gou819851e2013-04-16 16:05:56 -070096 phys_addr_t 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 */
Stephen Boyde24edf52012-07-12 17:46:19 -070099 writel_relaxed(BIT(0) | BIT(1), drv->cbase + MAHB0_SFAB_PORT_RESET);
100 writel_relaxed(BIT(7), drv->cbase + MAHB1_CLK_CTL);
101 writel_relaxed(BIT(7), drv->cbase + MAHB2_CLK_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700102
103 /* Vote for pll8 on behalf of the modem */
Stephen Boyde24edf52012-07-12 17:46:19 -0700104 reg = readl_relaxed(drv->cbase + PLL_ENA_MARM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700105 reg |= BIT(8);
Stephen Boyde24edf52012-07-12 17:46:19 -0700106 writel_relaxed(reg, drv->cbase + PLL_ENA_MARM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700107
108 /* Wait for PLL8 to enable */
Stephen Boyde24edf52012-07-12 17:46:19 -0700109 while (!(readl_relaxed(drv->cbase + PLL8_STATUS) & BIT(16)))
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700110 cpu_relax();
111
112 /* Set MAHB1 divider to Div-5 to run MAHB1,2 and sfab at 79.8 Mhz*/
Stephen Boyde24edf52012-07-12 17:46:19 -0700113 writel_relaxed(0x4, drv->cbase + MAHB1_NS);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700114
115 /* Vote for modem AHB1 and 2 clocks to be on on behalf of the modem */
Stephen Boyde24edf52012-07-12 17:46:19 -0700116 reg = readl_relaxed(drv->cbase + MARM_CLK_BRANCH_ENA_VOTE);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700117 reg |= BIT(0) | BIT(1);
Stephen Boyde24edf52012-07-12 17:46:19 -0700118 writel_relaxed(reg, drv->cbase + MARM_CLK_BRANCH_ENA_VOTE);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700119
120 /* Source marm_clk off of PLL8 */
Stephen Boyde24edf52012-07-12 17:46:19 -0700121 reg = readl_relaxed(drv->cbase + MARM_CLK_SRC_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700122 if ((reg & 0x1) == 0) {
Stephen Boyde24edf52012-07-12 17:46:19 -0700123 writel_relaxed(0x3, drv->cbase + MARM_CLK_SRC1_NS);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700124 reg |= 0x1;
125 } else {
Stephen Boyde24edf52012-07-12 17:46:19 -0700126 writel_relaxed(0x3, drv->cbase + MARM_CLK_SRC0_NS);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700127 reg &= ~0x1;
128 }
Stephen Boyde24edf52012-07-12 17:46:19 -0700129 writel_relaxed(reg | 0x2, drv->cbase + MARM_CLK_SRC_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700130
131 /*
132 * Force core on and periph on signals to remain active during halt
133 * for marm_clk and mahb2_clk
134 */
Stephen Boyde24edf52012-07-12 17:46:19 -0700135 writel_relaxed(0x6F, drv->cbase + MARM_CLK_FS);
136 writel_relaxed(0x6F, drv->cbase + MAHB2_CLK_FS);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700137
138 /*
139 * Enable all of the marm_clk branches, cxo sourced marm branches,
140 * and sleep clock branches
141 */
Stephen Boyde24edf52012-07-12 17:46:19 -0700142 writel_relaxed(0x10, drv->cbase + MARM_CLK_CTL);
143 writel_relaxed(0x10, drv->cbase + MAHB0_CLK_CTL);
144 writel_relaxed(0x10, drv->cbase + SFAB_MSS_S_HCLK_CTL);
145 writel_relaxed(0x10, drv->cbase + MSS_MODEM_CXO_CLK_CTL);
146 writel_relaxed(0x10, drv->cbase + MSS_SLP_CLK_CTL);
147 writel_relaxed(0x10, drv->cbase + MSS_MARM_SYS_REF_CLK_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700148
149 /* Wait for above clocks to be turned on */
Stephen Boyde24edf52012-07-12 17:46:19 -0700150 while (readl_relaxed(drv->cbase + CLK_HALT_MSS_SMPSS_MISC_STATE) &
151 (BIT(7) | BIT(8) | BIT(9) | BIT(10) | BIT(4) | BIT(6)))
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700152 cpu_relax();
153
154 /* Take MAHB0,1,2 clocks out of reset */
Stephen Boyde24edf52012-07-12 17:46:19 -0700155 writel_relaxed(0x0, drv->cbase + MAHB2_CLK_CTL);
156 writel_relaxed(0x0, drv->cbase + MAHB1_CLK_CTL);
157 writel_relaxed(0x0, drv->cbase + MAHB0_SFAB_PORT_RESET);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700158 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 */
Stephen Boyde24edf52012-07-12 17:46:19 -0700167 writel_relaxed(0x0, drv->cbase + MARM_RESET);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700168
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 Boyde24edf52012-07-12 17:46:19 -0700175 const struct modem_data *drv = dev_get_drvdata(pil->dev);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700176
177 /* Put modem into reset */
Stephen Boyde24edf52012-07-12 17:46:19 -0700178 writel_relaxed(0x1, drv->cbase + MARM_RESET);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700179 mb();
180
181 /* Put modem AHB0,1,2 clocks into reset */
Stephen Boyde24edf52012-07-12 17:46:19 -0700182 writel_relaxed(BIT(0) | BIT(1), drv->cbase + MAHB0_SFAB_PORT_RESET);
183 writel_relaxed(BIT(7), drv->cbase + MAHB1_CLK_CTL);
184 writel_relaxed(BIT(7), drv->cbase + MAHB2_CLK_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700185 mb();
186
187 /*
188 * Disable all of the marm_clk branches, cxo sourced marm branches,
189 * and sleep clock branches
190 */
Stephen Boyde24edf52012-07-12 17:46:19 -0700191 writel_relaxed(0x0, drv->cbase + MARM_CLK_CTL);
192 writel_relaxed(0x0, drv->cbase + MAHB0_CLK_CTL);
193 writel_relaxed(0x0, drv->cbase + SFAB_MSS_S_HCLK_CTL);
194 writel_relaxed(0x0, drv->cbase + MSS_MODEM_CXO_CLK_CTL);
195 writel_relaxed(0x0, drv->cbase + MSS_SLP_CLK_CTL);
196 writel_relaxed(0x0, drv->cbase + MSS_MARM_SYS_REF_CLK_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700197
198 /* Disable marm_clk */
Stephen Boyde24edf52012-07-12 17:46:19 -0700199 reg = readl_relaxed(drv->cbase + MARM_CLK_SRC_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700200 reg &= ~0x2;
Stephen Boyde24edf52012-07-12 17:46:19 -0700201 writel_relaxed(reg, drv->cbase + MARM_CLK_SRC_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700202
203 /* Clear modem's votes for ahb clocks */
Stephen Boyde24edf52012-07-12 17:46:19 -0700204 writel_relaxed(0x0, drv->cbase + MARM_CLK_BRANCH_ENA_VOTE);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700205
206 /* Clear modem's votes for PLLs */
Stephen Boyde24edf52012-07-12 17:46:19 -0700207 writel_relaxed(0x0, drv->cbase + PLL_ENA_MARM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700208
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700209 return 0;
210}
211
212static struct pil_reset_ops pil_modem_ops = {
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700213 .auth_and_reset = modem_reset,
Stephen Boyd3ac20732012-05-03 18:46:08 -0700214 .shutdown = modem_pil_shutdown,
Stephen Boyd06aba622012-03-22 10:59:22 -0700215 .proxy_vote = make_modem_proxy_votes,
216 .proxy_unvote = remove_modem_proxy_votes,
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700217};
218
219static int modem_init_image_trusted(struct pil_desc *pil, const u8 *metadata,
220 size_t size)
221{
222 return pas_init_image(PAS_MODEM, metadata, size);
223}
224
225static int modem_reset_trusted(struct pil_desc *pil)
226{
Stephen Boyd06aba622012-03-22 10:59:22 -0700227 return pas_auth_and_reset(PAS_MODEM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700228}
229
230static int modem_shutdown_trusted(struct pil_desc *pil)
231{
Stephen Boyd06aba622012-03-22 10:59:22 -0700232 return pas_shutdown(PAS_MODEM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700233}
234
235static struct pil_reset_ops pil_modem_ops_trusted = {
236 .init_image = modem_init_image_trusted,
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700237 .auth_and_reset = modem_reset_trusted,
238 .shutdown = modem_shutdown_trusted,
Stephen Boyd06aba622012-03-22 10:59:22 -0700239 .proxy_vote = make_modem_proxy_votes,
240 .proxy_unvote = remove_modem_proxy_votes,
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700241};
242
Stephen Boyd3ac20732012-05-03 18:46:08 -0700243static void modem_crash_shutdown(const struct subsys_desc *subsys)
244{
245 struct modem_data *drv;
246
247 /* If modem hasn't already crashed, send SMSM_RESET. */
248 drv = container_of(subsys, struct modem_data, subsys_desc);
249 if (!(smsm_get_state(SMSM_MODEM_STATE) & SMSM_RESET)) {
250 modem_unregister_notifier(&drv->notifier);
251 smsm_reset_modem(SMSM_RESET);
252 }
253
254 /* Wait to allow the modem to clean up caches etc. */
255 mdelay(5);
256}
257
258static irqreturn_t modem_wdog_bite_irq(int irq, void *dev_id)
259{
260 struct modem_data *drv = dev_id;
261
262 schedule_work(&drv->fatal_work);
263 disable_irq_nosync(drv->irq);
264
265 return IRQ_HANDLED;
266}
267
268static void modem_unlock_timeout(struct work_struct *work)
269{
270 struct modem_data *drv;
271 struct delayed_work *dwork = to_delayed_work(work);
272
273 pr_crit("Timeout waiting for modem to unlock.\n");
274
275 drv = container_of(dwork, struct modem_data, unlock_work);
276 /* The unlock didn't work, clear the reset */
Stephen Boyde24edf52012-07-12 17:46:19 -0700277 writel_relaxed(0x0, drv->cbase + MSS_MODEM_RESET);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700278 mb();
279
280 subsystem_restart_dev(drv->subsys);
281 enable_irq(drv->irq);
282}
283
284static void modem_fatal_fn(struct work_struct *work)
285{
286 u32 modem_state;
287 u32 panic_smsm_states = SMSM_RESET | SMSM_SYSTEM_DOWNLOAD;
288 u32 reset_smsm_states = SMSM_SYSTEM_REBOOT_USR | SMSM_SYSTEM_PWRDWN_USR;
289 struct modem_data *drv;
290
291 drv = container_of(work, struct modem_data, fatal_work);
292
293 pr_err("Watchdog bite received from modem!\n");
294
295 modem_state = smsm_get_state(SMSM_MODEM_STATE);
296 pr_err("Modem SMSM state = 0x%x!\n", modem_state);
297
298 if (modem_state == 0 || modem_state & panic_smsm_states) {
299 subsystem_restart_dev(drv->subsys);
300 enable_irq(drv->irq);
301 } else if (modem_state & reset_smsm_states) {
302 pr_err("User-invoked system reset/powerdown.");
303 kernel_restart(NULL);
304 } else {
305 unsigned long timeout = msecs_to_jiffies(6000);
306
307 pr_err("Modem AHB locked up. Trying to free up modem!\n");
308
Stephen Boyde24edf52012-07-12 17:46:19 -0700309 writel_relaxed(0x3, drv->cbase + MSS_MODEM_RESET);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700310 /*
311 * If we are still alive (allowing for the 5 second
312 * delayed-panic-reboot), the modem is either still wedged or
313 * SMSM didn't come through. Force panic in that case.
314 */
315 schedule_delayed_work(&drv->unlock_work, timeout);
316 }
317}
318
319static int modem_notif_handler(struct notifier_block *nb, unsigned long code,
320 void *p)
321{
322 struct modem_data *drv = container_of(nb, struct modem_data, notifier);
323
324 if (code == MODEM_NOTIFIER_START_RESET) {
325 if (drv->ignore_smsm_ack) {
326 drv->ignore_smsm_ack = 0;
327 } else {
328 pr_err("Modem error fatal'ed.");
329 subsystem_restart_dev(drv->subsys);
330 }
331 }
332 return NOTIFY_DONE;
333}
334
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700335static int modem_start(const struct subsys_desc *subsys)
336{
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700337 struct modem_data *drv;
338
339 drv = container_of(subsys, struct modem_data, subsys_desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700340 return pil_boot(&drv->pil_desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700341}
342
343static void modem_stop(const struct subsys_desc *subsys)
344{
345 struct modem_data *drv;
346
347 drv = container_of(subsys, struct modem_data, subsys_desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700348 pil_shutdown(&drv->pil_desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700349}
350
Stephen Boyd3ac20732012-05-03 18:46:08 -0700351static int modem_shutdown(const struct subsys_desc *subsys)
352{
353 struct modem_data *drv;
354
355 drv = container_of(subsys, struct modem_data, subsys_desc);
356 /*
357 * If the modem didn't already crash, setting SMSM_RESET here will help
358 * flush caches etc. The ignore_smsm_ack flag is set to ignore the
359 * SMSM_RESET notification that is generated due to the modem settings
360 * its own SMSM_RESET bit in response to the apps setting the apps
361 * SMSM_RESET bit.
362 */
363 if (!(smsm_get_state(SMSM_MODEM_STATE) & SMSM_RESET)) {
364 drv->ignore_smsm_ack = 1;
365 smsm_reset_modem(SMSM_RESET);
366 }
367
368 /* Disable the modem watchdog to allow clean modem bootup */
369 writel_relaxed(0x0, drv->wdog + 0x8);
370 /*
371 * The write above needs to go through before the modem is powered up
372 * again.
373 */
374 mb();
375 /* Wait here to allow the modem to clean up caches, etc. */
376 msleep(20);
377
Stephen Boyde83a0a22012-06-29 13:51:27 -0700378 pil_shutdown(&drv->pil_desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700379 disable_irq_nosync(drv->irq);
380
381 return 0;
382}
383
384static int modem_powerup(const struct subsys_desc *subsys)
385{
386 struct modem_data *drv;
387 int ret;
388
389 drv = container_of(subsys, struct modem_data, subsys_desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700390 ret = pil_boot(&drv->pil_desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700391 enable_irq(drv->irq);
392
393 return ret;
394}
395
Stephen Boyd3ac20732012-05-03 18:46:08 -0700396static int modem_ramdump(int enable, const struct subsys_desc *subsys)
397{
398 struct modem_data *drv;
399
400 drv = container_of(subsys, struct modem_data, subsys_desc);
Stephen Boyd5eb17ce2012-11-29 15:34:21 -0800401 if (!enable)
Stephen Boyd3ac20732012-05-03 18:46:08 -0700402 return 0;
Stephen Boyd5eb17ce2012-11-29 15:34:21 -0800403
404 return pil_do_ramdump(&drv->pil_desc, drv->ramdump_dev);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700405}
406
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700407static 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 Boyd3ac20732012-05-03 18:46:08 -0700412 int ret;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700413
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700414 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
415 if (!drv)
416 return -ENOMEM;
417 platform_set_drvdata(pdev, drv);
418
Stephen Boyd3ac20732012-05-03 18:46:08 -0700419 drv->irq = platform_get_irq(pdev, 0);
420 if (drv->irq < 0)
421 return drv->irq;
422
Stephen Boydb0895692012-03-23 15:23:10 -0700423 drv->xo = devm_clk_get(&pdev->dev, "xo");
Stephen Boyd67036532012-01-26 15:43:51 -0800424 if (IS_ERR(drv->xo))
425 return PTR_ERR(drv->xo);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700426
Stephen Boydf8f89282012-07-16 18:05:48 -0700427 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
428 drv->base = devm_request_and_ioremap(&pdev->dev, res);
429 if (!drv->base)
430 return -ENOMEM;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700431
Stephen Boydf8f89282012-07-16 18:05:48 -0700432 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
433 drv->wdog = devm_request_and_ioremap(&pdev->dev, res);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700434 if (!drv->wdog)
435 return -ENOMEM;
436
Stephen Boyde24edf52012-07-12 17:46:19 -0700437 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
438 if (!res)
439 return -EINVAL;
440
441 drv->cbase = devm_ioremap(&pdev->dev, res->start, resource_size(res));
442 if (!drv->cbase)
443 return -ENOMEM;
444
Stephen Boyde83a0a22012-06-29 13:51:27 -0700445 desc = &drv->pil_desc;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700446 desc->name = "modem";
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700447 desc->dev = &pdev->dev;
Stephen Boyd6d67d252011-09-27 11:50:05 -0700448 desc->owner = THIS_MODULE;
Stephen Boyd06aba622012-03-22 10:59:22 -0700449 desc->proxy_timeout = 10000;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700450
451 if (pas_supported(PAS_MODEM) > 0) {
452 desc->ops = &pil_modem_ops_trusted;
453 dev_info(&pdev->dev, "using secure boot\n");
454 } else {
455 desc->ops = &pil_modem_ops;
456 dev_info(&pdev->dev, "using non-secure boot\n");
457 }
Stephen Boyde83a0a22012-06-29 13:51:27 -0700458 ret = pil_desc_init(desc);
459 if (ret)
460 return ret;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700461
462 drv->notifier.notifier_call = modem_notif_handler,
463 ret = modem_register_notifier(&drv->notifier);
464 if (ret)
465 goto err_notify;
466
467 drv->subsys_desc.name = "modem";
Stephen Boyd77db8bb2012-06-27 15:15:16 -0700468 drv->subsys_desc.depends_on = "adsp";
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700469 drv->subsys_desc.dev = &pdev->dev;
470 drv->subsys_desc.owner = THIS_MODULE;
471 drv->subsys_desc.start = modem_start;
472 drv->subsys_desc.stop = modem_stop;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700473 drv->subsys_desc.shutdown = modem_shutdown;
474 drv->subsys_desc.powerup = modem_powerup;
475 drv->subsys_desc.ramdump = modem_ramdump;
476 drv->subsys_desc.crash_shutdown = modem_crash_shutdown;
477
478 INIT_WORK(&drv->fatal_work, modem_fatal_fn);
479 INIT_DELAYED_WORK(&drv->unlock_work, modem_unlock_timeout);
480
481 drv->subsys = subsys_register(&drv->subsys_desc);
482 if (IS_ERR(drv->subsys)) {
483 ret = PTR_ERR(drv->subsys);
484 goto err_subsys;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700485 }
Stephen Boyd3ac20732012-05-03 18:46:08 -0700486
Stephen Boydc1a72612012-07-05 14:07:35 -0700487 drv->ramdump_dev = create_ramdump_device("modem", &pdev->dev);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700488 if (!drv->ramdump_dev) {
489 ret = -ENOMEM;
490 goto err_ramdump;
491 }
492
493 ret = devm_request_irq(&pdev->dev, drv->irq, modem_wdog_bite_irq,
494 IRQF_TRIGGER_RISING, "modem_watchdog", drv);
495 if (ret)
496 goto err_irq;
Stephen Boyd6d67d252011-09-27 11:50:05 -0700497 return 0;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700498
499err_irq:
500 destroy_ramdump_device(drv->ramdump_dev);
501err_ramdump:
502 subsys_unregister(drv->subsys);
503err_subsys:
504 modem_unregister_notifier(&drv->notifier);
505err_notify:
Stephen Boyde83a0a22012-06-29 13:51:27 -0700506 pil_desc_release(desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700507 return ret;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700508}
509
510static int __devexit pil_modem_driver_exit(struct platform_device *pdev)
511{
512 struct modem_data *drv = platform_get_drvdata(pdev);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700513
514 destroy_ramdump_device(drv->ramdump_dev);
515 subsys_unregister(drv->subsys);
516 modem_unregister_notifier(&drv->notifier);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700517 pil_desc_release(&drv->pil_desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700518
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700519 return 0;
520}
521
522static struct platform_driver pil_modem_driver = {
523 .probe = pil_modem_driver_probe,
524 .remove = __devexit_p(pil_modem_driver_exit),
525 .driver = {
526 .name = "pil_modem",
527 .owner = THIS_MODULE,
528 },
529};
530
531static int __init pil_modem_init(void)
532{
533 return platform_driver_register(&pil_modem_driver);
534}
535module_init(pil_modem_init);
536
537static void __exit pil_modem_exit(void)
538{
539 platform_driver_unregister(&pil_modem_driver);
540}
541module_exit(pil_modem_exit);
542
543MODULE_DESCRIPTION("Support for booting modem processors");
544MODULE_LICENSE("GPL v2");