Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/mtd/onenand/onenand_base.c |
| 3 | * |
| 4 | * Copyright (C) 2005-2007 Samsung Electronics |
| 5 | * Kyungmin Park <kyungmin.park@samsung.com> |
| 6 | * |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 7 | * Credits: |
| 8 | * Adrian Hunter <ext-adrian.hunter@nokia.com>: |
| 9 | * auto-placement support, read-while load support, various fixes |
| 10 | * Copyright (C) Nokia Corporation, 2007 |
| 11 | * |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 12 | * Rohit Hagargundgi <h.rohit at samsung.com>, |
| 13 | * Amul Kumar Saha <amul.saha@samsung.com>: |
| 14 | * Flex-OneNAND support |
| 15 | * Copyright (C) Samsung Electronics, 2009 |
| 16 | * |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 17 | * This program is free software; you can redistribute it and/or modify |
| 18 | * it under the terms of the GNU General Public License version 2 as |
| 19 | * published by the Free Software Foundation. |
| 20 | */ |
| 21 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame^] | 22 | #include <common.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 23 | #include <log.h> |
Ladislav Michl | 243af2f | 2016-07-12 20:28:19 +0200 | [diff] [blame] | 24 | #include <watchdog.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 25 | #include <dm/devres.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 26 | #include <linux/bitops.h> |
Mike Frysinger | 11d1a09 | 2012-04-09 13:39:55 +0000 | [diff] [blame] | 27 | #include <linux/compat.h> |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 28 | #include <linux/mtd/mtd.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 29 | #include <linux/printk.h> |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 30 | #include "linux/mtd/flashchip.h" |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 31 | #include <linux/mtd/onenand.h> |
| 32 | |
| 33 | #include <asm/io.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 34 | #include <linux/errno.h> |
Fathi BOUDRA | 95feb70 | 2008-08-06 10:06:20 +0200 | [diff] [blame] | 35 | #include <malloc.h> |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 36 | |
Kyungmin Park | 6b85c9f | 2008-03-31 10:40:36 +0900 | [diff] [blame] | 37 | /* It should access 16-bit instead of 8-bit */ |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 38 | static void *memcpy_16(void *dst, const void *src, unsigned int len) |
Kyungmin Park | 6b85c9f | 2008-03-31 10:40:36 +0900 | [diff] [blame] | 39 | { |
| 40 | void *ret = dst; |
| 41 | short *d = dst; |
| 42 | const short *s = src; |
| 43 | |
| 44 | len >>= 1; |
| 45 | while (len-- > 0) |
| 46 | *d++ = *s++; |
| 47 | return ret; |
| 48 | } |
| 49 | |
Stefan Roese | db7ce8c | 2008-12-02 11:06:47 +0100 | [diff] [blame] | 50 | /** |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 51 | * onenand_oob_128 - oob info for Flex-Onenand with 4KB page |
| 52 | * For now, we expose only 64 out of 80 ecc bytes |
| 53 | */ |
| 54 | static struct nand_ecclayout onenand_oob_128 = { |
| 55 | .eccbytes = 64, |
| 56 | .eccpos = { |
| 57 | 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, |
| 58 | 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
| 59 | 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, |
| 60 | 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, |
| 61 | 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, |
| 62 | 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, |
| 63 | 102, 103, 104, 105 |
| 64 | }, |
| 65 | .oobfree = { |
| 66 | {2, 4}, {18, 4}, {34, 4}, {50, 4}, |
| 67 | {66, 4}, {82, 4}, {98, 4}, {114, 4} |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | /** |
Stefan Roese | db7ce8c | 2008-12-02 11:06:47 +0100 | [diff] [blame] | 72 | * onenand_oob_64 - oob info for large (2KB) page |
| 73 | */ |
| 74 | static struct nand_ecclayout onenand_oob_64 = { |
| 75 | .eccbytes = 20, |
| 76 | .eccpos = { |
| 77 | 8, 9, 10, 11, 12, |
| 78 | 24, 25, 26, 27, 28, |
| 79 | 40, 41, 42, 43, 44, |
| 80 | 56, 57, 58, 59, 60, |
| 81 | }, |
| 82 | .oobfree = { |
| 83 | {2, 3}, {14, 2}, {18, 3}, {30, 2}, |
| 84 | {34, 3}, {46, 2}, {50, 3}, {62, 2} |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | /** |
| 89 | * onenand_oob_32 - oob info for middle (1KB) page |
| 90 | */ |
| 91 | static struct nand_ecclayout onenand_oob_32 = { |
| 92 | .eccbytes = 10, |
| 93 | .eccpos = { |
| 94 | 8, 9, 10, 11, 12, |
| 95 | 24, 25, 26, 27, 28, |
| 96 | }, |
| 97 | .oobfree = { {2, 3}, {14, 2}, {18, 3}, {30, 2} } |
| 98 | }; |
| 99 | |
Marek Vasut | 4112012 | 2013-12-26 01:01:24 +0100 | [diff] [blame] | 100 | /* |
| 101 | * Warning! This array is used with the memcpy_16() function, thus |
| 102 | * it must be aligned to 2 bytes. GCC can make this array unaligned |
| 103 | * as the array is made of unsigned char, which memcpy16() doesn't |
| 104 | * like and will cause unaligned access. |
| 105 | */ |
| 106 | static const unsigned char __aligned(2) ffchars[] = { |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 107 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 108 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 16 */ |
| 109 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 110 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 32 */ |
| 111 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 112 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 48 */ |
| 113 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 114 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 64 */ |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 115 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 116 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 80 */ |
| 117 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 118 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 96 */ |
| 119 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 120 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 112 */ |
| 121 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 122 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 128 */ |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | /** |
| 126 | * onenand_readw - [OneNAND Interface] Read OneNAND register |
| 127 | * @param addr address to read |
| 128 | * |
| 129 | * Read OneNAND register |
| 130 | */ |
| 131 | static unsigned short onenand_readw(void __iomem * addr) |
| 132 | { |
| 133 | return readw(addr); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * onenand_writew - [OneNAND Interface] Write OneNAND register with value |
| 138 | * @param value value to write |
| 139 | * @param addr address to write |
| 140 | * |
| 141 | * Write OneNAND register with value |
| 142 | */ |
| 143 | static void onenand_writew(unsigned short value, void __iomem * addr) |
| 144 | { |
| 145 | writew(value, addr); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * onenand_block_address - [DEFAULT] Get block address |
| 150 | * @param device the device id |
| 151 | * @param block the block |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 152 | * Return: translated block address if DDP, otherwise same |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 153 | * |
| 154 | * Setup Start Address 1 Register (F100h) |
| 155 | */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 156 | static int onenand_block_address(struct onenand_chip *this, int block) |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 157 | { |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 158 | /* Device Flash Core select, NAND Flash Block Address */ |
| 159 | if (block & this->density_mask) |
| 160 | return ONENAND_DDP_CHIP1 | (block ^ this->density_mask); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 161 | |
| 162 | return block; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * onenand_bufferram_address - [DEFAULT] Get bufferram address |
| 167 | * @param device the device id |
| 168 | * @param block the block |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 169 | * Return: set DBS value if DDP, otherwise 0 |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 170 | * |
| 171 | * Setup Start Address 2 Register (F101h) for DDP |
| 172 | */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 173 | static int onenand_bufferram_address(struct onenand_chip *this, int block) |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 174 | { |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 175 | /* Device BufferRAM Select */ |
| 176 | if (block & this->density_mask) |
| 177 | return ONENAND_DDP_CHIP1; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 178 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 179 | return ONENAND_DDP_CHIP0; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /** |
| 183 | * onenand_page_address - [DEFAULT] Get page address |
| 184 | * @param page the page address |
| 185 | * @param sector the sector address |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 186 | * Return: combined page and sector address |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 187 | * |
| 188 | * Setup Start Address 8 Register (F107h) |
| 189 | */ |
| 190 | static int onenand_page_address(int page, int sector) |
| 191 | { |
| 192 | /* Flash Page Address, Flash Sector Address */ |
| 193 | int fpa, fsa; |
| 194 | |
| 195 | fpa = page & ONENAND_FPA_MASK; |
| 196 | fsa = sector & ONENAND_FSA_MASK; |
| 197 | |
| 198 | return ((fpa << ONENAND_FPA_SHIFT) | fsa); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * onenand_buffer_address - [DEFAULT] Get buffer address |
| 203 | * @param dataram1 DataRAM index |
| 204 | * @param sectors the sector address |
| 205 | * @param count the number of sectors |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 206 | * Return: the start buffer value |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 207 | * |
| 208 | * Setup Start Buffer Register (F200h) |
| 209 | */ |
| 210 | static int onenand_buffer_address(int dataram1, int sectors, int count) |
| 211 | { |
| 212 | int bsa, bsc; |
| 213 | |
| 214 | /* BufferRAM Sector Address */ |
| 215 | bsa = sectors & ONENAND_BSA_MASK; |
| 216 | |
| 217 | if (dataram1) |
| 218 | bsa |= ONENAND_BSA_DATARAM1; /* DataRAM1 */ |
| 219 | else |
| 220 | bsa |= ONENAND_BSA_DATARAM0; /* DataRAM0 */ |
| 221 | |
| 222 | /* BufferRAM Sector Count */ |
| 223 | bsc = count & ONENAND_BSC_MASK; |
| 224 | |
| 225 | return ((bsa << ONENAND_BSA_SHIFT) | bsc); |
| 226 | } |
| 227 | |
| 228 | /** |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 229 | * flexonenand_block - Return block number for flash address |
| 230 | * @param this - OneNAND device structure |
| 231 | * @param addr - Address for which block number is needed |
| 232 | */ |
| 233 | static unsigned int flexonenand_block(struct onenand_chip *this, loff_t addr) |
| 234 | { |
| 235 | unsigned int boundary, blk, die = 0; |
| 236 | |
| 237 | if (ONENAND_IS_DDP(this) && addr >= this->diesize[0]) { |
| 238 | die = 1; |
| 239 | addr -= this->diesize[0]; |
| 240 | } |
| 241 | |
| 242 | boundary = this->boundary[die]; |
| 243 | |
| 244 | blk = addr >> (this->erase_shift - 1); |
| 245 | if (blk > boundary) |
| 246 | blk = (blk + boundary + 1) >> 1; |
| 247 | |
| 248 | blk += die ? this->density_mask : 0; |
| 249 | return blk; |
| 250 | } |
| 251 | |
| 252 | unsigned int onenand_block(struct onenand_chip *this, loff_t addr) |
| 253 | { |
| 254 | if (!FLEXONENAND(this)) |
| 255 | return addr >> this->erase_shift; |
| 256 | return flexonenand_block(this, addr); |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * flexonenand_addr - Return address of the block |
| 261 | * @this: OneNAND device structure |
| 262 | * @block: Block number on Flex-OneNAND |
| 263 | * |
| 264 | * Return address of the block |
| 265 | */ |
| 266 | static loff_t flexonenand_addr(struct onenand_chip *this, int block) |
| 267 | { |
| 268 | loff_t ofs = 0; |
| 269 | int die = 0, boundary; |
| 270 | |
| 271 | if (ONENAND_IS_DDP(this) && block >= this->density_mask) { |
| 272 | block -= this->density_mask; |
| 273 | die = 1; |
| 274 | ofs = this->diesize[0]; |
| 275 | } |
| 276 | |
| 277 | boundary = this->boundary[die]; |
| 278 | ofs += (loff_t) block << (this->erase_shift - 1); |
| 279 | if (block > (boundary + 1)) |
| 280 | ofs += (loff_t) (block - boundary - 1) |
| 281 | << (this->erase_shift - 1); |
| 282 | return ofs; |
| 283 | } |
| 284 | |
| 285 | loff_t onenand_addr(struct onenand_chip *this, int block) |
| 286 | { |
| 287 | if (!FLEXONENAND(this)) |
| 288 | return (loff_t) block << this->erase_shift; |
| 289 | return flexonenand_addr(this, block); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * flexonenand_region - [Flex-OneNAND] Return erase region of addr |
| 294 | * @param mtd MTD device structure |
| 295 | * @param addr address whose erase region needs to be identified |
| 296 | */ |
| 297 | int flexonenand_region(struct mtd_info *mtd, loff_t addr) |
| 298 | { |
| 299 | int i; |
| 300 | |
| 301 | for (i = 0; i < mtd->numeraseregions; i++) |
| 302 | if (addr < mtd->eraseregions[i].offset) |
| 303 | break; |
| 304 | return i - 1; |
| 305 | } |
| 306 | |
| 307 | /** |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 308 | * onenand_get_density - [DEFAULT] Get OneNAND density |
| 309 | * @param dev_id OneNAND device ID |
| 310 | * |
| 311 | * Get OneNAND density from device ID |
| 312 | */ |
| 313 | static inline int onenand_get_density(int dev_id) |
| 314 | { |
| 315 | int density = dev_id >> ONENAND_DEVICE_DENSITY_SHIFT; |
| 316 | return (density & ONENAND_DEVICE_DENSITY_MASK); |
| 317 | } |
| 318 | |
| 319 | /** |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 320 | * onenand_command - [DEFAULT] Send command to OneNAND device |
| 321 | * @param mtd MTD device structure |
| 322 | * @param cmd the command to be sent |
| 323 | * @param addr offset to read from or write to |
| 324 | * @param len number of bytes to read or write |
| 325 | * |
| 326 | * Send command to OneNAND device. This function is used for middle/large page |
| 327 | * devices (1KB/2KB Bytes per page) |
| 328 | */ |
| 329 | static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, |
| 330 | size_t len) |
| 331 | { |
| 332 | struct onenand_chip *this = mtd->priv; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 333 | int value; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 334 | int block, page; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 335 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 336 | /* Now we use page size operation */ |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 337 | int sectors = 0, count = 0; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 338 | |
| 339 | /* Address translation */ |
| 340 | switch (cmd) { |
| 341 | case ONENAND_CMD_UNLOCK: |
| 342 | case ONENAND_CMD_LOCK: |
| 343 | case ONENAND_CMD_LOCK_TIGHT: |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 344 | case ONENAND_CMD_UNLOCK_ALL: |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 345 | block = -1; |
| 346 | page = -1; |
| 347 | break; |
| 348 | |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 349 | case FLEXONENAND_CMD_PI_ACCESS: |
| 350 | /* addr contains die index */ |
| 351 | block = addr * this->density_mask; |
| 352 | page = -1; |
| 353 | break; |
| 354 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 355 | case ONENAND_CMD_ERASE: |
| 356 | case ONENAND_CMD_BUFFERRAM: |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 357 | block = onenand_block(this, addr); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 358 | page = -1; |
| 359 | break; |
| 360 | |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 361 | case FLEXONENAND_CMD_READ_PI: |
| 362 | cmd = ONENAND_CMD_READ; |
| 363 | block = addr * this->density_mask; |
| 364 | page = 0; |
| 365 | break; |
| 366 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 367 | default: |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 368 | block = onenand_block(this, addr); |
| 369 | page = (int) (addr |
| 370 | - onenand_addr(this, block)) >> this->page_shift; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 371 | page &= this->page_mask; |
| 372 | break; |
| 373 | } |
| 374 | |
| 375 | /* NOTE: The setting order of the registers is very important! */ |
| 376 | if (cmd == ONENAND_CMD_BUFFERRAM) { |
| 377 | /* Select DataRAM for DDP */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 378 | value = onenand_bufferram_address(this, block); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 379 | this->write_word(value, |
| 380 | this->base + ONENAND_REG_START_ADDRESS2); |
| 381 | |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 382 | if (ONENAND_IS_4KB_PAGE(this)) |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 383 | ONENAND_SET_BUFFERRAM0(this); |
| 384 | else |
| 385 | /* Switch to the next data buffer */ |
| 386 | ONENAND_SET_NEXT_BUFFERRAM(this); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | if (block != -1) { |
| 392 | /* Write 'DFS, FBA' of Flash */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 393 | value = onenand_block_address(this, block); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 394 | this->write_word(value, |
| 395 | this->base + ONENAND_REG_START_ADDRESS1); |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 396 | |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 397 | /* Select DataRAM for DDP */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 398 | value = onenand_bufferram_address(this, block); |
| 399 | this->write_word(value, |
| 400 | this->base + ONENAND_REG_START_ADDRESS2); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | if (page != -1) { |
| 404 | int dataram; |
| 405 | |
| 406 | switch (cmd) { |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 407 | case FLEXONENAND_CMD_RECOVER_LSB: |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 408 | case ONENAND_CMD_READ: |
| 409 | case ONENAND_CMD_READOOB: |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 410 | if (ONENAND_IS_4KB_PAGE(this)) |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 411 | dataram = ONENAND_SET_BUFFERRAM0(this); |
| 412 | else |
| 413 | dataram = ONENAND_SET_NEXT_BUFFERRAM(this); |
| 414 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 415 | break; |
| 416 | |
| 417 | default: |
| 418 | dataram = ONENAND_CURRENT_BUFFERRAM(this); |
| 419 | break; |
| 420 | } |
| 421 | |
| 422 | /* Write 'FPA, FSA' of Flash */ |
| 423 | value = onenand_page_address(page, sectors); |
| 424 | this->write_word(value, |
| 425 | this->base + ONENAND_REG_START_ADDRESS8); |
| 426 | |
| 427 | /* Write 'BSA, BSC' of DataRAM */ |
| 428 | value = onenand_buffer_address(dataram, sectors, count); |
| 429 | this->write_word(value, this->base + ONENAND_REG_START_BUFFER); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /* Interrupt clear */ |
| 433 | this->write_word(ONENAND_INT_CLEAR, this->base + ONENAND_REG_INTERRUPT); |
| 434 | /* Write command */ |
| 435 | this->write_word(cmd, this->base + ONENAND_REG_COMMAND); |
| 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | /** |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 441 | * onenand_read_ecc - return ecc status |
| 442 | * @param this onenand chip structure |
| 443 | */ |
| 444 | static int onenand_read_ecc(struct onenand_chip *this) |
| 445 | { |
| 446 | int ecc, i; |
| 447 | |
| 448 | if (!FLEXONENAND(this)) |
| 449 | return this->read_word(this->base + ONENAND_REG_ECC_STATUS); |
| 450 | |
| 451 | for (i = 0; i < 4; i++) { |
| 452 | ecc = this->read_word(this->base |
| 453 | + ((ONENAND_REG_ECC_STATUS + i) << 1)); |
| 454 | if (likely(!ecc)) |
| 455 | continue; |
| 456 | if (ecc & FLEXONENAND_UNCORRECTABLE_ERROR) |
| 457 | return ONENAND_ECC_2BIT_ALL; |
| 458 | } |
| 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | /** |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 464 | * onenand_wait - [DEFAULT] wait until the command is done |
| 465 | * @param mtd MTD device structure |
| 466 | * @param state state to select the max. timeout value |
| 467 | * |
| 468 | * Wait for command done. This applies to all OneNAND command |
| 469 | * Read can take up to 30us, erase up to 2ms and program up to 350us |
| 470 | * according to general OneNAND specs |
| 471 | */ |
| 472 | static int onenand_wait(struct mtd_info *mtd, int state) |
| 473 | { |
| 474 | struct onenand_chip *this = mtd->priv; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 475 | unsigned int interrupt = 0; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 476 | unsigned int ctrl; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 477 | |
Ladislav Michl | 243af2f | 2016-07-12 20:28:19 +0200 | [diff] [blame] | 478 | /* Wait at most 20ms ... */ |
| 479 | u32 timeo = (CONFIG_SYS_HZ * 20) / 1000; |
| 480 | u32 time_start = get_timer(0); |
| 481 | do { |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 482 | schedule(); |
Ladislav Michl | 243af2f | 2016-07-12 20:28:19 +0200 | [diff] [blame] | 483 | if (get_timer(time_start) > timeo) |
| 484 | return -EIO; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 485 | interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT); |
Ladislav Michl | 243af2f | 2016-07-12 20:28:19 +0200 | [diff] [blame] | 486 | } while ((interrupt & ONENAND_INT_MASTER) == 0); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 487 | |
| 488 | ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS); |
| 489 | |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 490 | if (interrupt & ONENAND_INT_READ) { |
| 491 | int ecc = onenand_read_ecc(this); |
| 492 | if (ecc & ONENAND_ECC_2BIT_ALL) { |
| 493 | printk("onenand_wait: ECC error = 0x%04x\n", ecc); |
| 494 | return -EBADMSG; |
| 495 | } |
| 496 | } |
| 497 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 498 | if (ctrl & ONENAND_CTRL_ERROR) { |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 499 | printk("onenand_wait: controller error = 0x%04x\n", ctrl); |
| 500 | if (ctrl & ONENAND_CTRL_LOCK) |
| 501 | printk("onenand_wait: it's locked error = 0x%04x\n", |
| 502 | ctrl); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 503 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 504 | return -EIO; |
| 505 | } |
| 506 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * onenand_bufferram_offset - [DEFAULT] BufferRAM offset |
| 513 | * @param mtd MTD data structure |
| 514 | * @param area BufferRAM area |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 515 | * Return: offset given area |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 516 | * |
| 517 | * Return BufferRAM offset given area |
| 518 | */ |
| 519 | static inline int onenand_bufferram_offset(struct mtd_info *mtd, int area) |
| 520 | { |
| 521 | struct onenand_chip *this = mtd->priv; |
| 522 | |
| 523 | if (ONENAND_CURRENT_BUFFERRAM(this)) { |
| 524 | if (area == ONENAND_DATARAM) |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 525 | return mtd->writesize; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 526 | if (area == ONENAND_SPARERAM) |
| 527 | return mtd->oobsize; |
| 528 | } |
| 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * onenand_read_bufferram - [OneNAND Interface] Read the bufferram area |
| 535 | * @param mtd MTD data structure |
| 536 | * @param area BufferRAM area |
| 537 | * @param buffer the databuffer to put/get data |
| 538 | * @param offset offset to read from or write to |
| 539 | * @param count number of bytes to read/write |
| 540 | * |
| 541 | * Read the BufferRAM area |
| 542 | */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 543 | static int onenand_read_bufferram(struct mtd_info *mtd, loff_t addr, int area, |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 544 | unsigned char *buffer, int offset, |
| 545 | size_t count) |
| 546 | { |
| 547 | struct onenand_chip *this = mtd->priv; |
| 548 | void __iomem *bufferram; |
| 549 | |
| 550 | bufferram = this->base + area; |
| 551 | bufferram += onenand_bufferram_offset(mtd, area); |
| 552 | |
Wolfgang Denk | d7024b6 | 2008-05-01 21:30:16 +0200 | [diff] [blame] | 553 | memcpy_16(buffer, bufferram + offset, count); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | /** |
| 559 | * onenand_sync_read_bufferram - [OneNAND Interface] Read the bufferram area with Sync. Burst mode |
| 560 | * @param mtd MTD data structure |
| 561 | * @param area BufferRAM area |
| 562 | * @param buffer the databuffer to put/get data |
| 563 | * @param offset offset to read from or write to |
| 564 | * @param count number of bytes to read/write |
| 565 | * |
| 566 | * Read the BufferRAM area with Sync. Burst Mode |
| 567 | */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 568 | static int onenand_sync_read_bufferram(struct mtd_info *mtd, loff_t addr, int area, |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 569 | unsigned char *buffer, int offset, |
| 570 | size_t count) |
| 571 | { |
| 572 | struct onenand_chip *this = mtd->priv; |
| 573 | void __iomem *bufferram; |
| 574 | |
| 575 | bufferram = this->base + area; |
| 576 | bufferram += onenand_bufferram_offset(mtd, area); |
| 577 | |
| 578 | this->mmcontrol(mtd, ONENAND_SYS_CFG1_SYNC_READ); |
| 579 | |
Wolfgang Denk | d7024b6 | 2008-05-01 21:30:16 +0200 | [diff] [blame] | 580 | memcpy_16(buffer, bufferram + offset, count); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 581 | |
| 582 | this->mmcontrol(mtd, 0); |
| 583 | |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | /** |
| 588 | * onenand_write_bufferram - [OneNAND Interface] Write the bufferram area |
| 589 | * @param mtd MTD data structure |
| 590 | * @param area BufferRAM area |
| 591 | * @param buffer the databuffer to put/get data |
| 592 | * @param offset offset to read from or write to |
| 593 | * @param count number of bytes to read/write |
| 594 | * |
| 595 | * Write the BufferRAM area |
| 596 | */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 597 | static int onenand_write_bufferram(struct mtd_info *mtd, loff_t addr, int area, |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 598 | const unsigned char *buffer, int offset, |
| 599 | size_t count) |
| 600 | { |
| 601 | struct onenand_chip *this = mtd->priv; |
| 602 | void __iomem *bufferram; |
| 603 | |
| 604 | bufferram = this->base + area; |
| 605 | bufferram += onenand_bufferram_offset(mtd, area); |
| 606 | |
Wolfgang Denk | d7024b6 | 2008-05-01 21:30:16 +0200 | [diff] [blame] | 607 | memcpy_16(bufferram + offset, buffer, count); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | /** |
Stefan Roese | 5ed79ae | 2008-11-11 10:28:53 +0100 | [diff] [blame] | 613 | * onenand_get_2x_blockpage - [GENERIC] Get blockpage at 2x program mode |
| 614 | * @param mtd MTD data structure |
| 615 | * @param addr address to check |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 616 | * Return: blockpage address |
Stefan Roese | 5ed79ae | 2008-11-11 10:28:53 +0100 | [diff] [blame] | 617 | * |
| 618 | * Get blockpage address at 2x program mode |
| 619 | */ |
| 620 | static int onenand_get_2x_blockpage(struct mtd_info *mtd, loff_t addr) |
| 621 | { |
| 622 | struct onenand_chip *this = mtd->priv; |
| 623 | int blockpage, block, page; |
| 624 | |
| 625 | /* Calculate the even block number */ |
| 626 | block = (int) (addr >> this->erase_shift) & ~1; |
| 627 | /* Is it the odd plane? */ |
| 628 | if (addr & this->writesize) |
| 629 | block++; |
| 630 | page = (int) (addr >> (this->page_shift + 1)) & this->page_mask; |
| 631 | blockpage = (block << 7) | page; |
| 632 | |
| 633 | return blockpage; |
| 634 | } |
| 635 | |
| 636 | /** |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 637 | * onenand_check_bufferram - [GENERIC] Check BufferRAM information |
| 638 | * @param mtd MTD data structure |
| 639 | * @param addr address to check |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 640 | * Return: 1 if there are valid data, otherwise 0 |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 641 | * |
| 642 | * Check bufferram if there is data we required |
| 643 | */ |
| 644 | static int onenand_check_bufferram(struct mtd_info *mtd, loff_t addr) |
| 645 | { |
| 646 | struct onenand_chip *this = mtd->priv; |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 647 | int blockpage, found = 0; |
| 648 | unsigned int i; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 649 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 650 | if (ONENAND_IS_2PLANE(this)) |
| 651 | blockpage = onenand_get_2x_blockpage(mtd, addr); |
| 652 | else |
| 653 | blockpage = (int) (addr >> this->page_shift); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 654 | |
| 655 | /* Is there valid data? */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 656 | i = ONENAND_CURRENT_BUFFERRAM(this); |
| 657 | if (this->bufferram[i].blockpage == blockpage) |
| 658 | found = 1; |
| 659 | else { |
| 660 | /* Check another BufferRAM */ |
| 661 | i = ONENAND_NEXT_BUFFERRAM(this); |
| 662 | if (this->bufferram[i].blockpage == blockpage) { |
| 663 | ONENAND_SET_NEXT_BUFFERRAM(this); |
| 664 | found = 1; |
| 665 | } |
| 666 | } |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 667 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 668 | if (found && ONENAND_IS_DDP(this)) { |
| 669 | /* Select DataRAM for DDP */ |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 670 | int block = onenand_block(this, addr); |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 671 | int value = onenand_bufferram_address(this, block); |
| 672 | this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2); |
| 673 | } |
| 674 | |
| 675 | return found; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | /** |
| 679 | * onenand_update_bufferram - [GENERIC] Update BufferRAM information |
| 680 | * @param mtd MTD data structure |
| 681 | * @param addr address to update |
| 682 | * @param valid valid flag |
| 683 | * |
| 684 | * Update BufferRAM information |
| 685 | */ |
| 686 | static int onenand_update_bufferram(struct mtd_info *mtd, loff_t addr, |
| 687 | int valid) |
| 688 | { |
| 689 | struct onenand_chip *this = mtd->priv; |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 690 | int blockpage; |
| 691 | unsigned int i; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 692 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 693 | if (ONENAND_IS_2PLANE(this)) |
| 694 | blockpage = onenand_get_2x_blockpage(mtd, addr); |
| 695 | else |
| 696 | blockpage = (int)(addr >> this->page_shift); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 697 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 698 | /* Invalidate another BufferRAM */ |
| 699 | i = ONENAND_NEXT_BUFFERRAM(this); |
| 700 | if (this->bufferram[i].blockpage == blockpage) |
| 701 | this->bufferram[i].blockpage = -1; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 702 | |
| 703 | /* Update BufferRAM */ |
| 704 | i = ONENAND_CURRENT_BUFFERRAM(this); |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 705 | if (valid) |
| 706 | this->bufferram[i].blockpage = blockpage; |
| 707 | else |
| 708 | this->bufferram[i].blockpage = -1; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 709 | |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | /** |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 714 | * onenand_invalidate_bufferram - [GENERIC] Invalidate BufferRAM information |
| 715 | * @param mtd MTD data structure |
| 716 | * @param addr start address to invalidate |
| 717 | * @param len length to invalidate |
| 718 | * |
| 719 | * Invalidate BufferRAM information |
| 720 | */ |
| 721 | static void onenand_invalidate_bufferram(struct mtd_info *mtd, loff_t addr, |
Wolfgang Denk | 74e0dde | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 722 | unsigned int len) |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 723 | { |
| 724 | struct onenand_chip *this = mtd->priv; |
| 725 | int i; |
| 726 | loff_t end_addr = addr + len; |
| 727 | |
| 728 | /* Invalidate BufferRAM */ |
| 729 | for (i = 0; i < MAX_BUFFERRAM; i++) { |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 730 | loff_t buf_addr = this->bufferram[i].blockpage << this->page_shift; |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 731 | |
| 732 | if (buf_addr >= addr && buf_addr < end_addr) |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 733 | this->bufferram[i].blockpage = -1; |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | |
| 737 | /** |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 738 | * onenand_get_device - [GENERIC] Get chip for selected access |
| 739 | * @param mtd MTD device structure |
| 740 | * @param new_state the state which is requested |
| 741 | * |
| 742 | * Get the device and lock it for exclusive access |
| 743 | */ |
| 744 | static void onenand_get_device(struct mtd_info *mtd, int new_state) |
| 745 | { |
| 746 | /* Do nothing */ |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * onenand_release_device - [GENERIC] release chip |
| 751 | * @param mtd MTD device structure |
| 752 | * |
| 753 | * Deselect, release chip lock and wake up anyone waiting on the device |
| 754 | */ |
| 755 | static void onenand_release_device(struct mtd_info *mtd) |
| 756 | { |
| 757 | /* Do nothing */ |
| 758 | } |
| 759 | |
| 760 | /** |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 761 | * onenand_transfer_auto_oob - [INTERN] oob auto-placement transfer |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 762 | * @param mtd MTD device structure |
| 763 | * @param buf destination address |
| 764 | * @param column oob offset to read from |
| 765 | * @param thislen oob length to read |
| 766 | */ |
| 767 | static int onenand_transfer_auto_oob(struct mtd_info *mtd, uint8_t *buf, |
| 768 | int column, int thislen) |
| 769 | { |
| 770 | struct onenand_chip *this = mtd->priv; |
| 771 | struct nand_oobfree *free; |
| 772 | int readcol = column; |
| 773 | int readend = column + thislen; |
| 774 | int lastgap = 0; |
| 775 | unsigned int i; |
| 776 | uint8_t *oob_buf = this->oob_buf; |
| 777 | |
| 778 | free = this->ecclayout->oobfree; |
Prabhakar Kushwaha | 4d2ba17 | 2013-10-04 13:47:58 +0530 | [diff] [blame] | 779 | for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES_LARGE && free->length; |
| 780 | i++, free++) { |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 781 | if (readcol >= lastgap) |
| 782 | readcol += free->offset - lastgap; |
| 783 | if (readend >= lastgap) |
| 784 | readend += free->offset - lastgap; |
| 785 | lastgap = free->offset + free->length; |
| 786 | } |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 787 | this->read_bufferram(mtd, 0, ONENAND_SPARERAM, oob_buf, 0, mtd->oobsize); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 788 | free = this->ecclayout->oobfree; |
Prabhakar Kushwaha | 4d2ba17 | 2013-10-04 13:47:58 +0530 | [diff] [blame] | 789 | for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES_LARGE && free->length; |
| 790 | i++, free++) { |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 791 | int free_end = free->offset + free->length; |
| 792 | if (free->offset < readend && free_end > readcol) { |
| 793 | int st = max_t(int,free->offset,readcol); |
| 794 | int ed = min_t(int,free_end,readend); |
| 795 | int n = ed - st; |
| 796 | memcpy(buf, oob_buf + st, n); |
| 797 | buf += n; |
| 798 | } else if (column == 0) |
| 799 | break; |
| 800 | } |
| 801 | return 0; |
| 802 | } |
| 803 | |
| 804 | /** |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 805 | * onenand_recover_lsb - [Flex-OneNAND] Recover LSB page data |
| 806 | * @param mtd MTD device structure |
| 807 | * @param addr address to recover |
| 808 | * @param status return value from onenand_wait |
| 809 | * |
| 810 | * MLC NAND Flash cell has paired pages - LSB page and MSB page. LSB page has |
| 811 | * lower page address and MSB page has higher page address in paired pages. |
| 812 | * If power off occurs during MSB page program, the paired LSB page data can |
| 813 | * become corrupt. LSB page recovery read is a way to read LSB page though page |
| 814 | * data are corrupted. When uncorrectable error occurs as a result of LSB page |
| 815 | * read after power up, issue LSB page recovery read. |
| 816 | */ |
| 817 | static int onenand_recover_lsb(struct mtd_info *mtd, loff_t addr, int status) |
| 818 | { |
| 819 | struct onenand_chip *this = mtd->priv; |
| 820 | int i; |
| 821 | |
| 822 | /* Recovery is only for Flex-OneNAND */ |
| 823 | if (!FLEXONENAND(this)) |
| 824 | return status; |
| 825 | |
| 826 | /* check if we failed due to uncorrectable error */ |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 827 | if (!mtd_is_eccerr(status) && status != ONENAND_BBT_READ_ECC_ERROR) |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 828 | return status; |
| 829 | |
| 830 | /* check if address lies in MLC region */ |
| 831 | i = flexonenand_region(mtd, addr); |
| 832 | if (mtd->eraseregions[i].erasesize < (1 << this->erase_shift)) |
| 833 | return status; |
| 834 | |
| 835 | printk("onenand_recover_lsb:" |
| 836 | "Attempting to recover from uncorrectable read\n"); |
| 837 | |
| 838 | /* Issue the LSB page recovery command */ |
| 839 | this->command(mtd, FLEXONENAND_CMD_RECOVER_LSB, addr, this->writesize); |
| 840 | return this->wait(mtd, FL_READING); |
| 841 | } |
| 842 | |
| 843 | /** |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 844 | * onenand_read_ops_nolock - [OneNAND Interface] OneNAND read main and/or out-of-band |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 845 | * @param mtd MTD device structure |
| 846 | * @param from offset to read from |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 847 | * @param ops oob operation description structure |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 848 | * |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 849 | * OneNAND read main and/or out-of-band data |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 850 | */ |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 851 | static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from, |
| 852 | struct mtd_oob_ops *ops) |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 853 | { |
| 854 | struct onenand_chip *this = mtd->priv; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 855 | struct mtd_ecc_stats stats; |
| 856 | size_t len = ops->len; |
| 857 | size_t ooblen = ops->ooblen; |
| 858 | u_char *buf = ops->datbuf; |
| 859 | u_char *oobbuf = ops->oobbuf; |
| 860 | int read = 0, column, thislen; |
| 861 | int oobread = 0, oobcolumn, thisooblen, oobsize; |
| 862 | int ret = 0, boundary = 0; |
| 863 | int writesize = this->writesize; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 864 | |
Masahiro Yamada | f8a5d51 | 2017-10-18 00:10:48 +0900 | [diff] [blame] | 865 | pr_debug("onenand_read_ops_nolock: from = 0x%08x, len = %i\n", |
| 866 | (unsigned int) from, (int) len); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 867 | |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 868 | if (ops->mode == MTD_OPS_AUTO_OOB) |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 869 | oobsize = this->ecclayout->oobavail; |
| 870 | else |
| 871 | oobsize = mtd->oobsize; |
| 872 | |
| 873 | oobcolumn = from & (mtd->oobsize - 1); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 874 | |
| 875 | /* Do not allow reads past end of device */ |
| 876 | if ((from + len) > mtd->size) { |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 877 | printk(KERN_ERR "onenand_read_ops_nolock: Attempt read beyond end of device\n"); |
| 878 | ops->retlen = 0; |
| 879 | ops->oobretlen = 0; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 880 | return -EINVAL; |
| 881 | } |
| 882 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 883 | stats = mtd->ecc_stats; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 884 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 885 | /* Read-while-load method */ |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 886 | /* Note: We can't use this feature in MLC */ |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 887 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 888 | /* Do first load to bufferRAM */ |
| 889 | if (read < len) { |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 890 | if (!onenand_check_bufferram(mtd, from)) { |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 891 | this->main_buf = buf; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 892 | this->command(mtd, ONENAND_CMD_READ, from, writesize); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 893 | ret = this->wait(mtd, FL_READING); |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 894 | if (unlikely(ret)) |
| 895 | ret = onenand_recover_lsb(mtd, from, ret); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 896 | onenand_update_bufferram(mtd, from, !ret); |
| 897 | if (ret == -EBADMSG) |
| 898 | ret = 0; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 899 | } |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 900 | } |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 901 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 902 | thislen = min_t(int, writesize, len - read); |
| 903 | column = from & (writesize - 1); |
| 904 | if (column + thislen > writesize) |
| 905 | thislen = writesize - column; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 906 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 907 | while (!ret) { |
| 908 | /* If there is more to load then start next load */ |
| 909 | from += thislen; |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 910 | if (!ONENAND_IS_4KB_PAGE(this) && read + thislen < len) { |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 911 | this->main_buf = buf + thislen; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 912 | this->command(mtd, ONENAND_CMD_READ, from, writesize); |
| 913 | /* |
| 914 | * Chip boundary handling in DDP |
| 915 | * Now we issued chip 1 read and pointed chip 1 |
| 916 | * bufferam so we have to point chip 0 bufferam. |
| 917 | */ |
| 918 | if (ONENAND_IS_DDP(this) && |
| 919 | unlikely(from == (this->chipsize >> 1))) { |
| 920 | this->write_word(ONENAND_DDP_CHIP0, this->base + ONENAND_REG_START_ADDRESS2); |
| 921 | boundary = 1; |
| 922 | } else |
| 923 | boundary = 0; |
| 924 | ONENAND_SET_PREV_BUFFERRAM(this); |
| 925 | } |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 926 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 927 | /* While load is going, read from last bufferRAM */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 928 | this->read_bufferram(mtd, from - thislen, ONENAND_DATARAM, buf, column, thislen); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 929 | |
| 930 | /* Read oob area if needed */ |
| 931 | if (oobbuf) { |
| 932 | thisooblen = oobsize - oobcolumn; |
| 933 | thisooblen = min_t(int, thisooblen, ooblen - oobread); |
| 934 | |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 935 | if (ops->mode == MTD_OPS_AUTO_OOB) |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 936 | onenand_transfer_auto_oob(mtd, oobbuf, oobcolumn, thisooblen); |
| 937 | else |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 938 | this->read_bufferram(mtd, 0, ONENAND_SPARERAM, oobbuf, oobcolumn, thisooblen); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 939 | oobread += thisooblen; |
| 940 | oobbuf += thisooblen; |
| 941 | oobcolumn = 0; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 942 | } |
| 943 | |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 944 | if (ONENAND_IS_4KB_PAGE(this) && (read + thislen < len)) { |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 945 | this->command(mtd, ONENAND_CMD_READ, from, writesize); |
| 946 | ret = this->wait(mtd, FL_READING); |
| 947 | if (unlikely(ret)) |
| 948 | ret = onenand_recover_lsb(mtd, from, ret); |
| 949 | onenand_update_bufferram(mtd, from, !ret); |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 950 | if (mtd_is_eccerr(ret)) |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 951 | ret = 0; |
| 952 | } |
| 953 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 954 | /* See if we are done */ |
| 955 | read += thislen; |
| 956 | if (read == len) |
| 957 | break; |
| 958 | /* Set up for next read from bufferRAM */ |
| 959 | if (unlikely(boundary)) |
| 960 | this->write_word(ONENAND_DDP_CHIP1, this->base + ONENAND_REG_START_ADDRESS2); |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 961 | if (!ONENAND_IS_4KB_PAGE(this)) |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 962 | ONENAND_SET_NEXT_BUFFERRAM(this); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 963 | buf += thislen; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 964 | thislen = min_t(int, writesize, len - read); |
| 965 | column = 0; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 966 | |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 967 | if (!ONENAND_IS_4KB_PAGE(this)) { |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 968 | /* Now wait for load */ |
| 969 | ret = this->wait(mtd, FL_READING); |
| 970 | onenand_update_bufferram(mtd, from, !ret); |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 971 | if (mtd_is_eccerr(ret)) |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 972 | ret = 0; |
| 973 | } |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 974 | } |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 975 | |
| 976 | /* |
| 977 | * Return success, if no ECC failures, else -EBADMSG |
| 978 | * fs driver will take care of that, because |
| 979 | * retlen == desired len and result == -EBADMSG |
| 980 | */ |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 981 | ops->retlen = read; |
| 982 | ops->oobretlen = oobread; |
| 983 | |
| 984 | if (ret) |
| 985 | return ret; |
| 986 | |
| 987 | if (mtd->ecc_stats.failed - stats.failed) |
| 988 | return -EBADMSG; |
| 989 | |
Paul Burton | 700a76c | 2013-09-04 15:16:56 +0100 | [diff] [blame] | 990 | /* return max bitflips per ecc step; ONENANDs correct 1 bit only */ |
| 991 | return mtd->ecc_stats.corrected != stats.corrected ? 1 : 0; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | /** |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 995 | * onenand_read_oob_nolock - [MTD Interface] OneNAND read out-of-band |
| 996 | * @param mtd MTD device structure |
| 997 | * @param from offset to read from |
| 998 | * @param ops oob operation description structure |
| 999 | * |
| 1000 | * OneNAND read out-of-band data from the spare area |
| 1001 | */ |
| 1002 | static int onenand_read_oob_nolock(struct mtd_info *mtd, loff_t from, |
| 1003 | struct mtd_oob_ops *ops) |
| 1004 | { |
| 1005 | struct onenand_chip *this = mtd->priv; |
| 1006 | struct mtd_ecc_stats stats; |
| 1007 | int read = 0, thislen, column, oobsize; |
| 1008 | size_t len = ops->ooblen; |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1009 | unsigned int mode = ops->mode; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1010 | u_char *buf = ops->oobbuf; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1011 | int ret = 0, readcmd; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1012 | |
| 1013 | from += ops->ooboffs; |
| 1014 | |
Masahiro Yamada | f8a5d51 | 2017-10-18 00:10:48 +0900 | [diff] [blame] | 1015 | pr_debug("onenand_read_oob_nolock: from = 0x%08x, len = %i\n", |
| 1016 | (unsigned int) from, (int) len); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1017 | |
| 1018 | /* Initialize return length value */ |
| 1019 | ops->oobretlen = 0; |
| 1020 | |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1021 | if (mode == MTD_OPS_AUTO_OOB) |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1022 | oobsize = this->ecclayout->oobavail; |
| 1023 | else |
| 1024 | oobsize = mtd->oobsize; |
| 1025 | |
| 1026 | column = from & (mtd->oobsize - 1); |
| 1027 | |
| 1028 | if (unlikely(column >= oobsize)) { |
| 1029 | printk(KERN_ERR "onenand_read_oob_nolock: Attempted to start read outside oob\n"); |
| 1030 | return -EINVAL; |
| 1031 | } |
| 1032 | |
| 1033 | /* Do not allow reads past end of device */ |
| 1034 | if (unlikely(from >= mtd->size || |
| 1035 | column + len > ((mtd->size >> this->page_shift) - |
| 1036 | (from >> this->page_shift)) * oobsize)) { |
| 1037 | printk(KERN_ERR "onenand_read_oob_nolock: Attempted to read beyond end of device\n"); |
| 1038 | return -EINVAL; |
| 1039 | } |
| 1040 | |
| 1041 | stats = mtd->ecc_stats; |
| 1042 | |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 1043 | readcmd = ONENAND_IS_4KB_PAGE(this) ? |
| 1044 | ONENAND_CMD_READ : ONENAND_CMD_READOOB; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1045 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1046 | while (read < len) { |
| 1047 | thislen = oobsize - column; |
| 1048 | thislen = min_t(int, thislen, len); |
| 1049 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1050 | this->spare_buf = buf; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1051 | this->command(mtd, readcmd, from, mtd->oobsize); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1052 | |
| 1053 | onenand_update_bufferram(mtd, from, 0); |
| 1054 | |
| 1055 | ret = this->wait(mtd, FL_READING); |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1056 | if (unlikely(ret)) |
| 1057 | ret = onenand_recover_lsb(mtd, from, ret); |
| 1058 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1059 | if (ret && ret != -EBADMSG) { |
| 1060 | printk(KERN_ERR "onenand_read_oob_nolock: read failed = 0x%x\n", ret); |
| 1061 | break; |
| 1062 | } |
| 1063 | |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1064 | if (mode == MTD_OPS_AUTO_OOB) |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1065 | onenand_transfer_auto_oob(mtd, buf, column, thislen); |
| 1066 | else |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1067 | this->read_bufferram(mtd, 0, ONENAND_SPARERAM, buf, column, thislen); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1068 | |
| 1069 | read += thislen; |
| 1070 | |
| 1071 | if (read == len) |
| 1072 | break; |
| 1073 | |
| 1074 | buf += thislen; |
| 1075 | |
| 1076 | /* Read more? */ |
| 1077 | if (read < len) { |
| 1078 | /* Page size */ |
| 1079 | from += mtd->writesize; |
| 1080 | column = 0; |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | ops->oobretlen = read; |
| 1085 | |
| 1086 | if (ret) |
| 1087 | return ret; |
| 1088 | |
| 1089 | if (mtd->ecc_stats.failed - stats.failed) |
| 1090 | return -EBADMSG; |
| 1091 | |
| 1092 | return 0; |
| 1093 | } |
| 1094 | |
| 1095 | /** |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1096 | * onenand_read - [MTD Interface] MTD compability function for onenand_read_ecc |
| 1097 | * @param mtd MTD device structure |
| 1098 | * @param from offset to read from |
| 1099 | * @param len number of bytes to read |
| 1100 | * @param retlen pointer to variable to store the number of read bytes |
| 1101 | * @param buf the databuffer to put data |
| 1102 | * |
| 1103 | * This function simply calls onenand_read_ecc with oob buffer and oobsel = NULL |
| 1104 | */ |
| 1105 | int onenand_read(struct mtd_info *mtd, loff_t from, size_t len, |
| 1106 | size_t * retlen, u_char * buf) |
| 1107 | { |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1108 | struct mtd_oob_ops ops = { |
| 1109 | .len = len, |
| 1110 | .ooblen = 0, |
| 1111 | .datbuf = buf, |
| 1112 | .oobbuf = NULL, |
| 1113 | }; |
| 1114 | int ret; |
| 1115 | |
| 1116 | onenand_get_device(mtd, FL_READING); |
| 1117 | ret = onenand_read_ops_nolock(mtd, from, &ops); |
| 1118 | onenand_release_device(mtd); |
| 1119 | |
| 1120 | *retlen = ops.retlen; |
| 1121 | return ret; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | /** |
| 1125 | * onenand_read_oob - [MTD Interface] OneNAND read out-of-band |
| 1126 | * @param mtd MTD device structure |
| 1127 | * @param from offset to read from |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1128 | * @param ops oob operations description structure |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1129 | * |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1130 | * OneNAND main and/or out-of-band |
| 1131 | */ |
| 1132 | int onenand_read_oob(struct mtd_info *mtd, loff_t from, |
| 1133 | struct mtd_oob_ops *ops) |
| 1134 | { |
| 1135 | int ret; |
| 1136 | |
| 1137 | switch (ops->mode) { |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1138 | case MTD_OPS_PLACE_OOB: |
| 1139 | case MTD_OPS_AUTO_OOB: |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1140 | break; |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1141 | case MTD_OPS_RAW: |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1142 | /* Not implemented yet */ |
| 1143 | default: |
| 1144 | return -EINVAL; |
| 1145 | } |
| 1146 | |
| 1147 | onenand_get_device(mtd, FL_READING); |
| 1148 | if (ops->datbuf) |
| 1149 | ret = onenand_read_ops_nolock(mtd, from, ops); |
| 1150 | else |
| 1151 | ret = onenand_read_oob_nolock(mtd, from, ops); |
| 1152 | onenand_release_device(mtd); |
| 1153 | |
| 1154 | return ret; |
| 1155 | } |
| 1156 | |
| 1157 | /** |
| 1158 | * onenand_bbt_wait - [DEFAULT] wait until the command is done |
| 1159 | * @param mtd MTD device structure |
| 1160 | * @param state state to select the max. timeout value |
| 1161 | * |
| 1162 | * Wait for command done. |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1163 | */ |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1164 | static int onenand_bbt_wait(struct mtd_info *mtd, int state) |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1165 | { |
| 1166 | struct onenand_chip *this = mtd->priv; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1167 | unsigned int interrupt; |
| 1168 | unsigned int ctrl; |
| 1169 | |
Ladislav Michl | 243af2f | 2016-07-12 20:28:19 +0200 | [diff] [blame] | 1170 | /* Wait at most 20ms ... */ |
| 1171 | u32 timeo = (CONFIG_SYS_HZ * 20) / 1000; |
| 1172 | u32 time_start = get_timer(0); |
| 1173 | do { |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 1174 | schedule(); |
Ladislav Michl | 243af2f | 2016-07-12 20:28:19 +0200 | [diff] [blame] | 1175 | if (get_timer(time_start) > timeo) |
| 1176 | return ONENAND_BBT_READ_FATAL_ERROR; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1177 | interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT); |
Ladislav Michl | 243af2f | 2016-07-12 20:28:19 +0200 | [diff] [blame] | 1178 | } while ((interrupt & ONENAND_INT_MASTER) == 0); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1179 | |
| 1180 | /* To get correct interrupt status in timeout case */ |
| 1181 | interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT); |
| 1182 | ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS); |
| 1183 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1184 | if (interrupt & ONENAND_INT_READ) { |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1185 | int ecc = onenand_read_ecc(this); |
| 1186 | if (ecc & ONENAND_ECC_2BIT_ALL) { |
| 1187 | printk(KERN_INFO "onenand_bbt_wait: ecc error = 0x%04x" |
| 1188 | ", controller = 0x%04x\n", ecc, ctrl); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1189 | return ONENAND_BBT_READ_ERROR; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1190 | } |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1191 | } else { |
| 1192 | printk(KERN_ERR "onenand_bbt_wait: read timeout!" |
| 1193 | "ctrl=0x%04x intr=0x%04x\n", ctrl, interrupt); |
| 1194 | return ONENAND_BBT_READ_FATAL_ERROR; |
| 1195 | } |
| 1196 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1197 | /* Initial bad block case: 0x2400 or 0x0400 */ |
| 1198 | if (ctrl & ONENAND_CTRL_ERROR) { |
| 1199 | printk(KERN_DEBUG "onenand_bbt_wait: controller error = 0x%04x\n", ctrl); |
| 1200 | return ONENAND_BBT_READ_ERROR; |
| 1201 | } |
| 1202 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1203 | return 0; |
| 1204 | } |
| 1205 | |
| 1206 | /** |
| 1207 | * onenand_bbt_read_oob - [MTD Interface] OneNAND read out-of-band for bbt scan |
| 1208 | * @param mtd MTD device structure |
| 1209 | * @param from offset to read from |
| 1210 | * @param ops oob operation description structure |
| 1211 | * |
| 1212 | * OneNAND read out-of-band data from the spare area for bbt scan |
| 1213 | */ |
| 1214 | int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from, |
| 1215 | struct mtd_oob_ops *ops) |
| 1216 | { |
| 1217 | struct onenand_chip *this = mtd->priv; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1218 | int read = 0, thislen, column; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1219 | int ret = 0, readcmd; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1220 | size_t len = ops->ooblen; |
| 1221 | u_char *buf = ops->oobbuf; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1222 | |
Masahiro Yamada | f8a5d51 | 2017-10-18 00:10:48 +0900 | [diff] [blame] | 1223 | pr_debug("onenand_bbt_read_oob: from = 0x%08x, len = %zi\n", |
| 1224 | (unsigned int) from, len); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1225 | |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 1226 | readcmd = ONENAND_IS_4KB_PAGE(this) ? |
| 1227 | ONENAND_CMD_READ : ONENAND_CMD_READOOB; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1228 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1229 | /* Initialize return value */ |
| 1230 | ops->oobretlen = 0; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1231 | |
| 1232 | /* Do not allow reads past end of device */ |
| 1233 | if (unlikely((from + len) > mtd->size)) { |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1234 | printk(KERN_ERR "onenand_bbt_read_oob: Attempt read beyond end of device\n"); |
| 1235 | return ONENAND_BBT_READ_FATAL_ERROR; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | /* Grab the lock and see if the device is available */ |
| 1239 | onenand_get_device(mtd, FL_READING); |
| 1240 | |
| 1241 | column = from & (mtd->oobsize - 1); |
| 1242 | |
| 1243 | while (read < len) { |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1244 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1245 | thislen = mtd->oobsize - column; |
| 1246 | thislen = min_t(int, thislen, len); |
| 1247 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1248 | this->spare_buf = buf; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1249 | this->command(mtd, readcmd, from, mtd->oobsize); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1250 | |
| 1251 | onenand_update_bufferram(mtd, from, 0); |
| 1252 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1253 | ret = this->bbt_wait(mtd, FL_READING); |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1254 | if (unlikely(ret)) |
| 1255 | ret = onenand_recover_lsb(mtd, from, ret); |
| 1256 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1257 | if (ret) |
| 1258 | break; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1259 | |
Kyungmin Park | fee18b9 | 2009-07-21 11:58:04 +0900 | [diff] [blame] | 1260 | this->read_bufferram(mtd, 0, ONENAND_SPARERAM, buf, column, thislen); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1261 | read += thislen; |
| 1262 | if (read == len) |
| 1263 | break; |
| 1264 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1265 | buf += thislen; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1266 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1267 | /* Read more? */ |
| 1268 | if (read < len) { |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1269 | /* Update Page size */ |
| 1270 | from += this->writesize; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1271 | column = 0; |
| 1272 | } |
| 1273 | } |
| 1274 | |
| 1275 | /* Deselect and wake up anyone waiting on the device */ |
| 1276 | onenand_release_device(mtd); |
| 1277 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1278 | ops->oobretlen = read; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1279 | return ret; |
| 1280 | } |
| 1281 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1282 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1283 | #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE |
| 1284 | /** |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1285 | * onenand_verify_oob - [GENERIC] verify the oob contents after a write |
| 1286 | * @param mtd MTD device structure |
| 1287 | * @param buf the databuffer to verify |
| 1288 | * @param to offset to read from |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1289 | */ |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1290 | static int onenand_verify_oob(struct mtd_info *mtd, const u_char *buf, loff_t to) |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1291 | { |
| 1292 | struct onenand_chip *this = mtd->priv; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1293 | u_char *oob_buf = this->oob_buf; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1294 | int status, i, readcmd; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1295 | |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 1296 | readcmd = ONENAND_IS_4KB_PAGE(this) ? |
| 1297 | ONENAND_CMD_READ : ONENAND_CMD_READOOB; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1298 | |
| 1299 | this->command(mtd, readcmd, to, mtd->oobsize); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1300 | onenand_update_bufferram(mtd, to, 0); |
| 1301 | status = this->wait(mtd, FL_READING); |
| 1302 | if (status) |
| 1303 | return status; |
| 1304 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1305 | this->read_bufferram(mtd, 0, ONENAND_SPARERAM, oob_buf, 0, mtd->oobsize); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1306 | for (i = 0; i < mtd->oobsize; i++) |
| 1307 | if (buf[i] != 0xFF && buf[i] != oob_buf[i]) |
| 1308 | return -EBADMSG; |
| 1309 | |
| 1310 | return 0; |
| 1311 | } |
| 1312 | |
| 1313 | /** |
| 1314 | * onenand_verify - [GENERIC] verify the chip contents after a write |
| 1315 | * @param mtd MTD device structure |
| 1316 | * @param buf the databuffer to verify |
| 1317 | * @param addr offset to read from |
| 1318 | * @param len number of bytes to read and compare |
| 1319 | */ |
| 1320 | static int onenand_verify(struct mtd_info *mtd, const u_char *buf, loff_t addr, size_t len) |
| 1321 | { |
| 1322 | struct onenand_chip *this = mtd->priv; |
| 1323 | void __iomem *dataram; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1324 | int ret = 0; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1325 | int thislen, column; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1326 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1327 | while (len != 0) { |
| 1328 | thislen = min_t(int, this->writesize, len); |
| 1329 | column = addr & (this->writesize - 1); |
| 1330 | if (column + thislen > this->writesize) |
| 1331 | thislen = this->writesize - column; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1332 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1333 | this->command(mtd, ONENAND_CMD_READ, addr, this->writesize); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1334 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1335 | onenand_update_bufferram(mtd, addr, 0); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1336 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1337 | ret = this->wait(mtd, FL_READING); |
| 1338 | if (ret) |
| 1339 | return ret; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1340 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1341 | onenand_update_bufferram(mtd, addr, 1); |
| 1342 | |
| 1343 | dataram = this->base + ONENAND_DATARAM; |
| 1344 | dataram += onenand_bufferram_offset(mtd, ONENAND_DATARAM); |
| 1345 | |
| 1346 | if (memcmp(buf, dataram + column, thislen)) |
| 1347 | return -EBADMSG; |
| 1348 | |
| 1349 | len -= thislen; |
| 1350 | buf += thislen; |
| 1351 | addr += thislen; |
| 1352 | } |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1353 | |
| 1354 | return 0; |
| 1355 | } |
| 1356 | #else |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1357 | #define onenand_verify(...) (0) |
| 1358 | #define onenand_verify_oob(...) (0) |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1359 | #endif |
| 1360 | |
Stefan Roese | db7ce8c | 2008-12-02 11:06:47 +0100 | [diff] [blame] | 1361 | #define NOTALIGNED(x) ((x & (this->subpagesize - 1)) != 0) |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1362 | |
| 1363 | /** |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1364 | * onenand_fill_auto_oob - [INTERN] oob auto-placement transfer |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1365 | * @param mtd MTD device structure |
| 1366 | * @param oob_buf oob buffer |
| 1367 | * @param buf source address |
| 1368 | * @param column oob offset to write to |
| 1369 | * @param thislen oob length to write |
| 1370 | */ |
| 1371 | static int onenand_fill_auto_oob(struct mtd_info *mtd, u_char *oob_buf, |
| 1372 | const u_char *buf, int column, int thislen) |
| 1373 | { |
| 1374 | struct onenand_chip *this = mtd->priv; |
| 1375 | struct nand_oobfree *free; |
| 1376 | int writecol = column; |
| 1377 | int writeend = column + thislen; |
| 1378 | int lastgap = 0; |
| 1379 | unsigned int i; |
| 1380 | |
| 1381 | free = this->ecclayout->oobfree; |
Prabhakar Kushwaha | 4d2ba17 | 2013-10-04 13:47:58 +0530 | [diff] [blame] | 1382 | for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES_LARGE && free->length; |
| 1383 | i++, free++) { |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1384 | if (writecol >= lastgap) |
| 1385 | writecol += free->offset - lastgap; |
| 1386 | if (writeend >= lastgap) |
| 1387 | writeend += free->offset - lastgap; |
| 1388 | lastgap = free->offset + free->length; |
| 1389 | } |
| 1390 | free = this->ecclayout->oobfree; |
Prabhakar Kushwaha | 4d2ba17 | 2013-10-04 13:47:58 +0530 | [diff] [blame] | 1391 | for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES_LARGE && free->length; |
| 1392 | i++, free++) { |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1393 | int free_end = free->offset + free->length; |
| 1394 | if (free->offset < writeend && free_end > writecol) { |
| 1395 | int st = max_t(int,free->offset,writecol); |
| 1396 | int ed = min_t(int,free_end,writeend); |
| 1397 | int n = ed - st; |
| 1398 | memcpy(oob_buf + st, buf, n); |
| 1399 | buf += n; |
| 1400 | } else if (column == 0) |
| 1401 | break; |
| 1402 | } |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
| 1406 | /** |
| 1407 | * onenand_write_ops_nolock - [OneNAND Interface] write main and/or out-of-band |
| 1408 | * @param mtd MTD device structure |
| 1409 | * @param to offset to write to |
| 1410 | * @param ops oob operation description structure |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1411 | * |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1412 | * Write main and/or oob with ECC |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1413 | */ |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1414 | static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to, |
| 1415 | struct mtd_oob_ops *ops) |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1416 | { |
| 1417 | struct onenand_chip *this = mtd->priv; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1418 | int written = 0, column, thislen, subpage; |
| 1419 | int oobwritten = 0, oobcolumn, thisooblen, oobsize; |
| 1420 | size_t len = ops->len; |
| 1421 | size_t ooblen = ops->ooblen; |
| 1422 | const u_char *buf = ops->datbuf; |
| 1423 | const u_char *oob = ops->oobbuf; |
| 1424 | u_char *oobbuf; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1425 | int ret = 0; |
| 1426 | |
Masahiro Yamada | f8a5d51 | 2017-10-18 00:10:48 +0900 | [diff] [blame] | 1427 | pr_debug("onenand_write_ops_nolock: to = 0x%08x, len = %i\n", |
| 1428 | (unsigned int) to, (int) len); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1429 | |
| 1430 | /* Initialize retlen, in case of early exit */ |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1431 | ops->retlen = 0; |
| 1432 | ops->oobretlen = 0; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1433 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1434 | /* Reject writes, which are not page aligned */ |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1435 | if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) { |
| 1436 | printk(KERN_ERR "onenand_write_ops_nolock: Attempt to write not page aligned data\n"); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1437 | return -EINVAL; |
| 1438 | } |
| 1439 | |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1440 | if (ops->mode == MTD_OPS_AUTO_OOB) |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1441 | oobsize = this->ecclayout->oobavail; |
| 1442 | else |
| 1443 | oobsize = mtd->oobsize; |
| 1444 | |
| 1445 | oobcolumn = to & (mtd->oobsize - 1); |
| 1446 | |
| 1447 | column = to & (mtd->writesize - 1); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1448 | |
| 1449 | /* Loop until all data write */ |
| 1450 | while (written < len) { |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1451 | u_char *wbuf = (u_char *) buf; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1452 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1453 | thislen = min_t(int, mtd->writesize - column, len - written); |
| 1454 | thisooblen = min_t(int, oobsize - oobcolumn, ooblen - oobwritten); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1455 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1456 | this->command(mtd, ONENAND_CMD_BUFFERRAM, to, thislen); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1457 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1458 | /* Partial page write */ |
| 1459 | subpage = thislen < mtd->writesize; |
| 1460 | if (subpage) { |
| 1461 | memset(this->page_buf, 0xff, mtd->writesize); |
| 1462 | memcpy(this->page_buf + column, buf, thislen); |
| 1463 | wbuf = this->page_buf; |
| 1464 | } |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1465 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1466 | this->write_bufferram(mtd, to, ONENAND_DATARAM, wbuf, 0, mtd->writesize); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1467 | |
| 1468 | if (oob) { |
| 1469 | oobbuf = this->oob_buf; |
| 1470 | |
| 1471 | /* We send data to spare ram with oobsize |
| 1472 | * * to prevent byte access */ |
| 1473 | memset(oobbuf, 0xff, mtd->oobsize); |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1474 | if (ops->mode == MTD_OPS_AUTO_OOB) |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1475 | onenand_fill_auto_oob(mtd, oobbuf, oob, oobcolumn, thisooblen); |
| 1476 | else |
| 1477 | memcpy(oobbuf + oobcolumn, oob, thisooblen); |
| 1478 | |
| 1479 | oobwritten += thisooblen; |
| 1480 | oob += thisooblen; |
| 1481 | oobcolumn = 0; |
| 1482 | } else |
| 1483 | oobbuf = (u_char *) ffchars; |
| 1484 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1485 | this->write_bufferram(mtd, 0, ONENAND_SPARERAM, oobbuf, 0, mtd->oobsize); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1486 | |
| 1487 | this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1488 | |
| 1489 | ret = this->wait(mtd, FL_WRITING); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1490 | |
| 1491 | /* In partial page write we don't update bufferram */ |
| 1492 | onenand_update_bufferram(mtd, to, !ret && !subpage); |
| 1493 | if (ONENAND_IS_2PLANE(this)) { |
| 1494 | ONENAND_SET_BUFFERRAM1(this); |
| 1495 | onenand_update_bufferram(mtd, to + this->writesize, !ret && !subpage); |
| 1496 | } |
| 1497 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1498 | if (ret) { |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1499 | printk(KERN_ERR "onenand_write_ops_nolock: write filaed %d\n", ret); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1500 | break; |
| 1501 | } |
| 1502 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1503 | /* Only check verify write turn on */ |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1504 | ret = onenand_verify(mtd, buf, to, thislen); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1505 | if (ret) { |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1506 | printk(KERN_ERR "onenand_write_ops_nolock: verify failed %d\n", ret); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1507 | break; |
| 1508 | } |
| 1509 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1510 | written += thislen; |
| 1511 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1512 | if (written == len) |
| 1513 | break; |
| 1514 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1515 | column = 0; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1516 | to += thislen; |
| 1517 | buf += thislen; |
| 1518 | } |
| 1519 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1520 | ops->retlen = written; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1521 | |
| 1522 | return ret; |
| 1523 | } |
| 1524 | |
| 1525 | /** |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1526 | * onenand_write_oob_nolock - [INTERN] OneNAND write out-of-band |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1527 | * @param mtd MTD device structure |
| 1528 | * @param to offset to write to |
| 1529 | * @param len number of bytes to write |
| 1530 | * @param retlen pointer to variable to store the number of written bytes |
| 1531 | * @param buf the data to write |
| 1532 | * @param mode operation mode |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1533 | * |
| 1534 | * OneNAND write out-of-band |
| 1535 | */ |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1536 | static int onenand_write_oob_nolock(struct mtd_info *mtd, loff_t to, |
| 1537 | struct mtd_oob_ops *ops) |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1538 | { |
| 1539 | struct onenand_chip *this = mtd->priv; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1540 | int column, ret = 0, oobsize; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1541 | int written = 0, oobcmd; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1542 | u_char *oobbuf; |
| 1543 | size_t len = ops->ooblen; |
| 1544 | const u_char *buf = ops->oobbuf; |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1545 | unsigned int mode = ops->mode; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1546 | |
| 1547 | to += ops->ooboffs; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1548 | |
Masahiro Yamada | f8a5d51 | 2017-10-18 00:10:48 +0900 | [diff] [blame] | 1549 | pr_debug("onenand_write_oob_nolock: to = 0x%08x, len = %i\n", |
| 1550 | (unsigned int) to, (int) len); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1551 | |
| 1552 | /* Initialize retlen, in case of early exit */ |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1553 | ops->oobretlen = 0; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1554 | |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1555 | if (mode == MTD_OPS_AUTO_OOB) |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1556 | oobsize = this->ecclayout->oobavail; |
| 1557 | else |
| 1558 | oobsize = mtd->oobsize; |
| 1559 | |
| 1560 | column = to & (mtd->oobsize - 1); |
| 1561 | |
| 1562 | if (unlikely(column >= oobsize)) { |
| 1563 | printk(KERN_ERR "onenand_write_oob_nolock: Attempted to start write outside oob\n"); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1564 | return -EINVAL; |
| 1565 | } |
| 1566 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1567 | /* For compatibility with NAND: Do not allow write past end of page */ |
| 1568 | if (unlikely(column + len > oobsize)) { |
| 1569 | printk(KERN_ERR "onenand_write_oob_nolock: " |
| 1570 | "Attempt to write past end of page\n"); |
| 1571 | return -EINVAL; |
| 1572 | } |
| 1573 | |
| 1574 | /* Do not allow reads past end of device */ |
| 1575 | if (unlikely(to >= mtd->size || |
| 1576 | column + len > ((mtd->size >> this->page_shift) - |
| 1577 | (to >> this->page_shift)) * oobsize)) { |
| 1578 | printk(KERN_ERR "onenand_write_oob_nolock: Attempted to write past end of device\n"); |
| 1579 | return -EINVAL; |
| 1580 | } |
| 1581 | |
| 1582 | oobbuf = this->oob_buf; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1583 | |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 1584 | oobcmd = ONENAND_IS_4KB_PAGE(this) ? |
| 1585 | ONENAND_CMD_PROG : ONENAND_CMD_PROGOOB; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1586 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1587 | /* Loop until all data write */ |
| 1588 | while (written < len) { |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1589 | int thislen = min_t(int, oobsize, len - written); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1590 | |
| 1591 | this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobsize); |
| 1592 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1593 | /* We send data to spare ram with oobsize |
| 1594 | * to prevent byte access */ |
| 1595 | memset(oobbuf, 0xff, mtd->oobsize); |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1596 | if (mode == MTD_OPS_AUTO_OOB) |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1597 | onenand_fill_auto_oob(mtd, oobbuf, buf, column, thislen); |
| 1598 | else |
| 1599 | memcpy(oobbuf + column, buf, thislen); |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1600 | this->write_bufferram(mtd, 0, ONENAND_SPARERAM, oobbuf, 0, mtd->oobsize); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1601 | |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 1602 | if (ONENAND_IS_4KB_PAGE(this)) { |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1603 | /* Set main area of DataRAM to 0xff*/ |
| 1604 | memset(this->page_buf, 0xff, mtd->writesize); |
| 1605 | this->write_bufferram(mtd, 0, ONENAND_DATARAM, |
| 1606 | this->page_buf, 0, mtd->writesize); |
| 1607 | } |
| 1608 | |
| 1609 | this->command(mtd, oobcmd, to, mtd->oobsize); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1610 | |
| 1611 | onenand_update_bufferram(mtd, to, 0); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1612 | if (ONENAND_IS_2PLANE(this)) { |
| 1613 | ONENAND_SET_BUFFERRAM1(this); |
| 1614 | onenand_update_bufferram(mtd, to + this->writesize, 0); |
| 1615 | } |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1616 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1617 | ret = this->wait(mtd, FL_WRITING); |
| 1618 | if (ret) { |
| 1619 | printk(KERN_ERR "onenand_write_oob_nolock: write failed %d\n", ret); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1620 | break; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | ret = onenand_verify_oob(mtd, oobbuf, to); |
| 1624 | if (ret) { |
| 1625 | printk(KERN_ERR "onenand_write_oob_nolock: verify failed %d\n", ret); |
| 1626 | break; |
| 1627 | } |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1628 | |
| 1629 | written += thislen; |
| 1630 | if (written == len) |
| 1631 | break; |
| 1632 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1633 | to += mtd->writesize; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1634 | buf += thislen; |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1635 | column = 0; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1636 | } |
| 1637 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1638 | ops->oobretlen = written; |
| 1639 | |
| 1640 | return ret; |
| 1641 | } |
| 1642 | |
| 1643 | /** |
| 1644 | * onenand_write - [MTD Interface] compability function for onenand_write_ecc |
| 1645 | * @param mtd MTD device structure |
| 1646 | * @param to offset to write to |
| 1647 | * @param len number of bytes to write |
| 1648 | * @param retlen pointer to variable to store the number of written bytes |
| 1649 | * @param buf the data to write |
| 1650 | * |
| 1651 | * Write with ECC |
| 1652 | */ |
| 1653 | int onenand_write(struct mtd_info *mtd, loff_t to, size_t len, |
| 1654 | size_t * retlen, const u_char * buf) |
| 1655 | { |
| 1656 | struct mtd_oob_ops ops = { |
| 1657 | .len = len, |
| 1658 | .ooblen = 0, |
| 1659 | .datbuf = (u_char *) buf, |
| 1660 | .oobbuf = NULL, |
| 1661 | }; |
| 1662 | int ret; |
| 1663 | |
| 1664 | onenand_get_device(mtd, FL_WRITING); |
| 1665 | ret = onenand_write_ops_nolock(mtd, to, &ops); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1666 | onenand_release_device(mtd); |
| 1667 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1668 | *retlen = ops.retlen; |
| 1669 | return ret; |
| 1670 | } |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1671 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1672 | /** |
| 1673 | * onenand_write_oob - [MTD Interface] OneNAND write out-of-band |
| 1674 | * @param mtd MTD device structure |
| 1675 | * @param to offset to write to |
| 1676 | * @param ops oob operation description structure |
| 1677 | * |
| 1678 | * OneNAND write main and/or out-of-band |
| 1679 | */ |
| 1680 | int onenand_write_oob(struct mtd_info *mtd, loff_t to, |
| 1681 | struct mtd_oob_ops *ops) |
| 1682 | { |
| 1683 | int ret; |
| 1684 | |
| 1685 | switch (ops->mode) { |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1686 | case MTD_OPS_PLACE_OOB: |
| 1687 | case MTD_OPS_AUTO_OOB: |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1688 | break; |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1689 | case MTD_OPS_RAW: |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 1690 | /* Not implemented yet */ |
| 1691 | default: |
| 1692 | return -EINVAL; |
| 1693 | } |
| 1694 | |
| 1695 | onenand_get_device(mtd, FL_WRITING); |
| 1696 | if (ops->datbuf) |
| 1697 | ret = onenand_write_ops_nolock(mtd, to, ops); |
| 1698 | else |
| 1699 | ret = onenand_write_oob_nolock(mtd, to, ops); |
| 1700 | onenand_release_device(mtd); |
| 1701 | |
| 1702 | return ret; |
| 1703 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1704 | } |
| 1705 | |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 1706 | /** |
| 1707 | * onenand_block_isbad_nolock - [GENERIC] Check if a block is marked bad |
| 1708 | * @param mtd MTD device structure |
| 1709 | * @param ofs offset from device start |
| 1710 | * @param allowbbt 1, if its allowed to access the bbt area |
| 1711 | * |
| 1712 | * Check, if the block is bad, Either by reading the bad block table or |
| 1713 | * calling of the scan function. |
| 1714 | */ |
| 1715 | static int onenand_block_isbad_nolock(struct mtd_info *mtd, loff_t ofs, int allowbbt) |
| 1716 | { |
| 1717 | struct onenand_chip *this = mtd->priv; |
| 1718 | struct bbm_info *bbm = this->bbm; |
| 1719 | |
| 1720 | /* Return info from the table */ |
| 1721 | return bbm->isbad_bbt(mtd, ofs, allowbbt); |
| 1722 | } |
| 1723 | |
| 1724 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1725 | /** |
| 1726 | * onenand_erase - [MTD Interface] erase block(s) |
| 1727 | * @param mtd MTD device structure |
| 1728 | * @param instr erase instruction |
| 1729 | * |
| 1730 | * Erase one ore more blocks |
| 1731 | */ |
| 1732 | int onenand_erase(struct mtd_info *mtd, struct erase_info *instr) |
| 1733 | { |
| 1734 | struct onenand_chip *this = mtd->priv; |
| 1735 | unsigned int block_size; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1736 | loff_t addr = instr->addr; |
| 1737 | unsigned int len = instr->len; |
| 1738 | int ret = 0, i; |
| 1739 | struct mtd_erase_region_info *region = NULL; |
| 1740 | unsigned int region_end = 0; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1741 | |
Masahiro Yamada | f8a5d51 | 2017-10-18 00:10:48 +0900 | [diff] [blame] | 1742 | pr_debug("onenand_erase: start = 0x%08x, len = %i\n", |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1743 | (unsigned int) addr, len); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1744 | |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1745 | if (FLEXONENAND(this)) { |
| 1746 | /* Find the eraseregion of this address */ |
| 1747 | i = flexonenand_region(mtd, addr); |
| 1748 | region = &mtd->eraseregions[i]; |
| 1749 | |
| 1750 | block_size = region->erasesize; |
| 1751 | region_end = region->offset |
| 1752 | + region->erasesize * region->numblocks; |
| 1753 | |
| 1754 | /* Start address within region must align on block boundary. |
| 1755 | * Erase region's start offset is always block start address. |
| 1756 | */ |
| 1757 | if (unlikely((addr - region->offset) & (block_size - 1))) { |
Masahiro Yamada | f8a5d51 | 2017-10-18 00:10:48 +0900 | [diff] [blame] | 1758 | pr_debug("onenand_erase:" " Unaligned address\n"); |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1759 | return -EINVAL; |
| 1760 | } |
| 1761 | } else { |
| 1762 | block_size = 1 << this->erase_shift; |
| 1763 | |
| 1764 | /* Start address must align on block boundary */ |
| 1765 | if (unlikely(addr & (block_size - 1))) { |
Masahiro Yamada | f8a5d51 | 2017-10-18 00:10:48 +0900 | [diff] [blame] | 1766 | pr_debug("onenand_erase:" "Unaligned address\n"); |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1767 | return -EINVAL; |
| 1768 | } |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1769 | } |
| 1770 | |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1771 | /* Length must align on block boundary */ |
| 1772 | if (unlikely(len & (block_size - 1))) { |
Masahiro Yamada | f8a5d51 | 2017-10-18 00:10:48 +0900 | [diff] [blame] | 1773 | pr_debug("onenand_erase: Length not block aligned\n"); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1774 | return -EINVAL; |
| 1775 | } |
| 1776 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1777 | /* Grab the lock and see if the device is available */ |
| 1778 | onenand_get_device(mtd, FL_ERASING); |
| 1779 | |
| 1780 | /* Loop throught the pages */ |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1781 | instr->state = MTD_ERASING; |
| 1782 | |
| 1783 | while (len) { |
| 1784 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1785 | /* Check if we have a bad block, we do not erase bad blocks */ |
| 1786 | if (instr->priv == 0 && onenand_block_isbad_nolock(mtd, addr, 0)) { |
| 1787 | printk(KERN_WARNING "onenand_erase: attempt to erase" |
| 1788 | " a bad block at addr 0x%08x\n", |
| 1789 | (unsigned int) addr); |
| 1790 | instr->state = MTD_ERASE_FAILED; |
| 1791 | goto erase_exit; |
| 1792 | } |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1793 | |
| 1794 | this->command(mtd, ONENAND_CMD_ERASE, addr, block_size); |
| 1795 | |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 1796 | onenand_invalidate_bufferram(mtd, addr, block_size); |
| 1797 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1798 | ret = this->wait(mtd, FL_ERASING); |
| 1799 | /* Check, if it is write protected */ |
| 1800 | if (ret) { |
| 1801 | if (ret == -EPERM) |
Masahiro Yamada | f8a5d51 | 2017-10-18 00:10:48 +0900 | [diff] [blame] | 1802 | pr_debug("onenand_erase: " |
| 1803 | "Device is write protected!!!\n"); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1804 | else |
Masahiro Yamada | f8a5d51 | 2017-10-18 00:10:48 +0900 | [diff] [blame] | 1805 | pr_debug("onenand_erase: " |
| 1806 | "Failed erase, block %d\n", |
| 1807 | onenand_block(this, addr)); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1808 | instr->state = MTD_ERASE_FAILED; |
| 1809 | instr->fail_addr = addr; |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1810 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1811 | goto erase_exit; |
| 1812 | } |
| 1813 | |
| 1814 | len -= block_size; |
| 1815 | addr += block_size; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1816 | |
| 1817 | if (addr == region_end) { |
| 1818 | if (!len) |
| 1819 | break; |
| 1820 | region++; |
| 1821 | |
| 1822 | block_size = region->erasesize; |
| 1823 | region_end = region->offset |
| 1824 | + region->erasesize * region->numblocks; |
| 1825 | |
| 1826 | if (len & (block_size - 1)) { |
| 1827 | /* This has been checked at MTD |
| 1828 | * partitioning level. */ |
| 1829 | printk("onenand_erase: Unaligned address\n"); |
| 1830 | goto erase_exit; |
| 1831 | } |
| 1832 | } |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | instr->state = MTD_ERASE_DONE; |
| 1836 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1837 | erase_exit: |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1838 | |
| 1839 | ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1840 | |
| 1841 | /* Deselect and wake up anyone waiting on the device */ |
| 1842 | onenand_release_device(mtd); |
| 1843 | |
| 1844 | return ret; |
| 1845 | } |
| 1846 | |
| 1847 | /** |
| 1848 | * onenand_sync - [MTD Interface] sync |
| 1849 | * @param mtd MTD device structure |
| 1850 | * |
| 1851 | * Sync is actually a wait for chip ready function |
| 1852 | */ |
| 1853 | void onenand_sync(struct mtd_info *mtd) |
| 1854 | { |
Masahiro Yamada | f8a5d51 | 2017-10-18 00:10:48 +0900 | [diff] [blame] | 1855 | pr_debug("onenand_sync: called\n"); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1856 | |
| 1857 | /* Grab the lock and see if the device is available */ |
| 1858 | onenand_get_device(mtd, FL_SYNCING); |
| 1859 | |
| 1860 | /* Release it and go back */ |
| 1861 | onenand_release_device(mtd); |
| 1862 | } |
| 1863 | |
| 1864 | /** |
| 1865 | * onenand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad |
| 1866 | * @param mtd MTD device structure |
| 1867 | * @param ofs offset relative to mtd start |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 1868 | * |
| 1869 | * Check whether the block is bad |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1870 | */ |
| 1871 | int onenand_block_isbad(struct mtd_info *mtd, loff_t ofs) |
| 1872 | { |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 1873 | int ret; |
| 1874 | |
| 1875 | /* Check for invalid offset */ |
| 1876 | if (ofs > mtd->size) |
| 1877 | return -EINVAL; |
| 1878 | |
| 1879 | onenand_get_device(mtd, FL_READING); |
| 1880 | ret = onenand_block_isbad_nolock(mtd,ofs, 0); |
| 1881 | onenand_release_device(mtd); |
| 1882 | return ret; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | /** |
Kyungmin Park | 87b4950 | 2008-11-13 15:14:33 +0900 | [diff] [blame] | 1886 | * onenand_default_block_markbad - [DEFAULT] mark a block bad |
| 1887 | * @param mtd MTD device structure |
| 1888 | * @param ofs offset from device start |
| 1889 | * |
| 1890 | * This is the default implementation, which can be overridden by |
| 1891 | * a hardware specific driver. |
| 1892 | */ |
| 1893 | static int onenand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) |
| 1894 | { |
| 1895 | struct onenand_chip *this = mtd->priv; |
| 1896 | struct bbm_info *bbm = this->bbm; |
| 1897 | u_char buf[2] = {0, 0}; |
| 1898 | struct mtd_oob_ops ops = { |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 1899 | .mode = MTD_OPS_PLACE_OOB, |
Kyungmin Park | 87b4950 | 2008-11-13 15:14:33 +0900 | [diff] [blame] | 1900 | .ooblen = 2, |
| 1901 | .oobbuf = buf, |
| 1902 | .ooboffs = 0, |
| 1903 | }; |
| 1904 | int block; |
| 1905 | |
| 1906 | /* Get block number */ |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1907 | block = onenand_block(this, ofs); |
Kyungmin Park | 87b4950 | 2008-11-13 15:14:33 +0900 | [diff] [blame] | 1908 | if (bbm->bbt) |
| 1909 | bbm->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); |
| 1910 | |
| 1911 | /* We write two bytes, so we dont have to mess with 16 bit access */ |
| 1912 | ofs += mtd->oobsize + (bbm->badblockpos & ~0x01); |
| 1913 | return onenand_write_oob_nolock(mtd, ofs, &ops); |
| 1914 | } |
| 1915 | |
| 1916 | /** |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1917 | * onenand_block_markbad - [MTD Interface] Mark the block at the given offset as bad |
| 1918 | * @param mtd MTD device structure |
| 1919 | * @param ofs offset relative to mtd start |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 1920 | * |
| 1921 | * Mark the block as bad |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1922 | */ |
| 1923 | int onenand_block_markbad(struct mtd_info *mtd, loff_t ofs) |
| 1924 | { |
Ladislav Michl | 7868fba | 2017-06-20 17:17:45 +0200 | [diff] [blame] | 1925 | struct onenand_chip *this = mtd->priv; |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 1926 | int ret; |
| 1927 | |
| 1928 | ret = onenand_block_isbad(mtd, ofs); |
| 1929 | if (ret) { |
| 1930 | /* If it was bad already, return success and do nothing */ |
| 1931 | if (ret > 0) |
| 1932 | return 0; |
| 1933 | return ret; |
| 1934 | } |
| 1935 | |
Ladislav Michl | 7868fba | 2017-06-20 17:17:45 +0200 | [diff] [blame] | 1936 | onenand_get_device(mtd, FL_WRITING); |
| 1937 | ret = this->block_markbad(mtd, ofs); |
| 1938 | onenand_release_device(mtd); |
| 1939 | |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 1940 | return ret; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | /** |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1944 | * onenand_do_lock_cmd - [OneNAND Interface] Lock or unlock block(s) |
| 1945 | * @param mtd MTD device structure |
| 1946 | * @param ofs offset relative to mtd start |
| 1947 | * @param len number of bytes to lock or unlock |
| 1948 | * @param cmd lock or unlock command |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1949 | * |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1950 | * Lock or unlock one or more blocks |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1951 | */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1952 | static int onenand_do_lock_cmd(struct mtd_info *mtd, loff_t ofs, size_t len, int cmd) |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1953 | { |
| 1954 | struct onenand_chip *this = mtd->priv; |
| 1955 | int start, end, block, value, status; |
| 1956 | |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1957 | start = onenand_block(this, ofs); |
| 1958 | end = onenand_block(this, ofs + len); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1959 | |
| 1960 | /* Continuous lock scheme */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1961 | if (this->options & ONENAND_HAS_CONT_LOCK) { |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1962 | /* Set start block address */ |
| 1963 | this->write_word(start, |
| 1964 | this->base + ONENAND_REG_START_BLOCK_ADDRESS); |
| 1965 | /* Set end block address */ |
| 1966 | this->write_word(end - 1, |
| 1967 | this->base + ONENAND_REG_END_BLOCK_ADDRESS); |
| 1968 | /* Write unlock command */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1969 | this->command(mtd, cmd, 0, 0); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1970 | |
| 1971 | /* There's no return value */ |
| 1972 | this->wait(mtd, FL_UNLOCKING); |
| 1973 | |
| 1974 | /* Sanity check */ |
| 1975 | while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS) |
| 1976 | & ONENAND_CTRL_ONGO) |
| 1977 | continue; |
| 1978 | |
| 1979 | /* Check lock status */ |
| 1980 | status = this->read_word(this->base + ONENAND_REG_WP_STATUS); |
| 1981 | if (!(status & ONENAND_WP_US)) |
| 1982 | printk(KERN_ERR "wp status = 0x%x\n", status); |
| 1983 | |
| 1984 | return 0; |
| 1985 | } |
| 1986 | |
| 1987 | /* Block lock scheme */ |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 1988 | for (block = start; block < end; block++) { |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 1989 | /* Set block address */ |
| 1990 | value = onenand_block_address(this, block); |
| 1991 | this->write_word(value, this->base + ONENAND_REG_START_ADDRESS1); |
| 1992 | /* Select DataRAM for DDP */ |
| 1993 | value = onenand_bufferram_address(this, block); |
| 1994 | this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2); |
| 1995 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 1996 | /* Set start block address */ |
| 1997 | this->write_word(block, |
| 1998 | this->base + ONENAND_REG_START_BLOCK_ADDRESS); |
| 1999 | /* Write unlock command */ |
| 2000 | this->command(mtd, ONENAND_CMD_UNLOCK, 0, 0); |
| 2001 | |
| 2002 | /* There's no return value */ |
| 2003 | this->wait(mtd, FL_UNLOCKING); |
| 2004 | |
| 2005 | /* Sanity check */ |
| 2006 | while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS) |
| 2007 | & ONENAND_CTRL_ONGO) |
| 2008 | continue; |
| 2009 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2010 | /* Check lock status */ |
| 2011 | status = this->read_word(this->base + ONENAND_REG_WP_STATUS); |
| 2012 | if (!(status & ONENAND_WP_US)) |
| 2013 | printk(KERN_ERR "block = %d, wp status = 0x%x\n", |
| 2014 | block, status); |
| 2015 | } |
| 2016 | |
| 2017 | return 0; |
| 2018 | } |
| 2019 | |
Stefan Roese | 5ed79ae | 2008-11-11 10:28:53 +0100 | [diff] [blame] | 2020 | #ifdef ONENAND_LINUX |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2021 | /** |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2022 | * onenand_lock - [MTD Interface] Lock block(s) |
| 2023 | * @param mtd MTD device structure |
| 2024 | * @param ofs offset relative to mtd start |
| 2025 | * @param len number of bytes to unlock |
| 2026 | * |
| 2027 | * Lock one or more blocks |
| 2028 | */ |
| 2029 | static int onenand_lock(struct mtd_info *mtd, loff_t ofs, size_t len) |
| 2030 | { |
| 2031 | int ret; |
| 2032 | |
| 2033 | onenand_get_device(mtd, FL_LOCKING); |
| 2034 | ret = onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_LOCK); |
| 2035 | onenand_release_device(mtd); |
| 2036 | return ret; |
| 2037 | } |
| 2038 | |
| 2039 | /** |
| 2040 | * onenand_unlock - [MTD Interface] Unlock block(s) |
| 2041 | * @param mtd MTD device structure |
| 2042 | * @param ofs offset relative to mtd start |
| 2043 | * @param len number of bytes to unlock |
| 2044 | * |
| 2045 | * Unlock one or more blocks |
| 2046 | */ |
| 2047 | static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len) |
| 2048 | { |
| 2049 | int ret; |
| 2050 | |
| 2051 | onenand_get_device(mtd, FL_LOCKING); |
| 2052 | ret = onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_UNLOCK); |
| 2053 | onenand_release_device(mtd); |
| 2054 | return ret; |
| 2055 | } |
Stefan Roese | 5ed79ae | 2008-11-11 10:28:53 +0100 | [diff] [blame] | 2056 | #endif |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2057 | |
| 2058 | /** |
| 2059 | * onenand_check_lock_status - [OneNAND Interface] Check lock status |
| 2060 | * @param this onenand chip data structure |
| 2061 | * |
| 2062 | * Check lock status |
| 2063 | */ |
| 2064 | static int onenand_check_lock_status(struct onenand_chip *this) |
| 2065 | { |
| 2066 | unsigned int value, block, status; |
| 2067 | unsigned int end; |
| 2068 | |
| 2069 | end = this->chipsize >> this->erase_shift; |
| 2070 | for (block = 0; block < end; block++) { |
| 2071 | /* Set block address */ |
| 2072 | value = onenand_block_address(this, block); |
| 2073 | this->write_word(value, this->base + ONENAND_REG_START_ADDRESS1); |
| 2074 | /* Select DataRAM for DDP */ |
| 2075 | value = onenand_bufferram_address(this, block); |
| 2076 | this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2); |
| 2077 | /* Set start block address */ |
| 2078 | this->write_word(block, this->base + ONENAND_REG_START_BLOCK_ADDRESS); |
| 2079 | |
| 2080 | /* Check lock status */ |
| 2081 | status = this->read_word(this->base + ONENAND_REG_WP_STATUS); |
| 2082 | if (!(status & ONENAND_WP_US)) { |
| 2083 | printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status); |
| 2084 | return 0; |
| 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | return 1; |
| 2089 | } |
| 2090 | |
| 2091 | /** |
| 2092 | * onenand_unlock_all - [OneNAND Interface] unlock all blocks |
| 2093 | * @param mtd MTD device structure |
| 2094 | * |
| 2095 | * Unlock all blocks |
| 2096 | */ |
| 2097 | static void onenand_unlock_all(struct mtd_info *mtd) |
| 2098 | { |
| 2099 | struct onenand_chip *this = mtd->priv; |
| 2100 | loff_t ofs = 0; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2101 | size_t len = mtd->size; |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2102 | |
| 2103 | if (this->options & ONENAND_HAS_UNLOCK_ALL) { |
| 2104 | /* Set start block address */ |
| 2105 | this->write_word(0, this->base + ONENAND_REG_START_BLOCK_ADDRESS); |
| 2106 | /* Write unlock command */ |
| 2107 | this->command(mtd, ONENAND_CMD_UNLOCK_ALL, 0, 0); |
| 2108 | |
| 2109 | /* There's no return value */ |
| 2110 | this->wait(mtd, FL_LOCKING); |
| 2111 | |
| 2112 | /* Sanity check */ |
| 2113 | while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS) |
| 2114 | & ONENAND_CTRL_ONGO) |
| 2115 | continue; |
| 2116 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2117 | /* Check lock status */ |
| 2118 | if (onenand_check_lock_status(this)) |
| 2119 | return; |
| 2120 | |
| 2121 | /* Workaround for all block unlock in DDP */ |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2122 | if (ONENAND_IS_DDP(this) && !FLEXONENAND(this)) { |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2123 | /* All blocks on another chip */ |
| 2124 | ofs = this->chipsize >> 1; |
| 2125 | len = this->chipsize >> 1; |
| 2126 | } |
| 2127 | } |
| 2128 | |
| 2129 | onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_UNLOCK); |
| 2130 | } |
| 2131 | |
| 2132 | |
| 2133 | /** |
| 2134 | * onenand_check_features - Check and set OneNAND features |
| 2135 | * @param mtd MTD data structure |
| 2136 | * |
| 2137 | * Check and set OneNAND features |
| 2138 | * - lock scheme |
| 2139 | * - two plane |
| 2140 | */ |
| 2141 | static void onenand_check_features(struct mtd_info *mtd) |
| 2142 | { |
| 2143 | struct onenand_chip *this = mtd->priv; |
| 2144 | unsigned int density, process; |
| 2145 | |
| 2146 | /* Lock scheme depends on density and process */ |
| 2147 | density = onenand_get_density(this->device_id); |
| 2148 | process = this->version_id >> ONENAND_VERSION_PROCESS_SHIFT; |
| 2149 | |
| 2150 | /* Lock scheme */ |
| 2151 | switch (density) { |
| 2152 | case ONENAND_DEVICE_DENSITY_4Gb: |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 2153 | if (ONENAND_IS_DDP(this)) |
| 2154 | this->options |= ONENAND_HAS_2PLANE; |
| 2155 | else |
| 2156 | this->options |= ONENAND_HAS_4KB_PAGE; |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2157 | |
| 2158 | case ONENAND_DEVICE_DENSITY_2Gb: |
| 2159 | /* 2Gb DDP don't have 2 plane */ |
| 2160 | if (!ONENAND_IS_DDP(this)) |
| 2161 | this->options |= ONENAND_HAS_2PLANE; |
| 2162 | this->options |= ONENAND_HAS_UNLOCK_ALL; |
| 2163 | |
| 2164 | case ONENAND_DEVICE_DENSITY_1Gb: |
| 2165 | /* A-Die has all block unlock */ |
| 2166 | if (process) |
| 2167 | this->options |= ONENAND_HAS_UNLOCK_ALL; |
| 2168 | break; |
| 2169 | |
| 2170 | default: |
| 2171 | /* Some OneNAND has continuous lock scheme */ |
| 2172 | if (!process) |
| 2173 | this->options |= ONENAND_HAS_CONT_LOCK; |
| 2174 | break; |
| 2175 | } |
| 2176 | |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2177 | if (ONENAND_IS_MLC(this)) |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 2178 | this->options |= ONENAND_HAS_4KB_PAGE; |
| 2179 | |
| 2180 | if (ONENAND_IS_4KB_PAGE(this)) |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2181 | this->options &= ~ONENAND_HAS_2PLANE; |
| 2182 | |
| 2183 | if (FLEXONENAND(this)) { |
| 2184 | this->options &= ~ONENAND_HAS_CONT_LOCK; |
| 2185 | this->options |= ONENAND_HAS_UNLOCK_ALL; |
| 2186 | } |
| 2187 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2188 | if (this->options & ONENAND_HAS_CONT_LOCK) |
| 2189 | printk(KERN_DEBUG "Lock scheme is Continuous Lock\n"); |
| 2190 | if (this->options & ONENAND_HAS_UNLOCK_ALL) |
| 2191 | printk(KERN_DEBUG "Chip support all block unlock\n"); |
| 2192 | if (this->options & ONENAND_HAS_2PLANE) |
| 2193 | printk(KERN_DEBUG "Chip has 2 plane\n"); |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 2194 | if (this->options & ONENAND_HAS_4KB_PAGE) |
| 2195 | printk(KERN_DEBUG "Chip has 4KiB pagesize\n"); |
| 2196 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | /** |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2200 | * onenand_print_device_info - Print device ID |
| 2201 | * @param device device ID |
| 2202 | * |
| 2203 | * Print device ID |
| 2204 | */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2205 | char *onenand_print_device_info(int device, int version) |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2206 | { |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2207 | int vcc, demuxed, ddp, density, flexonenand; |
Fathi BOUDRA | 95feb70 | 2008-08-06 10:06:20 +0200 | [diff] [blame] | 2208 | char *dev_info = malloc(80); |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2209 | char *p = dev_info; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2210 | |
| 2211 | vcc = device & ONENAND_DEVICE_VCC_MASK; |
| 2212 | demuxed = device & ONENAND_DEVICE_IS_DEMUX; |
| 2213 | ddp = device & ONENAND_DEVICE_IS_DDP; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2214 | density = onenand_get_density(device); |
| 2215 | flexonenand = device & DEVICE_IS_FLEXONENAND; |
| 2216 | p += sprintf(dev_info, "%s%sOneNAND%s %dMB %sV 16-bit (0x%02x)", |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2217 | demuxed ? "" : "Muxed ", |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2218 | flexonenand ? "Flex-" : "", |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2219 | ddp ? "(DDP)" : "", |
| 2220 | (16 << density), vcc ? "2.65/3.3" : "1.8", device); |
Fathi BOUDRA | 95feb70 | 2008-08-06 10:06:20 +0200 | [diff] [blame] | 2221 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2222 | sprintf(p, "\nOneNAND version = 0x%04x", version); |
| 2223 | printk("%s\n", dev_info); |
| 2224 | |
Fathi BOUDRA | 95feb70 | 2008-08-06 10:06:20 +0200 | [diff] [blame] | 2225 | return dev_info; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | static const struct onenand_manufacturers onenand_manuf_ids[] = { |
Enric Balletbo i Serra | 891d81b | 2010-10-11 21:48:03 +0200 | [diff] [blame] | 2229 | {ONENAND_MFR_NUMONYX, "Numonyx"}, |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2230 | {ONENAND_MFR_SAMSUNG, "Samsung"}, |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2231 | }; |
| 2232 | |
| 2233 | /** |
| 2234 | * onenand_check_maf - Check manufacturer ID |
| 2235 | * @param manuf manufacturer ID |
| 2236 | * |
| 2237 | * Check manufacturer ID |
| 2238 | */ |
| 2239 | static int onenand_check_maf(int manuf) |
| 2240 | { |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2241 | int size = ARRAY_SIZE(onenand_manuf_ids); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2242 | int i; |
Marek Vasut | e333474 | 2011-11-06 00:59:52 +0100 | [diff] [blame] | 2243 | #ifdef ONENAND_DEBUG |
| 2244 | char *name; |
| 2245 | #endif |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2246 | |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2247 | for (i = 0; i < size; i++) |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2248 | if (manuf == onenand_manuf_ids[i].id) |
| 2249 | break; |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2250 | |
Marek Vasut | e333474 | 2011-11-06 00:59:52 +0100 | [diff] [blame] | 2251 | #ifdef ONENAND_DEBUG |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2252 | if (i < size) |
| 2253 | name = onenand_manuf_ids[i].name; |
| 2254 | else |
| 2255 | name = "Unknown"; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2256 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2257 | printk(KERN_DEBUG "OneNAND Manufacturer: %s (0x%0x)\n", name, manuf); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2258 | #endif |
| 2259 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2260 | return i == size; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | /** |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2264 | * flexonenand_get_boundary - Reads the SLC boundary |
| 2265 | * @param onenand_info - onenand info structure |
| 2266 | * |
| 2267 | * Fill up boundary[] field in onenand_chip |
| 2268 | **/ |
| 2269 | static int flexonenand_get_boundary(struct mtd_info *mtd) |
| 2270 | { |
| 2271 | struct onenand_chip *this = mtd->priv; |
| 2272 | unsigned int die, bdry; |
Marek Vasut | e333474 | 2011-11-06 00:59:52 +0100 | [diff] [blame] | 2273 | int syscfg, locked; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2274 | |
| 2275 | /* Disable ECC */ |
| 2276 | syscfg = this->read_word(this->base + ONENAND_REG_SYS_CFG1); |
| 2277 | this->write_word((syscfg | 0x0100), this->base + ONENAND_REG_SYS_CFG1); |
| 2278 | |
| 2279 | for (die = 0; die < this->dies; die++) { |
| 2280 | this->command(mtd, FLEXONENAND_CMD_PI_ACCESS, die, 0); |
| 2281 | this->wait(mtd, FL_SYNCING); |
| 2282 | |
| 2283 | this->command(mtd, FLEXONENAND_CMD_READ_PI, die, 0); |
Marek Vasut | e333474 | 2011-11-06 00:59:52 +0100 | [diff] [blame] | 2284 | this->wait(mtd, FL_READING); |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2285 | |
| 2286 | bdry = this->read_word(this->base + ONENAND_DATARAM); |
| 2287 | if ((bdry >> FLEXONENAND_PI_UNLOCK_SHIFT) == 3) |
| 2288 | locked = 0; |
| 2289 | else |
| 2290 | locked = 1; |
| 2291 | this->boundary[die] = bdry & FLEXONENAND_PI_MASK; |
| 2292 | |
| 2293 | this->command(mtd, ONENAND_CMD_RESET, 0, 0); |
Marek Vasut | e333474 | 2011-11-06 00:59:52 +0100 | [diff] [blame] | 2294 | this->wait(mtd, FL_RESETING); |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2295 | |
| 2296 | printk(KERN_INFO "Die %d boundary: %d%s\n", die, |
| 2297 | this->boundary[die], locked ? "(Locked)" : "(Unlocked)"); |
| 2298 | } |
| 2299 | |
| 2300 | /* Enable ECC */ |
| 2301 | this->write_word(syscfg, this->base + ONENAND_REG_SYS_CFG1); |
| 2302 | return 0; |
| 2303 | } |
| 2304 | |
| 2305 | /** |
| 2306 | * flexonenand_get_size - Fill up fields in onenand_chip and mtd_info |
Wolfgang Denk | 62fb2b4 | 2021-09-27 17:42:39 +0200 | [diff] [blame] | 2307 | * boundary[], diesize[], mtd->size, mtd->erasesize, |
| 2308 | * mtd->eraseregions |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2309 | * @param mtd - MTD device structure |
| 2310 | */ |
| 2311 | static void flexonenand_get_size(struct mtd_info *mtd) |
| 2312 | { |
| 2313 | struct onenand_chip *this = mtd->priv; |
| 2314 | int die, i, eraseshift, density; |
| 2315 | int blksperdie, maxbdry; |
| 2316 | loff_t ofs; |
| 2317 | |
| 2318 | density = onenand_get_density(this->device_id); |
| 2319 | blksperdie = ((loff_t)(16 << density) << 20) >> (this->erase_shift); |
| 2320 | blksperdie >>= ONENAND_IS_DDP(this) ? 1 : 0; |
| 2321 | maxbdry = blksperdie - 1; |
| 2322 | eraseshift = this->erase_shift - 1; |
| 2323 | |
| 2324 | mtd->numeraseregions = this->dies << 1; |
| 2325 | |
| 2326 | /* This fills up the device boundary */ |
| 2327 | flexonenand_get_boundary(mtd); |
| 2328 | die = 0; |
| 2329 | ofs = 0; |
| 2330 | i = -1; |
| 2331 | for (; die < this->dies; die++) { |
| 2332 | if (!die || this->boundary[die-1] != maxbdry) { |
| 2333 | i++; |
| 2334 | mtd->eraseregions[i].offset = ofs; |
| 2335 | mtd->eraseregions[i].erasesize = 1 << eraseshift; |
| 2336 | mtd->eraseregions[i].numblocks = |
| 2337 | this->boundary[die] + 1; |
| 2338 | ofs += mtd->eraseregions[i].numblocks << eraseshift; |
| 2339 | eraseshift++; |
| 2340 | } else { |
| 2341 | mtd->numeraseregions -= 1; |
| 2342 | mtd->eraseregions[i].numblocks += |
| 2343 | this->boundary[die] + 1; |
| 2344 | ofs += (this->boundary[die] + 1) << (eraseshift - 1); |
| 2345 | } |
| 2346 | if (this->boundary[die] != maxbdry) { |
| 2347 | i++; |
| 2348 | mtd->eraseregions[i].offset = ofs; |
| 2349 | mtd->eraseregions[i].erasesize = 1 << eraseshift; |
| 2350 | mtd->eraseregions[i].numblocks = maxbdry ^ |
| 2351 | this->boundary[die]; |
| 2352 | ofs += mtd->eraseregions[i].numblocks << eraseshift; |
| 2353 | eraseshift--; |
| 2354 | } else |
| 2355 | mtd->numeraseregions -= 1; |
| 2356 | } |
| 2357 | |
| 2358 | /* Expose MLC erase size except when all blocks are SLC */ |
| 2359 | mtd->erasesize = 1 << this->erase_shift; |
| 2360 | if (mtd->numeraseregions == 1) |
| 2361 | mtd->erasesize >>= 1; |
| 2362 | |
| 2363 | printk(KERN_INFO "Device has %d eraseregions\n", mtd->numeraseregions); |
| 2364 | for (i = 0; i < mtd->numeraseregions; i++) |
| 2365 | printk(KERN_INFO "[offset: 0x%08llx, erasesize: 0x%05x," |
| 2366 | " numblocks: %04u]\n", mtd->eraseregions[i].offset, |
| 2367 | mtd->eraseregions[i].erasesize, |
| 2368 | mtd->eraseregions[i].numblocks); |
| 2369 | |
| 2370 | for (die = 0, mtd->size = 0; die < this->dies; die++) { |
| 2371 | this->diesize[die] = (loff_t) (blksperdie << this->erase_shift); |
| 2372 | this->diesize[die] -= (loff_t) (this->boundary[die] + 1) |
| 2373 | << (this->erase_shift - 1); |
| 2374 | mtd->size += this->diesize[die]; |
| 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | /** |
| 2379 | * flexonenand_check_blocks_erased - Check if blocks are erased |
| 2380 | * @param mtd_info - mtd info structure |
| 2381 | * @param start - first erase block to check |
| 2382 | * @param end - last erase block to check |
| 2383 | * |
| 2384 | * Converting an unerased block from MLC to SLC |
| 2385 | * causes byte values to change. Since both data and its ECC |
| 2386 | * have changed, reads on the block give uncorrectable error. |
| 2387 | * This might lead to the block being detected as bad. |
| 2388 | * |
| 2389 | * Avoid this by ensuring that the block to be converted is |
| 2390 | * erased. |
| 2391 | */ |
| 2392 | static int flexonenand_check_blocks_erased(struct mtd_info *mtd, |
| 2393 | int start, int end) |
| 2394 | { |
| 2395 | struct onenand_chip *this = mtd->priv; |
| 2396 | int i, ret; |
| 2397 | int block; |
| 2398 | struct mtd_oob_ops ops = { |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 2399 | .mode = MTD_OPS_PLACE_OOB, |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2400 | .ooboffs = 0, |
| 2401 | .ooblen = mtd->oobsize, |
| 2402 | .datbuf = NULL, |
| 2403 | .oobbuf = this->oob_buf, |
| 2404 | }; |
| 2405 | loff_t addr; |
| 2406 | |
| 2407 | printk(KERN_DEBUG "Check blocks from %d to %d\n", start, end); |
| 2408 | |
| 2409 | for (block = start; block <= end; block++) { |
| 2410 | addr = flexonenand_addr(this, block); |
| 2411 | if (onenand_block_isbad_nolock(mtd, addr, 0)) |
| 2412 | continue; |
| 2413 | |
| 2414 | /* |
| 2415 | * Since main area write results in ECC write to spare, |
| 2416 | * it is sufficient to check only ECC bytes for change. |
| 2417 | */ |
| 2418 | ret = onenand_read_oob_nolock(mtd, addr, &ops); |
| 2419 | if (ret) |
| 2420 | return ret; |
| 2421 | |
| 2422 | for (i = 0; i < mtd->oobsize; i++) |
| 2423 | if (this->oob_buf[i] != 0xff) |
| 2424 | break; |
| 2425 | |
| 2426 | if (i != mtd->oobsize) { |
| 2427 | printk(KERN_WARNING "Block %d not erased.\n", block); |
| 2428 | return 1; |
| 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | return 0; |
| 2433 | } |
| 2434 | |
| 2435 | /** |
| 2436 | * flexonenand_set_boundary - Writes the SLC boundary |
| 2437 | * @param mtd - mtd info structure |
| 2438 | */ |
| 2439 | int flexonenand_set_boundary(struct mtd_info *mtd, int die, |
| 2440 | int boundary, int lock) |
| 2441 | { |
| 2442 | struct onenand_chip *this = mtd->priv; |
| 2443 | int ret, density, blksperdie, old, new, thisboundary; |
| 2444 | loff_t addr; |
| 2445 | |
| 2446 | if (die >= this->dies) |
| 2447 | return -EINVAL; |
| 2448 | |
| 2449 | if (boundary == this->boundary[die]) |
| 2450 | return 0; |
| 2451 | |
| 2452 | density = onenand_get_density(this->device_id); |
| 2453 | blksperdie = ((16 << density) << 20) >> this->erase_shift; |
| 2454 | blksperdie >>= ONENAND_IS_DDP(this) ? 1 : 0; |
| 2455 | |
| 2456 | if (boundary >= blksperdie) { |
| 2457 | printk("flexonenand_set_boundary:" |
| 2458 | "Invalid boundary value. " |
| 2459 | "Boundary not changed.\n"); |
| 2460 | return -EINVAL; |
| 2461 | } |
| 2462 | |
| 2463 | /* Check if converting blocks are erased */ |
| 2464 | old = this->boundary[die] + (die * this->density_mask); |
| 2465 | new = boundary + (die * this->density_mask); |
| 2466 | ret = flexonenand_check_blocks_erased(mtd, min(old, new) |
| 2467 | + 1, max(old, new)); |
| 2468 | if (ret) { |
| 2469 | printk(KERN_ERR "flexonenand_set_boundary: Please erase blocks before boundary change\n"); |
| 2470 | return ret; |
| 2471 | } |
| 2472 | |
| 2473 | this->command(mtd, FLEXONENAND_CMD_PI_ACCESS, die, 0); |
| 2474 | this->wait(mtd, FL_SYNCING); |
| 2475 | |
| 2476 | /* Check is boundary is locked */ |
| 2477 | this->command(mtd, FLEXONENAND_CMD_READ_PI, die, 0); |
| 2478 | ret = this->wait(mtd, FL_READING); |
| 2479 | |
| 2480 | thisboundary = this->read_word(this->base + ONENAND_DATARAM); |
| 2481 | if ((thisboundary >> FLEXONENAND_PI_UNLOCK_SHIFT) != 3) { |
| 2482 | printk(KERN_ERR "flexonenand_set_boundary: boundary locked\n"); |
| 2483 | goto out; |
| 2484 | } |
| 2485 | |
| 2486 | printk(KERN_INFO "flexonenand_set_boundary: Changing die %d boundary: %d%s\n", |
| 2487 | die, boundary, lock ? "(Locked)" : "(Unlocked)"); |
| 2488 | |
| 2489 | boundary &= FLEXONENAND_PI_MASK; |
| 2490 | boundary |= lock ? 0 : (3 << FLEXONENAND_PI_UNLOCK_SHIFT); |
| 2491 | |
| 2492 | addr = die ? this->diesize[0] : 0; |
| 2493 | this->command(mtd, ONENAND_CMD_ERASE, addr, 0); |
| 2494 | ret = this->wait(mtd, FL_ERASING); |
| 2495 | if (ret) { |
| 2496 | printk("flexonenand_set_boundary:" |
| 2497 | "Failed PI erase for Die %d\n", die); |
| 2498 | goto out; |
| 2499 | } |
| 2500 | |
| 2501 | this->write_word(boundary, this->base + ONENAND_DATARAM); |
| 2502 | this->command(mtd, ONENAND_CMD_PROG, addr, 0); |
| 2503 | ret = this->wait(mtd, FL_WRITING); |
| 2504 | if (ret) { |
| 2505 | printk("flexonenand_set_boundary:" |
| 2506 | "Failed PI write for Die %d\n", die); |
| 2507 | goto out; |
| 2508 | } |
| 2509 | |
| 2510 | this->command(mtd, FLEXONENAND_CMD_PI_UPDATE, die, 0); |
| 2511 | ret = this->wait(mtd, FL_WRITING); |
| 2512 | out: |
| 2513 | this->write_word(ONENAND_CMD_RESET, this->base + ONENAND_REG_COMMAND); |
| 2514 | this->wait(mtd, FL_RESETING); |
| 2515 | if (!ret) |
| 2516 | /* Recalculate device size on boundary change*/ |
| 2517 | flexonenand_get_size(mtd); |
| 2518 | |
| 2519 | return ret; |
| 2520 | } |
| 2521 | |
| 2522 | /** |
Lukasz Majewski | 9d7ba32 | 2011-11-09 11:25:32 +0100 | [diff] [blame] | 2523 | * onenand_chip_probe - [OneNAND Interface] Probe the OneNAND chip |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2524 | * @param mtd MTD device structure |
| 2525 | * |
| 2526 | * OneNAND detection method: |
| 2527 | * Compare the the values from command with ones from register |
| 2528 | */ |
Lukasz Majewski | 9d7ba32 | 2011-11-09 11:25:32 +0100 | [diff] [blame] | 2529 | static int onenand_chip_probe(struct mtd_info *mtd) |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2530 | { |
| 2531 | struct onenand_chip *this = mtd->priv; |
Lukasz Majewski | 9d7ba32 | 2011-11-09 11:25:32 +0100 | [diff] [blame] | 2532 | int bram_maf_id, bram_dev_id, maf_id, dev_id; |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2533 | int syscfg; |
| 2534 | |
| 2535 | /* Save system configuration 1 */ |
| 2536 | syscfg = this->read_word(this->base + ONENAND_REG_SYS_CFG1); |
Lukasz Majewski | 9d7ba32 | 2011-11-09 11:25:32 +0100 | [diff] [blame] | 2537 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2538 | /* Clear Sync. Burst Read mode to read BootRAM */ |
Lukasz Majewski | 9d7ba32 | 2011-11-09 11:25:32 +0100 | [diff] [blame] | 2539 | this->write_word((syscfg & ~ONENAND_SYS_CFG1_SYNC_READ), |
| 2540 | this->base + ONENAND_REG_SYS_CFG1); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2541 | |
| 2542 | /* Send the command for reading device ID from BootRAM */ |
| 2543 | this->write_word(ONENAND_CMD_READID, this->base + ONENAND_BOOTRAM); |
| 2544 | |
| 2545 | /* Read manufacturer and device IDs from BootRAM */ |
| 2546 | bram_maf_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x0); |
| 2547 | bram_dev_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x2); |
| 2548 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2549 | /* Reset OneNAND to read default register values */ |
| 2550 | this->write_word(ONENAND_CMD_RESET, this->base + ONENAND_BOOTRAM); |
| 2551 | |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 2552 | /* Wait reset */ |
Ladislav Michl | 243af2f | 2016-07-12 20:28:19 +0200 | [diff] [blame] | 2553 | if (this->wait(mtd, FL_RESETING)) |
| 2554 | return -ENXIO; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2555 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2556 | /* Restore system configuration 1 */ |
| 2557 | this->write_word(syscfg, this->base + ONENAND_REG_SYS_CFG1); |
| 2558 | |
| 2559 | /* Check manufacturer ID */ |
| 2560 | if (onenand_check_maf(bram_maf_id)) |
| 2561 | return -ENXIO; |
| 2562 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2563 | /* Read manufacturer and device IDs from Register */ |
| 2564 | maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID); |
| 2565 | dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID); |
| 2566 | |
| 2567 | /* Check OneNAND device */ |
| 2568 | if (maf_id != bram_maf_id || dev_id != bram_dev_id) |
| 2569 | return -ENXIO; |
Kyungmin Park | 05d2318 | 2008-03-17 08:54:06 +0900 | [diff] [blame] | 2570 | |
Lukasz Majewski | 9d7ba32 | 2011-11-09 11:25:32 +0100 | [diff] [blame] | 2571 | return 0; |
| 2572 | } |
| 2573 | |
| 2574 | /** |
| 2575 | * onenand_probe - [OneNAND Interface] Probe the OneNAND device |
| 2576 | * @param mtd MTD device structure |
| 2577 | * |
| 2578 | * OneNAND detection method: |
| 2579 | * Compare the the values from command with ones from register |
| 2580 | */ |
| 2581 | int onenand_probe(struct mtd_info *mtd) |
| 2582 | { |
| 2583 | struct onenand_chip *this = mtd->priv; |
Wolfgang Denk | b3efbbf | 2012-04-19 01:14:17 +0000 | [diff] [blame] | 2584 | int dev_id, ver_id; |
Lukasz Majewski | 9d7ba32 | 2011-11-09 11:25:32 +0100 | [diff] [blame] | 2585 | int density; |
| 2586 | int ret; |
| 2587 | |
| 2588 | ret = this->chip_probe(mtd); |
| 2589 | if (ret) |
| 2590 | return ret; |
| 2591 | |
Wolfgang Denk | b3efbbf | 2012-04-19 01:14:17 +0000 | [diff] [blame] | 2592 | /* Read device IDs from Register */ |
Lukasz Majewski | 9d7ba32 | 2011-11-09 11:25:32 +0100 | [diff] [blame] | 2593 | dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID); |
| 2594 | ver_id = this->read_word(this->base + ONENAND_REG_VERSION_ID); |
| 2595 | this->technology = this->read_word(this->base + ONENAND_REG_TECHNOLOGY); |
| 2596 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2597 | /* Flash device information */ |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2598 | mtd->name = onenand_print_device_info(dev_id, ver_id); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2599 | this->device_id = dev_id; |
Stefan Roese | 7c9aafe | 2008-11-11 10:29:09 +0100 | [diff] [blame] | 2600 | this->version_id = ver_id; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2601 | |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 2602 | /* Check OneNAND features */ |
| 2603 | onenand_check_features(mtd); |
| 2604 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2605 | density = onenand_get_density(dev_id); |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2606 | if (FLEXONENAND(this)) { |
| 2607 | this->dies = ONENAND_IS_DDP(this) ? 2 : 1; |
| 2608 | /* Maximum possible erase regions */ |
| 2609 | mtd->numeraseregions = this->dies << 1; |
| 2610 | mtd->eraseregions = malloc(sizeof(struct mtd_erase_region_info) |
| 2611 | * (this->dies << 1)); |
| 2612 | if (!mtd->eraseregions) |
| 2613 | return -ENOMEM; |
| 2614 | } |
| 2615 | |
| 2616 | /* |
| 2617 | * For Flex-OneNAND, chipsize represents maximum possible device size. |
| 2618 | * mtd->size represents the actual device size. |
| 2619 | */ |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2620 | this->chipsize = (16 << density) << 20; |
| 2621 | |
| 2622 | /* OneNAND page size & block size */ |
| 2623 | /* The data buffer size is equal to page size */ |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 2624 | mtd->writesize = |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2625 | this->read_word(this->base + ONENAND_REG_DATA_BUFFER_SIZE); |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2626 | /* We use the full BufferRAM */ |
Lukasz Majewski | 2b4fa32 | 2011-11-09 10:30:06 +0100 | [diff] [blame] | 2627 | if (ONENAND_IS_4KB_PAGE(this)) |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2628 | mtd->writesize <<= 1; |
| 2629 | |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 2630 | mtd->oobsize = mtd->writesize >> 5; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2631 | /* Pagers per block is always 64 in OneNAND */ |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 2632 | mtd->erasesize = mtd->writesize << 6; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2633 | /* |
| 2634 | * Flex-OneNAND SLC area has 64 pages per block. |
| 2635 | * Flex-OneNAND MLC area has 128 pages per block. |
| 2636 | * Expose MLC erase size to find erase_shift and page_mask. |
| 2637 | */ |
| 2638 | if (FLEXONENAND(this)) |
| 2639 | mtd->erasesize <<= 1; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2640 | |
| 2641 | this->erase_shift = ffs(mtd->erasesize) - 1; |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 2642 | this->page_shift = ffs(mtd->writesize) - 1; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2643 | this->ppb_shift = (this->erase_shift - this->page_shift); |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 2644 | this->page_mask = (mtd->erasesize / mtd->writesize) - 1; |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2645 | /* Set density mask. it is used for DDP */ |
| 2646 | if (ONENAND_IS_DDP(this)) |
| 2647 | this->density_mask = this->chipsize >> (this->erase_shift + 1); |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 2648 | /* It's real page size */ |
| 2649 | this->writesize = mtd->writesize; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2650 | |
| 2651 | /* REVIST: Multichip handling */ |
| 2652 | |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2653 | if (FLEXONENAND(this)) |
| 2654 | flexonenand_get_size(mtd); |
| 2655 | else |
| 2656 | mtd->size = this->chipsize; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2657 | |
Pali Rohár | 1b42e85 | 2020-10-31 17:32:50 +0100 | [diff] [blame] | 2658 | mtd->type = ONENAND_IS_MLC(this) ? MTD_MLCNANDFLASH : MTD_NANDFLASH; |
Kyungmin Park | 396b0c4 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 2659 | mtd->flags = MTD_CAP_NANDFLASH; |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 2660 | mtd->_erase = onenand_erase; |
Sergey Lapin | 3a38a55 | 2013-01-14 03:46:50 +0000 | [diff] [blame] | 2661 | mtd->_read_oob = onenand_read_oob; |
| 2662 | mtd->_write_oob = onenand_write_oob; |
| 2663 | mtd->_sync = onenand_sync; |
| 2664 | mtd->_block_isbad = onenand_block_isbad; |
| 2665 | mtd->_block_markbad = onenand_block_markbad; |
Ladislav Michl | 7dbad5c | 2016-07-12 20:28:21 +0200 | [diff] [blame] | 2666 | mtd->writebufsize = mtd->writesize; |
Fathi BOUDRA | 95feb70 | 2008-08-06 10:06:20 +0200 | [diff] [blame] | 2667 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2668 | return 0; |
| 2669 | } |
| 2670 | |
| 2671 | /** |
| 2672 | * onenand_scan - [OneNAND Interface] Scan for the OneNAND device |
| 2673 | * @param mtd MTD device structure |
| 2674 | * @param maxchips Number of chips to scan for |
| 2675 | * |
| 2676 | * This fills out all the not initialized function pointers |
| 2677 | * with the defaults. |
| 2678 | * The flash ID is read and the mtd/chip structures are |
| 2679 | * filled with the appropriate values. |
| 2680 | */ |
| 2681 | int onenand_scan(struct mtd_info *mtd, int maxchips) |
| 2682 | { |
Stefan Roese | db7ce8c | 2008-12-02 11:06:47 +0100 | [diff] [blame] | 2683 | int i; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2684 | struct onenand_chip *this = mtd->priv; |
| 2685 | |
| 2686 | if (!this->read_word) |
| 2687 | this->read_word = onenand_readw; |
| 2688 | if (!this->write_word) |
| 2689 | this->write_word = onenand_writew; |
| 2690 | |
| 2691 | if (!this->command) |
| 2692 | this->command = onenand_command; |
| 2693 | if (!this->wait) |
| 2694 | this->wait = onenand_wait; |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2695 | if (!this->bbt_wait) |
| 2696 | this->bbt_wait = onenand_bbt_wait; |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2697 | |
| 2698 | if (!this->read_bufferram) |
| 2699 | this->read_bufferram = onenand_read_bufferram; |
| 2700 | if (!this->write_bufferram) |
| 2701 | this->write_bufferram = onenand_write_bufferram; |
| 2702 | |
Lukasz Majewski | 9d7ba32 | 2011-11-09 11:25:32 +0100 | [diff] [blame] | 2703 | if (!this->chip_probe) |
| 2704 | this->chip_probe = onenand_chip_probe; |
| 2705 | |
Kyungmin Park | 87b4950 | 2008-11-13 15:14:33 +0900 | [diff] [blame] | 2706 | if (!this->block_markbad) |
| 2707 | this->block_markbad = onenand_default_block_markbad; |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2708 | if (!this->scan_bbt) |
| 2709 | this->scan_bbt = onenand_default_bbt; |
| 2710 | |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2711 | if (onenand_probe(mtd)) |
| 2712 | return -ENXIO; |
| 2713 | |
| 2714 | /* Set Sync. Burst Read after probing */ |
| 2715 | if (this->mmcontrol) { |
| 2716 | printk(KERN_INFO "OneNAND Sync. Burst Read support\n"); |
| 2717 | this->read_bufferram = onenand_sync_read_bufferram; |
| 2718 | } |
| 2719 | |
Kyungmin Park | 5d7a01c | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 2720 | /* Allocate buffers, if necessary */ |
| 2721 | if (!this->page_buf) { |
| 2722 | this->page_buf = kzalloc(mtd->writesize, GFP_KERNEL); |
| 2723 | if (!this->page_buf) { |
| 2724 | printk(KERN_ERR "onenand_scan(): Can't allocate page_buf\n"); |
| 2725 | return -ENOMEM; |
| 2726 | } |
| 2727 | this->options |= ONENAND_PAGEBUF_ALLOC; |
| 2728 | } |
| 2729 | if (!this->oob_buf) { |
| 2730 | this->oob_buf = kzalloc(mtd->oobsize, GFP_KERNEL); |
| 2731 | if (!this->oob_buf) { |
| 2732 | printk(KERN_ERR "onenand_scan: Can't allocate oob_buf\n"); |
| 2733 | if (this->options & ONENAND_PAGEBUF_ALLOC) { |
| 2734 | this->options &= ~ONENAND_PAGEBUF_ALLOC; |
| 2735 | kfree(this->page_buf); |
| 2736 | } |
| 2737 | return -ENOMEM; |
| 2738 | } |
| 2739 | this->options |= ONENAND_OOBBUF_ALLOC; |
| 2740 | } |
| 2741 | |
Stefan Roese | db7ce8c | 2008-12-02 11:06:47 +0100 | [diff] [blame] | 2742 | this->state = FL_READY; |
| 2743 | |
| 2744 | /* |
| 2745 | * Allow subpage writes up to oobsize. |
| 2746 | */ |
| 2747 | switch (mtd->oobsize) { |
Amul Kumar Saha | ed886a2 | 2009-11-06 17:15:31 +0530 | [diff] [blame] | 2748 | case 128: |
| 2749 | this->ecclayout = &onenand_oob_128; |
| 2750 | mtd->subpage_sft = 0; |
| 2751 | break; |
| 2752 | |
Stefan Roese | db7ce8c | 2008-12-02 11:06:47 +0100 | [diff] [blame] | 2753 | case 64: |
| 2754 | this->ecclayout = &onenand_oob_64; |
| 2755 | mtd->subpage_sft = 2; |
| 2756 | break; |
| 2757 | |
| 2758 | case 32: |
| 2759 | this->ecclayout = &onenand_oob_32; |
| 2760 | mtd->subpage_sft = 1; |
| 2761 | break; |
| 2762 | |
| 2763 | default: |
| 2764 | printk(KERN_WARNING "No OOB scheme defined for oobsize %d\n", |
| 2765 | mtd->oobsize); |
| 2766 | mtd->subpage_sft = 0; |
| 2767 | /* To prevent kernel oops */ |
| 2768 | this->ecclayout = &onenand_oob_32; |
| 2769 | break; |
| 2770 | } |
| 2771 | |
| 2772 | this->subpagesize = mtd->writesize >> mtd->subpage_sft; |
| 2773 | |
| 2774 | /* |
| 2775 | * The number of bytes available for a client to place data into |
| 2776 | * the out of band area |
| 2777 | */ |
| 2778 | this->ecclayout->oobavail = 0; |
Prabhakar Kushwaha | 4d2ba17 | 2013-10-04 13:47:58 +0530 | [diff] [blame] | 2779 | |
| 2780 | for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES_LARGE && |
Stefan Roese | db7ce8c | 2008-12-02 11:06:47 +0100 | [diff] [blame] | 2781 | this->ecclayout->oobfree[i].length; i++) |
| 2782 | this->ecclayout->oobavail += |
| 2783 | this->ecclayout->oobfree[i].length; |
| 2784 | mtd->oobavail = this->ecclayout->oobavail; |
| 2785 | |
| 2786 | mtd->ecclayout = this->ecclayout; |
| 2787 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2788 | /* Unlock whole block */ |
| 2789 | onenand_unlock_all(mtd); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2790 | |
Kyungmin Park | dc7a79c | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 2791 | return this->scan_bbt(mtd); |
Kyungmin Park | 79e9046 | 2007-09-10 17:13:49 +0900 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | /** |
| 2795 | * onenand_release - [OneNAND Interface] Free resources held by the OneNAND device |
| 2796 | * @param mtd MTD device structure |
| 2797 | */ |
| 2798 | void onenand_release(struct mtd_info *mtd) |
| 2799 | { |
| 2800 | } |