/* * Copyright (c) Hisilicon Technologies Co., Ltd.. 2020-2021. All rights reserved. * Description: amp device and driver tas2564 * Author: audio * Create: 2021-1-4 */ #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 ENDTBL_FLAG 0xff #define MAX_AMP_REG_LEN 20 #define TAS2564_MAX_VOL 0x05 #define TAS2564_MIN_VOL 0xff /* mute */ #define TAS2564_INIT_INTERVAL 5 /* delay 5ms */ #define INVALID_GPIONUM 0xff #define AMP_FIVEMS_DELAY 5 #define AMP_TENMS_DELAY 10 #define AMP_FIFTYMS_DELAY 50 #define TAS2564_MUTE_REG 0x07 static drv_amp_reg_map g_tas2564_init_reg[] = { { 0x02, 1, { 0x00 } }, { 0x00, 1, { 0x00 } }, { 0x7f, 1, { 0x00 } }, { 0x01, 1, { 0x01 } }, /* IC delay */ { 0x1a, 1, { 0xff } }, { 0x1b, 1, { 0xff } }, { 0x1c, 1, { 0xff } }, { 0x3e, 1, { 0x00 } }, { 0x33, 1, { 0x34 } }, { 0x40, 1, { 0x2d } }, { 0x3c, 1, { 0x3c } }, { 0x4a, 1, { 0x1a } }, { 0x30, 1, { 0x1d } }, { 0x38, 1, { 0x11 } }, { 0x08, 1, { 0x1e } }, { 0x0b, 1, { 0x42 } }, { 0x0c, 1, { 0x40 } }, { 0x0d, 1, { 0x04 } }, { 0x41, 1, { 0x48 } }, { 0x48, 1, { 0xa8 } }, { 0x4a, 1, { 0x1c } }, { 0x43, 1, { 0xc0 } }, { 0x04, 1, { 0xc2 } }, { 0x00, 1, { 0x01 } }, { 0x08, 1, { 0x00 } }, { 0x21, 1, { 0x08 } }, { 0x00, 1, { 0x03 } }, { 0x24, 1, { 0x0a } }, { 0x25, 1, { 0x42 } }, { 0x26, 1, { 0x38 } }, { 0x27, 1, { 0xed } }, { 0x00, 1, { 0x05 } }, { 0x14, 1, { 0x53 } }, { 0x15, 1, { 0xff } }, { 0x16, 1, { 0x2b } }, { 0x17, 1, { 0xcf } }, { 0x00, 1, { 0xfd } }, { 0x0d, 1, { 0x0d } }, { 0x58, 1, { 0x0d } }, { 0x5e, 1, { 0x8c } }, { 0x00, 1, { 0x00 } }, { 0x7f, 1, { 0x64 } }, { 0x00, 1, { 0x08 } }, { 0x1c, 1, { 0x50 } }, { 0x1d, 1, { 0x1b } }, { 0x1e, 1, { 0x01 } }, { 0x1f, 1, { 0xc0 } }, { 0x00, 1, { 0x07 } }, { 0x38, 1, { 0x31 } }, { 0x39, 1, { 0x99 } }, { 0x3a, 1, { 0x99 } }, { 0x3b, 1, { 0x9a } }, { 0x00, 1, { 0x00 } }, { 0x7f, 1, { 0x00 } }, { 0x00, 1, { 0x00 } }, { 0x7f, 1, { 0x00 } }, { 0x02, 1, { 0x8e } }, { 0x30, 1, { 0x1d } }, { 0x03, 1, { 0x1e } }, { 0x02, 1, { 0x01 } }, { 0x02, 1, { 0x00 } }, { ENDTBL_FLAG, 0x01, { 0x00 } } }; static td_s32 tas2564_init(const amp_platform_device *dev) { drv_amp_dev_hw_reset(dev, TD_TRUE); osal_msleep(AMP_TENMS_DELAY); /* release reset AMP */ drv_amp_dev_hw_reset(dev, TD_FALSE); osal_msleep(AMP_TENMS_DELAY); drv_amp_dev_write_reg_map(dev, g_tas2564_init_reg); return TD_SUCCESS; } static td_void tas2564_deinit(const amp_platform_device *dev) { drv_amp_dev_hw_reset(dev, TD_TRUE); } static td_s32 tas2564_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) ? TAS2564_MIN_VOL : TAS2564_MAX_VOL; if (channel_type != AMP_CHANNEL_TYPE_ALL) { /* need add by custom for gain */ } ret = amp_osal_i2c_write(&dev->i2c, TAS2564_MUTE_REG, &gain, 1); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(amp_osal_i2c_write, ret); return ret; } return ret; } static td_s32 tas2564_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, TAS2564_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 == TAS2564_MIN_VOL); } else { /* need add by custom */ } return TD_SUCCESS; } static td_void tas2564_dump_reg(const amp_platform_device *dev, td_void *file) { drv_amp_dev_dump_reg_map(dev, file, g_tas2564_init_reg); } static amp_platform_driver g_tas2564_driver = { .name = "TAS2564", .dev_type = EXT_DRV_AMP_TAS2564, .deinit = tas2564_deinit, .init = tas2564_init, .get_mute = tas2564_get_mute, .set_mute = tas2564_set_mute, .hw_mute = TD_NULL, .reset = TD_NULL, .get_active = TD_NULL, .dump_reg = tas2564_dump_reg, }; td_s32 tas2564_register_driver(td_void) { return amp_platform_driver_register(&g_tas2564_driver); } #ifdef __cplusplus } #endif /* __cplusplus */