initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / mtd / nand / spia.c
blobacf6fc808b7658c4e3b396dc6bc9dde8d724c994
1 /*
2 * drivers/mtd/nand/spia.c
4 * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
7 * 10-29-2001 TG change to support hardwarespecific access
8 * to controllines (due to change in nand.c)
9 * page_cache added
11 * $Id: spia.c,v 1.21 2003/07/11 15:12:29 dwmw2 Exp $
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
17 * Overview:
18 * This is a device driver for the NAND flash device found on the
19 * SPIA board which utilizes the Toshiba TC58V64AFT part. This is
20 * a 64Mibit (8MiB x 8 bits) NAND flash device.
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 #include <linux/slab.h>
26 #include <linux/module.h>
27 #include <linux/mtd/mtd.h>
28 #include <linux/mtd/nand.h>
29 #include <linux/mtd/partitions.h>
30 #include <asm/io.h>
33 * MTD structure for SPIA board
35 static struct mtd_info *spia_mtd = NULL;
38 * Values specific to the SPIA board (used with EP7212 processor)
40 #define SPIA_IO_BASE 0xd0000000 /* Start of EP7212 IO address space */
41 #define SPIA_FIO_BASE 0xf0000000 /* Address where flash is mapped */
42 #define SPIA_PEDR 0x0080 /*
43 * IO offset to Port E data register
44 * where the CLE, ALE and NCE pins
45 * are wired to.
47 #define SPIA_PEDDR 0x00c0 /*
48 * IO offset to Port E data direction
49 * register so we can control the IO
50 * lines.
54 * Module stuff
57 static int spia_io_base = SPIA_IO_BASE;
58 static int spia_fio_base = SPIA_FIO_BASE;
59 static int spia_pedr = SPIA_PEDR;
60 static int spia_peddr = SPIA_PEDDR;
62 MODULE_PARM(spia_io_base, "i");
63 MODULE_PARM(spia_fio_base, "i");
64 MODULE_PARM(spia_pedr, "i");
65 MODULE_PARM(spia_peddr, "i");
68 * Define partitions for flash device
70 const static struct mtd_partition partition_info[] = {
72 .name = "SPIA flash partition 1",
73 .offset = 0,
74 .size = 2*1024*1024
77 .name = "SPIA flash partition 2",
78 .offset = 2*1024*1024,
79 .size = 6*1024*1024
82 #define NUM_PARTITIONS 2
85 /*
86 * hardware specific access to control-lines
88 static void spia_hwcontrol(struct mtd_info *mtd, int cmd){
90 switch(cmd){
92 case NAND_CTL_SETCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x01; break;
93 case NAND_CTL_CLRCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x01; break;
95 case NAND_CTL_SETALE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x02; break;
96 case NAND_CTL_CLRALE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x02; break;
98 case NAND_CTL_SETNCE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x04; break;
99 case NAND_CTL_CLRNCE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x04; break;
104 * Main initialization routine
106 int __init spia_init (void)
108 struct nand_chip *this;
110 /* Allocate memory for MTD device structure and private data */
111 spia_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip),
112 GFP_KERNEL);
113 if (!spia_mtd) {
114 printk ("Unable to allocate SPIA NAND MTD device structure.\n");
115 return -ENOMEM;
118 /* Get pointer to private data */
119 this = (struct nand_chip *) (&spia_mtd[1]);
121 /* Initialize structures */
122 memset((char *) spia_mtd, 0, sizeof(struct mtd_info));
123 memset((char *) this, 0, sizeof(struct nand_chip));
125 /* Link the private data with the MTD structure */
126 spia_mtd->priv = this;
129 * Set GPIO Port E control register so that the pins are configured
130 * to be outputs for controlling the NAND flash.
132 (*(volatile unsigned char *) (spia_io_base + spia_peddr)) = 0x07;
134 /* Set address of NAND IO lines */
135 this->IO_ADDR_R = spia_fio_base;
136 this->IO_ADDR_W = spia_fio_base;
137 /* Set address of hardware control function */
138 this->hwcontrol = spia_hwcontrol;
139 /* 15 us command delay time */
140 this->chip_delay = 15;
142 /* Scan to find existence of the device */
143 if (nand_scan (spia_mtd, 1)) {
144 kfree (spia_mtd);
145 return -ENXIO;
148 /* Allocate memory for internal data buffer */
149 this->data_buf = kmalloc (sizeof(u_char) * (spia_mtd->oobblock + spia_mtd->oobsize), GFP_KERNEL);
150 if (!this->data_buf) {
151 printk ("Unable to allocate NAND data buffer for SPIA.\n");
152 kfree (spia_mtd);
153 return -ENOMEM;
156 /* Register the partitions */
157 add_mtd_partitions(spia_mtd, partition_info, NUM_PARTITIONS);
159 /* Return happy */
160 return 0;
162 module_init(spia_init);
165 * Clean up routine
167 #ifdef MODULE
168 static void __exit spia_cleanup (void)
170 struct nand_chip *this = (struct nand_chip *) &spia_mtd[1];
172 /* Unregister the device */
173 del_mtd_device (spia_mtd);
175 /* Free internal data buffer */
176 kfree (this->data_buf);
178 /* Free the MTD device structure */
179 kfree (spia_mtd);
181 module_exit(spia_cleanup);
182 #endif
184 MODULE_LICENSE("GPL");
185 MODULE_AUTHOR("Steven J. Hill <sjhill@realitydiluted.com");
186 MODULE_DESCRIPTION("Board-specific glue layer for NAND flash on SPIA board");