mtd: rawnand: Pass a nand_chip object to ecc->correct()
[linux-2.6-block.git] / include / linux / mtd / nand_bch.h
CommitLineData
193bd400
ID
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
11#ifndef __MTD_NAND_BCH_H__
12#define __MTD_NAND_BCH_H__
13
14struct mtd_info;
af37d2c3 15struct nand_chip;
193bd400
ID
16struct nand_bch_control;
17
18#if defined(CONFIG_MTD_NAND_ECC_BCH)
19
20static inline int mtd_nand_has_bch(void) { return 1; }
21
22/*
23 * Calculate BCH ecc code
24 */
af37d2c3 25int nand_bch_calculate_ecc(struct nand_chip *chip, const u_char *dat,
193bd400
ID
26 u_char *ecc_code);
27
28/*
29 * Detect and correct bit errors
30 */
00da2ea9
BB
31int nand_bch_correct_data(struct nand_chip *chip, u_char *dat,
32 u_char *read_ecc, u_char *calc_ecc);
193bd400
ID
33/*
34 * Initialize BCH encoder/decoder
35 */
a8c65d50 36struct nand_bch_control *nand_bch_init(struct mtd_info *mtd);
193bd400
ID
37/*
38 * Release BCH encoder/decoder resources
39 */
40void nand_bch_free(struct nand_bch_control *nbc);
41
42#else /* !CONFIG_MTD_NAND_ECC_BCH */
43
44static inline int mtd_nand_has_bch(void) { return 0; }
45
46static inline int
af37d2c3 47nand_bch_calculate_ecc(struct nand_chip *chip, const u_char *dat,
193bd400
ID
48 u_char *ecc_code)
49{
50 return -1;
51}
52
53static inline int
00da2ea9 54nand_bch_correct_data(struct nand_chip *chip, unsigned char *buf,
193bd400
ID
55 unsigned char *read_ecc, unsigned char *calc_ecc)
56{
6e941192 57 return -ENOTSUPP;
193bd400
ID
58}
59
a8c65d50 60static inline struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
193bd400
ID
61{
62 return NULL;
63}
64
65static inline void nand_bch_free(struct nand_bch_control *nbc) {}
66
67#endif /* CONFIG_MTD_NAND_ECC_BCH */
68
69#endif /* __MTD_NAND_BCH_H__ */