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_emmc.h"
10 #include "securec.h"
11
12 #define HDF_LOG_TAG mmc_emmc_c
13
EmmcDeviceDefaultGetCid(struct EmmcDevice * dev,uint8_t * cid,uint32_t len)14 static int32_t EmmcDeviceDefaultGetCid(struct EmmcDevice *dev, uint8_t *cid, uint32_t len)
15 {
16 struct MmcDevice *mmc = (struct MmcDevice *)dev;
17
18 if (memcpy_s(cid, sizeof(uint8_t) * len, (uint8_t *)(mmc->reg.rawCid),
19 sizeof(mmc->reg.rawCid)) != EOK) {
20 HDF_LOGE("EmmcDeviceDefaultGetCid: memcpy_s fail, size = %d!", len);
21 return HDF_FAILURE;
22 }
23 return HDF_SUCCESS;
24 }
25
26 static struct EmmcDeviceOps g_emmcOps = {
27 .getCid = EmmcDeviceDefaultGetCid,
28 };
29
EmmcDeviceGetCid(struct EmmcDevice * dev,uint8_t * cid,uint32_t len)30 int32_t EmmcDeviceGetCid(struct EmmcDevice *dev, uint8_t *cid, uint32_t len)
31 {
32 if (dev == NULL) {
33 return HDF_ERR_INVALID_OBJECT;
34 }
35 if (cid == NULL || len == 0) {
36 return HDF_ERR_INVALID_PARAM;
37 }
38 if (dev->emmcOps == NULL || dev->emmcOps->getCid == NULL) {
39 HDF_LOGE("EmmcDeviceGetCid: ops or getCid is NULL.");
40 return HDF_ERR_INVALID_OBJECT;
41 }
42 return dev->emmcOps->getCid(dev, cid, len);
43 }
44
EmmcDeviceAddOps(struct EmmcDevice * dev,struct EmmcDeviceOps * ops)45 void EmmcDeviceAddOps(struct EmmcDevice *dev, struct EmmcDeviceOps *ops)
46 {
47 if (dev == NULL) {
48 HDF_LOGE("EmmcDeviceAddOps: dev is NULL.");
49 return;
50 }
51 if (ops == NULL) {
52 dev->emmcOps = &g_emmcOps;
53 HDF_LOGD("EmmcDeviceAddOps: use default ops.");
54 } else {
55 dev->emmcOps = ops;
56 }
57 }
58