xref: /openbmc/u-boot/include/linux/mtd/nand_bch.h (revision dc557e9a1fe00ca9d884bd88feef5bebf23fede4)
14c6de856SChristian Hitz /*
24c6de856SChristian Hitz  * Copyright © 2011 Ivan Djelic <ivan.djelic@parrot.com>
34c6de856SChristian Hitz  *
44c6de856SChristian Hitz  * This program is free software; you can redistribute it and/or modify
54c6de856SChristian Hitz  * it under the terms of the GNU General Public License version 2 as
64c6de856SChristian Hitz  * published by the Free Software Foundation.
74c6de856SChristian Hitz  *
84c6de856SChristian Hitz  * This file is the header for the NAND BCH ECC implementation.
94c6de856SChristian Hitz  */
104c6de856SChristian Hitz 
114c6de856SChristian Hitz #ifndef __MTD_NAND_BCH_H__
124c6de856SChristian Hitz #define __MTD_NAND_BCH_H__
134c6de856SChristian Hitz 
144c6de856SChristian Hitz struct mtd_info;
154c6de856SChristian Hitz struct nand_bch_control;
164c6de856SChristian Hitz 
174c6de856SChristian Hitz #if defined(CONFIG_NAND_ECC_BCH)
184c6de856SChristian Hitz 
mtd_nand_has_bch(void)194c6de856SChristian Hitz static inline int mtd_nand_has_bch(void) { return 1; }
204c6de856SChristian Hitz 
214c6de856SChristian Hitz /*
224c6de856SChristian Hitz  * Calculate BCH ecc code
234c6de856SChristian Hitz  */
244c6de856SChristian Hitz int nand_bch_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
254c6de856SChristian Hitz 			   u_char *ecc_code);
264c6de856SChristian Hitz 
274c6de856SChristian Hitz /*
284c6de856SChristian Hitz  * Detect and correct bit errors
294c6de856SChristian Hitz  */
304c6de856SChristian Hitz int nand_bch_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc,
314c6de856SChristian Hitz 			  u_char *calc_ecc);
324c6de856SChristian Hitz /*
334c6de856SChristian Hitz  * Initialize BCH encoder/decoder
344c6de856SChristian Hitz  */
35*ceee07b6SScott Wood struct nand_bch_control *nand_bch_init(struct mtd_info *mtd);
364c6de856SChristian Hitz /*
374c6de856SChristian Hitz  * Release BCH encoder/decoder resources
384c6de856SChristian Hitz  */
394c6de856SChristian Hitz void nand_bch_free(struct nand_bch_control *nbc);
404c6de856SChristian Hitz 
414c6de856SChristian Hitz #else /* !CONFIG_NAND_ECC_BCH */
424c6de856SChristian Hitz 
mtd_nand_has_bch(void)434c6de856SChristian Hitz static inline int mtd_nand_has_bch(void) { return 0; }
444c6de856SChristian Hitz 
454c6de856SChristian Hitz static inline int
nand_bch_calculate_ecc(struct mtd_info * mtd,const u_char * dat,u_char * ecc_code)464c6de856SChristian Hitz nand_bch_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
474c6de856SChristian Hitz 		       u_char *ecc_code)
484c6de856SChristian Hitz {
494c6de856SChristian Hitz 	return -1;
504c6de856SChristian Hitz }
514c6de856SChristian Hitz 
524c6de856SChristian Hitz static inline int
nand_bch_correct_data(struct mtd_info * mtd,unsigned char * buf,unsigned char * read_ecc,unsigned char * calc_ecc)534c6de856SChristian Hitz nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
544c6de856SChristian Hitz 		      unsigned char *read_ecc, unsigned char *calc_ecc)
554c6de856SChristian Hitz {
56*ceee07b6SScott Wood 	return -ENOTSUPP;
574c6de856SChristian Hitz }
584c6de856SChristian Hitz 
nand_bch_init(struct mtd_info * mtd)59*ceee07b6SScott Wood static inline struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
604c6de856SChristian Hitz {
614c6de856SChristian Hitz 	return NULL;
624c6de856SChristian Hitz }
634c6de856SChristian Hitz 
nand_bch_free(struct nand_bch_control * nbc)644c6de856SChristian Hitz static inline void nand_bch_free(struct nand_bch_control *nbc) {}
654c6de856SChristian Hitz 
664c6de856SChristian Hitz #endif /* CONFIG_NAND_ECC_BCH */
674c6de856SChristian Hitz 
684c6de856SChristian Hitz #endif /* __MTD_NAND_BCH_H__ */
69