Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2010-2016, The Linux Foundation. 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 | #ifndef __APR_H_ |
| 14 | #define __APR_H_ |
| 15 | |
| 16 | #include <linux/mutex.h> |
| 17 | #include <soc/qcom/subsystem_notif.h> |
| 18 | |
| 19 | enum apr_subsys_state { |
| 20 | APR_SUBSYS_DOWN, |
| 21 | APR_SUBSYS_UP, |
| 22 | APR_SUBSYS_LOADED, |
| 23 | }; |
| 24 | |
| 25 | struct apr_q6 { |
| 26 | void *pil; |
| 27 | atomic_t q6_state; |
| 28 | atomic_t modem_state; |
| 29 | struct mutex lock; |
| 30 | }; |
| 31 | |
| 32 | struct apr_hdr { |
| 33 | uint16_t hdr_field; |
| 34 | uint16_t pkt_size; |
| 35 | uint8_t src_svc; |
| 36 | uint8_t src_domain; |
| 37 | uint16_t src_port; |
| 38 | uint8_t dest_svc; |
| 39 | uint8_t dest_domain; |
| 40 | uint16_t dest_port; |
| 41 | uint32_t token; |
| 42 | uint32_t opcode; |
| 43 | }; |
| 44 | |
| 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)) |
| 49 | |
| 50 | #define APR_HDR_SIZE sizeof(struct apr_hdr) |
| 51 | |
| 52 | /* Version */ |
| 53 | #define APR_PKT_VER 0x0 |
| 54 | |
| 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 |
| 61 | |
| 62 | /* APR Basic Response Message */ |
| 63 | #define APR_BASIC_RSP_RESULT 0x000110E8 |
| 64 | #define APR_RSP_ACCEPTED 0x000100BE |
| 65 | |
| 66 | /* Domain IDs */ |
| 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_MAX 0x6 |
| 73 | |
| 74 | /* ADSP service IDs */ |
| 75 | #define APR_SVC_TEST_CLIENT 0x2 |
| 76 | #define APR_SVC_ADSP_CORE 0x3 |
| 77 | #define APR_SVC_AFE 0x4 |
| 78 | #define APR_SVC_VSM 0x5 |
| 79 | #define APR_SVC_VPM 0x6 |
| 80 | #define APR_SVC_ASM 0x7 |
| 81 | #define APR_SVC_ADM 0x8 |
| 82 | #define APR_SVC_ADSP_MVM 0x09 |
| 83 | #define APR_SVC_ADSP_CVS 0x0A |
| 84 | #define APR_SVC_ADSP_CVP 0x0B |
| 85 | #define APR_SVC_USM 0x0C |
| 86 | #define APR_SVC_LSM 0x0D |
| 87 | #define APR_SVC_VIDC 0x16 |
| 88 | #define APR_SVC_MAX 0x17 |
| 89 | |
| 90 | /* Modem Service IDs */ |
| 91 | #define APR_SVC_MVS 0x3 |
| 92 | #define APR_SVC_MVM 0x4 |
| 93 | #define APR_SVC_CVS 0x5 |
| 94 | #define APR_SVC_CVP 0x6 |
| 95 | #define APR_SVC_SRD 0x7 |
| 96 | |
| 97 | /* APR Port IDs */ |
| 98 | #define APR_MAX_PORTS 0x80 |
| 99 | |
| 100 | #define APR_NAME_MAX 0x40 |
| 101 | |
| 102 | #define RESET_EVENTS 0x000130D7 |
| 103 | |
| 104 | #define LPASS_RESTART_EVENT 0x1000 |
| 105 | #define LPASS_RESTART_READY 0x1001 |
| 106 | |
| 107 | struct apr_client_data { |
| 108 | uint16_t reset_event; |
| 109 | uint16_t reset_proc; |
| 110 | uint16_t payload_size; |
| 111 | uint16_t hdr_len; |
| 112 | uint16_t msg_type; |
| 113 | uint16_t src; |
| 114 | uint16_t dest_svc; |
| 115 | uint16_t src_port; |
| 116 | uint16_t dest_port; |
| 117 | uint32_t token; |
| 118 | uint32_t opcode; |
| 119 | void *payload; |
| 120 | }; |
| 121 | |
| 122 | typedef int32_t (*apr_fn)(struct apr_client_data *data, void *priv); |
| 123 | |
| 124 | struct apr_svc { |
| 125 | uint16_t id; |
| 126 | uint16_t dest_id; |
| 127 | uint16_t client_id; |
| 128 | uint16_t dest_domain; |
| 129 | uint8_t rvd; |
| 130 | uint8_t port_cnt; |
| 131 | uint8_t svc_cnt; |
| 132 | uint8_t need_reset; |
| 133 | apr_fn port_fn[APR_MAX_PORTS]; |
| 134 | void *port_priv[APR_MAX_PORTS]; |
| 135 | apr_fn fn; |
| 136 | void *priv; |
| 137 | struct mutex m_lock; |
| 138 | spinlock_t w_lock; |
| 139 | uint8_t pkt_owner; |
| 140 | }; |
| 141 | |
| 142 | struct apr_client { |
| 143 | uint8_t id; |
| 144 | uint8_t svc_cnt; |
| 145 | uint8_t rvd; |
| 146 | struct mutex m_lock; |
| 147 | struct apr_svc_ch_dev *handle; |
| 148 | struct apr_svc svc[APR_SVC_MAX]; |
| 149 | }; |
| 150 | |
| 151 | struct apr_rx_intents { |
| 152 | int num_of_intents; |
| 153 | uint32_t size; |
| 154 | }; |
| 155 | |
| 156 | struct apr_pkt_cfg { |
| 157 | uint8_t pkt_owner; |
| 158 | struct apr_rx_intents intents; |
| 159 | }; |
| 160 | |
| 161 | int apr_load_adsp_image(void); |
| 162 | struct apr_client *apr_get_client(int dest_id, int client_id); |
| 163 | int apr_wait_for_device_up(int dest_id); |
| 164 | int apr_get_svc(const char *svc_name, int dest_id, int *client_id, |
| 165 | int *svc_idx, int *svc_id); |
| 166 | void apr_cb_func(void *buf, int len, void *priv); |
| 167 | struct apr_svc *apr_register(char *dest, char *svc_name, apr_fn svc_fn, |
| 168 | uint32_t src_port, void *priv); |
| 169 | inline int apr_fill_hdr(void *handle, uint32_t *buf, uint16_t src_port, |
| 170 | uint16_t msg_type, uint16_t dest_port, |
| 171 | uint32_t token, uint32_t opcode, uint16_t len); |
| 172 | |
| 173 | int apr_send_pkt(void *handle, uint32_t *buf); |
| 174 | int apr_deregister(void *handle); |
| 175 | void subsys_notif_register(char *client_name, int domain, |
| 176 | struct notifier_block *nb); |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame^] | 177 | void subsys_notif_deregister(char *client_name); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 178 | int apr_get_dest_id(char *dest); |
| 179 | uint16_t apr_get_data_src(struct apr_hdr *hdr); |
| 180 | void change_q6_state(int state); |
| 181 | void q6audio_dsp_not_responding(void); |
| 182 | void apr_reset(void *handle); |
| 183 | enum apr_subsys_state apr_get_subsys_state(void); |
| 184 | enum apr_subsys_state apr_get_modem_state(void); |
| 185 | void apr_set_modem_state(enum apr_subsys_state state); |
| 186 | enum apr_subsys_state apr_get_q6_state(void); |
| 187 | int apr_set_q6_state(enum apr_subsys_state state); |
| 188 | void apr_set_subsys_state(void); |
| 189 | const char *apr_get_lpass_subsys_name(void); |
| 190 | uint16_t apr_get_reset_domain(uint16_t proc); |
| 191 | #endif |