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 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 * This is a device driver for the NAND flash device found on the
15 * CLEP7312 board which utilizes the Toshiba TC58V64AFT part. This is
16 * a 64Mibit (8MiB x 8 bits) NAND flash device.
19 #include <linux/slab.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/nand.h>
24 #include <linux/mtd/partitions.h>
26 #include <mach/hardware.h> /* for CLPS7111_VIRT_BASE */
27 #include <asm/sizes.h>
28 #include <asm/hardware/clps7111.h>
31 * MTD structure for EDB7312 board
33 static struct mtd_info
*ep7312_mtd
= NULL
;
36 * Values specific to the EDB7312 board (used with EP7312 processor)
38 #define EP7312_FIO_PBASE 0x10000000 /* Phys address of flash */
39 #define EP7312_PXDR 0x0001 /*
40 * IO offset to Port B data register
41 * where the CLE, ALE and NCE pins
44 #define EP7312_PXDDR 0x0041 /*
45 * IO offset to Port B data direction
46 * register so we can control the IO
54 static unsigned long ep7312_fio_pbase
= EP7312_FIO_PBASE
;
55 static void __iomem
*ep7312_pxdr
= (void __iomem
*)EP7312_PXDR
;
56 static void __iomem
*ep7312_pxddr
= (void __iomem
*)EP7312_PXDDR
;
58 #ifdef CONFIG_MTD_PARTITIONS
60 * Define static partitions for flash device
62 static struct mtd_partition partition_info
[] = {
63 {.name
= "EP7312 Nand Flash",
65 .size
= 8 * 1024 * 1024}
68 #define NUM_PARTITIONS 1
73 * hardware specific access to control-lines
75 * NAND_NCE: bit 0 -> bit 6 (bit 7 = 1)
76 * NAND_CLE: bit 1 -> bit 4
77 * NAND_ALE: bit 2 -> bit 5
79 static void ep7312_hwcontrol(struct mtd_info
*mtd
, int cmd
, unsigned int ctrl
)
81 struct nand_chip
*chip
= mtd
->priv
;
83 if (ctrl
& NAND_CTRL_CHANGE
) {
84 unsigned char bits
= 0x80;
86 bits
|= (ctrl
& (NAND_CLE
| NAND_ALE
)) << 3;
87 bits
|= (ctrl
& NAND_NCE
) ? 0x00 : 0x40;
89 clps_writeb((clps_readb(ep7312_pxdr
) & 0xF0) | bits
,
92 if (cmd
!= NAND_CMD_NONE
)
93 writeb(cmd
, chip
->IO_ADDR_W
);
97 * read device ready pin
99 static int ep7312_device_ready(struct mtd_info
*mtd
)
104 #ifdef CONFIG_MTD_PARTITIONS
105 const char *part_probes
[] = { "cmdlinepart", NULL
};
109 * Main initialization routine
111 static int __init
ep7312_init(void)
113 struct nand_chip
*this;
114 const char *part_type
= 0;
115 int mtd_parts_nb
= 0;
116 struct mtd_partition
*mtd_parts
= 0;
117 void __iomem
*ep7312_fio_base
;
119 /* Allocate memory for MTD device structure and private data */
120 ep7312_mtd
= kmalloc(sizeof(struct mtd_info
) + sizeof(struct nand_chip
), GFP_KERNEL
);
122 printk("Unable to allocate EDB7312 NAND MTD device structure.\n");
126 /* map physical address */
127 ep7312_fio_base
= ioremap(ep7312_fio_pbase
, SZ_1K
);
128 if (!ep7312_fio_base
) {
129 printk("ioremap EDB7312 NAND flash failed\n");
134 /* Get pointer to private data */
135 this = (struct nand_chip
*)(&ep7312_mtd
[1]);
137 /* Initialize structures */
138 memset(ep7312_mtd
, 0, sizeof(struct mtd_info
));
139 memset(this, 0, sizeof(struct nand_chip
));
141 /* Link the private data with the MTD structure */
142 ep7312_mtd
->priv
= this;
143 ep7312_mtd
->owner
= THIS_MODULE
;
146 * Set GPIO Port B control register so that the pins are configured
147 * to be outputs for controlling the NAND flash.
149 clps_writeb(0xf0, ep7312_pxddr
);
151 /* insert callbacks */
152 this->IO_ADDR_R
= ep7312_fio_base
;
153 this->IO_ADDR_W
= ep7312_fio_base
;
154 this->cmd_ctrl
= ep7312_hwcontrol
;
155 this->dev_ready
= ep7312_device_ready
;
156 /* 15 us command delay time */
157 this->chip_delay
= 15;
159 /* Scan to find existence of the device */
160 if (nand_scan(ep7312_mtd
, 1)) {
161 iounmap((void *)ep7312_fio_base
);
165 #ifdef CONFIG_MTD_PARTITIONS
166 ep7312_mtd
->name
= "edb7312-nand";
167 mtd_parts_nb
= parse_mtd_partitions(ep7312_mtd
, part_probes
, &mtd_parts
, 0);
168 if (mtd_parts_nb
> 0)
169 part_type
= "command line";
173 if (mtd_parts_nb
== 0) {
174 mtd_parts
= partition_info
;
175 mtd_parts_nb
= NUM_PARTITIONS
;
176 part_type
= "static";
179 /* Register the partitions */
180 printk(KERN_NOTICE
"Using %s partition definition\n", part_type
);
181 add_mtd_partitions(ep7312_mtd
, mtd_parts
, mtd_parts_nb
);
187 module_init(ep7312_init
);
192 static void __exit
ep7312_cleanup(void)
194 struct nand_chip
*this = (struct nand_chip
*)&ep7312_mtd
[1];
196 /* Release resources, unregister device */
197 nand_release(ap7312_mtd
);
199 /* Release io resource */
200 iounmap(this->IO_ADDR_R
);
202 /* Free the MTD device structure */
206 module_exit(ep7312_cleanup
);
208 MODULE_LICENSE("GPL");
209 MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
210 MODULE_DESCRIPTION("MTD map driver for Cogent EDB7312 board");