2 * linux/include/linux/mtd/onenand.h
4 * Copyright © 2005-2009 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
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.
12 #ifndef __LINUX_MTD_ONENAND_H
13 #define __LINUX_MTD_ONENAND_H
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>
22 #define MAX_BUFFERRAM 2
24 /* Scan and identify a OneNAND device */
25 extern int onenand_scan(struct mtd_info
*mtd
, int max_chips
);
26 /* Free resources held by the OneNAND device */
27 extern void onenand_release(struct mtd_info
*mtd
);
30 * struct onenand_bufferram - OneNAND BufferRAM Data
31 * @blockpage: block & page address in BufferRAM
33 struct onenand_bufferram
{
40 unsigned boundary
[MAX_DIES
];
41 loff_t diesize
[MAX_DIES
];
42 unsigned int chipsize
;
43 unsigned int device_id
;
44 unsigned int version_id
;
45 unsigned int technology
;
46 unsigned int density_mask
;
49 unsigned int erase_shift
;
50 unsigned int page_shift
;
51 unsigned int page_mask
;
52 unsigned int writesize
;
54 unsigned int bufferram_index
;
55 struct onenand_bufferram bufferram
[MAX_BUFFERRAM
];
57 int (*command
)(struct mtd_info
*mtd
, int cmd
, loff_t address
, size_t len
);
58 int (*wait
)(struct mtd_info
*mtd
, int state
);
59 int (*bbt_wait
)(struct mtd_info
*mtd
, int state
);
60 void (*unlock_all
)(struct mtd_info
*mtd
);
61 int (*read_bufferram
)(struct mtd_info
*mtd
, int area
,
62 unsigned char *buffer
, int offset
, size_t count
);
63 int (*write_bufferram
)(struct mtd_info
*mtd
, int area
,
64 const unsigned char *buffer
, int offset
, size_t count
);
65 unsigned short (*read_word
)(void __iomem
*addr
);
66 void (*write_word
)(unsigned short value
, void __iomem
*addr
);
67 void (*mmcontrol
)(struct mtd_info
*mtd
, int sync_read
);
68 int (*chip_probe
)(struct mtd_info
*mtd
);
69 int (*block_markbad
)(struct mtd_info
*mtd
, loff_t ofs
);
70 int (*scan_bbt
)(struct mtd_info
*mtd
);
72 struct completion complete
;
78 unsigned char *page_buf
;
79 unsigned char *oob_buf
;
80 #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
81 unsigned char *verify_buf
;
85 struct nand_ecclayout
*ecclayout
;
95 #define ONENAND_PAGES_PER_BLOCK (1<<6)
97 #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
98 #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
99 #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
100 #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
101 #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0)
102 #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1)
104 #define FLEXONENAND(this) \
105 (this->device_id & DEVICE_IS_FLEXONENAND)
106 #define ONENAND_GET_SYS_CFG1(this) \
107 (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
108 #define ONENAND_SET_SYS_CFG1(v, this) \
109 (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
111 #define ONENAND_IS_DDP(this) \
112 (this->device_id & ONENAND_DEVICE_IS_DDP)
114 #define ONENAND_IS_MLC(this) \
115 (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
117 #ifdef CONFIG_MTD_ONENAND_2X_PROGRAM
118 #define ONENAND_IS_2PLANE(this) \
119 (this->options & ONENAND_HAS_2PLANE)
121 #define ONENAND_IS_2PLANE(this) (0)
124 /* Check byte access in OneNAND */
125 #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1)
130 #define ONENAND_HAS_CONT_LOCK (0x0001)
131 #define ONENAND_HAS_UNLOCK_ALL (0x0002)
132 #define ONENAND_HAS_2PLANE (0x0004)
133 #define ONENAND_HAS_4KB_PAGE (0x0008)
134 #define ONENAND_SKIP_UNLOCK_CHECK (0x0100)
135 #define ONENAND_PAGEBUF_ALLOC (0x1000)
136 #define ONENAND_OOBBUF_ALLOC (0x2000)
138 #define ONENAND_IS_4KB_PAGE(this) \
139 (this->options & ONENAND_HAS_4KB_PAGE)
142 * OneNAND Flash Manufacturer ID Codes
144 #define ONENAND_MFR_SAMSUNG 0xec
145 #define ONENAND_MFR_NUMONYX 0x20
148 * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure
149 * @name: Manufacturer name
150 * @id: manufacturer ID code of device.
152 struct onenand_manufacturers
{
157 int onenand_bbt_read_oob(struct mtd_info
*mtd
, loff_t from
,
158 struct mtd_oob_ops
*ops
);
159 unsigned onenand_block(struct onenand_chip
*this, loff_t addr
);
160 loff_t
onenand_addr(struct onenand_chip
*this, int block
);
161 int flexonenand_region(struct mtd_info
*mtd
, loff_t addr
);
163 struct mtd_partition
;
165 struct onenand_platform_data
{
166 void (*mmcontrol
)(struct mtd_info
*mtd
, int sync_read
);
167 int (*read_bufferram
)(struct mtd_info
*mtd
, int area
,
168 unsigned char *buffer
, int offset
, size_t count
);
169 struct mtd_partition
*parts
;
170 unsigned int nr_parts
;
173 #endif /* __LINUX_MTD_ONENAND_H */