blob: f6a853ea7d97912a9e740434dc925450d65fbc30 [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>
Deepak Katragadda4118ccc2013-07-05 10:01:19 -070028#include <mach/msm_bus_board.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"
33
34#define MARM_BOOT_CONTROL 0x0010
Stephen Boyde24edf52012-07-12 17:46:19 -070035#define MARM_RESET 0x2BD4
36#define MAHB0_SFAB_PORT_RESET 0x2304
37#define MARM_CLK_BRANCH_ENA_VOTE 0x3000
38#define MARM_CLK_SRC0_NS 0x2BC0
39#define MARM_CLK_SRC1_NS 0x2BC4
40#define MARM_CLK_SRC_CTL 0x2BC8
41#define MARM_CLK_CTL 0x2BCC
42#define SFAB_MSS_S_HCLK_CTL 0x2C00
43#define MSS_MODEM_CXO_CLK_CTL 0x2C44
44#define MSS_SLP_CLK_CTL 0x2C60
45#define MSS_MARM_SYS_REF_CLK_CTL 0x2C64
46#define MAHB0_CLK_CTL 0x2300
47#define MAHB1_CLK_CTL 0x2BE4
48#define MAHB2_CLK_CTL 0x2C20
49#define MAHB1_NS 0x2BE0
50#define MARM_CLK_FS 0x2BD0
51#define MAHB2_CLK_FS 0x2C24
52#define PLL_ENA_MARM 0x3500
53#define PLL8_STATUS 0x3158
54#define CLK_HALT_MSS_SMPSS_MISC_STATE 0x2FDC
55#define MSS_MODEM_RESET 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 Boyde24edf52012-07-12 17:46:19 -070060 void __iomem *cbase;
Stephen Boyd6d67d252011-09-27 11:50:05 -070061 struct pil_device *pil;
Stephen Boyd67036532012-01-26 15:43:51 -080062 struct clk *xo;
Stephen Boyd3ac20732012-05-03 18:46:08 -070063 struct notifier_block notifier;
64 int ignore_smsm_ack;
65 int irq;
Stephen Boyde83a0a22012-06-29 13:51:27 -070066 struct pil_desc pil_desc;
Stephen Boyd3ac20732012-05-03 18:46:08 -070067 struct subsys_device *subsys;
68 struct subsys_desc subsys_desc;
69 struct delayed_work unlock_work;
70 struct work_struct fatal_work;
71 struct ramdump_device *ramdump_dev;
Stephen Boyd4eb885b2011-09-29 01:16:03 -070072};
73
Stephen Boyd06aba622012-03-22 10:59:22 -070074static int make_modem_proxy_votes(struct pil_desc *pil)
Stephen Boyd4eb885b2011-09-29 01:16:03 -070075{
76 int ret;
Stephen Boyd06aba622012-03-22 10:59:22 -070077 struct modem_data *drv = dev_get_drvdata(pil->dev);
Stephen Boyd4eb885b2011-09-29 01:16:03 -070078
Stephen Boyd67036532012-01-26 15:43:51 -080079 ret = clk_prepare_enable(drv->xo);
80 if (ret) {
Stephen Boyd06aba622012-03-22 10:59:22 -070081 dev_err(pil->dev, "Failed to enable XO\n");
Stephen Boyd67036532012-01-26 15:43:51 -080082 return ret;
83 }
Stephen Boyd67036532012-01-26 15:43:51 -080084 return 0;
85}
86
Stephen Boyd06aba622012-03-22 10:59:22 -070087static void remove_modem_proxy_votes(struct pil_desc *pil)
Stephen Boyd67036532012-01-26 15:43:51 -080088{
Stephen Boyd06aba622012-03-22 10:59:22 -070089 struct modem_data *drv = dev_get_drvdata(pil->dev);
Stephen Boyd67036532012-01-26 15:43:51 -080090 clk_disable_unprepare(drv->xo);
Stephen Boyd4eb885b2011-09-29 01:16:03 -070091}
92
Stephen Boyd4eb885b2011-09-29 01:16:03 -070093static int modem_reset(struct pil_desc *pil)
94{
95 u32 reg;
96 const struct modem_data *drv = dev_get_drvdata(pil->dev);
Tianyi Gou819851e2013-04-16 16:05:56 -070097 phys_addr_t start_addr = pil_get_entry_addr(pil);
Stephen Boyd4eb885b2011-09-29 01:16:03 -070098
Stephen Boyd4eb885b2011-09-29 01:16:03 -070099 /* Put modem AHB0,1,2 clocks into reset */
Stephen Boyde24edf52012-07-12 17:46:19 -0700100 writel_relaxed(BIT(0) | BIT(1), drv->cbase + MAHB0_SFAB_PORT_RESET);
101 writel_relaxed(BIT(7), drv->cbase + MAHB1_CLK_CTL);
102 writel_relaxed(BIT(7), drv->cbase + MAHB2_CLK_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700103
104 /* Vote for pll8 on behalf of the modem */
Stephen Boyde24edf52012-07-12 17:46:19 -0700105 reg = readl_relaxed(drv->cbase + PLL_ENA_MARM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700106 reg |= BIT(8);
Stephen Boyde24edf52012-07-12 17:46:19 -0700107 writel_relaxed(reg, drv->cbase + PLL_ENA_MARM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700108
109 /* Wait for PLL8 to enable */
Stephen Boyde24edf52012-07-12 17:46:19 -0700110 while (!(readl_relaxed(drv->cbase + PLL8_STATUS) & BIT(16)))
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700111 cpu_relax();
112
113 /* Set MAHB1 divider to Div-5 to run MAHB1,2 and sfab at 79.8 Mhz*/
Stephen Boyde24edf52012-07-12 17:46:19 -0700114 writel_relaxed(0x4, drv->cbase + MAHB1_NS);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700115
116 /* Vote for modem AHB1 and 2 clocks to be on on behalf of the modem */
Stephen Boyde24edf52012-07-12 17:46:19 -0700117 reg = readl_relaxed(drv->cbase + MARM_CLK_BRANCH_ENA_VOTE);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700118 reg |= BIT(0) | BIT(1);
Stephen Boyde24edf52012-07-12 17:46:19 -0700119 writel_relaxed(reg, drv->cbase + MARM_CLK_BRANCH_ENA_VOTE);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700120
121 /* Source marm_clk off of PLL8 */
Stephen Boyde24edf52012-07-12 17:46:19 -0700122 reg = readl_relaxed(drv->cbase + MARM_CLK_SRC_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700123 if ((reg & 0x1) == 0) {
Stephen Boyde24edf52012-07-12 17:46:19 -0700124 writel_relaxed(0x3, drv->cbase + MARM_CLK_SRC1_NS);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700125 reg |= 0x1;
126 } else {
Stephen Boyde24edf52012-07-12 17:46:19 -0700127 writel_relaxed(0x3, drv->cbase + MARM_CLK_SRC0_NS);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700128 reg &= ~0x1;
129 }
Stephen Boyde24edf52012-07-12 17:46:19 -0700130 writel_relaxed(reg | 0x2, drv->cbase + MARM_CLK_SRC_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700131
132 /*
133 * Force core on and periph on signals to remain active during halt
134 * for marm_clk and mahb2_clk
135 */
Stephen Boyde24edf52012-07-12 17:46:19 -0700136 writel_relaxed(0x6F, drv->cbase + MARM_CLK_FS);
137 writel_relaxed(0x6F, drv->cbase + MAHB2_CLK_FS);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700138
139 /*
140 * Enable all of the marm_clk branches, cxo sourced marm branches,
141 * and sleep clock branches
142 */
Stephen Boyde24edf52012-07-12 17:46:19 -0700143 writel_relaxed(0x10, drv->cbase + MARM_CLK_CTL);
144 writel_relaxed(0x10, drv->cbase + MAHB0_CLK_CTL);
145 writel_relaxed(0x10, drv->cbase + SFAB_MSS_S_HCLK_CTL);
146 writel_relaxed(0x10, drv->cbase + MSS_MODEM_CXO_CLK_CTL);
147 writel_relaxed(0x10, drv->cbase + MSS_SLP_CLK_CTL);
148 writel_relaxed(0x10, drv->cbase + MSS_MARM_SYS_REF_CLK_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700149
150 /* Wait for above clocks to be turned on */
Stephen Boyde24edf52012-07-12 17:46:19 -0700151 while (readl_relaxed(drv->cbase + CLK_HALT_MSS_SMPSS_MISC_STATE) &
152 (BIT(7) | BIT(8) | BIT(9) | BIT(10) | BIT(4) | BIT(6)))
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700153 cpu_relax();
154
155 /* Take MAHB0,1,2 clocks out of reset */
Stephen Boyde24edf52012-07-12 17:46:19 -0700156 writel_relaxed(0x0, drv->cbase + MAHB2_CLK_CTL);
157 writel_relaxed(0x0, drv->cbase + MAHB1_CLK_CTL);
158 writel_relaxed(0x0, drv->cbase + MAHB0_SFAB_PORT_RESET);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700159 mb();
160
161 /* Setup exception vector table base address */
Stephen Boyd3030c252012-08-08 17:24:05 -0700162 writel_relaxed(start_addr | 0x1, drv->base + MARM_BOOT_CONTROL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700163
164 /* Wait for vector table to be setup */
165 mb();
166
167 /* Bring modem out of reset */
Stephen Boyde24edf52012-07-12 17:46:19 -0700168 writel_relaxed(0x0, drv->cbase + MARM_RESET);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700169
170 return 0;
171}
172
Stephen Boyd3ac20732012-05-03 18:46:08 -0700173static int modem_pil_shutdown(struct pil_desc *pil)
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700174{
175 u32 reg;
Stephen Boyde24edf52012-07-12 17:46:19 -0700176 const struct modem_data *drv = dev_get_drvdata(pil->dev);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700177
178 /* Put modem into reset */
Stephen Boyde24edf52012-07-12 17:46:19 -0700179 writel_relaxed(0x1, drv->cbase + MARM_RESET);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700180 mb();
181
182 /* Put modem AHB0,1,2 clocks into reset */
Stephen Boyde24edf52012-07-12 17:46:19 -0700183 writel_relaxed(BIT(0) | BIT(1), drv->cbase + MAHB0_SFAB_PORT_RESET);
184 writel_relaxed(BIT(7), drv->cbase + MAHB1_CLK_CTL);
185 writel_relaxed(BIT(7), drv->cbase + MAHB2_CLK_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700186 mb();
187
188 /*
189 * Disable all of the marm_clk branches, cxo sourced marm branches,
190 * and sleep clock branches
191 */
Stephen Boyde24edf52012-07-12 17:46:19 -0700192 writel_relaxed(0x0, drv->cbase + MARM_CLK_CTL);
193 writel_relaxed(0x0, drv->cbase + MAHB0_CLK_CTL);
194 writel_relaxed(0x0, drv->cbase + SFAB_MSS_S_HCLK_CTL);
195 writel_relaxed(0x0, drv->cbase + MSS_MODEM_CXO_CLK_CTL);
196 writel_relaxed(0x0, drv->cbase + MSS_SLP_CLK_CTL);
197 writel_relaxed(0x0, drv->cbase + MSS_MARM_SYS_REF_CLK_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700198
199 /* Disable marm_clk */
Stephen Boyde24edf52012-07-12 17:46:19 -0700200 reg = readl_relaxed(drv->cbase + MARM_CLK_SRC_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700201 reg &= ~0x2;
Stephen Boyde24edf52012-07-12 17:46:19 -0700202 writel_relaxed(reg, drv->cbase + MARM_CLK_SRC_CTL);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700203
204 /* Clear modem's votes for ahb clocks */
Stephen Boyde24edf52012-07-12 17:46:19 -0700205 writel_relaxed(0x0, drv->cbase + MARM_CLK_BRANCH_ENA_VOTE);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700206
207 /* Clear modem's votes for PLLs */
Stephen Boyde24edf52012-07-12 17:46:19 -0700208 writel_relaxed(0x0, drv->cbase + PLL_ENA_MARM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700209
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700210 return 0;
211}
212
213static struct pil_reset_ops pil_modem_ops = {
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700214 .auth_and_reset = modem_reset,
Stephen Boyd3ac20732012-05-03 18:46:08 -0700215 .shutdown = modem_pil_shutdown,
Stephen Boyd06aba622012-03-22 10:59:22 -0700216 .proxy_vote = make_modem_proxy_votes,
217 .proxy_unvote = remove_modem_proxy_votes,
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700218};
219
220static int modem_init_image_trusted(struct pil_desc *pil, const u8 *metadata,
221 size_t size)
222{
223 return pas_init_image(PAS_MODEM, metadata, size);
224}
225
226static int modem_reset_trusted(struct pil_desc *pil)
227{
Stephen Boyd06aba622012-03-22 10:59:22 -0700228 return pas_auth_and_reset(PAS_MODEM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700229}
230
231static int modem_shutdown_trusted(struct pil_desc *pil)
232{
Stephen Boyd06aba622012-03-22 10:59:22 -0700233 return pas_shutdown(PAS_MODEM);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700234}
235
236static struct pil_reset_ops pil_modem_ops_trusted = {
237 .init_image = modem_init_image_trusted,
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700238 .auth_and_reset = modem_reset_trusted,
239 .shutdown = modem_shutdown_trusted,
Stephen Boyd06aba622012-03-22 10:59:22 -0700240 .proxy_vote = make_modem_proxy_votes,
241 .proxy_unvote = remove_modem_proxy_votes,
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700242};
243
Stephen Boyd3ac20732012-05-03 18:46:08 -0700244static void modem_crash_shutdown(const struct subsys_desc *subsys)
245{
246 struct modem_data *drv;
247
248 /* If modem hasn't already crashed, send SMSM_RESET. */
249 drv = container_of(subsys, struct modem_data, subsys_desc);
250 if (!(smsm_get_state(SMSM_MODEM_STATE) & SMSM_RESET)) {
251 modem_unregister_notifier(&drv->notifier);
252 smsm_reset_modem(SMSM_RESET);
253 }
254
255 /* Wait to allow the modem to clean up caches etc. */
256 mdelay(5);
257}
258
259static irqreturn_t modem_wdog_bite_irq(int irq, void *dev_id)
260{
261 struct modem_data *drv = dev_id;
262
263 schedule_work(&drv->fatal_work);
264 disable_irq_nosync(drv->irq);
265
266 return IRQ_HANDLED;
267}
268
269static void modem_unlock_timeout(struct work_struct *work)
270{
271 struct modem_data *drv;
272 struct delayed_work *dwork = to_delayed_work(work);
273
274 pr_crit("Timeout waiting for modem to unlock.\n");
275
276 drv = container_of(dwork, struct modem_data, unlock_work);
277 /* The unlock didn't work, clear the reset */
Stephen Boyde24edf52012-07-12 17:46:19 -0700278 writel_relaxed(0x0, drv->cbase + MSS_MODEM_RESET);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700279 mb();
280
281 subsystem_restart_dev(drv->subsys);
282 enable_irq(drv->irq);
283}
284
285static void modem_fatal_fn(struct work_struct *work)
286{
287 u32 modem_state;
288 u32 panic_smsm_states = SMSM_RESET | SMSM_SYSTEM_DOWNLOAD;
289 u32 reset_smsm_states = SMSM_SYSTEM_REBOOT_USR | SMSM_SYSTEM_PWRDWN_USR;
290 struct modem_data *drv;
291
292 drv = container_of(work, struct modem_data, fatal_work);
293
294 pr_err("Watchdog bite received from modem!\n");
295
296 modem_state = smsm_get_state(SMSM_MODEM_STATE);
297 pr_err("Modem SMSM state = 0x%x!\n", modem_state);
298
299 if (modem_state == 0 || modem_state & panic_smsm_states) {
300 subsystem_restart_dev(drv->subsys);
301 enable_irq(drv->irq);
302 } else if (modem_state & reset_smsm_states) {
303 pr_err("User-invoked system reset/powerdown.");
304 kernel_restart(NULL);
305 } else {
306 unsigned long timeout = msecs_to_jiffies(6000);
307
308 pr_err("Modem AHB locked up. Trying to free up modem!\n");
309
Stephen Boyde24edf52012-07-12 17:46:19 -0700310 writel_relaxed(0x3, drv->cbase + MSS_MODEM_RESET);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700311 /*
312 * If we are still alive (allowing for the 5 second
313 * delayed-panic-reboot), the modem is either still wedged or
314 * SMSM didn't come through. Force panic in that case.
315 */
316 schedule_delayed_work(&drv->unlock_work, timeout);
317 }
318}
319
320static int modem_notif_handler(struct notifier_block *nb, unsigned long code,
321 void *p)
322{
323 struct modem_data *drv = container_of(nb, struct modem_data, notifier);
324
325 if (code == MODEM_NOTIFIER_START_RESET) {
326 if (drv->ignore_smsm_ack) {
327 drv->ignore_smsm_ack = 0;
328 } else {
329 pr_err("Modem error fatal'ed.");
330 subsystem_restart_dev(drv->subsys);
331 }
332 }
333 return NOTIFY_DONE;
334}
335
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700336static int modem_start(const struct subsys_desc *subsys)
337{
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700338 struct modem_data *drv;
339
340 drv = container_of(subsys, struct modem_data, subsys_desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700341 return pil_boot(&drv->pil_desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700342}
343
344static void modem_stop(const struct subsys_desc *subsys)
345{
346 struct modem_data *drv;
347
348 drv = container_of(subsys, struct modem_data, subsys_desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700349 pil_shutdown(&drv->pil_desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700350}
351
Stephen Boyd3ac20732012-05-03 18:46:08 -0700352static int modem_shutdown(const struct subsys_desc *subsys)
353{
354 struct modem_data *drv;
355
356 drv = container_of(subsys, struct modem_data, subsys_desc);
357 /*
358 * If the modem didn't already crash, setting SMSM_RESET here will help
359 * flush caches etc. The ignore_smsm_ack flag is set to ignore the
360 * SMSM_RESET notification that is generated due to the modem settings
361 * its own SMSM_RESET bit in response to the apps setting the apps
362 * SMSM_RESET bit.
363 */
364 if (!(smsm_get_state(SMSM_MODEM_STATE) & SMSM_RESET)) {
365 drv->ignore_smsm_ack = 1;
366 smsm_reset_modem(SMSM_RESET);
367 }
368
369 /* Disable the modem watchdog to allow clean modem bootup */
370 writel_relaxed(0x0, drv->wdog + 0x8);
371 /*
372 * The write above needs to go through before the modem is powered up
373 * again.
374 */
375 mb();
376 /* Wait here to allow the modem to clean up caches, etc. */
377 msleep(20);
378
Stephen Boyde83a0a22012-06-29 13:51:27 -0700379 pil_shutdown(&drv->pil_desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700380 disable_irq_nosync(drv->irq);
381
382 return 0;
383}
384
385static int modem_powerup(const struct subsys_desc *subsys)
386{
387 struct modem_data *drv;
388 int ret;
389
390 drv = container_of(subsys, struct modem_data, subsys_desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700391 ret = pil_boot(&drv->pil_desc);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700392 enable_irq(drv->irq);
393
394 return ret;
395}
396
Stephen Boyd3ac20732012-05-03 18:46:08 -0700397static int modem_ramdump(int enable, const struct subsys_desc *subsys)
398{
399 struct modem_data *drv;
400
401 drv = container_of(subsys, struct modem_data, subsys_desc);
Stephen Boyd5eb17ce2012-11-29 15:34:21 -0800402 if (!enable)
Stephen Boyd3ac20732012-05-03 18:46:08 -0700403 return 0;
Stephen Boyd5eb17ce2012-11-29 15:34:21 -0800404
405 return pil_do_ramdump(&drv->pil_desc, drv->ramdump_dev);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700406}
407
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700408static int __devinit pil_modem_driver_probe(struct platform_device *pdev)
409{
410 struct modem_data *drv;
411 struct resource *res;
412 struct pil_desc *desc;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700413 int ret;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700414
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700415 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
416 if (!drv)
417 return -ENOMEM;
418 platform_set_drvdata(pdev, drv);
419
Stephen Boyd3ac20732012-05-03 18:46:08 -0700420 drv->irq = platform_get_irq(pdev, 0);
421 if (drv->irq < 0)
422 return drv->irq;
423
Stephen Boydb0895692012-03-23 15:23:10 -0700424 drv->xo = devm_clk_get(&pdev->dev, "xo");
Stephen Boyd67036532012-01-26 15:43:51 -0800425 if (IS_ERR(drv->xo))
426 return PTR_ERR(drv->xo);
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700427
Stephen Boydf8f89282012-07-16 18:05:48 -0700428 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
429 drv->base = devm_request_and_ioremap(&pdev->dev, res);
430 if (!drv->base)
431 return -ENOMEM;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700432
Stephen Boydf8f89282012-07-16 18:05:48 -0700433 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
434 drv->wdog = devm_request_and_ioremap(&pdev->dev, res);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700435 if (!drv->wdog)
436 return -ENOMEM;
437
Stephen Boyde24edf52012-07-12 17:46:19 -0700438 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
439 if (!res)
440 return -EINVAL;
441
442 drv->cbase = devm_ioremap(&pdev->dev, res->start, resource_size(res));
443 if (!drv->cbase)
444 return -ENOMEM;
445
Stephen Boyde83a0a22012-06-29 13:51:27 -0700446 desc = &drv->pil_desc;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700447 desc->name = "modem";
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700448 desc->dev = &pdev->dev;
Stephen Boyd6d67d252011-09-27 11:50:05 -0700449 desc->owner = THIS_MODULE;
Stephen Boyd06aba622012-03-22 10:59:22 -0700450 desc->proxy_timeout = 10000;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700451
452 if (pas_supported(PAS_MODEM) > 0) {
453 desc->ops = &pil_modem_ops_trusted;
454 dev_info(&pdev->dev, "using secure boot\n");
455 } else {
456 desc->ops = &pil_modem_ops;
457 dev_info(&pdev->dev, "using non-secure boot\n");
458 }
Stephen Boyde83a0a22012-06-29 13:51:27 -0700459 ret = pil_desc_init(desc);
460 if (ret)
461 return ret;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700462
463 drv->notifier.notifier_call = modem_notif_handler,
464 ret = modem_register_notifier(&drv->notifier);
465 if (ret)
466 goto err_notify;
467
468 drv->subsys_desc.name = "modem";
Stephen Boyd77db8bb2012-06-27 15:15:16 -0700469 drv->subsys_desc.depends_on = "adsp";
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700470 drv->subsys_desc.dev = &pdev->dev;
471 drv->subsys_desc.owner = THIS_MODULE;
472 drv->subsys_desc.start = modem_start;
473 drv->subsys_desc.stop = modem_stop;
Stephen Boyd3ac20732012-05-03 18:46:08 -0700474 drv->subsys_desc.shutdown = modem_shutdown;
475 drv->subsys_desc.powerup = modem_powerup;
476 drv->subsys_desc.ramdump = modem_ramdump;
477 drv->subsys_desc.crash_shutdown = modem_crash_shutdown;
478
479 INIT_WORK(&drv->fatal_work, modem_fatal_fn);
480 INIT_DELAYED_WORK(&drv->unlock_work, modem_unlock_timeout);
481
482 drv->subsys = subsys_register(&drv->subsys_desc);
483 if (IS_ERR(drv->subsys)) {
484 ret = PTR_ERR(drv->subsys);
485 goto err_subsys;
Stephen Boyd4eb885b2011-09-29 01:16:03 -0700486 }
Stephen Boyd3ac20732012-05-03 18:46:08 -0700487
Stephen Boydc1a72612012-07-05 14:07:35 -0700488 drv->ramdump_dev = create_ramdump_device("modem", &pdev->dev);
Stephen Boyd3ac20732012-05-03 18:46:08 -0700489 if (!drv->ramdump_dev) {
490 ret = -ENOMEM;
491 goto err_ramdump;
492 }
493
Deepak Katragadda4118ccc2013-07-05 10:01:19 -0700494 scm_pas_init(MSM_BUS_MASTER_SPS);
495
Stephen Boyd3ac20732012-05-03 18:46:08 -0700496 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");