Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * drivers/mtd/nand/ts7250.c |
| 3 | * |
| 4 | * Copyright (C) 2004 Technologic Systems (support@embeddedARM.com) |
| 5 | * |
| 6 | * Derived from drivers/mtd/nand/edb7312.c |
David Woodhouse | 151e765 | 2006-05-14 01:51:54 +0100 | [diff] [blame] | 7 | * Copyright (C) 2004 Marius Gröger (mag@sysgo.de) |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 8 | * |
| 9 | * Derived from drivers/mtd/nand/autcpu12.c |
| 10 | * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de) |
| 11 | * |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License version 2 as |
| 14 | * published by the Free Software Foundation. |
| 15 | * |
| 16 | * Overview: |
| 17 | * This is a device driver for the NAND flash device found on the |
| 18 | * TS-7250 board which utilizes a Samsung 32 Mbyte part. |
| 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> |
Hartley Sweeten | 583ddaf | 2009-07-06 17:39:50 +0100 | [diff] [blame] | 27 | #include <linux/io.h> |
| 28 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 29 | #include <mach/hardware.h> |
Hartley Sweeten | 583ddaf | 2009-07-06 17:39:50 +0100 | [diff] [blame] | 30 | #include <mach/ts72xx.h> |
| 31 | |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 32 | #include <asm/sizes.h> |
| 33 | #include <asm/mach-types.h> |
| 34 | |
| 35 | /* |
| 36 | * MTD structure for TS7250 board |
| 37 | */ |
| 38 | static struct mtd_info *ts7250_mtd = NULL; |
| 39 | |
| 40 | #ifdef CONFIG_MTD_PARTITIONS |
| 41 | static const char *part_probes[] = { "cmdlinepart", NULL }; |
| 42 | |
| 43 | #define NUM_PARTITIONS 3 |
| 44 | |
| 45 | /* |
| 46 | * Define static partitions for flash device |
| 47 | */ |
| 48 | static struct mtd_partition partition_info32[] = { |
| 49 | { |
| 50 | .name = "TS-BOOTROM", |
| 51 | .offset = 0x00000000, |
| 52 | .size = 0x00004000, |
| 53 | }, { |
| 54 | .name = "Linux", |
| 55 | .offset = 0x00004000, |
| 56 | .size = 0x01d00000, |
| 57 | }, { |
| 58 | .name = "RedBoot", |
| 59 | .offset = 0x01d04000, |
| 60 | .size = 0x002fc000, |
| 61 | }, |
| 62 | }; |
| 63 | |
| 64 | /* |
| 65 | * Define static partitions for flash device |
| 66 | */ |
| 67 | static struct mtd_partition partition_info128[] = { |
| 68 | { |
| 69 | .name = "TS-BOOTROM", |
| 70 | .offset = 0x00000000, |
| 71 | .size = 0x00004000, |
| 72 | }, { |
| 73 | .name = "Linux", |
| 74 | .offset = 0x00004000, |
| 75 | .size = 0x07d00000, |
| 76 | }, { |
| 77 | .name = "RedBoot", |
| 78 | .offset = 0x07d04000, |
| 79 | .size = 0x002fc000, |
| 80 | }, |
| 81 | }; |
| 82 | #endif |
| 83 | |
| 84 | |
| 85 | /* |
| 86 | * hardware specific access to control-lines |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 87 | * |
| 88 | * ctrl: |
| 89 | * NAND_NCE: bit 0 -> bit 2 |
| 90 | * NAND_CLE: bit 1 -> bit 1 |
| 91 | * NAND_ALE: bit 2 -> bit 0 |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 92 | */ |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 93 | static void ts7250_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 94 | { |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 95 | struct nand_chip *chip = mtd->priv; |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 96 | |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 97 | if (ctrl & NAND_CTRL_CHANGE) { |
| 98 | unsigned long addr = TS72XX_NAND_CONTROL_VIRT_BASE; |
| 99 | unsigned char bits; |
| 100 | |
Petr Stetiar | 0e4ced5 | 2006-06-23 19:17:03 +0200 | [diff] [blame] | 101 | bits = (ctrl & NAND_NCE) << 2; |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 102 | bits |= ctrl & NAND_CLE; |
| 103 | bits |= (ctrl & NAND_ALE) >> 2; |
| 104 | |
| 105 | __raw_writeb((__raw_readb(addr) & ~0x7) | bits, addr); |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 106 | } |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 107 | |
| 108 | if (cmd != NAND_CMD_NONE) |
| 109 | writeb(cmd, chip->IO_ADDR_W); |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /* |
| 113 | * read device ready pin |
| 114 | */ |
| 115 | static int ts7250_device_ready(struct mtd_info *mtd) |
| 116 | { |
| 117 | return __raw_readb(TS72XX_NAND_BUSY_VIRT_BASE) & 0x20; |
| 118 | } |
| 119 | |
| 120 | /* |
| 121 | * Main initialization routine |
| 122 | */ |
| 123 | static int __init ts7250_init(void) |
| 124 | { |
| 125 | struct nand_chip *this; |
| 126 | const char *part_type = 0; |
| 127 | int mtd_parts_nb = 0; |
| 128 | struct mtd_partition *mtd_parts = 0; |
| 129 | |
| 130 | if (!machine_is_ts72xx() || board_is_ts7200()) |
| 131 | return -ENXIO; |
| 132 | |
| 133 | /* Allocate memory for MTD device structure and private data */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 134 | ts7250_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 135 | if (!ts7250_mtd) { |
| 136 | printk("Unable to allocate TS7250 NAND MTD device structure.\n"); |
| 137 | return -ENOMEM; |
| 138 | } |
| 139 | |
| 140 | /* Get pointer to private data */ |
| 141 | this = (struct nand_chip *)(&ts7250_mtd[1]); |
| 142 | |
| 143 | /* Initialize structures */ |
| 144 | memset(ts7250_mtd, 0, sizeof(struct mtd_info)); |
| 145 | memset(this, 0, sizeof(struct nand_chip)); |
| 146 | |
| 147 | /* Link the private data with the MTD structure */ |
| 148 | ts7250_mtd->priv = this; |
David Woodhouse | 552d920 | 2006-05-14 01:20:46 +0100 | [diff] [blame] | 149 | ts7250_mtd->owner = THIS_MODULE; |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 150 | |
| 151 | /* insert callbacks */ |
| 152 | this->IO_ADDR_R = (void *)TS72XX_NAND_DATA_VIRT_BASE; |
| 153 | this->IO_ADDR_W = (void *)TS72XX_NAND_DATA_VIRT_BASE; |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 154 | this->cmd_ctrl = ts7250_hwcontrol; |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 155 | this->dev_ready = ts7250_device_ready; |
| 156 | this->chip_delay = 15; |
Thomas Gleixner | 6dfc6d2 | 2006-05-23 12:00:46 +0200 | [diff] [blame] | 157 | this->ecc.mode = NAND_ECC_SOFT; |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 158 | |
| 159 | printk("Searching for NAND flash...\n"); |
| 160 | /* Scan to find existence of the device */ |
| 161 | if (nand_scan(ts7250_mtd, 1)) { |
| 162 | kfree(ts7250_mtd); |
| 163 | return -ENXIO; |
| 164 | } |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 165 | #ifdef CONFIG_MTD_PARTITIONS |
| 166 | ts7250_mtd->name = "ts7250-nand"; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 167 | mtd_parts_nb = parse_mtd_partitions(ts7250_mtd, part_probes, &mtd_parts, 0); |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 168 | if (mtd_parts_nb > 0) |
| 169 | part_type = "command line"; |
| 170 | else |
| 171 | mtd_parts_nb = 0; |
| 172 | #endif |
| 173 | if (mtd_parts_nb == 0) { |
| 174 | mtd_parts = partition_info32; |
| 175 | if (ts7250_mtd->size >= (128 * 0x100000)) |
| 176 | mtd_parts = partition_info128; |
| 177 | mtd_parts_nb = NUM_PARTITIONS; |
| 178 | part_type = "static"; |
| 179 | } |
| 180 | |
| 181 | /* Register the partitions */ |
| 182 | printk(KERN_NOTICE "Using %s partition definition\n", part_type); |
| 183 | add_mtd_partitions(ts7250_mtd, mtd_parts, mtd_parts_nb); |
| 184 | |
| 185 | /* Return happy */ |
| 186 | return 0; |
| 187 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 188 | |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 189 | module_init(ts7250_init); |
| 190 | |
| 191 | /* |
| 192 | * Clean up routine |
| 193 | */ |
| 194 | static void __exit ts7250_cleanup(void) |
| 195 | { |
| 196 | /* Unregister the device */ |
| 197 | del_mtd_device(ts7250_mtd); |
| 198 | |
| 199 | /* Free the MTD device structure */ |
| 200 | kfree(ts7250_mtd); |
| 201 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 202 | |
Lennert Buytenhek | 7d532dd | 2006-04-30 10:36:38 +0200 | [diff] [blame] | 203 | module_exit(ts7250_cleanup); |
| 204 | |
| 205 | MODULE_LICENSE("GPL"); |
| 206 | MODULE_AUTHOR("Jesse Off <joff@embeddedARM.com>"); |
| 207 | MODULE_DESCRIPTION("MTD map driver for Technologic Systems TS-7250 board"); |