18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright © 2011 Ivan Djelic <ivan.djelic@parrot.com>
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * This file is the header for the NAND BCH ECC implementation.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef __MTD_NAND_BCH_H__
98c2ecf20Sopenharmony_ci#define __MTD_NAND_BCH_H__
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cistruct mtd_info;
128c2ecf20Sopenharmony_cistruct nand_chip;
138c2ecf20Sopenharmony_cistruct nand_bch_control;
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_BCH)
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistatic inline int mtd_nand_has_bch(void) { return 1; }
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/*
208c2ecf20Sopenharmony_ci * Calculate BCH ecc code
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ciint nand_bch_calculate_ecc(struct nand_chip *chip, const u_char *dat,
238c2ecf20Sopenharmony_ci			   u_char *ecc_code);
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/*
268c2ecf20Sopenharmony_ci * Detect and correct bit errors
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ciint nand_bch_correct_data(struct nand_chip *chip, u_char *dat,
298c2ecf20Sopenharmony_ci			  u_char *read_ecc, u_char *calc_ecc);
308c2ecf20Sopenharmony_ci/*
318c2ecf20Sopenharmony_ci * Initialize BCH encoder/decoder
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_cistruct nand_bch_control *nand_bch_init(struct mtd_info *mtd);
348c2ecf20Sopenharmony_ci/*
358c2ecf20Sopenharmony_ci * Release BCH encoder/decoder resources
368c2ecf20Sopenharmony_ci */
378c2ecf20Sopenharmony_civoid nand_bch_free(struct nand_bch_control *nbc);
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#else /* !CONFIG_MTD_NAND_ECC_SW_BCH */
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistatic inline int mtd_nand_has_bch(void) { return 0; }
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistatic inline int
448c2ecf20Sopenharmony_cinand_bch_calculate_ecc(struct nand_chip *chip, const u_char *dat,
458c2ecf20Sopenharmony_ci		       u_char *ecc_code)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	return -1;
488c2ecf20Sopenharmony_ci}
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistatic inline int
518c2ecf20Sopenharmony_cinand_bch_correct_data(struct nand_chip *chip, unsigned char *buf,
528c2ecf20Sopenharmony_ci		      unsigned char *read_ecc, unsigned char *calc_ecc)
538c2ecf20Sopenharmony_ci{
548c2ecf20Sopenharmony_ci	return -ENOTSUPP;
558c2ecf20Sopenharmony_ci}
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistatic inline struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
588c2ecf20Sopenharmony_ci{
598c2ecf20Sopenharmony_ci	return NULL;
608c2ecf20Sopenharmony_ci}
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistatic inline void nand_bch_free(struct nand_bch_control *nbc) {}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#endif /* CONFIG_MTD_NAND_ECC_SW_BCH */
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#endif /* __MTD_NAND_BCH_H__ */
67