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.12 2005/11/07 11:14:30 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/init.h>
24 #include <linux/mtd/mtd.h>
25 #include <linux/mtd/nand.h>
26 #include <linux/mtd/partitions.h>
28 #include <asm/arch/hardware.h> /* for CLPS7111_VIRT_BASE */
29 #include <asm/sizes.h>
30 #include <asm/hardware/clps7111.h>
33 * MTD structure for EDB7312 board
35 static struct mtd_info
*ep7312_mtd
= NULL
;
38 * Values specific to the EDB7312 board (used with EP7312 processor)
40 #define EP7312_FIO_PBASE 0x10000000 /* Phys address of flash */
41 #define EP7312_PXDR 0x0001 /*
42 * IO offset to Port B data register
43 * where the CLE, ALE and NCE pins
46 #define EP7312_PXDDR 0x0041 /*
47 * IO offset to Port B data direction
48 * register so we can control the IO
56 static unsigned long ep7312_fio_pbase
= EP7312_FIO_PBASE
;
57 static void __iomem
* ep7312_pxdr
= (void __iomem
*) EP7312_PXDR
;
58 static void __iomem
* ep7312_pxddr
= (void __iomem
*) EP7312_PXDDR
;
60 #ifdef CONFIG_MTD_PARTITIONS
62 * Define static partitions for flash device
64 static struct mtd_partition partition_info
[] = {
65 { .name
= "EP7312 Nand Flash",
69 #define NUM_PARTITIONS 1
75 * hardware specific access to control-lines
77 static void ep7312_hwcontrol(struct mtd_info
*mtd
, int cmd
)
82 clps_writeb(clps_readb(ep7312_pxdr
) | 0x10, ep7312_pxdr
);
85 clps_writeb(clps_readb(ep7312_pxdr
) & ~0x10, ep7312_pxdr
);
89 clps_writeb(clps_readb(ep7312_pxdr
) | 0x20, ep7312_pxdr
);
92 clps_writeb(clps_readb(ep7312_pxdr
) & ~0x20, ep7312_pxdr
);
96 clps_writeb((clps_readb(ep7312_pxdr
) | 0x80) & ~0x40, ep7312_pxdr
);
99 clps_writeb((clps_readb(ep7312_pxdr
) | 0x80) | 0x40, ep7312_pxdr
);
105 * read device ready pin
107 static int ep7312_device_ready(struct mtd_info
*mtd
)
111 #ifdef CONFIG_MTD_PARTITIONS
112 const char *part_probes
[] = { "cmdlinepart", NULL
};
116 * Main initialization routine
118 static int __init
ep7312_init (void)
120 struct nand_chip
*this;
121 const char *part_type
= 0;
122 int mtd_parts_nb
= 0;
123 struct mtd_partition
*mtd_parts
= 0;
124 void __iomem
* ep7312_fio_base
;
126 /* Allocate memory for MTD device structure and private data */
127 ep7312_mtd
= kmalloc(sizeof(struct mtd_info
) +
128 sizeof(struct nand_chip
),
131 printk("Unable to allocate EDB7312 NAND MTD device structure.\n");
135 /* map physical adress */
136 ep7312_fio_base
= ioremap(ep7312_fio_pbase
, SZ_1K
);
137 if(!ep7312_fio_base
) {
138 printk("ioremap EDB7312 NAND flash failed\n");
143 /* Get pointer to private data */
144 this = (struct nand_chip
*) (&ep7312_mtd
[1]);
146 /* Initialize structures */
147 memset((char *) ep7312_mtd
, 0, sizeof(struct mtd_info
));
148 memset((char *) this, 0, sizeof(struct nand_chip
));
150 /* Link the private data with the MTD structure */
151 ep7312_mtd
->priv
= this;
154 * Set GPIO Port B control register so that the pins are configured
155 * to be outputs for controlling the NAND flash.
157 clps_writeb(0xf0, ep7312_pxddr
);
159 /* insert callbacks */
160 this->IO_ADDR_R
= ep7312_fio_base
;
161 this->IO_ADDR_W
= ep7312_fio_base
;
162 this->hwcontrol
= ep7312_hwcontrol
;
163 this->dev_ready
= ep7312_device_ready
;
164 /* 15 us command delay time */
165 this->chip_delay
= 15;
167 /* Scan to find existence of the device */
168 if (nand_scan (ep7312_mtd
, 1)) {
169 iounmap((void *)ep7312_fio_base
);
174 #ifdef CONFIG_MTD_PARTITIONS
175 ep7312_mtd
->name
= "edb7312-nand";
176 mtd_parts_nb
= parse_mtd_partitions(ep7312_mtd
, part_probes
,
178 if (mtd_parts_nb
> 0)
179 part_type
= "command line";
183 if (mtd_parts_nb
== 0) {
184 mtd_parts
= partition_info
;
185 mtd_parts_nb
= NUM_PARTITIONS
;
186 part_type
= "static";
189 /* Register the partitions */
190 printk(KERN_NOTICE
"Using %s partition definition\n", part_type
);
191 add_mtd_partitions(ep7312_mtd
, mtd_parts
, mtd_parts_nb
);
196 module_init(ep7312_init
);
201 static void __exit
ep7312_cleanup (void)
203 struct nand_chip
*this = (struct nand_chip
*) &ep7312_mtd
[1];
205 /* Release resources, unregister device */
206 nand_release (ap7312_mtd
);
208 /* Free internal data buffer */
209 kfree (this->data_buf
);
211 /* Free the MTD device structure */
214 module_exit(ep7312_cleanup
);
216 MODULE_LICENSE("GPL");
217 MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
218 MODULE_DESCRIPTION("MTD map driver for Cogent EDB7312 board");