David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright © 2011 Ivan Djelic <ivan.djelic@parrot.com> |
| 4 | * |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5 | * This file is the header for the NAND BCH ECC implementation. |
| 6 | */ |
| 7 | |
| 8 | #ifndef __MTD_NAND_BCH_H__ |
| 9 | #define __MTD_NAND_BCH_H__ |
| 10 | |
| 11 | struct mtd_info; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 12 | struct nand_chip; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13 | struct nand_bch_control; |
| 14 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 15 | #if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_BCH) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16 | |
| 17 | static inline int mtd_nand_has_bch(void) { return 1; } |
| 18 | |
| 19 | /* |
| 20 | * Calculate BCH ecc code |
| 21 | */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 22 | int nand_bch_calculate_ecc(struct nand_chip *chip, const u_char *dat, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 23 | u_char *ecc_code); |
| 24 | |
| 25 | /* |
| 26 | * Detect and correct bit errors |
| 27 | */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 28 | int nand_bch_correct_data(struct nand_chip *chip, u_char *dat, |
| 29 | u_char *read_ecc, u_char *calc_ecc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 30 | /* |
| 31 | * Initialize BCH encoder/decoder |
| 32 | */ |
| 33 | struct nand_bch_control *nand_bch_init(struct mtd_info *mtd); |
| 34 | /* |
| 35 | * Release BCH encoder/decoder resources |
| 36 | */ |
| 37 | void nand_bch_free(struct nand_bch_control *nbc); |
| 38 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 39 | #else /* !CONFIG_MTD_NAND_ECC_SW_BCH */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 40 | |
| 41 | static inline int mtd_nand_has_bch(void) { return 0; } |
| 42 | |
| 43 | static inline int |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 44 | nand_bch_calculate_ecc(struct nand_chip *chip, const u_char *dat, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 45 | u_char *ecc_code) |
| 46 | { |
| 47 | return -1; |
| 48 | } |
| 49 | |
| 50 | static inline int |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 51 | nand_bch_correct_data(struct nand_chip *chip, unsigned char *buf, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 52 | unsigned char *read_ecc, unsigned char *calc_ecc) |
| 53 | { |
| 54 | return -ENOTSUPP; |
| 55 | } |
| 56 | |
| 57 | static inline struct nand_bch_control *nand_bch_init(struct mtd_info *mtd) |
| 58 | { |
| 59 | return NULL; |
| 60 | } |
| 61 | |
| 62 | static inline void nand_bch_free(struct nand_bch_control *nbc) {} |
| 63 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 64 | #endif /* CONFIG_MTD_NAND_ECC_SW_BCH */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 65 | |
| 66 | #endif /* __MTD_NAND_BCH_H__ */ |