blob: 9535968d6ee7b19be3cafcbe5b7bab47ca290115 [file] [log] [blame]
Joonwoo Park91d95462012-08-02 10:55:54 -07001/*
2 * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
3 *
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/kernel.h>
15#include <linux/module.h>
16#include <linux/types.h>
17#include <linux/uaccess.h>
18#include <linux/err.h>
19#include <mach/qdsp6v2/apr.h>
20#include <mach/qdsp6v2/apr_tal.h>
21#include <mach/qdsp6v2/dsp_debug.h>
22#include <mach/peripheral-loader.h>
23
24struct apr_svc *apr_register(char *dest, char *svc_name, apr_fn svc_fn,
25 uint32_t src_port, void *priv)
26{
27 struct apr_client *client;
28 int client_id = 0;
29 int svc_idx = 0;
30 int svc_id = 0;
31 int dest_id = 0;
32 int temp_port = 0;
33 struct apr_svc *svc = NULL;
34 int rc = 0;
35
36 if (!dest || !svc_name || !svc_fn)
37 return NULL;
38
39 if (!strncmp(dest, "ADSP", 4))
40 dest_id = APR_DEST_QDSP6;
41 else if (!strncmp(dest, "MODEM", 5)) {
42 dest_id = APR_DEST_MODEM;
43 } else {
44 pr_err("APR: wrong destination\n");
45 goto done;
46 }
47
48 if (dest_id == APR_DEST_QDSP6 &&
49 apr_get_q6_state() == APR_SUBSYS_DOWN) {
50 pr_info("%s: Wait for Lpass to bootup\n", __func__);
51 rc = apr_wait_for_device_up(dest_id);
52 if (rc == 0) {
53 pr_err("%s: DSP is not Up\n", __func__);
54 return NULL;
55 }
56 pr_info("%s: Lpass Up\n", __func__);
57 } else if (dest_id == APR_DEST_MODEM &&
58 (apr_get_modem_state() == APR_SUBSYS_DOWN)) {
59 pr_info("%s: Wait for modem to bootup\n", __func__);
60 rc = apr_wait_for_device_up(dest_id);
61 if (rc == 0) {
62 pr_err("%s: Modem is not Up\n", __func__);
63 return NULL;
64 }
65 pr_info("%s: modem Up\n", __func__);
66 }
67
68 if (apr_get_svc(svc_name, dest_id, &client_id, &svc_idx, &svc_id)) {
69 pr_err("%s: apr_get_svc failed\n", __func__);
70 goto done;
71 }
72
73 /* APRv1 loads ADSP image automatically */
74 apr_load_adsp_image();
75
76 client = apr_get_client(dest_id, client_id);
77 mutex_lock(&client->m_lock);
78 if (!client->handle) {
79 client->handle = apr_tal_open(client_id, dest_id, APR_DL_SMD,
80 apr_cb_func, NULL);
81 if (!client->handle) {
82 svc = NULL;
83 pr_err("APR: Unable to open handle\n");
84 mutex_unlock(&client->m_lock);
85 goto done;
86 }
87 }
88 mutex_unlock(&client->m_lock);
89 svc = &client->svc[svc_idx];
90 mutex_lock(&svc->m_lock);
91 client->id = client_id;
92 if (svc->need_reset) {
93 mutex_unlock(&svc->m_lock);
94 pr_err("APR: Service needs reset\n");
95 goto done;
96 }
97 svc->priv = priv;
98 svc->id = svc_id;
99 svc->dest_id = dest_id;
100 svc->client_id = client_id;
101 if (src_port != 0xFFFFFFFF) {
102 temp_port = ((src_port >> 8) * 8) + (src_port & 0xFF);
103 pr_debug("port = %d t_port = %d\n", src_port, temp_port);
104 if (temp_port >= APR_MAX_PORTS || temp_port < 0) {
105 pr_err("APR: temp_port out of bounds\n");
106 mutex_unlock(&svc->m_lock);
107 return NULL;
108 }
109 if (!svc->port_cnt && !svc->svc_cnt)
110 client->svc_cnt++;
111 svc->port_cnt++;
112 svc->port_fn[temp_port] = svc_fn;
113 svc->port_priv[temp_port] = priv;
114 } else {
115 if (!svc->fn) {
116 if (!svc->port_cnt && !svc->svc_cnt)
117 client->svc_cnt++;
118 svc->fn = svc_fn;
119 if (svc->port_cnt)
120 svc->svc_cnt++;
121 }
122 }
123
124 mutex_unlock(&svc->m_lock);
125done:
126 return svc;
127}
128
129void apr_set_subsys_state(void)
130{
131 apr_set_q6_state(APR_SUBSYS_UP);
132 apr_set_modem_state(APR_SUBSYS_UP);
133}