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 TFA9879_ACCESSORY_IMPL_H 10 #define TFA9879_ACCESSORY_IMPL_H 11 12 #include "audio_accessory_if.h" 13 #include "osal_mem.h" 14 #include "osal_time.h" 15 #include "osal_io.h" 16 #include "securec.h" 17 #include <linux/types.h> 18 19 #ifdef __cplusplus 20 #if __cplusplus 21 extern "C" { 22 #endif 23 #endif /* __cplusplus */ 24 25 /* Hi35xx IO register address */ 26 #define HI35XX_I2C_REG_BASE_ADDR 0x114F0000 27 #define HI35XX_I2S_REG_BASE_ADDR 0x112F0000 28 29 typedef enum Hi35xxRegAddr { 30 IOCFG_REG36_ADDR = 0x114F0048, // I2C6_SCL 31 IOCFG_REG37_ADDR = 0x114F004C, // I2C6_SDA 32 IOCFG_REG73_ADDR = 0x112F0020, // I2S_MCLK 33 IOCFG_REG74_ADDR = 0x112F0024, // I2S_BCLK_TX 34 IOCFG_REG75_ADDR = 0x112F0028, // I2S_WS_TX 35 IOCFG_REG76_ADDR = 0x112F002C, // I2S_SD_TX 36 IOCFG_REG77_ADDR = 0x112F0030 // I2S_SD_RX 37 } Hi35xxRegAddr; 38 39 /* TFA9879 I2C Device address 1 1 0 1 1 A2 A1 R/W */ 40 typedef enum Tfa9879I2cDevAddr { 41 TFA9879_I2C_DEV_ADDR_ADSEL1 = 0x6D, // 1101101 42 TFA9879_I2C_DEV_ADDR_ADSEL2 = 0x6E, // 1101110 43 TFA9879_I2C_DEV_ADDR_ADSEL1_READ = 0xDB, // 1101 1011 44 TFA9879_I2C_DEV_ADDR_ADSEL1_WRITE = 0xDA, // 1101 1010 45 TFA9879_I2C_DEV_ADDR_ADSEL2_READ = 0xDD, // 1101 1101 46 TFA9879_I2C_DEV_ADDR_ADSEL2_WRITE = 0xDC // 1101 1100 47 } Tfa9879I2cDevAddr; 48 49 /* TFA9879 register address */ 50 #define TFA9879_REG_BASE_ADDR 0x00; 51 typedef enum Tfa9879RegAddr { 52 DEVICE_CONTROL_REG_ADDR = 0x00, 53 SERIAL_INTERFACE_INPUT1_REG_ADDR = 0x01, 54 PCM_IOM2_FMT_INPUT1_REG_ADDR = 0x02, 55 SERIAL_INTERFACE_INPUT2_REG_ADDR = 0x03, 56 PCM_IOM2_FMT_INPUT2_REG_ADDR = 0x04, 57 EQUALIZER_A_WORD1_REG_ADDR = 0x05, 58 EQUALIZER_A_WORD2_REG_ADDR = 0x06, 59 EQUALIZER_B_WORD1_REG_ADDR = 0x07, 60 EQUALIZER_B_WORD2_REG_ADDR = 0x08, 61 EQUALIZER_C_WORD1_REG_ADDR = 0x09, 62 EQUALIZER_C_WORD2_REG_ADDR = 0x0A, 63 EQUALIZER_D_WORD1_REG_ADDR = 0x0B, 64 EQUALIZER_D_WORD2_REG_ADDR = 0x0C, 65 EQUALIZER_E_WORD1_REG_ADDR = 0x0D, 66 EQUALIZER_E_WORD2_REG_ADDR = 0x0E, 67 BYPASS_CONTROL_REG_ADDR = 0x0F, 68 DYNAMIC_RANGE_COMP_REG_ADDR = 0x10, 69 BASS_TREBLE_REG_ADDR = 0x11, 70 HIGH_PASS_FILTER_REG_ADDR = 0x12, 71 VOLUME_CONTROL_REG_ADDR = 0x13, 72 DE_EMPHASIS_REG_ADDR = 0x14, 73 MISCELLANEOUS_STATUS_REG_ADDR = 0x15 74 } Tfa9879RegAddr; 75 76 enum CodecInputSel { 77 ADSEL1 = 0, 78 ADSEL2 = 1 79 }; 80 81 enum CodecOpMode { 82 OFF_MODE = 0, 83 AMPLIFIER_MODE = 1 84 }; 85 86 struct Tfa9879RegAttr { 87 uint8_t regAddr; 88 uint16_t regValue; // 16bit 89 }; 90 91 int32_t AccessoryDeviceInit(struct AudioCard *audioCard, const struct AccessoryDevice *device); 92 int32_t AccessoryDeviceReadReg(const struct AccessoryDevice *codec, uint32_t reg, uint32_t *value); 93 int32_t AccessoryDeviceWriteReg(const struct AccessoryDevice *codec, uint32_t reg, uint32_t value); 94 int32_t AccessoryAiaoDeviceReadReg(const struct AccessoryDevice *codec, uint32_t reg, uint32_t *value); 95 int32_t AccessoryAiaoDeviceWriteReg(const struct AccessoryDevice *codec, uint32_t reg, uint32_t value); 96 int32_t AccessoryDaiStartup(const struct AudioCard *card, const struct DaiDevice *device); 97 int32_t AccessoryDaiHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param, 98 const struct DaiDevice *device); 99 int32_t AccessoryDaiDeviceInit(const struct AudioCard *card, const struct DaiDevice *device); 100 101 102 #ifdef __cplusplus 103 #if __cplusplus 104 } 105 #endif 106 #endif 107 108 #endif 109