Linux 2.6.26-rc1
[cris-mirror.git] / drivers / mtd / nand / edb7312.c
blobba67bbec20d3a4fbab3ac9733d05ee7cc3f61229
1 /*
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.
15 * Overview:
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>
27 #include <asm/io.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
44 * are wired to.
46 #define EP7312_PXDDR 0x0041 /*
47 * IO offset to Port B data direction
48 * register so we can control the IO
49 * lines.
53 * Module stuff
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",
66 .offset = 0,
67 .size = 8 * 1024 * 1024}
70 #define NUM_PARTITIONS 1
72 #endif
75 * hardware specific access to control-lines
77 * NAND_NCE: bit 0 -> bit 6 (bit 7 = 1)
78 * NAND_CLE: bit 1 -> bit 4
79 * NAND_ALE: bit 2 -> bit 5
81 static void ep7312_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
83 struct nand_chip *chip = mtd->priv;
85 if (ctrl & NAND_CTRL_CHANGE) {
86 unsigned char bits = 0x80;
88 bits |= (ctrl & (NAND_CLE | NAND_ALE)) << 3;
89 bits |= (ctrl & NAND_NCE) ? 0x00 : 0x40;
91 clps_writeb((clps_readb(ep7312_pxdr) & 0xF0) | bits,
92 ep7312_pxdr);
94 if (cmd != NAND_CMD_NONE)
95 writeb(cmd, chip->IO_ADDR_W);
99 * read device ready pin
101 static int ep7312_device_ready(struct mtd_info *mtd)
103 return 1;
106 #ifdef CONFIG_MTD_PARTITIONS
107 const char *part_probes[] = { "cmdlinepart", NULL };
108 #endif
111 * Main initialization routine
113 static int __init ep7312_init(void)
115 struct nand_chip *this;
116 const char *part_type = 0;
117 int mtd_parts_nb = 0;
118 struct mtd_partition *mtd_parts = 0;
119 void __iomem *ep7312_fio_base;
121 /* Allocate memory for MTD device structure and private data */
122 ep7312_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
123 if (!ep7312_mtd) {
124 printk("Unable to allocate EDB7312 NAND MTD device structure.\n");
125 return -ENOMEM;
128 /* map physical address */
129 ep7312_fio_base = ioremap(ep7312_fio_pbase, SZ_1K);
130 if (!ep7312_fio_base) {
131 printk("ioremap EDB7312 NAND flash failed\n");
132 kfree(ep7312_mtd);
133 return -EIO;
136 /* Get pointer to private data */
137 this = (struct nand_chip *)(&ep7312_mtd[1]);
139 /* Initialize structures */
140 memset(ep7312_mtd, 0, sizeof(struct mtd_info));
141 memset(this, 0, sizeof(struct nand_chip));
143 /* Link the private data with the MTD structure */
144 ep7312_mtd->priv = this;
145 ep7312_mtd->owner = THIS_MODULE;
148 * Set GPIO Port B control register so that the pins are configured
149 * to be outputs for controlling the NAND flash.
151 clps_writeb(0xf0, ep7312_pxddr);
153 /* insert callbacks */
154 this->IO_ADDR_R = ep7312_fio_base;
155 this->IO_ADDR_W = ep7312_fio_base;
156 this->cmd_ctrl = ep7312_hwcontrol;
157 this->dev_ready = ep7312_device_ready;
158 /* 15 us command delay time */
159 this->chip_delay = 15;
161 /* Scan to find existence of the device */
162 if (nand_scan(ep7312_mtd, 1)) {
163 iounmap((void *)ep7312_fio_base);
164 kfree(ep7312_mtd);
165 return -ENXIO;
167 #ifdef CONFIG_MTD_PARTITIONS
168 ep7312_mtd->name = "edb7312-nand";
169 mtd_parts_nb = parse_mtd_partitions(ep7312_mtd, part_probes, &mtd_parts, 0);
170 if (mtd_parts_nb > 0)
171 part_type = "command line";
172 else
173 mtd_parts_nb = 0;
174 #endif
175 if (mtd_parts_nb == 0) {
176 mtd_parts = partition_info;
177 mtd_parts_nb = NUM_PARTITIONS;
178 part_type = "static";
181 /* Register the partitions */
182 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
183 add_mtd_partitions(ep7312_mtd, mtd_parts, mtd_parts_nb);
185 /* Return happy */
186 return 0;
189 module_init(ep7312_init);
192 * Clean up routine
194 static void __exit ep7312_cleanup(void)
196 struct nand_chip *this = (struct nand_chip *)&ep7312_mtd[1];
198 /* Release resources, unregister device */
199 nand_release(ap7312_mtd);
201 /* Release io resource */
202 iounmap(this->IO_ADDR_R);
204 /* Free the MTD device structure */
205 kfree(ep7312_mtd);
208 module_exit(ep7312_cleanup);
210 MODULE_LICENSE("GPL");
211 MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
212 MODULE_DESCRIPTION("MTD map driver for Cogent EDB7312 board");