mtd: gpmi: change the BCH layout setting for large oob NAND
[oweals/u-boot.git] / include / mxs_nand.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * NXP GPMI NAND flash driver
4  *
5  * Copyright (C) 2018 Toradex
6  * Authors:
7  * Stefan Agner <stefan.agner@toradex.com>
8  */
9
10 #include <linux/mtd/mtd.h>
11 #include <asm/cache.h>
12 #include <nand.h>
13 #include <asm/mach-imx/dma.h>
14
15 /**
16  * @gf_len:                   The length of Galois Field. (e.g., 13 or 14)
17  * @ecc_strength:             A number that describes the strength of the ECC
18  *                            algorithm.
19  * @ecc_chunk0_size:          The size, in bytes, of a first ECC chunk.
20  * @ecc_chunkn_size:          The size, in bytes, of a single ECC chunk after
21  *                            the first chunk in the page.
22  * @ecc_chunk_count:          The number of ECC chunks in the page,
23  * @block_mark_byte_offset:   The byte offset in the ECC-based page view at
24  *                            which the underlying physical block mark appears.
25  * @block_mark_bit_offset:    The bit offset into the ECC-based page view at
26  *                            which the underlying physical block mark appears.
27  * @ecc_for_meta:             The flag to indicate if there is a dedicate ecc
28  *                            for meta.
29  */
30 struct bch_geometry {
31         unsigned int  gf_len;
32         unsigned int  ecc_strength;
33         unsigned int  ecc_chunk0_size;
34         unsigned int  ecc_chunkn_size;
35         unsigned int  ecc_chunk_count;
36         unsigned int  block_mark_byte_offset;
37         unsigned int  block_mark_bit_offset;
38         unsigned int  ecc_for_meta; /* ECC for meta data */
39 };
40
41 struct mxs_nand_info {
42         struct nand_chip chip;
43         struct udevice *dev;
44         unsigned int    max_ecc_strength_supported;
45         bool            use_minimum_ecc;
46         int             cur_chip;
47
48         uint32_t        cmd_queue_len;
49         uint32_t        data_buf_size;
50         struct bch_geometry bch_geometry;
51
52         uint8_t         *cmd_buf;
53         uint8_t         *data_buf;
54         uint8_t         *oob_buf;
55
56         uint8_t         marking_block_bad;
57         uint8_t         raw_oob_mode;
58
59         struct mxs_gpmi_regs *gpmi_regs;
60         struct mxs_bch_regs *bch_regs;
61
62         /* Functions with altered behaviour */
63         int             (*hooked_read_oob)(struct mtd_info *mtd,
64                                 loff_t from, struct mtd_oob_ops *ops);
65         int             (*hooked_write_oob)(struct mtd_info *mtd,
66                                 loff_t to, struct mtd_oob_ops *ops);
67         int             (*hooked_block_markbad)(struct mtd_info *mtd,
68                                 loff_t ofs);
69
70         /* DMA descriptors */
71         struct mxs_dma_desc     **desc;
72         uint32_t                desc_index;
73
74         /* Hardware BCH interface and randomizer */
75         u32 en_randomizer;
76         u32 writesize;
77         u32 oobsize;
78         u32 bch_flash0layout0;
79         u32 bch_flash0layout1;
80 };
81
82 struct mxs_nand_layout {
83         u32 nblocks;
84         u32 meta_size;
85         u32 data0_size;
86         u32 ecc0;
87         u32 datan_size;
88         u32 eccn;
89 };
90
91 int mxs_nand_init_ctrl(struct mxs_nand_info *nand_info);
92 int mxs_nand_init_spl(struct nand_chip *nand);
93 int mxs_nand_setup_ecc(struct mtd_info *mtd);
94
95 void mxs_nand_mode_fcb(struct mtd_info *mtd);
96 void mxs_nand_mode_normal(struct mtd_info *mtd);
97 u32 mxs_nand_mark_byte_offset(struct mtd_info *mtd);
98 u32 mxs_nand_mark_bit_offset(struct mtd_info *mtd);
99 void mxs_nand_get_layout(struct mtd_info *mtd, struct mxs_nand_layout *l);