nand_bch.h 1.6 KB

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