blob: 19b567194cec09cfec56d4994f8661edac453a6f [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{
179 return pas_auth_and_reset(PAS_Q6);
180}
181
182static int pil_lpass_shutdown_trusted(struct pil_desc *pil)
183{
184 return pas_shutdown(PAS_Q6);
185}
186
187static struct pil_reset_ops pil_lpass_ops_trusted = {
188 .init_image = pil_lpass_init_image_trusted,
Stephen Boydc8c5db92012-12-03 11:13:20 -0800189 .mem_setup = pil_lpass_mem_setup_trusted,
Matt Wagantall10a59672012-07-26 11:52:02 -0700190 .proxy_vote = pil_q6v5_make_proxy_votes,
191 .proxy_unvote = pil_q6v5_remove_proxy_votes,
192 .auth_and_reset = pil_lpass_reset_trusted,
193 .shutdown = pil_lpass_shutdown_trusted,
194};
195
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700196static int wcnss_notifier_cb(struct notifier_block *this, unsigned long code,
Stephen Boyd633eb622012-06-13 12:05:35 -0700197 void *ss_handle)
198{
199 int ret;
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700200 pr_debug("%s: W-Notify: event %lu\n", __func__, code);
201 ret = sysmon_send_event(SYSMON_SS_LPASS, "wcnss", code);
202 if (ret < 0)
203 pr_err("%s: sysmon_send_event error %d", __func__, ret);
Stephen Boyd633eb622012-06-13 12:05:35 -0700204 return NOTIFY_DONE;
205}
206
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700207static struct notifier_block wnb = {
208 .notifier_call = wcnss_notifier_cb,
Stephen Boyd633eb622012-06-13 12:05:35 -0700209};
210
211static int modem_notifier_cb(struct notifier_block *this, unsigned long code,
212 void *ss_handle)
213{
214 int ret;
Ravishankar Sarawadifadfe3b2012-10-12 11:28:24 -0700215 pr_debug("%s: M-Notify: event %lu\n", __func__, code);
216 ret = sysmon_send_event(SYSMON_SS_LPASS, "modem", code);
217 if (ret < 0)
218 pr_err("%s: sysmon_send_event error %d", __func__, ret);
Stephen Boyd633eb622012-06-13 12:05:35 -0700219 return NOTIFY_DONE;
220}
221
222static struct notifier_block mnb = {
223 .notifier_call = modem_notifier_cb,
224};
225
226static void adsp_log_failure_reason(void)
227{
228 char *reason;
229 char buffer[81];
230 unsigned size;
231
232 reason = smem_get_entry(SMEM_SSR_REASON_LPASS0, &size);
233
234 if (!reason) {
235 pr_err("ADSP subsystem failure reason: (unknown, smem_get_entry failed).");
236 return;
237 }
238
239 if (reason[0] == '\0') {
240 pr_err("ADSP subsystem failure reason: (unknown, init value found)");
241 return;
242 }
243
244 size = min(size, sizeof(buffer) - 1);
245 memcpy(buffer, reason, size);
246 buffer[size] = '\0';
247 pr_err("ADSP subsystem failure reason: %s", buffer);
248 memset((void *)reason, 0x0, size);
249 wmb();
250}
251
252static void restart_adsp(struct lpass_data *drv)
253{
254 adsp_log_failure_reason();
255 subsystem_restart_dev(drv->subsys);
256}
257
258static void adsp_fatal_fn(struct work_struct *work)
259{
260 struct lpass_data *drv = container_of(work, struct lpass_data, work);
261
262 pr_err("Watchdog bite received from ADSP!\n");
263 restart_adsp(drv);
264}
265
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700266static irqreturn_t adsp_err_fatal_intr_handler (int irq, void *dev_id)
Stephen Boyd633eb622012-06-13 12:05:35 -0700267{
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700268 struct lpass_data *drv = dev_id;
Stephen Boyd633eb622012-06-13 12:05:35 -0700269
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700270 /* Ignore if we're the one that set the force stop bit in the outbound
271 * entry
272 */
Stephen Boyd633eb622012-06-13 12:05:35 -0700273 if (drv->crash_shutdown)
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700274 return IRQ_HANDLED;
Stephen Boyd633eb622012-06-13 12:05:35 -0700275
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700276 pr_err("Fatal error on the ADSP!\n");
277 restart_adsp(drv);
278 return IRQ_HANDLED;
Stephen Boyd633eb622012-06-13 12:05:35 -0700279}
280
281#define SCM_Q6_NMI_CMD 0x1
282
283static void send_q6_nmi(void)
284{
285 /* Send NMI to QDSP6 via an SCM call. */
286 scm_call_atomic1(SCM_SVC_UTIL, SCM_Q6_NMI_CMD, 0x1);
287 pr_debug("%s: Q6 NMI was sent.\n", __func__);
288}
289
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800290/*
291 * The "status" file where a static variable is read from and written to.
292 */
293static ssize_t adsp_state_show(struct kobject *kobj,
294 struct kobj_attribute *attr,
295 char *buf)
296{
297 return snprintf(buf, sizeof(status), "%s\n", status);
298}
299
300static struct kobj_attribute adsp_state_attribute =
301 __ATTR(status, 0444, adsp_state_show, NULL);
302
303static struct attribute *attrs[] = {
304 &adsp_state_attribute.attr,
305 NULL, /* need to NULL terminate the list of attributes */
306};
307
308static struct attribute_group attr_group = {
309 .attrs = attrs,
310};
311
312static void adsp_set_state(char *state)
313{
314 strlcpy(status, state, sizeof(status));
315 sysfs_notify(lpass_status, NULL, "status");
316}
317
Stephen Boyd633eb622012-06-13 12:05:35 -0700318#define subsys_to_lpass(d) container_of(d, struct lpass_data, subsys_desc)
319
320static int adsp_shutdown(const struct subsys_desc *subsys)
321{
322 struct lpass_data *drv = subsys_to_lpass(subsys);
323
324 send_q6_nmi();
325 /* The write needs to go through before the q6 is shutdown. */
326 mb();
Stephen Boyde83a0a22012-06-29 13:51:27 -0700327 pil_shutdown(&drv->q6->desc);
Stephen Boyd633eb622012-06-13 12:05:35 -0700328 disable_irq_nosync(drv->wdog_irq);
329
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800330 pr_debug("ADSP is Down\n");
331 adsp_set_state("OFFLINE");
Stephen Boyd633eb622012-06-13 12:05:35 -0700332 return 0;
333}
334
335static int adsp_powerup(const struct subsys_desc *subsys)
336{
337 struct lpass_data *drv = subsys_to_lpass(subsys);
338 int ret = 0;
Stephen Boyde83a0a22012-06-29 13:51:27 -0700339 ret = pil_boot(&drv->q6->desc);
Stephen Boyd633eb622012-06-13 12:05:35 -0700340 enable_irq(drv->wdog_irq);
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800341
342 pr_debug("ADSP is back online\n");
343 adsp_set_state("ONLINE");
Stephen Boyd633eb622012-06-13 12:05:35 -0700344 return ret;
345}
346
Stephen Boyd633eb622012-06-13 12:05:35 -0700347static int adsp_ramdump(int enable, const struct subsys_desc *subsys)
348{
349 struct lpass_data *drv = subsys_to_lpass(subsys);
350
351 if (!enable)
352 return 0;
Stephen Boyd5eb17ce2012-11-29 15:34:21 -0800353
354 return pil_do_ramdump(&drv->q6->desc, drv->ramdump_dev);
Stephen Boyd633eb622012-06-13 12:05:35 -0700355}
356
357static void adsp_crash_shutdown(const struct subsys_desc *subsys)
358{
359 struct lpass_data *drv = subsys_to_lpass(subsys);
360
361 drv->crash_shutdown = 1;
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700362 gpio_set_value(drv->force_stop_gpio, 1);
Stephen Boyd633eb622012-06-13 12:05:35 -0700363 send_q6_nmi();
364}
365
366static irqreturn_t adsp_wdog_bite_irq(int irq, void *dev_id)
367{
368 struct lpass_data *drv = dev_id;
369
370 disable_irq_nosync(drv->wdog_irq);
371 schedule_work(&drv->work);
372
373 return IRQ_HANDLED;
374}
375
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700376static int lpass_start(const struct subsys_desc *desc)
377{
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700378 struct lpass_data *drv = subsys_to_drv(desc);
379
Stephen Boyde83a0a22012-06-29 13:51:27 -0700380 return pil_boot(&drv->q6->desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700381}
382
383static void lpass_stop(const struct subsys_desc *desc)
384{
385 struct lpass_data *drv = subsys_to_drv(desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700386 pil_shutdown(&drv->q6->desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700387}
388
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700389static int __devinit pil_lpass_driver_probe(struct platform_device *pdev)
390{
Stephen Boyd633eb622012-06-13 12:05:35 -0700391 struct lpass_data *drv;
392 struct q6v5_data *q6;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700393 struct pil_desc *desc;
Matt Wagantall015b50af2013-03-05 18:51:16 -0800394 struct resource *res;
Ravishankar Sarawadiab203a82013-04-09 18:46:11 -0700395 int ret, gpio_clk_ready;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700396
Stephen Boyd633eb622012-06-13 12:05:35 -0700397 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
398 if (!drv)
399 return -ENOMEM;
Stephen Boyd3826cd42012-07-05 17:37:53 -0700400 platform_set_drvdata(pdev, drv);
Matt Wagantall55252f12012-05-02 18:02:54 -0700401
Stephen Boyd633eb622012-06-13 12:05:35 -0700402 drv->wdog_irq = platform_get_irq(pdev, 0);
403 if (drv->wdog_irq < 0)
404 return drv->wdog_irq;
405
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700406 ret = gpio_to_irq(of_get_named_gpio(pdev->dev.of_node,
407 "qcom,gpio-err-fatal", 0));
408 if (ret < 0)
409 return ret;
410 drv->err_fatal_irq = ret;
411
Ravishankar Sarawadiab203a82013-04-09 18:46:11 -0700412 ret = gpio_to_irq(of_get_named_gpio(pdev->dev.of_node,
413 "qcom,gpio-proxy-unvote", 0));
414 if (ret < 0)
415 return ret;
416 gpio_clk_ready = ret;
417
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700418 drv->force_stop_gpio = of_get_named_gpio(pdev->dev.of_node,
419 "qcom,gpio-force-stop", 0);
420 if (drv->force_stop_gpio < 0)
421 return drv->force_stop_gpio;
422
Stephen Boyd633eb622012-06-13 12:05:35 -0700423 q6 = pil_q6v5_init(pdev);
424 if (IS_ERR(q6))
425 return PTR_ERR(q6);
426 drv->q6 = q6;
427
428 desc = &q6->desc;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700429 desc->owner = THIS_MODULE;
Matt Wagantall4d89c2e2012-05-25 19:28:34 -0700430 desc->proxy_timeout = PROXY_TIMEOUT_MS;
Ravishankar Sarawadiab203a82013-04-09 18:46:11 -0700431 desc->proxy_unvote_irq = gpio_clk_ready;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700432
Matt Wagantall015b50af2013-03-05 18:51:16 -0800433 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "restart_reg");
434 q6->restart_reg = devm_request_and_ioremap(&pdev->dev, res);
435 if (!q6->restart_reg)
436 return -ENOMEM;
437
Stephen Boyd633eb622012-06-13 12:05:35 -0700438 q6->core_clk = devm_clk_get(&pdev->dev, "core_clk");
439 if (IS_ERR(q6->core_clk))
440 return PTR_ERR(q6->core_clk);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700441
Stephen Boyd633eb622012-06-13 12:05:35 -0700442 q6->ahb_clk = devm_clk_get(&pdev->dev, "iface_clk");
443 if (IS_ERR(q6->ahb_clk))
444 return PTR_ERR(q6->ahb_clk);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700445
Stephen Boyd633eb622012-06-13 12:05:35 -0700446 q6->axi_clk = devm_clk_get(&pdev->dev, "bus_clk");
447 if (IS_ERR(q6->axi_clk))
448 return PTR_ERR(q6->axi_clk);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700449
Stephen Boyd633eb622012-06-13 12:05:35 -0700450 q6->reg_clk = devm_clk_get(&pdev->dev, "reg_clk");
451 if (IS_ERR(q6->reg_clk))
452 return PTR_ERR(q6->reg_clk);
Matt Wagantall56865f02012-08-09 15:03:36 -0700453
Matt Wagantall10a59672012-07-26 11:52:02 -0700454 if (pas_supported(PAS_Q6) > 0) {
455 desc->ops = &pil_lpass_ops_trusted;
456 dev_info(&pdev->dev, "using secure boot\n");
457 } else {
458 desc->ops = &pil_lpass_ops;
459 dev_info(&pdev->dev, "using non-secure boot\n");
460 }
461
Stephen Boyde83a0a22012-06-29 13:51:27 -0700462 ret = pil_desc_init(desc);
463 if (ret)
464 return ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700465
Stephen Boyd633eb622012-06-13 12:05:35 -0700466 drv->subsys_desc.name = desc->name;
467 drv->subsys_desc.owner = THIS_MODULE;
468 drv->subsys_desc.dev = &pdev->dev;
469 drv->subsys_desc.shutdown = adsp_shutdown;
470 drv->subsys_desc.powerup = adsp_powerup;
471 drv->subsys_desc.ramdump = adsp_ramdump;
472 drv->subsys_desc.crash_shutdown = adsp_crash_shutdown;
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700473 drv->subsys_desc.start = lpass_start;
474 drv->subsys_desc.stop = lpass_stop;
Stephen Boyd633eb622012-06-13 12:05:35 -0700475
476 INIT_WORK(&drv->work, adsp_fatal_fn);
477
Stephen Boydc1a72612012-07-05 14:07:35 -0700478 drv->ramdump_dev = create_ramdump_device("adsp", &pdev->dev);
Stephen Boyd633eb622012-06-13 12:05:35 -0700479 if (!drv->ramdump_dev) {
480 ret = -ENOMEM;
481 goto err_ramdump;
482 }
483
484 drv->subsys = subsys_register(&drv->subsys_desc);
485 if (IS_ERR(drv->subsys)) {
486 ret = PTR_ERR(drv->subsys);
487 goto err_subsys;
488 }
489
490 ret = devm_request_irq(&pdev->dev, drv->wdog_irq, adsp_wdog_bite_irq,
491 IRQF_TRIGGER_RISING, dev_name(&pdev->dev), drv);
492 if (ret)
493 goto err_irq;
494
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700495 ret = devm_request_irq(&pdev->dev, drv->err_fatal_irq,
496 adsp_err_fatal_intr_handler,
497 IRQF_TRIGGER_RISING,
498 dev_name(&pdev->dev), drv);
499 if (ret)
500 goto err_irq;
Stephen Boyd633eb622012-06-13 12:05:35 -0700501
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700502 drv->wcnss_notif_hdle = subsys_notif_register_notifier("wcnss", &wnb);
503 if (IS_ERR(drv->wcnss_notif_hdle)) {
504 ret = PTR_ERR(drv->wcnss_notif_hdle);
505 goto err_notif_wcnss;
Stephen Boyd633eb622012-06-13 12:05:35 -0700506 }
507
508 drv->modem_notif_hdle = subsys_notif_register_notifier("modem", &mnb);
509 if (IS_ERR(drv->modem_notif_hdle)) {
510 ret = PTR_ERR(drv->modem_notif_hdle);
511 goto err_notif_modem;
512 }
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800513 lpass_status = kobject_create_and_add("audio_voice_service",
514 kernel_kobj);
515 if (!lpass_status) {
516 pr_err("%s: kobject create failed\n", __func__);
517 ret = -ENOMEM;
518 goto err_notif_modem;
519 }
520
521 ret = sysfs_create_group(lpass_status, &attr_group);
522 if (ret) {
523 pr_err("%s: sysfs create group failed\n", __func__);
524 goto err_kobj;
525 }
526
527 adsp_set_state("ONLINE");
Stephen Boyd633eb622012-06-13 12:05:35 -0700528 return 0;
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800529err_kobj:
530 kobject_put(lpass_status);
Stephen Boyd633eb622012-06-13 12:05:35 -0700531err_notif_modem:
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700532 subsys_notif_unregister_notifier(drv->wcnss_notif_hdle, &wnb);
533err_notif_wcnss:
Stephen Boyd633eb622012-06-13 12:05:35 -0700534err_irq:
535 subsys_unregister(drv->subsys);
536err_subsys:
537 destroy_ramdump_device(drv->ramdump_dev);
538err_ramdump:
Stephen Boyde83a0a22012-06-29 13:51:27 -0700539 pil_desc_release(desc);
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800540 return ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700541}
542
543static int __devexit pil_lpass_driver_exit(struct platform_device *pdev)
544{
Stephen Boyd633eb622012-06-13 12:05:35 -0700545 struct lpass_data *drv = platform_get_drvdata(pdev);
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700546 subsys_notif_unregister_notifier(drv->wcnss_notif_hdle, &wnb);
Stephen Boyd633eb622012-06-13 12:05:35 -0700547 subsys_notif_unregister_notifier(drv->modem_notif_hdle, &mnb);
Stephen Boyd633eb622012-06-13 12:05:35 -0700548 subsys_unregister(drv->subsys);
549 destroy_ramdump_device(drv->ramdump_dev);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700550 pil_desc_release(&drv->q6->desc);
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800551 sysfs_remove_group(lpass_status, &attr_group);
552 kobject_del(lpass_status);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700553 return 0;
554}
555
556static struct of_device_id lpass_match_table[] = {
557 { .compatible = "qcom,pil-q6v5-lpass" },
558 {}
559};
560
561static struct platform_driver pil_lpass_driver = {
562 .probe = pil_lpass_driver_probe,
563 .remove = __devexit_p(pil_lpass_driver_exit),
564 .driver = {
565 .name = "pil-q6v5-lpass",
566 .of_match_table = lpass_match_table,
567 .owner = THIS_MODULE,
568 },
569};
570
571static int __init pil_lpass_init(void)
572{
573 return platform_driver_register(&pil_lpass_driver);
574}
575module_init(pil_lpass_init);
576
577static void __exit pil_lpass_exit(void)
578{
579 platform_driver_unregister(&pil_lpass_driver);
580}
581module_exit(pil_lpass_exit);
582
583MODULE_DESCRIPTION("Support for booting low-power audio subsystems with QDSP6v5 (Hexagon) processors");
584MODULE_LICENSE("GPL v2");