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