• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "mtd_spi_common.h"
10 #include "hdf_log.h"
11 
SpiFlashDumpDefualt(struct MtdDevice * mtdDevice)12 static void SpiFlashDumpDefualt(struct MtdDevice *mtdDevice)
13 {
14     struct MtdSpiConfig *cfg = NULL;
15     struct SpiFlash *spi = NULL;
16 
17     if (mtdDevice == NULL) {
18         return;
19     }
20     MTD_DEVICE_DUMP(mtdDevice);
21 
22     spi = CONTAINER_OF(mtdDevice, struct SpiFlash, mtd);
23     HDF_LOGD("%s: cs = %u, qe = %u, addrCycle = %u", __func__,
24         spi->cs, spi->qeEnable, spi->addrCycle);
25 
26     cfg = &spi->readCfg;
27     HDF_LOGD("%s: readCfg -> ifType:%u, cmd:0x%x, dummy:%u, size:%u, clock:%u",
28         __func__, cfg->ifType, cfg->cmd, cfg->dummy, cfg->size, cfg->clock);
29     cfg = &spi->writeCfg;
30     HDF_LOGD("%s: writeCfg -> ifType:%u, cmd:0x%x, dummy:%u, size:%u, clock:%u",
31         __func__, cfg->ifType, cfg->cmd, cfg->dummy, cfg->size, cfg->clock);
32     cfg = &spi->eraseCfg;
33     HDF_LOGD("%s: eraseCfg -> ifType:%u, cmd:0x%x, dummy:%u, size:%u, clock:%u",
34         __func__, cfg->ifType, cfg->cmd, cfg->dummy, cfg->size, cfg->clock);
35 }
36 
SpiFlashAdd(struct SpiFlash * spi)37 int32_t SpiFlashAdd(struct SpiFlash *spi)
38 {
39     if (spi == NULL || spi->mtd.ops == NULL) {
40         return HDF_ERR_INVALID_OBJECT;
41     }
42     if (spi->mtd.ops->dump == NULL) {
43         spi->mtd.ops->dump = SpiFlashDumpDefualt;
44     }
45     return MtdDeviceAdd(&spi->mtd);
46 }
47 
SpiFlashDel(struct SpiFlash * spi)48 void SpiFlashDel(struct SpiFlash *spi)
49 {
50     if (spi != NULL) {
51         MtdDeviceDel(&spi->mtd);
52     }
53 }
54 
SpiFlashWaitReady(struct SpiFlash * spi)55 int32_t SpiFlashWaitReady(struct SpiFlash *spi)
56 {
57     int32_t ret;
58 
59     if (spi == NULL) {
60         return HDF_ERR_INVALID_OBJECT;
61     }
62     if (spi->spiOps.waitReady == NULL) {
63         return HDF_ERR_NOT_SUPPORT;
64     }
65     ret = (spi->spiOps.waitReady(spi));
66     if (ret != HDF_SUCCESS) {
67         HDF_LOGD("%s: wait dev ready failed, ret=%d", __func__, ret);
68     }
69     return ret;
70 }
71 
SpiFlashWriteEnable(struct SpiFlash * spi)72 int32_t SpiFlashWriteEnable(struct SpiFlash *spi)
73 {
74     int32_t ret;
75 
76     if (spi == NULL) {
77         return HDF_ERR_INVALID_OBJECT;
78     }
79     if (spi->spiOps.writeEnable == NULL) {
80         return HDF_ERR_NOT_SUPPORT;
81     }
82     ret = (spi->spiOps.writeEnable(spi));
83     if (ret != HDF_SUCCESS) {
84         HDF_LOGD("%s: dev write enable failed, ret=%d", __func__, ret);
85     }
86     return ret;
87 }
88 
SpiFlashQeEnable(struct SpiFlash * spi)89 int32_t SpiFlashQeEnable(struct SpiFlash *spi)
90 {
91     int32_t ret;
92 
93     if (spi == NULL) {
94         return HDF_ERR_INVALID_OBJECT;
95     }
96     if (spi->spiOps.qeEnable == NULL) {
97         return HDF_ERR_NOT_SUPPORT;
98     }
99     ret = (spi->spiOps.qeEnable(spi));
100     if (ret != HDF_SUCCESS) {
101         HDF_LOGD("%s: dev qe enable failed, ret=%d", __func__, ret);
102     }
103     return ret;
104 }
105 
SpiFlashEntry4Addr(struct SpiFlash * spi,int enable)106 int32_t SpiFlashEntry4Addr(struct SpiFlash *spi, int enable)
107 {
108     int32_t ret;
109 
110     if (spi == NULL) {
111         return HDF_ERR_INVALID_OBJECT;
112     }
113     if (spi->spiOps.entry4Addr == NULL) {
114         return HDF_ERR_NOT_SUPPORT;
115     }
116     ret = (spi->spiOps.entry4Addr(spi, enable));
117     if (ret != HDF_SUCCESS) {
118         HDF_LOGD("%s: dev set 4addr failed, enabl=%d, ret=%d", __func__, enable, ret);
119     }
120     return ret;
121 }
122