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