2 * drivers/mtd/nand/toto.c
4 * Copyright (c) 2003 Texas Instruments
6 * Derived from drivers/mtd/autcpu12.c
8 * Copyright (c) 2002 Thomas Gleixner <tgxl@linutronix.de>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 * This is a device driver for the NAND flash device found on the
16 * TI fido board. It supports 32MiB and 64MiB cards
18 * $Id: toto.c,v 1.4 2004/10/05 13:50:20 gleixner Exp $
21 #include <linux/slab.h>
22 #include <linux/init.h>
23 #include <linux/module.h>
24 #include <linux/delay.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/nand.h>
27 #include <linux/mtd/partitions.h>
29 #include <asm/arch/hardware.h>
30 #include <asm/sizes.h>
31 #include <asm/arch/toto.h>
32 #include <asm/arch-omap1510/hardware.h>
33 #include <asm/arch/gpio.h>
36 * MTD structure for TOTO board
38 static struct mtd_info
*toto_mtd
= NULL
;
40 static unsigned long toto_io_base
= OMAP_FLASH_1_BASE
;
42 #define CONFIG_NAND_WORKAROUND 1
44 #define NAND_NCE 0x4000
45 #define NAND_CLE 0x1000
46 #define NAND_ALE 0x0002
47 #define NAND_MASK (NAND_CLE | NAND_ALE | NAND_NCE)
49 #define T_NAND_CTL_CLRALE(iob) gpiosetout(NAND_ALE, 0)
50 #define T_NAND_CTL_SETALE(iob) gpiosetout(NAND_ALE, NAND_ALE)
51 #ifdef CONFIG_NAND_WORKAROUND /* "some" dev boards busted, blue wired to rts2 :( */
52 #define T_NAND_CTL_CLRCLE(iob) gpiosetout(NAND_CLE, 0); rts2setout(2, 2)
53 #define T_NAND_CTL_SETCLE(iob) gpiosetout(NAND_CLE, NAND_CLE); rts2setout(2, 0)
55 #define T_NAND_CTL_CLRCLE(iob) gpiosetout(NAND_CLE, 0)
56 #define T_NAND_CTL_SETCLE(iob) gpiosetout(NAND_CLE, NAND_CLE)
58 #define T_NAND_CTL_SETNCE(iob) gpiosetout(NAND_NCE, 0)
59 #define T_NAND_CTL_CLRNCE(iob) gpiosetout(NAND_NCE, NAND_NCE)
62 * Define partitions for flash devices
65 static struct mtd_partition partition_info64M
[] = {
66 { .name
= "toto kernel partition 1",
69 { .name
= "toto file sys partition 2",
72 { .name
= "toto user partition 3",
75 { .name
= "toto devboard extra partition 4",
80 static struct mtd_partition partition_info32M
[] = {
81 { .name
= "toto kernel partition 1",
84 { .name
= "toto file sys partition 2",
87 { .name
= "toto user partition 3",
92 #define NUM_PARTITIONS32M 3
93 #define NUM_PARTITIONS64M 4
95 * hardware specific access to control-lines
98 static void toto_hwcontrol(struct mtd_info
*mtd
, int cmd
)
101 udelay(1); /* hopefully enough time for tc make proceding write to clear */
104 case NAND_CTL_SETCLE
: T_NAND_CTL_SETCLE(cmd
); break;
105 case NAND_CTL_CLRCLE
: T_NAND_CTL_CLRCLE(cmd
); break;
107 case NAND_CTL_SETALE
: T_NAND_CTL_SETALE(cmd
); break;
108 case NAND_CTL_CLRALE
: T_NAND_CTL_CLRALE(cmd
); break;
110 case NAND_CTL_SETNCE
: T_NAND_CTL_SETNCE(cmd
); break;
111 case NAND_CTL_CLRNCE
: T_NAND_CTL_CLRNCE(cmd
); break;
113 udelay(1); /* allow time to ensure gpio state to over take memory write */
117 * Main initialization routine
119 int __init
toto_init (void)
121 struct nand_chip
*this;
124 /* Allocate memory for MTD device structure and private data */
125 toto_mtd
= kmalloc (sizeof(struct mtd_info
) + sizeof (struct nand_chip
),
128 printk (KERN_WARNING
"Unable to allocate toto NAND MTD device structure.\n");
133 /* Get pointer to private data */
134 this = (struct nand_chip
*) (&toto_mtd
[1]);
136 /* Initialize structures */
137 memset((char *) toto_mtd
, 0, sizeof(struct mtd_info
));
138 memset((char *) this, 0, sizeof(struct nand_chip
));
140 /* Link the private data with the MTD structure */
141 toto_mtd
->priv
= this;
143 /* Set address of NAND IO lines */
144 this->IO_ADDR_R
= toto_io_base
;
145 this->IO_ADDR_W
= toto_io_base
;
146 this->hwcontrol
= toto_hwcontrol
;
147 this->dev_ready
= NULL
;
148 /* 25 us command delay time */
149 this->chip_delay
= 30;
150 this->eccmode
= NAND_ECC_SOFT
;
152 /* Scan to find existance of the device */
153 if (nand_scan (toto_mtd
, 1)) {
158 /* Register the partitions */
159 switch(toto_mtd
->size
){
160 case SZ_64M
: add_mtd_partitions(toto_mtd
, partition_info64M
, NUM_PARTITIONS64M
); break;
161 case SZ_32M
: add_mtd_partitions(toto_mtd
, partition_info32M
, NUM_PARTITIONS32M
); break;
163 printk (KERN_WARNING
"Unsupported Nand device\n");
169 gpioreserve(NAND_MASK
); /* claim our gpios */
170 archflashwp(0,0); /* open up flash for writing */
175 kfree (this->data_buf
);
182 module_init(toto_init
);
187 static void __exit
toto_cleanup (void)
189 /* Release resources, unregister device */
190 nand_release (toto_mtd
);
192 /* Free the MTD device structure */
195 /* stop flash writes */
198 /* release gpios to system */
199 gpiorelease(NAND_MASK
);
201 module_exit(toto_cleanup
);
203 MODULE_LICENSE("GPL");
204 MODULE_AUTHOR("Richard Woodruff <r-woodruff2@ti.com>");
205 MODULE_DESCRIPTION("Glue layer for NAND flash on toto board");