You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.9 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2019-2019. All rights reserved.
* Description: amp device and driver ad82584
* 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 AD82584_MAX_VOL 0x00
#define AD82584_MIN_VOL 0xFF /* mute */
#define AD82584_MUTE_REG 0x02 /* master channel mute register */
static drv_amp_reg_map g_ad82584_init_reg[] = {
{ 0x02, 0x01, { 0x0f } }, /* mute */
{ 0x03, 0x01, { 0x18 } }, /* master vol default=0dB */
{ 0x04, 0x01, { 0x13 } }, /* CH1 vol default=2.5dB */
{ 0x05, 0x01, { 0x13 } }, /* CH2 vol default=2.5dB */
{ 0x07, 0x01, { 0x10 } }, /* bass_tone_control 12dB~-12dB 360Hz 0dB */
{ 0x08, 0x01, { 0x15 } }, /* treble_tone_control 12dB~-12dB 7kHz -5dB */
{ 0x09, 0x01, { 0x02 } }, /* bass_management_crossover_frequency 0x01=120Hz */
{ 0x0A, 0x01, { 0x98 } }, /* state_control_4(surround_off+bass_treble_off+eq_ch1to_ch2) */
{ 0x0B, 0x01, { 0x12 } }, /* CH1 DRC & power clipping enable RMS mode+HPF-off */
{ 0x0C, 0x01, { 0x12 } }, /* CH2 DRC & power clipping enable RMS mode+HPF-off */
{ 0x11, 0x01, { 0x30 } }, /* state_control_4(reset_off+mclk_on+power_saving_off+pwm_q_mode) */
{ 0x12, 0x01, { 0x81 } }, /* PVDD_UVP default=0x81=off+9.7V 0x01=on+9.7V */
/* noise gate SETTING */
{ 0x75, 0x03, { 0x00, 0x1a, 0x07 } }, /* noise gate ATH=-62d_b */
{ 0x76, 0x03, { 0x00, 0x20, 0xc4 } }, /* noise gate RTH=-60d_b */
{ ENDTBL_FLAG, 0x01, { 0x00 } },
};
static td_s32 ad82584_set_mute(const amp_platform_device *dev, amp_channel_type channel_type, td_bool mute)
{
td_s32 ret;
const td_u8 vol = (mute == TD_TRUE) ? AD82584_MIN_VOL : AD82584_MAX_VOL;
if (channel_type != AMP_CHANNEL_TYPE_ALL) {
/* need add by custom for gain */
}
ret = amp_osal_i2c_write(&dev->i2c, AD82584_MUTE_REG, &vol, 1);
if (ret != TD_SUCCESS) {
soc_err_print_call_fun_err(amp_osal_i2c_write, ret);
return ret;
}
return TD_SUCCESS;
}
static td_s32 ad82584_get_mute(const amp_platform_device *dev, amp_channel_type channel_type, td_bool *mute)
{
td_s32 ret;
td_u8 vol = 0;
if (mute == TD_NULL) {
return SOC_ERR_AMP_NULL_PTR;
}
ret = amp_osal_i2c_read(&dev->i2c, AD82584_MUTE_REG, &vol, 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 = (vol == AD82584_MIN_VOL);
} else {
/* need add by custom */
}
return TD_SUCCESS;
}
static td_s32 ad82584_init(const amp_platform_device *dev)
{
td_s32 ret;
drv_amp_dev_hw_mute(dev, TD_FALSE);
drv_amp_dev_hw_reset(dev, TD_FALSE);
/* release reset AMP */
osal_msleep(DELAY_20_MS);
drv_amp_dev_hw_reset(dev, TD_TRUE);
osal_msleep(DELAY_20_MS);
drv_amp_dev_hw_reset(dev, TD_FALSE);
osal_msleep(DELAY_20_MS);
drv_amp_dev_write_reg_map(dev, g_ad82584_init_reg);
ret = ad82584_set_mute(dev, AMP_CHANNEL_TYPE_ALL, TD_TRUE);
if (ret != TD_SUCCESS) {
soc_err_print_call_fun_err(ad82584_set_mute, ret);
return ret;
}
return TD_SUCCESS;
}
static td_void ad82584_deinit(const amp_platform_device *dev)
{
drv_amp_dev_hw_reset(dev, TD_TRUE);
}
static amp_platform_driver g_ad82584_driver = {
.name = "AD82584",
.dev_type = AMP_DEV_AD82584,
.deinit = ad82584_deinit,
.init = ad82584_init,
.get_mute = ad82584_get_mute,
.set_mute = ad82584_set_mute,
.hw_mute = drv_amp_dev_hw_mute,
.reset = TD_NULL,
.get_active = TD_NULL,
.dump_reg = TD_NULL,
};
td_s32 ad82584_register_driver(td_void)
{
return amp_platform_driver_register(&g_ad82584_driver);
}
#ifdef __cplusplus
}
#endif /* __cplusplus */