blob: 78f651963a2725e5fdc340f097fbb6996375e169 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/types.h>
16#include <linux/uaccess.h>
17#include <linux/spinlock.h>
18#include <linux/mutex.h>
19#include <linux/list.h>
20#include <linux/sched.h>
21#include <linux/wait.h>
22#include <linux/errno.h>
23#include <linux/fs.h>
24#include <linux/delay.h>
25#include <linux/debugfs.h>
26#include <linux/platform_device.h>
27#include <linux/sysfs.h>
28#include <linux/device.h>
29#include <linux/slab.h>
30#include <mach/peripheral-loader.h>
31#include <mach/msm_smd.h>
32#include <mach/qdsp6v2/apr.h>
33#include <mach/qdsp6v2/apr_tal.h>
34#include <mach/qdsp6v2/dsp_debug.h>
35#include <mach/subsystem_notif.h>
36#include <mach/subsystem_restart.h>
37
38struct apr_q6 q6;
39struct apr_client client[APR_DEST_MAX][APR_CLIENT_MAX];
40static atomic_t dsp_state;
41static atomic_t modem_state;
42
43static wait_queue_head_t dsp_wait;
44static wait_queue_head_t modem_wait;
45/* Subsystem restart: QDSP6 data, functions */
46static struct workqueue_struct *apr_reset_workqueue;
47static void apr_reset_deregister(struct work_struct *work);
48struct apr_reset_work {
49 void *handle;
50 struct work_struct work;
51};
52
53
54int apr_send_pkt(void *handle, uint32_t *buf)
55{
56 struct apr_svc *svc = handle;
57 struct apr_client *clnt;
58 struct apr_hdr *hdr;
59 uint16_t dest_id;
60 uint16_t client_id;
61 uint16_t w_len;
62 unsigned long flags;
63
64 if (!handle || !buf) {
65 pr_err("APR: Wrong parameters\n");
66 return -EINVAL;
67 }
68 if (svc->need_reset) {
69 pr_err("apr: send_pkt service need reset\n");
70 return -ENETRESET;
71 }
72
73 if ((svc->dest_id == APR_DEST_QDSP6) &&
74 (atomic_read(&dsp_state) == 0)) {
75 pr_err("apr: Still dsp is not Up\n");
76 return -ENETRESET;
77 } else if ((svc->dest_id == APR_DEST_MODEM) &&
78 (atomic_read(&modem_state) == 0)) {
79 pr_err("apr: Still Modem is not Up\n");
80 return -ENETRESET;
81 }
82
83
84 spin_lock_irqsave(&svc->w_lock, flags);
85 dest_id = svc->dest_id;
86 client_id = svc->client_id;
87 clnt = &client[dest_id][client_id];
88
89 if (!client[dest_id][client_id].handle) {
90 pr_err("APR: Still service is not yet opened\n");
91 spin_unlock_irqrestore(&svc->w_lock, flags);
92 return -EINVAL;
93 }
94 hdr = (struct apr_hdr *)buf;
95
96 hdr->src_domain = APR_DOMAIN_APPS;
97 hdr->src_svc = svc->id;
98 if (dest_id == APR_DEST_MODEM)
99 hdr->dest_domain = APR_DOMAIN_MODEM;
100 else if (dest_id == APR_DEST_QDSP6)
101 hdr->dest_domain = APR_DOMAIN_ADSP;
102
103 hdr->dest_svc = svc->id;
104
105 w_len = apr_tal_write(clnt->handle, buf, hdr->pkt_size);
106 if (w_len != hdr->pkt_size)
107 pr_err("Unable to write APR pkt successfully: %d\n", w_len);
108 spin_unlock_irqrestore(&svc->w_lock, flags);
109
110 return w_len;
111}
112
113static void apr_cb_func(void *buf, int len, void *priv)
114{
115 struct apr_client_data data;
116 struct apr_client *apr_client;
117 struct apr_svc *c_svc;
118 struct apr_hdr *hdr;
119 uint16_t hdr_size;
120 uint16_t msg_type;
121 uint16_t ver;
122 uint16_t src;
123 uint16_t svc;
124 uint16_t clnt;
125 int i;
126 int temp_port = 0;
127 uint32_t *ptr;
128
129 pr_debug("APR2: len = %d\n", len);
130 ptr = buf;
131 pr_debug("\n*****************\n");
132 for (i = 0; i < len/4; i++)
133 pr_debug("%x ", ptr[i]);
134 pr_debug("\n");
135 pr_debug("\n*****************\n");
136
137 if (!buf || len <= APR_HDR_SIZE) {
138 pr_err("APR: Improper apr pkt received:%p %d\n",
139 buf, len);
140 return;
141 }
142 hdr = buf;
143
144 ver = hdr->hdr_field;
145 ver = (ver & 0x000F);
146 if (ver > APR_PKT_VER + 1) {
147 pr_err("APR: Wrong version: %d\n", ver);
148 return;
149 }
150
151 hdr_size = hdr->hdr_field;
152 hdr_size = ((hdr_size & 0x00F0) >> 0x4) * 4;
153 if (hdr_size < APR_HDR_SIZE) {
154 pr_err("APR: Wrong hdr size:%d\n", hdr_size);
155 return;
156 }
157
158 if (hdr->pkt_size < APR_HDR_SIZE) {
159 pr_err("APR: Wrong paket size\n");
160 return;
161 }
162 msg_type = hdr->hdr_field;
163 msg_type = (msg_type >> 0x08) & 0x0003;
164 if (msg_type >= APR_MSG_TYPE_MAX &&
165 msg_type != APR_BASIC_RSP_RESULT) {
166 pr_err("APR: Wrong message type: %d\n", msg_type);
167 return;
168 }
169
170 if (hdr->src_domain >= APR_DOMAIN_MAX ||
171 hdr->dest_domain >= APR_DOMAIN_MAX ||
172 hdr->src_svc >= APR_SVC_MAX ||
173 hdr->dest_svc >= APR_SVC_MAX) {
174 pr_err("APR: Wrong APR header\n");
175 return;
176 }
177
178 svc = hdr->dest_svc;
179 if (hdr->src_domain == APR_DOMAIN_MODEM) {
180 src = APR_DEST_MODEM;
181 if (svc == APR_SVC_MVS || svc == APR_SVC_MVM ||
182 svc == APR_SVC_CVS || svc == APR_SVC_CVP ||
183 svc == APR_SVC_TEST_CLIENT)
184 clnt = APR_CLIENT_VOICE;
185 else {
186 pr_err("APR: Wrong svc :%d\n", svc);
187 return;
188 }
189 } else if (hdr->src_domain == APR_DOMAIN_ADSP) {
190 src = APR_DEST_QDSP6;
191 if (svc == APR_SVC_AFE || svc == APR_SVC_ASM ||
192 svc == APR_SVC_VSM || svc == APR_SVC_VPM ||
193 svc == APR_SVC_ADM || svc == APR_SVC_ADSP_CORE ||
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200194 svc == APR_SVC_USM ||
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700195 svc == APR_SVC_TEST_CLIENT || svc == APR_SVC_ADSP_MVM ||
196 svc == APR_SVC_ADSP_CVS || svc == APR_SVC_ADSP_CVP)
197 clnt = APR_CLIENT_AUDIO;
198 else {
199 pr_err("APR: Wrong svc :%d\n", svc);
200 return;
201 }
202 } else {
203 pr_err("APR: Pkt from wrong source: %d\n", hdr->src_domain);
204 return;
205 }
206
207 pr_debug("src =%d clnt = %d\n", src, clnt);
208 apr_client = &client[src][clnt];
209 for (i = 0; i < APR_SVC_MAX; i++)
210 if (apr_client->svc[i].id == svc) {
211 pr_debug("%d\n", apr_client->svc[i].id);
212 c_svc = &apr_client->svc[i];
213 break;
214 }
215
216 if (i == APR_SVC_MAX) {
217 pr_err("APR: service is not registered\n");
218 return;
219 }
220 pr_debug("svc_idx = %d\n", i);
221 pr_debug("%x %x %x %p %p\n", c_svc->id, c_svc->dest_id,
222 c_svc->client_id, c_svc->fn, c_svc->priv);
223 data.payload_size = hdr->pkt_size - hdr_size;
224 data.opcode = hdr->opcode;
225 data.src = src;
226 data.src_port = hdr->src_port;
227 data.dest_port = hdr->dest_port;
228 data.token = hdr->token;
229 data.msg_type = msg_type;
230 if (data.payload_size > 0)
231 data.payload = (char *)hdr + hdr_size;
232
233 temp_port = ((data.src_port >> 8) * 8) + (data.src_port & 0xFF);
234 pr_debug("port = %d t_port = %d\n", data.src_port, temp_port);
235 if (c_svc->port_cnt && c_svc->port_fn[temp_port])
236 c_svc->port_fn[temp_port](&data, c_svc->port_priv[temp_port]);
237 else if (c_svc->fn)
238 c_svc->fn(&data, c_svc->priv);
239 else
240 pr_err("APR: Rxed a packet for NULL callback\n");
241}
242
243struct apr_svc *apr_register(char *dest, char *svc_name, apr_fn svc_fn,
244 uint32_t src_port, void *priv)
245{
246 int client_id = 0;
247 int svc_idx = 0;
248 int svc_id = 0;
249 int dest_id = 0;
250 int temp_port = 0;
251 struct apr_svc *svc = NULL;
252 int rc = 0;
253
254 if (!dest || !svc_name || !svc_fn)
255 return NULL;
256
257 if (!strcmp(dest, "ADSP"))
258 dest_id = APR_DEST_QDSP6;
259 else if (!strcmp(dest, "MODEM")) {
260 dest_id = APR_DEST_MODEM;
261 } else {
262 pr_err("APR: wrong destination\n");
263 goto done;
264 }
265
266 if ((dest_id == APR_DEST_QDSP6) &&
267 (atomic_read(&dsp_state) == 0)) {
Bharath Ramachandramurthye0b55322011-08-23 10:54:14 -0700268 pr_info("%s: Wait for Lpass to bootup\n", __func__);
269 rc = wait_event_interruptible(dsp_wait,
270 (atomic_read(&dsp_state) == 1));
271 if (rc < 0) {
272 pr_err("%s: DSP is not Up\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700273 return NULL;
274 }
Bharath Ramachandramurthye0b55322011-08-23 10:54:14 -0700275 pr_debug("%s: Lpass Up\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700276 } else if ((dest_id == APR_DEST_MODEM) &&
277 (atomic_read(&modem_state) == 0)) {
Bharath Ramachandramurthye0b55322011-08-23 10:54:14 -0700278 pr_info("%s: Wait for modem to bootup\n", __func__);
279 rc = wait_event_interruptible(modem_wait,
280 (atomic_read(&modem_state) == 1));
281 if (rc < 0) {
282 pr_err("%s: Modem is not Up\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700283 return NULL;
284 }
Bharath Ramachandramurthye0b55322011-08-23 10:54:14 -0700285 pr_debug("%s: modem Up\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700286 }
287
288 if (!strcmp(svc_name, "AFE")) {
289 client_id = APR_CLIENT_AUDIO;
290 svc_idx = 0;
291 svc_id = APR_SVC_AFE;
292 } else if (!strcmp(svc_name, "ASM")) {
293 client_id = APR_CLIENT_AUDIO;
294 svc_idx = 1;
295 svc_id = APR_SVC_ASM;
296 } else if (!strcmp(svc_name, "ADM")) {
297 client_id = APR_CLIENT_AUDIO;
298 svc_idx = 2;
299 svc_id = APR_SVC_ADM;
300 } else if (!strcmp(svc_name, "CORE")) {
301 client_id = APR_CLIENT_AUDIO;
302 svc_idx = 3;
303 svc_id = APR_SVC_ADSP_CORE;
304 } else if (!strcmp(svc_name, "TEST")) {
305 if (dest_id == APR_DEST_QDSP6) {
306 client_id = APR_CLIENT_AUDIO;
307 svc_idx = 4;
308 } else {
309 client_id = APR_CLIENT_VOICE;
310 svc_idx = 7;
311 }
312 svc_id = APR_SVC_TEST_CLIENT;
313 } else if (!strcmp(svc_name, "VSM")) {
314 client_id = APR_CLIENT_VOICE;
315 svc_idx = 0;
316 svc_id = APR_SVC_VSM;
317 } else if (!strcmp(svc_name, "VPM")) {
318 client_id = APR_CLIENT_VOICE;
319 svc_idx = 1;
320 svc_id = APR_SVC_VPM;
321 } else if (!strcmp(svc_name, "MVS")) {
322 client_id = APR_CLIENT_VOICE;
323 svc_idx = 2;
324 svc_id = APR_SVC_MVS;
325 } else if (!strcmp(svc_name, "MVM")) {
326 if (dest_id == APR_DEST_MODEM) {
327 client_id = APR_CLIENT_VOICE;
328 svc_idx = 3;
329 svc_id = APR_SVC_MVM;
330 } else {
331 client_id = APR_CLIENT_AUDIO;
332 svc_idx = 5;
333 svc_id = APR_SVC_ADSP_MVM;
334 }
335 } else if (!strcmp(svc_name, "CVS")) {
336 if (dest_id == APR_DEST_MODEM) {
337 client_id = APR_CLIENT_VOICE;
338 svc_idx = 4;
339 svc_id = APR_SVC_CVS;
340 } else {
341 client_id = APR_CLIENT_AUDIO;
342 svc_idx = 6;
343 svc_id = APR_SVC_ADSP_CVS;
344 }
345 } else if (!strcmp(svc_name, "CVP")) {
346 if (dest_id == APR_DEST_MODEM) {
347 client_id = APR_CLIENT_VOICE;
348 svc_idx = 5;
349 svc_id = APR_SVC_CVP;
350 } else {
351 client_id = APR_CLIENT_AUDIO;
352 svc_idx = 7;
353 svc_id = APR_SVC_ADSP_CVP;
354 }
355 } else if (!strcmp(svc_name, "SRD")) {
356 client_id = APR_CLIENT_VOICE;
357 svc_idx = 6;
358 svc_id = APR_SVC_SRD;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200359 } else if (!strncmp(svc_name, "USM", 3)) {
360 client_id = APR_CLIENT_AUDIO;
361 svc_idx = 8;
362 svc_id = APR_SVC_USM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700363 } else {
364 pr_err("APR: Wrong svc name\n");
365 goto done;
366 }
367
368 pr_debug("svc name = %s c_id = %d dest_id = %d\n",
369 svc_name, client_id, dest_id);
370 mutex_lock(&q6.lock);
371 if (q6.state == APR_Q6_NOIMG) {
372 q6.pil = pil_get("q6");
373 if (!q6.pil) {
374 pr_err("APR: Unable to load q6 image\n");
375 mutex_unlock(&q6.lock);
376 return svc;
377 }
378 q6.state = APR_Q6_LOADED;
379 }
380 mutex_unlock(&q6.lock);
381 mutex_lock(&client[dest_id][client_id].m_lock);
382 if (!client[dest_id][client_id].handle) {
383 client[dest_id][client_id].handle = apr_tal_open(client_id,
384 dest_id, APR_DL_SMD, apr_cb_func, NULL);
385 if (!client[dest_id][client_id].handle) {
386 svc = NULL;
387 pr_err("APR: Unable to open handle\n");
388 mutex_unlock(&client[dest_id][client_id].m_lock);
389 goto done;
390 }
391 }
392 mutex_unlock(&client[dest_id][client_id].m_lock);
393 svc = &client[dest_id][client_id].svc[svc_idx];
394 mutex_lock(&svc->m_lock);
395 client[dest_id][client_id].id = client_id;
396 if (svc->need_reset) {
397 mutex_unlock(&svc->m_lock);
398 pr_err("APR: Service needs reset\n");
399 goto done;
400 }
401 svc->priv = priv;
402 svc->id = svc_id;
403 svc->dest_id = dest_id;
404 svc->client_id = client_id;
405 if (src_port != 0xFFFFFFFF) {
406 temp_port = ((src_port >> 8) * 8) + (src_port & 0xFF);
407 pr_debug("port = %d t_port = %d\n", src_port, temp_port);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +0530408 if (temp_port >= APR_MAX_PORTS || temp_port < 0) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700409 pr_err("APR: temp_port out of bounds\n");
410 mutex_unlock(&svc->m_lock);
411 return NULL;
412 }
413 if (!svc->port_cnt && !svc->svc_cnt)
414 client[dest_id][client_id].svc_cnt++;
415 svc->port_cnt++;
416 svc->port_fn[temp_port] = svc_fn;
417 svc->port_priv[temp_port] = priv;
418 } else {
419 if (!svc->fn) {
420 if (!svc->port_cnt && !svc->svc_cnt)
421 client[dest_id][client_id].svc_cnt++;
422 svc->fn = svc_fn;
423 if (svc->port_cnt)
424 svc->svc_cnt++;
425 }
426 }
427
428 mutex_unlock(&svc->m_lock);
429done:
430 return svc;
431}
432
433static void apr_reset_deregister(struct work_struct *work)
434{
435 struct apr_svc *handle = NULL;
436 struct apr_reset_work *apr_reset =
437 container_of(work, struct apr_reset_work, work);
438
439 handle = apr_reset->handle;
440 pr_debug("%s:handle[%p]\n", __func__, handle);
441 apr_deregister(handle);
442 kfree(apr_reset);
443}
444
445int apr_deregister(void *handle)
446{
447 struct apr_svc *svc = handle;
448 struct apr_client *clnt;
449 uint16_t dest_id;
450 uint16_t client_id;
451
452 if (!handle)
453 return -EINVAL;
454
455 mutex_lock(&svc->m_lock);
456 dest_id = svc->dest_id;
457 client_id = svc->client_id;
458 clnt = &client[dest_id][client_id];
459
460 if (svc->port_cnt > 0 || svc->svc_cnt > 0) {
461 if (svc->port_cnt)
462 svc->port_cnt--;
463 else if (svc->svc_cnt)
464 svc->svc_cnt--;
465 if (!svc->port_cnt && !svc->svc_cnt) {
466 client[dest_id][client_id].svc_cnt--;
467 svc->need_reset = 0x0;
468 }
469 } else if (client[dest_id][client_id].svc_cnt > 0) {
470 client[dest_id][client_id].svc_cnt--;
471 if (!client[dest_id][client_id].svc_cnt) {
472 svc->need_reset = 0x0;
473 pr_debug("%s: service is reset %p\n", __func__, svc);
474 }
475 }
476
477 if (!svc->port_cnt && !svc->svc_cnt) {
478 svc->priv = NULL;
479 svc->id = 0;
480 svc->fn = NULL;
481 svc->dest_id = 0;
482 svc->client_id = 0;
483 svc->need_reset = 0x0;
484 }
485 if (client[dest_id][client_id].handle &&
486 !client[dest_id][client_id].svc_cnt) {
487 apr_tal_close(client[dest_id][client_id].handle);
488 client[dest_id][client_id].handle = NULL;
489 }
490 mutex_unlock(&svc->m_lock);
491
492 return 0;
493}
494
495void apr_reset(void *handle)
496{
497 struct apr_reset_work *apr_reset_worker = NULL;
498
499 if (!handle)
500 return;
501 pr_debug("%s: handle[%p]\n", __func__, handle);
502
503 apr_reset_worker = kzalloc(sizeof(struct apr_reset_work),
504 GFP_ATOMIC);
505 if (apr_reset_worker == NULL || apr_reset_workqueue == NULL) {
506 pr_err("%s: mem failure\n", __func__);
507 return;
508 }
509 apr_reset_worker->handle = handle;
510 INIT_WORK(&apr_reset_worker->work, apr_reset_deregister);
511 queue_work(apr_reset_workqueue, &apr_reset_worker->work);
512}
513
514void change_q6_state(int state)
515{
516 mutex_lock(&q6.lock);
517 q6.state = state;
518 mutex_unlock(&q6.lock);
519}
520
521int adsp_state(int state)
522{
523 pr_info("dsp state = %d\n", state);
524 return 0;
525}
526
527/* Dispatch the Reset events to Modem and audio clients */
528void dispatch_event(unsigned long code, unsigned short proc)
529{
530 struct apr_client *apr_client;
531 struct apr_client_data data;
532 struct apr_svc *svc;
533 uint16_t clnt;
534 int i, j;
535
536 data.opcode = RESET_EVENTS;
537 data.reset_event = code;
538 data.reset_proc = proc;
539
540 clnt = APR_CLIENT_AUDIO;
541 apr_client = &client[proc][clnt];
542 for (i = 0; i < APR_SVC_MAX; i++) {
543 mutex_lock(&apr_client->svc[i].m_lock);
544 if (apr_client->svc[i].fn) {
545 apr_client->svc[i].need_reset = 0x1;
546 apr_client->svc[i].fn(&data, apr_client->svc[i].priv);
547 }
548 if (apr_client->svc[i].port_cnt) {
549 svc = &(apr_client->svc[i]);
550 svc->need_reset = 0x1;
551 for (j = 0; j < APR_MAX_PORTS; j++)
552 if (svc->port_fn[j])
553 svc->port_fn[j](&data,
554 svc->port_priv[j]);
555 }
556 mutex_unlock(&apr_client->svc[i].m_lock);
557 }
558
559 clnt = APR_CLIENT_VOICE;
560 apr_client = &client[proc][clnt];
561 for (i = 0; i < APR_SVC_MAX; i++) {
562 mutex_lock(&apr_client->svc[i].m_lock);
563 if (apr_client->svc[i].fn) {
564 apr_client->svc[i].need_reset = 0x1;
565 apr_client->svc[i].fn(&data, apr_client->svc[i].priv);
566 }
567 if (apr_client->svc[i].port_cnt) {
568 svc = &(apr_client->svc[i]);
569 svc->need_reset = 0x1;
570 for (j = 0; j < APR_MAX_PORTS; j++)
571 if (svc->port_fn[j])
572 svc->port_fn[j](&data,
573 svc->port_priv[j]);
574 }
575 mutex_unlock(&apr_client->svc[i].m_lock);
576 }
577}
578
579static int modem_notifier_cb(struct notifier_block *this, unsigned long code,
580 void *_cmd)
581{
582 switch (code) {
583 case SUBSYS_BEFORE_SHUTDOWN:
584 pr_debug("M-Notify: Shutdown started\n");
585 atomic_set(&modem_state, 0);
586 dispatch_event(code, APR_DEST_MODEM);
587 break;
588 case SUBSYS_AFTER_SHUTDOWN:
589 pr_debug("M-Notify: Shutdown Completed\n");
590 break;
591 case SUBSYS_BEFORE_POWERUP:
592 pr_debug("M-notify: Bootup started\n");
593 break;
594 case SUBSYS_AFTER_POWERUP:
595 if (atomic_read(&modem_state) == 0) {
596 atomic_set(&modem_state, 1);
597 wake_up(&modem_wait);
598 }
599 pr_debug("M-Notify: Bootup Completed\n");
600 break;
601 default:
602 pr_err("M-Notify: General: %lu\n", code);
603 break;
604 }
605 return NOTIFY_DONE;
606}
607
608static struct notifier_block mnb = {
609 .notifier_call = modem_notifier_cb,
610};
611
612static int lpass_notifier_cb(struct notifier_block *this, unsigned long code,
613 void *_cmd)
614{
615 switch (code) {
616 case SUBSYS_BEFORE_SHUTDOWN:
617 pr_debug("L-Notify: Shutdown started\n");
618 atomic_set(&dsp_state, 0);
619 dispatch_event(code, APR_DEST_QDSP6);
620 break;
621 case SUBSYS_AFTER_SHUTDOWN:
622 pr_debug("L-Notify: Shutdown Completed\n");
623 break;
624 case SUBSYS_BEFORE_POWERUP:
625 pr_debug("L-notify: Bootup started\n");
626 break;
627 case SUBSYS_AFTER_POWERUP:
628 if (atomic_read(&dsp_state) == 0) {
629 atomic_set(&dsp_state, 1);
630 wake_up(&dsp_wait);
631 }
632 pr_debug("L-Notify: Bootup Completed\n");
633 break;
634 default:
635 pr_err("L-Notify: Generel: %lu\n", code);
636 break;
637 }
638 return NOTIFY_DONE;
639}
640
641static struct notifier_block lnb = {
642 .notifier_call = lpass_notifier_cb,
643};
644
645
646static int __init apr_init(void)
647{
648 int i, j, k;
649
650 for (i = 0; i < APR_DEST_MAX; i++)
651 for (j = 0; j < APR_CLIENT_MAX; j++) {
652 mutex_init(&client[i][j].m_lock);
653 for (k = 0; k < APR_SVC_MAX; k++) {
654 mutex_init(&client[i][j].svc[k].m_lock);
655 spin_lock_init(&client[i][j].svc[k].w_lock);
656 }
657 }
658 mutex_init(&q6.lock);
659 dsp_debug_register(adsp_state);
660 apr_reset_workqueue =
661 create_singlethread_workqueue("apr_driver");
662 if (!apr_reset_workqueue)
663 return -ENOMEM;
664 return 0;
665}
666device_initcall(apr_init);
667
668static int __init apr_late_init(void)
669{
670 void *ret;
671 init_waitqueue_head(&dsp_wait);
672 init_waitqueue_head(&modem_wait);
673 atomic_set(&dsp_state, 1);
674 atomic_set(&modem_state, 1);
675 ret = subsys_notif_register_notifier("modem", &mnb);
676 pr_debug("subsys_register_notifier: ret1 = %p\n", ret);
677 ret = subsys_notif_register_notifier("lpass", &lnb);
678 pr_debug("subsys_register_notifier: ret2 = %p\n", ret);
679
680 return 0;
681}
682late_initcall(apr_late_init);