• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-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 "device_resource_if.h"
10 #include "hdf_base.h"
11 #include "hdf_log.h"
12 #include "osal_mem.h"
13 #include "osal_time.h"
14 #include "emmc_if.h"
15 #include "emmc_test.h"
16 
17 #define HDF_LOG_TAG emmc_test_c
18 
19 struct EmmcTestFunc {
20     enum EmmcTestCmd type;
21     int32_t (*Func)(struct EmmcTester *tester);
22 };
23 
EmmcTestGetHandle(struct EmmcTester * tester)24 static DevHandle EmmcTestGetHandle(struct EmmcTester *tester)
25 {
26     if (tester == NULL) {
27         HDF_LOGE("%s: tester is null", __func__);
28         return NULL;
29     }
30     return EmmcOpen(tester->busNum);
31 }
32 
EmmcTestReleaseHandle(DevHandle handle)33 static void EmmcTestReleaseHandle(DevHandle handle)
34 {
35     if (handle == NULL) {
36         HDF_LOGE("%s: sdio handle is null", __func__);
37         return;
38     }
39     EmmcClose(handle);
40 }
41 
TestEmmcGetCid(struct EmmcTester * tester)42 static int32_t TestEmmcGetCid(struct EmmcTester *tester)
43 {
44     int32_t ret, i;
45     uint8_t cid[EMMC_CID_LEN] = {0};
46 
47     ret = EmmcGetCid(tester->handle, cid, EMMC_CID_LEN);
48     if (ret != HDF_SUCCESS) {
49         HDF_LOGE("%s: EmmcGetCid failed ret=%d.", __func__, ret);
50         return HDF_FAILURE;
51     }
52     for (i = 0; i < EMMC_CID_LEN; i++) {
53         HDF_LOGE("%s: cid[%d] = 0x%x\n", __func__, i, cid[i]);
54     }
55     return HDF_SUCCESS;
56 }
57 
58 struct EmmcTestFunc g_emmcTestFunc[] = {
59     { EMMC_GET_CID_01, TestEmmcGetCid },
60 };
61 
EmmcTestEntry(struct EmmcTester * tester,int32_t cmd)62 static int32_t EmmcTestEntry(struct EmmcTester *tester, int32_t cmd)
63 {
64     int32_t i;
65     int32_t ret = HDF_SUCCESS;
66     bool isFind = false;
67 
68     if (tester == NULL) {
69         HDF_LOGE("%s: tester is NULL", __func__);
70         return HDF_ERR_INVALID_OBJECT;
71     }
72     tester->handle = EmmcTestGetHandle(tester);
73     if (tester->handle == NULL) {
74         HDF_LOGE("%s: emmc test get handle failed", __func__);
75         return HDF_FAILURE;
76     }
77     for (i = 0; i < sizeof(g_emmcTestFunc) / sizeof(g_emmcTestFunc[0]); i++) {
78         if (cmd == g_emmcTestFunc[i].type && g_emmcTestFunc[i].Func != NULL) {
79             ret = g_emmcTestFunc[i].Func(tester);
80             isFind = true;
81             break;
82         }
83     }
84     if (!isFind) {
85         ret = HDF_ERR_NOT_SUPPORT;
86         HDF_LOGE("%s: cmd %d not supported", __func__, cmd);
87     }
88     EmmcTestReleaseHandle(tester->handle);
89     return ret;
90 }
91 
EmmcTestFillConfig(struct EmmcTester * tester,const struct DeviceResourceNode * node)92 static int32_t EmmcTestFillConfig(struct EmmcTester *tester, const struct DeviceResourceNode *node)
93 {
94     int32_t ret;
95     struct DeviceResourceIface *drsOps = NULL;
96 
97     drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
98     if (drsOps == NULL || drsOps->GetUint32 == NULL) {
99         HDF_LOGE("%s: invalid drs ops", __func__);
100         return HDF_FAILURE;
101     }
102 
103     ret = drsOps->GetUint32(node, "busNum", &(tester->busNum), 0);
104     if (ret != HDF_SUCCESS) {
105         HDF_LOGE("%s: fill bus num failed", __func__);
106         return ret;
107     }
108 
109     ret = drsOps->GetUint32(node, "hostId", &(tester->hostId), 0);
110     if (ret != HDF_SUCCESS) {
111         HDF_LOGE("%s: fill hostId failed", __func__);
112         return ret;
113     }
114 
115     HDF_LOGE("%s: busNum:%d, hostId:%d.", __func__, tester->busNum, tester->hostId);
116     return HDF_SUCCESS;
117 }
118 
EmmcTestBind(struct HdfDeviceObject * device)119 static int32_t EmmcTestBind(struct HdfDeviceObject *device)
120 {
121     static struct EmmcTester tester;
122 
123     if (device == NULL) {
124         HDF_LOGE("%s: device or config is null!", __func__);
125         return HDF_ERR_IO;
126     }
127 
128     device->service = &tester.service;
129     HDF_LOGE("%s: EMMC_TEST service init success!", __func__);
130     return HDF_SUCCESS;
131 }
132 
EmmcTestInit(struct HdfDeviceObject * device)133 static int32_t EmmcTestInit(struct HdfDeviceObject *device)
134 {
135     struct EmmcTester *tester = NULL;
136     int32_t ret;
137 
138     if (device == NULL || device->service == NULL || device->property == NULL) {
139         HDF_LOGE("%s: invalid parameter", __func__);
140         return HDF_ERR_INVALID_PARAM;
141     }
142 
143     tester = (struct EmmcTester *)device->service;
144     if (tester == NULL) {
145         HDF_LOGE("%s: tester is NULL", __func__);
146         return HDF_ERR_INVALID_PARAM;
147     }
148     ret = EmmcTestFillConfig(tester, device->property);
149     if (ret != HDF_SUCCESS) {
150         HDF_LOGE("%s: read config failed", __func__);
151         return ret;
152     }
153     tester->TestEntry = EmmcTestEntry;
154     HDF_LOGE("%s: success", __func__);
155     return HDF_SUCCESS;
156 }
157 
EmmcTestRelease(struct HdfDeviceObject * device)158 static void EmmcTestRelease(struct HdfDeviceObject *device)
159 {
160     if (device != NULL) {
161         device->service = NULL;
162     }
163 }
164 
165 struct HdfDriverEntry g_emmcTestEntry = {
166     .moduleVersion = 1,
167     .Bind = EmmcTestBind,
168     .Init = EmmcTestInit,
169     .Release = EmmcTestRelease,
170     .moduleName = "PLATFORM_EMMC_TEST",
171 };
172 HDF_INIT(g_emmcTestEntry);
173