Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/mtd/nand/edb7312.c |
| 3 | * |
| 4 | * Copyright (C) 2002 Marius Gröger (mag@sysgo.de) |
| 5 | * |
| 6 | * Derived from drivers/mtd/nand/autcpu12.c |
| 7 | * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de) |
| 8 | * |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 9 | * $Id: edb7312.c,v 1.12 2005/11/07 11:14:30 gleixner Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * Overview: |
| 16 | * This is a device driver for the NAND flash device found on the |
| 17 | * CLEP7312 board which utilizes the Toshiba TC58V64AFT part. This is |
| 18 | * a 64Mibit (8MiB x 8 bits) NAND flash device. |
| 19 | */ |
| 20 | |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/mtd/mtd.h> |
| 25 | #include <linux/mtd/nand.h> |
| 26 | #include <linux/mtd/partitions.h> |
| 27 | #include <asm/io.h> |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 28 | #include <asm/arch/hardware.h> /* for CLPS7111_VIRT_BASE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/sizes.h> |
| 30 | #include <asm/hardware/clps7111.h> |
| 31 | |
| 32 | /* |
| 33 | * MTD structure for EDB7312 board |
| 34 | */ |
| 35 | static struct mtd_info *ep7312_mtd = NULL; |
| 36 | |
| 37 | /* |
| 38 | * Values specific to the EDB7312 board (used with EP7312 processor) |
| 39 | */ |
| 40 | #define EP7312_FIO_PBASE 0x10000000 /* Phys address of flash */ |
| 41 | #define EP7312_PXDR 0x0001 /* |
| 42 | * IO offset to Port B data register |
| 43 | * where the CLE, ALE and NCE pins |
| 44 | * are wired to. |
| 45 | */ |
| 46 | #define EP7312_PXDDR 0x0041 /* |
| 47 | * IO offset to Port B data direction |
| 48 | * register so we can control the IO |
| 49 | * lines. |
| 50 | */ |
| 51 | |
| 52 | /* |
| 53 | * Module stuff |
| 54 | */ |
| 55 | |
| 56 | static unsigned long ep7312_fio_pbase = EP7312_FIO_PBASE; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 57 | static void __iomem *ep7312_pxdr = (void __iomem *)EP7312_PXDR; |
| 58 | static void __iomem *ep7312_pxddr = (void __iomem *)EP7312_PXDDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | #ifdef CONFIG_MTD_PARTITIONS |
| 61 | /* |
| 62 | * Define static partitions for flash device |
| 63 | */ |
| 64 | static struct mtd_partition partition_info[] = { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 65 | {.name = "EP7312 Nand Flash", |
| 66 | .offset = 0, |
| 67 | .size = 8 * 1024 * 1024} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | }; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #define NUM_PARTITIONS 1 |
| 71 | |
| 72 | #endif |
| 73 | |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 74 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | * hardware specific access to control-lines |
| 76 | */ |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 77 | static void ep7312_hwcontrol(struct mtd_info *mtd, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 79 | switch (cmd) { |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 80 | |
| 81 | case NAND_CTL_SETCLE: |
| 82 | clps_writeb(clps_readb(ep7312_pxdr) | 0x10, ep7312_pxdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | break; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 84 | case NAND_CTL_CLRCLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | clps_writeb(clps_readb(ep7312_pxdr) & ~0x10, ep7312_pxdr); |
| 86 | break; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | case NAND_CTL_SETALE: |
| 89 | clps_writeb(clps_readb(ep7312_pxdr) | 0x20, ep7312_pxdr); |
| 90 | break; |
| 91 | case NAND_CTL_CLRALE: |
| 92 | clps_writeb(clps_readb(ep7312_pxdr) & ~0x20, ep7312_pxdr); |
| 93 | break; |
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 | case NAND_CTL_SETNCE: |
| 96 | clps_writeb((clps_readb(ep7312_pxdr) | 0x80) & ~0x40, ep7312_pxdr); |
| 97 | break; |
| 98 | case NAND_CTL_CLRNCE: |
| 99 | clps_writeb((clps_readb(ep7312_pxdr) | 0x80) | 0x40, ep7312_pxdr); |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * read device ready pin |
| 106 | */ |
| 107 | static int ep7312_device_ready(struct mtd_info *mtd) |
| 108 | { |
| 109 | return 1; |
| 110 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | #ifdef CONFIG_MTD_PARTITIONS |
| 113 | const char *part_probes[] = { "cmdlinepart", NULL }; |
| 114 | #endif |
| 115 | |
| 116 | /* |
| 117 | * Main initialization routine |
| 118 | */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 119 | static int __init ep7312_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
| 121 | struct nand_chip *this; |
| 122 | const char *part_type = 0; |
| 123 | int mtd_parts_nb = 0; |
| 124 | struct mtd_partition *mtd_parts = 0; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 125 | void __iomem *ep7312_fio_base; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /* Allocate memory for MTD device structure and private data */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 128 | ep7312_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | if (!ep7312_mtd) { |
| 130 | printk("Unable to allocate EDB7312 NAND MTD device structure.\n"); |
| 131 | return -ENOMEM; |
| 132 | } |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | /* map physical adress */ |
| 135 | ep7312_fio_base = ioremap(ep7312_fio_pbase, SZ_1K); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 136 | if (!ep7312_fio_base) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | printk("ioremap EDB7312 NAND flash failed\n"); |
| 138 | kfree(ep7312_mtd); |
| 139 | return -EIO; |
| 140 | } |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* Get pointer to private data */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 143 | this = (struct nand_chip *)(&ep7312_mtd[1]); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | /* Initialize structures */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 146 | memset(ep7312_mtd, 0, sizeof(struct mtd_info)); |
| 147 | memset(this, 0, sizeof(struct nand_chip)); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | /* Link the private data with the MTD structure */ |
| 150 | ep7312_mtd->priv = this; |
David Woodhouse | 552d920 | 2006-05-14 01:20:46 +0100 | [diff] [blame^] | 151 | ep7312_mtd->owner = THIS_MODULE; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | /* |
| 154 | * Set GPIO Port B control register so that the pins are configured |
| 155 | * to be outputs for controlling the NAND flash. |
| 156 | */ |
| 157 | clps_writeb(0xf0, ep7312_pxddr); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /* insert callbacks */ |
| 160 | this->IO_ADDR_R = ep7312_fio_base; |
| 161 | this->IO_ADDR_W = ep7312_fio_base; |
| 162 | this->hwcontrol = ep7312_hwcontrol; |
| 163 | this->dev_ready = ep7312_device_ready; |
| 164 | /* 15 us command delay time */ |
| 165 | this->chip_delay = 15; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | /* Scan to find existence of the device */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 168 | if (nand_scan(ep7312_mtd, 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | iounmap((void *)ep7312_fio_base); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 170 | kfree(ep7312_mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | return -ENXIO; |
| 172 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | #ifdef CONFIG_MTD_PARTITIONS |
| 174 | ep7312_mtd->name = "edb7312-nand"; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 175 | mtd_parts_nb = parse_mtd_partitions(ep7312_mtd, part_probes, &mtd_parts, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | if (mtd_parts_nb > 0) |
| 177 | part_type = "command line"; |
| 178 | else |
| 179 | mtd_parts_nb = 0; |
| 180 | #endif |
| 181 | if (mtd_parts_nb == 0) { |
| 182 | mtd_parts = partition_info; |
| 183 | mtd_parts_nb = NUM_PARTITIONS; |
| 184 | part_type = "static"; |
| 185 | } |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | /* Register the partitions */ |
| 188 | printk(KERN_NOTICE "Using %s partition definition\n", part_type); |
| 189 | add_mtd_partitions(ep7312_mtd, mtd_parts, mtd_parts_nb); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | /* Return happy */ |
| 192 | return 0; |
| 193 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | module_init(ep7312_init); |
| 196 | |
| 197 | /* |
| 198 | * Clean up routine |
| 199 | */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 200 | static void __exit ep7312_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 202 | struct nand_chip *this = (struct nand_chip *)&ep7312_mtd[1]; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | /* Release resources, unregister device */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 205 | nand_release(ap7312_mtd); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | /* Free internal data buffer */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 208 | kfree(this->data_buf); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | /* Free the MTD device structure */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 211 | kfree(ep7312_mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | module_exit(ep7312_cleanup); |
| 215 | |
| 216 | MODULE_LICENSE("GPL"); |
| 217 | MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>"); |
| 218 | MODULE_DESCRIPTION("MTD map driver for Cogent EDB7312 board"); |