1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef AUDIO_CODEC_BASE_H 10 #define AUDIO_CODEC_BASE_H 11 12 #include "audio_codec_if.h" 13 #include "audio_core.h" 14 #include "osal_io.h" 15 16 #ifdef __cplusplus 17 #if __cplusplus 18 extern "C" { 19 #endif 20 #endif /* __cplusplus */ 21 22 enum I2sFrequency { 23 I2S_SAMPLE_FREQUENCY_8000 = 8000, /* 8kHz sample_rate */ 24 I2S_SAMPLE_FREQUENCY_11025 = 11025, /* 11.025kHz sample_rate */ 25 I2S_SAMPLE_FREQUENCY_12000 = 12000, /* 12kHz sample_rate */ 26 I2S_SAMPLE_FREQUENCY_16000 = 16000, /* 16kHz sample_rate */ 27 I2S_SAMPLE_FREQUENCY_22050 = 22050, /* 22.050kHz sample_rate */ 28 I2S_SAMPLE_FREQUENCY_24000 = 24000, /* 24kHz sample_rate */ 29 I2S_SAMPLE_FREQUENCY_32000 = 32000, /* 32kHz sample_rate */ 30 I2S_SAMPLE_FREQUENCY_44100 = 44100, /* 44.1kHz sample_rate */ 31 I2S_SAMPLE_FREQUENCY_48000 = 48000, /* 48kHz sample_rate */ 32 I2S_SAMPLE_FREQUENCY_64000 = 64000, /* 64kHz sample_rate */ 33 I2S_SAMPLE_FREQUENCY_88200 = 88200, /* 88.2kHz sample_rate */ 34 I2S_SAMPLE_FREQUENCY_96000 = 96000 /* 96kHz sample_rate */ 35 }; 36 37 enum I2sFrequencyRegVal { 38 I2S_SAMPLE_FREQUENCY_REG_VAL_8000 = 0x0, /* 8kHz sample_rate */ 39 I2S_SAMPLE_FREQUENCY_REG_VAL_11025 = 0x1, /* 11.025kHz sample_rate */ 40 I2S_SAMPLE_FREQUENCY_REG_VAL_12000 = 0x2, /* 12kHz sample_rate */ 41 I2S_SAMPLE_FREQUENCY_REG_VAL_16000 = 0x3, /* 16kHz sample_rate */ 42 I2S_SAMPLE_FREQUENCY_REG_VAL_22050 = 0x4, /* 22.050kHz sample_rate */ 43 I2S_SAMPLE_FREQUENCY_REG_VAL_24000 = 0x5, /* 24kHz sample_rate */ 44 I2S_SAMPLE_FREQUENCY_REG_VAL_32000 = 0x6, /* 32kHz sample_rate */ 45 I2S_SAMPLE_FREQUENCY_REG_VAL_44100 = 0x7, /* 44.1kHz sample_rate */ 46 I2S_SAMPLE_FREQUENCY_REG_VAL_48000 = 0x8, /* 48kHz sample_rate */ 47 I2S_SAMPLE_FREQUENCY_REG_VAL_64000 = 0x9, /* 64kHz sample_rate */ 48 I2S_SAMPLE_FREQUENCY_REG_VAL_88200 = 0xA, /* 88.2kHz sample_rate */ 49 I2S_SAMPLE_FREQUENCY_REG_VAL_96000 = 0xB /* 96kHz sample_rate */ 50 }; 51 52 struct I2cTransferParam { 53 uint16_t i2cDevAddr; 54 uint16_t i2cBusNumber; 55 uint16_t i2cRegDataLen; // default 16 bit 56 }; 57 58 struct DaiParamsVal { 59 uint32_t frequencyVal; 60 uint32_t formatVal; 61 uint32_t channelVal; 62 }; 63 64 int32_t CodecGetServiceName(const struct HdfDeviceObject *device, const char **drvCodecName); 65 int32_t CodecGetDaiName(const struct HdfDeviceObject *device, const char **drvDaiName); 66 int32_t CodecGetConfigInfo(const struct HdfDeviceObject *device, struct CodecData *codecData); 67 int32_t CodecDaiGetPortConfigInfo(const struct HdfDeviceObject *device, struct DaiData *codecData); 68 int32_t CodecSetConfigInfoOfControls(struct CodecData *codeData, struct DaiData *daiData); 69 int32_t CodecSetCtlFunc(struct CodecData *codeData, enum AudioControlType controlType, const void *getCtrl, 70 const void *setCtrl); 71 int32_t CodecDeviceReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *value); 72 int32_t CodecDeviceWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t value); 73 int32_t CodecDaiRegI2cRead(const struct DaiDevice *dai, uint32_t reg, uint32_t *value); 74 int32_t CodecDaiRegI2cWrite(const struct DaiDevice *dai, uint32_t reg, uint32_t value); 75 int32_t CodecDeviceRegI2cRead(const struct CodecDevice *codec, uint32_t reg, uint32_t *value); 76 int32_t CodecDeviceRegI2cWrite(const struct CodecDevice *codec, uint32_t reg, uint32_t value); 77 int32_t CodecDeviceInitRegConfig(const struct CodecDevice *device); 78 int32_t CodecDaiDeviceStartupRegConfig(const struct DaiDevice *device); 79 80 #ifdef __cplusplus 81 #if __cplusplus 82 } 83 #endif 84 #endif /* __cplusplus */ 85 86 #endif 87