1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __DRIVERS_MTD_NAND_INGENIC_ECC_INTERNAL_H__
3 #define __DRIVERS_MTD_NAND_INGENIC_ECC_INTERNAL_H__
4 
5 #include <linux/compiler_types.h>
6 #include <linux/err.h>
7 #include <linux/mutex.h>
8 #include <linux/types.h>
9 #include <uapi/asm-generic/errno-base.h>
10 
11 struct clk;
12 struct device;
13 struct ingenic_ecc;
14 struct platform_device;
15 
16 /**
17  * struct ingenic_ecc_params - ECC parameters
18  * @size: data bytes per ECC step.
19  * @bytes: ECC bytes per step.
20  * @strength: number of correctable bits per ECC step.
21  */
22 struct ingenic_ecc_params {
23 	int size;
24 	int bytes;
25 	int strength;
26 };
27 
28 #if IS_ENABLED(CONFIG_MTD_NAND_INGENIC_ECC)
29 int ingenic_ecc_calculate(struct ingenic_ecc *ecc,
30 			  struct ingenic_ecc_params *params,
31 			  const u8 *buf, u8 *ecc_code);
32 int ingenic_ecc_correct(struct ingenic_ecc *ecc,
33 			struct ingenic_ecc_params *params, u8 *buf,
34 			u8 *ecc_code);
35 
36 void ingenic_ecc_release(struct ingenic_ecc *ecc);
37 struct ingenic_ecc *of_ingenic_ecc_get(struct device_node *np);
38 #else /* CONFIG_MTD_NAND_INGENIC_ECC */
39 int ingenic_ecc_calculate(struct ingenic_ecc *ecc,
40 			  struct ingenic_ecc_params *params,
41 			  const u8 *buf, u8 *ecc_code)
42 {
43 	return -ENODEV;
44 }
45 
46 int ingenic_ecc_correct(struct ingenic_ecc *ecc,
47 			struct ingenic_ecc_params *params, u8 *buf,
48 			u8 *ecc_code)
49 {
50 	return -ENODEV;
51 }
52 
53 void ingenic_ecc_release(struct ingenic_ecc *ecc)
54 {
55 }
56 
57 struct ingenic_ecc *of_ingenic_ecc_get(struct device_node *np)
58 {
59 	return ERR_PTR(-ENODEV);
60 }
61 #endif /* CONFIG_MTD_NAND_INGENIC_ECC */
62 
63 struct ingenic_ecc_ops {
64 	void (*disable)(struct ingenic_ecc *ecc);
65 	int (*calculate)(struct ingenic_ecc *ecc,
66 			 struct ingenic_ecc_params *params,
67 			 const u8 *buf, u8 *ecc_code);
68 	int (*correct)(struct ingenic_ecc *ecc,
69 			struct ingenic_ecc_params *params,
70 			u8 *buf, u8 *ecc_code);
71 };
72 
73 struct ingenic_ecc {
74 	struct device *dev;
75 	const struct ingenic_ecc_ops *ops;
76 	void __iomem *base;
77 	struct clk *clk;
78 	struct mutex lock;
79 };
80 
81 int ingenic_ecc_probe(struct platform_device *pdev);
82 
83 #endif /* __DRIVERS_MTD_NAND_INGENIC_ECC_INTERNAL_H__ */
84