From e16896cba0dbf33f5efb6a62320d81ba3a15377e Mon Sep 17 00:00:00 2001 From: kevin Date: Tue, 29 Jun 2021 09:13:31 +0800 Subject: [PATCH 001/205] modify sensor model driver Signed-off-by: kevin Change-Id: I0f773de2029daabcfa61381eb1b787d3b096dcd2 --- .../sensor/driver/accel/sensor_accel_driver.c | 182 ++++++++++-------- .../sensor/driver/accel/sensor_accel_driver.h | 14 +- .../common/include/sensor_device_manager.h | 13 +- .../driver/common/src/sensor_device_manager.c | 96 ++++----- .../driver/common/src/sensor_platform_if.c | 53 ----- .../sensor/driver/include/sensor_device_if.h | 3 +- .../driver/include/sensor_platform_if.h | 7 +- test/unittest/sensor/hdf_sensor_test.c | 126 +++++++----- test/unittest/sensor/hdf_sensor_test.h | 9 +- 9 files changed, 258 insertions(+), 245 deletions(-) diff --git a/model/sensor/driver/accel/sensor_accel_driver.c b/model/sensor/driver/accel/sensor_accel_driver.c index 5da6ee566..ab62901fc 100644 --- a/model/sensor/driver/accel/sensor_accel_driver.c +++ b/model/sensor/driver/accel/sensor_accel_driver.c @@ -12,7 +12,6 @@ #include "hdf_device_desc.h" #include "osal_math.h" #include "osal_mem.h" -#include "osal_time.h" #include "sensor_accel_driver.h" #include "sensor_config_controller.h" #include "sensor_device_manager.h" @@ -20,20 +19,17 @@ #define HDF_LOG_TAG sensor_accel_driver_c +#define HDF_ACCEL_WORK_QUEUE_NAME "hdf_accel_work_queue" + static struct AccelDetectIfList g_accelDetectIfList[] = { {ACCEL_CHIP_NAME_BMI160, DetectAccelBim160Chip}, }; +static struct AccelDrvData *g_accelDrvData = NULL; + static struct AccelDrvData *AccelGetDrvData(void) { - static struct AccelDrvData accelDrvData = { - .threadStatus = SENSOR_THREAD_NONE, - .initStatus = false, - .detectFlag = false, - .interval = ACC_DEFAULT_SAMPLING_200_MS, - }; - - return &accelDrvData; + return g_accelDrvData; } static struct SensorRegCfgGroupNode *g_regCfgGroup[SENSOR_GROUP_MAX] = { NULL }; @@ -45,61 +41,62 @@ int32_t RegisterAccelChipOps(const struct AccelOpsCall *ops) CHECK_NULL_PTR_RETURN_VALUE(ops, HDF_ERR_INVALID_PARAM); drvData = AccelGetDrvData(); + CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); drvData->ops.Init = ops->Init; drvData->ops.ReadData = ops->ReadData; return HDF_SUCCESS; } -static int32_t ReadAccelDataThreadWorker(void *arg) +static void AccelDataWorkEntry(void *arg) { - (void)arg; - int64_t interval; - struct AccelDrvData *drvData = NULL; + int32_t ret; + struct AccelDrvData *drvData = (struct AccelDrvData *)arg; + CHECK_NULL_PTR_RETURN(drvData); + CHECK_NULL_PTR_RETURN(drvData->ops.ReadData); - drvData = AccelGetDrvData(); - drvData->threadStatus = SENSOR_THREAD_START; - while (true) { - if (drvData->threadStatus == SENSOR_THREAD_RUNNING) { - if (drvData->ops.ReadData != NULL) { - (void)drvData->ops.ReadData(drvData->accelCfg); - } + ret = drvData->ops.ReadData(drvData->accelCfg); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: accel read data failed", __func__); + return; + } +} - interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT)); - OsalMSleep(interval); - } else if (drvData->threadStatus == SENSOR_THREAD_STOPPING) { - drvData->threadStatus = SENSOR_THREAD_STOPPED; - break; - } else { - OsalMSleep(ACC_DEFAULT_SAMPLING_200_MS / SENSOR_CONVERT_UNIT / SENSOR_CONVERT_UNIT); - } +static void AccelTimerEntry(uintptr_t arg) +{ + int64_t interval; + int32_t ret; + struct AccelDrvData *drvData = (struct AccelDrvData *)arg; + CHECK_NULL_PTR_RETURN(drvData); - if ((!drvData->initStatus) || (drvData->interval < 0) || drvData->threadStatus != SENSOR_THREAD_RUNNING) { - continue; - } + if (!HdfAddWork(&drvData->accelWorkQueue, &drvData->accelWork)) { + HDF_LOGE("%s: accel add work queue failed", __func__); } - HDF_LOGD("%s: accel thread have exited", __func__); - return HDF_SUCCESS; + interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT)); + interval = (interval < SENSOR_TIMER_MIN_TIME) ? SENSOR_TIMER_MIN_TIME : interval; + ret = OsalTimerSetTimeout(&drvData->accelTimer, interval); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: accel modify time failed", __func__); + } } -static int32_t InitAccelConfig(void) +static int32_t InitAccelData(void) { struct AccelDrvData *drvData = AccelGetDrvData(); int32_t ret; + CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); if (drvData->initStatus) { return HDF_SUCCESS; } - if (drvData->threadStatus != SENSOR_THREAD_NONE && drvData->threadStatus != SENSOR_THREAD_DESTROY) { - HDF_LOGE("%s: accel thread have created", __func__); - return HDF_SUCCESS; + if (HdfWorkQueueInit(&drvData->accelWorkQueue, HDF_ACCEL_WORK_QUEUE_NAME) != HDF_SUCCESS) { + HDF_LOGE("%s: accel init work queue failed", __func__); + return HDF_FAILURE; } - ret = CreateSensorThread(&drvData->thread, ReadAccelDataThreadWorker, "hdf_sensor_accel", drvData); - if (ret != HDF_SUCCESS) { + if (HdfWorkInit(&drvData->accelWork, AccelDataWorkEntry, drvData) != HDF_SUCCESS) { HDF_LOGE("%s: accel create thread failed", __func__); - drvData->threadStatus = SENSOR_THREAD_STOPPING; return HDF_FAILURE; } @@ -108,17 +105,12 @@ static int32_t InitAccelConfig(void) ret = drvData->ops.Init(drvData->accelCfg); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: accel create thread failed", __func__); - drvData->threadStatus = SENSOR_THREAD_STOPPING; return HDF_FAILURE; } - drvData->initStatus = true; - return HDF_SUCCESS; -} - -static int32_t SetAccelInfo(struct SensorBasicInfo *info) -{ - (void)info; + drvData->interval = SENSOR_TIMER_MIN_TIME; + drvData->initStatus = true; + drvData->enable = false; return HDF_SUCCESS; } @@ -128,14 +120,32 @@ static int32_t SetAccelEnable(void) int32_t ret; struct AccelDrvData *drvData = AccelGetDrvData(); + CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); CHECK_NULL_PTR_RETURN_VALUE(drvData->accelCfg, HDF_ERR_INVALID_PARAM); + + if (drvData->enable) { + HDF_LOGE("%s: accel sensor is enabled", __func__); + return HDF_SUCCESS; + } + ret = SetSensorRegCfgArray(&drvData->accelCfg->busCfg, drvData->accelCfg->regCfgGroup[SENSOR_ENABLE_GROUP]); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: accel sensor enable config failed", __func__); - return HDF_FAILURE; + return ret; + } + + ret = OsalTimerCreate(&drvData->accelTimer, SENSOR_TIMER_MIN_TIME, AccelTimerEntry, (uintptr_t)drvData); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: accel create timer failed[%d]", __func__, ret); + return ret; } - drvData->threadStatus = SENSOR_THREAD_RUNNING; + ret = OsalTimerStartLoop(&drvData->accelTimer); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: accel start timer failed[%d]", __func__, ret); + return ret; + } + drvData->enable = true; return HDF_SUCCESS; } @@ -145,16 +155,26 @@ static int32_t SetAccelDisable(void) int32_t ret; struct AccelDrvData *drvData = AccelGetDrvData(); + CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); CHECK_NULL_PTR_RETURN_VALUE(drvData->accelCfg, HDF_ERR_INVALID_PARAM); + if (!drvData->enable) { + HDF_LOGE("%s: accel sensor had disable", __func__); + return HDF_SUCCESS; + } + ret = SetSensorRegCfgArray(&drvData->accelCfg->busCfg, drvData->accelCfg->regCfgGroup[SENSOR_DISABLE_GROUP]); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: accel sensor disable config failed", __func__); - return HDF_FAILURE; + return ret; } - drvData->threadStatus = SENSOR_THREAD_STOPPED; - + ret = OsalTimerDelete(&drvData->accelTimer); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: accel delete timer failed", __func__); + return ret; + } + drvData->enable = false; return HDF_SUCCESS; } @@ -165,6 +185,8 @@ static int32_t SetAccelBatch(int64_t samplingInterval, int64_t interval) struct AccelDrvData *drvData = NULL; drvData = AccelGetDrvData(); + CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); + drvData->interval = samplingInterval; return HDF_SUCCESS; @@ -196,12 +218,16 @@ int32_t BindAccelDriver(struct HdfDeviceObject *device) { CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM); - static struct IDeviceIoService service = { - .object = {0}, - .Dispatch = DispatchAccel, - }; - device->service = &service; + struct AccelDrvData *drvData = (struct AccelDrvData *)OsalMemCalloc(sizeof(*drvData)); + if (drvData == NULL) { + HDF_LOGE("%s: malloc accel drv data fail!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + drvData->ioService.Dispatch = DispatchAccel; + drvData->device = device; + device->service = &drvData->ioService; + g_accelDrvData = drvData; return HDF_SUCCESS; } @@ -209,7 +235,8 @@ static int32_t InitAccelOps(struct SensorDeviceInfo *deviceInfo) { struct AccelDrvData *drvData = AccelGetDrvData(); - deviceInfo->ops.GetInfo = SetAccelInfo; + CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); + deviceInfo->ops.Enable = SetAccelEnable; deviceInfo->ops.Disable = SetAccelDisable; deviceInfo->ops.SetBatch = SetAccelBatch; @@ -222,9 +249,6 @@ static int32_t InitAccelOps(struct SensorDeviceInfo *deviceInfo) return HDF_FAILURE; } - drvData->accelCfg->sensorInfo.sensorTypeId = SENSOR_TAG_ACCELEROMETER; - drvData->accelCfg->sensorInfo.sensorId = SENSOR_TAG_ACCELEROMETER; - return HDF_SUCCESS; } @@ -232,7 +256,7 @@ static int32_t InitAccelAfterConfig(void) { struct SensorDeviceInfo deviceInfo; - if (InitAccelConfig() != HDF_SUCCESS) { + if (InitAccelData() != HDF_SUCCESS) { HDF_LOGE("%s: init accel config failed", __func__); return HDF_FAILURE; } @@ -256,6 +280,8 @@ static int32_t DetectAccelChip(void) int32_t ret; int32_t loop; struct AccelDrvData *drvData = AccelGetDrvData(); + + CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); CHECK_NULL_PTR_RETURN_VALUE(drvData->accelCfg, HDF_ERR_INVALID_PARAM); num = sizeof(g_accelDetectIfList) / sizeof(g_accelDetectIfList[0]); @@ -264,30 +290,27 @@ static int32_t DetectAccelChip(void) ret = g_accelDetectIfList[loop].DetectChip(drvData->accelCfg); if (ret == HDF_SUCCESS) { drvData->detectFlag = true; - break; + return HDF_SUCCESS; } } } - if (loop == num) { - HDF_LOGE("%s: detect accel device failed", __func__); - drvData->detectFlag = false; - return HDF_FAILURE; - } - return HDF_SUCCESS; + HDF_LOGE("%s: detect accel device failed", __func__); + drvData->detectFlag = false; + return HDF_FAILURE; } int32_t InitAccelDriver(struct HdfDeviceObject *device) { - struct AccelDrvData *drvData = AccelGetDrvData(); + CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM); + struct AccelDrvData *drvData = (struct AccelDrvData *)device->service; + CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); if (drvData->detectFlag) { HDF_LOGE("%s: accel sensor have detected", __func__); return HDF_SUCCESS; } - CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM); - drvData->accelCfg = (struct SensorCfgData *)OsalMemCalloc(sizeof(*drvData->accelCfg)); if (drvData->accelCfg == NULL) { HDF_LOGE("%s: malloc sensor config data failed", __func__); @@ -322,8 +345,7 @@ int32_t InitAccelDriver(struct HdfDeviceObject *device) return HDF_SUCCESS; INIT_EXIT: - DestroySensorThread(&drvData->thread, &drvData->threadStatus); - (void)DeleteSensorDevice(SENSOR_TAG_ACCELEROMETER); + (void)DeleteSensorDevice(&drvData->accelCfg->sensorInfo); REG_CONFIG_EXIT: ReleaseSensorAllRegConfig(drvData->accelCfg); (void)ReleaseSensorBusHandle(&drvData->accelCfg->busCfg); @@ -339,12 +361,12 @@ BASE_CONFIG_EXIT: void ReleaseAccelDriver(struct HdfDeviceObject *device) { - (void)device; - struct AccelDrvData *drvData = NULL; + CHECK_NULL_PTR_RETURN(device); - drvData = AccelGetDrvData(); - (void)DestroySensorThread(&drvData->thread, &drvData->threadStatus); - (void)DeleteSensorDevice(SENSOR_TAG_ACCELEROMETER); + struct AccelDrvData *drvData = (struct AccelDrvData *)device->service; + CHECK_NULL_PTR_RETURN(drvData); + + (void)DeleteSensorDevice(&drvData->accelCfg->sensorInfo); drvData->detectFlag = false; if (drvData->accelCfg != NULL) { diff --git a/model/sensor/driver/accel/sensor_accel_driver.h b/model/sensor/driver/accel/sensor_accel_driver.h index c8f8bcaae..1dc95d990 100644 --- a/model/sensor/driver/accel/sensor_accel_driver.h +++ b/model/sensor/driver/accel/sensor_accel_driver.h @@ -9,7 +9,9 @@ #ifndef SENSOR_ACCEL_DRIVER_H #define SENSOR_ACCEL_DRIVER_H -#include "osal_thread.h" +#include "hdf_workqueue.h" +#include "osal_mutex.h" +#include "osal_timer.h" #include "sensor_config_parser.h" #include "sensor_platform_if.h" @@ -50,12 +52,16 @@ struct AccelOpsCall { }; struct AccelDrvData { + struct IDeviceIoService ioService; + struct HdfDeviceObject *device; + HdfWorkQueue accelWorkQueue; + HdfWork accelWork; + OsalTimer accelTimer; bool detectFlag; - uint8_t threadStatus; - uint8_t initStatus; + bool enable; + bool initStatus; int64_t interval; struct SensorCfgData *accelCfg; - struct OsalThread thread; struct AccelOpsCall ops; }; diff --git a/model/sensor/driver/common/include/sensor_device_manager.h b/model/sensor/driver/common/include/sensor_device_manager.h index ba37d2674..2237b12fe 100644 --- a/model/sensor/driver/common/include/sensor_device_manager.h +++ b/model/sensor/driver/common/include/sensor_device_manager.h @@ -9,21 +9,24 @@ #ifndef SENSOR_DEVICE_MANAGER_H #define SENSOR_DEVICE_MANAGER_H +#include "hdf_workqueue.h" #include "osal_mutex.h" #include "sensor_device_type.h" #include "sensor_device_if.h" +#define HDF_SENSOR_EVENT_QUEUE_NAME "hdf_sensor_event_queue" + enum SensorCmd { SENSOR_CMD_GET_INFO_LIST = 0, SENSOR_CMD_OPS = 1, SENSOR_CMD_END, }; enum SensorOpsCmd { - SENSOR_OPS_CMD_ENABLE = 1, - SENSOR_OPS_CMD_DISABLE = 2, - SENSOR_OPS_CMD_SET_BATCH = 3, - SENSOR_OPS_CMD_SET_MODE = 4, - SENSOR_OPS_CMD_SET_OPTION = 5, + SENSOR_OPS_CMD_ENABLE = 0, + SENSOR_OPS_CMD_DISABLE = 1, + SENSOR_OPS_CMD_SET_BATCH = 2, + SENSOR_OPS_CMD_SET_MODE = 3, + SENSOR_OPS_CMD_SET_OPTION = 4, SENSOR_OPS_CMD_BUTT, }; diff --git a/model/sensor/driver/common/src/sensor_device_manager.c b/model/sensor/driver/common/src/sensor_device_manager.c index 3ef8e7e09..0e8ab5b71 100644 --- a/model/sensor/driver/common/src/sensor_device_manager.c +++ b/model/sensor/driver/common/src/sensor_device_manager.c @@ -28,63 +28,63 @@ static struct SensorDevMgrData *GetSensorDeviceManager(void) int32_t AddSensorDevice(const struct SensorDeviceInfo *deviceInfo) { - bool existSensor = false; struct SensorDevInfoNode *pos = NULL; - struct SensorDevInfoNode *tmp = NULL; struct SensorDevInfoNode *devInfoNode = NULL; struct SensorDevMgrData *manager = GetSensorDeviceManager(); CHECK_NULL_PTR_RETURN_VALUE(deviceInfo, HDF_ERR_INVALID_PARAM); CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM); - (void)OsalMutexLock(&manager->mutex); - DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) { - if (deviceInfo->sensorInfo.sensorId == pos->devInfo.sensorInfo.sensorId) { - HDF_LOGE("%s: sensor chip[0x%x] had existed", __func__, deviceInfo->sensorInfo.sensorId); - existSensor = true; - break; + DLIST_FOR_EACH_ENTRY(pos, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) { + if ((deviceInfo->sensorInfo.sensorId == pos->devInfo.sensorInfo.sensorId) && + (strcmp(deviceInfo->sensorInfo.sensorName, pos->devInfo.sensorInfo.sensorName) == 0)) { + HDF_LOGE("%{public}s: sensor id[%{public}d] had existed", __func__, deviceInfo->sensorInfo.sensorId); + return HDF_FAILURE; } } - if (!existSensor) { - devInfoNode = (struct SensorDevInfoNode*)OsalMemCalloc(sizeof(*devInfoNode)); - if (devInfoNode == NULL) { - (void)OsalMutexUnlock(&manager->mutex); - return HDF_FAILURE; - } - if (memcpy_s(&devInfoNode->devInfo, sizeof(devInfoNode->devInfo), - (void *)deviceInfo, sizeof(*deviceInfo)) != EOK) { - HDF_LOGE("%s: copy sensor info failed", __func__); - OsalMemFree(devInfoNode); - (void)OsalMutexUnlock(&manager->mutex); - return HDF_FAILURE; - } - DListInsertTail(&devInfoNode->node, &manager->sensorDevInfoHead); - HDF_LOGI("%s: register sensor device name[%s] success", __func__, deviceInfo->sensorInfo.sensorName); + (void)OsalMutexLock(&manager->mutex); + devInfoNode = (struct SensorDevInfoNode*)OsalMemCalloc(sizeof(*devInfoNode)); + if (devInfoNode == NULL) { + (void)OsalMutexUnlock(&manager->mutex); + return HDF_FAILURE; + } + if (memcpy_s(&devInfoNode->devInfo, sizeof(devInfoNode->devInfo), + (void *)deviceInfo, sizeof(*deviceInfo)) != EOK) { + HDF_LOGE("%{public}s: copy sensor info failed", __func__); + OsalMemFree(devInfoNode); + (void)OsalMutexUnlock(&manager->mutex); + return HDF_FAILURE; } + DListInsertTail(&devInfoNode->node, &manager->sensorDevInfoHead); (void)OsalMutexUnlock(&manager->mutex); + HDF_LOGI("%{public}s: register sensor name[%{private}s] success", __func__, deviceInfo->sensorInfo.sensorName); return HDF_SUCCESS; } -int32_t DeleteSensorDevice(int32_t sensorId) +int32_t DeleteSensorDevice(const struct SensorBasicInfo *sensorBaseInfo) { struct SensorDevInfoNode *pos = NULL; struct SensorDevInfoNode *tmp = NULL; struct SensorDevMgrData *manager = GetSensorDeviceManager(); + CHECK_NULL_PTR_RETURN_VALUE(sensorBaseInfo, HDF_ERR_INVALID_PARAM); CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM); + (void)OsalMutexLock(&manager->mutex); DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) { - if (sensorId == pos->devInfo.sensorInfo.sensorId) { + if ((sensorBaseInfo->sensorId == pos->devInfo.sensorInfo.sensorId) && + (strcmp(sensorBaseInfo->sensorName, pos->devInfo.sensorInfo.sensorName) == 0)) { DListRemove(&pos->node); OsalMemFree(pos); - break; + (void)OsalMutexUnlock(&manager->mutex); + return HDF_SUCCESS; } } (void)OsalMutexUnlock(&manager->mutex); - - return HDF_SUCCESS; + HDF_LOGE("%{public}s: delete sensor id invalid para", __func__); + return HDF_FAILURE; } int32_t ReportSensorEvent(const struct SensorReportEvent *events) @@ -132,7 +132,6 @@ static int32_t GetAllSensorInfo(struct HdfSBuf *data, struct HdfSBuf *reply) { (void)data; struct SensorDevInfoNode *pos = NULL; - struct SensorDevInfoNode *tmp = NULL; struct SensorBasicInfo *sensorInfo = NULL; struct SensorDevMgrData *manager = GetSensorDeviceManager(); int32_t count = 0; @@ -140,14 +139,12 @@ static int32_t GetAllSensorInfo(struct HdfSBuf *data, struct HdfSBuf *reply) CHECK_NULL_PTR_RETURN_VALUE(reply, HDF_ERR_INVALID_PARAM); CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM); - DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) { + DLIST_FOR_EACH_ENTRY(pos, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) { sensorInfo = &(pos->devInfo.sensorInfo); if (!HdfSbufWriteBuffer(reply, sensorInfo, sizeof(*sensorInfo))) { - HDF_LOGE("%s: write sbuf failed", __func__); return HDF_FAILURE; } - pos->devInfo.ops.GetInfo(NULL); count++; if ((count + 1) * sizeof(*sensorInfo) > HDF_SENSOR_INFO_MAX_BUF) { @@ -240,25 +237,25 @@ static struct SensorCmdHandleList g_sensorCmdHandle[] = { static int32_t DispatchCmdHandle(struct SensorDeviceInfo *deviceInfo, struct HdfSBuf *data, struct HdfSBuf *reply) { - int32_t methodCmd; + int32_t opsCmd; int32_t loop; int32_t count; CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM); - if (!HdfSbufReadInt32(data, &methodCmd)) { - HDF_LOGE("%s: sbuf read methodCmd failed", __func__); + if (!HdfSbufReadInt32(data, &opsCmd)) { + HDF_LOGE("%s: sbuf read opsCmd failed", __func__); return HDF_FAILURE; } - if (methodCmd >= SENSOR_OPS_CMD_BUTT || methodCmd <= 0) { - HDF_LOGE("%s: invalid cmd = %d", __func__, methodCmd); + if ((opsCmd >= SENSOR_OPS_CMD_BUTT) || (opsCmd < SENSOR_OPS_CMD_ENABLE)) { + HDF_LOGE("%s: invalid cmd = %d", __func__, opsCmd); return HDF_FAILURE; } count = sizeof(g_sensorCmdHandle) / sizeof(g_sensorCmdHandle[0]); for (loop = 0; loop < count; ++loop) { - if ((methodCmd == g_sensorCmdHandle[loop].cmd) && (g_sensorCmdHandle[loop].func != NULL)) { + if ((opsCmd == g_sensorCmdHandle[loop].cmd) && (g_sensorCmdHandle[loop].func != NULL)) { return g_sensorCmdHandle[loop].func(deviceInfo, data, reply); } } @@ -272,29 +269,38 @@ static int32_t DispatchSensor(struct HdfDeviceIoClient *client, struct SensorDevMgrData *manager = GetSensorDeviceManager(); struct SensorDevInfoNode *pos = NULL; int32_t sensorId; - int32_t ret = HDF_FAILURE; + int32_t ret; CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM); CHECK_NULL_PTR_RETURN_VALUE(client, HDF_ERR_INVALID_PARAM); + if (cmd >= SENSOR_CMD_END) { + HDF_LOGE("%s: sensor cmd invalid para", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (cmd == SENSOR_CMD_GET_INFO_LIST) { return GetAllSensorInfo(data, reply); } (void)OsalMutexLock(&manager->mutex); + if (!HdfSbufReadInt32(data, &sensorId)) { + HDF_LOGE("%s: sbuf read sensorId failed", __func__); + (void)OsalMutexUnlock(&manager->mutex); + return HDF_ERR_INVALID_PARAM; + } + DLIST_FOR_EACH_ENTRY(pos, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) { - if (!HdfSbufReadInt32(data, &sensorId)) { - HDF_LOGE("%s: sbuf read sensorId failed", __func__); - continue; - } if (sensorId == pos->devInfo.sensorInfo.sensorId) { ret = DispatchCmdHandle(&pos->devInfo, data, reply); - break; + (void)OsalMutexUnlock(&manager->mutex); + return ret; } } (void)OsalMutexUnlock(&manager->mutex); - return ret; + HDF_LOGE("%s: not find sensor[%d] handle function", __func__, sensorId); + return HDF_FAILURE; } int32_t BindSensorDevManager(struct HdfDeviceObject *device) diff --git a/model/sensor/driver/common/src/sensor_platform_if.c b/model/sensor/driver/common/src/sensor_platform_if.c index 8716ee83a..fe7e81f6d 100644 --- a/model/sensor/driver/common/src/sensor_platform_if.c +++ b/model/sensor/driver/common/src/sensor_platform_if.c @@ -8,7 +8,6 @@ #include "securec.h" #include "osal_io.h" -#include "osal_thread.h" #include "osal_time.h" #include "sensor_platform_if.h" @@ -119,55 +118,3 @@ int32_t SetSensorPinMux(uint32_t regAddr, int32_t regSize, uint32_t regValue) return HDF_SUCCESS; } - -int32_t CreateSensorThread(struct OsalThread *thread, OsalThreadEntry threadEntry, char *name, void *entryPara) -{ - struct OsalThreadParam config = { - .name = name, - .priority = OSAL_THREAD_PRI_DEFAULT, - .stackSize = SENSOR_STACK_SIZE, - }; - - CHECK_NULL_PTR_RETURN_VALUE(thread, HDF_ERR_INVALID_PARAM); - CHECK_NULL_PTR_RETURN_VALUE(threadEntry, HDF_ERR_INVALID_PARAM); - CHECK_NULL_PTR_RETURN_VALUE(name, HDF_ERR_INVALID_PARAM); - CHECK_NULL_PTR_RETURN_VALUE(entryPara, HDF_ERR_INVALID_PARAM); - - int32_t status = OsalThreadCreate(thread, threadEntry, entryPara); - if (status != HDF_SUCCESS) { - HDF_LOGE("%s: sensor create thread failed!status=%d", __func__, status); - return HDF_FAILURE; - } - - status = OsalThreadStart(thread, &config); - if (status != HDF_SUCCESS) { - HDF_LOGE("%s: sensor start thread failed!status=%d", __func__, status); - OsalThreadDestroy(thread); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -void DestroySensorThread(struct OsalThread *thread, uint8_t *status) -{ - int count = 0; - CHECK_NULL_PTR_RETURN(thread); - CHECK_NULL_PTR_RETURN(status); - - if (*status == SENSOR_THREAD_NONE || *status == SENSOR_THREAD_DESTROY) { - HDF_LOGE("%s,delete thread not need!", __func__); - return; - } - - if (*status != SENSOR_THREAD_STOPPED) { - *status = SENSOR_THREAD_STOPPING; - /* wait until thread worker exit */ - while ((*status != SENSOR_THREAD_STOPPED) && (count < MAX_SENSOR_EXIT_THREAD_COUNT)) { - OsalMSleep(MAX_SENSOR_WAIT_THREAD_TIME); - count++; - } - } - - OsalThreadDestroy(thread); - *status = SENSOR_THREAD_DESTROY; -} \ No newline at end of file diff --git a/model/sensor/driver/include/sensor_device_if.h b/model/sensor/driver/include/sensor_device_if.h index 6d437f621..c3315fdc7 100644 --- a/model/sensor/driver/include/sensor_device_if.h +++ b/model/sensor/driver/include/sensor_device_if.h @@ -12,7 +12,6 @@ #include "sensor_device_type.h" struct SensorOps { - int32_t (*GetInfo)(struct SensorBasicInfo *sensorInfo); int32_t (*Enable)(void); int32_t (*Disable)(void); int32_t (*SetBatch)(int64_t samplingInterval, int64_t reportInterval); @@ -26,7 +25,7 @@ struct SensorDeviceInfo { }; int32_t AddSensorDevice(const struct SensorDeviceInfo *deviceInfo); -int32_t DeleteSensorDevice(int32_t sensorId); +int32_t DeleteSensorDevice(const struct SensorBasicInfo *sensorBaseInfo); int32_t ReportSensorEvent(const struct SensorReportEvent *events); #endif /* SENSOR_DEVICE_IF_H */ diff --git a/model/sensor/driver/include/sensor_platform_if.h b/model/sensor/driver/include/sensor_platform_if.h index cc49aca45..bc91bf731 100644 --- a/model/sensor/driver/include/sensor_platform_if.h +++ b/model/sensor/driver/include/sensor_platform_if.h @@ -40,15 +40,14 @@ #define SENSOR_ADDR_WIDTH_1_BYTE 1 // 8 bit #define SENSOR_ADDR_WIDTH_2_BYTE 2 // 16 bit -#define SENSOR_ADDR_WIDTH_4_BYTE 4 // 32 bit +#define SENSOR_ADDR_WIDTH_4_BYTE 4 // 16 bit #define SENSOR_DATA_WIDTH_8_BIT 8 // 8 bit #define SENSOR_CONVERT_UNIT 1000 #define SENSOR_1K_UNIT 1024 #define SENSOR_SPI_MAX_SPEED 115200 #define SENSOR_SECOND_CONVERT_NANOSECOND (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT) -#define MAX_SENSOR_EXIT_THREAD_COUNT 10 -#define MAX_SENSOR_WAIT_THREAD_TIME 100 // 100MS +#define SENSOR_TIMER_MIN_TIME 20 enum SensorBusType { SENSOR_BUS_I2C = 0, @@ -96,7 +95,5 @@ enum SENSORConfigValueIndex { int32_t ReadSensor(struct SensorBusCfg *busCfg, uint16_t regAddr, uint8_t *data, uint16_t dataLen); int32_t WriteSensor(struct SensorBusCfg *busCfg, uint8_t *writeData, uint16_t len); int32_t SetSensorPinMux(uint32_t regAddr, int32_t regSize, uint32_t regValue); -int32_t CreateSensorThread(struct OsalThread *thread, OsalThreadEntry threadEntry, char *name, void *entryPara); -void DestroySensorThread(struct OsalThread *thread, uint8_t *status); #endif /* SENSOR_PLATFORM_IF_H */ \ No newline at end of file diff --git a/test/unittest/sensor/hdf_sensor_test.c b/test/unittest/sensor/hdf_sensor_test.c index 5ff416e8f..343da2329 100644 --- a/test/unittest/sensor/hdf_sensor_test.c +++ b/test/unittest/sensor/hdf_sensor_test.c @@ -12,7 +12,6 @@ #include "hdf_sensor_test.h" #include "osal_math.h" #include "osal_time.h" -#include "osal_timer.h" #include "sensor_platform_if.h" #include "sensor_device_manager.h" #include "sensor_device_type.h" @@ -22,18 +21,19 @@ #define HDF_SENSOR_TEST_VALUE 1024000000 // 1g = 9.8m/s^2 #define SENSOR_TEST_MAX_RANGE 8 #define SENSOR_TEST_MAX_POWER 230 +#define HDF_SENSOR_TEST_WORK_QUEUE_NAME "hdf_sensor_test_work_queue" static struct SensorTestDrvData *GetSensorTestDrvData(void) { static struct SensorTestDrvData sensorTestDrvData = { - .threadStatus = SENSOR_THREAD_NONE, + .enable = false, .initStatus = false, .interval = SENSOR_TEST_SAMPLING_200_MS, }; return &sensorTestDrvData; } -static void SensorReadTestData(void) +static void SensorTestDataWorkEntry(void *arg) { int32_t value = HDF_SENSOR_TEST_VALUE; struct SensorReportEvent event; @@ -52,75 +52,89 @@ static void SensorReadTestData(void) ReportSensorEvent(&event); } -static int32_t SensorReadDataThreadTestWorker(void *arg) +static void SensorTestTimerEntry(uintptr_t arg) { - (void)arg; int64_t interval; - CHECK_NULL_PTR_RETURN_VALUE(arg, HDF_ERR_INVALID_PARAM); - struct SensorTestDrvData *drvData = GetSensorTestDrvData(); - - drvData->threadStatus = SENSOR_THREAD_START; - while (true) { - if (drvData->threadStatus == SENSOR_THREAD_RUNNING) { - SensorReadTestData(); - interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT)); - OsalMSleep(interval); - } else if (drvData->threadStatus == SENSOR_THREAD_STOPPING) { - drvData->threadStatus = SENSOR_THREAD_STOPPED; - break; - } else { - OsalMSleep(SENSOR_TEST_SAMPLING_200_MS / SENSOR_CONVERT_UNIT / SENSOR_CONVERT_UNIT); - } + struct SensorTestDrvData *drvData = (struct SensorTestDrvData *)arg; + CHECK_NULL_PTR_RETURN(drvData); - if ((!drvData->initStatus) || (drvData->interval < 0) || drvData->threadStatus != SENSOR_THREAD_RUNNING) { - continue; - } + if (!HdfAddWork(&drvData->workQueue, &drvData->work)) { + HDF_LOGE("%s: sensor test add work queue failed", __func__); } - HDF_LOGE("%s: Sensor test thread have exited", __func__); - return HDF_SUCCESS; + interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT)); + interval = (interval < SENSOR_TIMER_MIN_TIME) ? SENSOR_TIMER_MIN_TIME : interval; + + if (OsalTimerSetTimeout(&drvData->timer, interval) != HDF_SUCCESS) { + HDF_LOGE("%s: sensor test modify time failed", __func__); + } } static int32_t SensorInitTestConfig(void) { struct SensorTestDrvData *drvData = GetSensorTestDrvData(); - if (drvData->threadStatus != SENSOR_THREAD_NONE && drvData->threadStatus != SENSOR_THREAD_DESTROY) { - HDF_LOGE("%s: Sensor test thread have created", __func__); - return HDF_SUCCESS; + if (HdfWorkQueueInit(&drvData->workQueue, HDF_SENSOR_TEST_WORK_QUEUE_NAME) != HDF_SUCCESS) { + HDF_LOGE("%s: sensor test init work queue failed", __func__); + return HDF_FAILURE; } - int32_t ret = CreateSensorThread(&drvData->thread, SensorReadDataThreadTestWorker, "hdf_sensor_test", drvData); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: Sensor test create thread failed", __func__); - drvData->threadStatus = SENSOR_THREAD_NONE; + if (HdfWorkInit(&drvData->work, SensorTestDataWorkEntry, drvData) != HDF_SUCCESS) { + HDF_LOGE("%s: sensor test create thread failed", __func__); return HDF_FAILURE; } - drvData->initStatus = true; - - return HDF_SUCCESS; -} -static int32_t SensorGetInfoTest(struct SensorBasicInfo *info) -{ - (void)info; + drvData->enable = false; + drvData->initStatus = true; return HDF_SUCCESS; } static int32_t SensorEnableTest(void) { + int32_t ret; struct SensorTestDrvData *drvData = GetSensorTestDrvData(); - drvData->threadStatus = SENSOR_THREAD_RUNNING; + if (drvData->enable) { + HDF_LOGE("%{public}s: sensor test had enable", __func__); + return HDF_SUCCESS; + } + + ret = OsalTimerCreate(&drvData->timer, SENSOR_TIMER_MIN_TIME, SensorTestTimerEntry, (uintptr_t)drvData); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: sensor test create timer failed[%{public}d]", __func__, ret); + return ret; + } + + ret = OsalTimerStartLoop(&drvData->timer); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: sensor test start timer failed[%{public}d]", __func__, ret); + return ret; + } + drvData->enable = true; + return HDF_SUCCESS; } static int32_t SensorDisableTest(void) { + int32_t ret; struct SensorTestDrvData *drvData = GetSensorTestDrvData(); - drvData->threadStatus = SENSOR_THREAD_STOPPED; + if (!drvData->enable) { + HDF_LOGE("%s: sensor test had disable", __func__); + return HDF_SUCCESS; + } + + if (drvData->timer.realTimer != NULL) { + ret = OsalTimerDelete(&drvData->timer); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: sensor test delete timer failed", __func__); + return ret; + } + } + + drvData->enable = false; return HDF_SUCCESS; } @@ -172,7 +186,6 @@ int32_t InitSensorDriverTest(struct HdfDeviceObject *device) { int32_t ret; (void)device; - struct SensorTestDrvData *drvData = GetSensorTestDrvData(); struct SensorDeviceInfo deviceInfo = { .sensorInfo = { @@ -187,7 +200,6 @@ int32_t InitSensorDriverTest(struct HdfDeviceObject *device) .power = SENSOR_TEST_MAX_POWER, }, .ops = { - .GetInfo = SensorGetInfoTest, .Enable = SensorEnableTest, .Disable = SensorDisableTest, .SetBatch = SensorSetBatchTest, @@ -199,14 +211,13 @@ int32_t InitSensorDriverTest(struct HdfDeviceObject *device) ret = SensorInitTestConfig(); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: sensor test config failed", __func__); - return HDF_FAILURE; + return ret; } ret = AddSensorDevice(&deviceInfo); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: sensor test register failed", __func__); - (void)DestroySensorThread(&drvData->thread, &drvData->threadStatus); - return HDF_FAILURE; + return ret; } HDF_LOGI("%s: init sensor test driver success", __func__); @@ -216,10 +227,29 @@ int32_t InitSensorDriverTest(struct HdfDeviceObject *device) void ReleaseSensorDriverTest(struct HdfDeviceObject *device) { (void)device; + int32_t ret; struct SensorTestDrvData *drvData = GetSensorTestDrvData(); + struct SensorDeviceInfo deviceInfo = { + .sensorInfo = { + .sensorName = "sensor_test", + .vendorName = "default", + .firmwareVersion = "1.0", + .hardwareVersion = "1.0", + .sensorTypeId = SENSOR_TAG_NONE, + .sensorId = SENSOR_TAG_NONE, + .maxRange = SENSOR_TEST_MAX_RANGE, + .accuracy = 1, + .power = SENSOR_TEST_MAX_POWER, + } + }; + (void)DeleteSensorDevice(&deviceInfo.sensorInfo); - (void)DestroySensorThread(&drvData->thread, &drvData->threadStatus); - (void)DeleteSensorDevice(SENSOR_TAG_NONE); + if (drvData->timer.realTimer != NULL) { + ret = OsalTimerDelete(&drvData->timer); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: sensor test delete timer failed", __func__); + } + } } struct HdfDriverEntry g_sensorTestDevEntry = { diff --git a/test/unittest/sensor/hdf_sensor_test.h b/test/unittest/sensor/hdf_sensor_test.h index b4b598d8e..fc443464e 100644 --- a/test/unittest/sensor/hdf_sensor_test.h +++ b/test/unittest/sensor/hdf_sensor_test.h @@ -9,15 +9,18 @@ #ifndef HDF_SENSOR_DRIVER_TEST_H #define HDF_SENSOR_DRIVER_TEST_H -#include "osal_thread.h" +#include "hdf_workqueue.h" +#include "osal_timer.h" #define SENSOR_TEST_SAMPLING_200_MS 200000000 struct SensorTestDrvData { - uint8_t threadStatus; uint8_t initStatus; int64_t interval; - struct OsalThread thread; + HdfWorkQueue workQueue; + HdfWork work; + OsalTimer timer; + bool enable; }; #endif // HDF_SENSOR_DRIVER_TEST_H \ No newline at end of file -- Gitee From f44b3136524ca4a167af4938f6469bcf55ba7d32 Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 30 Jun 2021 17:35:22 +0800 Subject: [PATCH 002/205] delete sensor log public Signed-off-by: kevin Change-Id: I32040a24cc83d822dbcb88cb92408f13221153f9 --- model/misc/vibrator/driver/src/vibrator_driver.c | 2 +- model/misc/vibrator/driver/src/vibrator_haptic.c | 14 +++++++------- .../driver/common/src/sensor_device_manager.c | 8 ++++---- test/unittest/sensor/hdf_sensor_test.c | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/model/misc/vibrator/driver/src/vibrator_driver.c b/model/misc/vibrator/driver/src/vibrator_driver.c index dc78c3529..9d47a1be9 100644 --- a/model/misc/vibrator/driver/src/vibrator_driver.c +++ b/model/misc/vibrator/driver/src/vibrator_driver.c @@ -96,7 +96,7 @@ static void VibratorWorkEntry(void *para) } if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: add vibrator work fail! device state[%d{public}]!", __func__, drvData->state); + HDF_LOGE("%s: add vibrator work fail! device state[%d]!", __func__, drvData->state); } } diff --git a/model/misc/vibrator/driver/src/vibrator_haptic.c b/model/misc/vibrator/driver/src/vibrator_haptic.c index c86dba083..740162196 100644 --- a/model/misc/vibrator/driver/src/vibrator_haptic.c +++ b/model/misc/vibrator/driver/src/vibrator_haptic.c @@ -171,7 +171,7 @@ static uint32_t ProcessHapticEffect(struct VibratorHapticData *hapticData) CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE); if ((hapticData->currentSeqIndex < 0) || ((hapticData->currentSeqIndex + 1) >= hapticData->seqCount)) { - HDF_LOGE("%{public}s: seq index invalid para", __func__); + HDF_LOGE("%{s: seq index invalid para", __func__); return 0; } @@ -181,7 +181,7 @@ static uint32_t ProcessHapticEffect(struct VibratorHapticData *hapticData) hapticData->currentSeqIndex++; if (hapticData->currentSeqIndex >= hapticData->seqCount) { - HDF_LOGE("%{public}s: seq index exceed max value", __func__); + HDF_LOGE("%s: seq index exceed max value", __func__); return 0; } @@ -201,24 +201,24 @@ void HapticTimerEntry(uintptr_t para) if (hapticData->effectType == VIBRATOR_TYPE_TIME) { duration = ProcessHapticTime(hapticData); - HDF_LOGE("%{public}s:ProcessHapticTime duration[%{public}d]", __func__, duration); + HDF_LOGE("%s:ProcessHapticTime duration[%d]", __func__, duration); } if (hapticData->effectType == VIBRATOR_TYPE_EFFECT) { duration = ProcessHapticEffect(hapticData); - HDF_LOGE("%{public}s:ProcessHapticEffect duration[%{public}d]", __func__, duration); + HDF_LOGE("%s:ProcessHapticEffect duration[%d]", __func__, duration); } duration = ((duration > 0) && (duration < VIBRATOR_MIN_WAIT_TIME)) ? VIBRATOR_MIN_WAIT_TIME : duration; if ((duration > 0) && (OsalTimerSetTimeout(&hapticData->timer, duration) == HDF_SUCCESS)) { - HDF_LOGD("%{public}s: modify haptic timer duration[%{public}d]", __func__, duration); + HDF_LOGD("%s: modify haptic timer duration[%d]", __func__, duration); return; } if (hapticData->timer.realTimer != NULL) { ret = OsalTimerDelete(&hapticData->timer); if (ret != HDF_SUCCESS) { - HDF_LOGE("%{public}s: delete haptic timer fail!", __func__); + HDF_LOGE("%s: delete haptic timer fail!", __func__); } } @@ -281,7 +281,7 @@ int32_t StartHaptic(struct VibratorEffectCfg *effectCfg) CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE); if ((effectCfg->cfgMode == VIBRATOR_MODE_PRESET) && (!hapticData->supportHaptic)) { - HDF_LOGE("%{public}s: vibrator no support haptic!", __func__); + HDF_LOGE("%s: vibrator no support haptic!", __func__); return HDF_ERR_NOT_SUPPORT; } diff --git a/model/sensor/driver/common/src/sensor_device_manager.c b/model/sensor/driver/common/src/sensor_device_manager.c index 0e8ab5b71..45d6c7b75 100644 --- a/model/sensor/driver/common/src/sensor_device_manager.c +++ b/model/sensor/driver/common/src/sensor_device_manager.c @@ -38,7 +38,7 @@ int32_t AddSensorDevice(const struct SensorDeviceInfo *deviceInfo) DLIST_FOR_EACH_ENTRY(pos, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) { if ((deviceInfo->sensorInfo.sensorId == pos->devInfo.sensorInfo.sensorId) && (strcmp(deviceInfo->sensorInfo.sensorName, pos->devInfo.sensorInfo.sensorName) == 0)) { - HDF_LOGE("%{public}s: sensor id[%{public}d] had existed", __func__, deviceInfo->sensorInfo.sensorId); + HDF_LOGE("%s: sensor id[%d] had existed", __func__, deviceInfo->sensorInfo.sensorId); return HDF_FAILURE; } } @@ -51,14 +51,14 @@ int32_t AddSensorDevice(const struct SensorDeviceInfo *deviceInfo) } if (memcpy_s(&devInfoNode->devInfo, sizeof(devInfoNode->devInfo), (void *)deviceInfo, sizeof(*deviceInfo)) != EOK) { - HDF_LOGE("%{public}s: copy sensor info failed", __func__); + HDF_LOGE("%s: copy sensor info failed", __func__); OsalMemFree(devInfoNode); (void)OsalMutexUnlock(&manager->mutex); return HDF_FAILURE; } DListInsertTail(&devInfoNode->node, &manager->sensorDevInfoHead); (void)OsalMutexUnlock(&manager->mutex); - HDF_LOGI("%{public}s: register sensor name[%{private}s] success", __func__, deviceInfo->sensorInfo.sensorName); + HDF_LOGI("%s: register sensor name[%s] success", __func__, deviceInfo->sensorInfo.sensorName); return HDF_SUCCESS; } @@ -83,7 +83,7 @@ int32_t DeleteSensorDevice(const struct SensorBasicInfo *sensorBaseInfo) } } (void)OsalMutexUnlock(&manager->mutex); - HDF_LOGE("%{public}s: delete sensor id invalid para", __func__); + HDF_LOGE("%s: delete sensor id invalid para", __func__); return HDF_FAILURE; } diff --git a/test/unittest/sensor/hdf_sensor_test.c b/test/unittest/sensor/hdf_sensor_test.c index 343da2329..ce89c9eb3 100644 --- a/test/unittest/sensor/hdf_sensor_test.c +++ b/test/unittest/sensor/hdf_sensor_test.c @@ -96,19 +96,19 @@ static int32_t SensorEnableTest(void) struct SensorTestDrvData *drvData = GetSensorTestDrvData(); if (drvData->enable) { - HDF_LOGE("%{public}s: sensor test had enable", __func__); + HDF_LOGE("%s: sensor test had enable", __func__); return HDF_SUCCESS; } ret = OsalTimerCreate(&drvData->timer, SENSOR_TIMER_MIN_TIME, SensorTestTimerEntry, (uintptr_t)drvData); if (ret != HDF_SUCCESS) { - HDF_LOGE("%{public}s: sensor test create timer failed[%{public}d]", __func__, ret); + HDF_LOGE("%s: sensor test create timer failed[%d]", __func__, ret); return ret; } ret = OsalTimerStartLoop(&drvData->timer); if (ret != HDF_SUCCESS) { - HDF_LOGE("%{public}s: sensor test start timer failed[%{public}d]", __func__, ret); + HDF_LOGE("%s: sensor test start timer failed[%d]", __func__, ret); return ret; } drvData->enable = true; -- Gitee From f335efb6c98957242c59ebf75ec6c6cac57fac4e Mon Sep 17 00:00:00 2001 From: yuanbo Date: Wed, 30 Jun 2021 15:19:48 +0800 Subject: [PATCH 003/205] fix DeviceNode release interface not called issue Signed-off-by: yuanbo --- core/host/src/devhost_service.c | 22 ++++++++++------------ core/host/src/hdf_device.c | 2 +- core/host/src/hdf_device_node.c | 12 +++--------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/core/host/src/devhost_service.c b/core/host/src/devhost_service.c index 15ebde7a0..48814c6f6 100644 --- a/core/host/src/devhost_service.c +++ b/core/host/src/devhost_service.c @@ -17,15 +17,15 @@ #define HDF_LOG_TAG devhost_service -static struct HdfDevice *DevHostServiceFindDevice(struct DevHostService *inst, uint16_t deviceId) +static struct HdfDevice *DevHostServiceFindDevice(struct DevHostService *hostService, uint16_t deviceId) { struct HdfDevice *deviceNode = NULL; - if (inst == NULL) { - HDF_LOGE("failed to find driver, inst is null"); + if (hostService == NULL) { + HDF_LOGE("failed to find driver, hostService is null"); return NULL; } - DLIST_FOR_EACH_ENTRY(deviceNode, &inst->devices, struct HdfDevice, node) { + DLIST_FOR_EACH_ENTRY(deviceNode, &hostService->devices, struct HdfDevice, node) { if (deviceNode->deviceId == deviceId) { return deviceNode; } @@ -33,12 +33,12 @@ static struct HdfDevice *DevHostServiceFindDevice(struct DevHostService *inst, u return NULL; } -static void DevHostServiceFreeDevice(struct DevHostService *inst, uint16_t deviceId) +static void DevHostServiceFreeDevice(struct DevHostService *hostService, uint16_t deviceId) { - struct HdfDevice *deviceNode = DevHostServiceFindDevice(inst, deviceId); - if (deviceNode != NULL) { - DListRemove(&deviceNode->node); - HdfDeviceFreeInstance(deviceNode); + struct HdfDevice *device = DevHostServiceFindDevice(hostService, deviceId); + if (device != NULL) { + DListRemove(&device->node); + HdfDeviceFreeInstance(device); } } @@ -90,9 +90,7 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice return HDF_SUCCESS; error: - if (DListIsEmpty(&hostService->devices)) { - DevHostServiceFreeDevice(hostService, hostService->hostId); - } + DevHostServiceFreeDevice(hostService, device->deviceId); return ret; } diff --git a/core/host/src/hdf_device.c b/core/host/src/hdf_device.c index 3fc557001..af7a6e810 100644 --- a/core/host/src/hdf_device.c +++ b/core/host/src/hdf_device.c @@ -68,7 +68,7 @@ struct HdfDevice *HdfDeviceNewInstance() void HdfDeviceFreeInstance(struct HdfDevice *device) { if (device != NULL) { - HdfObjectManagerFreeObject((struct HdfObject *)device); + HdfObjectManagerFreeObject(&device->super.object); } } diff --git a/core/host/src/hdf_device_node.c b/core/host/src/hdf_device_node.c index 793da0d6a..c76398b26 100644 --- a/core/host/src/hdf_device_node.c +++ b/core/host/src/hdf_device_node.c @@ -86,24 +86,15 @@ int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devIns } int ret = driverEntry->Init(&devNode->deviceObject); if (ret != HDF_SUCCESS) { - if (driverEntry->Release != NULL) { - driverEntry->Release(&devNode->deviceObject); - } return HDF_DEV_ERR_DEV_INIT_FAIL; } ret = HdfDeviceNodePublishService(devNode, deviceInfo, devInst); if (ret != HDF_SUCCESS) { - if (driverEntry->Release != NULL) { - driverEntry->Release(&devNode->deviceObject); - } return HDF_DEV_ERR_PUBLISH_FAIL; } deviceToken = devNode->token; ret = DevmgrServiceClntAttachDevice(deviceInfo, deviceToken); if (ret != HDF_SUCCESS) { - if (driverEntry->Release != NULL) { - driverEntry->Release(&devNode->deviceObject); - } return HDF_DEV_ERR_ATTACHDEV_FAIL; } return ret; @@ -186,6 +177,9 @@ void HdfDeviceNodeDelete(struct HdfSListNode *deviceEntry) } struct HdfDeviceNode *devNode = HDF_SLIST_CONTAINER_OF(struct HdfSListNode, deviceEntry, struct HdfDeviceNode, entry); + if (devNode->driverEntry->Release != NULL) { + devNode->driverEntry->Release(&devNode->deviceObject); + } HdfDeviceNodeFreeInstance(devNode); } -- Gitee From af4918afb57f6bbd0ccee77fdec8daf53915e767 Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 2 Jul 2021 11:21:48 +0800 Subject: [PATCH 004/205] modify vibrator debug infor Signed-off-by: kevin Change-Id: I3163af82b6c5a5639abb83ff55a1a6b8e2221c37 --- model/misc/vibrator/driver/src/vibrator_haptic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/misc/vibrator/driver/src/vibrator_haptic.c b/model/misc/vibrator/driver/src/vibrator_haptic.c index 740162196..39eacb6f3 100644 --- a/model/misc/vibrator/driver/src/vibrator_haptic.c +++ b/model/misc/vibrator/driver/src/vibrator_haptic.c @@ -171,7 +171,7 @@ static uint32_t ProcessHapticEffect(struct VibratorHapticData *hapticData) CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE); if ((hapticData->currentSeqIndex < 0) || ((hapticData->currentSeqIndex + 1) >= hapticData->seqCount)) { - HDF_LOGE("%{s: seq index invalid para", __func__); + HDF_LOGE("%s: seq index invalid para", __func__); return 0; } -- Gitee From 55d6ca11a7b304124da1144dc1264c0509b9b276 Mon Sep 17 00:00:00 2001 From: huangkai71 Date: Wed, 7 Jul 2021 02:52:15 +0000 Subject: [PATCH 005/205] update code from STD Signed-off-by: huangkai71 --- model/input/driver/hdf_hid_adapter.c | 115 +++++++++++++++++- model/input/driver/hdf_input_device_manager.c | 10 +- model/input/driver/hdf_input_device_manager.h | 2 +- model/input/driver/hdf_touch.c | 11 +- model/input/driver/touchscreen/touch_gt911.c | 21 ++++ 5 files changed, 143 insertions(+), 16 deletions(-) diff --git a/model/input/driver/hdf_hid_adapter.c b/model/input/driver/hdf_hid_adapter.c index c11238b68..47496b8a6 100644 --- a/model/input/driver/hdf_hid_adapter.c +++ b/model/input/driver/hdf_hid_adapter.c @@ -203,14 +203,127 @@ static int32_t HdfHIDDriverInit(struct HdfDeviceObject *device) return HDF_SUCCESS; } +static int32_t HidGetDevType(InputDevice *inputDev, struct HdfSBuf *reply) +{ + uint32_t devType = inputDev->devType; + HDF_LOGI("%s: enter, devType is %u", __func__, devType); + bool ret = HdfSbufWriteUint32(reply, devType); + if (!ret) { + HDF_LOGE("%s: HdfSbufWriteUint32 failed", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t HidGetDeviceStrInfo(InputDevice *inputDev, int32_t cmd, struct HdfSBuf *reply) +{ + const char *info = NULL; + if (inputDev == NULL) { + HDF_LOGE("%s: parameter invalid", __func__); + return HDF_ERR_INVALID_PARAM; + } + + switch (cmd) { + case GET_CHIP_NAME: + info = "null"; + break; + case GET_VENDOR_NAME: + info = "null"; + break; + case GET_CHIP_INFO: + info = "null"; + break; + default: + info = NULL; + break; + } + + bool ret = HdfSbufWriteString(reply, info); + if (!ret) { + HDF_LOGE("%s: HdfSbufWriteUint32 failed", __func__); + return HDF_FAILURE; + } + HDF_LOGI("%s: cmd is %d, the info is %s", __func__, cmd, info); + return HDF_SUCCESS; +} + +static int32_t HidGetDeviceAttr(InputDevice *inputDev, struct HdfSBuf *reply) +{ + int32_t ret; + if (inputDev == NULL) { + return HDF_FAILURE; + } + + HDF_LOGE("%s: enter", __func__); + ret = strncpy_s(inputDev->attrSet.devName, DEV_NAME_LEN, inputDev->devName, strlen(inputDev->devName)); + if (ret) { + HDF_LOGE("%s: copy name from inputDev failed, ret = %d", __func__, ret); + return HDF_FAILURE; + } + + if (!HdfSbufWriteBuffer(reply, &inputDev->attrSet, sizeof(DevAttr))) { + HDF_LOGE("%s: sbuf write dev attr failed", __func__); + return HDF_FAILURE; + } + + HDF_LOGI("%s: get dev attr succ", __func__); + return HDF_SUCCESS; +} + +static int32_t HidGetDeviceAbility(InputDevice *inputDev, struct HdfSBuf *reply) +{ + if (inputDev == NULL) { + return HDF_FAILURE; + } + HDF_LOGE("%s: enter", __func__); + + if (!HdfSbufWriteBuffer(reply, &inputDev->abilitySet, sizeof(DevAbility))) { + HDF_LOGE("%s: sbuf write dev ability failed", __func__); + return HDF_FAILURE; + } + + HDF_LOGI("%s: get dev ability succ", __func__); + return HDF_SUCCESS; +} + static int32_t HdfHIDDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply) { (void)cmd; + int32_t ret; + InputDevice *inputDev = NULL; if (client == NULL || data == NULL || reply == NULL) { HDF_LOGE("%s: param is null", __func__); return HDF_FAILURE; } - return HDF_SUCCESS; + + inputDev = (InputDevice *)client->device->priv; + if (inputDev == NULL) { + HDF_LOGE("%s: inputDev is null", __func__); + return HDF_FAILURE; + } + + HDF_LOGI("%s: cmd = %d", __func__, cmd); + switch (cmd) { + case GET_DEV_TYPE: + ret = HidGetDevType(inputDev, reply); + break; + case GET_CHIP_NAME: + case GET_VENDOR_NAME: + case GET_CHIP_INFO: + ret = HidGetDeviceStrInfo(inputDev, cmd, reply); + break; + case GET_DEV_ATTR: + ret = HidGetDeviceAttr(inputDev, reply); + break; + case GET_DEV_ABILITY: + ret = HidGetDeviceAbility(inputDev, reply); + break; + default: + ret = HDF_SUCCESS; + HDF_LOGE("%s: cmd unknown, cmd = 0x%x", __func__, cmd); + break; + } + return ret; } static int32_t HdfHIDDriverBind(struct HdfDeviceObject *device) diff --git a/model/input/driver/hdf_input_device_manager.c b/model/input/driver/hdf_input_device_manager.c index 2db56fd80..0407f0692 100644 --- a/model/input/driver/hdf_input_device_manager.c +++ b/model/input/driver/hdf_input_device_manager.c @@ -60,7 +60,7 @@ static struct HdfDeviceObject *HidRegisterHdfDevice(InputDevice *inputDev) return hdfDev; } -static void HotPlugNotify(const InputDevice *inputDev, bool status) +static void HotPlugNotify(const InputDevice *inputDev, uint32_t status) { struct HdfSBuf *sbuf = NULL; HotPlugEvent event = {0}; @@ -71,20 +71,21 @@ static void HotPlugNotify(const InputDevice *inputDev, bool status) HDF_LOGE("%s: obtain buffer failed", __func__); return; } + event.devId = inputDev->devId; event.devType = inputDev->devType; event.status = status; if (!HdfSbufWriteBuffer(sbuf, &event, sizeof(HotPlugEvent))) { HDF_LOGE("%s: write buffer failed", __func__); - goto EXIT; + HdfSbufFlush(sbuf); + return; } ret = HdfDeviceSendEvent(g_inputManager->hdfDevObj, 0, sbuf); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: send event failed", __func__); } -EXIT: - HdfSBufRecycle(sbuf); + HdfSbufFlush(sbuf); } static int32_t CreateDeviceNode(InputDevice *inputDev) @@ -92,6 +93,7 @@ static int32_t CreateDeviceNode(InputDevice *inputDev) if (IsHidDevice(inputDev->devType)) { HDF_LOGI("%s: prepare to register hdf device", __func__); inputDev->hdfDevObj = HidRegisterHdfDevice(inputDev); + inputDev->hdfDevObj->priv = (void *)inputDev; if (inputDev->hdfDevObj == NULL) { return HDF_DEV_ERR_NO_DEVICE; } diff --git a/model/input/driver/hdf_input_device_manager.h b/model/input/driver/hdf_input_device_manager.h index bed6437fb..713784ce0 100644 --- a/model/input/driver/hdf_input_device_manager.h +++ b/model/input/driver/hdf_input_device_manager.h @@ -20,7 +20,7 @@ #define HDF_LOG_TAG HDF_INPUT_DRV #define INPUT_DEV_PATH_LEN 64 #define MAX_INPUT_DEV_NUM 32 -#define DEV_NAME_LEN 16 +#define DEV_NAME_LEN 32 #define ONLINE 0 #define OFFLINE 1 diff --git a/model/input/driver/hdf_touch.c b/model/input/driver/hdf_touch.c index 6d32d162e..ad862cbd8 100644 --- a/model/input/driver/hdf_touch.c +++ b/model/input/driver/hdf_touch.c @@ -19,10 +19,7 @@ #define MAX_TOUCH_DEVICE 5 #define REGISTER_BYTE_SIZE 4 #define TOUCH_CHIP_NAME_LEN 10 -#define AXIS_X_MAX 479 -#define AXIS_X_RANGE 480 -#define AXIS_Y_MAX 959 -#define AXIS_Y_RANGE 960 + static TouchDriver *g_touchDriverList[MAX_TOUCH_DEVICE]; static void InputFrameReport(TouchDriver *driver); @@ -460,12 +457,6 @@ static int32_t TouchGetDeviceAttr(TouchDriver *driver, struct HdfSBuf *reply) HDF_LOGE("%s: enter", __func__); char *tempStr = "main_touch"; (void)strncpy_s(driver->inputDev->attrSet.devName, DEV_NAME_LEN, tempStr, strlen(tempStr)); - driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].min = 0; - driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].max = AXIS_X_MAX; - driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].range = AXIS_X_RANGE; - driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].min = 0; - driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].max = AXIS_Y_MAX; - driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].range = AXIS_Y_RANGE; if (!HdfSbufWriteBuffer(reply, &driver->inputDev->attrSet, sizeof(DevAttr))) { HDF_LOGE("%s: sbuf write dev attr failed", __func__); diff --git a/model/input/driver/touchscreen/touch_gt911.c b/model/input/driver/touchscreen/touch_gt911.c index 014ad7ed8..fb935966b 100644 --- a/model/input/driver/touchscreen/touch_gt911.c +++ b/model/input/driver/touchscreen/touch_gt911.c @@ -14,6 +14,12 @@ #include "input_i2c_ops.h" #include "touch_gt911.h" +#define AXIS_X_MAX 479 +#define AXIS_X_RANGE 480 +#define AXIS_Y_MAX 959 +#define AXIS_Y_RANGE 960 +#define MAX_POINT 5 + static int32_t ChipInit(ChipDevice *device) { return HDF_SUCCESS; @@ -179,7 +185,22 @@ static void SetAbility(ChipDevice *device) device->driver->inputDev->abilitySet.eventType[0] = SET_BIT(EV_SYN) | SET_BIT(EV_KEY) | SET_BIT(EV_ABS); device->driver->inputDev->abilitySet.absCode[0] = SET_BIT(ABS_X) | SET_BIT(ABS_Y); + device->driver->inputDev->abilitySet.absCode[1] = SET_BIT(ABS_MT_POSITION_X) | + SET_BIT(ABS_MT_POSITION_Y) | SET_BIT(ABS_MT_TRACKING_ID); device->driver->inputDev->abilitySet.keyCode[3] = SET_BIT(KEY_UP) | SET_BIT(KEY_DOWN); + device->driver->inputDev->attrSet.axisInfo[ABS_X].min = 0; + device->driver->inputDev->attrSet.axisInfo[ABS_X].max = AXIS_X_MAX; + device->driver->inputDev->attrSet.axisInfo[ABS_X].range = AXIS_X_RANGE; + device->driver->inputDev->attrSet.axisInfo[ABS_Y].min = 0; + device->driver->inputDev->attrSet.axisInfo[ABS_Y].max = AXIS_Y_MAX; + device->driver->inputDev->attrSet.axisInfo[ABS_Y].range = AXIS_Y_RANGE; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].min = 0; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].max = AXIS_X_MAX; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].range = AXIS_X_RANGE; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].min = 0; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].max = AXIS_Y_MAX; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].range = AXIS_Y_RANGE; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_TRACKING_ID].max = MAX_POINT; } static struct TouchChipOps g_gt911ChipOps = { -- Gitee From 16a074649b102f7047b3694f1993f6147e6bb686 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Thu, 8 Jul 2021 14:53:19 +0000 Subject: [PATCH 006/205] Description:adapter wlan hdi client Feature or Bugfix:Feature Binary Source: No Signed-off-by: YOUR_NAME --- include/wifi/hdf_wifi_event.h | 2 +- model/network/wifi/core/module/wifi_base.c | 18 +++++++++++++++++- .../network/wifi/platform/src/hdf_wifi_event.c | 7 ++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/wifi/hdf_wifi_event.h b/include/wifi/hdf_wifi_event.h index cfae47b11..4aad40b76 100644 --- a/include/wifi/hdf_wifi_event.h +++ b/include/wifi/hdf_wifi_event.h @@ -474,7 +474,7 @@ int32_t HdfWifiEventEapolRecv(const char *name, void *context); * @since 1.0 * @version 1.0 */ -int32_t HdfWifiEventResetResult(const uint8_t chipId, int32_t resetStatus); +int32_t HdfWifiEventResetResult(const uint8_t chipId, int32_t resetStatus, const char *ifName); #ifdef __cplusplus #if __cplusplus diff --git a/model/network/wifi/core/module/wifi_base.c b/model/network/wifi/core/module/wifi_base.c index 6f2911387..69e8fb1da 100644 --- a/model/network/wifi/core/module/wifi_base.c +++ b/model/network/wifi/core/module/wifi_base.c @@ -1107,6 +1107,7 @@ static int32_t WifiCmdDoResetChip(const RequestContext *context, struct HdfSBuf { int32_t ret; uint8_t chipId; + const char *ifName = NULL; struct HdfWlanDevice *wlanDevice = NULL; ret = ResetParaCheck(context, reqData, rspData); @@ -1118,11 +1119,20 @@ static int32_t WifiCmdDoResetChip(const RequestContext *context, struct HdfSBuf HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "chipId"); return HDF_FAILURE; } + ifName = HdfSbufReadString(reqData); + if (ifName == NULL) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName"); + return HDF_FAILURE; + } /* callback function use chipId */ if (!HdfSbufWriteUint8(rspData, chipId)) { HDF_LOGE("%s: %s!", __func__, ERROR_DESC_WRITE_RSP_FAILED); return HDF_FAILURE; } + if (!HdfSbufWriteString(rspData, ifName)) { + HDF_LOGE("%s: Serialize failed!", __func__); + return HDF_FAILURE; + } ret = WifiResetEntranceCheck(chipId); if (ret != HDF_SUCCESS) { @@ -1156,6 +1166,7 @@ void SendMessageResetDriverCallBack(const RequestContext *context, struct HdfSBu ErrorCode rspCode) { uint8_t chipId; + const char *ifName = NULL; (void)context; if (rspData == NULL || reqData == NULL) { @@ -1167,8 +1178,13 @@ void SendMessageResetDriverCallBack(const RequestContext *context, struct HdfSBu HDF_LOGE("%s: read data failed! ParamName=%s", __func__, "chipId"); return; } + ifName = HdfSbufReadString(reqData); + if (ifName == NULL) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName"); + return HDF_FAILURE; + } - int32_t ret = HdfWifiEventResetResult(chipId, rspCode); + int32_t ret = HdfWifiEventResetResult(chipId, ifName, rspCode); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: send resetDriver event fail!", __func__); } diff --git a/model/network/wifi/platform/src/hdf_wifi_event.c b/model/network/wifi/platform/src/hdf_wifi_event.c index 8ad90b5a2..109577831 100644 --- a/model/network/wifi/platform/src/hdf_wifi_event.c +++ b/model/network/wifi/platform/src/hdf_wifi_event.c @@ -400,7 +400,7 @@ int32_t HdfWifiEventEapolRecv(const char *name, void *context) return ret; } -int32_t HdfWifiEventResetResult(const uint8_t chipId, int32_t resetStatus) +int32_t HdfWifiEventResetResult(const uint8_t chipId, int32_t resetStatus, const char *ifName) { struct HdfSBuf *data = NULL; int32_t ret; @@ -410,6 +410,11 @@ int32_t HdfWifiEventResetResult(const uint8_t chipId, int32_t resetStatus) HDF_LOGE("%s InitDataBlock failed", __func__); return HDF_FAILURE; } + if (!HdfSbufWriteString(data, ifName)) { + HDF_LOGE("%s: Serialize failed!", __func__); + HdfSBufRecycle(data); + return HDF_FAILURE; + } if (!HdfSbufWriteInt32(data, resetStatus)) { HDF_LOGE("%s sbuf write failed", __func__); HdfSBufRecycle(data); -- Gitee From 16836dde36b42c3e640024eb571709a71bda4619 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Fri, 9 Jul 2021 03:21:43 +0000 Subject: [PATCH 007/205] Description:adapter wlan hdi client Feature or Bugfix:Feature Binary Source: No Signed-off-by: YOUR_NAME --- model/network/wifi/core/module/wifi_base.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/model/network/wifi/core/module/wifi_base.c b/model/network/wifi/core/module/wifi_base.c index 69e8fb1da..2bb44d55a 100644 --- a/model/network/wifi/core/module/wifi_base.c +++ b/model/network/wifi/core/module/wifi_base.c @@ -1181,10 +1181,10 @@ void SendMessageResetDriverCallBack(const RequestContext *context, struct HdfSBu ifName = HdfSbufReadString(reqData); if (ifName == NULL) { HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName"); - return HDF_FAILURE; + return; } - int32_t ret = HdfWifiEventResetResult(chipId, ifName, rspCode); + int32_t ret = HdfWifiEventResetResult(chipId, rspCode, ifName); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: send resetDriver event fail!", __func__); } -- Gitee From 46097e6e5d682f0b36d4fb75a98461d41792d2c8 Mon Sep 17 00:00:00 2001 From: vb6174 Date: Fri, 9 Jul 2021 06:59:33 +0000 Subject: [PATCH 008/205] add audio frame wrok code Signed-off-by: vb6174 --- model/audio/core/include/audio_control.h | 77 ++ model/audio/core/include/audio_core.h | 96 ++ model/audio/core/include/audio_host.h | 171 +++ model/audio/core/include/audio_parse.h | 28 + model/audio/core/include/codec_core.h | 35 + model/audio/core/src/audio_core.c | 1038 ++++++++++++++ model/audio/core/src/audio_host.c | 443 ++++++ model/audio/core/src/audio_parse.c | 60 + model/audio/core/src/codec_core.c | 166 +++ .../test/unittest/common/audio_common_test.h | 49 + .../test/unittest/common/audio_core_test.cpp | 153 ++ .../test/unittest/common/audio_host_test.cpp | 51 + .../test/unittest/common/audio_parse_test.cpp | 45 + .../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 | 643 +++++++++ model/audio/device/soc/include/dai_adapter.h | 53 + 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 | 1170 ++++++++++++++++ .../dispatch/include/audio_control_dispatch.h | 54 + .../dispatch/include/audio_stream_dispatch.h | 74 + .../dispatch/src/audio_control_dispatch.c | 333 +++++ .../dispatch/src/audio_stream_dispatch.c | 1068 ++++++++++++++ .../common/audio_stream_dispatch_test.cpp | 51 + model/audio/sapm/include/audio_sapm.h | 216 +++ model/audio/sapm/src/audio_sapm.c | 1230 +++++++++++++++++ .../test/unittest/common/audio_sapm_test.cpp | 69 + test/unittest/common/hdf_main_test.c | 8 +- test/unittest/common/hdf_main_test.h | 1 + .../model/audio/include/audio_core_test.h | 46 + .../model/audio/include/audio_host_test.h | 30 + .../model/audio/include/audio_parse_test.h | 28 + .../model/audio/include/audio_sapm_test.h | 32 + .../include/audio_stream_dispatch_test.h | 29 + .../model/audio/include/hdf_audio_test.h | 61 + .../model/audio/src/audio_core_test.c | 327 +++++ .../model/audio/src/audio_host_test.c | 64 + .../model/audio/src/audio_parse_test.c | 29 + .../model/audio/src/audio_sapm_test.c | 92 ++ .../audio/src/audio_stream_dispatch_test.c | 40 + .../unittest/model/audio/src/hdf_audio_test.c | 71 + 45 files changed, 9502 insertions(+), 1 deletion(-) create mode 100755 model/audio/core/include/audio_control.h create mode 100755 model/audio/core/include/audio_core.h create mode 100755 model/audio/core/include/audio_host.h create mode 100755 model/audio/core/include/audio_parse.h create mode 100755 model/audio/core/include/codec_core.h create mode 100755 model/audio/core/src/audio_core.c create mode 100755 model/audio/core/src/audio_host.c create mode 100755 model/audio/core/src/audio_parse.c create mode 100755 model/audio/core/src/codec_core.c create mode 100755 model/audio/core/test/unittest/common/audio_common_test.h create mode 100755 model/audio/core/test/unittest/common/audio_core_test.cpp create mode 100755 model/audio/core/test/unittest/common/audio_host_test.cpp create mode 100755 model/audio/core/test/unittest/common/audio_parse_test.cpp create mode 100755 model/audio/device/accessory/include/accessory_adapter.h create mode 100755 model/audio/device/accessory/src/accessory.c create mode 100755 model/audio/device/codec/include/codec_adapter.h create mode 100755 model/audio/device/codec/src/codec.c create mode 100755 model/audio/device/soc/include/dai_adapter.h create mode 100755 model/audio/device/soc/include/dsp_adapter.h create mode 100755 model/audio/device/soc/include/platform_adapter.h create mode 100755 model/audio/device/soc/src/dai.c create mode 100755 model/audio/device/soc/src/dsp.c create mode 100755 model/audio/device/soc/src/platform.c create mode 100755 model/audio/dispatch/include/audio_control_dispatch.h create mode 100755 model/audio/dispatch/include/audio_stream_dispatch.h create mode 100755 model/audio/dispatch/src/audio_control_dispatch.c create mode 100755 model/audio/dispatch/src/audio_stream_dispatch.c create mode 100755 model/audio/dispatch/test/unittest/common/audio_stream_dispatch_test.cpp create mode 100755 model/audio/sapm/include/audio_sapm.h create mode 100755 model/audio/sapm/src/audio_sapm.c create mode 100755 model/audio/sapm/test/unittest/common/audio_sapm_test.cpp create mode 100755 test/unittest/model/audio/include/audio_core_test.h create mode 100755 test/unittest/model/audio/include/audio_host_test.h create mode 100755 test/unittest/model/audio/include/audio_parse_test.h create mode 100755 test/unittest/model/audio/include/audio_sapm_test.h create mode 100755 test/unittest/model/audio/include/audio_stream_dispatch_test.h create mode 100755 test/unittest/model/audio/include/hdf_audio_test.h create mode 100755 test/unittest/model/audio/src/audio_core_test.c create mode 100755 test/unittest/model/audio/src/audio_host_test.c create mode 100755 test/unittest/model/audio/src/audio_parse_test.c create mode 100755 test/unittest/model/audio/src/audio_sapm_test.c create mode 100755 test/unittest/model/audio/src/audio_stream_dispatch_test.c create mode 100755 test/unittest/model/audio/src/hdf_audio_test.c diff --git a/model/audio/core/include/audio_control.h b/model/audio/core/include/audio_control.h new file mode 100755 index 000000000..8b2fab186 --- /dev/null +++ b/model/audio/core/include/audio_control.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2020-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_CONTROL_H +#define AUDIO_CONTROL_H + +#include "audio_types.h" +#include "hdf_dlist.h" + + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +struct AudioCtrlElemId { + const char *cardServiceName; + int32_t iface; + const char *itemName; /* ASCII name of item */ +}; + +struct AudioCtrlElemInfo { + struct AudioCtrlElemId id; + uint32_t count; /* count of values */ + int32_t type; /* R: value type - AUDIODRV_CTL_ELEM_IFACE_MIXER_* */ + int32_t min; /* R: minimum value */ + int32_t max; /* R: maximum value */ +}; + +struct AudioCtrlElemValue { + struct AudioCtrlElemId id; + int32_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 (*KconfigPut_t)(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); + +/* mixer control */ +struct AudioMixerControl { + int32_t min; + int32_t max; + int32_t platformMax; + uint32_t mask; + uint32_t reg; + uint32_t rreg; /* right sound channel reg */ + uint32_t shift; + uint32_t rshift; /* right sound channel reg shift */ + uint32_t invert; +}; + +struct AudioKcontrol { + const char *name; /* ASCII name of item */ + int32_t iface; + KconfigInfo_t Info; + KconfigGet_t Get; + KconfigPut_t Put; + void *privateData; + void *pri; + unsigned long privateValue; + struct DListHead list; /* list of controls */ +}; + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif diff --git a/model/audio/core/include/audio_core.h b/model/audio/core/include/audio_core.h new file mode 100755 index 000000000..03ac9ab57 --- /dev/null +++ b/model/audio/core/include/audio_core.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2020-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_CORE_H +#define AUDIO_CORE_H + +#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" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#define CHANNEL_MAX_NUM 2 +#define CHANNEL_MIN_NUM 1 + +#define AUDIO_DAI_LINK_COMPLETE 1 +#define AUDIO_DAI_LINK_UNCOMPLETE 0 + +#define AUDIO_DRIVER_LOG_ERR(fmt, arg...) do { \ + HDF_LOGE("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \ + } while (0) + +#define AUDIO_DRIVER_LOG_INFO(fmt, arg...) do { \ + HDF_LOGI("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \ + } while (0) + +#define AUDIO_DRIVER_LOG_WARNING(fmt, arg...) do { \ + HDF_LOGW("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \ + } while (0) + +#define AUDIO_DRIVER_LOG_DEBUG(fmt, arg...) do { \ + HDF_LOGD("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \ + } while (0) + +enum AudioDeviceType { + AUDIO_DAI_DEVICE, + AUDIO_DSP_DEVICE, + AUDIO_PLATFORM_DEVICE, + AUDIO_CODEC_DEVICE, + AUDIO_ACCESSORY_DEVICE, + AUDIO_DEVICE_BUTT, +}; + +enum PlayStatus { + STREAM_START = 4, + STREAM_STOP, +}; + +/* Dai registration interface */ +int32_t AudioSocRegisterDai(struct HdfDeviceObject *device, struct DaiData *data); +/* Platform registration interface */ +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 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); +struct CodecDevice *AudioKcontrolGetCodec(const struct AudioKcontrol *kcontrol); +struct AccessoryDevice *AudioKcontrolGetAccessory(const struct AudioKcontrol *kcontrol); +extern 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); + +extern int32_t AudioInfoCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo); +extern int32_t AudioGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +extern int32_t AudioPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +extern int32_t AiaoGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +extern int32_t AiaoPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +int32_t AudioRegisterDeviceDsp(struct HdfDeviceObject *device, struct DspData *dspData, struct DaiData *DaiData); +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* AUDIO_CORE_H */ diff --git a/model/audio/core/include/audio_host.h b/model/audio/core/include/audio_host.h new file mode 100755 index 000000000..2ab9e3c57 --- /dev/null +++ b/model/audio/core/include/audio_host.h @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2020-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_HOST_H +#define AUDIO_HOST_H + +#include "hdf_base.h" +#include "hdf_dlist.h" +#include "hdf_device_desc.h" +#include "hdf_log.h" +#include "device_resource_if.h" +#include "osal_mem.h" +#include "osal_mutex.h" +#include "securec.h" +#include "audio_types.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#define ADM_LOG_ERR(fmt, arg...) do { \ + HDF_LOGE("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \ + } while (0) + +#define ADM_LOG_INFO(fmt, arg...) do { \ + HDF_LOGI("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \ + } while (0) + +#define ADM_LOG_WARNING(fmt, arg...) do { \ + HDF_LOGW("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \ + } while (0) + +#define ADM_LOG_DEBUG(fmt, arg...) do { \ + HDF_LOGD("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \ + } while (0) + +#define BUFF_SIZE_MAX 64 + +#define AUDIO_LIST_HEAD_INIT(name) { &(name), &(name) } + +#define AUDIO_LIST_HEAD(name) \ + struct DListHead name = AUDIO_LIST_HEAD_INIT(name) + +struct AudioConfigData { + const char *cardServiceName; + const char *codecName; + const char *platformName; + const char *cpuDaiName; + const char *codecDaiName; + const char *accessoryName; + const char *accessoryDaiName; + const char *dspName; + const char *dspDaiName; +}; + +struct AudioCard { + struct AudioPcmRuntime *rtd; + struct AudioConfigData configData; + + /* Card-specific routes and components. */ + const struct AudioSapmComponent *sapmComponents; + int32_t sapmComponentsNum; + const struct AudioSapmRoute *sapmRoutes; + int32_t sapmRoutesNum; + + struct DListHead list; + struct DListHead controls; /* all controls for this card */ + struct DListHead components; /* all components for this card */ + struct DListHead paths; /* all paths for this card */ + struct DListHead sapmDirty; /* all dirty for this card */ +}; + +enum CriBuffStatus { + ENUM_CIR_BUFF_NORMAL = 1, + ENUM_CIR_BUFF_FULL, + ENUM_CIR_BUFF_EMPTY, +}; + +enum AudioStreamType { + AUDIO_CAPTURE_STREAM = 0, + AUDIO_RENDER_STREAM, +}; + +struct AudioPcmHwParams { + /* The stream type in a frame */ + enum AudioStreamType streamType; + /* The number of channels in a frame */ + uint32_t channels; + /* The number of frames per second */ + uint32_t rate; + /* The number of frames in a period */ + uint32_t periodSize; + /* The number of periods in a PCM */ + uint32_t periodCount; + /* The sample format of a PCM */ + enum AudioFormat format; /* < Audio data format. For details, see {@link AudioFormat}. */ + const char *cardServiceName; + uint32_t period; + uint32_t frameSize; + bool isBigEndian; + bool isSignedData; + uint32_t startThreshold; + uint32_t stopThreshold; + uint32_t silenceThreshold; +}; + +struct AudioHost { + struct IDeviceIoService service; + struct HdfDeviceObject *device; + void *priv; +}; + +struct AudioTxData { + enum CriBuffStatus status; + char *buf; /* buf address */ + unsigned long frames; /* frames number */ +}; + +struct AudioRxData { + enum CriBuffStatus status; + char *buf; + unsigned long bufSize; + unsigned long frames; /* frames number */ +}; + +struct AudioPcmRuntime { + /* runtime devices */ + struct CodecDevice *codec; + struct PlatformDevice *platform; + struct DaiDevice *codecDai; + struct DaiDevice *cpuDai; + struct DaiDevice *accessoryDai; + struct AccessoryDevice *accessory; + struct DspDevice *dsp; + struct DaiDevice *dspDai; + uint8_t complete; + uint32_t frameBits; + uint8_t *dmaArea; + unsigned long bufferSize; +}; + +struct AudioHost *AudioHostCreateAndBind(struct HdfDeviceObject *device); +void AudioHostDestroy(struct AudioHost *host); + +static inline struct HdfDeviceObject *AudioHostToDevice(struct AudioHost *host) +{ + return (host == NULL) ? NULL : host->device; +} + +static inline struct AudioHost *AudioHostFromDevice(struct HdfDeviceObject *device) +{ + return (device == NULL) ? NULL : (struct AudioHost *)device->service; +} + +/* Get a sound card instance */ +struct AudioCard *GetCardInstance(const char *serviceName); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* AUDIO_HOST_H */ diff --git a/model/audio/core/include/audio_parse.h b/model/audio/core/include/audio_parse.h new file mode 100755 index 000000000..e73e14c58 --- /dev/null +++ b/model/audio/core/include/audio_parse.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2020-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_PARSE_H +#define AUDIO_PARSE_H + +#include "audio_host.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +int32_t AudioFillConfigData(struct HdfDeviceObject *device, struct AudioConfigData *configData); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* AUDIO_PARSE_H */ diff --git a/model/audio/core/include/codec_core.h b/model/audio/core/include/codec_core.h new file mode 100755 index 000000000..a19378104 --- /dev/null +++ b/model/audio/core/include/codec_core.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020-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_CORE_H +#define CODEC_CORE_H + +#include "codec_adapter.h" +#include "audio_core.h" +#include "osal_io.h" + +#ifdef __cplusplus +#if __cplusplus +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); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* CODEC_CORE_H */ diff --git a/model/audio/core/src/audio_core.c b/model/audio/core/src/audio_core.c new file mode 100755 index 000000000..da1d36004 --- /dev/null +++ b/model/audio/core/src/audio_core.c @@ -0,0 +1,1038 @@ +/* + * 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" + +#define HDF_LOG_TAG audio_core + +AUDIO_LIST_HEAD(daiController); +AUDIO_LIST_HEAD(platformController); +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; + + if ((device == NULL) || (data == NULL)) { + ADM_LOG_ERR("Input params check error: device=%p, data=%p.", device, data); + return HDF_ERR_INVALID_OBJECT; + } + + platform = (struct PlatformDevice *)OsalMemCalloc(sizeof(*platform)); + if (platform == NULL) { + ADM_LOG_ERR("Malloc platform device fail!"); + return HDF_ERR_MALLOC_FAIL; + } + + platform->devPlatformName = data->drvPlatformName; + platform->devData = data; + platform->device = device; + DListInsertHead(&platform->list, &platformController); + ADM_LOG_INFO("Register [%s] success.", platform->devPlatformName); + + return HDF_SUCCESS; +} + +int32_t AudioSocRegisterDai(struct HdfDeviceObject *device, struct DaiData *data) +{ + struct DaiDevice *dai = NULL; + + if ((device == NULL) || (data == NULL)) { + ADM_LOG_ERR("Input params check error: device=%p, data=%p.", device, data); + return HDF_ERR_INVALID_OBJECT; + } + + dai = (struct DaiDevice *)OsalMemCalloc(sizeof(*dai)); + if (dai == NULL) { + ADM_LOG_ERR("Malloc dai device fail!"); + return HDF_ERR_MALLOC_FAIL; + } + + dai->devDaiName = data->drvDaiName; + dai->devData = data; + dai->device = device; + DListInsertHead(&dai->list, &daiController); + ADM_LOG_INFO("Register [%s] success.", dai->devDaiName); + + return HDF_SUCCESS; +} + +int32_t AudioRegisterAccessory(struct HdfDeviceObject *device, struct AccessoryData *data, struct DaiData *daiData) +{ + struct AccessoryDevice *accessory = NULL; + int32_t ret; + + if (device == NULL || data == NULL || daiData == NULL) { + ADM_LOG_ERR("Input params check error: device=%p, data=%p, daiData=%p.", device, data, daiData); + return HDF_ERR_INVALID_OBJECT; + } + + accessory = (struct AccessoryDevice *)OsalMemCalloc(sizeof(*accessory)); + if (accessory == NULL) { + ADM_LOG_ERR("Malloc accessory device fail!"); + return HDF_ERR_MALLOC_FAIL; + } + + accessory->devAccessoryName = data->drvAccessoryName; + accessory->devData = data; + accessory->device = device; + + ret = AudioSocDeviceRegister(device, (void *)daiData, AUDIO_DAI_DEVICE); + if (ret != HDF_SUCCESS) { + OsalMemFree(accessory); + ADM_LOG_ERR("Register accessory device fail ret=%d", ret); + return HDF_ERR_IO; + } + DListInsertHead(&accessory->list, &accessoryController); + ADM_LOG_INFO("Register [%s] success.", accessory->devAccessoryName); + + return HDF_SUCCESS; +} + +int32_t AudioRegisterCodec(struct HdfDeviceObject *device, struct CodecData *codecData, struct DaiData *daiData) +{ + struct CodecDevice *codec = NULL; + int32_t ret; + + if ((device == NULL) || (codecData == NULL) || (daiData == NULL)) { + ADM_LOG_ERR("Input params check error: device=%p, codecData=%p, daiData=%p.", + device, codecData, daiData); + return HDF_ERR_INVALID_OBJECT; + } + + codec = (struct CodecDevice *)OsalMemCalloc(sizeof(*codec)); + if (codec == NULL) { + ADM_LOG_ERR("Malloc codec device fail!"); + return HDF_ERR_MALLOC_FAIL; + } + + OsalMutexInit(&codec->mutex); + codec->devCodecName = codecData->drvCodecName; + codec->devData = codecData; + codec->device = device; + + ret = AudioSocDeviceRegister(device, (void *)daiData, AUDIO_DAI_DEVICE); + if (ret != HDF_SUCCESS) { + OsalMemFree(codec); + ADM_LOG_ERR("Register dai device fail ret=%d", ret); + return HDF_ERR_IO; + } + DListInsertHead(&codec->list, &codecController); + ADM_LOG_INFO("Register [%s] success.", codec->devCodecName); + + return HDF_SUCCESS; +} + +int32_t AudioSocDeviceRegister(struct HdfDeviceObject *device, void *data, enum AudioDeviceType deviceType) +{ + struct PlatformData *platformData = NULL; + struct DaiData *daiData = NULL; + int32_t ret; + + if ((device == NULL) || (data == NULL) || (deviceType >= AUDIO_DEVICE_BUTT) || (deviceType < 0)) { + ADM_LOG_ERR("Input params check error: device=%p, data=%p, deviceType=%d.", + device, data, deviceType); + return HDF_ERR_INVALID_OBJECT; + } + + switch (deviceType) { + case AUDIO_DAI_DEVICE: { + daiData = (struct DaiData *)data; + ret = AudioSocRegisterDai(device, daiData); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("Register dai device fail ret=%d", ret); + return HDF_FAILURE; + } + 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); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("Register dma device fail ret=%d", ret); + return HDF_FAILURE; + } + break; + } + default: { + ADM_LOG_ERR("Invalid device type."); + return HDF_FAILURE; + } + } + + return HDF_SUCCESS; +} + +void AudioSeekPlatformDevice(struct AudioPcmRuntime *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 (data->platformName == NULL) { + ADM_LOG_ERR("Input devicesName check error: data->platformName is NULL."); + return; + } + + DLIST_FOR_EACH_ENTRY(platform, &platformController, struct PlatformDevice, list) { + if (platform != NULL && platform->devPlatformName != NULL && + strcmp(platform->devPlatformName, data->platformName) == 0) { + rtd->platform = platform; + break; + } + } + return; +} + +void AudioSeekCpuDaiDevice(struct AudioPcmRuntime *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 (data->cpuDaiName == NULL) { + ADM_LOG_ERR("Input cpuDaiName check error: data->cpuDaiName is NULL."); + return; + } + + DLIST_FOR_EACH_ENTRY(cpuDai, &daiController, struct DaiDevice, list) { + if (cpuDai != NULL && cpuDai->devDaiName != NULL && strcmp(cpuDai->devDaiName, data->cpuDaiName) == 0) { + rtd->cpuDai = cpuDai; + break; + } + } + return; +} + +void AudioSeekCodecDevice(struct AudioPcmRuntime *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 (data->codecName == NULL || data->codecDaiName == NULL) { + ADM_LOG_ERR("Input devicesName check error: data->codecName=%p, data->codecDaiName=%p.", + data->codecName, data->codecDaiName); + return; + } + + DLIST_FOR_EACH_ENTRY(codec, &codecController, struct CodecDevice, list) { + if (codec != NULL && codec->devCodecName != NULL && strcmp(codec->devCodecName, data->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) { + rtd->codecDai = codecDai; + break; + } + } + break; + } + } + return; +} + +void AudioSeekAccessoryDevice(struct AudioPcmRuntime *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 (data->accessoryName == NULL) { + ADM_LOG_ERR("Input devicesName check error: data->accessoryName is NULL."); + return; + } + + DLIST_FOR_EACH_ENTRY(accessory, &accessoryController, struct AccessoryDevice, list) { + if (accessory != NULL && accessory->devAccessoryName != NULL && + strcmp(accessory->devAccessoryName, data->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) { + rtd->accessoryDai = accessoryDai; + break; + } + } + break; + } + } + return; +} + +void AudioSeekDspDevice(struct AudioPcmRuntime *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 (data->dspName == NULL || data->dspDaiName == NULL) { + ADM_LOG_ERR("Input devicesName check error: data->dspName=%p, data->dspDaiName=%p.", + data->codecName, data->codecDaiName); + return; + } + + DLIST_FOR_EACH_ENTRY(dsp, &dspController, struct DspDevice, list) { + if (dsp != NULL && dsp->devDspName != NULL && strcmp(dsp->devDspName, data->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) { + rtd->dspDai = dspDai; + break; + } + } + break; + } + } + return; +} + +int32_t AudioBindDaiLink(struct AudioCard *audioCard, 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; + } + + audioCard->rtd = (struct AudioPcmRuntime *)OsalMemCalloc(sizeof(struct AudioPcmRuntime)); + if (audioCard->rtd == NULL) { + ADM_LOG_ERR("Malloc audioCard->rtd fail!"); + return HDF_ERR_MALLOC_FAIL; + } + + audioCard->rtd->complete = AUDIO_DAI_LINK_UNCOMPLETE; + + 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; +} + +int32_t AudioUpdateCodecRegBits(struct CodecDevice *codec, struct AudioMixerControl *mixerControl, int32_t value) +{ + int32_t ret; + uint32_t curValue; + int32_t mixerControlMask; + if (codec == NULL || codec->devData == NULL || codec->devData->Write == NULL || mixerControl == NULL) { + ADM_LOG_ERR("Invalid accessory param."); + return HDF_ERR_INVALID_OBJECT; + } + + value = value << mixerControl->shift; + mixerControlMask = mixerControl->mask << mixerControl->shift; + + OsalMutexLock(&codec->mutex); + ret = AudioCodecDeviceReadReg(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); + if (ret != HDF_SUCCESS) { + OsalMutexUnlock(&codec->mutex); + ADM_LOG_ERR("Write reg fail ret=%d", ret); + return HDF_FAILURE; + } + OsalMutexUnlock(&codec->mutex); + + ADM_LOG_DEBUG("Success."); + return HDF_SUCCESS; +} + +int32_t AudioUpdateAccessoryRegBits(struct AccessoryDevice *accessory, + struct AudioMixerControl *mixerControl, int32_t value) +{ + int32_t ret; + uint32_t curValue; + int32_t mixerControlMask; + if (accessory == NULL || accessory->devData == NULL || + accessory->devData->Write == NULL || mixerControl == NULL) { + ADM_LOG_ERR("Invalid accessory param."); + return HDF_ERR_INVALID_OBJECT; + } + + value = value << mixerControl->shift; + mixerControlMask = mixerControl->mask << mixerControl->shift; + + OsalMutexLock(&accessory->mutex); + ret = AudioAccessoryDeviceReadReg(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); + if (ret != HDF_SUCCESS) { + OsalMutexUnlock(&accessory->mutex); + ADM_LOG_ERR("Write reg fail ret=%d", ret); + return HDF_FAILURE; + } + OsalMutexUnlock(&accessory->mutex); + + ADM_LOG_DEBUG("Success."); + return HDF_SUCCESS; +} + +int32_t AudioUpdateRegBits(enum AudioDeviceType deviceType, void *device, + struct AudioMixerControl *mixerControl, int32_t value) +{ + int32_t ret; + struct CodecDevice *codec = NULL; + struct AccessoryDevice *accessory = NULL; + ADM_LOG_DEBUG("Entry."); + + 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; + } + } + + return ret; +} + +int32_t AudioAiaoUpdateRegBits(struct CodecDevice *codec, uint32_t reg, uint32_t mask, uint32_t shift, int32_t value) +{ + int32_t ret; + uint32_t curValue; + ADM_LOG_DEBUG("Entry to update AIAO reg bits."); + + if (codec == NULL || codec->devData == NULL || codec->devData->AiaoWrite == NULL) { + ADM_LOG_ERR("Invalid AIAO codec param."); + return HDF_ERR_INVALID_OBJECT; + } + + value = value << shift; + mask = mask << shift; + + OsalMutexLock(&codec->mutex); + ret = AudioAiaoDeviceReadReg(codec, reg, &curValue); + if (ret != HDF_SUCCESS) { + OsalMutexUnlock(&codec->mutex); + ADM_LOG_ERR("Read AIAO reg fail ret=%d.", ret); + return HDF_FAILURE; + } + curValue = (curValue & ~mask) | (value & mask); + ret = codec->devData->AiaoWrite(codec, reg, curValue); + if (ret != HDF_SUCCESS) { + OsalMutexUnlock(&codec->mutex); + ADM_LOG_ERR("Write AIAO reg fail ret=%d", ret); + return HDF_FAILURE; + } + OsalMutexUnlock(&codec->mutex); + + ADM_LOG_DEBUG("Update AIAO reg bits successful."); + return HDF_SUCCESS; +} + +struct CodecDevice *AudioKcontrolGetCodec(const struct AudioKcontrol *kcontrol) +{ + struct AudioCard *audioCard = NULL; + if (kcontrol == NULL || kcontrol->pri == NULL) { + ADM_LOG_ERR("Input param kcontrol is NULL."); + return NULL; + } + + audioCard = (struct AudioCard *)(kcontrol->pri); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("Get codec or rtd fail."); + return NULL; + } + + return audioCard->rtd->codec; +} + +struct AccessoryDevice *AudioKcontrolGetAccessory(const struct AudioKcontrol *kcontrol) +{ + struct AudioCard *audioCard = NULL; + if (kcontrol == NULL || kcontrol->pri == NULL) { + ADM_LOG_ERR("Input param kcontrol is NULL."); + return NULL; + } + + audioCard = (struct AudioCard *)(kcontrol->pri); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("Get accessory or rtd fail."); + return NULL; + } + + return audioCard->rtd->accessory; +} + +struct AudioKcontrol *AudioAddControl(const struct AudioCard *audioCard, const struct AudioKcontrol *ctrl) +{ + struct AudioKcontrol *control = NULL; + + if ((audioCard == NULL) || (ctrl == NULL)) { + ADM_LOG_ERR("Input params check error: audioCard=%p, ctrl=%p.", audioCard, ctrl); + return NULL; + } + + control = (struct AudioKcontrol *)OsalMemCalloc(sizeof(*control)); + if (control == NULL) { + ADM_LOG_ERR("Malloc control fail!"); + return NULL; + } + control->name = ctrl->name; + control->iface = ctrl->iface; + control->Info = ctrl->Info; + control->Get = ctrl->Get; + control->Put = ctrl->Put; + control->pri = (void *)audioCard; + control->privateValue = ctrl->privateValue; + + return control; +} + +int32_t AudioAddControls(struct AudioCard *audioCard, const struct AudioKcontrol *controls, int32_t controlMaxNum) +{ + struct AudioKcontrol *control = NULL; + int32_t i; + ADM_LOG_DEBUG("Entry."); + + if ((audioCard == NULL) || (controls == NULL) || (controlMaxNum <= 0)) { + ADM_LOG_ERR("Input params check error: audioCard=%p, controls=%p, controlMaxNum=%d.", + audioCard, controls, controlMaxNum); + return HDF_FAILURE; + } + + for (i = 0; i < controlMaxNum; i++) { + control = AudioAddControl(audioCard, &controls[i]); + if (control == NULL) { + ADM_LOG_ERR("Add control fail!"); + return HDF_FAILURE; + } + DListInsertHead(&control->list, &audioCard->controls); + } + ADM_LOG_DEBUG("Success."); + return HDF_SUCCESS; +} + +int32_t AudioCodecDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *val) +{ + int32_t ret; + if (codec == NULL || codec->devData == NULL || codec->devData->Read == NULL || val == NULL) { + ADM_LOG_ERR("Input param codec is NULL."); + return HDF_FAILURE; + } + ret = codec->devData->Read(codec, reg, val); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("Device read fail."); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t AudioAccessoryDeviceReadReg(struct AccessoryDevice *accessory, uint32_t reg, uint32_t *val) +{ + int32_t ret; + if (accessory == NULL || accessory->devData == NULL || accessory->devData->Read == NULL || val == NULL) { + ADM_LOG_ERR("Input param accessory is NULL."); + return HDF_FAILURE; + } + ret = accessory->devData->Read(accessory, reg, val); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("Device read fail."); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t AudioAiaoDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *val) +{ + int32_t ret; + if (codec == NULL || codec->devData == NULL || codec->devData->AiaoRead == NULL || val == NULL) { + ADM_LOG_ERR("Input param codec is NULL."); + return HDF_FAILURE; + } + ret = codec->devData->AiaoRead(codec, reg, val); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("Device read fail."); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t AudioInfoCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo) +{ + struct AudioMixerControl *mixerCtrl = NULL; + + if (kcontrol == NULL || kcontrol->privateValue <= 0 || elemInfo == NULL) { + ADM_LOG_ERR("Input param kcontrol is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + elemInfo->count = CHANNEL_MIN_NUM; + mixerCtrl = (struct AudioMixerControl *)kcontrol->privateValue; + /* stereo */ + if (mixerCtrl->reg != mixerCtrl->rreg || mixerCtrl->shift != mixerCtrl->rshift) { + elemInfo->count = CHANNEL_MAX_NUM; + } + elemInfo->type = 1; /* volume type */ + elemInfo->min = mixerCtrl->min; + elemInfo->max = mixerCtrl->max; + + return HDF_SUCCESS; +} + +static int32_t AudioGetCtrlSwSubRReg(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, + enum AudioDeviceType deviceType, void *device) +{ + 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 (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 { + rcurValue = (rcurValue >> mixerCtrl->shift) & mixerCtrl->mask; + } + if (rcurValue > mixerCtrl->max || rcurValue < mixerCtrl->min) { + ADM_LOG_ERR("Audio invalid rcurValue=%d", rcurValue); + return HDF_FAILURE; + } + if (mixerCtrl->invert) { + rcurValue = mixerCtrl->max - rcurValue; + } + elemValue->value[1] = rcurValue; + } + + return HDF_SUCCESS; +} + +static int32_t AudioGetCtrlSwSubReg(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, + enum AudioDeviceType deviceType, void *device) +{ + 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; + } + curValue = (curValue >> mixerCtrl->shift) & mixerCtrl->mask; + if (curValue > mixerCtrl->max || curValue < mixerCtrl->min) { + ADM_LOG_ERR("Audio invalid curValue=%d", curValue); + return HDF_FAILURE; + } + if (mixerCtrl->invert) { + curValue = mixerCtrl->max - curValue; + } + elemValue->value[0] = curValue; + return HDF_SUCCESS; +} + +int32_t AudioGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +{ + enum AudioDeviceType deviceType; + 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."); + return HDF_ERR_INVALID_OBJECT; + } + + codec = AudioKcontrolGetCodec(kcontrol); + accessory = AudioKcontrolGetAccessory(kcontrol); + if (codec != NULL && codec->devData != NULL && codec->devData->Read != NULL) { + deviceType = AUDIO_CODEC_DEVICE; + if (AudioGetCtrlSwSubReg(kcontrol, elemValue, deviceType, codec) || + AudioGetCtrlSwSubRReg(kcontrol, elemValue, deviceType, codec)) { + ADM_LOG_ERR("Audio Codec Get Ctrl Reg fail."); + return HDF_FAILURE; + } + } else { + deviceType = AUDIO_ACCESSORY_DEVICE; + if (AudioGetCtrlSwSubReg(kcontrol, elemValue, deviceType, accessory) || + AudioGetCtrlSwSubRReg(kcontrol, elemValue, deviceType, accessory)) { + ADM_LOG_ERR("Audio Accessory Get Ctrl Reg fail."); + return HDF_FAILURE; + } + } + + ADM_LOG_DEBUG("Get audio ctrl switch successful."); + return HDF_SUCCESS; +} + +static int32_t AiaoGetRightCtrlSw(struct CodecDevice *codec, struct AudioMixerControl *mixerCtrl, + struct AudioCtrlElemValue *elemValue) +{ + int ret; + 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; + } + + return HDF_SUCCESS; +} + +int32_t AiaoGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +{ + int32_t ret; + 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."); + 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."); + 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); + return HDF_FAILURE; + } + curValue = (curValue >> mixerCtrl->shift) & mixerCtrl->mask; + if (curValue > mixerCtrl->max) { + ADM_LOG_ERR("AIAO invalid curValue=%d", curValue); + return HDF_FAILURE; + } + + if (mixerCtrl->invert) { + curValue = mixerCtrl->max - curValue; + } + elemValue->value[0] = curValue; + + ret = AiaoGetRightCtrlSw(codec, mixerCtrl, elemValue); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("AIAO get right ctrl is fail"); + return HDF_FAILURE; + } + + ADM_LOG_DEBUG("Get AIAO ctrl switch successful."); + return HDF_SUCCESS; +} + +static int32_t AudioPutCtrlSwSub(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, + enum AudioDeviceType deviceType, void *device) +{ + 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); + return HDF_ERR_INVALID_OBJECT; + } + + if (mixerCtrl->invert) { + 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; + } + + 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); + return HDF_FAILURE; + } + if (mixerCtrl->invert) { + rvalue = mixerCtrl->max - rvalue; + } + if (mixerCtrl->reg == mixerCtrl->rreg) { + rshift = mixerCtrl->rshift; + } else { + 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 AudioPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +{ + void *device = NULL; + enum AudioDeviceType deviceType; + int32_t ret = HDF_FAILURE; + ADM_LOG_DEBUG("Entry to put audio ctrl switch."); + + 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 = AudioPutCtrlSwSub(kcontrol, elemValue, deviceType, device); + } else if (accessory != NULL && accessory->devData != NULL && accessory->devData->Write != NULL) { + deviceType = AUDIO_ACCESSORY_DEVICE; + device = (void *)accessory; + ret = AudioPutCtrlSwSub(kcontrol, elemValue, deviceType, device); + } + + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("Audio update fail ret=%d", ret); + return HDF_FAILURE; + } + + ADM_LOG_DEBUG("Put audio ctrl switch successful."); + return HDF_SUCCESS; +} + +int32_t AiaoPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +{ + 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."); + 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; + } + + if (mixerCtrl->invert) { + value = mixerCtrl->max - value; + } + + 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); + 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); + 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) +{ + 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_DSP_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; +} diff --git a/model/audio/core/src/audio_host.c b/model/audio/core/src/audio_host.c new file mode 100755 index 000000000..80015a51c --- /dev/null +++ b/model/audio/core/src/audio_host.c @@ -0,0 +1,443 @@ +/* + * 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_host.h" +#include "audio_core.h" +#include "audio_parse.h" +#include "codec_adapter.h" + +#define HDF_LOG_TAG audio_host + +AUDIO_LIST_HEAD(cardManager); + +/* Get a sound card instance */ +struct AudioCard *GetCardInstance(const char *serviceName) +{ + struct AudioCard *audioCard = NULL; + + if (serviceName == NULL) { + ADM_LOG_ERR("serviceName is NULL."); + return NULL; + } + + DLIST_FOR_EACH_ENTRY(audioCard, &cardManager, struct AudioCard, list) { + if (strcmp(audioCard->configData.cardServiceName, serviceName) == 0) { + return audioCard; + } + } + return NULL; +} + +static int32_t AudioCodecDevInit(struct AudioCard *audioCard) +{ + if (audioCard == NULL) { + ADM_LOG_ERR("audioCard is NULL."); + return HDF_ERR_IO; + } + + ADM_LOG_DEBUG("entry."); + struct AudioPcmRuntime *rtd = NULL; + struct CodecDevice *codec = NULL; + rtd = audioCard->rtd; + if (rtd == NULL) { + ADM_LOG_ERR("rtd is NULL."); + 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; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +static int32_t AudioAccessoryDevInit(struct AudioCard *audioCard) +{ + if (audioCard == NULL) { + ADM_LOG_ERR("audioCard is NULL."); + return HDF_ERR_IO; + } + + ADM_LOG_DEBUG("entry."); + struct AudioPcmRuntime *rtd = NULL; + struct AccessoryDevice *accessory = NULL; + rtd = audioCard->rtd; + if (rtd == NULL) { + ADM_LOG_ERR("rtd is NULL."); + 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; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +static int32_t AudioPlatformDevInit(struct AudioCard *audioCard) +{ + struct AudioPcmRuntime *rtd = NULL; + struct PlatformDevice *platform = NULL; + + if (audioCard == NULL) { + ADM_LOG_ERR("audioCard is NULL."); + return HDF_ERR_IO; + } + ADM_LOG_DEBUG("entry."); + + rtd = audioCard->rtd; + if (rtd == NULL) { + ADM_LOG_ERR("Platform rtd is NULL."); + return HDF_ERR_IO; + } + platform = rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->PlatformInit == NULL) { + ADM_LOG_ERR("platform 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); + return HDF_ERR_IO; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +static int32_t AudioCodecDaiDevInit(struct AudioCard *audioCard) +{ + struct AudioPcmRuntime *rtd = NULL; + struct DaiDevice *codecDai = NULL; + + if (audioCard == NULL) { + ADM_LOG_ERR("audioCard is NULL."); + return HDF_ERR_IO; + } + ADM_LOG_DEBUG("entry."); + + rtd = audioCard->rtd; + if (rtd == NULL) { + ADM_LOG_ERR("CodecDai rtd is NULL."); + 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; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +static int32_t AudioAccessoryDaiDevInit(struct AudioCard *audioCard) +{ + struct AudioPcmRuntime *rtd = NULL; + struct DaiDevice *accessoryDai = NULL; + + if (audioCard == NULL) { + ADM_LOG_ERR("audioCard is NULL."); + return HDF_ERR_IO; + } + ADM_LOG_DEBUG("entry."); + + rtd = audioCard->rtd; + if (rtd == NULL) { + ADM_LOG_ERR("accessoryDai rtd is NULL."); + 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; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +static int32_t AudioCpuDaiDevInit(struct AudioCard *audioCard) +{ + struct AudioPcmRuntime *rtd = NULL; + struct DaiDevice *cpuDai = NULL; + + if (audioCard == NULL) { + ADM_LOG_ERR("audioCard is NULL."); + return HDF_ERR_IO; + } + ADM_LOG_DEBUG("entry."); + + rtd = audioCard->rtd; + if (rtd == NULL) { + ADM_LOG_ERR("cpuDai rtd is NULL."); + 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; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +static int32_t AudioDspDaiDevInit(struct AudioCard *audioCard) +{ + struct AudioPcmRuntime *rtd = NULL; + struct DaiDevice *dspDai = NULL; + struct DspDevice *dsp = NULL; + int ret; + + if (audioCard == NULL) { + ADM_LOG_ERR("audioCard is NULL."); + return HDF_ERR_IO; + } + ADM_LOG_DEBUG("dsp init entry."); + + rtd = audioCard->rtd; + if (rtd == NULL) { + ADM_LOG_ERR("dspDai rtd is NULL."); + return HDF_ERR_IO; + } + + 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; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} +static int32_t AudioInitDaiLink(struct AudioCard *audioCard) +{ + if (audioCard == NULL) { + ADM_LOG_ERR("audioCard is NULL."); + return HDF_ERR_IO; + } + ADM_LOG_DEBUG("entry."); + + if (AudioPlatformDevInit(audioCard) || AudioCpuDaiDevInit(audioCard)) { + ADM_LOG_ERR("Platform and CpuDai is NULL."); + return HDF_ERR_IO; + } + + if ((AudioCodecDevInit(audioCard) || AudioCodecDaiDevInit(audioCard)) && + (AudioAccessoryDevInit(audioCard) || AudioAccessoryDaiDevInit(audioCard))) { + ADM_LOG_ERR("codec is NULL."); + return HDF_ERR_IO; + } + + if (AudioDspDaiDevInit(audioCard)) { + ADM_LOG_ERR("Dsp Dai is NULL."); + 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); + } + OsalMemFree(card); +} + +void AudioHostDestroy(struct AudioHost *host) +{ + if (host == NULL) { + return; + } + OsalMemFree(host); +} + +struct AudioHost *AudioHostCreateAndBind(struct HdfDeviceObject *device) +{ + struct AudioHost *audioHost = NULL; + + if (device == NULL) { + ADM_LOG_ERR("device is NULL!"); + return NULL; + } + + audioHost = (struct AudioHost *)OsalMemCalloc(sizeof(*audioHost)); + if (audioHost == NULL) { + ADM_LOG_ERR("Malloc audio host fail!"); + return NULL; + } + audioHost->device = device; + device->service = &audioHost->service; + return audioHost; +} + +/* HdfDriverEntry implementations */ +static int32_t AudioDriverBind(struct HdfDeviceObject *device) +{ + struct AudioHost *audioHost = NULL; + + ADM_LOG_DEBUG("entry."); + if (device == NULL) { + ADM_LOG_ERR("device is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + audioHost = AudioHostCreateAndBind(device); + if (audioHost == NULL) { + ADM_LOG_ERR("audioHost create failed!"); + return HDF_FAILURE; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +static int32_t AudioDriverInit(struct HdfDeviceObject *device) +{ + struct AudioCard *audioCard = NULL; + struct AudioHost *audioHost = NULL; + int32_t ret; + + ADM_LOG_DEBUG("entry."); + if (device == NULL) { + ADM_LOG_ERR("device is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + audioHost = AudioHostFromDevice(device); + if (audioHost == NULL) { + ADM_LOG_ERR("audioHost is NULL."); + return HDF_FAILURE; + } + + audioCard = (struct AudioCard *)OsalMemCalloc(sizeof(*audioCard)); + if (audioCard == NULL) { + ADM_LOG_ERR("Malloc audioCard fail!"); + return HDF_FAILURE; + } + audioHost->priv = audioCard; + /* Get node information through HCS file */ + ret = AudioFillConfigData(device, &(audioCard->configData)); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("AudioFillConfigData fail ret=%d", ret); + return HDF_ERR_IO; + } + + /* Bind specific codec銆乸latform and dai device */ + AudioBindDaiLink(audioCard, &(audioCard->configData)); + if (!audioCard->rtd->complete) { + ADM_LOG_ERR("AudioBindDaiLink fail!"); + return HDF_ERR_IO; + } + + /* Initialize controls list */ + DListHeadInit(&audioCard->controls); + DListHeadInit(&audioCard->components); + DListHeadInit(&audioCard->paths); + DListHeadInit(&audioCard->sapmDirty); + /* Initialize hardware device */ + ret = AudioInitDaiLink(audioCard); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("AudioInitDaiLink fail ret=%d", ret); + return HDF_ERR_IO; + } + + /* sound card added to list */ + DListInsertHead(&audioCard->list, &cardManager); + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +static void AudioDriverRelease(struct HdfDeviceObject *device) +{ + struct AudioHost *audioHost = NULL; + + ADM_LOG_DEBUG("entry."); + if (device == NULL) { + ADM_LOG_ERR("device is NULL."); + return; + } + audioHost = AudioHostFromDevice(device); + if (audioHost == NULL) { + ADM_LOG_ERR("audioHost is NULL."); + return; + } + AudioCardDestroy(audioHost->priv); + AudioHostDestroy(audioHost); + + ADM_LOG_INFO("success."); +} + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_audioDriverEntry = { + .moduleVersion = 1, + .moduleName = "HDF_AUDIO", + .Bind = AudioDriverBind, + .Init = AudioDriverInit, + .Release = AudioDriverRelease, +}; +HDF_INIT(g_audioDriverEntry); diff --git a/model/audio/core/src/audio_parse.c b/model/audio/core/src/audio_parse.c new file mode 100755 index 000000000..7de9056ef --- /dev/null +++ b/model/audio/core/src/audio_parse.c @@ -0,0 +1,60 @@ +/* + * 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_parse.h" + +#define HDF_LOG_TAG audio_parse + +int32_t AudioFillConfigData(struct HdfDeviceObject *device, struct AudioConfigData *configData) +{ + const struct DeviceResourceNode *node = NULL; + struct DeviceResourceIface *drsOps = NULL; + ADM_LOG_DEBUG("Entry."); + + if (device == NULL || configData == NULL) { + ADM_LOG_ERR("Input para check error: device=%p, configData=%p.", device, configData); + return HDF_FAILURE; + } + + node = device->property; + if (node == NULL) { + ADM_LOG_ERR("drs node is NULL."); + return HDF_FAILURE; + } + drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL || drsOps->GetString == NULL) { + ADM_LOG_ERR("AudioFillConfigData: invalid drs ops fail!"); + return HDF_FAILURE; + } + + int32_t serviceRet = drsOps->GetString(node, "serviceName", &(configData->cardServiceName), 0); + int32_t codecRet = drsOps->GetString(node, "codecName", &(configData->codecName), 0); + int32_t platformRet = drsOps->GetString(node, "platformName", &(configData->platformName), 0); + int32_t cpuRet = drsOps->GetString(node, "cpuDaiName", &(configData->cpuDaiName), 0); + int32_t codeDaiRet = drsOps->GetString(node, "codecDaiName", &(configData->codecDaiName), 0); + int32_t dspRet = drsOps->GetString(node, "dspName", &(configData->dspName), 0); + int32_t dspDaiRet = drsOps->GetString(node, "dspDaiName", &(configData->dspDaiName), 0); + int32_t accessoryRet = drsOps->GetString(node, "accessoryName", &(configData->accessoryName), 0); + int32_t accessoryDaiRet = drsOps->GetString(node, "accessoryDaiName", &(configData->accessoryDaiName), 0); + if (serviceRet || codecRet || platformRet || cpuRet || codeDaiRet || + dspRet || dspDaiRet || accessoryRet || accessoryDaiRet) { + ADM_LOG_ERR("Read audioDeviceName fail: serviceRet=%d, codecRet=%d, platformRet=%d, cpuRet=%d, codeDaiRet=%d," + "dspRet=%d, dspDaiRet=%d, accessoryRet=%d, accessoryDaiRet=%s", + serviceRet, codecRet, platformRet, cpuRet, codeDaiRet, dspRet, + dspDaiRet, accessoryRet, accessoryDaiRet); + return HDF_FAILURE; + } + + ADM_LOG_DEBUG("Success! codecName = %s, platformName = %s, cpuDaiName = %s, codecDaiName = %s, " + "dspName = %s, dspDaiName = %s, accessoryName = %s, accessoryDaiName = %s.", + configData->codecName, configData->platformName, configData->cpuDaiName, + configData->codecDaiName, configData->dspName, configData->dspDaiName, + configData->accessoryName, configData->accessoryDaiName); + + return HDF_SUCCESS; +} diff --git a/model/audio/core/src/codec_core.c b/model/audio/core/src/codec_core.c new file mode 100755 index 000000000..22615f5b0 --- /dev/null +++ b/model/audio/core/src/codec_core.c @@ -0,0 +1,166 @@ +/* + * 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" + +#define HDF_LOG_TAG codec_core + +int32_t CodecDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *val) +{ + unsigned long acodecVir; + struct VirtualAddress *virtualAdd = NULL; + AUDIO_DRIVER_LOG_DEBUG("entry"); + + if ((codec == NULL) || (codec->device == NULL) || (val == NULL)) { + AUDIO_DRIVER_LOG_ERR("input param codec or codec->device is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + virtualAdd = (struct VirtualAddress *)codec->device->priv; + if (virtualAdd == NULL) { + AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + acodecVir = virtualAdd->acodecVir; + *val = OSAL_READL((void *)(acodecVir + reg)); + + AUDIO_DRIVER_LOG_DEBUG("success"); + return HDF_SUCCESS; +} + +int32_t CodecDeviceWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t value) +{ + unsigned long acodecVir; + struct VirtualAddress *virtualAdd = NULL; + AUDIO_DRIVER_LOG_DEBUG("entry"); + + if ((codec == NULL) || (codec->device == NULL)) { + AUDIO_DRIVER_LOG_ERR("param codec or codec->device is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + virtualAdd = (struct VirtualAddress *)codec->device->priv; + if (virtualAdd == NULL) { + AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + acodecVir = virtualAdd->acodecVir; + OSAL_WRITEL(value, (void *)(acodecVir + reg)); + + AUDIO_DRIVER_LOG_DEBUG("success"); + return HDF_SUCCESS; +} + +int32_t AiaoDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t *val) +{ + unsigned long aiaoVir; + struct VirtualAddress *virtualAdd = NULL; + AUDIO_DRIVER_LOG_DEBUG("entry"); + + if ((codec == NULL) || (codec->device == NULL) || (val == NULL)) { + AUDIO_DRIVER_LOG_ERR("codec or codec->device is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + virtualAdd = (struct VirtualAddress *)codec->device->priv; + if (virtualAdd == NULL) { + AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + aiaoVir = virtualAdd->aiaoVir; + *val = OSAL_READL((void *)(aiaoVir + reg)); + + AUDIO_DRIVER_LOG_DEBUG("success"); + return HDF_SUCCESS; +} + +int32_t AiaoDeviceWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t value) +{ + unsigned long aiaoVir; + struct VirtualAddress *virtualAdd = NULL; + AUDIO_DRIVER_LOG_DEBUG("entry"); + + if ((codec == NULL) || (codec->device == NULL)) { + AUDIO_DRIVER_LOG_ERR("codec or codec->device is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + virtualAdd = (struct VirtualAddress *)codec->device->priv; + if (virtualAdd == NULL) { + AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + aiaoVir = virtualAdd->aiaoVir; + OSAL_WRITEL(value, (void *)(aiaoVir + reg)); + + AUDIO_DRIVER_LOG_DEBUG("success"); + return HDF_SUCCESS; +} + +int32_t CodecGetServiceName(struct HdfDeviceObject *device, const char **drvCodecName) +{ + const struct DeviceResourceNode *node = NULL; + struct DeviceResourceIface *drsOps = NULL; + int32_t ret; + + if (device == NULL) { + AUDIO_DRIVER_LOG_ERR("input device para is nullptr."); + return HDF_FAILURE; + } + + node = device->property; + if (node == NULL) { + AUDIO_DRIVER_LOG_ERR("node instance is nullptr."); + return HDF_FAILURE; + } + drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL || drsOps->GetString == NULL) { + AUDIO_DRIVER_LOG_ERR("from resouce get drsOps fail!"); + return HDF_FAILURE; + } + + ret = drsOps->GetString(node, "serviceName", drvCodecName, 0); + if (ret != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("read codecServiceName fail!"); + return ret; + } + + return HDF_SUCCESS; +} + +int32_t CodecGetDaiName(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."); + return HDF_FAILURE; + } + + node = device->property; + if (node == NULL) { + AUDIO_DRIVER_LOG_ERR("drs node is NULL."); + return HDF_FAILURE; + } + drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL || drsOps->GetString == NULL) { + AUDIO_DRIVER_LOG_ERR("drs ops failed!"); + return HDF_FAILURE; + } + + ret = drsOps->GetString(node, "codecDaiName", drvDaiName, 0); + if (ret != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("read codecDaiName fail!"); + return ret; + } + + return HDF_SUCCESS; +} diff --git a/model/audio/core/test/unittest/common/audio_common_test.h b/model/audio/core/test/unittest/common/audio_common_test.h new file mode 100755 index 000000000..26881f098 --- /dev/null +++ b/model/audio/core/test/unittest/common/audio_common_test.h @@ -0,0 +1,49 @@ +/* + * 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_COMMON_TEST_H +#define AUDIO_COMMON_TEST_H + +#include "hdf_types.h" + +const int32_t g_testAudioType = 701; // 701 is TEST_AUDIO_TYPE + +enum { + TESTGETCODEC, + TESTGETCARDINSTANCE, + TESTHOSTDESTROY, + TESTGETCCNFIGDATA, + TESTREGISTERDAI, + TESTREGISTERPLATFORM, + TESTREGISTERCODEC, + TESTBINDDAILINK, + TESTDEVICEREGISTER, + TESTREGISTERDSP, + TESTREGISTERACCESSORY, + TESTUPDATEREGBITS, + TESTAIAOUPDATEREGBITS, + TESTKCONTROLGETCODEC, + TESTADDCONTROLS, + TESTADDCONTROL, + TESTDEVICEREADREG, + TESTAIAODEVICEREADREG, + TESTINFOCTRLSW, + TESTGETCTRLSW, + TESTPUTCTRLSW, + TESTAIAOGETCTRLSW, + TESTAIAOPUTCTRLSW, + 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 new file mode 100755 index 000000000..3ea44f759 --- /dev/null +++ b/model/audio/core/test/unittest/common/audio_core_test.cpp @@ -0,0 +1,153 @@ +/* + * 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_common_test.h" +#include +#include "hdf_uhdf_test.h" + +using namespace testing::ext; + +class AudioCoreTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void AudioCoreTest::SetUpTestCase() +{ + HdfTestOpenService(); +} + +void AudioCoreTest::TearDownTestCase() +{ + HdfTestCloseService(); +} + +void AudioCoreTest::SetUp() +{ +} + +void AudioCoreTest::TearDown() +{ +} + +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) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERPLATFORM, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterCodec, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERCODEC, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_BindDaiLink, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTBINDDAILINK, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_SocDeviceRegister, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTDEVICEREGISTER, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_SocRegisterDsp, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERDSP, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterAccessory, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERACCESSORY, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateRegBits, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTUPDATEREGBITS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_AiaoUpdateRegBits, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTAIAOUPDATEREGBITS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_KcontrolGetCodec, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTKCONTROLGETCODEC, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_AddControls, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTADDCONTROLS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_AddControl, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTADDCONTROL, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_DeviceReadReg, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTDEVICEREADREG, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_AiaoDeviceReadReg, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTAIAODEVICEREADREG, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_InfoCtrlSw, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTINFOCTRLSW, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_GetCtrlSw, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTGETCTRLSW, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_PutCtrlSw, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTPUTCTRLSW, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_AiaoGetCtrlSw, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTAIAOGETCTRLSW, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioCoreTest, AudioCoreTest_AiaoPutCtrlSw, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTAIAOPUTCTRLSW, -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 new file mode 100755 index 000000000..52e23e8db --- /dev/null +++ b/model/audio/core/test/unittest/common/audio_host_test.cpp @@ -0,0 +1,51 @@ +/* + * 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_common_test.h" +#include +#include "hdf_uhdf_test.h" + +using namespace testing::ext; + +class AudioHostTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void AudioHostTest::SetUpTestCase() +{ + HdfTestOpenService(); +} + +void AudioHostTest::TearDownTestCase() +{ + HdfTestCloseService(); +} + +void AudioHostTest::SetUp() +{ +} + +void AudioHostTest::TearDown() +{ +} + +HWTEST_F(AudioHostTest, AudioHostTest_GetCodec, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTGETCODEC, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +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 new file mode 100755 index 000000000..560cebd5e --- /dev/null +++ b/model/audio/core/test/unittest/common/audio_parse_test.cpp @@ -0,0 +1,45 @@ +/* + * 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_common_test.h" +#include +#include "hdf_uhdf_test.h" + +using namespace testing::ext; + +class AudioParseTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void AudioParseTest::SetUpTestCase() +{ + HdfTestOpenService(); +} + +void AudioParseTest::TearDownTestCase() +{ + HdfTestCloseService(); +} + +void AudioParseTest::SetUp() +{ +} + +void AudioParseTest::TearDown() +{ +} + +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 new file mode 100755 index 000000000..185bb7bc9 --- /dev/null +++ b/model/audio/device/accessory/include/accessory_adapter.h @@ -0,0 +1,71 @@ +/* + * 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 new file mode 100755 index 000000000..bf2aaaf1f --- /dev/null +++ b/model/audio/device/accessory/src/accessory.c @@ -0,0 +1,99 @@ +/* + * 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 new file mode 100755 index 000000000..4547c4430 --- /dev/null +++ b/model/audio/device/codec/include/codec_adapter.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 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 new file mode 100755 index 000000000..5293eda02 --- /dev/null +++ b/model/audio/device/codec/src/codec.c @@ -0,0 +1,643 @@ +/* + * 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 = AudioInfoCtrlSw, + .Get = AiaoGetCtrlSw, + .Put = AiaoPutCtrlSw, + .privateValue = (unsigned long)&g_audioRegParams[PLAYBACK_VOLUME], + }, { + .iface = AUDIODRV_CTL_ELEM_IFACE_ADC, + .name = "Master Capture Volume", + .Info = AudioInfoCtrlSw, + .Get = AudioGetCtrlSw, + .Put = AudioPutCtrlSw, + .privateValue = (unsigned long)&g_audioRegParams[CAPTURE_VOLUME], + }, { + .iface = AUDIODRV_CTL_ELEM_IFACE_DAC, + .name = "Playback Mute", + .Info = AudioInfoCtrlSw, + .Get = AudioGetCtrlSw, + .Put = AudioPutCtrlSw, + .privateValue = (unsigned long)&g_audioRegParams[PLAYBACK_MUTE], + }, { + .iface = AUDIODRV_CTL_ELEM_IFACE_ADC, + .name = "Capture Mute", + .Info = AudioInfoCtrlSw, + .Get = AudioGetCtrlSw, + .Put = AudioPutCtrlSw, + .privateValue = (unsigned long)&g_audioRegParams[CAPTURE_MUTE], + }, { + .iface = AUDIODRV_CTL_ELEM_IFACE_GAIN, + .name = "Mic Left Gain", + .Info = AudioInfoCtrlSw, + .Get = AudioGetCtrlSw, + .Put = AudioPutCtrlSw, + .privateValue = (unsigned long)&g_audioRegParams[LEFT_GAIN], + }, { + .iface = AUDIODRV_CTL_ELEM_IFACE_GAIN, + .name = "Mic Right Gain", + .Info = AudioInfoCtrlSw, + .Get = AudioGetCtrlSw, + .Put = AudioPutCtrlSw, + .privateValue = (unsigned long)&g_audioRegParams[RIGHT_GAIN], + }, { + .iface = AUDIODRV_CTL_ELEM_IFACE_ACODEC, + .name = "External Codec Enable", + .Info = AudioInfoCtrlSw, + .Get = AudioGetCtrlSw, + .Put = AudioPutCtrlSw, + .privateValue = (unsigned long)&g_audioRegParams[EXTERNAL_CODEC_ENABLE], + }, { + .iface = AUDIODRV_CTL_ELEM_IFACE_ACODEC, + .name = "Internally Codec Enable", + .Info = AudioInfoCtrlSw, + .Get = AudioGetCtrlSw, + .Put = AudioPutCtrlSw, + .privateValue = (unsigned long)&g_audioRegParams[INTERNALLY_CODEC_ENABLE], + }, { + .iface = AUDIODRV_CTL_ELEM_IFACE_AIAO, + .name = "Render Channel Mode", + .Info = AudioInfoCtrlSw, + .Get = AiaoGetCtrlSw, + .Put = AiaoPutCtrlSw, + .privateValue = (unsigned long)&g_audioRegParams[RENDER_CHANNEL_MODE], + }, { + .iface = AUDIODRV_CTL_ELEM_IFACE_AIAO, + .name = "Captrue Channel Mode", + .Info = AudioInfoCtrlSw, + .Get = AiaoGetCtrlSw, + .Put = AiaoPutCtrlSw, + .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 = AudioInfoCtrlSw, + .Get = AudioSapmGetCtrlSw, + .Put = AudioSapmPutCtrlSw, + .privateValue = (unsigned long)&g_audioSapmRegParams[DACL2DACR], + }, +}; + +static struct AudioKcontrol g_audioSapmDACRControls[] = { + { + .iface = AUDIODRV_CTL_ELEM_IFACE_DAC, + .name = "Dacr enable", + .Info = AudioInfoCtrlSw, + .Get = AudioSapmGetCtrlSw, + .Put = AudioSapmPutCtrlSw, + .privateValue = (unsigned long)&g_audioSapmRegParams[DACR2DACL], + }, +}; + +static struct AudioKcontrol g_audioSapmLPGAControls[] = { + { + .iface = AUDIODRV_CTL_ELEM_IFACE_PGA, + .name = "LPGA MIC Switch", + .Info = AudioInfoCtrlSw, + .Get = AudioSapmGetCtrlSw, + .Put = AudioSapmPutCtrlSw, + .privateValue = (unsigned long)&g_audioSapmRegParams[LPGA_MIC], + }, +}; + +static struct AudioKcontrol g_audioSapmRPGAControls[] = { + { + .iface = AUDIODRV_CTL_ELEM_IFACE_PGA, + .name = "RPGA MIC Switch", + .Info = AudioInfoCtrlSw, + .Get = AudioSapmGetCtrlSw, + .Put = AudioSapmPutCtrlSw, + .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 = 0, + }, { + .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)) { + 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/dai_adapter.h b/model/audio/device/soc/include/dai_adapter.h new file mode 100755 index 000000000..d3d767f19 --- /dev/null +++ b/model/audio/device/soc/include/dai_adapter.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 DAI_ADAPTER_H +#define DAI_ADAPTER_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/model/audio/device/soc/include/dsp_adapter.h b/model/audio/device/soc/include/dsp_adapter.h new file mode 100755 index 000000000..9d58ef1ce --- /dev/null +++ b/model/audio/device/soc/include/dsp_adapter.h @@ -0,0 +1,55 @@ +/* + * 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)(struct AudioCard *, void *, struct DspDevice *); + int32_t (*encode)(struct AudioCard *, void *, struct DspDevice *); + int32_t (*Equalizer)(struct AudioCard *, void *, 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 new file mode 100755 index 000000000..4dc4fea0a --- /dev/null +++ b/model/audio/device/soc/include/platform_adapter.h @@ -0,0 +1,136 @@ +/* + * 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 new file mode 100755 index 000000000..afdf81f65 --- /dev/null +++ b/model/audio/device/soc/src/dai.c @@ -0,0 +1,335 @@ +/* + * 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 new file mode 100755 index 000000000..c15908b69 --- /dev/null +++ b/model/audio/device/soc/src/dsp.c @@ -0,0 +1,483 @@ +/* + * 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(struct AudioCard *card, void *buf, struct DspDevice *device); +static int32_t DspEncodeAudioStream(struct AudioCard *card, void *buf, struct DspDevice *device); +static int32_t DspEqualizerActive(struct AudioCard *card, void *buf, 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(struct AudioCard *card, void *buf, struct DspDevice *device) +{ + (void)card; + (void)buf; + (void)device; + AUDIO_DRIVER_LOG_DEBUG("equalizer run!!!"); + return HDF_SUCCESS; +} + +static int32_t DspDecodeAudioStream(struct AudioCard *card, void *buf, struct DspDevice *device) +{ + (void)card; + (void)buf; + (void)device; + AUDIO_DRIVER_LOG_DEBUG("decode run!!!"); + return HDF_SUCCESS; +} + +static int32_t DspEncodeAudioStream(struct AudioCard *card, void *buf, 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 new file mode 100755 index 000000000..1d9033f56 --- /dev/null +++ b/model/audio/device/soc/src/platform.c @@ -0,0 +1,1170 @@ +/* + * 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) +{ + unsigned int 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) +{ + unsigned int 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); + + 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) { + 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) +{ + int buffSize; + + unsigned int 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 new file mode 100755 index 000000000..0420881ee --- /dev/null +++ b/model/audio/dispatch/include/audio_control_dispatch.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_CONTROL_DISPATCH_H +#define AUDIO_CONTROL_DISPATCH_H + +#include "audio_host.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + + +#define AUDIODRV_CTRL_ELEM_TYPE_INTEGER 2 /* integer type */ + +enum ControlDispMethodCmd { + AUDIODRV_CTRL_IOCTRL_ELEM_INFO, + AUDIODRV_CTRL_IOCTRL_ELEM_READ, + AUDIODRV_CTRL_IOCTRL_ELEM_WRITE, + AUDIODRV_CTRL_IOCTRL_ELEM_BUTT, +}; + +typedef int32_t (*ControlDispCmdHandle)(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply); + +struct ControlDispCmdHandleList { + enum ControlDispMethodCmd cmd; + ControlDispCmdHandle func; +}; + +struct ControlHost { + struct IDeviceIoService service; + struct HdfDeviceObject *device; + void *priv; +}; + +static inline struct ControlHost *ControlHostFromDevice(struct HdfDeviceObject *device) +{ + return (device == NULL) ? NULL : (struct ControlHost *)device->service; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* AUDIO_CONTROL_H */ diff --git a/model/audio/dispatch/include/audio_stream_dispatch.h b/model/audio/dispatch/include/audio_stream_dispatch.h new file mode 100755 index 000000000..4c72ddb04 --- /dev/null +++ b/model/audio/dispatch/include/audio_stream_dispatch.h @@ -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. + */ + +#ifndef AUDIO_STREAM_DISP_H +#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" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#define AUDIO_SERVICE_NAME_MAX_LEN 32 + +enum StreamDispMethodCmd { + AUDIO_DRV_PCM_IOCTRL_HW_PARAMS, + AUDIO_DRV_PCM_IOCTRL_RENDER_PREPARE, + AUDIO_DRV_PCM_IOCTRL_CAPTURE_PREPARE, + AUDIO_DRV_PCM_IOCTRL_WRITE, + AUDIO_DRV_PCM_IOCTRL_READ, + AUDIO_DRV_PCM_IOCTRL_RENDER_START, + AUDIO_DRV_PCM_IOCTRL_RENDER_STOP, + AUDIO_DRV_PCM_IOCTRL_CAPTURE_START, + AUDIO_DRV_PCM_IOCTRL_CAPTURE_STOP, + AUDIO_DRV_PCM_IOCTRL_RENDER_PAUSE, + AUDIO_DRV_PCM_IOCTRL_CAPTURE_PAUSE, + AUDIO_DRV_PCM_IOCTRL_RENDER_RESUME, + AUDIO_DRV_PCM_IOCTRL_CAPTURE_RESUME, + 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); + +struct StreamDispCmdHandleList { + enum StreamDispMethodCmd cmd; + StreamDispCmdHandle func; +}; + +struct StreamHost { + struct IDeviceIoService service; + struct HdfDeviceObject *device; + void *priv; +}; + +static inline struct StreamHost *StreamHostFromDevice(struct HdfDeviceObject *device) +{ + return (device == NULL) ? NULL : (struct StreamHost *)device->service; +} + +int32_t StreamDispatch(struct HdfDeviceIoClient *client, int cmdId, + struct HdfSBuf *data, struct HdfSBuf *reply); +void StreamHostDestroy(struct StreamHost *host); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* AUDIO_STREAM_DISP_H */ diff --git a/model/audio/dispatch/src/audio_control_dispatch.c b/model/audio/dispatch/src/audio_control_dispatch.c new file mode 100755 index 000000000..bc5d5d269 --- /dev/null +++ b/model/audio/dispatch/src/audio_control_dispatch.c @@ -0,0 +1,333 @@ +/* + * 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_control_dispatch.h" +#include "audio_sapm.h" + +#define HDF_LOG_TAG audio_control_dispatch + +static struct AudioKcontrol *AudioGetKctrlInstance(const struct AudioCtrlElemId *ctrlElemId) +{ + struct AudioKcontrol *kctrl = NULL; + struct AudioCard *audioCard = NULL; + + if (ctrlElemId == NULL) { + ADM_LOG_ERR("input params check error: ctrlElemId is NULL."); + return NULL; + } + + audioCard = GetCardInstance(ctrlElemId->cardServiceName); + if (audioCard == NULL) { + ADM_LOG_ERR("get kcontrol instance fail!"); + return NULL; + } + + DLIST_FOR_EACH_ENTRY(kctrl, &audioCard->controls, struct AudioKcontrol, list) { + if (strcmp(kctrl->name, ctrlElemId->itemName) != 0) { + continue; + } + if (kctrl->iface != ctrlElemId->iface) { + continue; + } + return kctrl; + } + return NULL; +} + +static int32_t ControlHostElemInfoSub(struct HdfSBuf *rspData, struct AudioCtrlElemId id) +{ + int32_t result; + struct AudioKcontrol *kctrl = NULL; + struct AudioCtrlElemInfo elemInfo; + if (rspData == NULL) { + ADM_LOG_ERR("Input rspData is null."); + return HDF_FAILURE; + } + kctrl = AudioGetKctrlInstance(&id); + if (kctrl == NULL || kctrl->Info == NULL) { + ADM_LOG_ERR("Find kctrl or Info fail!"); + return HDF_FAILURE; + } + + (void)memset_s(&elemInfo, sizeof(struct AudioCtrlElemInfo), 0, sizeof(struct AudioCtrlElemInfo)); + result = kctrl->Info(kctrl, &elemInfo); + if (result != HDF_SUCCESS) { + ADM_LOG_ERR("Get control info fail result=%d", result); + return HDF_FAILURE; + } + + if (!HdfSbufWriteInt32(rspData, elemInfo.type)) { + ADM_LOG_ERR("Write response data type failed!"); + return HDF_FAILURE; + } + if (!HdfSbufWriteInt32(rspData, elemInfo.max)) { + ADM_LOG_ERR("Write response data max failed!"); + return HDF_FAILURE; + } + if (!HdfSbufWriteInt32(rspData, elemInfo.min)) { + ADM_LOG_ERR("Write response data min failed!"); + return HDF_FAILURE; + } + if (!HdfSbufWriteUint32(rspData, elemInfo.count)) { + ADM_LOG_ERR("Write response data count failed!"); + return HDF_FAILURE; + } + ADM_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +static int32_t ControlHostElemInfo(struct HdfDeviceIoClient *client, struct HdfSBuf *reqData, struct HdfSBuf *rspData) +{ + struct AudioCtrlElemId id; + ADM_LOG_DEBUG("entry."); + + if ((client == NULL) || (reqData == NULL)) { + ADM_LOG_ERR("Input ElemInfo params check error: client=%p, reqData=%p.", client, reqData); + return HDF_FAILURE; + } + + (void)memset_s(&id, sizeof(struct AudioCtrlElemId), 0, sizeof(struct AudioCtrlElemId)); + if (!HdfSbufReadInt32(reqData, &id.iface)) { + ADM_LOG_ERR("Read ElemInfo request id failed!"); + return HDF_FAILURE; + } + + if (!(id.cardServiceName = HdfSbufReadString(reqData))) { + ADM_LOG_ERR("Read ElemInfo request cardServiceName failed!"); + return HDF_FAILURE; + } + + if (!(id.itemName = HdfSbufReadString(reqData))) { + ADM_LOG_ERR("Read ElemInfo request itemName failed!"); + return HDF_FAILURE; + } + + if (ControlHostElemInfoSub(rspData, id)) { + ADM_LOG_ERR("ControlHostElemInfoSub failed!"); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static int32_t ControlHostElemRead(struct HdfDeviceIoClient *client, struct HdfSBuf *reqData, struct HdfSBuf *rspData) +{ + struct AudioKcontrol *kctrl = NULL; + struct AudioCtrlElemValue elemValue; + struct AudioCtrlElemId id; + int32_t result; + ADM_LOG_DEBUG("entry."); + + if ((client == NULL) || (reqData == NULL) || (rspData == NULL)) { + ADM_LOG_ERR("Input ElemRead params check error: client=%p, reqData=%p, rspData=%p.", client, reqData, rspData); + return HDF_FAILURE; + } + + (void)memset_s(&id, sizeof(struct AudioCtrlElemId), 0, sizeof(struct AudioCtrlElemId)); + if (!HdfSbufReadInt32(reqData, &id.iface)) { + ADM_LOG_ERR("ElemRead request id failed!"); + return HDF_FAILURE; + } + + if (!(id.cardServiceName = HdfSbufReadString(reqData))) { + ADM_LOG_ERR("ElemRead request cardServiceName failed!"); + return HDF_FAILURE; + } + + if (!(id.itemName = HdfSbufReadString(reqData))) { + ADM_LOG_ERR("ElemRead request itemName failed!"); + return HDF_FAILURE; + } + + kctrl = AudioGetKctrlInstance(&id); + if (kctrl == NULL || kctrl->Get == NULL) { + ADM_LOG_ERR("Find kctrl or Get fail."); + return HDF_FAILURE; + } + + (void)memset_s(&elemValue, sizeof(struct AudioCtrlElemValue), 0, sizeof(struct AudioCtrlElemValue)); + result = kctrl->Get(kctrl, &elemValue); + if (result != HDF_SUCCESS) { + ADM_LOG_ERR("Get elemValue fail result=%d", result); + return HDF_FAILURE; + } + + if (!HdfSbufWriteInt32(rspData, elemValue.value[0])) { + ADM_LOG_ERR("Write response data value[0]=%d failed!", elemValue.value[0]); + return HDF_FAILURE; + } + if (!HdfSbufWriteInt32(rspData, elemValue.value[1])) { + ADM_LOG_ERR("Write response data value[1]=%d failed!", elemValue.value[1]); + return HDF_FAILURE; + } + ADM_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +static int32_t ControlHostElemWrite(struct HdfDeviceIoClient *client, struct HdfSBuf *reqData, struct HdfSBuf *rspData) +{ + struct AudioKcontrol *kctrl = NULL; + struct AudioCtrlElemValue elemValue; + int32_t result; + ADM_LOG_DEBUG("entry."); + + if ((client == NULL) || (reqData == NULL)) { + ADM_LOG_ERR("Input params check error: client=%p, reqData=%p.", client, reqData); + return HDF_FAILURE; + } + (void)rspData; + + (void)memset_s(&elemValue, sizeof(struct AudioCtrlElemValue), 0, sizeof(struct AudioCtrlElemValue)); + if (!HdfSbufReadInt32(reqData, &elemValue.value[0])) { + ADM_LOG_ERR("Read request elemValue failed!"); + return HDF_FAILURE; + } + + if (!HdfSbufReadInt32(reqData, &elemValue.id.iface)) { + ADM_LOG_ERR("Read request id failed!"); + return HDF_FAILURE; + } + + if (!(elemValue.id.cardServiceName = HdfSbufReadString(reqData))) { + ADM_LOG_ERR("Read request cardServiceName failed!"); + return HDF_FAILURE; + } + + if (!(elemValue.id.itemName = HdfSbufReadString(reqData))) { + ADM_LOG_ERR("Read request itemName failed!"); + return HDF_FAILURE; + } + + kctrl = AudioGetKctrlInstance(&elemValue.id); + if (kctrl == NULL || kctrl->Put == NULL) { + ADM_LOG_ERR("Find kctrl or Put fail!"); + return HDF_FAILURE; + } + + result = kctrl->Put(kctrl, &elemValue); + if (result != HDF_SUCCESS) { + ADM_LOG_ERR("Get control value fail result=%d", result); + return HDF_FAILURE; + } + ADM_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +static struct ControlDispCmdHandleList g_controlDispCmdHandle[] = { + {AUDIODRV_CTRL_IOCTRL_ELEM_INFO, ControlHostElemInfo}, + {AUDIODRV_CTRL_IOCTRL_ELEM_READ, ControlHostElemRead}, + {AUDIODRV_CTRL_IOCTRL_ELEM_WRITE, ControlHostElemWrite}, +}; + +static int32_t ControlDispatch(struct HdfDeviceIoClient *client, int cmdId, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + unsigned int i; + + if ((client == NULL) || (data == NULL)) { + ADM_LOG_ERR("Input params check error: client=%p, data=%p.", client, data); + return HDF_FAILURE; + } + + if (cmdId >= AUDIODRV_CTRL_IOCTRL_ELEM_BUTT || cmdId < 0) { + ADM_LOG_ERR("Invalid [cmdId=%d].", cmdId); + return HDF_FAILURE; + } + + AudioSapmRefreshTime(true); + for (i = 0; i < 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); + } + } + return HDF_FAILURE; +} + +static struct ControlHost *ControlHostCreateAndBind(struct HdfDeviceObject *device) +{ + struct ControlHost *controlHost = NULL; + + if (device == NULL) { + ADM_LOG_ERR("Input params check error: device is NULL."); + return NULL; + } + + controlHost = (struct ControlHost *)OsalMemCalloc(sizeof(*controlHost)); + if (controlHost == NULL) { + ADM_LOG_ERR("Malloc controlHost fail!"); + return NULL; + } + controlHost->device = device; + device->service = &controlHost->service; + return controlHost; +} + +static int32_t AudioControlBind(struct HdfDeviceObject *device) +{ + struct ControlHost *controlHost = NULL; + ADM_LOG_DEBUG("entry."); + + if (device == NULL) { + ADM_LOG_ERR("Input params check error: device is NULL."); + return HDF_FAILURE; + } + + controlHost = ControlHostCreateAndBind(device); + if (controlHost == NULL) { + ADM_LOG_ERR("controlHost is NULL."); + return HDF_FAILURE; + } + + controlHost->service.Dispatch = ControlDispatch; + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +static int32_t AudioControlInit(struct HdfDeviceObject *device) +{ + (void)device; + ADM_LOG_INFO("success."); + 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; + + if (device == NULL) { + ADM_LOG_ERR("Input params check error: device is NULL."); + return; + } + + controlHost = ControlHostFromDevice(device); + if (controlHost == NULL) { + ADM_LOG_ERR("controlHost is NULL."); + return; + } + ControlHostDestroy(controlHost); +} + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_audioControlEntry = { + .moduleVersion = 1, + .moduleName = "HDF_AUDIO_CONTROL", + .Bind = AudioControlBind, + .Init = AudioControlInit, + .Release = AudioControlRelease, +}; +HDF_INIT(g_audioControlEntry); diff --git a/model/audio/dispatch/src/audio_stream_dispatch.c b/model/audio/dispatch/src/audio_stream_dispatch.c new file mode 100755 index 000000000..550e84940 --- /dev/null +++ b/model/audio/dispatch/src/audio_stream_dispatch.c @@ -0,0 +1,1068 @@ +/* + * 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_stream_dispatch.h" + +#define HDF_LOG_TAG audio_stream_dispatch + +int32_t HwCpuDaiDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams *params) +{ + if ((audioCard == NULL) || (params == NULL)) { + ADM_LOG_ERR("CpuDai input param is NULL."); + return HDF_FAILURE; + } + + struct AudioPcmRuntime *rtd = audioCard->rtd; + if (rtd == NULL) { + ADM_LOG_ERR("CpuDai audioCard rtd is NULL."); + return HDF_FAILURE; + } + + struct DaiDevice *cpuDai = rtd->cpuDai; + if (cpuDai == NULL || cpuDai->devData == NULL || cpuDai->devData->ops == NULL) { + ADM_LOG_ERR("cpuDai param is NULL."); + return HDF_FAILURE; + } + + /* If there are HwParams function, it will be executed directly. + * If not, skip the if statement and execute in sequence. + */ + if (cpuDai->devData->ops->HwParams != NULL) { + int ret = cpuDai->devData->ops->HwParams(audioCard, params, cpuDai); + if (ret < 0) { + ADM_LOG_ERR("cpuDai hardware params fail ret=%d", ret); + return HDF_ERR_IO; + } + } + + return HDF_SUCCESS; +} + +int32_t HwCodecDaiDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams *params) +{ + if ((audioCard == NULL) || (params == NULL)) { + ADM_LOG_ERR("CodecDai input param is NULL."); + return HDF_FAILURE; + } + + struct AudioPcmRuntime *rtd = audioCard->rtd; + if (rtd == NULL) { + ADM_LOG_ERR("CodecDai audioCard rtd is NULL."); + return HDF_FAILURE; + } + struct DaiDevice *codecDai = rtd->codecDai; + if (codecDai == NULL) { + codecDai = rtd->accessoryDai; + } + if (codecDai == NULL || codecDai->devData == NULL || codecDai->devData->ops == NULL) { + ADM_LOG_ERR("codecDai param is NULL."); + return HDF_FAILURE; + } + + /* If there are HwParams function, it will be executed directly. + * If not, skip the if statement and execute in sequence. + */ + if (codecDai->devData->ops->HwParams != NULL) { + int ret = codecDai->devData->ops->HwParams(audioCard, params, codecDai); + if (ret < 0) { + ADM_LOG_ERR("codecDai hardware params fail ret=%d", ret); + return HDF_ERR_IO; + } + } + + return HDF_SUCCESS; +} + +int32_t HwPlatfromDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams *params) +{ + if ((audioCard == NULL) || (params == NULL)) { + ADM_LOG_ERR("Platfrom input param is NULL."); + return HDF_FAILURE; + } + + struct AudioPcmRuntime *rtd = audioCard->rtd; + if (rtd == NULL) { + ADM_LOG_ERR("audioCard rtd is NULL."); + return HDF_FAILURE; + } + + struct PlatformDevice *platform = rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL) { + ADM_LOG_ERR("platform param is NULL."); + return HDF_FAILURE; + } + + /* If there are HwParams function, it will be executed directly. + * If not, skip the if statement and execute in sequence. + */ + if (platform->devData->ops->HwParams != NULL) { + int ret = platform->devData->ops->HwParams(audioCard, params); + if (ret < 0) { + ADM_LOG_ERR("platform hardware params fail ret=%d", ret); + return HDF_ERR_IO; + } + } + + return HDF_SUCCESS; +} + +int32_t HwParamsDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams *params) +{ + if ((audioCard == NULL) || (params == NULL)) { + ADM_LOG_ERR("input param is NULL."); + return HDF_FAILURE; + } + + /* Traverse through each driver method; Enter if you have, if not, exectue in order */ + if (HwCodecDaiDispatch(audioCard, params) || + HwCpuDaiDispatch(audioCard, params) || + HwPlatfromDispatch(audioCard, params)) { + ADM_LOG_ERR("hardware params fail."); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t HwParamsDataAnalysis(struct HdfSBuf *reqData, struct AudioPcmHwParams *params) +{ + if ((reqData == NULL) || (params == NULL)) { + ADM_LOG_ERR(" input param is NULL."); + return HDF_FAILURE; + } + + if (!HdfSbufReadUint32(reqData, ¶ms->streamType)) { + ADM_LOG_ERR("read request streamType failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadUint32(reqData, ¶ms->channels)) { + ADM_LOG_ERR("read request channels failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadUint32(reqData, ¶ms->rate)) { + ADM_LOG_ERR("read request rate failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadUint32(reqData, ¶ms->periodSize)) { + ADM_LOG_ERR("read request periodSize failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadUint32(reqData, ¶ms->periodCount)) { + ADM_LOG_ERR("read request periodCount failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadUint32(reqData, (uint32_t *)¶ms->format)) { + ADM_LOG_ERR("read request format failed!"); + return HDF_FAILURE; + } + if (!(params->cardServiceName = HdfSbufReadString(reqData))) { + ADM_LOG_ERR("read request cardServiceName failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadUint32(reqData, ¶ms->period)) { + HDF_LOGE("read request perid failed!"); + return HDF_FAILURE; + } + + if (!HdfSbufReadUint32(reqData, ¶ms->frameSize)) { + HDF_LOGE("read request frameSize failed!"); + return HDF_FAILURE; + } + + if (!HdfSbufReadUint32(reqData, (uint32_t *)¶ms->isBigEndian)) { + HDF_LOGE("read request isBigEndian failed!"); + return HDF_FAILURE; + } + + if (!HdfSbufReadUint32(reqData, (uint32_t *)¶ms->isSignedData)) { + HDF_LOGE("read request isSignedData failed!"); + return HDF_FAILURE; + } + + if (!HdfSbufReadUint32(reqData, ¶ms->startThreshold)) { + HDF_LOGE("read request startThreshold failed!"); + return HDF_FAILURE; + } + + if (!HdfSbufReadUint32(reqData, ¶ms->stopThreshold)) { + HDF_LOGE("read request stopThreshold failed!"); + return HDF_FAILURE; + } + + if (!HdfSbufReadUint32(reqData, ¶ms->silenceThreshold)) { + HDF_LOGE("read request silenceThreshold failed!"); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +int32_t StreamHostHwParams(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmHwParams params; + struct StreamHost *streamHost = NULL; + struct AudioCard *audioCard = NULL; + char *cardName = NULL; + int ret; + ADM_LOG_DEBUG("entry."); + + if ((client == NULL) || (data == NULL)) { + ADM_LOG_ERR("input param is NULL."); + return HDF_FAILURE; + } + (void)reply; + + streamHost = StreamHostFromDevice(client->device); + if (streamHost == NULL) { + ADM_LOG_ERR("renderHost is NULL"); + return HDF_FAILURE; + } + + cardName = (char *)OsalMemCalloc(sizeof(char) * BUFF_SIZE_MAX); + if (cardName == NULL) { + ADM_LOG_ERR("malloc cardServiceName fail!"); + return HDF_FAILURE; + } + streamHost->priv = cardName; + + (void)memset_s(¶ms, sizeof(struct AudioPcmHwParams), 0, sizeof(struct AudioPcmHwParams)); + ret = HwParamsDataAnalysis(data, ¶ms); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("hwparams data analysis failed ret=%d", ret); + return HDF_FAILURE; + } + + if (memcpy_s(cardName, BUFF_SIZE_MAX, params.cardServiceName, BUFF_SIZE_MAX) != EOK) { + ADM_LOG_ERR("memcpy cardName failed."); + return HDF_FAILURE; + } + + audioCard = GetCardInstance(params.cardServiceName); + if (audioCard == NULL) { + ADM_LOG_ERR("get card instance fail."); + return HDF_FAILURE; + } + + ret = HwParamsDispatch(audioCard, ¶ms); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("hwparams dispatch failed ret=%d", ret); + return HDF_FAILURE; + } + ADM_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +static struct AudioCard *StreamHostGetCardInstance(const struct HdfDeviceIoClient *client) +{ + char *cardName = NULL; + struct StreamHost *streamHost = NULL; + struct AudioCard *audioCard = NULL; + + if (client == NULL) { + ADM_LOG_ERR("input param is NULL."); + return NULL; + } + + streamHost = StreamHostFromDevice(client->device); + if (streamHost == NULL) { + ADM_LOG_ERR("streamHost is NULL"); + return NULL; + } + + cardName = (char *)streamHost->priv; + if (cardName == NULL) { + ADM_LOG_ERR("streamHost priv is NULL."); + return NULL; + } + + audioCard = GetCardInstance(cardName); + if (audioCard == NULL) { + ADM_LOG_ERR("get card instance fail."); + return NULL; + } + + return audioCard; +} + +int32_t StreamHostCapturePrepare(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct PlatformDevice *platform = NULL; + struct AudioCard *audioCard = NULL; + int ret; + ADM_LOG_DEBUG("entry."); + + if (client == NULL) { + ADM_LOG_ERR("CapturePrepare input param is NULL."); + return HDF_FAILURE; + } + + (void)data; + (void)reply; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("CapturePrepare get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + platform = rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL || + platform->devData->ops->CapturePrepare == NULL) { + ADM_LOG_ERR("audioCard rtd platform is NULL."); + return HDF_FAILURE; + } + + ret = platform->devData->ops->CapturePrepare(audioCard); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform CapturePrepare fail ret=%d", ret); + return HDF_ERR_IO; + } + + ADM_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostRenderPrepare(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct PlatformDevice *platform = NULL; + struct AudioCard *audioCard = NULL; + int ret; + ADM_LOG_DEBUG("entry."); + + if (client == NULL) { + ADM_LOG_ERR("RenderPrepare input param is NULL."); + return HDF_FAILURE; + } + + (void)data; + (void)reply; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("RenderPrepare get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + platform = rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL || + platform->devData->ops->RenderPrepare == NULL) { + ADM_LOG_ERR("audioCard rtd platform is NULL."); + return HDF_FAILURE; + } + + ret = platform->devData->ops->RenderPrepare(audioCard); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform RenderPrepare fail ret=%d", ret); + return HDF_ERR_IO; + } + + ADM_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +static int32_t StreamTransferWrite(struct AudioCard *audioCard, struct AudioTxData *transfer) +{ + struct PlatformDevice *platform = NULL; + int32_t ret; + + if (audioCard == NULL || audioCard->rtd == NULL || transfer == 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->Write(audioCard, transfer); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform write fail ret=%d", ret); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +int32_t StreamHostWrite(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioTxData transfer; + struct AudioCard *audioCard = NULL; + int32_t ret; + uint32_t dataSize = 0; + ADM_LOG_DEBUG("entry."); + + if (client == NULL || reply == NULL) { + ADM_LOG_ERR("input param is NULL."); + return HDF_FAILURE; + } + + if (!HdfSbufReadUint32(data, (uint32_t *)&(transfer.frames))) { + ADM_LOG_ERR("read request frames failed!"); + return HDF_FAILURE; + } + if (!HdfSbufReadBuffer(data, (const void **)&(transfer.buf), &dataSize)) { + ADM_LOG_ERR("read request buf failed!"); + return HDF_FAILURE; + } + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("get card instance or rtd fail."); + return HDF_FAILURE; + } + + ret = StreamTransferWrite(audioCard, &transfer); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("write reg value fail ret=%d", ret); + return HDF_FAILURE; + } + + if (!HdfSbufWriteUint32(reply, (uint32_t)(transfer.status))) { + ADM_LOG_ERR("read response status failed!"); + return HDF_FAILURE; + } + ADM_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostRead(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct PlatformDevice *platform = NULL; + struct AudioCard *audioCard = NULL; + struct AudioRxData rxData; + int ret; + ADM_LOG_DEBUG("entry."); + + if (client == NULL || reply == NULL) { + ADM_LOG_ERR("input param is NULL."); + return HDF_FAILURE; + } + (void)data; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + platform = rtd->platform; + if (platform == NULL || platform->devData == NULL || + platform->devData->ops == NULL || platform->devData->ops->Read == NULL) { + ADM_LOG_ERR("audioCard rtd platform is NULL."); + return HDF_FAILURE; + } + + ret = platform->devData->ops->Read(audioCard, &rxData); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform read fail ret=%d", ret); + return HDF_FAILURE; + } + + if (!HdfSbufWriteUint32(reply, (uint32_t)(rxData.status))) { + ADM_LOG_ERR("write request data status failed!"); + return HDF_FAILURE; + } + + if (!HdfSbufWriteBuffer(reply, rxData.buf, (uint32_t)(rxData.bufSize))) { + ADM_LOG_ERR("write request data buf failed!"); + return HDF_FAILURE; + } + + if (!HdfSbufWriteUint32(reply, (uint32_t)(rxData.frames))) { + ADM_LOG_ERR("write frames failed!"); + return HDF_FAILURE; + } + + ADM_LOG_DEBUG("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostRenderStart(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct PlatformDevice *platform = NULL; + struct AudioCard *audioCard = NULL; + int ret; + ADM_LOG_DEBUG("entry."); + + if (client == NULL) { + ADM_LOG_ERR("RenderStart input param is NULL."); + return HDF_FAILURE; + } + + (void)data; + (void)reply; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("RenderStart get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + platform = rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL || + platform->devData->ops->RenderStart == NULL) { + ADM_LOG_ERR("audioCard rtd platform is NULL."); + return HDF_FAILURE; + } + + ret = platform->devData->ops->RenderStart(audioCard); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform render start fail ret=%d", ret); + return HDF_ERR_IO; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostCaptureStart(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct PlatformDevice *platform = NULL; + struct AudioCard *audioCard = NULL; + int ret; + ADM_LOG_DEBUG("entry."); + + if (client == NULL) { + ADM_LOG_ERR("CaptureStart input param is NULL."); + return HDF_FAILURE; + } + + (void)data; + (void)reply; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("CaptureStart get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + platform = rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL || + platform->devData->ops->CaptureStart == NULL) { + ADM_LOG_ERR("audioCard rtd platform is NULL."); + return HDF_FAILURE; + } + + ret = platform->devData->ops->CaptureStart(audioCard); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform capture start fail ret=%d", ret); + return HDF_ERR_IO; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostRenderStop(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct PlatformDevice *platform = NULL; + struct AudioCard *audioCard = NULL; + int ret; + ADM_LOG_DEBUG("entry."); + + if (client == NULL) { + ADM_LOG_ERR("RenderStop input param is NULL."); + return HDF_FAILURE; + } + + (void)data; + (void)reply; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("RenderStop get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + platform = rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL || + platform->devData->ops->RenderStop == NULL) { + ADM_LOG_ERR("audioCard rtd platform is NULL."); + return HDF_FAILURE; + } + + ret = platform->devData->ops->RenderStop(audioCard); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform render stop fail ret=%d", ret); + return HDF_ERR_IO; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostCaptureStop(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct PlatformDevice *platform = NULL; + struct AudioCard *audioCard = NULL; + int ret; + ADM_LOG_DEBUG("entry."); + + if (client == NULL) { + ADM_LOG_ERR("CaptureStop input param is NULL."); + return HDF_FAILURE; + } + + (void)data; + (void)reply; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("CaptureStop get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + platform = rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL || + platform->devData->ops->CaptureStop == NULL) { + ADM_LOG_ERR("audioCard rtd platform is NULL."); + return HDF_FAILURE; + } + + ret = platform->devData->ops->CaptureStop(audioCard); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform capture stop fail ret=%d", ret); + return HDF_ERR_IO; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostRenderPause(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct PlatformDevice *platform = NULL; + struct AudioCard *audioCard = NULL; + int ret; + ADM_LOG_DEBUG("entry."); + + if (client == NULL) { + ADM_LOG_ERR("RenderPause input param is NULL."); + return HDF_FAILURE; + } + + (void)data; + (void)reply; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("RenderPause get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + platform = rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL || + platform->devData->ops->RenderPause == NULL) { + ADM_LOG_ERR("audioCard rtd platform is NULL."); + return HDF_FAILURE; + } + + ret = platform->devData->ops->RenderPause(audioCard); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform render pause fail ret=%d", ret); + return HDF_ERR_IO; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostCapturePause(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct PlatformDevice *platform = NULL; + struct AudioCard *audioCard = NULL; + int ret; + ADM_LOG_DEBUG("entry."); + + if (client == NULL) { + ADM_LOG_ERR("CapturePause input param is NULL."); + return HDF_FAILURE; + } + + (void)data; + (void)reply; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("CapturePause get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + platform = rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL || + platform->devData->ops->CapturePause == NULL) { + ADM_LOG_ERR("audioCard rtd platform is NULL."); + return HDF_FAILURE; + } + + ret = platform->devData->ops->CapturePause(audioCard); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform captur pause fail ret=%d", ret); + return HDF_ERR_IO; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostRenderResume(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct PlatformDevice *platform = NULL; + struct AudioCard *audioCard = NULL; + int ret; + ADM_LOG_DEBUG("entry."); + + if (client == NULL) { + ADM_LOG_ERR("RenderResume input param is NULL."); + return HDF_FAILURE; + } + + (void)data; + (void)reply; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("RenderResume get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + platform = rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL || + platform->devData->ops->RenderResume == NULL) { + ADM_LOG_ERR("audioCard rtd platform is NULL."); + return HDF_FAILURE; + } + + ret = platform->devData->ops->RenderResume(audioCard); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform RenderResume fail ret=%d", ret); + return HDF_ERR_IO; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostCaptureResume(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct PlatformDevice *platform = NULL; + struct AudioCard *audioCard = NULL; + int ret; + ADM_LOG_DEBUG("entry."); + + if (client == NULL) { + ADM_LOG_ERR("CaptureResume input param is NULL."); + return HDF_FAILURE; + } + + (void)data; + (void)reply; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("CaptureResume get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + platform = rtd->platform; + if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL || + platform->devData->ops->CaptureResume == NULL) { + ADM_LOG_ERR("audioCard rtd platform is NULL."); + return HDF_FAILURE; + } + + ret = platform->devData->ops->CaptureResume(audioCard); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("platform CaptureResume fail ret=%d", ret); + return HDF_ERR_IO; + } + + ADM_LOG_INFO("success."); + return HDF_SUCCESS; +} + +int32_t StreamHostDspDecode(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct DspDevice *dspDev = NULL; + struct AudioCard *audioCard = NULL; + int ret; + ADM_LOG_DEBUG("Dsp Decode Entry."); + + if (client == NULL) { + ADM_LOG_ERR("DspDecode input param is NULL."); + return HDF_FAILURE; + } + + (void)reply; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("DspDecode get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + dspDev = rtd->dsp; + if (dspDev == NULL || dspDev->devData == NULL || dspDev->devData->decode == NULL) { + ADM_LOG_ERR("audioCard rtd dsp is NULL."); + return HDF_FAILURE; + } + + ret = dspDev->devData->decode(audioCard, (void*)data, dspDev); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("DeCode render pause fail ret=%d", ret); + return HDF_ERR_IO; + } + + ADM_LOG_INFO("Decode Success."); + return HDF_SUCCESS; +} + +int32_t StreamHostDspEncode(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct DspDevice *dspDev = NULL; + struct AudioCard *audioCard = NULL; + int ret; + ADM_LOG_DEBUG("Dsp Encode Entry."); + + if (client == NULL) { + ADM_LOG_ERR("DspEncode input param is NULL."); + return HDF_FAILURE; + } + + (void)reply; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("DspEncode get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + dspDev = rtd->dsp; + if (dspDev == NULL || dspDev->devData == NULL || dspDev->devData->encode == NULL) { + ADM_LOG_ERR("audioCard rtd dsp is NULL."); + return HDF_FAILURE; + } + + ret = dspDev->devData->encode(audioCard, (void*)data, dspDev); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("EnCode render pause fail ret=%d", ret); + return HDF_ERR_IO; + } + + ADM_LOG_INFO("Encode Success."); + return HDF_SUCCESS; +} + +int32_t StreamHostDspEqualizer(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct AudioPcmRuntime *rtd = NULL; + struct DspDevice *dspDev = NULL; + struct AudioCard *audioCard = NULL; + int ret; + ADM_LOG_DEBUG("Dsp Equalizer Entry."); + + if (client == NULL) { + ADM_LOG_ERR("DspEqualizer input param is NULL."); + return HDF_FAILURE; + } + + (void)reply; + + audioCard = StreamHostGetCardInstance(client); + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("DspEqualizer get card instance or rtd fail."); + return HDF_FAILURE; + } + rtd = audioCard->rtd; + + dspDev = rtd->dsp; + if (dspDev == NULL || dspDev->devData == NULL || dspDev->devData->Equalizer == NULL) { + ADM_LOG_ERR("audioCard rtd dsp is NULL."); + return HDF_FAILURE; + } + + ret = dspDev->devData->Equalizer(audioCard, (void*)data, dspDev); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("Equalizer render pause fail ret=%d", ret); + return HDF_ERR_IO; + } + + ADM_LOG_INFO("Equalizer Success."); + return HDF_SUCCESS; +} + +static struct StreamDispCmdHandleList g_streamDispCmdHandle[] = { + {AUDIO_DRV_PCM_IOCTRL_HW_PARAMS, StreamHostHwParams}, + {AUDIO_DRV_PCM_IOCTRL_RENDER_PREPARE, StreamHostRenderPrepare}, + {AUDIO_DRV_PCM_IOCTRL_CAPTURE_PREPARE, StreamHostCapturePrepare}, + {AUDIO_DRV_PCM_IOCTRL_WRITE, StreamHostWrite}, + {AUDIO_DRV_PCM_IOCTRL_READ, StreamHostRead}, + {AUDIO_DRV_PCM_IOCTRL_RENDER_START, StreamHostRenderStart}, + {AUDIO_DRV_PCM_IOCTRL_RENDER_STOP, StreamHostRenderStop}, + {AUDIO_DRV_PCM_IOCTRL_CAPTURE_START, StreamHostCaptureStart}, + {AUDIO_DRV_PCM_IOCTRL_CAPTURE_STOP, StreamHostCaptureStop}, + {AUDIO_DRV_PCM_IOCTRL_RENDER_PAUSE, StreamHostRenderPause}, + {AUDIO_DRV_PCM_IOCTRL_CAPTURE_PAUSE, StreamHostCapturePause}, + {AUDIO_DRV_PCM_IOCTRL_RENDER_RESUME, StreamHostRenderResume}, + {AUDIO_DRV_PCM_IOCTRL_CAPTURE_RESUME, StreamHostCaptureResume}, + {AUDIO_DRV_PCM_IOCTRL_DSP_DECODE, StreamHostDspDecode}, + {AUDIO_DRV_PCM_IOCTRL_DSP_ENCODE, StreamHostDspEncode}, + {AUDIO_DRV_PCM_IOCTRL_DSP_EQUALIZER, StreamHostDspEqualizer}, +}; + +int32_t StreamDispatch(struct HdfDeviceIoClient *client, int cmdId, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + unsigned int i; + + if ((client == NULL) || (data == NULL) || (reply == NULL)) { + return HDF_ERR_INVALID_PARAM; + } + + if (cmdId >= AUDIO_DRV_PCM_IOCTRL_BUTT || cmdId < 0) { + ADM_LOG_ERR("invalid [cmdId=%d]", cmdId); + return HDF_FAILURE; + } + + for (i = 0; i < sizeof(g_streamDispCmdHandle) / sizeof(g_streamDispCmdHandle[0]); ++i) { + if ((cmdId == (int)(g_streamDispCmdHandle[i].cmd)) && (g_streamDispCmdHandle[i].func != NULL)) { + return g_streamDispCmdHandle[i].func(client, data, reply); + } + } + return HDF_FAILURE; +} + +static struct StreamHost *StreamHostCreateAndBind(struct HdfDeviceObject *device) +{ + if (device == NULL) { + return NULL; + } + + struct StreamHost *streamHost = (struct StreamHost *)OsalMemCalloc(sizeof(*streamHost)); + if (streamHost == NULL) { + ADM_LOG_ERR("malloc host fail!"); + return NULL; + } + streamHost->device = device; + device->service = &streamHost->service; + return streamHost; +} + +static int32_t AudioStreamBind(struct HdfDeviceObject *device) +{ + ADM_LOG_DEBUG("entry!"); + if (device == NULL) { + return HDF_ERR_INVALID_PARAM; + } + + struct StreamHost *streamHost = StreamHostCreateAndBind(device); + if (streamHost->device == NULL) { + ADM_LOG_ERR("StreamHostCreateAndBind failed"); + return HDF_FAILURE; + } + + streamHost->service.Dispatch = StreamDispatch; + + ADM_LOG_INFO("success!"); + return HDF_SUCCESS; +} + +static int32_t AudioStreamInit(struct HdfDeviceObject *device) +{ + struct StreamHost *streamHost = NULL; + + if (device == NULL) { + ADM_LOG_ERR("device is NULL"); + return HDF_FAILURE; + } + ADM_LOG_DEBUG("entry."); + + streamHost = StreamHostFromDevice(device); + if (streamHost == NULL) { + ADM_LOG_ERR("renderHost is NULL"); + return HDF_FAILURE; + } + + ADM_LOG_INFO("Success!"); + 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) { + ADM_LOG_ERR("device is NULL"); + return; + } + + struct StreamHost *streamHost = StreamHostFromDevice(device); + if (streamHost == NULL) { + ADM_LOG_ERR("renderHost is NULL"); + return; + } + + StreamParamDestroy(streamHost->priv); + StreamHostDestroy(streamHost); +} + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_audioStreamEntry = { + .moduleVersion = 1, + .moduleName = "HDF_AUDIO_STREAM", + .Bind = AudioStreamBind, + .Init = AudioStreamInit, + .Release = AudioStreamRelease, +}; +HDF_INIT(g_audioStreamEntry); 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 new file mode 100755 index 000000000..33fd4422f --- /dev/null +++ b/model/audio/dispatch/test/unittest/common/audio_stream_dispatch_test.cpp @@ -0,0 +1,51 @@ +/* + * 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_common_test.h" +#include +#include "hdf_uhdf_test.h" + +using namespace testing::ext; + +class AudioStreamDispatchTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void AudioStreamDispatchTest::SetUpTestCase() +{ + HdfTestOpenService(); +} + +void AudioStreamDispatchTest::TearDownTestCase() +{ + HdfTestCloseService(); +} + +void AudioStreamDispatchTest::SetUp() +{ +} + +void AudioStreamDispatchTest::TearDown() +{ +} + +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 new file mode 100755 index 000000000..c7a452206 --- /dev/null +++ b/model/audio/sapm/include/audio_sapm.h @@ -0,0 +1,216 @@ +/* + * 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_SAPM_H +#define AUDIO_SAPM_H + +#include "audio_core.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#define SAPM_POLL_TIME 10000 /* 10s */ +#define SAPM_SLEEP_TIME (3 * 60000) /* 3min */ + +#define MIXER_REG_ADDR 10 /* mixer address -- Temporarily defined as this value */ + +#define SAPM_POWER_DOWN 0 +#define SAPM_POWER_UP 1 + +#define CONNECT_CODEC_PIN 1 +#define UNCONNECT_CODEC_PIN 0 + +#define EXIST_EXTERNAL_WIDGET 1 +#define UNEXIST_EXTERNAL_WIDGET 1 + +#define CONNECT_SINK_AND_SOURCE 1 +#define UNCONNECT_SINK_AND_SOURCE 0 + +/* sapm widget types */ +enum AudioSapmType { + AUDIO_SAPM_INPUT = 0, /* input pin */ + AUDIO_SAPM_OUTPUT, /* output pin */ + AUDIO_SAPM_MUX, /* selects 1 analog signal from many inputs */ + AUDIO_SAPM_VIRT_MUX, /* virtual version of snd_soc_dapm_mux */ + AUDIO_SAPM_VALUE_MUX, /* selects 1 analog signal from many inputs */ + AUDIO_SAPM_MIXER, /* mixes several analog signals together */ + AUDIO_SAPM_MIXER_NAMED_CTRL, /* mixer with named controls */ + AUDIO_SAPM_PGA, /* programmable gain/attenuation (volume) */ + AUDIO_SAPM_OUT_DRV, /* output driver */ + AUDIO_SAPM_ADC, /* analog to digital converter */ + AUDIO_SAPM_DAC, /* digital to analog converter */ + AUDIO_SAPM_MICBIAS, /* microphone bias (power) */ + AUDIO_SAPM_MIC, /* microphone */ + AUDIO_SAPM_HP, /* headphones */ + AUDIO_SAPM_SPK, /* speaker */ + AUDIO_SAPM_LINE, /* line input/output */ + AUDIO_SAPM_ANALOG_SWITCH, /* analog switch */ + AUDIO_SAPM_VMID, /* codec bias/vmid - to minimise pops */ + AUDIO_SAPM_PRE, /* machine specific pre component - exec first */ + AUDIO_SAPM_POST, /* machine specific post component - exec last */ + AUDIO_SAPM_SUPPLY, /* power/clock supply */ + AUDIO_SAPM_AIF_IN, /* audio interface input */ + AUDIO_SAPM_AIF_OUT, /* audio interface output */ +}; + +/* component has no PM register bit */ +#define AUDIO_SAPM_NOPM (-1) + +/* dapm stream operations */ +#define AUDIO_SAPM_STREAM_NOP 0x0 +#define AUDIO_SAPM_STREAM_START 0x1 +#define AUDIO_SAPM_STREAM_STOP 0x2 +#define AUDIO_SAPM_STREAM_SUSPEND 0x4 +#define AUDIO_SAPM_STREAM_RESUME 0x8 +#define AUDIO_SAPM_STREAM_PAUSE_PUSH 0x10 +#define AUDIO_SAPM_STREAM_PAUSE_RELEASE 0x20 + +/* sapm event types */ +#define AUDIO_SAPM_PRE_PMU 0x1 /* before component power up */ +#define AUDIO_SAPM_POST_PMU 0x2 /* after component power up */ +#define AUDIO_SAPM_PRE_PMD 0x4 /* before component power down */ +#define AUDIO_SAPM_POST_PMD 0x8 /* after component power down */ +#define AUDIO_SAPM_PRE_REG 0x10 /* before audio path setup */ +#define AUDIO_SAPM_POST_REG 0x20 /* after audio path setup */ +#define AUDIO_SAPM_PRE_POST_PMD (AUDIO_SAPM_PRE_PMD | AUDIO_SAPM_POST_PMD) + +enum AudioBiasLevel { + AUDIO_BIAS_OFF = 0, + AUDIO_BIAS_STANDBY = 1, + AUDIO_BIAS_PREPARE = 2, + AUDIO_BIAS_ON = 3, +}; + +/* SAPM context */ +struct AudioSapmContext { + int32_t componentNum; /* number of components in this context */ + enum AudioBiasLevel biasLevel; + enum AudioBiasLevel suspendBiasLevel; + + struct CodecDevice *codec; /* parent codec */ + struct PlatformDevice *platform; /* parent platform */ + struct AudioCard *card; /* parent card */ + + /* used during SAPM updates */ + enum AudioBiasLevel targetBiasLevel; + struct DListHead list; +}; + +/* enumerated kcontrol */ +struct AudioEnumKcontrol { + uint32_t reg; + uint32_t reg2; + uint8_t shiftLeft; + uint8_t shiftRight; + uint32_t max; + uint32_t mask; + const char * const *texts; + const uint32_t *values; + void *sapm; +}; + +/* sapm audio path between two components */ +struct AudioSapmpath { + char *name; + + /* source (input) and sink (output) components */ + struct AudioSapmComponent *source; + struct AudioSapmComponent *sink; + struct AudioKcontrol *kcontrol; + + /* status */ + uint8_t connect; /* source and sink components are connected */ + uint8_t walked; /* path has been walked */ + uint8_t weak; /* path ignored for power management */ + + int32_t (*connected)(struct AudioSapmComponent *source, struct AudioSapmComponent *sink); + + struct DListHead listSource; + struct DListHead listSink; + struct DListHead list; +}; + +/* sapm component */ +struct AudioSapmComponent { + enum AudioSapmType sapmType; + char *componentName; /* component name */ + char *streamName; /* stream name */ + struct AudioSapmContext *sapm; + struct CodecDevice *codec; /* parent codec */ + struct AccessoryDevice *accessory; /* parent accessory */ + struct PlatformDevice *platform; /* parent platform */ + + /* sapm control */ + int16_t reg; /* negative reg = no direct sapm */ + uint8_t shift; /* bits to shift */ + uint8_t invert; /* invert the power bit */ + uint8_t mask; + uint8_t connected; /* connected codec pin */ + uint8_t external; /* has external components */ + uint8_t active; /* active stream on DAC, ADC's */ + uint8_t newPower; /* power checked this run */ + uint8_t power; + uint8_t newCpt; + + /* external events */ + uint16_t eventFlags; /* flags to specify event types */ + int32_t (*Event)(struct AudioSapmComponent*, struct AudioKcontrol *, int32_t); + + /* power check callback */ + int32_t (*PowerCheck)(const struct AudioSapmComponent *); + + /* kcontrols that relate to this component */ + int32_t kcontrolsNum; + struct AudioKcontrol *kcontrolNews; + struct AudioKcontrol **kcontrols; + + struct DListHead list; + + /* component input and outputs */ + struct DListHead sources; + struct DListHead sinks; + + /* used during SAPM updates */ + struct DListHead powerList; + struct DListHead dirty; + + /* reserve clock interface */ + int32_t (*PowerClockOp)(struct AudioSapmComponent *); +}; + +struct AudioSapmRoute { + const char *sink; + const char *control; + const char *source; + + /* Note: currently only supported for links where source is a supply */ + uint32_t (*Connected)(struct AudioSapmComponent *source, + struct AudioSapmComponent *sink); +}; + +int32_t AudioSapmNewComponents(struct AudioCard *audioCard, + const struct AudioSapmComponent *component, int32_t cptMaxNum); +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 AudioSapmPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +extern int32_t AudioSapmGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* AUDIO_SAPM_H */ diff --git a/model/audio/sapm/src/audio_sapm.c b/model/audio/sapm/src/audio_sapm.c new file mode 100755 index 000000000..34a01d03d --- /dev/null +++ b/model/audio/sapm/src/audio_sapm.c @@ -0,0 +1,1230 @@ +/* + * 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_sapm.h" +#include "osal_io.h" +#include "osal_time.h" +#include "osal_timer.h" + +#define HDF_LOG_TAG audio_sapm + +static void AudioSapmEnterSleep(uintptr_t para); + +/* power up sequences */ +static int32_t g_audioSapmPowerUpSeq[] = { + [AUDIO_SAPM_PRE] = 0, /* 0 is audio sapm power up sequences */ + [AUDIO_SAPM_SUPPLY] = 1, /* 1 is audio sapm power up sequences */ + [AUDIO_SAPM_MICBIAS] = 2, /* 2 is audio sapm power up sequences */ + [AUDIO_SAPM_AIF_IN] = 3, /* 3 is audio sapm power up sequences */ + [AUDIO_SAPM_AIF_OUT] = 3, /* 3 is audio sapm power up sequences */ + [AUDIO_SAPM_MIC] = 4, /* 4 is audio sapm power up sequences */ + [AUDIO_SAPM_MUX] = 5, /* 5 is audio sapm power up sequences */ + [AUDIO_SAPM_VIRT_MUX] = 5, /* 5 is audio sapm power up sequences */ + [AUDIO_SAPM_VALUE_MUX] = 5, /* 5 is audio sapm power up sequences */ + [AUDIO_SAPM_DAC] = 6, /* 6 is audio sapm power up sequences */ + [AUDIO_SAPM_MIXER] = 7, /* 7 is audio sapm power up sequences */ + [AUDIO_SAPM_MIXER_NAMED_CTRL] = 7, /* 7 is audio sapm power up sequences */ + [AUDIO_SAPM_PGA] = 8, /* 8 is audio sapm power up sequences */ + [AUDIO_SAPM_ADC] = 9, /* 9 is audio sapm power up sequences */ + [AUDIO_SAPM_OUT_DRV] = 10, /* 10 is audio sapm power up sequences */ + [AUDIO_SAPM_HP] = 10, /* 10 is audio sapm power up sequences */ + [AUDIO_SAPM_SPK] = 10, /* 10 is audio sapm power up sequences */ + [AUDIO_SAPM_POST] = 11, /* 11 is audio sapm power up sequences */ +}; + +/* power down sequences */ +static int32_t g_audioSapmPowerDownSeq[] = { + [AUDIO_SAPM_PRE] = 0, /* 0 is audio sapm power down sequences */ + [AUDIO_SAPM_ADC] = 1, /* 1 is audio sapm power down sequences */ + [AUDIO_SAPM_HP] = 2, /* 2 is audio sapm power down sequences */ + [AUDIO_SAPM_SPK] = 2, /* 2 is audio sapm power down sequences */ + [AUDIO_SAPM_OUT_DRV] = 2, /* 2 is audio sapm power down sequences */ + [AUDIO_SAPM_PGA] = 4, /* 4 is audio sapm power down sequences */ + [AUDIO_SAPM_MIXER_NAMED_CTRL] = 5, /* 5 is audio sapm power down sequences */ + [AUDIO_SAPM_MIXER] = 5, /* 5 is audio sapm power down sequences */ + [AUDIO_SAPM_DAC] = 6, /* 6 is audio sapm power down sequences */ + [AUDIO_SAPM_MIC] = 7, /* 7 is audio sapm power down sequences */ + [AUDIO_SAPM_MICBIAS] = 8, /* 8 is audio sapm power down sequences */ + [AUDIO_SAPM_MUX] = 9, /* 9 is audio sapm power down sequences */ + [AUDIO_SAPM_VIRT_MUX] = 9, /* 9 is audio sapm power down sequences */ + [AUDIO_SAPM_VALUE_MUX] = 9, /* 9 is audio sapm power down sequences */ + [AUDIO_SAPM_AIF_IN] = 10, /* 10 is audio sapm power down sequences */ + [AUDIO_SAPM_AIF_OUT] = 10, /* 10 is audio sapm power down sequences */ + [AUDIO_SAPM_SUPPLY] = 11, /* 11 is audio sapm power down sequences */ + [AUDIO_SAPM_POST] = 12, /* 12 is audio sapm power down sequences */ +}; + +static int32_t g_audioSapmIsSleep = 0; +static int32_t g_audioSapmIsStandby = 0; +OSAL_DECLARE_TIMER(g_sleepTimer); + +static int32_t ConnectedInputEndPoint(const struct AudioSapmComponent *cpt) +{ + struct AudioSapmpath *path = NULL; + int32_t count = 0; + int32_t endPointVal = 1; + + if (cpt == NULL) { + ADM_LOG_ERR("input param cpt is NULL."); + return HDF_FAILURE; + } + + switch (cpt->sapmType) { + case AUDIO_SAPM_DAC: + case AUDIO_SAPM_AIF_IN: + case AUDIO_SAPM_INPUT: + case AUDIO_SAPM_MIC: + case AUDIO_SAPM_LINE: + return endPointVal; + default: + break; + } + + DLIST_FOR_EACH_ENTRY(path, &cpt->sources, struct AudioSapmpath, listSink) { + if ((path->source != NULL) && (path->connect == CONNECT_SINK_AND_SOURCE)) { + count += ConnectedInputEndPoint(path->source); + } + } + return count; +} + +static int32_t ConnectedOutputEndPoint(const struct AudioSapmComponent *cpt) +{ + struct AudioSapmpath *path = NULL; + int32_t count = 0; + int32_t endPointVal = 1; + + if (cpt == NULL) { + ADM_LOG_ERR("input param cpt is NULL."); + return HDF_FAILURE; + } + + switch (cpt->sapmType) { + case AUDIO_SAPM_ADC: + case AUDIO_SAPM_AIF_OUT: + case AUDIO_SAPM_OUTPUT: + case AUDIO_SAPM_HP: + case AUDIO_SAPM_SPK: + case AUDIO_SAPM_LINE: + return endPointVal; + default: + break; + } + + DLIST_FOR_EACH_ENTRY(path, &cpt->sinks, struct AudioSapmpath, listSource) { + if ((path->sink != NULL) && (path->connect == CONNECT_SINK_AND_SOURCE)) { + count += ConnectedOutputEndPoint(path->sink); + } + } + return count; +} + +static int32_t AudioSapmGenericCheckPower(const struct AudioSapmComponent *cpt) +{ + int32_t input; + int32_t output; + + if (cpt == NULL) { + ADM_LOG_ERR("input param cpt is NULL."); + return HDF_FAILURE; + } + + input = ConnectedInputEndPoint(cpt); + if (input == HDF_FAILURE) { + ADM_LOG_ERR("input endpoint fail!"); + return HDF_FAILURE; + } + output = ConnectedOutputEndPoint(cpt); + if (output == HDF_FAILURE) { + ADM_LOG_ERR("output endpoint fail!"); + return HDF_FAILURE; + } + + if ((input == 0) || (output == 0)) { + ADM_LOG_DEBUG("component is not in a complete path."); + return SAPM_POWER_DOWN; + } + return SAPM_POWER_UP; +} + +static int32_t AudioSapmAdcCheckPower(const struct AudioSapmComponent *cpt) +{ + int32_t input; + + if (cpt == NULL) { + ADM_LOG_ERR("input param cpt is NULL."); + return HDF_FAILURE; + } + + if (cpt->active == 0) { + input = AudioSapmGenericCheckPower(cpt); + } else { + input = ConnectedInputEndPoint(cpt); + } + if (input == HDF_FAILURE) { + ADM_LOG_ERR("input endpoint fail!"); + return HDF_FAILURE; + } + return input; +} + +static int AudioSapmDacCheckPower(const struct AudioSapmComponent *cpt) +{ + int32_t output; + + if (cpt == NULL) { + ADM_LOG_ERR("input param cpt is NULL."); + return HDF_FAILURE; + } + + if (cpt->active == 0) { + output = AudioSapmGenericCheckPower(cpt); + } else { + output = ConnectedOutputEndPoint(cpt); + } + if (output == HDF_FAILURE) { + ADM_LOG_ERR("output endpoint fail!"); + return HDF_FAILURE; + } + return output; +} + +static void AudioSampCheckPowerCallback(struct AudioSapmComponent *cpt) +{ + if (cpt == NULL) { + ADM_LOG_ERR("input param cpt is NULL."); + return; + } + + switch (cpt->sapmType) { + case AUDIO_SAPM_ANALOG_SWITCH: + case AUDIO_SAPM_MIXER: + case AUDIO_SAPM_MIXER_NAMED_CTRL: + cpt->PowerCheck = AudioSapmGenericCheckPower; + break; + case AUDIO_SAPM_MUX: + case AUDIO_SAPM_VIRT_MUX: + case AUDIO_SAPM_VALUE_MUX: + cpt->PowerCheck = AudioSapmGenericCheckPower; + break; + case AUDIO_SAPM_ADC: + case AUDIO_SAPM_AIF_OUT: + cpt->PowerCheck = AudioSapmAdcCheckPower; + break; + case AUDIO_SAPM_DAC: + case AUDIO_SAPM_AIF_IN: + cpt->PowerCheck = AudioSapmDacCheckPower; + break; + case AUDIO_SAPM_PGA: + case AUDIO_SAPM_OUT_DRV: + case AUDIO_SAPM_INPUT: + case AUDIO_SAPM_OUTPUT: + case AUDIO_SAPM_MICBIAS: + case AUDIO_SAPM_SPK: + case AUDIO_SAPM_HP: + case AUDIO_SAPM_MIC: + case AUDIO_SAPM_LINE: + cpt->PowerCheck = AudioSapmGenericCheckPower; + break; + default: + cpt->PowerCheck = AudioSapmGenericCheckPower; + break; + } + + return; +} + +int32_t AudioSapmNewComponent(struct AudioCard *audioCard, const struct AudioSapmComponent *component) +{ + struct AudioSapmComponent *cpt = NULL; + + if ((audioCard == NULL) || (component == NULL)) { + ADM_LOG_ERR("input params check error: audioCard=%p, component=%p.", audioCard, component); + return HDF_FAILURE; + } + + cpt = (struct AudioSapmComponent *)OsalMemCalloc(sizeof(struct AudioSapmComponent)); + if (cpt == NULL) { + ADM_LOG_ERR("malloc cpt fail!"); + return HDF_FAILURE; + } + + if (memcpy_s(cpt, sizeof(struct AudioSapmComponent), component, sizeof(struct AudioSapmComponent)) != EOK) { + ADM_LOG_ERR("memcpy cpt fail!"); + OsalMemFree(cpt); + return HDF_FAILURE; + } + + cpt->componentName = (char *)OsalMemCalloc(strlen(component->componentName) + 1); + if (cpt->componentName == NULL) { + ADM_LOG_ERR("malloc cpt->componentName fail!"); + OsalMemFree(cpt); + return HDF_FAILURE; + } + if (memcpy_s(cpt->componentName, strlen(component->componentName) + 1, + component->componentName, strlen(component->componentName) + 1) != EOK) { + ADM_LOG_ERR("memcpy cpt->componentName fail!"); + OsalMemFree(cpt->componentName); + OsalMemFree(cpt); + return HDF_FAILURE; + } + cpt->codec = audioCard->rtd->codec; + cpt->kcontrolsNum = component->kcontrolsNum; + cpt->active = 0; + AudioSampCheckPowerCallback(cpt); + cpt->PowerClockOp = NULL; + + DListHeadInit(&cpt->sources); + DListHeadInit(&cpt->sinks); + DListHeadInit(&cpt->list); + DListHeadInit(&cpt->dirty); + DListInsertHead(&cpt->list, &audioCard->components); + + cpt->connected = CONNECT_CODEC_PIN; + + return HDF_SUCCESS; +} + +int32_t AudioSapmNewComponents(struct AudioCard *audioCard, + const struct AudioSapmComponent *component, int32_t cptMaxNum) +{ + int32_t i; + int32_t ret; + + if ((audioCard == NULL) || (component == NULL)) { + ADM_LOG_ERR("input params check error: audioCard=%p, component=%p.", audioCard, component); + return HDF_FAILURE; + } + + for (i = 0; i < cptMaxNum; i++) { + ret = AudioSapmNewComponent(audioCard, component); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("AudioSapmNewComponent fail!"); + return HDF_FAILURE; + } + component++; + } + + return HDF_SUCCESS; +} + +static void MuxSetPathStatus(const struct AudioSapmComponent *cpt, struct AudioSapmpath *path, + const struct AudioEnumKcontrol *enumKtl, int32_t i) +{ + int32_t ret; + uint32_t val; + int32_t item; + uint32_t reg; + uint32_t shift; + + if ((cpt == NULL) || (path == NULL) || (enumKtl == NULL)) { + ADM_LOG_ERR("input MuxSet params check error: cpt=%p, path=%p, enumKtl=%p.", cpt, path, enumKtl); + return; + } + + shift = enumKtl->shiftLeft; + ret = AudioCodecDeviceReadReg(cpt->codec, reg, &val); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("MuxSet read reg fail!"); + return; + } + + item = val >> shift; + + path->connect = UNCONNECT_SINK_AND_SOURCE; + for (i = 0; i < enumKtl->max; i++) { + if ((strcmp(path->name, enumKtl->texts[i]) == 0) && item == i) { + path->connect = CONNECT_SINK_AND_SOURCE; + } + } + return; +} + +static void MuxValueSetPathStatus(const struct AudioSapmComponent *cpt, struct AudioSapmpath *path, + const struct AudioEnumKcontrol *enumKtl, int32_t i) +{ + int32_t ret; + uint32_t val; + uint32_t item; + uint32_t reg = 0; + uint32_t shift; + if ((cpt == NULL) || (path == NULL) || (enumKtl == NULL)) { + ADM_LOG_ERR("input muxValueSet params check error: cpt=%p, path=%p, enumKtl=%p.", cpt, path, enumKtl); + return; + } + + shift = enumKtl->shiftLeft; + + ret = AudioCodecDeviceReadReg(cpt->codec, reg, &val); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("muxValueSet read reg fail!"); + return; + } + + val = val >> shift; + for (item = 0; item < enumKtl->max; item++) { + if (val == enumKtl->values[item]) + break; + } + + path->connect = UNCONNECT_SINK_AND_SOURCE; + for (i = 0; i < enumKtl->max; i++) { + if ((strcmp(path->name, enumKtl->texts[i]) == 0) && item == i) { + path->connect = CONNECT_SINK_AND_SOURCE; + } + } + return; +} + +static void MixerSetPathStatus(const struct AudioSapmComponent *cpt, struct AudioSapmpath *path, + const struct AudioMixerControl *mixerCtrl) +{ + int32_t ret; + uint32_t reg; + uint32_t mask; + uint32_t shift; + uint32_t invert; + uint32_t curValue; + + if ((cpt == NULL) || (path == NULL) || (mixerCtrl == NULL)) { + ADM_LOG_ERR("input params check error: cpt=%p, path=%p, mixerCtrl=%p.", cpt, path, mixerCtrl); + return; + } + + reg = mixerCtrl->reg; + shift = mixerCtrl->shift; + mask = mixerCtrl->mask; + invert = mixerCtrl->invert; + + ret = AudioCodecDeviceReadReg(cpt->codec, reg, &curValue); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("read reg fail!"); + return; + } + + curValue = (curValue >> shift) & mask; + if ((invert && !curValue) || (!invert && curValue)) { + path->connect = CONNECT_SINK_AND_SOURCE; + } else { + path->connect = UNCONNECT_SINK_AND_SOURCE; + } + + return; +} + +static int32_t AudioSapmSetPathStatus(struct AudioSapmComponent *cpt, struct AudioSapmpath *path, int32_t i) +{ + if ((cpt == NULL) || (path == NULL)) { + ADM_LOG_ERR("input params check error: cpt=%p, path=%p.", cpt, path); + return HDF_FAILURE; + } + switch (cpt->sapmType) { + case AUDIO_SAPM_MIXER: + case AUDIO_SAPM_ANALOG_SWITCH: + case AUDIO_SAPM_MIXER_NAMED_CTRL: { + MixerSetPathStatus(cpt, path, (struct AudioMixerControl *)cpt->kcontrolNews[i].privateValue); + } + break; + case AUDIO_SAPM_MUX: { + MuxSetPathStatus(cpt, path, (struct AudioEnumKcontrol *)cpt->kcontrolNews[i].privateValue, i); + } + break; + case AUDIO_SAPM_VALUE_MUX: { + MuxValueSetPathStatus(cpt, path, (struct AudioEnumKcontrol *)cpt->kcontrolNews[i].privateValue, i); + } + break; + default: { + path->connect = CONNECT_SINK_AND_SOURCE; + break; + } + } + + return HDF_SUCCESS; +} + +static int32_t AudioSapmConnectMixer(struct AudioCard *audioCard, + struct AudioSapmComponent *source, struct AudioSapmComponent *sink, + struct AudioSapmpath *path, const char *controlName) +{ + int i; + + if ((audioCard == NULL) || (source == NULL) || (sink == NULL) || (path == NULL) || (controlName == NULL)) { + ADM_LOG_ERR("input params check error: audioCard=%p, source=%p, sink=%p, path=%p, controlName=%p.", + audioCard, source, sink, path, controlName); + return HDF_FAILURE; + } + + for (i = 0; i < sink->kcontrolsNum; i++) { + if (strcmp(controlName, sink->kcontrolNews[i].name) == 0) { + path->name = (char *)OsalMemCalloc(strlen(sink->kcontrolNews[i].name) + 1); + if (path->name == NULL) { + ADM_LOG_ERR("malloc path->name fail!"); + return HDF_FAILURE; + } + if (memcpy_s(path->name, strlen(sink->kcontrolNews[i].name) + 1, sink->kcontrolNews[i].name, + strlen(sink->kcontrolNews[i].name) + 1) != EOK) { + OsalMemFree(path->name); + ADM_LOG_ERR("memcpy cpt->componentName fail!"); + return HDF_FAILURE; + } + DListInsertHead(&path->list, &audioCard->paths); + DListInsertHead(&path->listSink, &sink->sources); + DListInsertHead(&path->listSource, &source->sinks); + + AudioSapmSetPathStatus(sink, path, i); + + return HDF_SUCCESS; + } + } + + return HDF_FAILURE; +} + +static int32_t AudioSampStaticOrDynamicPath(struct AudioCard *audioCard, + struct AudioSapmComponent *source, struct AudioSapmComponent *sink, + struct AudioSapmpath *path, const struct AudioSapmRoute *route) +{ + int32_t ret; + + if ((audioCard == NULL) || (source == NULL) || (sink == NULL) || (path == NULL) || (route == NULL)) { + ADM_LOG_ERR("input params check error: audioCard=%p, source=%p, sink=%p, path=%p, route=%p.", + audioCard, source, sink, path, route); + return HDF_FAILURE; + } + + if (route->control == NULL) { + DListInsertHead(&path->list, &audioCard->paths); + DListInsertHead(&path->listSink, &sink->sources); + DListInsertHead(&path->listSource, &source->sinks); + path->connect = CONNECT_SINK_AND_SOURCE; + return HDF_SUCCESS; + } + + switch (sink->sapmType) { + case AUDIO_SAPM_MUX: + case AUDIO_SAPM_VIRT_MUX: + case AUDIO_SAPM_VALUE_MUX: + break; + case AUDIO_SAPM_ANALOG_SWITCH: + case AUDIO_SAPM_MIXER: + case AUDIO_SAPM_MIXER_NAMED_CTRL: + case AUDIO_SAPM_PGA: + case AUDIO_SAPM_SPK: + ret = AudioSapmConnectMixer(audioCard, source, sink, path, route->control); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("connect mixer fail!"); + return HDF_FAILURE; + } + break; + case AUDIO_SAPM_HP: + case AUDIO_SAPM_MIC: + case AUDIO_SAPM_LINE: + DListInsertHead(&path->list, &audioCard->paths); + DListInsertHead(&path->listSink, &sink->sources); + DListInsertHead(&path->listSource, &source->sinks); + path->connect = CONNECT_SINK_AND_SOURCE; + break; + default: + DListInsertHead(&path->list, &audioCard->paths); + DListInsertHead(&path->listSink, &sink->sources); + DListInsertHead(&path->listSource, &source->sinks); + path->connect = CONNECT_SINK_AND_SOURCE; + break; + } + + return HDF_SUCCESS; +} + +static void AudioSampExtComponentsCheck(struct AudioSapmComponent *cptSource, struct AudioSapmComponent *cptSink) +{ + if ((cptSource == NULL) || (cptSink == NULL)) { + ADM_LOG_ERR("input params check error: cptSource=%p, cptSink=%p.", cptSource, cptSink); + return; + } + + /* check for external components */ + if (cptSink->sapmType == AUDIO_SAPM_INPUT) { + if (cptSource->sapmType == AUDIO_SAPM_MICBIAS || cptSource->sapmType == AUDIO_SAPM_MIC || + cptSource->sapmType == AUDIO_SAPM_LINE || cptSource->sapmType == AUDIO_SAPM_OUTPUT) + cptSink->external = EXIST_EXTERNAL_WIDGET; + } + if (cptSource->sapmType == AUDIO_SAPM_OUTPUT) { + if (cptSink->sapmType == AUDIO_SAPM_SPK || cptSink->sapmType == AUDIO_SAPM_HP || + cptSink->sapmType == AUDIO_SAPM_LINE || cptSink->sapmType == AUDIO_SAPM_INPUT) + cptSource->external = EXIST_EXTERNAL_WIDGET; + } + + return; +} +static int32_t AudioSapmAddRoute(struct AudioCard *audioCard, const struct AudioSapmRoute *route) +{ + struct AudioSapmpath *path = NULL; + struct AudioSapmComponent *cptSource = NULL; + struct AudioSapmComponent *cptSink = NULL; + struct AudioSapmComponent *cpt = NULL; + int32_t ret; + + if ((audioCard == NULL) || (route == NULL)) { + ADM_LOG_ERR("input params check error: audioCard=%p, route=%p.", audioCard, route); + return HDF_FAILURE; + } + + DLIST_FOR_EACH_ENTRY(cpt, &audioCard->components, struct AudioSapmComponent, list) { + if ((cptSource == NULL) && (strcmp(cpt->componentName, route->source) == 0)) { + cptSource = cpt; + continue; + } + if ((cptSink == NULL) && (strcmp(cpt->componentName, route->sink) == 0)) { + cptSink = cpt; + } + if ((cptSource != NULL) && (cptSink != NULL)) { + break; + } + } + if ((cptSource == NULL) || (cptSink == NULL)) { + ADM_LOG_ERR("find component fail!"); + return HDF_FAILURE; + } + + path = (struct AudioSapmpath *)OsalMemCalloc(sizeof(struct AudioSapmpath)); + if (path == NULL) { + ADM_LOG_ERR("malloc path fail!"); + return HDF_FAILURE; + } + path->source = cptSource; + path->sink = cptSink; + DListHeadInit(&path->list); + DListHeadInit(&path->listSink); + DListHeadInit(&path->listSource); + + /* check for external components */ + AudioSampExtComponentsCheck(cptSource, cptSink); + + ret = AudioSampStaticOrDynamicPath(audioCard, cptSource, cptSink, path, route); + if (ret != HDF_SUCCESS) { + OsalMemFree(path); + ADM_LOG_ERR("static or dynamic path fail!"); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t AudioSapmAddRoutes(struct AudioCard *audioCard, const struct AudioSapmRoute *route, int32_t routeMaxNum) +{ + int32_t i; + int32_t ret; + + if ((audioCard == NULL) || (route == NULL)) { + ADM_LOG_ERR("input params check error: audioCard=%p, route=%p.", audioCard, route); + return HDF_FAILURE; + } + + for (i = 0; i < routeMaxNum; i++) { + ret = AudioSapmAddRoute(audioCard, route); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("AudioSapmAddRoute failed!"); + return HDF_FAILURE; + } + route++; + } + return HDF_SUCCESS; +} + +int32_t AudioSapmNewMixerControls(struct AudioSapmComponent *cpt, struct AudioCard *audioCard) +{ + struct AudioSapmpath *path = NULL; + int32_t i; + + if ((cpt == NULL) || (audioCard == NULL)) { + ADM_LOG_ERR("input params check error: cpt=%p, audioCard=%p.", cpt, audioCard); + return HDF_FAILURE; + } + + for (i = 0; i < cpt->kcontrolsNum; i++) { + DLIST_FOR_EACH_ENTRY(path, &cpt->sources, struct AudioSapmpath, listSink) { + if (strcmp(path->name, cpt->kcontrolNews[i].name) != 0) { + continue; + } + + path->kcontrol = AudioAddControl(audioCard, &cpt->kcontrolNews[i]); + if (path->kcontrol == NULL) { + ADM_LOG_ERR("add control fail!"); + return HDF_FAILURE; + } + cpt->kcontrols[i] = path->kcontrol; + DListInsertHead(&cpt->kcontrols[i]->list, &audioCard->controls); + } + } + + return HDF_SUCCESS; +} + +int AudioSapmNewMuxControls(struct AudioSapmComponent *cpt, struct AudioCard *audioCard) +{ + struct AudioKcontrol *kctrl = NULL; + + if (cpt == NULL) { + ADM_LOG_ERR("input param cpt is NULL."); + return HDF_FAILURE; + } + + if (cpt->kcontrolsNum != 1) { + ADM_LOG_ERR("incorrect number of controls."); + return HDF_FAILURE; + } + + kctrl = AudioAddControl(audioCard, &cpt->kcontrolNews[0]); + if (kctrl == NULL) { + ADM_LOG_ERR("add control fail!"); + return HDF_FAILURE; + } + cpt->kcontrols[0] = kctrl; + DListInsertHead(&cpt->kcontrols[0]->list, &audioCard->controls); + + return HDF_SUCCESS; +} + +static void AudioSapmPowerSeqInsert(struct AudioSapmComponent *newCpt, + struct DListHead *list, int8_t isPowerUp) +{ + struct AudioSapmComponent *cpt = NULL; + int32_t *seq = {0}; + + if (newCpt == NULL) { + ADM_LOG_ERR("input param newCpt is NULL."); + return; + } + + if (isPowerUp) { + seq = g_audioSapmPowerUpSeq; + } else { + seq = g_audioSapmPowerDownSeq; + } + + DLIST_FOR_EACH_ENTRY(cpt, list, struct AudioSapmComponent, powerList) { + if ((seq[newCpt->sapmType] - seq[cpt->sapmType]) < 0) { + DListInsertTail(&newCpt->powerList, &cpt->powerList); + return; + } + } + DListInsertTail(&newCpt->powerList, list); + + ADM_LOG_DEBUG("[%s] success.", newCpt->componentName); + return; +} + +static void AudioSapmSetPower(struct AudioCard *audioCard, struct AudioSapmComponent *cpt, + uint8_t power, struct DListHead *upList, struct DListHead *downList) +{ + struct AudioSapmpath *path = NULL; + + if (cpt == NULL) { + ADM_LOG_ERR("input param cpt is NULL."); + return; + } + + DLIST_FOR_EACH_ENTRY(path, &cpt->sources, struct AudioSapmpath, listSink) { + if (path->source != NULL) { + if ((path->source->power != power) && path->connect) { + if (DListIsEmpty(&path->source->dirty)) { + DListInsertTail(&path->source->dirty, &audioCard->sapmDirty); + } + } + } + } + DLIST_FOR_EACH_ENTRY(path, &cpt->sinks, struct AudioSapmpath, listSource) { + if (path->sink != NULL) { + if ((path->sink->power != power) && path->connect) { + if (DListIsEmpty(&path->sink->dirty)) { + DListInsertTail(&path->sink->dirty, &audioCard->sapmDirty); + } + } + } + } + + if (power) { + AudioSapmPowerSeqInsert(cpt, upList, power); + } else { + AudioSapmPowerSeqInsert(cpt, downList, power); + } + + cpt->power = power; + return; +} + +static void AudioSapmPowerUpSeqRun(struct DListHead *list) +{ + enum AudioDeviceType deviceType; + struct AudioMixerControl mixerControl; + void *device = NULL; + struct AudioSapmComponent *cpt = NULL; + int32_t ret; + + if (list == NULL) { + ADM_LOG_ERR("input param list is NULL."); + return; + } + + DLIST_FOR_EACH_ENTRY(cpt, list, struct AudioSapmComponent, powerList) { + if ((cpt->reg >= 0) && (cpt->power == SAPM_POWER_DOWN)) { + cpt->power = SAPM_POWER_UP; + mixerControl.reg = cpt->reg; + mixerControl.mask = cpt->mask; + mixerControl.shift = cpt->shift; + if (cpt->codec != NULL && cpt->codec->devData != NULL) { + deviceType = AUDIO_CODEC_DEVICE; + device = cpt->codec; + } else { + deviceType = AUDIO_ACCESSORY_DEVICE; + device = cpt->accessory; + } + ret = AudioUpdateRegBits(deviceType, device, &mixerControl, SAPM_POWER_UP); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("update reg bits fail!"); + return; + } + } + } + return; +} + +static void AudioSapmPowerDownSeqRun(struct DListHead *list) +{ + void *device = NULL; + enum AudioDeviceType deviceType; + struct AudioMixerControl mixerControl; + struct AudioSapmComponent *cpt = NULL; + int32_t ret; + + if (list == NULL) { + ADM_LOG_ERR("input param list is NULL."); + return; + } + + DLIST_FOR_EACH_ENTRY(cpt, list, struct AudioSapmComponent, powerList) { + if ((cpt->reg >= 0) && (cpt->power == SAPM_POWER_UP)) { + cpt->power = SAPM_POWER_DOWN; + mixerControl.mask = cpt->mask; + mixerControl.reg = cpt->reg; + mixerControl.shift = cpt->shift; + if (cpt->codec != NULL && cpt->codec->devData != NULL) { + deviceType = AUDIO_CODEC_DEVICE; + device = cpt->codec; + } else { + deviceType = AUDIO_ACCESSORY_DEVICE; + device = cpt->accessory; + } + ret = AudioUpdateRegBits(deviceType, device, &mixerControl, SAPM_POWER_DOWN); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("update reg bits fail!"); + return; + } + } + } + + return; +} + +int32_t AudioSapmPowerComponents(struct AudioCard *audioCard) +{ + struct AudioSapmComponent *cpt = NULL; + struct DListHead upList; + struct DListHead downList; + + if (audioCard == NULL) { + ADM_LOG_ERR("input param audioCard is NULL."); + return HDF_FAILURE; + } + + DListHeadInit(&upList); + DListHeadInit(&downList); + + DLIST_FOR_EACH_ENTRY(cpt, &audioCard->sapmDirty, struct AudioSapmComponent, dirty) { + cpt->newPower = cpt->PowerCheck(cpt); + if (cpt->newPower == cpt->power) { + continue; + } + + if (g_audioSapmIsStandby && cpt->PowerClockOp != NULL) { + cpt->PowerClockOp(cpt); + } + + AudioSapmSetPower(audioCard, cpt, cpt->newPower, &upList, &downList); + } + + DLIST_FOR_EACH_ENTRY(cpt, &audioCard->components, struct AudioSapmComponent, list) { + DListRemove(&cpt->dirty); + DListHeadInit(&cpt->dirty); + } + + AudioSapmPowerDownSeqRun(&downList); + AudioSapmPowerUpSeqRun(&upList); + + return HDF_SUCCESS; +} + +static void ReadInitComponentPowerStatus(struct AudioSapmComponent *cpt) +{ + int32_t ret; + uint32_t regVal; + + if (cpt == NULL) { + ADM_LOG_ERR("input param cpt is NULL."); + return; + } + + if (cpt->reg >= 0) { + ret = AudioCodecDeviceReadReg(cpt->codec, cpt->reg, ®Val); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("read reg fail!"); + return; + } + regVal &= 1 << cpt->shift; + + if (cpt->invert) { + regVal = !regVal; + } + + if (regVal) { + cpt->power = SAPM_POWER_UP; + } else { + cpt->power = SAPM_POWER_DOWN; + } + } + + return; +} + +void AudioSapmSleep(const struct AudioCard *audioCard) +{ + if (audioCard == NULL) { + ADM_LOG_ERR("input param audioCard is NULL."); + return; + } + + if (g_sleepTimer.realTimer != NULL) { + OsalTimerDelete(&g_sleepTimer); + } + OsalTimerCreate(&g_sleepTimer, SAPM_POLL_TIME, AudioSapmEnterSleep, (uintptr_t)audioCard); + OsalTimerStartLoop(&g_sleepTimer); + AudioSapmRefreshTime(true); + + return; +} + +int32_t AudioSapmNewControls(struct AudioCard *audioCard) +{ + struct AudioSapmComponent *cpt = NULL; + int32_t ret; + + if (audioCard == NULL) { + ADM_LOG_ERR("input param audioCard is NULL."); + return HDF_FAILURE; + } + + DLIST_FOR_EACH_ENTRY(cpt, &audioCard->components, struct AudioSapmComponent, list) { + if (cpt->newCpt) { + continue; + } + if (cpt->kcontrolsNum > 0) { + cpt->kcontrols = OsalMemCalloc(sizeof(struct AudioKcontrol*) * cpt->kcontrolsNum); + if (cpt->kcontrols == NULL) { + ADM_LOG_ERR("malloc kcontrols fail!"); + return HDF_FAILURE; + } + } + + switch (cpt->sapmType) { + case AUDIO_SAPM_ANALOG_SWITCH: + case AUDIO_SAPM_MIXER: + case AUDIO_SAPM_MIXER_NAMED_CTRL: + case AUDIO_SAPM_SPK: + case AUDIO_SAPM_PGA: + ret = AudioSapmNewMixerControls(cpt, audioCard); + break; + case AUDIO_SAPM_MUX: + case AUDIO_SAPM_VIRT_MUX: + case AUDIO_SAPM_VALUE_MUX: + ret =AudioSapmNewMuxControls(cpt, audioCard); + break; + default: + ret = HDF_SUCCESS; + break; + } + if (ret != HDF_SUCCESS) { + OsalMemFree(cpt->kcontrols); + ADM_LOG_ERR("sapm new mixer or mux controls fail!"); + return HDF_FAILURE; + } + + ReadInitComponentPowerStatus(cpt); + cpt->newCpt = 1; + DListInsertTail(&cpt->dirty, &audioCard->sapmDirty); + } + + ret = AudioSapmPowerComponents(audioCard); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("sapm power component fail!"); + return HDF_FAILURE; + } + + AudioSapmSleep(audioCard); + return HDF_SUCCESS; +} + +static int32_t MixerUpdatePowerStatus(struct AudioKcontrol *kcontrol, uint32_t pathStatus) +{ + struct AudioCard *audioCard = NULL; + struct AudioSapmpath *path = NULL; + int32_t ret; + + if (kcontrol == NULL || kcontrol->pri == NULL) { + ADM_LOG_ERR("input param kcontrol is NULL."); + return HDF_FAILURE; + } + audioCard = (struct AudioCard *)(kcontrol->pri); + + DLIST_FOR_EACH_ENTRY(path, &audioCard->paths, struct AudioSapmpath, list) { + if (path->kcontrol != kcontrol) { + continue; + } + if (path->sink == NULL || path->source == NULL) { + ADM_LOG_ERR("get path sink or source fail!"); + return HDF_FAILURE; + } + if (path->sink->sapmType != AUDIO_SAPM_MIXER && + path->sink->sapmType != AUDIO_SAPM_MIXER_NAMED_CTRL && + path->sink->sapmType != AUDIO_SAPM_PGA && + path->sink->sapmType != AUDIO_SAPM_SPK && + path->sink->sapmType != AUDIO_SAPM_ANALOG_SWITCH) { + ADM_LOG_DEBUG("no mixer device."); + return HDF_DEV_ERR_NO_DEVICE; + } + path->connect = pathStatus; + DListInsertTail(&path->source->dirty, &audioCard->sapmDirty); + DListInsertTail(&path->sink->dirty, &audioCard->sapmDirty); + break; + } + + ret = AudioSapmPowerComponents(audioCard); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("sapm power component fail!"); + 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 AudioSapmGetCtrlSw(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."); + 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_FAILURE; + } + + curValue = (curValue >> mixerCtrl->shift) & mixerCtrl->mask; + if (curValue > mixerCtrl->max) { + ADM_LOG_ERR("invalid curValue:%d.", curValue); + return HDF_FAILURE; + } + + if (mixerCtrl->invert) { + curValue = mixerCtrl->max - curValue; + } + elemValue->value[0] = curValue; + + return HDF_SUCCESS; +} + +int32_t AudioSapmPutCtrlSwSub(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, + struct AudioMixerControl *mixerCtrl, int32_t value, uint32_t pathStatus) +{ + int32_t ret = HDF_FAILURE; + void *device = NULL; + enum AudioDeviceType deviceType; + uint32_t curValue; + struct CodecDevice *codec = AudioKcontrolGetCodec(kcontrol); + struct AccessoryDevice *accessory = AudioKcontrolGetAccessory(kcontrol); + + if (kcontrol == NULL || elemValue == NULL || mixerCtrl == NULL) { + ADM_LOG_ERR("parser is fail!"); + return HDF_FAILURE; + } + 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); + } + if (ret != 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) || 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) { + 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 AudioSapmPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +{ + uint32_t pathStatus; + int32_t value; + 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; + } + 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; + } + if (AudioSapmPutCtrlSwSub(kcontrol, elemValue, mixerCtrl, value, pathStatus) == HDF_FAILURE) { + ADM_LOG_ERR("AudioSapmPutCtrlSwSub value is fail."); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + + +u64 AudioSapmRefreshTime(bool bRefresh) +{ + static u64 time = 0; + + if (bRefresh) { + time = OsalGetSysTimeMs(); + g_audioSapmIsSleep = false; + } + return time; +} + +static bool AudioSapmCheckTime(void) +{ + int64_t diffTime = OsalGetSysTimeMs() - AudioSapmRefreshTime(false); + if (diffTime > SAPM_SLEEP_TIME) { + return true; + } else if (diffTime < 0) { + AudioSapmRefreshTime(true); + } + return false; +} + +static void AudioSapmEnterSleepSub(uintptr_t para, struct AudioSapmComponent *cpt) +{ + void *device = NULL; + int i; + enum AudioDeviceType deviceType; + struct DListHead downList; + struct AudioCard *audioCard = (struct AudioCard *)para; + + DListHeadInit(&downList); + DLIST_FOR_EACH_ENTRY(cpt, &audioCard->components, struct AudioSapmComponent, list) { + for (i = 0; (i < cpt->kcontrolsNum) && (cpt->kcontrols != NULL) && (cpt->kcontrols[i] != NULL); i++) { + struct AudioMixerControl *mixerCtrl = (struct AudioMixerControl *)(cpt->kcontrols[i]->privateValue); + if (mixerCtrl != NULL) { + if (cpt->codec != NULL && cpt->codec->devData != NULL) { + deviceType = AUDIO_CODEC_DEVICE; + device = cpt->codec; + } else { + deviceType = AUDIO_ACCESSORY_DEVICE; + device = cpt->accessory; + } + AudioUpdateRegBits(deviceType, device, mixerCtrl, SAPM_POWER_DOWN); + } + } + ReadInitComponentPowerStatus(cpt); + if (cpt->power == SAPM_POWER_UP) { + AudioSapmPowerSeqInsert(cpt, &downList, SAPM_POWER_DOWN); + } + } + AudioSapmPowerDownSeqRun(&downList); + g_audioSapmIsSleep = true; +} + +static void AudioSapmEnterSleep(uintptr_t para) +{ + struct AudioSapmComponent *cpt = NULL; + struct AudioCard *audioCard = (struct AudioCard *)para; + static bool bFirst = true; + + if ((g_audioSapmIsSleep == true) || (audioCard == NULL) || (!AudioSapmCheckTime())) { + return; + } + + if (bFirst) { + bFirst = false; + AudioSapmRefreshTime(true); + return; + } + + DLIST_FOR_EACH_ENTRY(cpt, &audioCard->components, struct AudioSapmComponent, list) { + if (cpt->PowerClockOp != NULL) { + if (g_audioSapmIsStandby == false) { + cpt->PowerClockOp(cpt); + g_audioSapmIsStandby = true; + AudioSapmRefreshTime(true); + } + } + } + if (g_audioSapmIsStandby == true) { + if (!AudioSapmCheckTime()) { + return; + } + g_audioSapmIsStandby = false; + } + + AudioSapmEnterSleepSub(para, cpt); +} diff --git a/model/audio/sapm/test/unittest/common/audio_sapm_test.cpp b/model/audio/sapm/test/unittest/common/audio_sapm_test.cpp new file mode 100755 index 000000000..7d700a9da --- /dev/null +++ b/model/audio/sapm/test/unittest/common/audio_sapm_test.cpp @@ -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. + */ + +#include "audio_common_test.h" +#include +#include "hdf_uhdf_test.h" + +using namespace testing::ext; + +class AudioSapmTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void AudioSapmTest::SetUpTestCase() +{ + HdfTestOpenService(); +} + +void AudioSapmTest::TearDownTestCase() +{ + HdfTestCloseService(); +} + +void AudioSapmTest::SetUp() +{ +} + +void AudioSapmTest::TearDown() +{ +} + +HWTEST_F(AudioSapmTest, AudioSapmTest001, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTNEWCOMPONENT, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioSapmTest, AudioSapmTest002, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTADDROUTES, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioSapmTest, AudioSapmTest003, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTNEWCONTROLS, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioSapmTest, AudioSapmTest004, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTPOWERCOMPONET, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +HWTEST_F(AudioSapmTest, AudioSapmTest005, TestSize.Level0) +{ + struct HdfTestMsg msg = {g_testAudioType, TESTREFRESHTIME, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} diff --git a/test/unittest/common/hdf_main_test.c b/test/unittest/common/hdf_main_test.c index ee5e40088..0662cc6c4 100644 --- a/test/unittest/common/hdf_main_test.c +++ b/test/unittest/common/hdf_main_test.c @@ -49,6 +49,9 @@ #if defined(LOSCFG_DRIVERS_HDF_WIFI) || defined(CONFIG_DRIVERS_HDF_WIFI) #include "hdf_wifi_test.h" #endif +#if defined(LOSCFG_DRIVERS_HDF_AUDIO_TEST) || defined(CONFIG_DRIVERS_HDF_AUDIO_TEST) +#include "hdf_audio_test.h" +#endif #define HDF_LOG_TAG hdf_test @@ -90,7 +93,10 @@ HdfTestFuncList g_hdfTestFuncList[] = { { TEST_CONFIG_TYPE, HdfConfigEntry }, { TEST_OSAL_ITEM, HdfOsalEntry }, #if defined(LOSCFG_DRIVERS_HDF_WIFI) || defined(CONFIG_DRIVERS_HDF_WIFI) - {TEST_WIFI_TYPE, HdfWifiEntry} + {TEST_WIFI_TYPE, HdfWifiEntry}, +#endif +#if defined(LOSCFG_DRIVERS_HDF_AUDIO_TEST) || defined(CONFIG_DRIVERS_HDF_AUDIO_TEST) + {TEST_AUDIO_TYPE, HdfAudioEntry}, #endif }; diff --git a/test/unittest/common/hdf_main_test.h b/test/unittest/common/hdf_main_test.h index be051bd93..e2fd3767a 100644 --- a/test/unittest/common/hdf_main_test.h +++ b/test/unittest/common/hdf_main_test.h @@ -67,6 +67,7 @@ typedef enum { TEST_WIFI_TYPE = TEST_WIFI_BEGIN + 1, TEST_WIFI_END = 600, TEST_CONFIG_TYPE = 601, + TEST_AUDIO_TYPE = 701, TEST_HDF_FRAME_END = 800, } HdfTestSubModuleCmd; diff --git a/test/unittest/model/audio/include/audio_core_test.h b/test/unittest/model/audio/include/audio_core_test.h new file mode 100755 index 000000000..b36a9f99c --- /dev/null +++ b/test/unittest/model/audio/include/audio_core_test.h @@ -0,0 +1,46 @@ +/* + * 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_CORE_TEST_H +#define AUDIO_CORE_TEST_H + +#include "hdf_types.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +int32_t AudioSocTestRegisterDai(void); +int32_t AudioSocTestRegisterPlatform(void); +int32_t AudioTestRegisterCodec(void); +int32_t AudioTestBindDaiLink(void); +int32_t AudioTestSocDeviceRegister(void); +int32_t AudioTestSocRegisterDsp(void); +int32_t AudioTestRegisterAccessory(void); +int32_t AudioTestUpdateRegBits(void); +int32_t AudioTestAiaoUpdateRegBits(void); +int32_t AudioTestKcontrolGetCodec(void); +int32_t AudioTestAddControls(void); +int32_t AudioTestAddControl(void); +int32_t AudioTestDeviceReadReg(void); +int32_t AudioTestAiaoDeviceReadReg(void); +int32_t AudioTestInfoCtrlSw(void); +int32_t AudioTestGetCtrlSw(void); +int32_t AudioTestPutCtrlSw(void); +int32_t AiaoTestGetCtrlSw(void); +int32_t AiaoTestPutCtrlSw(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* AUDIO_CORE_TEST_H */ diff --git a/test/unittest/model/audio/include/audio_host_test.h b/test/unittest/model/audio/include/audio_host_test.h new file mode 100755 index 000000000..42160326b --- /dev/null +++ b/test/unittest/model/audio/include/audio_host_test.h @@ -0,0 +1,30 @@ +/* + * 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_HOST_TEST_H +#define AUDIO_HOST_TEST_H + +#include "hdf_types.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +int32_t AudioKcontrolTestGetCodec(void); +int32_t GetCardTestInstance(void); +int32_t AudioHostTestDestroy(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* AUDIO_HOST_TEST_H */ diff --git a/test/unittest/model/audio/include/audio_parse_test.h b/test/unittest/model/audio/include/audio_parse_test.h new file mode 100755 index 000000000..1e070050b --- /dev/null +++ b/test/unittest/model/audio/include/audio_parse_test.h @@ -0,0 +1,28 @@ +/* + * 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_PARSE_TEST_H +#define AUDIO_PARSE_TEST_H + +#include "hdf_types.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +int32_t AudioFillTestConfigData(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* AUDIO_PARSE_TEST_H */ diff --git a/test/unittest/model/audio/include/audio_sapm_test.h b/test/unittest/model/audio/include/audio_sapm_test.h new file mode 100755 index 000000000..f3666c028 --- /dev/null +++ b/test/unittest/model/audio/include/audio_sapm_test.h @@ -0,0 +1,32 @@ +/* + * 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_SAPM_TEST_H +#define AUDIO_SAPM_TEST_H + +#include "hdf_types.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif +int32_t AudioSapmTestNewComponents(void); +int32_t AudioSapmTestAddRoutes(void); +int32_t AudioSapmTestNewControls(void); +int32_t AudioSapmTestPowerComponents(void); +int32_t AudioSapmTestRefreshTime(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif diff --git a/test/unittest/model/audio/include/audio_stream_dispatch_test.h b/test/unittest/model/audio/include/audio_stream_dispatch_test.h new file mode 100755 index 000000000..5891ff424 --- /dev/null +++ b/test/unittest/model/audio/include/audio_stream_dispatch_test.h @@ -0,0 +1,29 @@ +/* + * 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_STREAM_DISPATCH_TEST_H +#define AUDIO_STREAM_DISPATCH_TEST_H + +#include "hdf_types.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif +int32_t AudioControlDispatchTestStreamDispatch(void); +int32_t AudioControlDispatchTestStreamHostDestroy(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif diff --git a/test/unittest/model/audio/include/hdf_audio_test.h b/test/unittest/model/audio/include/hdf_audio_test.h new file mode 100755 index 000000000..36a3f34de --- /dev/null +++ b/test/unittest/model/audio/include/hdf_audio_test.h @@ -0,0 +1,61 @@ +/* + * 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 HDF_AUDIO_TEST_H +#define HDF_AUDIO_TEST_H + +#include "hdf_main_test.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +typedef enum { + AUDIO_DRIVER_TESTGETCODEC, + AUDIO_DRIVER_TESTGETCARDINSTANCE, + AUDIO_DRIVER_TESTHOSTDESTROY, + AUDIO_DRIVER_TESTGETCCNFIGDATA, + AUDIO_DRIVER_TESTREGISTERDAI, + AUDIO_DRIVER_TESTREGISTERPLATFORM, + AUDIO_DRIVER_TESTREGISTERCODEC, + AUDIO_DRIVER_TESTBINDDAILINK, + AUDIO_DRIVER_TESTDEVICEREGISTER, + AUDIO_DRIVER_TESTREGISTERDSP, + AUDIO_DRIVER_TESTREGISTERACCESSORY, + AUDIO_DRIVER_TESTUPDATEREGBITS, + AUDIO_DRIVER_TESTAIAOUPDATEREGBITS, + AUDIO_DRIVER_TESTKCONTROLGETCODEC, + AUDIO_DRIVER_TESTADDCONTROLS, + AUDIO_DRIVER_TESTADDCONTROL, + AUDIO_DRIVER_TESTDEVICEREADREG, + AUDIO_DRIVER_TESTAIAODEVICEREADREG, + AUDIO_DRIVER_TESTINFOCTRLSW, + AUDIO_DRIVER_TESTGETCTRLSW, + AUDIO_DRIVER_TESTPUTCTRLSW, + AUDIO_DRIVER_TESTAIAOGETCTRLSW, + AUDIO_DRIVER_TESTAIAOPUTCTRLSW, + AUDIO_DRIVER_TESTNEWCOMPONENT, + AUDIO_DRIVER_TESTADDROUTES, + AUDIO_DRIVER_TESTNEWCONTROLS, + AUDIO_DRIVER_TESTPOWERCOMPONET, + AUDIO_DRIVER_TESTREFRESHTIME, + AUDIO_DRIVER_TESTSTREAMDISPATCH, + AUDIO_DRIVER_TESTSTREAMDESTORY, +} HdfAudioTestCaseCmd; + +int32_t HdfAudioEntry(HdfTestMsg *msg); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* HDF_AUDIO_TEST_H */ diff --git a/test/unittest/model/audio/src/audio_core_test.c b/test/unittest/model/audio/src/audio_core_test.c new file mode 100755 index 000000000..1c2c1a47b --- /dev/null +++ b/test/unittest/model/audio/src/audio_core_test.c @@ -0,0 +1,327 @@ +/* + * 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_test.h" +#include "audio_core.h" + +#define HDF_LOG_TAG audio_core_test + +int32_t AudioSocTestRegisterDai(void) +{ + int32_t ret; + struct HdfDeviceObject *device = NULL; + struct DaiData *data = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AudioSocRegisterDai(device, data); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AudioSocRegisterDai fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioSocTestRegisterPlatform(void) +{ + int32_t ret; + struct HdfDeviceObject *device = NULL; + struct PlatformData *data = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AudioSocRegisterPlatform(device, data); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AudioSocRegisterPlatform fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestRegisterCodec(void) +{ + int32_t ret; + struct HdfDeviceObject *device = NULL; + struct CodecData *codecData = NULL; + struct DaiData *daiData = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AudioRegisterCodec(device, codecData, daiData); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AudioRegisterCodec fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestBindDaiLink(void) +{ + int32_t ret; + struct AudioCard *audioCard = NULL; + struct AudioConfigData *configData = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AudioBindDaiLink(audioCard, configData); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AudioBindDaiLink fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestSocDeviceRegister(void) +{ + int32_t ret; + void *data = NULL; + enum AudioDeviceType deviceType; + struct HdfDeviceObject *device = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AudioSocDeviceRegister(device, data, deviceType); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AudioSocDeviceRegister fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestSocRegisterDsp(void) +{ + int32_t ret; + struct HdfDeviceObject *device = NULL; + struct DaiData *data = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AudioSocRegisterDsp(device, data); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AudioSocRegisterDsp fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestRegisterAccessory(void) +{ + int32_t ret; + struct HdfDeviceObject *device = NULL; + struct AccessoryData *data = NULL; + struct DaiData *daiData = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AudioRegisterAccessory(device, data, daiData); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AudioRegisterAccessory fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestUpdateRegBits(void) +{ + int32_t codecRet; + int32_t accessoryRet; + int32_t value; + void *device = NULL; + struct AudioMixerControl *mixerControl = NULL; + HDF_LOGI("%s: enter", __func__); + + codecRet = AudioUpdateRegBits(AUDIO_CODEC_DEVICE, device, mixerControl, value); + accessoryRet = AudioUpdateRegBits(AUDIO_ACCESSORY_DEVICE, device, mixerControl, value); + if (codecRet != HDF_SUCCESS || accessoryRet != HDF_SUCCESS) { + HDF_LOGE("%s: AudioUpdateRegBits fail codecRet = %d, accessoryRet = %d", __func__, codecRet, accessoryRet); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestAiaoUpdateRegBits(void) +{ + uint32_t reg; + uint32_t mask; + uint32_t shift; + int32_t value; + int32_t ret; + struct CodecDevice *codec = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AudioAiaoUpdateRegBits(codec, reg, mask, shift, value); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AudioAiaoUpdateRegBits fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestKcontrolGetCodec(void) +{ + struct CodecDevice *codecDevice = NULL; + const struct AudioKcontrol *kcontrol = NULL; + HDF_LOGI("%s: enter", __func__); + + codecDevice = AudioKcontrolGetCodec(kcontrol); + if (codecDevice == NULL) { + HDF_LOGE("%s: AudioKcontrolGetCodec fail!", __func__); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestAddControls(void) +{ + struct AudioCard *audioCard = NULL; + const struct AudioKcontrol *controls = NULL; + int32_t controlMaxNum = 0; + int32_t ret; + HDF_LOGI("%s: enter", __func__); + + ret = AudioAddControls(audioCard, controls, controlMaxNum); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AudioAddControls fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestAddControl(void) +{ + struct AudioCard *audioCard = NULL; + const struct AudioKcontrol *control = NULL; + struct AudioKcontrol *audioKcontrol = NULL; + HDF_LOGI("%s: enter", __func__); + + audioKcontrol = AudioAddControl(audioCard, control); + if (audioKcontrol == NULL) { + HDF_LOGE("%s: AudioAddControl fail!", __func__); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestDeviceReadReg(void) +{ + int32_t codecRet; + int32_t acccessoryRet; + uint32_t reg = 0; + struct CodecDevice *codec = NULL; + struct AccessoryDevice *accessory = NULL; + HDF_LOGI("%s: enter", __func__); + + codecRet = AudioCodecDeviceReadReg(codec, reg); + acccessoryRet = AudioAccessoryDeviceReadReg(accessory, reg); + if (codecRet != HDF_SUCCESS || acccessoryRet != HDF_SUCCESS) { + HDF_LOGE("%s: AudioDeviceReadReg fail codecRet = %d, acccessoryRet = %d", __func__, codecRet, acccessoryRet); + } + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestAiaoDeviceReadReg(void) +{ + int32_t ret; + uint32_t reg = 0; + struct CodecDevice *codec = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AudioAiaoDeviceReadReg(codec, reg); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AudioAiaoDeviceReadReg fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestInfoCtrlSw(void) +{ + int32_t ret; + struct AudioKcontrol *kcontrol = NULL; + struct AudioCtrlElemInfo *elemInfo = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AudioInfoCtrlSw(kcontrol, elemInfo); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AudioInfoCtrlSw fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestGetCtrlSw(void) +{ + int32_t ret; + struct AudioKcontrol *kcontrol = NULL; + struct AudioCtrlElemValue *elemValue = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AudioGetCtrlSw(kcontrol, elemValue); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AudioGetCtrlSw fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioTestPutCtrlSw(void) +{ + int32_t ret; + struct AudioKcontrol *kcontrol = NULL; + struct AudioCtrlElemValue *elemValue = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AudioPutCtrlSw(kcontrol, elemValue); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AudioPutCtrlSw fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AiaoTestGetCtrlSw(void) +{ + int32_t ret; + struct AudioKcontrol *kcontrol = NULL; + struct AudioCtrlElemValue *elemValue = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AiaoGetCtrlSw(kcontrol, elemValue); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AiaoGetCtrlSw fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AiaoTestPutCtrlSw(void) +{ + int32_t ret; + struct AudioKcontrol *kcontrol = NULL; + struct AudioCtrlElemValue *elemValue = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AiaoPutCtrlSw(kcontrol, elemValue); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: AiaoPutCtrlSw fail ret = %d", __func__, ret); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} diff --git a/test/unittest/model/audio/src/audio_host_test.c b/test/unittest/model/audio/src/audio_host_test.c new file mode 100755 index 000000000..ef4d81c2a --- /dev/null +++ b/test/unittest/model/audio/src/audio_host_test.c @@ -0,0 +1,64 @@ +/* + * 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_host_test.h" +#include "audio_host.h" + +#define HDF_LOG_TAG audio_host_test + +int32_t AudioKcontrolTestGetCodec(void) +{ + struct HdfDeviceObject *device = NULL; + struct AudioHost *audioHost = NULL; + HDF_LOGI("%s: enter", __func__); + + audioHost = AudioHostCreateAndBind(device); + if (audioHost != NULL) { + HDF_LOGE("%s: codecDevice is not NULL", __func__); + return HDF_FAILURE; + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t GetCardTestInstance(void) +{ + int i; + const char *audioServiceName[] = { + "codec_service_0", + "codec_service_1", + "dma_service_0", + "dai_service", + "audio_service_0", + "audio_service_1", + "render_service", + "capture_service", + "control_service", + }; + HDF_LOGI("%s: enter", __func__); + + for (i = 0; i < sizeof(audioServiceName) / sizeof(audioServiceName[0]); ++i) { + if (GetCardInstance(audioServiceName[i]) == NULL) { + HDF_LOGE("%s: get %s fail!", __func__, audioServiceName[i]); + } + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioHostTestDestroy(void) +{ + struct AudioHost *host = NULL; + HDF_LOGI("%s: enter", __func__); + + AudioHostDestroy(host); + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} diff --git a/test/unittest/model/audio/src/audio_parse_test.c b/test/unittest/model/audio/src/audio_parse_test.c new file mode 100755 index 000000000..74c61c61e --- /dev/null +++ b/test/unittest/model/audio/src/audio_parse_test.c @@ -0,0 +1,29 @@ +/* + * 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_parse_test.h" +#include "audio_parse.h" + +#define HDF_LOG_TAG audio_parse_test + +int32_t AudioFillTestConfigData(void) +{ + int32_t ret; + struct HdfDeviceObject *device = NULL; + struct AudioConfigData *configData = NULL; + HDF_LOGI("%s: enter", __func__); + + ret = AudioFillConfigData(device, configData); + if (ret == HDF_SUCCESS) { + HDF_LOGE("%s: AudioFillConfigData fail! ret = %d", __func__, ret); + return HDF_FAILURE; + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} diff --git a/test/unittest/model/audio/src/audio_sapm_test.c b/test/unittest/model/audio/src/audio_sapm_test.c new file mode 100755 index 000000000..40a20d48c --- /dev/null +++ b/test/unittest/model/audio/src/audio_sapm_test.c @@ -0,0 +1,92 @@ +/* + * 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_sapm_test.h" +#include "audio_sapm.h" + +#define HDF_LOG_TAG audio_host_test + +int32_t AudioSapmTestNewComponents(void) +{ + struct AudioCard *audioCard = NULL; + struct AudioSapmComponent *component = NULL; + int32_t maxNum = 0; + int32_t ret; + HDF_LOGI("%s: enter", __func__); + + ret = AudioSapmNewComponents(audioCard, component, maxNum); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: audioCart or component is NULL", __func__); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioSapmTestAddRoutes(void) +{ + struct AudioCard *audioCard = NULL; + struct AudioSapmRoute *route = NULL; + int32_t routeMaxNum = 0; + int32_t ret; + HDF_LOGI("%s: enter", __func__); + + ret = AudioSapmAddRoutes(audioCard, route, routeMaxNum); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: audioCard or route is NULL", __func__); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioSapmTestNewControls(void) +{ + struct AudioCard *audioCard = NULL; + int32_t ret; + HDF_LOGI("%s: enter", __func__); + + ret = AudioSapmNewControls(audioCard); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: audioCard is NULL", __func__); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioSapmTestPowerComponents(void) +{ + struct AudioCard *audioCard = NULL; + int32_t ret; + HDF_LOGI("%s: enter", __func__); + + ret = AudioSapmPowerComponents(audioCard); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: audioCard is NULL", __func__); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + + +int32_t AudioSapmTestRefreshTime(void) +{ + bool bRefresh = true; + u64 time; + HDF_LOGI("%s: enter", __func__); + + time = AudioSapmRefreshTime(bRefresh); + if (time == 0) { + HDF_LOGE("%s: error", __func__); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + diff --git a/test/unittest/model/audio/src/audio_stream_dispatch_test.c b/test/unittest/model/audio/src/audio_stream_dispatch_test.c new file mode 100755 index 000000000..4d9d138c3 --- /dev/null +++ b/test/unittest/model/audio/src/audio_stream_dispatch_test.c @@ -0,0 +1,40 @@ +/* + * 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_stream_dispatch_test.h" +#include "audio_stream_dispatch.h" + +#define HDF_LOG_TAG audio_host_test + +int32_t AudioControlDispatchTestStreamDispatch(void) +{ + struct HdfDeviceIoClient *client = NULL; + struct HdfSBuf *data = NULL; + struct HdfSBuf *reply = NULL; + int32_t cmdId = 0; + int32_t ret; + HDF_LOGI("%s: enter", __func__); + + ret = StreamDispatch(client, cmdId, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: (client || cmdId || data ||reply) is NULL", __func__); + } + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t AudioControlDispatchTestStreamHostDestroy(void) +{ + struct StreamHost *host = NULL; + HDF_LOGI("%s: enter", __func__); + + StreamHostDestroy(host); + + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} diff --git a/test/unittest/model/audio/src/hdf_audio_test.c b/test/unittest/model/audio/src/hdf_audio_test.c new file mode 100755 index 000000000..72114884b --- /dev/null +++ b/test/unittest/model/audio/src/hdf_audio_test.c @@ -0,0 +1,71 @@ +/* + * 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 "hdf_log.h" +#include "hdf_audio_test.h" +#include "audio_host_test.h" +#include "audio_core_test.h" +#include "audio_parse_test.h" +#include "audio_sapm_test.h" +#include "audio_stream_dispatch_test.h" + +#define HDF_LOG_TAG hdf_audio_test + +// add test case entry +static HdfTestCaseList g_hdfAudioTestCaseList[] = { + {AUDIO_DRIVER_TESTGETCODEC, AudioKcontrolTestGetCodec}, + {AUDIO_DRIVER_TESTGETCARDINSTANCE, GetCardTestInstance}, + {AUDIO_DRIVER_TESTHOSTDESTROY, AudioHostTestDestroy}, + {AUDIO_DRIVER_TESTGETCCNFIGDATA, AudioFillTestConfigData}, + {AUDIO_DRIVER_TESTREGISTERDAI, AudioSocTestRegisterDai}, + {AUDIO_DRIVER_TESTREGISTERPLATFORM, AudioSocTestRegisterPlatform}, + {AUDIO_DRIVER_TESTREGISTERCODEC, AudioTestRegisterCodec}, + {AUDIO_DRIVER_TESTBINDDAILINK, AudioTestBindDaiLink}, + {AUDIO_DRIVER_TESTDEVICEREGISTER, AudioTestSocDeviceRegister}, + {AUDIO_DRIVER_TESTREGISTERDSP, AudioTestSocRegisterDsp}, + {AUDIO_DRIVER_TESTREGISTERACCESSORY, AudioTestRegisterAccessory}, + {AUDIO_DRIVER_TESTUPDATEREGBITS, AudioTestUpdateRegBits}, + {AUDIO_DRIVER_TESTAIAOUPDATEREGBITS, AudioTestAiaoUpdateRegBits}, + {AUDIO_DRIVER_TESTKCONTROLGETCODEC, AudioTestKcontrolGetCodec}, + {AUDIO_DRIVER_TESTADDCONTROLS, AudioTestAddControls}, + {AUDIO_DRIVER_TESTADDCONTROL, AudioTestAddControl}, + {AUDIO_DRIVER_TESTDEVICEREADREG, AudioTestDeviceReadReg}, + {AUDIO_DRIVER_TESTAIAODEVICEREADREG, AudioTestAiaoDeviceReadReg}, + {AUDIO_DRIVER_TESTINFOCTRLSW, AudioTestInfoCtrlSw}, + {AUDIO_DRIVER_TESTGETCTRLSW, AudioTestGetCtrlSw}, + {AUDIO_DRIVER_TESTPUTCTRLSW, AudioTestPutCtrlSw}, + {AUDIO_DRIVER_TESTAIAOGETCTRLSW, AiaoTestGetCtrlSw}, + {AUDIO_DRIVER_TESTAIAOPUTCTRLSW, AiaoTestPutCtrlSw}, + {AUDIO_DRIVER_TESTNEWCOMPONENT, AudioSapmTestNewComponents}, + {AUDIO_DRIVER_TESTADDROUTES, AudioSapmTestAddRoutes}, + {AUDIO_DRIVER_TESTNEWCONTROLS, AudioSapmTestNewControls}, + {AUDIO_DRIVER_TESTPOWERCOMPONET, AudioSapmTestPowerComponents}, + {AUDIO_DRIVER_TESTREFRESHTIME, AudioSapmTestRefreshTime}, + {AUDIO_DRIVER_TESTSTREAMDISPATCH, AudioControlDispatchTestStreamDispatch}, + {AUDIO_DRIVER_TESTSTREAMDESTORY, AudioControlDispatchTestStreamHostDestroy}, +}; + +int32_t HdfAudioEntry(HdfTestMsg *msg) +{ + int32_t result, i; + + if (msg == NULL) { + HDF_LOGE("%s is fail: HdfTestMsg is NULL!", __func__); + return HDF_SUCCESS; + } + + for (i = 0; i < sizeof(g_hdfAudioTestCaseList) / sizeof(g_hdfAudioTestCaseList[0]); ++i) { + if ((msg->subCmd == g_hdfAudioTestCaseList[i].subCmd) && (g_hdfAudioTestCaseList[i].testFunc != NULL)) { + result = g_hdfAudioTestCaseList[i].testFunc(); + HDF_LOGE("HdfTest:Audio test result[%s-%u]", ((result == 0) ? "pass" : "fail"), msg->subCmd); + msg->result = (result == 0) ? HDF_SUCCESS : HDF_FAILURE; + return HDF_SUCCESS; + } + } + return HDF_SUCCESS; +} -- Gitee From 7a1f7380d6d44f266ab8a0be037fc248d6e52f2c Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Fri, 9 Jul 2021 07:03:35 +0000 Subject: [PATCH 009/205] Description:adapter wlan hdi client Feature or Bugfix:Feature Binary Source: No Signed-off-by: YOUR_NAME --- model/network/wifi/core/module/wifi_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/network/wifi/core/module/wifi_base.c b/model/network/wifi/core/module/wifi_base.c index 2bb44d55a..1857174d7 100644 --- a/model/network/wifi/core/module/wifi_base.c +++ b/model/network/wifi/core/module/wifi_base.c @@ -1178,7 +1178,7 @@ void SendMessageResetDriverCallBack(const RequestContext *context, struct HdfSBu HDF_LOGE("%s: read data failed! ParamName=%s", __func__, "chipId"); return; } - ifName = HdfSbufReadString(reqData); + ifName = HdfSbufReadString(rspData); if (ifName == NULL) { HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName"); return; -- Gitee From c51a63aed165a26fea49eeb18908ad914bb26486 Mon Sep 17 00:00:00 2001 From: vb6174 Date: Fri, 9 Jul 2021 07:12:33 +0000 Subject: [PATCH 010/205] modify date Signed-off-by: vb6174 --- model/audio/core/include/audio_control.h | 2 +- model/audio/core/include/audio_core.h | 2 +- model/audio/core/include/audio_host.h | 2 +- model/audio/core/include/audio_parse.h | 2 +- model/audio/core/include/codec_core.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/model/audio/core/include/audio_control.h b/model/audio/core/include/audio_control.h index 8b2fab186..dc362462d 100755 --- a/model/audio/core/include/audio_control.h +++ b/model/audio/core/include/audio_control.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * 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. diff --git a/model/audio/core/include/audio_core.h b/model/audio/core/include/audio_core.h index 03ac9ab57..601768326 100755 --- a/model/audio/core/include/audio_core.h +++ b/model/audio/core/include/audio_core.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * 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. diff --git a/model/audio/core/include/audio_host.h b/model/audio/core/include/audio_host.h index 2ab9e3c57..603cbdc2b 100755 --- a/model/audio/core/include/audio_host.h +++ b/model/audio/core/include/audio_host.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * 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. diff --git a/model/audio/core/include/audio_parse.h b/model/audio/core/include/audio_parse.h index e73e14c58..03c931289 100755 --- a/model/audio/core/include/audio_parse.h +++ b/model/audio/core/include/audio_parse.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * 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. diff --git a/model/audio/core/include/codec_core.h b/model/audio/core/include/codec_core.h index a19378104..ddb49a548 100755 --- a/model/audio/core/include/codec_core.h +++ b/model/audio/core/include/codec_core.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * 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. -- Gitee From 12807cee58f6802b5ceea4c0f0a0dc5a7a2eb8fc Mon Sep 17 00:00:00 2001 From: vb6174 Date: Mon, 12 Jul 2021 02:42:49 +0000 Subject: [PATCH 011/205] rm audio card sleep Signed-off-by: vb6174 --- model/audio/sapm/src/audio_sapm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/model/audio/sapm/src/audio_sapm.c b/model/audio/sapm/src/audio_sapm.c index 34a01d03d..19def3b21 100755 --- a/model/audio/sapm/src/audio_sapm.c +++ b/model/audio/sapm/src/audio_sapm.c @@ -973,7 +973,6 @@ int32_t AudioSapmNewControls(struct AudioCard *audioCard) return HDF_FAILURE; } - AudioSapmSleep(audioCard); return HDF_SUCCESS; } -- Gitee From 4c4450b9a2b52e06290a484704a417b19c273843 Mon Sep 17 00:00:00 2001 From: zianed Date: Thu, 15 Jul 2021 19:35:31 +0800 Subject: [PATCH 012/205] add linux usb driver model Signed-off-by: zianed --- core/common/src/hdf_attribute.c | 10 +- core/host/include/devsvc_manager_clnt.h | 2 +- core/host/src/devsvc_manager_clnt.c | 4 +- core/host/src/hdf_driver_loader.c | 2 +- core/shared/include/hdf_attribute_manager.h | 2 +- core/shared/include/hdf_device_info.h | 5 + core/shared/include/hdf_usb_pnp_manage.h | 102 + core/shared/src/hdf_device_info.c | 4 + model/input/driver/hdf_input_device_manager.c | 2 +- test/unittest/common/hdf_main_test.c | 8 + test/unittest/common/hdf_main_test.h | 1 + test/unittest/include/hdf_uhdf_test.h | 1 + test/unittest/manager/sample_driver_test.c | 2 +- .../model/usb/include/hdf_usb_device_test.h | 141 + .../usb/include/usb_device_lite_cdcacm_test.h | 251 ++ .../model/usb/src/hdf_usb_device_test.c | 154 ++ .../usb/src/usb_device_lite_cdcacm_test.c | 770 ++++++ .../usb/src/usb_device_lite_sdk_if_test.c | 2268 +++++++++++++++++ 18 files changed, 3721 insertions(+), 8 deletions(-) create mode 100644 core/shared/include/hdf_usb_pnp_manage.h create mode 100644 test/unittest/model/usb/include/hdf_usb_device_test.h create mode 100644 test/unittest/model/usb/include/usb_device_lite_cdcacm_test.h create mode 100644 test/unittest/model/usb/src/hdf_usb_device_test.c create mode 100644 test/unittest/model/usb/src/usb_device_lite_cdcacm_test.c create mode 100644 test/unittest/model/usb/src/usb_device_lite_sdk_if_test.c diff --git a/core/common/src/hdf_attribute.c b/core/common/src/hdf_attribute.c index 83b609fd2..ce3db466b 100644 --- a/core/common/src/hdf_attribute.c +++ b/core/common/src/hdf_attribute.c @@ -18,6 +18,9 @@ #include "hdf_log.h" #include "osal_mem.h" #include "securec.h" +#ifdef LOSCFG_DRIVERS_HDF_USB_PNP_NOTIFY +#include "usb_pnp_manager.h" +#endif #define ATTR_HOST_NAME "hostName" #define ATTR_DEV_POLICY "policy" @@ -286,7 +289,7 @@ struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *h return deviceList; } -bool HdfDeviceListAdd(const char *moduleName, const char *serviceName) +bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const void *privateData) { struct HdfSListIterator itHost; struct HdfSListIterator itDeviceInfo; @@ -330,6 +333,11 @@ bool HdfDeviceListAdd(const char *moduleName, const char *serviceName) break; } deviceNodeInfo->svcName = svcName; +#ifdef LOSCFG_DRIVERS_HDF_USB_PNP_NOTIFY + if (!UsbPnpManagerAddPrivateData(deviceNodeInfo, privateData)) { + break; + } +#endif HdfSListAdd(hostClnt->deviceInfos, &deviceNodeInfo->node); hostClnt->devCount++; return true; diff --git a/core/host/include/devsvc_manager_clnt.h b/core/host/include/devsvc_manager_clnt.h index e164d8ae9..ec7f7bec7 100644 --- a/core/host/include/devsvc_manager_clnt.h +++ b/core/host/include/devsvc_manager_clnt.h @@ -21,7 +21,7 @@ int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *ser void DevSvcManagerClntRemoveService(const char *svcName); int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback); int DevSvcManagerClntUnsubscribeService(const char *svcName); -struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName); +struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName, const void *privateData); void HdfUnregisterDevice(const char *moduleName, const char *serviceName); #endif /* DEVSVC_MANAGER_CLNT_H */ diff --git a/core/host/src/devsvc_manager_clnt.c b/core/host/src/devsvc_manager_clnt.c index 7dd4aef7f..479839b94 100644 --- a/core/host/src/devsvc_manager_clnt.c +++ b/core/host/src/devsvc_manager_clnt.c @@ -64,10 +64,10 @@ struct HdfDeviceObject *DevSvcManagerClntGetDeviceObject(const char *svcName) return serviceManager->GetObject(serviceManager, svcName); } -struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName) +struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName, const void *privateData) { int ret; - if (!HdfDeviceListAdd(moduleName, serviceName)) { + if (!HdfDeviceListAdd(moduleName, serviceName, privateData)) { HDF_LOGE("%s device info add failed!", __func__); return NULL; } diff --git a/core/host/src/hdf_driver_loader.c b/core/host/src/hdf_driver_loader.c index 5ef03defe..98cfbee6c 100755 --- a/core/host/src/hdf_driver_loader.c +++ b/core/host/src/hdf_driver_loader.c @@ -42,7 +42,7 @@ struct HdfDeviceNode *HdfDriverLoaderLoadNode( devNode->driverEntry = driverEntry; devNode->deviceInfo = deviceInfo; devNode->deviceObject.property = HcsGetNodeByMatchAttr(HdfGetRootNode(), deviceInfo->deviceMatchAttr); - + devNode->deviceObject.priv = (void *)(deviceInfo->private); if (devNode->deviceObject.property == NULL) { HDF_LOGW("failed to load node, property is null, match attr is: %s", deviceInfo->deviceMatchAttr); } diff --git a/core/shared/include/hdf_attribute_manager.h b/core/shared/include/hdf_attribute_manager.h index ec90ee017..8138a5dbf 100644 --- a/core/shared/include/hdf_attribute_manager.h +++ b/core/shared/include/hdf_attribute_manager.h @@ -14,7 +14,7 @@ const struct DeviceResourceNode *HdfGetRootNode(void); bool HdfAttributeManagerGetHostList(struct HdfSList *hostList); struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *hostName); -bool HdfDeviceListAdd(const char *moduleName, const char *serviceName); +bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const void *privateData); void HdfDeviceListDel(const char *moduleName, const char *serviceName); #endif /* HDF_ATTRIBUTE_MANAGER_H */ diff --git a/core/shared/include/hdf_device_info.h b/core/shared/include/hdf_device_info.h index de2f2984d..aedf9c00b 100755 --- a/core/shared/include/hdf_device_info.h +++ b/core/shared/include/hdf_device_info.h @@ -36,8 +36,13 @@ struct HdfDeviceInfo { const char *moduleName; const char *svcName; const char *deviceMatchAttr; + const void *private; }; +struct HdfPrivateInfo { + uint32_t length; + const void *data; +}; struct HdfDeviceInfo *HdfDeviceInfoNewInstance(void); void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo); void HdfDeviceInfoFreeInstance(struct HdfDeviceInfo *deviceInfo); diff --git a/core/shared/include/hdf_usb_pnp_manage.h b/core/shared/include/hdf_usb_pnp_manage.h new file mode 100644 index 000000000..e22f7cb1d --- /dev/null +++ b/core/shared/include/hdf_usb_pnp_manage.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2020-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 HDF_USB_PNP_MANAGE_H +#define HDF_USB_PNP_MANAGE_H + +#include "hdf_base.h" + +#define USB_PNP_NOTIFY_TEST_MODE false +#define USB_PNP_INFO_MAX_INTERFACES 32 + +enum UsbPnpNotifyServiceCmd { + USB_PNP_NOTIFY_ADD_INTERFACE, + USB_PNP_NOTIFY_REMOVE_INTERFACE, + USB_PNP_NOTIFY_REPORT_INTERFACE, + USB_PNP_NOTIFY_ADD_DEVICE, + USB_PNP_NOTIFY_REMOVE_DEVICE, + #if USB_PNP_NOTIFY_TEST_MODE == true + USB_PNP_NOTIFY_ADD_TEST, + USB_PNP_NOTIFY_REMOVE_TEST, + #endif + USB_PNP_DRIVER_REGISTER_DEVICE, + USB_PNP_DRIVER_UNREGISTER_DEVICE, +}; + +enum UsbPnpNotifyRemoveType { + USB_PNP_NOTIFY_REMOVE_BUS_DEV_NUM, + USB_PNP_NOTIFY_REMOVE_INTERFACE_NUM, +}; + +enum { + USB_PNP_NOTIFY_MATCH_VENDOR = 0x0001, + USB_PNP_NOTIFY_MATCH_PRODUCT = 0x0002, + USB_PNP_NOTIFY_MATCH_DEV_LOW = 0x0004, + USB_PNP_NOTIFY_MATCH_DEV_HIGH = 0x0008, + USB_PNP_NOTIFY_MATCH_DEV_CLASS = 0x0010, + USB_PNP_NOTIFY_MATCH_DEV_SUBCLASS = 0x0020, + USB_PNP_NOTIFY_MATCH_DEV_PROTOCOL = 0x0040, + USB_PNP_NOTIFY_MATCH_INT_CLASS = 0x0080, + USB_PNP_NOTIFY_MATCH_INT_SUBCLASS = 0x0100, + USB_PNP_NOTIFY_MATCH_INT_PROTOCOL = 0x0200, + USB_PNP_NOTIFY_MATCH_INT_NUMBER = 0x0400, +}; + +struct UsbPnpNotifyServiceInfo { + uint32_t length; + + int32_t devNum; + int32_t busNum; + + int32_t interfaceLength; + uint8_t interfaceNumber[USB_PNP_INFO_MAX_INTERFACES]; +} __attribute__ ((packed)); + +struct UsbPnpNotifyInterfaceInfo { + uint8_t interfaceClass; + uint8_t interfaceSubClass; + uint8_t interfaceProtocol; + + uint8_t interfaceNumber; +}; + +struct UsbPnpNotifyDeviceInfo { + uint16_t vendorId; + uint16_t productId; + + uint16_t bcdDeviceLow; + uint16_t bcdDeviceHigh; + + uint8_t deviceClass; + uint8_t deviceSubClass; + uint8_t deviceProtocol; +}; + +struct UsbPnpNotifyMatchInfoTable { + uint32_t usbDevAddr; + int32_t devNum; + int32_t busNum; + + struct UsbPnpNotifyDeviceInfo deviceInfo; + + uint8_t removeType; + uint8_t numInfos; + + struct UsbPnpNotifyInterfaceInfo interfaceInfo[USB_PNP_INFO_MAX_INTERFACES]; +}; + +struct UsbPnpAddRemoveInfo { + int32_t devNum; + int32_t busNum; + uint8_t interfaceNumber; + uint8_t interfaceClass; + uint8_t interfaceSubClass; + uint8_t interfaceProtocol; +}; + +#endif /* HDF_USB_PNP_MANAGE_H */ diff --git a/core/shared/src/hdf_device_info.c b/core/shared/src/hdf_device_info.c index 9228d56fd..1fc5ac93d 100755 --- a/core/shared/src/hdf_device_info.c +++ b/core/shared/src/hdf_device_info.c @@ -29,6 +29,7 @@ void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo) deviceInfo->svcName = NULL; deviceInfo->moduleName = NULL; deviceInfo->deviceMatchAttr = NULL; + deviceInfo->private = NULL; } struct HdfDeviceInfo *HdfDeviceInfoNewInstance() @@ -49,6 +50,9 @@ void HdfDeviceInfoFreeInstance(struct HdfDeviceInfo *deviceInfo) if (deviceInfo->isDynamic && deviceInfo->svcName != NULL) { OsalMemFree((void *)deviceInfo->svcName); } + if (deviceInfo->private != NULL) { + OsalMemFree((void *)deviceInfo->private); + } OsalMemFree(deviceInfo); } } diff --git a/model/input/driver/hdf_input_device_manager.c b/model/input/driver/hdf_input_device_manager.c index 0407f0692..028d802af 100644 --- a/model/input/driver/hdf_input_device_manager.c +++ b/model/input/driver/hdf_input_device_manager.c @@ -52,7 +52,7 @@ static struct HdfDeviceObject *HidRegisterHdfDevice(InputDevice *inputDev) return NULL; } - hdfDev = HdfRegisterDevice(moduleName, svcName); + hdfDev = HdfRegisterDevice(moduleName, svcName, NULL); if (hdfDev == NULL) { HDF_LOGE("%s: HdfRegisterDevice failed", __func__); } diff --git a/test/unittest/common/hdf_main_test.c b/test/unittest/common/hdf_main_test.c index 0662cc6c4..af2847f98 100644 --- a/test/unittest/common/hdf_main_test.c +++ b/test/unittest/common/hdf_main_test.c @@ -52,6 +52,10 @@ #if defined(LOSCFG_DRIVERS_HDF_AUDIO_TEST) || defined(CONFIG_DRIVERS_HDF_AUDIO_TEST) #include "hdf_audio_test.h" #endif +#if defined(LOSCFG_DRIVERS_HDF_USB_DDK_DEVICE) || defined(CONFIG_DRIVERS_HDF_USB_DDK_DEVICE) +#include "hdf_usb_device_test.h" +#endif + #define HDF_LOG_TAG hdf_test @@ -98,6 +102,10 @@ HdfTestFuncList g_hdfTestFuncList[] = { #if defined(LOSCFG_DRIVERS_HDF_AUDIO_TEST) || defined(CONFIG_DRIVERS_HDF_AUDIO_TEST) {TEST_AUDIO_TYPE, HdfAudioEntry}, #endif +#if defined(LOSCFG_DRIVERS_HDF_USB_DDK_DEVICE) || defined(CONFIG_DRIVERS_HDF_USB_DDK_DEVICE) + {TEST_USB_DEVICE_TYPE, HdfUsbDeviceEntry}, +#endif + }; static int32_t HdfTestCaseProcess(struct HdfDeviceIoClient *client, diff --git a/test/unittest/common/hdf_main_test.h b/test/unittest/common/hdf_main_test.h index e2fd3767a..460783447 100644 --- a/test/unittest/common/hdf_main_test.h +++ b/test/unittest/common/hdf_main_test.h @@ -69,6 +69,7 @@ typedef enum { TEST_CONFIG_TYPE = 601, TEST_AUDIO_TYPE = 701, TEST_HDF_FRAME_END = 800, + TEST_USB_DEVICE_TYPE = 900, } HdfTestSubModuleCmd; struct HdfDeviceObject *GetDeviceObject(void); diff --git a/test/unittest/include/hdf_uhdf_test.h b/test/unittest/include/hdf_uhdf_test.h index dcd4f486f..e5586f6a1 100644 --- a/test/unittest/include/hdf_uhdf_test.h +++ b/test/unittest/include/hdf_uhdf_test.h @@ -64,6 +64,7 @@ enum HdfTestSubModuleCmd { TEST_WIFI_END = 600, TEST_CONFIG_TYPE = 601, TEST_HDF_FRAME_END = 800, + TEST_USB_DEVICE_TYPE = 900, }; void HdfTestOpenService(void); diff --git a/test/unittest/manager/sample_driver_test.c b/test/unittest/manager/sample_driver_test.c index bf69825f9..017926772 100644 --- a/test/unittest/manager/sample_driver_test.c +++ b/test/unittest/manager/sample_driver_test.c @@ -37,7 +37,7 @@ int32_t SampleDriverRegisterDevice(struct HdfSBuf *data) return HDF_FAILURE; } - struct HdfDeviceObject *devObj = HdfRegisterDevice(moduleName, serviceName); + struct HdfDeviceObject *devObj = HdfRegisterDevice(moduleName, serviceName, NULL); if (devObj == NULL) { return HDF_FAILURE; } diff --git a/test/unittest/model/usb/include/hdf_usb_device_test.h b/test/unittest/model/usb/include/hdf_usb_device_test.h new file mode 100644 index 000000000..7d5af872e --- /dev/null +++ b/test/unittest/model/usb/include/hdf_usb_device_test.h @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2020-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 HDF_USB_DEVICE_TEST_H +#define HDF_USB_DEVICE_TEST_H + +#include "hdf_base.h" +#include "hdf_main_test.h" + +typedef enum { + USB_DEVICE_CREATE_DEVICE, + USB_DEVICE_CREATE_DEVICE002, + USB_DEVICE_CREATE_DEVICE003, + USB_DEVICE_CREATE_DEVICE004, + USB_DEVICE_CREATE_DEVICE005, + USB_DEVICE_CREATE_DEVICE006, + USB_DEVICE_DEVICE_STATUS, + USB_DEVICE_DEVICE_STATUS002, + USB_DEVICE_DEVICE_STATUS003, + USB_DEVICE_DEVICE_STATUS004, + USB_DEVICE_DEVICE_STATUS005, + USB_DEVICE_DEVICE_STATUS006, + USB_DEVICE_GET_DEVICE, + USB_DEVICE_GET_DEVICE002, + USB_DEVICE_GET_DEVICE003, + USB_DEVICE_GET_DEVICE004, + USB_DEVICE_GET_DEVICE005, + USB_DEVICE_GET_DEVICE006, + USB_DEVICE_GET_INTERFACE, + USB_DEVICE_GET_INTERFACE002, + USB_DEVICE_GET_INTERFACE003, + USB_DEVICE_GET_INTERFACE004, + USB_DEVICE_GET_INTERFACE005, + USB_DEVICE_GET_INTERFACE006, + USB_DEVICE_GET_PIPEINFO, + USB_DEVICE_GET_PIPEINFO002, + USB_DEVICE_GET_PIPEINFO003, + USB_DEVICE_GET_PIPEINFO004, + USB_DEVICE_GET_PIPEINFO005, + USB_DEVICE_GET_PIPEINFO006, + USB_DEVICE_REQUEST_ASYNC, + USB_DEVICE_REQUEST_ASYNC002, + USB_DEVICE_REQUEST_ASYNC003, + USB_DEVICE_REQUEST_ASYNC004, + USB_DEVICE_REQUEST_ASYNC005, + USB_DEVICE_REQUEST_ASYNC006, + USB_DEVICE_REQUEST_SYNC, + USB_DEVICE_REQUEST_SYNC002, + USB_DEVICE_REQUEST_SYNC003, + USB_DEVICE_REQUEST_SYNC004, + USB_DEVICE_REQUEST_SYNC005, + USB_DEVICE_REQUEST_SYNC006, + USB_DEVICE_REGIST_PROP, + USB_DEVICE_REGIST_PROP002, + USB_DEVICE_REGIST_PROP003, + USB_DEVICE_REGIST_PROP004, + USB_DEVICE_REGIST_PROP005, + USB_DEVICE_REGIST_PROP006, + USB_DEVICE_GET_PROP, + USB_DEVICE_GET_PROP002, + USB_DEVICE_GET_PROP003, + USB_DEVICE_GET_PROP004, + USB_DEVICE_GET_PROP005, + USB_DEVICE_GET_PROP006, + USB_DEVICE_SET_PROP, + USB_DEVICE_SET_PROP002, + USB_DEVICE_SET_PROP003, + USB_DEVICE_SET_PROP004, + USB_DEVICE_SET_PROP005, + USB_DEVICE_SET_PROP006, + USB_DEVICE_ALLOC_CTRLREQUEST, + USB_DEVICE_ALLOC_CTRLREQUEST002, + USB_DEVICE_ALLOC_CTRLREQUEST003, + USB_DEVICE_ALLOC_CTRLREQUEST004, + USB_DEVICE_ALLOC_CTRLREQUEST005, + USB_DEVICE_ALLOC_CTRLREQUEST006, + USB_DEVICE_ALLOC_REQUEST, + USB_DEVICE_ALLOC_REQUEST002, + USB_DEVICE_ALLOC_REQUEST003, + USB_DEVICE_ALLOC_REQUEST004, + USB_DEVICE_ALLOC_REQUEST005, + USB_DEVICE_ALLOC_REQUEST006, + USB_DEVICE_FREE_REQUEST, + USB_DEVICE_FREE_REQUEST002, + USB_DEVICE_FREE_REQUEST003, + USB_DEVICE_FREE_REQUEST004, + USB_DEVICE_FREE_REQUEST005, + USB_DEVICE_FREE_REQUEST006, + USB_DEVICE_GET_REQUEST_STATUS, + USB_DEVICE_GET_REQUEST_STATUS002, + USB_DEVICE_GET_REQUEST_STATUS003, + USB_DEVICE_GET_REQUEST_STATUS004, + USB_DEVICE_GET_REQUEST_STATUS005, + USB_DEVICE_GET_REQUEST_STATUS006, + USB_DEVICE_CANCEL_REQUEST, + USB_DEVICE_CANCEL_REQUEST002, + USB_DEVICE_CANCEL_REQUEST003, + USB_DEVICE_CANCEL_REQUEST004, + USB_DEVICE_CANCEL_REQUEST005, + USB_DEVICE_CANCEL_REQUEST006, + USB_DEVICE_STOP_EVENT, + USB_DEVICE_STOP_EVENT002, + USB_DEVICE_STOP_EVENT003, + USB_DEVICE_STOP_EVENT004, + USB_DEVICE_STOP_EVENT005, + USB_DEVICE_STOP_EVENT006, + USB_DEVICE_START_EVENT, + USB_DEVICE_START_EVENT002, + USB_DEVICE_START_EVENT003, + USB_DEVICE_START_EVENT004, + USB_DEVICE_START_EVENT005, + USB_DEVICE_START_EVENT006, + USB_DEVICE_CLOSE_INTERFACE, + USB_DEVICE_CLOSE_INTERFACE002, + USB_DEVICE_CLOSE_INTERFACE003, + USB_DEVICE_CLOSE_INTERFACE004, + USB_DEVICE_CLOSE_INTERFACE005, + USB_DEVICE_CLOSE_INTERFACE006, + USB_DEVICE_OPEN_INTERFACE, + USB_DEVICE_OPEN_INTERFACE002, + USB_DEVICE_OPEN_INTERFACE003, + USB_DEVICE_OPEN_INTERFACE004, + USB_DEVICE_OPEN_INTERFACE005, + USB_DEVICE_OPEN_INTERFACE006, + USB_DEVICE_DELETE_DEVICE, + USB_DEVICE_DELETE_DEVICE002, + USB_DEVICE_DELETE_DEVICE003, + USB_DEVICE_DELETE_DEVICE004, + USB_DEVICE_DELETE_DEVICE005, + USB_DEVICE_DELETE_DEVICE006, + USB_DEVICE_MESSAGE_END = 300, +} HdfUsbDeviceTestCaseCmd; + +int32_t HdfUsbDeviceEntry(HdfTestMsg *msg); + +#endif // HDF_USB_DEVICE_TEST_H \ No newline at end of file diff --git a/test/unittest/model/usb/include/usb_device_lite_cdcacm_test.h b/test/unittest/model/usb/include/usb_device_lite_cdcacm_test.h new file mode 100644 index 000000000..bf204e17d --- /dev/null +++ b/test/unittest/model/usb/include/usb_device_lite_cdcacm_test.h @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef USB_DEVICE_LITE_CDCACM_TEST_H +#define USB_DEVICE_LITE_CDCACM_TEST_H + +#include +#include +#include "usbfn_device.h" +#include "usbfn_request.h" +#include "usbfn_interface.h" +#include "osal_atomic.h" +#include "osal_mutex.h" +#include "osal_time.h" + +#define TEST_TIMES 10 + +#define CDC_ACM +#define QUEUE_SIZE 8 +#define PORT_RATE 9600 +#define CHAR_FORMAT 8 + +#define SS_MAX_PACKET_SIZE 1024 +#define MAX_PACKET_SIZE 512 +#define EP_ADD_NOTIFY 1 +#define EP_ADD_DATA_IN 2 +#define EP_ADD_DATA_OUT 3 +#define DATA_EP_NUM 2 +#define NOTIFY_EP_NUM 1 +#define INTF_COUNT 2 + +#define ACM_NOTIFY_INTERVAL 32 /* ms */ +#define ACM_HS_NOTIFY_INTERVAL 9 /* ms */ +#define ACM_NOTIFY_MAXPACKET 10 /* notification + 2 bytes */ + +#define ACM_CTRL_IDX 1 +#define ACM_DATA_IDX 2 +#define ACM_IAD_IDX 3 + + +struct Serial { + struct AcmDevice *acm; + struct UsbCdcLineCoding lineCoding; + struct OsalMutex lock; + struct DListHead readPool; + struct DListHead readQueue; + int32_t readStarted; + int32_t readAllocated; + struct DListHead writePool; + int32_t writeStarted; + int32_t writeAllocated; + bool writeBusy; + + bool suspended; + bool startDelayed; + int refCount; +}; + +struct AcmNotifyMethod { + void (*Connect)(struct AcmDevice *acm); + void (*Disconnect)(struct AcmDevice *acm); + int (*SendBreak)(struct AcmDevice *acm, int duration); +}; + +struct AcmPipe { + uint8_t id; + uint16_t maxPacketSize; + struct UsbFnInterface *ctrlIface; +}; + +struct AcmInterface { + struct UsbFnInterface *fn; + UsbFnInterfaceHandle handle; +}; + +struct AcmDevice { + struct UsbFnDevice *fnDev; + struct AcmInterface ctrlIface; + struct AcmInterface dataIface; + struct AcmPipe notifyPipe; + struct AcmPipe dataInPipe; + struct AcmPipe dataOutPipe; + struct DListHead ctrlPool; + int32_t ctrlReqNum; + struct UsbFnRequest *notifyReq; + struct OsalMutex lock; + bool pending; + bool connect; + bool haved_submit; + uint32_t enableEvtCnt; + char *udcName; + char submit; + char submit_exit; + struct Serial *port; + struct UsbCdcLineCoding lineCoding; + uint16_t serialState; +#define SERIAL_STATE_DCD (1 << 0) +#define SERIAL_STATE_DSR (1 << 1) +#define SERIAL_STATE_BREAK (1 << 2) +#define SERIAL_STATE_RING (1 << 3) +#define SERIAL_STATE_FRAMING (1 << 4) +#define SERIAL_STATE_PARITY (1 << 5) +#define SERIAL_STATE_OVERRUN (1 << 6) + + uint16_t handshakeBits; + /* notification callbacks */ + struct AcmNotifyMethod *notify; +}; + +struct CtrlInfo { + uint8_t request; + struct AcmDevice *acm; +}; + +extern struct UsbFnDeviceDesc g_acmFnDevice; +struct AcmDevice *SetUpAcmDevice(void); +void ReleaseAcmDevice(struct AcmDevice *acm); +void AcmEventCallback(struct UsbFnEvent *event); +void AcmDeviceRelease(struct AcmDevice *acmDevice); + +int32_t UsbFnDviceTestCreate(void); +int32_t UsbFnDviceTestCreate002(void); +int32_t UsbFnDviceTestCreate003(void); +int32_t UsbFnDviceTestCreate004(void); +int32_t UsbFnDviceTestCreate005(void); +int32_t UsbFnDviceTestCreate006(void); +int32_t UsbFnDviceTestStatus(void); +int32_t UsbFnDviceTestStatus002(void); +int32_t UsbFnDviceTestStatus003(void); +int32_t UsbFnDviceTestStatus004(void); +int32_t UsbFnDviceTestStatus005(void); +int32_t UsbFnDviceTestStatus006(void); +int32_t UsbFnDviceTestGetDevice(void); +int32_t UsbFnDviceTestGetDevice002(void); +int32_t UsbFnDviceTestGetDevice003(void); +int32_t UsbFnDviceTestGetDevice004(void); +int32_t UsbFnDviceTestGetDevice005(void); +int32_t UsbFnDviceTestGetDevice006(void); +int32_t UsbFnDviceTestGetInterface(void); +int32_t UsbFnDviceTestGetInterface002(void); +int32_t UsbFnDviceTestGetInterface003(void); +int32_t UsbFnDviceTestGetInterface004(void); +int32_t UsbFnDviceTestGetInterface005(void); +int32_t UsbFnDviceTestGetInterface006(void); +int32_t UsbFnDviceTestGetPipeInfo(void); +int32_t UsbFnDviceTestGetPipeInfo002(void); +int32_t UsbFnDviceTestGetPipeInfo003(void); +int32_t UsbFnDviceTestGetPipeInfo004(void); +int32_t UsbFnDviceTestGetPipeInfo005(void); +int32_t UsbFnDviceTestGetPipeInfo006(void); +int32_t UsbFnDviceTestRequestAsync(void); +int32_t UsbFnDviceTestRequestAsync002(void); +int32_t UsbFnDviceTestRequestAsync003(void); +int32_t UsbFnDviceTestRequestAsync004(void); +int32_t UsbFnDviceTestRequestAsync005(void); +int32_t UsbFnDviceTestRequestAsync006(void); +int32_t UsbFnDviceTestRequestSync(void); +int32_t UsbFnDviceTestRequestSync002(void); +int32_t UsbFnDviceTestRequestSync003(void); +int32_t UsbFnDviceTestRequestSync004(void); +int32_t UsbFnDviceTestRequestSync005(void); +int32_t UsbFnDviceTestRequestSync006(void); +int32_t UsbFnDviceTestRegistProp(void); +int32_t UsbFnDviceTestRegistProp002(void); +int32_t UsbFnDviceTestRegistProp003(void); +int32_t UsbFnDviceTestRegistProp004(void); +int32_t UsbFnDviceTestRegistProp005(void); +int32_t UsbFnDviceTestRegistProp006(void); +int32_t UsbFnDviceTestGetProp(void); +int32_t UsbFnDviceTestGetProp002(void); +int32_t UsbFnDviceTestGetProp003(void); +int32_t UsbFnDviceTestGetProp004(void); +int32_t UsbFnDviceTestGetProp005(void); +int32_t UsbFnDviceTestGetProp006(void); +int32_t UsbFnDviceTestSetProp(void); +int32_t UsbFnDviceTestSetProp002(void); +int32_t UsbFnDviceTestSetProp003(void); +int32_t UsbFnDviceTestSetProp004(void); +int32_t UsbFnDviceTestSetProp005(void); +int32_t UsbFnDviceTestSetProp006(void); +int32_t UsbFnDviceTestAllocCtrlRequest(void); +int32_t UsbFnDviceTestAllocCtrlRequest002(void); +int32_t UsbFnDviceTestAllocCtrlRequest003(void); +int32_t UsbFnDviceTestAllocCtrlRequest004(void); +int32_t UsbFnDviceTestAllocCtrlRequest005(void); +int32_t UsbFnDviceTestAllocCtrlRequest006(void); +int32_t UsbFnDviceTestAllocRequest(void); +int32_t UsbFnDviceTestAllocRequest002(void); +int32_t UsbFnDviceTestAllocRequest003(void); +int32_t UsbFnDviceTestAllocRequest004(void); +int32_t UsbFnDviceTestAllocRequest005(void); +int32_t UsbFnDviceTestAllocRequest006(void); +int32_t UsbFnDviceTestFreeRequest(void); +int32_t UsbFnDviceTestFreeRequest002(void); +int32_t UsbFnDviceTestFreeRequest003(void); +int32_t UsbFnDviceTestFreeRequest004(void); +int32_t UsbFnDviceTestFreeRequest005(void); +int32_t UsbFnDviceTestFreeRequest006(void); +int32_t UsbFnDviceTestGetRequestStatus(void); +int32_t UsbFnDviceTestGetRequestStatus002(void); +int32_t UsbFnDviceTestGetRequestStatus003(void); +int32_t UsbFnDviceTestGetRequestStatus004(void); +int32_t UsbFnDviceTestGetRequestStatus005(void); +int32_t UsbFnDviceTestGetRequestStatus006(void); +int32_t UsbFnDviceTestCancelRequest(void); +int32_t UsbFnDviceTestCancelRequest002(void); +int32_t UsbFnDviceTestCancelRequest003(void); +int32_t UsbFnDviceTestCancelRequest004(void); +int32_t UsbFnDviceTestCancelRequest005(void); +int32_t UsbFnDviceTestCancelRequest006(void); +int32_t UsbFnDviceTestStopReceEvent(void); +int32_t UsbFnDviceTestStopReceEvent002(void); +int32_t UsbFnDviceTestStopReceEvent003(void); +int32_t UsbFnDviceTestStopReceEvent004(void); +int32_t UsbFnDviceTestStopReceEvent005(void); +int32_t UsbFnDviceTestStopReceEvent006(void); +int32_t UsbFnDviceTestStartReceEvent(void); +int32_t UsbFnDviceTestStartReceEvent002(void); +int32_t UsbFnDviceTestStartReceEvent003(void); +int32_t UsbFnDviceTestStartReceEvent004(void); +int32_t UsbFnDviceTestStartReceEvent005(void); +int32_t UsbFnDviceTestStartReceEvent006(void); +int32_t UsbFnDviceTestCloseInterface(void); +int32_t UsbFnDviceTestCloseInterface002(void); +int32_t UsbFnDviceTestCloseInterface003(void); +int32_t UsbFnDviceTestCloseInterface004(void); +int32_t UsbFnDviceTestCloseInterface005(void); +int32_t UsbFnDviceTestCloseInterface006(void); +int32_t UsbFnDviceTestOpenInterface(void); +int32_t UsbFnDviceTestOpenInterface002(void); +int32_t UsbFnDviceTestOpenInterface003(void); +int32_t UsbFnDviceTestOpenInterface004(void); +int32_t UsbFnDviceTestOpenInterface005(void); +int32_t UsbFnDviceTestOpenInterface006(void); +int32_t UsbFnDviceTestRemove(void); +int32_t UsbFnDviceTestRemove002(void); +int32_t UsbFnDviceTestRemove003(void); + +#endif diff --git a/test/unittest/model/usb/src/hdf_usb_device_test.c b/test/unittest/model/usb/src/hdf_usb_device_test.c new file mode 100644 index 000000000..cf5848216 --- /dev/null +++ b/test/unittest/model/usb/src/hdf_usb_device_test.c @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2020-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 "usb_device_lite_cdcacm_test.h" +#include "hdf_usb_device_test.h" +#include "hdf_module_test.h" +#include "hdf_log.h" +#include "hdf_message_test.h" +#include "osal.h" + +// add test case entry +static HdfTestCaseList g_hdfUsbDeviceTestCaseList[] = { + {USB_DEVICE_CREATE_DEVICE, UsbFnDviceTestCreate}, + {USB_DEVICE_CREATE_DEVICE002, UsbFnDviceTestCreate002}, + {USB_DEVICE_CREATE_DEVICE003, UsbFnDviceTestCreate003}, + {USB_DEVICE_CREATE_DEVICE004, UsbFnDviceTestCreate004}, + {USB_DEVICE_CREATE_DEVICE005, UsbFnDviceTestCreate005}, + {USB_DEVICE_CREATE_DEVICE006, UsbFnDviceTestCreate006}, + {USB_DEVICE_DEVICE_STATUS, UsbFnDviceTestStatus}, + {USB_DEVICE_DEVICE_STATUS002, UsbFnDviceTestStatus002}, + {USB_DEVICE_DEVICE_STATUS003, UsbFnDviceTestStatus003}, + {USB_DEVICE_DEVICE_STATUS004, UsbFnDviceTestStatus004}, + {USB_DEVICE_DEVICE_STATUS005, UsbFnDviceTestStatus005}, + {USB_DEVICE_DEVICE_STATUS006, UsbFnDviceTestStatus006}, + {USB_DEVICE_GET_DEVICE, UsbFnDviceTestGetDevice}, + {USB_DEVICE_GET_DEVICE002, UsbFnDviceTestGetDevice002}, + {USB_DEVICE_GET_DEVICE003, UsbFnDviceTestGetDevice003}, + {USB_DEVICE_GET_DEVICE004, UsbFnDviceTestGetDevice004}, + {USB_DEVICE_GET_DEVICE005, UsbFnDviceTestGetDevice005}, + {USB_DEVICE_GET_DEVICE006, UsbFnDviceTestGetDevice006}, + {USB_DEVICE_GET_INTERFACE, UsbFnDviceTestGetInterface}, + {USB_DEVICE_GET_INTERFACE002, UsbFnDviceTestGetInterface002}, + {USB_DEVICE_GET_INTERFACE003, UsbFnDviceTestGetInterface003}, + {USB_DEVICE_GET_INTERFACE004, UsbFnDviceTestGetInterface004}, + {USB_DEVICE_GET_INTERFACE005, UsbFnDviceTestGetInterface005}, + {USB_DEVICE_GET_INTERFACE006, UsbFnDviceTestGetInterface006}, + {USB_DEVICE_GET_PIPEINFO, UsbFnDviceTestGetPipeInfo}, + {USB_DEVICE_GET_PIPEINFO002, UsbFnDviceTestGetPipeInfo002}, + {USB_DEVICE_GET_PIPEINFO003, UsbFnDviceTestGetPipeInfo003}, + {USB_DEVICE_GET_PIPEINFO004, UsbFnDviceTestGetPipeInfo004}, + {USB_DEVICE_GET_PIPEINFO005, UsbFnDviceTestGetPipeInfo005}, + {USB_DEVICE_GET_PIPEINFO006, UsbFnDviceTestGetPipeInfo006}, + {USB_DEVICE_REQUEST_ASYNC, UsbFnDviceTestRequestAsync}, + {USB_DEVICE_REQUEST_ASYNC002, UsbFnDviceTestRequestAsync002}, + {USB_DEVICE_REQUEST_ASYNC003, UsbFnDviceTestRequestAsync003}, + {USB_DEVICE_REQUEST_ASYNC004, UsbFnDviceTestRequestAsync004}, + {USB_DEVICE_REQUEST_ASYNC005, UsbFnDviceTestRequestAsync005}, + {USB_DEVICE_REQUEST_ASYNC006, UsbFnDviceTestRequestAsync006}, + {USB_DEVICE_REQUEST_SYNC, UsbFnDviceTestRequestSync}, + {USB_DEVICE_REQUEST_SYNC002, UsbFnDviceTestRequestSync002}, + {USB_DEVICE_REQUEST_SYNC003, UsbFnDviceTestRequestSync003}, + {USB_DEVICE_REQUEST_SYNC004, UsbFnDviceTestRequestSync004}, + {USB_DEVICE_REQUEST_SYNC005, UsbFnDviceTestRequestSync005}, + {USB_DEVICE_REQUEST_SYNC006, UsbFnDviceTestRequestSync006}, + {USB_DEVICE_REGIST_PROP, UsbFnDviceTestRegistProp}, + {USB_DEVICE_REGIST_PROP002, UsbFnDviceTestRegistProp002}, + {USB_DEVICE_REGIST_PROP003, UsbFnDviceTestRegistProp003}, + {USB_DEVICE_REGIST_PROP004, UsbFnDviceTestRegistProp004}, + {USB_DEVICE_REGIST_PROP005, UsbFnDviceTestRegistProp005}, + {USB_DEVICE_REGIST_PROP006, UsbFnDviceTestRegistProp006}, + {USB_DEVICE_GET_PROP, UsbFnDviceTestGetProp}, + {USB_DEVICE_GET_PROP002, UsbFnDviceTestGetProp002}, + {USB_DEVICE_GET_PROP003, UsbFnDviceTestGetProp003}, + {USB_DEVICE_GET_PROP004, UsbFnDviceTestGetProp004}, + {USB_DEVICE_GET_PROP005, UsbFnDviceTestGetProp005}, + {USB_DEVICE_GET_PROP006, UsbFnDviceTestGetProp006}, + {USB_DEVICE_SET_PROP, UsbFnDviceTestSetProp}, + {USB_DEVICE_SET_PROP002, UsbFnDviceTestSetProp002}, + {USB_DEVICE_SET_PROP003, UsbFnDviceTestSetProp003}, + {USB_DEVICE_SET_PROP004, UsbFnDviceTestSetProp004}, + {USB_DEVICE_SET_PROP005, UsbFnDviceTestSetProp005}, + {USB_DEVICE_SET_PROP006, UsbFnDviceTestSetProp006}, + {USB_DEVICE_ALLOC_CTRLREQUEST, UsbFnDviceTestAllocCtrlRequest}, + {USB_DEVICE_ALLOC_CTRLREQUEST002, UsbFnDviceTestAllocCtrlRequest002}, + {USB_DEVICE_ALLOC_CTRLREQUEST003, UsbFnDviceTestAllocCtrlRequest003}, + {USB_DEVICE_ALLOC_CTRLREQUEST004, UsbFnDviceTestAllocCtrlRequest004}, + {USB_DEVICE_ALLOC_CTRLREQUEST005, UsbFnDviceTestAllocCtrlRequest005}, + {USB_DEVICE_ALLOC_CTRLREQUEST006, UsbFnDviceTestAllocCtrlRequest006}, + {USB_DEVICE_ALLOC_REQUEST, UsbFnDviceTestAllocRequest}, + {USB_DEVICE_ALLOC_REQUEST002, UsbFnDviceTestAllocRequest002}, + {USB_DEVICE_ALLOC_REQUEST003, UsbFnDviceTestAllocRequest003}, + {USB_DEVICE_ALLOC_REQUEST004, UsbFnDviceTestAllocRequest004}, + {USB_DEVICE_ALLOC_REQUEST005, UsbFnDviceTestAllocRequest005}, + {USB_DEVICE_ALLOC_REQUEST006, UsbFnDviceTestAllocRequest006}, + {USB_DEVICE_FREE_REQUEST, UsbFnDviceTestFreeRequest}, + {USB_DEVICE_FREE_REQUEST002, UsbFnDviceTestFreeRequest002}, + {USB_DEVICE_FREE_REQUEST003, UsbFnDviceTestFreeRequest003}, + {USB_DEVICE_FREE_REQUEST004, UsbFnDviceTestFreeRequest004}, + {USB_DEVICE_FREE_REQUEST005, UsbFnDviceTestFreeRequest005}, + {USB_DEVICE_FREE_REQUEST006, UsbFnDviceTestFreeRequest006}, + {USB_DEVICE_GET_REQUEST_STATUS, UsbFnDviceTestGetRequestStatus}, + {USB_DEVICE_GET_REQUEST_STATUS002, UsbFnDviceTestGetRequestStatus002}, + {USB_DEVICE_GET_REQUEST_STATUS003, UsbFnDviceTestGetRequestStatus003}, + {USB_DEVICE_GET_REQUEST_STATUS004, UsbFnDviceTestGetRequestStatus004}, + {USB_DEVICE_GET_REQUEST_STATUS005, UsbFnDviceTestGetRequestStatus005}, + {USB_DEVICE_GET_REQUEST_STATUS006, UsbFnDviceTestGetRequestStatus006}, + {USB_DEVICE_CANCEL_REQUEST, UsbFnDviceTestCancelRequest}, + {USB_DEVICE_CANCEL_REQUEST002, UsbFnDviceTestCancelRequest002}, + {USB_DEVICE_CANCEL_REQUEST003, UsbFnDviceTestCancelRequest003}, + {USB_DEVICE_CANCEL_REQUEST004, UsbFnDviceTestCancelRequest004}, + {USB_DEVICE_CANCEL_REQUEST005, UsbFnDviceTestCancelRequest005}, + {USB_DEVICE_CANCEL_REQUEST006, UsbFnDviceTestCancelRequest006}, + {USB_DEVICE_STOP_EVENT, UsbFnDviceTestStopReceEvent}, + {USB_DEVICE_STOP_EVENT002, UsbFnDviceTestStopReceEvent002}, + {USB_DEVICE_STOP_EVENT003, UsbFnDviceTestStopReceEvent003}, + {USB_DEVICE_STOP_EVENT004, UsbFnDviceTestStopReceEvent004}, + {USB_DEVICE_STOP_EVENT005, UsbFnDviceTestStopReceEvent005}, + {USB_DEVICE_STOP_EVENT006, UsbFnDviceTestStopReceEvent006}, + {USB_DEVICE_START_EVENT, UsbFnDviceTestStartReceEvent}, + {USB_DEVICE_START_EVENT002, UsbFnDviceTestStartReceEvent002}, + {USB_DEVICE_START_EVENT003, UsbFnDviceTestStartReceEvent003}, + {USB_DEVICE_START_EVENT004, UsbFnDviceTestStartReceEvent004}, + {USB_DEVICE_START_EVENT005, UsbFnDviceTestStartReceEvent005}, + {USB_DEVICE_START_EVENT006, UsbFnDviceTestStartReceEvent006}, + {USB_DEVICE_CLOSE_INTERFACE, UsbFnDviceTestCloseInterface}, + {USB_DEVICE_CLOSE_INTERFACE002, UsbFnDviceTestCloseInterface002}, + {USB_DEVICE_CLOSE_INTERFACE003, UsbFnDviceTestCloseInterface003}, + {USB_DEVICE_CLOSE_INTERFACE004, UsbFnDviceTestCloseInterface004}, + {USB_DEVICE_CLOSE_INTERFACE005, UsbFnDviceTestCloseInterface005}, + {USB_DEVICE_CLOSE_INTERFACE006, UsbFnDviceTestCloseInterface006}, + {USB_DEVICE_OPEN_INTERFACE, UsbFnDviceTestOpenInterface}, + {USB_DEVICE_OPEN_INTERFACE002, UsbFnDviceTestOpenInterface002}, + {USB_DEVICE_OPEN_INTERFACE003, UsbFnDviceTestOpenInterface003}, + {USB_DEVICE_OPEN_INTERFACE004, UsbFnDviceTestOpenInterface004}, + {USB_DEVICE_OPEN_INTERFACE005, UsbFnDviceTestOpenInterface005}, + {USB_DEVICE_OPEN_INTERFACE006, UsbFnDviceTestOpenInterface006}, + {USB_DEVICE_DELETE_DEVICE, UsbFnDviceTestRemove}, + {USB_DEVICE_DELETE_DEVICE002, UsbFnDviceTestRemove002}, + {USB_DEVICE_DELETE_DEVICE003, UsbFnDviceTestRemove003}, +}; + +int32_t HdfUsbDeviceEntry(HdfTestMsg *msg) +{ + int32_t result, i; + + if (msg == NULL) { + HDF_LOGE("%s is fail: HdfTestMsg is NULL!", __func__); + return HDF_SUCCESS; + } + + for (i = 0; i < sizeof(g_hdfUsbDeviceTestCaseList) / sizeof(g_hdfUsbDeviceTestCaseList[0]); ++i) { + if ((msg->subCmd == g_hdfUsbDeviceTestCaseList[i].subCmd) && (g_hdfUsbDeviceTestCaseList[i].testFunc != NULL)) { + result = g_hdfUsbDeviceTestCaseList[i].testFunc(); + HDF_LOGE("HdfTest:usb device test result[%s-%u]", ((result == 0) ? "pass" : "fail"), msg->subCmd); + msg->result = (result == 0) ? HDF_SUCCESS : HDF_FAILURE; + return HDF_SUCCESS; + } + } + return HDF_SUCCESS; +} \ No newline at end of file diff --git a/test/unittest/model/usb/src/usb_device_lite_cdcacm_test.c b/test/unittest/model/usb/src/usb_device_lite_cdcacm_test.c new file mode 100644 index 000000000..fa94ee7b4 --- /dev/null +++ b/test/unittest/model/usb/src/usb_device_lite_cdcacm_test.c @@ -0,0 +1,770 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "usb_device_lite_cdcacm_test.h" + +static struct UsbInterfaceAssocDescriptor g_acmIadDescriptor = { + .bLength = sizeof(g_acmIadDescriptor), + .bDescriptorType = USB_DDK_DT_INTERFACE_ASSOCIATION, +#ifdef CDC_ECM + .bFirstInterface = 0x02, +#else + .bFirstInterface = 0, +#endif + .bInterfaceCount = INTF_COUNT, + .bFunctionClass = USB_DDK_CLASS_COMM, + .bFunctionSubClass = USB_DDK_CDC_SUBCLASS_ACM, + .bFunctionProtocol = USB_DDK_CDC_ACM_PROTO_AT_V25TER, + .iFunction = ACM_IAD_IDX, +}; + +static struct UsbInterfaceDescriptor g_acmControlInterfaceDesc = { + .bLength = USB_DDK_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DDK_DT_INTERFACE, +#ifdef CDC_ECM + .bInterfaceNumber = 0x02, +#else + .bInterfaceNumber = 0, +#endif + .bAlternateSetting = 0, + .bNumEndpoints = NOTIFY_EP_NUM, + .bInterfaceClass = USB_DDK_CLASS_COMM, + .bInterfaceSubClass = USB_DDK_CDC_SUBCLASS_ACM, + .bInterfaceProtocol = USB_DDK_CDC_ACM_PROTO_AT_V25TER, + .iInterface = ACM_CTRL_IDX, +}; + +static struct UsbInterfaceDescriptor g_acmDataInterfaceDesc = { + .bLength = USB_DDK_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DDK_DT_INTERFACE, +#ifdef CDC_ECM + .bInterfaceNumber = 0x03, +#else + .bInterfaceNumber = 1, +#endif + .bAlternateSetting = 0, + .bNumEndpoints = DATA_EP_NUM, + .bInterfaceClass = USB_DDK_CLASS_CDC_DATA, + .bInterfaceSubClass = 0, + .bInterfaceProtocol = 2, + .iInterface = ACM_DATA_IDX, +}; + +static struct UsbCdcHeaderDesc g_acmHeaderDesc = { + .bLength = sizeof(g_acmHeaderDesc), + .bDescriptorType = USB_DDK_DT_CS_INTERFACE, + .bDescriptorSubType = USB_DDK_CDC_HEADER_TYPE, + .bcdCDC = CpuToLe16(0x0110), +}; + +static struct UsbCdcCallMgmtDescriptor g_acmCallMgmtDescriptor = { + .bLength = sizeof(g_acmCallMgmtDescriptor), + .bDescriptorType = USB_DDK_DT_CS_INTERFACE, + .bDescriptorSubType = USB_DDK_CDC_CALL_MANAGEMENT_TYPE, + .bmCapabilities = 0, + .bDataInterface = 1, +}; + +static struct UsbCdcAcmDescriptor g_acmDescriptor = { + .bLength = sizeof(g_acmDescriptor), + .bDescriptorType = USB_DDK_DT_CS_INTERFACE, + .bDescriptorSubType = USB_DDK_CDC_ACM_TYPE, + .bmCapabilities = USB_DDK_CDC_CAP_LINE, +}; + +static struct UsbCdcUnionDesc g_acmUnionDesc = { + .bLength = sizeof(g_acmUnionDesc), + .bDescriptorType = USB_DDK_DT_CS_INTERFACE, + .bDescriptorSubType = USB_DDK_CDC_UNION_TYPE, +#ifdef CDC_ECM + .bMasterInterface0 = 0x02, + .bSlaveInterface0 = 0x03, +#else + .bMasterInterface0 = 0, + .bSlaveInterface0 = 1, +#endif +}; + +static struct UsbEndpointDescriptor g_acmFsNotifyDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_NOTIFY | USB_DDK_DIR_IN, + .bmAttributes = USB_DDK_ENDPOINT_XFER_INT, + .wMaxPacketSize = CpuToLe16(ACM_NOTIFY_MAXPACKET), + .bInterval = ACM_NOTIFY_INTERVAL, +}; + +static struct UsbEndpointDescriptor g_acmFsInDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_DATA_IN | USB_DDK_DIR_IN, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, +}; + +static struct UsbEndpointDescriptor g_acmFsOutDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_DATA_OUT | USB_DDK_DIR_OUT, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, +}; + +static struct UsbDescriptorHeader *g_acmFsFunction[] = { + (struct UsbDescriptorHeader *) &g_acmIadDescriptor, + (struct UsbDescriptorHeader *) &g_acmControlInterfaceDesc, + (struct UsbDescriptorHeader *) &g_acmHeaderDesc, + (struct UsbDescriptorHeader *) &g_acmCallMgmtDescriptor, + (struct UsbDescriptorHeader *) &g_acmDescriptor, + (struct UsbDescriptorHeader *) &g_acmUnionDesc, + (struct UsbDescriptorHeader *) &g_acmFsNotifyDesc, + (struct UsbDescriptorHeader *) &g_acmDataInterfaceDesc, + (struct UsbDescriptorHeader *) &g_acmFsInDesc, + (struct UsbDescriptorHeader *) &g_acmFsOutDesc, + NULL, +}; + +static struct UsbEndpointDescriptor g_acmHsNotifyDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_NOTIFY | USB_DDK_DIR_IN, + .bmAttributes = USB_DDK_ENDPOINT_XFER_INT, + .wMaxPacketSize = CpuToLe16(ACM_NOTIFY_MAXPACKET), + .bInterval = ACM_HS_NOTIFY_INTERVAL, +}; + +static struct UsbEndpointDescriptor g_acmHsInDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_DATA_IN | USB_DDK_DIR_IN, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .wMaxPacketSize = CpuToLe16(MAX_PACKET_SIZE), +}; + +static struct UsbEndpointDescriptor g_acmHsOutDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_DATA_OUT | USB_DDK_DIR_OUT, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .wMaxPacketSize = CpuToLe16(MAX_PACKET_SIZE), +}; + +static struct UsbDescriptorHeader *g_acmHsFunction[] = { + (struct UsbDescriptorHeader *) &g_acmIadDescriptor, + (struct UsbDescriptorHeader *) &g_acmControlInterfaceDesc, + (struct UsbDescriptorHeader *) &g_acmHeaderDesc, + (struct UsbDescriptorHeader *) &g_acmCallMgmtDescriptor, + (struct UsbDescriptorHeader *) &g_acmDescriptor, + (struct UsbDescriptorHeader *) &g_acmUnionDesc, + (struct UsbDescriptorHeader *) &g_acmHsNotifyDesc, + (struct UsbDescriptorHeader *) &g_acmDataInterfaceDesc, + (struct UsbDescriptorHeader *) &g_acmHsInDesc, + (struct UsbDescriptorHeader *) &g_acmHsOutDesc, + NULL, +}; + +static struct UsbEndpointDescriptor g_acmSsInDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_DATA_IN | USB_DDK_DIR_IN, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .wMaxPacketSize = CpuToLe16(SS_MAX_PACKET_SIZE), +}; + +static struct UsbEndpointDescriptor g_acmSsOutDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_DATA_OUT | USB_DDK_DIR_OUT, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .wMaxPacketSize = CpuToLe16(SS_MAX_PACKET_SIZE), +}; + +static struct UsbSsEpCompDescriptor g_acmSsBulkCompDesc = { + .bLength = sizeof(g_acmSsBulkCompDesc), + .bDescriptorType = USB_DDK_DT_SS_ENDPOINT_COMP, +}; + +static struct UsbDescriptorHeader *g_acmSsFunction[] = { + (struct UsbDescriptorHeader *) &g_acmIadDescriptor, + (struct UsbDescriptorHeader *) &g_acmControlInterfaceDesc, + (struct UsbDescriptorHeader *) &g_acmHeaderDesc, + (struct UsbDescriptorHeader *) &g_acmCallMgmtDescriptor, + (struct UsbDescriptorHeader *) &g_acmDescriptor, + (struct UsbDescriptorHeader *) &g_acmUnionDesc, + (struct UsbDescriptorHeader *) &g_acmHsNotifyDesc, + (struct UsbDescriptorHeader *) &g_acmSsBulkCompDesc, + (struct UsbDescriptorHeader *) &g_acmDataInterfaceDesc, + (struct UsbDescriptorHeader *) &g_acmSsInDesc, + (struct UsbDescriptorHeader *) &g_acmSsBulkCompDesc, + (struct UsbDescriptorHeader *) &g_acmSsOutDesc, + (struct UsbDescriptorHeader *) &g_acmSsBulkCompDesc, + NULL, +}; + +static struct UsbString g_acmStringDefs[] = { + [0].s = "CDC Abstract Control Model (ACM)", + [1].s = "CDC ACM Data", + [2].s = "CDC Serial", + { } /* end of list */ +}; + +static struct UsbFnStrings g_acmStringTable = { + .language = 0x0409, /* en-us */ + .strings = g_acmStringDefs, +}; + +static struct UsbFnStrings *g_acmStrings[] = { + &g_acmStringTable, + NULL, +}; + +static struct UsbFnFunction g_acmFunction = { + .funcName = "f_generic.0", + .strings = g_acmStrings, + .fsDescriptors = g_acmFsFunction, + .hsDescriptors = g_acmHsFunction, + .ssDescriptors = g_acmSsFunction, + .sspDescriptors = NULL, +}; + +/** device **/ +#define BCD_USB 0x0200 +#define DEVICE_VENDOR_ID 0x12D1 +#define DEVICE_PRODUCT_ID 0x5000 +#define DEVICE_VERSION 0x0223 + +#define USB_MAX_PACKET_SIZE 0x40 +#define POWER 500 + +#define USB_FUNC_CONFIG_IDX USB_FUNC_FIRST_AVAIL_IDX +#define DRIVER_DESC "HDC Device" +#define CONFIG_DESC "hdc" + +static struct UsbDeviceDescriptor g_cdcMasterDeviceDesc = { + .bLength = sizeof(g_cdcMasterDeviceDesc), + .bDescriptorType = USB_DDK_DT_DEVICE, + .bcdUSB = CpuToLe16(BCD_USB), + .bDeviceClass = 0, + .bDeviceSubClass = 0, + .bDeviceProtocol = 0, + .bMaxPacketSize0 = USB_MAX_PACKET_SIZE, + .idVendor = CpuToLe16(DEVICE_VENDOR_ID), + .idProduct = CpuToLe16(DEVICE_PRODUCT_ID), + .bcdDevice = CpuToLe16(DEVICE_VERSION), + .iManufacturer = USB_FUNC_MANUFACTURER_IDX, + .iProduct = USB_FUNC_PRODUCT_IDX, + .iSerialNumber = USB_FUNC_SERIAL_IDX, + .bNumConfigurations = 1, +}; + +static struct UsbString g_stringsDev[] = { + {USB_FUNC_MANUFACTURER_IDX, "HISILICON"}, + {USB_FUNC_PRODUCT_IDX, DRIVER_DESC}, + {USB_FUNC_SERIAL_IDX, "0123456789POPLAR"}, + {USB_FUNC_CONFIG_IDX, CONFIG_DESC}, + { } /* end of list */ +}; + +static struct UsbFnStrings g_stringTabDev = { + .language = 0x0409, /* en-us */ + .strings = g_stringsDev, +}; + +static struct UsbFnStrings *g_devStrings[] = { + &g_stringTabDev, + NULL, +}; + +static struct UsbFnFunction *g_functions[] = { +#ifdef CDC_ECM + &g_ecmFunction, +#endif +#ifdef CDC_ACM + &g_acmFunction, +#endif + NULL +}; + +static struct UsbFnConfiguration g_masterConfig = { + .configurationValue = 1, + .iConfiguration = USB_FUNC_CONFIG_IDX, + .attributes = USB_CFG_BUS_POWERED, + .maxPower = POWER, + .functions = g_functions, +}; + +static struct UsbFnConfiguration *g_configs[] = { + &g_masterConfig, + NULL, +}; + +struct UsbFnDeviceDesc g_acmFnDevice = { + .deviceDesc = &g_cdcMasterDeviceDesc, + .deviceStrings = g_devStrings, + .configs = g_configs, +}; + +static struct Serial *SerialAlloc(void) +{ + struct Serial *port = NULL; + port = (struct Serial *)OsalMemCalloc(sizeof(*port)); + if (port == NULL) { + return NULL; + } + OsalMutexInit(&port->lock); + DListHeadInit(&port->readPool); + DListHeadInit(&port->readQueue); + DListHeadInit(&port->writePool); + + port->lineCoding.dwDTERate = CpuToLe32(PORT_RATE); + port->lineCoding.bCharFormat = CHAR_FORMAT; + port->lineCoding.bParityType = USB_CDC_NO_PARITY; + port->lineCoding.bDataBits = USB_CDC_1_STOP_BITS; + return port; +} + +static int ParseInterfaces(struct AcmDevice *acmDevice) +{ + uint32_t i; + uint32_t j; + struct UsbFnInterface *fnIface = NULL; + UsbFnInterfaceHandle handle = NULL; + int ret; + + for (i = 0; i < acmDevice->fnDev->numInterfaces; i++) { + fnIface = (struct UsbFnInterface *)UsbFnGetInterface(acmDevice->fnDev, i); + if (fnIface == NULL) { + return -1; + } + handle = UsbFnOpenInterface(fnIface); + if (handle == NULL) { + return -1; + } + for (j = 0; j < fnIface->info.numPipes; j++) { + struct UsbFnPipeInfo pipeInfo; + ret = UsbFnGetInterfacePipeInfo(fnIface, j, &pipeInfo); + if (ret != HDF_SUCCESS) { + return -1; + } + if (pipeInfo.type == USB_PIPE_TYPE_INTERRUPT) { + acmDevice->notifyPipe.id = pipeInfo.id; + acmDevice->notifyPipe.maxPacketSize = pipeInfo.maxPacketSize; + acmDevice->ctrlIface.fn = fnIface; + acmDevice->ctrlIface.handle = handle; + } else if (pipeInfo.type == USB_PIPE_TYPE_BULK) { + if (pipeInfo.dir == USB_PIPE_DIRECTION_IN) { + acmDevice->dataInPipe.id = pipeInfo.id; + acmDevice->dataInPipe.maxPacketSize = pipeInfo.maxPacketSize; + acmDevice->dataIface.fn = fnIface; + acmDevice->dataIface.handle = handle; + } else { + acmDevice->dataOutPipe.id = pipeInfo.id; + acmDevice->dataOutPipe.maxPacketSize = pipeInfo.maxPacketSize; + acmDevice->dataIface.fn = fnIface; + acmDevice->dataIface.handle = handle; + } + } + } + } + return 0; +} + +static void CtrlComplete(uint8_t pipe, struct UsbFnRequest *req) +{ + struct CtrlInfo *ctrlInfo = (struct CtrlInfo *)req->context; + struct AcmDevice *acm = ctrlInfo->acm; + + if (req == NULL) { + return; + } + if (USB_REQUEST_COMPLETED != req->status) { + goto out; + } + + if (ctrlInfo->request == USB_DDK_CDC_REQ_SET_LINE_CODING) { + struct UsbCdcLineCoding *value = (struct UsbCdcLineCoding *)req->buf; + if (req->actual == sizeof(*value)) { + acm->lineCoding = *value; + } + acm->connect = true; + } +out: + DListInsertTail(&req->list, &acm->ctrlPool); +} + +static int AllocCtrlRequests(struct AcmDevice *acmDevice) +{ + struct DListHead *head = &acmDevice->ctrlPool; + struct UsbFnRequest *req = NULL; + struct CtrlInfo *ctrlInfo = NULL; + int i; + int count = 2; + + DListHeadInit(&acmDevice->ctrlPool); + acmDevice->ctrlReqNum = 0; + + for (i = 0; i < count; i++) { + ctrlInfo = (struct CtrlInfo *)OsalMemCalloc(sizeof(*ctrlInfo)); + if (NULL == ctrlInfo) { + return -1; + } + ctrlInfo->acm = acmDevice; + req = UsbFnAllocCtrlRequest(acmDevice->ctrlIface.handle, + sizeof(struct UsbCdcLineCoding) + sizeof(struct UsbCdcLineCoding)); + if (NULL == req) { + return -1; + } + req->complete = CtrlComplete; + req->context = ctrlInfo; + DListInsertTail(&req->list, head); + acmDevice->ctrlReqNum++; + } + + return 0; +} + +static int32_t SendNotifyRequest(struct AcmDevice *acm, uint8_t type, + uint16_t value, void *data, uint32_t length) +{ + struct UsbFnRequest *req = acm->notifyReq; + struct UsbCdcNotification *notify = NULL; + int ret; + if (acm == NULL || req->buf) { + return -1; + } + acm->notifyReq = NULL; + acm->pending = false; + req->length = sizeof(*notify) + length; + + notify = (struct UsbCdcNotification *)req->buf; + notify->bmRequestType = USB_DDK_DIR_IN | USB_DDK_TYPE_CLASS | USB_DDK_RECIP_INTERFACE; + notify->bNotificationType = type; + notify->wValue = CpuToLe16(value); + notify->wIndex = CpuToLe16(acm->ctrlIface.fn->info.index); + notify->wLength = CpuToLe16(length); + memcpy_s((void *)(notify + 1), length, data, length); + + ret = UsbFnSubmitRequestAsync(req); + return ret; +} + +static int32_t NotifySerialState(struct AcmDevice *acm) +{ + int32_t ret = 0; + uint16_t serialState; + + OsalMutexLock(&acm->lock); + if (acm->notifyReq) { + serialState = CpuToLe16(acm->serialState); + ret = SendNotifyRequest(acm, USB_DDK_CDC_NOTIFY_SERIAL_STATE, + 0, &serialState, sizeof(acm->serialState)); + } else { + acm->pending = true; + } + OsalMutexUnlock(&acm->lock); + + return ret; +} + +static void NotifyComplete(uint8_t pipe, struct UsbFnRequest *req) +{ + struct AcmDevice *acm = (struct AcmDevice *)req->context; + bool pending = false; + + if (acm == NULL) { + return; + } + OsalMutexLock(&acm->lock); + if (req->status != USB_REQUEST_NO_DEVICE) { + pending = acm->pending; + } + acm->notifyReq = req; + OsalMutexUnlock(&acm->lock); + if (pending) { + NotifySerialState(acm); + } +} + +static int32_t AllocNotifyRequest(struct AcmDevice *acmDevice) +{ + /* allocate notification request */ + acmDevice->notifyReq = UsbFnAllocRequest(acmDevice->ctrlIface.handle, acmDevice->notifyPipe.id, + sizeof(struct UsbCdcNotification)); + if (acmDevice->notifyReq == NULL) { + return -1; + } + acmDevice->notifyReq->complete = NotifyComplete; + acmDevice->notifyReq->context = acmDevice; + + return HDF_SUCCESS; +} + +static void Connect(struct AcmDevice *acm) +{ + if (acm == NULL) { + return; + } + acm->serialState |= SERIAL_STATE_DSR | SERIAL_STATE_DCD; + NotifySerialState(acm); +} + +static void Disconnect(struct AcmDevice *acm) +{ + if (acm == NULL) { + return; + } + acm->serialState &= ~(SERIAL_STATE_DSR | SERIAL_STATE_DCD); + NotifySerialState(acm); +} + +static int32_t SendBreak(struct AcmDevice *acm, int duration) +{ + uint16_t state; + + if (acm == NULL) { + return -1; + } + state = acm->serialState; + state &= ~SERIAL_STATE_BREAK; + if (duration) + state |= SERIAL_STATE_BREAK; + + acm->serialState = state; + return NotifySerialState(acm); +} + +static struct AcmNotifyMethod g_notifyMethod = { + .Connect = Connect, + .Disconnect = Disconnect, + .SendBreak = SendBreak, +}; + +static uint32_t Enable(struct AcmDevice *acm) +{ + struct Serial *port = acm->port; + OsalMutexLock(&port->lock); + port->acm = acm; + acm->lineCoding = port->lineCoding; + if (port->refCount) { + if (acm->notify && acm->notify->Connect) { + acm->notify->Connect(acm); + } + } else { + if (acm->notify && acm->notify->Disconnect) { + acm->notify->Disconnect(acm); + } + } + OsalMutexUnlock(&port->lock); + + return HDF_SUCCESS; +} + +static uint32_t Disable(struct AcmDevice *acm) +{ + return HDF_SUCCESS; +} + +static struct UsbFnRequest *GetCtrlReq(struct AcmDevice *acm) +{ + struct UsbFnRequest *req = NULL; + struct DListHead *pool = &acm->ctrlPool; + if (!DListIsEmpty(pool)) { + req = DLIST_FIRST_ENTRY(pool, struct UsbFnRequest, list); + DListRemove(&req->list); + } + return req; +} + +static void Setup(struct AcmDevice *acm, struct UsbFnCtrlRequest *setup) +{ + struct UsbFnRequest *req = NULL; + struct CtrlInfo *ctrlInfo = NULL; + uint16_t value = Le16ToCpu(setup->value); + uint16_t length = Le16ToCpu(setup->length); + int ret = 0; + req = GetCtrlReq(acm); + if (req == NULL) { + return; + } + switch (setup->request) { + case USB_DDK_CDC_REQ_SET_LINE_CODING: + if (length != sizeof(struct UsbCdcLineCoding)) { + goto out; + } + ret = length; + break; + case USB_DDK_CDC_REQ_GET_LINE_CODING: + ret = (length > sizeof(struct UsbCdcLineCoding)) ? \ + sizeof(struct UsbCdcLineCoding) : length; + if (acm->lineCoding.dwDTERate == 0) { + acm->lineCoding = acm->port->lineCoding; + } + memcpy_s(req->buf, req->length, &acm->lineCoding, ret); + break; + case USB_DDK_CDC_REQ_SET_CONTROL_LINE_STATE: + ret = 0; + acm->handshakeBits = value; + break; + default: + break; + } + +out: + ctrlInfo = (struct CtrlInfo *)req->context; + ctrlInfo->request = setup->request; + req->length = ret; + ret = UsbFnSubmitRequestAsync(req); +} + +static void Suspend(struct AcmDevice *acm) +{ + struct Serial *port = acm->port; + + OsalMutexLock(&port->lock); + port->suspended = true; + OsalMutexUnlock(&port->lock); +} + +static void Resume(struct AcmDevice *acm) +{ + struct Serial *port = acm->port; + + OsalMutexLock(&port->lock); + port->suspended = false; + if (acm->notify && acm->notify->Connect) { + acm->notify->Connect(acm); + } + port->startDelayed = false; + OsalMutexUnlock(&port->lock); +} + +void AcmEventCallback(struct UsbFnEvent *event) +{ + struct AcmDevice *acm = NULL; + + if (event == NULL || event->context == NULL) + return; + acm = (struct AcmDevice *)event->context; + switch (event->type) { + case USBFN_STATE_BIND: + break; + case USBFN_STATE_UNBIND: + break; + case USBFN_STATE_ENABLE: + Enable(acm); + break; + case USBFN_STATE_DISABLE: + Disable(acm); + acm->enableEvtCnt = 0; + break; + case USBFN_STATE_SETUP: + Setup(acm, event->setup); + break; + case USBFN_STATE_SUSPEND: + Suspend(acm); + break; + case USBFN_STATE_RESUME: + Resume(acm); + break; + default: + break; + } +} + +struct AcmDevice *SetUpAcmDevice(void) +{ + int32_t ret; + + struct AcmDevice *acmDevice = NULL; + struct UsbFnDescriptorData descData; + descData.type = USBFN_DESC_DATA_TYPE_DESC; + descData.descriptor = &g_acmFnDevice; + acmDevice = (struct AcmDevice *)OsalMemCalloc(sizeof(*acmDevice)); + if (acmDevice == NULL) { + return NULL; + } + acmDevice->fnDev = (struct UsbFnDevice *)UsbFnCreateDevice("100e0000.hidwc3_0", &descData); + if (acmDevice->fnDev == NULL) { + return NULL; + } + acmDevice->port = (struct Serial *)SerialAlloc(); + if (acmDevice->port == NULL) { + return NULL; + } + ret = ParseInterfaces(acmDevice); + if (ret != 0) { + return NULL; + } + ret = AllocCtrlRequests(acmDevice); + if (ret != 0) { + return NULL; + } + ret = AllocNotifyRequest(acmDevice); + if (ret != 0) { + return NULL; + } + ret = UsbFnStartRecvInterfaceEvent(acmDevice->ctrlIface.fn, 0xff, AcmEventCallback, acmDevice); + if (ret != 0) { + return NULL; + } + acmDevice->notify = &g_notifyMethod; + return acmDevice; +} + +static int32_t FreeNotifyRequest(struct AcmDevice *acmDevice) +{ + int ret; + + /* allocate notification request */ + if (acmDevice->notifyReq == NULL) { + HDF_LOGE("%{public}s: notifyReq is NULL", __func__); + return -1; + } + acmDevice->notifyReq->complete = NULL; + acmDevice->notifyReq->context = NULL; + ret = UsbFnFreeRequest(acmDevice->notifyReq); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: free notifyReq failed", __func__); + return -1; + } + return HDF_SUCCESS; +} + +static int FreeCtrlRequests(struct AcmDevice *acmDevice) +{ + struct DListHead *head = &acmDevice->ctrlPool; + struct UsbFnRequest *req = NULL; + + while (!DListIsEmpty(head)) { + req = DLIST_FIRST_ENTRY(head, struct UsbFnRequest, list); + DListRemove(&req->list); + OsalMemFree(req->context); + (void)UsbFnFreeRequest(req); + acmDevice->ctrlReqNum--; + } + return 0; +} + +void ReleaseAcmDevice(struct AcmDevice *acm) +{ + if (acm == NULL) { + HDF_LOGE("%{public}s: acm is NULL", __func__); + return; + } + FreeNotifyRequest(acm); + FreeCtrlRequests(acm); + (void)UsbFnCloseInterface(acm->ctrlIface.handle); + (void)UsbFnCloseInterface(acm->dataIface.handle); + UsbFnStopRecvInterfaceEvent(acm->ctrlIface.fn); + OsalMemFree(acm->port); +} + diff --git a/test/unittest/model/usb/src/usb_device_lite_sdk_if_test.c b/test/unittest/model/usb/src/usb_device_lite_sdk_if_test.c new file mode 100644 index 000000000..d116eaba5 --- /dev/null +++ b/test/unittest/model/usb/src/usb_device_lite_sdk_if_test.c @@ -0,0 +1,2268 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "usb_device_lite_cdcacm_test.h" + +#define HDF_LOG_TAG usb_device_sdk_test + +static struct AcmDevice *g_acmDevice = NULL; +int32_t UsbFnDviceTestCreate(void) +{ + dprintf("%s: start\n", __func__); + g_acmDevice = SetUpAcmDevice(); + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: UsbFnDviceTestCreate fail", __func__); + return HDF_FAILURE; + } + dprintf("%s: success\n", __func__); + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCreate002(void) +{ + struct UsbFnDevice *fnDev = NULL; + struct UsbFnDescriptorData descData; + + descData.type = USBFN_DESC_DATA_TYPE_DESC; + descData.descriptor = NULL; + fnDev = (struct UsbFnDevice *)UsbFnCreateDevice("100e0000.hidwc3_0", &descData); + if (fnDev != NULL) { + HDF_LOGE("%s: UsbFnDviceTestCreate success!!", __func__); + return HDF_FAILURE; + } + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCreate003(void) +{ + struct UsbFnDevice *fnDev = NULL; + struct UsbFnDescriptorData descData; + + descData.type = USBFN_DESC_DATA_TYPE_PROP; + descData.property = NULL; + fnDev = (struct UsbFnDevice *)UsbFnCreateDevice("100e0000.hidwc3_0", &descData); + if (fnDev != NULL) { + HDF_LOGE("%s: UsbFnDviceTestCreate success!!", __func__); + return HDF_FAILURE; + } + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCreate004(void) +{ + struct UsbFnDevice *fnDev = NULL; + struct UsbFnDescriptorData descData; + + descData.type = USBFN_DESC_DATA_TYPE_DESC; + descData.descriptor = &g_acmFnDevice; + fnDev = (struct UsbFnDevice *)UsbFnCreateDevice("100e0000.hidwc3_0", &descData); + if (fnDev != NULL) { + HDF_LOGE("%s: UsbFnDviceTestCreate success!!", __func__); + return HDF_FAILURE; + } + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCreate005(void) +{ + struct UsbFnDevice *fnDev = NULL; + struct UsbFnDescriptorData descData; + + descData.type = USBFN_DESC_DATA_TYPE_DESC; + descData.descriptor = &g_acmFnDevice; + fnDev = (struct UsbFnDevice *)UsbFnCreateDevice("100e0000.hidwc3_1", &descData); + if (fnDev != NULL) { + HDF_LOGE("%s: UsbFnDviceTestCreate success!!", __func__); + return HDF_FAILURE; + } + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCreate006(void) +{ + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStatus(void) +{ + int ret; + UsbFnDeviceState devState; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetDeviceState(g_acmDevice->fnDev, &devState); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get status error", __LINE__); + return HDF_FAILURE; + } + if (!(devState >= USBFN_STATE_BIND && devState <= USBFN_STATE_RESUME)) { + HDF_LOGE("%s: device status error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStatus002(void) +{ + int ret; + UsbFnDeviceState devState; + ret = UsbFnGetDeviceState(NULL, &devState); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get status success!!", __LINE__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStatus003(void) +{ + int ret; + int count = 0; + UsbFnDeviceState devState; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + return HDF_FAILURE; + } + for (count = 0; count < TEST_TIMES; count++) { + ret = UsbFnGetDeviceState(g_acmDevice->fnDev, &devState); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get status error", __LINE__); + return HDF_FAILURE; + } + if (!(devState >= USBFN_STATE_BIND && devState <= USBFN_STATE_RESUME)) { + HDF_LOGE("%s: device status error", __func__); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStatus004(void) +{ + int ret; + ret = UsbFnGetDeviceState(NULL, NULL); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get status success!!", __LINE__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStatus005(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStatus006(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetDevice(void) +{ + const struct UsbFnDevice *device = NULL; + const char *udcName = "100e0000.hidwc3_0"; + device = UsbFnGetDevice(udcName); + if (device == NULL) { + HDF_LOGE("%s: get device fail", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetDevice002(void) +{ + const struct UsbFnDevice *device = NULL; + const char *udcName = "100e0000.hidwc3_1"; + device = UsbFnGetDevice(udcName); + if (device != NULL) { + HDF_LOGE("%s: get device success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetDevice003(void) +{ + const struct UsbFnDevice *device = NULL; + const char *udcName = NULL; + device = UsbFnGetDevice(udcName); + if (device != NULL) { + HDF_LOGE("%s: get device success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetDevice004(void) +{ + const struct UsbFnDevice *device = NULL; + const char *udcName = "100e0000.hidwc3_0 "; + device = UsbFnGetDevice(udcName); + if (device != NULL) { + HDF_LOGE("%s: get device success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetDevice005(void) +{ + const struct UsbFnDevice *device = NULL; + const char *udcName = "100e0000.hidwc3_0\0100e0000.hidwc3_0"; + device = UsbFnGetDevice(udcName); + if (device != NULL) { + HDF_LOGE("%s: get device success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetDevice006(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetInterface(void) +{ + struct UsbFnInterface *fnInterface = NULL; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + return HDF_FAILURE; + } + fnInterface = (struct UsbFnInterface *)UsbFnGetInterface(g_acmDevice->fnDev, 0); + if (fnInterface == NULL) { + HDF_LOGE("%s: get interface fail", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; + +} + +int32_t UsbFnDviceTestGetInterface002(void) +{ + struct UsbFnInterface *fnInterface = NULL; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + return HDF_FAILURE; + } + fnInterface = (struct UsbFnInterface *)UsbFnGetInterface(g_acmDevice->fnDev, 1); + if (fnInterface == NULL) { + HDF_LOGE("%s: get interface fail", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetInterface003(void) +{ + struct UsbFnInterface *fnInterface = NULL; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + dprintf("%s, %d\n", __func__, __LINE__); + return HDF_FAILURE; + } + fnInterface = (struct UsbFnInterface *)UsbFnGetInterface(g_acmDevice->fnDev, 0xA); + if (fnInterface != NULL) { + HDF_LOGE("%s: get interface success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetInterface004(void) +{ + struct UsbFnInterface *fnInterface = NULL; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + return HDF_FAILURE; + } + fnInterface = (struct UsbFnInterface *)UsbFnGetInterface(g_acmDevice->fnDev, 0x20); + if (fnInterface != NULL) { + HDF_LOGE("%s: get interface success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetInterface005(void) +{ + struct UsbFnInterface *fnInterface = NULL; + struct UsbFnDevice *fnDevice = NULL; + fnInterface = (struct UsbFnInterface *)UsbFnGetInterface(fnDevice, 0); + if (fnInterface != NULL) { + HDF_LOGE("%s: get interface success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetInterface006(void) +{ + struct UsbFnInterface *fnInterface = NULL; + int idCount; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + return HDF_FAILURE; + } + for (idCount = 0; idCount < 0x2; idCount++) { + fnInterface = (struct UsbFnInterface *)UsbFnGetInterface(g_acmDevice->fnDev, idCount); + if (fnInterface == NULL) { + HDF_LOGE("%s: get interface fail", __func__); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetPipeInfo(void) +{ + int ret; + struct UsbFnPipeInfo info; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfacePipeInfo(g_acmDevice->dataIface.fn, 0, &info); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get pipe info error", __func__); + return HDF_FAILURE; + } + if (info.id != 0) { + HDF_LOGE("%s: get pipe id error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetPipeInfo002(void) +{ + int ret; + struct UsbFnPipeInfo info; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfacePipeInfo(g_acmDevice->dataIface.fn, 1, &info); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get pipe info error", __func__); + return HDF_FAILURE; + } + if (info.id != 1) { + HDF_LOGE("%s: get pipe id error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetPipeInfo003(void) +{ + int ret; + struct UsbFnPipeInfo info; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfacePipeInfo(g_acmDevice->dataIface.fn, 0xF, &info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get pipe info success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetPipeInfo004(void) +{ + int ret; + struct UsbFnPipeInfo *info = NULL; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfacePipeInfo(g_acmDevice->dataIface.fn, 0, info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get pipe info success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetPipeInfo005(void) +{ + int ret; + struct UsbFnPipeInfo info; + struct UsbFnInterface *fn = NULL; + + ret = UsbFnGetInterfacePipeInfo(fn, 0, &info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get pipe info success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetPipeInfo006(void) +{ + int ret; + struct UsbFnPipeInfo info; + + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfacePipeInfo(g_acmDevice->ctrlIface.fn, 0, &info); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get pipe info error", __func__); + return HDF_FAILURE; + } + if (info.id != 0) { + HDF_LOGE("%s: get pipe id error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static void ReadComplete(uint8_t pipe, struct UsbFnRequest *req) +{ + if (NULL == req) { + return; + } + if (req->actual) { + uint8_t *data = (uint8_t *)req->buf; + data[req->actual] = '\0'; + dprintf("receive [%d] bytes data: %s\n", req->actual, data); + if (strcmp((const char *)data, "q") == 0 || \ + strcmp((const char *)data, "q\n") == 0) { + g_acmDevice->submit_exit = 1; + } + } + g_acmDevice->submit = 1; +} + +int32_t UsbFnDviceTestRequestAsync(void) +{ + struct UsbFnRequest *req = NULL; + int ret; + + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: async Request success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestAsync002(void) +{ + struct UsbFnRequest *req = NULL; + int ret = HDF_SUCCESS; + int ret1 = HDF_SUCCESS; + int waitMs = 100; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + dprintf("wait receiving data form host, please connect\n"); + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + req->complete = ReadComplete; + req->context = g_acmDevice; + while (g_acmDevice->connect == false) { + OsalMSleep(waitMs); + } + while (1) { + g_acmDevice->submit = 0; + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: async Request error", __func__); + ret = HDF_FAILURE; + break; + } + while(g_acmDevice->submit == 0) { + OsalMSleep(waitMs); + } + if (req->actual > 0) { + break; + } + } + ret1 = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret1) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return ret; +} + +int32_t UsbFnDviceTestRequestAsync003(void) +{ + struct UsbFnRequest *req = NULL; + int ret = HDF_SUCCESS; + int ret1 = HDF_SUCCESS; + int waitMs = 100; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + dprintf("wait receiving data form host, please connect\n"); + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + req->complete = ReadComplete; + req->context = g_acmDevice; + while (g_acmDevice->connect == false) { + OsalMSleep(waitMs); + } + g_acmDevice->submit_exit = 0; + while (g_acmDevice->submit_exit == 0) { + g_acmDevice->submit = 0; + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: async Request error", __func__); + ret = HDF_FAILURE; + break; + } + while(g_acmDevice->submit == 0) { + OsalMSleep(waitMs); + } + } + ret1 = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret1) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return ret; +} + +static void WriteComplete(uint8_t pipe, struct UsbFnRequest *req) +{ + dprintf("write data status = %d\n", req->status); + g_acmDevice->submit = 1; +} + +int32_t UsbFnDviceTestRequestAsync004(void) +{ + struct UsbFnRequest *req = NULL; + int ret = HDF_SUCCESS; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + req->complete = WriteComplete; + req->context = g_acmDevice; + g_acmDevice->submit = 0; + dprintf("------send \"abc\" to host------\n"); + memcpy_s(req->buf, g_acmDevice->dataInPipe.maxPacketSize, "abc", strlen("abc")); + req->length = strlen("abc"); + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: async Request error", __func__); + return HDF_FAILURE; + } + while(g_acmDevice->submit == 0) { + OsalMSleep(1); + } + g_acmDevice->submit = 0; + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestAsync005(void) +{ + struct UsbFnRequest *req = NULL; + int loopTime = TEST_TIMES; + int ret = HDF_SUCCESS; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + dprintf("------send \"xyz\" 10 times to host------\n"); + while (loopTime--) { + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + req->complete = WriteComplete; + req->context = g_acmDevice; + g_acmDevice->submit = 0; + memcpy_s(req->buf, g_acmDevice->dataInPipe.maxPacketSize, "xyz", strlen("xyz")); + req->length = strlen("xyz"); + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: async Request error", __func__); + return HDF_FAILURE; + } + while(g_acmDevice->submit == 0) { + OsalMSleep(1); + } + g_acmDevice->submit = 0; + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestAsync006(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync(void) +{ + struct UsbFnRequest *req = NULL; + int ret; + ret = UsbFnSubmitRequestSync(req, 0); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: sync Request success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync002(void) +{ + struct UsbFnRequest *req = NULL; + int ret; + uint8_t *data; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + dprintf("wait receiving data form host\n"); + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSubmitRequestSync(req, 0); + if (ret != 0 || req->actual <= 0 || req->status != USB_REQUEST_COMPLETED) { + HDF_LOGE("%s: Sync Request error", __func__); + return HDF_FAILURE; + } + data = (uint8_t *)req->buf; + data[req->actual] = '\0'; + dprintf("receive data from host: %s\n", data); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync003(void) +{ + struct UsbFnRequest *req = NULL; + int ret; + int submit_exit = 0; + uint8_t *data; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + dprintf("receive data until 'q' exit\n"); + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + while (submit_exit == 0){ + ret = UsbFnSubmitRequestSync(req, 0); + if (ret != 0 || req->actual <= 0 || req->status != USB_REQUEST_COMPLETED) { + HDF_LOGE("%s: Sync Request error", __func__); + break; + } + data = (uint8_t *)req->buf; + data[req->actual] = '\0'; + if (strcmp((const char *)data, "q") == 0 || \ + strcmp((const char *)data, "q\n") == 0) { + submit_exit = 1; + } + dprintf("receive data from host: %s\n", data); + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync004(void) +{ + struct UsbFnRequest *req = NULL; + int ret = HDF_SUCCESS; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + dprintf("------send \"abc\" to host------\n"); + memcpy_s(req->buf, g_acmDevice->dataInPipe.maxPacketSize, "abc", strlen("abc")); + req->length = strlen("abc"); + ret = UsbFnSubmitRequestSync(req, 0); + if (HDF_SUCCESS != ret || (req->actual != strlen("abc")) || \ + (req->status != USB_REQUEST_COMPLETED)) { + HDF_LOGE("%s: async Request error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync005(void) +{ + struct UsbFnRequest *req = NULL; + int loopTime = TEST_TIMES; + int ret = HDF_SUCCESS; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + dprintf("------send \"abcdefg\" 10 times to host------\n"); + while (loopTime--) { + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + memcpy_s(req->buf, g_acmDevice->dataInPipe.maxPacketSize, "abcdefg", strlen("abcdefg")); + req->length = strlen("abcdefg"); + ret = UsbFnSubmitRequestSync(req, 0); + if (HDF_SUCCESS != ret || (req->actual != strlen("abcdefg")) || \ + (req->status != USB_REQUEST_COMPLETED)) { + HDF_LOGE("%s: async Request error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync006(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync007(void) +{ + return HDF_SUCCESS; +} + +static int32_t PropCallBack(const struct UsbFnInterface *intf, const char *name, + const char *value) +{ + if (intf == NULL || name == NULL || value == NULL) { + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRegistProp(void) +{ + int ret; + struct UsbFnRegistInfo info; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + info.name = "name_test"; + info.value = "test_value"; + info.getProp = PropCallBack; + info.setProp = PropCallBack; + ret = UsbFnRegistInterfaceProp(g_acmDevice->ctrlIface.fn, &info); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: Regist Prop error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRegistProp002(void) +{ + int ret; + struct UsbFnRegistInfo info; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + info.name = "name_test"; + info.value = "test_value"; + info.getProp = PropCallBack; + info.setProp = PropCallBack; + ret = UsbFnRegistInterfaceProp(g_acmDevice->ctrlIface.fn, &info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Regist Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRegistProp003(void) +{ + int ret; + struct UsbFnRegistInfo info; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + info.name = NULL; + info.value = "test_value"; + info.getProp = PropCallBack; + info.setProp = PropCallBack; + ret = UsbFnRegistInterfaceProp(g_acmDevice->ctrlIface.fn, &info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Regist Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRegistProp004(void) +{ + int ret; + struct UsbFnRegistInfo info; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + info.name = "name_test4"; + info.value = "test_value"; + info.getProp = NULL; + info.setProp = PropCallBack; + ret = UsbFnRegistInterfaceProp(g_acmDevice->ctrlIface.fn, &info); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: Regist Prop error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRegistProp005(void) +{ + int ret; + struct UsbFnRegistInfo info; + struct UsbFnInterface *fn = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + info.name = "name_test5"; + info.value = "test_value"; + info.getProp = PropCallBack; + info.setProp = PropCallBack; + ret = UsbFnRegistInterfaceProp(fn, &info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Regist Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRegistProp006(void) +{ + int ret; + struct UsbFnRegistInfo *info = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnRegistInterfaceProp(g_acmDevice->ctrlIface.fn, info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Regist Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetProp(void) +{ + int ret; + char buffer[64] = {0}; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfaceProp(g_acmDevice->ctrlIface.fn, "name_test", buffer); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: Get Prop error", __func__); + return HDF_FAILURE; + } + if (strcmp(buffer, "test_value")) { + HDF_LOGE("%s: Get Prop value error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetProp002(void) +{ + int ret; + char buffer[64] = {0}; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfaceProp(g_acmDevice->ctrlIface.fn, "unkown", buffer); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Get Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetProp003(void) +{ + int ret; + char buffer[64] = {0}; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfaceProp(g_acmDevice->ctrlIface.fn, "idProduct", buffer); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: Get Prop error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetProp004(void) +{ + int ret; + char buffer[64] = {0}; + struct UsbFnInterface *fn = NULL; + + ret = UsbFnGetInterfaceProp(fn, "idProduct", buffer); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Get Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetProp005(void) +{ + int ret; + char buffer[64] = {0}; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfaceProp(g_acmDevice->ctrlIface.fn, "idVendor", buffer); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: Get Prop error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetProp006(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfaceProp(g_acmDevice->ctrlIface.fn, "name_test", NULL); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Get Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestSetProp(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSetInterfaceProp(g_acmDevice->ctrlIface.fn, "name_test", "hello"); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: Set Prop error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestSetProp002(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSetInterfaceProp(g_acmDevice->ctrlIface.fn, "unkown", "hello"); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Set Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestSetProp003(void) +{ + int ret; + struct UsbFnInterface *fn = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSetInterfaceProp(fn, "name_test", "hellotest"); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Set Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestSetProp004(void) +{ + int ret; + const char *propName = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSetInterfaceProp(g_acmDevice->ctrlIface.fn, propName, "hellotest"); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Set Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestSetProp005(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestSetProp006(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSetInterfaceProp(g_acmDevice->ctrlIface.fn, "bLength", "0x14"); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Get Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocCtrlRequest(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->dataIface.handle, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocCtrlRequest002(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, + sizeof(struct UsbCdcLineCoding) + sizeof(struct UsbCdcLineCoding)); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocCtrlRequest003(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, 0); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocCtrlRequest004(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, 0x801); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocCtrlRequest005(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + UsbFnInterfaceHandle handle = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(handle, + g_acmDevice->notifyPipe.maxPacketSize); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocCtrlRequest006(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, 0x800); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocRequest(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id, + sizeof(struct UsbCdcNotification)); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocRequest002(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id, + 0); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocRequest003(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id, + 0x800); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocRequest004(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + UsbFnInterfaceHandle handle = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(handle, g_acmDevice->notifyPipe.id, 0x800); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocRequest005(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, 0x20, 0x800); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocRequest006(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, + g_acmDevice->notifyPipe.id, 0x801); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestFreeRequest(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id, + g_acmDevice->notifyPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestFreeRequest002(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestFreeRequest003(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestFreeRequest004(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, + g_acmDevice->notifyPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestFreeRequest005(void) +{ + int ret; + int count; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + for (count = 0; count < TEST_TIMES; count++) { + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, + g_acmDevice->notifyPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestFreeRequest006(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: free Request success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetRequestStatus(void) +{ + int ret; + UsbRequestStatus status; + struct UsbFnRequest *notifyReq = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + notifyReq = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id, + sizeof(struct UsbCdcNotification)); + if (notifyReq == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetRequestStatus(notifyReq, &status); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get status error", __func__); + return HDF_FAILURE; + } + if (!(status >= USB_REQUEST_COMPLETED && status <= USB_REQUEST_OVERFLOW)) { + HDF_LOGE("%s: device status error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(notifyReq); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetRequestStatus002(void) +{ + int ret; + UsbRequestStatus status; + struct UsbFnRequest *notifyReq = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + notifyReq = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, + sizeof(struct UsbCdcNotification)); + if (notifyReq == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetRequestStatus(notifyReq, &status); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get status error", __func__); + dprintf("%s: get status error", __func__); + return HDF_FAILURE; + } + if (!(status >= USB_REQUEST_COMPLETED && status <= USB_REQUEST_OVERFLOW)) { + HDF_LOGE("%s: device status error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(notifyReq); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetRequestStatus003(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetRequestStatus(req, NULL); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get status success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetRequestStatus004(void) +{ + int ret; + UsbRequestStatus status; + struct UsbFnRequest *notifyReq = NULL; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + notifyReq = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (notifyReq == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSubmitRequestAsync(notifyReq); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get status error", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetRequestStatus(notifyReq, &status); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get status error", __func__); + return HDF_FAILURE; + } + if (!(status >= USB_REQUEST_COMPLETED && status <= USB_REQUEST_OVERFLOW)) { + HDF_LOGE("%s: device status error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(notifyReq); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetRequestStatus005(void) +{ + int ret; + UsbRequestStatus status; + struct UsbFnRequest *notifyReq = NULL; + ret = UsbFnGetRequestStatus(notifyReq, &status); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get status success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetRequestStatus006(void) +{ + return HDF_SUCCESS; +} + +static void TestCancelComplete(uint8_t pipe, struct UsbFnRequest *req) +{ + dprintf("%s, req->buf = 0x%x\n", __func__, (uint32_t)req->buf); + g_acmDevice->haved_submit = true; +} + +int32_t UsbFnDviceTestCancelRequest(void) +{ + int ret; + struct UsbFnRequest *notifyReq = NULL; + ret = UsbFnCancelRequest(notifyReq); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: cancel request success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCancelRequest002(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: CtrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, + sizeof(struct UsbCdcNotification)); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCancelRequest(req); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: cancel request success", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCancelRequest003(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCancelRequest(req); + if (HDF_SUCCESS == ret) { + dprintf("%s: cancel request success\n", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + dprintf("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCancelRequest004(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCancelRequest(req); + if (HDF_SUCCESS == ret) { + dprintf("%s: cancel request success\n", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + dprintf("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCancelRequest005(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + g_acmDevice->haved_submit = false; + req->complete = TestCancelComplete; + req->context = g_acmDevice; + dprintf("------send \"abc\" to host------\n"); + memcpy_s(req->buf, g_acmDevice->dataInPipe.maxPacketSize, "abc", strlen("abc")); + req->length = strlen("abc"); + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: request async error", __func__); + return HDF_FAILURE; + } + while(g_acmDevice->haved_submit == 0) { + OsalMSleep(1); + } + ret = UsbFnCancelRequest(req); + if (HDF_SUCCESS == ret) { + dprintf("%s: cancel request error", __func__); + return HDF_FAILURE; + } + g_acmDevice->haved_submit = false; + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCancelRequest006(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + struct UsbFnRequest *req2 = NULL; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + g_acmDevice->haved_submit = false; + req->complete = TestCancelComplete; + req->context = g_acmDevice; + + req2 = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req2 == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + g_acmDevice->submit = false; + req2->complete = ReadComplete; + req2->context = g_acmDevice; + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: request async error", __func__); + return HDF_FAILURE; + } + ret = UsbFnSubmitRequestAsync(req2); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: request async error", __func__); + return HDF_FAILURE; + } + ret = UsbFnCancelRequest(req2); + if (HDF_SUCCESS != ret) { + dprintf("%s: cancel request error", __func__); + return HDF_FAILURE; + } + ret = UsbFnCancelRequest(req); + if (HDF_SUCCESS != ret) { + dprintf("%s: cancel request error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + dprintf("%s: free Request error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req2); + if (HDF_SUCCESS != ret) { + dprintf("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStopReceEvent(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStopRecvInterfaceEvent(g_acmDevice->ctrlIface.fn); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: stop receive event error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStopReceEvent002(void) +{ + int ret; + struct UsbFnInterface *fn = NULL; + ret = UsbFnStopRecvInterfaceEvent(fn); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: stop receive event success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStopReceEvent003(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStopRecvInterfaceEvent(g_acmDevice->ctrlIface.fn); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: stop receive event success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStopReceEvent004(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStopRecvInterfaceEvent(g_acmDevice->dataIface.fn); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: stop receive event success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStopReceEvent005(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStopReceEvent006(void) +{ + return HDF_SUCCESS; +} + +static void eventCallback(struct UsbFnEvent *event) +{ + (void)event; +} + +int32_t UsbFnDviceTestStartReceEvent(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStartRecvInterfaceEvent(g_acmDevice->ctrlIface.fn, 0xff, + NULL, g_acmDevice); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: stop receive event successs!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStartReceEvent002(void) +{ + int ret; + struct UsbFnInterface *fn = NULL; + ret = UsbFnStartRecvInterfaceEvent(fn, 0xff, + eventCallback, g_acmDevice); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: stop receive event successs!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStartReceEvent003(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStartRecvInterfaceEvent(g_acmDevice->ctrlIface.fn, 0xff, + eventCallback, g_acmDevice); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: stop receive event error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStartReceEvent004(void) +{ + int ret; + int count; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + for (count = 0; count < TEST_TIMES; count++) { + ret = UsbFnStopRecvInterfaceEvent(g_acmDevice->ctrlIface.fn); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: stop receive event error", __func__); + return HDF_FAILURE; + } + ret = UsbFnStartRecvInterfaceEvent(g_acmDevice->ctrlIface.fn, 0xff, + eventCallback, g_acmDevice); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: stop receive event error", __func__); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStartReceEvent005(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStartRecvInterfaceEvent(g_acmDevice->ctrlIface.fn, 0xff, + eventCallback, g_acmDevice); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: start receive event success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStartReceEvent006(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStartRecvInterfaceEvent(g_acmDevice->dataIface.fn, 0xff, + eventCallback, g_acmDevice); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: start receive event success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCloseInterface(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCloseInterface(g_acmDevice->ctrlIface.handle); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: close interface error", __func__); + return HDF_FAILURE; + } + g_acmDevice->ctrlIface.handle = NULL; + + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCloseInterface002(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCloseInterface(g_acmDevice->dataIface.handle); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: close interface error", __func__); + return HDF_FAILURE; + } + g_acmDevice->dataIface.handle = NULL; + + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCloseInterface003(void) +{ + int ret; + + ret = UsbFnCloseInterface(g_acmDevice->ctrlIface.handle); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: close interface success!!", __func__); + return HDF_FAILURE; + } + g_acmDevice->ctrlIface.handle = NULL; + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCloseInterface004(void) +{ + int ret; + + ret = UsbFnCloseInterface(g_acmDevice->dataIface.handle); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: close interface success!!", __func__); + return HDF_FAILURE; + } + g_acmDevice->dataIface.handle = NULL; + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCloseInterface005(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCloseInterface006(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestOpenInterface(void) +{ + UsbFnInterfaceHandle handle; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + if (g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + handle = UsbFnOpenInterface(g_acmDevice->ctrlIface.fn); + if (NULL != handle) { + HDF_LOGE("%s: open interface success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestOpenInterface002(void) +{ + UsbFnInterfaceHandle handle; + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + if (g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + handle = UsbFnOpenInterface(g_acmDevice->dataIface.fn); + if (NULL != handle) { + HDF_LOGE("%s: open interface success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestOpenInterface003(void) +{ + int ret; + UsbFnInterfaceHandle handle; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + if (g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCloseInterface(g_acmDevice->ctrlIface.handle); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: close interface failed", __func__); + return HDF_FAILURE; + } + g_acmDevice->ctrlIface.handle = NULL; + handle = UsbFnOpenInterface(g_acmDevice->ctrlIface.fn); + if (NULL == handle) { + HDF_LOGE("%s: open interface failed", __func__); + return HDF_FAILURE; + } + g_acmDevice->ctrlIface.handle = handle; + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestOpenInterface004(void) +{ + int ret; + UsbFnInterfaceHandle handle; + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + if (g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCloseInterface(g_acmDevice->dataIface.handle); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: close interface failed", __func__); + return HDF_FAILURE; + } + g_acmDevice->dataIface.handle = NULL; + handle = UsbFnOpenInterface(g_acmDevice->dataIface.fn); + if (NULL == handle) { + HDF_LOGE("%s: open interface failed", __func__); + return HDF_FAILURE; + } + g_acmDevice->dataIface.handle = handle; + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestOpenInterface005(void) +{ + UsbFnInterfaceHandle handle; + struct UsbFnInterface *fn = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + handle = UsbFnOpenInterface(fn); + if (NULL != handle) { + HDF_LOGE("%s: open interface success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestOpenInterface006(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRemove(void) +{ + int ret; + struct UsbFnDevice *fnDev = NULL; + + ret = UsbFnRemoveDevice(fnDev); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: UsbFnRemoveDevice success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRemove002(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fndev is null", __func__); + return HDF_FAILURE; + } + + ReleaseAcmDevice(g_acmDevice); + ret = UsbFnRemoveDevice(g_acmDevice->fnDev); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: UsbFnRemoveDevice fail, ret = %d", __func__, ret); + return HDF_FAILURE; + } + OsalMemFree(g_acmDevice); + + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRemove003(void) +{ + return HDF_SUCCESS; +} + -- Gitee From 4b751410f17d7b81e39346b7c5efad21fb5c7c40 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Thu, 15 Jul 2021 20:05:55 +0800 Subject: [PATCH 013/205] fix hdf power management feature on kernel Signed-off-by: yuanbo --- ability/sbuf/src/hdf_sbuf.c | 23 +++-- .../adapter/syscall/src/hdf_syscall_adapter.c | 11 --- core/common/src/devmgr_service_start.c | 5 +- core/common/src/hdf_attribute.c | 10 +- core/host/include/hdf_device.h | 2 +- core/host/include/hdf_device_node.h | 5 +- core/host/include/power_state_token.h | 4 +- core/host/src/devhost_service.c | 81 +++++++++++++--- core/host/src/hdf_device.c | 10 +- core/host/src/hdf_device_node.c | 7 +- core/host/src/power_state_token.c | 49 +++------- core/manager/include/devhost_service_clnt.h | 4 +- core/manager/include/devmgr_service.h | 6 +- core/manager/include/power_state_token_clnt.h | 2 +- core/manager/src/devhost_service_clnt.c | 3 +- core/manager/src/devmgr_service.c | 95 +++++++++++-------- core/manager/src/power_state_manager.c | 83 ---------------- core/manager/src/power_state_token_clnt.c | 2 +- .../unittest/common/hdf_ioservice_test.cpp | 36 +++++++ core/shared/include/devhost_service_if.h | 7 +- core/shared/include/devmgr_service_if.h | 4 +- .../include/hdf_power_state.h} | 31 +++--- core/shared/include/power_state_token_if.h | 8 +- include/core/hdf_pm.h | 19 ++-- include/utils/hdf_dlist.h | 11 +++ test/unittest/manager/sample_driver_test.c | 56 ++++++++++- test/unittest/manager/sample_driver_test.h | 1 + 27 files changed, 316 insertions(+), 259 deletions(-) delete mode 100644 core/manager/src/power_state_manager.c rename core/{manager/include/power_state_manager.h => shared/include/hdf_power_state.h} (34%) diff --git a/ability/sbuf/src/hdf_sbuf.c b/ability/sbuf/src/hdf_sbuf.c index 9aea25fcf..2db96ff64 100644 --- a/ability/sbuf/src/hdf_sbuf.c +++ b/ability/sbuf/src/hdf_sbuf.c @@ -120,7 +120,7 @@ bool HdfSbufWriteUnpadBuffer(struct HdfSBuf *sbuf, const uint8_t *data, uint32_t const uint8_t *HdfSbufReadUnpadBuffer(struct HdfSBuf *sbuf, size_t length) { - HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUnpadBuffer, false); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUnpadBuffer, NULL); return sbuf->impl->readUnpadBuffer(sbuf->impl, length); } @@ -240,7 +240,7 @@ bool HdfSbufReadInt8(struct HdfSBuf *sbuf, int8_t *value) const char *HdfSbufReadString(struct HdfSBuf *sbuf) { - HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readString, false); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readString, NULL); return sbuf->impl->readString(sbuf->impl); } @@ -252,7 +252,7 @@ bool HdfSBufWriteString16(struct HdfSBuf *sbuf, const char16_t *value, uint32_t const char16_t *HdfSBufReadString16(struct HdfSBuf *sbuf) { - HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readString16, false); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readString16, NULL); return sbuf->impl->readString16(sbuf->impl); } @@ -264,7 +264,7 @@ int32_t HdfSBufWriteRemoteService(struct HdfSBuf *sbuf, const struct HdfRemoteSe struct HdfRemoteService *HdfSBufReadRemoteService(struct HdfSBuf *sbuf) { - HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readRemoteService, false); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readRemoteService, NULL); return sbuf->impl->readRemoteService(sbuf->impl); } @@ -306,6 +306,7 @@ bool HdfSbufReadFloat(struct HdfSBuf *sbuf, float *data) struct HdfSBuf *HdfSBufTypedObtainCapacity(uint32_t type, size_t capacity) { + struct HdfSBuf *sbuf = NULL; const struct HdfSbufConstructor *constructor = HdfSbufConstructorGet(type); if (constructor == NULL) { HDF_LOGE("sbuf constructor %d not implement", type); @@ -316,7 +317,7 @@ struct HdfSBuf *HdfSBufTypedObtainCapacity(uint32_t type, size_t capacity) return NULL; } - struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); + sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); if (sbuf == NULL) { HDF_LOGE("instance sbuf failure"); return NULL; @@ -334,11 +335,12 @@ struct HdfSBuf *HdfSBufTypedObtainCapacity(uint32_t type, size_t capacity) struct HdfSBuf *HdfSBufTypedObtainInplace(uint32_t type, struct HdfSbufImpl *impl) { + struct HdfSBuf *sbuf = NULL; if (type >= SBUF_TYPE_MAX || impl == NULL) { return NULL; } - struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); + sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); if (sbuf == NULL) { HDF_LOGE("obtain in-place sbuf failure"); return NULL; @@ -356,6 +358,7 @@ struct HdfSBuf *HdfSBufTypedObtain(uint32_t type) struct HdfSBuf *HdfSBufTypedBind(uint32_t type, uintptr_t base, size_t size) { + struct HdfSBuf *sbuf = NULL; const struct HdfSbufConstructor *constructor = HdfSbufConstructorGet(type); if (constructor == NULL) { HDF_LOGE("sbuf constructor %d not implement", type); @@ -367,7 +370,7 @@ struct HdfSBuf *HdfSBufTypedBind(uint32_t type, uintptr_t base, size_t size) return NULL; } - struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); + sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); if (sbuf == NULL) { HDF_LOGE("instance sbuf failure"); return NULL; @@ -400,8 +403,9 @@ struct HdfSBuf *HdfSBufBind(uintptr_t base, size_t size) struct HdfSBuf *HdfSBufCopy(const struct HdfSBuf *sbuf) { + struct HdfSBuf *newBuf = NULL; HDF_SBUF_IMPL_CHECK_RETURN(sbuf, copy, NULL); - struct HdfSBuf *newBuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); + newBuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); if (newBuf == NULL) { return NULL; } @@ -416,8 +420,9 @@ struct HdfSBuf *HdfSBufCopy(const struct HdfSBuf *sbuf) struct HdfSBuf *HdfSBufMove(struct HdfSBuf *sbuf) { + struct HdfSBuf *newBuf = NULL; HDF_SBUF_IMPL_CHECK_RETURN(sbuf, move, NULL); - struct HdfSBuf *newBuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); + newBuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); if (newBuf == NULL) { return NULL; } diff --git a/core/adapter/syscall/src/hdf_syscall_adapter.c b/core/adapter/syscall/src/hdf_syscall_adapter.c index 908022746..8bbdb0126 100644 --- a/core/adapter/syscall/src/hdf_syscall_adapter.c +++ b/core/adapter/syscall/src/hdf_syscall_adapter.c @@ -1046,17 +1046,6 @@ void HdfIoServiceGroupRemoveService(struct HdfIoServiceGroup *group, struct HdfI adapter->group = NULL; } -static int DlistGetCount(const struct DListHead *head) -{ - struct DListHead *next = head->next; - int count = 0; - while (next != head) { - next = next->next; - count++; - } - return count; -} - int HdfIoserviceGetListenerCount(const struct HdfIoService *service) { if (service == NULL) { diff --git a/core/common/src/devmgr_service_start.c b/core/common/src/devmgr_service_start.c index 6dbaa0741..a7d27eb9c 100644 --- a/core/common/src/devmgr_service_start.c +++ b/core/common/src/devmgr_service_start.c @@ -22,7 +22,6 @@ static int g_isQuickLoad = DEV_MGR_SLOW_LOAD; static void GetDeviceServiceNameByClass(DeviceClass deviceClass, struct HdfSBuf *reply) { - struct HdfSListIterator itHost; struct HdfSListIterator itDeviceInfo; struct HdfDeviceInfo *deviceInfo = NULL; struct DevHostServiceClnt *hostClnt = NULL; @@ -32,9 +31,7 @@ static void GetDeviceServiceNameByClass(DeviceClass deviceClass, struct HdfSBuf } HdfSbufFlush(reply); - HdfSListIteratorInit(&itHost, &devMgrSvc->hosts); - while (HdfSListIteratorHasNext(&itHost)) { - hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&itHost); + DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) { HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos); while (HdfSListIteratorHasNext(&itDeviceInfo)) { deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo); diff --git a/core/common/src/hdf_attribute.c b/core/common/src/hdf_attribute.c index 83b609fd2..d9ce26d00 100644 --- a/core/common/src/hdf_attribute.c +++ b/core/common/src/hdf_attribute.c @@ -288,7 +288,6 @@ struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *h bool HdfDeviceListAdd(const char *moduleName, const char *serviceName) { - struct HdfSListIterator itHost; struct HdfSListIterator itDeviceInfo; struct HdfDeviceInfo *deviceInfo = NULL; struct DevHostServiceClnt *hostClnt = NULL; @@ -301,9 +300,7 @@ bool HdfDeviceListAdd(const char *moduleName, const char *serviceName) if (deviceNodeInfo == NULL) { return false; } - HdfSListIteratorInit(&itHost, &devMgrSvc->hosts); - while (HdfSListIteratorHasNext(&itHost)) { - hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&itHost); + DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) { HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos); while (HdfSListIteratorHasNext(&itDeviceInfo)) { deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo); @@ -342,7 +339,6 @@ bool HdfDeviceListAdd(const char *moduleName, const char *serviceName) void HdfDeviceListDel(const char *moduleName, const char *serviceName) { - struct HdfSListIterator itHost; struct HdfSListIterator itDeviceInfo; struct HdfDeviceInfo *deviceInfo = NULL; struct DevHostServiceClnt *hostClnt = NULL; @@ -351,9 +347,7 @@ void HdfDeviceListDel(const char *moduleName, const char *serviceName) return; } - HdfSListIteratorInit(&itHost, &devMgrSvc->hosts); - while (HdfSListIteratorHasNext(&itHost)) { - hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&itHost); + DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) { HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos); while (HdfSListIteratorHasNext(&itDeviceInfo)) { deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo); diff --git a/core/host/include/hdf_device.h b/core/host/include/hdf_device.h index e15132a1d..25e2a0650 100644 --- a/core/host/include/hdf_device.h +++ b/core/host/include/hdf_device.h @@ -28,7 +28,7 @@ struct IHdfDevice { struct HdfDevice { struct IHdfDevice super; struct DListHead node; - struct HdfSList services; + struct DListHead devNodes; uint16_t deviceId; uint16_t hostId; }; diff --git a/core/host/include/hdf_device_node.h b/core/host/include/hdf_device_node.h index 87b9da5f5..475158ead 100644 --- a/core/host/include/hdf_device_node.h +++ b/core/host/include/hdf_device_node.h @@ -12,6 +12,7 @@ #include "hdf_device.h" #include "hdf_device_info.h" #include "hdf_device_desc.h" +#include "hdf_dlist.h" #include "hdf_pm.h" struct HdfDeviceNode; @@ -25,7 +26,7 @@ struct IDeviceNode { struct HdfDeviceNode { struct IDeviceNode super; - struct HdfSListNode entry; + struct DListHead entry; struct PowerStateToken *powerToken; struct DevHostService *hostService; struct HdfDeviceObject deviceObject; @@ -42,7 +43,7 @@ void HdfDeviceNodeConstruct(struct HdfDeviceNode *service); void HdfDeviceNodeDestruct(struct HdfDeviceNode *service); struct HdfDeviceNode *HdfDeviceNodeNewInstance(void); void HdfDeviceNodeFreeInstance(struct HdfDeviceNode *service); -void HdfDeviceNodeDelete(struct HdfSListNode *deviceEntry); +void HdfDeviceNodeDelete(struct HdfDeviceNode *devNode); int HdfDeviceNodePublishPublicService(struct HdfDeviceNode *service, const char *svcName); void HdfDeviceNodeReclaimService(const char *svcName); diff --git a/core/host/include/power_state_token.h b/core/host/include/power_state_token.h index f82d0a222..327564494 100644 --- a/core/host/include/power_state_token.h +++ b/core/host/include/power_state_token.h @@ -18,12 +18,12 @@ struct PowerStateToken { const struct IPowerEventListener *listener; struct HdfDeviceObject *deviceObject; struct HdfSRef wakeRef; - HdfPowerState state; + HdfPsmState psmState; uint32_t mode; }; struct PowerStateToken *PowerStateTokenNewInstance( struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener); void PowerStateTokenFreeInstance(struct PowerStateToken *stateToken); -int PowerStateOnSysStateChange(struct PowerStateToken *stateToken, int32_t state); +int PowerStateChange(struct PowerStateToken *stateToken, uint32_t pEvent); #endif /* POWER_STATE_TOKEN_H */ \ No newline at end of file diff --git a/core/host/src/devhost_service.c b/core/host/src/devhost_service.c index 48814c6f6..bd0c84135 100644 --- a/core/host/src/devhost_service.c +++ b/core/host/src/devhost_service.c @@ -14,6 +14,7 @@ #include "hdf_log.h" #include "hdf_object_manager.h" #include "osal_mem.h" +#include "power_state_token.h" #define HDF_LOG_TAG devhost_service @@ -63,16 +64,16 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice int ret = HDF_FAILURE; struct HdfDevice *device = NULL; struct HdfDeviceNode *devNode = NULL; - struct DevHostService *hostService = (struct DevHostService *)inst; + struct DevHostService *hostService = CONTAINER_OF(inst, struct DevHostService, super); struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance(); - if ((deviceInfo == NULL) || (driverLoader == NULL) || (driverLoader->LoadNode == NULL)) { + if (inst == NULL || deviceInfo == NULL || driverLoader == NULL || driverLoader->LoadNode == NULL) { HDF_LOGE("failed to add device, input param is null"); return ret; } device = DevHostServiceGetDevice(hostService, deviceInfo->deviceId); - if ((device == NULL) || (device->super.Attach == NULL)) { + if (device == NULL || device->super.Attach == NULL) { ret = HDF_DEV_ERR_NO_DEVICE; goto error; } @@ -94,18 +95,14 @@ error: return ret; } -static struct HdfDeviceNode *DevHostServiceGetDeviceNode(struct HdfSList *deviceNodes, +static struct HdfDeviceNode *DevHostServiceSeparateDeviceNode(struct DListHead *deviceNodes, const struct HdfDeviceInfo *deviceInfo) { - struct HdfSListIterator it; struct HdfDeviceNode *deviceNode = NULL; - HdfSListIteratorInit(&it, deviceNodes); - while (HdfSListIteratorHasNext(&it)) { - deviceNode = HDF_SLIST_CONTAINER_OF( - struct HdfSListNode, HdfSListIteratorNext(&it), struct HdfDeviceNode, entry); + DLIST_FOR_EACH_ENTRY(deviceNode, deviceNodes, struct HdfDeviceNode, entry) { if (strcmp(deviceNode->deviceInfo->svcName, deviceInfo->svcName) == 0 && strcmp(deviceNode->deviceInfo->moduleName, deviceInfo->moduleName) == 0) { - HdfSListRemove(deviceNodes, &deviceNode->entry); + DListRemove(&deviceNode->entry); return deviceNode; } } @@ -130,14 +127,14 @@ int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDevice } driverLoader->UnLoadNode(driverLoader, deviceInfo); - struct HdfDeviceNode *devNode = DevHostServiceGetDeviceNode(&device->services, deviceInfo); + struct HdfDeviceNode *devNode = DevHostServiceSeparateDeviceNode(&device->devNodes, deviceInfo); if (device->super.Detach != NULL) { device->super.Detach(&device->super, devNode); } else { HdfDeviceNodeFreeInstance(devNode); } DevSvcManagerClntRemoveService(deviceInfo->svcName); - if (HdfSListIsEmpty(&device->services)) { + if (DListIsEmpty(&device->devNodes)) { DevHostServiceFreeDevice(hostService, device->deviceId); } return HDF_SUCCESS; @@ -153,6 +150,64 @@ static int DevHostServiceStartService(struct IDevHostService *service) return DevmgrServiceClntAttachDeviceHost(hostService->hostId, service); } +static int ApplyDevicesPowerState(struct HdfDevice *device, uint32_t state) +{ + struct HdfDeviceNode *deviceNode = NULL; + int ret = HDF_SUCCESS; + + /* The power management strategy is to ignore devices that fail to + operate and avoid more devices that fail to sleep or wake up */ + if (IsPowerWakeState(state)) { + DLIST_FOR_EACH_ENTRY(deviceNode, &device->devNodes, struct HdfDeviceNode, entry) { + if (deviceNode->powerToken != NULL) { + ret = PowerStateChange(deviceNode->powerToken, state); + if (ret != HDF_SUCCESS) { + HDF_LOGE("device %s failed to resume(%d)", deviceNode->driverEntry->moduleName, state); + } + } + } + } else { + DLIST_FOR_EACH_ENTRY_REVERSE(deviceNode, &device->devNodes, struct HdfDeviceNode, entry) { + if (deviceNode->powerToken != NULL) { + ret = PowerStateChange(deviceNode->powerToken, state); + if (ret != HDF_SUCCESS) { + HDF_LOGE("device %s failed to suspend(%d)", deviceNode->driverEntry->moduleName, state); + } + } + } + } + + return HDF_SUCCESS; +} + +static int DevHostServicePmNotify(struct IDevHostService *service, uint32_t state) +{ + struct HdfDevice *device = NULL; + int ret = HDF_SUCCESS; + struct DevHostService *hostService = CONTAINER_OF(service, struct DevHostService, super); + if (hostService == NULL) { + HDF_LOGE("failed to start device service, hostService is null"); + return HDF_FAILURE; + } + + HDF_LOGD("host(%s) set power state=%u", hostService->hostName, state); + if (IsPowerWakeState(state)) { + DLIST_FOR_EACH_ENTRY_REVERSE(device, &hostService->devices, struct HdfDevice, node) { + if (ApplyDevicesPowerState(device, state) != HDF_SUCCESS) { + ret = HDF_FAILURE; + } + } + } else { + DLIST_FOR_EACH_ENTRY(device, &hostService->devices, struct HdfDevice, node) { + if (ApplyDevicesPowerState(device, state) != HDF_SUCCESS) { + ret = HDF_FAILURE; + } + } + } + + return ret; +} + void DevHostServiceConstruct(struct DevHostService *service) { struct IDevHostService *hostServiceIf = &service->super; @@ -160,6 +215,7 @@ void DevHostServiceConstruct(struct DevHostService *service) hostServiceIf->AddDevice = DevHostServiceAddDevice; hostServiceIf->DelDevice = DevHostServiceDelDevice; hostServiceIf->StartService = DevHostServiceStartService; + hostServiceIf->PmNotify = DevHostServicePmNotify; DListHeadInit(&service->devices); HdfServiceObserverConstruct(&service->observer); } @@ -214,4 +270,3 @@ void DevHostServiceFreeInstance(struct IDevHostService *service) HdfObjectManagerFreeObject(&service->object); } } - diff --git a/core/host/src/hdf_device.c b/core/host/src/hdf_device.c index af7a6e810..d61036007 100644 --- a/core/host/src/hdf_device.c +++ b/core/host/src/hdf_device.c @@ -26,19 +26,23 @@ static int HdfDeviceAttach(struct IHdfDevice *devInst, struct HdfDeviceNode *dev HDF_LOGE("failed to attach device, input params invalid"); return HDF_ERR_INVALID_PARAM; } - HdfSListAdd(&device->services, &devNode->entry); + DListInsertTail(&devNode->entry, &device->devNodes); return nodeIf->LaunchNode(devNode, devInst); } void HdfDeviceConstruct(struct HdfDevice *device) { device->super.Attach = HdfDeviceAttach; - HdfSListInit(&device->services); + DListHeadInit(&device->devNodes); } void HdfDeviceDestruct(struct HdfDevice *device) { - HdfSListFlush(&device->services, HdfDeviceNodeDelete); + struct HdfDeviceNode *devNode = NULL; + DLIST_FOR_EACH_ENTRY(devNode, &device->devNodes, struct HdfDeviceNode, entry) { + HdfDeviceNodeDelete(devNode); + } + DListHeadInit(&device->devNodes); } struct HdfObject *HdfDeviceCreate() diff --git a/core/host/src/hdf_device_node.c b/core/host/src/hdf_device_node.c index c76398b26..06f46b436 100644 --- a/core/host/src/hdf_device_node.c +++ b/core/host/src/hdf_device_node.c @@ -170,13 +170,12 @@ void HdfDeviceNodeFreeInstance(struct HdfDeviceNode *devNode) HdfObjectManagerFreeObject((struct HdfObject *) devNode); } -void HdfDeviceNodeDelete(struct HdfSListNode *deviceEntry) +void HdfDeviceNodeDelete(struct HdfDeviceNode *devNode) { - if (deviceEntry == NULL) { + if (devNode == NULL) { return; } - struct HdfDeviceNode *devNode = - HDF_SLIST_CONTAINER_OF(struct HdfSListNode, deviceEntry, struct HdfDeviceNode, entry); + if (devNode->driverEntry->Release != NULL) { devNode->driverEntry->Release(&devNode->deviceObject); } diff --git a/core/host/src/power_state_token.c b/core/host/src/power_state_token.c index ab65bbf68..f32c21354 100644 --- a/core/host/src/power_state_token.c +++ b/core/host/src/power_state_token.c @@ -11,7 +11,7 @@ #include "hdf_device_desc.h" #include "hdf_slist.h" #include "osal_mem.h" -#include "osal_sysevent.h" +#include "hdf_power_state.h" static void PowerStateTokenOnFirstAcquire(struct HdfSRef *sref) { @@ -21,27 +21,17 @@ static void PowerStateTokenOnFirstAcquire(struct HdfSRef *sref) struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF( struct HdfSRef, sref, struct PowerStateToken, wakeRef); - if (stateToken->state == POWER_STATE_ACTIVE) { + if (stateToken->psmState == PSM_STATE_ACTIVE) { return; } - struct IDevmgrService *devMgrSvcIf = NULL; - struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance(); - if (inst == NULL) { - return; - } - devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf; - if (devMgrSvcIf != NULL && devMgrSvcIf->AcquireWakeLock != NULL) { - devMgrSvcIf->AcquireWakeLock(devMgrSvcIf, &stateToken->super); - } - - if (stateToken->state == POWER_STATE_INACTIVE || stateToken->state == POWER_STATE_IDLE) { + if (stateToken->psmState == PSM_STATE_INACTIVE || stateToken->psmState == PSM_STATE_IDLE) { const struct IPowerEventListener *listener = stateToken->listener; if ((listener != NULL) && (listener->Resume != NULL)) { listener->Resume(stateToken->deviceObject); } } - stateToken->state = POWER_STATE_ACTIVE; + stateToken->psmState = PSM_STATE_ACTIVE; } static void PowerStateTokenOnLastRelease(struct HdfSRef *sref) @@ -52,53 +42,40 @@ static void PowerStateTokenOnLastRelease(struct HdfSRef *sref) struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF( struct HdfSRef, sref, struct PowerStateToken, wakeRef); - if (stateToken->state != POWER_STATE_ACTIVE && stateToken->state != POWER_STATE_IDLE) { + if (stateToken->psmState != PSM_STATE_ACTIVE && stateToken->psmState != PSM_STATE_IDLE) { return; } - struct IDevmgrService *devMgrSvcIf = NULL; const struct IPowerEventListener *listener = stateToken->listener; - struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance(); - if (inst == NULL) { - return; - } - - if (stateToken->state == POWER_STATE_ACTIVE) { - devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf; - if ((devMgrSvcIf != NULL) && (devMgrSvcIf->AcquireWakeLock != NULL)) { - devMgrSvcIf->ReleaseWakeLock(devMgrSvcIf, &stateToken->super); - } - } - if ((listener != NULL) && (listener->Suspend != NULL)) { listener->Suspend(stateToken->deviceObject); } - stateToken->state = POWER_STATE_INACTIVE; + stateToken->psmState = PSM_STATE_INACTIVE; } -int PowerStateOnSysStateChange(struct PowerStateToken *stateToken, int32_t state) +int PowerStateChange(struct PowerStateToken *stateToken, uint32_t pEvent) { if (stateToken == NULL || stateToken->listener == NULL || stateToken->mode != HDF_POWER_SYS_CTRL) { return HDF_SUCCESS; } - switch (state) { - case KEVENT_POWER_SUSPEND: + switch (pEvent) { + case POWER_STATE_SUSPEND: if (stateToken->listener->Suspend != NULL) { return stateToken->listener->Suspend(stateToken->deviceObject); } break; - case KEVENT_POWER_RESUME: + case POWER_STATE_RESUME: if (stateToken->listener->Resume != NULL) { return stateToken->listener->Resume(stateToken->deviceObject); } break; - case KEVENT_POWER_DISPLAY_OFF: + case POWER_STATE_DOZE_SUSPEND: if (stateToken->listener->DozeSuspend != NULL) { return stateToken->listener->DozeSuspend(stateToken->deviceObject); } break; - case KEVENT_POWER_DISPLAY_ON: + case POWER_STATE_DOZE_RESUME: if (stateToken->listener->DozeResume != NULL) { return stateToken->listener->DozeResume(stateToken->deviceObject); } @@ -158,7 +135,7 @@ static int32_t PowerStateTokenConstruct(struct PowerStateToken *powerStateToken, srefListener->OnFirstAcquire = PowerStateTokenOnFirstAcquire; srefListener->OnLastRelease = PowerStateTokenOnLastRelease; - powerStateToken->state = POWER_STATE_IDLE; + powerStateToken->psmState = PSM_STATE_IDLE; powerStateToken->listener = listener; powerStateToken->deviceObject = deviceObject; HdfSRefConstruct(&powerStateToken->wakeRef, srefListener); diff --git a/core/manager/include/devhost_service_clnt.h b/core/manager/include/devhost_service_clnt.h index c80f3b1c1..cbc34d64a 100644 --- a/core/manager/include/devhost_service_clnt.h +++ b/core/manager/include/devhost_service_clnt.h @@ -14,7 +14,7 @@ #include "hdf_map.h" struct DevHostServiceClnt { - struct HdfSListNode node; + struct DListHead node; struct HdfSList devices; struct HdfSList *deviceInfos; Map *deviceHashMap; @@ -28,6 +28,6 @@ struct DevHostServiceClnt { int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt); struct DevHostServiceClnt *DevHostServiceClntNewInstance(uint16_t hostId, const char *hostName); void DevHostServiceClntFreeInstance(struct DevHostServiceClnt *hostClnt); -void DevHostServiceClntDelete(struct HdfSListNode *listEntry); +void DevHostServiceClntDelete(struct DevHostServiceClnt *hostClnt); #endif /* DEVHOST_SERVICE_CLNT_H */ diff --git a/core/manager/include/devmgr_service.h b/core/manager/include/devmgr_service.h index 1d255d189..56f0e02cc 100644 --- a/core/manager/include/devmgr_service.h +++ b/core/manager/include/devmgr_service.h @@ -10,12 +10,12 @@ #define DEVICE_MANAGER_SERVICE_H #include "devmgr_service_if.h" -#include "hdf_slist.h" +#include "hdf_dlist.h" #include "osal_mutex.h" struct DevmgrService { struct IDevmgrService super; - struct HdfSList hosts; + struct DListHead hosts; struct OsalMutex devMgrMutex; }; @@ -27,7 +27,5 @@ struct IDevmgrService *DevmgrServiceGetInstance(void); int DevmgrServiceLoadDevice(const char *svcName); int DevmgrServiceUnLoadDevice(const char *svcName); int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc); -void DevmgrServiceAcquireWakeLock(struct IDevmgrService *inst, struct IPowerStateToken *tokenIf); -void DevmgrServiceReleaseWakeLock(struct IDevmgrService *inst, struct IPowerStateToken *tokenIf); #endif /* DEVICE_MANAGER_SERVICE_H */ diff --git a/core/manager/include/power_state_token_clnt.h b/core/manager/include/power_state_token_clnt.h index 1915a985e..64c2885ab 100644 --- a/core/manager/include/power_state_token_clnt.h +++ b/core/manager/include/power_state_token_clnt.h @@ -15,7 +15,7 @@ struct PowerStateTokenClnt { struct HdfSListNode entry; - HdfPowerState powerState; + HdfPsmState powerState; struct IPowerStateToken *tokenIf; }; diff --git a/core/manager/src/devhost_service_clnt.c b/core/manager/src/devhost_service_clnt.c index 490cf0405..43b4f1ca9 100644 --- a/core/manager/src/devhost_service_clnt.c +++ b/core/manager/src/devhost_service_clnt.c @@ -84,9 +84,8 @@ void DevHostServiceClntFreeInstance(struct DevHostServiceClnt *hostClnt) } } -void DevHostServiceClntDelete(struct HdfSListNode *listEntry) +void DevHostServiceClntDelete(struct DevHostServiceClnt *hostClnt) { - struct DevHostServiceClnt *hostClnt = (struct DevHostServiceClnt *)listEntry; if (hostClnt != NULL) { DevHostServiceClntFreeInstance(hostClnt); } diff --git a/core/manager/src/devmgr_service.c b/core/manager/src/devmgr_service.c index 545d8675a..da78d39e2 100644 --- a/core/manager/src/devmgr_service.c +++ b/core/manager/src/devmgr_service.c @@ -15,11 +15,11 @@ #include "hdf_host_info.h" #include "hdf_log.h" #include "hdf_object_manager.h" -#include "power_state_manager.h" #define HDF_LOG_TAG devmgr_service -static int DevmgrServiceActiveDevice(struct DevHostServiceClnt *hostClnt, struct HdfDeviceInfo *deviceInfo, bool isLoad) +static int DevmgrServiceActiveDevice(struct DevHostServiceClnt *hostClnt, + struct HdfDeviceInfo *deviceInfo, bool isLoad) { struct IDevHostService *devHostSvcIf = (struct IDevHostService *)hostClnt->hostService; if (devHostSvcIf == NULL) { @@ -43,7 +43,6 @@ static int DevmgrServiceActiveDevice(struct DevHostServiceClnt *hostClnt, struct static int DevmgrServiceFindAndActiveDevice(const char *svcName, bool isLoad) { - struct HdfSListIterator itHost; struct HdfSListIterator itDeviceInfo; struct HdfDeviceInfo *deviceInfo = NULL; struct DevHostServiceClnt *hostClnt = NULL; @@ -52,9 +51,7 @@ static int DevmgrServiceFindAndActiveDevice(const char *svcName, bool isLoad) return HDF_ERR_INVALID_PARAM; } - HdfSListIteratorInit(&itHost, &devMgrSvc->hosts); - while (HdfSListIteratorHasNext(&itHost)) { - hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&itHost); + DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) { HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos); while (HdfSListIteratorHasNext(&itDeviceInfo)) { deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo); @@ -63,13 +60,13 @@ static int DevmgrServiceFindAndActiveDevice(const char *svcName, bool isLoad) } } } + return HDF_FAILURE; } int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc) { int32_t ret; - struct HdfSListIterator itHost; struct HdfSListIterator itDeviceInfo; struct HdfDeviceInfo *deviceInfo = NULL; struct DevHostServiceClnt *hostClnt = NULL; @@ -77,9 +74,7 @@ int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc) return HDF_FAILURE; } - HdfSListIteratorInit(&itHost, &devMgrSvc->hosts); - while (HdfSListIteratorHasNext(&itHost)) { - hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&itHost); + DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) { HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos); while (HdfSListIteratorHasNext(&itDeviceInfo)) { deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo); @@ -106,16 +101,14 @@ int DevmgrServiceUnLoadDevice(const char *svcName) static struct DevHostServiceClnt *DevmgrServiceFindDeviceHost(struct IDevmgrService *inst, uint16_t hostId) { - struct HdfSListIterator it; struct DevHostServiceClnt *hostClnt = NULL; struct DevmgrService *dmService = (struct DevmgrService *)inst; if (dmService == NULL) { HDF_LOGE("failed to find device host, dmService is null"); return NULL; } - HdfSListIteratorInit(&it, &dmService->hosts); - while (HdfSListIteratorHasNext(&it)) { - hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&it); + + DLIST_FOR_EACH_ENTRY(hostClnt, &dmService->hosts, struct DevHostServiceClnt, node) { if (hostClnt->hostId == hostId) { return hostClnt; } @@ -198,7 +191,7 @@ static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst) struct DevHostServiceClnt *hostClnt = NULL; struct IDriverInstaller *installer = NULL; installer = DriverInstallerGetInstance(); - if ((installer == NULL) || (installer->StartDeviceHost == NULL)) { + if (installer == NULL || installer->StartDeviceHost == NULL) { HDF_LOGE("installer or installer->StartDeviceHost is null"); return HDF_FAILURE; } @@ -215,11 +208,11 @@ static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst) HDF_LOGW("failed to create new device host client"); continue; } - HdfSListAdd(&inst->hosts, &hostClnt->node); + DListInsertTail(&hostClnt->node, &inst->hosts); hostClnt->hostPid = installer->StartDeviceHost(hostAttr->hostId, hostAttr->hostName); if (hostClnt->hostPid == HDF_FAILURE) { HDF_LOGW("failed to start device host, host id is %u", hostAttr->hostId); - HdfSListRemove(&inst->hosts, &hostClnt->node); + DListRemove(&hostClnt->node); DevHostServiceClntFreeInstance(hostClnt); } } @@ -237,6 +230,45 @@ int DevmgrServiceStartService(struct IDevmgrService *inst) return DevmgrServiceStartDeviceHosts(dmService); } +int DevmgrServicePowerStateChange(struct IDevmgrService *devmgrService, enum HdfPowerState powerState) +{ + struct DevHostServiceClnt *hostClient = NULL; + struct DevmgrService *devmgr = NULL; + int result = HDF_SUCCESS; + + if (devmgrService == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + + if (!IsValidPowerState(powerState)) { + HDF_LOGE("%s:invalid power event %u", __func__, powerState); + return HDF_ERR_INVALID_PARAM; + } + devmgr = CONTAINER_OF(devmgrService, struct DevmgrService, super); + + if (IsPowerWakeState(powerState)) { + HDF_LOGI("%s:wake state %u", __func__, powerState); + DLIST_FOR_EACH_ENTRY(hostClient, &devmgr->hosts, struct DevHostServiceClnt, node) { + if (hostClient->hostService != NULL) { + if (hostClient->hostService->PmNotify(hostClient->hostService, powerState) != HDF_SUCCESS) { + result = HDF_FAILURE; + } + } + } + } else { + HDF_LOGI("%s:suspend state %u", __func__, powerState); + DLIST_FOR_EACH_ENTRY_REVERSE(hostClient, &devmgr->hosts, struct DevHostServiceClnt, node) { + if (hostClient->hostService != NULL) { + if (hostClient->hostService->PmNotify(hostClient->hostService, powerState) != HDF_SUCCESS) { + result = HDF_FAILURE; + } + } + } + } + + return result; +} + bool DevmgrServiceConstruct(struct DevmgrService *inst) { if (OsalMutexInit(&inst->devMgrMutex) != HDF_SUCCESS) { @@ -248,9 +280,8 @@ bool DevmgrServiceConstruct(struct DevmgrService *inst) devMgrSvcIf->AttachDevice = DevmgrServiceAttachDevice; devMgrSvcIf->AttachDeviceHost = DevmgrServiceAttachDeviceHost; devMgrSvcIf->StartService = DevmgrServiceStartService; - devMgrSvcIf->AcquireWakeLock = DevmgrServiceAcquireWakeLock; - devMgrSvcIf->ReleaseWakeLock = DevmgrServiceReleaseWakeLock; - HdfSListInit(&inst->hosts); + devMgrSvcIf->PowerStateChange = DevmgrServicePowerStateChange; + DListHeadInit(&inst->hosts); return true; } else { return false; @@ -285,24 +316,12 @@ void DevmgrServiceRelease(struct HdfObject *object) if (devmgrService == NULL) { return; } - HdfSListFlush(&devmgrService->hosts, DevHostServiceClntDelete); - OsalMutexDestroy(&devmgrService->devMgrMutex); -} - -void DevmgrServiceAcquireWakeLock(struct IDevmgrService *inst, struct IPowerStateToken *tokenIf) -{ - (void)inst; - struct PowerStateManager *stateManager = PowerStateManagerGetInstance(); - if ((stateManager != NULL) && (stateManager->AcquireWakeLock != NULL)) { - stateManager->AcquireWakeLock(stateManager, tokenIf); + struct DevHostServiceClnt *hostClnt = NULL; + struct DevHostServiceClnt *hostClntTmp = NULL; + DLIST_FOR_EACH_ENTRY_SAFE(hostClnt, hostClntTmp, &devmgrService->hosts, struct DevHostServiceClnt, node) { + DevHostServiceClntDelete(hostClnt); + DListRemove(&hostClnt->node); } -} -void DevmgrServiceReleaseWakeLock(struct IDevmgrService *inst, struct IPowerStateToken *tokenIf) -{ - (void)inst; - struct PowerStateManager *stateManager = PowerStateManagerGetInstance(); - if ((stateManager != NULL) && (stateManager->ReleaseWakeLock != NULL)) { - stateManager->ReleaseWakeLock(stateManager, tokenIf); - } + OsalMutexDestroy(&devmgrService->devMgrMutex); } diff --git a/core/manager/src/power_state_manager.c b/core/manager/src/power_state_manager.c deleted file mode 100644 index 29dcc7b1c..000000000 --- a/core/manager/src/power_state_manager.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2020-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 "power_state_manager.h" -#include "hdf_object_manager.h" -#include "power_state_token_clnt.h" - -static struct PowerStateTokenClnt *PowerStateManagerGetStateTokenClnt( - struct PowerStateManager *inst, struct IPowerStateToken *tokenIf) -{ - struct HdfSListIterator it; - if (inst == NULL) { - return NULL; - } - HdfSListIteratorInit(&it, &inst->tokens); - while (HdfSListIteratorHasNext(&it)) { - struct PowerStateTokenClnt *tokenClnt = - (struct PowerStateTokenClnt *)HdfSListIteratorNext(&it); - if (tokenClnt->tokenIf == tokenIf) { - return tokenClnt; - } - } - return NULL; -} - -static void PowerStateManagerAcquireWakeLock( - struct PowerStateManager *inst, struct IPowerStateToken *tokenIf) -{ - if (inst == NULL) { - return; - } - struct HdfSRef *sref = &inst->wakeRef; - struct PowerStateTokenClnt *stateTokenClnt = PowerStateManagerGetStateTokenClnt(inst, tokenIf); - if (stateTokenClnt == NULL) { - return; - } - stateTokenClnt->powerState = POWER_STATE_ACTIVE; - if (sref->Acquire != NULL) { - sref->Acquire(sref); - } -} - -static void PowerStateManagerReleaseWakeLock( - struct PowerStateManager *inst, struct IPowerStateToken *tokenIf) -{ - struct HdfSRef *sref = NULL; - struct PowerStateTokenClnt *stateTokenClnt = PowerStateManagerGetStateTokenClnt(inst, tokenIf); - if (inst == NULL || stateTokenClnt == NULL) { - return; - } - stateTokenClnt->powerState = POWER_STATE_INACTIVE; - sref = &inst->wakeRef; - if (sref->Release != NULL) { - sref->Release(sref); - } -} - -static void PowerStateManagerConstruct(struct PowerStateManager *inst) -{ - static struct IHdfSRefListener wakeLockRefListener = { - .OnFirstAcquire = NULL, - .OnLastRelease = NULL, - }; - - inst->AcquireWakeLock = PowerStateManagerAcquireWakeLock; - inst->ReleaseWakeLock = PowerStateManagerReleaseWakeLock; - HdfSListInit(&inst->tokens); - HdfSRefConstruct(&inst->wakeRef, &wakeLockRefListener); -} - -struct PowerStateManager *PowerStateManagerGetInstance() -{ - static struct PowerStateManager powerStateManager = { 0 }; - if (powerStateManager.AcquireWakeLock == NULL) { - PowerStateManagerConstruct(&powerStateManager); - } - return &powerStateManager; -} diff --git a/core/manager/src/power_state_token_clnt.c b/core/manager/src/power_state_token_clnt.c index 31eedb881..7bf1abd4a 100644 --- a/core/manager/src/power_state_token_clnt.c +++ b/core/manager/src/power_state_token_clnt.c @@ -12,7 +12,7 @@ static void PowerStateTokenClntConstruct(struct PowerStateTokenClnt *clnt, struct IPowerStateToken *tokenIf) { clnt->tokenIf = tokenIf; - clnt->powerState = POWER_STATE_INACTIVE; + clnt->powerState = PSM_STATE_INACTIVE; } struct PowerStateTokenClnt *PowerStateTokenClntNewInstance(struct IPowerStateToken *tokenIf) diff --git a/core/manager/test/unittest/common/hdf_ioservice_test.cpp b/core/manager/test/unittest/common/hdf_ioservice_test.cpp index 9057d7beb..ce24f0fd3 100644 --- a/core/manager/test/unittest/common/hdf_ioservice_test.cpp +++ b/core/manager/test/unittest/common/hdf_ioservice_test.cpp @@ -18,6 +18,7 @@ #include "osal_time.h" #include "sample_driver_test.h" #include "hdf_log.h" +#include "hdf_power_state.h" using namespace testing::ext; @@ -596,3 +597,38 @@ HWTEST_F(IoServiceTest, HdfIoService012, TestSize.Level0) HdfIoServiceRecycle(serv); } + +/* * + * @tc.name: HdfIoService013 + * @tc.desc: devmgr power state change test + * @tc.type: FUNC + */ +HWTEST_F(IoServiceTest, HdfIoService013, TestSize.Level0) +{ + struct HdfSBuf *data = HdfSBufObtainDefaultSize(); + ASSERT_NE(data, nullptr); + + struct HdfIoService *serv = HdfIoServiceBind(testSvcName); + ASSERT_NE(serv, nullptr); + + HdfSbufWriteUint32(data, POWER_STATE_SUSPEND); + int ret = serv->dispatcher->Dispatch(&serv->object, SAMPLE_DRIVER_PM_STATE_INJECT, data, NULL); + ASSERT_EQ(ret, HDF_SUCCESS); + + HdfSbufFlush(data); + HdfSbufWriteUint32(data, POWER_STATE_RESUME); + ret = serv->dispatcher->Dispatch(&serv->object, SAMPLE_DRIVER_PM_STATE_INJECT, data, NULL); + ASSERT_EQ(ret, HDF_SUCCESS); + + HdfSbufFlush(data); + HdfSbufWriteUint32(data, POWER_STATE_DOZE_SUSPEND); + ret = serv->dispatcher->Dispatch(&serv->object, SAMPLE_DRIVER_PM_STATE_INJECT, data, NULL); + ASSERT_EQ(ret, HDF_SUCCESS); + + HdfSbufFlush(data); + HdfSbufWriteUint32(data, POWER_STATE_DOZE_RESUME); + ret = serv->dispatcher->Dispatch(&serv->object, SAMPLE_DRIVER_PM_STATE_INJECT, data, NULL); + ASSERT_EQ(ret, HDF_SUCCESS); + HdfIoServiceRecycle(serv); + HdfSBufRecycle(data); +} diff --git a/core/shared/include/devhost_service_if.h b/core/shared/include/devhost_service_if.h index 83e9d21ac..a1c226915 100644 --- a/core/shared/include/devhost_service_if.h +++ b/core/shared/include/devhost_service_if.h @@ -14,9 +14,10 @@ struct IDevHostService { struct HdfObject object; - int (*AddDevice)(struct IDevHostService *, const struct HdfDeviceInfo *); - int (*DelDevice)(struct IDevHostService *, const struct HdfDeviceInfo *); - int (*StartService)(struct IDevHostService *); + int (*AddDevice)(struct IDevHostService *hostService, const struct HdfDeviceInfo *devInfo); + int (*DelDevice)(struct IDevHostService *hostService, const struct HdfDeviceInfo *devInfo); + int (*StartService)(struct IDevHostService *hostService); + int (*PmNotify)(struct IDevHostService *service, uint32_t powerState); }; #endif /* DEVHOST_SERVICE_IF_H */ diff --git a/core/shared/include/devmgr_service_if.h b/core/shared/include/devmgr_service_if.h index 136f2832a..55df8e426 100644 --- a/core/shared/include/devmgr_service_if.h +++ b/core/shared/include/devmgr_service_if.h @@ -13,6 +13,7 @@ #include "device_token_if.h" #include "hdf_object.h" #include "power_state_token_if.h" +#include "hdf_power_state.h" struct IDevmgrService { struct HdfObject base; @@ -20,8 +21,7 @@ struct IDevmgrService { int (*AttachDeviceHost)(struct IDevmgrService *, uint16_t, struct IDevHostService *); int (*AttachDevice)(struct IDevmgrService *, const struct HdfDeviceInfo *, struct IHdfDeviceToken *); int (*StartService)(struct IDevmgrService *); - void (*AcquireWakeLock)(struct IDevmgrService *, struct IPowerStateToken *); - void (*ReleaseWakeLock)(struct IDevmgrService *, struct IPowerStateToken *); + int (*PowerStateChange)(struct IDevmgrService *, enum HdfPowerState pEvent); }; #endif /* DEVMGR_SERVICE_IF_H */ diff --git a/core/manager/include/power_state_manager.h b/core/shared/include/hdf_power_state.h similarity index 34% rename from core/manager/include/power_state_manager.h rename to core/shared/include/hdf_power_state.h index 0cf87de32..d10557113 100644 --- a/core/manager/include/power_state_manager.h +++ b/core/shared/include/hdf_power_state.h @@ -6,20 +6,25 @@ * See the LICENSE file in the root of this repository for complete details. */ -#ifndef POWER_STATE_MANAGER_H -#define POWER_STATE_MANAGER_H +#ifndef HDF_POWER_STATE_H +#define HDF_POWER_STATE_H -#include "hdf_sref.h" -#include "hdf_slist.h" -#include "power_state_token_if.h" - -struct PowerStateManager { - struct HdfSRef wakeRef; - struct HdfSList tokens; - void (*AcquireWakeLock)(struct PowerStateManager *, struct IPowerStateToken *); - void (*ReleaseWakeLock)(struct PowerStateManager *, struct IPowerStateToken *); +enum HdfPowerState { + POWER_STATE_DOZE_RESUME, + POWER_STATE_DOZE_SUSPEND, + POWER_STATE_RESUME, + POWER_STATE_SUSPEND, + POWER_STATE_MAX, }; -struct PowerStateManager *PowerStateManagerGetInstance(void); +static inline bool IsPowerWakeState(uint32_t state) +{ + return state == POWER_STATE_DOZE_RESUME || state == POWER_STATE_RESUME; +} + +static inline bool IsValidPowerState(uint32_t state) +{ + return state < POWER_STATE_MAX; +} -#endif /* POWER_STATE_MANAGER_H */ \ No newline at end of file +#endif /* HDF_POWER_STATE_H */ \ No newline at end of file diff --git a/core/shared/include/power_state_token_if.h b/core/shared/include/power_state_token_if.h index fe828f1eb..0e054c01a 100644 --- a/core/shared/include/power_state_token_if.h +++ b/core/shared/include/power_state_token_if.h @@ -10,10 +10,10 @@ #define POWER_STATE_TOKEN_IF_H typedef enum { - POWER_STATE_IDLE, /* Idle state */ - POWER_STATE_ACTIVE, /* Activated state */ - POWER_STATE_INACTIVE, /* Error state */ -} HdfPowerState; + PSM_STATE_IDLE, /* Idle state */ + PSM_STATE_ACTIVE, /* Activated state */ + PSM_STATE_INACTIVE, /* Error state */ +} HdfPsmState; struct IPowerStateToken { void (*AcquireWakeLock)(struct IPowerStateToken *); diff --git a/include/core/hdf_pm.h b/include/core/hdf_pm.h index fbf6e3af4..1c8412fa4 100644 --- a/include/core/hdf_pm.h +++ b/include/core/hdf_pm.h @@ -1,10 +1,10 @@ -/* - * Copyright (c) 2020-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. - */ +/* + * Copyright (c) 2020-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 HDF_POWER_MANAGEMENT_H #define HDF_POWER_MANAGEMENT_H @@ -34,11 +34,6 @@ struct IPowerEventListener { int (*Suspend)(struct HdfDeviceObject *deviceObject); }; -static inline bool HdfPmIsWakeEvent(int sysEvent) -{ - return sysEvent >= KEVENT_POWER_RESUME && sysEvent <= KEVENT_POWER_DISPLAY_ON; -} - int HdfPmRegisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener); void HdfPmUnregisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener); void HdfPmAcquireDevice(struct HdfDeviceObject *deviceObject); diff --git a/include/utils/hdf_dlist.h b/include/utils/hdf_dlist.h index 369cb089f..196a4d2c8 100644 --- a/include/utils/hdf_dlist.h +++ b/include/utils/hdf_dlist.h @@ -143,6 +143,17 @@ static inline void DListMerge(struct DListHead *list, struct DListHead *head) DListHeadInit(list); } + +static inline int DlistGetCount(const struct DListHead *head) +{ + struct DListHead *next = head->next; + int count = 0; + while (next != head) { + next = next->next; + count++; + } + return count; +} /** * @brief Obtains the address of a structure variable from its member address. * diff --git a/test/unittest/manager/sample_driver_test.c b/test/unittest/manager/sample_driver_test.c index bf69825f9..f997f567e 100644 --- a/test/unittest/manager/sample_driver_test.c +++ b/test/unittest/manager/sample_driver_test.c @@ -7,8 +7,10 @@ */ #include "sample_driver_test.h" #include "devsvc_manager_clnt.h" +#include "devmgr_service.h" #include "hdf_log.h" #include "hdf_device_desc.h" +#include "hdf_pm.h" #define HDF_LOG_TAG sample_driver_test @@ -67,12 +69,22 @@ int32_t SampleDriverSendEvent(struct HdfDeviceIoClient *client, int id, struct H return broadcast ? HdfDeviceSendEvent(client->device, id, data) : HdfDeviceSendEventToClient(client, id, data); } +int32_t SampleDriverPowerStateInject(uint32_t powerState) +{ + struct IDevmgrService *devmgrService = DevmgrServiceGetInstance(); + int ret = devmgrService->PowerStateChange(devmgrService, powerState); + + HDF_LOGI("%s: inject power state(%d) done, ret = %d", __func__, powerState, ret); + return ret; +} + int32_t SampleDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) { int32_t ret = HDF_SUCCESS; if (reply == NULL || client == NULL) { return HDF_FAILURE; } + uint32_t powerState = 0; switch (cmdId) { case SAMPLE_DRIVER_REGISTER_DEVICE: { ret = SampleDriverRegisterDevice(data); @@ -91,6 +103,9 @@ int32_t SampleDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct ret = SampleDriverSendEvent(client, cmdId, data, true); HdfSbufWriteInt32(reply, INT32_MAX); break; + case SAMPLE_DRIVER_PM_STATE_INJECT: + HdfSbufReadUint32(data, &powerState); + return SampleDriverPowerStateInject(powerState); default: break; } @@ -113,14 +128,53 @@ int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) return HDF_SUCCESS; } +int HdfSampleDozeResume(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("%s:called, object = %llx", __func__, (uint64_t)deviceObject); + return HDF_SUCCESS; +} + +int HdfSampleDozeSuspend(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("%s:called, object = %llx", __func__, (uint64_t)deviceObject); + return HDF_SUCCESS; +} + +int HdfSampleResume(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("%s:called, object = %llx", __func__, (uint64_t)deviceObject); + return HDF_SUCCESS; +} + +int HdfSampleSuspend(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("%s:called, object = %llx", __func__, (uint64_t)deviceObject); + return HDF_SUCCESS; +} + +struct SampleDriverPmListener { + struct IPowerEventListener powerListener; + void *p; +}; + int HdfSampleDriverInit(struct HdfDeviceObject *deviceObject) { - HDF_LOGD("%s::enter!, deviceObject=%p", __func__, deviceObject); + HDF_LOGI("%s::enter!, deviceObject=%llx", __func__, (uint64_t)deviceObject); if (deviceObject == NULL) { HDF_LOGE("%s::ptr is null!", __func__); return HDF_FAILURE; } HDF_LOGD("%s:Init success", __func__); + + static struct SampleDriverPmListener pmListener = {0}; + pmListener.powerListener.DozeResume = HdfSampleDozeResume; + pmListener.powerListener.DozeSuspend = HdfSampleDozeSuspend; + pmListener.powerListener.Resume = HdfSampleResume; + pmListener.powerListener.Suspend = HdfSampleSuspend; + + int ret = HdfPmRegisterPowerListener(deviceObject, &pmListener.powerListener); + HDF_LOGI("%s:register power listener, ret = %d", __func__, ret); + return HDF_SUCCESS; } diff --git a/test/unittest/manager/sample_driver_test.h b/test/unittest/manager/sample_driver_test.h index 3241601bb..a2ce58f49 100644 --- a/test/unittest/manager/sample_driver_test.h +++ b/test/unittest/manager/sample_driver_test.h @@ -18,6 +18,7 @@ typedef enum { SAMPLE_DRIVER_UNREGISTER_DEVICE, SAMPLE_DRIVER_SENDEVENT_SINGLE_DEVICE, SAMPLE_DRIVER_SENDEVENT_BROADCAST_DEVICE, + SAMPLE_DRIVER_PM_STATE_INJECT, } SAMPLE_DRIVER_CMDID; struct HdfDeviceObject *GetDeviceObject(void); -- Gitee From 59eedac3d491a856251d98b15267f36e3ff06fc6 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Sat, 17 Jul 2021 10:15:23 +0800 Subject: [PATCH 014/205] fix IoService test case failed issue Signed-off-by: yuanbo --- core/manager/test/unittest/common/hdf_ioservice_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/manager/test/unittest/common/hdf_ioservice_test.cpp b/core/manager/test/unittest/common/hdf_ioservice_test.cpp index ce24f0fd3..08d76d3e1 100644 --- a/core/manager/test/unittest/common/hdf_ioservice_test.cpp +++ b/core/manager/test/unittest/common/hdf_ioservice_test.cpp @@ -39,7 +39,7 @@ public: static struct Eventlistener listener0; static struct Eventlistener listener1; const char *testSvcName = SAMPLE_SERVICE; - const int eventWaitTimeUs = (50 * 1000); + const int eventWaitTimeUs = (150 * 1000); static int eventCount; }; -- Gitee From 27317472053517478286a46c97856b89e0544c90 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Tue, 20 Jul 2021 02:47:41 +0000 Subject: [PATCH 015/205] sync code from std Signed-off-by: YOUR_NAME --- model/input/driver/hdf_hid_adapter.c | 87 +++++++++++-------- model/input/driver/hdf_hid_adapter.h | 4 +- model/input/driver/hdf_input_device_manager.c | 23 +++-- model/input/driver/hdf_input_device_manager.h | 3 +- model/input/driver/touchscreen/touch_gt911.c | 4 +- 5 files changed, 70 insertions(+), 51 deletions(-) diff --git a/model/input/driver/hdf_hid_adapter.c b/model/input/driver/hdf_hid_adapter.c index 47496b8a6..59b4ad702 100644 --- a/model/input/driver/hdf_hid_adapter.c +++ b/model/input/driver/hdf_hid_adapter.c @@ -15,7 +15,7 @@ #include "hdf_hid_adapter.h" InputDevice *cachedHid[MAX_INPUT_DEV_NUM]; -HidInfo cachedInfo[MAX_INPUT_DEV_NUM]; +HidInfo *g_cachedInfo[MAX_INPUT_DEV_NUM]; static bool HaveHidCache(void) { @@ -47,7 +47,7 @@ static int cachedPosId(void) { int32_t id = 0; while (id < MAX_INPUT_DEV_NUM) { - if (cachedInfo[id].devName == NULL) { + if (g_cachedInfo[id] == NULL) { return id; } id++; @@ -55,24 +55,36 @@ static int cachedPosId(void) return HDF_FAILURE; } -void GetInfoFromHid(HidInfo info) +void SendInfoToHdf(HidInfo *info) { + int ret; int32_t id = cachedPosId(); if (id == HDF_FAILURE) { HDF_LOGE("%s: cached hid info failed", __func__); return; } - cachedInfo[id] = info; + g_cachedInfo[id] = (HidInfo *)OsalMemAlloc(sizeof(HidInfo)); + if (g_cachedInfo[id] == NULL) { + HDF_LOGE("%s: malloc failed", __func__); + return; + } + ret = memcpy_s(g_cachedInfo[id], sizeof(HidInfo), info, sizeof(HidInfo)); + if (ret != 0) { + HDF_LOGE("%s: memcpy failed", __func__); + OsalMemFree(g_cachedInfo[id]); + g_cachedInfo[id] = NULL; + return; + } } static void SetInputDevAbility(InputDevice *inputDev) { - HidInfo info; + HidInfo *info = NULL; int32_t id = 0; uint32_t len; while (id < MAX_INPUT_DEV_NUM) { - if(cachedInfo[id].devName != NULL && !strcmp(inputDev->devName, cachedInfo[id].devName)) { - info = cachedInfo[id]; + if(g_cachedInfo[id] != NULL && !strcmp(inputDev->devName, g_cachedInfo[id]->devName)) { + info = g_cachedInfo[id]; break; } id++; @@ -83,35 +95,36 @@ static void SetInputDevAbility(InputDevice *inputDev) } len = sizeof(unsigned long); memcpy_s(inputDev->abilitySet.devProp, len * BITS_TO_LONG(INPUT_PROP_CNT), - info.devProp, len * BITS_TO_LONG(INPUT_PROP_CNT)); + info->devProp, len * BITS_TO_LONG(INPUT_PROP_CNT)); memcpy_s(inputDev->abilitySet.eventType, len * BITS_TO_LONG(EV_CNT), - info.eventType, len * BITS_TO_LONG(EV_CNT)); + info->eventType, len * BITS_TO_LONG(EV_CNT)); memcpy_s(inputDev->abilitySet.absCode, len * BITS_TO_LONG(ABS_CNT), - info.absCode, len * BITS_TO_LONG(ABS_CNT)); + info->absCode, len * BITS_TO_LONG(ABS_CNT)); memcpy_s(inputDev->abilitySet.relCode, len * BITS_TO_LONG(REL_CNT), - info.relCode, len * BITS_TO_LONG(REL_CNT)); + info->relCode, len * BITS_TO_LONG(REL_CNT)); memcpy_s(inputDev->abilitySet.keyCode, len * BITS_TO_LONG(KEY_CNT), - info.keyCode, len * BITS_TO_LONG(KEY_CNT)); + info->keyCode, len * BITS_TO_LONG(KEY_CNT)); memcpy_s(inputDev->abilitySet.ledCode, len * BITS_TO_LONG(LED_CNT), - info.ledCode, len * BITS_TO_LONG(LED_CNT)); + info->ledCode, len * BITS_TO_LONG(LED_CNT)); memcpy_s(inputDev->abilitySet.miscCode, len * BITS_TO_LONG(MSC_CNT), - info.miscCode, len * BITS_TO_LONG(MSC_CNT)); + info->miscCode, len * BITS_TO_LONG(MSC_CNT)); memcpy_s(inputDev->abilitySet.soundCode, len * BITS_TO_LONG(SND_CNT), - info.soundCode, len * BITS_TO_LONG(SND_CNT)); + info->soundCode, len * BITS_TO_LONG(SND_CNT)); memcpy_s(inputDev->abilitySet.forceCode, len * BITS_TO_LONG(FF_CNT), - info.forceCode, len * BITS_TO_LONG(FF_CNT)); + info->forceCode, len * BITS_TO_LONG(FF_CNT)); memcpy_s(inputDev->abilitySet.switchCode, len * BITS_TO_LONG(SW_CNT), - info.switchCode, len * BITS_TO_LONG(SW_CNT)); + info->switchCode, len * BITS_TO_LONG(SW_CNT)); - inputDev->attrSet.id.busType = info.bustype; - inputDev->attrSet.id.vendor = info.vendor; - inputDev->attrSet.id.product = info.product; - inputDev->attrSet.id.version = info.version; + inputDev->attrSet.id.busType = info->bustype; + inputDev->attrSet.id.vendor = info->vendor; + inputDev->attrSet.id.product = info->product; + inputDev->attrSet.id.version = info->version; - cachedInfo[id].devName = NULL; + OsalMemFree(g_cachedInfo[id]); + g_cachedInfo[id] = NULL; } -static InputDevice* HidConstructInputDev(HidInfo info) +static InputDevice* HidConstructInputDev(HidInfo *info) { InputDevice *inputDev = (InputDevice *)OsalMemAlloc(sizeof(InputDevice)); if (inputDev == NULL) { @@ -120,28 +133,26 @@ static InputDevice* HidConstructInputDev(HidInfo info) } (void)memset_s(inputDev, sizeof(InputDevice), 0, sizeof(InputDevice)); - inputDev->devType = info.devType; - inputDev->devName = info.devName; + + inputDev->devType = info->devType; + inputDev->devName = info->devName; SetInputDevAbility(inputDev); return inputDev; } -static InputDevice* DoRegisterInputDev(InputDevice* inputDev) +static void DoRegisterInputDev(InputDevice* inputDev) { int32_t ret; - ret = RegisterInputDevice(inputDev); - if (ret == HDF_SUCCESS) { - return inputDev; - } else { + if (ret != HDF_SUCCESS) { OsalMemFree(inputDev); inputDev = NULL; - return NULL; + return; } } -static InputDevice* CacheHid(InputDevice* inputDev) +static void CacheHid(InputDevice* inputDev) { int32_t i = 0; while ((i < MAX_INPUT_DEV_NUM) && (cachedHid[i] != NULL)) { @@ -149,9 +160,10 @@ static InputDevice* CacheHid(InputDevice* inputDev) } if (i < MAX_INPUT_DEV_NUM) { cachedHid[i] = inputDev; - return inputDev; + return; + } else { + HDF_LOGE("%s: cached hid device failed", __func__); } - return NULL; } static bool InputDriverLoaded(void) @@ -163,7 +175,7 @@ static bool InputDriverLoaded(void) return false; } -void* HidRegisterHdfInputDev(HidInfo info) +void* HidRegisterHdfInputDev(HidInfo *info) { InputDevice* inputDev = HidConstructInputDev(info); if (inputDev == NULL) { @@ -172,10 +184,11 @@ void* HidRegisterHdfInputDev(HidInfo info) } if (InputDriverLoaded()) { - return DoRegisterInputDev(inputDev); + DoRegisterInputDev(inputDev); } else { - return CacheHid(inputDev); + CacheHid(inputDev); } + return inputDev; } void HidUnregisterHdfInputDev(const void *inputDev) diff --git a/model/input/driver/hdf_hid_adapter.h b/model/input/driver/hdf_hid_adapter.h index 67285c385..487a047e2 100644 --- a/model/input/driver/hdf_hid_adapter.h +++ b/model/input/driver/hdf_hid_adapter.h @@ -73,8 +73,8 @@ enum HidType { HID_TYPE_UNKNOWN, /* Unknown input device type */ }; -void GetInfoFromHid(HidInfo info); -void* HidRegisterHdfInputDev(HidInfo dev); +void SendInfoToHdf(HidInfo *info); +void* HidRegisterHdfInputDev(HidInfo *dev); void HidUnregisterHdfInputDev(const void *inputDev); void HidReportEvent(const void *inputDev, uint32_t type, uint32_t code, int32_t value); diff --git a/model/input/driver/hdf_input_device_manager.c b/model/input/driver/hdf_input_device_manager.c index 028d802af..4d449b6c1 100644 --- a/model/input/driver/hdf_input_device_manager.c +++ b/model/input/driver/hdf_input_device_manager.c @@ -62,13 +62,11 @@ static struct HdfDeviceObject *HidRegisterHdfDevice(InputDevice *inputDev) static void HotPlugNotify(const InputDevice *inputDev, uint32_t status) { - struct HdfSBuf *sbuf = NULL; HotPlugEvent event = {0}; int32_t ret; - sbuf = HdfSBufObtain(sizeof(HotPlugEvent)); - if (sbuf == NULL) { - HDF_LOGE("%s: obtain buffer failed", __func__); + if (inputDev->eventBuf == NULL) { + HDF_LOGE("%s: event buffer is null", __func__); return; } @@ -76,16 +74,16 @@ static void HotPlugNotify(const InputDevice *inputDev, uint32_t status) event.devType = inputDev->devType; event.status = status; - if (!HdfSbufWriteBuffer(sbuf, &event, sizeof(HotPlugEvent))) { + if (!HdfSbufWriteBuffer(inputDev->eventBuf, &event, sizeof(HotPlugEvent))) { HDF_LOGE("%s: write buffer failed", __func__); - HdfSbufFlush(sbuf); + HdfSbufFlush(inputDev->eventBuf); return; } - ret = HdfDeviceSendEvent(g_inputManager->hdfDevObj, 0, sbuf); + ret = HdfDeviceSendEvent(g_inputManager->hdfDevObj, 0, inputDev->eventBuf); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: send event failed", __func__); } - HdfSbufFlush(sbuf); + HdfSbufFlush(inputDev->eventBuf); } static int32_t CreateDeviceNode(InputDevice *inputDev) @@ -230,6 +228,11 @@ static int32_t AllocPackageBuffer(InputDevice *inputDev) HDF_LOGE("%s: malloc sbuf failed", __func__); return HDF_ERR_MALLOC_FAIL; } + inputDev->eventBuf = HdfSBufObtain(sizeof(HotPlugEvent)); + if (inputDev->eventBuf == NULL) { + HDF_LOGE("%s: malloc sbuf failed", __func__); + return HDF_ERR_MALLOC_FAIL; + } inputDev->pkgNum = pkgNum; return HDF_SUCCESS; } @@ -320,12 +323,14 @@ void UnregisterInputDevice(InputDevice *inputDev) } DeleteDeviceNode(inputDev); - OsalMemFree(inputDev->pkgBuf); + HdfSBufRecycle(inputDev->pkgBuf); inputDev->pkgBuf = NULL; ret = DeleteInputDevice(inputDev); if (ret != HDF_SUCCESS) { goto EXIT; } + HdfSBufRecycle(inputDev->eventBuf); + inputDev->eventBuf = NULL; OsalMemFree(inputDev); inputDev = NULL; OsalMutexUnlock(&g_inputManager->mutex); diff --git a/model/input/driver/hdf_input_device_manager.h b/model/input/driver/hdf_input_device_manager.h index 713784ce0..8b959bd7d 100644 --- a/model/input/driver/hdf_input_device_manager.h +++ b/model/input/driver/hdf_input_device_manager.h @@ -20,7 +20,7 @@ #define HDF_LOG_TAG HDF_INPUT_DRV #define INPUT_DEV_PATH_LEN 64 #define MAX_INPUT_DEV_NUM 32 -#define DEV_NAME_LEN 32 +#define DEV_NAME_LEN 64 #define ONLINE 0 #define OFFLINE 1 @@ -108,6 +108,7 @@ typedef struct InputDeviceInfo { uint16_t pkgCount; bool errFrameFlag; struct HdfSBuf *pkgBuf; + struct HdfSBuf *eventBuf; void *pvtData; DevAttr attrSet; DevAbility abilitySet; diff --git a/model/input/driver/touchscreen/touch_gt911.c b/model/input/driver/touchscreen/touch_gt911.c index fb935966b..c25c7c099 100644 --- a/model/input/driver/touchscreen/touch_gt911.c +++ b/model/input/driver/touchscreen/touch_gt911.c @@ -15,9 +15,9 @@ #include "touch_gt911.h" #define AXIS_X_MAX 479 -#define AXIS_X_RANGE 480 +#define AXIS_X_RANGE 0 #define AXIS_Y_MAX 959 -#define AXIS_Y_RANGE 960 +#define AXIS_Y_RANGE 0 #define MAX_POINT 5 static int32_t ChipInit(ChipDevice *device) -- Gitee From fe4542116bc1388691f37b4f61068c362ebe3bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=87=AF?= Date: Tue, 20 Jul 2021 04:42:39 +0000 Subject: [PATCH 016/205] update model/input/driver/hdf_hid_adapter.c. --- model/input/driver/hdf_hid_adapter.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/model/input/driver/hdf_hid_adapter.c b/model/input/driver/hdf_hid_adapter.c index 59b4ad702..6f5a0df34 100644 --- a/model/input/driver/hdf_hid_adapter.c +++ b/model/input/driver/hdf_hid_adapter.c @@ -77,6 +77,18 @@ void SendInfoToHdf(HidInfo *info) } } +static void FreeCachedInfo() +{ + int32_t id = 0; + while (id < MAX_INPUT_DEV_NUM) { + if (g_cachedInfo[id] != NULL) { + OsalMemFree(g_cachedInfo[id]); + g_cachedInfo[id] = NULL; + } + id++; + } +} + static void SetInputDevAbility(InputDevice *inputDev) { HidInfo *info = NULL; @@ -120,8 +132,7 @@ static void SetInputDevAbility(InputDevice *inputDev) inputDev->attrSet.id.product = info->product; inputDev->attrSet.id.version = info->version; - OsalMemFree(g_cachedInfo[id]); - g_cachedInfo[id] = NULL; + FreeCachedInfo(); } static InputDevice* HidConstructInputDev(HidInfo *info) @@ -133,7 +144,6 @@ static InputDevice* HidConstructInputDev(HidInfo *info) } (void)memset_s(inputDev, sizeof(InputDevice), 0, sizeof(InputDevice)); - inputDev->devType = info->devType; inputDev->devName = info->devName; SetInputDevAbility(inputDev); -- Gitee From 345c97818531cb371b4a0851d9951ae63130ea1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=87=AF?= Date: Tue, 20 Jul 2021 06:16:10 +0000 Subject: [PATCH 017/205] update model/input/driver/hdf_hid_adapter.c. --- model/input/driver/hdf_hid_adapter.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/model/input/driver/hdf_hid_adapter.c b/model/input/driver/hdf_hid_adapter.c index 6f5a0df34..bfd7a771a 100644 --- a/model/input/driver/hdf_hid_adapter.c +++ b/model/input/driver/hdf_hid_adapter.c @@ -361,11 +361,21 @@ static int32_t HdfHIDDriverBind(struct HdfDeviceObject *device) return HDF_SUCCESS; } +static void HdfHIDDriverRelease(struct HdfDeviceObject *device) +{ + FreeCachedInfo(); + if (device == NULL) { + HDF_LOGE("%s: device is null", __func__); + return; + } +} + struct HdfDriverEntry g_hdfHIDEntry = { .moduleVersion = 1, .moduleName = "HDF_HID", .Bind = HdfHIDDriverBind, .Init = HdfHIDDriverInit, + .Release = HdfHIDDriverRelease, }; HDF_INIT(g_hdfHIDEntry); -- Gitee From 9e471b614300d57b55e64e1bf74e6aef52910a7b Mon Sep 17 00:00:00 2001 From: bigA2021 Date: Tue, 20 Jul 2021 04:35:26 -0700 Subject: [PATCH 018/205] fix hcs fail issue Signed-off-by: bigA2021 --- tools/hc-gen/build_hcs.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/tools/hc-gen/build_hcs.py b/tools/hc-gen/build_hcs.py index 4543cb3fd..d67bbd240 100755 --- a/tools/hc-gen/build_hcs.py +++ b/tools/hc-gen/build_hcs.py @@ -31,6 +31,7 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. +import fcntl import os import sys import argparse @@ -38,6 +39,31 @@ import platform import subprocess import time +_LOCK_FILE_NAME = "._lock" +_BUILD_DIR = 'build' +_LOCK_FILE = '' + + +def lock(): + global _LOCK_FILE + global _BUILD_DIR + global _LOCK_FILE_NAME + if not os.path.exists(_BUILD_DIR): + os.mkdir(_BUILD_DIR) + lock_file = os.path.join(_BUILD_DIR, _LOCK_FILE_NAME) + if not os.path.exists(lock_file): + with open(lock_file, 'w') as l_file: + l_file.write("lock") + l_file.close + print('hc-gen lock file ' + lock_file) + _LOCK_FILE = open(lock_file, 'r') + fcntl.flock(_LOCK_FILE.fileno(), fcntl.LOCK_EX) + + +def unlock(): + global _LOCK_FILE + _LOCK_FILE.close() + def exec_command(cmd): process = subprocess.Popen(cmd) @@ -57,14 +83,20 @@ def prepare(current_dir): def main(argv): + lock() current_dir = os.path.split(os.path.realpath(__file__))[0] hc_gen = os.path.join(current_dir, 'build', 'hc-gen') - build_hcs_cmd = [hc_gen] + argv[1:] + host_hc_gen = argv[1] + if (os.path.exists(host_hc_gen)): + build_hcs_cmd = argv[1:] + else: + prepare(current_dir) + build_hcs_cmd = [hc_gen] + argv[1:] prepare(current_dir) exec_command(build_hcs_cmd) - + unlock() if __name__ == '__main__': sys.exit(main(sys.argv)) -- Gitee From 31e9c564e0026449319961dffb5fc7aa78b7b67c Mon Sep 17 00:00:00 2001 From: crescent Date: Tue, 20 Jul 2021 08:34:41 +0000 Subject: [PATCH 019/205] clean audio codex Signed-off-by: crescent --- model/audio/core/src/audio_core.c | 6 +++--- model/audio/core/src/audio_parse.c | 2 +- model/audio/sapm/src/audio_sapm.c | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/model/audio/core/src/audio_core.c b/model/audio/core/src/audio_core.c index da1d36004..58bb8d14c 100755 --- a/model/audio/core/src/audio_core.c +++ b/model/audio/core/src/audio_core.c @@ -406,7 +406,7 @@ int32_t AudioBindDaiLink(struct AudioCard *audioCard, struct AudioConfigData *co int32_t AudioUpdateCodecRegBits(struct CodecDevice *codec, struct AudioMixerControl *mixerControl, int32_t value) { int32_t ret; - uint32_t curValue; + uint32_t curValue = 0; int32_t mixerControlMask; if (codec == NULL || codec->devData == NULL || codec->devData->Write == NULL || mixerControl == NULL) { ADM_LOG_ERR("Invalid accessory param."); @@ -440,7 +440,7 @@ int32_t AudioUpdateAccessoryRegBits(struct AccessoryDevice *accessory, struct AudioMixerControl *mixerControl, int32_t value) { int32_t ret; - uint32_t curValue; + uint32_t curValue = 0; int32_t mixerControlMask; if (accessory == NULL || accessory->devData == NULL || accessory->devData->Write == NULL || mixerControl == NULL) { @@ -502,7 +502,7 @@ int32_t AudioUpdateRegBits(enum AudioDeviceType deviceType, void *device, int32_t AudioAiaoUpdateRegBits(struct CodecDevice *codec, uint32_t reg, uint32_t mask, uint32_t shift, int32_t value) { int32_t ret; - uint32_t curValue; + uint32_t curValue = 0; ADM_LOG_DEBUG("Entry to update AIAO reg bits."); if (codec == NULL || codec->devData == NULL || codec->devData->AiaoWrite == NULL) { diff --git a/model/audio/core/src/audio_parse.c b/model/audio/core/src/audio_parse.c index 7de9056ef..13a68cfbc 100755 --- a/model/audio/core/src/audio_parse.c +++ b/model/audio/core/src/audio_parse.c @@ -44,7 +44,7 @@ int32_t AudioFillConfigData(struct HdfDeviceObject *device, struct AudioConfigDa if (serviceRet || codecRet || platformRet || cpuRet || codeDaiRet || dspRet || dspDaiRet || accessoryRet || accessoryDaiRet) { ADM_LOG_ERR("Read audioDeviceName fail: serviceRet=%d, codecRet=%d, platformRet=%d, cpuRet=%d, codeDaiRet=%d," - "dspRet=%d, dspDaiRet=%d, accessoryRet=%d, accessoryDaiRet=%s", + "dspRet=%d, dspDaiRet=%d, accessoryRet=%d, accessoryDaiRet=%d", serviceRet, codecRet, platformRet, cpuRet, codeDaiRet, dspRet, dspDaiRet, accessoryRet, accessoryDaiRet); return HDF_FAILURE; diff --git a/model/audio/sapm/src/audio_sapm.c b/model/audio/sapm/src/audio_sapm.c index 19def3b21..26e4ac366 100755 --- a/model/audio/sapm/src/audio_sapm.c +++ b/model/audio/sapm/src/audio_sapm.c @@ -317,9 +317,9 @@ static void MuxSetPathStatus(const struct AudioSapmComponent *cpt, struct AudioS const struct AudioEnumKcontrol *enumKtl, int32_t i) { int32_t ret; - uint32_t val; + uint32_t val = 0; int32_t item; - uint32_t reg; + uint32_t reg = 0; uint32_t shift; if ((cpt == NULL) || (path == NULL) || (enumKtl == NULL)) { @@ -349,7 +349,7 @@ static void MuxValueSetPathStatus(const struct AudioSapmComponent *cpt, struct A const struct AudioEnumKcontrol *enumKtl, int32_t i) { int32_t ret; - uint32_t val; + uint32_t val = 0; uint32_t item; uint32_t reg = 0; uint32_t shift; @@ -389,7 +389,7 @@ static void MixerSetPathStatus(const struct AudioSapmComponent *cpt, struct Audi uint32_t mask; uint32_t shift; uint32_t invert; - uint32_t curValue; + uint32_t curValue = 0; if ((cpt == NULL) || (path == NULL) || (mixerCtrl == NULL)) { ADM_LOG_ERR("input params check error: cpt=%p, path=%p, mixerCtrl=%p.", cpt, path, mixerCtrl); @@ -871,7 +871,7 @@ int32_t AudioSapmPowerComponents(struct AudioCard *audioCard) static void ReadInitComponentPowerStatus(struct AudioSapmComponent *cpt) { int32_t ret; - uint32_t regVal; + uint32_t regVal = 0; if (cpt == NULL) { ADM_LOG_ERR("input param cpt is NULL."); @@ -1068,7 +1068,7 @@ int32_t AudioSapmPutCtrlSwSub(struct AudioKcontrol *kcontrol, struct AudioCtrlEl int32_t ret = HDF_FAILURE; void *device = NULL; enum AudioDeviceType deviceType; - uint32_t curValue; + uint32_t curValue = 0; struct CodecDevice *codec = AudioKcontrolGetCodec(kcontrol); struct AccessoryDevice *accessory = AudioKcontrolGetAccessory(kcontrol); -- Gitee From 63ba05828c5e59caa416322d940aa317d154c8c6 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Wed, 21 Jul 2021 16:18:36 +0800 Subject: [PATCH 020/205] optmize ioservice thread destory work Signed-off-by: yuanbo --- .../adapter/syscall/include/hdf_syscall_adapter.h | 1 + core/adapter/syscall/src/hdf_syscall_adapter.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/adapter/syscall/include/hdf_syscall_adapter.h b/core/adapter/syscall/include/hdf_syscall_adapter.h index cb83b3f98..6ee33c935 100644 --- a/core/adapter/syscall/include/hdf_syscall_adapter.h +++ b/core/adapter/syscall/include/hdf_syscall_adapter.h @@ -22,6 +22,7 @@ enum HdfDevListenerThreadStatus { LISTENER_UNINITED = 0, LISTENER_INITED, LISTENER_EXITED, + LISTENER_STARTED, LISTENER_RUNNING, LISTENER_WAITING, }; diff --git a/core/adapter/syscall/src/hdf_syscall_adapter.c b/core/adapter/syscall/src/hdf_syscall_adapter.c index 8bbdb0126..18fca415e 100644 --- a/core/adapter/syscall/src/hdf_syscall_adapter.c +++ b/core/adapter/syscall/src/hdf_syscall_adapter.c @@ -217,6 +217,7 @@ static int32_t HdfDevEventListenTask(void *para) uint16_t pfdSize = 0; int32_t pollCount = 0; + thread->status = LISTENER_RUNNING; while (!thread->shouldStop) { if (thread->pollChanged) { pollCount = AssignPfds(thread, &pfds, &pfdSize); @@ -322,6 +323,7 @@ static int32_t HdfDevListenerThreadDoInit(struct HdfDevListenerThread *thread) static int32_t HdfDevListenerThreadInit(struct HdfDevListenerThread *thread) { switch (thread->status) { + case LISTENER_STARTED: // fall-through case LISTENER_RUNNING: // fall-through case LISTENER_INITED: // fall-through case LISTENER_WAITING: @@ -410,7 +412,7 @@ static int32_t HdfListenThreadInitPollFds(struct HdfDevListenerThread *thread) static int32_t HdfDevListenerThreadStart(struct HdfDevListenerThread *thread) { - if (thread->status == LISTENER_RUNNING) { + if (thread->status >= LISTENER_STARTED) { return HDF_SUCCESS; } @@ -445,7 +447,7 @@ static int32_t HdfDevListenerThreadStart(struct HdfDevListenerThread *thread) ret = HDF_FAILURE; break; } - thread->status = LISTENER_RUNNING; + thread->status = LISTENER_STARTED; return HDF_SUCCESS; } while (0); @@ -505,7 +507,7 @@ static int32_t HdfListenThreadPollAdd(struct HdfDevListenerThread *thread, struc DListInsertTail(&adapter->listNode, thread->adapterListPtr); - if (thread->status != LISTENER_RUNNING) { + if (thread->status < LISTENER_STARTED) { OsalMutexUnlock(&thread->mutex); return HDF_SUCCESS; } @@ -613,6 +615,9 @@ static void HdfDevListenerThreadDestroy(struct HdfDevListenerThread *thread) return; } + case LISTENER_STARTED: + thread->shouldStop = true; + break; case LISTENER_EXITED: // fall-through case LISTENER_INITED: HdfDevListenerThreadFree(thread); @@ -910,7 +915,7 @@ int32_t HdfIoServiceGroupRegisterListener(struct HdfIoServiceGroup *group, struc } } DListInsertTail(&listener->listNode, &adapterGroup->listenerList); - if (!DListIsEmpty(&adapterGroup->adapterList) && listenerThread->status != LISTENER_RUNNING) { + if (!DListIsEmpty(&adapterGroup->adapterList) && listenerThread->status < LISTENER_STARTED) { ret = HdfDevListenerThreadStart(listenerThread); if (ret != HDF_SUCCESS) { DListRemove(&listener->listNode); @@ -1011,7 +1016,7 @@ int32_t HdfIoServiceGroupAddService(struct HdfIoServiceGroup *group, struct HdfI OsalMutexLock(&listenerThread->mutex); if ((!DListIsEmpty(&adapterGroup->listenerList) || !DListIsEmpty(&adapter->listenerList)) && - listenerThread->status != LISTENER_RUNNING) { + listenerThread->status < LISTENER_STARTED) { ret = HdfDevListenerThreadStart(adapterGroup->thread); if (ret != HDF_SUCCESS) { HdfListenThreadPollDel(adapterGroup->thread, adapter); -- Gitee From 32422e781c571ba723d455555c8eaf104cdc7528 Mon Sep 17 00:00:00 2001 From: jiaziyang Date: Thu, 22 Jul 2021 17:21:32 +0800 Subject: [PATCH 021/205] =?UTF-8?q?=E4=BF=AE=E6=AD=A3rtc=5Fbase.c=E6=97=B6?= =?UTF-8?q?=E9=92=9F=E8=BD=AC=E6=8D=A2=E7=AE=97=E6=B3=95=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=8F=8Artc=5Fbase.h=E5=AD=98=E5=9C=A8=E7=9A=84=E6=97=A0?= =?UTF-8?q?=E6=95=88=E9=80=BB=E8=BE=91=E5=88=A4=E6=96=AD=C2=80=C2=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiaziyang --- support/platform/include/rtc_base.h | 8 ++++---- support/platform/src/rtc_base.c | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/support/platform/include/rtc_base.h b/support/platform/include/rtc_base.h index ebc7b1fb0..d37fc94c1 100644 --- a/support/platform/include/rtc_base.h +++ b/support/platform/include/rtc_base.h @@ -44,10 +44,10 @@ extern "C" { #define IS_INVALID_YEAR(year) ((year) < RTC_BEGIN_YEAR) #define IS_INVALID_MONTH(m) (((m) < RTC_JANUARY) || ((m) > RTC_MAX_MONTH)) #define IS_INVALID_WEEKDAY(wd) (((wd) < 1) || ((wd) > RTC_MAX_WEEKDAY)) -#define IS_INVALID_HOUR(hour) (((hour) < 0) || ((hour) >= RTC_MAX_HOUR)) -#define IS_INVALID_MIN(min) (((min) < 0) || ((min) >= RTC_MAX_MINUTE)) -#define IS_INVALID_SECOND(s) (((s) < 0) || ((s) >= RTC_MAX_SECOND)) -#define IS_INVALID_MS(ms) (((ms) < 0) || ((ms) >= RTC_MAX_MS)) +#define IS_INVALID_HOUR(hour) ((hour) >= RTC_MAX_HOUR) +#define IS_INVALID_MIN(min) ((min) >= RTC_MAX_MINUTE) +#define IS_INVALID_SECOND(s) ((s) >= RTC_MAX_SECOND) +#define IS_INVALID_MS(ms) ((ms) >= RTC_MAX_MS) enum RtcMonth { RTC_JANUARY = 1, diff --git a/support/platform/src/rtc_base.c b/support/platform/src/rtc_base.c index 5e671ac06..82d0039dd 100644 --- a/support/platform/src/rtc_base.c +++ b/support/platform/src/rtc_base.c @@ -95,17 +95,18 @@ uint64_t RtcTimeToTimestamp(const struct RtcTime *time) HDF_LOGE("RtcTimeToTimestamp: time invalid"); return 0; } - + + seconds = ((uint64_t)time->hour * RTC_MAX_MINUTE + time->minute) * RTC_MAX_SECOND + time->second; days = time->day - RTC_UNIT_DIFF; - month = time->month - RTC_UNIT_DIFF; + month = time->month; year = time->year; - while (--month >= 0) { + for(month--; month >= RTC_JANUARY; month--) { days += RtcGetMonthDays(IS_LEAP_YEAR(time->year), month); } - - while (--year >= RTC_BEGIN_YEAR) { + + for(year--; year >= RTC_BEGIN_YEAR; year--) { days += RTC_YEAR_DAYS(year); } @@ -129,7 +130,7 @@ void TimestampToRtcTime(struct RtcTime *time, const uint64_t seconds) time->year++; } - time->month = 0; + time->month = RTC_JANUARY; while (days >= RtcGetMonthDays(IS_LEAP_YEAR(time->year), time->month)) { days -= RtcGetMonthDays(IS_LEAP_YEAR(time->year), time->month); time->month++; @@ -140,7 +141,6 @@ void TimestampToRtcTime(struct RtcTime *time, const uint64_t seconds) time->minute = (daySeconds % RTC_HOUR_SECONDS) / RTC_MAX_MINUTE; time->hour = daySeconds / RTC_HOUR_SECONDS; - time->month += RTC_UNIT_DIFF; time->day += RTC_UNIT_DIFF; time->weekday = RtcGetWeekDay(time); PLAT_LOGV("TimestampToRtc:year-month-day weekday hour:min:second ms %04u-%02u-%02u %u %02u:%02u:%02u .%03u", -- Gitee From 6c5f2730a1279749bce566d88f35e9b3eb8f5f78 Mon Sep 17 00:00:00 2001 From: h00329621 Date: Thu, 22 Jul 2021 19:45:38 +0800 Subject: [PATCH 022/205] modify audio framework Signed-off-by: h00329621 --- model/audio/core/include/audio_control.h | 4 +- model/audio/core/include/audio_core.h | 10 +- model/audio/core/include/audio_host.h | 4 +- model/audio/core/src/audio_core.c | 47 +-- model/audio/core/src/audio_host.c | 18 +- model/audio/device/codec/src/codec.c | 89 ++-- model/audio/device/soc/include/dsp_adapter.h | 6 +- .../dispatch/src/audio_control_dispatch.c | 6 +- .../dispatch/src/audio_stream_dispatch.c | 34 +- model/audio/sapm/include/audio_sapm.h | 4 +- model/audio/sapm/src/audio_sapm.c | 388 +++++++++--------- 11 files changed, 312 insertions(+), 298 deletions(-) diff --git a/model/audio/core/include/audio_control.h b/model/audio/core/include/audio_control.h index dc362462d..fa88b7ead 100755 --- a/model/audio/core/include/audio_control.h +++ b/model/audio/core/include/audio_control.h @@ -41,7 +41,7 @@ struct AudioCtrlElemValue { 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 (*KconfigPut_t)(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +typedef int32_t (*KconfigSet_t)(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); /* mixer control */ struct AudioMixerControl { @@ -61,7 +61,7 @@ struct AudioKcontrol { int32_t iface; KconfigInfo_t Info; KconfigGet_t Get; - KconfigPut_t Put; + KconfigSet_t Set; void *privateData; void *pri; unsigned long privateValue; diff --git a/model/audio/core/include/audio_core.h b/model/audio/core/include/audio_core.h index 601768326..b82439c93 100755 --- a/model/audio/core/include/audio_core.h +++ b/model/audio/core/include/audio_core.h @@ -81,11 +81,11 @@ extern int32_t AudioCodecDeviceReadReg(struct CodecDevice *codec, uint32_t reg, 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); -extern int32_t AudioInfoCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo); -extern int32_t AudioGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); -extern int32_t AudioPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); -extern int32_t AiaoGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); -extern int32_t AiaoPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +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); #ifdef __cplusplus #if __cplusplus diff --git a/model/audio/core/include/audio_host.h b/model/audio/core/include/audio_host.h index 603cbdc2b..405708cfb 100755 --- a/model/audio/core/include/audio_host.h +++ b/model/audio/core/include/audio_host.h @@ -61,7 +61,7 @@ struct AudioConfigData { }; struct AudioCard { - struct AudioPcmRuntime *rtd; + struct AudioRuntimeDeivces *rtd; struct AudioConfigData configData; /* Card-specific routes and components. */ @@ -130,7 +130,7 @@ struct AudioRxData { unsigned long frames; /* frames number */ }; -struct AudioPcmRuntime { +struct AudioRuntimeDeivces { /* runtime devices */ struct CodecDevice *codec; struct PlatformDevice *platform; diff --git a/model/audio/core/src/audio_core.c b/model/audio/core/src/audio_core.c index 58bb8d14c..302f736c2 100755 --- a/model/audio/core/src/audio_core.c +++ b/model/audio/core/src/audio_core.c @@ -104,6 +104,7 @@ int32_t AudioRegisterAccessory(struct HdfDeviceObject *device, struct AccessoryD return HDF_ERR_MALLOC_FAIL; } + OsalMutexInit(&accessory->mutex); accessory->devAccessoryName = data->drvAccessoryName; accessory->devData = data; accessory->device = device; @@ -203,7 +204,7 @@ int32_t AudioSocDeviceRegister(struct HdfDeviceObject *device, void *data, enum return HDF_SUCCESS; } -void AudioSeekPlatformDevice(struct AudioPcmRuntime *rtd, const struct AudioConfigData *configData) +void AudioSeekPlatformDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) { const struct AudioConfigData *data = configData; struct PlatformDevice *platform = NULL; @@ -227,7 +228,7 @@ void AudioSeekPlatformDevice(struct AudioPcmRuntime *rtd, const struct AudioConf return; } -void AudioSeekCpuDaiDevice(struct AudioPcmRuntime *rtd, const struct AudioConfigData *configData) +void AudioSeekCpuDaiDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) { const struct AudioConfigData *data = configData; struct DaiDevice *cpuDai = NULL; @@ -250,7 +251,7 @@ void AudioSeekCpuDaiDevice(struct AudioPcmRuntime *rtd, const struct AudioConfig return; } -void AudioSeekCodecDevice(struct AudioPcmRuntime *rtd, const struct AudioConfigData *configData) +void AudioSeekCodecDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) { const struct AudioConfigData *data = configData; struct CodecDevice *codec = NULL; @@ -283,7 +284,7 @@ void AudioSeekCodecDevice(struct AudioPcmRuntime *rtd, const struct AudioConfigD return; } -void AudioSeekAccessoryDevice(struct AudioPcmRuntime *rtd, const struct AudioConfigData *configData) +void AudioSeekAccessoryDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) { const struct AudioConfigData *data = configData; struct AccessoryDevice *accessory = NULL; @@ -316,7 +317,7 @@ void AudioSeekAccessoryDevice(struct AudioPcmRuntime *rtd, const struct AudioCon return; } -void AudioSeekDspDevice(struct AudioPcmRuntime *rtd, const struct AudioConfigData *configData) +void AudioSeekDspDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData) { const struct AudioConfigData *data = configData; struct DspDevice *dsp = NULL; @@ -357,7 +358,7 @@ int32_t AudioBindDaiLink(struct AudioCard *audioCard, struct AudioConfigData *co return HDF_ERR_INVALID_OBJECT; } - audioCard->rtd = (struct AudioPcmRuntime *)OsalMemCalloc(sizeof(struct AudioPcmRuntime)); + audioCard->rtd = (struct AudioRuntimeDeivces *)OsalMemCalloc(sizeof(struct AudioRuntimeDeivces)); if (audioCard->rtd == NULL) { ADM_LOG_ERR("Malloc audioCard->rtd fail!"); return HDF_ERR_MALLOC_FAIL; @@ -585,7 +586,7 @@ struct AudioKcontrol *AudioAddControl(const struct AudioCard *audioCard, const s control->iface = ctrl->iface; control->Info = ctrl->Info; control->Get = ctrl->Get; - control->Put = ctrl->Put; + control->Set = ctrl->Set; control->pri = (void *)audioCard; control->privateValue = ctrl->privateValue; @@ -661,7 +662,7 @@ int32_t AudioAiaoDeviceReadReg(struct CodecDevice *codec, uint32_t reg, uint32_t return HDF_SUCCESS; } -int32_t AudioInfoCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo) +int32_t AudioInfoCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo) { struct AudioMixerControl *mixerCtrl = NULL; @@ -683,7 +684,7 @@ int32_t AudioInfoCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo return HDF_SUCCESS; } -static int32_t AudioGetCtrlSwSubRReg(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, +static int32_t AudioGetCtrlOpsSubRReg(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, enum AudioDeviceType deviceType, void *device) { int32_t ret = HDF_FAILURE; @@ -722,7 +723,7 @@ static int32_t AudioGetCtrlSwSubRReg(struct AudioKcontrol *kcontrol, struct Audi return HDF_SUCCESS; } -static int32_t AudioGetCtrlSwSubReg(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, +static int32_t AudioGetCtrlOpsSubReg(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, enum AudioDeviceType deviceType, void *device) { int32_t ret = HDF_FAILURE; @@ -753,7 +754,7 @@ static int32_t AudioGetCtrlSwSubReg(struct AudioKcontrol *kcontrol, struct Audio return HDF_SUCCESS; } -int32_t AudioGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +int32_t AudioGetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) { enum AudioDeviceType deviceType; struct CodecDevice *codec = NULL; @@ -769,15 +770,15 @@ int32_t AudioGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue accessory = AudioKcontrolGetAccessory(kcontrol); if (codec != NULL && codec->devData != NULL && codec->devData->Read != NULL) { deviceType = AUDIO_CODEC_DEVICE; - if (AudioGetCtrlSwSubReg(kcontrol, elemValue, deviceType, codec) || - AudioGetCtrlSwSubRReg(kcontrol, elemValue, deviceType, codec)) { + 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 (AudioGetCtrlSwSubReg(kcontrol, elemValue, deviceType, accessory) || - AudioGetCtrlSwSubRReg(kcontrol, elemValue, deviceType, accessory)) { + if (AudioGetCtrlOpsSubReg(kcontrol, elemValue, deviceType, accessory) || + AudioGetCtrlOpsSubRReg(kcontrol, elemValue, deviceType, accessory)) { ADM_LOG_ERR("Audio Accessory Get Ctrl Reg fail."); return HDF_FAILURE; } @@ -787,7 +788,7 @@ int32_t AudioGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue return HDF_SUCCESS; } -static int32_t AiaoGetRightCtrlSw(struct CodecDevice *codec, struct AudioMixerControl *mixerCtrl, +static int32_t AiaoGetRightCtrlOps(struct CodecDevice *codec, struct AudioMixerControl *mixerCtrl, struct AudioCtrlElemValue *elemValue) { int ret; @@ -816,7 +817,7 @@ static int32_t AiaoGetRightCtrlSw(struct CodecDevice *codec, struct AudioMixerCo return HDF_SUCCESS; } -int32_t AiaoGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +int32_t AiaoGetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) { int32_t ret; struct CodecDevice *codec = NULL; @@ -852,7 +853,7 @@ int32_t AiaoGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue } elemValue->value[0] = curValue; - ret = AiaoGetRightCtrlSw(codec, mixerCtrl, elemValue); + ret = AiaoGetRightCtrlOps(codec, mixerCtrl, elemValue); if (ret != HDF_SUCCESS) { ADM_LOG_ERR("AIAO get right ctrl is fail"); return HDF_FAILURE; @@ -862,7 +863,7 @@ int32_t AiaoGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue return HDF_SUCCESS; } -static int32_t AudioPutCtrlSwSub(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, +static int32_t AudioPutCtrlOpsSub(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, enum AudioDeviceType deviceType, void *device) { int32_t value; @@ -913,7 +914,7 @@ static int32_t AudioPutCtrlSwSub(struct AudioKcontrol *kcontrol, struct AudioCtr return HDF_SUCCESS; } -int32_t AudioPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +int32_t AudioSetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) { void *device = NULL; enum AudioDeviceType deviceType; @@ -930,11 +931,11 @@ int32_t AudioPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue if (codec != NULL && codec->devData != NULL && codec->devData->Write != NULL) { deviceType = AUDIO_CODEC_DEVICE; device = (void *)codec; - ret = AudioPutCtrlSwSub(kcontrol, elemValue, deviceType, device); + 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 = AudioPutCtrlSwSub(kcontrol, elemValue, deviceType, device); + ret = AudioPutCtrlOpsSub(kcontrol, elemValue, deviceType, device); } if (ret != HDF_SUCCESS) { @@ -946,7 +947,7 @@ int32_t AudioPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue return HDF_SUCCESS; } -int32_t AiaoPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +int32_t AiaoSetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) { struct CodecDevice *codec = NULL; struct AudioMixerControl *mixerCtrl = NULL; diff --git a/model/audio/core/src/audio_host.c b/model/audio/core/src/audio_host.c index 80015a51c..605a6d7a8 100755 --- a/model/audio/core/src/audio_host.c +++ b/model/audio/core/src/audio_host.c @@ -41,7 +41,7 @@ static int32_t AudioCodecDevInit(struct AudioCard *audioCard) } ADM_LOG_DEBUG("entry."); - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct CodecDevice *codec = NULL; rtd = audioCard->rtd; if (rtd == NULL) { @@ -72,7 +72,7 @@ static int32_t AudioAccessoryDevInit(struct AudioCard *audioCard) } ADM_LOG_DEBUG("entry."); - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct AccessoryDevice *accessory = NULL; rtd = audioCard->rtd; if (rtd == NULL) { @@ -97,11 +97,11 @@ static int32_t AudioAccessoryDevInit(struct AudioCard *audioCard) static int32_t AudioPlatformDevInit(struct AudioCard *audioCard) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; if (audioCard == NULL) { - ADM_LOG_ERR("audioCard is NULL."); + ADM_LOG_ERR("input param is NULL."); return HDF_ERR_IO; } ADM_LOG_DEBUG("entry."); @@ -113,7 +113,7 @@ static int32_t AudioPlatformDevInit(struct AudioCard *audioCard) } platform = rtd->platform; if (platform == NULL || platform->devData == NULL || platform->devData->PlatformInit == NULL) { - ADM_LOG_ERR("platform is NULL."); + ADM_LOG_ERR("audioCard is NULL."); return HDF_ERR_IO; } /* platform initialization */ @@ -129,7 +129,7 @@ static int32_t AudioPlatformDevInit(struct AudioCard *audioCard) static int32_t AudioCodecDaiDevInit(struct AudioCard *audioCard) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct DaiDevice *codecDai = NULL; if (audioCard == NULL) { @@ -161,7 +161,7 @@ static int32_t AudioCodecDaiDevInit(struct AudioCard *audioCard) static int32_t AudioAccessoryDaiDevInit(struct AudioCard *audioCard) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct DaiDevice *accessoryDai = NULL; if (audioCard == NULL) { @@ -193,7 +193,7 @@ static int32_t AudioAccessoryDaiDevInit(struct AudioCard *audioCard) static int32_t AudioCpuDaiDevInit(struct AudioCard *audioCard) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct DaiDevice *cpuDai = NULL; if (audioCard == NULL) { @@ -225,7 +225,7 @@ static int32_t AudioCpuDaiDevInit(struct AudioCard *audioCard) static int32_t AudioDspDaiDevInit(struct AudioCard *audioCard) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct DaiDevice *dspDai = NULL; struct DspDevice *dsp = NULL; int ret; diff --git a/model/audio/device/codec/src/codec.c b/model/audio/device/codec/src/codec.c index 5293eda02..a8f0262b5 100755 --- a/model/audio/device/codec/src/codec.c +++ b/model/audio/device/codec/src/codec.c @@ -125,72 +125,72 @@ static const struct AudioKcontrol g_audioControls[] = { { .iface = AUDIODRV_CTL_ELEM_IFACE_DAC, .name = "Master Playback Volume", - .Info = AudioInfoCtrlSw, - .Get = AiaoGetCtrlSw, - .Put = AiaoPutCtrlSw, + .Info = AudioInfoCtrlOps, + .Get = AiaoGetCtrlOps, + .Set = AiaoSetCtrlOps, .privateValue = (unsigned long)&g_audioRegParams[PLAYBACK_VOLUME], }, { .iface = AUDIODRV_CTL_ELEM_IFACE_ADC, .name = "Master Capture Volume", - .Info = AudioInfoCtrlSw, - .Get = AudioGetCtrlSw, - .Put = AudioPutCtrlSw, + .Info = AudioInfoCtrlOps, + .Get = AudioGetCtrlOps, + .Set = AudioSetCtrlOps, .privateValue = (unsigned long)&g_audioRegParams[CAPTURE_VOLUME], }, { .iface = AUDIODRV_CTL_ELEM_IFACE_DAC, .name = "Playback Mute", - .Info = AudioInfoCtrlSw, - .Get = AudioGetCtrlSw, - .Put = AudioPutCtrlSw, + .Info = AudioInfoCtrlOps, + .Get = AudioGetCtrlOps, + .Set = AudioSetCtrlOps, .privateValue = (unsigned long)&g_audioRegParams[PLAYBACK_MUTE], }, { .iface = AUDIODRV_CTL_ELEM_IFACE_ADC, .name = "Capture Mute", - .Info = AudioInfoCtrlSw, - .Get = AudioGetCtrlSw, - .Put = AudioPutCtrlSw, + .Info = AudioInfoCtrlOps, + .Get = AudioGetCtrlOps, + .Set = AudioSetCtrlOps, .privateValue = (unsigned long)&g_audioRegParams[CAPTURE_MUTE], }, { .iface = AUDIODRV_CTL_ELEM_IFACE_GAIN, .name = "Mic Left Gain", - .Info = AudioInfoCtrlSw, - .Get = AudioGetCtrlSw, - .Put = AudioPutCtrlSw, + .Info = AudioInfoCtrlOps, + .Get = AudioGetCtrlOps, + .Set = AudioSetCtrlOps, .privateValue = (unsigned long)&g_audioRegParams[LEFT_GAIN], }, { .iface = AUDIODRV_CTL_ELEM_IFACE_GAIN, .name = "Mic Right Gain", - .Info = AudioInfoCtrlSw, - .Get = AudioGetCtrlSw, - .Put = AudioPutCtrlSw, + .Info = AudioInfoCtrlOps, + .Get = AudioGetCtrlOps, + .Set = AudioSetCtrlOps, .privateValue = (unsigned long)&g_audioRegParams[RIGHT_GAIN], }, { .iface = AUDIODRV_CTL_ELEM_IFACE_ACODEC, .name = "External Codec Enable", - .Info = AudioInfoCtrlSw, - .Get = AudioGetCtrlSw, - .Put = AudioPutCtrlSw, + .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 = AudioInfoCtrlSw, - .Get = AudioGetCtrlSw, - .Put = AudioPutCtrlSw, + .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 = AudioInfoCtrlSw, - .Get = AiaoGetCtrlSw, - .Put = AiaoPutCtrlSw, + .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 = AudioInfoCtrlSw, - .Get = AiaoGetCtrlSw, - .Put = AiaoPutCtrlSw, + .Info = AudioInfoCtrlOps, + .Get = AiaoGetCtrlOps, + .Set = AiaoSetCtrlOps, .privateValue = (unsigned long)&g_audioRegParams[CAPTRUE_CHANNEL_MODE], }, }; @@ -239,9 +239,9 @@ static struct AudioKcontrol g_audioSapmDACLControls[] = { { .iface = AUDIODRV_CTL_ELEM_IFACE_DAC, .name = "Dacl enable", - .Info = AudioInfoCtrlSw, - .Get = AudioSapmGetCtrlSw, - .Put = AudioSapmPutCtrlSw, + .Info = AudioInfoCtrlOps, + .Get = AudioSapmGetCtrlOps, + .Set = AudioSapmSetCtrlOps, .privateValue = (unsigned long)&g_audioSapmRegParams[DACL2DACR], }, }; @@ -250,9 +250,9 @@ static struct AudioKcontrol g_audioSapmDACRControls[] = { { .iface = AUDIODRV_CTL_ELEM_IFACE_DAC, .name = "Dacr enable", - .Info = AudioInfoCtrlSw, - .Get = AudioSapmGetCtrlSw, - .Put = AudioSapmPutCtrlSw, + .Info = AudioInfoCtrlOps, + .Get = AudioSapmGetCtrlOps, + .Set = AudioSapmSetCtrlOps, .privateValue = (unsigned long)&g_audioSapmRegParams[DACR2DACL], }, }; @@ -261,9 +261,9 @@ static struct AudioKcontrol g_audioSapmLPGAControls[] = { { .iface = AUDIODRV_CTL_ELEM_IFACE_PGA, .name = "LPGA MIC Switch", - .Info = AudioInfoCtrlSw, - .Get = AudioSapmGetCtrlSw, - .Put = AudioSapmPutCtrlSw, + .Info = AudioInfoCtrlOps, + .Get = AudioSapmGetCtrlOps, + .Set = AudioSapmSetCtrlOps, .privateValue = (unsigned long)&g_audioSapmRegParams[LPGA_MIC], }, }; @@ -272,9 +272,9 @@ static struct AudioKcontrol g_audioSapmRPGAControls[] = { { .iface = AUDIODRV_CTL_ELEM_IFACE_PGA, .name = "RPGA MIC Switch", - .Info = AudioInfoCtrlSw, - .Get = AudioSapmGetCtrlSw, - .Put = AudioSapmPutCtrlSw, + .Info = AudioInfoCtrlOps, + .Get = AudioSapmGetCtrlOps, + .Set = AudioSapmSetCtrlOps, .privateValue = (unsigned long)&g_audioSapmRegParams[RPGA_MIC], }, }; @@ -286,7 +286,7 @@ static const struct AudioSapmComponent g_streamDomainComponents[] = { .reg = ACODEC_ANACTRLREG3_ADDR, .mask = 0x1, .shift = 15, - .invert = 0, + .invert = 1, }, { .sapmType = AUDIO_SAPM_ADC, /* ADCR */ .componentName = "ADCR", @@ -373,7 +373,8 @@ static int32_t CodecDeviceInit(struct AudioCard *audioCard, struct CodecDevice * void *device = NULL; AUDIO_DRIVER_LOG_DEBUG("entry."); - if ((audioCard == NULL) || (audioCard->rtd == NULL || audioCard->rtd->codec == NULL) || (codec == NULL)) { + 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; } diff --git a/model/audio/device/soc/include/dsp_adapter.h b/model/audio/device/soc/include/dsp_adapter.h index 9d58ef1ce..b36b39b29 100755 --- a/model/audio/device/soc/include/dsp_adapter.h +++ b/model/audio/device/soc/include/dsp_adapter.h @@ -34,9 +34,9 @@ struct DspData { 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)(struct AudioCard *, void *, struct DspDevice *); - int32_t (*encode)(struct AudioCard *, void *, struct DspDevice *); - int32_t (*Equalizer)(struct AudioCard *, void *, struct DspDevice *); + 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 */ diff --git a/model/audio/dispatch/src/audio_control_dispatch.c b/model/audio/dispatch/src/audio_control_dispatch.c index bc5d5d269..f6879f9ce 100755 --- a/model/audio/dispatch/src/audio_control_dispatch.c +++ b/model/audio/dispatch/src/audio_control_dispatch.c @@ -204,12 +204,12 @@ static int32_t ControlHostElemWrite(struct HdfDeviceIoClient *client, struct Hdf } kctrl = AudioGetKctrlInstance(&elemValue.id); - if (kctrl == NULL || kctrl->Put == NULL) { - ADM_LOG_ERR("Find kctrl or Put fail!"); + if (kctrl == NULL || kctrl->Set == NULL) { + ADM_LOG_ERR("Find kctrl or Set fail!"); return HDF_FAILURE; } - result = kctrl->Put(kctrl, &elemValue); + result = kctrl->Set(kctrl, &elemValue); if (result != HDF_SUCCESS) { ADM_LOG_ERR("Get control value fail result=%d", result); return HDF_FAILURE; diff --git a/model/audio/dispatch/src/audio_stream_dispatch.c b/model/audio/dispatch/src/audio_stream_dispatch.c index 550e84940..d3b176737 100755 --- a/model/audio/dispatch/src/audio_stream_dispatch.c +++ b/model/audio/dispatch/src/audio_stream_dispatch.c @@ -17,7 +17,7 @@ int32_t HwCpuDaiDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams *p return HDF_FAILURE; } - struct AudioPcmRuntime *rtd = audioCard->rtd; + struct AudioRuntimeDeivces *rtd = audioCard->rtd; if (rtd == NULL) { ADM_LOG_ERR("CpuDai audioCard rtd is NULL."); return HDF_FAILURE; @@ -50,7 +50,7 @@ int32_t HwCodecDaiDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams return HDF_FAILURE; } - struct AudioPcmRuntime *rtd = audioCard->rtd; + struct AudioRuntimeDeivces *rtd = audioCard->rtd; if (rtd == NULL) { ADM_LOG_ERR("CodecDai audioCard rtd is NULL."); return HDF_FAILURE; @@ -85,7 +85,7 @@ int32_t HwPlatfromDispatch(struct AudioCard *audioCard, struct AudioPcmHwParams return HDF_FAILURE; } - struct AudioPcmRuntime *rtd = audioCard->rtd; + struct AudioRuntimeDeivces *rtd = audioCard->rtd; if (rtd == NULL) { ADM_LOG_ERR("audioCard rtd is NULL."); return HDF_FAILURE; @@ -290,7 +290,7 @@ static struct AudioCard *StreamHostGetCardInstance(const struct HdfDeviceIoClien int32_t StreamHostCapturePrepare(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; struct AudioCard *audioCard = NULL; int ret; @@ -330,7 +330,7 @@ int32_t StreamHostCapturePrepare(struct HdfDeviceIoClient *client, struct HdfSBu int32_t StreamHostRenderPrepare(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; struct AudioCard *audioCard = NULL; int ret; @@ -438,7 +438,7 @@ int32_t StreamHostWrite(struct HdfDeviceIoClient *client, struct HdfSBuf *data, int32_t StreamHostRead(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; struct AudioCard *audioCard = NULL; struct AudioRxData rxData; @@ -492,7 +492,7 @@ int32_t StreamHostRead(struct HdfDeviceIoClient *client, struct HdfSBuf *data, s int32_t StreamHostRenderStart(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; struct AudioCard *audioCard = NULL; int ret; @@ -532,7 +532,7 @@ int32_t StreamHostRenderStart(struct HdfDeviceIoClient *client, struct HdfSBuf * int32_t StreamHostCaptureStart(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; struct AudioCard *audioCard = NULL; int ret; @@ -572,7 +572,7 @@ int32_t StreamHostCaptureStart(struct HdfDeviceIoClient *client, struct HdfSBuf int32_t StreamHostRenderStop(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; struct AudioCard *audioCard = NULL; int ret; @@ -612,7 +612,7 @@ int32_t StreamHostRenderStop(struct HdfDeviceIoClient *client, struct HdfSBuf *d int32_t StreamHostCaptureStop(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; struct AudioCard *audioCard = NULL; int ret; @@ -652,7 +652,7 @@ int32_t StreamHostCaptureStop(struct HdfDeviceIoClient *client, struct HdfSBuf * int32_t StreamHostRenderPause(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; struct AudioCard *audioCard = NULL; int ret; @@ -692,7 +692,7 @@ int32_t StreamHostRenderPause(struct HdfDeviceIoClient *client, struct HdfSBuf * int32_t StreamHostCapturePause(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; struct AudioCard *audioCard = NULL; int ret; @@ -732,7 +732,7 @@ int32_t StreamHostCapturePause(struct HdfDeviceIoClient *client, struct HdfSBuf int32_t StreamHostRenderResume(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; struct AudioCard *audioCard = NULL; int ret; @@ -772,7 +772,7 @@ int32_t StreamHostRenderResume(struct HdfDeviceIoClient *client, struct HdfSBuf int32_t StreamHostCaptureResume(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct PlatformDevice *platform = NULL; struct AudioCard *audioCard = NULL; int ret; @@ -812,7 +812,7 @@ int32_t StreamHostCaptureResume(struct HdfDeviceIoClient *client, struct HdfSBuf int32_t StreamHostDspDecode(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct DspDevice *dspDev = NULL; struct AudioCard *audioCard = NULL; int ret; @@ -850,7 +850,7 @@ int32_t StreamHostDspDecode(struct HdfDeviceIoClient *client, struct HdfSBuf *da int32_t StreamHostDspEncode(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct DspDevice *dspDev = NULL; struct AudioCard *audioCard = NULL; int ret; @@ -888,7 +888,7 @@ int32_t StreamHostDspEncode(struct HdfDeviceIoClient *client, struct HdfSBuf *da int32_t StreamHostDspEqualizer(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - struct AudioPcmRuntime *rtd = NULL; + struct AudioRuntimeDeivces *rtd = NULL; struct DspDevice *dspDev = NULL; struct AudioCard *audioCard = NULL; int ret; diff --git a/model/audio/sapm/include/audio_sapm.h b/model/audio/sapm/include/audio_sapm.h index c7a452206..700a1211f 100755 --- a/model/audio/sapm/include/audio_sapm.h +++ b/model/audio/sapm/include/audio_sapm.h @@ -204,8 +204,8 @@ int32_t AudioSapmNewControls(struct AudioCard *audioCard); int32_t AudioSapmPowerComponents(struct AudioCard *audioCard); u64 AudioSapmRefreshTime(bool bRefresh); -extern int32_t AudioSapmPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); -extern int32_t AudioSapmGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +extern int32_t AudioSapmGetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue); +extern int32_t AudioSapmSetCtrlOps(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 26e4ac366..33f7bb9f5 100755 --- a/model/audio/sapm/src/audio_sapm.c +++ b/model/audio/sapm/src/audio_sapm.c @@ -63,18 +63,18 @@ static int32_t g_audioSapmIsSleep = 0; static int32_t g_audioSapmIsStandby = 0; OSAL_DECLARE_TIMER(g_sleepTimer); -static int32_t ConnectedInputEndPoint(const struct AudioSapmComponent *cpt) +static int32_t ConnectedInputEndPoint(const struct AudioSapmComponent *sapmComponent) { struct AudioSapmpath *path = NULL; int32_t count = 0; int32_t endPointVal = 1; - if (cpt == NULL) { - ADM_LOG_ERR("input param cpt is NULL."); + if (sapmComponent == NULL) { + ADM_LOG_ERR("input param sapmComponent is NULL."); return HDF_FAILURE; } - switch (cpt->sapmType) { + switch (sapmComponent->sapmType) { case AUDIO_SAPM_DAC: case AUDIO_SAPM_AIF_IN: case AUDIO_SAPM_INPUT: @@ -85,7 +85,7 @@ static int32_t ConnectedInputEndPoint(const struct AudioSapmComponent *cpt) break; } - DLIST_FOR_EACH_ENTRY(path, &cpt->sources, struct AudioSapmpath, listSink) { + DLIST_FOR_EACH_ENTRY(path, &sapmComponent->sources, struct AudioSapmpath, listSink) { if ((path->source != NULL) && (path->connect == CONNECT_SINK_AND_SOURCE)) { count += ConnectedInputEndPoint(path->source); } @@ -93,18 +93,18 @@ static int32_t ConnectedInputEndPoint(const struct AudioSapmComponent *cpt) return count; } -static int32_t ConnectedOutputEndPoint(const struct AudioSapmComponent *cpt) +static int32_t ConnectedOutputEndPoint(const struct AudioSapmComponent *sapmComponent) { struct AudioSapmpath *path = NULL; int32_t count = 0; int32_t endPointVal = 1; - if (cpt == NULL) { - ADM_LOG_ERR("input param cpt is NULL."); + if (sapmComponent == NULL) { + ADM_LOG_ERR("input param sapmComponent is NULL."); return HDF_FAILURE; } - switch (cpt->sapmType) { + switch (sapmComponent->sapmType) { case AUDIO_SAPM_ADC: case AUDIO_SAPM_AIF_OUT: case AUDIO_SAPM_OUTPUT: @@ -116,7 +116,7 @@ static int32_t ConnectedOutputEndPoint(const struct AudioSapmComponent *cpt) break; } - DLIST_FOR_EACH_ENTRY(path, &cpt->sinks, struct AudioSapmpath, listSource) { + DLIST_FOR_EACH_ENTRY(path, &sapmComponent->sinks, struct AudioSapmpath, listSource) { if ((path->sink != NULL) && (path->connect == CONNECT_SINK_AND_SOURCE)) { count += ConnectedOutputEndPoint(path->sink); } @@ -124,22 +124,22 @@ static int32_t ConnectedOutputEndPoint(const struct AudioSapmComponent *cpt) return count; } -static int32_t AudioSapmGenericCheckPower(const struct AudioSapmComponent *cpt) +static int32_t AudioSapmGenericCheckPower(const struct AudioSapmComponent *sapmComponent) { int32_t input; int32_t output; - if (cpt == NULL) { + if (sapmComponent == NULL) { ADM_LOG_ERR("input param cpt is NULL."); return HDF_FAILURE; } - input = ConnectedInputEndPoint(cpt); + input = ConnectedInputEndPoint(sapmComponent); if (input == HDF_FAILURE) { ADM_LOG_ERR("input endpoint fail!"); return HDF_FAILURE; } - output = ConnectedOutputEndPoint(cpt); + output = ConnectedOutputEndPoint(sapmComponent); if (output == HDF_FAILURE) { ADM_LOG_ERR("output endpoint fail!"); return HDF_FAILURE; @@ -152,19 +152,19 @@ static int32_t AudioSapmGenericCheckPower(const struct AudioSapmComponent *cpt) return SAPM_POWER_UP; } -static int32_t AudioSapmAdcCheckPower(const struct AudioSapmComponent *cpt) +static int32_t AudioSapmAdcCheckPower(const struct AudioSapmComponent *sapmComponent) { int32_t input; - if (cpt == NULL) { - ADM_LOG_ERR("input param cpt is NULL."); + if (sapmComponent == NULL) { + ADM_LOG_ERR("input param sapmComponent is NULL."); return HDF_FAILURE; } - if (cpt->active == 0) { - input = AudioSapmGenericCheckPower(cpt); + if (sapmComponent->active == 0) { + input = AudioSapmGenericCheckPower(sapmComponent); } else { - input = ConnectedInputEndPoint(cpt); + input = ConnectedInputEndPoint(sapmComponent); } if (input == HDF_FAILURE) { ADM_LOG_ERR("input endpoint fail!"); @@ -173,19 +173,19 @@ static int32_t AudioSapmAdcCheckPower(const struct AudioSapmComponent *cpt) return input; } -static int AudioSapmDacCheckPower(const struct AudioSapmComponent *cpt) +static int AudioSapmDacCheckPower(const struct AudioSapmComponent *sapmComponent) { int32_t output; - if (cpt == NULL) { - ADM_LOG_ERR("input param cpt is NULL."); + if (sapmComponent == NULL) { + ADM_LOG_ERR("input sapmComponent cpt is NULL."); return HDF_FAILURE; } - if (cpt->active == 0) { - output = AudioSapmGenericCheckPower(cpt); + if (sapmComponent->active == 0) { + output = AudioSapmGenericCheckPower(sapmComponent); } else { - output = ConnectedOutputEndPoint(cpt); + output = ConnectedOutputEndPoint(sapmComponent); } if (output == HDF_FAILURE) { ADM_LOG_ERR("output endpoint fail!"); @@ -194,31 +194,31 @@ static int AudioSapmDacCheckPower(const struct AudioSapmComponent *cpt) return output; } -static void AudioSampCheckPowerCallback(struct AudioSapmComponent *cpt) +static void AudioSampCheckPowerCallback(struct AudioSapmComponent *sapmComponent) { - if (cpt == NULL) { + if (sapmComponent == NULL) { ADM_LOG_ERR("input param cpt is NULL."); return; } - switch (cpt->sapmType) { + switch (sapmComponent->sapmType) { case AUDIO_SAPM_ANALOG_SWITCH: case AUDIO_SAPM_MIXER: case AUDIO_SAPM_MIXER_NAMED_CTRL: - cpt->PowerCheck = AudioSapmGenericCheckPower; + sapmComponent->PowerCheck = AudioSapmGenericCheckPower; break; case AUDIO_SAPM_MUX: case AUDIO_SAPM_VIRT_MUX: case AUDIO_SAPM_VALUE_MUX: - cpt->PowerCheck = AudioSapmGenericCheckPower; + sapmComponent->PowerCheck = AudioSapmGenericCheckPower; break; case AUDIO_SAPM_ADC: case AUDIO_SAPM_AIF_OUT: - cpt->PowerCheck = AudioSapmAdcCheckPower; + sapmComponent->PowerCheck = AudioSapmAdcCheckPower; break; case AUDIO_SAPM_DAC: case AUDIO_SAPM_AIF_IN: - cpt->PowerCheck = AudioSapmDacCheckPower; + sapmComponent->PowerCheck = AudioSapmDacCheckPower; break; case AUDIO_SAPM_PGA: case AUDIO_SAPM_OUT_DRV: @@ -229,10 +229,10 @@ static void AudioSampCheckPowerCallback(struct AudioSapmComponent *cpt) case AUDIO_SAPM_HP: case AUDIO_SAPM_MIC: case AUDIO_SAPM_LINE: - cpt->PowerCheck = AudioSapmGenericCheckPower; + sapmComponent->PowerCheck = AudioSapmGenericCheckPower; break; default: - cpt->PowerCheck = AudioSapmGenericCheckPower; + sapmComponent->PowerCheck = AudioSapmGenericCheckPower; break; } @@ -241,51 +241,52 @@ static void AudioSampCheckPowerCallback(struct AudioSapmComponent *cpt) int32_t AudioSapmNewComponent(struct AudioCard *audioCard, const struct AudioSapmComponent *component) { - struct AudioSapmComponent *cpt = NULL; + struct AudioSapmComponent *sapmComponent = NULL; if ((audioCard == NULL) || (component == NULL)) { ADM_LOG_ERR("input params check error: audioCard=%p, component=%p.", audioCard, component); return HDF_FAILURE; } - cpt = (struct AudioSapmComponent *)OsalMemCalloc(sizeof(struct AudioSapmComponent)); - if (cpt == NULL) { + sapmComponent = (struct AudioSapmComponent *)OsalMemCalloc(sizeof(struct AudioSapmComponent)); + if (sapmComponent == NULL) { ADM_LOG_ERR("malloc cpt fail!"); return HDF_FAILURE; } - if (memcpy_s(cpt, sizeof(struct AudioSapmComponent), component, sizeof(struct AudioSapmComponent)) != EOK) { + if (memcpy_s(sapmComponent, sizeof(struct AudioSapmComponent), + component, sizeof(struct AudioSapmComponent)) != EOK) { ADM_LOG_ERR("memcpy cpt fail!"); - OsalMemFree(cpt); + OsalMemFree(sapmComponent); return HDF_FAILURE; } - cpt->componentName = (char *)OsalMemCalloc(strlen(component->componentName) + 1); - if (cpt->componentName == NULL) { + sapmComponent->componentName = (char *)OsalMemCalloc(strlen(component->componentName) + 1); + if (sapmComponent->componentName == NULL) { ADM_LOG_ERR("malloc cpt->componentName fail!"); - OsalMemFree(cpt); + OsalMemFree(sapmComponent); return HDF_FAILURE; } - if (memcpy_s(cpt->componentName, strlen(component->componentName) + 1, + if (memcpy_s(sapmComponent->componentName, strlen(component->componentName) + 1, component->componentName, strlen(component->componentName) + 1) != EOK) { ADM_LOG_ERR("memcpy cpt->componentName fail!"); - OsalMemFree(cpt->componentName); - OsalMemFree(cpt); + OsalMemFree(sapmComponent->componentName); + OsalMemFree(sapmComponent); return HDF_FAILURE; } - cpt->codec = audioCard->rtd->codec; - cpt->kcontrolsNum = component->kcontrolsNum; - cpt->active = 0; - AudioSampCheckPowerCallback(cpt); - cpt->PowerClockOp = NULL; + sapmComponent->codec = audioCard->rtd->codec; + sapmComponent->kcontrolsNum = component->kcontrolsNum; + sapmComponent->active = 0; + AudioSampCheckPowerCallback(sapmComponent); + sapmComponent->PowerClockOp = NULL; - DListHeadInit(&cpt->sources); - DListHeadInit(&cpt->sinks); - DListHeadInit(&cpt->list); - DListHeadInit(&cpt->dirty); - DListInsertHead(&cpt->list, &audioCard->components); + DListHeadInit(&sapmComponent->sources); + DListHeadInit(&sapmComponent->sinks); + DListHeadInit(&sapmComponent->list); + DListHeadInit(&sapmComponent->dirty); + DListInsertHead(&sapmComponent->list, &audioCard->components); - cpt->connected = CONNECT_CODEC_PIN; + sapmComponent->connected = CONNECT_CODEC_PIN; return HDF_SUCCESS; } @@ -313,7 +314,7 @@ int32_t AudioSapmNewComponents(struct AudioCard *audioCard, return HDF_SUCCESS; } -static void MuxSetPathStatus(const struct AudioSapmComponent *cpt, struct AudioSapmpath *path, +static void MuxSetPathStatus(const struct AudioSapmComponent *sapmComponent, struct AudioSapmpath *path, const struct AudioEnumKcontrol *enumKtl, int32_t i) { int32_t ret; @@ -322,13 +323,14 @@ static void MuxSetPathStatus(const struct AudioSapmComponent *cpt, struct AudioS uint32_t reg = 0; uint32_t shift; - if ((cpt == NULL) || (path == NULL) || (enumKtl == NULL)) { - ADM_LOG_ERR("input MuxSet params check error: cpt=%p, path=%p, enumKtl=%p.", cpt, path, enumKtl); + if ((sapmComponent == NULL) || (path == NULL) || (enumKtl == NULL)) { + ADM_LOG_ERR("input MuxSet params check error: sapmComponent=%p, path=%p, enumKtl=%p.", + sapmComponent, path, enumKtl); return; } shift = enumKtl->shiftLeft; - ret = AudioCodecDeviceReadReg(cpt->codec, reg, &val); + ret = AudioCodecDeviceReadReg(sapmComponent->codec, reg, &val); if (ret != HDF_SUCCESS) { ADM_LOG_ERR("MuxSet read reg fail!"); return; @@ -345,7 +347,7 @@ static void MuxSetPathStatus(const struct AudioSapmComponent *cpt, struct AudioS return; } -static void MuxValueSetPathStatus(const struct AudioSapmComponent *cpt, struct AudioSapmpath *path, +static void MuxValueSetPathStatus(const struct AudioSapmComponent *sapmComponent, struct AudioSapmpath *path, const struct AudioEnumKcontrol *enumKtl, int32_t i) { int32_t ret; @@ -353,14 +355,15 @@ static void MuxValueSetPathStatus(const struct AudioSapmComponent *cpt, struct A uint32_t item; uint32_t reg = 0; uint32_t shift; - if ((cpt == NULL) || (path == NULL) || (enumKtl == NULL)) { - ADM_LOG_ERR("input muxValueSet params check error: cpt=%p, path=%p, enumKtl=%p.", cpt, path, enumKtl); + if ((sapmComponent == NULL) || (path == NULL) || (enumKtl == NULL)) { + ADM_LOG_ERR("input muxValueSet params check error: cpt=%p, path=%p, enumKtl=%p.", + sapmComponent, path, enumKtl); return; } shift = enumKtl->shiftLeft; - ret = AudioCodecDeviceReadReg(cpt->codec, reg, &val); + ret = AudioCodecDeviceReadReg(sapmComponent->codec, reg, &val); if (ret != HDF_SUCCESS) { ADM_LOG_ERR("muxValueSet read reg fail!"); return; @@ -381,7 +384,7 @@ static void MuxValueSetPathStatus(const struct AudioSapmComponent *cpt, struct A return; } -static void MixerSetPathStatus(const struct AudioSapmComponent *cpt, struct AudioSapmpath *path, +static void MixerSetPathStatus(const struct AudioSapmComponent *sapmComponent, struct AudioSapmpath *path, const struct AudioMixerControl *mixerCtrl) { int32_t ret; @@ -391,8 +394,9 @@ static void MixerSetPathStatus(const struct AudioSapmComponent *cpt, struct Audi uint32_t invert; uint32_t curValue = 0; - if ((cpt == NULL) || (path == NULL) || (mixerCtrl == NULL)) { - ADM_LOG_ERR("input params check error: cpt=%p, path=%p, mixerCtrl=%p.", cpt, path, mixerCtrl); + if ((sapmComponent == NULL) || (path == NULL) || (mixerCtrl == NULL)) { + ADM_LOG_ERR("input params check error: sapmComponent=%p, path=%p, mixerCtrl=%p.", + sapmComponent, path, mixerCtrl); return; } @@ -401,7 +405,7 @@ static void MixerSetPathStatus(const struct AudioSapmComponent *cpt, struct Audi mask = mixerCtrl->mask; invert = mixerCtrl->invert; - ret = AudioCodecDeviceReadReg(cpt->codec, reg, &curValue); + ret = AudioCodecDeviceReadReg(sapmComponent->codec, reg, &curValue); if (ret != HDF_SUCCESS) { ADM_LOG_ERR("read reg fail!"); return; @@ -417,25 +421,28 @@ static void MixerSetPathStatus(const struct AudioSapmComponent *cpt, struct Audi return; } -static int32_t AudioSapmSetPathStatus(struct AudioSapmComponent *cpt, struct AudioSapmpath *path, int32_t i) +static int32_t AudioSapmSetPathStatus(struct AudioSapmComponent *sapmComponent, struct AudioSapmpath *path, int32_t i) { - if ((cpt == NULL) || (path == NULL)) { - ADM_LOG_ERR("input params check error: cpt=%p, path=%p.", cpt, path); + if ((sapmComponent == NULL) || (path == NULL)) { + ADM_LOG_ERR("input params check error: sapmComponent=%p, path=%p.", sapmComponent, path); return HDF_FAILURE; } - switch (cpt->sapmType) { + switch (sapmComponent->sapmType) { case AUDIO_SAPM_MIXER: case AUDIO_SAPM_ANALOG_SWITCH: case AUDIO_SAPM_MIXER_NAMED_CTRL: { - MixerSetPathStatus(cpt, path, (struct AudioMixerControl *)cpt->kcontrolNews[i].privateValue); + MixerSetPathStatus(sapmComponent, path, + (struct AudioMixerControl *)sapmComponent->kcontrolNews[i].privateValue); } break; case AUDIO_SAPM_MUX: { - MuxSetPathStatus(cpt, path, (struct AudioEnumKcontrol *)cpt->kcontrolNews[i].privateValue, i); + MuxSetPathStatus(sapmComponent, path, + (struct AudioEnumKcontrol *)sapmComponent->kcontrolNews[i].privateValue, i); } break; case AUDIO_SAPM_VALUE_MUX: { - MuxValueSetPathStatus(cpt, path, (struct AudioEnumKcontrol *)cpt->kcontrolNews[i].privateValue, i); + MuxValueSetPathStatus(sapmComponent, path, + (struct AudioEnumKcontrol *)sapmComponent->kcontrolNews[i].privateValue, i); } break; default: { @@ -453,7 +460,8 @@ static int32_t AudioSapmConnectMixer(struct AudioCard *audioCard, { int i; - if ((audioCard == NULL) || (source == NULL) || (sink == NULL) || (path == NULL) || (controlName == NULL)) { + if ((audioCard == NULL) || (source == NULL) || (sink == NULL) || + (path == NULL) || (controlName == NULL)) { ADM_LOG_ERR("input params check error: audioCard=%p, source=%p, sink=%p, path=%p, controlName=%p.", audioCard, source, sink, path, controlName); return HDF_FAILURE; @@ -566,7 +574,7 @@ static int32_t AudioSapmAddRoute(struct AudioCard *audioCard, const struct Audio struct AudioSapmpath *path = NULL; struct AudioSapmComponent *cptSource = NULL; struct AudioSapmComponent *cptSink = NULL; - struct AudioSapmComponent *cpt = NULL; + struct AudioSapmComponent *sapmComponent = NULL; int32_t ret; if ((audioCard == NULL) || (route == NULL)) { @@ -574,13 +582,13 @@ static int32_t AudioSapmAddRoute(struct AudioCard *audioCard, const struct Audio return HDF_FAILURE; } - DLIST_FOR_EACH_ENTRY(cpt, &audioCard->components, struct AudioSapmComponent, list) { - if ((cptSource == NULL) && (strcmp(cpt->componentName, route->source) == 0)) { - cptSource = cpt; + DLIST_FOR_EACH_ENTRY(sapmComponent, &audioCard->components, struct AudioSapmComponent, list) { + if ((cptSource == NULL) && (strcmp(sapmComponent->componentName, route->source) == 0)) { + cptSource = sapmComponent; continue; } - if ((cptSink == NULL) && (strcmp(cpt->componentName, route->sink) == 0)) { - cptSink = cpt; + if ((cptSink == NULL) && (strcmp(sapmComponent->componentName, route->sink) == 0)) { + cptSink = sapmComponent; } if ((cptSource != NULL) && (cptSink != NULL)) { break; @@ -635,67 +643,67 @@ int32_t AudioSapmAddRoutes(struct AudioCard *audioCard, const struct AudioSapmRo return HDF_SUCCESS; } -int32_t AudioSapmNewMixerControls(struct AudioSapmComponent *cpt, struct AudioCard *audioCard) +int32_t AudioSapmNewMixerControls(struct AudioSapmComponent *sapmComponent, struct AudioCard *audioCard) { struct AudioSapmpath *path = NULL; int32_t i; - if ((cpt == NULL) || (audioCard == NULL)) { - ADM_LOG_ERR("input params check error: cpt=%p, audioCard=%p.", cpt, audioCard); + 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 < cpt->kcontrolsNum; i++) { - DLIST_FOR_EACH_ENTRY(path, &cpt->sources, struct AudioSapmpath, listSink) { - if (strcmp(path->name, cpt->kcontrolNews[i].name) != 0) { + for (i = 0; i < sapmComponent->kcontrolsNum; i++) { + DLIST_FOR_EACH_ENTRY(path, &sapmComponent->sources, struct AudioSapmpath, listSink) { + if (strcmp(path->name, sapmComponent->kcontrolNews[i].name) != 0) { continue; } - path->kcontrol = AudioAddControl(audioCard, &cpt->kcontrolNews[i]); + path->kcontrol = AudioAddControl(audioCard, &sapmComponent->kcontrolNews[i]); if (path->kcontrol == NULL) { ADM_LOG_ERR("add control fail!"); return HDF_FAILURE; } - cpt->kcontrols[i] = path->kcontrol; - DListInsertHead(&cpt->kcontrols[i]->list, &audioCard->controls); + sapmComponent->kcontrols[i] = path->kcontrol; + DListInsertHead(&sapmComponent->kcontrols[i]->list, &audioCard->controls); } } return HDF_SUCCESS; } -int AudioSapmNewMuxControls(struct AudioSapmComponent *cpt, struct AudioCard *audioCard) +int AudioSapmNewMuxControls(struct AudioSapmComponent *sapmComponent, struct AudioCard *audioCard) { struct AudioKcontrol *kctrl = NULL; - if (cpt == NULL) { - ADM_LOG_ERR("input param cpt is NULL."); + if (sapmComponent == NULL) { + ADM_LOG_ERR("input param sapmComponent is NULL."); return HDF_FAILURE; } - if (cpt->kcontrolsNum != 1) { + if (sapmComponent->kcontrolsNum != 1) { ADM_LOG_ERR("incorrect number of controls."); return HDF_FAILURE; } - kctrl = AudioAddControl(audioCard, &cpt->kcontrolNews[0]); + kctrl = AudioAddControl(audioCard, &sapmComponent->kcontrolNews[0]); if (kctrl == NULL) { ADM_LOG_ERR("add control fail!"); return HDF_FAILURE; } - cpt->kcontrols[0] = kctrl; - DListInsertHead(&cpt->kcontrols[0]->list, &audioCard->controls); + sapmComponent->kcontrols[0] = kctrl; + DListInsertHead(&sapmComponent->kcontrols[0]->list, &audioCard->controls); return HDF_SUCCESS; } -static void AudioSapmPowerSeqInsert(struct AudioSapmComponent *newCpt, +static void AudioSapmPowerSeqInsert(struct AudioSapmComponent *newSapmComponent, struct DListHead *list, int8_t isPowerUp) { - struct AudioSapmComponent *cpt = NULL; + struct AudioSapmComponent *sapmComponent = NULL; int32_t *seq = {0}; - if (newCpt == NULL) { + if (newSapmComponent == NULL) { ADM_LOG_ERR("input param newCpt is NULL."); return; } @@ -706,29 +714,29 @@ static void AudioSapmPowerSeqInsert(struct AudioSapmComponent *newCpt, seq = g_audioSapmPowerDownSeq; } - DLIST_FOR_EACH_ENTRY(cpt, list, struct AudioSapmComponent, powerList) { - if ((seq[newCpt->sapmType] - seq[cpt->sapmType]) < 0) { - DListInsertTail(&newCpt->powerList, &cpt->powerList); + DLIST_FOR_EACH_ENTRY(sapmComponent, list, struct AudioSapmComponent, powerList) { + if ((seq[newSapmComponent->sapmType] - seq[sapmComponent->sapmType]) < 0) { + DListInsertTail(&newSapmComponent->powerList, &sapmComponent->powerList); return; } } - DListInsertTail(&newCpt->powerList, list); + DListInsertTail(&newSapmComponent->powerList, list); - ADM_LOG_DEBUG("[%s] success.", newCpt->componentName); + ADM_LOG_DEBUG("[%s] success.", newSapmComponent->componentName); return; } -static void AudioSapmSetPower(struct AudioCard *audioCard, struct AudioSapmComponent *cpt, +static void AudioSapmSetPower(struct AudioCard *audioCard, struct AudioSapmComponent *sapmComponent, uint8_t power, struct DListHead *upList, struct DListHead *downList) { struct AudioSapmpath *path = NULL; - if (cpt == NULL) { - ADM_LOG_ERR("input param cpt is NULL."); + if (sapmComponent == NULL) { + ADM_LOG_ERR("input param sapmComponent is NULL."); return; } - DLIST_FOR_EACH_ENTRY(path, &cpt->sources, struct AudioSapmpath, listSink) { + DLIST_FOR_EACH_ENTRY(path, &sapmComponent->sources, struct AudioSapmpath, listSink) { if (path->source != NULL) { if ((path->source->power != power) && path->connect) { if (DListIsEmpty(&path->source->dirty)) { @@ -737,7 +745,7 @@ static void AudioSapmSetPower(struct AudioCard *audioCard, struct AudioSapmCompo } } } - DLIST_FOR_EACH_ENTRY(path, &cpt->sinks, struct AudioSapmpath, listSource) { + DLIST_FOR_EACH_ENTRY(path, &sapmComponent->sinks, struct AudioSapmpath, listSource) { if (path->sink != NULL) { if ((path->sink->power != power) && path->connect) { if (DListIsEmpty(&path->sink->dirty)) { @@ -748,12 +756,12 @@ static void AudioSapmSetPower(struct AudioCard *audioCard, struct AudioSapmCompo } if (power) { - AudioSapmPowerSeqInsert(cpt, upList, power); + AudioSapmPowerSeqInsert(sapmComponent, upList, power); } else { - AudioSapmPowerSeqInsert(cpt, downList, power); + AudioSapmPowerSeqInsert(sapmComponent, downList, power); } - cpt->power = power; + sapmComponent->power = power; return; } @@ -762,7 +770,7 @@ static void AudioSapmPowerUpSeqRun(struct DListHead *list) enum AudioDeviceType deviceType; struct AudioMixerControl mixerControl; void *device = NULL; - struct AudioSapmComponent *cpt = NULL; + struct AudioSapmComponent *sapmComponent = NULL; int32_t ret; if (list == NULL) { @@ -770,18 +778,18 @@ static void AudioSapmPowerUpSeqRun(struct DListHead *list) return; } - DLIST_FOR_EACH_ENTRY(cpt, list, struct AudioSapmComponent, powerList) { - if ((cpt->reg >= 0) && (cpt->power == SAPM_POWER_DOWN)) { - cpt->power = SAPM_POWER_UP; - mixerControl.reg = cpt->reg; - mixerControl.mask = cpt->mask; - mixerControl.shift = cpt->shift; - if (cpt->codec != NULL && cpt->codec->devData != NULL) { + DLIST_FOR_EACH_ENTRY(sapmComponent, list, struct AudioSapmComponent, powerList) { + if ((sapmComponent->reg >= 0) && (sapmComponent->power == SAPM_POWER_DOWN)) { + 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 = cpt->codec; + device = sapmComponent->codec; } else { deviceType = AUDIO_ACCESSORY_DEVICE; - device = cpt->accessory; + device = sapmComponent->accessory; } ret = AudioUpdateRegBits(deviceType, device, &mixerControl, SAPM_POWER_UP); if (ret != HDF_SUCCESS) { @@ -798,7 +806,7 @@ static void AudioSapmPowerDownSeqRun(struct DListHead *list) void *device = NULL; enum AudioDeviceType deviceType; struct AudioMixerControl mixerControl; - struct AudioSapmComponent *cpt = NULL; + struct AudioSapmComponent *sapmComponent = NULL; int32_t ret; if (list == NULL) { @@ -806,18 +814,18 @@ static void AudioSapmPowerDownSeqRun(struct DListHead *list) return; } - DLIST_FOR_EACH_ENTRY(cpt, list, struct AudioSapmComponent, powerList) { - if ((cpt->reg >= 0) && (cpt->power == SAPM_POWER_UP)) { - cpt->power = SAPM_POWER_DOWN; - mixerControl.mask = cpt->mask; - mixerControl.reg = cpt->reg; - mixerControl.shift = cpt->shift; - if (cpt->codec != NULL && cpt->codec->devData != NULL) { + DLIST_FOR_EACH_ENTRY(sapmComponent, list, struct AudioSapmComponent, powerList) { + if ((sapmComponent->reg >= 0) && (sapmComponent->power == SAPM_POWER_UP)) { + 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 = cpt->codec; + device = sapmComponent->codec; } else { deviceType = AUDIO_ACCESSORY_DEVICE; - device = cpt->accessory; + device = sapmComponent->accessory; } ret = AudioUpdateRegBits(deviceType, device, &mixerControl, SAPM_POWER_DOWN); if (ret != HDF_SUCCESS) { @@ -832,7 +840,7 @@ static void AudioSapmPowerDownSeqRun(struct DListHead *list) int32_t AudioSapmPowerComponents(struct AudioCard *audioCard) { - struct AudioSapmComponent *cpt = NULL; + struct AudioSapmComponent *sapmComponent = NULL; struct DListHead upList; struct DListHead downList; @@ -844,22 +852,22 @@ int32_t AudioSapmPowerComponents(struct AudioCard *audioCard) DListHeadInit(&upList); DListHeadInit(&downList); - DLIST_FOR_EACH_ENTRY(cpt, &audioCard->sapmDirty, struct AudioSapmComponent, dirty) { - cpt->newPower = cpt->PowerCheck(cpt); - if (cpt->newPower == cpt->power) { + DLIST_FOR_EACH_ENTRY(sapmComponent, &audioCard->sapmDirty, struct AudioSapmComponent, dirty) { + sapmComponent->newPower = sapmComponent->PowerCheck(sapmComponent); + if (sapmComponent->newPower == sapmComponent->power) { continue; } - if (g_audioSapmIsStandby && cpt->PowerClockOp != NULL) { - cpt->PowerClockOp(cpt); + if (g_audioSapmIsStandby && sapmComponent->PowerClockOp != NULL) { + sapmComponent->PowerClockOp(sapmComponent); } - AudioSapmSetPower(audioCard, cpt, cpt->newPower, &upList, &downList); + AudioSapmSetPower(audioCard, sapmComponent, sapmComponent->newPower, &upList, &downList); } - DLIST_FOR_EACH_ENTRY(cpt, &audioCard->components, struct AudioSapmComponent, list) { - DListRemove(&cpt->dirty); - DListHeadInit(&cpt->dirty); + DLIST_FOR_EACH_ENTRY(sapmComponent, &audioCard->components, struct AudioSapmComponent, list) { + DListRemove(&sapmComponent->dirty); + DListHeadInit(&sapmComponent->dirty); } AudioSapmPowerDownSeqRun(&downList); @@ -868,32 +876,32 @@ int32_t AudioSapmPowerComponents(struct AudioCard *audioCard) return HDF_SUCCESS; } -static void ReadInitComponentPowerStatus(struct AudioSapmComponent *cpt) +static void ReadInitComponentPowerStatus(struct AudioSapmComponent *sapmComponent) { int32_t ret; - uint32_t regVal = 0; + uint32_t regVal; - if (cpt == NULL) { - ADM_LOG_ERR("input param cpt is NULL."); + if (sapmComponent == NULL) { + ADM_LOG_ERR("input param sapmComponent is NULL."); return; } - if (cpt->reg >= 0) { - ret = AudioCodecDeviceReadReg(cpt->codec, cpt->reg, ®Val); + if (sapmComponent->reg >= 0) { + ret = AudioCodecDeviceReadReg(sapmComponent->codec, sapmComponent->reg, ®Val); if (ret != HDF_SUCCESS) { ADM_LOG_ERR("read reg fail!"); return; } - regVal &= 1 << cpt->shift; + regVal &= 1 << sapmComponent->shift; - if (cpt->invert) { + if (sapmComponent->invert) { regVal = !regVal; } if (regVal) { - cpt->power = SAPM_POWER_UP; + sapmComponent->power = SAPM_POWER_UP; } else { - cpt->power = SAPM_POWER_DOWN; + sapmComponent->power = SAPM_POWER_DOWN; } } @@ -919,7 +927,7 @@ void AudioSapmSleep(const struct AudioCard *audioCard) int32_t AudioSapmNewControls(struct AudioCard *audioCard) { - struct AudioSapmComponent *cpt = NULL; + struct AudioSapmComponent *sapmComponent = NULL; int32_t ret; if (audioCard == NULL) { @@ -927,44 +935,44 @@ int32_t AudioSapmNewControls(struct AudioCard *audioCard) return HDF_FAILURE; } - DLIST_FOR_EACH_ENTRY(cpt, &audioCard->components, struct AudioSapmComponent, list) { - if (cpt->newCpt) { + DLIST_FOR_EACH_ENTRY(sapmComponent, &audioCard->components, struct AudioSapmComponent, list) { + if (sapmComponent->newCpt) { continue; } - if (cpt->kcontrolsNum > 0) { - cpt->kcontrols = OsalMemCalloc(sizeof(struct AudioKcontrol*) * cpt->kcontrolsNum); - if (cpt->kcontrols == NULL) { + if (sapmComponent->kcontrolsNum > 0) { + sapmComponent->kcontrols = OsalMemCalloc(sizeof(struct AudioKcontrol*) * sapmComponent->kcontrolsNum); + if (sapmComponent->kcontrols == NULL) { ADM_LOG_ERR("malloc kcontrols fail!"); return HDF_FAILURE; } } - switch (cpt->sapmType) { + switch (sapmComponent->sapmType) { case AUDIO_SAPM_ANALOG_SWITCH: case AUDIO_SAPM_MIXER: case AUDIO_SAPM_MIXER_NAMED_CTRL: case AUDIO_SAPM_SPK: case AUDIO_SAPM_PGA: - ret = AudioSapmNewMixerControls(cpt, audioCard); + ret = AudioSapmNewMixerControls(sapmComponent, audioCard); break; case AUDIO_SAPM_MUX: case AUDIO_SAPM_VIRT_MUX: case AUDIO_SAPM_VALUE_MUX: - ret =AudioSapmNewMuxControls(cpt, audioCard); + ret =AudioSapmNewMuxControls(sapmComponent, audioCard); break; default: ret = HDF_SUCCESS; break; } if (ret != HDF_SUCCESS) { - OsalMemFree(cpt->kcontrols); + OsalMemFree(sapmComponent->kcontrols); ADM_LOG_ERR("sapm new mixer or mux controls fail!"); return HDF_FAILURE; } - ReadInitComponentPowerStatus(cpt); - cpt->newCpt = 1; - DListInsertTail(&cpt->dirty, &audioCard->sapmDirty); + ReadInitComponentPowerStatus(sapmComponent); + sapmComponent->newCpt = 1; + DListInsertTail(&sapmComponent->dirty, &audioCard->sapmDirty); } ret = AudioSapmPowerComponents(audioCard); @@ -1024,7 +1032,7 @@ static int32_t MixerUpdatePowerStatus(struct AudioKcontrol *kcontrol, uint32_t p return HDF_SUCCESS; } -int32_t AudioSapmGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +int32_t AudioSapmGetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) { int32_t ret; struct CodecDevice *codec = NULL; @@ -1062,7 +1070,7 @@ int32_t AudioSapmGetCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemV return HDF_SUCCESS; } -int32_t AudioSapmPutCtrlSwSub(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, +int32_t AudioSapmPutCtrlOpsSub(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue, struct AudioMixerControl *mixerCtrl, int32_t value, uint32_t pathStatus) { int32_t ret = HDF_FAILURE; @@ -1106,13 +1114,14 @@ int32_t AudioSapmPutCtrlSwSub(struct AudioKcontrol *kcontrol, struct AudioCtrlEl } /* 1.first user specify old component -- power down; 2.second user specify new component -- power up */ -int32_t AudioSapmPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) +int32_t AudioSapmSetCtrlOps(struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue) { uint32_t pathStatus; int32_t value; 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; } @@ -1130,7 +1139,8 @@ int32_t AudioSapmPutCtrlSw(struct AudioKcontrol *kcontrol, struct AudioCtrlElemV } else { pathStatus = UNCONNECT_SINK_AND_SOURCE; } - if (AudioSapmPutCtrlSwSub(kcontrol, elemValue, mixerCtrl, value, pathStatus) == HDF_FAILURE) { + if (AudioSapmPutCtrlOpsSub(kcontrol, elemValue, + mixerCtrl, value, pathStatus) == HDF_FAILURE) { ADM_LOG_ERR("AudioSapmPutCtrlSwSub value is fail."); return HDF_FAILURE; } @@ -1161,7 +1171,7 @@ static bool AudioSapmCheckTime(void) return false; } -static void AudioSapmEnterSleepSub(uintptr_t para, struct AudioSapmComponent *cpt) +static void AudioSapmEnterSleepSub(uintptr_t para, struct AudioSapmComponent *sapmComponent) { void *device = NULL; int i; @@ -1170,23 +1180,25 @@ static void AudioSapmEnterSleepSub(uintptr_t para, struct AudioSapmComponent *cp struct AudioCard *audioCard = (struct AudioCard *)para; DListHeadInit(&downList); - DLIST_FOR_EACH_ENTRY(cpt, &audioCard->components, struct AudioSapmComponent, list) { - for (i = 0; (i < cpt->kcontrolsNum) && (cpt->kcontrols != NULL) && (cpt->kcontrols[i] != NULL); i++) { - struct AudioMixerControl *mixerCtrl = (struct AudioMixerControl *)(cpt->kcontrols[i]->privateValue); + 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 (cpt->codec != NULL && cpt->codec->devData != NULL) { + if (sapmComponent->codec != NULL && sapmComponent->codec->devData != NULL) { deviceType = AUDIO_CODEC_DEVICE; - device = cpt->codec; + device = sapmComponent->codec; } else { deviceType = AUDIO_ACCESSORY_DEVICE; - device = cpt->accessory; + device = sapmComponent->accessory; } AudioUpdateRegBits(deviceType, device, mixerCtrl, SAPM_POWER_DOWN); } } - ReadInitComponentPowerStatus(cpt); - if (cpt->power == SAPM_POWER_UP) { - AudioSapmPowerSeqInsert(cpt, &downList, SAPM_POWER_DOWN); + ReadInitComponentPowerStatus(sapmComponent); + if (sapmComponent->power == SAPM_POWER_UP) { + AudioSapmPowerSeqInsert(sapmComponent, &downList, SAPM_POWER_DOWN); } } AudioSapmPowerDownSeqRun(&downList); @@ -1195,7 +1207,7 @@ static void AudioSapmEnterSleepSub(uintptr_t para, struct AudioSapmComponent *cp static void AudioSapmEnterSleep(uintptr_t para) { - struct AudioSapmComponent *cpt = NULL; + struct AudioSapmComponent *sapmComponent = NULL; struct AudioCard *audioCard = (struct AudioCard *)para; static bool bFirst = true; @@ -1209,10 +1221,10 @@ static void AudioSapmEnterSleep(uintptr_t para) return; } - DLIST_FOR_EACH_ENTRY(cpt, &audioCard->components, struct AudioSapmComponent, list) { - if (cpt->PowerClockOp != NULL) { + DLIST_FOR_EACH_ENTRY(sapmComponent, &audioCard->components, struct AudioSapmComponent, list) { + if (sapmComponent->PowerClockOp != NULL) { if (g_audioSapmIsStandby == false) { - cpt->PowerClockOp(cpt); + sapmComponent->PowerClockOp(sapmComponent); g_audioSapmIsStandby = true; AudioSapmRefreshTime(true); } @@ -1225,5 +1237,5 @@ static void AudioSapmEnterSleep(uintptr_t para) g_audioSapmIsStandby = false; } - AudioSapmEnterSleepSub(para, cpt); + AudioSapmEnterSleepSub(para, sapmComponent); } -- Gitee From 0172c1e4ef074ffeb23cb24911a1539602f0950f Mon Sep 17 00:00:00 2001 From: h00329621 Date: Thu, 22 Jul 2021 21:04:27 +0800 Subject: [PATCH 023/205] modify audio Signed-off-by: h00329621 --- model/audio/device/soc/src/dsp.c | 12 ++++++------ model/audio/device/soc/src/platform.c | 14 ++++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/model/audio/device/soc/src/dsp.c b/model/audio/device/soc/src/dsp.c index c15908b69..518d73b6d 100755 --- a/model/audio/device/soc/src/dsp.c +++ b/model/audio/device/soc/src/dsp.c @@ -25,9 +25,9 @@ static int32_t DspDeviceWriteReg(struct DspDevice *device, uint8_t *buf, uint32_ 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(struct AudioCard *card, void *buf, struct DspDevice *device); -static int32_t DspEncodeAudioStream(struct AudioCard *card, void *buf, struct DspDevice *device); -static int32_t DspEqualizerActive(struct AudioCard *card, void *buf, struct DspDevice *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, @@ -445,7 +445,7 @@ static void DspDriverRelease(struct HdfDeviceObject *device) OsalMemFree(dspHost); } -static int32_t DspEqualizerActive(struct AudioCard *card, void *buf, struct DspDevice *device) +static int32_t DspEqualizerActive(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device) { (void)card; (void)buf; @@ -454,7 +454,7 @@ static int32_t DspEqualizerActive(struct AudioCard *card, void *buf, struct DspD return HDF_SUCCESS; } -static int32_t DspDecodeAudioStream(struct AudioCard *card, void *buf, struct DspDevice *device) +static int32_t DspDecodeAudioStream(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device) { (void)card; (void)buf; @@ -463,7 +463,7 @@ static int32_t DspDecodeAudioStream(struct AudioCard *card, void *buf, struct Ds return HDF_SUCCESS; } -static int32_t DspEncodeAudioStream(struct AudioCard *card, void *buf, struct DspDevice *device) +static int32_t DspEncodeAudioStream(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device) { (void)card; (void)buf; diff --git a/model/audio/device/soc/src/platform.c b/model/audio/device/soc/src/platform.c index 1d9033f56..d780d8412 100755 --- a/model/audio/device/soc/src/platform.c +++ b/model/audio/device/soc/src/platform.c @@ -66,7 +66,7 @@ static int32_t PlatformDriverBind(struct HdfDeviceObject *device) int32_t AudioRenderBuffInit(struct PlatformHost *platformHost) { - unsigned int buffSize; + uint64_t buffSize; if (platformHost == NULL) { AUDIO_DRIVER_LOG_ERR("input para is NULL."); return HDF_FAILURE; @@ -121,7 +121,7 @@ int32_t AudioRenderBuffFree(struct PlatformHost *platformHost) int32_t AudioCaptureBuffInit(struct PlatformHost *platformHost) { - unsigned int buffSize; + uint64_t buffSize; if (platformHost == NULL) { AUDIO_DRIVER_LOG_ERR("input para is NULL."); return HDF_FAILURE; @@ -282,6 +282,9 @@ int32_t AiaoSysPinMux(void) 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; } @@ -650,7 +653,7 @@ static int32_t UpdateWriteBuffOffset(struct PlatformHost *platformHost, unsigned int wptr; unsigned int rptr; int devId; - if (platformHost == NULL || buffOffset == NULL || txData == NULL) { + if (platformHost == NULL || buffOffset == NULL || txData == NULL || txData->buf == NULL) { AUDIO_DRIVER_LOG_ERR("input param is invalid."); return HDF_ERR_INVALID_PARAM; } @@ -734,9 +737,8 @@ static int32_t SetWriteBuffWptr(struct PlatformHost *platformHost, int32_t PlatformWrite(const struct AudioCard *card, struct AudioTxData *txData) { - int buffSize; - - unsigned int startThreshold; + uint64_t buffSize; + uint64_t startThreshold; struct PlatformHost *platformHost = NULL; AUDIO_DRIVER_LOG_DEBUG("entry."); -- Gitee From 715933c1495b6b5d936e463deb81d5f27ac81814 Mon Sep 17 00:00:00 2001 From: jiaziyang Date: Thu, 22 Jul 2021 21:06:04 +0800 Subject: [PATCH 024/205] =?UTF-8?q?=E4=BF=AE=E6=94=B9rtc=5Fbase.c=E4=B8=AD?= =?UTF-8?q?=E7=A9=BA=E8=A1=8C=E5=8F=8A=E5=85=B3=E9=94=AE=E5=AD=97=E7=9A=84?= =?UTF-8?q?=E5=87=B8=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiaziyang --- support/platform/src/rtc_base.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/support/platform/src/rtc_base.c b/support/platform/src/rtc_base.c index 82d0039dd..25be00507 100644 --- a/support/platform/src/rtc_base.c +++ b/support/platform/src/rtc_base.c @@ -95,18 +95,17 @@ uint64_t RtcTimeToTimestamp(const struct RtcTime *time) HDF_LOGE("RtcTimeToTimestamp: time invalid"); return 0; } - - + seconds = ((uint64_t)time->hour * RTC_MAX_MINUTE + time->minute) * RTC_MAX_SECOND + time->second; days = time->day - RTC_UNIT_DIFF; month = time->month; year = time->year; - for(month--; month >= RTC_JANUARY; month--) { + for (month--; month >= RTC_JANUARY; month--) { days += RtcGetMonthDays(IS_LEAP_YEAR(time->year), month); } - for(year--; year >= RTC_BEGIN_YEAR; year--) { + for (year--; year >= RTC_BEGIN_YEAR; year--) { days += RTC_YEAR_DAYS(year); } -- Gitee From 0703f6457060272a86e1cafdeb4b7f51827fd456 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Thu, 22 Jul 2021 20:11:58 +0800 Subject: [PATCH 025/205] fix codex scan issue Signed-off-by: yuanbo --- core/adapter/syscall/src/hdf_syscall_adapter.c | 3 ++- .../unittest/common/hdf_lite_manager_test.cpp | 4 ++-- test/unittest/manager/sample_driver_test.c | 15 +++++++++------ utils/src/hdf_cstring.c | 5 +++++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/core/adapter/syscall/src/hdf_syscall_adapter.c b/core/adapter/syscall/src/hdf_syscall_adapter.c index 18fca415e..b89f24570 100644 --- a/core/adapter/syscall/src/hdf_syscall_adapter.c +++ b/core/adapter/syscall/src/hdf_syscall_adapter.c @@ -604,7 +604,9 @@ static void HdfDevListenerThreadDestroy(struct HdfDevListenerThread *thread) continue; } if (HdfAdapterExitListenIoctl(thread->pfds[i].fd) == HDF_SUCCESS) { + thread->shouldStop = true; stopCount++; + break; } } @@ -612,7 +614,6 @@ static void HdfDevListenerThreadDestroy(struct HdfDevListenerThread *thread) thread->shouldStop = true; HDF_LOGE("%s:failed to exit listener thread with ioctl, will go async way", __func__); } - return; } case LISTENER_STARTED: diff --git a/core/manager/test/unittest/common/hdf_lite_manager_test.cpp b/core/manager/test/unittest/common/hdf_lite_manager_test.cpp index 623e4eb42..264a2fd74 100644 --- a/core/manager/test/unittest/common/hdf_lite_manager_test.cpp +++ b/core/manager/test/unittest/common/hdf_lite_manager_test.cpp @@ -84,7 +84,7 @@ HWTEST_F(HdfManagerTest, HdfRegisterDevice001, TestSize.Level0) int32_t ret = HDF_FAILURE; struct HdfSBuf *data = NULL; struct HdfIoService *ioService = HdfIoServiceBind(SAMPLE_SERVICE); - EXPECT_TRUE(ioService != NULL); + ASSERT_TRUE(ioService != NULL); data = HdfSBufObtainDefaultSize(); EXPECT_TRUE(data != NULL); EXPECT_TRUE(HdfSbufWriteString(data, "sample_driver")); @@ -118,7 +118,7 @@ HWTEST_F(HdfManagerTest, HdfRegisterDevice001, TestSize.Level0) HWTEST_F(HdfManagerTest, HdfGetServiceNameByDeviceClass001, TestSize.Level0) { struct HdfSBuf *data = HdfSBufObtain(1000); - EXPECT_TRUE(data != NULL); + ASSERT_TRUE(data != NULL); int32_t ret = HdfGetServiceNameByDeviceClass(DEVICE_CLASS_DEFAULT, data); EXPECT_TRUE(ret == HDF_SUCCESS); bool flag = false; diff --git a/test/unittest/manager/sample_driver_test.c b/test/unittest/manager/sample_driver_test.c index 84c3b6a58..609787660 100644 --- a/test/unittest/manager/sample_driver_test.c +++ b/test/unittest/manager/sample_driver_test.c @@ -72,6 +72,9 @@ int32_t SampleDriverSendEvent(struct HdfDeviceIoClient *client, int id, struct H int32_t SampleDriverPowerStateInject(uint32_t powerState) { struct IDevmgrService *devmgrService = DevmgrServiceGetInstance(); + if (devmgrService == NULL || devmgrService->PowerStateChange == NULL) { + return HDF_ERR_INVALID_OBJECT; + } int ret = devmgrService->PowerStateChange(devmgrService, powerState); HDF_LOGI("%s: inject power state(%d) done, ret = %d", __func__, powerState, ret); @@ -115,7 +118,7 @@ int32_t SampleDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) { - HDF_LOGD("%s::enter!, deviceObject=%p", __func__, deviceObject); + HDF_LOGD("%s::enter", __func__); if (deviceObject == NULL) { return HDF_FAILURE; } @@ -130,25 +133,25 @@ int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) int HdfSampleDozeResume(struct HdfDeviceObject *deviceObject) { - HDF_LOGI("%s:called, object = %llx", __func__, (uint64_t)deviceObject); + HDF_LOGI("%s:called", __func__); return HDF_SUCCESS; } int HdfSampleDozeSuspend(struct HdfDeviceObject *deviceObject) { - HDF_LOGI("%s:called, object = %llx", __func__, (uint64_t)deviceObject); + HDF_LOGI("%s:called", __func__); return HDF_SUCCESS; } int HdfSampleResume(struct HdfDeviceObject *deviceObject) { - HDF_LOGI("%s:called, object = %llx", __func__, (uint64_t)deviceObject); + HDF_LOGI("%s:called", __func__); return HDF_SUCCESS; } int HdfSampleSuspend(struct HdfDeviceObject *deviceObject) { - HDF_LOGI("%s:called, object = %llx", __func__, (uint64_t)deviceObject); + HDF_LOGI("%s:called", __func__); return HDF_SUCCESS; } @@ -159,7 +162,7 @@ struct SampleDriverPmListener { int HdfSampleDriverInit(struct HdfDeviceObject *deviceObject) { - HDF_LOGI("%s::enter!, deviceObject=%llx", __func__, (uint64_t)deviceObject); + HDF_LOGI("%s::enter!", __func__); if (deviceObject == NULL) { HDF_LOGE("%s::ptr is null!", __func__); return HDF_FAILURE; diff --git a/utils/src/hdf_cstring.c b/utils/src/hdf_cstring.c index 4b30bb2e7..761e21659 100644 --- a/utils/src/hdf_cstring.c +++ b/utils/src/hdf_cstring.c @@ -11,6 +11,8 @@ #include "osal_mem.h" #include "securec.h" +#define CSTRING_MAX 1024 + uint32_t HdfStringMakeHashKey(const char *key, uint32_t mask) { uint32_t hashValue = 0; @@ -26,6 +28,9 @@ struct HdfCString *HdfCStringObtain(const char *str) struct HdfCString *instance = NULL; if (str != NULL) { size_t strLen = strlen(str); + if (strLen > CSTRING_MAX) { + return NULL; + } size_t size = sizeof(struct HdfCString) + strLen + 1; instance = (struct HdfCString *)OsalMemCalloc(size); if (instance == NULL) { -- Gitee From 003c4d6e134c519d7a9fc298a521adc39e7b0fb4 Mon Sep 17 00:00:00 2001 From: yinshuqing Date: Thu, 22 Jul 2021 21:30:22 +0800 Subject: [PATCH 026/205] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6platform=5Fdevice=20platform=5Fmanager.c=20mm?= =?UTF-8?q?c=5Fif.c=20mmc=5Fprotocol.c=20uart=5Fcore.c=20i2c=5Ftest.c=20sp?= =?UTF-8?q?i=5Ftest.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yinshuqing --- support/platform/src/common/platform_device.c | 11 ++++++----- support/platform/src/common/platform_manager.c | 4 ++-- support/platform/src/mmc/mmc_if.c | 1 - support/platform/src/mmc/mmc_protocol.c | 3 ++- support/platform/src/uart_core.c | 1 + test/unittest/platform/common/i2c_test.c | 6 ++++++ test/unittest/platform/common/spi_test.c | 2 +- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/support/platform/src/common/platform_device.c b/support/platform/src/common/platform_device.c index 05ae7ea72..62050c05a 100644 --- a/support/platform/src/common/platform_device.c +++ b/support/platform/src/common/platform_device.c @@ -38,7 +38,7 @@ static void PlatformDeviceOnLastPut(struct HdfSRef *sref) device->ready = false; DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &device->notifiers, struct PlatformNotifierNode, node) { - if (pos != NULL && pos->notifier != NULL && pos->notifier->handle != NULL) { + if (pos!=NULL && pos->notifier != NULL && pos->notifier->handle != NULL) { pos->notifier->handle(device, PLAT_EVENT_DEAD, pos->notifier->data); } } @@ -153,14 +153,15 @@ static void PlatformDeviceRemoveNotifier(struct PlatformDevice *device, struct P (void)OsalSpinLock(&device->spin); DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &device->notifiers, struct PlatformNotifierNode, node) { - if (pos != NULL && pos->notifier != NULL) { + if (pos->notifier != NULL) { /* if notifier not set, we remove all the notifier nodes. */ - if (notifier == NULL || notifier == pos->notifier) { + if (notifier == pos->notifier) { DListRemove(&pos->node); OsalMemFree(pos); - } - if (notifier == pos->notifier) { break; + }else if (notifier == NULL) { + DListRemove(&pos->node); + OsalMemFree(pos); } } } diff --git a/support/platform/src/common/platform_manager.c b/support/platform/src/common/platform_manager.c index 0f3ccf662..2dbc222d6 100644 --- a/support/platform/src/common/platform_manager.c +++ b/support/platform/src/common/platform_manager.c @@ -78,7 +78,7 @@ int32_t PlatformManagerAddDevice(struct PlatformManager *manager, struct Platfor (void)OsalSpinLock(&manager->spin); DLIST_FOR_EACH_ENTRY(tmp, &manager->devices, struct PlatformDevice, node) { - if (tmp != NULL && tmp->magic == device->magic) { + if (tmp!=NULL && tmp->magic == device->magic) { repeatId = true; HDF_LOGE("PlatformManagerAddDevice: repeated magic:%u!", device->magic); break; @@ -130,7 +130,7 @@ struct PlatformDevice *PlatformManagerFindDevice(struct PlatformManager *manager (void)OsalSpinLock(&manager->spin); DLIST_FOR_EACH_ENTRY(tmp, &manager->devices, struct PlatformDevice, node) { - if (tmp != NULL && match(tmp, data)) { + if (tmp!=NULL && match(tmp, data)) { pdevice = PlatformDeviceGet(tmp); } } diff --git a/support/platform/src/mmc/mmc_if.c b/support/platform/src/mmc/mmc_if.c index 8b37d0d79..dba2d503a 100644 --- a/support/platform/src/mmc/mmc_if.c +++ b/support/platform/src/mmc/mmc_if.c @@ -29,7 +29,6 @@ static void *MmcCntlrObjGetByNumber(int16_t id) char *serviceName = NULL; if (id < 0) { - HDF_LOGE("MmcCntlrObjGetByNumber: invalid id:%d", id); return NULL; } serviceName = OsalMemCalloc(MMC_SVC_NAME_LEN + 1); diff --git a/support/platform/src/mmc/mmc_protocol.c b/support/platform/src/mmc/mmc_protocol.c index 304c3e127..a2ee8cfcb 100644 --- a/support/platform/src/mmc/mmc_protocol.c +++ b/support/platform/src/mmc/mmc_protocol.c @@ -3494,7 +3494,7 @@ static void SdioDecodeCisTplManfId(struct MmcCntlr *cntlr, struct SdioFunction * */ vendorId = (tuple->tplBody[1] << BITS_PER_BYTE) | tuple->tplBody[0]; deviceId = (tuple->tplBody[3] << BITS_PER_BYTE) | tuple->tplBody[2]; - HDF_LOGD("Sdio vendorId = 0x%x, deviceId = 0x%x.", vendorId, deviceId); + /* function CISTPL_MANFID. */ if (function != NULL) { function->deviceId = deviceId; @@ -3838,6 +3838,7 @@ static int32_t SdioAddFunctions(struct MmcCntlr *cntlr, uint32_t funcs) } ret = SdioReadFbr(cntlr, function); if (ret != HDF_SUCCESS) { + SdioDeleteFunction(function); return ret; } ret = SdioReadCis(cntlr, function); diff --git a/support/platform/src/uart_core.c b/support/platform/src/uart_core.c index 71cfcb050..caf03d1aa 100644 --- a/support/platform/src/uart_core.c +++ b/support/platform/src/uart_core.c @@ -75,6 +75,7 @@ static int32_t UartUserRead(struct UartHost *host, struct HdfSBuf *reply) } if (!HdfSbufWriteBuffer(reply, buf, len)) { HDF_LOGE("%s: sbuf write buffer failed", __func__); + OsalMemFree(buf); return HDF_ERR_IO; } OsalMemFree(buf); diff --git a/test/unittest/platform/common/i2c_test.c b/test/unittest/platform/common/i2c_test.c index cba586b29..2c6a9ed04 100644 --- a/test/unittest/platform/common/i2c_test.c +++ b/test/unittest/platform/common/i2c_test.c @@ -75,6 +75,7 @@ static int32_t I2cTestGetConfig(struct I2cTestConfig *config) HdfSBufRecycle(reply); HDF_LOGD("I2cTestGetConfig: exit!"); + HdfIoServiceRecycle(service); return HDF_SUCCESS; } @@ -260,6 +261,7 @@ int32_t I2cTestMultiThread(void) ret = OsalThreadCreate(&thread2, (OsalThreadEntry)I2cTestThreadFunc, (void *)&count2); if (ret != HDF_SUCCESS) { + (void)OsalThreadDestroy(&thread1); HDF_LOGE("create test thread1 fail:%d", ret); return HDF_FAILURE; } @@ -271,12 +273,16 @@ int32_t I2cTestMultiThread(void) ret = OsalThreadStart(&thread1, &cfg1); if (ret != HDF_SUCCESS) { + (void)OsalThreadDestroy(&thread1); + (void)OsalThreadDestroy(&thread2); HDF_LOGE("start test thread1 fail:%d", ret); return HDF_FAILURE; } ret = OsalThreadStart(&thread2, &cfg2); if (ret != HDF_SUCCESS) { + (void)OsalThreadDestroy(&thread1); + (void)OsalThreadDestroy(&thread2); HDF_LOGE("start test thread2 fail:%d", ret); return HDF_FAILURE; } diff --git a/test/unittest/platform/common/spi_test.c b/test/unittest/platform/common/spi_test.c index 671d3fd4c..d1603ac08 100644 --- a/test/unittest/platform/common/spi_test.c +++ b/test/unittest/platform/common/spi_test.c @@ -175,7 +175,7 @@ static int32_t SpiSetDmaIntMsg(struct SpiMsg *msg, uint32_t len) return HDF_ERR_MALLOC_FAIL; } rbuf = (uint8_t *)OsalMemAllocAlign(DMA_ALIGN_SIZE, len); - if (wbuf == NULL) { + if (rbuf == NULL) { OsalMemFree(wbuf); return HDF_ERR_MALLOC_FAIL; } -- Gitee From 4a68366c7aa2f73e4c870ee5b0262d2e10d284d4 Mon Sep 17 00:00:00 2001 From: yinshuqing Date: Fri, 23 Jul 2021 10:04:01 +0800 Subject: [PATCH 027/205] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86platform=5Fd?= =?UTF-8?q?evice.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yinshuqing --- support/platform/src/common/platform_device.c | 9 ++++----- support/platform/src/common/platform_manager.c | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) mode change 100644 => 100755 support/platform/src/common/platform_device.c diff --git a/support/platform/src/common/platform_device.c b/support/platform/src/common/platform_device.c old mode 100644 new mode 100755 index 62050c05a..734845563 --- a/support/platform/src/common/platform_device.c +++ b/support/platform/src/common/platform_device.c @@ -38,7 +38,7 @@ static void PlatformDeviceOnLastPut(struct HdfSRef *sref) device->ready = false; DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &device->notifiers, struct PlatformNotifierNode, node) { - if (pos!=NULL && pos->notifier != NULL && pos->notifier->handle != NULL) { + if (pos->notifier != NULL && pos->notifier->handle != NULL) { pos->notifier->handle(device, PLAT_EVENT_DEAD, pos->notifier->data); } } @@ -155,13 +155,12 @@ static void PlatformDeviceRemoveNotifier(struct PlatformDevice *device, struct P DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &device->notifiers, struct PlatformNotifierNode, node) { if (pos->notifier != NULL) { /* if notifier not set, we remove all the notifier nodes. */ - if (notifier == pos->notifier) { + if (notifier == NULL || notifier == pos->notifier) { DListRemove(&pos->node); OsalMemFree(pos); + } + if (notifier == pos->notifier) { break; - }else if (notifier == NULL) { - DListRemove(&pos->node); - OsalMemFree(pos); } } } diff --git a/support/platform/src/common/platform_manager.c b/support/platform/src/common/platform_manager.c index 2dbc222d6..0f3ccf662 100644 --- a/support/platform/src/common/platform_manager.c +++ b/support/platform/src/common/platform_manager.c @@ -78,7 +78,7 @@ int32_t PlatformManagerAddDevice(struct PlatformManager *manager, struct Platfor (void)OsalSpinLock(&manager->spin); DLIST_FOR_EACH_ENTRY(tmp, &manager->devices, struct PlatformDevice, node) { - if (tmp!=NULL && tmp->magic == device->magic) { + if (tmp != NULL && tmp->magic == device->magic) { repeatId = true; HDF_LOGE("PlatformManagerAddDevice: repeated magic:%u!", device->magic); break; @@ -130,7 +130,7 @@ struct PlatformDevice *PlatformManagerFindDevice(struct PlatformManager *manager (void)OsalSpinLock(&manager->spin); DLIST_FOR_EACH_ENTRY(tmp, &manager->devices, struct PlatformDevice, node) { - if (tmp!=NULL && match(tmp, data)) { + if (tmp != NULL && match(tmp, data)) { pdevice = PlatformDeviceGet(tmp); } } -- Gitee From 08446825d5658335ff741e22e567ca16da2fbdb4 Mon Sep 17 00:00:00 2001 From: yinshuqing Date: Fri, 23 Jul 2021 14:11:47 +0800 Subject: [PATCH 028/205] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86platform=5Fd?= =?UTF-8?q?evice.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yinshuqing --- support/platform/src/common/platform_device.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/support/platform/src/common/platform_device.c b/support/platform/src/common/platform_device.c index 734845563..bd8e214a7 100755 --- a/support/platform/src/common/platform_device.c +++ b/support/platform/src/common/platform_device.c @@ -155,12 +155,13 @@ static void PlatformDeviceRemoveNotifier(struct PlatformDevice *device, struct P DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &device->notifiers, struct PlatformNotifierNode, node) { if (pos->notifier != NULL) { /* if notifier not set, we remove all the notifier nodes. */ - if (notifier == NULL || notifier == pos->notifier) { + if (notifier == pos->notifier) { + DListRemove(&pos->node); + OsalMemFree(pos); + break; + } else if (notifier == NULL) { DListRemove(&pos->node); OsalMemFree(pos); - } - if (notifier == pos->notifier) { - break; } } } -- Gitee From a03495013902038e9a6cd97d71581ce87678a62d Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Mon, 26 Jul 2021 07:11:32 +0000 Subject: [PATCH 029/205] Deal with CodeDex warning Signed-off-by: YOUR_NAME --- model/input/driver/hdf_hid_adapter.c | 38 ++++++++++++++----- model/input/driver/hdf_input_device_manager.c | 2 +- model/input/driver/hdf_touch.c | 4 +- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/model/input/driver/hdf_hid_adapter.c b/model/input/driver/hdf_hid_adapter.c index bfd7a771a..3446117c4 100644 --- a/model/input/driver/hdf_hid_adapter.c +++ b/model/input/driver/hdf_hid_adapter.c @@ -14,6 +14,13 @@ #include "hdf_input_device_manager.h" #include "hdf_hid_adapter.h" +#define MEMCPY_CHECK_RETURN(ret) do { \ + if ((ret) != 0) { \ + HDF_LOGE("%s: memcpy failed, line %d", __func__, __LINE__); \ + return; \ + } \ +} while (0) + InputDevice *cachedHid[MAX_INPUT_DEV_NUM]; HidInfo *g_cachedInfo[MAX_INPUT_DEV_NUM]; @@ -94,6 +101,7 @@ static void SetInputDevAbility(InputDevice *inputDev) HidInfo *info = NULL; int32_t id = 0; uint32_t len; + int32_t ret; while (id < MAX_INPUT_DEV_NUM) { if(g_cachedInfo[id] != NULL && !strcmp(inputDev->devName, g_cachedInfo[id]->devName)) { info = g_cachedInfo[id]; @@ -106,26 +114,36 @@ static void SetInputDevAbility(InputDevice *inputDev) return; } len = sizeof(unsigned long); - memcpy_s(inputDev->abilitySet.devProp, len * BITS_TO_LONG(INPUT_PROP_CNT), + ret = memcpy_s(inputDev->abilitySet.devProp, len * BITS_TO_LONG(INPUT_PROP_CNT), info->devProp, len * BITS_TO_LONG(INPUT_PROP_CNT)); - memcpy_s(inputDev->abilitySet.eventType, len * BITS_TO_LONG(EV_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.eventType, len * BITS_TO_LONG(EV_CNT), info->eventType, len * BITS_TO_LONG(EV_CNT)); - memcpy_s(inputDev->abilitySet.absCode, len * BITS_TO_LONG(ABS_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.absCode, len * BITS_TO_LONG(ABS_CNT), info->absCode, len * BITS_TO_LONG(ABS_CNT)); - memcpy_s(inputDev->abilitySet.relCode, len * BITS_TO_LONG(REL_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.relCode, len * BITS_TO_LONG(REL_CNT), info->relCode, len * BITS_TO_LONG(REL_CNT)); - memcpy_s(inputDev->abilitySet.keyCode, len * BITS_TO_LONG(KEY_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.keyCode, len * BITS_TO_LONG(KEY_CNT), info->keyCode, len * BITS_TO_LONG(KEY_CNT)); - memcpy_s(inputDev->abilitySet.ledCode, len * BITS_TO_LONG(LED_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.ledCode, len * BITS_TO_LONG(LED_CNT), info->ledCode, len * BITS_TO_LONG(LED_CNT)); - memcpy_s(inputDev->abilitySet.miscCode, len * BITS_TO_LONG(MSC_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.miscCode, len * BITS_TO_LONG(MSC_CNT), info->miscCode, len * BITS_TO_LONG(MSC_CNT)); - memcpy_s(inputDev->abilitySet.soundCode, len * BITS_TO_LONG(SND_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.soundCode, len * BITS_TO_LONG(SND_CNT), info->soundCode, len * BITS_TO_LONG(SND_CNT)); - memcpy_s(inputDev->abilitySet.forceCode, len * BITS_TO_LONG(FF_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.forceCode, len * BITS_TO_LONG(FF_CNT), info->forceCode, len * BITS_TO_LONG(FF_CNT)); - memcpy_s(inputDev->abilitySet.switchCode, len * BITS_TO_LONG(SW_CNT), + MEMCPY_CHECK_RETURN(ret); + ret = memcpy_s(inputDev->abilitySet.switchCode, len * BITS_TO_LONG(SW_CNT), info->switchCode, len * BITS_TO_LONG(SW_CNT)); + MEMCPY_CHECK_RETURN(ret); inputDev->attrSet.id.busType = info->bustype; inputDev->attrSet.id.vendor = info->vendor; diff --git a/model/input/driver/hdf_input_device_manager.c b/model/input/driver/hdf_input_device_manager.c index 4d449b6c1..7e3a60b6e 100644 --- a/model/input/driver/hdf_input_device_manager.c +++ b/model/input/driver/hdf_input_device_manager.c @@ -91,10 +91,10 @@ static int32_t CreateDeviceNode(InputDevice *inputDev) if (IsHidDevice(inputDev->devType)) { HDF_LOGI("%s: prepare to register hdf device", __func__); inputDev->hdfDevObj = HidRegisterHdfDevice(inputDev); - inputDev->hdfDevObj->priv = (void *)inputDev; if (inputDev->hdfDevObj == NULL) { return HDF_DEV_ERR_NO_DEVICE; } + inputDev->hdfDevObj->priv = (void *)inputDev; } HDF_LOGI("%s: create node succ, devId is %d ", __func__, inputDev->devId); diff --git a/model/input/driver/hdf_touch.c b/model/input/driver/hdf_touch.c index ad862cbd8..8d2f17078 100644 --- a/model/input/driver/hdf_touch.c +++ b/model/input/driver/hdf_touch.c @@ -393,7 +393,7 @@ static int32_t TouchGetDevType(TouchDriver *driver, struct HdfSBuf *reply) static int32_t TouchSetPowerStatus(TouchDriver *driver, struct HdfSBuf *data) { - uint32_t pwrStatus; + uint32_t pwrStatus = 0; bool ret = HdfSbufReadUint32(data, &pwrStatus); if (!ret) { HDF_LOGE("%s: HdfSbufWriteUint32 failed", __func__); @@ -483,7 +483,7 @@ static int32_t TouchGetDeviceAbility(TouchDriver *driver, struct HdfSBuf *reply) static int32_t TouchSetGestureMode(TouchDriver *driver, struct HdfSBuf *data) { - uint32_t gestureMode; + uint32_t gestureMode = 0; bool ret = HdfSbufReadUint32(data, &gestureMode); if (!ret) { HDF_LOGE("%s: HdfSbufWriteUint32 failed", __func__); -- Gitee From 22ae5a82c972008b3b8c322b7b2147a8250b4050 Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 26 Jul 2021 15:31:48 +0800 Subject: [PATCH 030/205] modify sensor config Signed-off-by: kevin Change-Id: Ib6673b2c99a0a0194991eab84c1c25328732c5b6 --- model/misc/vibrator/driver/src/vibrator_driver.c | 13 ++++++++++--- .../driver/common/src/sensor_config_parser.c | 14 +++++++------- model/sensor/driver/include/sensor_platform_if.h | 14 ++------------ 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/model/misc/vibrator/driver/src/vibrator_driver.c b/model/misc/vibrator/driver/src/vibrator_driver.c index 9d47a1be9..5e8be1847 100644 --- a/model/misc/vibrator/driver/src/vibrator_driver.c +++ b/model/misc/vibrator/driver/src/vibrator_driver.c @@ -291,9 +291,16 @@ int32_t InitVibratorDriver(struct HdfDeviceObject *device) void ReleaseVibratorDriver(struct HdfDeviceObject *device) { - struct VibratorDriverData *drvData = (struct VibratorDriverData *)device->service; - if (device == NULL || drvData == NULL) { - HDF_LOGE("%s: pointer is null and return errno", __func__); + struct VibratorDriverData *drvData = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is null", __func__); + return; + } + + drvData = (struct VibratorDriverData *)device->service; + if (drvData == NULL) { + HDF_LOGE("%s: drvData is null", __func__); return; } diff --git a/model/sensor/driver/common/src/sensor_config_parser.c b/model/sensor/driver/common/src/sensor_config_parser.c index c91f8d0ee..c844da6f8 100644 --- a/model/sensor/driver/common/src/sensor_config_parser.c +++ b/model/sensor/driver/common/src/sensor_config_parser.c @@ -162,7 +162,7 @@ int32_t ParseSensorRegConfig(struct SensorCfgData *config) parser = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); CHECK_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM); - regCfgNode = parser->GetChildNode(config->root, "accelRegConfig"); + regCfgNode = parser->GetChildNode(config->root, "sensorRegConfig"); CHECK_NULL_PTR_RETURN_VALUE(regCfgNode, HDF_ERR_INVALID_PARAM); DEV_RES_NODE_FOR_EACH_ATTR(regCfgNode, regAttr) { @@ -386,18 +386,18 @@ int32_t GetSensorBaseConfigData(const struct DeviceResourceNode *node, struct Se config->root = node; CHECK_NULL_PTR_RETURN_VALUE(parser->GetChildNode, HDF_ERR_INVALID_PARAM); - const struct DeviceResourceNode *infoNode = parser->GetChildNode(node, "accelInfo"); + const struct DeviceResourceNode *infoNode = parser->GetChildNode(node, "sensorInfo"); CHECK_NULL_PTR_RETURN_VALUE(infoNode, HDF_ERR_INVALID_PARAM); - const struct DeviceResourceNode *busNode = parser->GetChildNode(node, "accelBusConfig"); + const struct DeviceResourceNode *busNode = parser->GetChildNode(node, "sensorBusConfig"); CHECK_NULL_PTR_RETURN_VALUE(busNode, HDF_ERR_INVALID_PARAM); - const struct DeviceResourceNode *attrNode = parser->GetChildNode(node, "accelAttr"); + const struct DeviceResourceNode *attrNode = parser->GetChildNode(node, "sensorIdAttr"); CHECK_NULL_PTR_RETURN_VALUE(attrNode, HDF_ERR_INVALID_PARAM); ret = ParseSensorInfo(parser, infoNode, config); - CHECK_PARSER_RESULT_RETURN_VALUE(ret, "accelInfo"); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorInfo"); ret = ParseSensorBus(parser, busNode, config); - CHECK_PARSER_RESULT_RETURN_VALUE(ret, "accelBusConfig"); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorBusConfig"); ret = ParseSensorAttr(parser, attrNode, config); - CHECK_PARSER_RESULT_RETURN_VALUE(ret, "accelAttr"); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorIdAttr"); return HDF_SUCCESS; } \ No newline at end of file diff --git a/model/sensor/driver/include/sensor_platform_if.h b/model/sensor/driver/include/sensor_platform_if.h index bc91bf731..6bf64210f 100644 --- a/model/sensor/driver/include/sensor_platform_if.h +++ b/model/sensor/driver/include/sensor_platform_if.h @@ -44,10 +44,10 @@ #define SENSOR_DATA_WIDTH_8_BIT 8 // 8 bit #define SENSOR_CONVERT_UNIT 1000 #define SENSOR_1K_UNIT 1024 -#define SENSOR_SPI_MAX_SPEED 115200 +#define SENSOR_SPI_MAX_SPEED 115200 #define SENSOR_SECOND_CONVERT_NANOSECOND (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT) -#define SENSOR_TIMER_MIN_TIME 20 +#define SENSOR_TIMER_MIN_TIME 20 enum SensorBusType { SENSOR_BUS_I2C = 0, @@ -76,16 +76,6 @@ struct SensorBusCfg { }; }; -enum SensorThreadStatus { - SENSOR_THREAD_NONE = 0, - SENSOR_THREAD_START = 1, - SENSOR_THREAD_RUNNING = 2, - SENSOR_THREAD_STOPPING = 3, - SENSOR_THREAD_STOPPED = 4, - SENSOR_THREAD_DESTROY = 5, - SENSOR_THREAD_STATUS_BUT, -}; - enum SENSORConfigValueIndex { SENSOR_ADDR_INDEX, SENSOR_VALUE_INDEX, -- Gitee From 49c78ba9369229c1fe6b0828609d3508967d5d97 Mon Sep 17 00:00:00 2001 From: jiaziyang Date: Mon, 26 Jul 2021 18:30:23 +0800 Subject: [PATCH 031/205] =?UTF-8?q?=E4=BF=AE=E6=94=B9uart=5Ftest.c?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=9C=A8UartRead=E4=B8=AD=E5=85=88=E8=AE=BE?= =?UTF-8?q?=E7=BD=AEUart=E4=BC=A0=E8=BE=93=E6=A8=A1=E5=BC=8F=E4=B8=BA?= =?UTF-8?q?=E9=9D=9E=E9=98=BB=E5=A1=9E=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiaziyang --- test/unittest/platform/common/uart_test.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unittest/platform/common/uart_test.c b/test/unittest/platform/common/uart_test.c index ea7f59ffc..7700323b3 100644 --- a/test/unittest/platform/common/uart_test.c +++ b/test/unittest/platform/common/uart_test.c @@ -35,6 +35,10 @@ static int32_t UartWriteTest(struct UartTest *test) static int32_t UartReadTest(struct UartTest *test) { + if (UartSetTransMode(test->handle, UART_MODE_RD_NONBLOCK) != HDF_SUCCESS) { + HDF_LOGE("%s: error", __func__); + return HDF_FAILURE; + } if (UartRead(test->handle, test->rbuf, test->len) != 0) { HDF_LOGE("%s: error", __func__); return HDF_FAILURE; -- Gitee From 96467bf9c36bede695fdd99b869d342ac3abf6e7 Mon Sep 17 00:00:00 2001 From: kevin Date: Tue, 27 Jul 2021 16:05:58 +0800 Subject: [PATCH 032/205] modify vibrator debug Signed-off-by: kevin Change-Id: I95bb0afc981be925bec2f6f4625920ec135733a3 --- model/misc/vibrator/driver/src/vibrator_haptic.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/model/misc/vibrator/driver/src/vibrator_haptic.c b/model/misc/vibrator/driver/src/vibrator_haptic.c index 39eacb6f3..9bd5ae451 100644 --- a/model/misc/vibrator/driver/src/vibrator_haptic.c +++ b/model/misc/vibrator/driver/src/vibrator_haptic.c @@ -74,13 +74,13 @@ static int32_t ParserHapticEffect(struct DeviceResourceIface *parser, const stru count = parser->GetElemNum(hapticNode, hapticAttr->name); // Minimum of two elements, including the type and sequence. if (count <= 1 || count > VIBRATOR_HAPTIC_SEQ_MAX) { - HDF_LOGD("%s: haptic [%s] parser seq count fail", __func__, hapticAttr->name); + HDF_LOGE("%s: haptic [%s] parser seq count fail", __func__, hapticAttr->name); continue; } effectNode = MallocEffectNode(count * VIBRATOR_HAPTIC_SEQ_SIZE); if (effectNode == NULL) { - HDF_LOGD("%s: malloc effect effectNode fail", __func__); + HDF_LOGE("%s: malloc effect effectNode fail", __func__); continue; } effectNode->effect = hapticAttr->name; @@ -201,17 +201,14 @@ void HapticTimerEntry(uintptr_t para) if (hapticData->effectType == VIBRATOR_TYPE_TIME) { duration = ProcessHapticTime(hapticData); - HDF_LOGE("%s:ProcessHapticTime duration[%d]", __func__, duration); } if (hapticData->effectType == VIBRATOR_TYPE_EFFECT) { duration = ProcessHapticEffect(hapticData); - HDF_LOGE("%s:ProcessHapticEffect duration[%d]", __func__, duration); } duration = ((duration > 0) && (duration < VIBRATOR_MIN_WAIT_TIME)) ? VIBRATOR_MIN_WAIT_TIME : duration; if ((duration > 0) && (OsalTimerSetTimeout(&hapticData->timer, duration) == HDF_SUCCESS)) { - HDF_LOGD("%s: modify haptic timer duration[%d]", __func__, duration); return; } -- Gitee From daf692f9a012e1d3218b1e8835d497cec5e9ccc4 Mon Sep 17 00:00:00 2001 From: yafeng_wang Date: Tue, 27 Jul 2021 16:25:40 +0800 Subject: [PATCH 033/205] feat: Add ADC driver framework and test cases --- include/platform/adc_if.h | 37 ++ support/platform/include/adc_core.h | 74 ++++ support/platform/src/adc_core.c | 399 ++++++++++++++++++ support/platform/src/adc_if.c | 54 +++ .../test/unittest/common/hdf_adc_test.cpp | 83 ++++ test/unittest/common/hdf_main_test.c | 6 + .../platform/common/adc_driver_test.c | 127 ++++++ test/unittest/platform/common/adc_test.c | 256 +++++++++++ test/unittest/platform/common/adc_test.h | 48 +++ test/unittest/platform/hdf_adc_entry_test.c | 26 ++ test/unittest/platform/hdf_adc_entry_test.h | 16 + 11 files changed, 1126 insertions(+) create mode 100644 include/platform/adc_if.h create mode 100644 support/platform/include/adc_core.h create mode 100644 support/platform/src/adc_core.c create mode 100644 support/platform/src/adc_if.c create mode 100644 support/platform/test/unittest/common/hdf_adc_test.cpp create mode 100644 test/unittest/platform/common/adc_driver_test.c create mode 100644 test/unittest/platform/common/adc_test.c create mode 100644 test/unittest/platform/common/adc_test.h create mode 100644 test/unittest/platform/hdf_adc_entry_test.c create mode 100644 test/unittest/platform/hdf_adc_entry_test.h diff --git a/include/platform/adc_if.h b/include/platform/adc_if.h new file mode 100644 index 000000000..79c06a0a0 --- /dev/null +++ b/include/platform/adc_if.h @@ -0,0 +1,37 @@ +/* + * 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 ADC_IF_H +#define ADC_IF_H + +#include "hdf_platform.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +struct AdcIoMsg { + uint32_t number; + uint32_t channel; +}; + +DevHandle AdcOpen(uint32_t num); + +void AdcClose(DevHandle handle); + +int32_t AdcRead(DevHandle handle, uint32_t channel, uint32_t *val); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* ADC_IF_H */ diff --git a/support/platform/include/adc_core.h b/support/platform/include/adc_core.h new file mode 100644 index 000000000..e0e47b521 --- /dev/null +++ b/support/platform/include/adc_core.h @@ -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. + */ + +#ifndef ADC_CORE_H +#define ADC_CORE_H + +#include "osal_spinlock.h" +#include "hdf_base.h" +#include "adc_if.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#define ADC_DEVICES_MAX 15 + +struct AdcDevice; +struct AdcMethod; +struct AdcLockMethod; + +struct AdcDevice { + const struct AdcMethod *ops; + OsalSpinlock spin; + uint32_t devNum; + uint32_t chanNum; + const struct AdcLockMethod *lockOps; + void *priv; +}; + +struct AdcMethod { + int32_t (*read)(struct AdcDevice *device, uint32_t channel, uint32_t *val); + int32_t (*start)(struct AdcDevice *device); + int32_t (*stop)(struct AdcDevice *device); +}; + +struct AdcLockMethod { + int32_t (*lock)(struct AdcDevice *device); + void (*unlock)(struct AdcDevice *device); +}; + +enum AdcIoCmd { + ADC_IO_READ = 0, + ADC_IO_OPEN, + ADC_IO_CLOSE, +}; + +int32_t AdcDeviceAdd(struct AdcDevice *device); + +void AdcDeviceRemove(struct AdcDevice *device); + +struct AdcDevice *AdcDeviceGet(uint32_t number); + +void AdcDevicePut(struct AdcDevice *device); + +int32_t AdcDeviceRead(struct AdcDevice *device, uint32_t channel, uint32_t *val); + +int32_t AdcDeviceStart(struct AdcDevice *device); + +int32_t AdcDeviceStop(struct AdcDevice *device); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* ADC_CORE_H */ diff --git a/support/platform/src/adc_core.c b/support/platform/src/adc_core.c new file mode 100644 index 000000000..a5178ab59 --- /dev/null +++ b/support/platform/src/adc_core.c @@ -0,0 +1,399 @@ +/* + * 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 "adc_core.h" +#include "hdf_device_desc.h" +#include "hdf_log.h" +#include "osal_mem.h" +#include "osal_spinlock.h" +#include "osal_time.h" +#include "plat_common.h" +#include "plat_log.h" + +#define HDF_LOG_TAG adc_core_c +#define LOCK_WAIT_SECONDS_M 1 +#define ADC_BUFF_SIZE 4 + +struct AdcManager { + struct IDeviceIoService service; + struct HdfDeviceObject *device; + struct AdcDevice *devices[ADC_DEVICES_MAX]; + OsalSpinlock spin; +}; + +static struct AdcManager *g_adcManager = NULL; + +static int32_t AdcDeviceLockDefault(struct AdcDevice *device) +{ + if (device == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + return OsalSpinLock(&device->spin); +} + +static void AdcDeviceUnlockDefault(struct AdcDevice *device) +{ + if (device == NULL) { + return; + } + (void)OsalSpinUnlock(&device->spin); +} + +static const struct AdcLockMethod g_adcLockOpsDefault = { + .lock = AdcDeviceLockDefault, + .unlock = AdcDeviceUnlockDefault, +}; + +static int32_t AdcManagerAddDevice(struct AdcDevice *device) +{ + int32_t ret; + struct AdcManager *manager = g_adcManager; + + if (device->devNum >= ADC_DEVICES_MAX) { + HDF_LOGE("%s: devNum:%u exceed", __func__, device->devNum); + return HDF_ERR_INVALID_OBJECT; + } + + if (manager == NULL) { + HDF_LOGE("%s: get adc manager fail", __func__); + return HDF_ERR_NOT_SUPPORT; + } + + if (OsalSpinLockIrq(&manager->spin) != HDF_SUCCESS) { + HDF_LOGE("%s: lock adc manager fail", __func__); + return HDF_ERR_DEVICE_BUSY; + } + + if (manager->devices[device->devNum] != NULL) { + HDF_LOGE("%s: adc device num:%u already exits", __func__, device->devNum); + ret = HDF_FAILURE; + } else { + manager->devices[device->devNum] = device; + ret = HDF_SUCCESS; + } + + (void)OsalSpinUnlockIrq(&manager->spin); + return ret; +} + +static void AdcManagerRemoveDevice(struct AdcDevice *device) +{ + struct AdcManager *manager = g_adcManager; + + if (device->devNum < 0 || device->devNum >= ADC_DEVICES_MAX) { + HDF_LOGE("%s: invalid devNum:%u", __func__, device->devNum); + return; + } + + if (manager == NULL) { + HDF_LOGE("%s: get adc manager fail", __func__); + return; + } + + if (OsalSpinLockIrq(&manager->spin) != HDF_SUCCESS) { + HDF_LOGE("%s: lock adc manager fail", __func__); + return; + } + + if (manager->devices[device->devNum] != device) { + HDF_LOGE("%s: adc device(%u) not in manager", __func__, device->devNum); + } else { + manager->devices[device->devNum] = NULL; + } + + (void)OsalSpinUnlockIrq(&manager->spin); +} + +static struct AdcDevice *AdcManagerFindDevice(uint32_t number) +{ + struct AdcDevice *device = NULL; + struct AdcManager *manager = g_adcManager; + + if (number < 0 || number >= ADC_DEVICES_MAX) { + HDF_LOGE("%s: invalid devNum:%u", __func__, number); + return NULL; + } + + if (manager == NULL) { + HDF_LOGE("%s: get adc manager fail", __func__); + return NULL; + } + + if (OsalSpinLockIrq(&manager->spin) != HDF_SUCCESS) { + HDF_LOGE("%s: lock adc manager fail", __func__); + return NULL; + } + + device = manager->devices[number]; + (void)OsalSpinUnlockIrq(&manager->spin); + + return device; +} + +int32_t AdcDeviceAdd(struct AdcDevice *device) +{ + int32_t ret; + + if (device == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + + if (device->ops == NULL) { + HDF_LOGE("%s: no ops supplied", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (device->lockOps == NULL) { + HDF_LOGI("%s: use default lockOps!", __func__); + device->lockOps = &g_adcLockOpsDefault; + } + + if (OsalSpinInit(&device->spin) != HDF_SUCCESS) { + HDF_LOGE("%s: init lock failed", __func__); + return HDF_FAILURE; + } + + ret = AdcManagerAddDevice(device); + if (ret != HDF_SUCCESS) { + (void)OsalSpinDestroy(&device->spin); + } + return ret; +} + +void AdcDeviceRemove(struct AdcDevice *device) +{ + if (device == NULL) { + return; + } + AdcManagerRemoveDevice(device); + (void)OsalSpinDestroy(&device->spin); +} + +struct AdcDevice *AdcDeviceGet(uint32_t number) +{ + return AdcManagerFindDevice(number); +} + +void AdcDevicePut(struct AdcDevice *device) +{ + (void)device; +} + +static inline int32_t AdcDeviceLock(struct AdcDevice *device) +{ + if (device->lockOps == NULL || device->lockOps->lock == NULL) { + return HDF_ERR_NOT_SUPPORT; + } + return device->lockOps->lock(device); +} + +static inline void AdcDeviceUnlock(struct AdcDevice *device) +{ + if (device->lockOps != NULL && device->lockOps->unlock != NULL) { + device->lockOps->unlock(device); + } +} + +int32_t AdcDeviceRead(struct AdcDevice *device, uint32_t channel, uint32_t *val) +{ + int32_t ret; + + if (device == NULL) { + HDF_LOGE("%s: device is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (device->ops == NULL || device->ops->read == NULL) { + HDF_LOGE("%s: ops or read is null", __func__); + return HDF_ERR_NOT_SUPPORT; + } + + if (val == NULL) { + HDF_LOGE("%s: invalid val pointer!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (AdcDeviceLock(device) != HDF_SUCCESS) { + HDF_LOGE("%s: lock add device failed", __func__); + return HDF_ERR_DEVICE_BUSY; + } + + ret = device->ops->read(device, channel, val); + AdcDeviceUnlock(device); + return ret; +} + +int32_t AdcDeviceStart(struct AdcDevice *device) +{ + int32_t ret; + + if (device == NULL) { + HDF_LOGE("%s: device is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (device->ops == NULL || device->ops->start == NULL) { + HDF_LOGE("%s: ops or start is null", __func__); + return HDF_ERR_NOT_SUPPORT; + } + + if (AdcDeviceLock(device) != HDF_SUCCESS) { + HDF_LOGE("%s: lock add device failed", __func__); + return HDF_ERR_DEVICE_BUSY; + } + + ret = device->ops->start(device); + AdcDeviceUnlock(device); + return ret; +} + +int32_t AdcDeviceStop(struct AdcDevice *device) +{ + int32_t ret; + + if (device == NULL) { + HDF_LOGE("%s: device is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (device->ops == NULL || device->ops->stop == NULL) { + HDF_LOGE("%s: ops or stop is null", __func__); + return HDF_ERR_NOT_SUPPORT; + } + + if (AdcDeviceLock(device) != HDF_SUCCESS) { + HDF_LOGE("%s: lock add device failed", __func__); + return HDF_ERR_DEVICE_BUSY; + } + + ret = device->ops->stop(device); + AdcDeviceUnlock(device); + return ret; +} + +static int32_t AdcManagerIoOpen(struct HdfSBuf *data, struct HdfSBuf *reply) +{ + uint32_t number; + + if (!HdfSbufReadUint32(data, &number)) { + return HDF_ERR_IO; + } + + if (number < 0 || number >= ADC_DEVICES_MAX || reply == NULL) { + return HDF_ERR_INVALID_PARAM; + } + + if (AdcDeviceGet(number) == NULL) { + return HDF_ERR_NOT_SUPPORT; + } + + if (!HdfSbufWriteUint32(reply, number)) { + return HDF_ERR_IO; + } + return HDF_SUCCESS; +} + +static int32_t AdcManagerIoClose(struct HdfSBuf *data, struct HdfSBuf *reply) +{ + uint32_t number; + + if (!HdfSbufReadUint32(data, &number)) { + return HDF_ERR_IO; + } + + if (number < 0 || number >= ADC_DEVICES_MAX) { + return HDF_ERR_INVALID_PARAM; + } + AdcDevicePut(AdcManagerFindDevice(number)); + return HDF_SUCCESS; +} + +static int32_t AdcManagerIoRead(struct HdfSBuf *data, struct HdfSBuf *reply) +{ + (void)data; + (void)reply; + return HDF_SUCCESS; +} + +static int32_t AdcManagerDispatch(struct HdfDeviceIoClient *client, int cmd, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + + switch (cmd) { + case ADC_IO_OPEN: + return AdcManagerIoOpen(data, reply); + case ADC_IO_CLOSE: + return AdcManagerIoClose(data, reply); + case ADC_IO_READ: + return AdcManagerIoRead(data, reply); + default: + ret = HDF_ERR_NOT_SUPPORT; + break; + } + return ret; +} + +static int32_t AdcManagerInit(struct HdfDeviceObject *device) +{ + int32_t ret; + struct AdcManager *manager = NULL; + + HDF_LOGI("%s: Enter", __func__); + if (device == NULL) { + HDF_LOGE("%s: device is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + manager = (struct AdcManager *)OsalMemCalloc(sizeof(*manager)); + if (manager == NULL) { + HDF_LOGE("%s: alloc manager failed", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + ret = OsalSpinInit(&manager->spin); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: spinlock init failed", __func__); + OsalMemFree(manager); + return HDF_FAILURE; + } + + manager->device = device; + g_adcManager = manager; + device->service = &manager->service; + device->service->Dispatch = AdcManagerDispatch; + return HDF_SUCCESS; +} + +static void AdcManagerRelease(struct HdfDeviceObject *device) +{ + struct AdcManager *manager = NULL; + + HDF_LOGI("%s: Enter", __func__); + if (device == NULL) { + HDF_LOGE("%s: device is null", __func__); + return; + } + + manager = (struct AdcManager *)device->service; + if (manager == NULL) { + HDF_LOGI("%s: no service bind", __func__); + return; + } + + g_adcManager = NULL; + OsalMemFree(manager); +} + +struct HdfDriverEntry g_adcManagerEntry = { + .moduleVersion = 1, + .Init = AdcManagerInit, + .Release = AdcManagerRelease, + .moduleName = "HDF_PLATFORM_ADC_MANAGER", +}; +HDF_INIT(g_adcManagerEntry); diff --git a/support/platform/src/adc_if.c b/support/platform/src/adc_if.c new file mode 100644 index 000000000..23c5fcc8b --- /dev/null +++ b/support/platform/src/adc_if.c @@ -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. + */ + +#include "adc_if.h" +#include "adc_core.h" +#include "hdf_log.h" +#include "osal_mem.h" +#include "securec.h" +#define HDF_LOG_TAG adc_if_c +#define ADC_SERVICE_NAME "HDF_PLATFORM_ADC_MANAGER" + +DevHandle AdcOpen(uint32_t number) +{ + int32_t ret; + struct AdcDevice *device = NULL; + + device = AdcDeviceGet(number); + if (device == NULL) { + return NULL; + } + + ret = AdcDeviceStart(device); + if (ret != HDF_SUCCESS) { + return NULL; + } + + return (DevHandle)device; +} + +void AdcClose(DevHandle handle) +{ + struct AdcDevice *device = (struct AdcDevice *)handle; + + if (device == NULL) { + return; + } + + (void)AdcDeviceStop(device); + AdcDevicePut(device); +} + +int32_t AdcRead(DevHandle handle, uint32_t channel, uint32_t *val) +{ + if (handle == NULL) { + HDF_LOGE("%s: invalid handle!", __func__); + return HDF_ERR_INVALID_PARAM; + } + return AdcDeviceRead((struct AdcDevice *)handle, channel, val); +} diff --git a/support/platform/test/unittest/common/hdf_adc_test.cpp b/support/platform/test/unittest/common/hdf_adc_test.cpp new file mode 100644 index 000000000..a486d7eac --- /dev/null +++ b/support/platform/test/unittest/common/hdf_adc_test.cpp @@ -0,0 +1,83 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include "hdf_uhdf_test.h" +#include "adc_test.h" +#include "hdf_io_service_if.h" + +using namespace testing::ext; + +class HdfLiteAdcTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void HdfLiteAdcTest::SetUpTestCase() +{ + HdfTestOpenService(); +} + +void HdfLiteAdcTest::TearDownTestCase() +{ + HdfTestCloseService(); +} + +void HdfLiteAdcTest::SetUp() +{ +} + +void HdfLiteAdcTest::TearDown() +{ +} + +/** + * @tc.name: AdcTestRead001 + * @tc.desc: adc read test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfLiteAdcTest, AdcTestRead001, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_ADC_TYPE, ADC_TEST_CMD_READ, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: AdcTestMultiThread001 + * @tc.desc: adc multi thread test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfLiteAdcTest, AdcTestMultiThread001, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_ADC_TYPE, ADC_TEST_CMD_MULTI_THREAD, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: AdcTestReliability001 + * @tc.desc: adc reliability test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfLiteAdcTest, AdcTestReliability001, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_ADC_TYPE, ADC_TEST_CMD_RELIABILITY, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + diff --git a/test/unittest/common/hdf_main_test.c b/test/unittest/common/hdf_main_test.c index af2847f98..7c5be8c78 100644 --- a/test/unittest/common/hdf_main_test.c +++ b/test/unittest/common/hdf_main_test.c @@ -20,6 +20,9 @@ #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2C) || defined(CONFIG_DRIVERS_HDF_PLATFORM_I2C) #include "hdf_i2c_entry_test.h" #endif +#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_ADC) || defined(CONFIG_DRIVERS_HDF_PLATFORM_ADC) +#include "hdf_adc_entry_test.h" +#endif #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_SPI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_SPI) #include "hdf_spi_entry_test.h" #endif @@ -68,6 +71,9 @@ HdfTestFuncList g_hdfTestFuncList[] = { #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2C) || defined(CONFIG_DRIVERS_HDF_PLATFORM_I2C) { TEST_PAL_I2C_TYPE, HdfI2cTestEntry }, #endif +#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_ADC) || defined(CONFIG_DRIVERS_HDF_PLATFORM_ADC) + { TEST_PAL_ADC_TYPE, HdfAdcTestEntry }, +#endif #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_SPI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_SPI) { TEST_PAL_SPI_TYPE, HdfSpiUnitTestEntry }, #endif diff --git a/test/unittest/platform/common/adc_driver_test.c b/test/unittest/platform/common/adc_driver_test.c new file mode 100644 index 000000000..eacb5f440 --- /dev/null +++ b/test/unittest/platform/common/adc_driver_test.c @@ -0,0 +1,127 @@ +/* + * 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 "adc_test.h" +#include "device_resource_if.h" +#include "hdf_base.h" +#include "hdf_device_desc.h" +#include "hdf_log.h" + +#define HDF_LOG_TAG adc_test_driver_c + +static struct AdcTestConfig g_config; + +static int32_t AdcTestDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + HDF_LOGD("%s: enter!", __func__); + + if (cmd == 0) { + if (reply == NULL) { + HDF_LOGE("%s: reply is null!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (!HdfSbufWriteBuffer(reply, &g_config, sizeof(g_config))) { + HDF_LOGE("%s: write reply failed", __func__); + return HDF_ERR_IO; + } + } else { + return HDF_ERR_NOT_SUPPORT; + } + + return HDF_SUCCESS; +} + +static int32_t AdcTestReadConfig(struct AdcTestConfig *config, const struct DeviceResourceNode *node) +{ + int32_t ret; + struct DeviceResourceIface *drsOps = NULL; + + drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL || drsOps->GetUint32 == NULL) { + HDF_LOGE("%s: invalid drs ops", __func__); + return HDF_FAILURE; + } + + ret = drsOps->GetUint32(node, "devNum", &config->devNum, 0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read devNum failed", __func__); + return ret; + } + + ret = drsOps->GetUint32(node, "channel", &config->channel, 0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read channel failed", __func__); + return ret; + } + + ret = drsOps->GetUint32(node, "maxChannel", &config->maxChannel, 0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read maxChannel failed", __func__); + return ret; + } + + ret = drsOps->GetUint32(node, "dataWidth", &config->dataWidth, 0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read dataWidth failed", __func__); + return ret; + } + + ret = drsOps->GetUint32(node, "rate", &config->rate, 0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read rate failed", __func__); + return ret; + } + + return HDF_SUCCESS; +} + +static int32_t AdcTestBind(struct HdfDeviceObject *device) +{ + int32_t ret; + static struct IDeviceIoService service; + + if (device == NULL || device->property == NULL) { + HDF_LOGE("%s: device or config is null!", __func__); + return HDF_ERR_IO; + } + + ret = AdcTestReadConfig(&g_config, device->property); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read config failed", __func__); + return ret; + } + service.Dispatch = AdcTestDispatch; + device->service = &service; + HDF_LOGI("%s: Done!", __func__); + return HDF_SUCCESS; +} + +static int32_t AdcTestInit(struct HdfDeviceObject *device) +{ + (void)device; + HDF_LOGI("%s: Done!", __func__); + return HDF_SUCCESS; +} + +static void AdcTestRelease(struct HdfDeviceObject *device) +{ + if (device != NULL) { + device->service = NULL; + } + HDF_LOGI("%s: Done!", __func__); + return; +} + +struct HdfDriverEntry g_adcTestEntry = { + .moduleVersion = 1, + .Bind = AdcTestBind, + .Init = AdcTestInit, + .Release = AdcTestRelease, + .moduleName = "PLATFORM_ADC_TEST", +}; +HDF_INIT(g_adcTestEntry); diff --git a/test/unittest/platform/common/adc_test.c b/test/unittest/platform/common/adc_test.c new file mode 100644 index 000000000..1ab30f035 --- /dev/null +++ b/test/unittest/platform/common/adc_test.c @@ -0,0 +1,256 @@ +/* + * 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 "adc_test.h" +#include "adc_if.h" +#include "hdf_base.h" +#include "hdf_io_service_if.h" +#include "hdf_log.h" +#include "osal_mem.h" +#include "securec.h" +#include "osal_thread.h" +#include "osal_time.h" + + +#define HDF_LOG_TAG adc_test_c + +#define TEST_ADC_VAL_NUM 50 +#define ADC_TEST_WAIT_TIMES 100 +#define ADC_TEST_STACK_SIZE (1024 * 64) + +static int32_t AdcTestGetConfig(struct AdcTestConfig *config) +{ + int32_t ret; + struct HdfSBuf *reply = NULL; + struct HdfIoService *service = NULL; + const void *buf = NULL; + uint32_t len; + + HDF_LOGD("%s: enter", __func__); + service = HdfIoServiceBind("ADC_TEST"); + if (service == NULL) { + return HDF_ERR_NOT_SUPPORT; + } + + reply = HdfSBufObtain(sizeof(*config) + sizeof(uint64_t)); + if (reply == NULL) { + HDF_LOGE("%s: failed to obtain reply", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + ret = service->dispatcher->Dispatch(&service->object, 0, NULL, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: remote dispatch failed", __func__); + return ret; + } + + if (!HdfSbufReadBuffer(reply, &buf, &len)) { + HDF_LOGE("%s: read buf failed", __func__); + HdfSBufRecycle(reply); + return HDF_ERR_IO; + } + + if (len != sizeof(*config)) { + HDF_LOGE("%s: config size:%zu, read size:%u", __func__, sizeof(*config), len); + HdfSBufRecycle(reply); + return HDF_ERR_IO; + } + + if (memcpy_s(config, sizeof(*config), buf, sizeof(*config)) != EOK) { + HDF_LOGE("%s: memcpy buf failed", __func__); + HdfSBufRecycle(reply); + return HDF_ERR_IO; + } + HdfSBufRecycle(reply); + HDF_LOGD("%s: exit", __func__); + return HDF_SUCCESS; +} + +struct AdcTester *AdcTesterGet(void) +{ + int32_t ret; + static struct AdcTester tester; + static bool hasInit = false; + + HDF_LOGE("%s: enter", __func__); + if (hasInit) { + return &tester; + } + ret = AdcTestGetConfig(&tester.config); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read config failed:%d", __func__, ret); + return NULL; + } + tester.handle = AdcOpen(tester.config.devNum); + if (tester.handle == NULL) { + HDF_LOGE("%s: open adc device:%u failed", __func__, tester.config.devNum); + return NULL; + } + hasInit = true; + HDF_LOGI("%s: done", __func__); + return &tester; +} + +int32_t AdcTestRead(void) +{ + struct AdcTester *tester = NULL; + uint32_t value[TEST_ADC_VAL_NUM]; + int32_t ret; + int i; + + HDF_LOGI("%s: enter", __func__); + tester = AdcTesterGet(); + if (tester == NULL) { + HDF_LOGE("%s: get tester failed", __func__); + return HDF_ERR_INVALID_OBJECT; + } + for (i = 0; i < TEST_ADC_VAL_NUM; i++) { + ret = AdcRead(tester->handle, tester->config.channel, &value[i]); + if (ret != HDF_SUCCESS || value[i] >= (1 << tester->config.dataWidth)) { + HDF_LOGE("%s: read value invalid:%u, ret:%d", __func__, value[i], ret); + return HDF_ERR_IO; + } + } + + HDF_LOGI("%s: done", __func__); + return HDF_SUCCESS; +} + +static int AdcTestThreadFunc(void *param) +{ + struct AdcTester *tester = NULL; + uint32_t val; + int i; + int32_t ret; + + HDF_LOGI("%s: enter", __func__); + tester = AdcTesterGet(); + if (tester == NULL) { + HDF_LOGE("%s: get tester failed", __func__); + *((int32_t *)param) = 1; + return HDF_ERR_INVALID_OBJECT; + } + + for (i = 0; i < ADC_TEST_WAIT_TIMES; i++) { + ret = AdcRead(tester->handle, tester->config.channel, &val); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read value invalid:%u, ret:%d", __func__, val, ret); + return HDF_ERR_IO; + } + } + + *((int32_t *)param) = 1; + HDF_LOGI("%s: done", __func__); + return val; +} + +int32_t AdcTestMultiThread(void) +{ + int32_t ret; + struct OsalThread thread1, thread2; + struct OsalThreadParam cfg1, cfg2; + int32_t count1, count2; + + count1 = count2 = 0; + HDF_LOGI("%s: enter", __func__); + ret = OsalThreadCreate(&thread1, (OsalThreadEntry)AdcTestThreadFunc, (void *)&count1); + if (ret != HDF_SUCCESS) { + HDF_LOGE("create test thread1 fail:%d", ret); + return HDF_FAILURE; + } + + ret = OsalThreadCreate(&thread2, (OsalThreadEntry)AdcTestThreadFunc, (void *)&count2); + if (ret != HDF_SUCCESS) { + HDF_LOGE("create test thread1 fail:%d", ret); + return HDF_FAILURE; + } + + cfg1.name = "AdcTestThread-1"; + cfg2.name = "AdcTestThread-2"; + cfg1.priority = cfg2.priority = OSAL_THREAD_PRI_DEFAULT; + cfg1.stackSize = cfg2.stackSize = ADC_TEST_STACK_SIZE; + + ret = OsalThreadStart(&thread1, &cfg1); + if (ret != HDF_SUCCESS) { + HDF_LOGE("start test thread1 fail:%d", ret); + return HDF_FAILURE; + } + + ret = OsalThreadStart(&thread2, &cfg2); + if (ret != HDF_SUCCESS) { + HDF_LOGE("start test thread2 fail:%d", ret); + return HDF_FAILURE; + } + + while (count1 == 0 || count2 == 0) { + HDF_LOGE("waitting testing thread finish..."); + OsalMSleep(ADC_TEST_WAIT_TIMES); + } + + (void)OsalThreadDestroy(&thread1); + (void)OsalThreadDestroy(&thread2); + HDF_LOGI("%s: done", __func__); + return HDF_SUCCESS; +} + +int32_t AdcTestReliability(void) +{ + struct AdcTester *tester = NULL; + uint32_t val; + + HDF_LOGI("%s: enter", __func__); + tester = AdcTesterGet(); + if (tester == NULL || tester->handle == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + HDF_LOGD("%s: test dfr for AdcRead ...", __func__); + // invalid handle + (void)AdcRead(NULL, tester->config.channel, &val); + // invalid channel + (void)AdcRead(tester->handle, tester->config.maxChannel + 1, &val); + // invalid val pointer + (void)AdcRead(tester->handle, tester->config.channel, NULL); + HDF_LOGI("%s: done", __func__); + return HDF_SUCCESS; +} + +struct AdcTestEntry { + int cmd; + int32_t (*func)(void); + const char *name; +}; + +static struct AdcTestEntry g_entry[] = { + { ADC_TEST_CMD_READ, AdcTestRead, "AdcTestRead" }, + { ADC_TEST_CMD_MULTI_THREAD, AdcTestMultiThread, "AdcTestMultiThread" }, + { ADC_TEST_CMD_RELIABILITY, AdcTestReliability, "AdcTestReliability" }, +}; + +int32_t AdcTestExecute(int cmd) +{ + uint32_t i; + int32_t ret = HDF_ERR_NOT_SUPPORT; + + if (cmd > ADC_TEST_CMD_MAX) { + HDF_LOGE("%s: invalid cmd:%d", __func__, cmd); + ret = HDF_ERR_NOT_SUPPORT; + goto __EXIT__; + } + + for (i = 0; i < sizeof(g_entry) / sizeof(g_entry[0]); i++) { + if (g_entry[i].cmd != cmd || g_entry[i].func == NULL) { + continue; + } + ret = g_entry[i].func(); + break; + } + +__EXIT__: + HDF_LOGE("[%s][======cmd:%d====ret:%d======]", __func__, cmd, ret); + return ret; +} diff --git a/test/unittest/platform/common/adc_test.h b/test/unittest/platform/common/adc_test.h new file mode 100644 index 000000000..4f1e1bbab --- /dev/null +++ b/test/unittest/platform/common/adc_test.h @@ -0,0 +1,48 @@ +/* + * 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 ADC_TEST_H +#define ADC_TEST_H + +#include "adc_if.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +struct AdcTestConfig { + uint32_t devNum; + uint32_t channel; + uint32_t maxChannel; + uint32_t dataWidth; + uint32_t rate; +}; + +struct AdcTester { + struct AdcTestConfig config; + DevHandle handle; +}; + +enum AdcTestCmd { + ADC_TEST_CMD_READ = 0, + ADC_TEST_CMD_MULTI_THREAD, + ADC_TEST_CMD_RELIABILITY, + ADC_TEST_CMD_MAX, +}; + +int32_t AdcTestExecute(int cmd); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* ADC_TEST_H */ diff --git a/test/unittest/platform/hdf_adc_entry_test.c b/test/unittest/platform/hdf_adc_entry_test.c new file mode 100644 index 000000000..63960616b --- /dev/null +++ b/test/unittest/platform/hdf_adc_entry_test.c @@ -0,0 +1,26 @@ +/* + * 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 "hdf_adc_entry_test.h" +#include "hdf_log.h" +#include "adc_test.h" +#include "hdf_log.h" + +#define HDF_LOG_TAG hdf_adc_entry_test + +int32_t HdfAdcTestEntry(HdfTestMsg *msg) +{ + HDF_LOGE("%s: enter", __func__); + if (msg == NULL) { + return HDF_FAILURE; + } + + msg->result = AdcTestExecute(msg->subCmd); + + return HDF_SUCCESS; +} diff --git a/test/unittest/platform/hdf_adc_entry_test.h b/test/unittest/platform/hdf_adc_entry_test.h new file mode 100644 index 000000000..f239f2931 --- /dev/null +++ b/test/unittest/platform/hdf_adc_entry_test.h @@ -0,0 +1,16 @@ +/* + * 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 HDF_ADC_ENTRY_TEST_H +#define HDF_ADC_ENTRY_TEST_H + +#include "hdf_main_test.h" + +int32_t HdfAdcTestEntry(HdfTestMsg *msg); + +#endif /* HDF_ADC_ENTRY_TEST_H */ \ No newline at end of file -- Gitee From d5a5d7193c1fc93dc398150e693da4731454b58a Mon Sep 17 00:00:00 2001 From: linux Date: Tue, 27 Jul 2021 17:37:40 +0800 Subject: [PATCH 034/205] correct USE_AFTER_FREE Signed-off-by: linux --- core/manager/src/devmgr_service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/manager/src/devmgr_service.c b/core/manager/src/devmgr_service.c index da78d39e2..81a6c8af0 100644 --- a/core/manager/src/devmgr_service.c +++ b/core/manager/src/devmgr_service.c @@ -319,8 +319,8 @@ void DevmgrServiceRelease(struct HdfObject *object) struct DevHostServiceClnt *hostClnt = NULL; struct DevHostServiceClnt *hostClntTmp = NULL; DLIST_FOR_EACH_ENTRY_SAFE(hostClnt, hostClntTmp, &devmgrService->hosts, struct DevHostServiceClnt, node) { - DevHostServiceClntDelete(hostClnt); DListRemove(&hostClnt->node); + DevHostServiceClntDelete(hostClnt); } OsalMutexDestroy(&devmgrService->devMgrMutex); -- Gitee From ae677e4fb0ca192a946d1bed941d3f14f4335bd7 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Wed, 28 Jul 2021 03:21:35 +0000 Subject: [PATCH 035/205] =?UTF-8?q?Description:L2=20p2p=20=E7=89=B9?= =?UTF-8?q?=E6=80=A7=E9=80=82=E9=85=8D=20Feature=20or=20Bugfix:Feature=20B?= =?UTF-8?q?inary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: YOUR_NAME --- include/wifi/hdf_wifi_event.h | 4 + include/wifi/wifi_mac80211_ops.h | 28 +- model/network/wifi/core/module/wifi_base.c | 395 +++++++++++++++++- model/network/wifi/include/hdf_wifi_cmd.h | 10 + .../wifi/platform/include/hdf_wlan_services.h | 7 + .../wifi/platform/src/hdf_wifi_event.c | 45 ++ 6 files changed, 485 insertions(+), 4 deletions(-) diff --git a/include/wifi/hdf_wifi_event.h b/include/wifi/hdf_wifi_event.h index 4aad40b76..3cccdb6ef 100644 --- a/include/wifi/hdf_wifi_event.h +++ b/include/wifi/hdf_wifi_event.h @@ -476,6 +476,10 @@ int32_t HdfWifiEventEapolRecv(const char *name, void *context); */ int32_t HdfWifiEventResetResult(const uint8_t chipId, int32_t resetStatus, const char *ifName); +int32_t HdfWifiEventRemainOnChannel(const struct NetDevice *netDev, uint32_t freq, uint32_t duration); + +int32_t HdfWifiEventCancelRemainOnChannel(const struct NetDevice *netDev, uint32_t freq); + #ifdef __cplusplus #if __cplusplus } diff --git a/include/wifi/wifi_mac80211_ops.h b/include/wifi/wifi_mac80211_ops.h index 4e1244bfb..7869d6c48 100644 --- a/include/wifi/wifi_mac80211_ops.h +++ b/include/wifi/wifi_mac80211_ops.h @@ -168,7 +168,14 @@ enum Ieee80211ChannelWidth { */ enum WlanWorkMode { WLAN_WORKMODE_STA = 2, /**< STA mode */ - WLAN_WORKMODE_AP = 3 /**< AP mode */ + WLAN_WORKMODE_AP = 3, /**< AP mode */ + WLAN_WORKMODE_AP_VLAN, + WLAN_WORKMODE_WDS, + WLAN_WORKMODE_MONITOR, + WLAN_WORKMODE_MESH_POINT, + WLAN_WORKMODE_P2P_CLIENT, + WLAN_WORKMODE_P2P_GO, + WLAN_WORKMODE_P2P_DEVICE, }; /** @@ -302,7 +309,7 @@ struct WlanScanRequest { uint8_t freqsCount; /**< Number of frequencies */ uint8_t *bssid; /**< BSSID to scan for */ struct WlanSSID *ssids; /**< SSIDs to scan for */ - uint16_t *freqs; /**< An array of frequencies */ + uint32_t *freqs; /**< An array of frequencies */ uint32_t extraIEsLen; /**< Length of an extended information element (IE) */ uint8_t *extraIEs; /**< Extended IEs */ }; @@ -581,6 +588,23 @@ struct HdfMac80211BaseOps { * @version 1.0 */ int32_t (*GetHwCapability)(NetDevice *netDev, struct WlanHwCapability **capability); + + int32_t (*RemainOnChannel)(NetDevice *netDev, WifiOnChannel *onChannel); + + int32_t (*CancelRemainOnChannel)(NetDevice *netDev); + + int32_t (*ProbeReqReport)(NetDevice *netDev, int32_t report); + + int32_t (*AddIf)(NetDevice *netDev, WifiIfAdd *ifAdd); + + int32_t (*RemoveIf)(NetDevice *netDev, WifiIfRemove *ifRemove); + + int32_t (*SetApWpsP2pIe)(NetDevice *netDev, WifiAppIe *appIe); + + int32_t (*GetDriverFlag)(struct NetDevice *netDev, WifiGetDrvFlags **params); + + int32_t (*SendAction)(struct NetDevice *netDev, WifiActionData *actionData); + }; /** diff --git a/model/network/wifi/core/module/wifi_base.c b/model/network/wifi/core/module/wifi_base.c index 1857174d7..40406bfa4 100644 --- a/model/network/wifi/core/module/wifi_base.c +++ b/model/network/wifi/core/module/wifi_base.c @@ -719,13 +719,70 @@ static int32_t WifiSendMlme(const RequestContext *context, struct HdfSBuf *reqDa return HDF_SUCCESS; } +int32_t SendAction(struct NetDevice *netdev, WifiActionData *actionData) +{ + struct HdfChipDriver *chipDriver = GetChipDriver(netdev); + if (chipDriver == NULL) { + HDF_LOGE("%s:bad net device found!", __func__); + return HDF_FAILURE; + } + + RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, SendAction); + return chipDriver->ops->SendAction(netdev, actionData); +} + static int32_t WifiCmdSendAction(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData) { + WifiActionData actionData = {0}; + const char *ifName = NULL; + uint32_t dataSize = 0; + struct NetDevice *netdev = NULL; + (void)context; - (void)reqData; (void)rspData; + if (reqData == NULL) { + HDF_LOGE("%s:reqData is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + ifName = HdfSbufReadString(reqData); + if (ifName == NULL) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName"); + return HDF_FAILURE; + } - return HDF_SUCCESS; + if (!HdfSbufReadBuffer(reqData, (const void **)&(actionData.bssid), &dataSize) || + dataSize != ETH_ADDR_LEN) { + HDF_LOGE("%s: %s!ParamName=%s,readSize=%u", __func__, ERROR_DESC_READ_REQ_FAILED, "bssid", dataSize); + return HDF_FAILURE; + } + + if (!HdfSbufReadBuffer(reqData, (const void **)&(actionData.dst), &dataSize) || + dataSize != ETH_ADDR_LEN) { + HDF_LOGE("%s: %s!ParamName=%s,readSize=%u", __func__, ERROR_DESC_READ_REQ_FAILED, "dst", dataSize); + return HDF_FAILURE; + } + + if (!HdfSbufReadBuffer(reqData, (const void **)&(actionData.src), &dataSize) || + dataSize != ETH_ADDR_LEN) { + HDF_LOGE("%s: %s!ParamName=%s,readSize=%u", __func__, ERROR_DESC_READ_REQ_FAILED, "src", dataSize); + return HDF_FAILURE; + } + + if (!HdfSbufReadBuffer(reqData, (const void **)&(actionData.data), &(actionData.dataLen))) { + HDF_LOGE("%s: %s!ParamName=%s,readSize=%u", __func__, ERROR_DESC_READ_REQ_FAILED, "data", actionData.dataLen); + return HDF_FAILURE; + } + netdev = NetDeviceGetInstByName(ifName); + if (netdev == NULL || netdev->netDeviceIf == NULL) { + HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName); + return HDF_FAILURE; + } + + int ret = SendAction(netdev, &actionData); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: fail to remain on channel,%d", __func__, ret); + } + return ret; } static int32_t WifiCmdGetNetworkInfo(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData) @@ -1214,6 +1271,333 @@ static int32_t WifiCmdResetDriver(const RequestContext *context, struct HdfSBuf return ret; } +static int32_t RemainOnChannel(struct NetDevice *netdev, WifiOnChannel *onChannel) +{ + struct HdfChipDriver *chipDriver = GetChipDriver(netdev); + if (chipDriver == NULL) { + HDF_LOGE("%s:bad net device found!", __func__); + return HDF_FAILURE; + } + + RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, RemainOnChannel); + return chipDriver->ops->RemainOnChannel(netdev, onChannel); +} + +static int32_t WifiCmdRemainOnChannel(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData) +{ + int32_t ret; + struct NetDevice *netdev = NULL; + const char *ifName = NULL; + WifiOnChannel wifiOnChannel = {0}; + + (void)context; + if (reqData == NULL || rspData == NULL) { + return HDF_ERR_INVALID_PARAM; + } + ifName = HdfSbufReadString(reqData); + if (ifName == NULL) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName"); + return HDF_FAILURE; + } + netdev = NetDeviceGetInstByName(ifName); + if (netdev == NULL) { + HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName); + return HDF_FAILURE; + } + if (!HdfSbufReadUint32(reqData, &(wifiOnChannel.freq))) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "freq"); + return HDF_FAILURE; + } + if (!HdfSbufReadUint32(reqData, &(wifiOnChannel.duration))) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "duration"); + return HDF_FAILURE; + } + ret = RemainOnChannel(netdev, &wifiOnChannel); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: fail to remain on channel,%d",__func__, ret); + } + return ret; +} + +static int32_t ProbeReqReport(struct NetDevice *netdev, int32_t report) +{ + struct HdfChipDriver *chipDriver = GetChipDriver(netdev); + if (chipDriver == NULL) { + HDF_LOGE("%s:bad net device found!", __func__); + return HDF_FAILURE; + } + + RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, ProbeReqReport); + return chipDriver->ops->ProbeReqReport(netdev, report); +} + +static int32_t WifiCmdProbeReqReport(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData) +{ + int32_t ret; + struct NetDevice *netdev = NULL; + const char *ifName = NULL; + int32_t report; + + (void)context; + if (reqData == NULL || rspData == NULL) { + return HDF_ERR_INVALID_PARAM; + } + ifName = HdfSbufReadString(reqData); + if (ifName == NULL) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName"); + return HDF_FAILURE; + } + netdev = NetDeviceGetInstByName(ifName); + if (netdev == NULL) { + HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName); + return HDF_FAILURE; + } + if (!HdfSbufReadInt32(reqData,&(report))) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "report"); + return HDF_FAILURE; + } + + ret = ProbeReqReport(netdev, report); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: fail to probe req report,%d",__func__, ret); + } + return ret; +} + +static int32_t CancelRemainOnChannel(struct NetDevice *netdev) +{ + struct HdfChipDriver *chipDriver = GetChipDriver(netdev); + if (chipDriver == NULL) { + HDF_LOGE("%s:bad net device found!", __func__); + return HDF_FAILURE; + } + + RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, CancelRemainOnChannel); + return chipDriver->ops->CancelRemainOnChannel(netdev); +} + +static int32_t WifiCmdCancelRemainOnChannel(const RequestContext *context, struct HdfSBuf *reqData, + struct HdfSBuf *rspData) +{ + int32_t ret; + struct NetDevice *netdev = NULL; + const char *ifName = NULL; + + (void)context; + if (reqData == NULL || rspData == NULL) { + return HDF_ERR_INVALID_PARAM; + } + ifName = HdfSbufReadString(reqData); + if (ifName == NULL) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName"); + return HDF_FAILURE; + } + netdev = NetDeviceGetInstByName(ifName); + if (netdev == NULL) { + HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName); + return HDF_FAILURE; + } + + ret = CancelRemainOnChannel(netdev); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: fail to cancel remain on channel,%d",__func__, ret); + } + return ret; +} + +static int32_t AddIf(struct NetDevice *netdev, WifiIfAdd *ifAdd) +{ + struct HdfChipDriver *chipDriver = GetChipDriver(netdev); + if (chipDriver == NULL) { + HDF_LOGE("%s:bad net device found!", __func__); + return HDF_FAILURE; + } + + RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, AddIf); + return chipDriver->ops->AddIf(netdev, ifAdd); +} + +static int32_t WifiCmdAddIf(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData) +{ + int32_t ret; + struct NetDevice *netdev = NULL; + const char *ifName = NULL; + WifiIfAdd ifAdd = {0}; + + (void)context; + if (reqData == NULL || rspData == NULL) { + return HDF_ERR_INVALID_PARAM; + } + ifName = HdfSbufReadString(reqData); + if (ifName == NULL) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName"); + return HDF_FAILURE; + } + netdev = NetDeviceGetInstByName(ifName); + if (netdev == NULL) { + HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName); + return HDF_FAILURE; + } + + if (!HdfSbufReadUint8(reqData, &(ifAdd.type))) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "type"); + return HDF_FAILURE; + } + + ret = AddIf(netdev, &ifAdd); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: fail to cancel remain on channel,%d",__func__, ret); + } + return ret; +} + +static int32_t RemoveIf(struct NetDevice *netdev, WifiIfRemove *ifRemove) +{ + struct HdfChipDriver *chipDriver = GetChipDriver(netdev); + if (chipDriver == NULL) { + HDF_LOGE("%s:bad net device found!", __func__); + return HDF_FAILURE; + } + + RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, RemoveIf); + return chipDriver->ops->RemoveIf(netdev, ifRemove); +} + +static int32_t WifiCmdRemoveIf(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData) +{ + int32_t ret; + struct NetDevice *netdev = NULL; + const char *ifName = NULL; + WifiIfRemove *ifRemove = NULL; + + (void)context; + if (reqData == NULL || rspData == NULL) { + return HDF_ERR_INVALID_PARAM; + } + ifName = HdfSbufReadString(reqData); + if (ifName == NULL) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName"); + return HDF_FAILURE; + } + netdev = NetDeviceGetInstByName(ifName); + if (netdev == NULL) { + HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName); + return HDF_FAILURE; + } + + uint32_t dataSize = 0; + if (!HdfSbufReadBuffer(reqData, (const void **)&(ifRemove), &dataSize) || dataSize != sizeof(WifiIfRemove)) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName"); + return HDF_FAILURE; + } + ret = RemoveIf(netdev, ifRemove); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: fail to remove interface,%d",__func__, ret); + } + return ret; +} + +static int32_t SetApWpsP2pIe(struct NetDevice *netdev, WifiAppIe *appIe) +{ + struct HdfChipDriver *chipDriver = GetChipDriver(netdev); + if (chipDriver == NULL) { + HDF_LOGE("%s:bad net device found!", __func__); + return HDF_FAILURE; + } + + RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, SetApWpsP2pIe); + return chipDriver->ops->SetApWpsP2pIe(netdev, appIe); +} + +static int32_t WifiCmdSetApWpsP2pIe(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData) +{ + int32_t ret; + struct NetDevice *netdev = NULL; + const char *ifName = NULL; + WifiAppIe appIe = {0}; + + (void)context; + if (reqData == NULL || rspData == NULL) { + return HDF_ERR_INVALID_PARAM; + } + ifName = HdfSbufReadString(reqData); + if (ifName == NULL) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName"); + return HDF_FAILURE; + } + netdev = NetDeviceGetInstByName(ifName); + if (netdev == NULL) { + HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName); + return HDF_FAILURE; + } + + if (!HdfSbufReadUint32(reqData, &(appIe.ieLen))) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ieLen"); + return HDF_FAILURE; + } + if (!HdfSbufReadUint8(reqData, &(appIe.appIeType))) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "appIeType"); + return HDF_FAILURE; + } + if (!HdfSbufReadBuffer(reqData, (const void**)&(appIe.ie), &(appIe.ieLen))) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "appIeType"); + return HDF_FAILURE; + } + ret = SetApWpsP2pIe(netdev, &appIe); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: fail to setapwpsp2pie,%d",__func__, ret); + } + return ret; +} + +int32_t GetDriverFlag (struct NetDevice *netdev, WifiGetDrvFlags **params) +{ + struct HdfChipDriver *chipDriver = GetChipDriver(netdev); + if (chipDriver == NULL) { + HDF_LOGE("%s:bad net device found!", __func__); + return HDF_FAILURE; + } + + RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, GetDriverFlag); + return chipDriver->ops->GetDriverFlag(netdev, params); +} + +static int32_t WifiCmdGetDriverFlag(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData) +{ + int32_t ret; + struct NetDevice *netdev = NULL; + const char *ifName = NULL; + WifiGetDrvFlags *params = NULL; + + (void)context; + if (reqData == NULL || rspData == NULL) { + return HDF_ERR_INVALID_PARAM; + } + ifName = HdfSbufReadString(reqData); + if (ifName == NULL) { + HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName"); + return HDF_FAILURE; + } + netdev = NetDeviceGetInstByName(ifName); + if (netdev == NULL) { + HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName); + return HDF_FAILURE; + } + + ret = GetDriverFlag(netdev, ¶ms); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: fail to getdriverflag,%d",__func__, ret); + } + + if (!HdfSbufWriteUint64(rspData, params->drvFlags)) { + HDF_LOGE("%s:%s!", __func__, ERROR_DESC_WRITE_RSP_FAILED); + ret = HDF_ERR_IO; + } + + HDF_LOGE("WifiCmdGetDriverFlag:%lx", params->drvFlags); + return ret; +} + static struct MessageDef g_wifiBaseFeatureCmds[] = { DUEMessage(CMD_BASE_NEW_KEY, WifiCmdNewKey, 0), DUEMessage(CMD_BASE_DEL_KEY, WifiCmdDelKey, 0), @@ -1240,6 +1624,13 @@ static struct MessageDef g_wifiBaseFeatureCmds[] = { DUEMessage(CMD_BASE_GET_IFNAMES, WifiCmdGetIfNamesByChipId, 0), DUEMessage(CMD_BASE_RESET_DRIVER, WifiCmdResetDriver, 0), DUEMessage(CMD_BASE_DO_RESET_PRIVATE, WifiCmdDoResetChip, 0), + DUEMessage(CMD_P2P_PROBE_REQ_REPORT, WifiCmdProbeReqReport, 0), + DUEMessage(CMD_P2P_REMAIN_ON_CHANNEL, WifiCmdRemainOnChannel, 0), + DUEMessage(CMD_P2P_CANCEL_REMAIN_ON_CHANNEL, WifiCmdCancelRemainOnChannel, 0), + DUEMessage(CMD_P2P_ADD_IF, WifiCmdAddIf, 0), + DUEMessage(CMD_P2P_REMOVE_IF, WifiCmdRemoveIf, 0), + DUEMessage(CMD_P2P_SET_AP_WPS_P2P_IE, WifiCmdSetApWpsP2pIe, 0), + DUEMessage(CMD_P2P_GET_DRIVER_FLAGS, WifiCmdGetDriverFlag, 0), }; ServiceDefine(BaseService, BASE_SERVICE_ID, g_wifiBaseFeatureCmds); diff --git a/model/network/wifi/include/hdf_wifi_cmd.h b/model/network/wifi/include/hdf_wifi_cmd.h index 9f0f17c00..b753efece 100644 --- a/model/network/wifi/include/hdf_wifi_cmd.h +++ b/model/network/wifi/include/hdf_wifi_cmd.h @@ -206,6 +206,16 @@ typedef struct { } WifiActionData; typedef struct { +typedef struct { + uint8_t type; +} WifiIfAdd; + +typedef struct { + uint32_t ieLen; + uint8_t appIeType; + uint8_t rsv[3]; + uint8_t *ie; +} WifiAppIe; int32_t mode; int32_t freq; int32_t channel; diff --git a/model/network/wifi/platform/include/hdf_wlan_services.h b/model/network/wifi/platform/include/hdf_wlan_services.h index cbc7e5fbc..ad4e1148d 100644 --- a/model/network/wifi/platform/include/hdf_wlan_services.h +++ b/model/network/wifi/platform/include/hdf_wlan_services.h @@ -43,6 +43,13 @@ enum BaseCommands { CMD_BASE_GET_IFNAMES, CMD_BASE_RESET_DRIVER, CMD_BASE_DO_RESET_PRIVATE = 25, + CMD_P2P_PROBE_REQ_REPORT = 26, + CMD_P2P_REMAIN_ON_CHANNEL, + CMD_P2P_CANCEL_REMAIN_ON_CHANNEL, + CMD_P2P_ADD_IF, + CMD_P2P_REMOVE_IF, + CMD_P2P_SET_AP_WPS_P2P_IE, + CMD_P2P_GET_DRIVER_FLAGS, }; enum APCommands { diff --git a/model/network/wifi/platform/src/hdf_wifi_event.c b/model/network/wifi/platform/src/hdf_wifi_event.c index 109577831..e519a13fc 100644 --- a/model/network/wifi/platform/src/hdf_wifi_event.c +++ b/model/network/wifi/platform/src/hdf_wifi_event.c @@ -430,6 +430,51 @@ int32_t HdfWifiEventResetResult(const uint8_t chipId, int32_t resetStatus, const return ret; } +int32_t HdfWifiEventRemainOnChannel(const struct NetDevice *netDev, uint32_t freq, uint32_t duration) +{ + struct HdfSBuf *data = NULL; + int32_t ret; + + data = HdfSBufObtainDefaultSize(); + if (data == NULL) { + HDF_LOGE("%s InitDataBlock failed", __func__); + return HDF_FAILURE; + } + if (!HdfSbufWriteString(data, netDev->name) || !HdfSbufWriteUint32(data, freq)) { + HDF_LOGE("%s sbuf write failed", __func__); + HdfSBufRecycle(data); + return HDF_FAILURE; + } + if (!HdfSbufWriteUint32(data, duration)) { + HDF_LOGE("%s sbuf write failed", __func__); + HdfSBufRecycle(data); + return HDF_FAILURE; + } + ret = HdfWlanSendBroadcastEvent(WIFI_WPA_EVENT_REMAIN_ON_CHANNEL, data); + HdfSBufRecycle(data); + return ret; +} + +int32_t HdfWifiEventCancelRemainOnChannel(const struct NetDevice *netDev, uint32_t freq) +{ + struct HdfSBuf *data = NULL; + int32_t ret; + + data = HdfSBufObtainDefaultSize(); + if (data == NULL) { + HDF_LOGE("%s InitDataBlock failed", __func__); + return HDF_FAILURE; + } + if (!HdfSbufWriteString(data, netDev->name) || !HdfSbufWriteUint32(data, freq)) { + HDF_LOGE("%s sbuf write failed", __func__); + HdfSBufRecycle(data); + return HDF_FAILURE; + } + ret = HdfWlanSendBroadcastEvent(WIFI_WPA_EVENT_CANCEL_REMAIN_ON_CHANNEL, data); + HdfSBufRecycle(data); + return ret; +} + #ifdef __cplusplus #if __cplusplus } -- Gitee From a0174bc26ff48b9f0a16f76e29278199de5cd361 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Wed, 28 Jul 2021 10:03:51 +0800 Subject: [PATCH 036/205] fix ioservice poll UAF issue Signed-off-by: yuanbo --- .../adapter/syscall/src/hdf_syscall_adapter.c | 39 +++++++++---------- core/adapter/vnode/src/hdf_vnode_adapter.c | 7 +++- include/osal/osal_time.h | 11 ++++++ support/posix/src/osal_time.c | 13 +++++++ 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/core/adapter/syscall/src/hdf_syscall_adapter.c b/core/adapter/syscall/src/hdf_syscall_adapter.c index b89f24570..d84ea8634 100644 --- a/core/adapter/syscall/src/hdf_syscall_adapter.c +++ b/core/adapter/syscall/src/hdf_syscall_adapter.c @@ -162,7 +162,7 @@ static int32_t HdfDevEventReadAndDispatch(struct HdfDevListenerThread *thread, i if (ret == -HDF_DEV_ERR_NODATA) { ret = HDF_SUCCESS; } else { - HDF_LOGE("%s:ioctl failed, errno=%d\n", __func__, ret); + HDF_LOGE("%s:ioctl failed, errno=%d", __func__, ret); } goto finish; @@ -240,7 +240,6 @@ static int32_t HdfDevEventListenTask(void *para) goto exit; } else if (((uint32_t)pfds[i].revents) & POLLHUP) { HDF_LOGI("event listener task received exit event"); - thread->shouldStop = true; goto exit; } else if (((uint32_t)pfds[i].revents) & POLLNVAL) { OsalMSleep(1); // polled closed fd, yield to sync @@ -269,7 +268,7 @@ static int32_t HdfAdapterStartListenIoctl(int fd) { int32_t ret = ioctl(fd, HDF_LISTEN_EVENT_START, 0); if (ret) { - HDF_LOGE("%s: failed to notify drv(%d) of start %d %s", __func__, fd, errno, strerror(errno)); + HDF_LOGE("%s: failed to notify drv(%d) of start %d %{public}s", __func__, fd, errno, strerror(errno)); return HDF_ERR_IO; } @@ -280,7 +279,7 @@ static int32_t HdfAdapterStopListenIoctl(int fd) { int32_t ret = ioctl(fd, HDF_LISTEN_EVENT_STOP, 0); if (ret) { - HDF_LOGE("%s: failed to notify drv(%d) of stop %d %s", __func__, fd, errno, strerror(errno)); + HDF_LOGE("%s: failed to notify drv(%d) of stop %d %{public}s", __func__, fd, errno, strerror(errno)); return HDF_ERR_IO; } @@ -291,10 +290,10 @@ static int32_t HdfAdapterExitListenIoctl(int fd) { int32_t ret = ioctl(fd, HDF_LISTEN_EVENT_EXIT, 0); if (ret) { - HDF_LOGE("%s: failed to notify drv(%d) of exit %d %s", __func__, fd, errno, strerror(errno)); + HDF_LOGE("%s: failed to notify drv(%d) of exit %d %{public}s", __func__, fd, errno, strerror(errno)); return HDF_ERR_IO; } - + HDF_LOGD("ioctl send poll thread(%d) exit event, ret=%d", fd, ret); return HDF_SUCCESS; } @@ -526,7 +525,7 @@ static int32_t HdfListenThreadPollAdd(struct HdfDevListenerThread *thread, struc if (headAdapter != NULL) { if (ioctl(headAdapter->fd, HDF_LISTEN_EVENT_WAKEUP, 0) != 0) { - HDF_LOGE("%s: failed to wakeup drv to add poll %d %s", __func__, errno, strerror(errno)); + HDF_LOGE("%s: failed to wakeup drv to add poll %d %{public}s", __func__, errno, strerror(errno)); thread->pfds[index].fd = SYSCALL_INVALID_FD; ret = HDF_ERR_IO; break; @@ -564,10 +563,7 @@ static void HdfListenThreadPollDel(struct HdfDevListenerThread *thread, struct } } - if (HdfAdapterStopListenIoctl(adapter->fd)) { - HDF_LOGE("%s: failed to stop device report %d %s", __func__, errno, strerror(errno)); - } - + HdfAdapterStopListenIoctl(adapter->fd); if (ioctl(adapter->fd, HDF_LISTEN_EVENT_WAKEUP, 0) != 0) { HDF_LOGE("%s: failed to wakeup drv to del poll %d %s", __func__, errno, strerror(errno)); } @@ -600,20 +596,23 @@ static void HdfDevListenerThreadDestroy(struct HdfDevListenerThread *thread) thread->listenerListPtr = NULL; OsalMutexUnlock(&thread->mutex); for (int i = 0; i < thread->pfdSize; i++) { - if (thread->pfds[i].fd == SYSCALL_INVALID_FD) { - continue; - } - if (HdfAdapterExitListenIoctl(thread->pfds[i].fd) == HDF_SUCCESS) { - thread->shouldStop = true; + if (thread->pfds[i].fd != SYSCALL_INVALID_FD && + HdfAdapterExitListenIoctl(thread->pfds[i].fd) == HDF_SUCCESS) { stopCount++; - break; } + thread->pfds[i].fd = SYSCALL_INVALID_FD; } if (stopCount == 0) { thread->shouldStop = true; HDF_LOGE("%s:failed to exit listener thread with ioctl, will go async way", __func__); + return; + } + while (thread->status != LISTENER_EXITED) { + OsalUSleep(1); } + HDF_LOGI("poll thread exited"); + HdfDevListenerThreadFree(thread); return; } case LISTENER_STARTED: @@ -691,11 +690,11 @@ struct HdfIoService *HdfIoServiceAdapterObtain(const char *serviceName) if (realpath(devNodePath, realPath) == NULL) { if (HdfLoadDriverByServiceName(serviceName) != HDF_SUCCESS) { - HDF_LOGE("%s: load %s driver failed", __func__, serviceName); + HDF_LOGE("%s: load %{public}s driver failed", __func__, serviceName); goto out; } if (realpath(devNodePath, realPath) == NULL) { - HDF_LOGE("%s: file name %s is invalid", __func__, devNodePath); + HDF_LOGE("%s: file name %{public}s is invalid", __func__, devNodePath); goto out; } } @@ -715,7 +714,7 @@ struct HdfIoService *HdfIoServiceAdapterObtain(const char *serviceName) adapter->fd = open(realPath, O_RDWR); if (adapter->fd < 0) { - HDF_LOGE("Open file node %s failed, (%d)%s", realPath, errno, strerror(errno)); + HDF_LOGE("Open file node %{public}s failed, (%d)%{public}s", realPath, errno, strerror(errno)); OsalMutexDestroy(&adapter->mutex); OsalMemFree(adapter); goto out; diff --git a/core/adapter/vnode/src/hdf_vnode_adapter.c b/core/adapter/vnode/src/hdf_vnode_adapter.c index 4694f1c5c..dab5a350e 100644 --- a/core/adapter/vnode/src/hdf_vnode_adapter.c +++ b/core/adapter/vnode/src/hdf_vnode_adapter.c @@ -524,7 +524,10 @@ static unsigned int HdfVNodeAdapterPoll(struct file *filep, poll_table *wait) { unsigned int mask = 0; struct HdfVNodeAdapterClient *client = (struct HdfVNodeAdapterClient *)OsalGetFilePriv(filep); - + if (client == NULL) { + mask |= POLLERR; + return mask; + } poll_wait(filep, &client->pollWait, wait); OsalMutexLock(&client->mutex); if (client->status == VNODE_CLIENT_EXITED) { @@ -536,6 +539,7 @@ static unsigned int HdfVNodeAdapterPoll(struct file *filep, poll_table *wait) client->wakeup--; } OsalMutexUnlock(&client->mutex); + return mask; } @@ -548,6 +552,7 @@ static int HdfVNodeAdapterClose(struct OsalCdev *cdev, struct file *filep) client->ioServiceClient.device->service->Release(&client->ioServiceClient); } HdfDestoryVNodeAdapterClient(client); + OsalSetFilePriv(filep, NULL); return HDF_SUCCESS; } diff --git a/include/osal/osal_time.h b/include/osal/osal_time.h index b74962271..37290924d 100644 --- a/include/osal/osal_time.h +++ b/include/osal/osal_time.h @@ -67,6 +67,17 @@ void OsalSleep(uint32_t sec); */ void OsalMSleep(uint32_t ms); +/** + * @brief Describes thread sleep, in microsecond. + * + * When a thread invokes this function, the CPU is released and the thread enters the sleep state. + * + * @param us Indicates the sleep time, in microsecond. + * @since 1.0 + * @version 1.0 + */ +void OsalUSleep(uint32_t us); + /** * @brief Obtains the second and microsecond time. * diff --git a/support/posix/src/osal_time.c b/support/posix/src/osal_time.c index dbd65d0f9..841dcd9ea 100644 --- a/support/posix/src/osal_time.c +++ b/support/posix/src/osal_time.c @@ -75,6 +75,19 @@ void OsalMSleep(uint32_t ms) } } +void OsalUSleep(uint32_t us) +{ + int result; + struct timespec ts; + + ts.tv_sec = us / ((long)HDF_KILO_UNIT * HDF_KILO_UNIT); + ts.tv_nsec = HDF_KILO_UNIT * ((long)(us % HDF_KILO_UNIT)); + result = nanosleep(&ts, &ts); + if (result != 0) { + HDF_LOGE("%s OsalUSleep failed %d", __func__, errno); + } +} + void OsalUDelay(uint32_t us) { (void)us; -- Gitee From 5d3e9a9e6caa0487f2d477a40057a7f7c6b110fd Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Wed, 28 Jul 2021 06:51:45 +0000 Subject: [PATCH 037/205] Description:p2p adapter Feature or Bugfix:Feature Binary Source: No Signed-off-by: YOUR_NAME --- model/network/wifi/include/hdf_wifi_cmd.h | 28 +++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/model/network/wifi/include/hdf_wifi_cmd.h b/model/network/wifi/include/hdf_wifi_cmd.h index b753efece..43a392ead 100644 --- a/model/network/wifi/include/hdf_wifi_cmd.h +++ b/model/network/wifi/include/hdf_wifi_cmd.h @@ -206,16 +206,30 @@ typedef struct { } WifiActionData; typedef struct { + uint32_t freq; + uint32_t duration; +} WifiOnChannel; + typedef struct { uint8_t type; } WifiIfAdd; +typedef struct { + uint8_t ifname[IFNAMSIZ]; +} WifiIfRemove; + typedef struct { uint32_t ieLen; uint8_t appIeType; uint8_t rsv[3]; uint8_t *ie; } WifiAppIe; + +typedef struct { + uint64_t drvFlags; +} WifiGetDrvFlags; + +typedef struct { int32_t mode; int32_t freq; int32_t channel; @@ -324,16 +338,6 @@ typedef struct { int32_t extraIesLen; } WifiScan; -typedef struct { - uint32_t freq; - uint32_t duration; -} WifiOnChannel; - - -typedef struct { - uint8_t ifname[IFNAMSIZ]; -} WifiIfRemove; - typedef struct { uint8_t type; uint8_t macAddr[ETH_ADDR_LEN]; @@ -345,10 +349,6 @@ typedef struct { uint8_t *macAddr; } WifiIftypeMacAddr; -typedef struct { - uint64_t drvFlags; -} WifiGetDrvFlags; - typedef struct { int32_t freq; } WifiChannelSwitch; -- Gitee From 913ab28441058104167fa0d3d198f152cfc7e350 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Wed, 28 Jul 2021 07:40:51 +0000 Subject: [PATCH 038/205] Description:p2p adapter Feature or Bugfix:Feature Binary Source: No Signed-off-by: YOUR_NAME --- model/network/wifi/core/module/wifi_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/network/wifi/core/module/wifi_base.c b/model/network/wifi/core/module/wifi_base.c index 40406bfa4..d0c3d19b0 100644 --- a/model/network/wifi/core/module/wifi_base.c +++ b/model/network/wifi/core/module/wifi_base.c @@ -1594,7 +1594,7 @@ static int32_t WifiCmdGetDriverFlag(const RequestContext *context, struct HdfSBu ret = HDF_ERR_IO; } - HDF_LOGE("WifiCmdGetDriverFlag:%lx", params->drvFlags); + HDF_LOGE("WifiCmdGetDriverFlag:%llx", params->drvFlags); return ret; } -- Gitee From 3402e87fd11e9c061f4d52bdbb718d96eda0dd83 Mon Sep 17 00:00:00 2001 From: juchenyang Date: Thu, 29 Jul 2021 03:44:54 +0000 Subject: [PATCH 039/205] Description:modify network port driver code. Feature or Bugfix:Feature Binary Source: No Signed-off-by: juchenyang --- include/ethernet/eth_chip_driver.h | 58 ++++ include/{wifi => net}/net_device.h | 24 +- model/network/common/netdevice/net_device.c | 26 +- .../common/netdevice/net_device_impl.h | 3 +- model/network/ethernet/include/eth_device.h | 72 +++++ model/network/ethernet/src/eth_chip_driver.c | 66 ++++ model/network/ethernet/src/eth_device.c | 291 ++++++++++++++++++ model/network/ethernet/src/hdf_eth_core.c | 215 +++++++++++++ .../wifi/platform/src/hdf_wlan_utils.c | 8 +- .../wifi/unittest/netdevice/net_device_test.c | 5 +- 10 files changed, 754 insertions(+), 14 deletions(-) create mode 100755 include/ethernet/eth_chip_driver.h rename include/{wifi => net}/net_device.h (96%) mode change 100644 => 100755 create mode 100755 model/network/ethernet/include/eth_device.h create mode 100755 model/network/ethernet/src/eth_chip_driver.c create mode 100755 model/network/ethernet/src/eth_device.c create mode 100755 model/network/ethernet/src/hdf_eth_core.c diff --git a/include/ethernet/eth_chip_driver.h b/include/ethernet/eth_chip_driver.h new file mode 100755 index 000000000..2c2372f55 --- /dev/null +++ b/include/ethernet/eth_chip_driver.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021-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 ETH_CHIP_DRIVER_H +#define ETH_CHIP_DRIVER_H + +#include "eth_device.h" +#include "net_device.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAX_CHIPDRIVER_COUNT 16 + +struct EthMacOps { + void (*MacInit)(void); + int32_t (*PortReset)(struct EthDevice *ethDevice); + int32_t (*PortInit)(struct EthDevice *ethDevice); +}; + +struct HdfEthMacChipDriver { + struct EthMacOps *ethMacOps; /**< Ethernet Mac some basic methods */ +}; + +struct HdfEthNetDeviceData { + struct HdfEthMacChipDriver *macChipDriver; /**< Mac ChipDriver */ +}; + +struct HdfEthNetDeviceData *GetEthNetDeviceData(const struct NetDevice *netDev); + +struct HdfEthChipDriverFactory { + const char *driverName; + int32_t (*InitEthDriver)(struct EthDevice *ethDevice); + int32_t (*DeinitEthDriver)(struct EthDevice *ethDevice); + struct HdfEthMacChipDriver *(*BuildMacDriver)(void); + void (*ReleaseMacDriver)(struct HdfEthMacChipDriver *chipDriver); + void (*GetMacAddr)(unsigned char *addr, int len); +}; + +struct HdfEthChipDriverManager { + struct HdfEthChipDriverFactory **chipFactoryInsts; + int32_t (*RegChipDriver)(struct HdfEthChipDriverFactory *factoryInst); + struct HdfEthChipDriverFactory *(*GetEthChipDriverByName)(const char *name); +}; + +struct HdfEthChipDriverManager *HdfEthGetChipDriverMgr(void); + +#ifdef __cplusplus +} +#endif + +#endif /* ETH_CHIP_DRIVER_H */ diff --git a/include/wifi/net_device.h b/include/net/net_device.h old mode 100644 new mode 100755 similarity index 96% rename from include/wifi/net_device.h rename to include/net/net_device.h index 9b1b59634..17b19ef47 --- a/include/wifi/net_device.h +++ b/include/net/net_device.h @@ -465,7 +465,7 @@ typedef struct NetDevice { char name[IFNAMSIZ]; /**< Network device name {@link IFNAMSIZ} */ NetLinkType LinkLayerType; /**< Data link layer type */ IfType funType; /**< Network port type */ - unsigned char macAddr[MAC_ADDR_SIZE]; /**< MAC address {@link MAC_ADDR_SIZE} */ + uint8_t macAddr[MAC_ADDR_SIZE]; /**< MAC address {@link MAC_ADDR_SIZE} */ uint32_t flags; /**< Network port status */ uint32_t mtu; /**< Maximum transmission unit */ int32_t watchdogTime; /**< Watchdog duration */ @@ -506,6 +506,9 @@ struct NetDeviceInterFace { int32_t (*changeMtu)(struct NetDevice *netDev, int32_t newMtu); /**< Changes the maximum number of * transmission units. */ + void (*linkStatusChanged)(struct NetDevice *netDev); /**< Detects the change of + * the Ethernet port connection status. + */ ProcessingResult (*specialEtherTypeProcess)(const struct NetDevice *netDev, NetBuf *buff); /**< Performs private processing without * involving network-layer data. @@ -517,6 +520,7 @@ struct NetDeviceInterFace { * * @param ifName Indicates the pointer to the network device name. * @param len Indicates the length of the network device name. + * @param type Indicates the data link type. * @param ifCategory Indicates the network port category. * * @return Returns the structure {@link NetDevice} for the initialized network device if the operation is successful; @@ -525,7 +529,7 @@ struct NetDeviceInterFace { * @since 1.0 * @version 1.0 */ -struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetIfCategory ifCategory); +struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetLinkType type, NetIfCategory ifCategory); /** * @brief Deletes a network device. @@ -544,7 +548,6 @@ int32_t NetDeviceDeInit(struct NetDevice *netDevice); * @brief Adds a network device to a protocol stack. * * @param netDevice Indicates the pointer to the network device structure obtained during initialization. - * @param ifType Indicates the network port type, as enumerated in {@link Protocol80211IfType}. * * @return Returns 0 if the operation is successful; returns a negative value representing {@link HDF_STATUS} * if the operation fails. @@ -552,7 +555,7 @@ int32_t NetDeviceDeInit(struct NetDevice *netDevice); * @since 1.0 * @version 1.0 */ -int32_t NetDeviceAdd(struct NetDevice *netDevice, Protocol80211IfType ifType); +int32_t NetDeviceAdd(struct NetDevice *netDevice); /** * @brief Deletes a network device from a protocol stack. @@ -695,6 +698,19 @@ int32_t NetIfSetMacAddr(struct NetDevice *netDevice, const unsigned char *macAdd */ int32_t NetIfSetLinkStatus(const struct NetDevice *netDevice, NetIfLinkStatus status); +/** + * @brief Get the netdevice data link layer status. + * + * @param netDevice Indicates the pointer to the network device obtained during initialization. + * @param status save link layer status, as enumerated in {@link NetIfLinkSatus}. + * + * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ +int32_t NetIfGetLinkStatus(const struct NetDevice *netDevice, NetIfLinkStatus *status); + /** * @brief Transfers the input data packets from the network side to a protocol stack. * diff --git a/model/network/common/netdevice/net_device.c b/model/network/common/netdevice/net_device.c index 2a336b304..37c750ad0 100644 --- a/model/network/common/netdevice/net_device.c +++ b/model/network/common/netdevice/net_device.c @@ -121,7 +121,7 @@ static struct NetDeviceImpl *GetImplByNetDevice(const struct NetDevice *netDevic return ndImpl; } -struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetIfCategory ifCategory) +struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetLinkType type, NetIfCategory ifCategory) { NetDevice *netDevice = NULL; struct NetDeviceImpl *ndImpl = NULL; @@ -167,6 +167,7 @@ struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetIfCategory DeInitNetDeviceImpl(ndImpl); return NULL; } + netDevice->LinkLayerType = type; HDF_LOGI("Init Net Device success!"); return netDevice; } @@ -190,7 +191,7 @@ int32_t NetDeviceDeInit(struct NetDevice *netDevice) return HDF_SUCCESS; } -int32_t NetDeviceAdd(struct NetDevice *netDevice, Protocol80211IfType ifType) +int32_t NetDeviceAdd(struct NetDevice *netDevice) { struct NetDeviceImplOp *op = NULL; struct NetDeviceImpl *ndImpl = GetImplByNetDevice(netDevice); @@ -204,7 +205,7 @@ int32_t NetDeviceAdd(struct NetDevice *netDevice, Protocol80211IfType ifType) HDF_LOGE("%s fail: Impl Add not exist.", __func__); return HDF_ERR_INVALID_PARAM; } - return op->add(ndImpl, ifType); + return op->add(ndImpl); } int32_t NetDeviceDelete(struct NetDevice *netDevice) @@ -339,7 +340,9 @@ static int32_t NetIfRxImpl(const struct NetDevice *netDevice, NetBuf *buff, Rece int32_t NetIfSetMacAddr(struct NetDevice *netDevice, const unsigned char *macAddr, unsigned char length) { + HDF_STATUS ret; struct NetDeviceImpl *ndImpl = NULL; + if (macAddr == NULL || length != MAC_ADDR_SIZE) { HDF_LOGE("%s fail: input param error!", __func__); return HDF_ERR_INVALID_PARAM; @@ -348,6 +351,13 @@ int32_t NetIfSetMacAddr(struct NetDevice *netDevice, const unsigned char *macAdd HDF_LOGE("%s fail : memcpy_s fail!", __func__); return HDF_FAILURE; } + if (netDevice->netDeviceIf != NULL && netDevice->netDeviceIf->setMacAddr != NULL) { + ret = netDevice->netDeviceIf->setMacAddr(netDevice, (void*)macAddr); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s fail : setMacAddr fail!", __func__); + return ret; + } + } ndImpl = GetImplByNetDevice(netDevice); if (ndImpl != NULL && ndImpl->interFace != NULL && ndImpl->interFace->changeMacAddr != NULL) { return ndImpl->interFace->changeMacAddr(ndImpl); @@ -385,6 +395,16 @@ int32_t NetIfSetLinkStatus(const struct NetDevice *netDevice, NetIfLinkStatus st return HDF_ERR_INVALID_PARAM; } +int32_t NetIfGetLinkStatus(const struct NetDevice *netDevice, NetIfLinkStatus *status) +{ + struct NetDeviceImpl *ndImpl = GetImplByNetDevice(netDevice); + if (ndImpl != NULL && ndImpl->interFace != NULL && ndImpl->interFace->getLinkStatus != NULL) { + return ndImpl->interFace->getLinkStatus(ndImpl, status); + } + HDF_LOGE("%s: netDevice not init or already free.", __func__); + return HDF_ERR_INVALID_PARAM; +} + int32_t NetIfDhcpsStart(const struct NetDevice *netDevice, char *ip, uint16_t ipNum) { struct NetDeviceImpl *ndImpl = GetImplByNetDevice(netDevice); diff --git a/model/network/common/netdevice/net_device_impl.h b/model/network/common/netdevice/net_device_impl.h index 22a627035..ee169075c 100644 --- a/model/network/common/netdevice/net_device_impl.h +++ b/model/network/common/netdevice/net_device_impl.h @@ -27,10 +27,11 @@ typedef enum { struct NetDeviceImplOp { int32_t (*init)(struct NetDeviceImpl *netDevice); int32_t (*deInit)(struct NetDeviceImpl *netDevice); - int32_t (*add)(struct NetDeviceImpl *netDevice, Protocol80211IfType ifType); + int32_t (*add)(struct NetDeviceImpl *netDevice); int32_t (*delete)(struct NetDeviceImpl *netDevice); int32_t (*setStatus)(struct NetDeviceImpl *netDevice, NetIfStatus status); int32_t (*setLinkStatus)(struct NetDeviceImpl *netDevice, NetIfLinkStatus status); + int32_t (*getLinkStatus)(struct NetDeviceImpl *netDevice, NetIfLinkStatus *status); int32_t (*receive)(struct NetDeviceImpl *netDevice, NetBuf *buff, ReceiveFlag flag); int32_t (*setIpAddr)(struct NetDeviceImpl *netDevice, const IpV4Addr *ipAddr, const IpV4Addr *netMask, const IpV4Addr *gw); diff --git a/model/network/ethernet/include/eth_device.h b/model/network/ethernet/include/eth_device.h new file mode 100755 index 000000000..774ecc30a --- /dev/null +++ b/model/network/ethernet/include/eth_device.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2021-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 ETH_DEVICE_H +#define ETH_DEVICE_H + +#include "net_device.h" +#include "hdf_device_desc.h" +#include + +#define MAX_NAME_LENGTH 16 +#define ETH_DEVICE_MAX 6 + +#define DELAY_TIME_LONG 3000 +#define DELAY_TIME_MEDIUM 50 +#define DELAY_TIME_SHORT 5 +#define SLEEP_TIME_SHORT 20 +#define SLEEP_TIME_MEDIUM 30 +#define SLEEP_TIME_COMMON 60 +#define SLEEP_TIME_LONG 250 + +#define MAC_ADDR_OFFSET_L8 8 +#define MAC_ADDR_OFFSET_L16 16 +#define MAC_ADDR_OFFSET_L24 24 + +struct EthDevice { + struct NetDevice *netdev; + struct ConfigEthDevList *config; + const char *name; + void *priv; +}; + +struct HdfConfigEthMac { + uint32_t regBase; + uint32_t irqVector; + uint8_t mdioFrqDiv; + uint8_t txBusy; + uint32_t iobase; + uint32_t regOffSize; +}; + +struct HdfConfigEthPhy { + uint8_t phyMode; +}; + +struct ConfigEthDevList { + uint8_t deviceInstId; + uint8_t isSetDefault; + const char *driverName; + uint8_t hwXmitq; + uint8_t qSize; + uint8_t port; + struct HdfConfigEthMac ethMac; + struct HdfConfigEthPhy ethPhy; +}; + +struct EthConfig { + struct ConfigEthDevList deviceInst[ETH_DEVICE_MAX]; + uint16_t deviceListSize; +}; + +struct EthDevice *CreateEthDevice(const struct ConfigEthDevList *configEthDevList); +int32_t ReleaseEthDevice(struct EthDevice *ethDevice); +int32_t GetEthIfName(const struct ConfigEthDevList *configEthDevList, char *ifName, uint32_t ifNameSize); +struct EthConfig *GetEthConfig(const struct DeviceResourceNode *node); + +#endif /* ETH_DEVICE_H */ diff --git a/model/network/ethernet/src/eth_chip_driver.c b/model/network/ethernet/src/eth_chip_driver.c new file mode 100755 index 000000000..805f766f4 --- /dev/null +++ b/model/network/ethernet/src/eth_chip_driver.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021-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 "eth_chip_driver.h" +#include "hdf_log.h" + +#define HDF_LOG_TAG HDF_ETH_CORE + +static struct HdfEthChipDriverFactory *g_ethChipDriverFactory[MAX_CHIPDRIVER_COUNT] = {NULL}; + +struct HdfEthChipDriverFactory *HdfEthGetChipDriverByName(const char *driverName) +{ + int32_t i; + if (driverName == NULL) { + HDF_LOGE("%s fail: drivreName is NULL", __func__); + return NULL; + } + + for (i = 0; i < MAX_CHIPDRIVER_COUNT; i++) { + if (g_ethChipDriverFactory[i] != NULL && g_ethChipDriverFactory[i]->driverName != NULL) { + struct HdfEthChipDriverFactory *factory = g_ethChipDriverFactory[i]; + if (strcmp(factory->driverName, driverName) == 0) { + return factory; + } + } + } + return NULL; +} + +int32_t HdfEthRegChipDriver(struct HdfEthChipDriverFactory *obj) +{ + int32_t index; + if (obj == NULL || obj->driverName == NULL) { + HDF_LOGE("%s: HdfEthChipDriverFactory obj is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (HdfEthGetChipDriverByName(obj->driverName) != NULL) { + HDF_LOGW("%s: chipDriver factory is already registed. name = %s", __func__, obj->driverName); + return HDF_FAILURE; + } + for (index = 0; index < MAX_CHIPDRIVER_COUNT; index++) { + if (g_ethChipDriverFactory[index] == NULL) { + g_ethChipDriverFactory[index] = obj; + HDF_LOGI("%s:Chip driver %s registed.", __func__, obj->driverName); + return HDF_SUCCESS; + } + } + HDF_LOGE("%s: Factory table is NULL", __func__); + return HDF_FAILURE; +} + +static struct HdfEthChipDriverManager g_chipDriverManager = { + .chipFactoryInsts = g_ethChipDriverFactory, + .RegChipDriver = HdfEthRegChipDriver, + .GetEthChipDriverByName = HdfEthGetChipDriverByName, +}; + +struct HdfEthChipDriverManager *HdfEthGetChipDriverMgr(void) +{ + return &g_chipDriverManager; +} \ No newline at end of file diff --git a/model/network/ethernet/src/eth_device.c b/model/network/ethernet/src/eth_device.c new file mode 100755 index 000000000..1080d83e7 --- /dev/null +++ b/model/network/ethernet/src/eth_device.c @@ -0,0 +1,291 @@ +/* + * Copyright (c) 2021-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 "eth_device.h" +#include "eth_chip_driver.h" +#include +#include "device_resource_if.h" +#include "hdf_log.h" +#include "los_vm_zone.h" +#include "osal_mem.h" + +#define HDF_LOG_TAG eth_device + +int32_t GetEthIfName(const struct ConfigEthDevList *configEthDevList, char *ifName, uint32_t ifNameSize) +{ + if (configEthDevList == NULL || ifName == NULL || ifNameSize == 0) { + HDF_LOGE("%s:para is null!", __func__); + return HDF_FAILURE; + } + if (snprintf_s(ifName, ifNameSize, ifNameSize - 1, "eth%d", configEthDevList->deviceInstId) < 0) { + HDF_LOGE("%s:format ifName failed!deviceInstId = %d.", __func__, configEthDevList->deviceInstId); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +struct EthDevice *CreateEthDevice(const struct ConfigEthDevList *configEthDevList) +{ + int32_t ret; + struct HdfEthNetDeviceData *data = NULL; + struct NetDevice *netDevice = NULL; + struct EthDevice *ethDevice = NULL; + char ethIfName[IFNAMSIZ] = {0}; + + if (configEthDevList == NULL) { + HDF_LOGE("%s input is NULL!", __func__); + return NULL; + } + data = (struct HdfEthNetDeviceData *)OsalMemCalloc(sizeof(struct HdfEthNetDeviceData)); + if (data == NULL) { + HDF_LOGE("%s failed to OsalMemCalloc HdfEthNetDeviceData", __func__); + return NULL; + } + ret = GetEthIfName(configEthDevList, ethIfName, IFNAMSIZ); + if (ret != HDF_SUCCESS) { + OsalMemFree(data); + return NULL; + } + netDevice = NetDeviceInit(ethIfName, strlen(ethIfName), ETHERNET_LINK, LITE_OS); + if (netDevice == NULL) { + HDF_LOGE("%s failed to init netDevice", __func__); + OsalMemFree(data); + return NULL; + } + ethDevice = (struct EthDevice *)OsalMemCalloc(sizeof(struct EthDevice)); + if (ethDevice == NULL) { + HDF_LOGE("%s failed to OsalMemCalloc ethDevice", __func__); + NetDeviceDeInit(netDevice); + OsalMemFree(data); + return NULL; + } + netDevice->mlPriv = ethDevice; + ethDevice->netdev = netDevice; + ethDevice->netdev->classDriverPriv = data; + ethDevice->name = configEthDevList->driverName; + return ethDevice; +} + +static int32_t ParseEthMacConfig(const struct DeviceResourceNode *node, struct HdfConfigEthMac *ethMacConfig) +{ + struct DeviceResourceIface *drsOps = NULL; + + if (node == NULL || ethMacConfig == NULL) { + HDF_LOGE("%s: invalid node or ethMacConfig!", __func__); + return HDF_FAILURE; + } + + drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL || drsOps->GetUint8 == NULL || drsOps->GetUint32 == NULL) { + HDF_LOGE("%s: at least one of the paras is NULL!", __func__); + return HDF_FAILURE; + } + if (drsOps->GetUint32(node, "regBase", ðMacConfig->regBase, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read regBase fail", __func__); + return HDF_FAILURE; + } + if (drsOps->GetUint32(node, "irqVector", ðMacConfig->irqVector, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read irqVector fail", __func__); + return HDF_FAILURE; + } + if (drsOps->GetUint8(node, "mdioFrqDiv", ðMacConfig->mdioFrqDiv, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read mdioFrqDiv fail", __func__); + return HDF_FAILURE; + } + if (drsOps->GetUint8(node, "txBusy", ðMacConfig->txBusy, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read txBusy fail", __func__); + return HDF_FAILURE; + } + if (drsOps->GetUint32(node, "iobase", ðMacConfig->iobase, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read iobase fail", __func__); + return HDF_FAILURE; + } + if (drsOps->GetUint32(node, "regOffSize", ðMacConfig->regOffSize, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read regOffSize fail", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t ParseEthPhyConfig(const struct DeviceResourceNode *node, struct HdfConfigEthPhy *ethPhyConfig) +{ + struct DeviceResourceIface *drsOps = NULL; + + if (node == NULL || ethPhyConfig == NULL) { + HDF_LOGE("%s: invalid node or ethPhyConfig!", __func__); + return HDF_FAILURE; + } + + drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL || drsOps->GetUint8 == NULL) { + HDF_LOGE("%s: at least one of the paras is NULL!", __func__); + return HDF_FAILURE; + } + + if (drsOps->GetUint8(node, "phyMode", ðPhyConfig->phyMode, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read phyMode fail", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t ParseEthDevInstConfig(const struct DeviceResourceNode *node, struct ConfigEthDevList *devLstConfig) +{ + struct DeviceResourceIface *drsOps = NULL; + const struct DeviceResourceNode *ethMacNode = NULL; + const struct DeviceResourceNode *ethPhyNode = NULL; + if (node == NULL || devLstConfig == NULL) { + return HDF_FAILURE; + } + drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL || drsOps->GetUint8 == NULL || drsOps->GetChildNode == NULL) { + HDF_LOGE("%s: at least one of the paras is NULL!", __func__); + return HDF_FAILURE; + } + if (drsOps->GetUint8(node, "deviceInstId", &devLstConfig->deviceInstId, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: deviceInstId fail!", __func__); + return HDF_FAILURE; + } + if (drsOps->GetUint8(node, "isSetDefault", &devLstConfig->isSetDefault, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: isSetDefault fail!", __func__); + return HDF_FAILURE; + } + if (drsOps->GetString(node, "driverName", &devLstConfig->driverName, NULL) != HDF_SUCCESS) { + HDF_LOGE("%s: driverName fail!", __func__); + return HDF_FAILURE; + } + if (drsOps->GetUint8(node, "hwXmitq", &devLstConfig->hwXmitq, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read hwXmitq fail", __func__); + return HDF_FAILURE; + } + if (drsOps->GetUint8(node, "qSize", &devLstConfig->qSize, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read qSize fail", __func__); + return HDF_FAILURE; + } + if (drsOps->GetUint8(node, "port", &devLstConfig->port, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read port fail", __func__); + return HDF_FAILURE; + } + + ethMacNode = drsOps->GetChildNode(node, "MAC"); + if (ethMacNode == NULL) { + HDF_LOGE("%s: GetChildNode fail!", __func__); + return HDF_FAILURE; + } + if (ParseEthMacConfig(ethMacNode, &devLstConfig->ethMac) != HDF_SUCCESS) { + return HDF_FAILURE; + } + ethPhyNode = drsOps->GetChildNode(node, "PHY"); + if (ethPhyNode == NULL) { + HDF_LOGE("%s: GetChildNode fail!", __func__); + return HDF_FAILURE; + } + if (ParseEthPhyConfig(ethPhyNode, &devLstConfig->ethPhy) != HDF_SUCCESS) { + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t ParseEthDevListNode(const struct DeviceResourceNode *node, struct EthConfig *ethConfig) +{ + struct DeviceResourceNode *childNode = NULL; + uint32_t index = 0; + + if (node == NULL || ethConfig == NULL) { + HDF_LOGE("%s: invalid node or ethConfig!", __func__); + return HDF_FAILURE; + } + DEV_RES_NODE_FOR_EACH_CHILD_NODE(node, childNode) + { + if (ParseEthDevInstConfig(childNode, ðConfig->deviceInst[index]) != HDF_SUCCESS) { + return HDF_FAILURE; + } + index++; + ethConfig->deviceListSize++; + } + HDF_LOGD("%s: deviceListSize=%d", __func__, ethConfig->deviceListSize); + return HDF_SUCCESS; +} + +static int32_t ParseConfigFromProperty(const struct DeviceResourceNode *node, struct EthConfig *config) +{ + struct DeviceResourceIface *drsOps = NULL; + const struct DeviceResourceNode *devListNode = NULL; + + drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL || drsOps->GetChildNode == NULL) { + HDF_LOGE("%s: invalid drs ops fail!", __func__); + return HDF_FAILURE; + } + devListNode = drsOps->GetChildNode(node, "ethList"); + if (devListNode == NULL) { + HDF_LOGE("%s: get child node fail!", __func__); + return HDF_FAILURE; + } + return ParseEthDevListNode(devListNode, config); +} + +struct EthConfig *GetEthConfig(const struct DeviceResourceNode *node) +{ + if (node == NULL) { + HDF_LOGE("%s input is NULL", __func__); + return NULL; + } + + struct EthConfig *config = NULL; + + config = (struct EthConfig *)OsalMemCalloc(sizeof(*config)); + if (config == NULL) { + HDF_LOGE("%s failed to OsalMemCalloc config", __func__); + return NULL; + } + + if (ParseConfigFromProperty(node, config) != HDF_SUCCESS) { + HDF_LOGE("%s failed to parse config from property", __func__); + return NULL; + } + return config; +} + +struct HdfEthNetDeviceData *GetEthNetDeviceData(const struct NetDevice *netDev) +{ + if (netDev == NULL) { + return NULL; + } + return (struct HdfEthNetDeviceData *)(netDev->classDriverPriv); +} + +int32_t ReleaseEthDevice(struct EthDevice *ethDevice) +{ + int32_t ret; + struct HdfEthNetDeviceData *data = NULL; + + if (ethDevice == NULL) { + HDF_LOGE("%s:NULL ptr!", __func__); + return HDF_FAILURE; + } + + data = GetEthNetDeviceData(ethDevice->netdev); + if (data == NULL) { + HDF_LOGE("%s: GetEthNetDeviceData failed!", __func__); + return HDF_FAILURE; + } + struct HdfEthMacChipDriver *macChipDriver = data->macChipDriver; + if (macChipDriver != NULL) { + OsalMemFree(macChipDriver); + macChipDriver = NULL; + } + ret = NetDeviceDeInit(ethDevice->netdev); + if (ret != HDF_SUCCESS) { + return ret; + } + + OsalMemFree(ethDevice); + OsalMemFree(data); + return HDF_SUCCESS; +} \ No newline at end of file diff --git a/model/network/ethernet/src/hdf_eth_core.c b/model/network/ethernet/src/hdf_eth_core.c new file mode 100755 index 000000000..b75e66382 --- /dev/null +++ b/model/network/ethernet/src/hdf_eth_core.c @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2021-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 "eth_chip_driver.h" +#include "eth_device.h" +#include "hdf_log.h" +#include "osal_mem.h" + +#define HDF_LOG_TAG eth_core +struct EthConfig *g_ethConfig = NULL; + +static struct HdfEthChipDriverFactory *HdfEthGetDriverFactory(const char *driverName) +{ + struct HdfEthChipDriverManager *initMgr = NULL; + if (driverName == NULL) { + HDF_LOGE("%s: driverName is ", __func__); + return NULL; + } + initMgr = HdfEthGetChipDriverMgr(); + if (initMgr == NULL) { + HDF_LOGE("%s: initMgr is NULL", __func__); + return NULL; + } + return initMgr->GetEthChipDriverByName(driverName); +} + +static int32_t DeinitEth(struct EthDevice *ethDevice) +{ + HDF_LOGD("%s enter", __func__); + struct HdfEthChipDriverFactory *ethChipDriverFact = NULL; + + if (ethDevice == NULL) { + HDF_LOGE("%s the input ethDevice is NULL!", __func__); + return HDF_ERR_INVALID_PARAM; + } + ethChipDriverFact = HdfEthGetDriverFactory(ethDevice->name); + if (ethChipDriverFact == NULL) { + HDF_LOGE("%s: get ethChipDriverFact failed! driverName = %s", __func__, ethDevice->name); + return HDF_FAILURE; + } + + if (ethChipDriverFact->DeinitEthDriver != NULL) { + return ethChipDriverFact->DeinitEthDriver(ethDevice); + } + return HDF_SUCCESS; +} + +#if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) +static int32_t SetEthNetworkAddr(struct NetDevice *netDev) +{ + IpV4Addr ip, netmask, gw; + + ip.addr = 0x0A01a8c0UL; /* 192, 168, 1. 10 */ + netmask.addr = 0x00ffffffUL; /* 255, 255, 255, 0 */ + gw.addr = 0x0101a8c0UL; /* 192, 168, 12, 1 */ + + if (NetIfSetAddr(netDev, &ip, &netmask, &gw) != HDF_SUCCESS) { + HDF_LOGE("%s fail: NetIfSetAddr error!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} +#endif + +static int32_t InitMacInterface(struct EthDevice *ethDevice, struct HdfEthMacChipDriver *macChipDriver) +{ + int32_t ret; + + if (macChipDriver->ethMacOps == NULL) { + HDF_LOGE("%s:ethMacOps is NULL.", __func__); + return HDF_FAILURE; + } + if (macChipDriver->ethMacOps->MacInit == NULL) { + HDF_LOGE("%s:MacInit is not implement.", __func__); + return HDF_FAILURE; + } + macChipDriver->ethMacOps->MacInit(); + + if (macChipDriver->ethMacOps->PortReset == NULL) { + HDF_LOGE("%s:PortReset is not implement.", __func__); + return HDF_FAILURE; + } + ret = macChipDriver->ethMacOps->PortReset(ethDevice); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:PortReset failed! ret = %d.", __func__, ret); + return HDF_FAILURE; + } + + if (macChipDriver->ethMacOps->PortInit == NULL) { + HDF_LOGE("%s:PortInit is not implement.", __func__); + return HDF_FAILURE; + } + ret = macChipDriver->ethMacOps->PortInit(ethDevice); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:PortInit failed! ret = %d.", __func__, ret); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t InitEth(struct EthDevice *ethDevice, const uint8_t isSetDefault, + struct HdfEthChipDriverFactory *ethChipDriverFact) +{ + int32_t ret; + struct HdfEthNetDeviceData *data = NULL; + struct HdfEthMacChipDriver *macChipDriver = NULL; + unsigned char enaddr[MAC_ADDR_SIZE] = {0}; + + macChipDriver = ethChipDriverFact->BuildMacDriver(); + if (macChipDriver == NULL) { + HDF_LOGE("%s:mac chip driver build fail!", __func__); + return HDF_FAILURE; + } + data = GetEthNetDeviceData(ethDevice->netdev); + if (data == NULL) { + HDF_LOGE("%s: data is NULL!", __func__); + ethChipDriverFact->ReleaseMacDriver(macChipDriver); + return HDF_FAILURE; + } + data->macChipDriver = macChipDriver; + + ret = ethChipDriverFact->InitEthDriver(ethDevice); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: failed to init eth phy", __func__); + DeinitEth(ethDevice); + ReleaseEthDevice(ethDevice); + return ret; + } + + ret = InitMacInterface(ethDevice, macChipDriver); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: InitMacInterface error!", __func__); + DeinitEth(ethDevice); + ReleaseEthDevice(ethDevice); + return HDF_FAILURE; + } + LOS_Msleep(DELAY_TIME_LONG); + + ethChipDriverFact->GetMacAddr(enaddr, MAC_ADDR_SIZE); + NetIfSetMacAddr(ethDevice->netdev, enaddr, MAC_ADDR_SIZE); + +#if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) + ret = SetEthNetworkAddr(ethDevice->netdev); + if (ret != HDF_SUCCESS) { + PRINTK("%s set eth network addr fail\n", __func__); + DeinitEth(ethDevice); + ReleaseEthDevice(ethDevice); + return ret; + } +#endif + NetIfSetStatus(ethDevice->netdev, NETIF_UP); + return HDF_SUCCESS; +} + +static int32_t HdfEthDriverInit(struct HdfDeviceObject *deviceObject) +{ + int32_t ret; + uint8_t i; + + if (deviceObject == NULL) { + HDF_LOGE("%s deviceObject is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + g_ethConfig = GetEthConfig(deviceObject->property); + if (g_ethConfig == NULL) { + HDF_LOGE("%s failed to get g_ethConfig!", __func__); + return HDF_FAILURE; + } + for (i = 0; i < g_ethConfig->deviceListSize; i++) { + struct EthDevice *ethDevice = CreateEthDevice(&g_ethConfig->deviceInst[i]); + if (ethDevice == NULL) { + return HDF_FAILURE; + } + ethDevice->config = &g_ethConfig->deviceInst[i]; + + struct HdfEthChipDriverFactory *ethChipDriverFact = HdfEthGetDriverFactory(ethDevice->name); + if (ethChipDriverFact == NULL) { + HDF_LOGE("%s: get ethChipDriverFact failed! driverName = %s", __func__, ethDevice->name); + return HDF_FAILURE; + } + ret = InitEth(ethDevice, g_ethConfig->deviceInst[i].isSetDefault, ethChipDriverFact); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s failed to init eth driver, ret: %d", __func__, ret); + return ret; + } + } + PRINTK("%s hdf eth driver framework init success\n", __func__); + return ret; +} + +static int32_t HdfEthDriverBind(struct HdfDeviceObject *deviceObject) +{ + (void)deviceObject; + return HDF_SUCCESS; +} + +static void HdfEthDriverRelease(struct HdfDeviceObject *deviceObject) +{ + (void)deviceObject; +} + +struct HdfDriverEntry g_ethEntry = { + .moduleVersion = 1, + .Bind = HdfEthDriverBind, + .Init = HdfEthDriverInit, + .Release = HdfEthDriverRelease, + .moduleName = "HDF_ETHERNET" +}; + +HDF_INIT(g_ethEntry); \ No newline at end of file diff --git a/model/network/wifi/platform/src/hdf_wlan_utils.c b/model/network/wifi/platform/src/hdf_wlan_utils.c index cc92c61ee..b7dc9ac24 100644 --- a/model/network/wifi/platform/src/hdf_wlan_utils.c +++ b/model/network/wifi/platform/src/hdf_wlan_utils.c @@ -96,9 +96,9 @@ int32_t RenewNetDevice(NetDevice **netDev) } *netDev = NULL; #ifdef _PRE_HDF_LINUX - result = NetDeviceInit(ifName, strlen(ifName), FULL_OS); + result = NetDeviceInit(ifName, strlen(ifName), WIFI_LINK, FULL_OS); #else - result = NetDeviceInit(ifName, strlen(ifName), LITE_OS); + result = NetDeviceInit(ifName, strlen(ifName), WIFI_LINK, LITE_OS); #endif if (result == NULL) { HDF_LOGE("%s:alloc NetDevice return NULL!", __func__); @@ -163,9 +163,9 @@ struct NetDevice *AllocPlatformNetDevice(struct HdfWlanDevice *device) break; } #ifdef _PRE_HDF_LINUX - result = NetDeviceInit(ifName, strlen(ifName), FULL_OS); + result = NetDeviceInit(ifName, strlen(ifName), WIFI_LINK, FULL_OS); #else - result = NetDeviceInit(ifName, strlen(ifName), LITE_OS); + result = NetDeviceInit(ifName, strlen(ifName), WIFI_LINK, LITE_OS); #endif } while (false); if (result == NULL) { diff --git a/test/unittest/model/network/wifi/unittest/netdevice/net_device_test.c b/test/unittest/model/network/wifi/unittest/netdevice/net_device_test.c index 5d47a211d..4d41b0019 100644 --- a/test/unittest/model/network/wifi/unittest/netdevice/net_device_test.c +++ b/test/unittest/model/network/wifi/unittest/netdevice/net_device_test.c @@ -25,11 +25,12 @@ static bool WiFiNetDeviceTestEnv(void) HDF_LOGE("%s: strcpy_s fail", __func__); return false; } - g_netDevice = NetDeviceInit(devName, strlen(devName), LITE_OS); + g_netDevice = NetDeviceInit(devName, strlen(devName), WIFI_LINK, LITE_OS); if (g_netDevice == NULL) { HDF_LOGE("%s fail ", __func__); return false; } + g_netDevice->funType.wlanType = PROTOCOL_80211_IFTYPE_STATION; HDF_LOGE("%s success ", __func__); return true; } @@ -62,7 +63,7 @@ int32_t WiFiNetDviceTestAdd(void) return HDF_FAILURE; } } - if (NetDeviceAdd(g_netDevice, PROTOCOL_80211_IFTYPE_STATION) != HDF_SUCCESS) { + if (NetDeviceAdd(g_netDevice) != HDF_SUCCESS) { HDF_LOGE("%s add fail!", __func__); return HDF_FAILURE; } -- Gitee From cefbc25356adec0368bba06b2ed8a2bdcc47d0b3 Mon Sep 17 00:00:00 2001 From: haizhouyang Date: Thu, 29 Jul 2021 14:49:54 +0800 Subject: [PATCH 040/205] feature: auto detec gpio on linux Signed-off-by: haizhouyang --- support/platform/include/gpio_core.h | 8 ++- support/platform/include/plat_log.h | 2 +- support/platform/src/gpio_core.c | 74 ++++++++++++++++++---------- support/platform/src/gpio_if.c | 16 +++--- 4 files changed, 64 insertions(+), 36 deletions(-) diff --git a/support/platform/include/gpio_core.h b/support/platform/include/gpio_core.h index 6e1a0dc44..4f8fbdd6f 100644 --- a/support/platform/include/gpio_core.h +++ b/support/platform/include/gpio_core.h @@ -25,7 +25,7 @@ struct GpioCntlr; struct GpioMethod; struct GpioInfo; -#define GPIO_NUM_DEFAULT 200 +#define GPIO_NUM_MAX 0xFFFF /** * @brief Defines the struct which represent a hardware GPIO controller. @@ -138,6 +138,12 @@ void GpioCntlrIrqCallback(struct GpioCntlr *cntlr, uint16_t local); struct GpioCntlr *GpioGetCntlr(uint16_t gpio); +static inline uint16_t GpioToLocal(uint16_t gpio) +{ + struct GpioCntlr *cntlr = GpioGetCntlr(gpio); + return (cntlr == NULL) ? gpio : (gpio - cntlr->start); +} + static inline uint16_t GpioGetLocalNumber(struct GpioCntlr *cntlr, uint16_t gpio) { return (cntlr == NULL) ? gpio : (gpio - cntlr->start); diff --git a/support/platform/include/plat_log.h b/support/platform/include/plat_log.h index bc2d0671c..d3b4c6f29 100644 --- a/support/platform/include/plat_log.h +++ b/support/platform/include/plat_log.h @@ -11,7 +11,7 @@ #include "hdf_log.h" -#if defined(__LITEOS__) +#if defined(__LITEOS__) || defined(__KERNEL__) #define PLAT_LOGV(fmt, arg...) #else #define PLAT_LOGV(fmt, arg...) HDF_LOGV(fmt, ##arg) diff --git a/support/platform/src/gpio_core.c b/support/platform/src/gpio_core.c index 7224aeb2b..8419ab765 100644 --- a/support/platform/src/gpio_core.c +++ b/support/platform/src/gpio_core.c @@ -56,9 +56,49 @@ static void GpioCntlrListPut(void) (void)OsalSpinUnlockIrqRestore(&g_listLock, &g_irqFlags); } +static uint16_t GpioCntlrQueryStart(struct GpioCntlr *cntlr, struct DListHead *list) +{ + uint16_t freeStart; + uint16_t freeCount; + struct GpioCntlr *iterLast = NULL; + struct GpioCntlr *iterCur = NULL; + struct GpioCntlr *tmp = NULL; + + DLIST_FOR_EACH_ENTRY_SAFE(iterCur, tmp, list, struct GpioCntlr, list) { + if (iterLast == NULL) { + freeStart = 0; + freeCount = iterCur->start; + } else { + freeStart = iterLast->start + iterLast->count; + freeCount = iterCur->start - freeStart; + } + + if (cntlr->start < freeStart) { + HDF_LOGE("GpioCntlrQueryStart: start:%u not available(freeStart:%u, freeCount:%u)", + cntlr->start, freeStart, freeCount); + return GPIO_NUM_MAX; + } + + if ((cntlr->start + cntlr->count) <= (freeStart + freeCount)) { + return freeStart; + } + + iterLast = iterCur; + } + if (iterLast == NULL) { // empty list + return cntlr->start; + } + if (cntlr->start >= (iterLast->start + iterLast->count)) { + return iterLast->start + iterLast->count; + } + HDF_LOGE("GpioCntlrQueryStart: start:%u not available(lastStart:%u, lastCount:%u)", + cntlr->start, iterLast->start, iterLast->count); + return GPIO_NUM_MAX; +} + int32_t GpioCntlrAdd(struct GpioCntlr *cntlr) { - struct GpioCntlr *last = NULL; + uint16_t start; struct DListHead *list = NULL; if (cntlr == NULL) { @@ -90,12 +130,12 @@ int32_t GpioCntlrAdd(struct GpioCntlr *cntlr) OsalSpinInit(&cntlr->spin); list = GpioCntlrListGet(); - if (DListIsEmpty(list)) { - cntlr->start = 0; - } else { - last = DLIST_LAST_ENTRY(list, struct GpioCntlr, list); - cntlr->start = last->start + last->count; + if ((start = GpioCntlrQueryStart(cntlr, list)) >= GPIO_NUM_MAX) { + HDF_LOGE("GpioCntlrAdd: query range for start:%d fail:%d", cntlr->start, start); + GpioCntlrListPut(); + return HDF_ERR_INVALID_PARAM; } + cntlr->start = start; DListHeadInit(&cntlr->list); DListInsertTail(&cntlr->list, list); GpioCntlrListPut(); @@ -219,7 +259,6 @@ static int32_t GpioIrqBridgeFunc(uint16_t local, void *data) return HDF_SUCCESS; } -#ifndef __KERNEL__ static int GpioIrqThreadWorker(void *data) { int32_t ret; @@ -234,7 +273,7 @@ static int GpioIrqThreadWorker(void *data) break; } PLAT_LOGV("GpioIrqThreadWorker: enter! gpio:%u-%u", bridge->cntlr->start, bridge->local); - (void)bridge->func(bridge->local, bridge->data); + (void)bridge->func(bridge->local + bridge->cntlr->start, bridge->data); } /* it's the bridge struct we create before, so release it ourself */ (void)OsalSemDestroy(&bridge->sem); @@ -303,21 +342,9 @@ __ERR_FORMAT_NAME: OsalMemFree(bridge); return NULL; } -#else -static struct GpioIrqBridge *GpioIrqBridgeCreate(struct GpioCntlr *cntlr, - uint16_t local, GpioIrqFunc func, void *arg) -{ - (void)cntlr; - (void)local; - (void)func; - (void)arg; - return NULL; -} -#endif static void GpioIrqBridgeDestroy(struct GpioIrqBridge *bridge) { -#ifndef __KERNEL__ uint32_t flags; (void)OsalSpinLockIrqSave(&bridge->spin, &flags); if (!bridge->stop) { @@ -325,9 +352,6 @@ static void GpioIrqBridgeDestroy(struct GpioIrqBridge *bridge) (void)OsalSemPost(&bridge->sem); } (void)OsalSpinUnlockIrqRestore(&bridge->spin, &flags); -#else - (void)bridge; -#endif } void GpioCntlrIrqCallback(struct GpioCntlr *cntlr, uint16_t local) @@ -342,7 +366,7 @@ void GpioCntlrIrqCallback(struct GpioCntlr *cntlr, uint16_t local) HDF_LOGW("GpioCntlrIrqCallback: ginfo or irqFunc is NULL!"); } } else { - HDF_LOGW("GpioCntlrIrqCallback: invalid cntlr(ginfos) or loal num!"); + HDF_LOGW("GpioCntlrIrqCallback: invalid cntlr(ginfos) or loal num:%u!", local); } } @@ -372,11 +396,9 @@ int32_t GpioCntlrSetIrq(struct GpioCntlr *cntlr, uint16_t local, uint16_t mode, theData = bridge; theFunc = GpioIrqBridgeFunc; } -#ifndef __KERNEL__ if (bridge == NULL) { return HDF_FAILURE; } -#endif } (void)OsalSpinLockIrqSave(&cntlr->spin, &flags); diff --git a/support/platform/src/gpio_if.c b/support/platform/src/gpio_if.c index 444fdfe37..eca819fc0 100644 --- a/support/platform/src/gpio_if.c +++ b/support/platform/src/gpio_if.c @@ -16,40 +16,40 @@ int32_t GpioRead(uint16_t gpio, uint16_t *val) { - return GpioCntlrRead(GpioGetCntlr(gpio), gpio, val); + return GpioCntlrRead(GpioGetCntlr(gpio), GpioToLocal(gpio), val); } int32_t GpioWrite(uint16_t gpio, uint16_t val) { - return GpioCntlrWrite(GpioGetCntlr(gpio), gpio, val); + return GpioCntlrWrite(GpioGetCntlr(gpio), GpioToLocal(gpio), val); } int32_t GpioSetDir(uint16_t gpio, uint16_t dir) { - return GpioCntlrSetDir(GpioGetCntlr(gpio), gpio, dir); + return GpioCntlrSetDir(GpioGetCntlr(gpio), GpioToLocal(gpio), dir); } int32_t GpioGetDir(uint16_t gpio, uint16_t *dir) { - return GpioCntlrGetDir(GpioGetCntlr(gpio), gpio, dir); + return GpioCntlrGetDir(GpioGetCntlr(gpio), GpioToLocal(gpio), dir); } int32_t GpioSetIrq(uint16_t gpio, uint16_t mode, GpioIrqFunc func, void *arg) { - return GpioCntlrSetIrq(GpioGetCntlr(gpio), gpio, mode, func, arg); + return GpioCntlrSetIrq(GpioGetCntlr(gpio), GpioToLocal(gpio), mode, func, arg); } int32_t GpioUnSetIrq(uint16_t gpio) { - return GpioCntlrUnsetIrq(GpioGetCntlr(gpio), gpio); + return GpioCntlrUnsetIrq(GpioGetCntlr(gpio), GpioToLocal(gpio)); } int32_t GpioEnableIrq(uint16_t gpio) { - return GpioCntlrEnableIrq(GpioGetCntlr(gpio), gpio); + return GpioCntlrEnableIrq(GpioGetCntlr(gpio), GpioToLocal(gpio)); } int32_t GpioDisableIrq(uint16_t gpio) { - return GpioCntlrDisableIrq(GpioGetCntlr(gpio), gpio); + return GpioCntlrDisableIrq(GpioGetCntlr(gpio), GpioToLocal(gpio)); } -- Gitee From d21a817028ba962fad53724c79b3e175d24ba5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=87=AF?= Date: Thu, 29 Jul 2021 11:13:04 +0000 Subject: [PATCH 041/205] update model/input/driver/hdf_touch.c. --- model/input/driver/hdf_touch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/model/input/driver/hdf_touch.c b/model/input/driver/hdf_touch.c index 8d2f17078..d595e1461 100644 --- a/model/input/driver/hdf_touch.c +++ b/model/input/driver/hdf_touch.c @@ -106,7 +106,8 @@ static int32_t HandlePowerEvent(ChipDevice *chipDev, uint32_t *timing, uint32_t static int32_t InputPinMuxCfg(uint32_t regAddr, int32_t regSize, uint32_t regValue) { - uint8_t *base = NULL; + return HDF_SUCCESS; +/* uint8_t *base = NULL; if (regAddr == 0) { HDF_LOGE("%s: regAddr invalid", __func__); return HDF_FAILURE; @@ -120,7 +121,7 @@ static int32_t InputPinMuxCfg(uint32_t regAddr, int32_t regSize, uint32_t regVal OSAL_WRITEL(regValue, base); OsalIoUnmap((void *)base); - return HDF_SUCCESS; + return HDF_SUCCESS; */ } static int32_t SetPowerOnTiming(ChipDevice *chipDev) -- Gitee From bc35e450fc06a5c983db58069d70fa5e29e63a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=87=AF?= Date: Thu, 29 Jul 2021 11:39:48 +0000 Subject: [PATCH 042/205] add code for dayu Signed-off-by: huangkai71 --- model/input/driver/hdf_touch.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/model/input/driver/hdf_touch.c b/model/input/driver/hdf_touch.c index d595e1461..acaadd92c 100644 --- a/model/input/driver/hdf_touch.c +++ b/model/input/driver/hdf_touch.c @@ -106,8 +106,10 @@ static int32_t HandlePowerEvent(ChipDevice *chipDev, uint32_t *timing, uint32_t static int32_t InputPinMuxCfg(uint32_t regAddr, int32_t regSize, uint32_t regValue) { +#if defined(CONFIG_ARCH_SPRD) return HDF_SUCCESS; -/* uint8_t *base = NULL; +#endif + uint8_t *base = NULL; if (regAddr == 0) { HDF_LOGE("%s: regAddr invalid", __func__); return HDF_FAILURE; @@ -121,7 +123,7 @@ static int32_t InputPinMuxCfg(uint32_t regAddr, int32_t regSize, uint32_t regVal OSAL_WRITEL(regValue, base); OsalIoUnmap((void *)base); - return HDF_SUCCESS; */ + return HDF_SUCCESS; } static int32_t SetPowerOnTiming(ChipDevice *chipDev) @@ -265,9 +267,13 @@ static int32_t ChipDriverInit(ChipDevice *chipDev) CHECK_RETURN_VALUE(ret); HDF_LOGI("%s: chipDetect succ, ret = %d ", __func__, ret); +#if defined(CONFIG_ARCH_SPRD) + HDF_LOGI("%s: DAYU do not update firmware", __func__); +#else ret = chipDev->ops->UpdateFirmware(chipDev); CHECK_RETURN_VALUE(ret); HDF_LOGI("%s: update firmware success", __func__); +#endif ret = SetupChipIrq(chipDev); CHECK_RETURN_VALUE(ret); -- Gitee From 96d0a89eed80ced6a1c68cd153a05918f5ff4a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=87=AF?= Date: Thu, 29 Jul 2021 11:46:46 +0000 Subject: [PATCH 043/205] add code for dayu Signed-off-by: huangkai71 --- model/input/driver/touchscreen/touch_gt911.c | 27 +++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/model/input/driver/touchscreen/touch_gt911.c b/model/input/driver/touchscreen/touch_gt911.c index c25c7c099..2a5354f45 100644 --- a/model/input/driver/touchscreen/touch_gt911.c +++ b/model/input/driver/touchscreen/touch_gt911.c @@ -14,10 +14,6 @@ #include "input_i2c_ops.h" #include "touch_gt911.h" -#define AXIS_X_MAX 479 -#define AXIS_X_RANGE 0 -#define AXIS_Y_MAX 959 -#define AXIS_Y_RANGE 0 #define MAX_POINT 5 static int32_t ChipInit(ChipDevice *device) @@ -98,10 +94,17 @@ static void ParsePointData(ChipDevice *device, FrameData *frame, uint8_t *buf, u for (i = 0; i < pointNum; i++) { if (chipVer == 0) { // chipversion A:gt911_zsj5p5 frame->fingers[i].trackId = buf[GT_POINT_SIZE * i + GT_TRACK_ID]; +#if defined(CONFIG_ARCH_SPRD) + frame->fingers[i].y = (resY - 1 - ((buf[GT_POINT_SIZE * i + GT_X_LOW] & ONE_BYTE_MASK) | + ((buf[GT_POINT_SIZE * i + GT_X_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET))) * resX / resY; + frame->fingers[i].x = ((buf[GT_POINT_SIZE * i + GT_Y_LOW] & ONE_BYTE_MASK) | + ((buf[GT_POINT_SIZE * i + GT_Y_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET)) * resY / resX; +#else frame->fingers[i].y = (buf[GT_POINT_SIZE * i + GT_X_LOW] & ONE_BYTE_MASK) | ((buf[GT_POINT_SIZE * i + GT_X_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET); frame->fingers[i].x = (buf[GT_POINT_SIZE * i + GT_Y_LOW] & ONE_BYTE_MASK) | ((buf[GT_POINT_SIZE * i + GT_Y_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET); +#endif if (frame->fingers[i].x == 0) { frame->fingers[i].x = X_OFFSET; } @@ -189,17 +192,17 @@ static void SetAbility(ChipDevice *device) SET_BIT(ABS_MT_POSITION_Y) | SET_BIT(ABS_MT_TRACKING_ID); device->driver->inputDev->abilitySet.keyCode[3] = SET_BIT(KEY_UP) | SET_BIT(KEY_DOWN); device->driver->inputDev->attrSet.axisInfo[ABS_X].min = 0; - device->driver->inputDev->attrSet.axisInfo[ABS_X].max = AXIS_X_MAX; - device->driver->inputDev->attrSet.axisInfo[ABS_X].range = AXIS_X_RANGE; + device->driver->inputDev->attrSet.axisInfo[ABS_X].max = device->boardCfg->attr.resolutionX - 1; + device->driver->inputDev->attrSet.axisInfo[ABS_X].range = 0; device->driver->inputDev->attrSet.axisInfo[ABS_Y].min = 0; - device->driver->inputDev->attrSet.axisInfo[ABS_Y].max = AXIS_Y_MAX; - device->driver->inputDev->attrSet.axisInfo[ABS_Y].range = AXIS_Y_RANGE; + device->driver->inputDev->attrSet.axisInfo[ABS_Y].max = device->boardCfg->attr.resolutionY - 1; + device->driver->inputDev->attrSet.axisInfo[ABS_Y].range = 0; device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].min = 0; - device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].max = AXIS_X_MAX; - device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].range = AXIS_X_RANGE; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].max = device->boardCfg->attr.resolutionX - 1; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_X].range = 0; device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].min = 0; - device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].max = AXIS_Y_MAX; - device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].range = AXIS_Y_RANGE; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].max = device->boardCfg->attr.resolutionY - 1; + device->driver->inputDev->attrSet.axisInfo[ABS_MT_POSITION_Y].range = 0; device->driver->inputDev->attrSet.axisInfo[ABS_MT_TRACKING_ID].max = MAX_POINT; } -- Gitee From 6f00697e5e75b9db67d3448121d75ff335e5bac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=87=AF?= Date: Thu, 29 Jul 2021 12:31:36 +0000 Subject: [PATCH 044/205] update model/input/driver/touchscreen/touch_gt911.c. Signed-off-by: huangkai71 --- model/input/driver/touchscreen/touch_gt911.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/model/input/driver/touchscreen/touch_gt911.c b/model/input/driver/touchscreen/touch_gt911.c index 2a5354f45..7ed36242e 100644 --- a/model/input/driver/touchscreen/touch_gt911.c +++ b/model/input/driver/touchscreen/touch_gt911.c @@ -96,9 +96,11 @@ static void ParsePointData(ChipDevice *device, FrameData *frame, uint8_t *buf, u frame->fingers[i].trackId = buf[GT_POINT_SIZE * i + GT_TRACK_ID]; #if defined(CONFIG_ARCH_SPRD) frame->fingers[i].y = (resY - 1 - ((buf[GT_POINT_SIZE * i + GT_X_LOW] & ONE_BYTE_MASK) | - ((buf[GT_POINT_SIZE * i + GT_X_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET))) * resX / resY; + ((buf[GT_POINT_SIZE * i + GT_X_HIGH] & ONE_BYTE_MASK) << + ONE_BYTE_OFFSET))) * resX / resY; frame->fingers[i].x = ((buf[GT_POINT_SIZE * i + GT_Y_LOW] & ONE_BYTE_MASK) | - ((buf[GT_POINT_SIZE * i + GT_Y_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET)) * resY / resX; + ((buf[GT_POINT_SIZE * i + GT_Y_HIGH] & ONE_BYTE_MASK) << + ONE_BYTE_OFFSET)) * resY / resX; #else frame->fingers[i].y = (buf[GT_POINT_SIZE * i + GT_X_LOW] & ONE_BYTE_MASK) | ((buf[GT_POINT_SIZE * i + GT_X_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET); -- Gitee From 663b503074b3ce82cbe8e7babf6261e6e6b436bd Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Fri, 30 Jul 2021 06:34:51 +0000 Subject: [PATCH 045/205] add hdf drm panel driver for display Signed-off-by: YOUR_NAME --- .../driver/{ => adapter_soc}/hi35xx_disp.c | 280 ++--------- .../hi35xx_disp.h} | 114 +---- model/display/driver/hdf_disp.c | 152 +++--- model/display/driver/hdf_disp.h | 122 ++++- model/display/driver/hdf_drm_panel.c | 257 ++++++++++ model/display/driver/hdf_drm_panel.h | 25 + model/display/driver/hi35xx_disp.h | 29 -- model/display/driver/lcd_abs_if.c | 57 --- model/display/driver/lcdkit/lite_lcdkit.c | 2 +- model/display/driver/lcdkit/lite_lcdkit.h | 1 - model/display/driver/panel/ili9881c_boe.c | 340 +++++++++++++ model/display/driver/panel/ili9881c_boe.h | 446 ++++++++++++++++++ model/display/driver/panel/mipi_icn9700.c | 5 +- model/display/driver/panel/ssp_st7789.c | 9 +- 14 files changed, 1332 insertions(+), 507 deletions(-) rename model/display/driver/{ => adapter_soc}/hi35xx_disp.c (57%) rename model/display/driver/{lcd_abs_if.h => adapter_soc/hi35xx_disp.h} (59%) create mode 100644 model/display/driver/hdf_drm_panel.c create mode 100644 model/display/driver/hdf_drm_panel.h delete mode 100644 model/display/driver/hi35xx_disp.h delete mode 100644 model/display/driver/lcd_abs_if.c create mode 100644 model/display/driver/panel/ili9881c_boe.c create mode 100644 model/display/driver/panel/ili9881c_boe.h diff --git a/model/display/driver/hi35xx_disp.c b/model/display/driver/adapter_soc/hi35xx_disp.c similarity index 57% rename from model/display/driver/hi35xx_disp.c rename to model/display/driver/adapter_soc/hi35xx_disp.c index 98ddc0e3e..febf1ef92 100644 --- a/model/display/driver/hi35xx_disp.c +++ b/model/display/driver/adapter_soc/hi35xx_disp.c @@ -12,20 +12,12 @@ #include "hdf_device_desc.h" #include "hdf_disp.h" #include "hdf_log.h" -#include "lcd_abs_if.h" #include "osal_io.h" -#include "osal_mem.h" #include "pwm_if.h" #define TRANSFORM_KILO 1000 #define TRANSFORM_MILL 1000000 -struct Hi35xxDispCtrl { - struct DispControl ctrl; - unsigned long mipiCfgBase; - unsigned long pwmCfgBase; -}; - static void MipiMuxCfg(unsigned long ioCfgBase) { /* config dsi data lane0 */ @@ -107,11 +99,11 @@ void Lcd24BitMuxCfg(unsigned long ioCfgBase) OSAL_WRITEL(0x532, ioCfgBase + 0x0030); } -static void LcdPinMuxCfg(const struct Hi35xxDispCtrl *hi35xxCtrl, uint32_t intf) +static void LcdPinMuxCfg(uint32_t intf) { unsigned long ioCfgBase; - ioCfgBase = hi35xxCtrl->mipiCfgBase; + ioCfgBase = (unsigned long)OsalIoRemap(IO_CFG2_BASE, IO_CFG_SIZE); if (intf == MIPI_DSI) { MipiMuxCfg(ioCfgBase); } else if (intf == LCD_6BIT) { @@ -125,12 +117,11 @@ static void LcdPinMuxCfg(const struct Hi35xxDispCtrl *hi35xxCtrl, uint32_t intf) } } -static void PwmPinMuxCfg(const struct Hi35xxDispCtrl *hi35xxCtrl, uint32_t dev) +static void PwmPinMuxCfg(uint32_t dev) { /* pwm pin config */ unsigned long ioCfgBase; - - ioCfgBase = hi35xxCtrl->pwmCfgBase; + ioCfgBase = (unsigned long)OsalIoRemap(IO_CFG1_BASE, IO_CFG_SIZE); switch (dev) { case PWM_DEV0: OSAL_WRITEL(0x601, ioCfgBase + 0x0024); @@ -206,7 +197,7 @@ static uint32_t CalcDataRate(struct PanelInfo *info) static int32_t MipiDsiInit(struct PanelInfo *info) { int32_t ret; - struct DevHandle *mipiHandle = NULL; + DevHandle mipiHandle = NULL; struct MipiCfg cfg; mipiHandle = MipiDsiOpen(0); @@ -240,18 +231,19 @@ static int32_t MipiDsiInit(struct PanelInfo *info) return ret; } -static int32_t PwmInit(struct Hi35xxDispCtrl *hi35xxCtrl, struct PanelInfo *info) +static int32_t PwmInit(struct PanelInfo *info) { int32_t ret; /* pwm pin config */ - PwmPinMuxCfg(hi35xxCtrl, info->pwm.dev); + PwmPinMuxCfg(info->pwm.dev); /* pwm config */ - struct DevHandle *pwmHandle = PwmOpen(info->pwm.dev); + DevHandle pwmHandle = PwmOpen(info->pwm.dev); if (pwmHandle == NULL) { HDF_LOGE("%s: PwmOpen failed", __func__); return HDF_FAILURE; } + struct PwmConfig config; (void)memset_s(&config, sizeof(struct PwmConfig), 0, sizeof(struct PwmConfig)); config.duty = 1; @@ -267,59 +259,6 @@ static int32_t PwmInit(struct Hi35xxDispCtrl *hi35xxCtrl, struct PanelInfo *info return HDF_SUCCESS; } -static int32_t Hi35xxHardwareInit(struct Hi35xxDispCtrl *hi35xxCtrl) -{ - int32_t i; - int32_t panelNum; - int32_t ret = HDF_FAILURE; - struct PanelData **panel = NULL; - struct PanelInfo *info = NULL; - - if (hi35xxCtrl->ctrl.panelManager == NULL) { - HDF_LOGE("%s: panelManager is null", __func__); - return HDF_FAILURE; - } - if (hi35xxCtrl->ctrl.panelManager->panelNum <= 0) { - HDF_LOGE("%s: none of panels registered", __func__); - return HDF_FAILURE; - } - panelNum = hi35xxCtrl->ctrl.panelManager->panelNum; - panel = hi35xxCtrl->ctrl.panelManager->panel; - for (i = 0; i < panelNum; i++) { - info = panel[i]->info; - if (info == NULL) { - HDF_LOGE("%s:get info failed", __func__); - return HDF_FAILURE; - } - if (info->blk.type == BLK_PWM) { - ret = PwmInit(hi35xxCtrl, info); - if (ret) { - HDF_LOGE("%s:PwmInit failed", __func__); - return HDF_FAILURE; - } - } - /* lcd pin mux config */ - LcdPinMuxCfg(hi35xxCtrl, info->intfType); - if (info->intfType == MIPI_DSI) { - /* mipi dsi init */ - ret = MipiDsiInit(info); - if (ret) { - HDF_LOGE("%s:MipiDsiInit failed", __func__); - return HDF_FAILURE; - } - } - if (panel[i]->init != NULL) { - /* panel driver init */ - ret = panel[i]->init(panel[i]); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: panelData->init failed", __func__); - return HDF_FAILURE; - } - } - } - return ret; -} - static int32_t GetLcdIntfType(enum LcdIntfType type, uint32_t *out) { int32_t ret = HDF_SUCCESS; @@ -351,187 +290,64 @@ static int32_t GetLcdIntfType(enum LcdIntfType type, uint32_t *out) return ret; } -static int32_t Hi35xxGetDispInfo(struct DispControl *dispCtrl, uint32_t devId) -{ - struct PanelInfo *panelInfo = NULL; - struct DispInfo *info = NULL; - struct PanelData *panel = NULL; - - if (dispCtrl == NULL) { - HDF_LOGE("%s:dispCtrl is null", __func__); - return HDF_FAILURE; - } - if (dispCtrl->panelManager == NULL || (devId >= dispCtrl->panelManager->panelNum)) { - HDF_LOGE("%s: get panel fail", __func__); - return HDF_FAILURE; - } - panel = dispCtrl->panelManager->panel[devId]; - if (panel == NULL) { - HDF_LOGE("%s:panel is null", __func__); - return HDF_FAILURE; - } - panelInfo = panel->info; - if (panelInfo == NULL) { - HDF_LOGE("%s:get info failed", __func__); - return HDF_FAILURE; - } - info = dispCtrl->info; - if (info == NULL) { - HDF_LOGE("%s:info is null", __func__); - return HDF_FAILURE; - } - info->width = panelInfo->width; - info->height = panelInfo->height; - info->hbp = panelInfo->hbp; - info->hfp = panelInfo->hfp; - info->hsw = panelInfo->hsw; - info->vbp = panelInfo->vbp; - info->vfp = panelInfo->vfp; - info->vsw = panelInfo->vsw; - if (GetLcdIntfType(panelInfo->intfType, &info->intfType) != HDF_SUCCESS) { - HDF_LOGE("%s:GetLcdIntfType failed", __func__); - return HDF_FAILURE; - } - info->intfSync = panelInfo->intfSync; - info->frameRate = panelInfo->frameRate; - info->minLevel = panelInfo->blk.minLevel; - info->maxLevel = panelInfo->blk.maxLevel; - info->defLevel = panelInfo->blk.defLevel; - HDF_LOGI("info->width = %d, info->height = %d", info->width, info->height); - HDF_LOGI("info->hbp = %d, info->hfp = %d", info->hbp, info->hfp); - HDF_LOGI("info->frameRate = %d, info->intfSync = %d", info->frameRate, info->intfSync); - return HDF_SUCCESS; -} - -static int32_t Hi35xxOn(struct DispControl *dispCtrl, uint32_t devId) +static int32_t Hi35xxHardWareInit(void) { - int32_t ret = HDF_FAILURE; + int32_t i; + int32_t ret; + struct PanelManager *panelManager = NULL; struct PanelData *panel = NULL; + struct PanelInfo *info = NULL; - if (dispCtrl == NULL) { - HDF_LOGE("%s: dispCtrl is null", __func__); - return HDF_FAILURE; - } - if (dispCtrl->panelManager == NULL || (devId >= dispCtrl->panelManager->panelNum)) { - HDF_LOGE("%s: get panel fail", __func__); - return HDF_FAILURE; - } - panel = dispCtrl->panelManager->panel[devId]; - if (panel == NULL) { - HDF_LOGE("%s: panel is null", __func__); + panelManager = GetPanelManager(); + if (panelManager == NULL) { + HDF_LOGE("%s: panelManager is null", __func__); return HDF_FAILURE; } - if (panel->on != NULL) { - /* panel driver on */ - ret = panel->on(panel); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: panel->on failed", __func__); + for (i = 0; i < panelManager->panelNum; i++) { + panel = panelManager->panel[i]; + info = panel->info; + if (info == NULL) { + HDF_LOGE("%s:GetPanelInfo failed", __func__); return HDF_FAILURE; } - } - return ret; -} - -static int32_t Hi35xxOff(struct DispControl *dispCtrl, uint32_t devId) -{ - int32_t ret = HDF_FAILURE; - struct PanelData *panel = NULL; - - if (dispCtrl == NULL) { - HDF_LOGE("%s: dispCtrl is null", __func__); - return HDF_FAILURE; - } - if (dispCtrl->panelManager == NULL || (devId >= dispCtrl->panelManager->panelNum)) { - HDF_LOGE("%s: get panel fail", __func__); - return HDF_FAILURE; - } - panel = dispCtrl->panelManager->panel[devId]; - if (panel == NULL) { - HDF_LOGE("%s: panel is null", __func__); - return HDF_FAILURE; - } - if (panel->off != NULL) { - /* panel driver off */ - ret = panel->off(panel); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: panel->off failed", __func__); - return HDF_FAILURE; + if (info->blk.type == BLK_PWM) { + ret = PwmInit(info); + if (ret) { + HDF_LOGE("%s:PwmInit failed", __func__); + return HDF_FAILURE; + } } - } - return ret; -} - -static int32_t Hi35xxSetBacklight(struct DispControl *dispCtrl, uint32_t devId, uint32_t level) -{ - int32_t ret = HDF_FAILURE; - struct PanelData *panel = NULL; - - if (dispCtrl == NULL) { - HDF_LOGE("%s: dispCtrl is null", __func__); - return HDF_FAILURE; - } - if (dispCtrl->panelManager == NULL || (devId >= dispCtrl->panelManager->panelNum)) { - HDF_LOGE("%s: get panel fail", __func__); - return HDF_FAILURE; - } - panel = dispCtrl->panelManager->panel[devId]; - if (panel == NULL) { - HDF_LOGE("%s: panel is null", __func__); - return HDF_FAILURE; - } - if (panel->setBacklight != NULL) { - /* panel driver set backlight */ - ret = panel->setBacklight(panel, level); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: setBacklight failed", __func__); + /* lcd pin mux config */ + LcdPinMuxCfg(info->intfType); + if (info->intfType == MIPI_DSI) { + /* mipi dsi init */ + ret = MipiDsiInit(info); + if (ret) { + HDF_LOGE("%s:MipiDsiInit failed", __func__); + return HDF_FAILURE; + } + } + if (GetLcdIntfType(info->intfType, &info->intfType) != HDF_SUCCESS) { + HDF_LOGE("%s:GetLcdIntfType failed", __func__); return HDF_FAILURE; } + if (panel->init != NULL) { + if ((panel->init(panel)) != HDF_SUCCESS) { + HDF_LOGE("%s:panel[%d] init failed", __func__, i); + return HDF_FAILURE; + } + } } - return ret; -} - -static int32_t Hi35xxResInit(struct Hi35xxDispCtrl *hi35xxCtrl, struct PanelManager *panelManager) -{ - hi35xxCtrl->ctrl.ops.on = Hi35xxOn; - hi35xxCtrl->ctrl.ops.off = Hi35xxOff; - hi35xxCtrl->ctrl.ops.setBacklight = Hi35xxSetBacklight; - hi35xxCtrl->ctrl.ops.getDispInfo = Hi35xxGetDispInfo; - hi35xxCtrl->ctrl.panelManager = panelManager; - hi35xxCtrl->mipiCfgBase = (unsigned long)OsalIoRemap(IO_CFG2_BASE, IO_CFG_SIZE); - hi35xxCtrl->pwmCfgBase = (unsigned long)OsalIoRemap(IO_CFG1_BASE, IO_CFG_SIZE); return HDF_SUCCESS; } static int32_t Hi35xxEntryInit(struct HdfDeviceObject *object) { - struct PanelManager *panelManager = NULL; - struct Hi35xxDispCtrl *hi35xxCtrl = NULL; - if (object == NULL) { - HDF_LOGE("%s: object is null!", __func__); - return HDF_FAILURE; - } - hi35xxCtrl = (struct Hi35xxDispCtrl *)OsalMemCalloc(sizeof(struct Hi35xxDispCtrl)); - if (hi35xxCtrl == NULL) { - HDF_LOGE("%s hi35xxCtrl malloc fail", __func__); - return HDF_FAILURE; - } - panelManager = GetPanelManager(); - if (panelManager == NULL) { - HDF_LOGE("%s: panelManager is null", __func__); - return HDF_FAILURE; - } - if (Hi35xxResInit(hi35xxCtrl, panelManager) == HDF_FAILURE) { - HDF_LOGE("%s Hi35xxResInit fail", __func__); - return HDF_FAILURE; - } - if (Hi35xxHardwareInit(hi35xxCtrl) == HDF_FAILURE) { - HDF_LOGE("%s Hi35xxHardwareInit fail", __func__); + HDF_LOGE("%s: object is null", __func__); return HDF_FAILURE; } - hi35xxCtrl->ctrl.object = object; - hi35xxCtrl->ctrl.object->priv = hi35xxCtrl; - return RegisterDispCtrl(&hi35xxCtrl->ctrl); + return Hi35xxHardWareInit(); } struct HdfDriverEntry g_hi35xxDevEntry = { diff --git a/model/display/driver/lcd_abs_if.h b/model/display/driver/adapter_soc/hi35xx_disp.h similarity index 59% rename from model/display/driver/lcd_abs_if.h rename to model/display/driver/adapter_soc/hi35xx_disp.h index aa20f497f..682546b93 100644 --- a/model/display/driver/lcd_abs_if.h +++ b/model/display/driver/adapter_soc/hi35xx_disp.h @@ -6,29 +6,24 @@ * See the LICENSE file in the root of this repository for complete details. */ -#ifndef LCD_ABS_IF_H -#define LCD_ABS_IF_H +#ifndef HI35XX_DISP_H +#define HI35XX_DISP_H #include "hdf_base.h" -#include "hdf_device_desc.h" -#include "hdf_log.h" -#include "mipi_dsi_if.h" -/* support max panel number */ -#define PANEL_MAX 2 +#define IO_CFG1_BASE 0x111F0000 +#define IO_CFG2_BASE 0x112F0000 +#define IO_CFG_SIZE 0x10000 -enum LcdIntfType { - MIPI_DSI, - LCD_6BIT, - LCD_8BIT, - LCD_16BIT, - LCD_18BIT, - LCD_24BIT, -}; +#define PWM_DEV0 0 +#define PWM_DEV1 1 -enum BacklightType { - BLK_PWM, - BLK_MIPI, -}; +/* output interface type */ +#define INTF_LCD_6BIT (0x01L << 9) +#define INTF_LCD_8BIT (0x01L << 10) +#define INTF_LCD_16BIT (0x01L << 11) +#define INTF_LCD_18BIT (0x01L << 12) +#define INTF_LCD_24BIT (0x01L << 13) +#define INTF_MIPI (0x01L << 14) /* output timing */ enum IntfSync { @@ -82,83 +77,4 @@ enum IntfSync { OUTPUT_7680X4320_30, /* For HDMI2.1 at 30 Hz */ }; -struct MipiDsiDesc { - enum DsiLane lane; - enum DsiMode mode; /* output mode: DSI_VIDEO/DSI_CMD */ - enum DsiBurstMode burstMode; - enum DsiOutFormat format; -}; - -enum PowerStatus { - POWER_STATUS_ON, /* The power status is on */ - POWER_STATUS_STANDBY, /* The power status is standby */ - POWER_STATUS_SUSPEND, /* The power status is suspend */ - POWER_STATUS_OFF, /* The power status is off */ - POWER_STATUS_BUTT -}; - -struct BlkDesc { - uint32_t type; - uint32_t minLevel; - uint32_t maxLevel; - uint32_t defLevel; -}; - -struct PwmCfg { - uint32_t dev; - uint32_t period; -}; - -struct PanelInfo { - uint32_t width; - uint32_t height; - uint32_t hbp; - uint32_t hfp; - uint32_t hsw; - uint32_t vbp; - uint32_t vfp; - uint32_t vsw; - uint32_t frameRate; - enum LcdIntfType intfType; - enum IntfSync intfSync; - struct MipiDsiDesc mipi; - struct BlkDesc blk; - struct PwmCfg pwm; -}; - -struct PanelStatus { - enum PowerStatus powerStatus; - uint32_t currLevel; -}; - -struct PanelData; -struct PanelEsd { - bool support; - uint32_t interval; - uint32_t state; - uint32_t recoveryNum; - uint32_t cmpMode; - int32_t (*checkFunc)(struct PanelData *panel); - void *expect_data; -}; - -struct PanelData { - struct HdfDeviceObject *object; - int32_t (*init)(struct PanelData *panel); - int32_t (*on)(struct PanelData *panel); - int32_t (*off)(struct PanelData *panel); - int32_t (*setBacklight)(struct PanelData *panel, uint32_t level); - struct PanelInfo *info; - struct PanelStatus status; - struct PanelEsd *esd; -}; - -struct PanelManager { - struct PanelData *panel[PANEL_MAX]; - uint32_t panelNum; -}; - -int32_t RegisterPanel(struct PanelData *data); -struct PanelManager *GetPanelManager(void); -struct PanelData *GetPanel(int32_t index); -#endif /* LCD_ABS_IF_H */ +#endif /* HI35XX_DISP_H */ diff --git a/model/display/driver/hdf_disp.c b/model/display/driver/hdf_disp.c index 77b80cb54..dbbf41a3c 100644 --- a/model/display/driver/hdf_disp.c +++ b/model/display/driver/hdf_disp.c @@ -14,27 +14,40 @@ #define OFFSET_TWO_BYTE 16 static struct DispManager *g_dispManager = NULL; - -int32_t RegisterDispCtrl(struct DispControl *dispCtrl) +static struct PanelManager g_panelManager; +int32_t RegisterPanel(struct PanelData *data) { - if (dispCtrl == NULL) { - HDF_LOGE("%s: dispCtrl is null", __func__); + int32_t panelNum; + + if (data == NULL) { + HDF_LOGE("%s: panel data is null", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (data->info == NULL) { + HDF_LOGE("%s panel info is null", __func__); return HDF_FAILURE; } - if (g_dispManager == NULL) { - g_dispManager = (struct DispManager *)OsalMemCalloc(sizeof(struct DispManager)); - if (g_dispManager == NULL) { - HDF_LOGE("%s g_dispManager malloc fail", __func__); - return HDF_FAILURE; - } - g_dispManager->dispCtrl = dispCtrl; - g_dispManager->panelManager = dispCtrl->panelManager; + panelNum = g_panelManager.panelNum; + if (panelNum >= PANEL_MAX) { + HDF_LOGE("%s registered panel up PANEL_MAX", __func__); + return HDF_FAILURE; } - HDF_LOGI("%s: success", __func__); + g_panelManager.panel[panelNum] = data; + g_panelManager.panelNum++; + HDF_LOGI("%s: register success", __func__); return HDF_SUCCESS; } -static struct DispManager *GetDispManager(void) +struct PanelManager *GetPanelManager(void) +{ + if (g_panelManager.panelNum == 0) { + return NULL; + } else { + return &g_panelManager; + } +} + +struct DispManager *GetDispManager(void) { if (g_dispManager != NULL && g_dispManager->initialzed) { return g_dispManager; @@ -87,7 +100,6 @@ static int32_t SetDispBacklight(uint32_t devId, uint32_t level) int32_t ret = HDF_FAILURE; struct DispManager *disp = NULL; struct PanelInfo *info = NULL; - struct DispControlOps *ops = NULL; struct PanelData *panel = NULL; disp = GetDispManager(); @@ -104,10 +116,6 @@ static int32_t SetDispBacklight(uint32_t devId, uint32_t level) } else if (level < info->blk.minLevel && level != 0) { level = info->blk.minLevel; } - if (disp->dispCtrl == NULL) { - HDF_LOGE("%s:dispCtrl is null", __func__); - return HDF_FAILURE; - } OsalMutexLock(&disp->dispMutex); if (panel->status.powerStatus != POWER_STATUS_ON) { HDF_LOGE("%s:devId[%d] not in power on mode", __func__, devId); @@ -119,9 +127,8 @@ static int32_t SetDispBacklight(uint32_t devId, uint32_t level) OsalMutexUnlock(&disp->dispMutex); return HDF_SUCCESS; } - ops = &disp->dispCtrl->ops; - if (ops->setBacklight) { - ret = ops->setBacklight(disp->dispCtrl, devId, level); + if (panel->setBacklight) { + ret = panel->setBacklight(panel, level); if (ret != HDF_SUCCESS) { HDF_LOGE("%s:setBacklight failed", __func__); OsalMutexUnlock(&disp->dispMutex); @@ -135,9 +142,8 @@ static int32_t SetDispBacklight(uint32_t devId, uint32_t level) static int32_t GetDispInfo(uint32_t devId, struct DispInfo *info) { - int32_t ret = HDF_FAILURE; - struct DispControlOps *ops = NULL; struct DispManager *disp = NULL; + struct PanelData *panel = NULL; if (info == NULL) { HDF_LOGE("%s:info is null", __func__); @@ -148,32 +154,37 @@ static int32_t GetDispInfo(uint32_t devId, struct DispInfo *info) HDF_LOGE("%s: disp is null", __func__); return HDF_FAILURE; } - if (disp->dispCtrl == NULL) { - HDF_LOGE("%s: dispCtrl is null", __func__); + if (devId >= disp->panelManager->panelNum) { + HDF_LOGE("%s: devId exceed registered panelNum", __func__); return HDF_FAILURE; } - disp->dispCtrl->info = info; - ops = &disp->dispCtrl->ops; - if (ops->getDispInfo != NULL) { - ret = ops->getDispInfo(disp->dispCtrl, devId); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: getDispInfo failed", __func__); - return HDF_FAILURE; - } - } - return ret; + panel = disp->panelManager->panel[devId]; + info->width = panel->info->width; + info->height = panel->info->height; + info->hbp = panel->info->hbp; + info->hfp = panel->info->hfp; + info->hsw = panel->info->hsw; + info->vbp = panel->info->vbp; + info->vfp = panel->info->vfp; + info->vsw = panel->info->vsw; + info->intfType = panel->info->intfType; + info->intfSync = panel->info->intfSync; + info->frameRate = panel->info->frameRate; + info->minLevel = panel->info->blk.minLevel; + info->maxLevel = panel->info->blk.maxLevel; + info->defLevel = panel->info->blk.defLevel; + return HDF_SUCCESS; } static int32_t SetDispPower(uint32_t devId, uint32_t powerStatus) { int32_t ret = HDF_FAILURE; - struct DispControlOps *ops = NULL; struct DispManager *disp = NULL; struct PanelData *panel = NULL; disp = GetDispManager(); - if (disp == NULL || disp->dispCtrl == NULL) { - HDF_LOGE("%s:disp or dispCtrl is null", __func__); + if (disp == NULL) { + HDF_LOGE("%s:disp is null", __func__); return HDF_FAILURE; } if (devId >= disp->panelManager->panelNum) { @@ -187,19 +198,18 @@ static int32_t SetDispPower(uint32_t devId, uint32_t powerStatus) HDF_LOGE("%s:devId[%d] already in mode = %d", __func__, devId, powerStatus); return HDF_SUCCESS; } - ops = &disp->dispCtrl->ops; switch (powerStatus) { case POWER_STATUS_ON: - if (ops->on) { - ret = ops->on(disp->dispCtrl, devId); + if (panel->on) { + ret = panel->on(panel); } if (ret == HDF_SUCCESS) { EsdCheckStartUp(disp->esd, devId); } break; case POWER_STATUS_OFF: - if (ops->off) { - ret = ops->off(disp->dispCtrl, devId); + if (panel->off) { + ret = panel->off(panel); } if (ret == HDF_SUCCESS) { EsdCheckEnd(disp->esd, devId); @@ -388,18 +398,15 @@ static int HdfDispBind(struct HdfDeviceObject *dev) return HDF_SUCCESS; } -static void PanelRecovery(struct DispControl *dispCtrl, uint32_t devId) +static void PanelRecovery(struct PanelData *panel) { - struct DispControlOps *ops = NULL; - HDF_LOGI("%s enter", __func__); - ops = &dispCtrl->ops; - if (ops->off) { - ops->off(dispCtrl, devId); + if (panel->off) { + panel->off(panel); } OsalMSleep(150); // delay 150ms - if (ops->on) { - ops->on(dispCtrl, devId); + if (panel->on) { + panel->on(panel); } } @@ -425,7 +432,7 @@ static void EsdWorkHandler(void *arg) struct DispManager *disp = NULL; disp = GetDispManager(); - if ((disp->dispCtrl == NULL) || (devId >= disp->panelManager->panelNum)) { + if (devId >= disp->panelManager->panelNum) { HDF_LOGE("%s: dispCtrl is null or panel is null", __func__); return; } @@ -436,7 +443,7 @@ static void EsdWorkHandler(void *arg) if (ret != HDF_SUCCESS) { OsalMutexLock(&disp->dispMutex); if (panel->esd->state == ESD_RUNNING) { - PanelRecovery(disp->dispCtrl, devId); + PanelRecovery(panel); } else { HDF_LOGI("%s: esd check has disabled", __func__); OsalMutexUnlock(&disp->dispMutex); @@ -445,7 +452,7 @@ static void EsdWorkHandler(void *arg) OsalMutexUnlock(&disp->dispMutex); panel->esd->recoveryNum++; } - HDF_LOGD("%s devId[%d] recoveryNum = %d",__func__, devId, panel->esd->recoveryNum); + HDF_LOGD("%s devId[%d] recoveryNum = %d", __func__, devId, panel->esd->recoveryNum); if (panel->esd->recoveryNum >= ESD_MAX_RECOVERY) { panel->esd->recoveryNum = 0; OsalMutexLock(&disp->dispMutex); @@ -475,7 +482,7 @@ static void EsdCheckStartUp(struct DispEsd *esd, uint32_t devId) EsdTimerHandler, (uintptr_t)devId); OsalTimerStartLoop(esd->timer[devId]); esd->panelEsd[devId]->state = ESD_RUNNING; - HDF_LOGI("%s , devId[%d] enable esd check", __func__, devId); + HDF_LOGI("%s devId[%d] enable esd check", __func__, devId); } } } @@ -633,18 +640,16 @@ static int32_t EsdCheckInit(struct DispManager *disp) return HDF_SUCCESS; } -static int32_t HdfDispEntryInit(struct HdfDeviceObject *object) +static int32_t DispManagerInit(struct PanelManager *panelManager) { int32_t ret; - if (object == NULL) { - HDF_LOGE("%s: object is null!", __func__); - return HDF_FAILURE; - } + g_dispManager = (struct DispManager *)OsalMemCalloc(sizeof(struct DispManager)); if (g_dispManager == NULL) { - HDF_LOGE("%s: g_dispManager is null", __func__); + HDF_LOGE("%s g_dispManager malloc fail", __func__); return HDF_FAILURE; } + g_dispManager->panelManager = panelManager; ret = HdfWorkQueueInit(&g_dispManager->dispWorkQueue, "dispWQ"); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: HdfWorkQueueInit fail", __func__); @@ -661,6 +666,29 @@ static int32_t HdfDispEntryInit(struct HdfDeviceObject *object) return HDF_SUCCESS; } +static int32_t HdfDispEntryInit(struct HdfDeviceObject *object) +{ + int32_t ret; + struct PanelManager *panelManager = NULL; + + if (object == NULL) { + HDF_LOGE("%s: object is null!", __func__); + return HDF_FAILURE; + } + panelManager = GetPanelManager(); + if (panelManager == NULL) { + HDF_LOGE("%s: panelManager is null!", __func__); + return HDF_FAILURE; + } + ret = DispManagerInit(panelManager); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: DispManagerInit fail", __func__); + return HDF_FAILURE; + } + HDF_LOGI("%s success", __func__); + return HDF_SUCCESS; +} + struct HdfDriverEntry g_dispDevEntry = { .moduleVersion = 1, .moduleName = "HDF_DISP", diff --git a/model/display/driver/hdf_disp.h b/model/display/driver/hdf_disp.h index 4c9f2e852..6d7bb13ea 100644 --- a/model/display/driver/hdf_disp.h +++ b/model/display/driver/hdf_disp.h @@ -10,9 +10,10 @@ #define HDF_DISP_H #include "hdf_base.h" #include "hdf_device_desc.h" +#include "hdf_log.h" #include "hdf_sbuf.h" #include "hdf_workqueue.h" -#include "lcd_abs_if.h" +#include "mipi_dsi_if.h" #include "osal_mem.h" #include "osal_mutex.h" #include "osal_timer.h" @@ -23,6 +24,102 @@ #define HDF_LOG_TAG HDF_DISP #define ESD_DEFAULT_INTERVAL 5000 #define ESD_MAX_RECOVERY 10 +/* support max panel number */ +#define PANEL_MAX 2 + +enum LcdIntfType { + MIPI_DSI, + LCD_6BIT, + LCD_8BIT, + LCD_16BIT, + LCD_18BIT, + LCD_24BIT, +}; + +enum BacklightType { + BLK_PWM, + BLK_MIPI, +}; + +struct MipiDsiDesc { + enum DsiLane lane; + enum DsiMode mode; /* output mode: DSI_VIDEO/DSI_CMD */ + enum DsiBurstMode burstMode; + enum DsiOutFormat format; +}; + +enum PowerStatus { + POWER_STATUS_ON, /* The power status is on */ + POWER_STATUS_STANDBY, /* The power status is standby */ + POWER_STATUS_SUSPEND, /* The power status is suspend */ + POWER_STATUS_OFF, /* The power status is off */ + POWER_STATUS_BUTT +}; + +struct BlkDesc { + uint32_t type; + uint32_t minLevel; + uint32_t maxLevel; + uint32_t defLevel; +}; + +struct PwmCfg { + uint32_t dev; + uint32_t period; +}; + +struct PanelInfo { + uint32_t width; + uint32_t height; + uint32_t hbp; + uint32_t hfp; + uint32_t hsw; + uint32_t vbp; + uint32_t vfp; + uint32_t vsw; + uint32_t frameRate; + uint32_t clockFreq; + uint32_t pWidth; + uint32_t pHeight; + enum LcdIntfType intfType; + uint32_t intfSync; + struct MipiDsiDesc mipi; + struct BlkDesc blk; + struct PwmCfg pwm; +}; + +struct PanelStatus { + enum PowerStatus powerStatus; + uint32_t currLevel; +}; + +struct PanelData; +struct PanelEsd { + bool support; + uint32_t interval; + uint32_t state; + uint32_t recoveryNum; + uint32_t cmpMode; + int32_t (*checkFunc)(struct PanelData *panel); + void *expect_data; +}; + +struct PanelData { + struct HdfDeviceObject *object; + int32_t (*init)(struct PanelData *panel); + int32_t (*on)(struct PanelData *panel); + int32_t (*off)(struct PanelData *panel); + int32_t (*setBacklight)(struct PanelData *panel, uint32_t level); + struct PanelInfo *info; + struct PanelStatus status; + struct PanelEsd *esd; + void *priv; +}; + +struct PanelManager { + struct PanelData *panel[PANEL_MAX]; + uint32_t panelNum; +}; typedef int32_t (*DispCmdHandle)(struct HdfDeviceObject *device, struct HdfSBuf *reqData, struct HdfSBuf *rspData); @@ -37,7 +134,7 @@ struct DispInfo { uint32_t vsw; uint32_t frameRate; uint32_t intfType; - enum IntfSync intfSync; + uint32_t intfSync; uint32_t minLevel; uint32_t maxLevel; uint32_t defLevel; @@ -64,23 +161,7 @@ struct DispEsd { int32_t panelNum; }; -struct DispControl; -struct DispControlOps { - int32_t (*on)(struct DispControl *dispCtrl, uint32_t devId); - int32_t (*off)(struct DispControl *dispCtrl, uint32_t devId); - int32_t (*setBacklight)(struct DispControl *dispCtrl, uint32_t devId, uint32_t level); - int32_t (*getDispInfo)(struct DispControl *dispCtrl, uint32_t devId); -}; - -struct DispControl { - struct HdfDeviceObject *object; - struct PanelManager *panelManager; - struct DispInfo *info; - struct DispControlOps ops; -}; - struct DispManager { - struct DispControl *dispCtrl; struct PanelManager *panelManager; struct OsalMutex dispMutex; HdfWorkQueue dispWorkQueue; @@ -88,5 +169,8 @@ struct DispManager { struct DispEsd *esd; }; -int32_t RegisterDispCtrl(struct DispControl *dispCtrl); +int32_t RegisterPanel(struct PanelData *data); +struct PanelManager *GetPanelManager(void); +struct DispManager *GetDispManager(void); + #endif /* HDF_DISP_H */ diff --git a/model/display/driver/hdf_drm_panel.c b/model/display/driver/hdf_drm_panel.c new file mode 100644 index 000000000..f6a3b8391 --- /dev/null +++ b/model/display/driver/hdf_drm_panel.c @@ -0,0 +1,257 @@ + +/* + * Copyright (c) 2020-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 "hdf_drm_panel.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include