~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: 43f96b2f168c7b88e0c907996f2ae64f8554ed58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * © Copyright 2016 ATMEL
 * © Copyright 2016 Free Electrons
 *
 * Author: Boris Brezillon <boris.brezillon@free-electrons.com>
 *
 * Derived from the atmel_nand.c driver which contained the following
 * copyrights:
 *
 *    Copyright © 2003 Rick Bronson
 *
 *    Derived from drivers/mtd/nand/autcpu12.c (removed in v3.8)
 *        Copyright © 2001 Thomas Gleixner (gleixner@autronix.de)
 *
 *    Derived from drivers/mtd/spia.c (removed in v3.8)
 *        Copyright © 2000 Steven J. Hill (sjhill@cotw.com)
 *
 *
 *    Add Hardware ECC support for AT91SAM9260 / AT91SAM9263
 *        Richard Genoud (richard.genoud@gmail.com), Adeneo Copyright © 2007
 *
 *        Derived from Das U-Boot source code
 *              (u-boot-1.1.5/board/atmel/at91sam9263ek/nand.c)
 *        © Copyright 2006 ATMEL Rousset, Lacressonniere Nicolas
 *
 *    Add Programmable Multibit ECC support for various AT91 SoC
 *        © Copyright 2012 ATMEL, Hong Xu
 *
 *    Add Nand Flash Controller support for SAMA5 SoC
 *        © Copyright 2013 ATMEL, Josh Wu (josh.wu@atmel.com)
 */

#ifndef ATMEL_PMECC_H
#define ATMEL_PMECC_H

#define ATMEL_PMECC_MAXIMIZE_ECC_STRENGTH	0
#define ATMEL_PMECC_SECTOR_SIZE_AUTO		0
#define ATMEL_PMECC_OOBOFFSET_AUTO		-1

struct atmel_pmecc_user_req {
	int pagesize;
	int oobsize;
	struct {
		int strength;
		int bytes;
		int sectorsize;
		int nsectors;
		int ooboffset;
	} ecc;
};

struct atmel_pmecc_suspend_ctx {
	u32 setup;
	u32 pulse;
	u32 cycle;
	u32 timings;
	u32 mode;
};

struct atmel_pmecc {
	struct udevice *dev;
	const struct atmel_pmecc_caps *caps;

	struct {
		void __iomem *base;
		void __iomem *errloc;
		void __iomem *timing;
	} regs;

	/* Mutex used for pmecc enable/disable */
	struct mutex lock;

	struct atmel_pmecc_suspend_ctx suspend;
};

struct atmel_pmecc *devm_atmel_pmecc_get(struct udevice *dev);

struct atmel_pmecc_user *
atmel_pmecc_create_user(struct atmel_pmecc *pmecc,
			struct atmel_pmecc_user_req *req);
void atmel_pmecc_destroy_user(struct atmel_pmecc_user *user);

void atmel_pmecc_reset(struct atmel_pmecc *pmecc);
int atmel_pmecc_enable(struct atmel_pmecc_user *user, int op);
void atmel_pmecc_disable(struct atmel_pmecc_user *user);
int atmel_pmecc_wait_rdy(struct atmel_pmecc_user *user);
int atmel_pmecc_correct_sector(struct atmel_pmecc_user *user, int sector,
			       void *data, void *ecc);
bool atmel_pmecc_correct_erased_chunks(struct atmel_pmecc_user *user);
void atmel_pmecc_get_generated_eccbytes(struct atmel_pmecc_user *user,
					int sector, void *ecc);

#endif /* ATMEL_PMECC_H */