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 "pin_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 #include "string.h"
15
16 #define HDF_LOG_TAG pin_driver_test_c
17
18 static struct PinTestConfig g_config;
19
PinTestDispatch(struct HdfDeviceIoClient * client,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)20 static int32_t PinTestDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
21 {
22 if (cmd == 0) {
23 if (reply == NULL) {
24 HDF_LOGE("%s: reply is null!", __func__);
25 return HDF_ERR_INVALID_PARAM;
26 }
27 if (!HdfSbufWriteBuffer(reply, &g_config, sizeof(g_config))) {
28 HDF_LOGE("%s: write reply failed", __func__);
29 return HDF_ERR_IO;
30 }
31 } else {
32 return HDF_ERR_NOT_SUPPORT;
33 }
34
35 return HDF_SUCCESS;
36 }
PinTestReadConfig(struct PinTestConfig * config,const struct DeviceResourceNode * node)37 static int32_t PinTestReadConfig(struct PinTestConfig *config, const struct DeviceResourceNode *node)
38 {
39 int32_t ret;
40 const char *funcName = NULL;
41 struct DeviceResourceIface *drsOps = NULL;
42
43 drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
44 if (drsOps == NULL || drsOps->GetUint32 == NULL || drsOps->GetString == NULL) {
45 HDF_LOGE("%s: invalid drs ops", __func__);
46 return HDF_FAILURE;
47 }
48 ret = drsOps->GetString(node, "pinName", &config->pinName, 0);
49 if (ret != HDF_SUCCESS) {
50 HDF_LOGE("%s: read pinName failed", __func__);
51 return ret;
52 }
53
54 ret = drsOps->GetUint32(node, "strengthNum", &config->strengthNum, 0);
55 if (ret != HDF_SUCCESS) {
56 HDF_LOGE("%s: read StrengthNum failed", __func__);
57 return ret;
58 }
59
60 ret = drsOps->GetUint32(node, "PullTypeNum", &config->PullTypeNum, 0);
61 if (ret != HDF_SUCCESS) {
62 HDF_LOGE("%s: read PullTypeNum failed", __func__);
63 return ret;
64 }
65
66 ret = drsOps->GetString(node, "funcName", &funcName, 0);
67 if (ret != HDF_SUCCESS) {
68 HDF_LOGE("%s: read funcName failed", __func__);
69 return ret;
70 }
71 stpcpy(config->funcNameBuf, funcName);
72 return HDF_SUCCESS;
73 }
74
PinTestBind(struct HdfDeviceObject * device)75 static int32_t PinTestBind(struct HdfDeviceObject *device)
76 {
77 int32_t ret;
78 static struct IDeviceIoService service;
79
80 if (device == NULL || device->property == NULL) {
81 HDF_LOGE("%s: device or config is null!", __func__);
82 return HDF_ERR_IO;
83 }
84 ret = PinTestReadConfig(&g_config, device->property);
85 if (ret != HDF_SUCCESS) {
86 HDF_LOGE("%s: read config failed", __func__);
87 return ret;
88 }
89 service.Dispatch = PinTestDispatch;
90 device->service = &service;
91 return HDF_SUCCESS;
92 }
93
PinTestInit(struct HdfDeviceObject * device)94 static int32_t PinTestInit(struct HdfDeviceObject *device)
95 {
96 (void)device;
97 return HDF_SUCCESS;
98 }
99
PinTestRelease(struct HdfDeviceObject * device)100 static void PinTestRelease(struct HdfDeviceObject *device)
101 {
102 if (device != NULL) {
103 device->service = NULL;
104 }
105 HDF_LOGI("%s: Done!", __func__);
106 return;
107 }
108
109 struct HdfDriverEntry g_pinTestEntry = {
110 .moduleVersion = 1,
111 .Bind = PinTestBind,
112 .Init = PinTestInit,
113 .Release = PinTestRelease,
114 .moduleName = "PLATFORM_PIN_TEST",
115 };
116 HDF_INIT(g_pinTestEntry);