2 * linux/include/linux/mtd/onenand.h
4 * Copyright (C) 2005-2007 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/onenand_regs.h>
18 #include <linux/mtd/bbm.h>
20 #define MAX_BUFFERRAM 2
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);
28 * onenand_state_t - chip states
29 * Enumeration for OneNAND flash chip state
44 * struct onenand_bufferram - OneNAND BufferRAM Data
45 * @blockpage: block & page address in BufferRAM
47 struct onenand_bufferram {
52 * struct onenand_chip - OneNAND Private Flash Chip Data
53 * @base: [BOARDSPECIFIC] address to access OneNAND
54 * @chipsize: [INTERN] the size of one chip for multichip arrays
55 * @device_id: [INTERN] device ID
56 * @density_mask: chip density, used for DDP devices
57 * @verstion_id: [INTERN] version ID
58 * @options: [BOARDSPECIFIC] various chip options. They can
59 * partly be set to inform onenand_scan about
60 * @erase_shift: [INTERN] number of address bits in a block
61 * @page_shift: [INTERN] number of address bits in a page
62 * @page_mask: [INTERN] a page per block mask
63 * @bufferram_index: [INTERN] BufferRAM index
64 * @bufferram: [INTERN] BufferRAM info
65 * @readw: [REPLACEABLE] hardware specific function for read short
66 * @writew: [REPLACEABLE] hardware specific function for write short
67 * @command: [REPLACEABLE] hardware specific function for writing
68 * commands to the chip
69 * @wait: [REPLACEABLE] hardware specific function for wait on ready
70 * @read_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area
71 * @write_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area
72 * @read_word: [REPLACEABLE] hardware specific function for read
74 * @write_word: [REPLACEABLE] hardware specific function for write
76 * @mmcontrol: sync burst read function
77 * @block_markbad: function to mark a block as bad
78 * @scan_bbt: [REPLACEALBE] hardware specific function for scanning
80 * @chip_lock: [INTERN] spinlock used to protect access to this
81 * structure and the chip
82 * @wq: [INTERN] wait queue to sleep on if a OneNAND
83 * operation is in progress
84 * @state: [INTERN] the current state of the OneNAND device
85 * @page_buf: data buffer
86 * @subpagesize: [INTERN] holds the subpagesize
87 * @ecclayout: [REPLACEABLE] the default ecc placement scheme
88 * @bbm: [REPLACEABLE] pointer to Bad Block Management
89 * @priv: [OPTIONAL] pointer to private chip date
93 unsigned int chipsize;
94 unsigned int device_id;
95 unsigned int version_id;
96 unsigned int density_mask;
99 unsigned int erase_shift;
100 unsigned int page_shift;
101 unsigned int page_mask;
103 unsigned int bufferram_index;
104 struct onenand_bufferram bufferram[MAX_BUFFERRAM];
106 int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
107 int (*wait)(struct mtd_info *mtd, int state);
108 int (*read_bufferram)(struct mtd_info *mtd, int area,
109 unsigned char *buffer, int offset, size_t count);
110 int (*write_bufferram)(struct mtd_info *mtd, int area,
111 const unsigned char *buffer, int offset, size_t count);
112 unsigned short (*read_word)(void __iomem *addr);
113 void (*write_word)(unsigned short value, void __iomem *addr);
114 void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
115 int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
116 int (*scan_bbt)(struct mtd_info *mtd);
118 struct completion complete;
121 spinlock_t chip_lock;
122 wait_queue_head_t wq;
123 onenand_state_t state;
124 unsigned char *page_buf;
127 struct nand_ecclayout *ecclayout;
137 #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
138 #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
139 #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
140 #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
142 #define ONENAND_GET_SYS_CFG1(this) \
143 (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
144 #define ONENAND_SET_SYS_CFG1(v, this) \
145 (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
147 #define ONENAND_IS_DDP(this) \
148 (this->device_id & ONENAND_DEVICE_IS_DDP)
150 /* Check byte access in OneNAND */
151 #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1)
156 #define ONENAND_HAS_CONT_LOCK (0x0001)
157 #define ONENAND_HAS_UNLOCK_ALL (0x0002)
158 #define ONENAND_PAGEBUF_ALLOC (0x1000)
161 * OneNAND Flash Manufacturer ID Codes
163 #define ONENAND_MFR_SAMSUNG 0xec
166 * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure
167 * @name: Manufacturer name
168 * @id: manufacturer ID code of device.
170 struct onenand_manufacturers {
175 #endif /* __LINUX_MTD_ONENAND_H */