mediatek: add a new spi-nand driver for kernel 5.10
[openwrt/openwrt.git] / target / linux / mediatek / files-5.10 / drivers / mtd / mtk-snand / mtk-snand.h
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3 * Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
4 *
5 * Author: Weijie Gao <weijie.gao@mediatek.com>
6 */
7
8 #ifndef _MTK_SNAND_H_
9 #define _MTK_SNAND_H_
10
11 #ifndef PRIVATE_MTK_SNAND_HEADER
12 #include <stddef.h>
13 #include <stdint.h>
14 #include <stdbool.h>
15 #endif
16
17 enum mtk_snand_soc {
18 SNAND_SOC_MT7622,
19 SNAND_SOC_MT7629,
20
21 __SNAND_SOC_MAX
22 };
23
24 struct mtk_snand_platdata {
25 void *nfi_base;
26 void *ecc_base;
27 enum mtk_snand_soc soc;
28 bool quad_spi;
29 };
30
31 struct mtk_snand_chip_info {
32 const char *model;
33 uint64_t chipsize;
34 uint32_t blocksize;
35 uint32_t pagesize;
36 uint32_t sparesize;
37 uint32_t spare_per_sector;
38 uint32_t fdm_size;
39 uint32_t fdm_ecc_size;
40 uint32_t num_sectors;
41 uint32_t sector_size;
42 uint32_t ecc_strength;
43 uint32_t ecc_bytes;
44 };
45
46 struct mtk_snand;
47 struct snand_flash_info;
48
49 int mtk_snand_init(void *dev, const struct mtk_snand_platdata *pdata,
50 struct mtk_snand **psnf);
51 int mtk_snand_cleanup(struct mtk_snand *snf);
52
53 int mtk_snand_chip_reset(struct mtk_snand *snf);
54 int mtk_snand_read_page(struct mtk_snand *snf, uint64_t addr, void *buf,
55 void *oob, bool raw);
56 int mtk_snand_write_page(struct mtk_snand *snf, uint64_t addr, const void *buf,
57 const void *oob, bool raw);
58 int mtk_snand_erase_block(struct mtk_snand *snf, uint64_t addr);
59 int mtk_snand_block_isbad(struct mtk_snand *snf, uint64_t addr);
60 int mtk_snand_block_markbad(struct mtk_snand *snf, uint64_t addr);
61 int mtk_snand_fill_oob(struct mtk_snand *snf, uint8_t *oobraw,
62 const uint8_t *oobbuf, size_t ooblen);
63 int mtk_snand_transfer_oob(struct mtk_snand *snf, uint8_t *oobbuf,
64 size_t ooblen, const uint8_t *oobraw);
65 int mtk_snand_read_page_auto_oob(struct mtk_snand *snf, uint64_t addr,
66 void *buf, void *oob, size_t ooblen,
67 size_t *actualooblen, bool raw);
68 int mtk_snand_write_page_auto_oob(struct mtk_snand *snf, uint64_t addr,
69 const void *buf, const void *oob,
70 size_t ooblen, size_t *actualooblen,
71 bool raw);
72 int mtk_snand_get_chip_info(struct mtk_snand *snf,
73 struct mtk_snand_chip_info *info);
74 int mtk_snand_irq_process(struct mtk_snand *snf);
75
76 #endif /* _MTK_SNAND_H_ */