/* * Copyright (c) Hisilicon Technologies Co., Ltd.. 2019-2019. All rights reserved. * Description: amp device and driver alc1310 * 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 ALC1310_MAX_VOL 0xff #define ALC1310_MIN_VOL 0x00 /* mute */ #define ALC1310_MUTE_REG 0x12 /* volume register */ #define ALC1310_CHANNEL_NUM 2 static drv_amp_reg_map g_alc1310_init_reg[] = { /* init */ { 0x05, 0x02, { 0x40, 0x3e } }, { 0x02, 0x02, { 0x80, 0x00 } }, { 0x09, 0x02, { 0x80, 0x00 } }, /* DC */ { 0x6a, 0x02, { 0x00, 0xdc } }, { 0x6c, 0x02, { 0x00, 0x24 } }, /* D9 */ { 0x14, 0x02, { 0x00, 0xd9 } }, { 0x50, 0x02, { 0xa4, 0x10 } }, /* DRC */ { 0x09, 0x02, { 0xC8, 0x00 } }, /* DRC enable */ { 0x0a, 0x02, { 0x06, 0x06 } }, { 0x0c, 0x02, { 0x04, 0x02 } }, { 0x0e, 0x02, { 0x00, 0x00 } }, /* down layer register and value */ { 0x6a, 0x02, { 0x00, 0x9d } }, { 0x6c, 0x02, { 0x46, 0x00 } }, { 0x6a, 0x02, { 0x00, 0x9e } }, { 0x6c, 0x02, { 0x23, 0x23 } }, /* b0 */ { 0x6a, 0x02, { 0x00, 0xb0 } }, { 0x6c, 0x02, { 0x88, 0x03 } }, /* silence detection:level is -80d_b */ { 0x13, 0x02, { 0x00, 0x0c } }, /* unmute */ { 0x13, 0x02, { 0x00, 0x0c } }, /* unmute */ { 0x12, 0x02, { 0x00, 0x00 } }, /* L/R volume */ /* BQ1 bq1_ty= 4 bq1_fs=44100 bq1_fc=100_bq1_ga=1 bq1_fb=120 */ { 0x6a, 0x02, { 0x00, 0x00 } }, { 0x6c, 0x02, { 0x02, 0x00 } }, { 0x6a, 0x02, { 0x00, 0x01 } }, { 0x6c, 0x02, { 0x87, 0x8E } }, { 0x6a, 0x02, { 0x00, 0x02 } }, { 0x6c, 0x02, { 0x1C, 0x09 } }, { 0x6a, 0x02, { 0x00, 0x03 } }, { 0x6c, 0x02, { 0xD4, 0xC5 } }, { 0x6a, 0x02, { 0x00, 0x04 } }, { 0x6c, 0x02, { 0x01, 0xF6 } }, { 0x6a, 0x02, { 0x00, 0x05 } }, { 0x6c, 0x02, { 0x45, 0x96 } }, { 0x6a, 0x02, { 0x00, 0x06 } }, { 0x6c, 0x02, { 0x03, 0xF7 } }, { 0x6a, 0x02, { 0x00, 0x07 } }, { 0x6c, 0x02, { 0x37, 0xBD } }, { 0x6a, 0x02, { 0x00, 0x08 } }, { 0x6c, 0x02, { 0x1E, 0x08 } }, { 0x6a, 0x02, { 0x00, 0x09 } }, { 0x6c, 0x02, { 0xAD, 0xE1 } }, /* BQ2 bq2_ty= 4 bq2_fs=44100 bq2_fc=6000 bq2_ga=0.5 bq2_fb=1500 */ { 0x6a, 0x02, { 0x00, 0xa } }, { 0x6c, 0x02, { 0x02, 0x02 } }, { 0x6a, 0x02, { 0x00, 0x0b } }, { 0x6c, 0x02, { 0x9D, 0x55 } }, { 0x6a, 0x02, { 0x00, 0x0c } }, { 0x6c, 0x02, { 0x1D, 0x9C } }, { 0x6a, 0x02, { 0x00, 0x0d } }, { 0x6c, 0x02, { 0xF6, 0x0A } }, { 0x6a, 0x02, { 0x00, 0x0e } }, { 0x6c, 0x02, { 0x01, 0xA2 } }, { 0x6a, 0x02, { 0x00, 0x0f } }, { 0x6c, 0x02, { 0xFE, 0xEA } }, { 0x6a, 0x02, { 0x00, 0x10 } }, { 0x6c, 0x02, { 0x02, 0x66 } }, { 0x6a, 0x02, { 0x00, 0x11 } }, { 0x6c, 0x02, { 0x28, 0xC3 } }, { 0x6a, 0x02, { 0x00, 0x12 } }, { 0x6c, 0x02, { 0x1E, 0x58 } }, { 0x6a, 0x02, { 0x00, 0x13 } }, { 0x6c, 0x02, { 0x40, 0x03 } }, /* BQ3 bq3_ty= 4 bq3_fs=44100 bq3_fc=11000 bq3_ga=1.5 bq3_fb=14000 */ { 0x6a, 0x02, { 0x00, 0x14 } }, { 0x6c, 0x02, { 0x02, 0x25 } }, { 0x6a, 0x02, { 0x00, 0x15 } }, { 0x6c, 0x02, { 0x88, 0x62 } }, { 0x6a, 0x02, { 0x00, 0x16 } }, { 0x6c, 0x02, { 0x1F, 0xFD } }, { 0x6a, 0x02, { 0x00, 0x17 } }, { 0x6c, 0x02, { 0xEC, 0x29 } }, { 0x6a, 0x02, { 0x00, 0x18 } }, { 0x6c, 0x02, { 0x00, 0x47 } }, { 0x6a, 0x02, { 0x00, 0x19 } }, { 0x6c, 0x02, { 0x09, 0xFB } }, { 0x6a, 0x02, { 0x00, 0x1a } }, { 0x6c, 0x02, { 0x00, 0x02 } }, { 0x6a, 0x02, { 0x00, 0x1b } }, { 0x6c, 0x02, { 0x3A, 0xD3 } }, { 0x6a, 0x02, { 0x00, 0x1c } }, { 0x6c, 0x02, { 0x1F, 0x8E } }, { 0x6a, 0x02, { 0x00, 0x1d } }, { 0x6c, 0x02, { 0x38, 0x7E } }, { 0x04, 0x02, { 0xc7, 0x00 } }, { ENDTBL_FLAG, 0x01, { 0x00 } }, }; static td_s32 alc1310_set_mute(const amp_platform_device *dev, amp_channel_type channel_type, td_bool mute) { td_s32 ret; td_u8 gain[ALC1310_CHANNEL_NUM]; if (mute == TD_TRUE) { gain[0] = ALC1310_MIN_VOL; gain[1] = ALC1310_MIN_VOL; } else { gain[0] = ALC1310_MAX_VOL; gain[1] = ALC1310_MAX_VOL; } if (channel_type != AMP_CHANNEL_TYPE_ALL) { /* need add by custom for gain */ } ret = amp_osal_i2c_write(&dev->i2c, ALC1310_MUTE_REG, gain, ALC1310_CHANNEL_NUM); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(amp_osal_i2c_write, ret); return ret; } drv_amp_dev_hw_mute(dev, TD_FALSE); osal_msleep(DELAY_10_MS); return TD_SUCCESS; } static td_s32 alc1310_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, ALC1310_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 == ALC1310_MIN_VOL); } else { /* need add by custom */ } return TD_SUCCESS; } static td_s32 alc1310_init(const amp_platform_device *dev) { td_s32 ret; ret = alc1310_set_mute(dev, AMP_CHANNEL_TYPE_ALL, TD_TRUE); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(alc1310_set_mute, ret); return ret; } drv_amp_dev_hw_mute(dev, TD_TRUE); osal_msleep(DELAY_10_MS); drv_amp_dev_hw_reset(dev, TD_TRUE); osal_msleep(DELAY_10_MS); drv_amp_dev_hw_reset(dev, TD_FALSE); drv_amp_dev_write_reg_map(dev, g_alc1310_init_reg); return TD_SUCCESS; } static td_void alc1310_deinit(const amp_platform_device *dev) { drv_amp_dev_hw_reset(dev, TD_TRUE); } static amp_platform_driver g_alc1310_driver = { .name = "ALC1310", .dev_type = AMP_DEV_ALC1310, .deinit = alc1310_deinit, .init = alc1310_init, .get_mute = alc1310_get_mute, .set_mute = alc1310_set_mute, .hw_mute = drv_amp_dev_hw_mute, .reset = TD_NULL, .get_active = TD_NULL, .dump_reg = TD_NULL, }; td_s32 alc1310_register_driver(td_void) { return amp_platform_driver_register(&g_alc1310_driver); } #ifdef __cplusplus } #endif /* __cplusplus */