• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "adc_test.h"
10 #include "device_resource_if.h"
11 #include "hdf_base.h"
12 #include "hdf_device_desc.h"
13 #include "hdf_log.h"
14 
15 #define HDF_LOG_TAG adc_test_driver_c
16 
17 static struct AdcTestConfig g_config;
18 
AdcTestDispatch(struct HdfDeviceIoClient * client,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)19 static int32_t AdcTestDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
20 {
21     (void)data;
22     (void)client;
23 
24     if (cmd == 0) {
25         if (reply == NULL) {
26             HDF_LOGE("%s: reply is null!", __func__);
27             return HDF_ERR_INVALID_PARAM;
28         }
29         if (!HdfSbufWriteBuffer(reply, &g_config, sizeof(g_config))) {
30             HDF_LOGE("%s: write reply failed", __func__);
31             return HDF_ERR_IO;
32         }
33     } else {
34         return HDF_ERR_NOT_SUPPORT;
35     }
36 
37     return HDF_SUCCESS;
38 }
39 
AdcTestReadConfig(struct AdcTestConfig * config,const struct DeviceResourceNode * node)40 static int32_t AdcTestReadConfig(struct AdcTestConfig *config, const struct DeviceResourceNode *node)
41 {
42     int32_t ret;
43     struct DeviceResourceIface *drsOps = NULL;
44 
45     drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
46     if (drsOps == NULL || drsOps->GetUint32 == NULL) {
47         HDF_LOGE("%s: invalid drs ops", __func__);
48         return HDF_FAILURE;
49     }
50 
51     ret = drsOps->GetUint32(node, "devNum", &config->devNum, 0);
52     if (ret != HDF_SUCCESS) {
53         HDF_LOGE("%s: read devNum failed", __func__);
54         return ret;
55     }
56 
57     ret = drsOps->GetUint32(node, "channel", &config->channel, 0);
58     if (ret != HDF_SUCCESS) {
59         HDF_LOGE("%s: read channel failed", __func__);
60         return ret;
61     }
62 
63     ret = drsOps->GetUint32(node, "maxChannel", &config->maxChannel, 0);
64     if (ret != HDF_SUCCESS) {
65         HDF_LOGE("%s: read maxChannel failed", __func__);
66         return ret;
67     }
68 
69     ret = drsOps->GetUint32(node, "dataWidth", &config->dataWidth, 0);
70     if (ret != HDF_SUCCESS) {
71         HDF_LOGE("%s: read dataWidth failed", __func__);
72         return ret;
73     }
74 
75     ret = drsOps->GetUint32(node, "rate", &config->rate, 0);
76     if (ret != HDF_SUCCESS) {
77         HDF_LOGE("%s: read rate failed", __func__);
78         return ret;
79     }
80 
81     return HDF_SUCCESS;
82 }
83 
AdcTestBind(struct HdfDeviceObject * device)84 static int32_t AdcTestBind(struct HdfDeviceObject *device)
85 {
86     int32_t ret;
87     static struct IDeviceIoService service;
88 
89     if (device == NULL || device->property == NULL) {
90         HDF_LOGE("%s: device or config is null!", __func__);
91         return HDF_ERR_IO;
92     }
93 
94     ret = AdcTestReadConfig(&g_config, device->property);
95     if (ret != HDF_SUCCESS) {
96         HDF_LOGE("%s: read config failed", __func__);
97         return ret;
98     }
99     service.Dispatch = AdcTestDispatch;
100     device->service = &service;
101     HDF_LOGI("%s: Done!", __func__);
102     return HDF_SUCCESS;
103 }
104 
AdcTestInit(struct HdfDeviceObject * device)105 static int32_t AdcTestInit(struct HdfDeviceObject *device)
106 {
107     (void)device;
108     HDF_LOGI("%s: Done!", __func__);
109     return HDF_SUCCESS;
110 }
111 
AdcTestRelease(struct HdfDeviceObject * device)112 static void AdcTestRelease(struct HdfDeviceObject *device)
113 {
114     if (device != NULL) {
115         device->service = NULL;
116     }
117     HDF_LOGI("%s: Done!", __func__);
118     return;
119 }
120 
121 struct HdfDriverEntry g_adcTestEntry = {
122     .moduleVersion = 1,
123     .Bind = AdcTestBind,
124     .Init = AdcTestInit,
125     .Release = AdcTestRelease,
126     .moduleName = "PLATFORM_ADC_TEST",
127 };
128 HDF_INIT(g_adcTestEntry);
129