/* * Copyright (c) Hisilicon Technologies Co., Ltd.. 2019-2019. All rights reserved. * Description: amp device and driver rt9107b * 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 RT9107B_MAX_VOL 0x05 #define RT9107B_MIN_VOL 0xff /* mute */ static drv_amp_reg_map g_rt9107b_init_reg[] = { { 0x1B, 0x01, { 0x00 } }, /* 0:factory trim */ { 0x06, 0x01, { 0x00 } }, /* 0:soft mute */ { 0x20, 0x04, { 0x00, 0x89, 0x77, 0x72 } }, /* 0x98->0x89 to invert L/R output, BD mode */ { 0x11, 0x01, { 0xB8 } }, /* 0xB8:BD mode */ { 0x12, 0x01, { 0x60 } }, /* 0x60:BD mode */ { 0x13, 0x01, { 0xB8 } }, /* 0xA0:BD mode */ { 0x14, 0x01, { 0x60 } }, /* 0x48:BD mode */ { 0x50, 0x04, { 0x00, 0x00, 0x00, 0x00 } }, /* band switch and EQ control */ /* EQ */ { 0x29, 0x14, { 0x00, 0x7F, 0x55, 0x51, 0x0F, 0x80, 0xAA, 0xAF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0xAA, 0xA3, 0x00, 0x00, 0x00, 0x00 } }, { 0x2A, 0x14, { 0x00, 0x7F, 0x83, 0xD8, 0x0F, 0x02, 0xD2, 0xDA, 0x00, 0x7D, 0xDB, 0x4F, 0x00, 0xFD, 0x2D, 0x26, 0x0F, 0x82, 0xA0, 0xD8 } }, { 0x2B, 0x14, { 0x00, 0x80, 0x7C, 0xA0, 0x0F, 0x02, 0x35, 0x8E, 0x00, 0x7D, 0xD9, 0x39, 0x00, 0xFD, 0xCA, 0x72, 0x0F, 0x81, 0xAA, 0x27 } }, { 0x2C, 0x14, { 0x00, 0x81, 0xA3, 0xAE, 0x0F, 0x08, 0xB0, 0x42, 0x00, 0x78, 0xC1, 0x41, 0x00, 0xF7, 0x4F, 0xBE, 0x0F, 0x85, 0x9B, 0x11 } }, { 0x2D, 0x14, { 0x00, 0x85, 0x2A, 0x32, 0x0F, 0x2E, 0x41, 0x33, 0x00, 0x61, 0xCB, 0xB8, 0x00, 0xD1, 0xBE, 0xCD, 0x0F, 0x99, 0x0A, 0x15 } }, { 0x2E, 0x14, { 0x00, 0x8B, 0xBA, 0xC9, 0x0F, 0xA7, 0xEC, 0xDA, 0x00, 0x3B, 0x67, 0x91, 0x00, 0x58, 0x13, 0x26, 0x0F, 0xB8, 0xDD, 0xA6 } }, { 0x2F, 0x14, { 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, { 0x30, 0x14, { 0x00, 0x7F, 0x55, 0x51, 0x0F, 0x80, 0xAA, 0xAF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0xAA, 0xA3, 0x00, 0x00, 0x00, 0x00 } }, { 0x31, 0x14, { 0x00, 0x7F, 0x83, 0xD8, 0x0F, 0x02, 0xD2, 0xDA, 0x00, 0x7D, 0xDB, 0x4F, 0x00, 0xFD, 0x2D, 0x26, 0x0F, 0x82, 0xA0, 0xD8 } }, { 0x32, 0x14, { 0x00, 0x80, 0x7C, 0xA0, 0x0F, 0x02, 0x35, 0x8E, 0x00, 0x7D, 0xD9, 0x39, 0x00, 0xFD, 0xCA, 0x72, 0x0F, 0x81, 0xAA, 0x27 } }, { 0x33, 0x14, { 0x00, 0x81, 0xA3, 0xAE, 0x0F, 0x08, 0xB0, 0x42, 0x00, 0x78, 0xC1, 0x41, 0x00, 0xF7, 0x4F, 0xBE, 0x0F, 0x85, 0x9B, 0x11 } }, { 0x34, 0x14, { 0x00, 0x85, 0x2A, 0x32, 0x0F, 0x2E, 0x41, 0x33, 0x00, 0x61, 0xCB, 0xB8, 0x00, 0xD1, 0xBE, 0xCD, 0x0F, 0x99, 0x0A, 0x15 } }, { 0x35, 0x14, { 0x00, 0x8B, 0xBA, 0xC9, 0x0F, 0xA7, 0xEC, 0xDA, 0x00, 0x3B, 0x67, 0x91, 0x00, 0x58, 0x13, 0x26, 0x0F, 0xB8, 0xDD, 0xA6 } }, { 0x36, 0x14, { 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* energy filter params(a,w) */ { 0x3A, 0x08, { 0x00, 0x02, 0xA3, 0x9A, 0x00, 0x7D, 0x5C, 0x65 } }, /* attack and decay filters */ { 0x3B, 0x08, { 0x00, 0x02, 0xA3, 0x9A, 0x00, 0x7D, 0x5C, 0x65 } }, { 0x3C, 0x08, { 0x00, 0x00, 0x06, 0xd3, 0x00, 0x7f, 0xf9, 0x2c } }, /* the compression control(T,K,O) */ { 0x40, 0x04, { 0xFD, 0x82, 0x30, 0x98 } }, { 0x41, 0x04, { 0x0F, 0x81, 0x47, 0xAF } }, { 0x42, 0x04, { 0x00, 0x08, 0x42, 0x10 } }, { 0x46, 0x04, { 0x00, 0x00, 0x00, 0x03 } }, /* DRC control */ { 0x07, 0x01, { 0x05 } }, /* default umute,mute:0xff,umute:0x5 */ { 0x05, 0x01, { 0x00 } }, /* 0: start play, 1:power down and hard mute */ { ENDTBL_FLAG, 0x01, { 0x00 } }, }; static td_void tas9107_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 rt9107_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) ? RT9107B_MIN_VOL : RT9107B_MAX_VOL; if (channel_type != AMP_CHANNEL_TYPE_ALL) { /* need add by custom for gain */ } ret = amp_osal_i2c_write(&dev->i2c, 0x07, &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 rt9107_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; } /* 0x07: mute register addr */ ret = amp_osal_i2c_read(&dev->i2c, 0x07, &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 == RT9107B_MIN_VOL); } else { /* need add by custom */ } return TD_SUCCESS; } static td_s32 rt9107_init(const amp_platform_device *dev) { td_s32 ret; ret = rt9107_set_mute(dev, AMP_CHANNEL_TYPE_ALL, TD_TRUE); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(rt9107_set_mute, ret); return ret; } drv_amp_dev_hw_mute(dev, TD_FALSE); 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); tas9107_write_reg_map(dev, g_rt9107b_init_reg); return TD_SUCCESS; } static td_void rt9107_deinit(const amp_platform_device *dev) { drv_amp_dev_hw_reset(dev, TD_TRUE); } static amp_platform_driver g_rt9107b_driver = { .name = "RT9107B", .dev_type = AMP_DEV_RT9107B, .deinit = rt9107_deinit, .init = rt9107_init, .get_mute = rt9107_get_mute, .set_mute = rt9107_set_mute, .hw_mute = drv_amp_dev_hw_mute, .reset = TD_NULL, .get_active = TD_NULL, .dump_reg = TD_NULL, }; td_s32 rt9107b_register_driver(td_void) { return amp_platform_driver_register(&g_rt9107b_driver); } #ifdef __cplusplus } #endif /* __cplusplus */