1 /* Copyright (c) 2010-2017, 2019, The Linux Foundation. All rights reserved.
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.
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.
16 #include <linux/mutex.h>
17 #include <soc/qcom/subsystem_notif.h>
19 enum apr_subsys_state {
45 #define APR_HDR_LEN(hdr_len) ((hdr_len)/4)
46 #define APR_PKT_SIZE(hdr_len, payload_len) ((hdr_len) + (payload_len))
47 #define APR_HDR_FIELD(msg_type, hdr_len, ver)\
48 (((msg_type & 0x3) << 8) | ((hdr_len & 0xF) << 4) | (ver & 0xF))
50 #define APR_HDR_SIZE sizeof(struct apr_hdr)
53 #define APR_PKT_VER 0x0
55 /* Command and Response Types */
56 #define APR_MSG_TYPE_EVENT 0x0
57 #define APR_MSG_TYPE_CMD_RSP 0x1
58 #define APR_MSG_TYPE_SEQ_CMD 0x2
59 #define APR_MSG_TYPE_NSEQ_CMD 0x3
60 #define APR_MSG_TYPE_MAX 0x04
62 /* APR Basic Response Message */
63 #define APR_BASIC_RSP_RESULT 0x000110E8
64 #define APR_RSP_ACCEPTED 0x000100BE
67 #define APR_DOMAIN_SIM 0x1
68 #define APR_DOMAIN_PC 0x2
69 #define APR_DOMAIN_MODEM 0x3
70 #define APR_DOMAIN_ADSP 0x4
71 #define APR_DOMAIN_APPS 0x5
72 #define APR_DOMAIN_SDSP 0x8
73 #define APR_DOMAIN_MAX 0x9
76 /* ADSP service IDs */
77 #define APR_SVC_TEST_CLIENT 0x2
78 #define APR_SVC_ADSP_CORE 0x3
79 #define APR_SVC_AFE 0x4
80 #define APR_SVC_VSM 0x5
81 #define APR_SVC_VPM 0x6
82 #define APR_SVC_ASM 0x7
83 #define APR_SVC_ADM 0x8
84 #define APR_SVC_ADSP_MVM 0x09
85 #define APR_SVC_ADSP_CVS 0x0A
86 #define APR_SVC_ADSP_CVP 0x0B
87 #define APR_SVC_USM 0x0C
88 #define APR_SVC_LSM 0x0D
89 #define APR_SVC_VIDC 0x16
90 #define APR_SVC_MAX 0x17
92 /* Modem Service IDs */
93 #define APR_SVC_MVS 0x3
94 #define APR_SVC_MVM 0x4
95 #define APR_SVC_CVS 0x5
96 #define APR_SVC_CVP 0x6
97 #define APR_SVC_SRD 0x7
99 /* Sensor DSP Micro Audio Service IDs */
100 #define APR_SVC_MAS 0x3
103 #define APR_MAX_PORTS 0x80
105 #define APR_NAME_MAX 0x40
107 #define RESET_EVENTS 0x000130D7
109 #define LPASS_RESTART_EVENT 0x1000
110 #define LPASS_RESTART_READY 0x1001
112 struct apr_client_data {
113 uint16_t reset_event;
115 uint16_t payload_size;
127 typedef int32_t (*apr_fn)(struct apr_client_data *data, void *priv);
133 uint16_t dest_domain;
138 apr_fn port_fn[APR_MAX_PORTS];
139 void *port_priv[APR_MAX_PORTS];
145 #ifdef CONFIG_MSM_QDSP6_APRV2_VM
146 uint16_t vm_dest_svc;
156 struct apr_svc_ch_dev *handle;
157 struct apr_svc svc[APR_SVC_MAX];
160 struct apr_rx_intents {
167 struct apr_rx_intents intents;
170 int apr_load_adsp_image(void);
171 struct apr_client *apr_get_client(int dest_id, int client_id);
172 int apr_wait_for_device_up(int dest_id);
173 int apr_get_svc(const char *svc_name, int dest_id, int *client_id,
174 int *svc_idx, int *svc_id);
175 void apr_cb_func(void *buf, int len, void *priv);
176 struct apr_svc *apr_register(char *dest, char *svc_name, apr_fn svc_fn,
177 uint32_t src_port, void *priv);
178 inline int apr_fill_hdr(void *handle, uint32_t *buf, uint16_t src_port,
179 uint16_t msg_type, uint16_t dest_port,
180 uint32_t token, uint32_t opcode, uint16_t len);
182 int apr_send_pkt(void *handle, uint32_t *buf);
183 int apr_deregister(void *handle);
184 void subsys_notif_register(char *client_name, int domain,
185 struct notifier_block *nb);
186 int apr_get_dest_id(char *dest);
187 uint16_t apr_get_data_src(struct apr_hdr *hdr);
188 void change_q6_state(int state);
189 void q6audio_dsp_not_responding(void);
190 void apr_reset(void *handle);
191 enum apr_subsys_state apr_get_subsys_state(void);
192 enum apr_subsys_state apr_get_modem_state(void);
193 void apr_set_modem_state(enum apr_subsys_state state);
194 enum apr_subsys_state apr_get_q6_state(void);
195 int apr_set_q6_state(enum apr_subsys_state state);
196 void apr_set_subsys_state(void);
197 const char *apr_get_lpass_subsys_name(void);
198 uint16_t apr_get_reset_domain(uint16_t proc);
199 #ifdef CONFIG_MSM_QDSP6_APRV2_VM
200 static inline int apr_start_rx_rt(void *handle)
205 static inline int apr_end_rx_rt(void *handle)
210 int apr_start_rx_rt(void *handle);
211 int apr_end_rx_rt(void *handle);