• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "hdf_log.h"
16 #include "hdf_base.h"
17 #include "hdf_device_desc.h"
18 #include "device_resource_if.h"
19 #include "los_vm_zone.h"
20 #include "cfiflash_internal.h"
21 
22 static struct block_operations g_cfiBlkops = {
23     CfiBlkOpen,
24     CfiBlkClose,
25     CfiBlkRead,
26     CfiBlkWrite,
27     CfiBlkGeometry,
28     NULL,           /* int     (*ioctl)(struct Vnode *vnode, int cmd, unsigned long arg); */
29     NULL,           /* int     (*unlink)(struct Vnode *vnode); */
30 };
31 
GetCfiBlkOps()32 struct block_operations *GetCfiBlkOps()
33 {
34     return &g_cfiBlkops;
35 }
36 
37 static struct MtdDev g_cfiMtdDev = {
38     .priv = NULL,
39     .type = MTD_NORFLASH,
40     .size = CFIFLASH_CAPACITY,
41     .eraseSize = CFIFLASH_ERASEBLK_SIZE,
42     .erase = CfiMtdErase,
43     .read = CfiMtdRead,
44     .write = CfiMtdWrite,
45 };
46 
GetCfiMtdDev()47 struct MtdDev *GetCfiMtdDev()
48 {
49     return &g_cfiMtdDev;
50 }
51 
HdfCfiDriverInit(struct HdfDeviceObject * deviceObject)52 int HdfCfiDriverInit(struct HdfDeviceObject *deviceObject)
53 {
54     int ret;
55     uint32_t pbase;
56     struct DeviceResourceIface *p = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
57 
58     if (deviceObject == NULL ||  deviceObject->property == NULL) {
59         HDF_LOGE("[%s]deviceObject or property is null", __func__);
60         return HDF_ERR_INVALID_PARAM;
61     }
62 
63     if ((ret = p->GetUint32(deviceObject->property, "pbase0", &pbase, 0))) {
64         HDF_LOGE("[%s]GetUint32 error:%d", __func__, ret);
65         return HDF_FAILURE;
66     }
67     if(CfiFlashInit((uint8_t *)IO_DEVICE_ADDR(pbase))) {
68         return HDF_ERR_NOT_SUPPORT;
69     }
70 
71     if (p->GetUint32(deviceObject->property, "pbase1", &pbase, 0) == 0) {
72         (void)CfiFlashInit((uint8_t *)IO_DEVICE_ADDR(pbase));
73     }
74 
75     return HDF_SUCCESS;
76 }
77 
78 struct HdfDriverEntry g_cfiDriverEntry = {
79     .moduleVersion = 1,
80     .moduleName = "cfi_flash_driver",
81     .Bind = NULL,
82     .Init = HdfCfiDriverInit,
83     .Release = NULL,
84 };
85 
86 HDF_INIT(g_cfiDriverEntry);
87