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 "hdf_log.h"
18 #include "hdf_device_desc.h"
19 #include "device_resource_if.h"
20 #include "cfiflash_internal.h"
21
HdfCfiDriverInit(struct HdfDeviceObject *deviceObject)22 int HdfCfiDriverInit(struct HdfDeviceObject *deviceObject)
23 {
24 int ret, cfi_drv_idx = 0;
25 uint32_t pbase;
26 struct DeviceResourceIface *p = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
27
28 if (deviceObject == NULL || deviceObject->property == NULL) {
29 HDF_LOGE("[%s]deviceObject or property is null", __func__);
30 return HDF_ERR_INVALID_PARAM;
31 }
32
33 if ((ret = p->GetUint32(deviceObject->property, "pbase0", &pbase, 0))) {
34 HDF_LOGE("[%s]GetUint32 get cfi0 basee error:%d", __func__, ret);
35 return HDF_FAILURE;
36 }
37
38 if (CfiFlashInit(cfi_drv_idx, pbase)) {
39 return HDF_ERR_NOT_SUPPORT;
40 }
41
42 if ((ret = p->GetUint32(deviceObject->property, "pbase1", &pbase, 0))) {
43 HDF_LOGE("[%s]GetUint32 get cfi1 basee error:%d", __func__, ret);
44 return HDF_FAILURE;
45 }
46
47 cfi_drv_idx++;
48 if (CfiFlashInit(cfi_drv_idx, pbase)) {
49 return HDF_ERR_NOT_SUPPORT;
50 }
51
52 return HDF_SUCCESS;
53 }
54
55 struct HdfDriverEntry g_cfiDriverEntry = {
56 .moduleVersion = 1,
57 .moduleName = "cfi_flash_driver",
58 .Bind = NULL,
59 .Init = HdfCfiDriverInit,
60 .Release = NULL,
61 };
62
63 HDF_INIT(g_cfiDriverEntry);
64