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