blob: 04c1be35e72d8ae5502ae631f239911a99030938 [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>
Stephen Boyd633eb622012-06-13 12:05:35 -070032
Matt Wagantallc2bbdc32012-03-21 19:44:50 -070033#include "peripheral-loader.h"
34#include "pil-q6v5.h"
Matt Wagantall10a59672012-07-26 11:52:02 -070035#include "scm-pas.h"
Stephen Boyd633eb622012-06-13 12:05:35 -070036#include "sysmon.h"
Matt Wagantallc2bbdc32012-03-21 19:44:50 -070037
Matt Wagantallc2bbdc32012-03-21 19:44:50 -070038#define QDSP6SS_RST_EVB 0x010
Matt Wagantall4d89c2e2012-05-25 19:28:34 -070039#define PROXY_TIMEOUT_MS 10000
Matt Wagantallc2bbdc32012-03-21 19:44:50 -070040
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -080041static struct kobject *lpass_status;
42static char status[32];
43
Stephen Boyd633eb622012-06-13 12:05:35 -070044struct lpass_data {
45 struct q6v5_data *q6;
46 struct subsys_device *subsys;
47 struct subsys_desc subsys_desc;
48 void *ramdump_dev;
49 int wdog_irq;
50 struct work_struct work;
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -070051 void *wcnss_notif_hdle;
Stephen Boyd633eb622012-06-13 12:05:35 -070052 void *modem_notif_hdle;
53 int crash_shutdown;
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -070054 unsigned int err_fatal_irq;
55 int force_stop_gpio;
Stephen Boyd633eb622012-06-13 12:05:35 -070056};
57
58#define subsys_to_drv(d) container_of(d, struct lpass_data, subsys_desc)
59
Matt Wagantall8c2246d2012-08-12 17:08:04 -070060static int pil_lpass_enable_clks(struct q6v5_data *drv)
61{
62 int ret;
63
64 ret = clk_reset(drv->core_clk, CLK_RESET_DEASSERT);
65 if (ret)
66 goto err_reset;
67 ret = clk_prepare_enable(drv->core_clk);
68 if (ret)
69 goto err_core_clk;
70 ret = clk_prepare_enable(drv->ahb_clk);
71 if (ret)
72 goto err_ahb_clk;
73 ret = clk_prepare_enable(drv->axi_clk);
74 if (ret)
75 goto err_axi_clk;
76 ret = clk_prepare_enable(drv->reg_clk);
77 if (ret)
78 goto err_reg_clk;
79
80 return 0;
81
82err_reg_clk:
83 clk_disable_unprepare(drv->axi_clk);
84err_axi_clk:
85 clk_disable_unprepare(drv->ahb_clk);
86err_ahb_clk:
87 clk_disable_unprepare(drv->core_clk);
88err_core_clk:
89 clk_reset(drv->core_clk, CLK_RESET_ASSERT);
90err_reset:
91 return ret;
92}
93
94static void pil_lpass_disable_clks(struct q6v5_data *drv)
95{
96 clk_disable_unprepare(drv->reg_clk);
97 clk_disable_unprepare(drv->axi_clk);
98 clk_disable_unprepare(drv->ahb_clk);
99 clk_disable_unprepare(drv->core_clk);
100 clk_reset(drv->core_clk, CLK_RESET_ASSERT);
101}
102
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700103static int pil_lpass_shutdown(struct pil_desc *pil)
104{
Stephen Boyd3826cd42012-07-05 17:37:53 -0700105 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700106
Matt Wagantallb7747992012-05-11 19:37:51 -0700107 pil_q6v5_halt_axi_port(pil, drv->axi_halt_base);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700108
Matt Wagantalld41ce772012-05-10 23:16:41 -0700109 /*
110 * If the shutdown function is called before the reset function, clocks
111 * will not be enabled yet. Enable them here so that register writes
112 * performed during the shutdown succeed.
113 */
114 if (drv->is_booted == false)
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700115 pil_lpass_enable_clks(drv);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700116
117 pil_q6v5_shutdown(pil);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700118 pil_lpass_disable_clks(drv);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700119
Matt Wagantall015b50af2013-03-05 18:51:16 -0800120 writel_relaxed(1, drv->restart_reg);
121
Matt Wagantalld41ce772012-05-10 23:16:41 -0700122 drv->is_booted = false;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700123
124 return 0;
125}
126
127static int pil_lpass_reset(struct pil_desc *pil)
128{
Stephen Boyd3826cd42012-07-05 17:37:53 -0700129 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Tianyi Gou819851e2013-04-16 16:05:56 -0700130 phys_addr_t start_addr = pil_get_entry_addr(pil);
Matt Wagantalld41ce772012-05-10 23:16:41 -0700131 int ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700132
Matt Wagantall015b50af2013-03-05 18:51:16 -0800133 /* Deassert reset to subsystem and wait for propagation */
134 writel_relaxed(0, drv->restart_reg);
135 mb();
136 udelay(2);
137
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700138 ret = pil_lpass_enable_clks(drv);
Matt Wagantalld41ce772012-05-10 23:16:41 -0700139 if (ret)
140 return ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700141
142 /* Program Image Address */
Stephen Boyd3030c252012-08-08 17:24:05 -0700143 writel_relaxed((start_addr >> 4) & 0x0FFFFFF0,
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700144 drv->reg_base + QDSP6SS_RST_EVB);
145
Matt Wagantalld41ce772012-05-10 23:16:41 -0700146 ret = pil_q6v5_reset(pil);
147 if (ret) {
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700148 pil_lpass_disable_clks(drv);
Matt Wagantalld41ce772012-05-10 23:16:41 -0700149 return ret;
150 }
151
152 drv->is_booted = true;
153
154 return 0;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700155}
156
157static struct pil_reset_ops pil_lpass_ops = {
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700158 .proxy_vote = pil_q6v5_make_proxy_votes,
159 .proxy_unvote = pil_q6v5_remove_proxy_votes,
160 .auth_and_reset = pil_lpass_reset,
161 .shutdown = pil_lpass_shutdown,
162};
163
Matt Wagantall10a59672012-07-26 11:52:02 -0700164static int pil_lpass_init_image_trusted(struct pil_desc *pil,
165 const u8 *metadata, size_t size)
166{
167 return pas_init_image(PAS_Q6, metadata, size);
168}
169
Stephen Boydc8c5db92012-12-03 11:13:20 -0800170static int pil_lpass_mem_setup_trusted(struct pil_desc *pil, phys_addr_t addr,
171 size_t size)
172{
173 return pas_mem_setup(PAS_Q6, addr, size);
174}
175
Matt Wagantall10a59672012-07-26 11:52:02 -0700176static int pil_lpass_reset_trusted(struct pil_desc *pil)
177{
178 return pas_auth_and_reset(PAS_Q6);
179}
180
181static int pil_lpass_shutdown_trusted(struct pil_desc *pil)
182{
183 return pas_shutdown(PAS_Q6);
184}
185
186static struct pil_reset_ops pil_lpass_ops_trusted = {
187 .init_image = pil_lpass_init_image_trusted,
Stephen Boydc8c5db92012-12-03 11:13:20 -0800188 .mem_setup = pil_lpass_mem_setup_trusted,
Matt Wagantall10a59672012-07-26 11:52:02 -0700189 .proxy_vote = pil_q6v5_make_proxy_votes,
190 .proxy_unvote = pil_q6v5_remove_proxy_votes,
191 .auth_and_reset = pil_lpass_reset_trusted,
192 .shutdown = pil_lpass_shutdown_trusted,
193};
194
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700195static int wcnss_notifier_cb(struct notifier_block *this, unsigned long code,
Stephen Boyd633eb622012-06-13 12:05:35 -0700196 void *ss_handle)
197{
198 int ret;
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700199 pr_debug("%s: W-Notify: event %lu\n", __func__, code);
200 ret = sysmon_send_event(SYSMON_SS_LPASS, "wcnss", code);
201 if (ret < 0)
202 pr_err("%s: sysmon_send_event error %d", __func__, ret);
Stephen Boyd633eb622012-06-13 12:05:35 -0700203 return NOTIFY_DONE;
204}
205
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700206static struct notifier_block wnb = {
207 .notifier_call = wcnss_notifier_cb,
Stephen Boyd633eb622012-06-13 12:05:35 -0700208};
209
210static int modem_notifier_cb(struct notifier_block *this, unsigned long code,
211 void *ss_handle)
212{
213 int ret;
Ravishankar Sarawadifadfe3b2012-10-12 11:28:24 -0700214 pr_debug("%s: M-Notify: event %lu\n", __func__, code);
215 ret = sysmon_send_event(SYSMON_SS_LPASS, "modem", code);
216 if (ret < 0)
217 pr_err("%s: sysmon_send_event error %d", __func__, ret);
Stephen Boyd633eb622012-06-13 12:05:35 -0700218 return NOTIFY_DONE;
219}
220
221static struct notifier_block mnb = {
222 .notifier_call = modem_notifier_cb,
223};
224
225static void adsp_log_failure_reason(void)
226{
227 char *reason;
228 char buffer[81];
229 unsigned size;
230
231 reason = smem_get_entry(SMEM_SSR_REASON_LPASS0, &size);
232
233 if (!reason) {
234 pr_err("ADSP subsystem failure reason: (unknown, smem_get_entry failed).");
235 return;
236 }
237
238 if (reason[0] == '\0') {
239 pr_err("ADSP subsystem failure reason: (unknown, init value found)");
240 return;
241 }
242
243 size = min(size, sizeof(buffer) - 1);
244 memcpy(buffer, reason, size);
245 buffer[size] = '\0';
246 pr_err("ADSP subsystem failure reason: %s", buffer);
247 memset((void *)reason, 0x0, size);
248 wmb();
249}
250
251static void restart_adsp(struct lpass_data *drv)
252{
253 adsp_log_failure_reason();
254 subsystem_restart_dev(drv->subsys);
255}
256
257static void adsp_fatal_fn(struct work_struct *work)
258{
259 struct lpass_data *drv = container_of(work, struct lpass_data, work);
260
261 pr_err("Watchdog bite received from ADSP!\n");
262 restart_adsp(drv);
263}
264
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700265static irqreturn_t adsp_err_fatal_intr_handler (int irq, void *dev_id)
Stephen Boyd633eb622012-06-13 12:05:35 -0700266{
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700267 struct lpass_data *drv = dev_id;
Stephen Boyd633eb622012-06-13 12:05:35 -0700268
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700269 /* Ignore if we're the one that set the force stop bit in the outbound
270 * entry
271 */
Stephen Boyd633eb622012-06-13 12:05:35 -0700272 if (drv->crash_shutdown)
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700273 return IRQ_HANDLED;
Stephen Boyd633eb622012-06-13 12:05:35 -0700274
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700275 pr_err("Fatal error on the ADSP!\n");
276 restart_adsp(drv);
277 return IRQ_HANDLED;
Stephen Boyd633eb622012-06-13 12:05:35 -0700278}
279
280#define SCM_Q6_NMI_CMD 0x1
281
282static void send_q6_nmi(void)
283{
284 /* Send NMI to QDSP6 via an SCM call. */
285 scm_call_atomic1(SCM_SVC_UTIL, SCM_Q6_NMI_CMD, 0x1);
286 pr_debug("%s: Q6 NMI was sent.\n", __func__);
287}
288
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800289/*
290 * The "status" file where a static variable is read from and written to.
291 */
292static ssize_t adsp_state_show(struct kobject *kobj,
293 struct kobj_attribute *attr,
294 char *buf)
295{
296 return snprintf(buf, sizeof(status), "%s\n", status);
297}
298
299static struct kobj_attribute adsp_state_attribute =
300 __ATTR(status, 0444, adsp_state_show, NULL);
301
302static struct attribute *attrs[] = {
303 &adsp_state_attribute.attr,
304 NULL, /* need to NULL terminate the list of attributes */
305};
306
307static struct attribute_group attr_group = {
308 .attrs = attrs,
309};
310
311static void adsp_set_state(char *state)
312{
313 strlcpy(status, state, sizeof(status));
314 sysfs_notify(lpass_status, NULL, "status");
315}
316
Stephen Boyd633eb622012-06-13 12:05:35 -0700317#define subsys_to_lpass(d) container_of(d, struct lpass_data, subsys_desc)
318
319static int adsp_shutdown(const struct subsys_desc *subsys)
320{
321 struct lpass_data *drv = subsys_to_lpass(subsys);
322
323 send_q6_nmi();
324 /* The write needs to go through before the q6 is shutdown. */
325 mb();
Stephen Boyde83a0a22012-06-29 13:51:27 -0700326 pil_shutdown(&drv->q6->desc);
Stephen Boyd633eb622012-06-13 12:05:35 -0700327 disable_irq_nosync(drv->wdog_irq);
328
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800329 pr_debug("ADSP is Down\n");
330 adsp_set_state("OFFLINE");
Stephen Boyd633eb622012-06-13 12:05:35 -0700331 return 0;
332}
333
334static int adsp_powerup(const struct subsys_desc *subsys)
335{
336 struct lpass_data *drv = subsys_to_lpass(subsys);
337 int ret = 0;
Stephen Boyde83a0a22012-06-29 13:51:27 -0700338 ret = pil_boot(&drv->q6->desc);
Stephen Boyd633eb622012-06-13 12:05:35 -0700339 enable_irq(drv->wdog_irq);
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800340
341 pr_debug("ADSP is back online\n");
342 adsp_set_state("ONLINE");
Stephen Boyd633eb622012-06-13 12:05:35 -0700343 return ret;
344}
345
Stephen Boyd633eb622012-06-13 12:05:35 -0700346static int adsp_ramdump(int enable, const struct subsys_desc *subsys)
347{
348 struct lpass_data *drv = subsys_to_lpass(subsys);
349
350 if (!enable)
351 return 0;
Stephen Boyd5eb17ce2012-11-29 15:34:21 -0800352
353 return pil_do_ramdump(&drv->q6->desc, drv->ramdump_dev);
Stephen Boyd633eb622012-06-13 12:05:35 -0700354}
355
356static void adsp_crash_shutdown(const struct subsys_desc *subsys)
357{
358 struct lpass_data *drv = subsys_to_lpass(subsys);
359
360 drv->crash_shutdown = 1;
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700361 gpio_set_value(drv->force_stop_gpio, 1);
Stephen Boyd633eb622012-06-13 12:05:35 -0700362 send_q6_nmi();
363}
364
365static irqreturn_t adsp_wdog_bite_irq(int irq, void *dev_id)
366{
367 struct lpass_data *drv = dev_id;
368
369 disable_irq_nosync(drv->wdog_irq);
370 schedule_work(&drv->work);
371
372 return IRQ_HANDLED;
373}
374
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700375static int lpass_start(const struct subsys_desc *desc)
376{
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700377 struct lpass_data *drv = subsys_to_drv(desc);
378
Stephen Boyde83a0a22012-06-29 13:51:27 -0700379 return pil_boot(&drv->q6->desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700380}
381
382static void lpass_stop(const struct subsys_desc *desc)
383{
384 struct lpass_data *drv = subsys_to_drv(desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700385 pil_shutdown(&drv->q6->desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700386}
387
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700388static int __devinit pil_lpass_driver_probe(struct platform_device *pdev)
389{
Stephen Boyd633eb622012-06-13 12:05:35 -0700390 struct lpass_data *drv;
391 struct q6v5_data *q6;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700392 struct pil_desc *desc;
Matt Wagantall015b50af2013-03-05 18:51:16 -0800393 struct resource *res;
Ravishankar Sarawadiab203a82013-04-09 18:46:11 -0700394 int ret, gpio_clk_ready;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700395
Stephen Boyd633eb622012-06-13 12:05:35 -0700396 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
397 if (!drv)
398 return -ENOMEM;
Stephen Boyd3826cd42012-07-05 17:37:53 -0700399 platform_set_drvdata(pdev, drv);
Matt Wagantall55252f12012-05-02 18:02:54 -0700400
Stephen Boyd633eb622012-06-13 12:05:35 -0700401 drv->wdog_irq = platform_get_irq(pdev, 0);
402 if (drv->wdog_irq < 0)
403 return drv->wdog_irq;
404
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700405 ret = gpio_to_irq(of_get_named_gpio(pdev->dev.of_node,
406 "qcom,gpio-err-fatal", 0));
407 if (ret < 0)
408 return ret;
409 drv->err_fatal_irq = ret;
410
Ravishankar Sarawadiab203a82013-04-09 18:46:11 -0700411 ret = gpio_to_irq(of_get_named_gpio(pdev->dev.of_node,
412 "qcom,gpio-proxy-unvote", 0));
413 if (ret < 0)
414 return ret;
415 gpio_clk_ready = ret;
416
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700417 drv->force_stop_gpio = of_get_named_gpio(pdev->dev.of_node,
418 "qcom,gpio-force-stop", 0);
419 if (drv->force_stop_gpio < 0)
420 return drv->force_stop_gpio;
421
Stephen Boyd633eb622012-06-13 12:05:35 -0700422 q6 = pil_q6v5_init(pdev);
423 if (IS_ERR(q6))
424 return PTR_ERR(q6);
425 drv->q6 = q6;
426
427 desc = &q6->desc;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700428 desc->owner = THIS_MODULE;
Matt Wagantall4d89c2e2012-05-25 19:28:34 -0700429 desc->proxy_timeout = PROXY_TIMEOUT_MS;
Ravishankar Sarawadiab203a82013-04-09 18:46:11 -0700430 desc->proxy_unvote_irq = gpio_clk_ready;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700431
Matt Wagantall015b50af2013-03-05 18:51:16 -0800432 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "restart_reg");
433 q6->restart_reg = devm_request_and_ioremap(&pdev->dev, res);
434 if (!q6->restart_reg)
435 return -ENOMEM;
436
Stephen Boyd633eb622012-06-13 12:05:35 -0700437 q6->core_clk = devm_clk_get(&pdev->dev, "core_clk");
438 if (IS_ERR(q6->core_clk))
439 return PTR_ERR(q6->core_clk);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700440
Stephen Boyd633eb622012-06-13 12:05:35 -0700441 q6->ahb_clk = devm_clk_get(&pdev->dev, "iface_clk");
442 if (IS_ERR(q6->ahb_clk))
443 return PTR_ERR(q6->ahb_clk);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700444
Stephen Boyd633eb622012-06-13 12:05:35 -0700445 q6->axi_clk = devm_clk_get(&pdev->dev, "bus_clk");
446 if (IS_ERR(q6->axi_clk))
447 return PTR_ERR(q6->axi_clk);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700448
Stephen Boyd633eb622012-06-13 12:05:35 -0700449 q6->reg_clk = devm_clk_get(&pdev->dev, "reg_clk");
450 if (IS_ERR(q6->reg_clk))
451 return PTR_ERR(q6->reg_clk);
Matt Wagantall56865f02012-08-09 15:03:36 -0700452
Matt Wagantall10a59672012-07-26 11:52:02 -0700453 if (pas_supported(PAS_Q6) > 0) {
454 desc->ops = &pil_lpass_ops_trusted;
455 dev_info(&pdev->dev, "using secure boot\n");
456 } else {
457 desc->ops = &pil_lpass_ops;
458 dev_info(&pdev->dev, "using non-secure boot\n");
459 }
460
Stephen Boyde83a0a22012-06-29 13:51:27 -0700461 ret = pil_desc_init(desc);
462 if (ret)
463 return ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700464
Stephen Boyd633eb622012-06-13 12:05:35 -0700465 drv->subsys_desc.name = desc->name;
466 drv->subsys_desc.owner = THIS_MODULE;
467 drv->subsys_desc.dev = &pdev->dev;
468 drv->subsys_desc.shutdown = adsp_shutdown;
469 drv->subsys_desc.powerup = adsp_powerup;
470 drv->subsys_desc.ramdump = adsp_ramdump;
471 drv->subsys_desc.crash_shutdown = adsp_crash_shutdown;
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700472 drv->subsys_desc.start = lpass_start;
473 drv->subsys_desc.stop = lpass_stop;
Stephen Boyd633eb622012-06-13 12:05:35 -0700474
475 INIT_WORK(&drv->work, adsp_fatal_fn);
476
Stephen Boydc1a72612012-07-05 14:07:35 -0700477 drv->ramdump_dev = create_ramdump_device("adsp", &pdev->dev);
Stephen Boyd633eb622012-06-13 12:05:35 -0700478 if (!drv->ramdump_dev) {
479 ret = -ENOMEM;
480 goto err_ramdump;
481 }
482
483 drv->subsys = subsys_register(&drv->subsys_desc);
484 if (IS_ERR(drv->subsys)) {
485 ret = PTR_ERR(drv->subsys);
486 goto err_subsys;
487 }
488
489 ret = devm_request_irq(&pdev->dev, drv->wdog_irq, adsp_wdog_bite_irq,
490 IRQF_TRIGGER_RISING, dev_name(&pdev->dev), drv);
491 if (ret)
492 goto err_irq;
493
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700494 ret = devm_request_irq(&pdev->dev, drv->err_fatal_irq,
495 adsp_err_fatal_intr_handler,
496 IRQF_TRIGGER_RISING,
497 dev_name(&pdev->dev), drv);
498 if (ret)
499 goto err_irq;
Stephen Boyd633eb622012-06-13 12:05:35 -0700500
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700501 drv->wcnss_notif_hdle = subsys_notif_register_notifier("wcnss", &wnb);
502 if (IS_ERR(drv->wcnss_notif_hdle)) {
503 ret = PTR_ERR(drv->wcnss_notif_hdle);
504 goto err_notif_wcnss;
Stephen Boyd633eb622012-06-13 12:05:35 -0700505 }
506
507 drv->modem_notif_hdle = subsys_notif_register_notifier("modem", &mnb);
508 if (IS_ERR(drv->modem_notif_hdle)) {
509 ret = PTR_ERR(drv->modem_notif_hdle);
510 goto err_notif_modem;
511 }
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800512 lpass_status = kobject_create_and_add("audio_voice_service",
513 kernel_kobj);
514 if (!lpass_status) {
515 pr_err("%s: kobject create failed\n", __func__);
516 ret = -ENOMEM;
517 goto err_notif_modem;
518 }
519
520 ret = sysfs_create_group(lpass_status, &attr_group);
521 if (ret) {
522 pr_err("%s: sysfs create group failed\n", __func__);
523 goto err_kobj;
524 }
525
526 adsp_set_state("ONLINE");
Stephen Boyd633eb622012-06-13 12:05:35 -0700527 return 0;
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800528err_kobj:
529 kobject_put(lpass_status);
Stephen Boyd633eb622012-06-13 12:05:35 -0700530err_notif_modem:
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700531 subsys_notif_unregister_notifier(drv->wcnss_notif_hdle, &wnb);
532err_notif_wcnss:
Stephen Boyd633eb622012-06-13 12:05:35 -0700533err_irq:
534 subsys_unregister(drv->subsys);
535err_subsys:
536 destroy_ramdump_device(drv->ramdump_dev);
537err_ramdump:
Stephen Boyde83a0a22012-06-29 13:51:27 -0700538 pil_desc_release(desc);
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800539 return ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700540}
541
542static int __devexit pil_lpass_driver_exit(struct platform_device *pdev)
543{
Stephen Boyd633eb622012-06-13 12:05:35 -0700544 struct lpass_data *drv = platform_get_drvdata(pdev);
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700545 subsys_notif_unregister_notifier(drv->wcnss_notif_hdle, &wnb);
Stephen Boyd633eb622012-06-13 12:05:35 -0700546 subsys_notif_unregister_notifier(drv->modem_notif_hdle, &mnb);
Stephen Boyd633eb622012-06-13 12:05:35 -0700547 subsys_unregister(drv->subsys);
548 destroy_ramdump_device(drv->ramdump_dev);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700549 pil_desc_release(&drv->q6->desc);
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800550 sysfs_remove_group(lpass_status, &attr_group);
551 kobject_del(lpass_status);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700552 return 0;
553}
554
555static struct of_device_id lpass_match_table[] = {
556 { .compatible = "qcom,pil-q6v5-lpass" },
557 {}
558};
559
560static struct platform_driver pil_lpass_driver = {
561 .probe = pil_lpass_driver_probe,
562 .remove = __devexit_p(pil_lpass_driver_exit),
563 .driver = {
564 .name = "pil-q6v5-lpass",
565 .of_match_table = lpass_match_table,
566 .owner = THIS_MODULE,
567 },
568};
569
570static int __init pil_lpass_init(void)
571{
572 return platform_driver_register(&pil_lpass_driver);
573}
574module_init(pil_lpass_init);
575
576static void __exit pil_lpass_exit(void)
577{
578 platform_driver_unregister(&pil_lpass_driver);
579}
580module_exit(pil_lpass_exit);
581
582MODULE_DESCRIPTION("Support for booting low-power audio subsystems with QDSP6v5 (Hexagon) processors");
583MODULE_LICENSE("GPL v2");