/* * Copyright (c) Hisilicon Technologies Co., Ltd.. 2019-2019. All rights reserved. * Description: amp device and driver ntp8212 * 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 NTP8212_MASTER_VOL_REG 0x2e #define NTP8212_MAX_VOL 0xff #define NTP8212_MIN_VOL 0x00 /* mute */ /* address data_length data_n data_n+1... */ static drv_amp_reg_map g_ntp8212_init_reg[] = { /* I2C configuration file for NTP8212 */ { 0x02, 1, { 0x02 } }, /* master clock 18.432M Hz */ { 0x00, 1, { 0x00 } }, /* audio interface setup,I2S slave, 48kHz */ { 0x38, 1, { 0x02 } }, /* DBTL */ { 0x4E, 1, { 0x0E } }, /* DBTL MINIMUM PW for ch12 */ { 0x50, 1, { 0x03 } }, /* NS selection for ch12 */ { 0x52, 1, { 0x10 } }, /* softstart off for ch12 */ { 0x62, 1, { 0x18 } }, /* 2 CHANNEL MODE */ { 0x55, 1, { 0x0A } }, /* MINIMUM PW 4 for ch12 */ { 0x15, 1, { 0xE7 } }, /* prescaler value for L/R */ { 0x61, 1, { 0x81 } }, /* I2S glitch filter setting */ { 0x2C, 1, { 0x43 } }, /* POE control enable */ { 0x28, 1, { 0x04 } }, /* PWM MASK ON */ { 0x2E, 1, { 0xCF } }, /* master volume 0d_b */ { 0x2F, 1, { 0xCF } }, /* channel 1 volume 0dB */ { 0x30, 1, { 0xCF } }, /* channel 2 volume 0dB */ { 0x25, 1, { 0x00 } }, /* enhanced DRC enable, allpass disable */ { 0x1C, 1, { 0xA8 } }, /* LR DRC low side enable with +0dB */ { 0x62, 1, { 0x18 } }, /* 2CH / SB ON */ { 0x28, 1, { 0x04 } }, /* PWM MASK ON */ { 0x27, 1, { 0x00 } }, /* PWM switching ON */ { 0x26, 1, { 0x00 } }, /* soft-mute OFF */ { ENDTBL_FLAG, 0x01, { 0x00 } }, }; static td_void ntp8212_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 ntp8212_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) ? NTP8212_MIN_VOL : NTP8212_MAX_VOL; if (channel_type != AMP_CHANNEL_TYPE_ALL) { /* need add by custom for gain */ } ret = amp_osal_i2c_write(&dev->i2c, NTP8212_MASTER_VOL_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 ntp8212_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, NTP8212_MASTER_VOL_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 == NTP8212_MIN_VOL); } else { /* need add by custom */ } return TD_SUCCESS; } static td_s32 ntp8212_init(const amp_platform_device *dev) { td_s32 ret; ret = ntp8212_set_mute(dev, AMP_CHANNEL_TYPE_ALL, TD_TRUE); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(ntp8212_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); ntp8212_write_reg_map(dev, g_ntp8212_init_reg); return TD_SUCCESS; } static td_void ntp8212_deinit(const amp_platform_device *dev) { drv_amp_dev_hw_reset(dev, TD_TRUE); } static amp_platform_driver g_ntp8212_driver = { .name = "NTP8212", .dev_type = AMP_DEV_NTP8212, .deinit = ntp8212_deinit, .init = ntp8212_init, .get_mute = ntp8212_get_mute, .set_mute = ntp8212_set_mute, .hw_mute = drv_amp_dev_hw_mute, .reset = TD_NULL, .get_active = TD_NULL, .dump_reg = TD_NULL, }; td_s32 ntp8212_register_driver(td_void) { return amp_platform_driver_register(&g_ntp8212_driver); } #ifdef __cplusplus } #endif /* __cplusplus */