nand_bch.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #ifndef __MTD_NAND_BCH_H__
  11. #define __MTD_NAND_BCH_H__
  12. struct mtd_info;
  13. struct nand_bch_control;
  14. #if defined(CONFIG_NAND_ECC_BCH)
  15. static inline int mtd_nand_has_bch(void) { return 1; }
  16. /*
  17. * Calculate BCH ecc code
  18. */
  19. int nand_bch_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
  20. u_char *ecc_code);
  21. /*
  22. * Detect and correct bit errors
  23. */
  24. int nand_bch_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc,
  25. u_char *calc_ecc);
  26. /*
  27. * Initialize BCH encoder/decoder
  28. */
  29. struct nand_bch_control *nand_bch_init(struct mtd_info *mtd);
  30. /*
  31. * Release BCH encoder/decoder resources
  32. */
  33. void nand_bch_free(struct nand_bch_control *nbc);
  34. #else /* !CONFIG_NAND_ECC_BCH */
  35. static inline int mtd_nand_has_bch(void) { return 0; }
  36. static inline int
  37. nand_bch_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
  38. u_char *ecc_code)
  39. {
  40. return -1;
  41. }
  42. static inline int
  43. nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
  44. unsigned char *read_ecc, unsigned char *calc_ecc)
  45. {
  46. return -ENOTSUPP;
  47. }
  48. static inline struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
  49. {
  50. return NULL;
  51. }
  52. static inline void nand_bch_free(struct nand_bch_control *nbc) {}
  53. #endif /* CONFIG_NAND_ECC_BCH */
  54. #endif /* __MTD_NAND_BCH_H__ */