xref: /linux/drivers/mtd/nand/raw/atmel/pmecc.h (revision c39f2d9db0fd81ea20bb5cce9b3f082ca63753e2)
1*b849f8b5STudor Ambarus /* SPDX-License-Identifier: GPL-2.0 */
293db446aSBoris Brezillon /*
393db446aSBoris Brezillon  * © Copyright 2016 ATMEL
493db446aSBoris Brezillon  * © Copyright 2016 Free Electrons
593db446aSBoris Brezillon  *
693db446aSBoris Brezillon  * Author: Boris Brezillon <boris.brezillon@free-electrons.com>
793db446aSBoris Brezillon  *
893db446aSBoris Brezillon  * Derived from the atmel_nand.c driver which contained the following
993db446aSBoris Brezillon  * copyrights:
1093db446aSBoris Brezillon  *
1193db446aSBoris Brezillon  *    Copyright © 2003 Rick Bronson
1293db446aSBoris Brezillon  *
1393db446aSBoris Brezillon  *    Derived from drivers/mtd/nand/autcpu12.c (removed in v3.8)
1493db446aSBoris Brezillon  *        Copyright © 2001 Thomas Gleixner (gleixner@autronix.de)
1593db446aSBoris Brezillon  *
1693db446aSBoris Brezillon  *    Derived from drivers/mtd/spia.c (removed in v3.8)
1793db446aSBoris Brezillon  *        Copyright © 2000 Steven J. Hill (sjhill@cotw.com)
1893db446aSBoris Brezillon  *
1993db446aSBoris Brezillon  *
2093db446aSBoris Brezillon  *    Add Hardware ECC support for AT91SAM9260 / AT91SAM9263
2193db446aSBoris Brezillon  *        Richard Genoud (richard.genoud@gmail.com), Adeneo Copyright © 2007
2293db446aSBoris Brezillon  *
2393db446aSBoris Brezillon  *        Derived from Das U-Boot source code
2493db446aSBoris Brezillon  *              (u-boot-1.1.5/board/atmel/at91sam9263ek/nand.c)
2593db446aSBoris Brezillon  *        © Copyright 2006 ATMEL Rousset, Lacressonniere Nicolas
2693db446aSBoris Brezillon  *
2793db446aSBoris Brezillon  *    Add Programmable Multibit ECC support for various AT91 SoC
2893db446aSBoris Brezillon  *        © Copyright 2012 ATMEL, Hong Xu
2993db446aSBoris Brezillon  *
3093db446aSBoris Brezillon  *    Add Nand Flash Controller support for SAMA5 SoC
3193db446aSBoris Brezillon  *        © Copyright 2013 ATMEL, Josh Wu (josh.wu@atmel.com)
3293db446aSBoris Brezillon  */
3393db446aSBoris Brezillon 
3493db446aSBoris Brezillon #ifndef ATMEL_PMECC_H
3593db446aSBoris Brezillon #define ATMEL_PMECC_H
3693db446aSBoris Brezillon 
3793db446aSBoris Brezillon #define ATMEL_PMECC_MAXIMIZE_ECC_STRENGTH	0
3893db446aSBoris Brezillon #define ATMEL_PMECC_SECTOR_SIZE_AUTO		0
3993db446aSBoris Brezillon #define ATMEL_PMECC_OOBOFFSET_AUTO		-1
4093db446aSBoris Brezillon 
4193db446aSBoris Brezillon struct atmel_pmecc_user_req {
4293db446aSBoris Brezillon 	int pagesize;
4393db446aSBoris Brezillon 	int oobsize;
4493db446aSBoris Brezillon 	struct {
4593db446aSBoris Brezillon 		int strength;
4693db446aSBoris Brezillon 		int bytes;
4793db446aSBoris Brezillon 		int sectorsize;
4893db446aSBoris Brezillon 		int nsectors;
4993db446aSBoris Brezillon 		int ooboffset;
5093db446aSBoris Brezillon 	} ecc;
5193db446aSBoris Brezillon };
5293db446aSBoris Brezillon 
5393db446aSBoris Brezillon struct atmel_pmecc *devm_atmel_pmecc_get(struct device *dev);
5493db446aSBoris Brezillon 
5593db446aSBoris Brezillon struct atmel_pmecc_user *
5693db446aSBoris Brezillon atmel_pmecc_create_user(struct atmel_pmecc *pmecc,
5793db446aSBoris Brezillon 			struct atmel_pmecc_user_req *req);
5893db446aSBoris Brezillon void atmel_pmecc_destroy_user(struct atmel_pmecc_user *user);
5993db446aSBoris Brezillon 
6093db446aSBoris Brezillon void atmel_pmecc_reset(struct atmel_pmecc *pmecc);
6193db446aSBoris Brezillon int atmel_pmecc_enable(struct atmel_pmecc_user *user, int op);
6293db446aSBoris Brezillon void atmel_pmecc_disable(struct atmel_pmecc_user *user);
6393db446aSBoris Brezillon int atmel_pmecc_wait_rdy(struct atmel_pmecc_user *user);
6493db446aSBoris Brezillon int atmel_pmecc_correct_sector(struct atmel_pmecc_user *user, int sector,
6593db446aSBoris Brezillon 			       void *data, void *ecc);
6693db446aSBoris Brezillon bool atmel_pmecc_correct_erased_chunks(struct atmel_pmecc_user *user);
6793db446aSBoris Brezillon void atmel_pmecc_get_generated_eccbytes(struct atmel_pmecc_user *user,
6893db446aSBoris Brezillon 					int sector, void *ecc);
6993db446aSBoris Brezillon 
7093db446aSBoris Brezillon #endif /* ATMEL_PMECC_H */
71