onenand.h 7.0 KB
Newer Older
1 2 3
/*
 *  linux/include/linux/mtd/onenand.h
 *
A
Amul Kumar Saha 已提交
4
 *  Copyright © 2005-2009 Samsung Electronics
5 6 7 8 9 10 11 12 13 14 15
 *  Kyungmin Park <kyungmin.park@samsung.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef __LINUX_MTD_ONENAND_H
#define __LINUX_MTD_ONENAND_H

#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>
20

R
Rohit Hagargundgi 已提交
21
#define MAX_DIES		2
22 23 24 25 26 27 28 29 30
#define MAX_BUFFERRAM		2

/* Scan and identify a OneNAND device */
extern int onenand_scan(struct mtd_info *mtd, int max_chips);
/* Free resources held by the OneNAND device */
extern void onenand_release(struct mtd_info *mtd);

/**
 * struct onenand_bufferram - OneNAND BufferRAM Data
31
 * @blockpage:		block & page address in BufferRAM
32 33
 */
struct onenand_bufferram {
34
	int	blockpage;
35 36 37 38
};

/**
 * struct onenand_chip - OneNAND Private Flash Chip Data
R
Randy Dunlap 已提交
39
 * @base:		[BOARDSPECIFIC] address to access OneNAND
R
Rohit Hagargundgi 已提交
40 41 42
 * @dies:		[INTERN][FLEX-ONENAND] number of dies on chip
 * @boundary:		[INTERN][FLEX-ONENAND] Boundary of the dies
 * @diesize:		[INTERN][FLEX-ONENAND] Size of the dies
R
Randy Dunlap 已提交
43
 * @chipsize:		[INTERN] the size of one chip for multichip arrays
R
Rohit Hagargundgi 已提交
44 45
 *			FIXME For Flex-OneNAND, chipsize holds maximum possible
 *			device size ie when all blocks are considered MLC
R
Randy Dunlap 已提交
46 47 48 49 50 51 52 53
 * @device_id:		[INTERN] device ID
 * @density_mask:	chip density, used for DDP devices
 * @verstion_id:	[INTERN] version ID
 * @options:		[BOARDSPECIFIC] various chip options. They can
 *			partly be set to inform onenand_scan about
 * @erase_shift:	[INTERN] number of address bits in a block
 * @page_shift:		[INTERN] number of address bits in a page
 * @page_mask:		[INTERN] a page per block mask
54
 * @writesize:		[INTERN] a real page size
R
Randy Dunlap 已提交
55 56 57 58 59 60 61
 * @bufferram_index:	[INTERN] BufferRAM index
 * @bufferram:		[INTERN] BufferRAM info
 * @readw:		[REPLACEABLE] hardware specific function for read short
 * @writew:		[REPLACEABLE] hardware specific function for write short
 * @command:		[REPLACEABLE] hardware specific function for writing
 *			commands to the chip
 * @wait:		[REPLACEABLE] hardware specific function for wait on ready
62 63
 * @bbt_wait:		[REPLACEABLE] hardware specific function for bbt wait on ready
 * @unlock_all:		[REPLACEABLE] hardware specific function for unlock all
R
Randy Dunlap 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
 * @read_bufferram:	[REPLACEABLE] hardware specific function for BufferRAM Area
 * @write_bufferram:	[REPLACEABLE] hardware specific function for BufferRAM Area
 * @read_word:		[REPLACEABLE] hardware specific function for read
 *			register of OneNAND
 * @write_word:		[REPLACEABLE] hardware specific function for write
 *			register of OneNAND
 * @mmcontrol:		sync burst read function
 * @block_markbad:	function to mark a block as bad
 * @scan_bbt:		[REPLACEALBE] hardware specific function for scanning
 *			Bad block Table
 * @chip_lock:		[INTERN] spinlock used to protect access to this
 *			structure and the chip
 * @wq:			[INTERN] wait queue to sleep on if a OneNAND
 *			operation is in progress
 * @state:		[INTERN] the current state of the OneNAND device
79 80
 * @page_buf:		[INTERN] page main data buffer
 * @oob_buf:		[INTERN] page oob data buffer
81
 * @subpagesize:	[INTERN] holds the subpagesize
R
Randy Dunlap 已提交
82 83 84
 * @ecclayout:		[REPLACEABLE] the default ecc placement scheme
 * @bbm:		[REPLACEABLE] pointer to Bad Block Management
 * @priv:		[OPTIONAL] pointer to private chip date
85 86 87
 */
struct onenand_chip {
	void __iomem		*base;
R
Rohit Hagargundgi 已提交
88 89 90
	unsigned		dies;
	unsigned		boundary[MAX_DIES];
	loff_t			diesize[MAX_DIES];
91 92
	unsigned int		chipsize;
	unsigned int		device_id;
93
	unsigned int		version_id;
R
Rohit Hagargundgi 已提交
94
	unsigned int		technology;
95
	unsigned int		density_mask;
96 97 98 99 100
	unsigned int		options;

	unsigned int		erase_shift;
	unsigned int		page_shift;
	unsigned int		page_mask;
101
	unsigned int		writesize;
102 103 104 105 106 107

	unsigned int		bufferram_index;
	struct onenand_bufferram	bufferram[MAX_BUFFERRAM];

	int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
	int (*wait)(struct mtd_info *mtd, int state);
108 109
	int (*bbt_wait)(struct mtd_info *mtd, int state);
	void (*unlock_all)(struct mtd_info *mtd);
110 111 112 113 114 115
	int (*read_bufferram)(struct mtd_info *mtd, int area,
			unsigned char *buffer, int offset, size_t count);
	int (*write_bufferram)(struct mtd_info *mtd, int area,
			const unsigned char *buffer, int offset, size_t count);
	unsigned short (*read_word)(void __iomem *addr);
	void (*write_word)(unsigned short value, void __iomem *addr);
116
	void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
117 118
	int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
	int (*scan_bbt)(struct mtd_info *mtd);
119

120 121 122
	struct completion	complete;
	int			irq;

123 124
	spinlock_t		chip_lock;
	wait_queue_head_t	wq;
125
	flstate_t		state;
126
	unsigned char		*page_buf;
127
	unsigned char		*oob_buf;
128

129
	int			subpagesize;
130
	struct nand_ecclayout	*ecclayout;
131

132
	void			*bbm;
133

134 135 136
	void			*priv;
};

137 138 139
/*
 * Helper macros
 */
A
Amul Kumar Saha 已提交
140 141
#define ONENAND_PAGES_PER_BLOCK        (1<<6)

142 143 144
#define ONENAND_CURRENT_BUFFERRAM(this)		(this->bufferram_index)
#define ONENAND_NEXT_BUFFERRAM(this)		(this->bufferram_index ^ 1)
#define ONENAND_SET_NEXT_BUFFERRAM(this)	(this->bufferram_index ^= 1)
145
#define ONENAND_SET_PREV_BUFFERRAM(this)	(this->bufferram_index ^= 1)
146 147
#define ONENAND_SET_BUFFERRAM0(this)		(this->bufferram_index = 0)
#define ONENAND_SET_BUFFERRAM1(this)		(this->bufferram_index = 1)
148

R
Rohit Hagargundgi 已提交
149 150
#define FLEXONENAND(this)						\
	(this->device_id & DEVICE_IS_FLEXONENAND)
151 152 153 154 155
#define ONENAND_GET_SYS_CFG1(this)					\
	(this->read_word(this->base + ONENAND_REG_SYS_CFG1))
#define ONENAND_SET_SYS_CFG1(v, this)					\
	(this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))

156 157 158
#define ONENAND_IS_DDP(this)						\
	(this->device_id & ONENAND_DEVICE_IS_DDP)

R
Rohit Hagargundgi 已提交
159 160 161
#define ONENAND_IS_MLC(this)						\
	(this->technology & ONENAND_TECHNOLOGY_IS_MLC)

162 163 164 165 166 167 168
#ifdef CONFIG_MTD_ONENAND_2X_PROGRAM
#define ONENAND_IS_2PLANE(this)						\
	(this->options & ONENAND_HAS_2PLANE)
#else
#define ONENAND_IS_2PLANE(this)			(0)
#endif

169 170 171
/* Check byte access in OneNAND */
#define ONENAND_CHECK_BYTE_ACCESS(addr)		(addr & 0x1)

172 173 174
/*
 * Options bits
 */
175 176
#define ONENAND_HAS_CONT_LOCK		(0x0001)
#define ONENAND_HAS_UNLOCK_ALL		(0x0002)
177
#define ONENAND_HAS_2PLANE		(0x0004)
178
#define ONENAND_SKIP_UNLOCK_CHECK	(0x0100)
179
#define ONENAND_PAGEBUF_ALLOC		(0x1000)
180
#define ONENAND_OOBBUF_ALLOC		(0x2000)
181 182 183 184 185

/*
 * OneNAND Flash Manufacturer ID Codes
 */
#define ONENAND_MFR_SAMSUNG	0xec
186
#define ONENAND_MFR_NUMONYX	0x20
187 188

/**
R
Randy Dunlap 已提交
189 190 191
 * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure
 * @name:	Manufacturer name
 * @id:		manufacturer ID code of device.
192 193 194 195 196 197
*/
struct onenand_manufacturers {
        int id;
        char *name;
};

198 199
int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
			 struct mtd_oob_ops *ops);
R
Rohit Hagargundgi 已提交
200 201 202
unsigned onenand_block(struct onenand_chip *this, loff_t addr);
loff_t onenand_addr(struct onenand_chip *this, int block);
int flexonenand_region(struct mtd_info *mtd, loff_t addr);
203

204 205 206 207 208 209 210 211
struct mtd_partition;

struct onenand_platform_data {
	void		(*mmcontrol)(struct mtd_info *mtd, int sync_read);
	struct mtd_partition *parts;
	unsigned int	nr_parts;
};

212
#endif	/* __LINUX_MTD_ONENAND_H */