/* * Copyright (c) Hisilicon Technologies Co., Ltd.. 2019-2019. All rights reserved. * Description: amp device and driver ad82584f * Author: audio * Create: 2019-05-30 */ #include "osal_ext.h" #include "soc_errno.h" #include "drv_amp_debug.h" #include "drv_amp_osal.h" #include "drv_amp_common.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #define AD82584F_MAX_VOL 0x00 /* unmute */ #define AD82584F_MIN_VOL 0x7f /* mute */ #define AD82584F_MUTE_REG 0x02 /* master mute and channel mute */ #define AD82584F_RESET_VALUE 0x12 /* software reset value */ #define AD82584F_NORMAL_VALUE 0x32 /* software reset normal operation */ #define AD82584F_RESET_REG 0x1A /* software reset register */ static drv_amp_reg_map g_ad82584f_init_reg[] = { { 0x00, 0x01, { 0x04 } }, /* state control 1 */ { 0x01, 0x01, { 0x81 } }, /* state control 2 */ { 0x02, 0x01, { 0x7f } }, /* master mute and channel mute */ { 0x03, 0x01, { 0x00 } }, /* master volume control , 12d_b */ { 0x04, 0x01, { 0x00 } }, /* channel 1 volume , 12d_b */ { 0x05, 0x01, { 0x00 } }, /* channel 2 volume , 12d_b */ { 0x06, 0x01, { 0x18 } }, /* channel 3 volume , 0d_b */ { 0x07, 0x01, { 0x18 } }, /* channel 4 volume , 0d_b */ { 0x08, 0x01, { 0x18 } }, /* channel 5 volume , 0d_b */ { 0x09, 0x01, { 0x18 } }, /* channel 6 volume , 0d_b */ { 0x0A, 0x02, { 0x10, 0x10 } }, /* bass/treble tone boost and cut */ { 0x0C, 0x01, { 0x90 } }, /* state control 4 */ { 0x0D, 0x08, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* channel configuration registers */ { 0x15, 0x04, { 0x6a, 0x6a, 0x6a, 0x6a } }, /* DRC limiter attack/release rate */ { 0x19, 0x01, { 0x06 } }, { 0x1A, 0x01, { 0x32 } }, /* state control 5 */ { 0x1B, 0x01, { 0x01 } }, /* state control 6 */ { 0x1C, 0x01, { 0x00 } }, /* state control 7 */ { 0x1D, 0x11, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 } }, /* user-defined coefficients registers */ { 0x2E, 0x02, { 0x00, 0x00 } }, { 0x33, 0x01, { 0x6d } }, /* power saving mode switching level */ { 0x34, 0x02, { 0x40, 0x00 } }, /* volume fine tune */ { 0x42, 0x01, { 0x00 } }, /* level meter clear */ { 0x43, 0x01, { 0x00 } }, /* power meter clear */ { ENDTBL_FLAG, 0x01, { 0x00 } }, /* end flag */ }; static td_void ad82584f_soft_reset(const amp_platform_device *dev, td_bool reset) { td_s32 ret; td_u8 val; val = (reset == TD_TRUE) ? AD82584F_RESET_VALUE : AD82584F_NORMAL_VALUE; ret = amp_osal_i2c_write(&dev->i2c, AD82584F_RESET_REG, &val, 1); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(amp_osal_i2c_write, ret); return; } } static td_s32 ad82584f_set_mute(const amp_platform_device *dev, amp_channel_type channel_type, td_bool mute) { td_s32 ret; td_u8 gain; gain = (mute == TD_TRUE) ? AD82584F_MIN_VOL : AD82584F_MAX_VOL; if (channel_type != AMP_CHANNEL_TYPE_ALL) { /* need add by custom for gain */ } ret = amp_osal_i2c_write(&dev->i2c, AD82584F_MUTE_REG, &gain, 1); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(amp_osal_i2c_write, ret); return ret; } return TD_SUCCESS; } static td_s32 ad82584f_get_mute(const amp_platform_device *dev, amp_channel_type channel_type, td_bool *mute) { td_s32 ret; td_u8 gain = 0; if (mute == TD_NULL) { return SOC_ERR_AMP_NULL_PTR; } ret = amp_osal_i2c_read(&dev->i2c, AD82584F_MUTE_REG, &gain, 1); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(amp_osal_i2c_read, ret); return ret; } if (channel_type == AMP_CHANNEL_TYPE_ALL) { *mute = (gain == AD82584F_MIN_VOL); } else { /* need add by custom */ } return TD_SUCCESS; } static td_s32 ad82584f_init(const amp_platform_device *dev) { td_s32 ret; ad82584f_soft_reset(dev, TD_TRUE); osal_msleep(DELAY_10_MS); ad82584f_soft_reset(dev, TD_FALSE); osal_msleep(DELAY_10_MS); drv_amp_dev_write_reg_map(dev, g_ad82584f_init_reg); drv_amp_dev_hw_mute(dev, TD_FALSE); osal_msleep(DELAY_20_MS); ret = ad82584f_set_mute(dev, AMP_CHANNEL_TYPE_ALL, TD_FALSE); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(ad82584f_set_mute, ret); } return TD_SUCCESS; } static td_void ad82584f_deinit(const amp_platform_device *dev) { drv_amp_dev_hw_reset(dev, TD_TRUE); } static td_void ad82584f_dump_reg(const amp_platform_device *dev, td_void *file) { drv_amp_dev_dump_reg_map(dev, file, g_ad82584f_init_reg); } static td_s32 ad82584f_get_active(const amp_platform_device *dev, td_bool *active) { if (active == TD_NULL) { return SOC_ERR_AMP_NULL_PTR; } *active = TD_TRUE; return TD_SUCCESS; } static amp_platform_driver g_ad82584f_driver = { .name = "AD82584F", .dev_type = AMP_DEV_AD82584F, .deinit = ad82584f_deinit, .init = ad82584f_init, .get_mute = ad82584f_get_mute, .set_mute = ad82584f_set_mute, .hw_mute = drv_amp_dev_hw_mute, .reset = ad82584f_soft_reset, .get_active = ad82584f_get_active, .dump_reg = ad82584f_dump_reg, }; td_s32 ad82584f_register_driver(td_void) { return amp_platform_driver_register(&g_ad82584f_driver); } #ifdef __cplusplus } #endif /* __cplusplus */