1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright © 2011 Ivan Djelic <ivan.djelic@parrot.com>
4 *
5 * This file is the header for the NAND BCH ECC implementation.
6 */
7
8 #ifndef __MTD_NAND_BCH_H__
9 #define __MTD_NAND_BCH_H__
10
11 struct mtd_info;
12 struct nand_chip;
13 struct nand_bch_control;
14
15 #if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_BCH)
16
mtd_nand_has_bch(void)17 static inline int mtd_nand_has_bch(void) { return 1; }
18
19 /*
20 * Calculate BCH ecc code
21 */
22 int nand_bch_calculate_ecc(struct nand_chip *chip, const u_char *dat,
23 u_char *ecc_code);
24
25 /*
26 * Detect and correct bit errors
27 */
28 int nand_bch_correct_data(struct nand_chip *chip, u_char *dat,
29 u_char *read_ecc, u_char *calc_ecc);
30 /*
31 * Initialize BCH encoder/decoder
32 */
33 struct nand_bch_control *nand_bch_init(struct mtd_info *mtd);
34 /*
35 * Release BCH encoder/decoder resources
36 */
37 void nand_bch_free(struct nand_bch_control *nbc);
38
39 #else /* !CONFIG_MTD_NAND_ECC_SW_BCH */
40
mtd_nand_has_bch(void)41 static inline int mtd_nand_has_bch(void) { return 0; }
42
43 static inline int
nand_bch_calculate_ecc(struct nand_chip * chip,const u_char * dat,u_char * ecc_code)44 nand_bch_calculate_ecc(struct nand_chip *chip, const u_char *dat,
45 u_char *ecc_code)
46 {
47 return -1;
48 }
49
50 static inline int
nand_bch_correct_data(struct nand_chip * chip,unsigned char * buf,unsigned char * read_ecc,unsigned char * calc_ecc)51 nand_bch_correct_data(struct nand_chip *chip, unsigned char *buf,
52 unsigned char *read_ecc, unsigned char *calc_ecc)
53 {
54 return -ENOTSUPP;
55 }
56
nand_bch_init(struct mtd_info * mtd)57 static inline struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
58 {
59 return NULL;
60 }
61
nand_bch_free(struct nand_bch_control * nbc)62 static inline void nand_bch_free(struct nand_bch_control *nbc) {}
63
64 #endif /* CONFIG_MTD_NAND_ECC_SW_BCH */
65
66 #endif /* __MTD_NAND_BCH_H__ */
67