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