2 * drivers/mtd/nand/edb7312.c
4 * Copyright (C) 2002 Marius Gröger (mag@sysgo.de)
6 * Derived from drivers/mtd/nand/autcpu12.c
7 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
9 * $Id: edb7312.c,v 1.5 2003/04/20 07:24:40 gleixner Exp $
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 * This is a device driver for the NAND flash device found on the
17 * CLEP7312 board which utilizes the Toshiba TC58V64AFT part. This is
18 * a 64Mibit (8MiB x 8 bits) NAND flash device.
21 #include <linux/slab.h>
22 #include <linux/module.h>
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/nand.h>
25 #include <linux/mtd/partitions.h>
27 #include <asm/arch/hardware.h> /* for CLPS7111_VIRT_BASE */
28 #include <asm/sizes.h>
29 #include <asm/hardware/clps7111.h>
32 * MTD structure for EDB7312 board
34 static struct mtd_info *ep7312_mtd = NULL;
37 * Values specific to the EDB7312 board (used with EP7312 processor)
39 #define EP7312_FIO_PBASE 0x10000000 /* Phys address of flash */
40 #define EP7312_PXDR 0x0001 /*
41 * IO offset to Port B data register
42 * where the CLE, ALE and NCE pins
45 #define EP7312_PXDDR 0x0041 /*
46 * IO offset to Port B data direction
47 * register so we can control the IO
55 static int ep7312_fio_pbase = EP7312_FIO_PBASE;
56 static int ep7312_pxdr = EP7312_PXDR;
57 static int ep7312_pxddr = EP7312_PXDDR;
60 MODULE_PARM(ep7312_fio_pbase, "i");
61 MODULE_PARM(ep7312_pxdr, "i");
62 MODULE_PARM(ep7312_pxddr, "i");
64 __setup("ep7312_fio_pbase=",ep7312_fio_pbase);
65 __setup("ep7312_pxdr=",ep7312_pxdr);
66 __setup("ep7312_pxddr=",ep7312_pxddr);
69 #ifdef CONFIG_MTD_PARTITIONS
71 * Define static partitions for flash device
73 static struct mtd_partition partition_info[] = {
74 { .name = "EP7312 Nand Flash",
78 #define NUM_PARTITIONS 1
84 * hardware specific access to control-lines
86 static void ep7312_hwcontrol(int cmd)
91 clps_writeb(clps_readb(ep7312_pxdr) | 0x10, ep7312_pxdr);
94 clps_writeb(clps_readb(ep7312_pxdr) & ~0x10, ep7312_pxdr);
98 clps_writeb(clps_readb(ep7312_pxdr) | 0x20, ep7312_pxdr);
100 case NAND_CTL_CLRALE:
101 clps_writeb(clps_readb(ep7312_pxdr) & ~0x20, ep7312_pxdr);
104 case NAND_CTL_SETNCE:
105 clps_writeb((clps_readb(ep7312_pxdr) | 0x80) & ~0x40, ep7312_pxdr);
107 case NAND_CTL_CLRNCE:
108 clps_writeb((clps_readb(ep7312_pxdr) | 0x80) | 0x40, ep7312_pxdr);
114 * read device ready pin
116 static int ep7312_device_ready(void)
122 * Main initialization routine
124 static int __init ep7312_init (void)
126 struct nand_chip *this;
127 const char *part_type = 0;
128 int mtd_parts_nb = 0;
129 struct mtd_partition *mtd_parts = 0;
132 /* Allocate memory for MTD device structure and private data */
133 ep7312_mtd = kmalloc(sizeof(struct mtd_info) +
134 sizeof(struct nand_chip),
137 printk("Unable to allocate EDB7312 NAND MTD device structure.\n");
141 /* map physical adress */
142 ep7312_fio_base = (unsigned long)ioremap(ep7312_fio_pbase, SZ_1K);
143 if(!ep7312_fio_base) {
144 printk("ioremap EDB7312 NAND flash failed\n");
149 /* Get pointer to private data */
150 this = (struct nand_chip *) (&ep7312_mtd[1]);
152 /* Initialize structures */
153 memset((char *) ep7312_mtd, 0, sizeof(struct mtd_info));
154 memset((char *) this, 0, sizeof(struct nand_chip));
156 /* Link the private data with the MTD structure */
157 ep7312_mtd->priv = this;
160 * Set GPIO Port B control register so that the pins are configured
161 * to be outputs for controlling the NAND flash.
163 clps_writeb(0xf0, ep7312_pxddr);
165 /* insert callbacks */
166 this->IO_ADDR_R = ep7312_fio_base;
167 this->IO_ADDR_W = ep7312_fio_base;
168 this->hwcontrol = ep7312_hwcontrol;
169 this->dev_ready = ep7312_device_ready;
170 /* 15 us command delay time */
171 this->chip_delay = 15;
173 /* Scan to find existence of the device */
174 if (nand_scan (ep7312_mtd)) {
175 iounmap((void *)ep7312_fio_base);
180 /* Allocate memory for internal data buffer */
181 this->data_buf = kmalloc (sizeof(u_char) * (ep7312_mtd->oobblock + ep7312_mtd->oobsize), GFP_KERNEL);
182 if (!this->data_buf) {
183 printk("Unable to allocate NAND data buffer for EDB7312.\n");
184 iounmap((void *)ep7312_fio_base);
189 #ifdef CONFIG_MTD_CMDLINE_PARTS
190 mtd_parts_nb = parse_cmdline_partitions(ep7312_mtd, &mtd_parts,
192 if (mtd_parts_nb > 0)
193 part_type = "command line";
197 if (mtd_parts_nb == 0)
199 mtd_parts = partition_info;
200 mtd_parts_nb = NUM_PARTITIONS;
201 part_type = "static";
204 /* Register the partitions */
205 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
206 add_mtd_partitions(ep7312_mtd, mtd_parts, mtd_parts_nb);
211 module_init(ep7312_init);
216 static void __exit ep7312_cleanup (void)
218 struct nand_chip *this = (struct nand_chip *) &ep7312_mtd[1];
220 /* Unregister the device */
221 del_mtd_device (ep7312_mtd);
223 /* Free internal data buffer */
224 kfree (this->data_buf);
226 /* Free the MTD device structure */
229 module_exit(ep7312_cleanup);
231 MODULE_LICENSE("GPL");
232 MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
233 MODULE_DESCRIPTION("MTD map driver for Cogent EDB7312 board");