blob: d3c832b6cd3fdb31f995189b693acf365e2e638b [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
Stephen Boyd3ac20732012-05-03 18:46:08 -070025#include <mach/subsystem_restart.h>
26#include <mach/msm_smsm.h>
Stephen Boyd4eb885b2011-09-29 01:16:03 -070027
Stephen Boyd3ac20732012-05-03 18:46:08 -070028#include "modem_notifier.h"
Stephen Boyd4eb885b2011-09-29 01:16:03 -070029#include "peripheral-loader.h"
30#include "scm-pas.h"
Stephen Boyd3ac20732012-05-03 18:46:08 -070031#include "ramdump.h"
Stephen Boyd4eb885b2011-09-29 01:16:03 -070032
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);
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 */
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
396/* FIXME: Get address, size from PIL */
397static struct ramdump_segment modem_segments[] = {
398 { 0x42F00000, 0x46000000 - 0x42F00000 },
399};
400
401static int modem_ramdump(int enable, const struct subsys_desc *subsys)
402{
403 struct modem_data *drv;
404
405 drv = container_of(subsys, struct modem_data, subsys_desc);
406 if (enable)
407 return do_ramdump(drv->ramdump_dev, modem_segments,
408 ARRAY_SIZE(modem_segments));
409 else
410 return 0;
411}
412
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700413static int __devinit pil_modem_driver_probe(struct platform_device *pdev)
414{
415 struct modem_data *drv;
416 struct resource *res;
417 struct pil_desc *desc;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700418 int ret;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700419
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700420 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
421 if (!drv)
422 return -ENOMEM;
423 platform_set_drvdata(pdev, drv);
424
Stephen Boyd3ac20732012-05-03 18:46:08 -0700425 drv->irq = platform_get_irq(pdev, 0);
426 if (drv->irq < 0)
427 return drv->irq;
428
Stephen Boydb0895692012-03-23 15:23:10 -0700429 drv->xo = devm_clk_get(&pdev->dev, "xo");
Stephen Boyd67036532012-01-26 15:43:51 -0800430 if (IS_ERR(drv->xo))
431 return PTR_ERR(drv->xo);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700432
Stephen Boydf8f89282012-07-16 18:05:48 -0700433 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
434 drv->base = devm_request_and_ioremap(&pdev->dev, res);
435 if (!drv->base)
436 return -ENOMEM;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700437
Stephen Boydf8f89282012-07-16 18:05:48 -0700438 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
439 drv->wdog = devm_request_and_ioremap(&pdev->dev, res);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700440 if (!drv->wdog)
441 return -ENOMEM;
442
Stephen Boyde24edf52012-07-12 17:46:19 -0700443 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
444 if (!res)
445 return -EINVAL;
446
447 drv->cbase = devm_ioremap(&pdev->dev, res->start, resource_size(res));
448 if (!drv->cbase)
449 return -ENOMEM;
450
Stephen Boyde83a0a22012-06-29 13:51:27 -0700451 desc = &drv->pil_desc;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700452 desc->name = "modem";
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700453 desc->dev = &pdev->dev;
Stephen Boyd6d67d252011-09-27 11:50:05 -0700454 desc->owner = THIS_MODULE;
Stephen Boyd06aba622012-03-22 10:59:22 -0700455 desc->proxy_timeout = 10000;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700456
457 if (pas_supported(PAS_MODEM) > 0) {
458 desc->ops = &pil_modem_ops_trusted;
459 dev_info(&pdev->dev, "using secure boot\n");
460 } else {
461 desc->ops = &pil_modem_ops;
462 dev_info(&pdev->dev, "using non-secure boot\n");
463 }
Stephen Boyde83a0a22012-06-29 13:51:27 -0700464 ret = pil_desc_init(desc);
465 if (ret)
466 return ret;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700467
468 drv->notifier.notifier_call = modem_notif_handler,
469 ret = modem_register_notifier(&drv->notifier);
470 if (ret)
471 goto err_notify;
472
473 drv->subsys_desc.name = "modem";
Stephen Boyd77db8bb2012-06-27 15:15:16 -0700474 drv->subsys_desc.depends_on = "adsp";
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700475 drv->subsys_desc.dev = &pdev->dev;
476 drv->subsys_desc.owner = THIS_MODULE;
477 drv->subsys_desc.start = modem_start;
478 drv->subsys_desc.stop = modem_stop;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700479 drv->subsys_desc.shutdown = modem_shutdown;
480 drv->subsys_desc.powerup = modem_powerup;
481 drv->subsys_desc.ramdump = modem_ramdump;
482 drv->subsys_desc.crash_shutdown = modem_crash_shutdown;
483
484 INIT_WORK(&drv->fatal_work, modem_fatal_fn);
485 INIT_DELAYED_WORK(&drv->unlock_work, modem_unlock_timeout);
486
487 drv->subsys = subsys_register(&drv->subsys_desc);
488 if (IS_ERR(drv->subsys)) {
489 ret = PTR_ERR(drv->subsys);
490 goto err_subsys;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700491 }
Stephen Boyd3ac20732012-05-03 18:46:08 -0700492
Stephen Boydc1a72612012-07-05 14:07:35 -0700493 drv->ramdump_dev = create_ramdump_device("modem", &pdev->dev);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700494 if (!drv->ramdump_dev) {
495 ret = -ENOMEM;
496 goto err_ramdump;
497 }
498
499 ret = devm_request_irq(&pdev->dev, drv->irq, modem_wdog_bite_irq,
500 IRQF_TRIGGER_RISING, "modem_watchdog", drv);
501 if (ret)
502 goto err_irq;
Stephen Boyd6d67d252011-09-27 11:50:05 -0700503 return 0;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700504
505err_irq:
506 destroy_ramdump_device(drv->ramdump_dev);
507err_ramdump:
508 subsys_unregister(drv->subsys);
509err_subsys:
510 modem_unregister_notifier(&drv->notifier);
511err_notify:
Stephen Boyde83a0a22012-06-29 13:51:27 -0700512 pil_desc_release(desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700513 return ret;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700514}
515
516static int __devexit pil_modem_driver_exit(struct platform_device *pdev)
517{
518 struct modem_data *drv = platform_get_drvdata(pdev);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700519
520 destroy_ramdump_device(drv->ramdump_dev);
521 subsys_unregister(drv->subsys);
522 modem_unregister_notifier(&drv->notifier);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700523 pil_desc_release(&drv->pil_desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700524
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700525 return 0;
526}
527
528static struct platform_driver pil_modem_driver = {
529 .probe = pil_modem_driver_probe,
530 .remove = __devexit_p(pil_modem_driver_exit),
531 .driver = {
532 .name = "pil_modem",
533 .owner = THIS_MODULE,
534 },
535};
536
537static int __init pil_modem_init(void)
538{
539 return platform_driver_register(&pil_modem_driver);
540}
541module_init(pil_modem_init);
542
543static void __exit pil_modem_exit(void)
544{
545 platform_driver_unregister(&pil_modem_driver);
546}
547module_exit(pil_modem_exit);
548
549MODULE_DESCRIPTION("Support for booting modem processors");
550MODULE_LICENSE("GPL v2");