upload tizen1.0 source
[kernel/linux-2.6.36.git] / include / linux / mtd / onenand.h
1 /*
2  *  linux/include/linux/mtd/onenand.h
3  *
4  *  Copyright © 2005-2009 Samsung Electronics
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>
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 #include <linux/clk.h>
21
22 #define MAX_DIES                2
23 #define MAX_BUFFERRAM           2
24
25 /* Scan and identify a OneNAND device */
26 extern int onenand_scan(struct mtd_info *mtd, int max_chips);
27 /* Free resources held by the OneNAND device */
28 extern void onenand_release(struct mtd_info *mtd);
29
30 /**
31  * struct onenand_bufferram - OneNAND BufferRAM Data
32  * @blockpage:          block & page address in BufferRAM
33  */
34 struct onenand_bufferram {
35         int     blockpage;
36 };
37
38 /**
39  * struct onenand_chip - OneNAND Private Flash Chip Data
40  * @base:               [BOARDSPECIFIC] address to access OneNAND
41  * @dies:               [INTERN][FLEX-ONENAND] number of dies on chip
42  * @boundary:           [INTERN][FLEX-ONENAND] Boundary of the dies
43  * @diesize:            [INTERN][FLEX-ONENAND] Size of the dies
44  * @chipsize:           [INTERN] the size of one chip for multichip arrays
45  *                      FIXME For Flex-OneNAND, chipsize holds maximum possible
46  *                      device size ie when all blocks are considered MLC
47  * @device_id:          [INTERN] device ID
48  * @density_mask:       chip density, used for DDP devices
49  * @verstion_id:        [INTERN] version ID
50  * @options:            [BOARDSPECIFIC] various chip options. They can
51  *                      partly be set to inform onenand_scan about
52  * @erase_shift:        [INTERN] number of address bits in a block
53  * @page_shift:         [INTERN] number of address bits in a page
54  * @page_mask:          [INTERN] a page per block mask
55  * @writesize:          [INTERN] a real page size
56  * @bufferram_index:    [INTERN] BufferRAM index
57  * @bufferram:          [INTERN] BufferRAM info
58  * @readw:              [REPLACEABLE] hardware specific function for read short
59  * @writew:             [REPLACEABLE] hardware specific function for write short
60  * @command:            [REPLACEABLE] hardware specific function for writing
61  *                      commands to the chip
62  * @wait:               [REPLACEABLE] hardware specific function for wait on ready
63  * @bbt_wait:           [REPLACEABLE] hardware specific function for bbt wait on ready
64  * @unlock_all:         [REPLACEABLE] hardware specific function for unlock all
65  * @read_bufferram:     [REPLACEABLE] hardware specific function for BufferRAM Area
66  * @write_bufferram:    [REPLACEABLE] hardware specific function for BufferRAM Area
67  * @read_word:          [REPLACEABLE] hardware specific function for read
68  *                      register of OneNAND
69  * @write_word:         [REPLACEABLE] hardware specific function for write
70  *                      register of OneNAND
71  * @mmcontrol:          sync burst read function
72  * @chip_probe:         [REPLACEABLE] hardware specific function for chip probe
73  * @block_markbad:      function to mark a block as bad
74  * @scan_bbt:           [REPLACEALBE] hardware specific function for scanning
75  *                      Bad block Table
76  * @chip_lock:          [INTERN] spinlock used to protect access to this
77  *                      structure and the chip
78  * @wq:                 [INTERN] wait queue to sleep on if a OneNAND
79  *                      operation is in progress
80  * @state:              [INTERN] the current state of the OneNAND device
81  * @page_buf:           [INTERN] page main data buffer
82  * @oob_buf:            [INTERN] page oob data buffer
83  * @subpagesize:        [INTERN] holds the subpagesize
84  * @ecclayout:          [REPLACEABLE] the default ecc placement scheme
85  * @bbm:                [REPLACEABLE] pointer to Bad Block Management
86  * @priv:               [OPTIONAL] pointer to private chip date
87  */
88 struct onenand_chip {
89         void __iomem            *base;
90         unsigned                dies;
91         unsigned                boundary[MAX_DIES];
92         loff_t                  diesize[MAX_DIES];
93         unsigned int            chipsize;
94         unsigned int            device_id;
95         unsigned int            version_id;
96         unsigned int            technology;
97         unsigned int            density_mask;
98         unsigned int            options;
99
100         unsigned int            erase_shift;
101         unsigned int            page_shift;
102         unsigned int            page_mask;
103         unsigned int            writesize;
104
105         unsigned int            bufferram_index;
106         struct onenand_bufferram        bufferram[MAX_BUFFERRAM];
107
108         int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
109         int (*wait)(struct mtd_info *mtd, int state);
110         int (*bbt_wait)(struct mtd_info *mtd, int state);
111         void (*unlock_all)(struct mtd_info *mtd);
112         int (*read_bufferram)(struct mtd_info *mtd, int area,
113                         unsigned char *buffer, int offset, size_t count);
114         int (*write_bufferram)(struct mtd_info *mtd, int area,
115                         const unsigned char *buffer, int offset, size_t count);
116         unsigned short (*read_word)(void __iomem *addr);
117         void (*write_word)(unsigned short value, void __iomem *addr);
118         void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
119         int (*chip_probe)(struct mtd_info *mtd);
120         int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
121         int (*scan_bbt)(struct mtd_info *mtd);
122
123         struct completion       complete;
124         int                     irq;
125
126         spinlock_t              chip_lock;
127         wait_queue_head_t       wq;
128         flstate_t               state;
129         unsigned char           *page_buf;
130         unsigned char           *oob_buf;
131 #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
132         unsigned char           *verify_buf;
133 #endif
134
135         int                     subpagesize;
136         struct nand_ecclayout   *ecclayout;
137
138         void                    *bbm;
139
140         void                    *priv;
141         struct clk              *clk;
142
143         unsigned int    ecc_registers;
144         unsigned int    error_mask;
145 };
146
147 /*
148  * Helper macros
149  */
150 #define ONENAND_PAGES_PER_BLOCK        (1<<6)
151
152 #define ONENAND_CURRENT_BUFFERRAM(this)         (this->bufferram_index)
153 #define ONENAND_NEXT_BUFFERRAM(this)            (this->bufferram_index ^ 1)
154 #define ONENAND_SET_NEXT_BUFFERRAM(this)        (this->bufferram_index ^= 1)
155 #define ONENAND_SET_PREV_BUFFERRAM(this)        (this->bufferram_index ^= 1)
156 #define ONENAND_SET_BUFFERRAM0(this)            (this->bufferram_index = 0)
157 #define ONENAND_SET_BUFFERRAM1(this)            (this->bufferram_index = 1)
158
159 #ifdef CONFIG_MTD_ONENAND_FLEXONENAND
160 #define FLEXONENAND(this)                                               \
161         (this->device_id & DEVICE_IS_FLEXONENAND)
162 #else
163 #define FLEXONENAND(this)                       (0)
164 #endif
165
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
171 #define ONENAND_IS_DDP(this)                                            \
172         (this->device_id & ONENAND_DEVICE_IS_DDP)
173
174 #define ONENAND_IS_MLC(this)                                            \
175         (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
176
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
184 /* Check byte access in OneNAND */
185 #define ONENAND_CHECK_BYTE_ACCESS(addr)         (addr & 0x1)
186
187 /*
188  * Options bits
189  */
190 #define ONENAND_HAS_CONT_LOCK           (0x0001)
191 #define ONENAND_HAS_UNLOCK_ALL          (0x0002)
192 #define ONENAND_HAS_2PLANE              (0x0004)
193 #define ONENAND_HAS_4KB_PAGE            (0x0008)
194 #define ONENAND_SKIP_UNLOCK_CHECK       (0x0100)
195 #define ONENAND_RUNTIME_BADBLOCK_CHECK  (0x0200)
196 #define ONENAND_PAGEBUF_ALLOC           (0x1000)
197 #define ONENAND_OOBBUF_ALLOC            (0x2000)
198
199 #define ONENAND_IS_4KB_PAGE(this)                                       \
200         (this->options & ONENAND_HAS_4KB_PAGE)
201
202 /*
203  * OneNAND Flash Manufacturer ID Codes
204  */
205 #define ONENAND_MFR_SAMSUNG     0xec
206 #define ONENAND_MFR_NUMONYX     0x20
207
208 /**
209  * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure
210  * @name:       Manufacturer name
211  * @id:         manufacturer ID code of device.
212 */
213 struct onenand_manufacturers {
214         int id;
215         char *name;
216 };
217
218 int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
219                          struct mtd_oob_ops *ops);
220 unsigned onenand_block(struct onenand_chip *this, loff_t addr);
221 loff_t onenand_addr(struct onenand_chip *this, int block);
222 int flexonenand_region(struct mtd_info *mtd, loff_t addr);
223
224 struct mtd_partition;
225
226 struct onenand_platform_data {
227         void            (*mmcontrol)(struct mtd_info *mtd, int sync_read);
228         int             (*read_bufferram)(struct mtd_info *mtd, int area,
229                         unsigned char *buffer, int offset, size_t count);
230         struct mtd_partition *parts;
231         unsigned int    nr_parts;
232 };
233
234 #endif  /* __LINUX_MTD_ONENAND_H */