xref: /openbmc/u-boot/include/linux/mtd/nand_bch.h (revision 4c6de8560cb42a6b6c2d565d41b6801e4b02d4b3)
1*4c6de856SChristian Hitz /*
2*4c6de856SChristian Hitz  * Copyright © 2011 Ivan Djelic <ivan.djelic@parrot.com>
3*4c6de856SChristian Hitz  *
4*4c6de856SChristian Hitz  * This program is free software; you can redistribute it and/or modify
5*4c6de856SChristian Hitz  * it under the terms of the GNU General Public License version 2 as
6*4c6de856SChristian Hitz  * published by the Free Software Foundation.
7*4c6de856SChristian Hitz  *
8*4c6de856SChristian Hitz  * This file is the header for the NAND BCH ECC implementation.
9*4c6de856SChristian Hitz  */
10*4c6de856SChristian Hitz 
11*4c6de856SChristian Hitz #ifndef __MTD_NAND_BCH_H__
12*4c6de856SChristian Hitz #define __MTD_NAND_BCH_H__
13*4c6de856SChristian Hitz 
14*4c6de856SChristian Hitz struct mtd_info;
15*4c6de856SChristian Hitz struct nand_bch_control;
16*4c6de856SChristian Hitz 
17*4c6de856SChristian Hitz #if defined(CONFIG_NAND_ECC_BCH)
18*4c6de856SChristian Hitz 
19*4c6de856SChristian Hitz static inline int mtd_nand_has_bch(void) { return 1; }
20*4c6de856SChristian Hitz 
21*4c6de856SChristian Hitz /*
22*4c6de856SChristian Hitz  * Calculate BCH ecc code
23*4c6de856SChristian Hitz  */
24*4c6de856SChristian Hitz int nand_bch_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
25*4c6de856SChristian Hitz 			   u_char *ecc_code);
26*4c6de856SChristian Hitz 
27*4c6de856SChristian Hitz /*
28*4c6de856SChristian Hitz  * Detect and correct bit errors
29*4c6de856SChristian Hitz  */
30*4c6de856SChristian Hitz int nand_bch_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc,
31*4c6de856SChristian Hitz 			  u_char *calc_ecc);
32*4c6de856SChristian Hitz /*
33*4c6de856SChristian Hitz  * Initialize BCH encoder/decoder
34*4c6de856SChristian Hitz  */
35*4c6de856SChristian Hitz struct nand_bch_control *
36*4c6de856SChristian Hitz nand_bch_init(struct mtd_info *mtd, unsigned int eccsize,
37*4c6de856SChristian Hitz 	      unsigned int eccbytes, struct nand_ecclayout **ecclayout);
38*4c6de856SChristian Hitz /*
39*4c6de856SChristian Hitz  * Release BCH encoder/decoder resources
40*4c6de856SChristian Hitz  */
41*4c6de856SChristian Hitz void nand_bch_free(struct nand_bch_control *nbc);
42*4c6de856SChristian Hitz 
43*4c6de856SChristian Hitz #else /* !CONFIG_NAND_ECC_BCH */
44*4c6de856SChristian Hitz 
45*4c6de856SChristian Hitz static inline int mtd_nand_has_bch(void) { return 0; }
46*4c6de856SChristian Hitz 
47*4c6de856SChristian Hitz static inline int
48*4c6de856SChristian Hitz nand_bch_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
49*4c6de856SChristian Hitz 		       u_char *ecc_code)
50*4c6de856SChristian Hitz {
51*4c6de856SChristian Hitz 	return -1;
52*4c6de856SChristian Hitz }
53*4c6de856SChristian Hitz 
54*4c6de856SChristian Hitz static inline int
55*4c6de856SChristian Hitz nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
56*4c6de856SChristian Hitz 		      unsigned char *read_ecc, unsigned char *calc_ecc)
57*4c6de856SChristian Hitz {
58*4c6de856SChristian Hitz 	return -1;
59*4c6de856SChristian Hitz }
60*4c6de856SChristian Hitz 
61*4c6de856SChristian Hitz static inline struct nand_bch_control *
62*4c6de856SChristian Hitz nand_bch_init(struct mtd_info *mtd, unsigned int eccsize,
63*4c6de856SChristian Hitz 	      unsigned int eccbytes, struct nand_ecclayout **ecclayout)
64*4c6de856SChristian Hitz {
65*4c6de856SChristian Hitz 	return NULL;
66*4c6de856SChristian Hitz }
67*4c6de856SChristian Hitz 
68*4c6de856SChristian Hitz static inline void nand_bch_free(struct nand_bch_control *nbc) {}
69*4c6de856SChristian Hitz 
70*4c6de856SChristian Hitz #endif /* CONFIG_NAND_ECC_BCH */
71*4c6de856SChristian Hitz 
72*4c6de856SChristian Hitz #endif /* __MTD_NAND_BCH_H__ */
73