blob: 6cd6ffeda4ad3bea6511da50fbd30d31d8b9452b [file] [log] [blame]
Matt Wagantallc2bbdc32012-03-21 19:44:50 -07001/*
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -08002 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Matt Wagantallc2bbdc32012-03-21 19:44:50 -07003 *
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/init.h>
15#include <linux/module.h>
16#include <linux/platform_device.h>
17#include <linux/io.h>
Matt Wagantallc2bbdc32012-03-21 19:44:50 -070018#include <linux/err.h>
19#include <linux/of.h>
Matt Wagantalld41ce772012-05-10 23:16:41 -070020#include <linux/clk.h>
Stephen Boyd633eb622012-06-13 12:05:35 -070021#include <linux/workqueue.h>
22#include <linux/interrupt.h>
23#include <linux/delay.h>
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -080024#include <linux/sysfs.h>
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -070025#include <linux/of_gpio.h>
Stephen Boyd633eb622012-06-13 12:05:35 -070026
Matt Wagantall8c2246d2012-08-12 17:08:04 -070027#include <mach/clk.h>
Stephen Boyd633eb622012-06-13 12:05:35 -070028#include <mach/subsystem_restart.h>
29#include <mach/subsystem_notif.h>
30#include <mach/scm.h>
Seemanta Dutta4e2d49c2013-04-05 16:28:11 -070031#include <mach/ramdump.h>
Jeff Hugo5ba15fe2013-05-06 14:24:24 -060032#include <mach/msm_smem.h>
Stephen Boyd633eb622012-06-13 12:05:35 -070033
Matt Wagantallc2bbdc32012-03-21 19:44:50 -070034#include "peripheral-loader.h"
35#include "pil-q6v5.h"
Matt Wagantall10a59672012-07-26 11:52:02 -070036#include "scm-pas.h"
Stephen Boyd633eb622012-06-13 12:05:35 -070037#include "sysmon.h"
Matt Wagantallc2bbdc32012-03-21 19:44:50 -070038
Matt Wagantallc2bbdc32012-03-21 19:44:50 -070039#define QDSP6SS_RST_EVB 0x010
Matt Wagantall4d89c2e2012-05-25 19:28:34 -070040#define PROXY_TIMEOUT_MS 10000
Matt Wagantallc2bbdc32012-03-21 19:44:50 -070041
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -080042static struct kobject *lpass_status;
43static char status[32];
44
Stephen Boyd633eb622012-06-13 12:05:35 -070045struct lpass_data {
46 struct q6v5_data *q6;
47 struct subsys_device *subsys;
48 struct subsys_desc subsys_desc;
49 void *ramdump_dev;
50 int wdog_irq;
51 struct work_struct work;
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -070052 void *wcnss_notif_hdle;
Stephen Boyd633eb622012-06-13 12:05:35 -070053 void *modem_notif_hdle;
54 int crash_shutdown;
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -070055 unsigned int err_fatal_irq;
56 int force_stop_gpio;
Stephen Boyd633eb622012-06-13 12:05:35 -070057};
58
59#define subsys_to_drv(d) container_of(d, struct lpass_data, subsys_desc)
60
Matt Wagantall8c2246d2012-08-12 17:08:04 -070061static int pil_lpass_enable_clks(struct q6v5_data *drv)
62{
63 int ret;
64
65 ret = clk_reset(drv->core_clk, CLK_RESET_DEASSERT);
66 if (ret)
67 goto err_reset;
68 ret = clk_prepare_enable(drv->core_clk);
69 if (ret)
70 goto err_core_clk;
71 ret = clk_prepare_enable(drv->ahb_clk);
72 if (ret)
73 goto err_ahb_clk;
74 ret = clk_prepare_enable(drv->axi_clk);
75 if (ret)
76 goto err_axi_clk;
77 ret = clk_prepare_enable(drv->reg_clk);
78 if (ret)
79 goto err_reg_clk;
80
81 return 0;
82
83err_reg_clk:
84 clk_disable_unprepare(drv->axi_clk);
85err_axi_clk:
86 clk_disable_unprepare(drv->ahb_clk);
87err_ahb_clk:
88 clk_disable_unprepare(drv->core_clk);
89err_core_clk:
90 clk_reset(drv->core_clk, CLK_RESET_ASSERT);
91err_reset:
92 return ret;
93}
94
95static void pil_lpass_disable_clks(struct q6v5_data *drv)
96{
97 clk_disable_unprepare(drv->reg_clk);
98 clk_disable_unprepare(drv->axi_clk);
99 clk_disable_unprepare(drv->ahb_clk);
100 clk_disable_unprepare(drv->core_clk);
101 clk_reset(drv->core_clk, CLK_RESET_ASSERT);
102}
103
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700104static int pil_lpass_shutdown(struct pil_desc *pil)
105{
Stephen Boyd3826cd42012-07-05 17:37:53 -0700106 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700107
Matt Wagantallb7747992012-05-11 19:37:51 -0700108 pil_q6v5_halt_axi_port(pil, drv->axi_halt_base);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700109
Matt Wagantalld41ce772012-05-10 23:16:41 -0700110 /*
111 * If the shutdown function is called before the reset function, clocks
112 * will not be enabled yet. Enable them here so that register writes
113 * performed during the shutdown succeed.
114 */
115 if (drv->is_booted == false)
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700116 pil_lpass_enable_clks(drv);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700117
118 pil_q6v5_shutdown(pil);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700119 pil_lpass_disable_clks(drv);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700120
Matt Wagantall015b50af2013-03-05 18:51:16 -0800121 writel_relaxed(1, drv->restart_reg);
122
Matt Wagantalld41ce772012-05-10 23:16:41 -0700123 drv->is_booted = false;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700124
125 return 0;
126}
127
128static int pil_lpass_reset(struct pil_desc *pil)
129{
Stephen Boyd3826cd42012-07-05 17:37:53 -0700130 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Tianyi Gou819851e2013-04-16 16:05:56 -0700131 phys_addr_t start_addr = pil_get_entry_addr(pil);
Matt Wagantalld41ce772012-05-10 23:16:41 -0700132 int ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700133
Matt Wagantall015b50af2013-03-05 18:51:16 -0800134 /* Deassert reset to subsystem and wait for propagation */
135 writel_relaxed(0, drv->restart_reg);
136 mb();
137 udelay(2);
138
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700139 ret = pil_lpass_enable_clks(drv);
Matt Wagantalld41ce772012-05-10 23:16:41 -0700140 if (ret)
141 return ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700142
143 /* Program Image Address */
Stephen Boyd3030c252012-08-08 17:24:05 -0700144 writel_relaxed((start_addr >> 4) & 0x0FFFFFF0,
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700145 drv->reg_base + QDSP6SS_RST_EVB);
146
Matt Wagantalld41ce772012-05-10 23:16:41 -0700147 ret = pil_q6v5_reset(pil);
148 if (ret) {
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700149 pil_lpass_disable_clks(drv);
Matt Wagantalld41ce772012-05-10 23:16:41 -0700150 return ret;
151 }
152
153 drv->is_booted = true;
154
155 return 0;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700156}
157
158static struct pil_reset_ops pil_lpass_ops = {
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700159 .proxy_vote = pil_q6v5_make_proxy_votes,
160 .proxy_unvote = pil_q6v5_remove_proxy_votes,
161 .auth_and_reset = pil_lpass_reset,
162 .shutdown = pil_lpass_shutdown,
163};
164
Matt Wagantall10a59672012-07-26 11:52:02 -0700165static int pil_lpass_init_image_trusted(struct pil_desc *pil,
166 const u8 *metadata, size_t size)
167{
168 return pas_init_image(PAS_Q6, metadata, size);
169}
170
Stephen Boydc8c5db92012-12-03 11:13:20 -0800171static int pil_lpass_mem_setup_trusted(struct pil_desc *pil, phys_addr_t addr,
172 size_t size)
173{
174 return pas_mem_setup(PAS_Q6, addr, size);
175}
176
Matt Wagantall10a59672012-07-26 11:52:02 -0700177static int pil_lpass_reset_trusted(struct pil_desc *pil)
178{
Vikram Mulukutlaa30b53a2013-05-28 15:47:22 -0700179 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
180 int ret;
181
182 ret = clk_prepare_enable(drv->axi_clk);
183 if (ret)
184 return ret;
Matt Wagantall10a59672012-07-26 11:52:02 -0700185 return pas_auth_and_reset(PAS_Q6);
186}
187
188static int pil_lpass_shutdown_trusted(struct pil_desc *pil)
189{
Vikram Mulukutlaa30b53a2013-05-28 15:47:22 -0700190 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
191 int ret;
192
193 ret = pas_shutdown(PAS_Q6);
194 if (ret)
195 return ret;
196 clk_disable_unprepare(drv->axi_clk);
197 return 0;
Matt Wagantall10a59672012-07-26 11:52:02 -0700198}
199
200static struct pil_reset_ops pil_lpass_ops_trusted = {
201 .init_image = pil_lpass_init_image_trusted,
Stephen Boydc8c5db92012-12-03 11:13:20 -0800202 .mem_setup = pil_lpass_mem_setup_trusted,
Matt Wagantall10a59672012-07-26 11:52:02 -0700203 .proxy_vote = pil_q6v5_make_proxy_votes,
204 .proxy_unvote = pil_q6v5_remove_proxy_votes,
205 .auth_and_reset = pil_lpass_reset_trusted,
206 .shutdown = pil_lpass_shutdown_trusted,
207};
208
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700209static int wcnss_notifier_cb(struct notifier_block *this, unsigned long code,
Stephen Boyd633eb622012-06-13 12:05:35 -0700210 void *ss_handle)
211{
212 int ret;
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700213 pr_debug("%s: W-Notify: event %lu\n", __func__, code);
214 ret = sysmon_send_event(SYSMON_SS_LPASS, "wcnss", code);
215 if (ret < 0)
216 pr_err("%s: sysmon_send_event error %d", __func__, ret);
Stephen Boyd633eb622012-06-13 12:05:35 -0700217 return NOTIFY_DONE;
218}
219
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700220static struct notifier_block wnb = {
221 .notifier_call = wcnss_notifier_cb,
Stephen Boyd633eb622012-06-13 12:05:35 -0700222};
223
224static int modem_notifier_cb(struct notifier_block *this, unsigned long code,
225 void *ss_handle)
226{
227 int ret;
Ravishankar Sarawadifadfe3b2012-10-12 11:28:24 -0700228 pr_debug("%s: M-Notify: event %lu\n", __func__, code);
229 ret = sysmon_send_event(SYSMON_SS_LPASS, "modem", code);
230 if (ret < 0)
231 pr_err("%s: sysmon_send_event error %d", __func__, ret);
Stephen Boyd633eb622012-06-13 12:05:35 -0700232 return NOTIFY_DONE;
233}
234
235static struct notifier_block mnb = {
236 .notifier_call = modem_notifier_cb,
237};
238
239static void adsp_log_failure_reason(void)
240{
241 char *reason;
242 char buffer[81];
243 unsigned size;
244
245 reason = smem_get_entry(SMEM_SSR_REASON_LPASS0, &size);
246
247 if (!reason) {
248 pr_err("ADSP subsystem failure reason: (unknown, smem_get_entry failed).");
249 return;
250 }
251
252 if (reason[0] == '\0') {
253 pr_err("ADSP subsystem failure reason: (unknown, init value found)");
254 return;
255 }
256
257 size = min(size, sizeof(buffer) - 1);
258 memcpy(buffer, reason, size);
259 buffer[size] = '\0';
260 pr_err("ADSP subsystem failure reason: %s", buffer);
261 memset((void *)reason, 0x0, size);
262 wmb();
263}
264
265static void restart_adsp(struct lpass_data *drv)
266{
267 adsp_log_failure_reason();
268 subsystem_restart_dev(drv->subsys);
269}
270
271static void adsp_fatal_fn(struct work_struct *work)
272{
273 struct lpass_data *drv = container_of(work, struct lpass_data, work);
274
275 pr_err("Watchdog bite received from ADSP!\n");
276 restart_adsp(drv);
277}
278
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700279static irqreturn_t adsp_err_fatal_intr_handler (int irq, void *dev_id)
Stephen Boyd633eb622012-06-13 12:05:35 -0700280{
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700281 struct lpass_data *drv = dev_id;
Stephen Boyd633eb622012-06-13 12:05:35 -0700282
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700283 /* Ignore if we're the one that set the force stop bit in the outbound
284 * entry
285 */
Stephen Boyd633eb622012-06-13 12:05:35 -0700286 if (drv->crash_shutdown)
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700287 return IRQ_HANDLED;
Stephen Boyd633eb622012-06-13 12:05:35 -0700288
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700289 pr_err("Fatal error on the ADSP!\n");
290 restart_adsp(drv);
291 return IRQ_HANDLED;
Stephen Boyd633eb622012-06-13 12:05:35 -0700292}
293
294#define SCM_Q6_NMI_CMD 0x1
295
296static void send_q6_nmi(void)
297{
298 /* Send NMI to QDSP6 via an SCM call. */
299 scm_call_atomic1(SCM_SVC_UTIL, SCM_Q6_NMI_CMD, 0x1);
300 pr_debug("%s: Q6 NMI was sent.\n", __func__);
301}
302
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800303/*
304 * The "status" file where a static variable is read from and written to.
305 */
306static ssize_t adsp_state_show(struct kobject *kobj,
307 struct kobj_attribute *attr,
308 char *buf)
309{
310 return snprintf(buf, sizeof(status), "%s\n", status);
311}
312
313static struct kobj_attribute adsp_state_attribute =
314 __ATTR(status, 0444, adsp_state_show, NULL);
315
316static struct attribute *attrs[] = {
317 &adsp_state_attribute.attr,
318 NULL, /* need to NULL terminate the list of attributes */
319};
320
321static struct attribute_group attr_group = {
322 .attrs = attrs,
323};
324
325static void adsp_set_state(char *state)
326{
327 strlcpy(status, state, sizeof(status));
328 sysfs_notify(lpass_status, NULL, "status");
329}
330
Stephen Boyd633eb622012-06-13 12:05:35 -0700331#define subsys_to_lpass(d) container_of(d, struct lpass_data, subsys_desc)
332
333static int adsp_shutdown(const struct subsys_desc *subsys)
334{
335 struct lpass_data *drv = subsys_to_lpass(subsys);
336
337 send_q6_nmi();
338 /* The write needs to go through before the q6 is shutdown. */
339 mb();
Stephen Boyde83a0a22012-06-29 13:51:27 -0700340 pil_shutdown(&drv->q6->desc);
Stephen Boyd633eb622012-06-13 12:05:35 -0700341 disable_irq_nosync(drv->wdog_irq);
342
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800343 pr_debug("ADSP is Down\n");
344 adsp_set_state("OFFLINE");
Stephen Boyd633eb622012-06-13 12:05:35 -0700345 return 0;
346}
347
348static int adsp_powerup(const struct subsys_desc *subsys)
349{
350 struct lpass_data *drv = subsys_to_lpass(subsys);
351 int ret = 0;
Stephen Boyde83a0a22012-06-29 13:51:27 -0700352 ret = pil_boot(&drv->q6->desc);
Stephen Boyd633eb622012-06-13 12:05:35 -0700353 enable_irq(drv->wdog_irq);
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800354
355 pr_debug("ADSP is back online\n");
356 adsp_set_state("ONLINE");
Stephen Boyd633eb622012-06-13 12:05:35 -0700357 return ret;
358}
359
Stephen Boyd633eb622012-06-13 12:05:35 -0700360static int adsp_ramdump(int enable, const struct subsys_desc *subsys)
361{
362 struct lpass_data *drv = subsys_to_lpass(subsys);
363
364 if (!enable)
365 return 0;
Stephen Boyd5eb17ce2012-11-29 15:34:21 -0800366
367 return pil_do_ramdump(&drv->q6->desc, drv->ramdump_dev);
Stephen Boyd633eb622012-06-13 12:05:35 -0700368}
369
370static void adsp_crash_shutdown(const struct subsys_desc *subsys)
371{
372 struct lpass_data *drv = subsys_to_lpass(subsys);
373
374 drv->crash_shutdown = 1;
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700375 gpio_set_value(drv->force_stop_gpio, 1);
Stephen Boyd633eb622012-06-13 12:05:35 -0700376 send_q6_nmi();
377}
378
379static irqreturn_t adsp_wdog_bite_irq(int irq, void *dev_id)
380{
381 struct lpass_data *drv = dev_id;
382
383 disable_irq_nosync(drv->wdog_irq);
384 schedule_work(&drv->work);
385
386 return IRQ_HANDLED;
387}
388
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700389static int lpass_start(const struct subsys_desc *desc)
390{
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700391 struct lpass_data *drv = subsys_to_drv(desc);
392
Stephen Boyde83a0a22012-06-29 13:51:27 -0700393 return pil_boot(&drv->q6->desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700394}
395
396static void lpass_stop(const struct subsys_desc *desc)
397{
398 struct lpass_data *drv = subsys_to_drv(desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700399 pil_shutdown(&drv->q6->desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700400}
401
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700402static int __devinit pil_lpass_driver_probe(struct platform_device *pdev)
403{
Stephen Boyd633eb622012-06-13 12:05:35 -0700404 struct lpass_data *drv;
405 struct q6v5_data *q6;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700406 struct pil_desc *desc;
Matt Wagantall015b50af2013-03-05 18:51:16 -0800407 struct resource *res;
Ravishankar Sarawadiab203a82013-04-09 18:46:11 -0700408 int ret, gpio_clk_ready;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700409
Stephen Boyd633eb622012-06-13 12:05:35 -0700410 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
411 if (!drv)
412 return -ENOMEM;
Stephen Boyd3826cd42012-07-05 17:37:53 -0700413 platform_set_drvdata(pdev, drv);
Matt Wagantall55252f12012-05-02 18:02:54 -0700414
Stephen Boyd633eb622012-06-13 12:05:35 -0700415 drv->wdog_irq = platform_get_irq(pdev, 0);
416 if (drv->wdog_irq < 0)
417 return drv->wdog_irq;
418
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700419 ret = gpio_to_irq(of_get_named_gpio(pdev->dev.of_node,
420 "qcom,gpio-err-fatal", 0));
421 if (ret < 0)
422 return ret;
423 drv->err_fatal_irq = ret;
424
Ravishankar Sarawadiab203a82013-04-09 18:46:11 -0700425 ret = gpio_to_irq(of_get_named_gpio(pdev->dev.of_node,
426 "qcom,gpio-proxy-unvote", 0));
427 if (ret < 0)
428 return ret;
429 gpio_clk_ready = ret;
430
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700431 drv->force_stop_gpio = of_get_named_gpio(pdev->dev.of_node,
432 "qcom,gpio-force-stop", 0);
433 if (drv->force_stop_gpio < 0)
434 return drv->force_stop_gpio;
435
Stephen Boyd633eb622012-06-13 12:05:35 -0700436 q6 = pil_q6v5_init(pdev);
437 if (IS_ERR(q6))
438 return PTR_ERR(q6);
439 drv->q6 = q6;
440
441 desc = &q6->desc;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700442 desc->owner = THIS_MODULE;
Matt Wagantall4d89c2e2012-05-25 19:28:34 -0700443 desc->proxy_timeout = PROXY_TIMEOUT_MS;
Ravishankar Sarawadiab203a82013-04-09 18:46:11 -0700444 desc->proxy_unvote_irq = gpio_clk_ready;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700445
Matt Wagantall015b50af2013-03-05 18:51:16 -0800446 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "restart_reg");
447 q6->restart_reg = devm_request_and_ioremap(&pdev->dev, res);
448 if (!q6->restart_reg)
449 return -ENOMEM;
450
Stephen Boyd633eb622012-06-13 12:05:35 -0700451 q6->core_clk = devm_clk_get(&pdev->dev, "core_clk");
452 if (IS_ERR(q6->core_clk))
453 return PTR_ERR(q6->core_clk);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700454
Stephen Boyd633eb622012-06-13 12:05:35 -0700455 q6->ahb_clk = devm_clk_get(&pdev->dev, "iface_clk");
456 if (IS_ERR(q6->ahb_clk))
457 return PTR_ERR(q6->ahb_clk);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700458
Stephen Boyd633eb622012-06-13 12:05:35 -0700459 q6->axi_clk = devm_clk_get(&pdev->dev, "bus_clk");
460 if (IS_ERR(q6->axi_clk))
461 return PTR_ERR(q6->axi_clk);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700462
Stephen Boyd633eb622012-06-13 12:05:35 -0700463 q6->reg_clk = devm_clk_get(&pdev->dev, "reg_clk");
464 if (IS_ERR(q6->reg_clk))
465 return PTR_ERR(q6->reg_clk);
Matt Wagantall56865f02012-08-09 15:03:36 -0700466
Matt Wagantall10a59672012-07-26 11:52:02 -0700467 if (pas_supported(PAS_Q6) > 0) {
468 desc->ops = &pil_lpass_ops_trusted;
469 dev_info(&pdev->dev, "using secure boot\n");
470 } else {
471 desc->ops = &pil_lpass_ops;
472 dev_info(&pdev->dev, "using non-secure boot\n");
473 }
474
Stephen Boyde83a0a22012-06-29 13:51:27 -0700475 ret = pil_desc_init(desc);
476 if (ret)
477 return ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700478
Stephen Boyd633eb622012-06-13 12:05:35 -0700479 drv->subsys_desc.name = desc->name;
480 drv->subsys_desc.owner = THIS_MODULE;
481 drv->subsys_desc.dev = &pdev->dev;
482 drv->subsys_desc.shutdown = adsp_shutdown;
483 drv->subsys_desc.powerup = adsp_powerup;
484 drv->subsys_desc.ramdump = adsp_ramdump;
485 drv->subsys_desc.crash_shutdown = adsp_crash_shutdown;
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700486 drv->subsys_desc.start = lpass_start;
487 drv->subsys_desc.stop = lpass_stop;
Stephen Boyd633eb622012-06-13 12:05:35 -0700488
489 INIT_WORK(&drv->work, adsp_fatal_fn);
490
Stephen Boydc1a72612012-07-05 14:07:35 -0700491 drv->ramdump_dev = create_ramdump_device("adsp", &pdev->dev);
Stephen Boyd633eb622012-06-13 12:05:35 -0700492 if (!drv->ramdump_dev) {
493 ret = -ENOMEM;
494 goto err_ramdump;
495 }
496
497 drv->subsys = subsys_register(&drv->subsys_desc);
498 if (IS_ERR(drv->subsys)) {
499 ret = PTR_ERR(drv->subsys);
500 goto err_subsys;
501 }
502
503 ret = devm_request_irq(&pdev->dev, drv->wdog_irq, adsp_wdog_bite_irq,
504 IRQF_TRIGGER_RISING, dev_name(&pdev->dev), drv);
505 if (ret)
506 goto err_irq;
507
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700508 ret = devm_request_irq(&pdev->dev, drv->err_fatal_irq,
509 adsp_err_fatal_intr_handler,
510 IRQF_TRIGGER_RISING,
511 dev_name(&pdev->dev), drv);
512 if (ret)
513 goto err_irq;
Stephen Boyd633eb622012-06-13 12:05:35 -0700514
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700515 drv->wcnss_notif_hdle = subsys_notif_register_notifier("wcnss", &wnb);
516 if (IS_ERR(drv->wcnss_notif_hdle)) {
517 ret = PTR_ERR(drv->wcnss_notif_hdle);
518 goto err_notif_wcnss;
Stephen Boyd633eb622012-06-13 12:05:35 -0700519 }
520
521 drv->modem_notif_hdle = subsys_notif_register_notifier("modem", &mnb);
522 if (IS_ERR(drv->modem_notif_hdle)) {
523 ret = PTR_ERR(drv->modem_notif_hdle);
524 goto err_notif_modem;
525 }
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800526 lpass_status = kobject_create_and_add("audio_voice_service",
527 kernel_kobj);
528 if (!lpass_status) {
529 pr_err("%s: kobject create failed\n", __func__);
530 ret = -ENOMEM;
531 goto err_notif_modem;
532 }
533
534 ret = sysfs_create_group(lpass_status, &attr_group);
535 if (ret) {
536 pr_err("%s: sysfs create group failed\n", __func__);
537 goto err_kobj;
538 }
539
540 adsp_set_state("ONLINE");
Stephen Boyd633eb622012-06-13 12:05:35 -0700541 return 0;
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800542err_kobj:
543 kobject_put(lpass_status);
Stephen Boyd633eb622012-06-13 12:05:35 -0700544err_notif_modem:
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700545 subsys_notif_unregister_notifier(drv->wcnss_notif_hdle, &wnb);
546err_notif_wcnss:
Stephen Boyd633eb622012-06-13 12:05:35 -0700547err_irq:
548 subsys_unregister(drv->subsys);
549err_subsys:
550 destroy_ramdump_device(drv->ramdump_dev);
551err_ramdump:
Stephen Boyde83a0a22012-06-29 13:51:27 -0700552 pil_desc_release(desc);
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800553 return ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700554}
555
556static int __devexit pil_lpass_driver_exit(struct platform_device *pdev)
557{
Stephen Boyd633eb622012-06-13 12:05:35 -0700558 struct lpass_data *drv = platform_get_drvdata(pdev);
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700559 subsys_notif_unregister_notifier(drv->wcnss_notif_hdle, &wnb);
Stephen Boyd633eb622012-06-13 12:05:35 -0700560 subsys_notif_unregister_notifier(drv->modem_notif_hdle, &mnb);
Stephen Boyd633eb622012-06-13 12:05:35 -0700561 subsys_unregister(drv->subsys);
562 destroy_ramdump_device(drv->ramdump_dev);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700563 pil_desc_release(&drv->q6->desc);
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800564 sysfs_remove_group(lpass_status, &attr_group);
565 kobject_del(lpass_status);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700566 return 0;
567}
568
569static struct of_device_id lpass_match_table[] = {
570 { .compatible = "qcom,pil-q6v5-lpass" },
571 {}
572};
573
574static struct platform_driver pil_lpass_driver = {
575 .probe = pil_lpass_driver_probe,
576 .remove = __devexit_p(pil_lpass_driver_exit),
577 .driver = {
578 .name = "pil-q6v5-lpass",
579 .of_match_table = lpass_match_table,
580 .owner = THIS_MODULE,
581 },
582};
583
584static int __init pil_lpass_init(void)
585{
586 return platform_driver_register(&pil_lpass_driver);
587}
588module_init(pil_lpass_init);
589
590static void __exit pil_lpass_exit(void)
591{
592 platform_driver_unregister(&pil_lpass_driver);
593}
594module_exit(pil_lpass_exit);
595
596MODULE_DESCRIPTION("Support for booting low-power audio subsystems with QDSP6v5 (Hexagon) processors");
597MODULE_LICENSE("GPL v2");