1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright(c) 2020 Intel Corporation 4 * 5 * Author: Cezary Rojewski <cezary.rojewski@intel.com> 6 */ 7 8 #ifndef __SND_SOC_INTEL_CATPT_MSG_H 9 #define __SND_SOC_INTEL_CATPT_MSG_H 10 11 struct catpt_dev; 12 13 /* IPC messages base types */ 14 15 enum catpt_reply_status { 16 CATPT_REPLY_SUCCESS = 0, 17 CATPT_REPLY_ERROR_INVALID_PARAM = 1, 18 CATPT_REPLY_UNKNOWN_MESSAGE_TYPE = 2, 19 CATPT_REPLY_OUT_OF_RESOURCES = 3, 20 CATPT_REPLY_BUSY = 4, 21 CATPT_REPLY_PENDING = 5, 22 CATPT_REPLY_FAILURE = 6, 23 CATPT_REPLY_INVALID_REQUEST = 7, 24 CATPT_REPLY_UNINITIALIZED = 8, 25 CATPT_REPLY_NOT_FOUND = 9, 26 CATPT_REPLY_SOURCE_NOT_STARTED = 10, 27 }; 28 29 /* GLOBAL messages */ 30 31 enum catpt_global_msg_type { 32 CATPT_GLB_GET_FW_VERSION = 0, 33 CATPT_GLB_ALLOCATE_STREAM = 3, 34 CATPT_GLB_FREE_STREAM = 4, 35 CATPT_GLB_STREAM_MESSAGE = 6, 36 CATPT_GLB_REQUEST_CORE_DUMP = 7, 37 CATPT_GLB_SET_DEVICE_FORMATS = 10, 38 CATPT_GLB_ENTER_DX_STATE = 12, 39 CATPT_GLB_GET_MIXER_STREAM_INFO = 13, 40 }; 41 42 union catpt_global_msg { 43 u32 val; 44 struct { 45 u32 status:5; 46 u32 context:19; /* stream or module specific */ 47 u32 global_msg_type:5; 48 u32 fw_ready:1; 49 u32 done:1; 50 u32 busy:1; 51 }; 52 } __packed; 53 54 #define CATPT_MSG(hdr) { .val = hdr } 55 #define CATPT_GLOBAL_MSG(msg_type) \ 56 { .global_msg_type = CATPT_GLB_##msg_type } 57 58 #define BUILD_HASH_SIZE 40 59 60 struct catpt_fw_version { 61 u8 build; 62 u8 minor; 63 u8 major; 64 u8 type; 65 u8 build_hash[BUILD_HASH_SIZE]; 66 u32 log_providers_hash; 67 } __packed; 68 69 int catpt_ipc_get_fw_version(struct catpt_dev *cdev, 70 struct catpt_fw_version *version); 71 72 /* PIN_IDs represent both, individual streams and the general mixer. */ 73 enum catpt_pin_id { 74 CATPT_PIN_ID_SYSTEM = 0, 75 CATPT_PIN_ID_REFERENCE = 1, 76 CATPT_PIN_ID_CAPTURE1 = 2, 77 CATPT_PIN_ID_CAPTURE2 = 3, 78 CATPT_PIN_ID_OFFLOAD1 = 4, 79 CATPT_PIN_ID_OFFLOAD2 = 5, 80 CATPT_PIN_ID_MIXER = 7, 81 CATPT_PIN_ID_BLUETOOTH_CAPTURE = 8, 82 CATPT_PIN_ID_BLUETOOTH_RENDER = 9, 83 /* 10 is reserved */ 84 CATPT_PIN_ID_INVALID = 11, 85 }; 86 87 enum catpt_path_id { 88 CATPT_PATH_SSP0_OUT = 0, 89 CATPT_PATH_SSP0_IN = 1, 90 CATPT_PATH_SSP1_OUT = 2, 91 CATPT_PATH_SSP1_IN = 3, 92 /* duplicated audio in capture path */ 93 CATPT_PATH_SSP0_IN_DUP = 4, 94 }; 95 96 enum catpt_stream_type { 97 CATPT_STRM_TYPE_RENDER = 0, /* offload */ 98 CATPT_STRM_TYPE_SYSTEM = 1, 99 CATPT_STRM_TYPE_CAPTURE = 2, 100 CATPT_STRM_TYPE_LOOPBACK = 3, 101 CATPT_STRM_TYPE_BLUETOOTH_RENDER = 4, 102 CATPT_STRM_TYPE_BLUETOOTH_CAPTURE = 5, 103 }; 104 105 enum catpt_format_id { 106 CATPT_FORMAT_PCM = 0, 107 CATPT_FORMAT_MP3 = 1, 108 CATPT_FORMAT_AAC = 2, 109 CATPT_FORMAT_WMA = 3, 110 }; 111 112 enum catpt_channel_index { 113 CATPT_CHANNEL_LEFT = 0x0, 114 CATPT_CHANNEL_CENTER = 0x1, 115 CATPT_CHANNEL_RIGHT = 0x2, 116 CATPT_CHANNEL_LEFT_SURROUND = 0x3, 117 CATPT_CHANNEL_CENTER_SURROUND = 0x3, 118 CATPT_CHANNEL_RIGHT_SURROUND = 0x4, 119 CATPT_CHANNEL_LFE = 0x7, 120 CATPT_CHANNEL_INVALID = 0xF, 121 }; 122 123 enum catpt_channel_config { 124 CATPT_CHANNEL_CONFIG_MONO = 0, /* One channel only */ 125 CATPT_CHANNEL_CONFIG_STEREO = 1, /* L & R */ 126 CATPT_CHANNEL_CONFIG_2_POINT_1 = 2, /* L, R & LFE; PCM only */ 127 CATPT_CHANNEL_CONFIG_3_POINT_0 = 3, /* L, C & R; MP3 & AAC only */ 128 CATPT_CHANNEL_CONFIG_3_POINT_1 = 4, /* L, C, R & LFE; PCM only */ 129 CATPT_CHANNEL_CONFIG_QUATRO = 5, /* L, R, Ls & Rs; PCM only */ 130 CATPT_CHANNEL_CONFIG_4_POINT_0 = 6, /* L, C, R & Cs; MP3 & AAC only */ 131 CATPT_CHANNEL_CONFIG_5_POINT_0 = 7, /* L, C, R, Ls & Rs */ 132 CATPT_CHANNEL_CONFIG_5_POINT_1 = 8, /* L, C, R, Ls, Rs & LFE */ 133 CATPT_CHANNEL_CONFIG_DUAL_MONO = 9, /* One channel replicated in two */ 134 CATPT_CHANNEL_CONFIG_INVALID = 10, 135 }; 136 137 enum catpt_interleaving_style { 138 CATPT_INTERLEAVING_PER_CHANNEL = 0, 139 CATPT_INTERLEAVING_PER_SAMPLE = 1, 140 }; 141 142 struct catpt_audio_format { 143 u32 sample_rate; 144 u32 bit_depth; 145 u32 channel_map; 146 u32 channel_config; 147 u32 interleaving; 148 u8 num_channels; 149 u8 valid_bit_depth; 150 u8 reserved[2]; 151 } __packed; 152 153 struct catpt_ring_info { 154 u32 page_table_addr; 155 u32 num_pages; 156 u32 size; 157 u32 offset; 158 u32 ring_first_page_pfn; 159 } __packed; 160 161 #define CATPT_MODULE_COUNT (CATPT_MODID_LAST + 1) 162 163 enum catpt_module_id { 164 CATPT_MODID_BASE_FW = 0x0, 165 CATPT_MODID_MP3 = 0x1, 166 CATPT_MODID_AAC_5_1 = 0x2, 167 CATPT_MODID_AAC_2_0 = 0x3, 168 CATPT_MODID_SRC = 0x4, 169 CATPT_MODID_WAVES = 0x5, 170 CATPT_MODID_DOLBY = 0x6, 171 CATPT_MODID_BOOST = 0x7, 172 CATPT_MODID_LPAL = 0x8, 173 CATPT_MODID_DTS = 0x9, 174 CATPT_MODID_PCM_CAPTURE = 0xA, 175 CATPT_MODID_PCM_SYSTEM = 0xB, 176 CATPT_MODID_PCM_REFERENCE = 0xC, 177 CATPT_MODID_PCM = 0xD, /* offload */ 178 CATPT_MODID_BLUETOOTH_RENDER = 0xE, 179 CATPT_MODID_BLUETOOTH_CAPTURE = 0xF, 180 CATPT_MODID_LAST = CATPT_MODID_BLUETOOTH_CAPTURE, 181 }; 182 183 struct catpt_module_entry { 184 u32 module_id; 185 u32 entry_point; 186 } __packed; 187 188 struct catpt_module_map { 189 u8 num_entries; 190 struct catpt_module_entry entries[]; 191 } __packed; 192 193 struct catpt_memory_info { 194 u32 offset; 195 u32 size; 196 } __packed; 197 198 #define CATPT_CHANNELS_MAX 4 199 #define CATPT_ALL_CHANNELS_MASK UINT_MAX 200 201 struct catpt_stream_info { 202 u32 stream_hw_id; 203 u32 reserved; 204 u32 read_pos_regaddr; 205 u32 pres_pos_regaddr; 206 u32 peak_meter_regaddr[CATPT_CHANNELS_MAX]; 207 u32 volume_regaddr[CATPT_CHANNELS_MAX]; 208 } __packed; 209 210 int catpt_ipc_alloc_stream(struct catpt_dev *cdev, 211 enum catpt_path_id path_id, 212 enum catpt_stream_type type, 213 struct catpt_audio_format *afmt, 214 struct catpt_ring_info *rinfo, 215 u8 num_modules, 216 struct catpt_module_entry *modules, 217 struct resource *persistent, 218 struct resource *scratch, 219 struct catpt_stream_info *sinfo); 220 int catpt_ipc_free_stream(struct catpt_dev *cdev, u8 stream_hw_id); 221 222 enum catpt_ssp_iface { 223 CATPT_SSP_IFACE_0 = 0, 224 CATPT_SSP_IFACE_1 = 1, 225 CATPT_SSP_COUNT, 226 }; 227 228 enum catpt_mclk_frequency { 229 CATPT_MCLK_OFF = 0, 230 CATPT_MCLK_FREQ_6_MHZ = 1, 231 CATPT_MCLK_FREQ_21_MHZ = 2, 232 CATPT_MCLK_FREQ_24_MHZ = 3, 233 }; 234 235 enum catpt_ssp_mode { 236 CATPT_SSP_MODE_I2S_CONSUMER = 0, 237 CATPT_SSP_MODE_I2S_PROVIDER = 1, 238 CATPT_SSP_MODE_TDM_PROVIDER = 2, 239 }; 240 241 struct catpt_ssp_device_format { 242 u32 iface; 243 u32 mclk; 244 u32 mode; 245 u16 clock_divider; 246 u8 channels; 247 } __packed; 248 249 int catpt_ipc_set_device_format(struct catpt_dev *cdev, 250 struct catpt_ssp_device_format *devfmt); 251 252 enum catpt_dx_state { 253 CATPT_DX_STATE_D3 = 3, 254 }; 255 256 enum catpt_dx_type { 257 CATPT_DX_TYPE_FW_IMAGE = 0, 258 CATPT_DX_TYPE_MEMORY_DUMP = 1, 259 }; 260 261 struct catpt_save_meminfo { 262 u32 offset; 263 u32 size; 264 u32 source; 265 } __packed; 266 267 #define SAVE_MEMINFO_MAX 14 268 269 struct catpt_dx_context { 270 u32 num_meminfo; 271 struct catpt_save_meminfo meminfo[SAVE_MEMINFO_MAX]; 272 } __packed; 273 274 int catpt_ipc_enter_dxstate(struct catpt_dev *cdev, enum catpt_dx_state state, 275 struct catpt_dx_context *context); 276 277 struct catpt_mixer_stream_info { 278 u32 mixer_hw_id; 279 u32 peak_meter_regaddr[CATPT_CHANNELS_MAX]; 280 u32 volume_regaddr[CATPT_CHANNELS_MAX]; 281 } __packed; 282 283 int catpt_ipc_get_mixer_stream_info(struct catpt_dev *cdev, 284 struct catpt_mixer_stream_info *info); 285 286 /* STREAM messages */ 287 288 enum catpt_stream_msg_type { 289 CATPT_STRM_RESET_STREAM = 0, 290 CATPT_STRM_PAUSE_STREAM = 1, 291 CATPT_STRM_RESUME_STREAM = 2, 292 CATPT_STRM_STAGE_MESSAGE = 3, 293 CATPT_STRM_NOTIFICATION = 4, 294 }; 295 296 enum catpt_stage_action { 297 CATPT_STG_SET_VOLUME = 1, 298 CATPT_STG_SET_WRITE_POSITION = 2, 299 CATPT_STG_MUTE_LOOPBACK = 3, 300 }; 301 302 union catpt_stream_msg { 303 u32 val; 304 struct { 305 u32 status:5; 306 u32 reserved:7; 307 u32 stage_action:4; 308 u32 stream_hw_id:4; 309 u32 stream_msg_type:4; 310 u32 global_msg_type:5; 311 u32 fw_ready:1; 312 u32 done:1; 313 u32 busy:1; 314 }; 315 } __packed; 316 317 #define CATPT_STREAM_MSG(msg_type) \ 318 { \ 319 .stream_msg_type = CATPT_STRM_##msg_type, \ 320 .global_msg_type = CATPT_GLB_STREAM_MESSAGE } 321 #define CATPT_STAGE_MSG(msg_type) \ 322 { \ 323 .stage_action = CATPT_STG_##msg_type, \ 324 .stream_msg_type = CATPT_STRM_STAGE_MESSAGE, \ 325 .global_msg_type = CATPT_GLB_STREAM_MESSAGE } 326 327 int catpt_ipc_reset_stream(struct catpt_dev *cdev, u8 stream_hw_id); 328 int catpt_ipc_pause_stream(struct catpt_dev *cdev, u8 stream_hw_id); 329 int catpt_ipc_resume_stream(struct catpt_dev *cdev, u8 stream_hw_id); 330 331 /* STREAM messages - STAGE subtype */ 332 333 enum catpt_audio_curve_type { 334 CATPT_AUDIO_CURVE_NONE = 0, 335 CATPT_AUDIO_CURVE_WINDOWS_FADE = 1, 336 }; 337 338 int catpt_ipc_set_volume(struct catpt_dev *cdev, u8 stream_hw_id, 339 u32 channel, u32 volume, 340 u32 curve_duration, 341 enum catpt_audio_curve_type curve_type); 342 343 int catpt_ipc_set_write_pos(struct catpt_dev *cdev, u8 stream_hw_id, 344 u32 pos, bool eob, bool ll); 345 346 int catpt_ipc_mute_loopback(struct catpt_dev *cdev, u8 stream_hw_id, bool mute); 347 348 /* NOTIFICATION messages */ 349 350 enum catpt_notify_reason { 351 CATPT_NOTIFY_POSITION_CHANGED = 0, 352 CATPT_NOTIFY_GLITCH_OCCURRED = 1, 353 }; 354 355 union catpt_notify_msg { 356 u32 val; 357 struct { 358 u32 mailbox_address:29; 359 u32 fw_ready:1; 360 u32 done:1; 361 u32 busy:1; 362 }; 363 struct { 364 u32 status:5; 365 u32 reserved:7; 366 u32 notify_reason:4; 367 u32 stream_hw_id:4; 368 u32 stream_msg_type:4; 369 u32 global_msg_type:5; 370 u32 hdr:3; /* fw_ready, done, busy */ 371 }; 372 } __packed; 373 374 #define FW_INFO_SIZE_MAX 100 375 376 struct catpt_fw_ready { 377 u32 inbox_offset; 378 u32 outbox_offset; 379 u32 inbox_size; 380 u32 outbox_size; 381 u32 fw_info_size; 382 char fw_info[FW_INFO_SIZE_MAX]; 383 } __packed; 384 385 struct catpt_notify_position { 386 u32 stream_position; 387 u32 fw_cycle_count; 388 } __packed; 389 390 enum catpt_glitch_type { 391 CATPT_GLITCH_UNDERRUN = 1, 392 CATPT_GLITCH_DECODER_ERROR = 2, 393 CATPT_GLITCH_DOUBLED_WRITE_POS = 3, 394 }; 395 396 struct catpt_notify_glitch { 397 u32 type; 398 u64 presentation_pos; 399 u32 write_pos; 400 } __packed; 401 402 #endif 403