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