a5xelte: overlay: Disable config_cleanupUnusedFingerprints
[GitHub/LineageOS/android_device_samsung_a7xelte.git] / amplifier / tfa.h
1 /*
2 * Copyright (C) 2017 Christopher N. Hesse <raymanfx@gmail.com>
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 TFA_H
18 #define TFA_H
19
20 #include <pthread.h>
21 #include <stdatomic.h>
22 #include <stdbool.h>
23
24 #define TFA_LIBRARY_PATH "/system/lib/libtfa98xx.so"
25
26
27 /*
28 * Amplifier audio modes for different usecases.
29 */
30 typedef enum {
31 Audio_Mode_None = -1,
32 Audio_Mode_Music_Normal,
33 Audio_Mode_Voice,
34 Audio_Mode_Max
35 } tfa_mode_t;
36
37 /*
38 * It doesn't really matter what this is, apparently we just need a continuous
39 * chunk of memory...
40 */
41 typedef struct {
42 volatile int a1;
43 volatile unsigned char a2[500];
44 } __attribute__((packed)) tfa_handle_t;
45
46 /*
47 * Vendor functions that we dlsym.
48 */
49 typedef int (*tfa_device_open_t)(tfa_handle_t*, int);
50 typedef int (*tfa_enable_t)(tfa_handle_t*, int);
51
52 /*
53 * TFA Amplifier device abstraction.
54 *
55 * lib_handle: The prebuilt vendor blob, loaded into memory
56 * tfa_handle: Misc data we need to pass to the vendor function calls
57 * tfa_lock: A mutex guarding amplifier enable/disable operations
58 * tfa_device_open: Vendor function for initializing the amplifier
59 * tfa_enable: Vendor function for enabling/disabling the amplifier
60 * mode: Audio mode for the current audio device
61 */
62 typedef struct {
63 void *lib_handle;
64 tfa_handle_t* tfa_handle;
65 pthread_mutex_t tfa_lock;
66 tfa_device_open_t tfa_device_open;
67 tfa_enable_t tfa_enable;
68 tfa_mode_t mode;
69
70 // for clock init
71 atomic_bool initializing;
72 bool clock_enabled;
73 bool writing;
74 pthread_t write_thread;
75 pthread_mutex_t mutex;
76 pthread_cond_t cond;
77 } tfa_device_t;
78
79 /*
80 * Public API
81 */
82 int tfa_power(tfa_device_t *tfa_dev, bool on);
83 tfa_device_t * tfa_device_open();
84 void tfa_device_close(tfa_device_t *tfa_dev);
85
86 #endif // TFA_H