1 /* 2 * linux/include/linux/mtd/onenand.h 3 * 4 * Copyright © 2005-2009 Samsung Electronics 5 * Kyungmin Park <[email protected]> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 */ 11 12 #ifndef __LINUX_MTD_ONENAND_H 13 #define __LINUX_MTD_ONENAND_H 14 15 #include <linux/spinlock.h> 16 #include <linux/completion.h> 17 #include <linux/mtd/flashchip.h> 18 #include <linux/mtd/onenand_regs.h> 19 #include <linux/mtd/bbm.h> 20 21 #define MAX_DIES 2 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 29 /** 30 * struct onenand_bufferram - OneNAND BufferRAM Data 31 * @blockpage: block & page address in BufferRAM 32 */ 33 struct onenand_bufferram { 34 int blockpage; 35 }; 36 37 /** 38 * struct onenand_chip - OneNAND Private Flash Chip Data 39 * @base: [BOARDSPECIFIC] address to access OneNAND 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 43 * @chipsize: [INTERN] the size of one chip for multichip arrays 44 * FIXME For Flex-OneNAND, chipsize holds maximum possible 45 * device size ie when all blocks are considered MLC 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 53 * @page_mask: [INTERN] a page per block mask 54 * @writesize: [INTERN] a real page size 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 62 * @bbt_wait: [REPLACEABLE] hardware specific function for bbt wait on ready 63 * @unlock_all: [REPLACEABLE] hardware specific function for unlock all 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 71 * @chip_probe: [REPLACEABLE] hardware specific function for chip probe 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 80 * @page_buf: [INTERN] page main data buffer 81 * @oob_buf: [INTERN] page oob data buffer 82 * @subpagesize: [INTERN] holds the subpagesize 83 * @bbm: [REPLACEABLE] pointer to Bad Block Management 84 * @priv: [OPTIONAL] pointer to private chip date 85 */ 86 struct onenand_chip { 87 void __iomem *base; 88 unsigned dies; 89 unsigned boundary[MAX_DIES]; 90 loff_t diesize[MAX_DIES]; 91 unsigned int chipsize; 92 unsigned int device_id; 93 unsigned int version_id; 94 unsigned int technology; 95 unsigned int density_mask; 96 unsigned int options; 97 unsigned int badblockpos; 98 99 unsigned int erase_shift; 100 unsigned int page_shift; 101 unsigned int page_mask; 102 unsigned int writesize; 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); 109 int (*bbt_wait)(struct mtd_info *mtd, int state); 110 void (*unlock_all)(struct mtd_info *mtd); 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); 117 void (*mmcontrol)(struct mtd_info *mtd, int sync_read); 118 int (*chip_probe)(struct mtd_info *mtd); 119 int (*block_markbad)(struct mtd_info *mtd, loff_t ofs); 120 int (*scan_bbt)(struct mtd_info *mtd); 121 int (*enable)(struct mtd_info *mtd); 122 int (*disable)(struct mtd_info *mtd); 123 124 struct completion complete; 125 int irq; 126 127 spinlock_t chip_lock; 128 wait_queue_head_t wq; 129 flstate_t state; 130 unsigned char *page_buf; 131 unsigned char *oob_buf; 132 #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE 133 unsigned char *verify_buf; 134 #endif 135 136 int subpagesize; 137 138 void *bbm; 139 140 void *priv; 141 142 /* 143 * Shows that the current operation is composed 144 * of sequence of commands. For example, cache program. 145 * Such command status OnGo bit is checked at the end of 146 * sequence. 147 */ 148 unsigned int ongoing; 149 }; 150 151 /* 152 * Helper macros 153 */ 154 #define ONENAND_PAGES_PER_BLOCK (1<<6) 155 156 #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index) 157 #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1) 158 #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1) 159 #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1) 160 #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0) 161 #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1) 162 163 #define FLEXONENAND(this) \ 164 (this->device_id & DEVICE_IS_FLEXONENAND) 165 #define ONENAND_GET_SYS_CFG1(this) \ 166 (this->read_word(this->base + ONENAND_REG_SYS_CFG1)) 167 #define ONENAND_SET_SYS_CFG1(v, this) \ 168 (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1)) 169 170 #define ONENAND_IS_DDP(this) \ 171 (this->device_id & ONENAND_DEVICE_IS_DDP) 172 173 #define ONENAND_IS_MLC(this) \ 174 (this->technology & ONENAND_TECHNOLOGY_IS_MLC) 175 176 #ifdef CONFIG_MTD_ONENAND_2X_PROGRAM 177 #define ONENAND_IS_2PLANE(this) \ 178 (this->options & ONENAND_HAS_2PLANE) 179 #else 180 #define ONENAND_IS_2PLANE(this) (0) 181 #endif 182 183 #define ONENAND_IS_CACHE_PROGRAM(this) \ 184 (this->options & ONENAND_HAS_CACHE_PROGRAM) 185 186 #define ONENAND_IS_NOP_1(this) \ 187 (this->options & ONENAND_HAS_NOP_1) 188 189 /* Check byte access in OneNAND */ 190 #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1) 191 192 #define ONENAND_BADBLOCK_POS 0 193 194 /* 195 * Options bits 196 */ 197 #define ONENAND_HAS_CONT_LOCK (0x0001) 198 #define ONENAND_HAS_UNLOCK_ALL (0x0002) 199 #define ONENAND_HAS_2PLANE (0x0004) 200 #define ONENAND_HAS_4KB_PAGE (0x0008) 201 #define ONENAND_HAS_CACHE_PROGRAM (0x0010) 202 #define ONENAND_HAS_NOP_1 (0x0020) 203 #define ONENAND_SKIP_UNLOCK_CHECK (0x0100) 204 #define ONENAND_PAGEBUF_ALLOC (0x1000) 205 #define ONENAND_OOBBUF_ALLOC (0x2000) 206 #define ONENAND_SKIP_INITIAL_UNLOCKING (0x4000) 207 208 #define ONENAND_IS_4KB_PAGE(this) \ 209 (this->options & ONENAND_HAS_4KB_PAGE) 210 211 /* 212 * OneNAND Flash Manufacturer ID Codes 213 */ 214 #define ONENAND_MFR_SAMSUNG 0xec 215 #define ONENAND_MFR_NUMONYX 0x20 216 217 /** 218 * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure 219 * @name: Manufacturer name 220 * @id: manufacturer ID code of device. 221 */ 222 struct onenand_manufacturers { 223 int id; 224 char *name; 225 }; 226 227 int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from, 228 struct mtd_oob_ops *ops); 229 unsigned onenand_block(struct onenand_chip *this, loff_t addr); 230 loff_t onenand_addr(struct onenand_chip *this, int block); 231 int flexonenand_region(struct mtd_info *mtd, loff_t addr); 232 233 struct mtd_partition; 234 235 struct onenand_platform_data { 236 void (*mmcontrol)(struct mtd_info *mtd, int sync_read); 237 int (*read_bufferram)(struct mtd_info *mtd, int area, 238 unsigned char *buffer, int offset, size_t count); 239 struct mtd_partition *parts; 240 unsigned int nr_parts; 241 }; 242 243 #endif /* __LINUX_MTD_ONENAND_H */ 244