]> bbs.cooldavid.org Git - net-next-2.6.git/blob - include/linux/mtd/onenand.h
[MTD] OneNAND: Remove unused fields
[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_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
27 /*
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,
37         FL_LOCKING,
38         FL_RESETING,
39         FL_OTPING,
40         FL_PM_SUSPENDED,
41 } onenand_state_t;
42
43 /**
44  * struct onenand_bufferram - OneNAND BufferRAM Data
45  * @block:              block address in BufferRAM
46  * @page:               page address in BufferRAM
47  * @valid:              valid flag
48  */
49 struct onenand_bufferram {
50         int block;
51         int page;
52         int valid;
53 };
54
55 /**
56  * struct onenand_chip - OneNAND Private Flash Chip Data
57  * @base:               [BOARDSPECIFIC] address to access OneNAND
58  * @chipsize:           [INTERN] the size of one chip for multichip arrays
59  * @device_id:          [INTERN] device ID
60  * @density_mask:       chip density, used for DDP devices
61  * @verstion_id:        [INTERN] version ID
62  * @options:            [BOARDSPECIFIC] various chip options. They can
63  *                      partly be set to inform onenand_scan about
64  * @erase_shift:        [INTERN] number of address bits in a block
65  * @page_shift:         [INTERN] number of address bits in a page
66  * @page_mask:          [INTERN] a page per block mask
67  * @bufferram_index:    [INTERN] BufferRAM index
68  * @bufferram:          [INTERN] BufferRAM info
69  * @readw:              [REPLACEABLE] hardware specific function for read short
70  * @writew:             [REPLACEABLE] hardware specific function for write short
71  * @command:            [REPLACEABLE] hardware specific function for writing
72  *                      commands to the chip
73  * @wait:               [REPLACEABLE] hardware specific function for wait on ready
74  * @read_bufferram:     [REPLACEABLE] hardware specific function for BufferRAM Area
75  * @write_bufferram:    [REPLACEABLE] hardware specific function for BufferRAM Area
76  * @read_word:          [REPLACEABLE] hardware specific function for read
77  *                      register of OneNAND
78  * @write_word:         [REPLACEABLE] hardware specific function for write
79  *                      register of OneNAND
80  * @mmcontrol:          sync burst read function
81  * @block_markbad:      function to mark a block as bad
82  * @scan_bbt:           [REPLACEALBE] hardware specific function for scanning
83  *                      Bad block Table
84  * @chip_lock:          [INTERN] spinlock used to protect access to this
85  *                      structure and the chip
86  * @wq:                 [INTERN] wait queue to sleep on if a OneNAND
87  *                      operation is in progress
88  * @state:              [INTERN] the current state of the OneNAND device
89  * @page_buf:           data buffer
90  * @subpagesize:        [INTERN] holds the subpagesize
91  * @ecclayout:          [REPLACEABLE] the default ecc placement scheme
92  * @bbm:                [REPLACEABLE] pointer to Bad Block Management
93  * @priv:               [OPTIONAL] pointer to private chip date
94  */
95 struct onenand_chip {
96         void __iomem            *base;
97         unsigned int            chipsize;
98         unsigned int            device_id;
99         unsigned int            version_id;
100         unsigned int            density_mask;
101         unsigned int            options;
102
103         unsigned int            erase_shift;
104         unsigned int            page_shift;
105         unsigned int            page_mask;
106
107         unsigned int            bufferram_index;
108         struct onenand_bufferram        bufferram[MAX_BUFFERRAM];
109
110         int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
111         int (*wait)(struct mtd_info *mtd, int state);
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 (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
120         int (*scan_bbt)(struct mtd_info *mtd);
121
122         struct completion       complete;
123         int                     irq;
124
125         spinlock_t              chip_lock;
126         wait_queue_head_t       wq;
127         onenand_state_t         state;
128         unsigned char           *page_buf;
129
130         int                     subpagesize;
131         struct nand_ecclayout   *ecclayout;
132
133         void                    *bbm;
134
135         void                    *priv;
136 };
137
138 /*
139  * Helper macros
140  */
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)
144 #define ONENAND_SET_PREV_BUFFERRAM(this)        (this->bufferram_index ^= 1)
145
146 #define ONENAND_GET_SYS_CFG1(this)                                      \
147         (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
148 #define ONENAND_SET_SYS_CFG1(v, this)                                   \
149         (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
150
151 #define ONENAND_IS_DDP(this)                                            \
152         (this->device_id & ONENAND_DEVICE_IS_DDP)
153
154 /* Check byte access in OneNAND */
155 #define ONENAND_CHECK_BYTE_ACCESS(addr)         (addr & 0x1)
156
157 /*
158  * Options bits
159  */
160 #define ONENAND_HAS_CONT_LOCK           (0x0001)
161 #define ONENAND_HAS_UNLOCK_ALL          (0x0002)
162 #define ONENAND_PAGEBUF_ALLOC           (0x1000)
163
164 /*
165  * OneNAND Flash Manufacturer ID Codes
166  */
167 #define ONENAND_MFR_SAMSUNG     0xec
168
169 /**
170  * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure
171  * @name:       Manufacturer name
172  * @id:         manufacturer ID code of device.
173 */
174 struct onenand_manufacturers {
175         int id;
176         char *name;
177 };
178
179 #endif  /* __LINUX_MTD_ONENAND_H */