blob: a9a6942ecf1eba4a2ba6954db87d5b1eef269413 [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>
Deepak Katragadda4118ccc2013-07-05 10:01:19 -070033#include <mach/msm_bus_board.h>
Stephen Boyd633eb622012-06-13 12:05:35 -070034
Matt Wagantallc2bbdc32012-03-21 19:44:50 -070035#include "peripheral-loader.h"
36#include "pil-q6v5.h"
Matt Wagantall10a59672012-07-26 11:52:02 -070037#include "scm-pas.h"
Stephen Boyd633eb622012-06-13 12:05:35 -070038#include "sysmon.h"
Matt Wagantallc2bbdc32012-03-21 19:44:50 -070039
Matt Wagantallc2bbdc32012-03-21 19:44:50 -070040#define QDSP6SS_RST_EVB 0x010
Matt Wagantall4d89c2e2012-05-25 19:28:34 -070041#define PROXY_TIMEOUT_MS 10000
Matt Wagantallc2bbdc32012-03-21 19:44:50 -070042
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -080043static struct kobject *lpass_status;
44static char status[32];
45
Stephen Boyd633eb622012-06-13 12:05:35 -070046struct lpass_data {
47 struct q6v5_data *q6;
48 struct subsys_device *subsys;
49 struct subsys_desc subsys_desc;
50 void *ramdump_dev;
Stephen Boyd633eb622012-06-13 12:05:35 -070051 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;
55};
56
57#define subsys_to_drv(d) container_of(d, struct lpass_data, subsys_desc)
58
Matt Wagantall8c2246d2012-08-12 17:08:04 -070059static int pil_lpass_enable_clks(struct q6v5_data *drv)
60{
61 int ret;
62
63 ret = clk_reset(drv->core_clk, CLK_RESET_DEASSERT);
64 if (ret)
65 goto err_reset;
66 ret = clk_prepare_enable(drv->core_clk);
67 if (ret)
68 goto err_core_clk;
69 ret = clk_prepare_enable(drv->ahb_clk);
70 if (ret)
71 goto err_ahb_clk;
72 ret = clk_prepare_enable(drv->axi_clk);
73 if (ret)
74 goto err_axi_clk;
75 ret = clk_prepare_enable(drv->reg_clk);
76 if (ret)
77 goto err_reg_clk;
78
79 return 0;
80
81err_reg_clk:
82 clk_disable_unprepare(drv->axi_clk);
83err_axi_clk:
84 clk_disable_unprepare(drv->ahb_clk);
85err_ahb_clk:
86 clk_disable_unprepare(drv->core_clk);
87err_core_clk:
88 clk_reset(drv->core_clk, CLK_RESET_ASSERT);
89err_reset:
90 return ret;
91}
92
93static void pil_lpass_disable_clks(struct q6v5_data *drv)
94{
95 clk_disable_unprepare(drv->reg_clk);
96 clk_disable_unprepare(drv->axi_clk);
97 clk_disable_unprepare(drv->ahb_clk);
98 clk_disable_unprepare(drv->core_clk);
99 clk_reset(drv->core_clk, CLK_RESET_ASSERT);
100}
101
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700102static int pil_lpass_shutdown(struct pil_desc *pil)
103{
Stephen Boyd3826cd42012-07-05 17:37:53 -0700104 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700105
Matt Wagantallb7747992012-05-11 19:37:51 -0700106 pil_q6v5_halt_axi_port(pil, drv->axi_halt_base);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700107
Matt Wagantalld41ce772012-05-10 23:16:41 -0700108 /*
109 * If the shutdown function is called before the reset function, clocks
110 * will not be enabled yet. Enable them here so that register writes
111 * performed during the shutdown succeed.
112 */
113 if (drv->is_booted == false)
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700114 pil_lpass_enable_clks(drv);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700115
116 pil_q6v5_shutdown(pil);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700117 pil_lpass_disable_clks(drv);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700118
Matt Wagantall015b50af2013-03-05 18:51:16 -0800119 writel_relaxed(1, drv->restart_reg);
120
Matt Wagantalld41ce772012-05-10 23:16:41 -0700121 drv->is_booted = false;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700122
123 return 0;
124}
125
126static int pil_lpass_reset(struct pil_desc *pil)
127{
Stephen Boyd3826cd42012-07-05 17:37:53 -0700128 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
Tianyi Gou819851e2013-04-16 16:05:56 -0700129 phys_addr_t start_addr = pil_get_entry_addr(pil);
Matt Wagantalld41ce772012-05-10 23:16:41 -0700130 int ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700131
Matt Wagantall015b50af2013-03-05 18:51:16 -0800132 /* Deassert reset to subsystem and wait for propagation */
133 writel_relaxed(0, drv->restart_reg);
134 mb();
135 udelay(2);
136
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700137 ret = pil_lpass_enable_clks(drv);
Matt Wagantalld41ce772012-05-10 23:16:41 -0700138 if (ret)
139 return ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700140
141 /* Program Image Address */
Stephen Boyd3030c252012-08-08 17:24:05 -0700142 writel_relaxed((start_addr >> 4) & 0x0FFFFFF0,
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700143 drv->reg_base + QDSP6SS_RST_EVB);
144
Matt Wagantalld41ce772012-05-10 23:16:41 -0700145 ret = pil_q6v5_reset(pil);
146 if (ret) {
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700147 pil_lpass_disable_clks(drv);
Matt Wagantalld41ce772012-05-10 23:16:41 -0700148 return ret;
149 }
150
151 drv->is_booted = true;
152
153 return 0;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700154}
155
156static struct pil_reset_ops pil_lpass_ops = {
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700157 .proxy_vote = pil_q6v5_make_proxy_votes,
158 .proxy_unvote = pil_q6v5_remove_proxy_votes,
159 .auth_and_reset = pil_lpass_reset,
160 .shutdown = pil_lpass_shutdown,
161};
162
Matt Wagantall10a59672012-07-26 11:52:02 -0700163static int pil_lpass_init_image_trusted(struct pil_desc *pil,
164 const u8 *metadata, size_t size)
165{
166 return pas_init_image(PAS_Q6, metadata, size);
167}
168
Stephen Boydc8c5db92012-12-03 11:13:20 -0800169static int pil_lpass_mem_setup_trusted(struct pil_desc *pil, phys_addr_t addr,
170 size_t size)
171{
172 return pas_mem_setup(PAS_Q6, addr, size);
173}
174
Matt Wagantall10a59672012-07-26 11:52:02 -0700175static int pil_lpass_reset_trusted(struct pil_desc *pil)
176{
Vikram Mulukutlaa30b53a2013-05-28 15:47:22 -0700177 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
178 int ret;
179
180 ret = clk_prepare_enable(drv->axi_clk);
181 if (ret)
182 return ret;
Matt Wagantall10a59672012-07-26 11:52:02 -0700183 return pas_auth_and_reset(PAS_Q6);
184}
185
186static int pil_lpass_shutdown_trusted(struct pil_desc *pil)
187{
Vikram Mulukutlaa30b53a2013-05-28 15:47:22 -0700188 struct q6v5_data *drv = container_of(pil, struct q6v5_data, desc);
189 int ret;
190
191 ret = pas_shutdown(PAS_Q6);
192 if (ret)
193 return ret;
194 clk_disable_unprepare(drv->axi_clk);
195 return 0;
Matt Wagantall10a59672012-07-26 11:52:02 -0700196}
197
198static struct pil_reset_ops pil_lpass_ops_trusted = {
199 .init_image = pil_lpass_init_image_trusted,
Stephen Boydc8c5db92012-12-03 11:13:20 -0800200 .mem_setup = pil_lpass_mem_setup_trusted,
Matt Wagantall10a59672012-07-26 11:52:02 -0700201 .proxy_vote = pil_q6v5_make_proxy_votes,
202 .proxy_unvote = pil_q6v5_remove_proxy_votes,
203 .auth_and_reset = pil_lpass_reset_trusted,
204 .shutdown = pil_lpass_shutdown_trusted,
205};
206
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700207static int wcnss_notifier_cb(struct notifier_block *this, unsigned long code,
Stephen Boyd633eb622012-06-13 12:05:35 -0700208 void *ss_handle)
209{
210 int ret;
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700211 pr_debug("%s: W-Notify: event %lu\n", __func__, code);
212 ret = sysmon_send_event(SYSMON_SS_LPASS, "wcnss", code);
213 if (ret < 0)
214 pr_err("%s: sysmon_send_event error %d", __func__, ret);
Stephen Boyd633eb622012-06-13 12:05:35 -0700215 return NOTIFY_DONE;
216}
217
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700218static struct notifier_block wnb = {
219 .notifier_call = wcnss_notifier_cb,
Stephen Boyd633eb622012-06-13 12:05:35 -0700220};
221
222static int modem_notifier_cb(struct notifier_block *this, unsigned long code,
223 void *ss_handle)
224{
225 int ret;
Ravishankar Sarawadifadfe3b2012-10-12 11:28:24 -0700226 pr_debug("%s: M-Notify: event %lu\n", __func__, code);
227 ret = sysmon_send_event(SYSMON_SS_LPASS, "modem", code);
228 if (ret < 0)
229 pr_err("%s: sysmon_send_event error %d", __func__, ret);
Stephen Boyd633eb622012-06-13 12:05:35 -0700230 return NOTIFY_DONE;
231}
232
233static struct notifier_block mnb = {
234 .notifier_call = modem_notifier_cb,
235};
236
237static void adsp_log_failure_reason(void)
238{
239 char *reason;
240 char buffer[81];
241 unsigned size;
242
243 reason = smem_get_entry(SMEM_SSR_REASON_LPASS0, &size);
244
245 if (!reason) {
246 pr_err("ADSP subsystem failure reason: (unknown, smem_get_entry failed).");
247 return;
248 }
249
250 if (reason[0] == '\0') {
251 pr_err("ADSP subsystem failure reason: (unknown, init value found)");
252 return;
253 }
254
255 size = min(size, sizeof(buffer) - 1);
256 memcpy(buffer, reason, size);
257 buffer[size] = '\0';
258 pr_err("ADSP subsystem failure reason: %s", buffer);
259 memset((void *)reason, 0x0, size);
260 wmb();
261}
262
263static void restart_adsp(struct lpass_data *drv)
264{
265 adsp_log_failure_reason();
266 subsystem_restart_dev(drv->subsys);
267}
268
269static void adsp_fatal_fn(struct work_struct *work)
270{
271 struct lpass_data *drv = container_of(work, struct lpass_data, work);
272
273 pr_err("Watchdog bite received from ADSP!\n");
274 restart_adsp(drv);
275}
276
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700277static irqreturn_t adsp_err_fatal_intr_handler (int irq, void *dev_id)
Stephen Boyd633eb622012-06-13 12:05:35 -0700278{
Seemanta Dutta076d00e2013-06-17 17:58:18 -0700279 struct lpass_data *drv = subsys_to_drv(dev_id);
Stephen Boyd633eb622012-06-13 12:05:35 -0700280
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700281 /* Ignore if we're the one that set the force stop bit in the outbound
282 * entry
283 */
Stephen Boyd633eb622012-06-13 12:05:35 -0700284 if (drv->crash_shutdown)
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700285 return IRQ_HANDLED;
Stephen Boyd633eb622012-06-13 12:05:35 -0700286
Ravishankar Sarawadi28a33ce2013-03-28 14:36:49 -0700287 pr_err("Fatal error on the ADSP!\n");
288 restart_adsp(drv);
289 return IRQ_HANDLED;
Stephen Boyd633eb622012-06-13 12:05:35 -0700290}
291
292#define SCM_Q6_NMI_CMD 0x1
293
294static void send_q6_nmi(void)
295{
296 /* Send NMI to QDSP6 via an SCM call. */
297 scm_call_atomic1(SCM_SVC_UTIL, SCM_Q6_NMI_CMD, 0x1);
298 pr_debug("%s: Q6 NMI was sent.\n", __func__);
299}
300
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800301/*
302 * The "status" file where a static variable is read from and written to.
303 */
304static ssize_t adsp_state_show(struct kobject *kobj,
305 struct kobj_attribute *attr,
306 char *buf)
307{
308 return snprintf(buf, sizeof(status), "%s\n", status);
309}
310
311static struct kobj_attribute adsp_state_attribute =
312 __ATTR(status, 0444, adsp_state_show, NULL);
313
314static struct attribute *attrs[] = {
315 &adsp_state_attribute.attr,
316 NULL, /* need to NULL terminate the list of attributes */
317};
318
319static struct attribute_group attr_group = {
320 .attrs = attrs,
321};
322
323static void adsp_set_state(char *state)
324{
325 strlcpy(status, state, sizeof(status));
326 sysfs_notify(lpass_status, NULL, "status");
327}
328
Stephen Boyd633eb622012-06-13 12:05:35 -0700329#define subsys_to_lpass(d) container_of(d, struct lpass_data, subsys_desc)
330
331static int adsp_shutdown(const struct subsys_desc *subsys)
332{
333 struct lpass_data *drv = subsys_to_lpass(subsys);
334
335 send_q6_nmi();
336 /* The write needs to go through before the q6 is shutdown. */
337 mb();
Stephen Boyde83a0a22012-06-29 13:51:27 -0700338 pil_shutdown(&drv->q6->desc);
Seemanta Dutta076d00e2013-06-17 17:58:18 -0700339 disable_irq_nosync(drv->subsys_desc.wdog_bite_irq);
Stephen Boyd633eb622012-06-13 12:05:35 -0700340
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800341 pr_debug("ADSP is Down\n");
342 adsp_set_state("OFFLINE");
Stephen Boyd633eb622012-06-13 12:05:35 -0700343 return 0;
344}
345
346static int adsp_powerup(const struct subsys_desc *subsys)
347{
348 struct lpass_data *drv = subsys_to_lpass(subsys);
349 int ret = 0;
Stephen Boyde83a0a22012-06-29 13:51:27 -0700350 ret = pil_boot(&drv->q6->desc);
Seemanta Dutta076d00e2013-06-17 17:58:18 -0700351 enable_irq(drv->subsys_desc.wdog_bite_irq);
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800352
353 pr_debug("ADSP is back online\n");
354 adsp_set_state("ONLINE");
Stephen Boyd633eb622012-06-13 12:05:35 -0700355 return ret;
356}
357
Stephen Boyd633eb622012-06-13 12:05:35 -0700358static int adsp_ramdump(int enable, const struct subsys_desc *subsys)
359{
360 struct lpass_data *drv = subsys_to_lpass(subsys);
361
362 if (!enable)
363 return 0;
Stephen Boyd5eb17ce2012-11-29 15:34:21 -0800364
365 return pil_do_ramdump(&drv->q6->desc, drv->ramdump_dev);
Stephen Boyd633eb622012-06-13 12:05:35 -0700366}
367
368static void adsp_crash_shutdown(const struct subsys_desc *subsys)
369{
370 struct lpass_data *drv = subsys_to_lpass(subsys);
371
372 drv->crash_shutdown = 1;
Seemanta Dutta076d00e2013-06-17 17:58:18 -0700373 gpio_set_value(subsys->force_stop_gpio, 1);
Stephen Boyd633eb622012-06-13 12:05:35 -0700374 send_q6_nmi();
375}
376
377static irqreturn_t adsp_wdog_bite_irq(int irq, void *dev_id)
378{
Seemanta Dutta076d00e2013-06-17 17:58:18 -0700379 struct lpass_data *drv = subsys_to_drv(dev_id);
Stephen Boyd633eb622012-06-13 12:05:35 -0700380
Seemanta Dutta076d00e2013-06-17 17:58:18 -0700381 disable_irq_nosync(drv->subsys_desc.wdog_bite_irq);
Stephen Boyd633eb622012-06-13 12:05:35 -0700382 schedule_work(&drv->work);
383
384 return IRQ_HANDLED;
385}
386
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700387static int lpass_start(const struct subsys_desc *desc)
388{
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700389 struct lpass_data *drv = subsys_to_drv(desc);
390
Stephen Boyde83a0a22012-06-29 13:51:27 -0700391 return pil_boot(&drv->q6->desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700392}
393
394static void lpass_stop(const struct subsys_desc *desc)
395{
396 struct lpass_data *drv = subsys_to_drv(desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700397 pil_shutdown(&drv->q6->desc);
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700398}
399
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700400static int __devinit pil_lpass_driver_probe(struct platform_device *pdev)
401{
Stephen Boyd633eb622012-06-13 12:05:35 -0700402 struct lpass_data *drv;
403 struct q6v5_data *q6;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700404 struct pil_desc *desc;
Matt Wagantall015b50af2013-03-05 18:51:16 -0800405 struct resource *res;
Seemanta Duttad99446c2013-06-17 18:05:18 -0700406 int ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700407
Stephen Boyd633eb622012-06-13 12:05:35 -0700408 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
409 if (!drv)
410 return -ENOMEM;
Stephen Boyd3826cd42012-07-05 17:37:53 -0700411 platform_set_drvdata(pdev, drv);
Matt Wagantall55252f12012-05-02 18:02:54 -0700412
Stephen Boyd633eb622012-06-13 12:05:35 -0700413 q6 = pil_q6v5_init(pdev);
414 if (IS_ERR(q6))
415 return PTR_ERR(q6);
416 drv->q6 = q6;
417
418 desc = &q6->desc;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700419 desc->owner = THIS_MODULE;
Matt Wagantall4d89c2e2012-05-25 19:28:34 -0700420 desc->proxy_timeout = PROXY_TIMEOUT_MS;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700421
Matt Wagantall015b50af2013-03-05 18:51:16 -0800422 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "restart_reg");
423 q6->restart_reg = devm_request_and_ioremap(&pdev->dev, res);
424 if (!q6->restart_reg)
425 return -ENOMEM;
426
Stephen Boyd633eb622012-06-13 12:05:35 -0700427 q6->core_clk = devm_clk_get(&pdev->dev, "core_clk");
428 if (IS_ERR(q6->core_clk))
429 return PTR_ERR(q6->core_clk);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700430
Stephen Boyd633eb622012-06-13 12:05:35 -0700431 q6->ahb_clk = devm_clk_get(&pdev->dev, "iface_clk");
432 if (IS_ERR(q6->ahb_clk))
433 return PTR_ERR(q6->ahb_clk);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700434
Stephen Boyd633eb622012-06-13 12:05:35 -0700435 q6->axi_clk = devm_clk_get(&pdev->dev, "bus_clk");
436 if (IS_ERR(q6->axi_clk))
437 return PTR_ERR(q6->axi_clk);
Matt Wagantall8c2246d2012-08-12 17:08:04 -0700438
Stephen Boyd633eb622012-06-13 12:05:35 -0700439 q6->reg_clk = devm_clk_get(&pdev->dev, "reg_clk");
440 if (IS_ERR(q6->reg_clk))
441 return PTR_ERR(q6->reg_clk);
Matt Wagantall56865f02012-08-09 15:03:36 -0700442
Matt Wagantall10a59672012-07-26 11:52:02 -0700443 if (pas_supported(PAS_Q6) > 0) {
444 desc->ops = &pil_lpass_ops_trusted;
445 dev_info(&pdev->dev, "using secure boot\n");
446 } else {
447 desc->ops = &pil_lpass_ops;
448 dev_info(&pdev->dev, "using non-secure boot\n");
449 }
450
Deepak Katragadda4118ccc2013-07-05 10:01:19 -0700451 scm_pas_init(MSM_BUS_MASTER_CRYPTO_CORE0);
452
Stephen Boyde83a0a22012-06-29 13:51:27 -0700453 ret = pil_desc_init(desc);
454 if (ret)
455 return ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700456
Stephen Boyd633eb622012-06-13 12:05:35 -0700457 drv->subsys_desc.name = desc->name;
458 drv->subsys_desc.owner = THIS_MODULE;
459 drv->subsys_desc.dev = &pdev->dev;
460 drv->subsys_desc.shutdown = adsp_shutdown;
461 drv->subsys_desc.powerup = adsp_powerup;
462 drv->subsys_desc.ramdump = adsp_ramdump;
463 drv->subsys_desc.crash_shutdown = adsp_crash_shutdown;
Stephen Boyd3e4e9752012-06-27 12:46:32 -0700464 drv->subsys_desc.start = lpass_start;
465 drv->subsys_desc.stop = lpass_stop;
Seemanta Dutta076d00e2013-06-17 17:58:18 -0700466 drv->subsys_desc.err_fatal_handler = adsp_err_fatal_intr_handler;
467 drv->subsys_desc.wdog_bite_handler = adsp_wdog_bite_irq;
Stephen Boyd633eb622012-06-13 12:05:35 -0700468
469 INIT_WORK(&drv->work, adsp_fatal_fn);
470
Stephen Boydc1a72612012-07-05 14:07:35 -0700471 drv->ramdump_dev = create_ramdump_device("adsp", &pdev->dev);
Stephen Boyd633eb622012-06-13 12:05:35 -0700472 if (!drv->ramdump_dev) {
473 ret = -ENOMEM;
474 goto err_ramdump;
475 }
476
477 drv->subsys = subsys_register(&drv->subsys_desc);
478 if (IS_ERR(drv->subsys)) {
479 ret = PTR_ERR(drv->subsys);
480 goto err_subsys;
481 }
482
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700483 drv->wcnss_notif_hdle = subsys_notif_register_notifier("wcnss", &wnb);
484 if (IS_ERR(drv->wcnss_notif_hdle)) {
485 ret = PTR_ERR(drv->wcnss_notif_hdle);
486 goto err_notif_wcnss;
Stephen Boyd633eb622012-06-13 12:05:35 -0700487 }
488
489 drv->modem_notif_hdle = subsys_notif_register_notifier("modem", &mnb);
490 if (IS_ERR(drv->modem_notif_hdle)) {
491 ret = PTR_ERR(drv->modem_notif_hdle);
492 goto err_notif_modem;
493 }
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800494 lpass_status = kobject_create_and_add("audio_voice_service",
495 kernel_kobj);
496 if (!lpass_status) {
497 pr_err("%s: kobject create failed\n", __func__);
498 ret = -ENOMEM;
499 goto err_notif_modem;
500 }
501
502 ret = sysfs_create_group(lpass_status, &attr_group);
503 if (ret) {
504 pr_err("%s: sysfs create group failed\n", __func__);
505 goto err_kobj;
506 }
507
508 adsp_set_state("ONLINE");
Stephen Boyd633eb622012-06-13 12:05:35 -0700509 return 0;
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800510err_kobj:
511 kobject_put(lpass_status);
Stephen Boyd633eb622012-06-13 12:05:35 -0700512err_notif_modem:
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700513 subsys_notif_unregister_notifier(drv->wcnss_notif_hdle, &wnb);
514err_notif_wcnss:
Stephen Boyd633eb622012-06-13 12:05:35 -0700515 subsys_unregister(drv->subsys);
516err_subsys:
517 destroy_ramdump_device(drv->ramdump_dev);
518err_ramdump:
Stephen Boyde83a0a22012-06-29 13:51:27 -0700519 pil_desc_release(desc);
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800520 return ret;
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700521}
522
523static int __devexit pil_lpass_driver_exit(struct platform_device *pdev)
524{
Stephen Boyd633eb622012-06-13 12:05:35 -0700525 struct lpass_data *drv = platform_get_drvdata(pdev);
Ravishankar Sarawadic14fb5e2013-04-03 17:39:46 -0700526 subsys_notif_unregister_notifier(drv->wcnss_notif_hdle, &wnb);
Stephen Boyd633eb622012-06-13 12:05:35 -0700527 subsys_notif_unregister_notifier(drv->modem_notif_hdle, &mnb);
Stephen Boyd633eb622012-06-13 12:05:35 -0700528 subsys_unregister(drv->subsys);
529 destroy_ramdump_device(drv->ramdump_dev);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700530 pil_desc_release(&drv->q6->desc);
Phani Kumar Uppalapati598a1da2013-01-24 12:29:54 -0800531 sysfs_remove_group(lpass_status, &attr_group);
532 kobject_del(lpass_status);
Matt Wagantallc2bbdc32012-03-21 19:44:50 -0700533 return 0;
534}
535
536static struct of_device_id lpass_match_table[] = {
537 { .compatible = "qcom,pil-q6v5-lpass" },
538 {}
539};
540
541static struct platform_driver pil_lpass_driver = {
542 .probe = pil_lpass_driver_probe,
543 .remove = __devexit_p(pil_lpass_driver_exit),
544 .driver = {
545 .name = "pil-q6v5-lpass",
546 .of_match_table = lpass_match_table,
547 .owner = THIS_MODULE,
548 },
549};
550
551static int __init pil_lpass_init(void)
552{
553 return platform_driver_register(&pil_lpass_driver);
554}
555module_init(pil_lpass_init);
556
557static void __exit pil_lpass_exit(void)
558{
559 platform_driver_unregister(&pil_lpass_driver);
560}
561module_exit(pil_lpass_exit);
562
563MODULE_DESCRIPTION("Support for booting low-power audio subsystems with QDSP6v5 (Hexagon) processors");
564MODULE_LICENSE("GPL v2");