aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand
diff options
context:
space:
mode:
authorMike Rapoport <mike@compulab.co.il>2007-04-22 01:53:21 -0400
committerDavid Woodhouse <dwmw2@infradead.org>2007-04-27 18:04:32 -0400
commit54d33c4c715b80cc022b8e4974a4de693c96fc99 (patch)
tree92ae13b8c791c3db66454aec00ea425158411c90 /drivers/mtd/nand
parentd1da4e50e5d09f02c340927a4fcb7f54202fa033 (diff)
[MTD] [NAND] CM-x270 MTD driver
This patch provides MTD support for NAND flash devices on CM-x270 modules. Signed-off-by: Mike Rapoport <mike@compulab.co.il> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'drivers/mtd/nand')
-rw-r--r--drivers/mtd/nand/Kconfig5
-rw-r--r--drivers/mtd/nand/Makefile1
-rw-r--r--drivers/mtd/nand/cmx270_nand.c267
3 files changed, 273 insertions, 0 deletions
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 4e62afe0c0f3..d05873b8c155 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -258,6 +258,11 @@ config MTD_NAND_AT91
258 Enables support for NAND Flash / Smart Media Card interface 258 Enables support for NAND Flash / Smart Media Card interface
259 on Atmel AT91 processors. 259 on Atmel AT91 processors.
260 260
261config MTD_NAND_CM_X270
262 tristate "Support for NAND Flash on CM-X270 modules"
263 depends on MTD_NAND && MACH_ARMCORE
264
265
261config MTD_NAND_NANDSIM 266config MTD_NAND_NANDSIM
262 tristate "Support for NAND Flash Simulator" 267 tristate "Support for NAND Flash Simulator"
263 depends on MTD_PARTITIONS 268 depends on MTD_PARTITIONS
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index 80f1dfc77949..6872031a3fb2 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_MTD_NAND_NANDSIM) += nandsim.o
24obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o 24obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o
25obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o 25obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o
26obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o 26obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o
27obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270_nand.o
27obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o 28obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o
28 29
29nand-objs := nand_base.o nand_bbt.o 30nand-objs := nand_base.o nand_bbt.o
diff --git a/drivers/mtd/nand/cmx270_nand.c b/drivers/mtd/nand/cmx270_nand.c
new file mode 100644
index 000000000000..cb663ef245d5
--- /dev/null
+++ b/drivers/mtd/nand/cmx270_nand.c
@@ -0,0 +1,267 @@
1/*
2 * linux/drivers/mtd/nand/cmx270-nand.c
3 *
4 * Copyright (C) 2006 Compulab, Ltd.
5 * Mike Rapoport <mike@compulab.co.il>
6 *
7 * Derived from drivers/mtd/nand/h1910.c
8 * Copyright (C) 2002 Marius Gröger (mag@sysgo.de)
9 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
10 *
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 * Overview:
17 * This is a device driver for the NAND flash device found on the
18 * CM-X270 board.
19 */
20
21#include <linux/mtd/nand.h>
22#include <linux/mtd/partitions.h>
23
24#include <asm/io.h>
25#include <asm/irq.h>
26
27#include <asm/arch/hardware.h>
28#include <asm/arch/pxa-regs.h>
29
30#define GPIO_NAND_CS (11)
31#define GPIO_NAND_RB (89)
32
33/* This macro needed to ensure in-order operation of GPIO and local
34 * bus. Without both asm command and dummy uncached read there're
35 * states when NAND access is broken. I've looked for such macro(s) in
36 * include/asm-arm but found nothing approptiate.
37 * dmac_clean_range is close, but is makes cache invalidation
38 * unnecessary here and it cannot be used in module
39 */
40#define DRAIN_WB() \
41 do { \
42 unsigned char dummy; \
43 asm volatile ("mcr p15, 0, r0, c7, c10, 4":::"r0"); \
44 dummy=*((unsigned char*)UNCACHED_ADDR); \
45 } while(0)
46
47/* MTD structure for CM-X270 board */
48static struct mtd_info *cmx270_nand_mtd;
49
50/* remaped IO address of the device */
51static void __iomem *cmx270_nand_io;
52
53/*
54 * Define static partitions for flash device
55 */
56static struct mtd_partition partition_info[] = {
57 [0] = {
58 .name = "cmx270-0",
59 .offset = 0,
60 .size = MTDPART_SIZ_FULL
61 }
62};
63#define NUM_PARTITIONS (ARRAY_SIZE(partition_info))
64
65const char *part_probes[] = { "cmdlinepart", NULL };
66
67static u_char cmx270_read_byte(struct mtd_info *mtd)
68{
69 struct nand_chip *this = mtd->priv;
70
71 return (readl(this->IO_ADDR_R) >> 16);
72}
73
74static void cmx270_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
75{
76 int i;
77 struct nand_chip *this = mtd->priv;
78
79 for (i=0; i<len; i++)
80 writel((*buf++ << 16), this->IO_ADDR_W);
81}
82
83static void cmx270_read_buf(struct mtd_info *mtd, u_char *buf, int len)
84{
85 int i;
86 struct nand_chip *this = mtd->priv;
87
88 for (i=0; i<len; i++)
89 *buf++ = readl(this->IO_ADDR_R) >> 16;
90}
91
92static int cmx270_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
93{
94 int i;
95 struct nand_chip *this = mtd->priv;
96
97 for (i=0; i<len; i++)
98 if (buf[i] != (u_char)(readl(this->IO_ADDR_R) >> 16))
99 return -EFAULT;
100
101 return 0;
102}
103
104static inline void nand_cs_on(void)
105{
106 GPCR(GPIO_NAND_CS) = GPIO_bit(GPIO_NAND_CS);
107}
108
109static void nand_cs_off(void)
110{
111 DRAIN_WB();
112
113 GPSR(GPIO_NAND_CS) = GPIO_bit(GPIO_NAND_CS);
114}
115
116/*
117 * hardware specific access to control-lines
118 */
119static void cmx270_hwcontrol(struct mtd_info *mtd, int dat,
120 unsigned int ctrl)
121{
122 struct nand_chip* this = mtd->priv;
123 unsigned int nandaddr = (unsigned int)this->IO_ADDR_W;
124
125 DRAIN_WB();
126
127 if (ctrl & NAND_CTRL_CHANGE) {
128 if ( ctrl & NAND_ALE )
129 nandaddr |= (1 << 3);
130 else
131 nandaddr &= ~(1 << 3);
132 if ( ctrl & NAND_CLE )
133 nandaddr |= (1 << 2);
134 else
135 nandaddr &= ~(1 << 2);
136 if ( ctrl & NAND_NCE )
137 nand_cs_on();
138 else
139 nand_cs_off();
140 }
141
142 DRAIN_WB();
143 this->IO_ADDR_W = (void __iomem*)nandaddr;
144 if (dat != NAND_CMD_NONE)
145 writel((dat << 16), this->IO_ADDR_W);
146
147 DRAIN_WB();
148}
149
150/*
151 * read device ready pin
152 */
153static int cmx270_device_ready(struct mtd_info *mtd)
154{
155 DRAIN_WB();
156
157 return (GPLR(GPIO_NAND_RB) & GPIO_bit(GPIO_NAND_RB));
158}
159
160/*
161 * Main initialization routine
162 */
163static int cmx270_init(void)
164{
165 struct nand_chip *this;
166 const char *part_type;
167 struct mtd_partition *mtd_parts;
168 int mtd_parts_nb = 0;
169 int ret;
170
171 /* Allocate memory for MTD device structure and private data */
172 cmx270_nand_mtd = kzalloc(sizeof(struct mtd_info) +
173 sizeof(struct nand_chip),
174 GFP_KERNEL);
175 if (!cmx270_nand_mtd) {
176 printk("Unable to allocate CM-X270 NAND MTD device structure.\n");
177 return -ENOMEM;
178 }
179
180 cmx270_nand_io = ioremap(PXA_CS1_PHYS, 12);
181 if (!cmx270_nand_io) {
182 printk("Unable to ioremap NAND device\n");
183 ret = -EINVAL;
184 goto err1;
185 }
186
187 /* Get pointer to private data */
188 this = (struct nand_chip *)(&cmx270_nand_mtd[1]);
189
190 /* Link the private data with the MTD structure */
191 cmx270_nand_mtd->owner = THIS_MODULE;
192 cmx270_nand_mtd->priv = this;
193
194 /* insert callbacks */
195 this->IO_ADDR_R = cmx270_nand_io;
196 this->IO_ADDR_W = cmx270_nand_io;
197 this->cmd_ctrl = cmx270_hwcontrol;
198 this->dev_ready = cmx270_device_ready;
199
200 /* 15 us command delay time */
201 this->chip_delay = 20;
202 this->ecc.mode = NAND_ECC_SOFT;
203
204 /* read/write functions */
205 this->read_byte = cmx270_read_byte;
206 this->read_buf = cmx270_read_buf;
207 this->write_buf = cmx270_write_buf;
208 this->verify_buf = cmx270_verify_buf;
209
210 /* Scan to find existence of the device */
211 if (nand_scan (cmx270_nand_mtd, 1)) {
212 printk(KERN_NOTICE "No NAND device\n");
213 ret = -ENXIO;
214 goto err2;
215 }
216
217#ifdef CONFIG_MTD_CMDLINE_PARTS
218 mtd_parts_nb = parse_mtd_partitions(cmx270_nand_mtd, part_probes,
219 &mtd_parts, 0);
220 if (mtd_parts_nb > 0)
221 part_type = "command line";
222 else
223 mtd_parts_nb = 0;
224#endif
225 if (!mtd_parts_nb) {
226 mtd_parts = partition_info;
227 mtd_parts_nb = NUM_PARTITIONS;
228 part_type = "static";
229 }
230
231 /* Register the partitions */
232 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
233 ret = add_mtd_partitions(cmx270_nand_mtd, mtd_parts, mtd_parts_nb);
234 if (ret)
235 goto err2;
236
237 /* Return happy */
238 return 0;
239
240err2:
241 iounmap(cmx270_nand_io);
242err1:
243 kfree(cmx270_nand_mtd);
244
245 return ret;
246
247}
248module_init(cmx270_init);
249
250/*
251 * Clean up routine
252 */
253static void cmx270_cleanup(void)
254{
255 /* Release resources, unregister device */
256 nand_release(cmx270_nand_mtd);
257
258 iounmap(cmx270_nand_io);
259
260 /* Free the MTD device structure */
261 kfree (cmx270_nand_mtd);
262}
263module_exit(cmx270_cleanup);
264
265MODULE_LICENSE("GPL");
266MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
267MODULE_DESCRIPTION("NAND flash driver for Compulab CM-X270 Module");