1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright © 2011 Ivan Djelic <ivan.djelic@parrot.com>
5 * This file is the header for the NAND BCH ECC implementation.
8 #ifndef __MTD_NAND_BCH_H__
9 #define __MTD_NAND_BCH_H__
13 struct nand_bch_control;
15 #if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_BCH)
17 static inline int mtd_nand_has_bch(void) { return 1; }
20 * Calculate BCH ecc code
22 int nand_bch_calculate_ecc(struct nand_chip *chip, const u_char *dat,
26 * Detect and correct bit errors
28 int nand_bch_correct_data(struct nand_chip *chip, u_char *dat,
29 u_char *read_ecc, u_char *calc_ecc);
31 * Initialize BCH encoder/decoder
33 struct nand_bch_control *nand_bch_init(struct mtd_info *mtd);
35 * Release BCH encoder/decoder resources
37 void nand_bch_free(struct nand_bch_control *nbc);
39 #else /* !CONFIG_MTD_NAND_ECC_SW_BCH */
41 static inline int mtd_nand_has_bch(void) { return 0; }
44 nand_bch_calculate_ecc(struct nand_chip *chip, const u_char *dat,
51 nand_bch_correct_data(struct nand_chip *chip, unsigned char *buf,
52 unsigned char *read_ecc, unsigned char *calc_ecc)
57 static inline struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
62 static inline void nand_bch_free(struct nand_bch_control *nbc) {}
64 #endif /* CONFIG_MTD_NAND_ECC_SW_BCH */
66 #endif /* __MTD_NAND_BCH_H__ */