1 /*
2  * Copyright (c) 2022 Intel Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __DAI_PARAMS_INTEL_IPC4_H__
8 #define __DAI_PARAMS_INTEL_IPC4_H__
9 
10 #include <stdint.h>
11 
12 #define DAI_INTEL_I2S_TDM_MAX_SLOT_MAP_COUNT 8
13 
14 #define I2SIPCMC 8
15 #define I2SOPCMC 8
16 
17 /**< Type of the gateway. */
18 enum dai_intel_ipc4_connector_node_id_type {
19 	/**< HD/A host output (-> DSP). */
20 	dai_intel_ipc4_hda_host_output_class = 0,
21 	/**< HD/A host input (<- DSP). */
22 	dai_intel_ipc4_hda_host_input_class = 1,
23 	/**< HD/A host input/output (rsvd for future use). */
24 	dai_intel_ipc4_hda_host_inout_class = 2,
25 
26 	/**< HD/A link output (DSP ->). */
27 	dai_intel_ipc4_hda_link_output_class = 8,
28 	/**< HD/A link input (DSP <-). */
29 	dai_intel_ipc4_hda_link_input_class = 9,
30 	/**< HD/A link input/output (rsvd for future use). */
31 	dai_intel_ipc4_hda_link_inout_class = 10,
32 
33 	/**< DMIC link input (DSP <-). */
34 	dai_intel_ipc4_dmic_link_input_class = 11,
35 
36 	/**< I2S link output (DSP ->). */
37 	dai_intel_ipc4_i2s_link_output_class = 12,
38 	/**< I2S link input (DSP <-). */
39 	dai_intel_ipc4_i2s_link_input_class = 13,
40 
41 	/**< ALH link output, legacy for SNDW (DSP ->). */
42 	dai_intel_ipc4_alh_link_output_class = 16,
43 	/**< ALH link input, legacy for SNDW (DSP <-). */
44 	dai_intel_ipc4_alh_link_input_class = 17,
45 
46 	/**< SNDW link output (DSP ->). */
47 	dai_intel_ipc4_alh_snd_wire_stream_link_output_class = 16,
48 	/**< SNDW link input (DSP <-). */
49 	dai_intel_ipc4_alh_snd_wire_stream_link_input_class = 17,
50 
51 	/**< UAOL link output (DSP ->). */
52 	dai_intel_ipc4_alh_uaol_stream_link_output_class = 18,
53 	/**< UAOL link input (DSP <-). */
54 	dai_intel_ipc4_alh_uaol_stream_link_input_class = 19,
55 
56 	/**< IPC output (DSP ->). */
57 	dai_intel_ipc4_ipc_output_class = 20,
58 	/**< IPC input (DSP <-). */
59 	dai_intel_ipc4_ipc_input_class = 21,
60 
61 	/**< I2S Multi gtw output (DSP ->). */
62 	dai_intel_ipc4_i2s_multi_link_output_class = 22,
63 	/**< I2S Multi gtw input (DSP <-). */
64 	dai_intel_ipc4_i2s_multi_link_input_class = 23,
65 	/**< GPIO */
66 	dai_intel_ipc4_gpio_class = 24,
67 	/**< SPI */
68 	dai_intel_ipc4_spi_output_class = 25,
69 	dai_intel_ipc4_spi_input_class = 26,
70 	dai_intel_ipc4_max_connector_node_id_type
71 };
72 
73 struct ssp_intel_aux_tlv {
74 	uint32_t type;
75 	uint32_t size;
76 	uint32_t val[];
77 } __packed;
78 
79 struct ssp_intel_mn_ctl {
80 	uint32_t div_m;
81 	uint32_t div_n;
82 } __packed;
83 
84 struct ssp_intel_clk_ctl {
85 	uint32_t start;
86 	uint32_t stop;
87 } __packed;
88 
89 struct ssp_intel_tr_ctl {
90 	uint32_t sampling_frequency;
91 	uint32_t bit_depth;
92 	uint32_t channel_map;
93 	uint32_t channel_config;
94 	uint32_t interleaving_style;
95 	uint32_t format;
96 } __packed;
97 
98 struct ssp_intel_run_ctl {
99 	uint32_t enabled;
100 } __packed;
101 
102 struct ssp_intel_node_ctl {
103 	uint32_t node_id;
104 	uint32_t sampling_rate;
105 } __packed;
106 
107 struct ssp_intel_sync_ctl {
108 	uint32_t sync_denominator;
109 	uint32_t count;
110 } __packed;
111 
112 struct ssp_intel_ext_ctl {
113 	uint32_t ext_data;
114 } __packed;
115 
116 struct ssp_intel_link_ctl {
117 	uint32_t clock_source;
118 } __packed;
119 
120 #define SSP_MN_DIVIDER_CONTROLS                 0
121 #define SSP_DMA_CLK_CONTROLS                    1
122 #define SSP_DMA_TRANSMISSION_START              2
123 #define SSP_DMA_TRANSMISSION_STOP               3
124 #define SSP_DMA_ALWAYS_RUNNING_MODE             4
125 #define SSP_DMA_SYNC_DATA                       5
126 #define SSP_DMA_CLK_CONTROLS_EXT                6
127 #define SSP_LINK_CLK_SOURCE                     7
128 
129 /**< Base top-level structure of an address of a gateway. */
130 /*!
131  * The virtual index value, presented on the top level as raw 8 bits,
132  * is expected to be encoded in a gateway specific way depending on
133  * the actual type of gateway.
134  */
135 union dai_intel_ipc4_connector_node_id {
136 
137 	/**< Raw 32-bit value of node id. */
138 	uint32_t dw;
139 
140 	/**< Bit fields */
141 	struct {
142 		/**< Index of the virtual DMA at the gateway. */
143 		uint32_t v_index : 8;
144 
145 		/**< Type of the gateway, one of ConnectorNodeId::Type values. */
146 		uint32_t dma_type : 5;
147 
148 		/**< Rsvd field. */
149 		uint32_t _rsvd : 19;
150 	} f; /**<< Bits */
151 } __packed;
152 
153 /*!
154  * Attributes are usually provided along with the gateway configuration
155  * BLOB when the FW is requested to instantiate that gateway.
156  *
157  * There are flags which requests FW to allocate gateway related data
158  * (buffers and other items used while transferring data, like linked list)
159  *  to be allocated from a special memory area, e.g low power memory.
160  */
161 union dai_intel_ipc4_gateway_attributes {
162 
163 	/**< Raw value */
164 	uint32_t dw;
165 
166 	/**< Access to the fields */
167 	struct {
168 		/**< Gateway data requested in low power memory. */
169 		uint32_t lp_buffer_alloc : 1;
170 
171 		/**< Gateway data requested in register file memory. */
172 		uint32_t alloc_from_reg_file : 1;
173 
174 		/**< Reserved field */
175 		uint32_t _rsvd : 30;
176 	} bits; /**<< Bits */
177 } __packed;
178 
179 /**< Configuration for the IPC Gateway */
180 struct dai_intel_ipc4_gateway_config_blob {
181 
182 	/**< Size of the gateway buffer, specified in bytes */
183 	uint32_t buffer_size;
184 
185 	/**< Flags */
186 	union flags {
187 		struct bits {
188 			/**< Activates high threshold notification */
189 			/*!
190 			 * Indicates whether notification should be sent to the host
191 			 * when the size of data in the buffer reaches the high threshold
192 			 * specified by threshold_high parameter.
193 			 */
194 			uint32_t notif_high : 1;
195 
196 			/**< Activates low threshold notification */
197 			/*!
198 			 * Indicates whether notification should be sent to the host
199 			 * when the size of data in the buffer reaches the low threshold
200 			 * specified by threshold_low parameter.
201 			 */
202 			uint32_t notif_low : 1;
203 
204 			/**< Reserved field */
205 			uint32_t rsvd : 30;
206 		} f; /**<< Bits */
207 		/**< Raw value of flags */
208 		uint32_t flags_raw;
209 	} u; /**<< Flags */
210 
211 	/**< High threshold */
212 	/*!
213 	 * Specifies the high threshold (in bytes) for notifying the host
214 	 * about the buffered data level.
215 	 */
216 	uint32_t threshold_high;
217 
218 	/**< Low threshold */
219 	/*!
220 	 * Specifies the low threshold (in bytes) for notifying the host
221 	 * about the buffered data level.
222 	 */
223 	uint32_t threshold_low;
224 } __packed;
225 
226 /* i2s Configuration BLOB building blocks */
227 
228 /* i2s registers for i2s Configuration */
229 struct dai_intel_ipc4_ssp_config {
230 	uint32_t ssc0;
231 	uint32_t ssc1;
232 	uint32_t sscto;
233 	uint32_t sspsp;
234 #ifndef CONFIG_SOC_INTEL_ACE30_PTL
235 	uint32_t sstsa;
236 	uint32_t ssrsa;
237 #endif
238 	uint32_t ssc2;
239 	uint32_t sspsp2;
240 	uint32_t ssc3;
241 	uint32_t ssioc;
242 #ifdef CONFIG_SOC_INTEL_ACE30_PTL
243 	uint64_t ssmidytsa[I2SIPCMC];
244 	uint64_t ssmodytsa[I2SOPCMC];
245 #endif
246 } __packed;
247 
248 struct dai_intel_ipc4_ssp_mclk_config {
249 	/* master clock divider control register */
250 	uint32_t mdivc;
251 
252 	/* master clock divider ratio register */
253 	uint32_t mdivr;
254 } __packed;
255 
256 struct dai_intel_ipc4_ssp_mclk_config_2 {
257 	uint32_t mdivctlr;
258 	uint32_t mdivrcnt;
259 	uint32_t mdivr[];
260 } __packed;
261 
262 struct dai_intel_ipc4_ssp_driver_config {
263 	struct dai_intel_ipc4_ssp_config i2s_config;
264 	struct dai_intel_ipc4_ssp_mclk_config mclk_config;
265 } __packed;
266 
267 struct dai_intel_ipc4_ssp_start_control {
268 	/* delay in msec between enabling interface (moment when
269 	 * Copier instance is being attached to the interface) and actual
270 	 * interface start. Value of 0 means no delay.
271 	 */
272 	uint32_t clock_warm_up    : 16;
273 
274 	/* specifies if parameters target MCLK (1) or SCLK (0) */
275 	uint32_t mclk             : 1;
276 
277 	/* value of 1 means that clock should be started immediately
278 	 * even if no Copier instance is currently attached to the interface.
279 	 */
280 	uint32_t warm_up_ovr      : 1;
281 	uint32_t rsvd0            : 14;
282 } __packed;
283 
284 struct dai_intel_ipc4_ssp_stop_control {
285 	/* delay in msec between stopping the interface
286 	 * (moment when Copier instance is being detached from the interface)
287 	 * and interface clock stop. Value of 0 means no delay.
288 	 */
289 	uint32_t clock_stop_delay : 16;
290 
291 	/* value of 1 means that clock should be kept running (infinite
292 	 * stop delay) after Copier instance detaches from the interface.
293 	 */
294 	uint32_t keep_running     : 1;
295 
296 	/* value of 1 means that clock should be stopped immediately */
297 	uint32_t clock_stop_ovr   : 1;
298 	uint32_t rsvd1            : 14;
299 } __packed;
300 
301 union dai_intel_ipc4_ssp_dma_control {
302 	struct dai_intel_ipc4_ssp_control {
303 		struct dai_intel_ipc4_ssp_start_control start_control;
304 		struct dai_intel_ipc4_ssp_stop_control stop_control;
305 	} control_data;
306 
307 	struct dai_intel_ipc4_mn_div_config {
308 		uint32_t mval;
309 		uint32_t nval;
310 	} mndiv_control_data;
311 } __packed;
312 
313 struct dai_intel_ipc4_ssp_configuration_blob {
314 	union dai_intel_ipc4_gateway_attributes gw_attr;
315 
316 	/* TDM time slot mappings */
317 	uint32_t tdm_ts_group[DAI_INTEL_I2S_TDM_MAX_SLOT_MAP_COUNT];
318 
319 	/* i2s port configuration */
320 	struct dai_intel_ipc4_ssp_driver_config i2s_driver_config;
321 
322 	/* optional configuration parameters */
323 	union dai_intel_ipc4_ssp_dma_control i2s_dma_control[0];
324 } __packed;
325 
326 #define SSP_BLOB_VER_1_5 0xee000105
327 
328 struct dai_intel_ipc4_ssp_configuration_blob_ver_1_5 {
329 	union dai_intel_ipc4_gateway_attributes gw_attr;
330 
331 	uint32_t version;
332 	uint32_t size;
333 
334 	/* TDM time slot mappings */
335 	uint32_t tdm_ts_group[DAI_INTEL_I2S_TDM_MAX_SLOT_MAP_COUNT];
336 
337 	/* i2s port configuration */
338 	struct dai_intel_ipc4_ssp_config i2s_ssp_config;
339 	/* clock configuration parameters */
340 	struct dai_intel_ipc4_ssp_mclk_config_2 i2s_mclk_control;
341 } __packed;
342 
343 #endif
344