]>
Commit | Line | Data |
---|---|---|
ce082596 JR |
1 | /* |
2 | * NAND Flash Controller Device Driver | |
3 | * Copyright (c) 2009 - 2010, Intel Corporation and its suppliers. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms and conditions of the GNU General Public License, | |
7 | * version 2, as published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along with | |
15 | * this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | * | |
18 | */ | |
19 | ||
a81b4708 MY |
20 | #ifndef __DENALI_H__ |
21 | #define __DENALI_H__ | |
22 | ||
24715c74 | 23 | #include <linux/bitops.h> |
6ea9ad24 | 24 | #include <linux/mtd/nand.h> |
ce082596 JR |
25 | |
26 | #define DEVICE_RESET 0x0 | |
df8b9702 | 27 | #define DEVICE_RESET__BANK(bank) BIT(bank) |
ce082596 JR |
28 | |
29 | #define TRANSFER_SPARE_REG 0x10 | |
df8b9702 | 30 | #define TRANSFER_SPARE_REG__FLAG BIT(0) |
ce082596 JR |
31 | |
32 | #define LOAD_WAIT_CNT 0x20 | |
df8b9702 | 33 | #define LOAD_WAIT_CNT__VALUE GENMASK(15, 0) |
ce082596 JR |
34 | |
35 | #define PROGRAM_WAIT_CNT 0x30 | |
df8b9702 | 36 | #define PROGRAM_WAIT_CNT__VALUE GENMASK(15, 0) |
ce082596 JR |
37 | |
38 | #define ERASE_WAIT_CNT 0x40 | |
df8b9702 | 39 | #define ERASE_WAIT_CNT__VALUE GENMASK(15, 0) |
ce082596 JR |
40 | |
41 | #define INT_MON_CYCCNT 0x50 | |
df8b9702 | 42 | #define INT_MON_CYCCNT__VALUE GENMASK(15, 0) |
ce082596 JR |
43 | |
44 | #define RB_PIN_ENABLED 0x60 | |
df8b9702 | 45 | #define RB_PIN_ENABLED__BANK(bank) BIT(bank) |
ce082596 JR |
46 | |
47 | #define MULTIPLANE_OPERATION 0x70 | |
df8b9702 | 48 | #define MULTIPLANE_OPERATION__FLAG BIT(0) |
ce082596 JR |
49 | |
50 | #define MULTIPLANE_READ_ENABLE 0x80 | |
df8b9702 | 51 | #define MULTIPLANE_READ_ENABLE__FLAG BIT(0) |
ce082596 JR |
52 | |
53 | #define COPYBACK_DISABLE 0x90 | |
df8b9702 | 54 | #define COPYBACK_DISABLE__FLAG BIT(0) |
ce082596 JR |
55 | |
56 | #define CACHE_WRITE_ENABLE 0xa0 | |
df8b9702 | 57 | #define CACHE_WRITE_ENABLE__FLAG BIT(0) |
ce082596 JR |
58 | |
59 | #define CACHE_READ_ENABLE 0xb0 | |
df8b9702 | 60 | #define CACHE_READ_ENABLE__FLAG BIT(0) |
ce082596 JR |
61 | |
62 | #define PREFETCH_MODE 0xc0 | |
df8b9702 MY |
63 | #define PREFETCH_MODE__PREFETCH_EN BIT(0) |
64 | #define PREFETCH_MODE__PREFETCH_BURST_LENGTH GENMASK(15, 4) | |
ce082596 JR |
65 | |
66 | #define CHIP_ENABLE_DONT_CARE 0xd0 | |
df8b9702 | 67 | #define CHIP_EN_DONT_CARE__FLAG BIT(0) |
ce082596 JR |
68 | |
69 | #define ECC_ENABLE 0xe0 | |
df8b9702 | 70 | #define ECC_ENABLE__FLAG BIT(0) |
ce082596 JR |
71 | |
72 | #define GLOBAL_INT_ENABLE 0xf0 | |
df8b9702 | 73 | #define GLOBAL_INT_EN_FLAG BIT(0) |
ce082596 | 74 | |
1bb88666 MY |
75 | #define TWHR2_AND_WE_2_RE 0x100 |
76 | #define TWHR2_AND_WE_2_RE__WE_2_RE GENMASK(5, 0) | |
77 | #define TWHR2_AND_WE_2_RE__TWHR2 GENMASK(13, 8) | |
ce082596 | 78 | |
1bb88666 MY |
79 | #define TCWAW_AND_ADDR_2_DATA 0x110 |
80 | /* The width of ADDR_2_DATA is 6 bit for old IP, 7 bit for new IP */ | |
81 | #define TCWAW_AND_ADDR_2_DATA__ADDR_2_DATA GENMASK(6, 0) | |
82 | #define TCWAW_AND_ADDR_2_DATA__TCWAW GENMASK(13, 8) | |
ce082596 JR |
83 | |
84 | #define RE_2_WE 0x120 | |
df8b9702 | 85 | #define RE_2_WE__VALUE GENMASK(5, 0) |
ce082596 | 86 | |
6ea9ad24 | 87 | #define ACC_CLKS 0x130 |
df8b9702 | 88 | #define ACC_CLKS__VALUE GENMASK(3, 0) |
ce082596 JR |
89 | |
90 | #define NUMBER_OF_PLANES 0x140 | |
df8b9702 | 91 | #define NUMBER_OF_PLANES__VALUE GENMASK(2, 0) |
ce082596 JR |
92 | |
93 | #define PAGES_PER_BLOCK 0x150 | |
df8b9702 | 94 | #define PAGES_PER_BLOCK__VALUE GENMASK(15, 0) |
ce082596 JR |
95 | |
96 | #define DEVICE_WIDTH 0x160 | |
df8b9702 | 97 | #define DEVICE_WIDTH__VALUE GENMASK(1, 0) |
ce082596 JR |
98 | |
99 | #define DEVICE_MAIN_AREA_SIZE 0x170 | |
df8b9702 | 100 | #define DEVICE_MAIN_AREA_SIZE__VALUE GENMASK(15, 0) |
ce082596 JR |
101 | |
102 | #define DEVICE_SPARE_AREA_SIZE 0x180 | |
df8b9702 | 103 | #define DEVICE_SPARE_AREA_SIZE__VALUE GENMASK(15, 0) |
ce082596 JR |
104 | |
105 | #define TWO_ROW_ADDR_CYCLES 0x190 | |
df8b9702 | 106 | #define TWO_ROW_ADDR_CYCLES__FLAG BIT(0) |
ce082596 JR |
107 | |
108 | #define MULTIPLANE_ADDR_RESTRICT 0x1a0 | |
df8b9702 | 109 | #define MULTIPLANE_ADDR_RESTRICT__FLAG BIT(0) |
ce082596 JR |
110 | |
111 | #define ECC_CORRECTION 0x1b0 | |
df8b9702 | 112 | #define ECC_CORRECTION__VALUE GENMASK(4, 0) |
ce082596 JR |
113 | |
114 | #define READ_MODE 0x1c0 | |
df8b9702 | 115 | #define READ_MODE__VALUE GENMASK(3, 0) |
ce082596 JR |
116 | |
117 | #define WRITE_MODE 0x1d0 | |
df8b9702 | 118 | #define WRITE_MODE__VALUE GENMASK(3, 0) |
ce082596 JR |
119 | |
120 | #define COPYBACK_MODE 0x1e0 | |
df8b9702 | 121 | #define COPYBACK_MODE__VALUE GENMASK(3, 0) |
ce082596 JR |
122 | |
123 | #define RDWR_EN_LO_CNT 0x1f0 | |
df8b9702 | 124 | #define RDWR_EN_LO_CNT__VALUE GENMASK(4, 0) |
ce082596 JR |
125 | |
126 | #define RDWR_EN_HI_CNT 0x200 | |
df8b9702 | 127 | #define RDWR_EN_HI_CNT__VALUE GENMASK(4, 0) |
ce082596 JR |
128 | |
129 | #define MAX_RD_DELAY 0x210 | |
df8b9702 | 130 | #define MAX_RD_DELAY__VALUE GENMASK(3, 0) |
ce082596 JR |
131 | |
132 | #define CS_SETUP_CNT 0x220 | |
df8b9702 | 133 | #define CS_SETUP_CNT__VALUE GENMASK(4, 0) |
1bb88666 | 134 | #define CS_SETUP_CNT__TWB GENMASK(17, 12) |
ce082596 JR |
135 | |
136 | #define SPARE_AREA_SKIP_BYTES 0x230 | |
df8b9702 | 137 | #define SPARE_AREA_SKIP_BYTES__VALUE GENMASK(5, 0) |
ce082596 JR |
138 | |
139 | #define SPARE_AREA_MARKER 0x240 | |
df8b9702 | 140 | #define SPARE_AREA_MARKER__VALUE GENMASK(15, 0) |
ce082596 JR |
141 | |
142 | #define DEVICES_CONNECTED 0x250 | |
df8b9702 | 143 | #define DEVICES_CONNECTED__VALUE GENMASK(2, 0) |
ce082596 | 144 | |
6ea9ad24 | 145 | #define DIE_MASK 0x260 |
df8b9702 | 146 | #define DIE_MASK__VALUE GENMASK(7, 0) |
ce082596 JR |
147 | |
148 | #define FIRST_BLOCK_OF_NEXT_PLANE 0x270 | |
df8b9702 | 149 | #define FIRST_BLOCK_OF_NEXT_PLANE__VALUE GENMASK(15, 0) |
ce082596 JR |
150 | |
151 | #define WRITE_PROTECT 0x280 | |
df8b9702 | 152 | #define WRITE_PROTECT__FLAG BIT(0) |
ce082596 JR |
153 | |
154 | #define RE_2_RE 0x290 | |
df8b9702 | 155 | #define RE_2_RE__VALUE GENMASK(5, 0) |
ce082596 | 156 | |
6ea9ad24 | 157 | #define MANUFACTURER_ID 0x300 |
df8b9702 | 158 | #define MANUFACTURER_ID__VALUE GENMASK(7, 0) |
ce082596 JR |
159 | |
160 | #define DEVICE_ID 0x310 | |
df8b9702 | 161 | #define DEVICE_ID__VALUE GENMASK(7, 0) |
ce082596 JR |
162 | |
163 | #define DEVICE_PARAM_0 0x320 | |
df8b9702 | 164 | #define DEVICE_PARAM_0__VALUE GENMASK(7, 0) |
ce082596 JR |
165 | |
166 | #define DEVICE_PARAM_1 0x330 | |
df8b9702 | 167 | #define DEVICE_PARAM_1__VALUE GENMASK(7, 0) |
ce082596 JR |
168 | |
169 | #define DEVICE_PARAM_2 0x340 | |
df8b9702 | 170 | #define DEVICE_PARAM_2__VALUE GENMASK(7, 0) |
ce082596 JR |
171 | |
172 | #define LOGICAL_PAGE_DATA_SIZE 0x350 | |
df8b9702 | 173 | #define LOGICAL_PAGE_DATA_SIZE__VALUE GENMASK(15, 0) |
ce082596 JR |
174 | |
175 | #define LOGICAL_PAGE_SPARE_SIZE 0x360 | |
df8b9702 | 176 | #define LOGICAL_PAGE_SPARE_SIZE__VALUE GENMASK(15, 0) |
ce082596 | 177 | |
6ea9ad24 | 178 | #define REVISION 0x370 |
df8b9702 | 179 | #define REVISION__VALUE GENMASK(15, 0) |
ce082596 JR |
180 | |
181 | #define ONFI_DEVICE_FEATURES 0x380 | |
df8b9702 | 182 | #define ONFI_DEVICE_FEATURES__VALUE GENMASK(5, 0) |
ce082596 | 183 | |
6ea9ad24 | 184 | #define ONFI_OPTIONAL_COMMANDS 0x390 |
df8b9702 | 185 | #define ONFI_OPTIONAL_COMMANDS__VALUE GENMASK(5, 0) |
ce082596 JR |
186 | |
187 | #define ONFI_TIMING_MODE 0x3a0 | |
df8b9702 | 188 | #define ONFI_TIMING_MODE__VALUE GENMASK(5, 0) |
ce082596 JR |
189 | |
190 | #define ONFI_PGM_CACHE_TIMING_MODE 0x3b0 | |
df8b9702 | 191 | #define ONFI_PGM_CACHE_TIMING_MODE__VALUE GENMASK(5, 0) |
ce082596 JR |
192 | |
193 | #define ONFI_DEVICE_NO_OF_LUNS 0x3c0 | |
df8b9702 MY |
194 | #define ONFI_DEVICE_NO_OF_LUNS__NO_OF_LUNS GENMASK(7, 0) |
195 | #define ONFI_DEVICE_NO_OF_LUNS__ONFI_DEVICE BIT(8) | |
ce082596 JR |
196 | |
197 | #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_L 0x3d0 | |
df8b9702 | 198 | #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_L__VALUE GENMASK(15, 0) |
ce082596 JR |
199 | |
200 | #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_U 0x3e0 | |
df8b9702 MY |
201 | #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_U__VALUE GENMASK(15, 0) |
202 | ||
203 | #define FEATURES 0x3f0 | |
204 | #define FEATURES__N_BANKS GENMASK(1, 0) | |
205 | #define FEATURES__ECC_MAX_ERR GENMASK(5, 2) | |
206 | #define FEATURES__DMA BIT(6) | |
207 | #define FEATURES__CMD_DMA BIT(7) | |
208 | #define FEATURES__PARTITION BIT(8) | |
209 | #define FEATURES__XDMA_SIDEBAND BIT(9) | |
210 | #define FEATURES__GPREG BIT(10) | |
211 | #define FEATURES__INDEX_ADDR BIT(11) | |
ce082596 JR |
212 | |
213 | #define TRANSFER_MODE 0x400 | |
df8b9702 | 214 | #define TRANSFER_MODE__VALUE GENMASK(1, 0) |
ce082596 | 215 | |
df8b9702 MY |
216 | #define INTR_STATUS(bank) (0x410 + (bank) * 0x50) |
217 | #define INTR_EN(bank) (0x420 + (bank) * 0x50) | |
24715c74 | 218 | /* bit[1:0] is used differently depending on IP version */ |
df8b9702 MY |
219 | #define INTR__ECC_UNCOR_ERR BIT(0) /* new IP */ |
220 | #define INTR__ECC_TRANSACTION_DONE BIT(0) /* old IP */ | |
221 | #define INTR__ECC_ERR BIT(1) /* old IP */ | |
222 | #define INTR__DMA_CMD_COMP BIT(2) | |
223 | #define INTR__TIME_OUT BIT(3) | |
224 | #define INTR__PROGRAM_FAIL BIT(4) | |
225 | #define INTR__ERASE_FAIL BIT(5) | |
226 | #define INTR__LOAD_COMP BIT(6) | |
227 | #define INTR__PROGRAM_COMP BIT(7) | |
228 | #define INTR__ERASE_COMP BIT(8) | |
229 | #define INTR__PIPE_CPYBCK_CMD_COMP BIT(9) | |
230 | #define INTR__LOCKED_BLK BIT(10) | |
231 | #define INTR__UNSUP_CMD BIT(11) | |
232 | #define INTR__INT_ACT BIT(12) | |
233 | #define INTR__RST_COMP BIT(13) | |
234 | #define INTR__PIPE_CMD_ERR BIT(14) | |
235 | #define INTR__PAGE_XFER_INC BIT(15) | |
236 | ||
237 | #define PAGE_CNT(bank) (0x430 + (bank) * 0x50) | |
238 | #define ERR_PAGE_ADDR(bank) (0x440 + (bank) * 0x50) | |
239 | #define ERR_BLOCK_ADDR(bank) (0x450 + (bank) * 0x50) | |
ce082596 | 240 | |
ce082596 | 241 | #define ECC_THRESHOLD 0x600 |
df8b9702 | 242 | #define ECC_THRESHOLD__VALUE GENMASK(9, 0) |
ce082596 | 243 | |
6ea9ad24 | 244 | #define ECC_ERROR_BLOCK_ADDRESS 0x610 |
df8b9702 | 245 | #define ECC_ERROR_BLOCK_ADDRESS__VALUE GENMASK(15, 0) |
ce082596 JR |
246 | |
247 | #define ECC_ERROR_PAGE_ADDRESS 0x620 | |
df8b9702 MY |
248 | #define ECC_ERROR_PAGE_ADDRESS__VALUE GENMASK(11, 0) |
249 | #define ECC_ERROR_PAGE_ADDRESS__BANK GENMASK(15, 12) | |
ce082596 JR |
250 | |
251 | #define ECC_ERROR_ADDRESS 0x630 | |
df8b9702 MY |
252 | #define ECC_ERROR_ADDRESS__OFFSET GENMASK(11, 0) |
253 | #define ECC_ERROR_ADDRESS__SECTOR_NR GENMASK(15, 12) | |
ce082596 JR |
254 | |
255 | #define ERR_CORRECTION_INFO 0x640 | |
df8b9702 MY |
256 | #define ERR_CORRECTION_INFO__BYTEMASK GENMASK(7, 0) |
257 | #define ERR_CORRECTION_INFO__DEVICE_NR GENMASK(11, 8) | |
258 | #define ERR_CORRECTION_INFO__ERROR_TYPE BIT(14) | |
259 | #define ERR_CORRECTION_INFO__LAST_ERR_INFO BIT(15) | |
ce082596 | 260 | |
24715c74 MY |
261 | #define ECC_COR_INFO(bank) (0x650 + (bank) / 2 * 0x10) |
262 | #define ECC_COR_INFO__SHIFT(bank) ((bank) % 2 * 8) | |
df8b9702 MY |
263 | #define ECC_COR_INFO__MAX_ERRORS GENMASK(6, 0) |
264 | #define ECC_COR_INFO__UNCOR_ERR BIT(7) | |
24715c74 | 265 | |
7de117fd MY |
266 | #define CFG_DATA_BLOCK_SIZE 0x6b0 |
267 | ||
268 | #define CFG_LAST_DATA_BLOCK_SIZE 0x6c0 | |
269 | ||
270 | #define CFG_NUM_DATA_BLOCKS 0x6d0 | |
271 | ||
272 | #define CFG_META_DATA_SIZE 0x6e0 | |
273 | ||
ce082596 | 274 | #define DMA_ENABLE 0x700 |
df8b9702 | 275 | #define DMA_ENABLE__FLAG BIT(0) |
ce082596 JR |
276 | |
277 | #define IGNORE_ECC_DONE 0x710 | |
df8b9702 | 278 | #define IGNORE_ECC_DONE__FLAG BIT(0) |
ce082596 JR |
279 | |
280 | #define DMA_INTR 0x720 | |
1aded58a | 281 | #define DMA_INTR_EN 0x730 |
df8b9702 MY |
282 | #define DMA_INTR__TARGET_ERROR BIT(0) |
283 | #define DMA_INTR__DESC_COMP_CHANNEL0 BIT(1) | |
284 | #define DMA_INTR__DESC_COMP_CHANNEL1 BIT(2) | |
285 | #define DMA_INTR__DESC_COMP_CHANNEL2 BIT(3) | |
286 | #define DMA_INTR__DESC_COMP_CHANNEL3 BIT(4) | |
287 | #define DMA_INTR__MEMCOPY_DESC_COMP BIT(5) | |
ce082596 JR |
288 | |
289 | #define TARGET_ERR_ADDR_LO 0x740 | |
df8b9702 | 290 | #define TARGET_ERR_ADDR_LO__VALUE GENMASK(15, 0) |
ce082596 JR |
291 | |
292 | #define TARGET_ERR_ADDR_HI 0x750 | |
df8b9702 | 293 | #define TARGET_ERR_ADDR_HI__VALUE GENMASK(15, 0) |
ce082596 JR |
294 | |
295 | #define CHNL_ACTIVE 0x760 | |
df8b9702 MY |
296 | #define CHNL_ACTIVE__CHANNEL0 BIT(0) |
297 | #define CHNL_ACTIVE__CHANNEL1 BIT(1) | |
298 | #define CHNL_ACTIVE__CHANNEL2 BIT(2) | |
299 | #define CHNL_ACTIVE__CHANNEL3 BIT(3) | |
ce082596 | 300 | |
ce082596 | 301 | #define PASS 0 /*success flag*/ |
ce082596 | 302 | |
ce082596 JR |
303 | #define MODE_00 0x00000000 |
304 | #define MODE_01 0x04000000 | |
305 | #define MODE_10 0x08000000 | |
306 | #define MODE_11 0x0C000000 | |
307 | ||
6ea9ad24 | 308 | struct nand_buf { |
e07caa36 | 309 | uint8_t *buf; |
ce082596 JR |
310 | dma_addr_t dma_buf; |
311 | }; | |
312 | ||
ce082596 | 313 | struct denali_nand_info { |
ce082596 | 314 | struct nand_chip nand; |
1bb88666 | 315 | unsigned long clk_x_rate; /* bus interface clock rate */ |
ce082596 | 316 | int flash_bank; /* currently selected chip */ |
ce082596 | 317 | struct nand_buf buf; |
84457949 | 318 | struct device *dev; |
60ca41f1 MY |
319 | void __iomem *flash_reg; /* Register Interface */ |
320 | void __iomem *flash_mem; /* Host Data/Command Interface */ | |
ce082596 JR |
321 | |
322 | /* elements used by ISR */ | |
323 | struct completion complete; | |
324 | spinlock_t irq_lock; | |
c19e31d0 | 325 | uint32_t irq_mask; |
ce082596 | 326 | uint32_t irq_status; |
2a0a288e | 327 | int irq; |
66406524 | 328 | |
e30b4690 MY |
329 | int devnum; /* represent how many nands connected */ |
330 | int bbtskipbytes; | |
331 | int max_banks; | |
e7beeeec | 332 | unsigned int revision; |
be72a4aa | 333 | unsigned int caps; |
7de117fd | 334 | const struct nand_ecc_caps *ecc_caps; |
ce082596 JR |
335 | }; |
336 | ||
24715c74 | 337 | #define DENALI_CAP_HW_ECC_FIXUP BIT(0) |
210a2c87 | 338 | #define DENALI_CAP_DMA_64BIT BIT(1) |
24715c74 | 339 | |
7de117fd | 340 | int denali_calc_ecc_bytes(int step_size, int strength); |
2a0a288e DN |
341 | extern int denali_init(struct denali_nand_info *denali); |
342 | extern void denali_remove(struct denali_nand_info *denali); | |
343 | ||
a81b4708 | 344 | #endif /* __DENALI_H__ */ |