From 5193a047730f20ee64a288ca4cbc698a135df756 Mon Sep 17 00:00:00 2001 From: vb6174 Date: Mon, 16 Aug 2021 14:19:51 +0000 Subject: [PATCH 1/2] update audio code Signed-off-by: vb6174 --- .../common/include/audio_accessory_base.h | 69 + .../include/audio_codec_base.h} | 20 +- .../include/audio_platform_base.h} | 45 +- model/audio/common/src/audio_accessory_base.c | 75 ++ .../src/audio_codec_base.c} | 24 +- model/audio/common/src/audio_dsp_base.c | 0 model/audio/common/src/audio_platform_base.c | 74 ++ model/audio/core/include/audio_control.h | 8 +- model/audio/core/include/audio_core.h | 55 +- model/audio/core/include/audio_host.h | 22 +- model/audio/core/include/audio_parse.h | 2 +- model/audio/core/src/audio_core.c | 895 +++++++------ model/audio/core/src/audio_host.c | 217 +-- model/audio/core/src/audio_parse.c | 2 +- .../test/unittest/common/audio_common_test.h | 45 +- .../test/unittest/common/audio_core_test.cpp | 139 +- .../test/unittest/common/audio_host_test.cpp | 2 + .../test/unittest/common/audio_parse_test.cpp | 2 + .../accessory/include/accessory_adapter.h | 71 - model/audio/device/accessory/src/accessory.c | 99 -- .../device/codec/include/codec_adapter.h | 93 -- model/audio/device/codec/src/codec.c | 644 --------- model/audio/device/soc/include/dsp_adapter.h | 55 - .../device/soc/include/platform_adapter.h | 136 -- model/audio/device/soc/src/dai.c | 335 ----- model/audio/device/soc/src/dsp.c | 483 ------- model/audio/device/soc/src/platform.c | 1172 ----------------- .../dispatch/include/audio_control_dispatch.h | 3 +- .../dispatch/include/audio_stream_dispatch.h | 16 +- .../dispatch/src/audio_control_dispatch.c | 32 +- .../dispatch/src/audio_stream_dispatch.c | 308 ++++- .../common/audio_stream_dispatch_test.cpp | 6 - model/audio/sapm/include/audio_sapm.h | 15 +- model/audio/sapm/src/audio_sapm.c | 388 +++--- 34 files changed, 1576 insertions(+), 3976 deletions(-) create mode 100755 model/audio/common/include/audio_accessory_base.h rename model/audio/{core/include/codec_core.h => common/include/audio_codec_base.h} (40%) rename model/audio/{device/soc/include/dai_adapter.h => common/include/audio_platform_base.h} (32%) create mode 100755 model/audio/common/src/audio_accessory_base.c rename model/audio/{core/src/codec_core.c => common/src/audio_codec_base.c} (81%) create mode 100755 model/audio/common/src/audio_dsp_base.c create mode 100755 model/audio/common/src/audio_platform_base.c delete mode 100755 model/audio/device/accessory/include/accessory_adapter.h delete mode 100755 model/audio/device/accessory/src/accessory.c delete mode 100755 model/audio/device/codec/include/codec_adapter.h delete mode 100755 model/audio/device/codec/src/codec.c delete mode 100755 model/audio/device/soc/include/dsp_adapter.h delete mode 100755 model/audio/device/soc/include/platform_adapter.h delete mode 100755 model/audio/device/soc/src/dai.c delete mode 100755 model/audio/device/soc/src/dsp.c delete mode 100755 model/audio/device/soc/src/platform.c diff --git a/model/audio/common/include/audio_accessory_base.h b/model/audio/common/include/audio_accessory_base.h new file mode 100755 index 000000000..ab0f94a06 --- /dev/null +++ b/model/audio/common/include/audio_accessory_base.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef AUDIO_ACCESSORY_BASE_H +#define AUDIO_ACCESSORY_BASE_H + +#include "audio_host.h" +#include "audio_control.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +enum I2sFrequency { + I2S_SAMPLE_FREQUENCY_8000 = 8000, /* 8kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_11025 = 11025, /* 11.025kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_12000 = 12000, /* 12kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_16000 = 16000, /* 16kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_22050 = 22050, /* 22.050kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_24000 = 24000, /* 24kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_32000 = 32000, /* 32kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_44100 = 44100, /* 44.1kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_48000 = 48000, /* 48kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_64000 = 64000, /* 64kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_88200 = 88200, /* 88.2kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_96000 = 96000 /* 96kHz sample_rate */ +}; + +enum I2sFrequencyRegVal { + I2S_SAMPLE_FREQUENCY_REG_VAL_8000 = 0x0, /* 8kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_REG_VAL_11025 = 0x1, /* 11.025kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_REG_VAL_12000 = 0x2, /* 12kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_REG_VAL_16000 = 0x3, /* 16kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_REG_VAL_22050 = 0x4, /* 22.050kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_REG_VAL_24000 = 0x5, /* 24kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_REG_VAL_32000 = 0x6, /* 32kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_REG_VAL_44100 = 0x7, /* 44.1kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_REG_VAL_48000 = 0x8, /* 48kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_REG_VAL_64000 = 0x9, /* 64kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_REG_VAL_88200 = 0xA, /* 88.2kHz sample_rate */ + I2S_SAMPLE_FREQUENCY_REG_VAL_96000 = 0xB /* 96kHz sample_rate */ +}; + +enum I2sFormatRegVal { + I2S_SAMPLE_FORMAT_REG_VAL_MSB_24 = 0x2, /* MSB-justified data up to 24 bits */ + I2S_SAMPLE_FORMAT_REG_VAL_24 = 0x3, /* I2S data up to 24 bits */ + I2S_SAMPLE_FORMAT_REG_VAL_LSB_16 = 0x4, /* LSB-justified 16-bit data */ + I2S_SAMPLE_FORMAT_REG_VAL_LSB_18 = 0x5, /* LSB-justified 18-bit data */ + I2S_SAMPLE_FORMAT_REG_VAL_LSB_20 = 0x6, /* LSB-justified 20-bit data */ + I2S_SAMPLE_FORMAT_REG_VAL_LSB_24 = 0x7, /* LSB-justified 24-bit data */ +}; + +int32_t FormatToBitWidth(enum AudioFormat format, uint16_t *bitWidth); +int32_t RateToFrequency(uint32_t rate, uint16_t *freq); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif diff --git a/model/audio/core/include/codec_core.h b/model/audio/common/include/audio_codec_base.h similarity index 40% rename from model/audio/core/include/codec_core.h rename to model/audio/common/include/audio_codec_base.h index ddb49a548..f4d5bf3b3 100755 --- a/model/audio/core/include/codec_core.h +++ b/model/audio/common/include/audio_codec_base.h @@ -6,10 +6,10 @@ * See the LICENSE file in the root of this repository for complete details. */ -#ifndef CODEC_CORE_H -#define CODEC_CORE_H +#ifndef AUDIO_CODEC_BASE_H +#define AUDIO_CODEC_BASE_H -#include "codec_adapter.h" +#include "audio_codec_if.h" #include "audio_core.h" #include "osal_io.h" @@ -19,12 +19,12 @@ extern "C" { #endif #endif /* __cplusplus */ -int32_t CodecDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *value); -int32_t CodecDeviceWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t value); -int32_t AiaoDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *value); -int32_t AiaoDeviceWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t value); -int32_t CodecGetServiceName(struct HdfDeviceObject *device, const char **drvCodecName); -int32_t CodecGetDaiName(struct HdfDeviceObject *device, const char **drvDaiName); +int32_t CodecDeviceReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *value); +int32_t CodecDeviceWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t value); +int32_t CodecAiaoDeviceReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *value); +int32_t CodecAiaoDeviceWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t value); +int32_t CodecGetServiceName(const struct HdfDeviceObject *device, const char **drvCodecName); +int32_t CodecGetDaiName(const struct HdfDeviceObject *device, const char **drvDaiName); #ifdef __cplusplus #if __cplusplus @@ -32,4 +32,4 @@ int32_t CodecGetDaiName(struct HdfDeviceObject *device, const char **drvDaiName) #endif #endif /* __cplusplus */ -#endif /* CODEC_CORE_H */ +#endif diff --git a/model/audio/device/soc/include/dai_adapter.h b/model/audio/common/include/audio_platform_base.h similarity index 32% rename from model/audio/device/soc/include/dai_adapter.h rename to model/audio/common/include/audio_platform_base.h index d3d767f19..72a9608c0 100755 --- a/model/audio/device/soc/include/dai_adapter.h +++ b/model/audio/common/include/audio_platform_base.h @@ -6,8 +6,11 @@ * See the LICENSE file in the root of this repository for complete details. */ -#ifndef DAI_ADAPTER_H -#define DAI_ADAPTER_H +#ifndef AUDIO_PLATFORM_BASE_H +#define AUDIO_PLATFORM_BASE_H + +#include "audio_platform_if.h" +#include "audio_host.h" #ifdef __cplusplus #if __cplusplus @@ -15,34 +18,18 @@ extern "C" { #endif #endif /* __cplusplus */ -struct DaiDevice { - const char *devDaiName; - struct DaiData *devData; - struct HdfDeviceObject *device; - struct DListHead list; -}; - -struct AudioDaiOps { - int32_t (*Startup)(const struct AudioCard *, const struct DaiDevice *); - int32_t (*HwParams)(const struct AudioCard *, const struct AudioPcmHwParams *, const struct DaiDevice *); - int32_t (*Trigger)(const struct AudioCard *, int, const struct DaiDevice *); +enum DataBitWidth { + DATA_BIT_WIDTH8 = 8, /* 8 bit witdth */ + DATA_BIT_WIDTH16 = 16, /* 16 bit witdth */ + DATA_BIT_WIDTH18 = 18, /* 18 bit witdth */ + DATA_BIT_WIDTH20 = 20, /* 20 bit witdth */ + DATA_BIT_WIDTH24 = 24, /* 24 bit witdth */ + DATA_BIT_WIDTH32 = 32, /* 32 bit witdth */ }; -struct DaiData { - const char *drvDaiName; - /* DAI driver callbacks */ - int32_t (*DaiInit)(const struct AudioCard *, const struct DaiDevice *); - /* ops */ - const struct AudioDaiOps *ops; -}; - -/* Dai host is defined in dai driver */ -struct DaiHost { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - void *priv; - bool daiInitFlag; -}; +struct PlatformData *PlatformDataFromDevice(const struct AudioCard *card); +int32_t PlatformCreatePlatformHost(const struct AudioCard *card, struct PlatformHost **platformHost); +int32_t AudioDataBigEndianChange(char *srcData, uint32_t audioLen, enum DataBitWidth bitWidth); #ifdef __cplusplus #if __cplusplus @@ -50,4 +37,4 @@ struct DaiHost { #endif #endif /* __cplusplus */ -#endif +#endif /* CODEC_CORE_H */ diff --git a/model/audio/common/src/audio_accessory_base.c b/model/audio/common/src/audio_accessory_base.c new file mode 100755 index 000000000..715440022 --- /dev/null +++ b/model/audio/common/src/audio_accessory_base.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "audio_accessory_base.h" +#include "audio_device_log.h" + +#define HDF_LOG_TAG audio_accessory_base + +int32_t FormatToBitWidth(enum AudioFormat format, uint16_t *bitWidth) +{ + // current set default format(standard) for 16/24 bit + switch (format) { + case AUDIO_FORMAT_PCM_16_BIT: + *bitWidth = I2S_SAMPLE_FORMAT_REG_VAL_24; + break; + case AUDIO_FORMAT_PCM_24_BIT: + *bitWidth = I2S_SAMPLE_FORMAT_REG_VAL_24; + break; + default: + AUDIO_DEVICE_LOG_ERR("format: %d is not support.", format); + return HDF_ERR_NOT_SUPPORT; + } + return HDF_SUCCESS; +} + +int32_t RateToFrequency(uint32_t rate, uint16_t *freq) +{ + switch (rate) { + case I2S_SAMPLE_FREQUENCY_8000: + *freq = I2S_SAMPLE_FREQUENCY_REG_VAL_8000; + break; + case I2S_SAMPLE_FREQUENCY_11025: + *freq = I2S_SAMPLE_FREQUENCY_REG_VAL_11025; + break; + case I2S_SAMPLE_FREQUENCY_12000: + *freq = I2S_SAMPLE_FREQUENCY_REG_VAL_12000; + break; + case I2S_SAMPLE_FREQUENCY_16000: + *freq = I2S_SAMPLE_FREQUENCY_REG_VAL_16000; + break; + case I2S_SAMPLE_FREQUENCY_22050: + *freq = I2S_SAMPLE_FREQUENCY_REG_VAL_22050; + break; + case I2S_SAMPLE_FREQUENCY_24000: + *freq = I2S_SAMPLE_FREQUENCY_REG_VAL_24000; + break; + case I2S_SAMPLE_FREQUENCY_32000: + *freq = I2S_SAMPLE_FREQUENCY_REG_VAL_32000; + break; + case I2S_SAMPLE_FREQUENCY_44100: + *freq = I2S_SAMPLE_FREQUENCY_REG_VAL_44100; + break; + case I2S_SAMPLE_FREQUENCY_48000: + *freq = I2S_SAMPLE_FREQUENCY_REG_VAL_48000; + break; + case I2S_SAMPLE_FREQUENCY_64000: + *freq = I2S_SAMPLE_FREQUENCY_REG_VAL_64000; + break; + case I2S_SAMPLE_FREQUENCY_88200: + *freq = I2S_SAMPLE_FREQUENCY_REG_VAL_88200; + break; + case I2S_SAMPLE_FREQUENCY_96000: + *freq = I2S_SAMPLE_FREQUENCY_REG_VAL_96000; + break; + default: + AUDIO_DEVICE_LOG_ERR("rate: %d is not support.", rate); + return HDF_ERR_NOT_SUPPORT; + } + return HDF_SUCCESS; +} diff --git a/model/audio/core/src/codec_core.c b/model/audio/common/src/audio_codec_base.c similarity index 81% rename from model/audio/core/src/codec_core.c rename to model/audio/common/src/audio_codec_base.c index 22615f5b0..6d7d0a46d 100755 --- a/model/audio/core/src/codec_core.c +++ b/model/audio/common/src/audio_codec_base.c @@ -6,11 +6,11 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include "codec_core.h" +#include "audio_codec_base.h" -#define HDF_LOG_TAG codec_core +#define HDF_LOG_TAG audio_codec_base -int32_t CodecDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *val) +int32_t CodecDeviceReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val) { unsigned long acodecVir; struct VirtualAddress *virtualAdd = NULL; @@ -20,7 +20,7 @@ int32_t CodecDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *va AUDIO_DRIVER_LOG_ERR("input param codec or codec->device is NULL."); return HDF_ERR_INVALID_OBJECT; } - virtualAdd = (struct VirtualAddress *)codec->device->priv; + virtualAdd = (struct VirtualAddress *)((volatile uintptr_t)codec->device->priv); if (virtualAdd == NULL) { AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL."); return HDF_ERR_INVALID_OBJECT; @@ -32,7 +32,7 @@ int32_t CodecDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *va return HDF_SUCCESS; } -int32_t CodecDeviceWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t value) +int32_t CodecDeviceWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t value) { unsigned long acodecVir; struct VirtualAddress *virtualAdd = NULL; @@ -43,7 +43,7 @@ int32_t CodecDeviceWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t va return HDF_ERR_INVALID_OBJECT; } - virtualAdd = (struct VirtualAddress *)codec->device->priv; + virtualAdd = (struct VirtualAddress *)((volatile uintptr_t)codec->device->priv); if (virtualAdd == NULL) { AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL."); return HDF_ERR_INVALID_OBJECT; @@ -56,7 +56,7 @@ int32_t CodecDeviceWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t va return HDF_SUCCESS; } -int32_t AiaoDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *val) +int32_t CodecAiaoDeviceReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val) { unsigned long aiaoVir; struct VirtualAddress *virtualAdd = NULL; @@ -67,7 +67,7 @@ int32_t AiaoDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *val return HDF_ERR_INVALID_OBJECT; } - virtualAdd = (struct VirtualAddress *)codec->device->priv; + virtualAdd = (struct VirtualAddress *)((volatile uintptr_t)codec->device->priv); if (virtualAdd == NULL) { AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL."); return HDF_ERR_INVALID_OBJECT; @@ -80,7 +80,7 @@ int32_t AiaoDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *val return HDF_SUCCESS; } -int32_t AiaoDeviceWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t value) +int32_t CodecAiaoDeviceWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t value) { unsigned long aiaoVir; struct VirtualAddress *virtualAdd = NULL; @@ -90,7 +90,7 @@ int32_t AiaoDeviceWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t val AUDIO_DRIVER_LOG_ERR("codec or codec->device is NULL."); return HDF_ERR_INVALID_OBJECT; } - virtualAdd = (struct VirtualAddress *)codec->device->priv; + virtualAdd = (struct VirtualAddress *)((volatile uintptr_t)codec->device->priv); if (virtualAdd == NULL) { AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL."); return HDF_ERR_INVALID_OBJECT; @@ -103,7 +103,7 @@ int32_t AiaoDeviceWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t val return HDF_SUCCESS; } -int32_t CodecGetServiceName(struct HdfDeviceObject *device, const char **drvCodecName) +int32_t CodecGetServiceName(const struct HdfDeviceObject *device, const char **drvCodecName) { const struct DeviceResourceNode *node = NULL; struct DeviceResourceIface *drsOps = NULL; @@ -134,7 +134,7 @@ int32_t CodecGetServiceName(struct HdfDeviceObject *device, const char **drvCode return HDF_SUCCESS; } -int32_t CodecGetDaiName(struct HdfDeviceObject *device, const char **drvDaiName) +int32_t CodecGetDaiName(const struct HdfDeviceObject *device, const char **drvDaiName) { const struct DeviceResourceNode *node = NULL; struct DeviceResourceIface *drsOps = NULL; diff --git a/model/audio/common/src/audio_dsp_base.c b/model/audio/common/src/audio_dsp_base.c new file mode 100755 index 000000000..e69de29bb diff --git a/model/audio/common/src/audio_platform_base.c b/model/audio/common/src/audio_platform_base.c new file mode 100755 index 000000000..29337f0e4 --- /dev/null +++ b/model/audio/common/src/audio_platform_base.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "audio_platform_base.h" +#include "audio_core.h" + +#define HDF_LOG_TAG audio_platform_base + +struct PlatformData *PlatformDataFromDevice(const struct AudioCard *card) +{ + if (card == NULL || card->rtd == NULL || card->rtd->platform == NULL) { + AUDIO_DRIVER_LOG_ERR("param is null."); + return NULL; + } + return card->rtd->platform->devData; +} + +int32_t PlatformCreatePlatformHost(const struct AudioCard *card, struct PlatformHost **platformHost) +{ + if (platformHost == NULL) { + AUDIO_DRIVER_LOG_ERR("input param platformHost is invalid."); + return HDF_ERR_INVALID_PARAM; + } + if (card == NULL || card->rtd == NULL || card->rtd->platform == NULL) { + AUDIO_DRIVER_LOG_ERR("input para is NULL."); + return HDF_FAILURE; + } + + *platformHost = PlatformHostFromDevice(card->rtd->platform->device); + if (*platformHost == NULL) { + AUDIO_DRIVER_LOG_ERR("PlatformHostFromDevice faile."); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t AudioDataBigEndianChange(char *srcData, uint32_t audioLen, enum DataBitWidth bitWidth) +{ + uint64_t i; + uint16_t framesize; + char temp; + if (srcData == NULL) { + AUDIO_DRIVER_LOG_ERR("srcData is NULL."); + return HDF_FAILURE; + } + + switch (bitWidth) { + case DATA_BIT_WIDTH8: + framesize = 1; /* 1 byte */ + break; + case DATA_BIT_WIDTH16: + framesize = 2; /* 2 bytes */ + break; + case DATA_BIT_WIDTH24: + framesize = 3; /* 3 bytes */ + break; + default: + framesize = 2; /* default 2 bytes */ + break; + } + + for (i = 0; i < audioLen; i += framesize) { + temp = srcData[i]; + srcData[i] = srcData[i + framesize - 1]; + srcData[i + framesize - 1] = temp; + } + AUDIO_DRIVER_LOG_DEBUG("audioLen = %d\n", audioLen); + return HDF_SUCCESS; +} diff --git a/model/audio/core/include/audio_control.h b/model/audio/core/include/audio_control.h index fa88b7ead..6ef26082b 100755 --- a/model/audio/core/include/audio_control.h +++ b/model/audio/core/include/audio_control.h @@ -35,13 +35,13 @@ struct AudioCtrlElemInfo { struct AudioCtrlElemValue { struct AudioCtrlElemId id; - int32_t value[2]; + uint32_t value[2]; }; struct AudioKcontrol; -typedef int32_t (*KconfigInfo_t)(struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo); -typedef int32_t (*KconfigGet_t)(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); -typedef int32_t (*KconfigSet_t)(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +typedef int32_t (*KconfigInfo_t)(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo); +typedef int32_t (*KconfigGet_t)(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +typedef int32_t (*KconfigSet_t)(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue); /* mixer control */ struct AudioMixerControl { diff --git a/model/audio/core/include/audio_core.h b/model/audio/core/include/audio_core.h index b82439c93..6235bbb7a 100755 --- a/model/audio/core/include/audio_core.h +++ b/model/audio/core/include/audio_core.h @@ -11,11 +11,11 @@ #include "audio_host.h" #include "audio_control.h" -#include "codec_adapter.h" -#include "platform_adapter.h" -#include "dai_adapter.h" -#include "accessory_adapter.h" -#include "dsp_adapter.h" +#include "audio_codec_if.h" +#include "audio_platform_if.h" +#include "audio_dai_if.h" +#include "audio_accessory_if.h" +#include "audio_dsp_if.h" #ifdef __cplusplus #if __cplusplus @@ -65,28 +65,43 @@ int32_t AudioSocRegisterDai(struct HdfDeviceObject *device, struct DaiData *data int32_t AudioSocRegisterPlatform(struct HdfDeviceObject *device, struct PlatformData *data); /* Codec registration interface */ int32_t AudioRegisterCodec(struct HdfDeviceObject *device, struct CodecData *codecData, struct DaiData *daiData); -int32_t AudioBindDaiLink(struct AudioCard *audioCard, struct AudioConfigData *configData); +int32_t AudioBindDaiLink(struct AudioCard *audioCard, const struct AudioConfigData *configData); int32_t AudioSocDeviceRegister(struct HdfDeviceObject *device, void *data, enum AudioDeviceType deviceType); int32_t AudioSocRegisterDsp(struct HdfDeviceObject *device, struct DaiData *data); int32_t AudioRegisterAccessory(struct HdfDeviceObject *device, struct AccessoryData *data, struct DaiData *daiData); -int32_t AudioUpdateRegBits(enum AudioDeviceType deviceType, void *device, - struct AudioMixerControl *mixerControl, int32_t value); -int32_t AudioAiaoUpdateRegBits(struct CodecDevice *codec, uint32_t reg, uint32_t mask, uint32_t shift, int32_t value); +int32_t AudioUpdateCodecRegBits(struct CodecDevice *codec, + const struct AudioMixerControl *mixerControl, uint32_t value); +int32_t AudioUpdateAccessoryRegBits(struct AccessoryDevice *accessory, + const struct AudioMixerControl *mixerControl, uint32_t value); +int32_t AudioUpdateCodecAiaoRegBits(struct CodecDevice *codec, const struct AudioMixerControl *mixerControl, + uint32_t value); +int32_t AudioUpdateAccessoryAiaoRegBits(struct AccessoryDevice *accessory, + const struct AudioMixerControl *mixerControl, uint32_t value); struct CodecDevice *AudioKcontrolGetCodec(const struct AudioKcontrol *kcontrol); struct AccessoryDevice *AudioKcontrolGetAccessory(const struct AudioKcontrol *kcontrol); -extern int32_t AudioAddControls(struct AudioCard *audioCard, +int32_t AudioAddControls(struct AudioCard *audioCard, const struct AudioKcontrol *controls, int32_t controlMaxNum); -extern struct AudioKcontrol *AudioAddControl(const struct AudioCard *audioCard, const struct AudioKcontrol *ctl); -extern int32_t AudioCodecDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *val); -extern int32_t AudioAccessoryDeviceReadReg(struct AccessoryDevice *accessory, uint32_t reg, uint32_t *val); -extern int32_t AudioAiaoDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *val); +struct AudioKcontrol *AudioAddControl(const struct AudioCard *audioCard, const struct AudioKcontrol *ctl); -extern int32_t AudioInfoCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo); -extern int32_t AudioGetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); -extern int32_t AudioSetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); -extern int32_t AiaoGetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); -extern int32_t AiaoSetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); -int32_t AudioRegisterDeviceDsp(struct HdfDeviceObject *device, struct DspData *dspData, struct DaiData *DaiData); +int32_t AudioCodecReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val); +int32_t AudioCodecWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t val); +int32_t AudioAccessoryReadReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t *val); +int32_t AudioAccessoryWriteReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t val); +int32_t AudioCodecAiaoReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val); +int32_t AudioCodecAiaoWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t val); +int32_t AudioAccessoryAiaoReadReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t *val); +int32_t AudioAccessoryAiaoWriteReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t val); + +int32_t AudioInfoCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo); +int32_t AudioCodecGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +int32_t AudioCodecSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue); +int32_t AudioAccessoryGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +int32_t AudioAccessorySetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue); +int32_t AudioCodecAiaoGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +int32_t AudioCodecAiaoSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue); +int32_t AudioAccessoryAiaoGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +int32_t AudioAccessoryAiaoSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue); +int32_t AudioRegisterDsp(struct HdfDeviceObject *device, struct DspData *dspData, struct DaiData *DaiData); #ifdef __cplusplus #if __cplusplus } diff --git a/model/audio/core/include/audio_host.h b/model/audio/core/include/audio_host.h index 405708cfb..5435db60a 100755 --- a/model/audio/core/include/audio_host.h +++ b/model/audio/core/include/audio_host.h @@ -75,6 +75,9 @@ struct AudioCard { struct DListHead components; /* all components for this card */ struct DListHead paths; /* all paths for this card */ struct DListHead sapmDirty; /* all dirty for this card */ + bool sapmSleepState; + bool sapmStandbyState; + bool sapmMonitorState; }; enum CriBuffStatus { @@ -130,6 +133,24 @@ struct AudioRxData { unsigned long frames; /* frames number */ }; +struct AudioTxMmapData { + void *memoryAddress; /**< Pointer to the mmap buffer */ + int32_t memoryFd; /**< File descriptor of the mmap buffer */ + int32_t totalBufferFrames; /**< Total size of the mmap buffer (unit: frame )*/ + int32_t transferFrameSize; /**< Transfer size (unit: frame) */ + int32_t isShareable; /**< Whether the mmap buffer can be shared among processes */ + uint32_t offset; +}; + +struct AudioRxMmapData { + void *memoryAddress; /**< Pointer to the mmap buffer */ + int32_t memoryFd; /**< File descriptor of the mmap buffer */ + int32_t totalBufferFrames; /**< Total size of the mmap buffer (unit: frame )*/ + int32_t transferFrameSize; /**< Transfer size (unit: frame) */ + int32_t isShareable; /**< Whether the mmap buffer can be shared among processes */ + uint32_t offset; +}; + struct AudioRuntimeDeivces { /* runtime devices */ struct CodecDevice *codec; @@ -147,7 +168,6 @@ struct AudioRuntimeDeivces { }; struct AudioHost *AudioHostCreateAndBind(struct HdfDeviceObject *device); -void AudioHostDestroy(struct AudioHost *host); static inline struct HdfDeviceObject *AudioHostToDevice(struct AudioHost *host) { diff --git a/model/audio/core/include/audio_parse.h b/model/audio/core/include/audio_parse.h index 03c931289..9ded34ee9 100755 --- a/model/audio/core/include/audio_parse.h +++ b/model/audio/core/include/audio_parse.h @@ -17,7 +17,7 @@ extern "C" { #endif #endif /* __cplusplus */ -int32_t AudioFillConfigData(struct HdfDeviceObject *device, struct AudioConfigData *configData); +int32_t AudioFillConfigData(const struct HdfDeviceObject *device, struct AudioConfigData *configData); #ifdef __cplusplus #if __cplusplus diff --git a/model/audio/core/src/audio_core.c b/model/audio/core/src/audio_core.c index 302f736c2..fb3581ed4 100755 --- a/model/audio/core/src/audio_core.c +++ b/model/audio/core/src/audio_core.c @@ -16,30 +16,6 @@ AUDIO_LIST_HEAD(codecController); AUDIO_LIST_HEAD(dspController); AUDIO_LIST_HEAD(accessoryController); -int32_t AudioSocRegisterDsp(struct HdfDeviceObject *device, struct DaiData *data) -{ - struct DaiDevice *dsp = NULL; - - if ((device == NULL) || (data == NULL)) { - ADM_LOG_ERR("Input params check error: device=%p, data=%p.", device, data); - return HDF_ERR_INVALID_OBJECT; - } - - dsp = (struct DaiDevice *)OsalMemCalloc(sizeof(*dsp)); - if (dsp == NULL) { - ADM_LOG_ERR("Malloc dsp device fail!"); - return HDF_ERR_MALLOC_FAIL; - } - - dsp->devDaiName = data->drvDaiName; - dsp->devData = data; - dsp->device = device; - DListInsertHead(&dsp->list, &daiController); - ADM_LOG_INFO("Register [%s] success.", dsp->devDaiName); - - return HDF_SUCCESS; -} - int32_t AudioSocRegisterPlatform(struct HdfDeviceObject *device, struct PlatformData *data) { struct PlatformDevice *platform = NULL; @@ -155,6 +131,39 @@ int32_t AudioRegisterCodec(struct HdfDeviceObject *device, struct CodecData *cod return HDF_SUCCESS; } +int32_t AudioRegisterDsp(struct HdfDeviceObject *device, struct DspData *dspData, struct DaiData *DaiData) +{ + struct DspDevice *dspDev = NULL; + int32_t ret; + + if ((device == NULL) || (dspData == NULL) || (DaiData == NULL)) { + ADM_LOG_ERR("Input params check error: device=%p, dspData=%p, daiData=%p.", + device, dspData, DaiData); + return HDF_ERR_INVALID_OBJECT; + } + + dspDev = (struct DspDevice *)OsalMemCalloc(sizeof(*dspDev)); + if (dspDev == NULL) { + ADM_LOG_ERR("Malloc codec device fail!"); + return HDF_ERR_MALLOC_FAIL; + } + + dspDev->devDspName = dspData->drvDspName; + dspDev->devData = dspData; + dspDev->device = device; + + ret = AudioSocDeviceRegister(device, (void *)DaiData, AUDIO_DAI_DEVICE); + if (ret != HDF_SUCCESS) { + OsalMemFree(dspDev); + ADM_LOG_ERR("Register dai device fail ret=%d", ret); + return HDF_ERR_IO; + } + DListInsertHead(&dspDev->list, &dspController); + ADM_LOG_INFO("Register [%s] success.", dspDev->devDspName); + + return HDF_SUCCESS; +} + int32_t AudioSocDeviceRegister(struct HdfDeviceObject *device, void *data, enum AudioDeviceType deviceType) { struct PlatformData *platformData = NULL; @@ -177,15 +186,6 @@ int32_t AudioSocDeviceRegister(struct HdfDeviceObject *device, void *data, enum } break; } - case AUDIO_DSP_DEVICE: { - daiData = (struct DaiData *)data; - ret = AudioSocRegisterDsp(device, daiData); - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("Register dsp device fail ret=%d", ret); - return HDF_FAILURE; - } - break; - } case AUDIO_PLATFORM_DEVICE: { platformData = (struct PlatformData *)data; ret = AudioSocRegisterPlatform(device, platformData); @@ -204,76 +204,76 @@ int32_t AudioSocDeviceRegister(struct HdfDeviceObject *device, void *data, enum return HDF_SUCCESS; } -void AudioSeekPlatformDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) +int32_t AudioSeekPlatformDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) { - const struct AudioConfigData *data = configData; struct PlatformDevice *platform = NULL; - - if (rtd == NULL || data == NULL) { - ADM_LOG_ERR("Input params check error: rtd=%p, data=%p.", rtd, data); - return; + if (rtd == NULL || configData == NULL) { + ADM_LOG_ERR("Input params check error: rtd=%p, configData=%p.", rtd, configData); + return HDF_ERR_INVALID_OBJECT; } - if (data->platformName == NULL) { - ADM_LOG_ERR("Input devicesName check error: data->platformName is NULL."); - return; + if (configData->platformName == NULL) { + ADM_LOG_ERR("Input devicesName check error: configData->platformName is NULL."); + return HDF_ERR_INVALID_OBJECT; } DLIST_FOR_EACH_ENTRY(platform, &platformController, struct PlatformDevice, list) { if (platform != NULL && platform->devPlatformName != NULL && - strcmp(platform->devPlatformName, data->platformName) == 0) { + strcmp(platform->devPlatformName, configData->platformName) == 0) { rtd->platform = platform; break; } } - return; + + return HDF_SUCCESS; } -void AudioSeekCpuDaiDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) +int32_t AudioSeekCpuDaiDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) { - const struct AudioConfigData *data = configData; struct DaiDevice *cpuDai = NULL; - - if (rtd == NULL || data == NULL) { - ADM_LOG_ERR("Input params check error: rtd=%p, data=%p.", rtd, data); - return; + if (rtd == NULL || configData == NULL) { + ADM_LOG_ERR("Input params check error: rtd=%p, configData=%p.", rtd, configData); + return HDF_ERR_INVALID_OBJECT; } - if (data->cpuDaiName == NULL) { - ADM_LOG_ERR("Input cpuDaiName check error: data->cpuDaiName is NULL."); - return; + if (configData->cpuDaiName == NULL) { + ADM_LOG_ERR("Input cpuDaiName check error: configData->cpuDaiName is NULL."); + return HDF_ERR_INVALID_OBJECT; } + if (DListIsEmpty(&daiController)) { + ADM_LOG_ERR("daiController is empty."); + return HDF_FAILURE; + } DLIST_FOR_EACH_ENTRY(cpuDai, &daiController, struct DaiDevice, list) { - if (cpuDai != NULL && cpuDai->devDaiName != NULL && strcmp(cpuDai->devDaiName, data->cpuDaiName) == 0) { + if (cpuDai != NULL && cpuDai->devDaiName != NULL && + strcmp(cpuDai->devDaiName, configData->cpuDaiName) == 0) { rtd->cpuDai = cpuDai; break; } } - return; + + return HDF_SUCCESS; } -void AudioSeekCodecDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) +int32_t AudioSeekCodecDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) { - const struct AudioConfigData *data = configData; struct CodecDevice *codec = NULL; struct DaiDevice *codecDai = NULL; - - if ((rtd == NULL) || (data == NULL)) { - ADM_LOG_ERR("Input params check error: rtd=%p, data=%p.", rtd, data); - return; + if ((rtd == NULL) || (configData == NULL)) { + ADM_LOG_ERR("Input params check error: rtd=%p, configData=%p.", rtd, configData); + return HDF_ERR_INVALID_OBJECT; } - if (data->codecName == NULL || data->codecDaiName == NULL) { - ADM_LOG_ERR("Input devicesName check error: data->codecName=%p, data->codecDaiName=%p.", - data->codecName, data->codecDaiName); - return; + if (configData->codecName == NULL || configData->codecDaiName == NULL) { + ADM_LOG_ERR("Input devicesName check error: configData->codecName=%p, configData->codecDaiName=%p.", + configData->codecName, configData->codecDaiName); + return HDF_ERR_INVALID_OBJECT; } DLIST_FOR_EACH_ENTRY(codec, &codecController, struct CodecDevice, list) { - if (codec != NULL && codec->devCodecName != NULL && strcmp(codec->devCodecName, data->codecName) == 0) { + if (codec != NULL && codec->devCodecName != NULL && strcmp(codec->devCodecName, configData->codecName) == 0) { rtd->codec = codec; - DLIST_FOR_EACH_ENTRY(codecDai, &daiController, struct DaiDevice, list) { if (codecDai != NULL && codecDai->device != NULL && codec->device == codecDai->device && - strcmp(codecDai->devDaiName, data->codecDaiName) == 0) { + codecDai->devDaiName != NULL && strcmp(codecDai->devDaiName, configData->codecDaiName) == 0) { rtd->codecDai = codecDai; break; } @@ -281,32 +281,32 @@ void AudioSeekCodecDevice(struct AudioRuntimeDeivces *rtd, const struct AudioCon break; } } - return; + + return HDF_SUCCESS; } -void AudioSeekAccessoryDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) +int32_t AudioSeekAccessoryDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) { - const struct AudioConfigData *data = configData; struct AccessoryDevice *accessory = NULL; struct DaiDevice *accessoryDai = NULL; - - if (rtd == NULL || data == NULL) { - ADM_LOG_ERR("Input params check error: rtd=%p, data=%p.", rtd, data); - return; + if (rtd == NULL || configData == NULL) { + ADM_LOG_ERR("Input params check error: rtd=%p, configData=%p.", rtd, configData); + return HDF_ERR_INVALID_OBJECT; } - if (data->accessoryName == NULL) { - ADM_LOG_ERR("Input devicesName check error: data->accessoryName is NULL."); - return; + if (configData->accessoryName == NULL || configData->accessoryDaiName == NULL) { + ADM_LOG_ERR("Input devicesName check error: configData->accessoryName or" + "configData->accessoryDaiName is NULL."); + return HDF_ERR_INVALID_OBJECT; } DLIST_FOR_EACH_ENTRY(accessory, &accessoryController, struct AccessoryDevice, list) { if (accessory != NULL && accessory->devAccessoryName != NULL && - strcmp(accessory->devAccessoryName, data->accessoryName) == 0) { + strcmp(accessory->devAccessoryName, configData->accessoryName) == 0) { rtd->accessory = accessory; - DLIST_FOR_EACH_ENTRY(accessoryDai, &daiController, struct DaiDevice, list) { - if (accessoryDai != NULL && accessoryDai->device != NULL && accessory->device == accessoryDai->device && - strcmp(accessoryDai->devDaiName, data->accessoryDaiName) == 0) { + if (accessoryDai != NULL && accessoryDai->device != NULL && + accessory->device == accessoryDai->device && accessoryDai->devDaiName != NULL && + strcmp(accessoryDai->devDaiName, configData->accessoryDaiName) == 0) { rtd->accessoryDai = accessoryDai; break; } @@ -314,31 +314,30 @@ void AudioSeekAccessoryDevice(struct AudioRuntimeDeivces *rtd, const struct Audi break; } } - return; + + return HDF_SUCCESS; } -void AudioSeekDspDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) +int32_t AudioSeekDspDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) { - const struct AudioConfigData *data = configData; struct DspDevice *dsp = NULL; struct DaiDevice *dspDai = NULL; - - if ((rtd == NULL) || (data == NULL)) { - ADM_LOG_ERR("Input params check error: rtd=%p, data=%p.", rtd, data); - return; + if ((rtd == NULL) || (configData == NULL)) { + ADM_LOG_ERR("Input params check error: rtd=%p, configData=%p.", rtd, configData); + return HDF_ERR_INVALID_OBJECT; } - if (data->dspName == NULL || data->dspDaiName == NULL) { - ADM_LOG_ERR("Input devicesName check error: data->dspName=%p, data->dspDaiName=%p.", - data->codecName, data->codecDaiName); - return; + if (configData->dspName == NULL || configData->dspDaiName == NULL) { + ADM_LOG_ERR("Input devicesName check error: configData->dspName=%p, configData->dspDaiName=%p.", + configData->dspName, configData->dspDaiName); + return HDF_ERR_INVALID_OBJECT; } DLIST_FOR_EACH_ENTRY(dsp, &dspController, struct DspDevice, list) { - if (dsp != NULL && dsp->devDspName != NULL && strcmp(dsp->devDspName, data->dspName) == 0) { + if (dsp != NULL && dsp->devDspName != NULL && strcmp(dsp->devDspName, configData->dspName) == 0) { rtd->dsp = dsp; DLIST_FOR_EACH_ENTRY(dspDai, &daiController, struct DaiDevice, list) { if (dspDai != NULL && dspDai->device != NULL && dsp->device == dspDai->device && - strcmp(dspDai->devDaiName, data->dspDaiName) == 0) { + dspDai->devDaiName != NULL && strcmp(dspDai->devDaiName, configData->dspDaiName) == 0) { rtd->dspDai = dspDai; break; } @@ -346,13 +345,12 @@ void AudioSeekDspDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfi break; } } - return; + + return HDF_SUCCESS; } -int32_t AudioBindDaiLink(struct AudioCard *audioCard, struct AudioConfigData *configData) +int32_t AudioBindDaiLink(struct AudioCard *audioCard, const struct AudioConfigData *configData) { - int32_t ret; - if ((audioCard == NULL) || (configData == NULL)) { ADM_LOG_ERR("Input params check error: audioCard=%p, configData=%p.", audioCard, configData); return HDF_ERR_INVALID_OBJECT; @@ -365,51 +363,34 @@ int32_t AudioBindDaiLink(struct AudioCard *audioCard, struct AudioConfigData *co } audioCard->rtd->complete = AUDIO_DAI_LINK_UNCOMPLETE; + if (AudioSeekPlatformDevice(audioCard->rtd, configData) == HDF_SUCCESS) { + ADM_LOG_DEBUG("PLATFORM [%s] is registered!", configData->platformName); + } + if (AudioSeekCpuDaiDevice(audioCard->rtd, configData) == HDF_SUCCESS) { + ADM_LOG_DEBUG("CPU DAI [%s] is registered!", configData->cpuDaiName); + } + if (AudioSeekCodecDevice(audioCard->rtd, configData) == HDF_SUCCESS) { + ADM_LOG_DEBUG("CODEC [%s] is registered!", configData->codecName); + } + if (AudioSeekAccessoryDevice(audioCard->rtd, configData) == HDF_SUCCESS) { + ADM_LOG_DEBUG("CODEC [%s] is registered!", configData->accessoryName); + } + if (AudioSeekDspDevice(audioCard->rtd, configData) == HDF_SUCCESS) { + ADM_LOG_DEBUG("CODEC [%s] is registered!", configData->dspName); + } + audioCard->rtd->complete = AUDIO_DAI_LINK_COMPLETE; + ADM_LOG_DEBUG("All devices register complete!"); - AudioSeekPlatformDevice(audioCard->rtd, configData); - AudioSeekCpuDaiDevice(audioCard->rtd, configData); - AudioSeekCodecDevice(audioCard->rtd, configData); - AudioSeekAccessoryDevice(audioCard->rtd, configData); - AudioSeekDspDevice(audioCard->rtd, configData); - if (!audioCard->rtd->codec && !audioCard->rtd->accessory) { - OsalMemFree(audioCard->rtd); - ret = HDF_FAILURE; - ADM_LOG_DEBUG("CODEC [%s] not registered!", configData->codecName); - } else if (!audioCard->rtd->codecDai && !audioCard->rtd->accessoryDai) { - OsalMemFree(audioCard->rtd); - ret = HDF_FAILURE; - ADM_LOG_DEBUG("CODEC DAI [%s] not registered!", configData->codecDaiName); - } else if (!audioCard->rtd->platform) { - OsalMemFree(audioCard->rtd); - ret = HDF_FAILURE; - ADM_LOG_DEBUG("Platform [%s] not registered!", configData->platformName); - } else if (!audioCard->rtd->cpuDai) { - OsalMemFree(audioCard->rtd); - ret = HDF_FAILURE; - ADM_LOG_DEBUG("CPU DAI [%s] not registered!", configData->cpuDaiName); - } else if (!audioCard->rtd->dsp) { - OsalMemFree(audioCard->rtd); - ret = HDF_FAILURE; - ADM_LOG_ERR("DSP [%s] not registered!", configData->dspName); - } else if (!audioCard->rtd->dspDai) { - OsalMemFree(audioCard->rtd); - ret = HDF_FAILURE; - ADM_LOG_ERR("DSP DAI [%s] not registered!", configData->dspDaiName); - } else { - audioCard->rtd->complete = AUDIO_DAI_LINK_COMPLETE; - ret = HDF_SUCCESS; - ADM_LOG_DEBUG("All devices register complete!"); - } - - return ret; + return HDF_SUCCESS; } -int32_t AudioUpdateCodecRegBits(struct CodecDevice *codec, struct AudioMixerControl *mixerControl, int32_t value) +int32_t AudioUpdateCodecRegBits(struct CodecDevice *codec, + const struct AudioMixerControl *mixerControl, uint32_t value) { int32_t ret; - uint32_t curValue = 0; - int32_t mixerControlMask; - if (codec == NULL || codec->devData == NULL || codec->devData->Write == NULL || mixerControl == NULL) { + uint32_t curValue; + uint32_t mixerControlMask; + if (codec == NULL || mixerControl == NULL) { ADM_LOG_ERR("Invalid accessory param."); return HDF_ERR_INVALID_OBJECT; } @@ -418,14 +399,15 @@ int32_t AudioUpdateCodecRegBits(struct CodecDevice *codec, struct AudioMixerCont mixerControlMask = mixerControl->mask << mixerControl->shift; OsalMutexLock(&codec->mutex); - ret = AudioCodecDeviceReadReg(codec, mixerControl->reg, &curValue); + ret = AudioCodecReadReg(codec, mixerControl->reg, &curValue); if (ret != HDF_SUCCESS) { OsalMutexUnlock(&codec->mutex); ADM_LOG_ERR("Read reg fail ret=%d.", ret); return HDF_FAILURE; } + curValue = (curValue & ~mixerControlMask) | (value & mixerControlMask); - ret = codec->devData->Write(codec, mixerControl->reg, curValue); + ret = AudioCodecWriteReg(codec, mixerControl->reg, curValue); if (ret != HDF_SUCCESS) { OsalMutexUnlock(&codec->mutex); ADM_LOG_ERR("Write reg fail ret=%d", ret); @@ -438,13 +420,12 @@ int32_t AudioUpdateCodecRegBits(struct CodecDevice *codec, struct AudioMixerCont } int32_t AudioUpdateAccessoryRegBits(struct AccessoryDevice *accessory, - struct AudioMixerControl *mixerControl, int32_t value) + const struct AudioMixerControl *mixerControl, uint32_t value) { int32_t ret; - uint32_t curValue = 0; - int32_t mixerControlMask; - if (accessory == NULL || accessory->devData == NULL || - accessory->devData->Write == NULL || mixerControl == NULL) { + uint32_t curValue; + uint32_t mixerControlMask; + if (accessory == NULL || mixerControl == NULL) { ADM_LOG_ERR("Invalid accessory param."); return HDF_ERR_INVALID_OBJECT; } @@ -453,14 +434,14 @@ int32_t AudioUpdateAccessoryRegBits(struct AccessoryDevice *accessory, mixerControlMask = mixerControl->mask << mixerControl->shift; OsalMutexLock(&accessory->mutex); - ret = AudioAccessoryDeviceReadReg(accessory, mixerControl->reg, &curValue); + ret = AudioAccessoryReadReg(accessory, mixerControl->reg, &curValue); if (ret != HDF_SUCCESS) { OsalMutexUnlock(&accessory->mutex); ADM_LOG_ERR("Read reg fail ret=%d", ret); return HDF_FAILURE; } curValue = (curValue & ~mixerControlMask) | (value & mixerControlMask); - ret = accessory->devData->Write(accessory, mixerControl->reg, curValue); + ret = AudioAccessoryWriteReg(accessory, mixerControl->reg, curValue); if (ret != HDF_SUCCESS) { OsalMutexUnlock(&accessory->mutex); ADM_LOG_ERR("Write reg fail ret=%d", ret); @@ -472,65 +453,75 @@ int32_t AudioUpdateAccessoryRegBits(struct AccessoryDevice *accessory, return HDF_SUCCESS; } -int32_t AudioUpdateRegBits(enum AudioDeviceType deviceType, void *device, - struct AudioMixerControl *mixerControl, int32_t value) +int32_t AudioUpdateCodecAiaoRegBits(struct CodecDevice *codec, + const struct AudioMixerControl *mixerControl, uint32_t value) { int32_t ret; - struct CodecDevice *codec = NULL; - struct AccessoryDevice *accessory = NULL; - ADM_LOG_DEBUG("Entry."); + uint32_t curValue; + uint32_t mixerControlMask; + ADM_LOG_DEBUG("Entry to update AIAO codec reg bits."); - switch (deviceType) { - case AUDIO_CODEC_DEVICE: { - codec = (struct CodecDevice *)device; - ret = AudioUpdateCodecRegBits(codec, mixerControl, value); - break; - } - case AUDIO_ACCESSORY_DEVICE: { - accessory = (struct AccessoryDevice *)device; - ret = AudioUpdateAccessoryRegBits(accessory, mixerControl, value); - break; - } - default: { - ADM_LOG_ERR("Invalid device type."); - return HDF_FAILURE; - } + if (codec == NULL || mixerControl == NULL) { + ADM_LOG_ERR("Invalid AIAO codec param."); + return HDF_ERR_INVALID_OBJECT; } - return ret; + value = value << mixerControl->shift; + mixerControlMask = mixerControl->mask << mixerControl->shift; + + OsalMutexLock(&codec->mutex); + ret = AudioCodecAiaoReadReg(codec, mixerControl->reg, &curValue); + if (ret != HDF_SUCCESS) { + OsalMutexUnlock(&codec->mutex); + ADM_LOG_ERR("Read AIAO codec reg fail ret=%d.", ret); + return HDF_FAILURE; + } + curValue = (curValue & ~mixerControlMask) | (value & mixerControlMask); + ret = AudioCodecAiaoWriteReg(codec, mixerControl->reg, curValue); + if (ret != HDF_SUCCESS) { + OsalMutexUnlock(&codec->mutex); + ADM_LOG_ERR("Write AIAO codec reg fail ret=%d", ret); + return HDF_FAILURE; + } + OsalMutexUnlock(&codec->mutex); + + ADM_LOG_DEBUG("Update AIAO codec reg bits successful."); + return HDF_SUCCESS; } -int32_t AudioAiaoUpdateRegBits(struct CodecDevice *codec, uint32_t reg, uint32_t mask, uint32_t shift, int32_t value) +int32_t AudioUpdateAccessoryAiaoRegBits(struct AccessoryDevice *accessory, + const struct AudioMixerControl *mixerControl, uint32_t value) { int32_t ret; - uint32_t curValue = 0; - ADM_LOG_DEBUG("Entry to update AIAO reg bits."); + uint32_t curValue; + uint32_t mixerControlMask; + ADM_LOG_DEBUG("Entry to update AIAO accessory reg bits."); - if (codec == NULL || codec->devData == NULL || codec->devData->AiaoWrite == NULL) { - ADM_LOG_ERR("Invalid AIAO codec param."); + if (accessory == NULL || mixerControl == NULL) { + ADM_LOG_ERR("Invalid AIAO accessory param."); return HDF_ERR_INVALID_OBJECT; } - value = value << shift; - mask = mask << shift; + value = value << mixerControl->shift; + mixerControlMask = mixerControl->mask << mixerControl->shift; - OsalMutexLock(&codec->mutex); - ret = AudioAiaoDeviceReadReg(codec, reg, &curValue); + OsalMutexLock(&accessory->mutex); + ret = AudioAccessoryAiaoReadReg(accessory, mixerControl->reg, &curValue); if (ret != HDF_SUCCESS) { - OsalMutexUnlock(&codec->mutex); - ADM_LOG_ERR("Read AIAO reg fail ret=%d.", ret); + OsalMutexUnlock(&accessory->mutex); + ADM_LOG_ERR("Read AIAO accessory reg fail ret=%d.", ret); return HDF_FAILURE; } - curValue = (curValue & ~mask) | (value & mask); - ret = codec->devData->AiaoWrite(codec, reg, curValue); + curValue = (curValue & ~mixerControlMask) | (value & mixerControlMask); + ret = AudioAccessoryAiaoWriteReg(accessory, mixerControl->reg, curValue); if (ret != HDF_SUCCESS) { - OsalMutexUnlock(&codec->mutex); - ADM_LOG_ERR("Write AIAO reg fail ret=%d", ret); + OsalMutexUnlock(&accessory->mutex); + ADM_LOG_ERR("Write AIAO accessory reg fail ret=%d", ret); return HDF_FAILURE; } - OsalMutexUnlock(&codec->mutex); + OsalMutexUnlock(&accessory->mutex); - ADM_LOG_DEBUG("Update AIAO reg bits successful."); + ADM_LOG_DEBUG("Update AIAO accessory reg bits successful."); return HDF_SUCCESS; } @@ -542,7 +533,7 @@ struct CodecDevice *AudioKcontrolGetCodec(const struct AudioKcontrol *kcontrol) return NULL; } - audioCard = (struct AudioCard *)(kcontrol->pri); + audioCard = (struct AudioCard *)((volatile uintptr_t)(kcontrol->pri)); if (audioCard == NULL || audioCard->rtd == NULL) { ADM_LOG_ERR("Get codec or rtd fail."); return NULL; @@ -559,7 +550,7 @@ struct AccessoryDevice *AudioKcontrolGetAccessory(const struct AudioKcontrol *kc return NULL; } - audioCard = (struct AudioCard *)(kcontrol->pri); + audioCard = (struct AudioCard *)((volatile uintptr_t)(kcontrol->pri)); if (audioCard == NULL || audioCard->rtd == NULL) { ADM_LOG_ERR("Get accessory or rtd fail."); return NULL; @@ -617,7 +608,7 @@ int32_t AudioAddControls(struct AudioCard *audioCard, const struct AudioKcontrol return HDF_SUCCESS; } -int32_t AudioCodecDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *val) +int32_t AudioCodecReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val) { int32_t ret; if (codec == NULL || codec->devData == NULL || codec->devData->Read == NULL || val == NULL) { @@ -626,13 +617,13 @@ int32_t AudioCodecDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_ } ret = codec->devData->Read(codec, reg, val); if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("Device read fail."); + ADM_LOG_ERR("Codec device read fail."); return HDF_FAILURE; } return HDF_SUCCESS; } -int32_t AudioAccessoryDeviceReadReg(struct AccessoryDevice *accessory, uint32_t reg, uint32_t *val) +int32_t AudioAccessoryReadReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t *val) { int32_t ret; if (accessory == NULL || accessory->devData == NULL || accessory->devData->Read == NULL || val == NULL) { @@ -641,13 +632,13 @@ int32_t AudioAccessoryDeviceReadReg(struct AccessoryDevice *accessory, uint32_t } ret = accessory->devData->Read(accessory, reg, val); if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("Device read fail."); + ADM_LOG_ERR("Accessory device read fail."); return HDF_FAILURE; } return HDF_SUCCESS; } -int32_t AudioAiaoDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *val) +int32_t AudioCodecAiaoReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val) { int32_t ret; if (codec == NULL || codec->devData == NULL || codec->devData->AiaoRead == NULL || val == NULL) { @@ -662,7 +653,82 @@ int32_t AudioAiaoDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t return HDF_SUCCESS; } -int32_t AudioInfoCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo) +int32_t AudioAccessoryAiaoReadReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t *val) +{ + int32_t ret; + if (accessory == NULL || accessory->devData == NULL || accessory->devData->AiaoRead == NULL || val == NULL) { + ADM_LOG_ERR("Input param accessory is NULL."); + return HDF_FAILURE; + } + ret = accessory->devData->AiaoRead(accessory, reg, val); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("Device read fail."); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t AudioCodecWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t val) +{ + int32_t ret; + if (codec == NULL || codec->devData == NULL || codec->devData->Write == NULL) { + ADM_LOG_ERR("Input param codec is NULL."); + return HDF_FAILURE; + } + ret = codec->devData->Write(codec, reg, val); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("Codec device write fail."); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t AudioAccessoryWriteReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t val) +{ + int32_t ret; + if (accessory == NULL || accessory->devData == NULL || accessory->devData->Write == NULL) { + ADM_LOG_ERR("Input param accessory is NULL."); + return HDF_FAILURE; + } + ret = accessory->devData->Write(accessory, reg, val); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("Accessory device write fail."); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t AudioCodecAiaoWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t val) +{ + int32_t ret; + if (codec == NULL || codec->devData == NULL || codec->devData->AiaoWrite == NULL) { + ADM_LOG_ERR("Input param codec aiao is NULL."); + return HDF_FAILURE; + } + ret = codec->devData->AiaoWrite(codec, reg, val); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("Codec aiao device write fail."); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t AudioAccessoryAiaoWriteReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t val) +{ + int32_t ret; + if (accessory == NULL || accessory->devData == NULL || accessory->devData->AiaoWrite == NULL) { + ADM_LOG_ERR("Input param accessory aiao is NULL."); + return HDF_FAILURE; + } + ret = accessory->devData->AiaoWrite(accessory, reg, val); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("Accessory aiao device write fail."); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t AudioInfoCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo) { struct AudioMixerControl *mixerCtrl = NULL; @@ -672,7 +738,7 @@ int32_t AudioInfoCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemInf } elemInfo->count = CHANNEL_MIN_NUM; - mixerCtrl = (struct AudioMixerControl *)kcontrol->privateValue; + mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)(kcontrol->privateValue)); /* stereo */ if (mixerCtrl->reg != mixerCtrl->rreg || mixerCtrl->shift != mixerCtrl->rshift) { elemInfo->count = CHANNEL_MAX_NUM; @@ -684,27 +750,15 @@ int32_t AudioInfoCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemInf return HDF_SUCCESS; } -static int32_t AudioGetCtrlOpsSubRReg(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, - enum AudioDeviceType deviceType, void *device) +static int32_t AudioGetCtrlOpsRReg(struct AudioCtrlElemValue *elemValue, + const struct AudioMixerControl *mixerCtrl, uint32_t rcurValue) { - int32_t ret = HDF_FAILURE; - uint32_t rcurValue; - struct AudioMixerControl *mixerCtrl = NULL; - mixerCtrl = (struct AudioMixerControl *)kcontrol->privateValue; - struct CodecDevice *codec = (struct CodecDevice *)device; - struct AccessoryDevice *accessory = (struct AccessoryDevice *)device; + if (elemValue == NULL || mixerCtrl == NULL) { + ADM_LOG_ERR("Audio input param is NULL."); + return HDF_ERR_INVALID_OBJECT; + } if (mixerCtrl->reg != mixerCtrl->rreg || mixerCtrl->shift != mixerCtrl->rshift) { - if (codec != NULL && codec->devData != NULL && codec->devData->Read != NULL) { - ret = codec->devData->Read(codec, mixerCtrl->rreg, &rcurValue); - } else if (accessory != NULL && accessory->devData != NULL && accessory->devData->Read != NULL) { - ret = accessory->devData->Read(accessory, mixerCtrl->rreg, &rcurValue); - } - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("Device read fail."); - return HDF_FAILURE; - } - if (mixerCtrl->reg == mixerCtrl->rreg) { rcurValue = (rcurValue >> mixerCtrl->rshift) & mixerCtrl->mask; } else { @@ -723,25 +777,14 @@ static int32_t AudioGetCtrlOpsSubRReg(struct AudioKcontrol *kcontrol, struct Aud return HDF_SUCCESS; } -static int32_t AudioGetCtrlOpsSubReg(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, - enum AudioDeviceType deviceType, void *device) +static int32_t AudioGetCtrlOpsReg(struct AudioCtrlElemValue *elemValue, + const struct AudioMixerControl *mixerCtrl, uint32_t curValue) { - int32_t ret = HDF_FAILURE; - uint32_t curValue; - struct AudioMixerControl *mixerCtrl = NULL; - mixerCtrl = (struct AudioMixerControl *)kcontrol->privateValue; - struct CodecDevice *codec = (struct CodecDevice *)device; - struct AccessoryDevice *accessory = (struct AccessoryDevice *)device; - - if (codec != NULL && codec->devData != NULL && codec->devData->Read != NULL) { - ret = codec->devData->Read(codec, mixerCtrl->reg, &curValue); - } else if (accessory != NULL && accessory->devData != NULL && accessory->devData->Read != NULL) { - ret = accessory->devData->Read(accessory, mixerCtrl->reg, &curValue); - } - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("Device read fail."); - return HDF_FAILURE; + if (elemValue == NULL || mixerCtrl == NULL) { + ADM_LOG_ERR("Audio input param is NULL."); + return HDF_ERR_INVALID_OBJECT; } + curValue = (curValue >> mixerCtrl->shift) & mixerCtrl->mask; if (curValue > mixerCtrl->max || curValue < mixerCtrl->min) { ADM_LOG_ERR("Audio invalid curValue=%d", curValue); @@ -751,152 +794,174 @@ static int32_t AudioGetCtrlOpsSubReg(struct AudioKcontrol *kcontrol, struct Audi curValue = mixerCtrl->max - curValue; } elemValue->value[0] = curValue; + return HDF_SUCCESS; } -int32_t AudioGetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +int32_t AudioCodecGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) { - enum AudioDeviceType deviceType; + uint32_t curValue; + uint32_t rcurValue; + struct AudioMixerControl *mixerCtrl = NULL; struct CodecDevice *codec = NULL; - struct AccessoryDevice *accessory = NULL; - ADM_LOG_DEBUG("Entry to get audio ctrl switch."); - if (kcontrol == NULL || kcontrol->privateValue <= 0 || elemValue == NULL) { - ADM_LOG_ERR("Audio input param kcontrol is NULL."); + ADM_LOG_ERR("Audio input param is NULL."); return HDF_ERR_INVALID_OBJECT; } - + mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue); codec = AudioKcontrolGetCodec(kcontrol); - accessory = AudioKcontrolGetAccessory(kcontrol); - if (codec != NULL && codec->devData != NULL && codec->devData->Read != NULL) { - deviceType = AUDIO_CODEC_DEVICE; - if (AudioGetCtrlOpsSubReg(kcontrol, elemValue, deviceType, codec) || - AudioGetCtrlOpsSubRReg(kcontrol, elemValue, deviceType, codec)) { - ADM_LOG_ERR("Audio Codec Get Ctrl Reg fail."); - return HDF_FAILURE; - } - } else { - deviceType = AUDIO_ACCESSORY_DEVICE; - if (AudioGetCtrlOpsSubReg(kcontrol, elemValue, deviceType, accessory) || - AudioGetCtrlOpsSubRReg(kcontrol, elemValue, deviceType, accessory)) { - ADM_LOG_ERR("Audio Accessory Get Ctrl Reg fail."); - return HDF_FAILURE; - } + if (mixerCtrl == NULL || codec == NULL) { + ADM_LOG_ERR("mixerCtrl and codec is NULL."); + return HDF_FAILURE; + } + if (AudioCodecReadReg(codec, mixerCtrl->reg, &curValue) != HDF_SUCCESS || + AudioCodecReadReg(codec, mixerCtrl->rreg, &rcurValue) != HDF_SUCCESS) { + ADM_LOG_ERR("Read Reg fail."); + return HDF_FAILURE; + } + if (AudioGetCtrlOpsReg(elemValue, mixerCtrl, curValue) != HDF_SUCCESS || + AudioGetCtrlOpsRReg(elemValue, mixerCtrl, rcurValue) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio codec get kcontrol reg and rreg fail."); + return HDF_FAILURE; } - ADM_LOG_DEBUG("Get audio ctrl switch successful."); return HDF_SUCCESS; } -static int32_t AiaoGetRightCtrlOps(struct CodecDevice *codec, struct AudioMixerControl *mixerCtrl, - struct AudioCtrlElemValue *elemValue) +int32_t AudioAccessoryGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) { - int ret; + uint32_t curValue; uint32_t rcurValue; - if (mixerCtrl->reg != mixerCtrl->rreg || mixerCtrl->shift != mixerCtrl->rshift) { - ret = codec->devData->AiaoRead(codec, mixerCtrl->rreg, &rcurValue); - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("AIAO read rreg fail rcurValue=%d", rcurValue); - return HDF_FAILURE; - } - if (mixerCtrl->reg == mixerCtrl->rreg) { - rcurValue = (rcurValue >> mixerCtrl->rshift) & mixerCtrl->mask; - } else { - rcurValue = (rcurValue >> mixerCtrl->shift) & mixerCtrl->mask; - } - if (rcurValue > mixerCtrl->max) { - ADM_LOG_ERR("AIAO Invalid rcurValue=%d", rcurValue); - return HDF_FAILURE; - } - if (mixerCtrl->invert) { - rcurValue = mixerCtrl->max - rcurValue; - } - elemValue->value[1] = rcurValue; + struct AudioMixerControl *mixerCtrl = NULL; + struct AccessoryDevice *accessory = NULL; + if (kcontrol == NULL || kcontrol->privateValue <= 0 || elemValue == NULL) { + ADM_LOG_ERR("Audio input param is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue); + accessory = AudioKcontrolGetAccessory(kcontrol); + if (mixerCtrl == NULL || accessory == NULL) { + ADM_LOG_ERR("mixerCtrl and accessory is NULL."); + return HDF_FAILURE; + } + if (AudioAccessoryReadReg(accessory, mixerCtrl->reg, &curValue) != HDF_SUCCESS || + AudioAccessoryReadReg(accessory, mixerCtrl->rreg, &rcurValue) != HDF_SUCCESS) { + ADM_LOG_ERR("Read Reg fail."); + return HDF_FAILURE; + } + if (AudioGetCtrlOpsReg(elemValue, mixerCtrl, curValue) != HDF_SUCCESS || + AudioGetCtrlOpsRReg(elemValue, mixerCtrl, rcurValue) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio accessory get kcontrol reg and rreg fail."); + return HDF_FAILURE; } return HDF_SUCCESS; } -int32_t AiaoGetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +int32_t AudioCodecAiaoGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) { - int32_t ret; + uint32_t curValue; + uint32_t rcurValue; struct CodecDevice *codec = NULL; struct AudioMixerControl *mixerCtrl = NULL; - uint32_t curValue; - - ADM_LOG_DEBUG("Entry to get AIAO ctrl switch"); - if (kcontrol == NULL || kcontrol->privateValue <= 0 || elemValue == NULL) { - ADM_LOG_ERR("AIAO input param is NULL."); + ADM_LOG_ERR("CODECAIAO input param is NULL."); return HDF_ERR_INVALID_OBJECT; } codec = AudioKcontrolGetCodec(kcontrol); - if (codec == NULL || codec->devData == NULL || codec->devData->AiaoRead == NULL) { - ADM_LOG_ERR("AIAO codec device is NULL."); + mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue); + if (mixerCtrl == NULL || codec == NULL) { + ADM_LOG_ERR("mixerCtrl and codec is NULL."); return HDF_FAILURE; } - mixerCtrl = (struct AudioMixerControl *)kcontrol->privateValue; - ret = codec->devData->AiaoRead(codec, mixerCtrl->reg, &curValue); - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("AIAO read rreg fail rcurValue=%d", curValue); + if (AudioCodecAiaoReadReg(codec, mixerCtrl->reg, &curValue) != HDF_SUCCESS || + AudioCodecAiaoReadReg(codec, mixerCtrl->rreg, &rcurValue) != HDF_SUCCESS) { + ADM_LOG_ERR("Read Reg fail."); return HDF_FAILURE; } - curValue = (curValue >> mixerCtrl->shift) & mixerCtrl->mask; - if (curValue > mixerCtrl->max) { - ADM_LOG_ERR("AIAO invalid curValue=%d", curValue); + if (AudioGetCtrlOpsReg(elemValue, mixerCtrl, curValue) != HDF_SUCCESS || + AudioGetCtrlOpsRReg(elemValue, mixerCtrl, rcurValue) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio CODECAIAO get kcontrol reg and rreg fail."); return HDF_FAILURE; } - if (mixerCtrl->invert) { - curValue = mixerCtrl->max - curValue; + ADM_LOG_DEBUG("Get CODECAIAO ctrl switch successful."); + return HDF_SUCCESS; +} + +int32_t AudioAccessoryAiaoGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +{ + uint32_t curValue; + uint32_t rcurValue; + struct AccessoryDevice *accessory = NULL; + struct AudioMixerControl *mixerCtrl = NULL; + if (kcontrol == NULL || kcontrol->privateValue <= 0 || elemValue == NULL) { + ADM_LOG_ERR("ACCESSORYCAIAO input param is NULL."); + return HDF_ERR_INVALID_OBJECT; } - elemValue->value[0] = curValue; - ret = AiaoGetRightCtrlOps(codec, mixerCtrl, elemValue); - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("AIAO get right ctrl is fail"); + accessory = AudioKcontrolGetAccessory(kcontrol); + mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue); + if (mixerCtrl == NULL || accessory == NULL) { + ADM_LOG_ERR("mixerCtrl and accessory is NULL."); + return HDF_FAILURE; + } + if (AudioAccessoryAiaoReadReg(accessory, mixerCtrl->reg, &curValue) != HDF_SUCCESS || + AudioAccessoryAiaoReadReg(accessory, mixerCtrl->rreg, &rcurValue) != HDF_SUCCESS) { + ADM_LOG_ERR("Read Reg fail."); + return HDF_FAILURE; + } + if (AudioGetCtrlOpsReg(elemValue, mixerCtrl, curValue) != HDF_SUCCESS || + AudioGetCtrlOpsRReg(elemValue, mixerCtrl, rcurValue) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio ACCESSORYCAIAO get kcontrol reg and rreg fail."); return HDF_FAILURE; } - ADM_LOG_DEBUG("Get AIAO ctrl switch successful."); + ADM_LOG_DEBUG("Get ACCESSORYCAIAO ctrl switch successful."); return HDF_SUCCESS; } -static int32_t AudioPutCtrlOpsSub(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, - enum AudioDeviceType deviceType, void *device) +static int32_t AudioSetCtrlOpsReg(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue, + const struct AudioMixerControl *mixerCtrl, uint32_t *value) { - int32_t value; - int32_t rvalue; - int32_t rshift; - int32_t ret; - struct AudioMixerControl *mixerCtrl = NULL; - mixerCtrl = (struct AudioMixerControl *)kcontrol->privateValue; - - value = elemValue->value[0]; - if (value < mixerCtrl->min || value > mixerCtrl->max) { - ADM_LOG_ERR("Audio invalid value=%d", value); + if (kcontrol == NULL || (kcontrol->privateValue <= 0) || elemValue == NULL || + mixerCtrl == NULL || value == NULL) { + ADM_LOG_ERR("Audio input param is NULL."); return HDF_ERR_INVALID_OBJECT; } + *value = elemValue->value[0]; + if (*value < mixerCtrl->min || *value > mixerCtrl->max) { + ADM_LOG_ERR("Audio invalid value=%d", *value); + return HDF_ERR_INVALID_OBJECT; + } if (mixerCtrl->invert) { - value = mixerCtrl->max - value; + *value = mixerCtrl->max - *value; } - ret = AudioUpdateRegBits(deviceType, device, mixerCtrl, value); - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("Audio update reg bits fail ret=%d", ret); - return HDF_FAILURE; + return HDF_SUCCESS; +} + +static int32_t AudioSetCtrlOpsRReg(const struct AudioCtrlElemValue *elemValue, + struct AudioMixerControl *mixerCtrl, uint32_t *rvalue, bool *updateRReg) +{ + uint32_t rshift; + if (elemValue == NULL || mixerCtrl == NULL || rvalue == NULL || updateRReg == NULL) { + ADM_LOG_ERR("Audio input param is NULL."); + return HDF_ERR_INVALID_OBJECT; } if (mixerCtrl->reg != mixerCtrl->rreg || mixerCtrl->shift != mixerCtrl->rshift) { - rvalue = elemValue->value[1]; - if (rvalue < mixerCtrl->min || rvalue > mixerCtrl->max) { - ADM_LOG_ERR("Audio invalid rvalue=%d", rvalue); + *updateRReg = true; + *rvalue = elemValue->value[1]; + if (*rvalue < mixerCtrl->min || *rvalue > mixerCtrl->max) { + ADM_LOG_ERR("Audio invalid fail."); return HDF_FAILURE; } if (mixerCtrl->invert) { - rvalue = mixerCtrl->max - rvalue; + *rvalue = mixerCtrl->max - *rvalue; } if (mixerCtrl->reg == mixerCtrl->rreg) { rshift = mixerCtrl->rshift; @@ -904,136 +969,164 @@ static int32_t AudioPutCtrlOpsSub(struct AudioKcontrol *kcontrol, struct AudioCt rshift = mixerCtrl->shift; } mixerCtrl->shift = rshift; - ret = AudioUpdateRegBits(deviceType, device, mixerCtrl, rvalue); - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("Audio stereo update reg bits fail ret=%d", ret); - return HDF_FAILURE; - } } return HDF_SUCCESS; } -int32_t AudioSetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +int32_t AudioCodecSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue) { - void *device = NULL; - enum AudioDeviceType deviceType; - int32_t ret = HDF_FAILURE; - ADM_LOG_DEBUG("Entry to put audio ctrl switch."); + uint32_t value; + uint32_t rvalue; + bool updateRReg = false; + struct CodecDevice *codec = NULL; + struct AudioMixerControl *mixerCtrl = NULL; + if (kcontrol == NULL || (kcontrol->privateValue <= 0) || elemValue == NULL) { + ADM_LOG_ERR("Audio input param is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue); + if (AudioSetCtrlOpsReg(kcontrol, elemValue, mixerCtrl, &value) != HDF_SUCCESS) { + ADM_LOG_ERR("AudioSetCtrlOpsReg is fail."); + return HDF_ERR_INVALID_OBJECT; + } + codec = AudioKcontrolGetCodec(kcontrol); + if (codec == NULL) { + ADM_LOG_ERR("AudioKcontrolGetCodec is fail."); + return HDF_ERR_INVALID_OBJECT; + } + if (AudioUpdateCodecRegBits(codec, mixerCtrl, value) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio codec stereo update reg bits fail."); + return HDF_FAILURE; + } + if (AudioSetCtrlOpsRReg(elemValue, mixerCtrl, &rvalue, &updateRReg) != HDF_SUCCESS) { + ADM_LOG_ERR("AudioSetCtrlOpsRReg is fail."); + return HDF_ERR_INVALID_OBJECT; + } + + if (updateRReg) { + if (AudioUpdateCodecRegBits(codec, mixerCtrl, rvalue) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio codec stereo update reg bits fail."); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +int32_t AudioAccessorySetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue) +{ + uint32_t value; + uint32_t rvalue; + bool updateRReg = false; + struct AccessoryDevice *accessory = NULL; + struct AudioMixerControl *mixerCtrl = NULL; if (kcontrol == NULL || (kcontrol->privateValue <= 0) || elemValue == NULL) { ADM_LOG_ERR("Audio input param is NULL."); return HDF_ERR_INVALID_OBJECT; } - struct CodecDevice *codec = AudioKcontrolGetCodec(kcontrol); - struct AccessoryDevice *accessory = AudioKcontrolGetAccessory(kcontrol); - if (codec != NULL && codec->devData != NULL && codec->devData->Write != NULL) { - deviceType = AUDIO_CODEC_DEVICE; - device = (void *)codec; - ret = AudioPutCtrlOpsSub(kcontrol, elemValue, deviceType, device); - } else if (accessory != NULL && accessory->devData != NULL && accessory->devData->Write != NULL) { - deviceType = AUDIO_ACCESSORY_DEVICE; - device = (void *)accessory; - ret = AudioPutCtrlOpsSub(kcontrol, elemValue, deviceType, device); + mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue); + if (AudioSetCtrlOpsReg(kcontrol, elemValue, mixerCtrl, &value) != HDF_SUCCESS) { + ADM_LOG_ERR("AudioSetCtrlOpsReg fail."); + return HDF_FAILURE; + } + + accessory = AudioKcontrolGetAccessory(kcontrol); + if (AudioUpdateAccessoryRegBits(accessory, mixerCtrl, value) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio accessory stereo update reg bits fail."); + return HDF_FAILURE; } - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("Audio update fail ret=%d", ret); + if (AudioSetCtrlOpsRReg(elemValue, mixerCtrl, &rvalue, &updateRReg) != HDF_SUCCESS) { + ADM_LOG_ERR("AudioSetCtrlOpsRReg fail."); return HDF_FAILURE; } - ADM_LOG_DEBUG("Put audio ctrl switch successful."); + if (updateRReg) { + if (AudioUpdateAccessoryRegBits(accessory, mixerCtrl, rvalue) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio accessory stereo update reg bits fail."); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; } -int32_t AiaoSetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +int32_t AudioCodecAiaoSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue) { + uint32_t value; + uint32_t rvalue; + bool updateRReg = false; struct CodecDevice *codec = NULL; struct AudioMixerControl *mixerCtrl = NULL; - int32_t value; - int32_t rvalue; - uint32_t rshift; - int32_t ret; - ADM_LOG_DEBUG("Entry to put AIAO ctrl switch."); - if (kcontrol == NULL || (kcontrol->privateValue <= 0) || elemValue == NULL) { - ADM_LOG_ERR("AIAO input param is NULL."); + ADM_LOG_ERR("Audio codec aiao input param is NULL."); return HDF_ERR_INVALID_OBJECT; } - codec = AudioKcontrolGetCodec(kcontrol); - mixerCtrl = (struct AudioMixerControl *)kcontrol->privateValue; - value = elemValue->value[0]; - if (value < mixerCtrl->min || value > mixerCtrl->max) { - ADM_LOG_ERR("AIAO invalid value=%d", value); - return HDF_ERR_INVALID_OBJECT; + mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue); + if (AudioSetCtrlOpsReg(kcontrol, elemValue, mixerCtrl, &value) != HDF_SUCCESS) { + ADM_LOG_ERR("AudioSetCtrlOpsReg fail."); + return HDF_FAILURE; } - if (mixerCtrl->invert) { - value = mixerCtrl->max - value; + codec = AudioKcontrolGetCodec(kcontrol); + if (AudioUpdateCodecAiaoRegBits(codec, mixerCtrl, value) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio codec aiao stereo update reg bits fail."); + return HDF_FAILURE; } - ret = AudioAiaoUpdateRegBits(codec, mixerCtrl->reg, mixerCtrl->mask, mixerCtrl->shift, value); - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("AIAO update reg bits fail ret=%d", ret); + if (AudioSetCtrlOpsRReg(elemValue, mixerCtrl, &rvalue, &updateRReg) != HDF_SUCCESS) { + ADM_LOG_ERR("AudioSetCtrlOpsRReg fail."); return HDF_FAILURE; } - - if (mixerCtrl->reg != mixerCtrl->rreg || mixerCtrl->shift != mixerCtrl->rshift) { - rvalue = elemValue->value[1]; - if (rvalue < mixerCtrl->min || rvalue > mixerCtrl->max) { - ADM_LOG_ERR("AIAO invalid rvalue=%d", rvalue); - return HDF_ERR_INVALID_OBJECT; - } - if (mixerCtrl->invert) { - rvalue = mixerCtrl->max - rvalue; - } - if (mixerCtrl->reg == mixerCtrl->rreg) { - rshift = mixerCtrl->rshift; - } else { - rshift = mixerCtrl->shift; - } - ret = AudioAiaoUpdateRegBits(codec, mixerCtrl->rreg, mixerCtrl->mask, rshift, rvalue); - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("AIAO stereo update reg bits fail ret=%d", ret); + if (updateRReg) { + if (AudioUpdateCodecAiaoRegBits(codec, mixerCtrl, rvalue) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio codec aiao stereo update reg bits fail."); return HDF_FAILURE; } } - ADM_LOG_DEBUG("Put AIAO ctrl switch successful."); return HDF_SUCCESS; } -int32_t AudioRegisterDeviceDsp(struct HdfDeviceObject *device, struct DspData *dspData, struct DaiData *DaiData) +int32_t AudioAccessoryAiaoSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue) { - struct DspDevice *dspDev = NULL; - int32_t ret; - - if ((device == NULL) || (dspData == NULL) || (DaiData == NULL)) { - ADM_LOG_ERR("Input params check error: device=%p, dspData=%p, daiData=%p.", - device, dspData, DaiData); + uint32_t value; + uint32_t rvalue; + bool updateRReg = false; + struct AccessoryDevice *accessory = NULL; + struct AudioMixerControl *mixerCtrl = NULL; + if (kcontrol == NULL || (kcontrol->privateValue <= 0) || elemValue == NULL) { + ADM_LOG_ERR("Audio accessory aiao input param is NULL."); return HDF_ERR_INVALID_OBJECT; } - dspDev = (struct DspDevice *)OsalMemCalloc(sizeof(*dspDev)); - if (dspDev == NULL) { - ADM_LOG_ERR("Malloc codec device fail!"); - return HDF_ERR_MALLOC_FAIL; + mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue); + if (AudioSetCtrlOpsReg(kcontrol, elemValue, mixerCtrl, &value) != HDF_SUCCESS) { + ADM_LOG_ERR("AudioSetCtrlOpsReg fail."); + return HDF_FAILURE; } - dspDev->devDspName = dspData->drvDspName; - dspDev->devData = dspData; - dspDev->device = device; + accessory = AudioKcontrolGetAccessory(kcontrol); + if (AudioUpdateAccessoryAiaoRegBits(accessory, mixerCtrl, value) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio accessory aiao stereo update reg bits fail."); + return HDF_FAILURE; + } - ret = AudioSocDeviceRegister(device, (void *)DaiData, AUDIO_DSP_DEVICE); - if (ret != HDF_SUCCESS) { - OsalMemFree(dspDev); - ADM_LOG_ERR("Register dai device fail ret=%d", ret); - return HDF_ERR_IO; + if (AudioSetCtrlOpsRReg(elemValue, mixerCtrl, &rvalue, &updateRReg) != HDF_SUCCESS) { + ADM_LOG_ERR("AudioSetCtrlOpsRReg fail."); + return HDF_FAILURE; + } + + if (updateRReg) { + if (AudioUpdateAccessoryAiaoRegBits(accessory, mixerCtrl, rvalue) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio accessory aiao stereo update reg bits fail."); + return HDF_FAILURE; + } } - DListInsertHead(&dspDev->list, &dspController); - ADM_LOG_INFO("Register [%s] success.", dspDev->devDspName); return HDF_SUCCESS; } diff --git a/model/audio/core/src/audio_host.c b/model/audio/core/src/audio_host.c index 605a6d7a8..61c2434c3 100755 --- a/model/audio/core/src/audio_host.c +++ b/model/audio/core/src/audio_host.c @@ -7,9 +7,9 @@ */ #include "audio_host.h" +#include "audio_codec_if.h" #include "audio_core.h" #include "audio_parse.h" -#include "codec_adapter.h" #define HDF_LOG_TAG audio_host @@ -25,7 +25,17 @@ struct AudioCard *GetCardInstance(const char *serviceName) return NULL; } + if (DListIsEmpty(&cardManager)) { + ADM_LOG_ERR("cardManager is empty."); + return NULL; + } + DLIST_FOR_EACH_ENTRY(audioCard, &cardManager, struct AudioCard, list) { + if (audioCard->configData.cardServiceName == NULL) { + ADM_LOG_ERR("cardServiceName is NULL."); + return NULL; + } + if (strcmp(audioCard->configData.cardServiceName, serviceName) == 0) { return audioCard; } @@ -49,15 +59,13 @@ static int32_t AudioCodecDevInit(struct AudioCard *audioCard) return HDF_ERR_IO; } codec = rtd->codec; - if (codec == NULL || codec->devData == NULL || codec->devData->Init == NULL) { - ADM_LOG_ERR("codec is NULL."); - return HDF_ERR_IO; - } - /* codec initialization */ - int32_t ret = codec->devData->Init(audioCard, codec); - if (ret < 0) { - ADM_LOG_ERR("codec initialization fail ret=%d", ret); - return HDF_ERR_IO; + if (codec != NULL && codec->devData != NULL && codec->devData->Init != NULL) { + /* codec initialization */ + int32_t ret = codec->devData->Init(audioCard, codec); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("codec initialization fail ret=%d", ret); + return HDF_ERR_IO; + } } ADM_LOG_INFO("success."); @@ -80,22 +88,20 @@ static int32_t AudioAccessoryDevInit(struct AudioCard *audioCard) return HDF_ERR_IO; } accessory = rtd->accessory; - if (accessory == NULL || accessory->devData == NULL || accessory->devData->AccessoryInit == NULL) { - ADM_LOG_ERR("accessory is NULL."); - return HDF_ERR_IO; - } - /* codec initialization */ - int32_t ret = accessory->devData->AccessoryInit(audioCard, accessory); - if (ret < 0) { - ADM_LOG_ERR("accessory initialization fail ret=%d", ret); - return HDF_ERR_IO; + if (accessory != NULL && accessory->devData != NULL && accessory->devData->Init != NULL) { + /* codec initialization */ + int32_t ret = accessory->devData->Init(audioCard, accessory); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("accessory initialization fail ret=%d", ret); + return HDF_ERR_IO; + } } ADM_LOG_INFO("success."); return HDF_SUCCESS; } -static int32_t AudioPlatformDevInit(struct AudioCard *audioCard) +static int32_t AudioPlatformDevInit(const struct AudioCard *audioCard) { struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; @@ -112,22 +118,51 @@ static int32_t AudioPlatformDevInit(struct AudioCard *audioCard) return HDF_ERR_IO; } platform = rtd->platform; - if (platform == NULL || platform->devData == NULL || platform->devData->PlatformInit == NULL) { + if (platform != NULL && platform->devData != NULL && platform->devData->PlatformInit != NULL) { + /* platform initialization */ + int32_t ret = platform->devData->PlatformInit(audioCard, platform); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform initialization fail ret=%d", ret); + return HDF_ERR_IO; + } + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +static int32_t AudioDspDevInit(const struct AudioCard *audioCard) +{ + struct AudioRuntimeDeivces *rtd = NULL; + struct DspDevice *dsp = NULL; + + if (audioCard == NULL) { ADM_LOG_ERR("audioCard is NULL."); return HDF_ERR_IO; } - /* platform initialization */ - int32_t ret = platform->devData->PlatformInit(audioCard, platform); - if (ret < 0) { - ADM_LOG_ERR("platform initialization fail ret=%d", ret); + ADM_LOG_DEBUG("entry."); + + rtd = audioCard->rtd; + if (rtd == NULL) { + ADM_LOG_ERR("audioCard rtd object is NULL."); return HDF_ERR_IO; } + dsp = rtd->dsp; + if (dsp != NULL && dsp->devData != NULL && dsp->devData->DspInit != NULL) { + /* dsp initialization */ + int32_t ret = dsp->devData->DspInit(dsp); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("dsp initialization fail ret=%d", ret); + return HDF_ERR_IO; + } + } + ADM_LOG_INFO("success."); return HDF_SUCCESS; } -static int32_t AudioCodecDaiDevInit(struct AudioCard *audioCard) +static int32_t AudioCodecDaiDevInit(const struct AudioCard *audioCard) { struct AudioRuntimeDeivces *rtd = NULL; struct DaiDevice *codecDai = NULL; @@ -144,22 +179,20 @@ static int32_t AudioCodecDaiDevInit(struct AudioCard *audioCard) return HDF_ERR_IO; } codecDai = rtd->codecDai; - if (codecDai == NULL || codecDai->devData == NULL || codecDai->devData->DaiInit == NULL) { - ADM_LOG_ERR("codecDai is NULL."); - return HDF_ERR_IO; - } - /* codec dai initialization */ - int32_t ret = codecDai->devData->DaiInit(audioCard, codecDai); - if (ret < 0) { - ADM_LOG_ERR("codec dai initialization fail ret=%d", ret); - return HDF_ERR_IO; + if (codecDai != NULL && codecDai->devData != NULL && codecDai->devData->DaiInit != NULL) { + /* codec dai initialization */ + int32_t ret = codecDai->devData->DaiInit(audioCard, codecDai); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("codec dai initialization fail ret=%d", ret); + return HDF_ERR_IO; + } } ADM_LOG_INFO("success."); return HDF_SUCCESS; } -static int32_t AudioAccessoryDaiDevInit(struct AudioCard *audioCard) +static int32_t AudioAccessoryDaiDevInit(const struct AudioCard *audioCard) { struct AudioRuntimeDeivces *rtd = NULL; struct DaiDevice *accessoryDai = NULL; @@ -176,22 +209,20 @@ static int32_t AudioAccessoryDaiDevInit(struct AudioCard *audioCard) return HDF_ERR_IO; } accessoryDai = rtd->accessoryDai; - if (accessoryDai == NULL || accessoryDai->devData == NULL || accessoryDai->devData->DaiInit == NULL) { - ADM_LOG_ERR("accessoryDai is NULL."); - return HDF_ERR_IO; - } - /* codec dai initialization */ - int32_t ret = accessoryDai->devData->DaiInit(audioCard, accessoryDai); - if (ret < 0) { - ADM_LOG_ERR("accessory dai initialization fail ret=%d", ret); - return HDF_ERR_IO; + if (accessoryDai != NULL && accessoryDai->devData != NULL && accessoryDai->devData->DaiInit != NULL) { + /* codec dai initialization */ + int32_t ret = accessoryDai->devData->DaiInit(audioCard, accessoryDai); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("accessory dai initialization fail ret=%d", ret); + return HDF_ERR_IO; + } } ADM_LOG_INFO("success."); return HDF_SUCCESS; } -static int32_t AudioCpuDaiDevInit(struct AudioCard *audioCard) +static int32_t AudioCpuDaiDevInit(const struct AudioCard *audioCard) { struct AudioRuntimeDeivces *rtd = NULL; struct DaiDevice *cpuDai = NULL; @@ -208,26 +239,23 @@ static int32_t AudioCpuDaiDevInit(struct AudioCard *audioCard) return HDF_ERR_IO; } cpuDai = rtd->cpuDai; - if (cpuDai == NULL || cpuDai->devData == NULL || cpuDai->devData->DaiInit == NULL) { - ADM_LOG_ERR("cpuDai is NULL."); - return HDF_ERR_IO; - } - /* cpu dai initialization */ - int32_t ret = cpuDai->devData->DaiInit(audioCard, cpuDai); - if (ret < 0) { - ADM_LOG_ERR("cpu dai initialization fail ret=%d", ret); - return HDF_ERR_IO; + if (cpuDai != NULL && cpuDai->devData != NULL && cpuDai->devData->DaiInit != NULL) { + /* cpu dai initialization */ + int32_t ret = cpuDai->devData->DaiInit(audioCard, cpuDai); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("cpu dai initialization fail ret=%d", ret); + return HDF_ERR_IO; + } } ADM_LOG_INFO("success."); return HDF_SUCCESS; } -static int32_t AudioDspDaiDevInit(struct AudioCard *audioCard) +static int32_t AudioDspDaiDevInit(const struct AudioCard *audioCard) { struct AudioRuntimeDeivces *rtd = NULL; struct DaiDevice *dspDai = NULL; - struct DspDevice *dsp = NULL; int ret; if (audioCard == NULL) { @@ -243,32 +271,18 @@ static int32_t AudioDspDaiDevInit(struct AudioCard *audioCard) } dspDai = rtd->dspDai; - if (dspDai == NULL || dspDai->devData == NULL || dspDai->devData->DaiInit == NULL) { - ADM_LOG_ERR("dsp is NULL."); - return HDF_ERR_IO; - } - - ret = dspDai->devData->DaiInit(audioCard, dspDai); - if (ret < 0) { - ADM_LOG_ERR("dsp dai initialization fail ret=%d", ret); - return HDF_ERR_IO; - } - - dsp = rtd->dsp; - if (dsp == NULL || dsp->devData == NULL || dsp->devData->DspInit == NULL) { - ADM_LOG_ERR("dsp is NULL."); - return HDF_ERR_IO; - } - - ret = dsp->devData->DspInit(dsp); - if (ret < 0) { - ADM_LOG_ERR("dsp initialization fail ret=%d", ret); - return HDF_ERR_IO; + if (dspDai != NULL && dspDai->devData != NULL && dspDai->devData->DaiInit != NULL) { + ret = dspDai->devData->DaiInit(audioCard, dspDai); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("dsp dai initialization fail ret=%d", ret); + return HDF_ERR_IO; + } } ADM_LOG_INFO("success."); return HDF_SUCCESS; } + static int32_t AudioInitDaiLink(struct AudioCard *audioCard) { if (audioCard == NULL) { @@ -278,42 +292,27 @@ static int32_t AudioInitDaiLink(struct AudioCard *audioCard) ADM_LOG_DEBUG("entry."); if (AudioPlatformDevInit(audioCard) || AudioCpuDaiDevInit(audioCard)) { - ADM_LOG_ERR("Platform and CpuDai is NULL."); + ADM_LOG_ERR("Platform and CpuDai init fail."); return HDF_ERR_IO; } - if ((AudioCodecDevInit(audioCard) || AudioCodecDaiDevInit(audioCard)) && - (AudioAccessoryDevInit(audioCard) || AudioAccessoryDaiDevInit(audioCard))) { - ADM_LOG_ERR("codec is NULL."); + if ((AudioCodecDevInit(audioCard) || AudioCodecDaiDevInit(audioCard))) { + ADM_LOG_ERR("codec init fail."); return HDF_ERR_IO; } - if (AudioDspDaiDevInit(audioCard)) { - ADM_LOG_ERR("Dsp Dai is NULL."); + if (AudioAccessoryDevInit(audioCard) || AudioAccessoryDaiDevInit(audioCard)) { + ADM_LOG_ERR("Accessory init fail."); return HDF_ERR_IO; } - ADM_LOG_DEBUG("success."); - return HDF_SUCCESS; -} - -void AudioCardDestroy(struct AudioCard *card) -{ - if (card == NULL) { - return; - } - if (card->rtd != NULL) { - OsalMemFree(card->rtd); + if (AudioDspDevInit(audioCard) || AudioDspDaiDevInit(audioCard)) { + ADM_LOG_ERR("Dsp Dai init fail."); + return HDF_ERR_IO; } - OsalMemFree(card); -} -void AudioHostDestroy(struct AudioHost *host) -{ - if (host == NULL) { - return; - } - OsalMemFree(host); + ADM_LOG_DEBUG("success."); + return HDF_SUCCESS; } struct AudioHost *AudioHostCreateAndBind(struct HdfDeviceObject *device) @@ -415,6 +414,7 @@ static int32_t AudioDriverInit(struct HdfDeviceObject *device) static void AudioDriverRelease(struct HdfDeviceObject *device) { struct AudioHost *audioHost = NULL; + struct AudioCard *audioCard = NULL; ADM_LOG_DEBUG("entry."); if (device == NULL) { @@ -426,8 +426,15 @@ static void AudioDriverRelease(struct HdfDeviceObject *device) ADM_LOG_ERR("audioHost is NULL."); return; } - AudioCardDestroy(audioHost->priv); - AudioHostDestroy(audioHost); + + if (audioHost->priv != NULL) { + audioCard = (struct AudioCard *)audioHost->priv; + if (audioCard->rtd != NULL) { + OsalMemFree(audioCard->rtd); + } + OsalMemFree(audioHost->priv); + } + OsalMemFree(audioHost); ADM_LOG_INFO("success."); } diff --git a/model/audio/core/src/audio_parse.c b/model/audio/core/src/audio_parse.c index 13a68cfbc..b483b3c0b 100755 --- a/model/audio/core/src/audio_parse.c +++ b/model/audio/core/src/audio_parse.c @@ -10,7 +10,7 @@ #define HDF_LOG_TAG audio_parse -int32_t AudioFillConfigData(struct HdfDeviceObject *device, struct AudioConfigData *configData) +int32_t AudioFillConfigData(const struct HdfDeviceObject *device, struct AudioConfigData *configData) { const struct DeviceResourceNode *node = NULL; struct DeviceResourceIface *drsOps = NULL; diff --git a/model/audio/core/test/unittest/common/audio_common_test.h b/model/audio/core/test/unittest/common/audio_common_test.h index 26881f098..74f213f15 100755 --- a/model/audio/core/test/unittest/common/audio_common_test.h +++ b/model/audio/core/test/unittest/common/audio_common_test.h @@ -16,34 +16,47 @@ const int32_t g_testAudioType = 701; // 701 is TEST_AUDIO_TYPE enum { TESTGETCODEC, TESTGETCARDINSTANCE, - TESTHOSTDESTROY, TESTGETCCNFIGDATA, - TESTREGISTERDAI, + TESTREGISTERPLATFORM, + TESTREGISTERDAI, + TESTREGISTERACCESSORY, TESTREGISTERCODEC, - TESTBINDDAILINK, - TESTDEVICEREGISTER, TESTREGISTERDSP, - TESTREGISTERACCESSORY, - TESTUPDATEREGBITS, - TESTAIAOUPDATEREGBITS, + TESTSOCDEVICEREGISTER, + TESTBINDDAILINK, + TESTUPDATECODECREGBITS, + TESTUPDATEACCESSORYREGBITS, + TESTUPDATECODECAIAOREGBITS, + TESTUPDATEACCESSORYAIAOREGBITS, TESTKCONTROLGETCODEC, - TESTADDCONTROLS, + TESTKCONTROLGETACCESSORY, TESTADDCONTROL, - TESTDEVICEREADREG, - TESTAIAODEVICEREADREG, - TESTINFOCTRLSW, - TESTGETCTRLSW, - TESTPUTCTRLSW, - TESTAIAOGETCTRLSW, - TESTAIAOPUTCTRLSW, + TESTADDCONTROLS, + TESTCODECREADREG, + TESTACCESSORYREADREG, + TESTCODECAIAOREADREG, + TESTACCESSORYAIAOREADREG, + TESTCODECWRITEREG, + TESTACCESSORYWRITEREG, + TESTCODECAIAOWRITEREG, + TESTACCESSORYAIAOWRITEREG, + TESTINFOCTRLOPS, + TESTCODECGETCTRLOPS, + TESTACCESSORYGETCTRLOPS, + TESTCODECAIAOGETCTRLOPS, + TESTACCESSORYAIAOGETCTRLOPS, + TESTCODECSETCTRLOPS, + TESTACCESSORYSETCTRLOPS, + TESTCODECAIAOSETCTRLOPS, + TESTACCESSORYAIAOSETCTRLOPS, + TESTNEWCOMPONENT, TESTADDROUTES, TESTNEWCONTROLS, TESTPOWERCOMPONET, TESTREFRESHTIME, TESTSTREAMDISPATCH, - TESTSTREAMDESTORY, }; #endif /* AUDIO_COMMON_TEST_H */ diff --git a/model/audio/core/test/unittest/common/audio_core_test.cpp b/model/audio/core/test/unittest/common/audio_core_test.cpp index 3ea44f759..91f8f7900 100755 --- a/model/audio/core/test/unittest/common/audio_core_test.cpp +++ b/model/audio/core/test/unittest/common/audio_core_test.cpp @@ -11,7 +11,7 @@ #include "hdf_uhdf_test.h" using namespace testing::ext; - +namespace { class AudioCoreTest : public testing::Test { public: static void SetUpTestCase(); @@ -38,15 +38,21 @@ void AudioCoreTest::TearDown() { } +HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterPlatform, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERPLATFORM, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterDai, TestSize.Level0) { struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERDAI, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterPlatform, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterAccessory, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERPLATFORM, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERACCESSORY, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -56,39 +62,45 @@ HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterCodec, TestSize.Level0) EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_BindDaiLink, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_SocRegisterDsp, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTBINDDAILINK, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERDSP, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } HWTEST_F(AudioCoreTest, AudioCoreTest_SocDeviceRegister, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTDEVICEREGISTER, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTSOCDEVICEREGISTER, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_SocRegisterDsp, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_BindDaiLink, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERDSP, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTBINDDAILINK, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterAccessory, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateCodecRegBits, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERACCESSORY, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTUPDATECODECREGBITS, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateRegBits, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateAccessoryRegBits, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTUPDATEREGBITS, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTUPDATEACCESSORYREGBITS, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_AiaoUpdateRegBits, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateCodecAiaoRegBits, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTAIAOUPDATEREGBITS, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTUPDATECODECAIAOREGBITS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateAccessoryAiaoRegBits, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTUPDATEACCESSORYAIAOREGBITS, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -98,9 +110,9 @@ HWTEST_F(AudioCoreTest, AudioCoreTest_KcontrolGetCodec, TestSize.Level0) EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_AddControls, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_KcontrolGetAccessory, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTADDCONTROLS, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTKCONTROLGETACCESSORY, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -110,44 +122,111 @@ HWTEST_F(AudioCoreTest, AudioCoreTest_AddControl, TestSize.Level0) EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_DeviceReadReg, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_AddControls, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTADDCONTROLS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_CodecReadReg, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTCODECREADREG, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryReadReg, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTDEVICEREADREG, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYREADREG, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_AiaoDeviceReadReg, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_CodecAiaoReadReg, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTAIAODEVICEREADREG, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTCODECAIAOREADREG, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_InfoCtrlSw, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryAiaoReadReg, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTINFOCTRLSW, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYAIAOREADREG, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_GetCtrlSw, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_CodecWriteReg, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTGETCTRLSW, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTCODECWRITEREG, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_PutCtrlSw, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryWriteReg, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTPUTCTRLSW, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYWRITEREG, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_AiaoGetCtrlSw, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_CodecAiaoWriteReg, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTAIAOGETCTRLSW, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTCODECAIAOWRITEREG, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -HWTEST_F(AudioCoreTest, AudioCoreTest_AiaoPutCtrlSw, TestSize.Level0) +HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryAiaoWriteReg, TestSize.Level0) { - struct HdfTestMsg msg = {g_testAudioType, TESTAIAOPUTCTRLSW, -1}; + struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYAIAOWRITEREG, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } + +HWTEST_F(AudioCoreTest, AudioCoreTest_InfoCtrlOps, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTINFOCTRLOPS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_CodecGetCtrlOps, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTCODECGETCTRLOPS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryGetCtrlOps, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYGETCTRLOPS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_CodecAiaoGetCtrlOps, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTCODECAIAOGETCTRLOPS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryAiaoGetCtrlOps, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYAIAOGETCTRLOPS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_CodecSetCtrlOps, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTCODECSETCTRLOPS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_AccessorySetCtrlOps, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYSETCTRLOPS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_CodecAiaoSetCtrlOps, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTCODECAIAOSETCTRLOPS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryAiaoSetCtrlOps, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYAIAOSETCTRLOPS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} +} diff --git a/model/audio/core/test/unittest/common/audio_host_test.cpp b/model/audio/core/test/unittest/common/audio_host_test.cpp index 52e23e8db..6632edb9a 100755 --- a/model/audio/core/test/unittest/common/audio_host_test.cpp +++ b/model/audio/core/test/unittest/common/audio_host_test.cpp @@ -12,6 +12,7 @@ using namespace testing::ext; +namespace { class AudioHostTest : public testing::Test { public: static void SetUpTestCase(); @@ -49,3 +50,4 @@ HWTEST_F(AudioHostTest, AudioHostTest_GetAudioServiceName, TestSize.Level0) struct HdfTestMsg msg = {g_testAudioType, TESTGETCARDINSTANCE, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } +} diff --git a/model/audio/core/test/unittest/common/audio_parse_test.cpp b/model/audio/core/test/unittest/common/audio_parse_test.cpp index 560cebd5e..6b612d03a 100755 --- a/model/audio/core/test/unittest/common/audio_parse_test.cpp +++ b/model/audio/core/test/unittest/common/audio_parse_test.cpp @@ -12,6 +12,7 @@ using namespace testing::ext; +namespace { class AudioParseTest : public testing::Test { public: static void SetUpTestCase(); @@ -43,3 +44,4 @@ HWTEST_F(AudioParseTest, AudioParseTest_GetConfigData, TestSize.Level0) struct HdfTestMsg msg = {g_testAudioType, TESTGETCCNFIGDATA, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } +} diff --git a/model/audio/device/accessory/include/accessory_adapter.h b/model/audio/device/accessory/include/accessory_adapter.h deleted file mode 100755 index 185bb7bc9..000000000 --- a/model/audio/device/accessory/include/accessory_adapter.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#ifndef ACCESSORY_ADAPTER_H -#define ACCESSORY_ADAPTER_H - -#include "audio_host.h" -#include "audio_control.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif /* __cplusplus */ - -struct AccessoryDevice { - const char *devAccessoryName; - struct AccessoryData *devData; - struct HdfDeviceObject *device; - struct DListHead list; - struct OsalMutex mutex; -}; - -struct AudioAccessoryOps { - const char *devAccessoryName; - struct AccessoryData *devData; - struct HdfDeviceObject *device; - struct DListHead list; -}; - -struct AccessoryData { - const char *drvAccessoryName; - /* Accessory driver callbacks */ - int32_t (*AccessoryInit)(struct AudioCard *, const struct AccessoryDevice *device); - int32_t (*Read)(const struct AccessoryDevice *, uint32_t, uint32_t *); - int32_t (*Write)(const struct AccessoryDevice *, uint32_t, uint32_t); - - const struct AudioKcontrol *controls; - int numControls; -}; - -/* Accessory host is defined in accessory driver */ -struct AccessoryHost { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - void *priv; -}; - - -int32_t ExternalCodecDeviceInit(struct AudioCard *audioCard, const struct AccessoryDevice *device); -int32_t ExternalCodecDeviceReadReg(const struct AccessoryDevice *codec, uint32_t reg, uint32_t *value); -int32_t ExternalCodecDeviceWriteReg(const struct AccessoryDevice *codec, uint32_t reg, uint32_t value); - -int32_t ExternalCodecDaiStartup(const struct AudioCard *card, const struct DaiDevice *device); -int32_t ExternalCodecDaiHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param, - const struct DaiDevice *device); -int32_t ExternalCodecDaiDeviceInit(const struct AudioCard *card, const struct DaiDevice *device); - - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - -#endif diff --git a/model/audio/device/accessory/src/accessory.c b/model/audio/device/accessory/src/accessory.c deleted file mode 100755 index bf2aaaf1f..000000000 --- a/model/audio/device/accessory/src/accessory.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#include "audio_core.h" -#include "accessory_adapter.h" -#include "audio_sapm.h" -#include "hdf_log.h" - -#define HDF_LOG_TAG "accessory" - -struct AccessoryData g_accessoryData = { - .AccessoryInit = ExternalCodecDeviceInit, - .Read = ExternalCodecDeviceReadReg, - .Write = ExternalCodecDeviceWriteReg, -}; - -struct AudioDaiOps g_accessoryDaiDeviceOps = { - .Startup = ExternalCodecDaiStartup, - .HwParams = ExternalCodecDaiHwParams, -}; - -struct DaiData g_accessoryDaiData = { - .drvDaiName = "accessory_dai", - .DaiInit = ExternalCodecDaiDeviceInit, - .ops = &g_accessoryDaiDeviceOps, -}; - -/* HdfDriverEntry */ -static int32_t GetServiceName(const struct HdfDeviceObject *device) -{ - const struct DeviceResourceNode *node = NULL; - struct DeviceResourceIface *drsOps = NULL; - int32_t ret; - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("input HdfDeviceObject object is nullptr."); - return HDF_FAILURE; - } - node = device->property; - if (node == NULL) { - AUDIO_DRIVER_LOG_ERR("get drs node is nullptr."); - return HDF_FAILURE; - } - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (drsOps == NULL || drsOps->GetString == NULL) { - AUDIO_DRIVER_LOG_ERR("drsOps or drsOps getString is null!"); - return HDF_FAILURE; - } - ret = drsOps->GetString(node, "serviceName", &g_accessoryData.drvAccessoryName, 0); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("read serviceName fail!"); - return ret; - } - return HDF_SUCCESS; -} - -/* HdfDriverEntry implementations */ -static int32_t AccessoryDriverInit(struct HdfDeviceObject *device) -{ - int32_t ret; - AUDIO_DRIVER_LOG_DEBUG("entry.\n"); - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("device is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - ret = GetServiceName(device); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("get service name fail."); - return ret; - } - ret = AudioRegisterAccessory(device, &g_accessoryData, &g_accessoryDaiData); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("register dai fail."); - return ret; - } - AUDIO_DRIVER_LOG_DEBUG("Success!\n"); - return HDF_SUCCESS; -} - -/* HdfDriverEntry implementations */ -static int32_t AccessoryDriverBind(struct HdfDeviceObject *device) -{ - (void)device; - return HDF_SUCCESS; -} - -/* HdfDriverEntry definitions */ -struct HdfDriverEntry g_accessoryDriverEntry = { - .moduleVersion = 1, - .moduleName = "CODEC_TFA9879", - .Bind = AccessoryDriverBind, - .Init = AccessoryDriverInit, - .Release = NULL, -}; -HDF_INIT(g_accessoryDriverEntry); diff --git a/model/audio/device/codec/include/codec_adapter.h b/model/audio/device/codec/include/codec_adapter.h deleted file mode 100755 index 4547c4430..000000000 --- a/model/audio/device/codec/include/codec_adapter.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#ifndef CODEC_ADAPTER_H -#define CODEC_ADAPTER_H - -#include "audio_host.h" -#include "audio_control.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif /* __cplusplus */ - -#define AUDIODRV_CTL_ELEM_IFACE_DAC 0 /* virtual dac device */ -#define AUDIODRV_CTL_ELEM_IFACE_ADC 1 /* virtual adc device */ -#define AUDIODRV_CTL_ELEM_IFACE_GAIN 2 /* virtual adc device */ -#define AUDIODRV_CTL_ELEM_IFACE_MIXER 3 /* virtual mixer device */ -#define AUDIODRV_CTL_ELEM_IFACE_ACODEC 4 /* Acodec device */ -#define AUDIODRV_CTL_ELEM_IFACE_PGA 5 /* PGA device */ -#define AUDIODRV_CTL_ELEM_IFACE_AIAO 6 /* AIAO device */ - -struct VirtualAddress { - unsigned long acodecVir; - unsigned long aiaoVir; -}; - -struct CodecDevice { - const char *devCodecName; - struct CodecData *devData; - struct HdfDeviceObject *device; - struct DListHead list; - struct OsalMutex mutex; -}; - -/* codec related definitions */ -struct CodecData { - const char *drvCodecName; - /* Codec driver callbacks */ - int32_t (*Init)(struct AudioCard *, struct CodecDevice *); - int32_t (*Read)(struct CodecDevice *, uint32_t, uint32_t *); - int32_t (*Write)(struct CodecDevice *, uint32_t, uint32_t); - int32_t (*AiaoRead)(struct CodecDevice *, uint32_t, uint32_t *); - int32_t (*AiaoWrite)(struct CodecDevice *, uint32_t, uint32_t); - const struct AudioKcontrol *controls; - int numControls; - const struct AudioSapmComponent *sapmComponents; - int numSapmComponent; - const struct AudioSapmRoute *sapmRoutes; - int numSapmRoutes; -}; - -/* Codec host is defined in codec driver */ -struct CodecHost { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - unsigned long priv; - unsigned long aiaoPriv; -}; - -enum AudioRegParams { - PLAYBACK_VOLUME = 0, - CAPTURE_VOLUME, - PLAYBACK_MUTE, - CAPTURE_MUTE, - LEFT_GAIN, - RIGHT_GAIN, - EXTERNAL_CODEC_ENABLE, - INTERNALLY_CODEC_ENABLE, - RENDER_CHANNEL_MODE, - CAPTRUE_CHANNEL_MODE, -}; - -enum SapmRegParams { - LPGA_MIC = 0, - RPGA_MIC, - DACL2DACR, - DACR2DACL, -}; - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - -#endif /* CODEC_CORE_H */ diff --git a/model/audio/device/codec/src/codec.c b/model/audio/device/codec/src/codec.c deleted file mode 100755 index a8f0262b5..000000000 --- a/model/audio/device/codec/src/codec.c +++ /dev/null @@ -1,644 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#include "codec_core.h" -#include "audio_core.h" -#include "audio_sapm.h" -#include "hi3516_aiao.h" -#include "hi3516_codec.h" -#include "osal_io.h" -#include "osal_irq.h" - -#define HDF_LOG_TAG codec - -#define ACODEC_CTRLREG0_ADDR 0x2c /* adcl,adcr, dacl, dacr power ctrl reg */ -#define ACODEC_DACREG1_ADDR 0x38 /* codec ctrl reg 3 */ -#define ACODEC_ADCREG0_ADDR 0x3c /* codec ctrl reg 4 */ -#define ACODEC_REG18_ADDR 0x48 /* codec ctrl reg 18 */ -#define ACODEC_ANACTRLREG0_ADDR 0x14 /* codec ana ctrl reg 0 */ -#define ACODEC_ANACTRLREG3_ADDR 0x20 /* codec ana ctrl reg 0 */ -#define ACODEC_CTRLREG1_ADDR 0x30 /* acodec ctrl reg1 */ -#define AIAO_RX_IF_ATTRI_ADDR 0x1000 /* aiao receive channel interface attribute */ -#define AIAO_TX_IF_ATTRI_ADDR 0x2000 /* aiao tranfer channel interface attribute */ -#define AIAO_TX_DSP_CTRL_ADDR 0x2004 - -static const struct AudioMixerControl g_audioRegParams[] = { - { - .reg = AIAO_TX_DSP_CTRL_ADDR, /* [0] output volume */ - .rreg = AIAO_TX_DSP_CTRL_ADDR, - .shift = 8, - .rshift = 8, - .min = 0x28, - .max = 0x7F, - .mask = 0x7F, - .invert = 0, - }, { - .reg = ACODEC_ADCREG0_ADDR, /* [1] input volume */ - .rreg = ACODEC_ADCREG0_ADDR, - .shift = 24, - .rshift = 24, - .min = 0x0, - .max = 0x57, - .mask = 0x7F, - .invert = 1, - }, { - .reg = ACODEC_DACREG1_ADDR, /* [2] output mute */ - .rreg = ACODEC_DACREG1_ADDR, - .shift = 31, - .rshift = 31, - .min = 0x0, - .max = 0x1, - .mask = 0x1, - .invert = 0, - }, { - .reg = ACODEC_ADCREG0_ADDR, /* [3] input mute */ - .rreg = ACODEC_ADCREG0_ADDR, - .shift = 31, - .rshift = 31, - .min = 0x0, - .max = 0x1, - .mask = 0x1, - .invert = 0, - }, { - .reg = ACODEC_ANACTRLREG3_ADDR, /* [4] left mic gain */ - .rreg = ACODEC_ANACTRLREG3_ADDR, - .shift = 16, - .rshift = 16, - .min = 0x0, - .max = 0xF, - .mask = 0x1F, - .invert = 0, - }, { - .reg = ACODEC_ANACTRLREG3_ADDR, /* [5] right mic gain */ - .rreg = ACODEC_ANACTRLREG3_ADDR, - .shift = 24, - .rshift = 24, - .min = 0x0, - .max = 0xF, - .mask = 0x1F, - .invert = 0, - }, { - .reg = ACODEC_REG18_ADDR, /* [6] external codec enable */ - .rreg = ACODEC_REG18_ADDR, - .shift = 1, - .rshift = 1, - .min = 0x0, - .max = 0x1, - .mask = 0x1, - .invert = 0, - }, { - .reg = ACODEC_REG18_ADDR, /* [7] internally codec enable */ - .rreg = ACODEC_REG18_ADDR, - .shift = 0, - .rshift = 0, - .min = 0x0, - .max = 0x1, - .mask = 0x1, - .invert = 0, - }, { - .reg = AIAO_TX_IF_ATTRI_ADDR, /* [8] aiao render channel mode */ - .rreg = AIAO_TX_IF_ATTRI_ADDR, - .shift = 16, - .rshift = 16, - .min = 0x0, - .max = 0x7, - .mask = 0x7, - .invert = 0, - }, { - .reg = AIAO_RX_IF_ATTRI_ADDR, /* [9] aiao capture channel mode */ - .rreg = AIAO_RX_IF_ATTRI_ADDR, - .shift = 16, - .rshift = 16, - .min = 0x0, - .max = 0x7, - .mask = 0x7, - .invert = 0, - }, -}; - -static const struct AudioKcontrol g_audioControls[] = { - { - .iface = AUDIODRV_CTL_ELEM_IFACE_DAC, - .name = "Master Playback Volume", - .Info = AudioInfoCtrlOps, - .Get = AiaoGetCtrlOps, - .Set = AiaoSetCtrlOps, - .privateValue = (unsigned long)&g_audioRegParams[PLAYBACK_VOLUME], - }, { - .iface = AUDIODRV_CTL_ELEM_IFACE_ADC, - .name = "Master Capture Volume", - .Info = AudioInfoCtrlOps, - .Get = AudioGetCtrlOps, - .Set = AudioSetCtrlOps, - .privateValue = (unsigned long)&g_audioRegParams[CAPTURE_VOLUME], - }, { - .iface = AUDIODRV_CTL_ELEM_IFACE_DAC, - .name = "Playback Mute", - .Info = AudioInfoCtrlOps, - .Get = AudioGetCtrlOps, - .Set = AudioSetCtrlOps, - .privateValue = (unsigned long)&g_audioRegParams[PLAYBACK_MUTE], - }, { - .iface = AUDIODRV_CTL_ELEM_IFACE_ADC, - .name = "Capture Mute", - .Info = AudioInfoCtrlOps, - .Get = AudioGetCtrlOps, - .Set = AudioSetCtrlOps, - .privateValue = (unsigned long)&g_audioRegParams[CAPTURE_MUTE], - }, { - .iface = AUDIODRV_CTL_ELEM_IFACE_GAIN, - .name = "Mic Left Gain", - .Info = AudioInfoCtrlOps, - .Get = AudioGetCtrlOps, - .Set = AudioSetCtrlOps, - .privateValue = (unsigned long)&g_audioRegParams[LEFT_GAIN], - }, { - .iface = AUDIODRV_CTL_ELEM_IFACE_GAIN, - .name = "Mic Right Gain", - .Info = AudioInfoCtrlOps, - .Get = AudioGetCtrlOps, - .Set = AudioSetCtrlOps, - .privateValue = (unsigned long)&g_audioRegParams[RIGHT_GAIN], - }, { - .iface = AUDIODRV_CTL_ELEM_IFACE_ACODEC, - .name = "External Codec Enable", - .Info = AudioInfoCtrlOps, - .Get = AudioGetCtrlOps, - .Set = AudioSetCtrlOps, - .privateValue = (unsigned long)&g_audioRegParams[EXTERNAL_CODEC_ENABLE], - }, { - .iface = AUDIODRV_CTL_ELEM_IFACE_ACODEC, - .name = "Internally Codec Enable", - .Info = AudioInfoCtrlOps, - .Get = AudioGetCtrlOps, - .Set = AudioSetCtrlOps, - .privateValue = (unsigned long)&g_audioRegParams[INTERNALLY_CODEC_ENABLE], - }, { - .iface = AUDIODRV_CTL_ELEM_IFACE_AIAO, - .name = "Render Channel Mode", - .Info = AudioInfoCtrlOps, - .Get = AiaoGetCtrlOps, - .Set = AiaoSetCtrlOps, - .privateValue = (unsigned long)&g_audioRegParams[RENDER_CHANNEL_MODE], - }, { - .iface = AUDIODRV_CTL_ELEM_IFACE_AIAO, - .name = "Captrue Channel Mode", - .Info = AudioInfoCtrlOps, - .Get = AiaoGetCtrlOps, - .Set = AiaoSetCtrlOps, - .privateValue = (unsigned long)&g_audioRegParams[CAPTRUE_CHANNEL_MODE], - }, -}; - -static const struct AudioMixerControl g_audioSapmRegParams[] = { - { - .reg = ACODEC_ANACTRLREG3_ADDR, /* LPGA MIC 0 -- connect MIC */ - .rreg = ACODEC_ANACTRLREG3_ADDR, - .shift = 23, - .rshift = 23, - .min = 0x0, - .max = 0x1, - .mask = 0x1, - .invert = 0, - }, { - .reg = ACODEC_ANACTRLREG3_ADDR, /* RPGA MIC 0 -- connect MIC */ - .rreg = ACODEC_ANACTRLREG3_ADDR, - .shift = 31, - .rshift = 31, - .min = 0x0, - .max = 0x1, - .mask = 0x1, - .invert = 0, - }, { - .reg = ACODEC_CTRLREG1_ADDR, /* [2] dacl to dacr mixer */ - .rreg = ACODEC_CTRLREG1_ADDR, - .shift = 27, - .rshift = 27, - .min = 0x0, - .max = 0x1, - .mask = 0x1, - .invert = 0, - }, { - .reg = ACODEC_CTRLREG1_ADDR, /* [3] dacr to dacl mixer */ - .rreg = ACODEC_CTRLREG1_ADDR, - .shift = 26, - .rshift = 26, - .min = 0x0, - .max = 0x1, - .mask = 0x1, - .invert = 0, - }, -}; - -static struct AudioKcontrol g_audioSapmDACLControls[] = { - { - .iface = AUDIODRV_CTL_ELEM_IFACE_DAC, - .name = "Dacl enable", - .Info = AudioInfoCtrlOps, - .Get = AudioSapmGetCtrlOps, - .Set = AudioSapmSetCtrlOps, - .privateValue = (unsigned long)&g_audioSapmRegParams[DACL2DACR], - }, -}; - -static struct AudioKcontrol g_audioSapmDACRControls[] = { - { - .iface = AUDIODRV_CTL_ELEM_IFACE_DAC, - .name = "Dacr enable", - .Info = AudioInfoCtrlOps, - .Get = AudioSapmGetCtrlOps, - .Set = AudioSapmSetCtrlOps, - .privateValue = (unsigned long)&g_audioSapmRegParams[DACR2DACL], - }, -}; - -static struct AudioKcontrol g_audioSapmLPGAControls[] = { - { - .iface = AUDIODRV_CTL_ELEM_IFACE_PGA, - .name = "LPGA MIC Switch", - .Info = AudioInfoCtrlOps, - .Get = AudioSapmGetCtrlOps, - .Set = AudioSapmSetCtrlOps, - .privateValue = (unsigned long)&g_audioSapmRegParams[LPGA_MIC], - }, -}; - -static struct AudioKcontrol g_audioSapmRPGAControls[] = { - { - .iface = AUDIODRV_CTL_ELEM_IFACE_PGA, - .name = "RPGA MIC Switch", - .Info = AudioInfoCtrlOps, - .Get = AudioSapmGetCtrlOps, - .Set = AudioSapmSetCtrlOps, - .privateValue = (unsigned long)&g_audioSapmRegParams[RPGA_MIC], - }, -}; - -static const struct AudioSapmComponent g_streamDomainComponents[] = { - { - .sapmType = AUDIO_SAPM_ADC, /* ADCL */ - .componentName = "ADCL", - .reg = ACODEC_ANACTRLREG3_ADDR, - .mask = 0x1, - .shift = 15, - .invert = 1, - }, { - .sapmType = AUDIO_SAPM_ADC, /* ADCR */ - .componentName = "ADCR", - .reg = ACODEC_ANACTRLREG3_ADDR, - .mask = 0x1, - .shift = 14, - .invert = 0, - }, { - .sapmType = AUDIO_SAPM_DAC, /* DACL */ - .componentName = "DACL", - .reg = ACODEC_ANACTRLREG0_ADDR, - .mask = 0x1, - .shift = 11, - .invert = 0, - }, { - .sapmType = AUDIO_SAPM_DAC, /* DACR */ - .componentName = "DACR", - .reg = ACODEC_ANACTRLREG0_ADDR, - .mask = 0x1, - .shift = 12, - .invert = 0, - }, { - .sapmType = AUDIO_SAPM_PGA, /* LPGA */ - .componentName = "LPGA", - .reg = ACODEC_ANACTRLREG3_ADDR, - .mask = 0x1, - .shift = 13, - .invert = 0, - .kcontrolNews = g_audioSapmLPGAControls, - .kcontrolsNum = ARRAY_SIZE(g_audioSapmLPGAControls), - }, { - .sapmType = AUDIO_SAPM_PGA, /* RPGA */ - .componentName = "RPGA", - .reg = ACODEC_ANACTRLREG3_ADDR, - .mask = 0x1, - .shift = 12, - .invert = 0, - .kcontrolNews = g_audioSapmRPGAControls, - .kcontrolsNum = ARRAY_SIZE(g_audioSapmRPGAControls), - }, { - .sapmType = AUDIO_SAPM_SPK, /* SPKL */ - .componentName = "SPKL", - .reg = AUDIO_SAPM_NOPM, - .mask = 0x1, - .shift = 0, - .invert = 0, - .kcontrolNews = g_audioSapmDACLControls, - .kcontrolsNum = ARRAY_SIZE(g_audioSapmDACLControls), - }, { - .sapmType = AUDIO_SAPM_SPK, /* SPKR */ - .componentName = "SPKR", - .reg = AUDIO_SAPM_NOPM, - .mask = 0x1, - .shift = 0, - .invert = 0, - .kcontrolNews = g_audioSapmDACRControls, - .kcontrolsNum = ARRAY_SIZE(g_audioSapmDACRControls), - }, { - .sapmType = AUDIO_SAPM_MIC, /* MIC */ - .componentName = "MIC", - .reg = AUDIO_SAPM_NOPM, - .mask = 0x1, - .shift = 0, - .invert = 0, - }, -}; - -static const struct AudioSapmRoute g_audioRoutes[] = { - { "SPKL", "Dacl enable", "DACL"}, - { "SPKR", "Dacr enable", "DACR"}, - - { "ADCL", NULL, "LPGA"}, - { "LPGA", "LPGA MIC Switch", "MIC"}, - - { "ADCR", NULL, "RPGA"}, - { "RPGA", "RPGA MIC Switch", "MIC"}, -}; - -static int32_t CodecDeviceInit(struct AudioCard *audioCard, struct CodecDevice *codec) -{ - const int innerCodecEnable = 7; - struct VirtualAddress *virtualAdd = NULL; - struct AudioMixerControl mixerCtrl = g_audioRegParams[innerCodecEnable]; - void *device = NULL; - - AUDIO_DRIVER_LOG_DEBUG("entry."); - if ((audioCard == NULL) || (audioCard->rtd == NULL || audioCard->rtd->codec == NULL) || - (codec == NULL || codec->device == NULL)) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - virtualAdd = (struct VirtualAddress *)OsalMemCalloc(sizeof(struct VirtualAddress)); - if (virtualAdd == NULL) { - AUDIO_DRIVER_LOG_ERR("virtualAdd fail!"); - return HDF_ERR_MALLOC_FAIL; - } - virtualAdd->acodecVir = (uintptr_t)OsalIoRemap(ACODEC_REG_BASE, ACODEC_MAX_REG_SIZE); - virtualAdd->aiaoVir = (uintptr_t)OsalIoRemap(AIAO_REG_BASE, AIAO_MAX_REG_SIZE); - codec->device->priv = virtualAdd; - - /* default inner codec */ - device = (void *)audioCard->rtd->codec; - if (AudioUpdateRegBits(AUDIO_CODEC_DEVICE, device, &mixerCtrl, 1) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("update reg bits fail."); - return HDF_FAILURE; - } - - /* INIT */ - if (CodecHalSysInit() != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("CodecHalSysInit fail."); - return HDF_FAILURE; - } - - /* Acode init */ - AcodecDeviceInit(); - - if (AudioAddControls(audioCard, codec->devData->controls, codec->devData->numControls) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("add controls fail."); - return HDF_FAILURE; - } - - if (AudioSapmNewComponents(audioCard, codec->devData->sapmComponents, - codec->devData->numSapmComponent) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("new components fail."); - return HDF_FAILURE; - } - - if (AudioSapmAddRoutes(audioCard, codec->devData->sapmRoutes, - codec->devData->numSapmRoutes) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("add route fail."); - return HDF_FAILURE; - } - - if (AudioSapmNewControls(audioCard) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("add sapm controls fail."); - return HDF_FAILURE; - } - - AUDIO_DRIVER_LOG_DEBUG("success."); - return HDF_SUCCESS; -} - -int32_t CodecDaiDeviceInit(const struct AudioCard *card, const struct DaiDevice *device) -{ - if (device == NULL || device->devDaiName == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_FAILURE; - } - - AUDIO_DRIVER_LOG_DEBUG("codec dai device name: %s\n", device->devDaiName); - (void)card; - return HDF_SUCCESS; -} - -static int32_t FramatToBitWidth(enum AudioFormat format, unsigned int *bitWidth) -{ - switch (format) { - case AUDIO_FORMAT_PCM_8_BIT: - *bitWidth = BIT_WIDTH8; - break; - - case AUDIO_FORMAT_PCM_16_BIT: - *bitWidth = BIT_WIDTH16; - break; - - case AUDIO_FORMAT_PCM_24_BIT: - *bitWidth = BIT_WIDTH24; - break; - - case AUDIO_FORMAT_PCM_32_BIT: - *bitWidth = BIT_WIDTH32; - break; - - case AUDIO_FORMAT_AAC_MAIN: - case AUDIO_FORMAT_AAC_LC: - case AUDIO_FORMAT_AAC_LD: - case AUDIO_FORMAT_AAC_ELD: - case AUDIO_FORMAT_AAC_HE_V1: - case AUDIO_FORMAT_AAC_HE_V2: - break; - - default: - AUDIO_DRIVER_LOG_ERR("format: %d is not define.", format); - return HI_FAILURE; - break; - } - - return HI_SUCCESS; -} - - -int32_t CodecDaiHwParams(const struct AudioCard *card, - const struct AudioPcmHwParams *param, const struct DaiDevice *device) -{ - int ret; - unsigned int bitWidth; - (void)card; - (void)device; - - AUDIO_DRIVER_LOG_DEBUG("entry."); - if (param == NULL || param->cardServiceName == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_FAILURE; - } - - ret = FramatToBitWidth(param->format, &bitWidth); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("FramatToBitWidth: faile."); - return HDF_FAILURE; - } - - ret = AcodecSetI2s1Fs(param->rate); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AcodecSetI2s1Fs fail."); - return HDF_FAILURE; - } - - ret = AcodecSetI2s1DataWidth(bitWidth); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AcodecSetI2s1DataWidth fail."); - return HDF_FAILURE; - } - - AUDIO_DRIVER_LOG_DEBUG("channels = %d, rate = %d, periodSize = %d, \ - periodCount = %d, format = %d, cardServiceName = %s \n", - param->channels, param->rate, param->periodSize, - param->periodCount, (uint32_t)param->format, param->cardServiceName); - - AUDIO_DRIVER_LOG_DEBUG("success."); - return HDF_SUCCESS; -} - -int32_t CodecDaiStartup(const struct AudioCard *card, const struct DaiDevice *device) -{ - (void)card; - (void)device; - - return HDF_SUCCESS; -} - -struct CodecData g_codecData = { - .Init = CodecDeviceInit, - .Read = CodecDeviceReadReg, - .Write = CodecDeviceWriteReg, - .AiaoRead = AiaoDeviceReadReg, - .AiaoWrite = AiaoDeviceWriteReg, - .controls = g_audioControls, - .numControls = ARRAY_SIZE(g_audioControls), - .sapmComponents = g_streamDomainComponents, - .numSapmComponent = ARRAY_SIZE(g_streamDomainComponents), - .sapmRoutes = g_audioRoutes, - .numSapmRoutes = ARRAY_SIZE(g_audioRoutes), -}; - -struct AudioDaiOps g_codecDaiDeviceOps = { - .Startup = CodecDaiStartup, - .HwParams = CodecDaiHwParams, -}; - -struct DaiData g_codecDaiData = { - .DaiInit = CodecDaiDeviceInit, - .ops = &g_codecDaiDeviceOps, -}; - -/* HdfDriverEntry implementations */ -static int32_t CodecDriverBind(struct HdfDeviceObject *device) -{ - struct CodecHost *codecHost = NULL; - - AUDIO_DRIVER_LOG_DEBUG("entry!"); - - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_FAILURE; - } - - codecHost = (struct CodecHost *)OsalMemCalloc(sizeof(*codecHost)); - if (codecHost == NULL) { - AUDIO_DRIVER_LOG_ERR("malloc host fail!"); - return HDF_FAILURE; - } - - codecHost->device = device; - device->service = &codecHost->service; - - AUDIO_DRIVER_LOG_DEBUG("success!"); - return HDF_SUCCESS; -} - -static int32_t CodecDriverInit(struct HdfDeviceObject *device) -{ - int32_t ret; - - AUDIO_DRIVER_LOG_DEBUG("entry."); - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("device is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - - ret = CodecGetServiceName(device, &g_codecData.drvCodecName); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("get codec service name fail."); - return ret; - } - - ret = CodecGetDaiName(device, &g_codecDaiData.drvDaiName); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("get codec dai name fail."); - return ret; - } - - ret = AudioRegisterCodec(device, &g_codecData, &g_codecDaiData); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("register dai fail."); - return ret; - } - - AUDIO_DRIVER_LOG_DEBUG("Success."); - return HDF_SUCCESS; -} - -static void CodecDriverRelease(struct HdfDeviceObject *device) -{ - struct CodecHost *codecHost = NULL; - struct VirtualAddress *virtualAdd = NULL; - - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("device is NULL"); - return; - } - - if (device->priv != NULL) { - virtualAdd = (struct VirtualAddress *)device->priv; - OsalIoUnmap((void *)((uintptr_t)(void*)&virtualAdd->acodecVir)); - OsalIoUnmap((void *)((uintptr_t)(void*)&virtualAdd->aiaoVir)); - OsalMemFree(device->priv); - } - - codecHost = (struct CodecHost *)device->service; - if (codecHost == NULL) { - HDF_LOGE("CodecDriverRelease: codecHost is NULL"); - return; - } - OsalMemFree(codecHost); -} - -/* HdfDriverEntry definitions */ -struct HdfDriverEntry g_codecDriverEntry = { - .moduleVersion = 1, - .moduleName = "CODEC_HI3516", - .Bind = CodecDriverBind, - .Init = CodecDriverInit, - .Release = CodecDriverRelease, -}; -HDF_INIT(g_codecDriverEntry); diff --git a/model/audio/device/soc/include/dsp_adapter.h b/model/audio/device/soc/include/dsp_adapter.h deleted file mode 100755 index b36b39b29..000000000 --- a/model/audio/device/soc/include/dsp_adapter.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#ifndef DSP_ADAPTER_H -#define DSP_ADAPTER_H -#include "audio_host.h" -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif /* __cplusplus */ - -struct DspDevice { - const char *devDspName; - struct DspData *devData; - struct HdfDeviceObject *device; - struct DListHead list; -}; - -struct AudioDspOps { - int32_t (*Startup)(const struct AudioCard *, const struct DspDevice *); - int32_t (*HwParams)(const struct AudioCard *, const struct AudioPcmHwParams *, const struct DspDevice *); - int32_t (*Trigger)(struct AudioCard *, int, struct DspDevice *); -}; - -struct DspData { - const char *drvDspName; - /* dsp driver callbacks */ - int32_t (*DspInit)(const struct DspDevice *device); - int32_t (*Read)(struct DspDevice *, uint8_t *, uint32_t); - int32_t (*Write)(struct DspDevice *, uint8_t *, uint32_t); - int32_t (*decode)(const struct AudioCard *, const uint8_t *, const struct DspDevice *); - int32_t (*encode)(const struct AudioCard *, const uint8_t *, const struct DspDevice *); - int32_t (*Equalizer)(const struct AudioCard *, const uint8_t *, const struct DspDevice *); -}; - -/* Dsp host is defined in dsp driver */ -struct DspHost { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - void *priv; -}; - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - -#endif diff --git a/model/audio/device/soc/include/platform_adapter.h b/model/audio/device/soc/include/platform_adapter.h deleted file mode 100755 index 4dc4fea0a..000000000 --- a/model/audio/device/soc/include/platform_adapter.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#ifndef PLATFORM_ADAPTER_H -#define PLATFORM_ADAPTER_H - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif /* __cplusplus */ - -#define I2S_IOCFG2_BASE1 0x0020 -#define I2S_IOCFG2_BASE2 0x0024 -#define I2S_IOCFG2_BASE3 0x0028 -#define I2S_IOCFG2_BASE4 0x002C -#define I2S_IOCFG2_BASE5 0x0030 - -#define I2S_IOCFG2_BASE1_VAL 0x663 -#define I2S_IOCFG2_BASE2_VAL 0x673 -#define I2S_IOCFG2_BASE3_VAL 0x573 -#define I2S_IOCFG2_BASE4_VAL 0x473 -#define I2S_IOCFG2_BASE5_VAL 0x433 - -#define I2S_IOCFG3_BASE1 0x44 -#define I2S_IOCFG3_BASE1_VAL 0x0600 - -#define GPIO_BASE1 0x2010 -#define GPIO_BASE2 0x2400 -#define GPIO_BASE3 0x2010 - -#define GPIO_BASE2_VAL 0x000000ff -#define GPIO_BASE3_VAL 0x00000000 - -#define IOCFG2_BASE_ADDR 0x112F0000 -#define IOCFG3_BASE_ADDR 0x10FF0000 -#define GPIO_BASE_ADDR 0x120D0000 -#define BASE_ADDR_REMAP_SIZE 0x10000 - -struct CircleBufInfo { - uint32_t cirBufSize; - uint32_t trafBufSize; - uint32_t period; - uint32_t periodSize; - uint32_t periodCount; - unsigned long phyAddr; - uint32_t *virtAddr; - uint32_t wbufOffSet; - uint32_t wptrOffSet; - uint32_t runStatus; - uint32_t chnId; - uint32_t enable; - struct OsalMutex buffMutex; -}; - -struct PcmInfo { - /* The number of channels in a frame */ - uint32_t channels; - /* The number of frames per second */ - uint32_t rate; - uint32_t bitWidth; - uint32_t frameSize; - bool isBigEndian; - bool isSignedData; - uint32_t startThreshold; - uint32_t stopThreshold; - uint32_t silenceThreshold; - uint32_t totalStreamSize; -}; - -/* platform related definitions */ -struct AudioPlatformOps { - int32_t (*HwParams)(const struct AudioCard *, const struct AudioPcmHwParams *); - int32_t (*RenderTrigger)(struct AudioCard *, int); - int32_t (*CaptureTrigger)(struct AudioCard *, int); - uint32_t (*Pointer)(struct AudioCard *); - int32_t (*Write)(const struct AudioCard *, struct AudioTxData *); - int32_t (*Read)(const struct AudioCard *, struct AudioRxData *); - int32_t (*RenderPrepare)(const struct AudioCard *); - int32_t (*CapturePrepare)(const struct AudioCard *); - int32_t (*RenderStart)(const struct AudioCard *); - int32_t (*CaptureStart)(const struct AudioCard *); - int32_t (*RenderStop)(const struct AudioCard *); - int32_t (*CaptureStop)(const struct AudioCard *); - int32_t (*RenderPause)(const struct AudioCard *); - int32_t (*CapturePause)(const struct AudioCard *); - int32_t (*RenderResume)(const struct AudioCard *); - int32_t (*CaptureResume)(const struct AudioCard *); -}; - -struct PlatformDevice { - const char *devPlatformName; - struct PlatformData *devData; - struct HdfDeviceObject *device; - struct DListHead list; -}; - -struct PlatformData { - const char *drvPlatformName; - /* platform driver callbacks */ - int32_t (*PlatformInit)(const struct AudioCard *, const struct PlatformDevice *); - /* pcm creation and destruction */ - int32_t (*PcmNew)(struct PlatformDevice *); - void (*PcmFree)(struct PlatformDevice *); - /* platform stream ops */ - struct AudioPlatformOps *ops; -}; - -/* Platform host is defined in platform driver */ -struct PlatformHost { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - void *priv; - bool platformInitFlag; - struct CircleBufInfo renderBufInfo; - struct CircleBufInfo captureBufInfo; - struct PcmInfo pcmInfo; -}; - -static inline struct PlatformHost *PlatformHostFromDevice(struct HdfDeviceObject *device) -{ - return (device == NULL) ? NULL : (struct PlatformHost *)device->service; -} - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - -#endif diff --git a/model/audio/device/soc/src/dai.c b/model/audio/device/soc/src/dai.c deleted file mode 100755 index afdf81f65..000000000 --- a/model/audio/device/soc/src/dai.c +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#include "audio_core.h" -#include "hi3516_aiao.h" -#include "hi3516_codec.h" -#include "osal_io.h" - -#define HDF_LOG_TAG dai - -/* HdfDriverEntry implementations */ -static int32_t DaiDriverBind(struct HdfDeviceObject *device) -{ - struct DaiHost *daiHost = NULL; - AUDIO_DRIVER_LOG_DEBUG("entry!"); - - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_FAILURE; - } - - daiHost = (struct DaiHost *)OsalMemCalloc(sizeof(*daiHost)); - if (daiHost == NULL) { - AUDIO_DRIVER_LOG_ERR("malloc host fail!"); - return HDF_FAILURE; - } - - daiHost->device = device; - daiHost->daiInitFlag = false; - device->service = &daiHost->service; - - AUDIO_DRIVER_LOG_DEBUG("success!"); - return HDF_SUCCESS; -} - -int32_t DaiDeviceInit(const struct AudioCard *audioCard, const struct DaiDevice *dai) -{ - int ret; - struct DaiHost *daiHost = NULL; - unsigned int chnId = 0; - - if (dai == NULL || dai->device == NULL || dai->devDaiName == NULL) { - AUDIO_DRIVER_LOG_ERR("dai is nullptr."); - return HDF_FAILURE; - } - AUDIO_DRIVER_LOG_DEBUG("cpu dai device name: %s\n", dai->devDaiName); - (void)audioCard; - - daiHost = (struct DaiHost *)dai->device->service; - if (daiHost == NULL) { - AUDIO_DRIVER_LOG_ERR("dai host is NULL."); - return HDF_FAILURE; - } - - if (daiHost->daiInitFlag == true) { - AUDIO_DRIVER_LOG_DEBUG("dai init complete!"); - return HDF_SUCCESS; - } - - ret = AiaoHalSysInit(); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AiaoHalSysInit: fail."); - return HDF_FAILURE; - } - - ret = I2sCrgCfgInit(chnId); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AiaoHalSysInit: fail."); - return HDF_FAILURE; - } - - daiHost->daiInitFlag = true; - - return HDF_SUCCESS; -} - -static int32_t CheckSampleRate(unsigned int sampleRates) -{ - bool checkSampleRate = (sampleRates == AUDIO_SAMPLE_RATE_8000 || - sampleRates == AUDIO_SAMPLE_RATE_12000 || - sampleRates == AUDIO_SAMPLE_RATE_11025 || - sampleRates == AUDIO_SAMPLE_RATE_16000 || - sampleRates == AUDIO_SAMPLE_RATE_22050 || - sampleRates == AUDIO_SAMPLE_RATE_24000 || - sampleRates == AUDIO_SAMPLE_RATE_32000 || - sampleRates == AUDIO_SAMPLE_RATE_44100 || - sampleRates == AUDIO_SAMPLE_RATE_48000 || - sampleRates == AUDIO_SAMPLE_RATE_64000 || - sampleRates == AUDIO_SAMPLE_RATE_96000); - if (checkSampleRate) { - return HDF_SUCCESS; - } else { - AUDIO_DRIVER_LOG_ERR("FramatToSampleRate fail: Invalid sampling rate: %d.", sampleRates); - return HI_FAILURE; - } -} - -static int32_t FramatToBitWidth(enum AudioFormat format, unsigned int *bitWidth) -{ - switch (format) { - case AUDIO_FORMAT_PCM_16_BIT: - *bitWidth = BIT_WIDTH16; - break; - - case AUDIO_FORMAT_PCM_24_BIT: - *bitWidth = BIT_WIDTH24; - break; - - default: - AUDIO_DRIVER_LOG_ERR("format: %d is not define.", format); - return HI_FAILURE; - break; - } - - return HDF_SUCCESS; -} - -int32_t AiSetClkAttr(struct PlatformHost *platformHost, const struct AudioPcmHwParams *param) -{ - int ret; - unsigned int bitWidth; - - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("platform host is NULL."); - return HDF_FAILURE; - } - - if (param == NULL) { - AUDIO_DRIVER_LOG_ERR("param is NULL."); - return HDF_FAILURE; - } - - ret = FramatToBitWidth(param->format, &bitWidth); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("FramatToBitWidth: fail."); - return HDF_FAILURE; - } - platformHost->pcmInfo.bitWidth = bitWidth; - - ret = AipSetSysCtlReg(platformHost->captureBufInfo.chnId, param->channels, bitWidth, param->rate); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AiSetClkAttr: fail."); - return HDF_FAILURE; - } - - ret = AipSetAttr(platformHost->captureBufInfo.chnId, param->channels, bitWidth); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AiSetClkAttr: fail."); - return HDF_FAILURE; - } - - return HDF_SUCCESS; -} - -int32_t AoSetClkAttr(struct PlatformHost *platformHost, const struct AudioPcmHwParams *param) -{ - int ret; - unsigned int bitWidth; - - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("platform host is nullptr."); - return HDF_FAILURE; - } - - if (param == NULL) { - AUDIO_DRIVER_LOG_ERR("param is nullptr."); - return HDF_FAILURE; - } - - ret = FramatToBitWidth(param->format, &bitWidth); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("FramatToBitWidth: fail."); - return HDF_FAILURE; - } - platformHost->pcmInfo.bitWidth = bitWidth; - - ret = AopSetSysCtlReg(platformHost->renderBufInfo.chnId, param->channels, bitWidth, param->rate); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("PlatformAopSetSysCtl: fail."); - return HDF_FAILURE; - } - - ret = AopSetAttr(platformHost->renderBufInfo.chnId, param->channels, bitWidth); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("PlatformAopSetAttrReg: fail."); - return HDF_FAILURE; - } - - AUDIO_DRIVER_LOG_DEBUG("bitWidth: %d.", bitWidth); - - return HDF_SUCCESS; -} - -int32_t DaiHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param, const struct DaiDevice *device) -{ - struct PlatformHost *platformHost = NULL; - int ret; - (void)device; - - AUDIO_DRIVER_LOG_DEBUG("entry."); - - if (card == NULL || card->rtd == NULL || card->rtd->platform == NULL || - param == NULL || param->cardServiceName == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is nullptr."); - return HDF_FAILURE; - } - - ret = CheckSampleRate(param->rate); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("CheckSampleRate: fail."); - return HDF_FAILURE; - } - - platformHost = PlatformHostFromDevice(card->rtd->platform->device); - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("platformHost is nullptr."); - return HDF_FAILURE; - } - - if (param->streamType == AUDIO_RENDER_STREAM) { - ret = AoSetClkAttr(platformHost, param); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AoSetClkAttr: fail."); - return HDF_FAILURE; - } - } else if (param->streamType == AUDIO_CAPTURE_STREAM) { - ret = AiSetClkAttr(platformHost, param); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AiSetClkAttr: fail."); - return HDF_FAILURE; - } - } else { - AUDIO_DRIVER_LOG_ERR("param streamType is invalid."); - return HDF_FAILURE; - } - - AUDIO_DRIVER_LOG_DEBUG("channels = %d, rate = %d, periodSize = %d, \ - periodCount = %d, format = %d, cardServiceName = %s \n", - param->channels, param->rate, param->periodSize, - param->periodCount, (uint32_t)param->format, param->cardServiceName); - - AUDIO_DRIVER_LOG_DEBUG("success."); - return HDF_SUCCESS; -} - -int32_t DaiTrigger(const struct AudioCard *card, int cmd, const struct DaiDevice *device) -{ - (void)card; - (void)device; - (void)cmd; - - return HDF_SUCCESS; -} - -struct AudioDaiOps g_daiDeviceOps = { - .HwParams = DaiHwParams, - .Trigger = DaiTrigger, -}; - -struct DaiData g_daiData = { - .DaiInit = DaiDeviceInit, - .ops = &g_daiDeviceOps, -}; - -static int32_t DaiGetServiceName(const struct HdfDeviceObject *device) -{ - const struct DeviceResourceNode *node = NULL; - struct DeviceResourceIface *drsOps = NULL; - int32_t ret; - - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is nullptr."); - return HDF_FAILURE; - } - - node = device->property; - if (node == NULL) { - AUDIO_DRIVER_LOG_ERR("drs node is nullptr."); - return HDF_FAILURE; - } - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (drsOps == NULL || drsOps->GetString == NULL) { - AUDIO_DRIVER_LOG_ERR("invalid drs ops fail!"); - return HDF_FAILURE; - } - - ret = drsOps->GetString(node, "serviceName", &g_daiData.drvDaiName, 0); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("read serviceName fail!"); - return ret; - } - - return HDF_SUCCESS; -} - -static int32_t DaiDriverInit(struct HdfDeviceObject *device) -{ - int32_t ret; - AUDIO_DRIVER_LOG_DEBUG("entry.\n"); - - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("device is nullptr."); - return HDF_ERR_INVALID_OBJECT; - } - - ret = DaiGetServiceName(device); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("get service name fail."); - return ret; - } - - ret = AudioSocDeviceRegister(device, (void *)&g_daiData, AUDIO_DAI_DEVICE); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("register dai fail."); - return ret; - } - - AUDIO_DRIVER_LOG_DEBUG("success.\n"); - return HDF_SUCCESS; -} - -/* HdfDriverEntry definitions */ -struct HdfDriverEntry g_daiDriverEntry = { - .moduleVersion = 1, - .moduleName = "DAI_HI3516", - .Bind = DaiDriverBind, - .Init = DaiDriverInit, - .Release = NULL, -}; -HDF_INIT(g_daiDriverEntry); diff --git a/model/audio/device/soc/src/dsp.c b/model/audio/device/soc/src/dsp.c deleted file mode 100755 index 518d73b6d..000000000 --- a/model/audio/device/soc/src/dsp.c +++ /dev/null @@ -1,483 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#include "audio_core.h" -#include "dsp_adapter.h" -#include "gpio_if.h" -#include "spi_if.h" -#include "tfa9879_codec.h" -#define DEFAULT_SPEED 2000000 -#define BITS_PER_WORD_EIGHT 8 -#define DSP_CS_NUM 1 -#define DSP_SPI_BUS_NUM 1 - -#define HDF_LOG_TAG dsp - -static int32_t DspLinkDeviceInit(const struct AudioCard *card, const struct DaiDevice *device); -static int32_t DspDeviceInit(const struct DspDevice *device); -static int32_t DspDeviceReadReg(struct DspDevice *device, uint8_t *buf, uint32_t len); -static int32_t DspDeviceWriteReg(struct DspDevice *device, uint8_t *buf, uint32_t len); -static int32_t DspLinkStartup(const struct AudioCard *card, const struct DaiDevice *device); -static int32_t DspLinkHwParams(const struct AudioCard *card, - const struct AudioPcmHwParams *param, const struct DaiDevice *device); -static int32_t DspDecodeAudioStream(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device); -static int32_t DspEncodeAudioStream(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device); -static int32_t DspEqualizerActive(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device); - -struct DspData g_dspData = { - .DspInit = DspDeviceInit, - .Read = DspDeviceReadReg, - .Write = DspDeviceWriteReg, - .decode = DspDecodeAudioStream, - .encode = DspEncodeAudioStream, - .Equalizer = DspEqualizerActive, -}; - -struct AudioDaiOps g_dspLinkDeviceOps = { - .Startup = DspLinkStartup, - .HwParams = DspLinkHwParams, -}; - -struct DaiData g_dspDaiData = { - .DaiInit = DspLinkDeviceInit, - .ops = &g_dspLinkDeviceOps, -}; - -struct SpiDevInfo g_devInfo = { - .busNum = DSP_SPI_BUS_NUM, - .csNum = DSP_CS_NUM, -}; - -static int32_t DspLinkStartup(const struct AudioCard *card, const struct DaiDevice *device) -{ - (void)card; - (void)device; - return HDF_SUCCESS; -} - -static int32_t DspCfgI2sFrequency(uint32_t rate, uint16_t *frequency) -{ - switch (rate) { - case I2S_SAMPLE_FREQUENCY_8000: - *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_8000; - break; - case I2S_SAMPLE_FREQUENCY_11025: - *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_11025; - break; - case I2S_SAMPLE_FREQUENCY_12000: - *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_12000; - break; - case I2S_SAMPLE_FREQUENCY_16000: - *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_16000; - break; - case I2S_SAMPLE_FREQUENCY_22050: - *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_22050; - break; - case I2S_SAMPLE_FREQUENCY_24000: - *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_24000; - break; - case I2S_SAMPLE_FREQUENCY_32000: - *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_32000; - break; - case I2S_SAMPLE_FREQUENCY_44100: - *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_44100; - break; - case I2S_SAMPLE_FREQUENCY_48000: - *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_48000; - break; - case I2S_SAMPLE_FREQUENCY_64000: - *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_64000; - break; - case I2S_SAMPLE_FREQUENCY_88200: - *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_88200; - break; - case I2S_SAMPLE_FREQUENCY_96000: - *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_96000; - break; - default: - AUDIO_DRIVER_LOG_ERR("rate: %d is not support.", rate); - return HDF_ERR_NOT_SUPPORT; - } - return HDF_SUCCESS; -} - -static int32_t DspSetI2sBitWidth(enum AudioFormat format, uint16_t *bitWidth) -{ - switch (format) { - case AUDIO_FORMAT_PCM_8_BIT: - *bitWidth = I2S_SAMPLE_FORMAT_REG_VAL_24; - break; - case AUDIO_FORMAT_PCM_16_BIT: - *bitWidth = I2S_SAMPLE_FORMAT_REG_VAL_24; - break; - case AUDIO_FORMAT_PCM_24_BIT: - *bitWidth = I2S_SAMPLE_FORMAT_REG_VAL_24; - break; - default: - AUDIO_DRIVER_LOG_ERR("format: %d is not support.", format); - return HDF_ERR_NOT_SUPPORT; - } - return HDF_SUCCESS; -} - -static int DspSetI2sFrequency(uint16_t frequencyVal) -{ - return HDF_SUCCESS; -} - -static int DspSetI2sFormat(uint16_t formatVal) -{ - return HDF_SUCCESS; -} - -static int32_t DspLinkHwParams(const struct AudioCard *card, - const struct AudioPcmHwParams *param, const struct DaiDevice *device) -{ - int ret; - uint16_t frequency, bitWidth; - (void)card; - (void)device; - AUDIO_DRIVER_LOG_DEBUG("entry."); - if (param == NULL || param->cardServiceName == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is nullptr."); - return HDF_ERR_INVALID_PARAM; - } - ret = DspCfgI2sFrequency(param->rate, &frequency); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("RateToFrequency fail."); - return HDF_ERR_NOT_SUPPORT; - } - ret = DspSetI2sBitWidth(param->format, &bitWidth); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("FormatToBitWidth fail."); - return HDF_ERR_NOT_SUPPORT; - } - ret = DspSetI2sFrequency(frequency); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("SetDspI2sFs fail."); - return HDF_FAILURE; - } - ret = DspSetI2sFormat(bitWidth); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("SetDspI2sFormat fail."); - return HDF_FAILURE; - } - AUDIO_DRIVER_LOG_DEBUG("DspLinkHwParams: channels = %d, rate = %d, periodSize = %d, \ - periodCount = %d, format = %d, cardServiceName = %s \n", - param->channels, param->rate, param->periodSize, - param->periodCount, (uint32_t)param->format, param->cardServiceName); - AUDIO_DRIVER_LOG_DEBUG("success."); - return HDF_SUCCESS; -} - -static int DspPowerEnable(void) -{ - return HDF_SUCCESS; -} - -static int DspGpioPinInit(void) -{ - return HDF_SUCCESS; -} - -static int DspI2cPinInit(void) -{ - return HDF_SUCCESS; -} - -static int DspI2sInit(void) -{ - return HDF_SUCCESS; -} - -static int DspI2cInit(void) -{ - return HDF_SUCCESS; -} - -/* not init dsp gpio */ -static int DspSpiPinInit(void) -{ - return HDF_FAILURE; -} - -static int32_t DspDeviceInit(const struct DspDevice *device) -{ - DevHandle devHandle; - struct SpiCfg devCfg = { - .maxSpeedHz = DEFAULT_SPEED, - .mode = SPI_CLK_POLARITY, - .transferMode = SPI_DMA_TRANSFER, - .bitsPerWord = BITS_PER_WORD_EIGHT, - }; - - if (DspPowerEnable() != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DspPowerEnable: return Error!"); - return HDF_FAILURE; - } - - if (DspGpioPinInit() != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DspGpioPinInit: return Error!"); - return HDF_FAILURE; - } - - if (DspI2cPinInit() != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DspI2cPinInit: return Error!"); - return HDF_FAILURE; - } - - if (DspSpiPinInit() == HDF_SUCCESS) { - devHandle = SpiOpen(&g_devInfo); - if (devHandle == NULL) { - AUDIO_DRIVER_LOG_ERR("DspDeviceOpen: Spi failed!"); - return HDF_FAILURE; - } - - if (SpiSetCfg(devHandle, &devCfg) != HDF_SUCCESS) { - SpiClose(devHandle); - AUDIO_DRIVER_LOG_ERR("DspDeviceCfg: spi failed!"); - return HDF_FAILURE; - } - SpiClose(devHandle); - } else { - AUDIO_DRIVER_LOG_ERR("Dsp Gpio Pin: not init!"); - } - - if (DspI2cInit() != HDF_SUCCESS) { - return HDF_FAILURE; - } - - if (DspI2sInit() != HDF_SUCCESS) { - return HDF_FAILURE; - } - - return HDF_SUCCESS; -} - -static int32_t DspDeviceReadReg(struct DspDevice *device, uint8_t *buf, uint32_t len) -{ - int32_t ret; - - DevHandle devHandle = SpiOpen(&g_devInfo); - if (devHandle == NULL) { - AUDIO_DRIVER_LOG_ERR("DspDeviceOpen: Spi failed!"); - return HDF_FAILURE; - } - - ret = SpiRead(devHandle, buf, len); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DspDeviceRead: spi failed!"); - SpiClose(devHandle); - return HDF_FAILURE; - } - - SpiClose(devHandle); - - return HDF_SUCCESS; -} - -static int32_t DspDeviceWriteReg(struct DspDevice *device, uint8_t *buf, uint32_t len) -{ - int32_t ret; - - DevHandle devHandle = SpiOpen(&g_devInfo); - if (devHandle == NULL) { - AUDIO_DRIVER_LOG_ERR("DspDeviceOpen: Spi failed!"); - return HDF_FAILURE; - } - - ret = SpiWrite(devHandle, buf, len); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DspDeviceRead: spi failed!"); - SpiClose(devHandle); - return HDF_FAILURE; - } - - SpiClose(devHandle); - - return HDF_SUCCESS; -} - -static int32_t DspLinkDeviceInit(const struct AudioCard *card, const struct DaiDevice *device) -{ - if (device == NULL || device->devDaiName == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is nullptr."); - return HDF_FAILURE; - } - AUDIO_DRIVER_LOG_DEBUG("dsp Link device name: %s\n", device->devDaiName); - (void)card; - return HDF_SUCCESS; -} - -static int32_t DspDriverBind(struct HdfDeviceObject *device) -{ - struct AudioHost *audioHost = NULL; - - AUDIO_DRIVER_LOG_DEBUG("entry."); - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("device is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - - audioHost = AudioHostCreateAndBind(device); - if (audioHost == NULL) { - AUDIO_DRIVER_LOG_ERR("audioHost create failed!"); - return HDF_FAILURE; - } - - AUDIO_DRIVER_LOG_DEBUG("dsp band success."); - return HDF_SUCCESS; -} - -static int32_t DspGetServiceName(const struct HdfDeviceObject *device, const char **drvDspName) -{ - const struct DeviceResourceNode *node = NULL; - struct DeviceResourceIface *drsOps = NULL; - int32_t ret; - - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("device is NULL."); - return HDF_FAILURE; - } - - node = device->property; - if (node == NULL) { - AUDIO_DRIVER_LOG_ERR("deivce property is NULL."); - return HDF_FAILURE; - } - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (drsOps == NULL || drsOps->GetString == NULL) { - AUDIO_DRIVER_LOG_ERR("from resource get drsops failed!"); - return HDF_FAILURE; - } - - ret = drsOps->GetString(node, "serviceName", drvDspName, 0); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("read DspServiceName fail!"); - return ret; - } - - return HDF_SUCCESS; -} - -static int32_t DspGetDaiName(const struct HdfDeviceObject *device, const char **drvDaiName) -{ - const struct DeviceResourceNode *node = NULL; - struct DeviceResourceIface *drsOps = NULL; - int32_t ret; - - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is null pointer."); - return HDF_FAILURE; - } - - node = device->property; - if (node == NULL) { - AUDIO_DRIVER_LOG_ERR("drs node is null pointer."); - return HDF_FAILURE; - } - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (drsOps == NULL || drsOps->GetString == NULL) { - AUDIO_DRIVER_LOG_ERR("drs ops fail!"); - return HDF_FAILURE; - } - - ret = drsOps->GetString(node, "dspDaiName", drvDaiName, 0); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("read dspDaiName fail!"); - return ret; - } - - return HDF_SUCCESS; -} - -static int32_t DspDriverInit(struct HdfDeviceObject *device) -{ - int32_t ret; - AUDIO_DRIVER_LOG_DEBUG("entry.\n"); - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("device is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - - ret = DspGetServiceName(device, &g_dspData.drvDspName); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("get dsp service name fail."); - return ret; - } - - ret = DspGetDaiName(device, &g_dspDaiData.drvDaiName); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("get dsp dai name fail."); - return ret; - } - - ret = AudioRegisterDeviceDsp(device, &g_dspData, &g_dspDaiData); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("register dai fail."); - return ret; - } - AUDIO_DRIVER_LOG_DEBUG("Success!\n"); - return HDF_SUCCESS; -} - - -static void DspDriverRelease(struct HdfDeviceObject *device) -{ - struct DspHost *dspHost = NULL; - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("device is NULL"); - return; - } - - dspHost = (struct DspHost *)device->service; - if (dspHost == NULL) { - AUDIO_DRIVER_LOG_ERR("DspHost is NULL"); - return; - } - - OsalIoUnmap((void *)((uintptr_t)(void*)&dspHost->priv)); - OsalMemFree(dspHost); -} - -static int32_t DspEqualizerActive(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device) -{ - (void)card; - (void)buf; - (void)device; - AUDIO_DRIVER_LOG_DEBUG("equalizer run!!!"); - return HDF_SUCCESS; -} - -static int32_t DspDecodeAudioStream(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device) -{ - (void)card; - (void)buf; - (void)device; - AUDIO_DRIVER_LOG_DEBUG("decode run!!!"); - return HDF_SUCCESS; -} - -static int32_t DspEncodeAudioStream(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device) -{ - (void)card; - (void)buf; - (void)device; - AUDIO_DRIVER_LOG_DEBUG("encode run!!!"); - return HDF_SUCCESS; -} - -/* HdfDriverEntry definitions */ -struct HdfDriverEntry g_dspDriverEntry = { - .moduleVersion = 1, - .moduleName = "DSP", - .Bind = DspDriverBind, - .Init = DspDriverInit, - .Release = DspDriverRelease, -}; -HDF_INIT(g_dspDriverEntry); diff --git a/model/audio/device/soc/src/platform.c b/model/audio/device/soc/src/platform.c deleted file mode 100755 index d780d8412..000000000 --- a/model/audio/device/soc/src/platform.c +++ /dev/null @@ -1,1172 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#include "gpio_if.h" -#include -#include "audio_core.h" -#include -#include "hi3516_aiao.h" -#include "hi3516_codec.h" -#include "osal_io.h" -#include "osal_mem.h" - -#define HDF_LOG_TAG platform -const int AIAO_BUFF_OFFSET = 128; -const int AIAO_BUFF_POINT = 320; -const int AIAO_BUFF_TRANS = 16 * 1024; -const int AIAO_BUFF_SIZE = 128 * 1024; -const int RENDER_TRAF_BUF_SIZE = 1024; -const int CAPTURE_TRAF_BUF_SIZE = 1024 * 16; - -const int AUDIO_BUFF_MIN = 128; -const int AUDIO_RECORD_MIN = 1024 * 16; -const int BITSTOBYTE = 8; - -static int g_captureBuffFreeCount = 0; -static int g_captureBuffInitCount = 0; -static int g_renderBuffFreeCount = 0; -static int g_renderBuffInitCount = 0; - -const int MIN_PERIOD_SIZE = 4096; -const int MAX_PERIOD_SIZE = 1024 * 16; -const int MIN_PERIOD_COUNT = 8; -const int MAX_PERIOD_COUNT = 32; -const int MAX_AIAO_BUFF_SIZE = 128 * 1024; -const int MIN_AIAO_BUFF_SIZE = 16 * 1024; - -/* HdfDriverEntry implementations */ -static int32_t PlatformDriverBind(struct HdfDeviceObject *device) -{ - struct PlatformHost *platformHost = NULL; - AUDIO_DRIVER_LOG_DEBUG("entry!"); - - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_FAILURE; - } - - platformHost = (struct PlatformHost *)OsalMemCalloc(sizeof(*platformHost)); - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("malloc host fail!"); - return HDF_FAILURE; - } - - platformHost->device = device; - platformHost->platformInitFlag = false; - device->service = &platformHost->service; - - AUDIO_DRIVER_LOG_DEBUG("success!"); - return HDF_SUCCESS; -} - -int32_t AudioRenderBuffInit(struct PlatformHost *platformHost) -{ - uint64_t buffSize; - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_FAILURE; - } - - if (platformHost->renderBufInfo.virtAddr != NULL) { - return HDF_SUCCESS; - } - - buffSize = platformHost->renderBufInfo.periodCount * platformHost->renderBufInfo.periodSize; - if (buffSize < MIN_AIAO_BUFF_SIZE || buffSize > MAX_AIAO_BUFF_SIZE) { - AUDIO_DRIVER_LOG_ERR("buffSize is invalid."); - return HDF_FAILURE; - } - AUDIO_DRIVER_LOG_INFO("buffSize = %d ", buffSize); - - platformHost->renderBufInfo.phyAddr = 0; - platformHost->renderBufInfo.virtAddr = dma_alloc_writecombine(NULL, buffSize, - (dma_addr_t *)&platformHost->renderBufInfo.phyAddr, GFP_DMA | GFP_KERNEL); - - if (platformHost->renderBufInfo.virtAddr == NULL) { - AUDIO_DRIVER_LOG_ERR("mem alloc failed."); - return HDF_FAILURE; - } - platformHost->renderBufInfo.cirBufSize = buffSize; - - AUDIO_DRIVER_LOG_DEBUG("phyAddr = %x virtAddr = %x", - platformHost->renderBufInfo.phyAddr, platformHost->renderBufInfo.virtAddr); - AUDIO_DRIVER_LOG_DEBUG("g_renderBuffInitCount: %d", g_renderBuffInitCount++); - - return HDF_SUCCESS; -} - -int32_t AudioRenderBuffFree(struct PlatformHost *platformHost) -{ - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_FAILURE; - } - - if (platformHost->renderBufInfo.virtAddr != NULL) { - dma_free_writecombine(NULL, platformHost->renderBufInfo.cirBufSize, platformHost->renderBufInfo.virtAddr, - platformHost->renderBufInfo.phyAddr); - } - - AUDIO_DRIVER_LOG_DEBUG("g_renderBuffFreeCount: %d", g_renderBuffFreeCount++); - - platformHost->renderBufInfo.virtAddr = NULL; - platformHost->renderBufInfo.phyAddr = 0; - return HDF_SUCCESS; -} - -int32_t AudioCaptureBuffInit(struct PlatformHost *platformHost) -{ - uint64_t buffSize; - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_FAILURE; - } - if (platformHost->captureBufInfo.virtAddr != NULL) { - return HDF_SUCCESS; - } - buffSize = platformHost->captureBufInfo.periodCount * platformHost->captureBufInfo.periodSize; - if (buffSize < MIN_AIAO_BUFF_SIZE || buffSize > MAX_AIAO_BUFF_SIZE) { - AUDIO_DRIVER_LOG_ERR("buffSize is invalid."); - return HDF_FAILURE; - } - AUDIO_DRIVER_LOG_INFO("buffSize = %d ", buffSize); - - platformHost->captureBufInfo.phyAddr = 0; - platformHost->captureBufInfo.virtAddr = dma_alloc_writecombine(NULL, buffSize, - (dma_addr_t *)&platformHost->captureBufInfo.phyAddr, GFP_DMA | GFP_KERNEL); - - if (platformHost->captureBufInfo.virtAddr == NULL) { - AUDIO_DRIVER_LOG_ERR("mem alloc failed."); - return HDF_FAILURE; - } - platformHost->captureBufInfo.cirBufSize = buffSize; - - AUDIO_DRIVER_LOG_DEBUG("phyAddr = %x virtAddr = %x", - platformHost->captureBufInfo.phyAddr, platformHost->captureBufInfo.virtAddr); - AUDIO_DRIVER_LOG_DEBUG("g_captureBuffInitCount: %d", g_captureBuffInitCount++); - - return HDF_SUCCESS; -} - -int32_t AudioCaptureBuffFree(struct PlatformHost *platformHost) -{ - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_FAILURE; - } - - if (platformHost->captureBufInfo.virtAddr != NULL) { - dma_free_writecombine(NULL, platformHost->captureBufInfo.cirBufSize, platformHost->captureBufInfo.virtAddr, - platformHost->captureBufInfo.phyAddr); - } - AUDIO_DRIVER_LOG_DEBUG("g_captureBuffFreeCount: %d", g_captureBuffFreeCount++); - - platformHost->captureBufInfo.virtAddr = NULL; - platformHost->captureBufInfo.phyAddr = 0; - return HDF_SUCCESS; -} - -int32_t AudioAoInit(const struct PlatformHost *platformHost) -{ - int ret; - - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_FAILURE; - } - - if (platformHost->renderBufInfo.phyAddr == 0) { - AUDIO_DRIVER_LOG_ERR("phyAddr is error"); - return HDF_FAILURE; - } - ret = AopHalSetBufferAddr(0, platformHost->renderBufInfo.phyAddr); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("failed."); - return HDF_FAILURE; - } - - ret = AopHalSetBufferSize(0, platformHost->renderBufInfo.cirBufSize); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AopHalSetBufferSize: failed."); - return HDF_FAILURE; - } - - AUDIO_DRIVER_LOG_DEBUG("AopHalSetBufferSize: %d", platformHost->renderBufInfo.cirBufSize); - - ret = AopHalSetTransSize(0, platformHost->renderBufInfo.trafBufSize); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("aop_hal_set_trans_size: faile."); - return HDF_FAILURE; - } - - return HDF_SUCCESS; -} - -int32_t AudioAiInit(const struct PlatformHost *platformHost) -{ - int ret; - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_FAILURE; - } - - if (platformHost->captureBufInfo.phyAddr == 0) { - AUDIO_DRIVER_LOG_ERR("phyAddr is error"); - return HDF_FAILURE; - } - - ret = AipHalSetBufferAddr(0, platformHost->captureBufInfo.phyAddr); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AipHalSetBufferAddr: failed."); - return HDF_FAILURE; - } - - ret = AipHalSetBufferSize(0, platformHost->captureBufInfo.cirBufSize); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AipHalSetBufferSize: failed."); - return HDF_FAILURE; - } - - ret = AipHalSetTransSize(0, AIAO_BUFF_POINT); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AipHalSetTransSize: faile."); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -static void SysWritelI2s(unsigned long addr, unsigned int value) -{ - *(volatile unsigned int *)(addr) = value; -} - -int32_t AiaoSysPinMux(void) -{ - static void *regIocfg2Base = 0; - static void *regIocfg3Base = 0; - static void *regGpioBase = 0; - - regIocfg2Base = OsalIoRemap(IOCFG2_BASE_ADDR, BASE_ADDR_REMAP_SIZE); - if (regIocfg2Base == NULL) { - AUDIO_DRIVER_LOG_ERR("regIocfg2Base is NULL."); - return HDF_FAILURE; - } - - regIocfg3Base = OsalIoRemap(IOCFG3_BASE_ADDR, BASE_ADDR_REMAP_SIZE); - if (regIocfg3Base == NULL) { - AUDIO_DRIVER_LOG_ERR("g_regIocfg3Base is NULL."); - return HDF_FAILURE; - } - - regGpioBase = OsalIoRemap(GPIO_BASE_ADDR, BASE_ADDR_REMAP_SIZE); - if (regGpioBase == NULL) { - AUDIO_DRIVER_LOG_ERR("g_regGpioBase is NULL."); - return HDF_FAILURE; - } - - AUDIO_DRIVER_LOG_DEBUG("I2s0PinMuxAmpUnmute i2s0_pin_mux"); - SysWritelI2s((uintptr_t)regIocfg2Base + I2S_IOCFG2_BASE1, I2S_IOCFG2_BASE1_VAL); - SysWritelI2s((uintptr_t)regIocfg2Base + I2S_IOCFG2_BASE2, I2S_IOCFG2_BASE2_VAL); - SysWritelI2s((uintptr_t)regIocfg2Base + I2S_IOCFG2_BASE3, I2S_IOCFG2_BASE3_VAL); - SysWritelI2s((uintptr_t)regIocfg2Base + I2S_IOCFG2_BASE4, I2S_IOCFG2_BASE4_VAL); - SysWritelI2s((uintptr_t)regIocfg2Base + I2S_IOCFG2_BASE5, I2S_IOCFG2_BASE5_VAL); - - AUDIO_DRIVER_LOG_DEBUG("I2s0PinMuxAmpUnmute AmpUnmute"); - SysWritelI2s((uintptr_t)regIocfg3Base + I2S_IOCFG3_BASE1, I2S_IOCFG3_BASE1_VAL); - SysWritelI2s((uintptr_t)regGpioBase + GPIO_BASE1, GPIO_BASE3_VAL); - SysWritelI2s((uintptr_t)regGpioBase + GPIO_BASE2, GPIO_BASE2_VAL); - SysWritelI2s((uintptr_t)regGpioBase + GPIO_BASE3, GPIO_BASE3_VAL); - - OsalIoUnmap(regGpioBase); - OsalIoUnmap(regIocfg3Base); - OsalIoUnmap(regIocfg2Base); - return HDF_SUCCESS; -} - - -int32_t AudioPlatformDeviceInit(const struct AudioCard *card, const struct PlatformDevice *platform) -{ - struct PlatformHost *platformHost = NULL; - int ret; - unsigned int chnId = 0; - - if (platform == NULL || platform->device == NULL) { - AUDIO_DRIVER_LOG_ERR("platform is NULL."); - return HDF_FAILURE; - } - (void)card; - - platformHost = (struct PlatformHost *)platform->device->service; - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("platform host is NULL."); - return HDF_FAILURE; - } - - if (platformHost->platformInitFlag == true) { - AUDIO_DRIVER_LOG_DEBUG("platform init complete!"); - return HDF_SUCCESS; - } - platformHost->platformInitFlag = true; - - ret = AiaoHalSysInit(); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AiaoHalSysInit: faile."); - return HDF_FAILURE; - } - - /* PIN MUX */ - ret = AiaoSysPinMux(); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AiaoSysPinMux fail."); - return HDF_FAILURE; - } - - /* CLK reset */ - ret = AiaoClockReset(); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AiaoClockReset: faile."); - return HDF_FAILURE; - } - - /* aiao init */ - ret = AiaoDeviceInit(chnId); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AiaoClockReset: faile."); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t RenderSetAiaoAttr(struct PlatformHost *platformHost, const struct AudioPcmHwParams *param) -{ - if (platformHost == NULL || param == NULL) { - AUDIO_DRIVER_LOG_ERR("platform is NULL."); - return HDF_FAILURE; - } - platformHost->renderBufInfo.period = param->period; - if (param->periodSize < MIN_PERIOD_SIZE || param->periodSize > MAX_PERIOD_SIZE) { - AUDIO_DRIVER_LOG_ERR("periodSize is invalid."); - return HDF_FAILURE; - } - platformHost->renderBufInfo.periodSize = param->periodSize; - if (param->periodCount < MIN_PERIOD_COUNT || param->periodCount > MAX_PERIOD_COUNT) { - AUDIO_DRIVER_LOG_ERR("periodCount is invalid."); - return HDF_FAILURE; - } - platformHost->renderBufInfo.periodCount = param->periodCount; - - platformHost->renderBufInfo.trafBufSize = RENDER_TRAF_BUF_SIZE; - return HDF_SUCCESS; -} - -int32_t CaptureSetAiaoAttr(struct PlatformHost *platformHost, const struct AudioPcmHwParams *param) -{ - if (platformHost == NULL || param == NULL) { - AUDIO_DRIVER_LOG_ERR("platform is NULL."); - return HDF_FAILURE; - } - - platformHost->captureBufInfo.period = param->period; - if (param->periodSize < MIN_PERIOD_SIZE || param->periodSize > MAX_PERIOD_SIZE) { - AUDIO_DRIVER_LOG_ERR("periodSize is invalid %d.", param->periodSize); - return HDF_FAILURE; - } - platformHost->captureBufInfo.periodSize = param->periodSize; - if (param->periodCount < MIN_PERIOD_COUNT || param->periodCount > MAX_PERIOD_COUNT) { - AUDIO_DRIVER_LOG_ERR("periodCount is invalid %d.", param->periodCount); - return HDF_FAILURE; - } - platformHost->captureBufInfo.periodCount = param->periodCount; - - if (param->silenceThreshold < MIN_PERIOD_SIZE || param->silenceThreshold > MAX_PERIOD_SIZE) { - AUDIO_DRIVER_LOG_ERR("silenceThreshold is invalid %d.", param->silenceThreshold); - platformHost->captureBufInfo.trafBufSize = CAPTURE_TRAF_BUF_SIZE; - } else { - platformHost->captureBufInfo.trafBufSize = param->silenceThreshold; - } - return HDF_SUCCESS; -} - -int32_t PlatformHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param) -{ - int ret; - const int chnlCntMin = 1; - const int chnlCntMax = 2; - struct PlatformHost *platformHost = NULL; - AUDIO_DRIVER_LOG_DEBUG("entry."); - - if (card == NULL || card->rtd == NULL || card->rtd->platform == NULL || - param == NULL || param->cardServiceName == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_FAILURE; - } - - if (param->channels < chnlCntMin || param->channels > chnlCntMax) { - AUDIO_DRIVER_LOG_ERR("channels para is invalid."); - return HDF_FAILURE; - } - - platformHost = PlatformHostFromDevice(card->rtd->platform->device); - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("platformHost is null."); - return HDF_FAILURE; - } - - platformHost->pcmInfo.rate = param->rate; - platformHost->pcmInfo.frameSize = param->channels * platformHost->pcmInfo.bitWidth / BITSTOBYTE; - - platformHost->renderBufInfo.chnId = 0; - platformHost->captureBufInfo.chnId = 0; - - platformHost->pcmInfo.isBigEndian = param->isBigEndian; - platformHost->pcmInfo.isSignedData = param->isSignedData; - - platformHost->pcmInfo.startThreshold = param->startThreshold; - platformHost->pcmInfo.stopThreshold = param->stopThreshold; - platformHost->pcmInfo.silenceThreshold = param->silenceThreshold; - - if (param->streamType == AUDIO_RENDER_STREAM) { - ret = RenderSetAiaoAttr(platformHost, param); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AoSetClkAttr: fail."); - return HDF_FAILURE; - } - } else if (param->streamType == AUDIO_CAPTURE_STREAM) { - ret = CaptureSetAiaoAttr(platformHost, param); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AiSetClkAttr: fail."); - return HDF_FAILURE; - } - } else { - AUDIO_DRIVER_LOG_ERR("param streamType is invalid."); - return HDF_FAILURE; - } - AUDIO_DRIVER_LOG_DEBUG("success."); - return HDF_SUCCESS; -} - -int32_t PlatformCreatePlatformHost(const struct AudioCard *card, struct PlatformHost **platformHost) -{ - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("input param platformHost is invalid."); - return HDF_ERR_INVALID_PARAM; - } - if (card == NULL || card->rtd == NULL || card->rtd->platform == NULL) { - AUDIO_DRIVER_LOG_ERR("input para is NULL."); - return HDF_FAILURE; - } - - *platformHost = PlatformHostFromDevice(card->rtd->platform->device); - if (*platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("PlatformHostFromDevice faile."); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t PlatformRenderPrepare(const struct AudioCard *card) -{ - int ret; - struct PlatformHost *platformHost = NULL; - AUDIO_DRIVER_LOG_DEBUG("PlatformPrepare: entry."); - - ret = PlatformCreatePlatformHost(card, &platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("PlatformCreatePlatformHost failed."); - return HDF_FAILURE; - } - - if (platformHost->renderBufInfo.virtAddr == NULL) { - ret = AudioRenderBuffInit(platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AudioRenderBuffInit: fail."); - return HDF_FAILURE; - } - - ret = AudioAoInit(platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AudioAoInit: fail."); - return HDF_FAILURE; - } - } - - (void)memset_s(platformHost->renderBufInfo.virtAddr, - platformHost->renderBufInfo.cirBufSize, 0, - platformHost->renderBufInfo.cirBufSize); - platformHost->renderBufInfo.wbufOffSet = 0; - platformHost->renderBufInfo.wptrOffSet = 0; - platformHost->pcmInfo.totalStreamSize = 0; - - ret = AopHalSetBuffWptr(0, 0); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AopHalSetBuffWptr: failed."); - return HDF_FAILURE; - } - - ret = AopHalSetBuffRptr(0, 0); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AopHalSetBuffRptr: failed."); - return HDF_FAILURE; - } - AUDIO_DRIVER_LOG_DEBUG("success."); - return HDF_SUCCESS; -} - -int32_t PlatformCapturePrepare(const struct AudioCard *card) -{ - int ret; - struct PlatformHost *platformHost = NULL; - AUDIO_DRIVER_LOG_DEBUG("entry."); - - ret = PlatformCreatePlatformHost(card, &platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("PlatformCreatePlatformHost failed."); - return HDF_FAILURE; - } - - if (platformHost->captureBufInfo.virtAddr == NULL) { - ret = AudioCaptureBuffInit(platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AudioCaptureBuffInit: fail."); - return HDF_FAILURE; - } - ret = AudioAiInit(platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AudioAiInit: fail."); - return HDF_FAILURE; - } - } - - (void)memset_s(platformHost->captureBufInfo.virtAddr, - platformHost->captureBufInfo.cirBufSize, 0, - platformHost->captureBufInfo.cirBufSize); - platformHost->captureBufInfo.wbufOffSet = 0; - platformHost->captureBufInfo.wptrOffSet = 0; - platformHost->captureBufInfo.chnId = 0; - platformHost->pcmInfo.totalStreamSize = 0; - - ret = AipHalSetBuffWptr(0, 0); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AipHalSetBuffWptr: failed."); - return HDF_FAILURE; - } - - ret = AipHalSetBuffRptr(0, 0); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AipHalSetBuffRptr: failed."); - return HDF_FAILURE; - } - - AUDIO_DRIVER_LOG_DEBUG("success."); - return HDF_SUCCESS; -} - -int32_t AudioDataBigEndianChange(char *srcData, uint32_t audioLen, enum AuidoBitWidth bitWidth) -{ - uint64_t i; - uint16_t framesize; - char temp; - if (srcData == NULL) { - AUDIO_DRIVER_LOG_ERR("srcData is NULL."); - return HDF_FAILURE; - } - - switch (bitWidth) { - case BIT_WIDTH8: - framesize = 1; /* 1 byte */ - break; - case BIT_WIDTH16: - framesize = 2; /* 2 bytes */ - break; - case BIT_WIDTH24: - framesize = 3; /* 3 bytes */ - break; - default: - framesize = 2; /* default 2 bytes */ - break; - } - - for (i = 0; i < audioLen; i += framesize) { - temp = srcData[i]; - srcData[i] = srcData[i + framesize - 1]; - srcData[i + framesize - 1] = temp; - } - AUDIO_DRIVER_LOG_DEBUG("audioLen = %d\n", audioLen); - return HDF_SUCCESS; -} - - -static int32_t UpdateWriteBufData(struct PlatformHost *platformHost, unsigned int wptr, - unsigned int buffSize, unsigned int *buffOffset, const char *buf) -{ - int ret; - unsigned int buffFirstSize; - unsigned int buffSecordSize; - if (platformHost == NULL || buffOffset == NULL || buf == NULL) { - AUDIO_DRIVER_LOG_ERR("input param is invalid."); - return HDF_ERR_INVALID_PARAM; - } - - if (platformHost->renderBufInfo.cirBufSize - wptr >= buffSize) { - *buffOffset = wptr + buffSize; - ret = memcpy_s((char *)(platformHost->renderBufInfo.virtAddr) + wptr, - buffSize, buf, buffSize); - if (ret != 0) { - AUDIO_DRIVER_LOG_ERR("memcpy_s failed."); - return HDF_FAILURE; - } - if (*buffOffset >= platformHost->renderBufInfo.cirBufSize) { - *buffOffset = 0; - } - } else { - buffFirstSize = platformHost->renderBufInfo.cirBufSize - wptr; - ret = memcpy_s((char *)(platformHost->renderBufInfo.virtAddr) + wptr, - buffFirstSize, buf, buffFirstSize); - if (ret != 0) { - AUDIO_DRIVER_LOG_ERR("memcpy_s failed."); - return HDF_FAILURE; - } - - buffSecordSize = buffSize - buffFirstSize; - ret = memcpy_s((char *)platformHost->renderBufInfo.virtAddr, - buffSecordSize, buf + buffFirstSize, - buffSecordSize); - if (ret != 0) { - AUDIO_DRIVER_LOG_ERR("memcpy_s failed."); - return HDF_FAILURE; - } - *buffOffset = buffSecordSize; - } - return HDF_SUCCESS; -} - -static int32_t UpdateWriteBuffOffset(struct PlatformHost *platformHost, - unsigned int buffSize, unsigned int *buffOffset, struct AudioTxData *txData) -{ - unsigned int buffAvailable; - int ret; - unsigned int wptr; - unsigned int rptr; - int devId; - if (platformHost == NULL || buffOffset == NULL || txData == NULL || txData->buf == NULL) { - AUDIO_DRIVER_LOG_ERR("input param is invalid."); - return HDF_ERR_INVALID_PARAM; - } - - devId = platformHost->renderBufInfo.chnId; - rptr = AiaoHalReadReg(AopBuffRptrReg(devId)); - wptr = AiaoHalReadReg(AopBuffWptrReg(devId)); - AUDIO_DRIVER_LOG_DEBUG("rptrReg = [0x%08x, wptrReg = [0x%08x], input size = [%u]", - rptr, wptr, buffSize); - - if (wptr >= rptr) { - // [S ... R ... W ... E] - buffAvailable = platformHost->renderBufInfo.cirBufSize - (wptr - rptr); - - if (buffAvailable < buffSize + AUDIO_BUFF_MIN) { - AUDIO_DRIVER_LOG_DEBUG("not available buffer."); - txData->status = ENUM_CIR_BUFF_FULL; - return HDF_SUCCESS; - } - - ret = UpdateWriteBufData(platformHost, wptr, buffSize, buffOffset, txData->buf); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("aop_hal_set_buff_wptr failed."); - return HDF_FAILURE; - } - } else { - // [S ... W ... R ... E] - buffAvailable = rptr - wptr; - - if (buffAvailable < buffSize + AUDIO_BUFF_MIN) { - AUDIO_DRIVER_LOG_DEBUG("not available buffer."); - txData->status = ENUM_CIR_BUFF_FULL; - return HDF_SUCCESS; - } - - *buffOffset = wptr + buffSize; - ret = memcpy_s((char *)(platformHost->renderBufInfo.virtAddr) + wptr, - buffSize, txData->buf, buffSize); - if (ret != 0) { - AUDIO_DRIVER_LOG_ERR("memcpy_s failed."); - return HDF_FAILURE; - } - } - return HDF_SUCCESS; -} - -static int32_t SetWriteBuffWptr(struct PlatformHost *platformHost, - unsigned int buffSize, struct AudioTxData *txData) -{ - int ret; - int devId; - int buffOffset; - - if (platformHost == NULL || txData == NULL) { - AUDIO_DRIVER_LOG_ERR("input param is invalid."); - return HDF_ERR_INVALID_PARAM; - } - - devId = platformHost->renderBufInfo.chnId; - ret = UpdateWriteBuffOffset(platformHost, buffSize, &buffOffset, txData); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("UpdateWptrRptr: failed."); - return HDF_FAILURE; - } - if (txData->status == ENUM_CIR_BUFF_FULL) { - AUDIO_DRIVER_LOG_DEBUG("not available buffer wait a minute."); - return HDF_SUCCESS; - } - - if (platformHost->renderBufInfo.runStatus == 1) { - platformHost->pcmInfo.totalStreamSize += buffSize; - ret = AopHalSetBuffWptr(devId, buffOffset); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AopHalSetBuffWptr failed."); - return HDF_FAILURE; - } - } - txData->status = ENUM_CIR_BUFF_NORMAL; - return HDF_SUCCESS; -} - -int32_t PlatformWrite(const struct AudioCard *card, struct AudioTxData *txData) -{ - uint64_t buffSize; - uint64_t startThreshold; - struct PlatformHost *platformHost = NULL; - AUDIO_DRIVER_LOG_DEBUG("entry."); - - if (card == NULL || card->rtd == NULL || card->rtd->platform == NULL || - txData == NULL || txData->buf == NULL) { - AUDIO_DRIVER_LOG_ERR("param is null."); - return HDF_FAILURE; - } - - platformHost = PlatformHostFromDevice(card->rtd->platform->device); - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("PlatformHostFromDevice is invalid."); - return HDF_FAILURE; - } - - OsalMutexLock(&platformHost->renderBufInfo.buffMutex); - if (platformHost->renderBufInfo.virtAddr == NULL) { - AUDIO_DRIVER_LOG_ERR("renderBufInfo.virtAddr is nullptr."); - OsalMutexUnlock(&platformHost->renderBufInfo.buffMutex); - return HDF_FAILURE; - } - buffSize = txData->frames * platformHost->pcmInfo.frameSize; - startThreshold = platformHost->pcmInfo.startThreshold * platformHost->pcmInfo.frameSize; - - if (buffSize >= platformHost->renderBufInfo.cirBufSize) { - AUDIO_DRIVER_LOG_ERR("stream data too long."); - OsalMutexUnlock(&platformHost->renderBufInfo.buffMutex); - return HDF_FAILURE; - } - - if (platformHost->pcmInfo.isBigEndian) { - if (AudioDataBigEndianChange(txData->buf, buffSize, platformHost->pcmInfo.bitWidth) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AudioDataBigEndianChange: failed."); - OsalMutexUnlock(&platformHost->renderBufInfo.buffMutex); - return HDF_FAILURE; - } - } - - if (platformHost->renderBufInfo.runStatus == 1) { - if ((platformHost->renderBufInfo.enable == 0) && - (platformHost->pcmInfo.totalStreamSize > startThreshold)) { - AopHalDevEnable(platformHost->captureBufInfo.chnId); - platformHost->renderBufInfo.enable = 1; - } - } - - if (SetWriteBuffWptr(platformHost, buffSize, txData) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("SetWriteBuffWptr: failed."); - OsalMutexUnlock(&platformHost->renderBufInfo.buffMutex); - return HDF_FAILURE; - } - OsalMutexUnlock(&platformHost->renderBufInfo.buffMutex); - - AUDIO_DRIVER_LOG_DEBUG("now total = %d", platformHost->pcmInfo.totalStreamSize); - return HDF_SUCCESS; -} - -static int32_t UpdateReadBuffData(const struct PlatformHost *platformHost, - unsigned int *tranferSize, unsigned int *buffOffset, - struct AudioRxData *rxData) -{ - unsigned int dataAvailable; - unsigned int validData; - unsigned int wptr; - unsigned int rptr; - int devId; - devId = platformHost->captureBufInfo.chnId; - // Buf/DMA offset - rptr = AiaoHalReadReg(AipBuffRptrReg(devId)); - wptr = AiaoHalReadReg(AipBuffWptrReg(devId)); - // Buf manage - if (wptr >= rptr) { - // [S ... R ... W ... E] - dataAvailable = wptr - rptr; - - if (dataAvailable >= platformHost->captureBufInfo.trafBufSize) { - rxData->buf = (char *)(platformHost->captureBufInfo.virtAddr) + rptr; - *tranferSize = platformHost->captureBufInfo.trafBufSize; - *buffOffset = rptr + *tranferSize; - } else { - AUDIO_DRIVER_LOG_DEBUG("PlatformRead: not available data."); - rxData->buf = (char *)(platformHost->captureBufInfo.virtAddr) + rptr; - rxData->status = ENUM_CIR_BUFF_EMPTY; - rxData->bufSize = 0; - rxData->frames = 0; - return HDF_SUCCESS; - } - - AUDIO_DRIVER_LOG_DEBUG("tranferSize : %d buffOffset : %d ", *tranferSize, *buffOffset); - } else { - // [S ... W ... R ... E] - validData = rptr + platformHost->captureBufInfo.trafBufSize; - if (validData < platformHost->captureBufInfo.cirBufSize) { - rxData->buf = (char *)(platformHost->captureBufInfo.virtAddr) + rptr; - *tranferSize = platformHost->captureBufInfo.trafBufSize; - *buffOffset = rptr + *tranferSize; - } else { - rxData->buf = (char *)(platformHost->captureBufInfo.virtAddr) + rptr; - *tranferSize = platformHost->captureBufInfo.cirBufSize - rptr; - *buffOffset = 0; - } - AUDIO_DRIVER_LOG_DEBUG("tranferSize : %d rptrReg.u32 : %d ", *tranferSize, rptr); - } - - AUDIO_DRIVER_LOG_DEBUG("rptrReg = [0x%08x], wptrReg = [0x%08x], max size = [%u]", - rptr, wptr, platformHost->captureBufInfo.trafBufSize); - - return HDF_SUCCESS; -} - -int32_t PlatformRead(const struct AudioCard *card, struct AudioRxData *rxData) -{ - unsigned int buffOffset; - struct PlatformHost *platformHost = NULL; - int devId; - unsigned int tranferSize; - - if (rxData == NULL || card == NULL || card->rtd == NULL || card->rtd->platform == NULL) { - AUDIO_DRIVER_LOG_ERR("param is null."); - return HDF_FAILURE; - } - - platformHost = PlatformHostFromDevice(card->rtd->platform->device); - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("PlatformHostFromDevice: fail."); - return HDF_FAILURE; - } - devId = platformHost->captureBufInfo.chnId; - - OsalMutexLock(&platformHost->captureBufInfo.buffMutex); - if (platformHost->captureBufInfo.virtAddr == NULL) { - AUDIO_DRIVER_LOG_ERR("PlatformWrite: capture data buffer is not initialized."); - OsalMutexUnlock(&platformHost->captureBufInfo.buffMutex); - return HDF_FAILURE; - } - - if (UpdateReadBuffData(platformHost, &tranferSize, &buffOffset, rxData) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("UpdateReadBuffData failed."); - OsalMutexUnlock(&platformHost->captureBufInfo.buffMutex); - return HDF_FAILURE; - } - OsalMutexUnlock(&platformHost->captureBufInfo.buffMutex); - - if (rxData->status == ENUM_CIR_BUFF_EMPTY) { - AUDIO_DRIVER_LOG_DEBUG("not available data wait a minute."); - return HDF_SUCCESS; - } - - if (!platformHost->pcmInfo.isBigEndian) { - if (AudioDataBigEndianChange(rxData->buf, tranferSize, platformHost->pcmInfo.bitWidth) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AudioDataBigEndianChange: failed."); - return HDF_FAILURE; - } - } - - rxData->frames = tranferSize / platformHost->pcmInfo.frameSize; - rxData->bufSize = tranferSize; - rxData->status = ENUM_CIR_BUFF_NORMAL; - - if (buffOffset >= platformHost->captureBufInfo.cirBufSize) { - buffOffset = 0; - } - - if (AipHalSetBuffRptr(devId, buffOffset) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AipHalSetBuffRptr failed."); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t PlatformRenderStart(const struct AudioCard *card) -{ - int ret; - struct PlatformHost *platformHost = NULL; - - ret = PlatformCreatePlatformHost(card, &platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("PlatformCreatePlatformHost failed."); - return HDF_FAILURE; - } - - platformHost->renderBufInfo.runStatus = 1; - platformHost->renderBufInfo.enable = 0; - ShowAllAcodecRegister(); - ShowAllAiaoRegister(); - - AUDIO_DRIVER_LOG_INFO("audio render start"); - return HDF_SUCCESS; -} - -int32_t PlatformCaptureStart(const struct AudioCard *card) -{ - int ret; - struct PlatformHost *platformHost = NULL; - - ret = PlatformCreatePlatformHost(card, &platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("PlatformCreatePlatformHost failed."); - return HDF_FAILURE; - } - - AipHalSetRxStart(platformHost->captureBufInfo.chnId, HI_TRUE); - ShowAllAcodecRegister(); - ShowAllAiaoRegister(); - AUDIO_DRIVER_LOG_INFO("audio capture start"); - return HDF_SUCCESS; -} - -int32_t PlatformRenderStop(const struct AudioCard *card) -{ - int ret; - struct PlatformHost *platformHost = NULL; - - ret = PlatformCreatePlatformHost(card, &platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("PlatformCreatePlatformHost failed."); - return HDF_FAILURE; - } - - OsalMutexLock(&platformHost->renderBufInfo.buffMutex); - platformHost->renderBufInfo.runStatus = 0; - AopHalSetTxStart(platformHost->renderBufInfo.chnId, HI_FALSE); - ret = AudioRenderBuffFree(platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AudioRenderBuffFree failed."); - OsalMutexUnlock(&platformHost->renderBufInfo.buffMutex); - return HDF_FAILURE; - } - OsalMutexUnlock(&platformHost->renderBufInfo.buffMutex); - AUDIO_DRIVER_LOG_INFO("audio stream stop"); - - return HDF_SUCCESS; -} - -int32_t PlatformCaptureStop(const struct AudioCard *card) -{ - int ret; - struct PlatformHost *platformHost = NULL; - - ret = PlatformCreatePlatformHost(card, &platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("PlatformCreatePlatformHost failed."); - return HDF_FAILURE; - } - OsalMutexLock(&platformHost->captureBufInfo.buffMutex); - AipHalSetRxStart(platformHost->captureBufInfo.chnId, HI_FALSE); - ret = AudioCaptureBuffFree(platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("AudioCaptureBuffFree failed."); - OsalMutexUnlock(&platformHost->captureBufInfo.buffMutex); - return HDF_FAILURE; - } - OsalMutexUnlock(&platformHost->captureBufInfo.buffMutex); - AUDIO_DRIVER_LOG_INFO("audio stream stop"); - return HDF_SUCCESS; -} - -int32_t PlatformCapturePause(const struct AudioCard *card) -{ - int ret; - struct PlatformHost *platformHost = NULL; - - ret = PlatformCreatePlatformHost(card, &platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("PlatformCreatePlatformHost failed."); - return HDF_FAILURE; - } - - AipHalSetRxStart(platformHost->captureBufInfo.chnId, HI_FALSE); - AUDIO_DRIVER_LOG_INFO("audio stream pause"); - return HDF_SUCCESS; -} - -int32_t PlatformRenderPause(const struct AudioCard *card) -{ - int ret; - struct PlatformHost *platformHost = NULL; - - ret = PlatformCreatePlatformHost(card, &platformHost); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("PlatformCreatePlatformHost failed."); - return HDF_FAILURE; - } - - platformHost->renderBufInfo.runStatus = 0; - AopHalSetTxStart(platformHost->renderBufInfo.chnId, HI_FALSE); - - AUDIO_DRIVER_LOG_INFO("audio stream pause"); - return HDF_SUCCESS; -} - -int32_t PlatformRenderResume(const struct AudioCard *card) -{ - int ret = PlatformRenderStart(card); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("PlatformRenderResume failed."); - return HDF_FAILURE; - } - AUDIO_DRIVER_LOG_INFO("audio stream resume"); - return HDF_SUCCESS; -} - -int32_t PlatformCaptureResume(const struct AudioCard *card) -{ - int ret; - (void)card; - ret = PlatformCaptureStart(card); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("PlatformCaptureStart failed."); - return HDF_FAILURE; - } - AUDIO_DRIVER_LOG_INFO("audio stream resume"); - return HDF_SUCCESS; -} - -struct AudioPlatformOps g_platformDeviceOps = { - .HwParams = PlatformHwParams, - .Write = PlatformWrite, - .Read = PlatformRead, - .RenderPrepare = PlatformRenderPrepare, - .CapturePrepare = PlatformCapturePrepare, - .RenderStart = PlatformRenderStart, - .CaptureStart = PlatformCaptureStart, - .RenderStop = PlatformRenderStop, - .CaptureStop = PlatformCaptureStop, - .RenderPause = PlatformRenderPause, - .CapturePause = PlatformCapturePause, - .RenderResume = PlatformRenderResume, - .CaptureResume = PlatformCaptureResume, -}; - -struct PlatformData g_platformData = { - .PlatformInit = AudioPlatformDeviceInit, - .ops = &g_platformDeviceOps, -}; - -static int32_t PlatformGetServiceName(const struct HdfDeviceObject *device) -{ - const struct DeviceResourceNode *node = NULL; - struct DeviceResourceIface *drsOps = NULL; - int32_t ret; - - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("para is NULL."); - return HDF_FAILURE; - } - - node = device->property; - if (node == NULL) { - AUDIO_DRIVER_LOG_ERR("node is NULL."); - return HDF_FAILURE; - } - - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (drsOps == NULL || drsOps->GetString == NULL) { - AUDIO_DRIVER_LOG_ERR("get drsops object instance fail!"); - return HDF_FAILURE; - } - - ret = drsOps->GetString(node, "serviceName", &g_platformData.drvPlatformName, 0); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("read serviceName fail!"); - return ret; - } - - return HDF_SUCCESS; -} - -static int32_t PlatformDriverInit(struct HdfDeviceObject *device) -{ - int32_t ret; - - AUDIO_DRIVER_LOG_DEBUG("entry.\n"); - struct PlatformHost *platformHost = NULL; - - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("device is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - - ret = PlatformGetServiceName(device); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("get service name fail."); - return ret; - } - - ret = AudioSocDeviceRegister(device, (void *)&g_platformData, AUDIO_PLATFORM_DEVICE); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("register dai fail."); - return ret; - } - - platformHost = (struct PlatformHost *)device->service; - if (NULL != platformHost) { - OsalMutexInit(&platformHost->renderBufInfo.buffMutex); - OsalMutexInit(&platformHost->captureBufInfo.buffMutex); - } - - AUDIO_DRIVER_LOG_DEBUG("success.\n"); - return HDF_SUCCESS; -} - -static void PlatformDriverRelease(struct HdfDeviceObject *device) -{ - struct PlatformHost *platformHost = NULL; - - if (device == NULL) { - AUDIO_DRIVER_LOG_ERR("device is NULL"); - return; - } - - platformHost = (struct PlatformHost *)device->service; - if (platformHost == NULL) { - AUDIO_DRIVER_LOG_ERR("platformHost is NULL"); - return; - } - - OsalMutexDestroy(&platformHost->renderBufInfo.buffMutex); - OsalMutexDestroy(&platformHost->captureBufInfo.buffMutex); - OsalMemFree(platformHost); -} - -/* HdfDriverEntry definitions */ -struct HdfDriverEntry g_platformDriverEntry = { - .moduleVersion = 1, - .moduleName = "DMA_HI3516", - .Bind = PlatformDriverBind, - .Init = PlatformDriverInit, - .Release = PlatformDriverRelease, -}; -HDF_INIT(g_platformDriverEntry); diff --git a/model/audio/dispatch/include/audio_control_dispatch.h b/model/audio/dispatch/include/audio_control_dispatch.h index 0420881ee..2d3959316 100755 --- a/model/audio/dispatch/include/audio_control_dispatch.h +++ b/model/audio/dispatch/include/audio_control_dispatch.h @@ -27,7 +27,8 @@ enum ControlDispMethodCmd { AUDIODRV_CTRL_IOCTRL_ELEM_BUTT, }; -typedef int32_t (*ControlDispCmdHandle)(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply); +typedef int32_t (*ControlDispCmdHandle)(const struct HdfDeviceIoClient *client, + struct HdfSBuf *data, struct HdfSBuf *reply); struct ControlDispCmdHandleList { enum ControlDispMethodCmd cmd; diff --git a/model/audio/dispatch/include/audio_stream_dispatch.h b/model/audio/dispatch/include/audio_stream_dispatch.h index 4c72ddb04..b1d4c7529 100755 --- a/model/audio/dispatch/include/audio_stream_dispatch.h +++ b/model/audio/dispatch/include/audio_stream_dispatch.h @@ -10,10 +10,10 @@ #define AUDIO_STREAM_DISP_H #include "audio_host.h" -#include "codec_adapter.h" -#include "platform_adapter.h" -#include "dai_adapter.h" -#include "dsp_adapter.h" +#include "audio_codec_if.h" +#include "audio_platform_if.h" +#include "audio_dai_if.h" +#include "audio_dsp_if.h" #ifdef __cplusplus #if __cplusplus @@ -37,13 +37,18 @@ enum StreamDispMethodCmd { AUDIO_DRV_PCM_IOCTRL_CAPTURE_PAUSE, AUDIO_DRV_PCM_IOCTRL_RENDER_RESUME, AUDIO_DRV_PCM_IOCTRL_CAPTURE_RESUME, + AUDIO_DRV_PCM_IOCTL_MMAP_BUFFER, + AUDIO_DRV_PCM_IOCTL_MMAP_BUFFER_CAPTURE, + AUDIO_DRV_PCM_IOCTL_MMAP_POSITION, + AUDIO_DRV_PCM_IOCTL_MMAP_POSITION_CAPTURE, AUDIO_DRV_PCM_IOCTRL_DSP_DECODE, AUDIO_DRV_PCM_IOCTRL_DSP_ENCODE, AUDIO_DRV_PCM_IOCTRL_DSP_EQUALIZER, AUDIO_DRV_PCM_IOCTRL_BUTT, }; -typedef int32_t (*StreamDispCmdHandle)(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply); +typedef int32_t (*StreamDispCmdHandle)(const struct HdfDeviceIoClient *client, + struct HdfSBuf *data, struct HdfSBuf *reply); struct StreamDispCmdHandleList { enum StreamDispMethodCmd cmd; @@ -63,7 +68,6 @@ static inline struct StreamHost *StreamHostFromDevice(struct HdfDeviceObject *de int32_t StreamDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply); -void StreamHostDestroy(struct StreamHost *host); #ifdef __cplusplus #if __cplusplus diff --git a/model/audio/dispatch/src/audio_control_dispatch.c b/model/audio/dispatch/src/audio_control_dispatch.c index f6879f9ce..082e66a35 100755 --- a/model/audio/dispatch/src/audio_control_dispatch.c +++ b/model/audio/dispatch/src/audio_control_dispatch.c @@ -7,7 +7,7 @@ */ #include "audio_control_dispatch.h" -#include "audio_sapm.h" +#include "audio_control.h" #define HDF_LOG_TAG audio_control_dispatch @@ -16,7 +16,7 @@ static struct AudioKcontrol *AudioGetKctrlInstance(const struct AudioCtrlElemId struct AudioKcontrol *kctrl = NULL; struct AudioCard *audioCard = NULL; - if (ctrlElemId == NULL) { + if (ctrlElemId == NULL || ctrlElemId->itemName == NULL || ctrlElemId->cardServiceName == NULL) { ADM_LOG_ERR("input params check error: ctrlElemId is NULL."); return NULL; } @@ -28,6 +28,9 @@ static struct AudioKcontrol *AudioGetKctrlInstance(const struct AudioCtrlElemId } DLIST_FOR_EACH_ENTRY(kctrl, &audioCard->controls, struct AudioKcontrol, list) { + if (kctrl->name == NULL) { + continue; + } if (strcmp(kctrl->name, ctrlElemId->itemName) != 0) { continue; } @@ -39,7 +42,7 @@ static struct AudioKcontrol *AudioGetKctrlInstance(const struct AudioCtrlElemId return NULL; } -static int32_t ControlHostElemInfoSub(struct HdfSBuf *rspData, struct AudioCtrlElemId id) +static int32_t ControlHostElemInfoSub(struct HdfSBuf *rspData, const struct AudioCtrlElemId id) { int32_t result; struct AudioKcontrol *kctrl = NULL; @@ -81,7 +84,8 @@ static int32_t ControlHostElemInfoSub(struct HdfSBuf *rspData, struct AudioCtrlE return HDF_SUCCESS; } -static int32_t ControlHostElemInfo(struct HdfDeviceIoClient *client, struct HdfSBuf *reqData, struct HdfSBuf *rspData) +static int32_t ControlHostElemInfo(const struct HdfDeviceIoClient *client, + struct HdfSBuf *reqData, struct HdfSBuf *rspData) { struct AudioCtrlElemId id; ADM_LOG_DEBUG("entry."); @@ -115,7 +119,8 @@ static int32_t ControlHostElemInfo(struct HdfDeviceIoClient *client, struct HdfS return HDF_SUCCESS; } -static int32_t ControlHostElemRead(struct HdfDeviceIoClient *client, struct HdfSBuf *reqData, struct HdfSBuf *rspData) +static int32_t ControlHostElemRead(const struct HdfDeviceIoClient *client, struct HdfSBuf *reqData, + struct HdfSBuf *rspData) { struct AudioKcontrol *kctrl = NULL; struct AudioCtrlElemValue elemValue; @@ -169,7 +174,8 @@ static int32_t ControlHostElemRead(struct HdfDeviceIoClient *client, struct HdfS return HDF_SUCCESS; } -static int32_t ControlHostElemWrite(struct HdfDeviceIoClient *client, struct HdfSBuf *reqData, struct HdfSBuf *rspData) +static int32_t ControlHostElemWrite(const struct HdfDeviceIoClient *client, + struct HdfSBuf *reqData, struct HdfSBuf *rspData) { struct AudioKcontrol *kctrl = NULL; struct AudioCtrlElemValue elemValue; @@ -239,8 +245,7 @@ static int32_t ControlDispatch(struct HdfDeviceIoClient *client, int cmdId, return HDF_FAILURE; } - AudioSapmRefreshTime(true); - for (i = 0; i < ARRAY_SIZE(g_controlDispCmdHandle); ++i) { + for (i = 0; i < HDF_ARRAY_SIZE(g_controlDispCmdHandle); ++i) { if ((cmdId == (int)(g_controlDispCmdHandle[i].cmd)) && (g_controlDispCmdHandle[i].func != NULL)) { return g_controlDispCmdHandle[i].func(client, data, reply); } @@ -296,15 +301,6 @@ static int32_t AudioControlInit(struct HdfDeviceObject *device) return HDF_SUCCESS; } -static void ControlHostDestroy(struct ControlHost *host) -{ - if (host == NULL) { - ADM_LOG_ERR("Input params check error: host is NULL."); - return; - } - OsalMemFree(host); -} - static void AudioControlRelease(struct HdfDeviceObject *device) { struct ControlHost *controlHost = NULL; @@ -319,7 +315,7 @@ static void AudioControlRelease(struct HdfDeviceObject *device) ADM_LOG_ERR("controlHost is NULL."); return; } - ControlHostDestroy(controlHost); + OsalMemFree(controlHost); } /* HdfDriverEntry definitions */ diff --git a/model/audio/dispatch/src/audio_stream_dispatch.c b/model/audio/dispatch/src/audio_stream_dispatch.c index d3b176737..70e26609a 100755 --- a/model/audio/dispatch/src/audio_stream_dispatch.c +++ b/model/audio/dispatch/src/audio_stream_dispatch.c @@ -10,7 +10,7 @@ #define HDF_LOG_TAG audio_stream_dispatch -int32_t HwCpuDaiDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams *params) +int32_t HwCpuDaiDispatch(const struct AudioCard *audioCard, const struct AudioPcmHwParams *params) { if ((audioCard == NULL) || (params == NULL)) { ADM_LOG_ERR("CpuDai input param is NULL."); @@ -43,7 +43,7 @@ int32_t HwCpuDaiDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams *p return HDF_SUCCESS; } -int32_t HwCodecDaiDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams *params) +int32_t HwCodecDaiDispatch(const struct AudioCard *audioCard, const struct AudioPcmHwParams *params) { if ((audioCard == NULL) || (params == NULL)) { ADM_LOG_ERR("CodecDai input param is NULL."); @@ -78,7 +78,7 @@ int32_t HwCodecDaiDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams return HDF_SUCCESS; } -int32_t HwPlatfromDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams *params) +int32_t HwPlatfromDispatch(const struct AudioCard *audioCard, const struct AudioPcmHwParams *params) { if ((audioCard == NULL) || (params == NULL)) { ADM_LOG_ERR("Platfrom input param is NULL."); @@ -111,7 +111,7 @@ int32_t HwPlatfromDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams return HDF_SUCCESS; } -int32_t HwParamsDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams *params) +int32_t HwParamsDispatch(const struct AudioCard *audioCard, const struct AudioPcmHwParams *params) { if ((audioCard == NULL) || (params == NULL)) { ADM_LOG_ERR("input param is NULL."); @@ -201,7 +201,8 @@ static int32_t HwParamsDataAnalysis(struct HdfSBuf *reqData, struct AudioPcmHwPa return HDF_SUCCESS; } -int32_t StreamHostHwParams(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostHwParams(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, + struct HdfSBuf *reply) { struct AudioPcmHwParams params; struct StreamHost *streamHost = NULL; @@ -210,7 +211,7 @@ int32_t StreamHostHwParams(struct HdfDeviceIoClient *client, struct HdfSBuf *dat int ret; ADM_LOG_DEBUG("entry."); - if ((client == NULL) || (data == NULL)) { + if ((client == NULL || client->device == NULL) || (data == NULL)) { ADM_LOG_ERR("input param is NULL."); return HDF_FAILURE; } @@ -262,7 +263,7 @@ static struct AudioCard *StreamHostGetCardInstance(const struct HdfDeviceIoClien struct StreamHost *streamHost = NULL; struct AudioCard *audioCard = NULL; - if (client == NULL) { + if (client == NULL || client->device == NULL) { ADM_LOG_ERR("input param is NULL."); return NULL; } @@ -288,7 +289,8 @@ static struct AudioCard *StreamHostGetCardInstance(const struct HdfDeviceIoClien return audioCard; } -int32_t StreamHostCapturePrepare(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostCapturePrepare(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, + struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; @@ -328,7 +330,8 @@ int32_t StreamHostCapturePrepare(struct HdfDeviceIoClient *client, struct HdfSBu return HDF_SUCCESS; } -int32_t StreamHostRenderPrepare(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostRenderPrepare(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, + struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; @@ -368,7 +371,7 @@ int32_t StreamHostRenderPrepare(struct HdfDeviceIoClient *client, struct HdfSBuf return HDF_SUCCESS; } -static int32_t StreamTransferWrite(struct AudioCard *audioCard, struct AudioTxData *transfer) +static int32_t StreamTransferWrite(const struct AudioCard *audioCard, struct AudioTxData *transfer) { struct PlatformDevice *platform = NULL; int32_t ret; @@ -394,7 +397,63 @@ static int32_t StreamTransferWrite(struct AudioCard *audioCard, struct AudioTxDa return HDF_SUCCESS; } -int32_t StreamHostWrite(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +static int32_t StreamTransferMmapWrite(const struct AudioCard *audioCard, struct AudioTxMmapData *txMmapData) +{ + struct PlatformDevice *platform = NULL; + int32_t ret; + ADM_LOG_DEBUG("entry."); + + if (audioCard == NULL || audioCard->rtd == NULL || txMmapData == NULL) { + ADM_LOG_ERR("input param is NULL."); + return HDF_FAILURE; + } + + platform = audioCard->rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL || + platform->devData->ops->Write == NULL) { + ADM_LOG_ERR("audioCard platform is NULL."); + return HDF_FAILURE; + } + + ret = platform->devData->ops->MmapWrite(audioCard, txMmapData); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform write fail ret=%d", ret); + return HDF_FAILURE; + } + + ADM_LOG_DEBUG("sucess."); + return HDF_SUCCESS; +} + +static int32_t StreamTransferMmapRead(const struct AudioCard *audioCard, struct AudioRxMmapData *rxMmapData) +{ + struct PlatformDevice *platform = NULL; + int32_t ret; + ADM_LOG_DEBUG("entry."); + + if (audioCard == NULL || audioCard->rtd == NULL || rxMmapData == NULL) { + ADM_LOG_ERR("input param is NULL."); + return HDF_FAILURE; + } + + platform = audioCard->rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL || + platform->devData->ops->MmapRead == NULL) { + ADM_LOG_ERR("audioCard platform is NULL."); + return HDF_FAILURE; + } + + ret = platform->devData->ops->MmapRead(audioCard, rxMmapData); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform read fail ret=%d", ret); + return HDF_FAILURE; + } + + ADM_LOG_DEBUG("sucess."); + return HDF_SUCCESS; +} + +int32_t StreamHostWrite(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { struct AudioTxData transfer; struct AudioCard *audioCard = NULL; @@ -436,7 +495,7 @@ int32_t StreamHostWrite(struct HdfDeviceIoClient *client, struct HdfSBuf *data, return HDF_SUCCESS; } -int32_t StreamHostRead(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostRead(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; @@ -490,7 +549,149 @@ int32_t StreamHostRead(struct HdfDeviceIoClient *client, struct HdfSBuf *data, s return HDF_SUCCESS; } -int32_t StreamHostRenderStart(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostMmapWrite(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioTxMmapData txMmapData; + struct AudioCard *audioCard = NULL; + uint64_t mAddress = 0; + ADM_LOG_DEBUG("entry."); + if (client == NULL || reply == NULL) { + ADM_LOG_ERR("input param is NULL."); + return HDF_FAILURE; + } + if (!HdfSbufReadUint64(data, &mAddress)) { + ADM_LOG_ERR("render mmap read request memory address failed!"); + return HDF_FAILURE; + } + + txMmapData.memoryAddress = (void *)((uintptr_t)mAddress); + + if (!HdfSbufReadInt32(data, (uint32_t *)&(txMmapData.memoryFd))) { + ADM_LOG_ERR("render mmap read request memory fd failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadInt32(data, (uint32_t *)&(txMmapData.totalBufferFrames))) { + ADM_LOG_ERR("render mmap read request total buffer frames failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadInt32(data, (uint32_t *)&(txMmapData.transferFrameSize))) { + ADM_LOG_ERR("render mmap read request transfer frame size failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadInt32(data, (uint32_t *)&(txMmapData.isShareable))) { + ADM_LOG_ERR("render mmap read request is share able failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadUint32(data, (uint32_t *)&(txMmapData.offset))) { + ADM_LOG_ERR("render mmap read request offset failed!"); + return HDF_FAILURE; + } + audioCard = StreamHostGetCardInstance(client); + if (StreamTransferMmapWrite(audioCard, &txMmapData) != HDF_SUCCESS) { + ADM_LOG_ERR("render mmap write reg value fail!"); + return HDF_FAILURE; + } + ADM_LOG_DEBUG("success."); + return HDF_SUCCESS; +} +int32_t StreamHostMmapPositionWrite(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioCard *audioCard = NULL; + ADM_LOG_DEBUG("entry."); + if (client == NULL || reply == NULL) { + ADM_LOG_ERR("input param is NULL."); + return HDF_FAILURE; + } + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL || audioCard->rtd->platform == NULL) { + ADM_LOG_ERR("audioCard instance is NULL."); + return HDF_FAILURE; + } + struct PlatformHost *platformHost = PlatformHostFromDevice(audioCard->rtd->platform->device); + if (platformHost == NULL) { + ADM_LOG_ERR("platformHost instance is NULL."); + return HDF_FAILURE; + } + if (!HdfSbufWriteUint64(reply, platformHost->renderBufInfo.framesPosition)) { + ADM_LOG_ERR("render mmap write position fail!"); + return HDF_FAILURE; + } + ADM_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostMmapRead(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + uint64_t mAddress = 0; + struct AudioCard *audioCard = NULL; + struct AudioRxMmapData rxMmapData; + ADM_LOG_DEBUG("entry."); + if (client == NULL || reply == NULL) { + ADM_LOG_ERR("input param is NULL."); + return HDF_FAILURE; + } + if (!HdfSbufReadUint64(data, &mAddress)) { + ADM_LOG_ERR("capture mmap read request memory address failed!"); + return HDF_FAILURE; + } + rxMmapData.memoryAddress = (void *)((uintptr_t)mAddress); + + if (!HdfSbufReadInt32(data, (uint32_t *)&(rxMmapData.memoryFd))) { + ADM_LOG_ERR("capture mmap read request memory fd failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadInt32(data, (uint32_t *)&(rxMmapData.totalBufferFrames))) { + ADM_LOG_ERR("capture mmap read request total buffer frames failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadInt32(data, (uint32_t *)&(rxMmapData.transferFrameSize))) { + ADM_LOG_ERR("capture mmap read request transfer frame size failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadInt32(data, (uint32_t *)&(rxMmapData.isShareable))) { + ADM_LOG_ERR("capture mmap read request is share able failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadUint32(data, (uint32_t *)&(rxMmapData.offset))) { + ADM_LOG_ERR("capture mmap read request offset failed!"); + return HDF_FAILURE; + } + audioCard = StreamHostGetCardInstance(client); + if (StreamTransferMmapRead(audioCard, &rxMmapData) != HDF_SUCCESS) { + ADM_LOG_ERR("capture mmap read reg value fail!"); + return HDF_FAILURE; + } + ADM_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostMmapPositionRead(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioCard *audioCard = NULL; + ADM_LOG_DEBUG("entry."); + if (client == NULL || reply == NULL) { + ADM_LOG_ERR("input param is NULL."); + return HDF_FAILURE; + } + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL || audioCard->rtd->platform == NULL) { + ADM_LOG_ERR("audioCard is NULL."); + return HDF_FAILURE; + } + struct PlatformHost *platformHost = PlatformHostFromDevice(audioCard->rtd->platform->device); + if (platformHost == NULL) { + ADM_LOG_ERR("platformHost is NULL."); + return HDF_FAILURE; + } + if (!HdfSbufWriteUint64(reply, platformHost->captureBufInfo.framesPosition)) { + ADM_LOG_ERR("render mmap write position fail!"); + return HDF_FAILURE; + } + ADM_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostRenderStart(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; @@ -526,11 +727,11 @@ int32_t StreamHostRenderStart(struct HdfDeviceIoClient *client, struct HdfSBuf * return HDF_ERR_IO; } - ADM_LOG_INFO("success."); + ADM_LOG_DEBUG("success."); return HDF_SUCCESS; } -int32_t StreamHostCaptureStart(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostCaptureStart(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; @@ -566,11 +767,12 @@ int32_t StreamHostCaptureStart(struct HdfDeviceIoClient *client, struct HdfSBuf return HDF_ERR_IO; } - ADM_LOG_INFO("success."); + ADM_LOG_DEBUG("success."); return HDF_SUCCESS; } -int32_t StreamHostRenderStop(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostRenderStop(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, + struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; @@ -606,11 +808,11 @@ int32_t StreamHostRenderStop(struct HdfDeviceIoClient *client, struct HdfSBuf *d return HDF_ERR_IO; } - ADM_LOG_INFO("success."); + ADM_LOG_DEBUG("success."); return HDF_SUCCESS; } -int32_t StreamHostCaptureStop(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostCaptureStop(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; @@ -646,11 +848,11 @@ int32_t StreamHostCaptureStop(struct HdfDeviceIoClient *client, struct HdfSBuf * return HDF_ERR_IO; } - ADM_LOG_INFO("success."); + ADM_LOG_DEBUG("success."); return HDF_SUCCESS; } -int32_t StreamHostRenderPause(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostRenderPause(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; @@ -686,11 +888,12 @@ int32_t StreamHostRenderPause(struct HdfDeviceIoClient *client, struct HdfSBuf * return HDF_ERR_IO; } - ADM_LOG_INFO("success."); + ADM_LOG_DEBUG("success."); return HDF_SUCCESS; } -int32_t StreamHostCapturePause(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostCapturePause(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, + struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; @@ -726,11 +929,12 @@ int32_t StreamHostCapturePause(struct HdfDeviceIoClient *client, struct HdfSBuf return HDF_ERR_IO; } - ADM_LOG_INFO("success."); + ADM_LOG_DEBUG("success."); return HDF_SUCCESS; } -int32_t StreamHostRenderResume(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostRenderResume(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, + struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; @@ -766,11 +970,12 @@ int32_t StreamHostRenderResume(struct HdfDeviceIoClient *client, struct HdfSBuf return HDF_ERR_IO; } - ADM_LOG_INFO("success."); + ADM_LOG_DEBUG("success."); return HDF_SUCCESS; } -int32_t StreamHostCaptureResume(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostCaptureResume(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, + struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; @@ -806,11 +1011,12 @@ int32_t StreamHostCaptureResume(struct HdfDeviceIoClient *client, struct HdfSBuf return HDF_ERR_IO; } - ADM_LOG_INFO("success."); + ADM_LOG_DEBUG("success."); return HDF_SUCCESS; } -int32_t StreamHostDspDecode(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostDspDecode(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, + struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct DspDevice *dspDev = NULL; @@ -844,11 +1050,12 @@ int32_t StreamHostDspDecode(struct HdfDeviceIoClient *client, struct HdfSBuf *da return HDF_ERR_IO; } - ADM_LOG_INFO("Decode Success."); + ADM_LOG_DEBUG("Decode Success."); return HDF_SUCCESS; } -int32_t StreamHostDspEncode(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostDspEncode(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, + struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct DspDevice *dspDev = NULL; @@ -882,11 +1089,12 @@ int32_t StreamHostDspEncode(struct HdfDeviceIoClient *client, struct HdfSBuf *da return HDF_ERR_IO; } - ADM_LOG_INFO("Encode Success."); + ADM_LOG_DEBUG("Encode Success."); return HDF_SUCCESS; } -int32_t StreamHostDspEqualizer(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t StreamHostDspEqualizer(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, + struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; struct DspDevice *dspDev = NULL; @@ -920,7 +1128,7 @@ int32_t StreamHostDspEqualizer(struct HdfDeviceIoClient *client, struct HdfSBuf return HDF_ERR_IO; } - ADM_LOG_INFO("Equalizer Success."); + ADM_LOG_DEBUG("Equalizer Success."); return HDF_SUCCESS; } @@ -938,6 +1146,10 @@ static struct StreamDispCmdHandleList g_streamDispCmdHandle[] = { {AUDIO_DRV_PCM_IOCTRL_CAPTURE_PAUSE, StreamHostCapturePause}, {AUDIO_DRV_PCM_IOCTRL_RENDER_RESUME, StreamHostRenderResume}, {AUDIO_DRV_PCM_IOCTRL_CAPTURE_RESUME, StreamHostCaptureResume}, + {AUDIO_DRV_PCM_IOCTL_MMAP_BUFFER, StreamHostMmapWrite}, + {AUDIO_DRV_PCM_IOCTL_MMAP_BUFFER_CAPTURE, StreamHostMmapRead}, + {AUDIO_DRV_PCM_IOCTL_MMAP_POSITION, StreamHostMmapPositionWrite}, + {AUDIO_DRV_PCM_IOCTL_MMAP_POSITION_CAPTURE, StreamHostMmapPositionRead}, {AUDIO_DRV_PCM_IOCTRL_DSP_DECODE, StreamHostDspDecode}, {AUDIO_DRV_PCM_IOCTRL_DSP_ENCODE, StreamHostDspEncode}, {AUDIO_DRV_PCM_IOCTRL_DSP_EQUALIZER, StreamHostDspEqualizer}, @@ -989,7 +1201,7 @@ static int32_t AudioStreamBind(struct HdfDeviceObject *device) } struct StreamHost *streamHost = StreamHostCreateAndBind(device); - if (streamHost->device == NULL) { + if (streamHost == NULL || streamHost->device == NULL) { ADM_LOG_ERR("StreamHostCreateAndBind failed"); return HDF_FAILURE; } @@ -1020,26 +1232,6 @@ static int32_t AudioStreamInit(struct HdfDeviceObject *device) return HDF_SUCCESS; } -void StreamParamDestroy(struct AudioPcmHwParams *params) -{ - if (params == NULL) { - return; - } - - OsalMemFree(params); - params = NULL; -} - -void StreamHostDestroy(struct StreamHost *host) -{ - if (host == NULL) { - return; - } - - OsalMemFree(host); - host = NULL; -} - static void AudioStreamRelease(struct HdfDeviceObject *device) { if (device == NULL) { @@ -1053,8 +1245,10 @@ static void AudioStreamRelease(struct HdfDeviceObject *device) return; } - StreamParamDestroy(streamHost->priv); - StreamHostDestroy(streamHost); + if (streamHost->priv != NULL) { + OsalMemFree(streamHost->priv); + } + OsalMemFree(streamHost); } /* HdfDriverEntry definitions */ diff --git a/model/audio/dispatch/test/unittest/common/audio_stream_dispatch_test.cpp b/model/audio/dispatch/test/unittest/common/audio_stream_dispatch_test.cpp index 33fd4422f..50bd21dcb 100755 --- a/model/audio/dispatch/test/unittest/common/audio_stream_dispatch_test.cpp +++ b/model/audio/dispatch/test/unittest/common/audio_stream_dispatch_test.cpp @@ -43,9 +43,3 @@ HWTEST_F(AudioStreamDispatchTest, AudioStreamDispatchTest001, TestSize.Level0) struct HdfTestMsg msg = {g_testAudioType, TESTSTREAMDISPATCH, -1}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } - -HWTEST_F(AudioStreamDispatchTest, AudioStreamDispatchTest002, TestSize.Level0) -{ - struct HdfTestMsg msg = {g_testAudioType, TESTSTREAMDESTORY, -1}; - EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); -} diff --git a/model/audio/sapm/include/audio_sapm.h b/model/audio/sapm/include/audio_sapm.h index 700a1211f..0eaa935cb 100755 --- a/model/audio/sapm/include/audio_sapm.h +++ b/model/audio/sapm/include/audio_sapm.h @@ -201,11 +201,16 @@ int32_t AudioSapmNewComponents(struct AudioCard *audioCard, int32_t AudioSapmAddRoutes(struct AudioCard *audioCard, const struct AudioSapmRoute *route, int32_t routeMaxNum); int32_t AudioSapmNewControls(struct AudioCard *audioCard); -int32_t AudioSapmPowerComponents(struct AudioCard *audioCard); -u64 AudioSapmRefreshTime(bool bRefresh); - -extern int32_t AudioSapmGetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); -extern int32_t AudioSapmSetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +int AudioSapmPowerComponents(struct AudioCard *audioCard); +int32_t AudioSapmSleep(const struct AudioCard *audioCard); +uint64_t AudioSapmRefreshTime(bool bRefresh); +int32_t AudioSampPowerUp(const struct AudioCard *card); +int32_t AudioSampSetPowerMonitor(struct AudioCard *card, bool powerMonitorState); + +int32_t AudioCodecSapmSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue); +int32_t AudioCodecSapmGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +int32_t AudioAccessorySapmSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue); +int32_t AudioAccessorySapmGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); #ifdef __cplusplus #if __cplusplus diff --git a/model/audio/sapm/src/audio_sapm.c b/model/audio/sapm/src/audio_sapm.c index 33f7bb9f5..1b8800b81 100755 --- a/model/audio/sapm/src/audio_sapm.c +++ b/model/audio/sapm/src/audio_sapm.c @@ -243,11 +243,16 @@ int32_t AudioSapmNewComponent(struct AudioCard *audioCard, const struct AudioSap { struct AudioSapmComponent *sapmComponent = NULL; - if ((audioCard == NULL) || (component == NULL)) { + if ((audioCard == NULL || audioCard->rtd == NULL || audioCard->rtd->codec == NULL) || (component == NULL)) { ADM_LOG_ERR("input params check error: audioCard=%p, component=%p.", audioCard, component); return HDF_FAILURE; } + if (component->componentName == NULL) { + ADM_LOG_ERR("component->componentName is NULL"); + return HDF_FAILURE; + } + sapmComponent = (struct AudioSapmComponent *)OsalMemCalloc(sizeof(struct AudioSapmComponent)); if (sapmComponent == NULL) { ADM_LOG_ERR("malloc cpt fail!"); @@ -323,14 +328,15 @@ static void MuxSetPathStatus(const struct AudioSapmComponent *sapmComponent, str uint32_t reg = 0; uint32_t shift; - if ((sapmComponent == NULL) || (path == NULL) || (enumKtl == NULL)) { + if ((sapmComponent == NULL || sapmComponent->codec == NULL) || (path == NULL || path->name == NULL) || + (enumKtl == NULL || enumKtl->texts == NULL)) { ADM_LOG_ERR("input MuxSet params check error: sapmComponent=%p, path=%p, enumKtl=%p.", sapmComponent, path, enumKtl); return; } shift = enumKtl->shiftLeft; - ret = AudioCodecDeviceReadReg(sapmComponent->codec, reg, &val); + ret = AudioCodecReadReg(sapmComponent->codec, reg, &val); if (ret != HDF_SUCCESS) { ADM_LOG_ERR("MuxSet read reg fail!"); return; @@ -340,6 +346,11 @@ static void MuxSetPathStatus(const struct AudioSapmComponent *sapmComponent, str path->connect = UNCONNECT_SINK_AND_SOURCE; for (i = 0; i < enumKtl->max; i++) { + if (enumKtl->texts[i] == NULL) { + ADM_LOG_ERR("enumKtl->texts[%d] is NULL", i); + continue; + } + if ((strcmp(path->name, enumKtl->texts[i]) == 0) && item == i) { path->connect = CONNECT_SINK_AND_SOURCE; } @@ -355,7 +366,8 @@ static void MuxValueSetPathStatus(const struct AudioSapmComponent *sapmComponent uint32_t item; uint32_t reg = 0; uint32_t shift; - if ((sapmComponent == NULL) || (path == NULL) || (enumKtl == NULL)) { + if ((sapmComponent == NULL || sapmComponent->codec == NULL) || (path == NULL || path->name == NULL) || + (enumKtl == NULL || enumKtl->texts == NULL)) { ADM_LOG_ERR("input muxValueSet params check error: cpt=%p, path=%p, enumKtl=%p.", sapmComponent, path, enumKtl); return; @@ -363,7 +375,7 @@ static void MuxValueSetPathStatus(const struct AudioSapmComponent *sapmComponent shift = enumKtl->shiftLeft; - ret = AudioCodecDeviceReadReg(sapmComponent->codec, reg, &val); + ret = AudioCodecReadReg(sapmComponent->codec, reg, &val); if (ret != HDF_SUCCESS) { ADM_LOG_ERR("muxValueSet read reg fail!"); return; @@ -377,6 +389,10 @@ static void MuxValueSetPathStatus(const struct AudioSapmComponent *sapmComponent path->connect = UNCONNECT_SINK_AND_SOURCE; for (i = 0; i < enumKtl->max; i++) { + if (enumKtl->texts[i] == NULL) { + continue; + } + if ((strcmp(path->name, enumKtl->texts[i]) == 0) && item == i) { path->connect = CONNECT_SINK_AND_SOURCE; } @@ -392,9 +408,9 @@ static void MixerSetPathStatus(const struct AudioSapmComponent *sapmComponent, s uint32_t mask; uint32_t shift; uint32_t invert; - uint32_t curValue = 0; + uint32_t curValue; - if ((sapmComponent == NULL) || (path == NULL) || (mixerCtrl == NULL)) { + if ((sapmComponent == NULL || sapmComponent->codec == NULL) || (path == NULL) || (mixerCtrl == NULL)) { ADM_LOG_ERR("input params check error: sapmComponent=%p, path=%p, mixerCtrl=%p.", sapmComponent, path, mixerCtrl); return; @@ -405,7 +421,7 @@ static void MixerSetPathStatus(const struct AudioSapmComponent *sapmComponent, s mask = mixerCtrl->mask; invert = mixerCtrl->invert; - ret = AudioCodecDeviceReadReg(sapmComponent->codec, reg, &curValue); + ret = AudioCodecReadReg(sapmComponent->codec, reg, &curValue); if (ret != HDF_SUCCESS) { ADM_LOG_ERR("read reg fail!"); return; @@ -421,7 +437,8 @@ static void MixerSetPathStatus(const struct AudioSapmComponent *sapmComponent, s return; } -static int32_t AudioSapmSetPathStatus(struct AudioSapmComponent *sapmComponent, struct AudioSapmpath *path, int32_t i) +static int32_t AudioSapmSetPathStatus(const struct AudioSapmComponent *sapmComponent, + struct AudioSapmpath *path, int32_t i) { if ((sapmComponent == NULL) || (path == NULL)) { ADM_LOG_ERR("input params check error: sapmComponent=%p, path=%p.", sapmComponent, path); @@ -432,17 +449,17 @@ static int32_t AudioSapmSetPathStatus(struct AudioSapmComponent *sapmComponent, case AUDIO_SAPM_ANALOG_SWITCH: case AUDIO_SAPM_MIXER_NAMED_CTRL: { MixerSetPathStatus(sapmComponent, path, - (struct AudioMixerControl *)sapmComponent->kcontrolNews[i].privateValue); + (struct AudioMixerControl *)((volatile uintptr_t)sapmComponent->kcontrolNews[i].privateValue)); } break; case AUDIO_SAPM_MUX: { MuxSetPathStatus(sapmComponent, path, - (struct AudioEnumKcontrol *)sapmComponent->kcontrolNews[i].privateValue, i); + (struct AudioEnumKcontrol *)((volatile uintptr_t)sapmComponent->kcontrolNews[i].privateValue), i); } break; case AUDIO_SAPM_VALUE_MUX: { MuxValueSetPathStatus(sapmComponent, path, - (struct AudioEnumKcontrol *)sapmComponent->kcontrolNews[i].privateValue, i); + (struct AudioEnumKcontrol *)((volatile uintptr_t)sapmComponent->kcontrolNews[i].privateValue), i); } break; default: { @@ -468,6 +485,10 @@ static int32_t AudioSapmConnectMixer(struct AudioCard *audioCard, } for (i = 0; i < sink->kcontrolsNum; i++) { + if (sink->kcontrolNews[i].name == NULL) { + continue; + } + if (strcmp(controlName, sink->kcontrolNews[i].name) == 0) { path->name = (char *)OsalMemCalloc(strlen(sink->kcontrolNews[i].name) + 1); if (path->name == NULL) { @@ -577,12 +598,16 @@ static int32_t AudioSapmAddRoute(struct AudioCard *audioCard, const struct Audio struct AudioSapmComponent *sapmComponent = NULL; int32_t ret; - if ((audioCard == NULL) || (route == NULL)) { + if ((audioCard == NULL || &audioCard->components == NULL) || + (route == NULL || route->source == NULL || route->sink == NULL)) { ADM_LOG_ERR("input params check error: audioCard=%p, route=%p.", audioCard, route); return HDF_FAILURE; } DLIST_FOR_EACH_ENTRY(sapmComponent, &audioCard->components, struct AudioSapmComponent, list) { + if (sapmComponent == NULL || sapmComponent->componentName == NULL) { + continue; + } if ((cptSource == NULL) && (strcmp(sapmComponent->componentName, route->source) == 0)) { cptSource = sapmComponent; continue; @@ -648,13 +673,17 @@ int32_t AudioSapmNewMixerControls(struct AudioSapmComponent *sapmComponent, stru struct AudioSapmpath *path = NULL; int32_t i; - if ((sapmComponent == NULL) || (audioCard == NULL)) { + if (sapmComponent == NULL || audioCard == NULL) { ADM_LOG_ERR("input params check error: sapmComponent=%p, audioCard=%p.", sapmComponent, audioCard); return HDF_FAILURE; } for (i = 0; i < sapmComponent->kcontrolsNum; i++) { DLIST_FOR_EACH_ENTRY(path, &sapmComponent->sources, struct AudioSapmpath, listSink) { + if (path == NULL || path->name == NULL || sapmComponent->kcontrolNews[i].name == NULL) { + continue; + } + if (strcmp(path->name, sapmComponent->kcontrolNews[i].name) != 0) { continue; } @@ -676,8 +705,8 @@ int AudioSapmNewMuxControls(struct AudioSapmComponent *sapmComponent, struct Aud { struct AudioKcontrol *kctrl = NULL; - if (sapmComponent == NULL) { - ADM_LOG_ERR("input param sapmComponent is NULL."); + if (sapmComponent == NULL || sapmComponent->kcontrolNews == NULL || audioCard == NULL) { + ADM_LOG_ERR("input param is NULL."); return HDF_FAILURE; } @@ -703,7 +732,7 @@ static void AudioSapmPowerSeqInsert(struct AudioSapmComponent *newSapmComponent, struct AudioSapmComponent *sapmComponent = NULL; int32_t *seq = {0}; - if (newSapmComponent == NULL) { + if (newSapmComponent == NULL || list == NULL || newSapmComponent->componentName == NULL) { ADM_LOG_ERR("input param newCpt is NULL."); return; } @@ -761,18 +790,14 @@ static void AudioSapmSetPower(struct AudioCard *audioCard, struct AudioSapmCompo AudioSapmPowerSeqInsert(sapmComponent, downList, power); } - sapmComponent->power = power; return; } -static void AudioSapmPowerUpSeqRun(struct DListHead *list) +static void AudioSapmPowerUpSeqRun(const struct DListHead *list) { - enum AudioDeviceType deviceType; + uint32_t val; struct AudioMixerControl mixerControl; - void *device = NULL; struct AudioSapmComponent *sapmComponent = NULL; - int32_t ret; - if (list == NULL) { ADM_LOG_ERR("input param list is NULL."); return; @@ -780,34 +805,34 @@ static void AudioSapmPowerUpSeqRun(struct DListHead *list) DLIST_FOR_EACH_ENTRY(sapmComponent, list, struct AudioSapmComponent, powerList) { if ((sapmComponent->reg >= 0) && (sapmComponent->power == SAPM_POWER_DOWN)) { + val = SAPM_POWER_UP; sapmComponent->power = SAPM_POWER_UP; mixerControl.reg = sapmComponent->reg; mixerControl.mask = sapmComponent->mask; mixerControl.shift = sapmComponent->shift; - if (sapmComponent->codec != NULL && sapmComponent->codec->devData != NULL) { - deviceType = AUDIO_CODEC_DEVICE; - device = sapmComponent->codec; - } else { - deviceType = AUDIO_ACCESSORY_DEVICE; - device = sapmComponent->accessory; + if (sapmComponent->invert) { + val = !val; } - ret = AudioUpdateRegBits(deviceType, device, &mixerControl, SAPM_POWER_UP); - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("update reg bits fail!"); - return; + if (sapmComponent->codec != NULL) { + AudioUpdateCodecRegBits(sapmComponent->codec, &mixerControl, val); + ADM_LOG_DEBUG("Sapm Codec Power Up."); + } + if (sapmComponent->accessory != NULL) { + AudioUpdateAccessoryRegBits(sapmComponent->accessory, &mixerControl, val); + ADM_LOG_DEBUG("Sapm Accessory Power Up."); } } } + return; } -static void AudioSapmPowerDownSeqRun(struct DListHead *list) +static void AudioSapmPowerDownSeqRun(const struct DListHead *list) { - void *device = NULL; - enum AudioDeviceType deviceType; + uint32_t val; struct AudioMixerControl mixerControl; struct AudioSapmComponent *sapmComponent = NULL; - int32_t ret; + ADM_LOG_DEBUG("entry!"); if (list == NULL) { ADM_LOG_ERR("input param list is NULL."); @@ -816,21 +841,21 @@ static void AudioSapmPowerDownSeqRun(struct DListHead *list) DLIST_FOR_EACH_ENTRY(sapmComponent, list, struct AudioSapmComponent, powerList) { if ((sapmComponent->reg >= 0) && (sapmComponent->power == SAPM_POWER_UP)) { + val = SAPM_POWER_DOWN; sapmComponent->power = SAPM_POWER_DOWN; mixerControl.mask = sapmComponent->mask; mixerControl.reg = sapmComponent->reg; mixerControl.shift = sapmComponent->shift; - if (sapmComponent->codec != NULL && sapmComponent->codec->devData != NULL) { - deviceType = AUDIO_CODEC_DEVICE; - device = sapmComponent->codec; - } else { - deviceType = AUDIO_ACCESSORY_DEVICE; - device = sapmComponent->accessory; + if (sapmComponent->invert) { + val = !val; } - ret = AudioUpdateRegBits(deviceType, device, &mixerControl, SAPM_POWER_DOWN); - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("update reg bits fail!"); - return; + if (sapmComponent->codec != NULL) { + AudioUpdateCodecRegBits(sapmComponent->codec, &mixerControl, val); + ADM_LOG_DEBUG("Sapm Codec Power Down."); + } + if (sapmComponent->accessory != NULL) { + AudioUpdateAccessoryRegBits(sapmComponent->accessory, &mixerControl, val); + ADM_LOG_DEBUG("Sapm Accessory Power Down."); } } } @@ -838,11 +863,12 @@ static void AudioSapmPowerDownSeqRun(struct DListHead *list) return; } -int32_t AudioSapmPowerComponents(struct AudioCard *audioCard) +int AudioSapmPowerComponents(struct AudioCard *audioCard) { struct AudioSapmComponent *sapmComponent = NULL; struct DListHead upList; struct DListHead downList; + ADM_LOG_DEBUG("entry!"); if (audioCard == NULL) { ADM_LOG_ERR("input param audioCard is NULL."); @@ -879,15 +905,15 @@ int32_t AudioSapmPowerComponents(struct AudioCard *audioCard) static void ReadInitComponentPowerStatus(struct AudioSapmComponent *sapmComponent) { int32_t ret; - uint32_t regVal; + uint32_t regVal = 0; - if (sapmComponent == NULL) { + if (sapmComponent == NULL || sapmComponent->codec == NULL) { ADM_LOG_ERR("input param sapmComponent is NULL."); return; } if (sapmComponent->reg >= 0) { - ret = AudioCodecDeviceReadReg(sapmComponent->codec, sapmComponent->reg, ®Val); + ret = AudioCodecReadReg(sapmComponent->codec, sapmComponent->reg, ®Val); if (ret != HDF_SUCCESS) { ADM_LOG_ERR("read reg fail!"); return; @@ -908,11 +934,11 @@ static void ReadInitComponentPowerStatus(struct AudioSapmComponent *sapmComponen return; } -void AudioSapmSleep(const struct AudioCard *audioCard) +int32_t AudioSapmSleep(const struct AudioCard *audioCard) { if (audioCard == NULL) { ADM_LOG_ERR("input param audioCard is NULL."); - return; + return HDF_ERR_INVALID_OBJECT; } if (g_sleepTimer.realTimer != NULL) { @@ -922,17 +948,17 @@ void AudioSapmSleep(const struct AudioCard *audioCard) OsalTimerStartLoop(&g_sleepTimer); AudioSapmRefreshTime(true); - return; + return HDF_SUCCESS; } int32_t AudioSapmNewControls(struct AudioCard *audioCard) { struct AudioSapmComponent *sapmComponent = NULL; - int32_t ret; + int ret; if (audioCard == NULL) { ADM_LOG_ERR("input param audioCard is NULL."); - return HDF_FAILURE; + return HDF_ERR_INVALID_OBJECT; } DLIST_FOR_EACH_ENTRY(sapmComponent, &audioCard->components, struct AudioSapmComponent, list) { @@ -984,17 +1010,17 @@ int32_t AudioSapmNewControls(struct AudioCard *audioCard) return HDF_SUCCESS; } -static int32_t MixerUpdatePowerStatus(struct AudioKcontrol *kcontrol, uint32_t pathStatus) +static int32_t MixerUpdatePowerStatus(const struct AudioKcontrol *kcontrol, uint32_t pathStatus) { struct AudioCard *audioCard = NULL; struct AudioSapmpath *path = NULL; - int32_t ret; + int ret; if (kcontrol == NULL || kcontrol->pri == NULL) { ADM_LOG_ERR("input param kcontrol is NULL."); - return HDF_FAILURE; + return HDF_ERR_INVALID_OBJECT; } - audioCard = (struct AudioCard *)(kcontrol->pri); + audioCard = (struct AudioCard *)((volatile uintptr_t)(kcontrol->pri)); DLIST_FOR_EACH_ENTRY(path, &audioCard->paths, struct AudioSapmpath, list) { if (path->kcontrol != kcontrol) { @@ -1024,134 +1050,136 @@ static int32_t MixerUpdatePowerStatus(struct AudioKcontrol *kcontrol, uint32_t p return HDF_FAILURE; } - DLIST_FOR_EACH_ENTRY(path, &audioCard->paths, struct AudioSapmpath, list) { - ADM_LOG_DEBUG("path->sink->componentName = %s, path->source->componentName = %s, \ - path->connect = %d.", - path->sink->componentName, path->source->componentName, path->connect); - } return HDF_SUCCESS; } -int32_t AudioSapmGetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +int32_t AudioCodecSapmGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) { - int32_t ret; - struct CodecDevice *codec = NULL; - struct AudioMixerControl *mixerCtrl = NULL; - uint32_t curValue; - - if (kcontrol == NULL || kcontrol->privateValue <= 0 || elemValue == NULL) { - ADM_LOG_ERR("input params: kcontrol is NULL or elemValue=%p.", elemValue); - return HDF_ERR_INVALID_OBJECT; - } - - codec = AudioKcontrolGetCodec(kcontrol); - if (codec == NULL || codec->devData == NULL || codec->devData->Read == NULL) { - ADM_LOG_ERR("codec device is NULL."); + if (AudioCodecGetCtrlOps(kcontrol, elemValue) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio codec sapm get control switch is fail!"); return HDF_FAILURE; } - mixerCtrl = (struct AudioMixerControl *)kcontrol->privateValue; - ret = codec->devData->Read(codec, mixerCtrl->reg, &curValue); - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("sapm Get Ctrl Read fail!"); + + return HDF_SUCCESS; +} + +int32_t AudioAccessorySapmGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +{ + if (AudioAccessoryGetCtrlOps(kcontrol, elemValue) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio accessory sapm get control switch is fail!"); return HDF_FAILURE; } - curValue = (curValue >> mixerCtrl->shift) & mixerCtrl->mask; - if (curValue > mixerCtrl->max) { - ADM_LOG_ERR("invalid curValue:%d.", curValue); - return HDF_FAILURE; + return HDF_SUCCESS; +} + +/* 1.first user specify old component -- power down; 2.second user specify new component -- power up */ +static int32_t AudioSapmSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue, + uint32_t *value, uint32_t *pathStatus) +{ + struct AudioMixerControl *mixerCtrl = NULL; + int iFlag = (kcontrol == NULL) || (kcontrol->privateValue <= 0) || (elemValue == NULL) + || (value == NULL) || (pathStatus == NULL); + if (iFlag) { + ADM_LOG_ERR("input params invalid."); + return HDF_ERR_INVALID_OBJECT; } + mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue); + *value = elemValue->value[0]; + if (*value < mixerCtrl->min || *value > mixerCtrl->max) { + ADM_LOG_ERR("value is invalid."); + return HDF_ERR_INVALID_OBJECT; + } if (mixerCtrl->invert) { - curValue = mixerCtrl->max - curValue; + *value = mixerCtrl->max - *value; + } + if (*value) { + *pathStatus = CONNECT_SINK_AND_SOURCE; + } else { + *pathStatus = UNCONNECT_SINK_AND_SOURCE; } - elemValue->value[0] = curValue; return HDF_SUCCESS; } -int32_t AudioSapmPutCtrlOpsSub(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, - struct AudioMixerControl *mixerCtrl, int32_t value, uint32_t pathStatus) +int32_t AudioCodecSapmSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue) { - int32_t ret = HDF_FAILURE; - void *device = NULL; - enum AudioDeviceType deviceType; uint32_t curValue = 0; - struct CodecDevice *codec = AudioKcontrolGetCodec(kcontrol); - struct AccessoryDevice *accessory = AudioKcontrolGetAccessory(kcontrol); + uint32_t value; + uint32_t pathStatus = 0; + struct CodecDevice *codec = NULL; + struct AudioMixerControl *mixerCtrl = NULL; + if ((kcontrol == NULL) || (kcontrol->privateValue <= 0) || (elemValue == NULL)) { + ADM_LOG_ERR("input params: kcontrol is NULL or elemValue=%p.", elemValue); + return HDF_ERR_INVALID_OBJECT; + } - if (kcontrol == NULL || elemValue == NULL || mixerCtrl == NULL) { - ADM_LOG_ERR("parser is fail!"); - return HDF_FAILURE; + mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue); + if (AudioSapmSetCtrlOps(kcontrol, elemValue, &value, &pathStatus) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio sapm put control switch fail!"); } - if (codec != NULL) { - deviceType = AUDIO_CODEC_DEVICE; - device = (void *)codec; - ret = AudioCodecDeviceReadReg(codec, mixerCtrl->reg, &curValue); - } else if (accessory != NULL) { - deviceType = AUDIO_ACCESSORY_DEVICE; - device = (void *)accessory; - ret = AudioAccessoryDeviceReadReg(accessory, mixerCtrl->reg, &curValue); + codec = AudioKcontrolGetCodec(kcontrol); + if (AudioCodecReadReg(codec, mixerCtrl->reg, &curValue) != HDF_SUCCESS) { + ADM_LOG_ERR("Device read register is failure!"); + return HDF_FAILURE; } - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("Device read fail!"); + if (MixerUpdatePowerStatus(kcontrol, pathStatus) != HDF_SUCCESS) { + ADM_LOG_ERR("update power status is failure!"); return HDF_FAILURE; } curValue &= mixerCtrl->mask << mixerCtrl->shift; value = (value & mixerCtrl->mask) << mixerCtrl->shift; - if ((curValue != value) || g_audioSapmIsSleep) { - if (MixerUpdatePowerStatus(kcontrol, pathStatus) != HDF_SUCCESS) { - ADM_LOG_ERR("update power status fail!"); - return HDF_FAILURE; - } - if (AudioUpdateRegBits(deviceType, device, mixerCtrl, elemValue->value[0]) != HDF_SUCCESS) { + if (curValue != value) { + if (AudioUpdateCodecRegBits(codec, mixerCtrl, elemValue->value[0]) != HDF_SUCCESS) { ADM_LOG_ERR("update reg bits fail!"); return HDF_FAILURE; } } - return HDF_SUCCESS; } /* 1.first user specify old component -- power down; 2.second user specify new component -- power up */ -int32_t AudioSapmSetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +int32_t AudioAccessorySapmSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue) { - uint32_t pathStatus; - int32_t value; + uint32_t curValue = 0; + uint32_t value = 0; + uint32_t pathStatus = 0; + struct AccessoryDevice *accessory = NULL; struct AudioMixerControl *mixerCtrl = NULL; - - if ((kcontrol == NULL) || (kcontrol->privateValue <= 0) || - (elemValue == NULL)) { + if ((kcontrol == NULL) || (kcontrol->privateValue <= 0) || (elemValue == NULL)) { ADM_LOG_ERR("input params: kcontrol is NULL or elemValue=%p.", elemValue); return HDF_ERR_INVALID_OBJECT; } - mixerCtrl = (struct AudioMixerControl *)kcontrol->privateValue; - value = elemValue->value[0]; - if (value < mixerCtrl->min || value > mixerCtrl->max) { - ADM_LOG_ERR("value is invalid."); - return HDF_ERR_INVALID_OBJECT; - } - if (mixerCtrl->invert) { - value = mixerCtrl->max - value; - } - if (value) { - pathStatus = CONNECT_SINK_AND_SOURCE; - } else { - pathStatus = UNCONNECT_SINK_AND_SOURCE; + + mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue); + if (AudioSapmSetCtrlOps(kcontrol, elemValue, &value, &pathStatus) != HDF_SUCCESS) { + ADM_LOG_ERR("Audio sapm put control switch fail!"); } - if (AudioSapmPutCtrlOpsSub(kcontrol, elemValue, - mixerCtrl, value, pathStatus) == HDF_FAILURE) { - ADM_LOG_ERR("AudioSapmPutCtrlSwSub value is fail."); + accessory = AudioKcontrolGetAccessory(kcontrol); + if (AudioAccessoryReadReg(accessory, mixerCtrl->reg, &curValue) != HDF_SUCCESS) { + ADM_LOG_ERR("Device read fail!"); return HDF_FAILURE; } + curValue &= mixerCtrl->mask << mixerCtrl->shift; + value = (value & mixerCtrl->mask) << mixerCtrl->shift; + if (curValue != value) { + if (MixerUpdatePowerStatus(kcontrol, pathStatus) != HDF_SUCCESS) { + ADM_LOG_ERR("update power status fail!"); + return HDF_FAILURE; + } + if (AudioUpdateAccessoryRegBits(accessory, mixerCtrl, elemValue->value[0]) != HDF_SUCCESS) { + ADM_LOG_ERR("update reg bits fail!"); + return HDF_FAILURE; + } + } return HDF_SUCCESS; } - -u64 AudioSapmRefreshTime(bool bRefresh) +uint64_t AudioSapmRefreshTime(bool bRefresh) { - static u64 time = 0; + static uint64_t time = 0; if (bRefresh) { time = OsalGetSysTimeMs(); @@ -1162,7 +1190,7 @@ u64 AudioSapmRefreshTime(bool bRefresh) static bool AudioSapmCheckTime(void) { - int64_t diffTime = OsalGetSysTimeMs() - AudioSapmRefreshTime(false); + uint64_t diffTime = OsalGetSysTimeMs() - AudioSapmRefreshTime(false); if (diffTime > SAPM_SLEEP_TIME) { return true; } else if (diffTime < 0) { @@ -1171,32 +1199,55 @@ static bool AudioSapmCheckTime(void) return false; } +int32_t AudioSampPowerUp(const struct AudioCard *card) +{ + struct DListHead upList; + struct AudioSapmComponent *sapmComponent = NULL; + + if (card == NULL) { + ADM_LOG_ERR("input params is null."); + return HDF_ERR_INVALID_OBJECT; + } + + DListHeadInit(&upList); + DLIST_FOR_EACH_ENTRY(sapmComponent, &card->components, struct AudioSapmComponent, list) { + if (sapmComponent == NULL) { + continue; + } + if (sapmComponent->power == SAPM_POWER_DOWN) { + AudioSapmPowerSeqInsert(sapmComponent, &upList, SAPM_POWER_UP); + } + } + AudioSapmPowerUpSeqRun(&upList); + return HDF_SUCCESS; +} + +int32_t AudioSampSetPowerMonitor(struct AudioCard *card, bool powerMonitorState) +{ + if (card == NULL) { + ADM_LOG_ERR("input params is null."); + return HDF_ERR_INVALID_OBJECT; + } + AudioSapmRefreshTime(true); + card->sapmMonitorState = powerMonitorState; + return HDF_SUCCESS; +} + static void AudioSapmEnterSleepSub(uintptr_t para, struct AudioSapmComponent *sapmComponent) { - void *device = NULL; - int i; - enum AudioDeviceType deviceType; struct DListHead downList; struct AudioCard *audioCard = (struct AudioCard *)para; + ADM_LOG_INFO("entry!"); DListHeadInit(&downList); + if (audioCard == NULL) { + ADM_LOG_ERR("audioCard is null."); + return; + } DLIST_FOR_EACH_ENTRY(sapmComponent, &audioCard->components, struct AudioSapmComponent, list) { - for (i = 0; (i < sapmComponent->kcontrolsNum) && (sapmComponent->kcontrols != NULL) && - (sapmComponent->kcontrols[i] != NULL); i++) { - struct AudioMixerControl *mixerCtrl = - (struct AudioMixerControl *)(sapmComponent->kcontrols[i]->privateValue); - if (mixerCtrl != NULL) { - if (sapmComponent->codec != NULL && sapmComponent->codec->devData != NULL) { - deviceType = AUDIO_CODEC_DEVICE; - device = sapmComponent->codec; - } else { - deviceType = AUDIO_ACCESSORY_DEVICE; - device = sapmComponent->accessory; - } - AudioUpdateRegBits(deviceType, device, mixerCtrl, SAPM_POWER_DOWN); - } + if (sapmComponent == NULL) { + continue; } - ReadInitComponentPowerStatus(sapmComponent); if (sapmComponent->power == SAPM_POWER_UP) { AudioSapmPowerSeqInsert(sapmComponent, &downList, SAPM_POWER_DOWN); } @@ -1209,15 +1260,22 @@ static void AudioSapmEnterSleep(uintptr_t para) { struct AudioSapmComponent *sapmComponent = NULL; struct AudioCard *audioCard = (struct AudioCard *)para; - static bool bFirst = true; +#ifndef __LITEOS__ + ADM_LOG_DEBUG("entry!"); +#endif - if ((g_audioSapmIsSleep == true) || (audioCard == NULL) || (!AudioSapmCheckTime())) { + if (audioCard == NULL) { + return; + } + if (g_audioSapmIsSleep == true) { return; } - if (bFirst) { - bFirst = false; - AudioSapmRefreshTime(true); + if (audioCard->sapmMonitorState == false) { + return; + } + + if (!AudioSapmCheckTime()) { return; } -- Gitee From 8a5f9293577960c4dd168468d1be19bf89c67a31 Mon Sep 17 00:00:00 2001 From: vb6174 Date: Tue, 17 Aug 2021 06:28:14 +0000 Subject: [PATCH 2/2] add include Signed-off-by: vb6174 --- include/audio/audio_accessory_if.h | 62 +++++++++++++ include/audio/audio_codec_if.h | 93 +++++++++++++++++++ include/audio/audio_dai_if.h | 53 +++++++++++ include/audio/audio_dsp_if.h | 54 +++++++++++ include/audio/audio_platform_if.h | 141 +++++++++++++++++++++++++++++ 5 files changed, 403 insertions(+) create mode 100755 include/audio/audio_accessory_if.h create mode 100755 include/audio/audio_codec_if.h create mode 100755 include/audio/audio_dai_if.h create mode 100755 include/audio/audio_dsp_if.h create mode 100755 include/audio/audio_platform_if.h diff --git a/include/audio/audio_accessory_if.h b/include/audio/audio_accessory_if.h new file mode 100755 index 000000000..a86532d2d --- /dev/null +++ b/include/audio/audio_accessory_if.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef AUDIO_ACCESSORY_IF_H +#define AUDIO_ACCESSORY_IF_H + +#include "audio_host.h" +#include "audio_control.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +struct AccessoryDevice { + const char *devAccessoryName; + struct AccessoryData *devData; + struct HdfDeviceObject *device; + struct DListHead list; + struct OsalMutex mutex; +}; + +struct AudioAccessoryOps { + const char *devAccessoryName; + struct AccessoryData *devData; + struct HdfDeviceObject *device; + struct DListHead list; +}; + +/* Accessory host is defined in accessory driver */ +struct AccessoryHost { + struct IDeviceIoService service; // accessory service + struct HdfDeviceObject *device; // accessory deovce + void *priv; // accessory private data +}; + +struct AccessoryData { + const char *drvAccessoryName; + /* Accessory driver callbacks */ + int32_t (*Init)(struct AudioCard *, const struct AccessoryDevice *device); + int32_t (*Read)(const struct AccessoryDevice *, uint32_t, uint32_t *); + int32_t (*Write)(const struct AccessoryDevice *, uint32_t, uint32_t); + int32_t (*AiaoRead)(const struct AccessoryDevice *, uint32_t, uint32_t *); + int32_t (*AiaoWrite)(const struct AccessoryDevice *, uint32_t, uint32_t); + + const struct AudioKcontrol *controls; + int numControls; +}; + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif diff --git a/include/audio/audio_codec_if.h b/include/audio/audio_codec_if.h new file mode 100755 index 000000000..d0636abb4 --- /dev/null +++ b/include/audio/audio_codec_if.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef AUDIO_CODEC_IF_H +#define AUDIO_CODEC_IF_H + +#include "audio_host.h" +#include "audio_control.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#define AUDIODRV_CTL_ELEM_IFACE_DAC 0 /* virtual dac device */ +#define AUDIODRV_CTL_ELEM_IFACE_ADC 1 /* virtual adc device */ +#define AUDIODRV_CTL_ELEM_IFACE_GAIN 2 /* virtual adc device */ +#define AUDIODRV_CTL_ELEM_IFACE_MIXER 3 /* virtual mixer device */ +#define AUDIODRV_CTL_ELEM_IFACE_ACODEC 4 /* Acodec device */ +#define AUDIODRV_CTL_ELEM_IFACE_PGA 5 /* PGA device */ +#define AUDIODRV_CTL_ELEM_IFACE_AIAO 6 /* AIAO device */ + +struct VirtualAddress { + unsigned long acodecVir; + unsigned long aiaoVir; +}; + +struct CodecDevice { + const char *devCodecName; + struct CodecData *devData; + struct HdfDeviceObject *device; + struct DListHead list; + struct OsalMutex mutex; +}; + +/* codec related definitions */ +struct CodecData { + const char *drvCodecName; + /* Codec driver callbacks */ + int32_t (*Init)(struct AudioCard *, struct CodecDevice *); + int32_t (*Read)(const struct CodecDevice *, uint32_t, uint32_t *); + int32_t (*Write)(const struct CodecDevice *, uint32_t, uint32_t); + int32_t (*AiaoRead)(const struct CodecDevice *, uint32_t, uint32_t *); + int32_t (*AiaoWrite)(const struct CodecDevice *, uint32_t, uint32_t); + const struct AudioKcontrol *controls; + int numControls; + const struct AudioSapmComponent *sapmComponents; + int numSapmComponent; + const struct AudioSapmRoute *sapmRoutes; + int numSapmRoutes; +}; + +/* Codec host is defined in codec driver */ +struct CodecHost { + struct IDeviceIoService service; + struct HdfDeviceObject *device; + unsigned long priv; + unsigned long aiaoPriv; +}; + +enum AudioRegParams { + PLAYBACK_VOLUME = 0, + CAPTURE_VOLUME, + PLAYBACK_MUTE, + CAPTURE_MUTE, + LEFT_GAIN, + RIGHT_GAIN, + EXTERNAL_CODEC_ENABLE, + INTERNALLY_CODEC_ENABLE, + RENDER_CHANNEL_MODE, + CAPTRUE_CHANNEL_MODE, +}; + +enum SapmRegParams { + LPGA_MIC = 0, + RPGA_MIC, + DACL2DACR, + DACR2DACL, +}; + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* CODEC_CORE_H */ diff --git a/include/audio/audio_dai_if.h b/include/audio/audio_dai_if.h new file mode 100755 index 000000000..f6e756edf --- /dev/null +++ b/include/audio/audio_dai_if.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef AUDIO_DAI_IF_H +#define AUDIO_DAI_IF_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +struct DaiDevice { + const char *devDaiName; + struct DaiData *devData; + struct HdfDeviceObject *device; + struct DListHead list; +}; + +struct AudioDaiOps { + int32_t (*Startup)(const struct AudioCard *, const struct DaiDevice *); + int32_t (*HwParams)(const struct AudioCard *, const struct AudioPcmHwParams *, const struct DaiDevice *); + int32_t (*Trigger)(const struct AudioCard *, int, const struct DaiDevice *); +}; + +struct DaiData { + const char *drvDaiName; + /* DAI driver callbacks */ + int32_t (*DaiInit)(const struct AudioCard *, const struct DaiDevice *); + /* ops */ + const struct AudioDaiOps *ops; +}; + +/* Dai host is defined in dai driver */ +struct DaiHost { + struct IDeviceIoService service; + struct HdfDeviceObject *device; + void *priv; + bool daiInitFlag; +}; + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif diff --git a/include/audio/audio_dsp_if.h b/include/audio/audio_dsp_if.h new file mode 100755 index 000000000..ae72f096b --- /dev/null +++ b/include/audio/audio_dsp_if.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef AUDIO_DSP_IF_H +#define AUDIO_DSP_IF_H +#include "audio_host.h" +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +struct DspDevice { + const char *devDspName; + struct DspData *devData; + struct HdfDeviceObject *device; + struct DListHead list; +}; + +struct AudioDspOps { + int32_t (*Startup)(const struct AudioCard *, const struct DspDevice *); + int32_t (*HwParams)(const struct AudioCard *, const struct AudioPcmHwParams *, const struct DspDevice *); + int32_t (*Trigger)(struct AudioCard *, int, struct DspDevice *); +}; + +/* Dsp host is defined in dsp driver */ +struct DspHost { + struct IDeviceIoService service; // dsp service + struct HdfDeviceObject *device; // dsp device + void *priv; // dsp private data +}; + +struct DspData { + const char *drvDspName; + /* dsp driver callbacks */ + int32_t (*DspInit)(const struct DspDevice *device); + int32_t (*Read)(struct DspDevice *, uint8_t *, uint32_t); + int32_t (*Write)(struct DspDevice *, uint8_t *, uint32_t); + int32_t (*decode)(const struct AudioCard *, const uint8_t *, const struct DspDevice *); + int32_t (*encode)(const struct AudioCard *, const uint8_t *, const struct DspDevice *); + int32_t (*Equalizer)(const struct AudioCard *, const uint8_t *, const struct DspDevice *); +}; + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ +#endif diff --git a/include/audio/audio_platform_if.h b/include/audio/audio_platform_if.h new file mode 100755 index 000000000..6ac044d68 --- /dev/null +++ b/include/audio/audio_platform_if.h @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef AUDIO_PLATFORM_IF_H +#define AUDIO_PLATFORM_IF_H + +#include "audio_host.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#define I2S_IOCFG2_BASE1 0x0020 +#define I2S_IOCFG2_BASE2 0x0024 +#define I2S_IOCFG2_BASE3 0x0028 +#define I2S_IOCFG2_BASE4 0x002C +#define I2S_IOCFG2_BASE5 0x0030 + +#define I2S_IOCFG2_BASE1_VAL 0x663 +#define I2S_IOCFG2_BASE2_VAL 0x673 +#define I2S_IOCFG2_BASE3_VAL 0x573 +#define I2S_IOCFG2_BASE4_VAL 0x473 +#define I2S_IOCFG2_BASE5_VAL 0x433 + +#define I2S_IOCFG3_BASE1 0x44 +#define I2S_IOCFG3_BASE1_VAL 0x0600 + +#define GPIO_BASE1 0x2010 +#define GPIO_BASE2 0x2400 +#define GPIO_BASE3 0x2010 + +#define GPIO_BASE2_VAL 0x000000ff +#define GPIO_BASE3_VAL 0x00000000 + +#define IOCFG2_BASE_ADDR 0x112F0000 +#define IOCFG3_BASE_ADDR 0x10FF0000 +#define GPIO_BASE_ADDR 0x120D0000 +#define BASE_ADDR_REMAP_SIZE 0x10000 + +struct CircleBufInfo { + uint32_t cirBufSize; + uint32_t trafBufSize; + uint32_t period; + uint32_t periodSize; + uint32_t periodCount; + unsigned long phyAddr; + uint32_t *virtAddr; + uint32_t wbufOffSet; + uint32_t wptrOffSet; + uint32_t runStatus; + uint32_t chnId; + uint32_t enable; + struct OsalMutex buffMutex; + uint64_t framesPosition; +}; + +struct PcmInfo { + /* The number of channels in a frame */ + uint32_t channels; + /* The number of frames per second */ + uint32_t rate; + uint32_t bitWidth; + uint32_t frameSize; + bool isBigEndian; + bool isSignedData; + uint32_t startThreshold; + uint32_t stopThreshold; + uint32_t silenceThreshold; + uint32_t totalStreamSize; +}; + +/* platform related definitions */ +struct AudioPlatformOps { + int32_t (*HwParams)(const struct AudioCard *, const struct AudioPcmHwParams *); + int32_t (*RenderTrigger)(struct AudioCard *, int); + int32_t (*CaptureTrigger)(struct AudioCard *, int); + uint32_t (*Pointer)(struct AudioCard *); + int32_t (*Write)(const struct AudioCard *, struct AudioTxData *); + int32_t (*Read)(const struct AudioCard *, struct AudioRxData *); + int32_t (*MmapWrite)(const struct AudioCard *, struct AudioTxMmapData *); + int32_t (*MmapRead)(const struct AudioCard *, struct AudioRxMmapData *); + int32_t (*RenderPrepare)(const struct AudioCard *); + int32_t (*CapturePrepare)(const struct AudioCard *); + int32_t (*RenderStart)(struct AudioCard *); + int32_t (*CaptureStart)(struct AudioCard *); + int32_t (*RenderStop)(struct AudioCard *); + int32_t (*CaptureStop)(struct AudioCard *); + int32_t (*RenderPause)(struct AudioCard *); + int32_t (*CapturePause)(struct AudioCard *); + int32_t (*RenderResume)(struct AudioCard *); + int32_t (*CaptureResume)(struct AudioCard *); +}; + +struct PlatformDevice { + const char *devPlatformName; + struct PlatformData *devData; + struct HdfDeviceObject *device; + struct DListHead list; +}; + +struct PlatformData { + const char *drvPlatformName; + /* platform driver callbacks */ + int32_t (*PlatformInit)(const struct AudioCard *, const struct PlatformDevice *); + /* pcm creation and destruction */ + int32_t (*PcmNew)(struct PlatformDevice *); + void (*PcmFree)(struct PlatformDevice *); + /* platform stream ops */ + struct AudioPlatformOps *ops; +}; + +/* Platform host is defined in platform driver */ +struct PlatformHost { + struct IDeviceIoService service; + struct HdfDeviceObject *device; + void *priv; + bool platformInitFlag; + struct CircleBufInfo renderBufInfo; + struct CircleBufInfo captureBufInfo; + struct PcmInfo pcmInfo; +}; + +static inline struct PlatformHost *PlatformHostFromDevice(struct HdfDeviceObject *device) +{ + return (device == NULL) ? NULL : (struct PlatformHost *)device->service; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif -- Gitee