xref: /OK3568_Linux_fs/u-boot/drivers/mtd/nand/raw/mxs_nand.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0+ */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * NXP GPMI NAND flash driver
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2018 Toradex
6*4882a593Smuzhiyun  * Authors:
7*4882a593Smuzhiyun  * Stefan Agner <stefan.agner@toradex.com>
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <linux/mtd/mtd.h>
11*4882a593Smuzhiyun #include <asm/cache.h>
12*4882a593Smuzhiyun #include <nand.h>
13*4882a593Smuzhiyun #include <asm/mach-imx/dma.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun /**
16*4882a593Smuzhiyun  * @gf_len:                   The length of Galois Field. (e.g., 13 or 14)
17*4882a593Smuzhiyun  * @ecc_strength:             A number that describes the strength of the ECC
18*4882a593Smuzhiyun  *                            algorithm.
19*4882a593Smuzhiyun  * @ecc_chunk_size:           The size, in bytes, of a single ECC chunk. Note
20*4882a593Smuzhiyun  *                            the first chunk in the page includes both data and
21*4882a593Smuzhiyun  *                            metadata, so it's a bit larger than this value.
22*4882a593Smuzhiyun  * @ecc_chunk_count:          The number of ECC chunks in the page,
23*4882a593Smuzhiyun  * @block_mark_byte_offset:   The byte offset in the ECC-based page view at
24*4882a593Smuzhiyun  *                            which the underlying physical block mark appears.
25*4882a593Smuzhiyun  * @block_mark_bit_offset:    The bit offset into the ECC-based page view at
26*4882a593Smuzhiyun  *                            which the underlying physical block mark appears.
27*4882a593Smuzhiyun  */
28*4882a593Smuzhiyun struct bch_geometry {
29*4882a593Smuzhiyun 	unsigned int  gf_len;
30*4882a593Smuzhiyun 	unsigned int  ecc_strength;
31*4882a593Smuzhiyun 	unsigned int  ecc_chunk_size;
32*4882a593Smuzhiyun 	unsigned int  ecc_chunk_count;
33*4882a593Smuzhiyun 	unsigned int  block_mark_byte_offset;
34*4882a593Smuzhiyun 	unsigned int  block_mark_bit_offset;
35*4882a593Smuzhiyun };
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun struct mxs_nand_info {
38*4882a593Smuzhiyun 	struct nand_chip chip;
39*4882a593Smuzhiyun 	struct udevice *dev;
40*4882a593Smuzhiyun 	unsigned int	max_ecc_strength_supported;
41*4882a593Smuzhiyun 	bool		use_minimum_ecc;
42*4882a593Smuzhiyun 	int		cur_chip;
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun 	uint32_t	cmd_queue_len;
45*4882a593Smuzhiyun 	uint32_t	data_buf_size;
46*4882a593Smuzhiyun 	struct bch_geometry bch_geometry;
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 	uint8_t		*cmd_buf;
49*4882a593Smuzhiyun 	uint8_t		*data_buf;
50*4882a593Smuzhiyun 	uint8_t		*oob_buf;
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun 	uint8_t		marking_block_bad;
53*4882a593Smuzhiyun 	uint8_t		raw_oob_mode;
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 	struct mxs_gpmi_regs *gpmi_regs;
56*4882a593Smuzhiyun 	struct mxs_bch_regs *bch_regs;
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun 	/* Functions with altered behaviour */
59*4882a593Smuzhiyun 	int		(*hooked_read_oob)(struct mtd_info *mtd,
60*4882a593Smuzhiyun 				loff_t from, struct mtd_oob_ops *ops);
61*4882a593Smuzhiyun 	int		(*hooked_write_oob)(struct mtd_info *mtd,
62*4882a593Smuzhiyun 				loff_t to, struct mtd_oob_ops *ops);
63*4882a593Smuzhiyun 	int		(*hooked_block_markbad)(struct mtd_info *mtd,
64*4882a593Smuzhiyun 				loff_t ofs);
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun 	/* DMA descriptors */
67*4882a593Smuzhiyun 	struct mxs_dma_desc	**desc;
68*4882a593Smuzhiyun 	uint32_t		desc_index;
69*4882a593Smuzhiyun };
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun int mxs_nand_init_ctrl(struct mxs_nand_info *nand_info);
72*4882a593Smuzhiyun int mxs_nand_init_spl(struct nand_chip *nand);
73*4882a593Smuzhiyun int mxs_nand_setup_ecc(struct mtd_info *mtd);
74