blob: c26ff86ad08aa51ec57a9479d6a77b5e2560455d [file] [log] [blame]
Kyungmin Parkcd5f6342005-07-11 11:41:53 +01001/*
2 * linux/include/linux/mtd/onenand.h
3 *
Amul Kumar Saha3cf60252009-10-21 17:00:05 +05304 * Copyright © 2005-2009 Samsung Electronics
Kyungmin Parkcd5f6342005-07-11 11:41:53 +01005 * 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>
Kyungmin Park2c221202006-11-16 11:23:48 +090016#include <linux/completion.h>
Alessandro Rubini30631cb2009-09-20 23:28:14 +020017#include <linux/mtd/flashchip.h>
Kyungmin Parkcd5f6342005-07-11 11:41:53 +010018#include <linux/mtd/onenand_regs.h>
Kyungmin Parkcdc00132005-09-03 07:15:48 +010019#include <linux/mtd/bbm.h>
Kyungmin Parkcd5f6342005-07-11 11:41:53 +010020
Rohit Hagargundgi5988af22009-05-12 13:46:57 -070021#define MAX_DIES 2
Kyungmin Parkcd5f6342005-07-11 11:41:53 +010022#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
Kyungmin Parkcd5f6342005-07-11 11:41:53 +010029/**
30 * struct onenand_bufferram - OneNAND BufferRAM Data
Kyungmin Parkabf3c0f2007-02-02 09:29:36 +090031 * @blockpage: block & page address in BufferRAM
Kyungmin Parkcd5f6342005-07-11 11:41:53 +010032 */
33struct onenand_bufferram {
Kyungmin Parkabf3c0f2007-02-02 09:29:36 +090034 int blockpage;
Kyungmin Parkcd5f6342005-07-11 11:41:53 +010035};
36
37/**
38 * struct onenand_chip - OneNAND Private Flash Chip Data
Randy Dunlapea9b6dc2006-06-28 21:48:38 -070039 * @base: [BOARDSPECIFIC] address to access OneNAND
Rohit Hagargundgi5988af22009-05-12 13:46:57 -070040 * @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
Randy Dunlapea9b6dc2006-06-28 21:48:38 -070043 * @chipsize: [INTERN] the size of one chip for multichip arrays
Rohit Hagargundgi5988af22009-05-12 13:46:57 -070044 * FIXME For Flex-OneNAND, chipsize holds maximum possible
45 * device size ie when all blocks are considered MLC
Randy Dunlapea9b6dc2006-06-28 21:48:38 -070046 * @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
Randy Dunlapea9b6dc2006-06-28 21:48:38 -070053 * @page_mask: [INTERN] a page per block mask
Kyungmin Parkee9745f2007-06-30 13:57:49 +090054 * @writesize: [INTERN] a real page size
Randy Dunlapea9b6dc2006-06-28 21:48:38 -070055 * @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
Kyungmin Park31bb9992009-05-12 13:46:57 -070062 * @bbt_wait: [REPLACEABLE] hardware specific function for bbt wait on ready
63 * @unlock_all: [REPLACEABLE] hardware specific function for unlock all
Randy Dunlapea9b6dc2006-06-28 21:48:38 -070064 * @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
71 * @block_markbad: function to mark a block as bad
72 * @scan_bbt: [REPLACEALBE] hardware specific function for scanning
73 * Bad block Table
74 * @chip_lock: [INTERN] spinlock used to protect access to this
75 * structure and the chip
76 * @wq: [INTERN] wait queue to sleep on if a OneNAND
77 * operation is in progress
78 * @state: [INTERN] the current state of the OneNAND device
Kyungmin Park470bc842007-03-09 10:08:11 +090079 * @page_buf: [INTERN] page main data buffer
80 * @oob_buf: [INTERN] page oob data buffer
Kyungmin Park60d84f92006-12-22 16:21:54 +090081 * @subpagesize: [INTERN] holds the subpagesize
Randy Dunlapea9b6dc2006-06-28 21:48:38 -070082 * @ecclayout: [REPLACEABLE] the default ecc placement scheme
83 * @bbm: [REPLACEABLE] pointer to Bad Block Management
84 * @priv: [OPTIONAL] pointer to private chip date
Kyungmin Parkcd5f6342005-07-11 11:41:53 +010085 */
86struct onenand_chip {
87 void __iomem *base;
Rohit Hagargundgi5988af22009-05-12 13:46:57 -070088 unsigned dies;
89 unsigned boundary[MAX_DIES];
90 loff_t diesize[MAX_DIES];
Kyungmin Parkcd5f6342005-07-11 11:41:53 +010091 unsigned int chipsize;
92 unsigned int device_id;
Kyungmin Park28b79ff2006-09-26 09:45:28 +000093 unsigned int version_id;
Rohit Hagargundgi5988af22009-05-12 13:46:57 -070094 unsigned int technology;
Kyungmin Park83a36832005-09-29 04:53:16 +010095 unsigned int density_mask;
Kyungmin Parkcd5f6342005-07-11 11:41:53 +010096 unsigned int options;
97
98 unsigned int erase_shift;
99 unsigned int page_shift;
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100100 unsigned int page_mask;
Kyungmin Parkee9745f2007-06-30 13:57:49 +0900101 unsigned int writesize;
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100102
103 unsigned int bufferram_index;
104 struct onenand_bufferram bufferram[MAX_BUFFERRAM];
105
106 int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
107 int (*wait)(struct mtd_info *mtd, int state);
Kyungmin Park31bb9992009-05-12 13:46:57 -0700108 int (*bbt_wait)(struct mtd_info *mtd, int state);
109 void (*unlock_all)(struct mtd_info *mtd);
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100110 int (*read_bufferram)(struct mtd_info *mtd, int area,
111 unsigned char *buffer, int offset, size_t count);
112 int (*write_bufferram)(struct mtd_info *mtd, int area,
113 const unsigned char *buffer, int offset, size_t count);
114 unsigned short (*read_word)(void __iomem *addr);
115 void (*write_word)(unsigned short value, void __iomem *addr);
Kyungmin Park52b0eea2005-09-03 07:07:19 +0100116 void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
Kyungmin Parkcdc00132005-09-03 07:15:48 +0100117 int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
118 int (*scan_bbt)(struct mtd_info *mtd);
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100119
Kyungmin Park2c221202006-11-16 11:23:48 +0900120 struct completion complete;
121 int irq;
122
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100123 spinlock_t chip_lock;
124 wait_queue_head_t wq;
Alessandro Rubini30631cb2009-09-20 23:28:14 +0200125 flstate_t state;
Kyungmin Park532a37c2005-12-16 11:17:29 +0900126 unsigned char *page_buf;
Kyungmin Park470bc842007-03-09 10:08:11 +0900127 unsigned char *oob_buf;
Kyungmin Park4a8ce0b2010-04-28 17:46:46 +0200128#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
129 unsigned char *verify_buf;
130#endif
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100131
Kyungmin Park60d84f92006-12-22 16:21:54 +0900132 int subpagesize;
Thomas Gleixner5bd34c02006-05-27 22:16:10 +0200133 struct nand_ecclayout *ecclayout;
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100134
Thomas Gleixner5bd34c02006-05-27 22:16:10 +0200135 void *bbm;
Kyungmin Parkcdc00132005-09-03 07:15:48 +0100136
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100137 void *priv;
138};
139
Kyungmin Parkfcc31472005-09-03 07:20:08 +0100140/*
141 * Helper macros
142 */
Amul Kumar Saha3cf60252009-10-21 17:00:05 +0530143#define ONENAND_PAGES_PER_BLOCK (1<<6)
144
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100145#define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
146#define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
147#define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
Adrian Huntera8de85d2007-01-04 09:51:26 +0200148#define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
Kyungmin Parkee9745f2007-06-30 13:57:49 +0900149#define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0)
150#define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1)
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100151
Rohit Hagargundgi5988af22009-05-12 13:46:57 -0700152#define FLEXONENAND(this) \
153 (this->device_id & DEVICE_IS_FLEXONENAND)
Kyungmin Parkfcc31472005-09-03 07:20:08 +0100154#define ONENAND_GET_SYS_CFG1(this) \
155 (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
156#define ONENAND_SET_SYS_CFG1(v, this) \
157 (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
158
Kyungmin Park738d61f2007-01-15 17:09:14 +0900159#define ONENAND_IS_DDP(this) \
160 (this->device_id & ONENAND_DEVICE_IS_DDP)
161
Rohit Hagargundgi5988af22009-05-12 13:46:57 -0700162#define ONENAND_IS_MLC(this) \
163 (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
164
Kyungmin Parkee9745f2007-06-30 13:57:49 +0900165#ifdef CONFIG_MTD_ONENAND_2X_PROGRAM
166#define ONENAND_IS_2PLANE(this) \
167 (this->options & ONENAND_HAS_2PLANE)
168#else
169#define ONENAND_IS_2PLANE(this) (0)
170#endif
171
Kyungmin Park9c01f872006-05-12 17:02:31 +0300172/* Check byte access in OneNAND */
173#define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1)
174
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100175/*
176 * Options bits
177 */
Kyungmin Park28b79ff2006-09-26 09:45:28 +0000178#define ONENAND_HAS_CONT_LOCK (0x0001)
179#define ONENAND_HAS_UNLOCK_ALL (0x0002)
Kyungmin Parkee9745f2007-06-30 13:57:49 +0900180#define ONENAND_HAS_2PLANE (0x0004)
Kyungmin Park6a88c472010-04-28 17:46:45 +0200181#define ONENAND_HAS_4KB_PAGE (0x0008)
Kyungmin Park31bb9992009-05-12 13:46:57 -0700182#define ONENAND_SKIP_UNLOCK_CHECK (0x0100)
Kyungmin Park532a37c2005-12-16 11:17:29 +0900183#define ONENAND_PAGEBUF_ALLOC (0x1000)
Kyungmin Park470bc842007-03-09 10:08:11 +0900184#define ONENAND_OOBBUF_ALLOC (0x2000)
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100185
Kyungmin Park6a88c472010-04-28 17:46:45 +0200186#define ONENAND_IS_4KB_PAGE(this) \
187 (this->options & ONENAND_HAS_4KB_PAGE)
188
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100189/*
190 * OneNAND Flash Manufacturer ID Codes
191 */
192#define ONENAND_MFR_SAMSUNG 0xec
Adrian Hunteree8f3762009-05-05 11:04:19 +0300193#define ONENAND_MFR_NUMONYX 0x20
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100194
195/**
Randy Dunlapea9b6dc2006-06-28 21:48:38 -0700196 * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure
197 * @name: Manufacturer name
198 * @id: manufacturer ID code of device.
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100199*/
200struct onenand_manufacturers {
201 int id;
202 char *name;
203};
204
Adrian Bunk607d1cb2008-04-14 17:20:38 +0300205int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
206 struct mtd_oob_ops *ops);
Rohit Hagargundgi5988af22009-05-12 13:46:57 -0700207unsigned onenand_block(struct onenand_chip *this, loff_t addr);
208loff_t onenand_addr(struct onenand_chip *this, int block);
209int flexonenand_region(struct mtd_info *mtd, loff_t addr);
Adrian Bunk607d1cb2008-04-14 17:20:38 +0300210
Magnus Damm778dbcc2009-09-18 12:51:44 -0700211struct mtd_partition;
212
213struct onenand_platform_data {
214 void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
Kyungmin Park3328dc32010-04-28 17:46:47 +0200215 int (*read_bufferram)(struct mtd_info *mtd, int area,
216 unsigned char *buffer, int offset, size_t count);
Magnus Damm778dbcc2009-09-18 12:51:44 -0700217 struct mtd_partition *parts;
218 unsigned int nr_parts;
219};
220
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100221#endif /* __LINUX_MTD_ONENAND_H */