b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * All Rights Reserved |
| 3 | * |
| 4 | * MARVELL CONFIDENTIAL |
| 5 | * Copyright 2012 Marvell International Ltd All Rights Reserved. |
| 6 | * The source code contained or described herein and all documents related to |
| 7 | * the source code ("Material") are owned by Marvell International Ltd or its |
| 8 | * suppliers or licensors. Title to the Material remains with Marvell International Ltd |
| 9 | * or its suppliers and licensors. The Material contains trade secrets and |
| 10 | * proprietary and confidential information of Marvell or its suppliers and |
| 11 | * licensors. The Material is protected by worldwide copyright and trade secret |
| 12 | * laws and treaty provisions. No part of the Material may be used, copied, |
| 13 | * reproduced, modified, published, uploaded, posted, transmitted, distributed, |
| 14 | * or disclosed in any way without Marvell's prior express written permission. |
| 15 | * |
| 16 | * No license under any patent, copyright, trade secret or other intellectual |
| 17 | * property right is granted to or conferred upon you by disclosure or delivery |
| 18 | * of the Materials, either expressly, by implication, inducement, estoppel or |
| 19 | * otherwise. Any license under such intellectual property rights must be |
| 20 | * express and approved by Marvell in writing. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #ifndef __H_ACM_APH__ |
| 25 | #define __H_ACM_APH__ |
| 26 | |
| 27 | #include "acm_debug.h" |
| 28 | #include "acm_ach.h" |
| 29 | #include "acm_api.h" |
| 30 | #include "audio_protocol.h" |
| 31 | #include "audio_profile.h" |
| 32 | |
| 33 | #define MAX_STRING_LEN 60 |
| 34 | #define MAX_VOLUME_INDEX 100 |
| 35 | #define INVALID_CTL_UNIT_ID 0 |
| 36 | #define INVALID_PATH_ID 0xFF |
| 37 | #define INVALID_ORDER_INDEX 0xFF |
| 38 | |
| 39 | #define XML_NAME_LEN 128 |
| 40 | #define DIGITAL_GAIN_OFFSET 37 |
| 41 | #define GENERATE_XML_NAME(BUF, SIZE, PREFIX, APPENDIX) \ |
| 42 | do{\ |
| 43 | (BUF) = (char *)malloc((SIZE)); \ |
| 44 | if ((BUF)) {\ |
| 45 | memset((BUF), 0, (SIZE)); \ |
| 46 | snprintf((BUF), (SIZE), "%s%s.xml", (PREFIX), (APPENDIX));\ |
| 47 | } \ |
| 48 | }while(0) |
| 49 | |
| 50 | #define PATHSTATUS_MAX 2048 |
| 51 | //-------------------------------------------------------------- |
| 52 | //-------- Basic Elements Definition |
| 53 | //-------------------------------------------------------------- |
| 54 | typedef enum { |
| 55 | APH_PATH_ID_HIFIPLAYTOEARPHONE = 0, |
| 56 | APH_PATH_ID_HIFIPLAYTOSPKR, |
| 57 | APH_PATH_ID_HIFIPLAYTOHP, |
| 58 | APH_PATH_ID_HIFIRECORDFROMMIC1, |
| 59 | APH_PATH_ID_HIFIRECORDFROMHSMIC, |
| 60 | APH_PATH_ID_VOICEPLAYTOEARPHONE, |
| 61 | APH_PATH_ID_VOICEPLAYTOSPKR, |
| 62 | APH_PATH_ID_VOICEPLAYTOHP, |
| 63 | APH_PATH_ID_VOICERECORDFROMMIC1, |
| 64 | APH_PATH_ID_VOICERECORDFROMHSMIC, |
| 65 | |
| 66 | APH_PATH_ID_CNT |
| 67 | } APH_PATH_ID; |
| 68 | |
| 69 | #define APH_PATH_OUT_CNT 6 |
| 70 | #define APH_PATH_IN_CNT 4 |
| 71 | |
| 72 | typedef enum { |
| 73 | APH_GAIN_ID_NB = 0, |
| 74 | APH_GAIN_ID_WB, |
| 75 | APH_GAIN_ID_NB_EXTRA, |
| 76 | APH_GAIN_ID_WB_EXTRA, |
| 77 | |
| 78 | APH_GAIN_ID_CNT |
| 79 | } APH_GAIN_ID; |
| 80 | |
| 81 | typedef enum { |
| 82 | ELBA, |
| 83 | USTICA, |
| 84 | DELAY, |
| 85 | NAU8810, |
| 86 | ALC5616, |
| 87 | |
| 88 | AUDIO_COMPONENT_CNT |
| 89 | } APH_AudioComponent; |
| 90 | |
| 91 | |
| 92 | typedef enum { |
| 93 | ENABLE, |
| 94 | DISABLE, |
| 95 | MUTE, |
| 96 | SETVOLUME, |
| 97 | SWITCH, |
| 98 | |
| 99 | PATH_OPERATION_CNT |
| 100 | } APH_PathOperation; |
| 101 | |
| 102 | /* Force type is added for GELATO, as some registers are used as trigger/update signal, will repeatedly write a same value. For bit value with Force field type, just write to codec ignore ref_count/bind-writing/cache check features */ |
| 103 | typedef enum { |
| 104 | REG_FIELD_TYPE_INVALID = 0, |
| 105 | REG_FIELD_TYPE_NORMAL = 1, |
| 106 | REG_FIELD_TYPE_GAIN = 2, |
| 107 | REG_FIELD_TYPE_COEFF = 4, |
| 108 | REG_FIELD_TYPE_FORCE = 8 |
| 109 | } APH_RegisterFieldType; |
| 110 | |
| 111 | typedef enum { |
| 112 | REG_MISC_NONE, |
| 113 | REG_MISC_MIC1, |
| 114 | REG_MISC_MIC2, |
| 115 | REG_MISC_DUAL_MIC, |
| 116 | REG_MISC_SLAVE, |
| 117 | REG_MISC_MASTER, |
| 118 | REG_MISC_NB_RATE, |
| 119 | REG_MISC_WB_RATE, |
| 120 | REG_MISC_VOIP_RATE, |
| 121 | REG_MISC_DEFAULT_RATE, |
| 122 | REG_MISC_FORCE_DELAY |
| 123 | } APH_RegisterMisc; |
| 124 | |
| 125 | typedef enum { |
| 126 | PATH_DIRECTION_IN, |
| 127 | PATH_DIRECTION_OUT, |
| 128 | } APH_PathDirection; |
| 129 | |
| 130 | typedef enum { |
| 131 | HIFI_PATH, |
| 132 | FM_PATH, |
| 133 | VOICE_PATH, |
| 134 | UNKNOW_PATH, |
| 135 | }APH_PathType; |
| 136 | |
| 137 | |
| 138 | //-------------------------------------------------------------- |
| 139 | //-------- ACM_APH Related Data Structures |
| 140 | //-------------------------------------------------------------- |
| 141 | typedef struct { |
| 142 | APH_AudioComponent Component; |
| 143 | unsigned char Address; |
| 144 | unsigned short Value; |
| 145 | } ACMAPH_Register; |
| 146 | |
| 147 | typedef struct { |
| 148 | APH_PATH_ID PathID; |
| 149 | ACMAPH_Register *RegisterList; |
| 150 | unsigned char RegisterNum; |
| 151 | } ACMAPH_Component; |
| 152 | |
| 153 | typedef struct { |
| 154 | int PathID; |
| 155 | char PathName[32]; |
| 156 | } ACMAPH_AudioPathID; |
| 157 | |
| 158 | typedef struct { |
| 159 | unsigned char Volume; |
| 160 | APH_AudioComponent Component; |
| 161 | unsigned char Address; |
| 162 | unsigned short Value; |
| 163 | } ACMAPH_VolumeRegister; |
| 164 | |
| 165 | typedef struct { |
| 166 | APH_PATH_ID PathID; |
| 167 | ACMAPH_VolumeRegister *RegisterList; |
| 168 | unsigned char RegisterNum; |
| 169 | } ACMAPH_VolumeComponent; |
| 170 | |
| 171 | |
| 172 | typedef struct { |
| 173 | APH_GAIN_ID id; |
| 174 | unsigned char volume; |
| 175 | signed char gain; |
| 176 | } ACMAPH_MSAGain; |
| 177 | |
| 178 | typedef struct { |
| 179 | APH_PATH_ID PathID; |
| 180 | ACMAPH_MSAGain *GainList; |
| 181 | unsigned char GainNum; |
| 182 | } ACMAPH_MSAComponent; |
| 183 | |
| 184 | |
| 185 | //-------------------------------------------------------------- |
| 186 | //-------- Path Configuration Related Data Structures |
| 187 | //-------------------------------------------------------------- |
| 188 | typedef struct tag_APH_ControlUnitConfiguration { |
| 189 | union { |
| 190 | struct { |
| 191 | unsigned char reg_index; |
| 192 | unsigned char reg_mask; |
| 193 | unsigned char reg_shift; |
| 194 | unsigned char reg_type; |
| 195 | unsigned char reg_misc; |
| 196 | unsigned short length; |
| 197 | unsigned char *reg_value; |
| 198 | } i2c; |
| 199 | struct { |
| 200 | unsigned char gpio_port; |
| 201 | unsigned char gpio_value; |
| 202 | } gpio; |
| 203 | struct { |
| 204 | unsigned char hci_ocf; |
| 205 | unsigned char hci_ogf; |
| 206 | unsigned short length; |
| 207 | unsigned char *hci_parameters; |
| 208 | } hci; |
| 209 | struct { |
| 210 | unsigned int delay_value; |
| 211 | unsigned char delay_misc; |
| 212 | } delay; |
| 213 | } ctl_unit; |
| 214 | unsigned short control_unit_id; |
| 215 | struct tag_APH_ControlUnitConfiguration *next; |
| 216 | } APH_ControlUnitConfiguration; |
| 217 | |
| 218 | |
| 219 | //-------------------------------------------------------------- |
| 220 | //-------- APH Related Data Structures |
| 221 | //-------------------------------------------------------------- |
| 222 | typedef struct { |
| 223 | APH_AudioComponent component_id; |
| 224 | ACH_ComponentHandler *component_handler; |
| 225 | } APH_ACHComponent; |
| 226 | |
| 227 | typedef struct { |
| 228 | unsigned short enabled; |
| 229 | unsigned int value; |
| 230 | unsigned char mute; |
| 231 | } APH_PathStatus; |
| 232 | |
| 233 | typedef enum |
| 234 | { |
| 235 | AUDIOHAL_SPK_MUTE = 0, |
| 236 | AUDIOHAL_SPK_VOL_1, |
| 237 | AUDIOHAL_SPK_VOL_2, |
| 238 | AUDIOHAL_SPK_VOL_3, |
| 239 | AUDIOHAL_SPK_VOL_4, |
| 240 | AUDIOHAL_SPK_VOL_5, |
| 241 | AUDIOHAL_SPK_VOL_6, |
| 242 | AUDIOHAL_SPK_VOL_7, |
| 243 | AUDIOHAL_SPK_VOL_8, |
| 244 | AUDIOHAL_SPK_VOL_9, |
| 245 | AUDIOHAL_SPK_VOL_10, |
| 246 | AUDIOHAL_SPK_VOL_QTY //11 |
| 247 | } AUDIOHAL_SPK_LEVEL_T; |
| 248 | |
| 249 | typedef enum { |
| 250 | APH_CODEC_ID_NONE=0, |
| 251 | APH_CODEC_ID_PM805, |
| 252 | APH_CODEC_ID_PM812, |
| 253 | APH_CODEC_ID_NAU8810, |
| 254 | APH_CODEC_ID_ALC5616, |
| 255 | |
| 256 | APH_CODEC_CNT |
| 257 | } APH_CODEC_ID; |
| 258 | |
| 259 | typedef struct |
| 260 | { |
| 261 | APH_AudioComponent Component_1; |
| 262 | unsigned short RegAddr_1; |
| 263 | unsigned short RegVal_1; |
| 264 | |
| 265 | APH_AudioComponent Component_2; |
| 266 | unsigned short RegAddr_2; |
| 267 | unsigned short RegVal_2; |
| 268 | |
| 269 | APH_AudioComponent Component_3; |
| 270 | unsigned short RegAddr_3; |
| 271 | unsigned short RegVal_3; |
| 272 | |
| 273 | APH_AudioComponent Component_4; |
| 274 | unsigned short RegAddr_4; |
| 275 | unsigned short RegVal_4; |
| 276 | } ACMCodec_GainInT; |
| 277 | |
| 278 | typedef struct |
| 279 | { |
| 280 | APH_AudioComponent Component_1; |
| 281 | unsigned short RegAddr_1; |
| 282 | unsigned short RegVal_1; |
| 283 | |
| 284 | APH_AudioComponent Component_2; |
| 285 | unsigned short RegAddr_2; |
| 286 | unsigned short RegVal_2; |
| 287 | |
| 288 | APH_AudioComponent Component_3; |
| 289 | unsigned short RegAddr_3; |
| 290 | unsigned short RegVal_3; |
| 291 | |
| 292 | APH_AudioComponent Component_4; |
| 293 | unsigned short RegAddr_4; |
| 294 | unsigned short RegVal_4; |
| 295 | } ACMCodec_GainOutT; |
| 296 | |
| 297 | typedef struct |
| 298 | { |
| 299 | AUDIO_PROFILE_ID Profile_id; |
| 300 | unsigned short CodecControl; |
| 301 | ACMCodec_GainInT Tx_CodecGain; //TX has the same gain for every volume |
| 302 | short Tx_DSPGain; //TX has the same gain for every volume, High 8bits: WB gain, Low 8bits: NB gain |
| 303 | ACMCodec_GainOutT Rx_CodecGain[AUDIOHAL_SPK_VOL_QTY]; |
| 304 | short Rx_DSPGain[AUDIOHAL_SPK_VOL_QTY]; //High 8bits: WB gain, Low 8bits: NB gain |
| 305 | short Rx_DSPSideToneGain; //High 8bits: WB gain, Low 8bits: NB gain |
| 306 | } ACMCodec_GainT; |
| 307 | |
| 308 | //-------------------------------------------------------------- |
| 309 | //-------- External APH APIs |
| 310 | //-------------------------------------------------------------- |
| 311 | const ACMAPH_AudioPathID *ACM_GetPathConfigTable(); |
| 312 | |
| 313 | void ACM_Init_Property(void); |
| 314 | void ACM_APHInit(void); |
| 315 | void ACM_APHDeInit(void); |
| 316 | char * ACM_GetPathName(int PathID); |
| 317 | ACM_ReturnCode APHAudioPathEnable(const char *path, unsigned int value); |
| 318 | ACM_ReturnCode APHAudioPathDisable(const char *path); |
| 319 | ACM_ReturnCode APHAudioPathCheck (const char * path_Rx, const char * path_Tx) ; |
| 320 | void APHDisableAllPath(void); |
| 321 | ACM_ReturnCode APHAudioPathSwitch (const char *path_Rx, const char *path_Tx, unsigned int value); |
| 322 | ACM_ReturnCode APHAudioPathMute(const char *path, unsigned int value); |
| 323 | ACM_ReturnCode APHAudioPathVolumeSet(const char *path, unsigned int value); |
| 324 | ACM_ReturnCode ACM_ReloadCalibrationData(void); |
| 325 | ACM_ReturnCode APHReloadNvm(void); |
| 326 | ACM_ReturnCode APHAudioPathCheckPathId (int path_id_Rx, int path_id_Tx); |
| 327 | ACM_ReturnCode ACM_GetEnabledPathId(int *path_id_Rx, int *path_id_Tx, int *volume_Rx, int *mute_Tx); |
| 328 | ACM_ReturnCode APHGetMSAGain(const char *out_path, const char *path, unsigned char *volume, unsigned short id, signed short *gain, signed short *sidetone_gain); |
| 329 | unsigned int ACM_GetEnabledPathVolume(void); |
| 330 | ACM_ReturnCode ACM_GetPathStatus(char *buff, unsigned int maxsize); |
| 331 | ACM_ReturnCode ACM_GetPathDirection(const char *path, unsigned char *path_direction); |
| 332 | |
| 333 | #endif |