/* * Copyright (c) Hisilicon Technologies Co., Ltd.. 2019-2019. All rights reserved. * Description: amp device and driver ntp8214 * 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 NTP8214_MAX_VOL 0xff #define NTP8214_MIN_VOL 0x00 /* mute */ /* address data_length data_n data_n+1... */ static drv_amp_reg_map g_ntp8214_init_reg[] = { /* I2C configuration file for NTP8214 */ { 0x02, 1, { 0x00 } }, /* master clock 12.288MHz */ { 0x00, 1, { 0x00 } }, /* audio interface setup,I2S slave, 48kHz */ { 0x5D, 1, { 0x01 } }, /* driver control SHDN go to high */ { 0x3C, 1, { 0x67 } }, /* prescaler value for L/R */ { 0x17, 1, { 0xB7 } }, /* channel 1 volume +12dB, 0x9F == 0dB */ { 0x18, 1, { 0xB7 } }, /* channel 2 volume +12dB */ { 0x20, 1, { 0xA8 } }, /* LR DRC low side enable with +0dB */ { 0x21, 1, { 0x72 } }, /* LR DRC low side attack 15ms, release 0.2sec */ { 0x22, 1, { 0xA8 } }, /* LR DRC high side enable with +0dB */ { 0x23, 1, { 0x01 } }, /* LR DRC high side attack 8ms, release 0.5sec */ { 0x26, 1, { 0xA8 } }, /* POST DRC enable with +0dB */ { 0x27, 1, { 0x51 } }, /* POST DRC attack 15ms, release 0.2sec */ { 0x2A, 1, { 0xEA } }, /* sub DRC enable with -9dB */ { 0x2B, 1, { 0x01 } }, /* sub DRC attack 8ms, release 0.5sec */ { 0x29, 1, { 0x11 } }, /* 2_band DRC mode enable */ { 0x2C, 1, { 0x01 } }, /* sub band DRC mode enable */ { 0x60, 1, { 0x28 } }, /* DC, unstable frequency check enable */ { 0x41, 1, { 0x12 } }, /* minimum pulse width 40ns */ { 0x43, 1, { 0x02 } }, /* BTL output DBTL mode */ { 0x4A, 1, { 0x00 } }, /* PWM soft start control , soft start disable */ { 0x0c, 1, { 0x0 } }, /* PWM MASK ON -> PWM ON -> soft mute off -> master volume 0dB */ { ENDTBL_FLAG, 0x01, { 0x00 } } }; static td_void ntp8214_write_reg_map(const amp_platform_device *dev, drv_amp_reg_map *reg_map) { td_s32 ret; td_u32 addr; td_u32 size; td_u8 *reg = TD_NULL; while (1) { if ((reg_map == TD_NULL) || (reg_map->addr == ENDTBL_FLAG)) { return; } addr = reg_map->addr; reg = reg_map->reg; size = reg_map->size; ret = amp_osal_i2c_write(&dev->i2c, addr, reg, size); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(amp_osal_i2c_write, ret); return; } /* 0x1B:oscillator trim, 0x46:DRC control, 0x50:EQ control, 0xF9:I2C device addr */ if ((addr == 0x1B) || (addr == 0x46) || (addr == 0x50) || (addr == 0xF9)) { osal_msleep(1); } reg_map++; } } static td_s32 ntp8214_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) ? NTP8214_MIN_VOL : NTP8214_MAX_VOL; if (channel_type != AMP_CHANNEL_TYPE_ALL) { /* need add by custom for gain */ } ret = amp_osal_i2c_write(&dev->i2c, 0x0c, &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 ntp8214_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, 0x0c, &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 == NTP8214_MIN_VOL); } else { /* need add by custom */ } return TD_SUCCESS; } static td_s32 ntp8214_init(const amp_platform_device *dev) { td_s32 ret; ret = ntp8214_set_mute(dev, AMP_CHANNEL_TYPE_ALL, TD_TRUE); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(ntp8214_set_mute, ret); return ret; } drv_amp_dev_hw_mute(dev, TD_FALSE); osal_msleep(DELAY_10_MS); /* reset AMP */ drv_amp_dev_hw_reset(dev, TD_TRUE); osal_msleep(DELAY_10_MS); /* release reset AMP */ drv_amp_dev_hw_reset(dev, TD_FALSE); ntp8214_write_reg_map(dev, g_ntp8214_init_reg); return TD_SUCCESS; } static td_void ntp8214_deinit(const amp_platform_device *dev) { drv_amp_dev_hw_reset(dev, TD_TRUE); } static amp_platform_driver g_ntp8214_driver = { .name = "NTP8214", .dev_type = AMP_DEV_NTP8214, .deinit = ntp8214_deinit, .init = ntp8214_init, .get_mute = ntp8214_get_mute, .set_mute = ntp8214_set_mute, .hw_mute = drv_amp_dev_hw_mute, .reset = TD_NULL, .get_active = TD_NULL, .dump_reg = TD_NULL, }; td_s32 ntp8214_register_driver(td_void) { return amp_platform_driver_register(&g_ntp8214_driver); } #ifdef __cplusplus } #endif /* __cplusplus */