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