1 /*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "los_debug.h"
17 #include "ff_gen_drv.h"
18 #include "diskio.h"
19 #include "hdf_log.h"
20 #include "hdf_device_desc.h"
21 #include "device_resource_if.h"
22 #include "cfiflash_internal.h"
23
24 static DiskioDrvTypeDef g_cfiBlkops = {
25 DiskInit,
26 DiskStatus,
27 DisckRead,
28 DiskWrite,
29 DiskIoctl,
30 };
31
GetCfiBlkOps()32 DiskioDrvTypeDef *GetCfiBlkOps()
33 {
34 return &g_cfiBlkops;
35 }
36
HdfCfiDriverInit(struct HdfDeviceObject * deviceObject)37 int HdfCfiDriverInit(struct HdfDeviceObject *deviceObject)
38 {
39 int ret, cfi_drv_idx = 0;
40 uint32_t pbase;
41 struct DeviceResourceIface *p = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
42
43 if (deviceObject == NULL || deviceObject->property == NULL) {
44 HDF_LOGE("[%s]deviceObject or property is null", __func__);
45 return HDF_ERR_INVALID_PARAM;
46 }
47
48 if ((ret = p->GetUint32(deviceObject->property, "pbase0", &pbase, 0))) {
49 HDF_LOGE("[%s]GetUint32 get cfi0 basee error:%d", __func__, ret);
50 return HDF_FAILURE;
51 }
52
53 if (CfiFlashInit(cfi_drv_idx, pbase)) {
54 return HDF_ERR_NOT_SUPPORT;
55 }
56
57 if ((ret = p->GetUint32(deviceObject->property, "pbase1", &pbase, 0))) {
58 HDF_LOGE("[%s]GetUint32 get cfi1 basee error:%d", __func__, ret);
59 return HDF_FAILURE;
60 }
61
62 cfi_drv_idx++;
63 if (CfiFlashInit(cfi_drv_idx, pbase)) {
64 return HDF_ERR_NOT_SUPPORT;
65 }
66
67 return HDF_SUCCESS;
68 }
69
70 struct HdfDriverEntry g_cfiDriverEntry = {
71 .moduleVersion = 1,
72 .moduleName = "cfi_flash_driver",
73 .Bind = NULL,
74 .Init = HdfCfiDriverInit,
75 .Release = NULL,
76 };
77
78 HDF_INIT(g_cfiDriverEntry);
79