blob: 6e5acfc92ca970e35f550798dc740e20ab9c2c87 [file] [log] [blame]
Vikram Pandurangad3b58cc2017-09-27 12:17:36 -07001/* Copyright (c) 2014, 2019, The Linux Foundation. All rights reserved.
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302 *
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 Bhattacharya8e2277f2017-07-20 18:31:55 +053017#include <linux/msm_audio_calibration.h>
Laxminath Kasam605b42f2017-08-01 22:02:15 +053018#include <dsp/msm_audio_ion.h>
19#include <dsp/audio_calibration.h>
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053020
21struct cal_data {
22 size_t size;
23 void *kvaddr;
24 phys_addr_t paddr;
25};
26
27struct 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
35struct 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 Pandurangad3b58cc2017-09-27 12:17:36 -070041 bool cal_stale;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053042 struct mem_map_data map_data;
43 int32_t buffer_number;
44};
45
46struct 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
55struct cal_type_info {
56 struct audio_cal_reg reg;
57 struct cal_util_callbacks cal_util_callbacks;
58};
59
60struct 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 */
68int cal_utils_create_cal_types(int num_cal_types,
69 struct cal_type_data **cal_type,
70 struct cal_type_info *info);
71void cal_utils_destroy_cal_types(int num_cal_types,
72 struct cal_type_data **cal_type);
73
74/* common functions for callbacks */
75int 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);
78int cal_utils_dealloc_cal(size_t data_size, void *data,
79 struct cal_type_data *cal_type);
80int 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 */
85void 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 */
90bool cal_utils_match_buf_num(struct cal_block_data *cal_block,
91 void *user_data);
92
93/* common matching functions to find cal blocks */
94struct cal_block_data *cal_utils_get_only_cal_block(
95 struct cal_type_data *cal_type);
96
97/* Size of calibration specific data */
98size_t get_cal_info_size(int32_t cal_type);
99size_t get_user_cal_type_size(int32_t cal_type);
100
101/* Version of the cal type*/
102int32_t cal_utils_get_cal_type_version(void *cal_type_data);
Vikram Pandurangad3b58cc2017-09-27 12:17:36 -0700103
104void cal_utils_mark_cal_used(struct cal_block_data *cal_block);
105
106bool cal_utils_is_cal_stale(struct cal_block_data *cal_block);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530107#endif