1 /*
2  * Copyright (C) 2018 Knowles Electronics
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _IAXXX_ODSP_HW_H_
18 #define _IAXXX_ODSP_HW_H_
19 
20 #if __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include <linux/mfd/adnc/iaxxx-odsp.h>
26 #include <linux/mfd/adnc/iaxxx-system-identifiers.h>
27 
28 #define NAME_MAX_SIZE 256
29 struct iaxxx_odsp_hw;
30 
31 struct iaxxx_config_file {
32     const char *filename;
33 };
34 
35 struct iaxxx_config_value {
36     uint64_t config_val;
37     uint32_t config_val_sz;
38 };
39 
40 union iaxxx_config_data {
41     struct iaxxx_config_file fdata;
42     struct iaxxx_config_value vdata;
43 };
44 
45 enum iaxxx_config_type {
46     CONFIG_FILE,
47     CONFIG_VALUE
48 };
49 
50 struct iaxxx_create_config_data {
51     enum iaxxx_config_type type;
52     union iaxxx_config_data data;
53 };
54 
55 struct iaxxx_plugin_status_data {
56     uint32_t block_id;
57     uint8_t  create_status;
58     uint8_t  enable_status;
59     uint16_t process_count;
60     uint16_t process_err_count;
61     uint32_t in_frames_consumed;
62     uint32_t out_frames_produced;
63     uint32_t private_memsize;
64     uint8_t  frame_notification_mode;
65     uint8_t  state_management_mode;
66 };
67 
68 struct iaxxx_plugin_endpoint_status_data {
69     uint8_t  status;
70     uint8_t  frame_status;
71     uint8_t  endpoint_status;
72     uint8_t  usage;
73     uint8_t  mandatory;
74     uint16_t counter;
75     uint8_t  op_encoding;
76     uint8_t  op_sample_rate;
77     uint16_t op_frame_length;
78 };
79 
80 struct iaxxx_get_event_info {
81   uint16_t event_id;
82   uint32_t data;
83 };
84 
85 enum clock_source {
86     SYSCLK,
87     INT_OSC,
88     EXT_OSC,
89 };
90 
91 /**
92  * Initialize the ODSP HAL
93  *
94  * Input  - NA
95  * Output - Handle to iaxxx_odsp_hw on success, NULL on failure
96  */
97 struct iaxxx_odsp_hw* iaxxx_odsp_init();
98 
99 /**
100  * De-Initialize the ODSP HAL
101  *
102  * Input  - odsp_hw_hdl - Handle to odsp hw structure
103  * Output - 0 on success, on failure < 0
104  */
105 int iaxxx_odsp_deinit(struct iaxxx_odsp_hw *odsp_hw_hdl);
106 
107 /**
108  * Load a package
109  *
110  * Input  - odsp_hw_hdl - Handle to odsp hw structure
111  *          pkg_name - Relative path to the Package binary (Should be placed in
112  *                     the firmware location)
113  *          pkg_id - Package ID
114  * Output - 0 on success, on failure < 0
115  */
116 int iaxxx_odsp_package_load(struct iaxxx_odsp_hw *odsp_hw_hdl,
117                             const char *pkg_name,
118                             const uint32_t pkg_id);
119 
120 /**
121  * Unload a package
122  *
123  * Input  - odsp_hw_hdl - Handle to odsp hw structure
124  *          pkg_id - Package ID
125  * Output - 0 on success, on failure < 0
126  */
127 int iaxxx_odsp_package_unload(struct iaxxx_odsp_hw *odsp_hw_hdl,
128 			                const uint32_t pkg_id);
129 
130 /**
131  * Get package version
132  *
133  * Input  - odsp_hw_hdl - Handle to odsp hw structure
134  *          inst_id - Instance ID
135  *          version - Package version string buffer
136  *          len - String buffer size
137  *
138  * Output - 0 on success, on failure < 0
139  */
140 int iaxxx_odsp_plugin_get_package_version(struct iaxxx_odsp_hw *odsp_hw_hdl,
141                             uint8_t inst_id, char *version, uint32_t len);
142 
143 /**
144  * Get plugin version
145  *
146  * Input  - odsp_hw_hdl - Handle to odsp hw structure
147  *          inst_id - Instance ID
148  *          version - Plugin version string buffer
149  *          len - String buffer size
150  *
151  * Output - 0 on success, on failure < 0
152  */
153 int iaxxx_odsp_plugin_get_plugin_version(struct iaxxx_odsp_hw *odsp_hw_hdl,
154                             uint8_t inst_id, char *version, uint32_t len);
155 
156 /**
157  * Create a plugin
158  *
159  * Input  - odsp_hw_hdl - Handle to odsp hw structure
160  *          inst_id - Instance ID
161  *          priority - Priority of the plugin
162  *          pkg_id - Package ID
163  *          plg_idx - Plugin Index*
164  *          block_id - Block ID
165  *          config_id - Config ID
166  *
167  * Output - 0 on success, on failure < 0
168  */
169 int iaxxx_odsp_plugin_create(struct iaxxx_odsp_hw *odsp_hw_hdl,
170                             const uint32_t inst_id,
171                             const uint32_t priority,
172                             const uint32_t pkg_id,
173                             const uint32_t plg_idx,
174                             const uint32_t block_id,
175                             const uint32_t config_id);
176 
177 /**
178  * Set the creation configuration on a plugin
179  *
180  * Input  - odsp_hw_hdl - Handle to odsp hw structure
181  *          inst_id - Instance ID
182  *          block_id - Block ID
183  *          cdata - Creation configuration data
184  * Output - 0 on success, on failure < 0
185  */
186 int iaxxx_odsp_plugin_set_creation_config(
187                                         struct iaxxx_odsp_hw *odsp_hw_hdl,
188                                         const uint32_t inst_id,
189                                         const uint32_t block_id,
190                                         struct iaxxx_create_config_data cdata);
191 
192 /**
193  * Destroy the plugin
194  *
195  * Input  - odsp_hw_hdl - Handle to odsp hw structure
196  *          inst_id - Instance ID
197  *          block_id - Block ID
198  *
199  * Output - 0 on success, on failure < 0
200  */
201 int iaxxx_odsp_plugin_destroy(struct iaxxx_odsp_hw *odsp_hw_hdl,
202                             const uint32_t inst_id,
203                             const uint32_t block_id);
204 
205 /**
206  * Enable the plugin
207  *
208  * Input  - odsp_hw_hdl - Handle to odsp hw structure
209  *          inst_id - Instance ID
210  *          block_id - Block ID
211  * Output - 0 on success, on failure < 0
212  */
213 int iaxxx_odsp_plugin_enable(struct iaxxx_odsp_hw *odsp_hw_hdl,
214                             const uint32_t inst_id,
215                             const uint32_t block_id);
216 
217 /**
218  * Disable the plugin
219  *
220  * Input  - odsp_hw_hdl - Handle to odsp hw structure
221  *          inst_id - Instance ID
222  *          block_id - Block ID
223  * Output - 0 on success, on failure < 0
224  */
225 int iaxxx_odsp_plugin_disable(struct iaxxx_odsp_hw *odsp_hw_hdl,
226                             const uint32_t inst_id,
227                             const uint32_t block_id);
228 
229 /**
230  * Reset the plugin
231  *
232  * Input  - odsp_hw_hdl - Handle to odsp hw structure
233  *          inst_id - Instance ID
234  *          block_id - Block ID
235  * Output - 0 on success, on failure < 0
236  */
237 int iaxxx_odsp_plugin_reset(struct iaxxx_odsp_hw *odsp_hw_hdl,
238                             const uint32_t inst_id,
239                             const uint32_t block_id);
240 
241 /**
242  * Set a parameter on a plugin
243  *
244  * Input  - odsp_hw_hdl - Handle to odsp hw structure
245  *          inst_id - Instance ID
246  *          param_id - Parameter ID
247  *          param_val - Parameter Value*
248  *          block_id  - Block ID
249  * Output - 0 on success, on failure < 0
250  */
251 int iaxxx_odsp_plugin_set_parameter(struct iaxxx_odsp_hw *odsp_hw_hdl,
252                                     const uint32_t inst_id,
253                                     const uint32_t param_id,
254                                     const uint32_t param_val,
255                                     const uint32_t block_id);
256 
257 /**
258  * Get the value of parameter on a plugin
259  *
260  * Input  - odsp_hw_hdl - Handle to odsp hw structure
261  *          inst_id - Instance ID
262  *          param_id - Parameter ID
263  *          block_id - Block ID*
264  *          param_val - Parameter Value
265  * Output - 0 on success, on failure < 0
266  */
267 int iaxxx_odsp_plugin_get_parameter(struct iaxxx_odsp_hw *odsp_hw_hdl,
268                                     const uint32_t inst_id,
269                                     const uint32_t param_id,
270                                     const uint32_t block_id,
271                                     uint32_t *param_val);
272 
273 /**
274  * Set a parameter block on a plugin
275  *
276  * Input  - odsp_hw_hdl - Handle to odsp hw structure
277  *          inst_id - Instance ID
278  *          param_blk_id - Parameter block id
279  *          block_id - Block ID
280  *          param_buf - Pointer to the parameter block
281  *          param_buf_sz - Parameter block size
282  * Output - 0 on success, on failure < 0
283  */
284 int iaxxx_odsp_plugin_set_parameter_blk(struct iaxxx_odsp_hw *odsp_hw_hdl,
285                                         const uint32_t inst_id,
286                                         const uint32_t param_blk_id,
287                                         const uint32_t block_id,
288                                         const void *param_buf,
289                                         const uint32_t param_buf_sz);
290 
291 /**
292  * Set a parameter block on a plugin
293  *
294  * Input  - odsp_hw_hdl - Handle to odsp hw structure
295  *          inst_id - Instance ID
296  *          param_blk_id - Parameter block id
297  *          block_id - Block ID
298  *          file_name - Relative path to the Parameter File(Should be placed in
299  *                     the firmware location)
300  * Output - 0 on success, on failure < 0
301  */
302 int iaxxx_odsp_plugin_set_parameter_blk_from_file(
303                                         struct iaxxx_odsp_hw *odsp_hw_hdl,
304                                         const uint32_t inst_id,
305                                         const uint32_t param_blk_id,
306                                         const uint32_t block_id,
307                                         const char *file_name);
308 
309 /**
310  * Set custom configuration for plugin
311  *
312  * Input  - odsp_hw_hdl 	    - Handle to odsp hw structure
313  *          inst_id  		    - Instance ID
314  *          block_id 		    - Block ID
315  *          param_blk_id  	    - Parameter block id
316  *          custom_config_id    - Id for what type of custom configuration
317  *          filename		    - Name of file with custom config data
318  *
319  * Output - 0 on success, on failure < 0
320  */
321 int iaxxx_odsp_plugin_set_custom_cfg(struct iaxxx_odsp_hw *odsp_hw_hdl,
322                                     const uint32_t inst_id,
323                                     const uint32_t block_id,
324                                     const uint32_t param_blk_id,
325                                     const uint32_t custom_config_id,
326                                     const char *filename);
327 
328 /**
329  * Subscribe to an event
330  *
331  * Input  - odsp_hw_hdl - Handle to odsp hw structure
332  *          src_id  	- System Id of event source
333  *          event_id 	- Event Id
334  *          dst_id	- System Id of event destination
335  *          dst_opaque	- Info sought by destination task when even occurs
336  *
337  * Output - 0 on success, on failure < 0
338  */
339 int iaxxx_odsp_evt_subscribe(struct iaxxx_odsp_hw *odsp_hw_hdl,
340                             const uint16_t src_id,
341                             const uint16_t event_id,
342                             const uint16_t dst_id,
343                             const uint32_t dst_opaque);
344 
345 /**
346  * Unsubscribe an event
347  *
348  * Input  - odsp_hw_hdl - Handle to odsp hw structure
349  *          src_id  	- System Id of event source
350  *          event_id 	- Event Id
351  *          dst_id	- System Id of event destination
352  *
353  * Output - 0 on success, on failure < 0
354  */
355 int iaxxx_odsp_evt_unsubscribe(struct iaxxx_odsp_hw *odsp_hw_hdl,
356                             const uint16_t src_id,
357                             const uint16_t event_id,
358                             const uint16_t dst_id);
359 
360 /**
361  * Trigger an event. This may be most useful when debugging the system,
362  * but can also be used to trigger simultaneous behavior in entities which
363  * have subscribed, or to simply provide notifications regarding host status:
364  *
365  * Input  - odsp_hw_hdl - Handle to odsp hw structure
366  *          src_id      - SystemId of event source
367  *          evt_id      - Id of event
368  *          src_opaque  - Source opaque to pass with event notification
369  *
370  * Output - 0 on success, on failure < 0
371  */
372 int iaxxx_odsp_evt_trigger(struct iaxxx_odsp_hw *odsp_hw_hdl,
373                         uint16_t src_id,
374                         uint16_t evt_id,
375                         uint32_t src_opaque);
376 
377 /**
378  * Fetches next event subscription entry from the last read position
379  *
380  * Input  - odsp_hw_hdl - Handle to odsp hw structure
381  *          src_id      - System Id of event source
382  *          evt_id      - Event Id
383  *          dst_id      - System Id of event destination
384  *          dst_opaque  - Destination opaque data
385  *
386  * Output - 0 on success, on failure < 0
387  */
388 int iaxxx_odsp_evt_read_subscription(struct iaxxx_odsp_hw *odsp_hw_hdl,
389                                     uint16_t *src_id,
390                                     uint16_t *evt_id,
391                                     uint16_t *dst_id,
392                                     uint32_t *dst_opaque);
393 
394 /**
395  * Reset index for retrieving subscription entries
396  *
397  * Input  - odsp_hw_hdl - Handle to odsp hw structure
398  *
399  * Output - 0 on success, on failure < 0
400  */
401 int iaxxx_odsp_evt_reset_read_index(struct iaxxx_odsp_hw *odsp_hw_hdl);
402 
403 /**
404  * Retrieve an event notification
405  *
406  * Input  - odsp_hw_hdl - Handle to odsp hw structure
407  *          src_id      - pointer to uint16_t for reporting SystemId of
408  *                        event source
409  *          evt_dd      - pointer to uint16_t for reporting Id of event
410  *          src_opaque  - pointer to the first parameter of event
411  *          dst_opaque  - pointer to the second parameter of event
412  *                        This will be destOpaque in case if event is
413  *                        subscribed with valid destOpaque otherwise
414  *                        it will be used as second parameter.
415  *
416  * Output - 0 on success, on failure < 0
417  */
418 int iaxxx_odsp_evt_retrieve_notification(struct iaxxx_odsp_hw *odsp_hw_hdl,
419                                         uint16_t *src_id,
420                                         uint16_t *evt_id,
421                                         uint32_t *src_opaque,
422                                         uint32_t *dst_opaque);
423 
424 /**
425  * Retrieve an event
426  *
427  * Input  - odsp_hw_hdl - Handle to odsp hw structure
428  *          event_info  - Struct to return event info
429  *
430  * Output - 0 on success, on failure < 0
431  */
432 int iaxxx_odsp_evt_getevent(struct iaxxx_odsp_hw *odsp_hw_hdl,
433                             struct iaxxx_get_event_info *event_info);
434 
435 /**
436  * Create a plugin for a statically loaded package
437  *
438  * Input  - odsp_hw_hdl - Handle to odsp hw structure
439  *          inst_id - Instance ID
440  *          priority - Priority of the plugin
441  *          pkg_id - Package ID
442  *          plg_idx - Plugin Index*
443  *          block_id - Block ID
444  *          config_id - Config ID
445  *
446  * Output - 0 on success, on failure < 0
447  */
448 int iaxxx_odsp_plugin_create_static_package(struct iaxxx_odsp_hw *odsp_hw_hdl,
449                                             const uint32_t inst_id,
450                                             const uint32_t priority,
451                                             const uint32_t pkg_id,
452                                             const uint32_t plg_idx,
453                                             const uint32_t block_id,
454                                             const uint32_t config_id);
455 
456 /**
457  * Get a parameter block from a plugin
458  *
459  * Input  - odsp_hw_hdl     - Handle to odsp hw structure
460  *          inst_id         - Instance ID
461  *          block_id        - Block ID
462  *          param_blk_id    - Parameter block id
463  *          param_buf       - Pointer to the parameter block
464  *          param_buf_sz    - Parameter block size in words
465  *
466  * Output - 0 on success, on failure < 0
467  */
468 int iaxxx_odsp_plugin_get_parameter_blk(struct iaxxx_odsp_hw *odsp_hw_hdl,
469                                         const uint32_t inst_id,
470                                         const uint32_t block_id,
471                                         const uint32_t param_blk_id,
472                                         uint32_t *param_buf,
473                                         const uint32_t param_buf_sz);
474 
475 /**
476  * Set Event for the plugin
477  *
478  * Input  - odsp_hw_hdl - Handle to odsp hw structure
479  *          inst_id - Instance ID
480  *          eventEnableMask - event Mask
481  *          block_id - Block ID
482  *
483  * Output - 0 on success, on failure < 0
484  */
485 int iaxxx_odsp_plugin_setevent(struct iaxxx_odsp_hw *odsp_hw_hdl,
486                             const uint32_t inst_id,
487                             const uint32_t eventEnableMask,
488                             const uint32_t block_id);
489 
490 /* Read Plugin Error Info
491  *
492  * Input  - odsp_hw_hdl     - Handle to odsp hw structure
493  *          error_code      - Pointer to uint32 to return error code
494  *          error_instance  - Pointer to uint8 to return plugin instance
495  *                            where error occurred.
496  *
497  * Output - 0 on success, on failure < 0
498  */
499 int iaxxx_odsp_plugin_read_error(struct iaxxx_odsp_hw *odsp_hw_hdl,
500                                 const uint32_t block_id,
501                                 uint32_t *error_code,
502                                 uint8_t *error_instance);
503 
504 /* Read the timestamps of all output endpoint
505  *
506  * Input  - odsp_hw_hdl     - Handle to odsp hw structure
507  *          proc_id         - Proc ID
508  *          timestamps      - The timestamps array(with 16 elements count)
509  *                            to be filled.
510  *
511  * Output - 0 on success, on failure < 0
512  */
513 int iaxxx_odsp_plugin_get_ep_timestamps(struct iaxxx_odsp_hw *odsp_hw_hdl,
514                                     uint64_t *timestamps, uint8_t proc_id);
515 
516 /**
517  * Set a parameter block on a plugin and get ack to
518  * ensure the data has been sent and retry if not.
519  *
520  * Input  - odsp_hw_hdl       - Handle to odsp hw structure
521  *          inst_id           - Instance ID
522  *          param_blk_id      - Parameter block id
523  *          block_id          - Block ID
524  *          set_param_buf     - Pointer to the parameter block
525  *          set_param_buf_sz  - Parameter block size in bytes
526  *          response_data_buf - Buffer for response data from plugin
527  *          response_data_sz  - Size of Buffer in uint32 words for
528  *                              response data from plugin
529  *          max_no_retries    - Max number of retries in case of busy
530  *                              response from plugin.
531  * Output - 0 on success, on failure < 0
532  */
533 int iaxxx_odsp_plugin_set_parameter_blk_with_ack(
534                                         struct iaxxx_odsp_hw *odsp_hw_hdl,
535                                         const uint32_t inst_id,
536                                         const uint32_t param_blk_id,
537                                         const uint32_t block_id,
538                                         const void *set_param_buf,
539                                         const uint32_t set_param_buf_sz,
540                                         uint32_t* response_data_buf,
541                                         const uint32_t response_data_sz,
542                                         const uint32_t max_no_retries);
543 
544 /**
545  * Get Plugin status information.
546  *
547  * Input  - odsp_hw_hdl         - Handle to odsp hw structure
548  *          inst_id             - Instance ID
549  *          plugin_status_data  - Pointer to struct to return plugin status.
550  *
551  * Output - 0 on success, on failure < 0
552  */
553 int iaxxx_odsp_plugin_get_status_info(
554                         struct iaxxx_odsp_hw *odsp_hw_hdl,
555                         const uint32_t inst_id,
556                         struct iaxxx_plugin_status_data *plugin_status_data);
557 
558 /**
559  * Get Plugin endpoint status information.
560  *
561  * Input  - odsp_hw_hdl            - Handle to odsp hw structure
562  *          inst_id                - Instance ID
563  *          ep_index               - Index of Endpoint
564  *          direction              - If Input endpoint or Output endpoint
565  *                                   0 => input, 1 => output
566  *          plugin_ep_status_data  - Pointer to struct to return plugin
567  *                                   endpoint status.
568  *
569  *
570  * Output - 0 on success, on failure < 0
571  */
572 int iaxxx_odsp_plugin_get_endpoint_status(
573             struct iaxxx_odsp_hw *odsp_hw_hdl,
574             const uint32_t inst_id,
575             const uint8_t ep_index,
576             const uint8_t direction,
577             struct iaxxx_plugin_endpoint_status_data *plugin_ep_status_data);
578 
579 /**
580  * Returns the execution status of given processor
581  *
582  * Input  - odsp_hw_hdl     - Handle to odsp hw structure
583  *          proc_id         - Proc id
584  *          status          - Execution status of the processor
585  *
586  * Output - 0 on success, on failure < 0
587  */
588 int iaxxx_odsp_get_proc_execution_status(struct iaxxx_odsp_hw *odsp_hw_hdl,
589                                     uint8_t proc_id, uint32_t *status);
590 
591 /**
592  * Returns Rom version number, Rom version string
593  *         Application version number, Application version string
594  *
595  * Input  - odsp_hw_hdl     - Handle to odsp hw structure
596  *          rom_ver_num     - Rom version number
597  *          rom_ver_str     - Rom version string
598  *          rom_ver_str_len - Rom version string length
599  *          app_ver_num     - App version number
600  *          app_ver_str     - App version string
601  *          app_ver_str_len - App version string length
602  *
603  * Output - 0 on success, on failure < 0
604  */
605 int iaxxx_odsp_get_sys_versions(struct iaxxx_odsp_hw *odsp_hw_hdl,
606                                 uint32_t *rom_ver_num,
607                                 char *rom_ver_str,
608                                 uint32_t rom_ver_str_len,
609                                 uint32_t *app_ver_num,
610                                 char *app_ver_str,
611                                 uint32_t app_ver_str_len);
612 
613 /**
614  * Returns Device ID
615  *
616  * Input  - odsp_hw_hdl     - Handle to odsp hw structure
617  *          device_id       - Returned Device ID
618  *
619  * Output - 0 on success, on failure < 0
620  */
621 int iaxxx_odsp_get_device_id(struct iaxxx_odsp_hw *odsp_hw_hdl,
622                             uint32_t *device_id);
623 
624 /**
625  * Returns Firmware status
626  *
627  * Input  - odsp_hw_hdl     - Handle to odsp hw structure
628  *          mode            - Returned firmware status
629  *              0: Firmware has crashed
630  *              1: Firmware is idle
631  *              2: Firmware is active
632  *
633  * Output - 0 on success, on failure < 0
634  */
635 int iaxxx_odsp_get_fw_status(struct iaxxx_odsp_hw *odsp_hw_hdl,
636                                        uint32_t *status);
637 
638 /**
639  * Resets the firmware by redownloading the firmware
640  *
641  * Input  - odsp_hw_hdl     - Handle to odsp hw structure
642  *
643  * Output - 0 on success, on failure < 0
644  */
645 int iaxxx_odsp_reset_fw(struct iaxxx_odsp_hw *odsp_hw_hdl);
646 
647 #if __cplusplus
648 } // extern "C"
649 #endif
650 
651 #endif // #ifndef _IAXXX_ODSP_HW_H_
652