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.
219 lines
4.5 KiB
219 lines
4.5 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights reserved.
|
|
* Description: amp api reference.
|
|
* Author: audio
|
|
* Create: 2019-05-26
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdint.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <pthread.h>
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/poll.h>
|
|
|
|
#include "mpi_amp_debug.h"
|
|
#include "mpi_amp.h"
|
|
#include "uapi_amp.h"
|
|
#include "drv_ioctl_amp.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif /* __cplusplus */
|
|
|
|
#define DRV_AMP_DEVICE_NAME "soc_amp"
|
|
#define AMP_DEVICE_NAME "/dev/" DRV_AMP_DEVICE_NAME
|
|
|
|
static td_s32 g_amp_fd = -1;
|
|
|
|
td_s32 uapi_amp_init(uapi_amp_info *amp_info)
|
|
{
|
|
check_amp_null_ptr(amp_info);
|
|
|
|
if (g_amp_fd < 0) {
|
|
g_amp_fd = open(AMP_DEVICE_NAME, O_RDWR, 0);
|
|
if (g_amp_fd < 0) {
|
|
soc_log_fatal("Open AMP Device err\n");
|
|
g_amp_fd = -1;
|
|
return TD_FAILURE;
|
|
}
|
|
}
|
|
|
|
return ioctl(g_amp_fd, CMD_AMP_INIT);
|
|
}
|
|
|
|
td_s32 uapi_amp_deinit(td_void)
|
|
{
|
|
if (g_amp_fd > 0) {
|
|
close(g_amp_fd);
|
|
g_amp_fd = -1;
|
|
}
|
|
|
|
return TD_SUCCESS;
|
|
}
|
|
|
|
td_s32 uapi_amp_set_mute(td_bool mute)
|
|
{
|
|
return ioctl(g_amp_fd, CMD_AMP_SETMUTE, &mute);
|
|
}
|
|
|
|
td_s32 uapi_amp_get_mute(td_bool *mute)
|
|
{
|
|
td_s32 ret;
|
|
td_bool amp_mute = TD_FALSE;
|
|
|
|
check_amp_null_ptr(mute);
|
|
|
|
ret = ioctl(g_amp_fd, CMD_AMP_GETMUTE, &_mute);
|
|
if (ret == TD_SUCCESS) {
|
|
*mute = amp_mute;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
td_s32 uapi_amp_set_sub_woofer_volume(td_u32 volume)
|
|
{
|
|
return ioctl(g_amp_fd, CMD_AMP_SETSUBWOOFERVOL, &volume);
|
|
}
|
|
|
|
td_s32 uapi_amp_get_sub_woofer_volume(td_u32 *volume)
|
|
{
|
|
td_s32 ret;
|
|
td_u32 vol = 0;
|
|
|
|
check_amp_null_ptr(volume);
|
|
|
|
ret = ioctl(g_amp_fd, CMD_AMP_GETSUBWOOFERVOL, &vol);
|
|
if (ret == TD_SUCCESS) {
|
|
*volume = vol;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
td_s32 uapi_amp_write_reg(td_u32 reg_addr, td_u32 size, td_u8 *value)
|
|
{
|
|
amp_reg_operate_param reg_param = { 0 };
|
|
|
|
check_amp_null_ptr(value);
|
|
|
|
reg_param.reg_addr = reg_addr;
|
|
reg_param.byte_size = size;
|
|
reg_param.value_vir_addr = (td_u64)(uintptr_t)value;
|
|
|
|
return ioctl(g_amp_fd, CMD_AMP_WRITEREG, ®_param);
|
|
}
|
|
|
|
td_s32 uapi_amp_read_reg(td_u32 reg_addr, td_u32 size, td_u8 *value)
|
|
{
|
|
amp_reg_operate_param reg_param = { 0 };
|
|
|
|
check_amp_null_ptr(value);
|
|
|
|
reg_param.reg_addr = reg_addr;
|
|
reg_param.byte_size = size;
|
|
reg_param.value_vir_addr = (td_u64)(uintptr_t)value;
|
|
|
|
return ioctl(g_amp_fd, CMD_AMP_READREG, ®_param);
|
|
}
|
|
|
|
td_s32 uapi_amp_get_info(uapi_amp_multi_info *amp_multi_info)
|
|
{
|
|
check_amp_null_ptr(amp_multi_info);
|
|
|
|
return ioctl(g_amp_fd, CMD_AMP_GETINFO, amp_multi_info);
|
|
}
|
|
|
|
td_s32 uapi_amp_open(td_void)
|
|
{
|
|
if (g_amp_fd < 0) {
|
|
g_amp_fd = open(AMP_DEVICE_NAME, O_RDWR, 0);
|
|
if (g_amp_fd < 0) {
|
|
soc_log_fatal("Open amp Device err!\n");
|
|
g_amp_fd = -1;
|
|
return TD_FAILURE;
|
|
}
|
|
}
|
|
|
|
return ioctl(g_amp_fd, CMD_AMP_INIT);
|
|
}
|
|
|
|
td_s32 uapi_amp_close(td_void)
|
|
{
|
|
td_s32 ret;
|
|
|
|
if (g_amp_fd >= 0) {
|
|
ret = close(g_amp_fd);
|
|
if (ret != TD_SUCCESS) {
|
|
soc_err_print_call_fun_err(close, ret);
|
|
soc_err_print_s32(g_amp_fd);
|
|
}
|
|
|
|
g_amp_fd = -1;
|
|
}
|
|
|
|
return TD_SUCCESS;
|
|
}
|
|
|
|
td_s32 uapi_amp_mute_channel(td_u32 channel_mask, td_bool mute)
|
|
{
|
|
amp_mute_channel_param mute_channel;
|
|
|
|
mute_channel.channel_mask = channel_mask;
|
|
mute_channel.mute = mute;
|
|
return ioctl(g_amp_fd, CMD_AMP_MUTECHANNEL, &mute_channel);
|
|
}
|
|
|
|
td_s32 uapi_amp_get_channel_mute(td_u32 channel_mask, td_bool *mute)
|
|
{
|
|
td_s32 ret;
|
|
amp_mute_channel_param mute_channel = {
|
|
.channel_mask = channel_mask,
|
|
.mute = TD_FALSE,
|
|
};
|
|
|
|
check_amp_null_ptr(mute);
|
|
|
|
ret = ioctl(g_amp_fd, CMD_AMP_GET_CHANNELMUTE, &mute_channel);
|
|
if (ret != TD_SUCCESS) {
|
|
soc_log_err("ioctl CMD_AMP_GET_CHANNELMUTE failed\n");
|
|
soc_err_print_s32(ret);
|
|
}
|
|
|
|
*mute = mute_channel.mute;
|
|
return ret;
|
|
}
|
|
|
|
td_s32 uapi_amp_get_active_status(td_u32 amp_id, td_bool *active)
|
|
{
|
|
td_s32 ret;
|
|
amp_active_status_param active_status;
|
|
|
|
check_amp_null_ptr(active);
|
|
|
|
active_status.amp_id = amp_id;
|
|
|
|
ret = ioctl(g_amp_fd, CMD_AMP_GETACTIVESTATUS, &active_status);
|
|
if (ret == TD_SUCCESS) {
|
|
*active = active_status.active;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
td_s32 uapi_amp_reset(td_u32 amp_id)
|
|
{
|
|
return ioctl(g_amp_fd, CMD_AMP_RESET, &_id);
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif /* __cplusplus */
|
|
|