Commit | Line | Data |
---|---|---|
cd5f6346 KP |
1 | /* |
2 | * linux/include/linux/mtd/onenand.h | |
3 | * | |
28b79ff9 | 4 | * Copyright (C) 2005-2006 Samsung Electronics |
cd5f6346 KP |
5 | * Kyungmin Park <kyungmin.park@samsung.com> |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | */ | |
11 | ||
12 | #ifndef __LINUX_MTD_ONENAND_H | |
13 | #define __LINUX_MTD_ONENAND_H | |
14 | ||
15 | #include <linux/spinlock.h> | |
16 | #include <linux/mtd/onenand_regs.h> | |
cdc00130 | 17 | #include <linux/mtd/bbm.h> |
cd5f6346 KP |
18 | |
19 | #define MAX_BUFFERRAM 2 | |
20 | ||
21 | /* Scan and identify a OneNAND device */ | |
22 | extern int onenand_scan(struct mtd_info *mtd, int max_chips); | |
23 | /* Free resources held by the OneNAND device */ | |
24 | extern void onenand_release(struct mtd_info *mtd); | |
25 | ||
ea9b6dcc | 26 | /* |
cd5f6346 KP |
27 | * onenand_state_t - chip states |
28 | * Enumeration for OneNAND flash chip state | |
29 | */ | |
30 | typedef enum { | |
31 | FL_READY, | |
32 | FL_READING, | |
33 | FL_WRITING, | |
34 | FL_ERASING, | |
35 | FL_SYNCING, | |
36 | FL_UNLOCKING, | |
37 | FL_LOCKING, | |
493c6460 KP |
38 | FL_RESETING, |
39 | FL_OTPING, | |
a41371eb | 40 | FL_PM_SUSPENDED, |
cd5f6346 KP |
41 | } onenand_state_t; |
42 | ||
43 | /** | |
44 | * struct onenand_bufferram - OneNAND BufferRAM Data | |
ea9b6dcc RD |
45 | * @block: block address in BufferRAM |
46 | * @page: page address in BufferRAM | |
47 | * @valid: valid flag | |
cd5f6346 KP |
48 | */ |
49 | struct onenand_bufferram { | |
50 | int block; | |
51 | int page; | |
52 | int valid; | |
53 | }; | |
54 | ||
55 | /** | |
56 | * struct onenand_chip - OneNAND Private Flash Chip Data | |
ea9b6dcc RD |
57 | * @base: [BOARDSPECIFIC] address to access OneNAND |
58 | * @chipsize: [INTERN] the size of one chip for multichip arrays | |
59 | * @device_id: [INTERN] device ID | |
60 | * @density_mask: chip density, used for DDP devices | |
61 | * @verstion_id: [INTERN] version ID | |
62 | * @options: [BOARDSPECIFIC] various chip options. They can | |
63 | * partly be set to inform onenand_scan about | |
64 | * @erase_shift: [INTERN] number of address bits in a block | |
65 | * @page_shift: [INTERN] number of address bits in a page | |
66 | * @ppb_shift: [INTERN] number of address bits in a pages per block | |
67 | * @page_mask: [INTERN] a page per block mask | |
68 | * @bufferram_index: [INTERN] BufferRAM index | |
69 | * @bufferram: [INTERN] BufferRAM info | |
70 | * @readw: [REPLACEABLE] hardware specific function for read short | |
71 | * @writew: [REPLACEABLE] hardware specific function for write short | |
72 | * @command: [REPLACEABLE] hardware specific function for writing | |
73 | * commands to the chip | |
74 | * @wait: [REPLACEABLE] hardware specific function for wait on ready | |
75 | * @read_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area | |
76 | * @write_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area | |
77 | * @read_word: [REPLACEABLE] hardware specific function for read | |
78 | * register of OneNAND | |
79 | * @write_word: [REPLACEABLE] hardware specific function for write | |
80 | * register of OneNAND | |
81 | * @mmcontrol: sync burst read function | |
82 | * @block_markbad: function to mark a block as bad | |
83 | * @scan_bbt: [REPLACEALBE] hardware specific function for scanning | |
84 | * Bad block Table | |
85 | * @chip_lock: [INTERN] spinlock used to protect access to this | |
86 | * structure and the chip | |
87 | * @wq: [INTERN] wait queue to sleep on if a OneNAND | |
88 | * operation is in progress | |
89 | * @state: [INTERN] the current state of the OneNAND device | |
90 | * @page_buf: data buffer | |
91 | * @ecclayout: [REPLACEABLE] the default ecc placement scheme | |
92 | * @bbm: [REPLACEABLE] pointer to Bad Block Management | |
93 | * @priv: [OPTIONAL] pointer to private chip date | |
cd5f6346 KP |
94 | */ |
95 | struct onenand_chip { | |
96 | void __iomem *base; | |
97 | unsigned int chipsize; | |
98 | unsigned int device_id; | |
28b79ff9 | 99 | unsigned int version_id; |
83a36838 | 100 | unsigned int density_mask; |
cd5f6346 KP |
101 | unsigned int options; |
102 | ||
103 | unsigned int erase_shift; | |
104 | unsigned int page_shift; | |
105 | unsigned int ppb_shift; /* Pages per block shift */ | |
106 | unsigned int page_mask; | |
107 | ||
108 | unsigned int bufferram_index; | |
109 | struct onenand_bufferram bufferram[MAX_BUFFERRAM]; | |
110 | ||
111 | int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len); | |
112 | int (*wait)(struct mtd_info *mtd, int state); | |
113 | int (*read_bufferram)(struct mtd_info *mtd, int area, | |
114 | unsigned char *buffer, int offset, size_t count); | |
115 | int (*write_bufferram)(struct mtd_info *mtd, int area, | |
116 | const unsigned char *buffer, int offset, size_t count); | |
117 | unsigned short (*read_word)(void __iomem *addr); | |
118 | void (*write_word)(unsigned short value, void __iomem *addr); | |
52b0eea7 | 119 | void (*mmcontrol)(struct mtd_info *mtd, int sync_read); |
cdc00130 KP |
120 | int (*block_markbad)(struct mtd_info *mtd, loff_t ofs); |
121 | int (*scan_bbt)(struct mtd_info *mtd); | |
cd5f6346 KP |
122 | |
123 | spinlock_t chip_lock; | |
124 | wait_queue_head_t wq; | |
125 | onenand_state_t state; | |
532a37cf | 126 | unsigned char *page_buf; |
cd5f6346 | 127 | |
5bd34c09 | 128 | struct nand_ecclayout *ecclayout; |
cd5f6346 | 129 | |
5bd34c09 | 130 | void *bbm; |
cdc00130 | 131 | |
cd5f6346 KP |
132 | void *priv; |
133 | }; | |
134 | ||
fcc31470 KP |
135 | /* |
136 | * Helper macros | |
137 | */ | |
cd5f6346 KP |
138 | #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index) |
139 | #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1) | |
140 | #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1) | |
141 | ||
fcc31470 KP |
142 | #define ONENAND_GET_SYS_CFG1(this) \ |
143 | (this->read_word(this->base + ONENAND_REG_SYS_CFG1)) | |
144 | #define ONENAND_SET_SYS_CFG1(v, this) \ | |
145 | (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1)) | |
146 | ||
9c01f87d KP |
147 | /* Check byte access in OneNAND */ |
148 | #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1) | |
149 | ||
cd5f6346 KP |
150 | /* |
151 | * Options bits | |
152 | */ | |
28b79ff9 KP |
153 | #define ONENAND_HAS_CONT_LOCK (0x0001) |
154 | #define ONENAND_HAS_UNLOCK_ALL (0x0002) | |
532a37cf | 155 | #define ONENAND_PAGEBUF_ALLOC (0x1000) |
cd5f6346 KP |
156 | |
157 | /* | |
158 | * OneNAND Flash Manufacturer ID Codes | |
159 | */ | |
160 | #define ONENAND_MFR_SAMSUNG 0xec | |
cd5f6346 KP |
161 | |
162 | /** | |
ea9b6dcc RD |
163 | * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure |
164 | * @name: Manufacturer name | |
165 | * @id: manufacturer ID code of device. | |
cd5f6346 KP |
166 | */ |
167 | struct onenand_manufacturers { | |
168 | int id; | |
169 | char *name; | |
170 | }; | |
171 | ||
172 | #endif /* __LINUX_MTD_ONENAND_H */ |