1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * NXP GPMI NAND flash driver
5 * Copyright (C) 2018 Toradex
7 * Stefan Agner <stefan.agner@toradex.com>
10 #include <linux/mtd/mtd.h>
11 #include <linux/mtd/rawnand.h>
12 #include <asm/cache.h>
14 #include <asm/mach-imx/dma.h>
17 * @gf_len: The length of Galois Field. (e.g., 13 or 14)
18 * @ecc_strength: A number that describes the strength of the ECC
20 * @ecc_chunk0_size: The size, in bytes, of a first ECC chunk.
21 * @ecc_chunkn_size: The size, in bytes, of a single ECC chunk after
22 * the first chunk in the page.
23 * @ecc_chunk_count: The number of ECC chunks in the page,
24 * @block_mark_byte_offset: The byte offset in the ECC-based page view at
25 * which the underlying physical block mark appears.
26 * @block_mark_bit_offset: The bit offset into the ECC-based page view at
27 * which the underlying physical block mark appears.
28 * @ecc_for_meta: The flag to indicate if there is a dedicate ecc
33 unsigned int ecc_strength;
34 unsigned int ecc_chunk0_size;
35 unsigned int ecc_chunkn_size;
36 unsigned int ecc_chunk_count;
37 unsigned int block_mark_byte_offset;
38 unsigned int block_mark_bit_offset;
39 unsigned int ecc_for_meta; /* ECC for meta data */
42 struct mxs_nand_info {
43 struct nand_chip chip;
45 unsigned int max_ecc_strength_supported;
47 /* legacy bch geometry flag */
48 bool legacy_bch_geometry;
51 uint32_t cmd_queue_len;
52 uint32_t data_buf_size;
53 struct bch_geometry bch_geometry;
59 uint8_t marking_block_bad;
62 struct mxs_gpmi_regs *gpmi_regs;
63 struct mxs_bch_regs *bch_regs;
65 /* Functions with altered behaviour */
66 int (*hooked_read_oob)(struct mtd_info *mtd,
67 loff_t from, struct mtd_oob_ops *ops);
68 int (*hooked_write_oob)(struct mtd_info *mtd,
69 loff_t to, struct mtd_oob_ops *ops);
70 int (*hooked_block_markbad)(struct mtd_info *mtd,
74 struct mxs_dma_desc **desc;
77 /* Hardware BCH interface and randomizer */
81 u32 bch_flash0layout0;
82 u32 bch_flash0layout1;
85 struct mxs_nand_layout {
95 int mxs_nand_init_ctrl(struct mxs_nand_info *nand_info);
96 int mxs_nand_init_spl(struct nand_chip *nand);
97 int mxs_nand_setup_ecc(struct mtd_info *mtd);
99 void mxs_nand_mode_fcb_62bit(struct mtd_info *mtd);
100 void mxs_nand_mode_fcb_40bit(struct mtd_info *mtd);
101 void mxs_nand_mode_normal(struct mtd_info *mtd);
102 u32 mxs_nand_mark_byte_offset(struct mtd_info *mtd);
103 u32 mxs_nand_mark_bit_offset(struct mtd_info *mtd);
104 void mxs_nand_get_layout(struct mtd_info *mtd, struct mxs_nand_layout *l);