Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/include/linux/mtd/onenand.h |
| 3 | * |
Kyungmin Park | 75384b0 | 2007-01-18 11:10:57 +0900 | [diff] [blame] | 4 | * Copyright (C) 2005-2007 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> |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 17 | #include <linux/mtd/onenand_regs.h> |
Kyungmin Park | cdc0013 | 2005-09-03 07:15:48 +0100 | [diff] [blame] | 18 | #include <linux/mtd/bbm.h> |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 19 | |
| 20 | #define MAX_BUFFERRAM 2 |
| 21 | |
| 22 | /* Scan and identify a OneNAND device */ |
| 23 | extern int onenand_scan(struct mtd_info *mtd, int max_chips); |
| 24 | /* Free resources held by the OneNAND device */ |
| 25 | extern void onenand_release(struct mtd_info *mtd); |
| 26 | |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 27 | /* |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 28 | * onenand_state_t - chip states |
| 29 | * Enumeration for OneNAND flash chip state |
| 30 | */ |
| 31 | typedef enum { |
| 32 | FL_READY, |
| 33 | FL_READING, |
| 34 | FL_WRITING, |
| 35 | FL_ERASING, |
| 36 | FL_SYNCING, |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 37 | FL_LOCKING, |
Kyungmin Park | 493c646 | 2006-05-12 17:03:07 +0300 | [diff] [blame] | 38 | FL_RESETING, |
| 39 | FL_OTPING, |
Kyungmin Park | a41371e | 2005-09-29 03:55:31 +0100 | [diff] [blame] | 40 | FL_PM_SUSPENDED, |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 41 | } onenand_state_t; |
| 42 | |
| 43 | /** |
| 44 | * struct onenand_bufferram - OneNAND BufferRAM Data |
Kyungmin Park | abf3c0f | 2007-02-02 09:29:36 +0900 | [diff] [blame] | 45 | * @blockpage: block & page address in BufferRAM |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 46 | */ |
| 47 | struct onenand_bufferram { |
Kyungmin Park | abf3c0f | 2007-02-02 09:29:36 +0900 | [diff] [blame] | 48 | int blockpage; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | /** |
| 52 | * struct onenand_chip - OneNAND Private Flash Chip Data |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 53 | * @base: [BOARDSPECIFIC] address to access OneNAND |
| 54 | * @chipsize: [INTERN] the size of one chip for multichip arrays |
| 55 | * @device_id: [INTERN] device ID |
| 56 | * @density_mask: chip density, used for DDP devices |
| 57 | * @verstion_id: [INTERN] version ID |
| 58 | * @options: [BOARDSPECIFIC] various chip options. They can |
| 59 | * partly be set to inform onenand_scan about |
| 60 | * @erase_shift: [INTERN] number of address bits in a block |
| 61 | * @page_shift: [INTERN] number of address bits in a page |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 62 | * @page_mask: [INTERN] a page per block mask |
Kyungmin Park | ee9745f | 2007-06-30 13:57:49 +0900 | [diff] [blame] | 63 | * @writesize: [INTERN] a real page size |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 64 | * @bufferram_index: [INTERN] BufferRAM index |
| 65 | * @bufferram: [INTERN] BufferRAM info |
| 66 | * @readw: [REPLACEABLE] hardware specific function for read short |
| 67 | * @writew: [REPLACEABLE] hardware specific function for write short |
| 68 | * @command: [REPLACEABLE] hardware specific function for writing |
| 69 | * commands to the chip |
| 70 | * @wait: [REPLACEABLE] hardware specific function for wait on ready |
| 71 | * @read_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area |
| 72 | * @write_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area |
| 73 | * @read_word: [REPLACEABLE] hardware specific function for read |
| 74 | * register of OneNAND |
| 75 | * @write_word: [REPLACEABLE] hardware specific function for write |
| 76 | * register of OneNAND |
| 77 | * @mmcontrol: sync burst read function |
| 78 | * @block_markbad: function to mark a block as bad |
| 79 | * @scan_bbt: [REPLACEALBE] hardware specific function for scanning |
| 80 | * Bad block Table |
| 81 | * @chip_lock: [INTERN] spinlock used to protect access to this |
| 82 | * structure and the chip |
| 83 | * @wq: [INTERN] wait queue to sleep on if a OneNAND |
| 84 | * operation is in progress |
| 85 | * @state: [INTERN] the current state of the OneNAND device |
Kyungmin Park | 470bc84 | 2007-03-09 10:08:11 +0900 | [diff] [blame] | 86 | * @page_buf: [INTERN] page main data buffer |
| 87 | * @oob_buf: [INTERN] page oob data buffer |
Kyungmin Park | 60d84f9 | 2006-12-22 16:21:54 +0900 | [diff] [blame] | 88 | * @subpagesize: [INTERN] holds the subpagesize |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 89 | * @ecclayout: [REPLACEABLE] the default ecc placement scheme |
| 90 | * @bbm: [REPLACEABLE] pointer to Bad Block Management |
| 91 | * @priv: [OPTIONAL] pointer to private chip date |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 92 | */ |
| 93 | struct onenand_chip { |
| 94 | void __iomem *base; |
| 95 | unsigned int chipsize; |
| 96 | unsigned int device_id; |
Kyungmin Park | 28b79ff | 2006-09-26 09:45:28 +0000 | [diff] [blame] | 97 | unsigned int version_id; |
Kyungmin Park | 83a3683 | 2005-09-29 04:53:16 +0100 | [diff] [blame] | 98 | unsigned int density_mask; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 99 | unsigned int options; |
| 100 | |
| 101 | unsigned int erase_shift; |
| 102 | unsigned int page_shift; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 103 | unsigned int page_mask; |
Kyungmin Park | ee9745f | 2007-06-30 13:57:49 +0900 | [diff] [blame] | 104 | unsigned int writesize; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 105 | |
| 106 | unsigned int bufferram_index; |
| 107 | struct onenand_bufferram bufferram[MAX_BUFFERRAM]; |
| 108 | |
| 109 | int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len); |
| 110 | int (*wait)(struct mtd_info *mtd, int state); |
| 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 | cdc0013 | 2005-09-03 07:15:48 +0100 | [diff] [blame] | 118 | int (*block_markbad)(struct mtd_info *mtd, loff_t ofs); |
| 119 | int (*scan_bbt)(struct mtd_info *mtd); |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 120 | |
Kyungmin Park | 2c22120 | 2006-11-16 11:23:48 +0900 | [diff] [blame] | 121 | struct completion complete; |
| 122 | int irq; |
| 123 | |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 124 | spinlock_t chip_lock; |
| 125 | wait_queue_head_t wq; |
| 126 | onenand_state_t state; |
Kyungmin Park | 532a37c | 2005-12-16 11:17:29 +0900 | [diff] [blame] | 127 | unsigned char *page_buf; |
Kyungmin Park | 470bc84 | 2007-03-09 10:08:11 +0900 | [diff] [blame] | 128 | unsigned char *oob_buf; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 129 | |
Kyungmin Park | 60d84f9 | 2006-12-22 16:21:54 +0900 | [diff] [blame] | 130 | int subpagesize; |
Thomas Gleixner | 5bd34c0 | 2006-05-27 22:16:10 +0200 | [diff] [blame] | 131 | struct nand_ecclayout *ecclayout; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 132 | |
Thomas Gleixner | 5bd34c0 | 2006-05-27 22:16:10 +0200 | [diff] [blame] | 133 | void *bbm; |
Kyungmin Park | cdc0013 | 2005-09-03 07:15:48 +0100 | [diff] [blame] | 134 | |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 135 | void *priv; |
| 136 | }; |
| 137 | |
Kyungmin Park | fcc3147 | 2005-09-03 07:20:08 +0100 | [diff] [blame] | 138 | /* |
| 139 | * Helper macros |
| 140 | */ |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 141 | #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index) |
| 142 | #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1) |
| 143 | #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1) |
Adrian Hunter | a8de85d | 2007-01-04 09:51:26 +0200 | [diff] [blame] | 144 | #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1) |
Kyungmin Park | ee9745f | 2007-06-30 13:57:49 +0900 | [diff] [blame] | 145 | #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0) |
| 146 | #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1) |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 147 | |
Kyungmin Park | fcc3147 | 2005-09-03 07:20:08 +0100 | [diff] [blame] | 148 | #define ONENAND_GET_SYS_CFG1(this) \ |
| 149 | (this->read_word(this->base + ONENAND_REG_SYS_CFG1)) |
| 150 | #define ONENAND_SET_SYS_CFG1(v, this) \ |
| 151 | (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1)) |
| 152 | |
Kyungmin Park | 738d61f | 2007-01-15 17:09:14 +0900 | [diff] [blame] | 153 | #define ONENAND_IS_DDP(this) \ |
| 154 | (this->device_id & ONENAND_DEVICE_IS_DDP) |
| 155 | |
Kyungmin Park | ee9745f | 2007-06-30 13:57:49 +0900 | [diff] [blame] | 156 | #ifdef CONFIG_MTD_ONENAND_2X_PROGRAM |
| 157 | #define ONENAND_IS_2PLANE(this) \ |
| 158 | (this->options & ONENAND_HAS_2PLANE) |
| 159 | #else |
| 160 | #define ONENAND_IS_2PLANE(this) (0) |
| 161 | #endif |
| 162 | |
Kyungmin Park | 9c01f87 | 2006-05-12 17:02:31 +0300 | [diff] [blame] | 163 | /* Check byte access in OneNAND */ |
| 164 | #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1) |
| 165 | |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 166 | /* |
| 167 | * Options bits |
| 168 | */ |
Kyungmin Park | 28b79ff | 2006-09-26 09:45:28 +0000 | [diff] [blame] | 169 | #define ONENAND_HAS_CONT_LOCK (0x0001) |
| 170 | #define ONENAND_HAS_UNLOCK_ALL (0x0002) |
Kyungmin Park | ee9745f | 2007-06-30 13:57:49 +0900 | [diff] [blame] | 171 | #define ONENAND_HAS_2PLANE (0x0004) |
Kyungmin Park | 532a37c | 2005-12-16 11:17:29 +0900 | [diff] [blame] | 172 | #define ONENAND_PAGEBUF_ALLOC (0x1000) |
Kyungmin Park | 470bc84 | 2007-03-09 10:08:11 +0900 | [diff] [blame] | 173 | #define ONENAND_OOBBUF_ALLOC (0x2000) |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 174 | |
| 175 | /* |
| 176 | * OneNAND Flash Manufacturer ID Codes |
| 177 | */ |
| 178 | #define ONENAND_MFR_SAMSUNG 0xec |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 179 | |
| 180 | /** |
Randy Dunlap | ea9b6dc | 2006-06-28 21:48:38 -0700 | [diff] [blame] | 181 | * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure |
| 182 | * @name: Manufacturer name |
| 183 | * @id: manufacturer ID code of device. |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 184 | */ |
| 185 | struct onenand_manufacturers { |
| 186 | int id; |
| 187 | char *name; |
| 188 | }; |
| 189 | |
Adrian Bunk | 607d1cb | 2008-04-14 17:20:38 +0300 | [diff] [blame] | 190 | int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from, |
| 191 | struct mtd_oob_ops *ops); |
| 192 | |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 193 | #endif /* __LINUX_MTD_ONENAND_H */ |