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.
164 lines
4.1 KiB
164 lines
4.1 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2019-2019. All rights reserved.
|
|
* Description: amp device and driver ad83583
|
|
* 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 AD83586_MAX_VOL 0x00
|
|
#define AD83586_MIN_VOL 0x08 /* mute */
|
|
#define AD83586_MUTE_REG 0x02 /* master channel mute register */
|
|
|
|
static drv_amp_reg_map g_ad83586_init_reg[] = {
|
|
{ 0x00, 0x01, { 0x01 } }, /* i2s left aliment */
|
|
{ 0x01, 0x01, { 0x04 } },
|
|
{ 0x02, 0x01, { 0x00 } },
|
|
{ 0x03, 0x01, { 0x18 } },
|
|
{ 0x04, 0x01, { 0x04 } },
|
|
{ 0x05, 0x01, { 0x04 } },
|
|
{ 0x06, 0x01, { 0x07 } },
|
|
{ 0x07, 0x01, { 0x10 } },
|
|
{ 0x08, 0x01, { 0x10 } },
|
|
{ 0x09, 0x01, { 0x02 } },
|
|
{ 0x0A, 0x01, { 0x90 } },
|
|
{ 0x0B, 0x01, { 0x12 } },
|
|
{ 0x0C, 0x01, { 0x12 } },
|
|
{ 0x0D, 0x01, { 0x12 } },
|
|
{ 0x0E, 0x01, { 0x6A } },
|
|
{ 0x0F, 0x01, { 0x00 } },
|
|
{ 0x10, 0x01, { 0x06 } },
|
|
{ 0x11, 0x01, { 0x22 } },
|
|
{ 0x12, 0x01, { 0x80 } },
|
|
{ 0x13, 0x01, { 0x04 } },
|
|
{ 0x14, 0x01, { 0x74 } },
|
|
{ 0x15, 0x01, { 0x08 } },
|
|
{ 0x16, 0x01, { 0x00 } },
|
|
{ 0x17, 0x01, { 0x00 } },
|
|
{ 0x18, 0x01, { 0x00 } },
|
|
{ 0x19, 0x01, { 0x02 } },
|
|
{ 0x1A, 0x01, { 0x24 } },
|
|
{ 0x1B, 0x01, { 0x3E } },
|
|
{ 0x1C, 0x01, { 0x81 } },
|
|
{ 0x1D, 0x01, { 0x46 } },
|
|
{ 0x1E, 0x01, { 0xE1 } },
|
|
{ 0x1F, 0x01, { 0x76 } },
|
|
{ 0x20, 0x01, { 0x27 } },
|
|
{ 0x21, 0x01, { 0x00 } },
|
|
{ 0x22, 0x01, { 0x02 } },
|
|
{ 0x23, 0x01, { 0x24 } },
|
|
{ 0x24, 0x01, { 0x00 } },
|
|
{ 0x25, 0x01, { 0x00 } },
|
|
{ 0x26, 0x01, { 0x00 } },
|
|
{ 0x27, 0x01, { 0x3F } },
|
|
{ 0x28, 0x01, { 0x00 } },
|
|
{ 0x29, 0x01, { 0x00 } },
|
|
{ 0x2A, 0x01, { 0x0D } },
|
|
{ 0x2B, 0x01, { 0x54 } },
|
|
|
|
{ ENDTBL_FLAG, 0x01, { 0x00 } },
|
|
};
|
|
|
|
static td_s32 ad83586_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) ? AD83586_MIN_VOL : AD83586_MAX_VOL;
|
|
if (channel_type != AMP_CHANNEL_TYPE_ALL) {
|
|
/* need add by custom for gain */
|
|
}
|
|
|
|
ret = amp_osal_i2c_write(&dev->i2c, AD83586_MUTE_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 ad83586_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, AD83586_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 == AD83586_MIN_VOL);
|
|
} else {
|
|
/* need add by custom */
|
|
}
|
|
return TD_SUCCESS;
|
|
}
|
|
|
|
static td_s32 ad83586_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);
|
|
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_ad83586_init_reg);
|
|
|
|
ret = ad83586_set_mute(dev, AMP_CHANNEL_TYPE_ALL, TD_TRUE);
|
|
if (ret != TD_SUCCESS) {
|
|
soc_err_print_call_fun_err(ad83586_set_mute, ret);
|
|
return ret;
|
|
}
|
|
|
|
return TD_SUCCESS;
|
|
}
|
|
|
|
static td_void ad83586_deinit(const amp_platform_device *dev)
|
|
{
|
|
drv_amp_dev_hw_reset(dev, TD_TRUE);
|
|
}
|
|
|
|
static amp_platform_driver g_ad83586_driver = {
|
|
.name = "AD83586",
|
|
.dev_type = AMP_DEV_AD83586,
|
|
.deinit = ad83586_deinit,
|
|
.init = ad83586_init,
|
|
.get_mute = ad83586_get_mute,
|
|
.set_mute = ad83586_set_mute,
|
|
.hw_mute = drv_amp_dev_hw_mute,
|
|
.reset = TD_NULL,
|
|
.get_active = TD_NULL,
|
|
.dump_reg = TD_NULL,
|
|
};
|
|
|
|
td_s32 ad83586_register_driver(td_void)
|
|
{
|
|
return amp_platform_driver_register(&g_ad83586_driver);
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif /* __cplusplus */
|