]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - include/linux/mtd/onenand.h
mtd: use bbm.h in nand.h
[thirdparty/kernel/stable.git] / include / linux / mtd / onenand.h
CommitLineData
cd5f6346
KP
1/*
2 * linux/include/linux/mtd/onenand.h
3 *
75384b0d 4 * Copyright (C) 2005-2007 Samsung Electronics
cd5f6346
KP
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>
2c22120f 16#include <linux/completion.h>
cd5f6346 17#include <linux/mtd/onenand_regs.h>
cdc00130 18#include <linux/mtd/bbm.h>
cd5f6346 19
5988af23 20#define MAX_DIES 2
cd5f6346
KP
21#define MAX_BUFFERRAM 2
22
23/* Scan and identify a OneNAND device */
24extern int onenand_scan(struct mtd_info *mtd, int max_chips);
25/* Free resources held by the OneNAND device */
26extern void onenand_release(struct mtd_info *mtd);
27
ea9b6dcc 28/*
cd5f6346
KP
29 * onenand_state_t - chip states
30 * Enumeration for OneNAND flash chip state
31 */
32typedef enum {
33 FL_READY,
34 FL_READING,
35 FL_WRITING,
36 FL_ERASING,
37 FL_SYNCING,
cd5f6346 38 FL_LOCKING,
493c6460
KP
39 FL_RESETING,
40 FL_OTPING,
a41371eb 41 FL_PM_SUSPENDED,
cd5f6346
KP
42} onenand_state_t;
43
44/**
45 * struct onenand_bufferram - OneNAND BufferRAM Data
abf3c0f2 46 * @blockpage: block & page address in BufferRAM
cd5f6346
KP
47 */
48struct onenand_bufferram {
abf3c0f2 49 int blockpage;
cd5f6346
KP
50};
51
52/**
53 * struct onenand_chip - OneNAND Private Flash Chip Data
ea9b6dcc 54 * @base: [BOARDSPECIFIC] address to access OneNAND
5988af23
RH
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
ea9b6dcc 58 * @chipsize: [INTERN] the size of one chip for multichip arrays
5988af23
RH
59 * FIXME For Flex-OneNAND, chipsize holds maximum possible
60 * device size ie when all blocks are considered MLC
ea9b6dcc
RD
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
ea9b6dcc 68 * @page_mask: [INTERN] a page per block mask
ee9745fc 69 * @writesize: [INTERN] a real page size
ea9b6dcc
RD
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
31bb999e
KP
77 * @bbt_wait: [REPLACEABLE] hardware specific function for bbt wait on ready
78 * @unlock_all: [REPLACEABLE] hardware specific function for unlock all
ea9b6dcc
RD
79 * @read_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area
80 * @write_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area
81 * @read_word: [REPLACEABLE] hardware specific function for read
82 * register of OneNAND
83 * @write_word: [REPLACEABLE] hardware specific function for write
84 * register of OneNAND
85 * @mmcontrol: sync burst read function
86 * @block_markbad: function to mark a block as bad
87 * @scan_bbt: [REPLACEALBE] hardware specific function for scanning
88 * Bad block Table
89 * @chip_lock: [INTERN] spinlock used to protect access to this
90 * structure and the chip
91 * @wq: [INTERN] wait queue to sleep on if a OneNAND
92 * operation is in progress
93 * @state: [INTERN] the current state of the OneNAND device
470bc844
KP
94 * @page_buf: [INTERN] page main data buffer
95 * @oob_buf: [INTERN] page oob data buffer
60d84f97 96 * @subpagesize: [INTERN] holds the subpagesize
ea9b6dcc
RD
97 * @ecclayout: [REPLACEABLE] the default ecc placement scheme
98 * @bbm: [REPLACEABLE] pointer to Bad Block Management
99 * @priv: [OPTIONAL] pointer to private chip date
cd5f6346
KP
100 */
101struct onenand_chip {
102 void __iomem *base;
5988af23
RH
103 unsigned dies;
104 unsigned boundary[MAX_DIES];
105 loff_t diesize[MAX_DIES];
cd5f6346
KP
106 unsigned int chipsize;
107 unsigned int device_id;
28b79ff9 108 unsigned int version_id;
5988af23 109 unsigned int technology;
83a36838 110 unsigned int density_mask;
cd5f6346
KP
111 unsigned int options;
112
113 unsigned int erase_shift;
114 unsigned int page_shift;
cd5f6346 115 unsigned int page_mask;
ee9745fc 116 unsigned int writesize;
cd5f6346
KP
117
118 unsigned int bufferram_index;
119 struct onenand_bufferram bufferram[MAX_BUFFERRAM];
120
121 int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
122 int (*wait)(struct mtd_info *mtd, int state);
31bb999e
KP
123 int (*bbt_wait)(struct mtd_info *mtd, int state);
124 void (*unlock_all)(struct mtd_info *mtd);
cd5f6346
KP
125 int (*read_bufferram)(struct mtd_info *mtd, int area,
126 unsigned char *buffer, int offset, size_t count);
127 int (*write_bufferram)(struct mtd_info *mtd, int area,
128 const unsigned char *buffer, int offset, size_t count);
129 unsigned short (*read_word)(void __iomem *addr);
130 void (*write_word)(unsigned short value, void __iomem *addr);
52b0eea7 131 void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
cdc00130
KP
132 int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
133 int (*scan_bbt)(struct mtd_info *mtd);
cd5f6346 134
2c22120f
KP
135 struct completion complete;
136 int irq;
137
cd5f6346
KP
138 spinlock_t chip_lock;
139 wait_queue_head_t wq;
140 onenand_state_t state;
532a37cf 141 unsigned char *page_buf;
470bc844 142 unsigned char *oob_buf;
cd5f6346 143
60d84f97 144 int subpagesize;
5bd34c09 145 struct nand_ecclayout *ecclayout;
cd5f6346 146
5bd34c09 147 void *bbm;
cdc00130 148
cd5f6346
KP
149 void *priv;
150};
151
fcc31470
KP
152/*
153 * Helper macros
154 */
cd5f6346
KP
155#define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
156#define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
157#define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
a8de85d5 158#define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
ee9745fc
KP
159#define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0)
160#define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1)
cd5f6346 161
5988af23
RH
162#define FLEXONENAND(this) \
163 (this->device_id & DEVICE_IS_FLEXONENAND)
fcc31470
KP
164#define ONENAND_GET_SYS_CFG1(this) \
165 (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
166#define ONENAND_SET_SYS_CFG1(v, this) \
167 (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
168
738d61f5
KP
169#define ONENAND_IS_DDP(this) \
170 (this->device_id & ONENAND_DEVICE_IS_DDP)
171
5988af23
RH
172#define ONENAND_IS_MLC(this) \
173 (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
174
ee9745fc
KP
175#ifdef CONFIG_MTD_ONENAND_2X_PROGRAM
176#define ONENAND_IS_2PLANE(this) \
177 (this->options & ONENAND_HAS_2PLANE)
178#else
179#define ONENAND_IS_2PLANE(this) (0)
180#endif
181
9c01f87d
KP
182/* Check byte access in OneNAND */
183#define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1)
184
cd5f6346
KP
185/*
186 * Options bits
187 */
28b79ff9
KP
188#define ONENAND_HAS_CONT_LOCK (0x0001)
189#define ONENAND_HAS_UNLOCK_ALL (0x0002)
ee9745fc 190#define ONENAND_HAS_2PLANE (0x0004)
31bb999e 191#define ONENAND_SKIP_UNLOCK_CHECK (0x0100)
532a37cf 192#define ONENAND_PAGEBUF_ALLOC (0x1000)
470bc844 193#define ONENAND_OOBBUF_ALLOC (0x2000)
cd5f6346
KP
194
195/*
196 * OneNAND Flash Manufacturer ID Codes
197 */
198#define ONENAND_MFR_SAMSUNG 0xec
ee8f3768 199#define ONENAND_MFR_NUMONYX 0x20
cd5f6346
KP
200
201/**
ea9b6dcc
RD
202 * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure
203 * @name: Manufacturer name
204 * @id: manufacturer ID code of device.
cd5f6346
KP
205*/
206struct onenand_manufacturers {
207 int id;
208 char *name;
209};
210
607d1cb1
AB
211int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
212 struct mtd_oob_ops *ops);
5988af23
RH
213unsigned onenand_block(struct onenand_chip *this, loff_t addr);
214loff_t onenand_addr(struct onenand_chip *this, int block);
215int flexonenand_region(struct mtd_info *mtd, loff_t addr);
607d1cb1 216
778dbcc1
MD
217struct mtd_partition;
218
219struct onenand_platform_data {
220 void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
221 struct mtd_partition *parts;
222 unsigned int nr_parts;
223};
224
cd5f6346 225#endif /* __LINUX_MTD_ONENAND_H */