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