Vikram Panduranga | d3b58cc | 2017-09-27 12:17:36 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2014, 2019, The Linux Foundation. All rights reserved. |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 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 _AUDIO_CAL_UTILS_H |
| 14 | #define _AUDIO_CAL_UTILS_H |
| 15 | |
| 16 | #include <linux/msm_ion.h> |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 17 | #include <linux/msm_audio_calibration.h> |
Laxminath Kasam | 605b42f | 2017-08-01 22:02:15 +0530 | [diff] [blame] | 18 | #include <dsp/msm_audio_ion.h> |
| 19 | #include <dsp/audio_calibration.h> |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 20 | |
| 21 | struct cal_data { |
| 22 | size_t size; |
| 23 | void *kvaddr; |
| 24 | phys_addr_t paddr; |
| 25 | }; |
| 26 | |
| 27 | struct mem_map_data { |
| 28 | size_t map_size; |
| 29 | int32_t q6map_handle; |
| 30 | int32_t ion_map_handle; |
| 31 | struct ion_client *ion_client; |
| 32 | struct ion_handle *ion_handle; |
| 33 | }; |
| 34 | |
| 35 | struct cal_block_data { |
| 36 | size_t client_info_size; |
| 37 | void *client_info; |
| 38 | void *cal_info; |
| 39 | struct list_head list; |
| 40 | struct cal_data cal_data; |
Vikram Panduranga | d3b58cc | 2017-09-27 12:17:36 -0700 | [diff] [blame] | 41 | bool cal_stale; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 42 | struct mem_map_data map_data; |
| 43 | int32_t buffer_number; |
| 44 | }; |
| 45 | |
| 46 | struct cal_util_callbacks { |
| 47 | int (*map_cal) |
| 48 | (int32_t cal_type, struct cal_block_data *cal_block); |
| 49 | int (*unmap_cal) |
| 50 | (int32_t cal_type, struct cal_block_data *cal_block); |
| 51 | bool (*match_block) |
| 52 | (struct cal_block_data *cal_block, void *user_data); |
| 53 | }; |
| 54 | |
| 55 | struct cal_type_info { |
| 56 | struct audio_cal_reg reg; |
| 57 | struct cal_util_callbacks cal_util_callbacks; |
| 58 | }; |
| 59 | |
| 60 | struct cal_type_data { |
| 61 | struct cal_type_info info; |
| 62 | struct mutex lock; |
| 63 | struct list_head cal_blocks; |
| 64 | }; |
| 65 | |
| 66 | |
| 67 | /* to register & degregister with cal util driver */ |
| 68 | int cal_utils_create_cal_types(int num_cal_types, |
| 69 | struct cal_type_data **cal_type, |
| 70 | struct cal_type_info *info); |
| 71 | void cal_utils_destroy_cal_types(int num_cal_types, |
| 72 | struct cal_type_data **cal_type); |
| 73 | |
| 74 | /* common functions for callbacks */ |
| 75 | int cal_utils_alloc_cal(size_t data_size, void *data, |
| 76 | struct cal_type_data *cal_type, |
| 77 | size_t client_info_size, void *client_info); |
| 78 | int cal_utils_dealloc_cal(size_t data_size, void *data, |
| 79 | struct cal_type_data *cal_type); |
| 80 | int cal_utils_set_cal(size_t data_size, void *data, |
| 81 | struct cal_type_data *cal_type, |
| 82 | size_t client_info_size, void *client_info); |
| 83 | |
| 84 | /* use for SSR */ |
| 85 | void cal_utils_clear_cal_block_q6maps(int num_cal_types, |
| 86 | struct cal_type_data **cal_type); |
| 87 | |
| 88 | |
| 89 | /* common matching functions used to add blocks */ |
| 90 | bool cal_utils_match_buf_num(struct cal_block_data *cal_block, |
| 91 | void *user_data); |
| 92 | |
| 93 | /* common matching functions to find cal blocks */ |
| 94 | struct cal_block_data *cal_utils_get_only_cal_block( |
| 95 | struct cal_type_data *cal_type); |
| 96 | |
| 97 | /* Size of calibration specific data */ |
| 98 | size_t get_cal_info_size(int32_t cal_type); |
| 99 | size_t get_user_cal_type_size(int32_t cal_type); |
| 100 | |
| 101 | /* Version of the cal type*/ |
| 102 | int32_t cal_utils_get_cal_type_version(void *cal_type_data); |
Vikram Panduranga | d3b58cc | 2017-09-27 12:17:36 -0700 | [diff] [blame] | 103 | |
| 104 | void cal_utils_mark_cal_used(struct cal_block_data *cal_block); |
| 105 | |
| 106 | bool cal_utils_is_cal_stale(struct cal_block_data *cal_block); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 107 | #endif |