2 * drivers/mtd/nand/spia.c
4 * Copyright (C) 2000 Steven J. Hill (sjhill@cotw.com)
7 * 10-29-2001 TG change to support hardwarespecific access
8 * to controllines (due to change in nand.c)
11 * $Id: spia.c,v 1.1.1.1 2005/04/11 02:50:26 jack 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.
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/slab.h>
24 #include <linux/module.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/nand.h>
27 #include <linux/mtd/partitions.h>
31 * MTD structure for SPIA board
33 static struct mtd_info *spia_mtd = NULL;
36 * Values specific to the SPIA board (used with EP7212 processor)
38 #define SPIA_IO_ADDR = 0xd0000000 /* Start of EP7212 IO address space */
39 #define SPIA_FIO_ADDR = 0xf0000000 /* Address where flash is mapped */
40 #define SPIA_PEDR = 0x0080 /*
41 * IO offset to Port E data register
42 * where the CLE, ALE and NCE pins
45 #define SPIA_PEDDR = 0x00c0 /*
46 * IO offset to Port E data direction
47 * register so we can control the IO
55 static int spia_io_base = SPIA_IO_BASE;
56 static int spia_fio_base = SPIA_FIO_BASE;
57 static int spia_pedr = SPIA_PEDR;
58 static int spia_peddr = SPIA_PEDDR;
60 MODULE_PARM(spia_io_base, "i");
61 MODULE_PARM(spia_fio_base, "i");
62 MODULE_PARM(spia_pedr, "i");
63 MODULE_PARM(spia_peddr, "i");
65 __setup("spia_io_base=",spia_io_base);
66 __setup("spia_fio_base=",spia_fio_base);
67 __setup("spia_pedr=",spia_pedr);
68 __setup("spia_peddr=",spia_peddr);
71 * Define partitions for flash device
73 const static struct mtd_partition partition_info[] = {
74 { name: "SPIA flash partition 1",
77 { name: "SPIA flash partition 2",
81 #define NUM_PARTITIONS 2
85 * hardware specific access to control-lines
87 void spia_hwcontrol(int cmd){
91 case NAND_CTL_SETCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x01; break;
92 case NAND_CTL_CLRCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x01; break;
94 case NAND_CTL_SETALE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x02; break;
95 case NAND_CTL_CLRALE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x02; break;
97 case NAND_CTL_SETNCE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x04; break;
98 case NAND_CTL_CLRNCE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x04; break;
103 * Main initialization routine
105 int __init spia_init (void)
107 struct nand_chip *this;
109 /* Allocate memory for MTD device structure and private data */
110 spia_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip),
113 printk ("Unable to allocate SPIA NAND MTD device structure.\n");
117 /* Get pointer to private data */
118 this = (struct nand_chip *) (&spia_mtd[1]);
120 /* Initialize structures */
121 memset((char *) spia_mtd, 0, sizeof(struct mtd_info));
122 memset((char *) this, 0, sizeof(struct nand_chip));
124 /* Link the private data with the MTD structure */
125 spia_mtd->priv = this;
128 * Set GPIO Port E control register so that the pins are configured
129 * to be outputs for controlling the NAND flash.
131 (*(volatile unsigned char *) (spia_io_base + spia_peddr)) = 0x07;
133 /* Set address of NAND IO lines */
134 this->IO_ADDR_R = spia_fio_base;
135 this->IO_ADDR_W = spia_fio_base;
136 /* Set address of hardware control function */
137 this->hwcontrol = spia_hwcontrol;
138 /* 15 us command delay time */
139 this->chip_delay = 15;
141 /* Scan to find existence of the device */
142 if (nand_scan (spia_mtd)) {
147 /* Allocate memory for internal data buffer */
148 this->data_buf = kmalloc (sizeof(u_char) * (spia_mtd->oobblock + spia_mtd->oobsize), GFP_KERNEL);
149 if (!this->data_buf) {
150 printk ("Unable to allocate NAND data buffer for SPIA.\n");
155 /* Allocate memory for internal data buffer */
156 this->data_cache = kmalloc (sizeof(u_char) * (spia_mtd->oobblock + spia_mtd->oobsize), GFP_KERNEL);
157 if (!this->data_cache) {
158 printk ("Unable to allocate NAND data cache for SPIA.\n");
159 kfree (this->data_buf);
163 this->cache_page = -1;
165 /* Register the partitions */
166 add_mtd_partitions(spia_mtd, partition_info, NUM_PARTITIONS);
171 module_init(spia_init);
177 static void __exit spia_cleanup (void)
179 struct nand_chip *this = (struct nand_chip *) &spia_mtd[1];
181 /* Unregister the device */
182 del_mtd_device (spia_mtd);
184 /* Free internal data buffer */
185 kfree (this->data_buf);
186 kfree (this->page_cache);
188 /* Free the MTD device structure */
191 module_exit(spia_cleanup);
194 MODULE_LICENSE("GPL");
195 MODULE_AUTHOR("Steven J. Hill <sjhill@cotw.com");
196 MODULE_DESCRIPTION("Board-specific glue layer for NAND flash on SPIA board");