blob: 0c8f4e38e5b4b4268b75646ac0f5839a6961157c [file] [log] [blame]
Matt Wagantall292aace2012-01-26 19:12:34 -08001/*
2 * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <linux/kernel.h>
15#include <linux/err.h>
16#include <linux/io.h>
17#include <linux/elf.h>
18#include <linux/delay.h>
19#include <linux/module.h>
20#include <linux/slab.h>
21#include <linux/platform_device.h>
Matt Wagantall292aace2012-01-26 19:12:34 -080022#include <linux/clk.h>
Matt Wagantall19ac4fd2012-02-03 20:18:23 -080023#include <linux/smp.h>
Stephen Boydd86214b2012-05-10 15:26:35 -070024#include <linux/miscdevice.h>
25#include <linux/reboot.h>
26#include <linux/interrupt.h>
Matt Wagantall292aace2012-01-26 19:12:34 -080027
28#include <mach/msm_iomap.h>
29#include <mach/msm_xo.h>
Matt Wagantall556d3f72012-02-16 17:36:29 -080030#include <mach/socinfo.h>
Matt Wagantallf3471ef2012-03-09 14:21:54 -080031#include <mach/msm_bus_board.h>
32#include <mach/msm_bus.h>
Stephen Boydd86214b2012-05-10 15:26:35 -070033#include <mach/subsystem_restart.h>
34#include <mach/peripheral-loader.h>
Matt Wagantall292aace2012-01-26 19:12:34 -080035
36#include "peripheral-loader.h"
37#include "scm-pas.h"
Stephen Boydd86214b2012-05-10 15:26:35 -070038#include "smd_private.h"
39#include "ramdump.h"
Matt Wagantall292aace2012-01-26 19:12:34 -080040
41#define GSS_CSR_AHB_CLK_SEL 0x0
42#define GSS_CSR_RESET 0x4
43#define GSS_CSR_CLK_BLK_CONFIG 0x8
44#define GSS_CSR_CLK_ENABLE 0xC
45#define GSS_CSR_BOOT_REMAP 0x14
46#define GSS_CSR_POWER_UP_DOWN 0x18
Matt Wagantall19ac4fd2012-02-03 20:18:23 -080047#define GSS_CSR_CFG_HID 0x2C
Matt Wagantall292aace2012-01-26 19:12:34 -080048
49#define GSS_SLP_CLK_CTL (MSM_CLK_CTL_BASE + 0x2C60)
50#define GSS_RESET (MSM_CLK_CTL_BASE + 0x2C64)
51#define GSS_CLAMP_ENA (MSM_CLK_CTL_BASE + 0x2C68)
52#define GSS_CXO_SRC_CTL (MSM_CLK_CTL_BASE + 0x2C74)
53
Matt Wagantall292aace2012-01-26 19:12:34 -080054#define PLL5_STATUS (MSM_CLK_CTL_BASE + 0x30F8)
55#define PLL_ENA_GSS (MSM_CLK_CTL_BASE + 0x3480)
Matt Wagantall292aace2012-01-26 19:12:34 -080056
57#define PLL5_VOTE BIT(5)
58#define PLL_STATUS BIT(16)
59#define REMAP_ENABLE BIT(16)
60#define A5_POWER_STATUS BIT(4)
61#define A5_POWER_ENA BIT(0)
62#define NAV_POWER_ENA BIT(1)
63#define XO_CLK_BRANCH_ENA BIT(0)
64#define SLP_CLK_BRANCH_ENA BIT(4)
65#define A5_RESET BIT(0)
66
Matt Wagantall292aace2012-01-26 19:12:34 -080067struct gss_data {
68 void __iomem *base;
Matt Wagantall19ac4fd2012-02-03 20:18:23 -080069 void __iomem *qgic2_base;
Matt Wagantall292aace2012-01-26 19:12:34 -080070 unsigned long start_addr;
Matt Wagantall292aace2012-01-26 19:12:34 -080071 struct clk *xo;
Stephen Boyd6d67d252011-09-27 11:50:05 -070072 struct pil_device *pil;
Stephen Boydd86214b2012-05-10 15:26:35 -070073 struct miscdevice misc_dev;
74 struct subsys_device *subsys;
75 struct subsys_desc subsys_desc;
76 int crash_shutdown;
77 int irq;
Stephen Boyd4684add2012-06-27 12:57:18 -070078 void *subsys_handle;
Stephen Boydd86214b2012-05-10 15:26:35 -070079 struct ramdump_device *ramdump_dev;
80 struct ramdump_device *smem_ramdump_dev;
Matt Wagantall292aace2012-01-26 19:12:34 -080081};
82
Matt Wagantall292aace2012-01-26 19:12:34 -080083static int pil_gss_init_image(struct pil_desc *pil, const u8 *metadata,
84 size_t size)
85{
86 const struct elf32_hdr *ehdr = (struct elf32_hdr *)metadata;
87 struct gss_data *drv = dev_get_drvdata(pil->dev);
88 drv->start_addr = ehdr->e_entry;
89 return 0;
90}
91
Stephen Boydab2b9072012-03-22 10:59:22 -070092static int make_gss_proxy_votes(struct pil_desc *pil)
Matt Wagantall292aace2012-01-26 19:12:34 -080093{
94 int ret;
Stephen Boydab2b9072012-03-22 10:59:22 -070095 struct gss_data *drv = dev_get_drvdata(pil->dev);
Matt Wagantall292aace2012-01-26 19:12:34 -080096
97 ret = clk_prepare_enable(drv->xo);
98 if (ret) {
Stephen Boydab2b9072012-03-22 10:59:22 -070099 dev_err(pil->dev, "Failed to enable XO\n");
Matt Wagantall292aace2012-01-26 19:12:34 -0800100 return ret;
101 }
Matt Wagantall292aace2012-01-26 19:12:34 -0800102 return 0;
103}
104
Stephen Boydab2b9072012-03-22 10:59:22 -0700105static void remove_gss_proxy_votes(struct pil_desc *pil)
Matt Wagantall292aace2012-01-26 19:12:34 -0800106{
Stephen Boydab2b9072012-03-22 10:59:22 -0700107 struct gss_data *drv = dev_get_drvdata(pil->dev);
Matt Wagantall292aace2012-01-26 19:12:34 -0800108 clk_disable_unprepare(drv->xo);
109}
110
Matt Wagantall292aace2012-01-26 19:12:34 -0800111static void gss_init(struct gss_data *drv)
112{
113 void __iomem *base = drv->base;
114
115 /* Supply clocks to GSS. */
116 writel_relaxed(XO_CLK_BRANCH_ENA, GSS_CXO_SRC_CTL);
117 writel_relaxed(SLP_CLK_BRANCH_ENA, GSS_SLP_CLK_CTL);
118
119 /* Deassert GSS reset and clamps. */
120 writel_relaxed(0x0, GSS_RESET);
121 writel_relaxed(0x0, GSS_CLAMP_ENA);
122 mb();
123
124 /*
125 * Configure clock source and dividers for 288MHz core, 144MHz AXI and
126 * 72MHz AHB, all derived from the 288MHz PLL.
127 */
128 writel_relaxed(0x341, base + GSS_CSR_CLK_BLK_CONFIG);
129 writel_relaxed(0x1, base + GSS_CSR_AHB_CLK_SEL);
130
131 /* Assert all GSS resets. */
132 writel_relaxed(0x7F, base + GSS_CSR_RESET);
133
134 /* Enable all bus clocks and wait for resets to propagate. */
135 writel_relaxed(0x1F, base + GSS_CSR_CLK_ENABLE);
136 mb();
137 udelay(1);
138
139 /* Release subsystem from reset, but leave A5 in reset. */
140 writel_relaxed(A5_RESET, base + GSS_CSR_RESET);
141}
142
Matt Wagantall556d3f72012-02-16 17:36:29 -0800143static void cfg_qgic2_bus_access(void *data)
Matt Wagantall292aace2012-01-26 19:12:34 -0800144{
Matt Wagantall19ac4fd2012-02-03 20:18:23 -0800145 struct gss_data *drv = data;
Matt Wagantall19ac4fd2012-02-03 20:18:23 -0800146 int i;
Matt Wagantall292aace2012-01-26 19:12:34 -0800147
Matt Wagantall556d3f72012-02-16 17:36:29 -0800148 /*
149 * Apply a 8064 v1.0 workaround to configure QGIC bus access.
150 * This must be done from Krait 0 to configure the Master ID
151 * correctly.
152 */
153 writel_relaxed(0x2, drv->base + GSS_CSR_CFG_HID);
Matt Wagantall19ac4fd2012-02-03 20:18:23 -0800154 for (i = 0; i <= 3; i++)
155 readl_relaxed(drv->qgic2_base);
Matt Wagantall292aace2012-01-26 19:12:34 -0800156}
157
158static int pil_gss_shutdown(struct pil_desc *pil)
159{
160 struct gss_data *drv = dev_get_drvdata(pil->dev);
161 void __iomem *base = drv->base;
162 u32 regval;
163 int ret;
164
165 ret = clk_prepare_enable(drv->xo);
166 if (ret) {
167 dev_err(pil->dev, "Failed to enable XO\n");
168 return ret;
169 }
170
Matt Wagantallf3471ef2012-03-09 14:21:54 -0800171 /* Make sure bus port is halted. */
172 msm_bus_axi_porthalt(MSM_BUS_MASTER_GSS_NAV);
173
Matt Wagantall292aace2012-01-26 19:12:34 -0800174 /*
175 * Vote PLL on in GSS's voting register and wait for it to enable.
176 * The PLL must be enable to switch the GFMUX to a low-power source.
177 */
178 writel_relaxed(PLL5_VOTE, PLL_ENA_GSS);
179 while ((readl_relaxed(PLL5_STATUS) & PLL_STATUS) == 0)
180 cpu_relax();
181
182 /* Perform one-time GSS initialization. */
183 gss_init(drv);
184
185 /* Assert A5 reset. */
186 regval = readl_relaxed(base + GSS_CSR_RESET);
187 regval |= A5_RESET;
188 writel_relaxed(regval, base + GSS_CSR_RESET);
189
190 /* Power down A5 and NAV. */
191 regval = readl_relaxed(base + GSS_CSR_POWER_UP_DOWN);
192 regval &= ~(A5_POWER_ENA|NAV_POWER_ENA);
193 writel_relaxed(regval, base + GSS_CSR_POWER_UP_DOWN);
194
195 /* Select XO clock source and increase dividers to save power. */
196 regval = readl_relaxed(base + GSS_CSR_CLK_BLK_CONFIG);
197 regval |= 0x3FF;
198 writel_relaxed(regval, base + GSS_CSR_CLK_BLK_CONFIG);
199
200 /* Disable bus clocks. */
201 writel_relaxed(0x1F, base + GSS_CSR_CLK_ENABLE);
202
203 /* Clear GSS PLL votes. */
204 writel_relaxed(0, PLL_ENA_GSS);
205 mb();
206
207 clk_disable_unprepare(drv->xo);
Matt Wagantall292aace2012-01-26 19:12:34 -0800208
209 return 0;
210}
211
Matt Wagantall19ac4fd2012-02-03 20:18:23 -0800212static int pil_gss_reset(struct pil_desc *pil)
213{
214 struct gss_data *drv = dev_get_drvdata(pil->dev);
215 void __iomem *base = drv->base;
216 unsigned long start_addr = drv->start_addr;
217 int ret;
218
Matt Wagantallf3471ef2012-03-09 14:21:54 -0800219 /* Unhalt bus port. */
220 ret = msm_bus_axi_portunhalt(MSM_BUS_MASTER_GSS_NAV);
221 if (ret) {
222 dev_err(pil->dev, "Failed to unhalt bus port\n");
Matt Wagantallf3471ef2012-03-09 14:21:54 -0800223 return ret;
224 }
225
Matt Wagantall19ac4fd2012-02-03 20:18:23 -0800226 /* Vote PLL on in GSS's voting register and wait for it to enable. */
227 writel_relaxed(PLL5_VOTE, PLL_ENA_GSS);
228 while ((readl_relaxed(PLL5_STATUS) & PLL_STATUS) == 0)
229 cpu_relax();
230
231 /* Perform GSS initialization. */
232 gss_init(drv);
233
234 /* Configure boot address and enable remap. */
235 writel_relaxed(REMAP_ENABLE | (start_addr >> 16),
236 base + GSS_CSR_BOOT_REMAP);
237
238 /* Power up A5 core. */
239 writel_relaxed(A5_POWER_ENA, base + GSS_CSR_POWER_UP_DOWN);
240 while (!(readl_relaxed(base + GSS_CSR_POWER_UP_DOWN) & A5_POWER_STATUS))
241 cpu_relax();
242
Matt Wagantall556d3f72012-02-16 17:36:29 -0800243 if (cpu_is_apq8064() &&
244 ((SOCINFO_VERSION_MAJOR(socinfo_get_version()) == 1) &&
245 (SOCINFO_VERSION_MINOR(socinfo_get_version()) == 0))) {
246 ret = smp_call_function_single(0, cfg_qgic2_bus_access, drv, 1);
247 if (ret) {
248 pr_err("Failed to configure QGIC2 bus access\n");
249 pil_gss_shutdown(pil);
250 return ret;
251 }
Matt Wagantall19ac4fd2012-02-03 20:18:23 -0800252 }
253
254 /* Release A5 from reset. */
255 writel_relaxed(0x0, base + GSS_CSR_RESET);
256
257 return 0;
258}
259
Matt Wagantall292aace2012-01-26 19:12:34 -0800260static struct pil_reset_ops pil_gss_ops = {
261 .init_image = pil_gss_init_image,
Matt Wagantall292aace2012-01-26 19:12:34 -0800262 .auth_and_reset = pil_gss_reset,
263 .shutdown = pil_gss_shutdown,
Stephen Boydab2b9072012-03-22 10:59:22 -0700264 .proxy_vote = make_gss_proxy_votes,
265 .proxy_unvote = remove_gss_proxy_votes,
Matt Wagantall292aace2012-01-26 19:12:34 -0800266};
267
Matt Wagantall11afeee2012-02-07 18:38:59 -0800268static int pil_gss_init_image_trusted(struct pil_desc *pil,
269 const u8 *metadata, size_t size)
270{
271 return pas_init_image(PAS_GSS, metadata, size);
272}
273
Matt Wagantall556d3f72012-02-16 17:36:29 -0800274static int pil_gss_shutdown_trusted(struct pil_desc *pil)
275{
276 struct gss_data *drv = dev_get_drvdata(pil->dev);
277 int ret;
278
Stephen Boyd7663ccc2012-02-21 19:34:55 -0800279 /*
280 * CXO is used in the secure shutdown code to configure the processor
281 * for low power mode.
282 */
283 ret = clk_prepare_enable(drv->xo);
284 if (ret) {
285 dev_err(pil->dev, "Failed to enable XO\n");
Matt Wagantall556d3f72012-02-16 17:36:29 -0800286 return ret;
Stephen Boyd7663ccc2012-02-21 19:34:55 -0800287 }
Matt Wagantall556d3f72012-02-16 17:36:29 -0800288
Matt Wagantallf3471ef2012-03-09 14:21:54 -0800289 msm_bus_axi_porthalt(MSM_BUS_MASTER_GSS_NAV);
Stephen Boyd7663ccc2012-02-21 19:34:55 -0800290 ret = pas_shutdown(PAS_GSS);
291 clk_disable_unprepare(drv->xo);
Matt Wagantall556d3f72012-02-16 17:36:29 -0800292
293 return ret;
294}
295
Matt Wagantall11afeee2012-02-07 18:38:59 -0800296static int pil_gss_reset_trusted(struct pil_desc *pil)
297{
Matt Wagantall11afeee2012-02-07 18:38:59 -0800298 int err;
299
Matt Wagantallf3471ef2012-03-09 14:21:54 -0800300 err = msm_bus_axi_portunhalt(MSM_BUS_MASTER_GSS_NAV);
301 if (err) {
302 dev_err(pil->dev, "Failed to unhalt bus port\n");
Stephen Boydab2b9072012-03-22 10:59:22 -0700303 goto out;
Matt Wagantallf3471ef2012-03-09 14:21:54 -0800304 }
Matt Wagantall11afeee2012-02-07 18:38:59 -0800305
306 err = pas_auth_and_reset(PAS_GSS);
307 if (err)
Matt Wagantallf3471ef2012-03-09 14:21:54 -0800308 goto halt_port;
Matt Wagantall11afeee2012-02-07 18:38:59 -0800309
Matt Wagantallf3471ef2012-03-09 14:21:54 -0800310 return 0;
Matt Wagantall556d3f72012-02-16 17:36:29 -0800311
Matt Wagantallf3471ef2012-03-09 14:21:54 -0800312halt_port:
313 msm_bus_axi_porthalt(MSM_BUS_MASTER_GSS_NAV);
Matt Wagantallf3471ef2012-03-09 14:21:54 -0800314out:
Matt Wagantall11afeee2012-02-07 18:38:59 -0800315 return err;
316}
317
Matt Wagantall11afeee2012-02-07 18:38:59 -0800318static struct pil_reset_ops pil_gss_ops_trusted = {
319 .init_image = pil_gss_init_image_trusted,
Matt Wagantall11afeee2012-02-07 18:38:59 -0800320 .auth_and_reset = pil_gss_reset_trusted,
321 .shutdown = pil_gss_shutdown_trusted,
Stephen Boydab2b9072012-03-22 10:59:22 -0700322 .proxy_vote = make_gss_proxy_votes,
323 .proxy_unvote = remove_gss_proxy_votes,
Matt Wagantall11afeee2012-02-07 18:38:59 -0800324};
325
Stephen Boydd86214b2012-05-10 15:26:35 -0700326#define MAX_SSR_REASON_LEN 81U
327
328static void log_gss_sfr(void)
329{
330 u32 size;
331 char *smem_reason, reason[MAX_SSR_REASON_LEN];
332
333 smem_reason = smem_get_entry(SMEM_SSR_REASON_MSS0, &size);
334 if (!smem_reason || !size) {
335 pr_err("GSS subsystem failure reason: (unknown, smem_get_entry failed).\n");
336 return;
337 }
338 if (!smem_reason[0]) {
339 pr_err("GSS subsystem failure reason: (unknown, init string found).\n");
340 return;
341 }
342
343 size = min(size, MAX_SSR_REASON_LEN-1);
344 memcpy(reason, smem_reason, size);
345 reason[size] = '\0';
346 pr_err("GSS subsystem failure reason: %s.\n", reason);
347
348 smem_reason[0] = '\0';
349 wmb();
350}
351
352static void restart_gss(struct gss_data *drv)
353{
354 log_gss_sfr();
355 subsystem_restart_dev(drv->subsys);
356}
357
358static void smsm_state_cb(void *data, uint32_t old_state, uint32_t new_state)
359{
360 struct gss_data *drv = data;
361
362 /* Ignore if we're the one that set SMSM_RESET */
363 if (drv->crash_shutdown)
364 return;
365
366 if (new_state & SMSM_RESET) {
367 pr_err("GSS SMSM state changed to SMSM_RESET.\n"
368 "Probable err_fatal on the GSS. "
369 "Calling subsystem restart...\n");
370 restart_gss(drv);
371 }
372}
373
Stephen Boyd4684add2012-06-27 12:57:18 -0700374static int gss_start(const struct subsys_desc *desc)
375{
376 void *ret;
377 struct gss_data *drv;
378
379 drv = container_of(desc, struct gss_data, subsys_desc);
380 ret = pil_get("gss");
381 if (IS_ERR(ret))
382 return PTR_ERR(ret);
383 return 0;
384}
385
386static void gss_stop(const struct subsys_desc *desc)
387{
388 struct gss_data *drv;
389
390 drv = container_of(desc, struct gss_data, subsys_desc);
391 pil_put(drv->pil);
392}
393
Stephen Boydd86214b2012-05-10 15:26:35 -0700394static int gss_shutdown(const struct subsys_desc *desc)
395{
396 struct gss_data *drv = container_of(desc, struct gss_data, subsys_desc);
397
398 pil_force_shutdown("gss");
399 disable_irq_nosync(drv->irq);
400
401 return 0;
402}
403
404static int gss_powerup(const struct subsys_desc *desc)
405{
406 struct gss_data *drv = container_of(desc, struct gss_data, subsys_desc);
407
408 pil_force_boot("gss");
409 enable_irq(drv->irq);
410 return 0;
411}
412
413void gss_crash_shutdown(const struct subsys_desc *desc)
414{
415 struct gss_data *drv = container_of(desc, struct gss_data, subsys_desc);
416
417 drv->crash_shutdown = 1;
418 smsm_reset_modem(SMSM_RESET);
419}
420
421/* FIXME: Get address, size from PIL */
422static struct ramdump_segment gss_segments[] = {
423 {0x89000000, 0x00D00000}
424};
425
426static struct ramdump_segment smem_segments[] = {
427 {0x80000000, 0x00200000},
428};
429
430static int gss_ramdump(int enable, const struct subsys_desc *desc)
431{
432 int ret;
433 struct gss_data *drv = container_of(desc, struct gss_data, subsys_desc);
434
435 if (enable) {
436 ret = do_ramdump(drv->ramdump_dev, gss_segments,
437 ARRAY_SIZE(gss_segments));
438 if (ret < 0) {
439 pr_err("Unable to dump gss memory\n");
440 return ret;
441 }
442
443 ret = do_ramdump(drv->smem_ramdump_dev, smem_segments,
444 ARRAY_SIZE(smem_segments));
445 if (ret < 0) {
446 pr_err("Unable to dump smem memory (rc = %d).\n", ret);
447 return ret;
448 }
449 }
450
451 return 0;
452}
453
454static irqreturn_t gss_wdog_bite_irq(int irq, void *dev_id)
455{
456 struct gss_data *drv = dev_id;
457
458 pr_err("Watchdog bite received from GSS!\n");
459 restart_gss(drv);
460
461 return IRQ_HANDLED;
462}
463
464static int gss_open(struct inode *inode, struct file *filp)
465{
Stephen Boydd86214b2012-05-10 15:26:35 -0700466 struct miscdevice *c = filp->private_data;
467 struct gss_data *drv = container_of(c, struct gss_data, misc_dev);
468
Stephen Boyd4684add2012-06-27 12:57:18 -0700469 drv->subsys_handle = subsystem_get("gss");
470 if (!drv->subsys_handle)
471 pr_debug("%s - subsystem_get returned NULL\n", __func__);
Stephen Boydd86214b2012-05-10 15:26:35 -0700472
473 return 0;
474}
475
476static int gss_release(struct inode *inode, struct file *filp)
477{
478 struct miscdevice *c = filp->private_data;
479 struct gss_data *drv = container_of(c, struct gss_data, misc_dev);
480
Stephen Boyd4684add2012-06-27 12:57:18 -0700481 subsystem_put(drv->subsys_handle);
482 pr_debug("%s subsystem_put called on GSS\n", __func__);
Stephen Boydd86214b2012-05-10 15:26:35 -0700483
484 return 0;
485}
486
487const struct file_operations gss_file_ops = {
488 .open = gss_open,
489 .release = gss_release,
490 .owner = THIS_MODULE,
491};
492
Matt Wagantall292aace2012-01-26 19:12:34 -0800493static int __devinit pil_gss_probe(struct platform_device *pdev)
494{
495 struct gss_data *drv;
496 struct resource *res;
497 struct pil_desc *desc;
Stephen Boydd86214b2012-05-10 15:26:35 -0700498 int ret;
Matt Wagantall292aace2012-01-26 19:12:34 -0800499
500 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
501 if (!res)
502 return -EINVAL;
503
504 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
505 if (!drv)
506 return -ENOMEM;
507 platform_set_drvdata(pdev, drv);
508
509 drv->base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
510 if (!drv->base)
511 return -ENOMEM;
512
513 desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL);
514 if (!desc)
515 return -ENOMEM;
516
Matt Wagantall19ac4fd2012-02-03 20:18:23 -0800517 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
518 if (!res)
519 return -EINVAL;
520
521 drv->qgic2_base = devm_ioremap(&pdev->dev, res->start,
522 resource_size(res));
523 if (!drv->qgic2_base)
524 return -ENOMEM;
525
Stephen Boyd22b04472012-03-23 15:23:10 -0700526 drv->xo = devm_clk_get(&pdev->dev, "xo");
Matt Wagantall292aace2012-01-26 19:12:34 -0800527 if (IS_ERR(drv->xo))
528 return PTR_ERR(drv->xo);
529
Stephen Boydd86214b2012-05-10 15:26:35 -0700530 drv->irq = platform_get_irq(pdev, 0);
531 if (drv->irq < 0)
532 return drv->irq;
533
Matt Wagantall292aace2012-01-26 19:12:34 -0800534 desc->name = "gss";
535 desc->dev = &pdev->dev;
Stephen Boyd6d67d252011-09-27 11:50:05 -0700536 desc->owner = THIS_MODULE;
Stephen Boydab2b9072012-03-22 10:59:22 -0700537 desc->proxy_timeout = 10000;
Matt Wagantall292aace2012-01-26 19:12:34 -0800538
Matt Wagantall11afeee2012-02-07 18:38:59 -0800539 if (pas_supported(PAS_GSS) > 0) {
540 desc->ops = &pil_gss_ops_trusted;
541 dev_info(&pdev->dev, "using secure boot\n");
542 } else {
543 desc->ops = &pil_gss_ops;
544 dev_info(&pdev->dev, "using non-secure boot\n");
545 }
Stephen Boyd95a1c542012-06-21 12:45:11 -0700546 /* Force into low power mode because hardware doesn't do this */
547 desc->ops->shutdown(desc);
Matt Wagantall292aace2012-01-26 19:12:34 -0800548
Stephen Boyd6d67d252011-09-27 11:50:05 -0700549 drv->pil = msm_pil_register(desc);
550 if (IS_ERR(drv->pil)) {
Stephen Boyd6d67d252011-09-27 11:50:05 -0700551 return PTR_ERR(drv->pil);
Matt Wagantall292aace2012-01-26 19:12:34 -0800552 }
Stephen Boydd86214b2012-05-10 15:26:35 -0700553
554 ret = smsm_state_cb_register(SMSM_MODEM_STATE, SMSM_RESET,
555 smsm_state_cb, drv);
556 if (ret < 0)
557 dev_warn(&pdev->dev, "Unable to register SMSM callback\n");
558
559 drv->subsys_desc.name = "gss";
Stephen Boyd4684add2012-06-27 12:57:18 -0700560 drv->subsys_desc.dev = &pdev->dev;
561 drv->subsys_desc.owner = THIS_MODULE;
562 drv->subsys_desc.start = gss_start;
563 drv->subsys_desc.stop = gss_stop;
Stephen Boydd86214b2012-05-10 15:26:35 -0700564 drv->subsys_desc.shutdown = gss_shutdown;
565 drv->subsys_desc.powerup = gss_powerup;
566 drv->subsys_desc.ramdump = gss_ramdump;
567 drv->subsys_desc.crash_shutdown = gss_crash_shutdown;
568
569 drv->subsys = subsys_register(&drv->subsys_desc);
570 if (IS_ERR(drv->subsys)) {
571 ret = PTR_ERR(drv->subsys);
572 goto err_subsys;
573 }
574
575 drv->misc_dev.minor = MISC_DYNAMIC_MINOR;
576 drv->misc_dev.name = "gss";
577 drv->misc_dev.fops = &gss_file_ops;
578 ret = misc_register(&drv->misc_dev);
579 if (ret)
580 goto err_misc;
581
582 drv->ramdump_dev = create_ramdump_device("gss");
583 if (!drv->ramdump_dev) {
584 ret = -ENOMEM;
585 goto err_ramdump;
586 }
587
588 drv->smem_ramdump_dev = create_ramdump_device("smem-gss");
589 if (!drv->smem_ramdump_dev) {
590 ret = -ENOMEM;
591 goto err_smem;
592 }
593
594 ret = devm_request_irq(&pdev->dev, drv->irq, gss_wdog_bite_irq,
595 IRQF_TRIGGER_RISING, "gss_a5_wdog", drv);
596 if (ret < 0)
597 goto err;
Stephen Boyd6d67d252011-09-27 11:50:05 -0700598 return 0;
Stephen Boydd86214b2012-05-10 15:26:35 -0700599err:
600 destroy_ramdump_device(drv->smem_ramdump_dev);
601err_smem:
602 destroy_ramdump_device(drv->ramdump_dev);
603err_ramdump:
604 misc_deregister(&drv->misc_dev);
605err_misc:
606 subsys_unregister(drv->subsys);
607err_subsys:
608 msm_pil_unregister(drv->pil);
609 return ret;
Matt Wagantall292aace2012-01-26 19:12:34 -0800610}
611
612static int __devexit pil_gss_remove(struct platform_device *pdev)
613{
614 struct gss_data *drv = platform_get_drvdata(pdev);
Stephen Boydd86214b2012-05-10 15:26:35 -0700615
616 destroy_ramdump_device(drv->smem_ramdump_dev);
617 destroy_ramdump_device(drv->ramdump_dev);
618 misc_deregister(&drv->misc_dev);
619 subsys_unregister(drv->subsys);
Stephen Boyd6d67d252011-09-27 11:50:05 -0700620 msm_pil_unregister(drv->pil);
Stephen Boydd86214b2012-05-10 15:26:35 -0700621
Matt Wagantall292aace2012-01-26 19:12:34 -0800622 return 0;
623}
624
625static struct platform_driver pil_gss_driver = {
626 .probe = pil_gss_probe,
627 .remove = __devexit_p(pil_gss_remove),
628 .driver = {
629 .name = "pil_gss",
630 .owner = THIS_MODULE,
631 },
632};
633
634static int __init pil_gss_init(void)
635{
636 return platform_driver_register(&pil_gss_driver);
637}
638module_init(pil_gss_init);
639
640static void __exit pil_gss_exit(void)
641{
642 platform_driver_unregister(&pil_gss_driver);
643}
644module_exit(pil_gss_exit);
645
646MODULE_DESCRIPTION("Support for booting the GSS processor");
647MODULE_LICENSE("GPL v2");