xref: /openbmc/u-boot/include/linux/mtd/flashchip.h (revision 6e87ae1c)
1 /*
2  * Copyright © 2000      Red Hat UK Limited
3  * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  *
7  */
8 
9 #ifndef __MTD_FLASHCHIP_H__
10 #define __MTD_FLASHCHIP_H__
11 
12 #ifndef __UBOOT__
13 /* For spinlocks. sched.h includes spinlock.h from whichever directory it
14  * happens to be in - so we don't have to care whether we're on 2.2, which
15  * has asm/spinlock.h, or 2.4, which has linux/spinlock.h
16  */
17 #include <linux/sched.h>
18 #include <linux/mutex.h>
19 #endif
20 
21 typedef enum {
22 	FL_READY,
23 	FL_STATUS,
24 	FL_CFI_QUERY,
25 	FL_JEDEC_QUERY,
26 	FL_ERASING,
27 	FL_ERASE_SUSPENDING,
28 	FL_ERASE_SUSPENDED,
29 	FL_WRITING,
30 	FL_WRITING_TO_BUFFER,
31 	FL_OTP_WRITE,
32 	FL_WRITE_SUSPENDING,
33 	FL_WRITE_SUSPENDED,
34 	FL_PM_SUSPENDED,
35 	FL_SYNCING,
36 	FL_UNLOADING,
37 	FL_LOCKING,
38 	FL_UNLOCKING,
39 	FL_POINT,
40 	FL_XIP_WHILE_ERASING,
41 	FL_XIP_WHILE_WRITING,
42 	FL_SHUTDOWN,
43 	/* These 2 come from nand_state_t, which has been unified here */
44 	FL_READING,
45 	FL_CACHEDPRG,
46 	/* These 4 come from onenand_state_t, which has been unified here */
47 	FL_RESETING,
48 	FL_OTPING,
49 	FL_PREPARING_ERASE,
50 	FL_VERIFYING_ERASE,
51 
52 	FL_UNKNOWN
53 } flstate_t;
54 
55 
56 
57 /* NOTE: confusingly, this can be used to refer to more than one chip at a time,
58    if they're interleaved.  This can even refer to individual partitions on
59    the same physical chip when present. */
60 
61 struct flchip {
62 	unsigned long start; /* Offset within the map */
63 	//	unsigned long len;
64 	/* We omit len for now, because when we group them together
65 	   we insist that they're all of the same size, and the chip size
66 	   is held in the next level up. If we get more versatile later,
67 	   it'll make it a damn sight harder to find which chip we want from
68 	   a given offset, and we'll want to add the per-chip length field
69 	   back in.
70 	*/
71 	int ref_point_counter;
72 	flstate_t state;
73 	flstate_t oldstate;
74 
75 	unsigned int write_suspended:1;
76 	unsigned int erase_suspended:1;
77 	unsigned long in_progress_block_addr;
78 
79 	struct mutex mutex;
80 #ifndef __UBOOT__
81 	wait_queue_head_t wq; /* Wait on here when we're waiting for the chip
82 			     to be ready */
83 #endif
84 	int word_write_time;
85 	int buffer_write_time;
86 	int erase_time;
87 
88 	int word_write_time_max;
89 	int buffer_write_time_max;
90 	int erase_time_max;
91 
92 	void *priv;
93 };
94 
95 /* This is used to handle contention on write/erase operations
96    between partitions of the same physical chip. */
97 struct flchip_shared {
98 	struct mutex lock;
99 	struct flchip *writing;
100 	struct flchip *erasing;
101 };
102 
103 
104 #endif /* __MTD_FLASHCHIP_H__ */
105