Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/mtd/nand/toto.c |
| 3 | * |
| 4 | * Copyright (c) 2003 Texas Instruments |
| 5 | * |
| 6 | * Derived from drivers/mtd/autcpu12.c |
| 7 | * |
| 8 | * Copyright (c) 2002 Thomas Gleixner <tgxl@linutronix.de> |
| 9 | * |
| 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. |
| 13 | * |
| 14 | * Overview: |
| 15 | * This is a device driver for the NAND flash device found on the |
| 16 | * TI fido board. It supports 32MiB and 64MiB cards |
| 17 | * |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 18 | * $Id: toto.c,v 1.5 2005/11/07 11:14:31 gleixner Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
| 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> |
| 28 | #include <asm/io.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> |
| 34 | |
| 35 | /* |
| 36 | * MTD structure for TOTO board |
| 37 | */ |
| 38 | static struct mtd_info *toto_mtd = NULL; |
| 39 | |
| 40 | static unsigned long toto_io_base = OMAP_FLASH_1_BASE; |
| 41 | |
| 42 | #define CONFIG_NAND_WORKAROUND 1 |
| 43 | |
| 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) |
| 48 | |
| 49 | #define T_NAND_CTL_CLRALE(iob) gpiosetout(NAND_ALE, 0) |
| 50 | #define T_NAND_CTL_SETALE(iob) gpiosetout(NAND_ALE, NAND_ALE) |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 51 | #ifdef CONFIG_NAND_WORKAROUND /* "some" dev boards busted, blue wired to rts2 :( */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
| 54 | #else |
| 55 | #define T_NAND_CTL_CLRCLE(iob) gpiosetout(NAND_CLE, 0) |
| 56 | #define T_NAND_CTL_SETCLE(iob) gpiosetout(NAND_CLE, NAND_CLE) |
| 57 | #endif |
| 58 | #define T_NAND_CTL_SETNCE(iob) gpiosetout(NAND_NCE, 0) |
| 59 | #define T_NAND_CTL_CLRNCE(iob) gpiosetout(NAND_NCE, NAND_NCE) |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* |
| 62 | * Define partitions for flash devices |
| 63 | */ |
| 64 | |
| 65 | static struct mtd_partition partition_info64M[] = { |
| 66 | { .name = "toto kernel partition 1", |
| 67 | .offset = 0, |
| 68 | .size = 2 * SZ_1M }, |
| 69 | { .name = "toto file sys partition 2", |
| 70 | .offset = 2 * SZ_1M, |
| 71 | .size = 14 * SZ_1M }, |
| 72 | { .name = "toto user partition 3", |
| 73 | .offset = 16 * SZ_1M, |
| 74 | .size = 16 * SZ_1M }, |
| 75 | { .name = "toto devboard extra partition 4", |
| 76 | .offset = 32 * SZ_1M, |
| 77 | .size = 32 * SZ_1M }, |
| 78 | }; |
| 79 | |
| 80 | static struct mtd_partition partition_info32M[] = { |
| 81 | { .name = "toto kernel partition 1", |
| 82 | .offset = 0, |
| 83 | .size = 2 * SZ_1M }, |
| 84 | { .name = "toto file sys partition 2", |
| 85 | .offset = 2 * SZ_1M, |
| 86 | .size = 14 * SZ_1M }, |
| 87 | { .name = "toto user partition 3", |
| 88 | .offset = 16 * SZ_1M, |
| 89 | .size = 16 * SZ_1M }, |
| 90 | }; |
| 91 | |
| 92 | #define NUM_PARTITIONS32M 3 |
| 93 | #define NUM_PARTITIONS64M 4 |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 94 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | * hardware specific access to control-lines |
| 96 | */ |
| 97 | |
| 98 | static void toto_hwcontrol(struct mtd_info *mtd, int cmd) |
| 99 | { |
| 100 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 101 | udelay(1); /* hopefully enough time for tc make proceding write to clear */ |
| 102 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | case NAND_CTL_SETCLE: T_NAND_CTL_SETCLE(cmd); break; |
| 104 | case NAND_CTL_CLRCLE: T_NAND_CTL_CLRCLE(cmd); break; |
| 105 | |
| 106 | case NAND_CTL_SETALE: T_NAND_CTL_SETALE(cmd); break; |
| 107 | case NAND_CTL_CLRALE: T_NAND_CTL_CLRALE(cmd); break; |
| 108 | |
| 109 | case NAND_CTL_SETNCE: T_NAND_CTL_SETNCE(cmd); break; |
| 110 | case NAND_CTL_CLRNCE: T_NAND_CTL_CLRNCE(cmd); break; |
| 111 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 112 | udelay(1); /* allow time to ensure gpio state to over take memory write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /* |
| 116 | * Main initialization routine |
| 117 | */ |
David Woodhouse | cead4db | 2006-05-16 13:54:50 +0100 | [diff] [blame] | 118 | static int __init toto_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
| 120 | struct nand_chip *this; |
| 121 | int err = 0; |
| 122 | |
| 123 | /* Allocate memory for MTD device structure and private data */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 124 | toto_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | if (!toto_mtd) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 126 | printk(KERN_WARNING "Unable to allocate toto NAND MTD device structure.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | err = -ENOMEM; |
| 128 | goto out; |
| 129 | } |
| 130 | |
| 131 | /* Get pointer to private data */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 132 | this = (struct nand_chip *)(&toto_mtd[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | /* Initialize structures */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 135 | memset(toto_mtd, 0, sizeof(struct mtd_info)); |
| 136 | memset(this, 0, sizeof(struct nand_chip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | /* Link the private data with the MTD structure */ |
| 139 | toto_mtd->priv = this; |
David Woodhouse | 552d920 | 2006-05-14 01:20:46 +0100 | [diff] [blame] | 140 | toto_mtd->owner = THIS_MODULE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | /* Set address of NAND IO lines */ |
| 143 | this->IO_ADDR_R = toto_io_base; |
| 144 | this->IO_ADDR_W = toto_io_base; |
| 145 | this->hwcontrol = toto_hwcontrol; |
| 146 | this->dev_ready = NULL; |
| 147 | /* 25 us command delay time */ |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 148 | this->chip_delay = 30; |
Thomas Gleixner | 6dfc6d2 | 2006-05-23 12:00:46 +0200 | [diff] [blame^] | 149 | this->ecc.mode = NAND_ECC_SOFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 151 | /* Scan to find existance of the device */ |
| 152 | if (nand_scan(toto_mtd, 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | err = -ENXIO; |
| 154 | goto out_mtd; |
| 155 | } |
| 156 | |
| 157 | /* Register the partitions */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 158 | switch (toto_mtd->size) { |
| 159 | case SZ_64M: |
| 160 | add_mtd_partitions(toto_mtd, partition_info64M, NUM_PARTITIONS64M); |
| 161 | break; |
| 162 | case SZ_32M: |
| 163 | add_mtd_partitions(toto_mtd, partition_info32M, NUM_PARTITIONS32M); |
| 164 | break; |
| 165 | default:{ |
| 166 | printk(KERN_WARNING "Unsupported Nand device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | err = -ENXIO; |
| 168 | goto out_buf; |
| 169 | } |
| 170 | } |
| 171 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 172 | gpioreserve(NAND_MASK); /* claim our gpios */ |
| 173 | archflashwp(0, 0); /* open up flash for writing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | goto out; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 176 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 177 | out_buf: |
| 178 | kfree(this->data_buf); |
| 179 | out_mtd: |
| 180 | kfree(toto_mtd); |
| 181 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | return err; |
| 183 | } |
| 184 | |
| 185 | module_init(toto_init); |
| 186 | |
| 187 | /* |
| 188 | * Clean up routine |
| 189 | */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 190 | static void __exit toto_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
| 192 | /* Release resources, unregister device */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 193 | nand_release(toto_mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | /* Free the MTD device structure */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 196 | kfree(toto_mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | /* stop flash writes */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 199 | archflashwp(0, 1); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | /* release gpios to system */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 202 | gpiorelease(NAND_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | module_exit(toto_cleanup); |
| 206 | |
| 207 | MODULE_LICENSE("GPL"); |
| 208 | MODULE_AUTHOR("Richard Woodruff <r-woodruff2@ti.com>"); |
| 209 | MODULE_DESCRIPTION("Glue layer for NAND flash on toto board"); |