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 "mmc_dispatch.h"
10 #include "hdf_log.h"
11 #include "mmc_corex.h"
12 #include "mmc_emmc.h"
13 #include "mmc_sdio.h"
14
MmcCmdDevPresent(struct MmcCntlr * cntlr,struct HdfSBuf * data,struct HdfSBuf * reply)15 static int32_t MmcCmdDevPresent(struct MmcCntlr *cntlr, struct HdfSBuf *data, struct HdfSBuf *reply)
16 {
17 (void)data;
18 if (reply == NULL) {
19 return HDF_ERR_INVALID_PARAM;
20 }
21 if (!HdfSbufWriteUint8(reply, MmcCntlrDevPresent(cntlr))) {
22 HDF_LOGE("MmcCmdDevPresent: write reply sbuf fail!");
23 return HDF_ERR_IO;
24 }
25 return HDF_SUCCESS;
26 }
27
MmcDispatch(struct MmcCntlr * cntlr,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)28 static int32_t MmcDispatch(struct MmcCntlr *cntlr, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
29 {
30 int32_t ret;
31
32 switch (cmd) {
33 case MMC_CMD_DEV_PRESENT:
34 ret = MmcCmdDevPresent(cntlr, data, reply);
35 break;
36 default:
37 ret = HDF_ERR_NOT_SUPPORT;
38 break;
39 }
40 return ret;
41 }
42
EmmcCmdGetCid(struct MmcCntlr * cntlr,struct HdfSBuf * reply)43 static int32_t EmmcCmdGetCid(struct MmcCntlr *cntlr, struct HdfSBuf *reply)
44 {
45 int32_t ret;
46 uint8_t cid[EMMC_CID_LEN] = {0};
47
48 if (reply == NULL || cntlr == NULL) {
49 return HDF_ERR_INVALID_PARAM;
50 }
51
52 ret = EmmcDeviceGetCid((struct EmmcDevice *)cntlr->curDev, cid, EMMC_CID_LEN);
53 if (ret != HDF_SUCCESS) {
54 HDF_LOGE("MmcCmdGetCid: get cid fail!");
55 return ret;
56 }
57
58 if (HdfSbufWriteBuffer(reply, cid, EMMC_CID_LEN) == false) {
59 HDF_LOGE("MmcCmdGetCid: write back cid fail!");
60 return HDF_ERR_IO;
61 }
62
63 return HDF_SUCCESS;
64 }
65
EmmcDispatch(struct MmcCntlr * cntlr,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)66 static int32_t EmmcDispatch(struct MmcCntlr *cntlr, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
67 {
68 int32_t ret;
69 (void)data;
70
71 switch (cmd) {
72 case EMMC_CMD_GET_CID:
73 ret = EmmcCmdGetCid(cntlr, reply);
74 break;
75 default:
76 ret = HDF_ERR_NOT_SUPPORT;
77 break;
78 }
79 return ret;
80 }
81
SdioDispatch(struct MmcCntlr * cntlr,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)82 static int32_t SdioDispatch(struct MmcCntlr *cntlr, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
83 {
84 (void)cntlr;
85 (void)cmd;
86 (void)data;
87 (void)reply;
88 return HDF_ERR_NOT_SUPPORT;
89 }
90
MmcIoDispatch(struct HdfDeviceIoClient * client,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)91 int32_t MmcIoDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
92 {
93 int32_t ret;
94 struct MmcCntlr *cntlr = NULL;
95
96 if (client == NULL || client->device == NULL) {
97 HDF_LOGE("MmcIoDispatch: client or hdf dev obj is NULL");
98 return HDF_ERR_INVALID_OBJECT;
99 }
100
101 cntlr = (struct MmcCntlr *)client->device->service;
102 if (cntlr == NULL) {
103 HDF_LOGE("MmcIoDispatch: service is NULL");
104 return HDF_ERR_INVALID_OBJECT;
105 }
106
107 if (cmd < MMC_CMD_MAX) {
108 ret = MmcDispatch(cntlr, cmd, data, reply);
109 } else if (cmd < EMMC_CMD_MAX) {
110 ret = EmmcDispatch(cntlr, cmd, data, reply);
111 } else if (cmd < SDIO_CMD_MAX) {
112 ret = SdioDispatch(cntlr, cmd, data, reply);
113 } else {
114 ret = HDF_ERR_NOT_SUPPORT;
115 }
116
117 return ret;
118 }
119