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