Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/include/linux/mtd/onenand.h |
| 3 | * |
Amul Kumar Saha | 3cf6025 | 2009-10-21 17:00:05 +0530 | [diff] [blame] | 4 | * Copyright © 2005-2009 Samsung Electronics |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 5 | * Kyungmin Park <kyungmin.park@samsung.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #ifndef __LINUX_MTD_ONENAND_H |
| 13 | #define __LINUX_MTD_ONENAND_H |
| 14 | |
| 15 | #include <linux/spinlock.h> |
Kyungmin Park | 2c22120 | 2006-11-16 11:23:48 +0900 | [diff] [blame] | 16 | #include <linux/completion.h> |
Alessandro Rubini | 30631cb | 2009-09-20 23:28:14 +0200 | [diff] [blame] | 17 | #include <linux/mtd/flashchip.h> |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 18 | #include <linux/mtd/onenand_regs.h> |
Kyungmin Park | cdc0013 | 2005-09-03 07:15:48 +0100 | [diff] [blame] | 19 | #include <linux/mtd/bbm.h> |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 20 | |
Rohit Hagargundgi | 5988af2 | 2009-05-12 13:46:57 -0700 | [diff] [blame] | 21 | #define MAX_DIES 2 |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 22 | #define MAX_BUFFERRAM 2 |
| 23 | |
| 24 | /* Scan and identify a OneNAND device */ |
| 25 | extern int onenand_scan(struct mtd_info *mtd, int max_chips); |
| 26 | /* Free resources held by the OneNAND device */ |
| 27 | extern void onenand_release(struct mtd_info *mtd); |
| 28 | |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 29 | /** |
| 30 | * struct onenand_bufferram - OneNAND BufferRAM Data |
Kyungmin Park | abf3c0f | 2007-02-02 09:29:36 +0900 | [diff] [blame] | 31 | * @blockpage: block & page address in BufferRAM |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 32 | */ |
| 33 | struct onenand_bufferram { |
Kyungmin Park | abf3c0f | 2007-02-02 09:29:36 +0900 | [diff] [blame] | 34 | int blockpage; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | /** |
| 38 | * struct onenand_chip - OneNAND Private Flash Chip Data |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 39 | * @base: [BOARDSPECIFIC] address to access OneNAND |
Rohit Hagargundgi | 5988af2 | 2009-05-12 13:46:57 -0700 | [diff] [blame] | 40 | * @dies: [INTERN][FLEX-ONENAND] number of dies on chip |
| 41 | * @boundary: [INTERN][FLEX-ONENAND] Boundary of the dies |
| 42 | * @diesize: [INTERN][FLEX-ONENAND] Size of the dies |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 43 | * @chipsize: [INTERN] the size of one chip for multichip arrays |
Rohit Hagargundgi | 5988af2 | 2009-05-12 13:46:57 -0700 | [diff] [blame] | 44 | * FIXME For Flex-OneNAND, chipsize holds maximum possible |
| 45 | * device size ie when all blocks are considered MLC |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 46 | * @device_id: [INTERN] device ID |
| 47 | * @density_mask: chip density, used for DDP devices |
| 48 | * @verstion_id: [INTERN] version ID |
| 49 | * @options: [BOARDSPECIFIC] various chip options. They can |
| 50 | * partly be set to inform onenand_scan about |
| 51 | * @erase_shift: [INTERN] number of address bits in a block |
| 52 | * @page_shift: [INTERN] number of address bits in a page |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 53 | * @page_mask: [INTERN] a page per block mask |
Kyungmin Park | ee9745f | 2007-06-30 13:57:49 +0900 | [diff] [blame] | 54 | * @writesize: [INTERN] a real page size |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 55 | * @bufferram_index: [INTERN] BufferRAM index |
| 56 | * @bufferram: [INTERN] BufferRAM info |
| 57 | * @readw: [REPLACEABLE] hardware specific function for read short |
| 58 | * @writew: [REPLACEABLE] hardware specific function for write short |
| 59 | * @command: [REPLACEABLE] hardware specific function for writing |
| 60 | * commands to the chip |
| 61 | * @wait: [REPLACEABLE] hardware specific function for wait on ready |
Kyungmin Park | 31bb999 | 2009-05-12 13:46:57 -0700 | [diff] [blame] | 62 | * @bbt_wait: [REPLACEABLE] hardware specific function for bbt wait on ready |
| 63 | * @unlock_all: [REPLACEABLE] hardware specific function for unlock all |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 64 | * @read_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area |
| 65 | * @write_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area |
| 66 | * @read_word: [REPLACEABLE] hardware specific function for read |
| 67 | * register of OneNAND |
| 68 | * @write_word: [REPLACEABLE] hardware specific function for write |
| 69 | * register of OneNAND |
| 70 | * @mmcontrol: sync burst read function |
Kyungmin Park | ad0d363 | 2010-05-28 11:03:11 +0900 | [diff] [blame] | 71 | * @chip_probe: [REPLACEABLE] hardware specific function for chip probe |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 72 | * @block_markbad: function to mark a block as bad |
| 73 | * @scan_bbt: [REPLACEALBE] hardware specific function for scanning |
| 74 | * Bad block Table |
| 75 | * @chip_lock: [INTERN] spinlock used to protect access to this |
| 76 | * structure and the chip |
| 77 | * @wq: [INTERN] wait queue to sleep on if a OneNAND |
| 78 | * operation is in progress |
| 79 | * @state: [INTERN] the current state of the OneNAND device |
Kyungmin Park | 470bc84 | 2007-03-09 10:08:11 +0900 | [diff] [blame] | 80 | * @page_buf: [INTERN] page main data buffer |
| 81 | * @oob_buf: [INTERN] page oob data buffer |
Kyungmin Park | 60d84f9 | 2006-12-22 16:21:54 +0900 | [diff] [blame] | 82 | * @subpagesize: [INTERN] holds the subpagesize |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 83 | * @ecclayout: [REPLACEABLE] the default ecc placement scheme |
| 84 | * @bbm: [REPLACEABLE] pointer to Bad Block Management |
| 85 | * @priv: [OPTIONAL] pointer to private chip date |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 86 | */ |
| 87 | struct onenand_chip { |
| 88 | void __iomem *base; |
Rohit Hagargundgi | 5988af2 | 2009-05-12 13:46:57 -0700 | [diff] [blame] | 89 | unsigned dies; |
| 90 | unsigned boundary[MAX_DIES]; |
| 91 | loff_t diesize[MAX_DIES]; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 92 | unsigned int chipsize; |
| 93 | unsigned int device_id; |
Kyungmin Park | 28b79ff | 2006-09-26 09:45:28 +0000 | [diff] [blame] | 94 | unsigned int version_id; |
Rohit Hagargundgi | 5988af2 | 2009-05-12 13:46:57 -0700 | [diff] [blame] | 95 | unsigned int technology; |
Kyungmin Park | 83a3683 | 2005-09-29 04:53:16 +0100 | [diff] [blame] | 96 | unsigned int density_mask; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 97 | unsigned int options; |
| 98 | |
| 99 | unsigned int erase_shift; |
| 100 | unsigned int page_shift; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 101 | unsigned int page_mask; |
Kyungmin Park | ee9745f | 2007-06-30 13:57:49 +0900 | [diff] [blame] | 102 | unsigned int writesize; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 103 | |
| 104 | unsigned int bufferram_index; |
| 105 | struct onenand_bufferram bufferram[MAX_BUFFERRAM]; |
| 106 | |
| 107 | int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len); |
| 108 | int (*wait)(struct mtd_info *mtd, int state); |
Kyungmin Park | 31bb999 | 2009-05-12 13:46:57 -0700 | [diff] [blame] | 109 | int (*bbt_wait)(struct mtd_info *mtd, int state); |
| 110 | void (*unlock_all)(struct mtd_info *mtd); |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 111 | int (*read_bufferram)(struct mtd_info *mtd, int area, |
| 112 | unsigned char *buffer, int offset, size_t count); |
| 113 | int (*write_bufferram)(struct mtd_info *mtd, int area, |
| 114 | const unsigned char *buffer, int offset, size_t count); |
| 115 | unsigned short (*read_word)(void __iomem *addr); |
| 116 | void (*write_word)(unsigned short value, void __iomem *addr); |
Kyungmin Park | 52b0eea | 2005-09-03 07:07:19 +0100 | [diff] [blame] | 117 | void (*mmcontrol)(struct mtd_info *mtd, int sync_read); |
Kyungmin Park | ad0d363 | 2010-05-28 11:03:11 +0900 | [diff] [blame] | 118 | int (*chip_probe)(struct mtd_info *mtd); |
Kyungmin Park | cdc0013 | 2005-09-03 07:15:48 +0100 | [diff] [blame] | 119 | int (*block_markbad)(struct mtd_info *mtd, loff_t ofs); |
| 120 | int (*scan_bbt)(struct mtd_info *mtd); |
Adrian Hunter | cf24dc8 | 2010-02-19 15:39:52 +0100 | [diff] [blame] | 121 | int (*enable)(struct mtd_info *mtd); |
| 122 | int (*disable)(struct mtd_info *mtd); |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 123 | |
Kyungmin Park | 2c22120 | 2006-11-16 11:23:48 +0900 | [diff] [blame] | 124 | struct completion complete; |
| 125 | int irq; |
| 126 | |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 127 | spinlock_t chip_lock; |
| 128 | wait_queue_head_t wq; |
Alessandro Rubini | 30631cb | 2009-09-20 23:28:14 +0200 | [diff] [blame] | 129 | flstate_t state; |
Kyungmin Park | 532a37c | 2005-12-16 11:17:29 +0900 | [diff] [blame] | 130 | unsigned char *page_buf; |
Kyungmin Park | 470bc84 | 2007-03-09 10:08:11 +0900 | [diff] [blame] | 131 | unsigned char *oob_buf; |
Kyungmin Park | 4a8ce0b | 2010-04-28 17:46:46 +0200 | [diff] [blame] | 132 | #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE |
| 133 | unsigned char *verify_buf; |
| 134 | #endif |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 135 | |
Kyungmin Park | 60d84f9 | 2006-12-22 16:21:54 +0900 | [diff] [blame] | 136 | int subpagesize; |
Thomas Gleixner | 5bd34c0 | 2006-05-27 22:16:10 +0200 | [diff] [blame] | 137 | struct nand_ecclayout *ecclayout; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 138 | |
Thomas Gleixner | 5bd34c0 | 2006-05-27 22:16:10 +0200 | [diff] [blame] | 139 | void *bbm; |
Kyungmin Park | cdc0013 | 2005-09-03 07:15:48 +0100 | [diff] [blame] | 140 | |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 141 | void *priv; |
Roman Tereshonkov | 3e3198f | 2010-11-03 12:55:19 +0200 | [diff] [blame] | 142 | |
| 143 | /* |
| 144 | * Shows that the current operation is composed |
| 145 | * of sequence of commands. For example, cache program. |
| 146 | * Such command status OnGo bit is checked at the end of |
| 147 | * sequence. |
| 148 | */ |
| 149 | unsigned int ongoing; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 150 | }; |
| 151 | |
Kyungmin Park | fcc3147 | 2005-09-03 07:20:08 +0100 | [diff] [blame] | 152 | /* |
| 153 | * Helper macros |
| 154 | */ |
Amul Kumar Saha | 3cf6025 | 2009-10-21 17:00:05 +0530 | [diff] [blame] | 155 | #define ONENAND_PAGES_PER_BLOCK (1<<6) |
| 156 | |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 157 | #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index) |
| 158 | #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1) |
| 159 | #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1) |
Adrian Hunter | a8de85d | 2007-01-04 09:51:26 +0200 | [diff] [blame] | 160 | #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1) |
Kyungmin Park | ee9745f | 2007-06-30 13:57:49 +0900 | [diff] [blame] | 161 | #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0) |
| 162 | #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1) |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 163 | |
Rohit Hagargundgi | 5988af2 | 2009-05-12 13:46:57 -0700 | [diff] [blame] | 164 | #define FLEXONENAND(this) \ |
| 165 | (this->device_id & DEVICE_IS_FLEXONENAND) |
Kyungmin Park | fcc3147 | 2005-09-03 07:20:08 +0100 | [diff] [blame] | 166 | #define ONENAND_GET_SYS_CFG1(this) \ |
| 167 | (this->read_word(this->base + ONENAND_REG_SYS_CFG1)) |
| 168 | #define ONENAND_SET_SYS_CFG1(v, this) \ |
| 169 | (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1)) |
| 170 | |
Kyungmin Park | 738d61f | 2007-01-15 17:09:14 +0900 | [diff] [blame] | 171 | #define ONENAND_IS_DDP(this) \ |
| 172 | (this->device_id & ONENAND_DEVICE_IS_DDP) |
| 173 | |
Rohit Hagargundgi | 5988af2 | 2009-05-12 13:46:57 -0700 | [diff] [blame] | 174 | #define ONENAND_IS_MLC(this) \ |
| 175 | (this->technology & ONENAND_TECHNOLOGY_IS_MLC) |
| 176 | |
Kyungmin Park | ee9745f | 2007-06-30 13:57:49 +0900 | [diff] [blame] | 177 | #ifdef CONFIG_MTD_ONENAND_2X_PROGRAM |
| 178 | #define ONENAND_IS_2PLANE(this) \ |
| 179 | (this->options & ONENAND_HAS_2PLANE) |
| 180 | #else |
| 181 | #define ONENAND_IS_2PLANE(this) (0) |
| 182 | #endif |
| 183 | |
Roman Tereshonkov | 3e3198f | 2010-11-03 12:55:19 +0200 | [diff] [blame] | 184 | #define ONENAND_IS_CACHE_PROGRAM(this) \ |
| 185 | (this->options & ONENAND_HAS_CACHE_PROGRAM) |
| 186 | |
Kyungmin Park | e1c1024 | 2011-06-22 14:16:49 +0900 | [diff] [blame] | 187 | #define ONENAND_IS_NOP_1(this) \ |
| 188 | (this->options & ONENAND_HAS_NOP_1) |
| 189 | |
Kyungmin Park | 9c01f87d | 2006-05-12 17:02:31 +0300 | [diff] [blame] | 190 | /* Check byte access in OneNAND */ |
| 191 | #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1) |
| 192 | |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 193 | /* |
| 194 | * Options bits |
| 195 | */ |
Kyungmin Park | 28b79ff | 2006-09-26 09:45:28 +0000 | [diff] [blame] | 196 | #define ONENAND_HAS_CONT_LOCK (0x0001) |
| 197 | #define ONENAND_HAS_UNLOCK_ALL (0x0002) |
Kyungmin Park | ee9745f | 2007-06-30 13:57:49 +0900 | [diff] [blame] | 198 | #define ONENAND_HAS_2PLANE (0x0004) |
Kyungmin Park | 6a88c47 | 2010-04-28 17:46:45 +0200 | [diff] [blame] | 199 | #define ONENAND_HAS_4KB_PAGE (0x0008) |
Roman Tereshonkov | 3e3198f | 2010-11-03 12:55:19 +0200 | [diff] [blame] | 200 | #define ONENAND_HAS_CACHE_PROGRAM (0x0010) |
Kyungmin Park | e1c1024 | 2011-06-22 14:16:49 +0900 | [diff] [blame] | 201 | #define ONENAND_HAS_NOP_1 (0x0020) |
Kyungmin Park | 31bb999 | 2009-05-12 13:46:57 -0700 | [diff] [blame] | 202 | #define ONENAND_SKIP_UNLOCK_CHECK (0x0100) |
Kyungmin Park | 532a37c | 2005-12-16 11:17:29 +0900 | [diff] [blame] | 203 | #define ONENAND_PAGEBUF_ALLOC (0x1000) |
Kyungmin Park | 470bc84 | 2007-03-09 10:08:11 +0900 | [diff] [blame] | 204 | #define ONENAND_OOBBUF_ALLOC (0x2000) |
Roman Tereshonkov | b3dcfd35 | 2011-02-17 13:44:41 +0200 | [diff] [blame] | 205 | #define ONENAND_SKIP_INITIAL_UNLOCKING (0x4000) |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 206 | |
Kyungmin Park | 6a88c47 | 2010-04-28 17:46:45 +0200 | [diff] [blame] | 207 | #define ONENAND_IS_4KB_PAGE(this) \ |
| 208 | (this->options & ONENAND_HAS_4KB_PAGE) |
| 209 | |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 210 | /* |
| 211 | * OneNAND Flash Manufacturer ID Codes |
| 212 | */ |
| 213 | #define ONENAND_MFR_SAMSUNG 0xec |
Adrian Hunter | ee8f376 | 2009-05-05 11:04:19 +0300 | [diff] [blame] | 214 | #define ONENAND_MFR_NUMONYX 0x20 |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 215 | |
| 216 | /** |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 217 | * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure |
| 218 | * @name: Manufacturer name |
| 219 | * @id: manufacturer ID code of device. |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 220 | */ |
| 221 | struct onenand_manufacturers { |
| 222 | int id; |
| 223 | char *name; |
| 224 | }; |
| 225 | |
Adrian Bunk | 607d1cb | 2008-04-14 17:20:38 +0300 | [diff] [blame] | 226 | int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from, |
| 227 | struct mtd_oob_ops *ops); |
Rohit Hagargundgi | 5988af2 | 2009-05-12 13:46:57 -0700 | [diff] [blame] | 228 | unsigned onenand_block(struct onenand_chip *this, loff_t addr); |
| 229 | loff_t onenand_addr(struct onenand_chip *this, int block); |
| 230 | int flexonenand_region(struct mtd_info *mtd, loff_t addr); |
Adrian Bunk | 607d1cb | 2008-04-14 17:20:38 +0300 | [diff] [blame] | 231 | |
Magnus Damm | 778dbcc | 2009-09-18 12:51:44 -0700 | [diff] [blame] | 232 | struct mtd_partition; |
| 233 | |
| 234 | struct onenand_platform_data { |
| 235 | void (*mmcontrol)(struct mtd_info *mtd, int sync_read); |
Kyungmin Park | 3328dc3 | 2010-04-28 17:46:47 +0200 | [diff] [blame] | 236 | int (*read_bufferram)(struct mtd_info *mtd, int area, |
| 237 | unsigned char *buffer, int offset, size_t count); |
Magnus Damm | 778dbcc | 2009-09-18 12:51:44 -0700 | [diff] [blame] | 238 | struct mtd_partition *parts; |
| 239 | unsigned int nr_parts; |
| 240 | }; |
| 241 | |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 242 | #endif /* __LINUX_MTD_ONENAND_H */ |