| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | *  drivers/mtd/nand/h1910.c | 
|  | 3 | * | 
|  | 4 | *  Copyright (C) 2003 Joshua Wise (joshua@joshuawise.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) 2002 Marius Gröger (mag@sysgo.de) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | *       Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de) | 
|  | 9 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | *   iPAQ h1910 board which utilizes the Samsung K9F2808 part. This is | 
|  | 17 | *   a 128Mibit (16MiB x 8 bits) NAND flash device. | 
|  | 18 | */ | 
|  | 19 |  | 
|  | 20 | #include <linux/slab.h> | 
|  | 21 | #include <linux/init.h> | 
|  | 22 | #include <linux/module.h> | 
|  | 23 | #include <linux/mtd/mtd.h> | 
|  | 24 | #include <linux/mtd/nand.h> | 
|  | 25 | #include <linux/mtd/partitions.h> | 
|  | 26 | #include <asm/io.h> | 
| Alexander Shiyan | 304b2c6 | 2012-05-06 09:21:57 +0400 | [diff] [blame] | 27 | #include <mach/hardware.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/sizes.h> | 
| Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 29 | #include <mach/h1900-gpio.h> | 
|  | 30 | #include <mach/ipaq.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 |  | 
|  | 32 | /* | 
|  | 33 | * MTD structure for EDB7312 board | 
|  | 34 | */ | 
|  | 35 | static struct mtd_info *h1910_nand_mtd = NULL; | 
|  | 36 |  | 
|  | 37 | /* | 
|  | 38 | * Module stuff | 
|  | 39 | */ | 
|  | 40 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | /* | 
|  | 42 | * Define static partitions for flash device | 
|  | 43 | */ | 
|  | 44 | static struct mtd_partition partition_info[] = { | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 45 | {name:"h1910 NAND Flash", | 
|  | 46 | offset:0, | 
|  | 47 | size:16 * 1024 * 1024} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | }; | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 49 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define NUM_PARTITIONS 1 | 
|  | 51 |  | 
| Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 52 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | *	hardware specific access to control-lines | 
| Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 54 | * | 
|  | 55 | *	NAND_NCE: bit 0 - don't care | 
|  | 56 | *	NAND_CLE: bit 1 - address bit 2 | 
|  | 57 | *	NAND_ALE: bit 2 - address bit 3 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | */ | 
| Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 59 | static void h1910_hwcontrol(struct mtd_info *mtd, int cmd, | 
|  | 60 | unsigned int ctrl) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { | 
| Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 62 | struct nand_chip *chip = mtd->priv; | 
| Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 63 |  | 
| Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 64 | if (cmd != NAND_CMD_NONE) | 
|  | 65 | writeb(cmd, chip->IO_ADDR_W | ((ctrl & 0x6) << 1)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } | 
|  | 67 |  | 
|  | 68 | /* | 
|  | 69 | *	read device ready pin | 
|  | 70 | */ | 
|  | 71 | #if 0 | 
|  | 72 | static int h1910_device_ready(struct mtd_info *mtd) | 
|  | 73 | { | 
|  | 74 | return (GPLR(55) & GPIO_bit(55)); | 
|  | 75 | } | 
|  | 76 | #endif | 
|  | 77 |  | 
|  | 78 | /* | 
|  | 79 | * Main initialization routine | 
|  | 80 | */ | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 81 | static int __init h1910_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { | 
|  | 83 | struct nand_chip *this; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | void __iomem *nandaddr; | 
| Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 85 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | if (!machine_is_h1900()) | 
|  | 87 | return -ENODEV; | 
| Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 88 |  | 
| Russell King | 0c2e4b4 | 2005-11-17 16:46:41 +0000 | [diff] [blame] | 89 | nandaddr = ioremap(0x08000000, 0x1000); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | if (!nandaddr) { | 
|  | 91 | printk("Failed to ioremap nand flash.\n"); | 
|  | 92 | return -ENOMEM; | 
|  | 93 | } | 
| 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 | /* Allocate memory for MTD device structure and private data */ | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 96 | h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | if (!h1910_nand_mtd) { | 
|  | 98 | printk("Unable to allocate h1910 NAND MTD device structure.\n"); | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 99 | iounmap((void *)nandaddr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | return -ENOMEM; | 
|  | 101 | } | 
| Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 102 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | /* Get pointer to private data */ | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 104 | this = (struct nand_chip *)(&h1910_nand_mtd[1]); | 
| Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 105 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | /* Initialize structures */ | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 107 | memset(h1910_nand_mtd, 0, sizeof(struct mtd_info)); | 
|  | 108 | memset(this, 0, sizeof(struct nand_chip)); | 
| Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 109 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /* Link the private data with the MTD structure */ | 
|  | 111 | h1910_nand_mtd->priv = this; | 
| David Woodhouse | 552d920 | 2006-05-14 01:20:46 +0100 | [diff] [blame] | 112 | h1910_nand_mtd->owner = THIS_MODULE; | 
| 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 | /* | 
|  | 115 | * Enable VPEN | 
|  | 116 | */ | 
|  | 117 | GPSR(37) = GPIO_bit(37); | 
| Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 118 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /* insert callbacks */ | 
|  | 120 | this->IO_ADDR_R = nandaddr; | 
|  | 121 | this->IO_ADDR_W = nandaddr; | 
| Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 122 | this->cmd_ctrl = h1910_hwcontrol; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | this->dev_ready = NULL;	/* unknown whether that was correct or not so we will just do it like this */ | 
|  | 124 | /* 15 us command delay time */ | 
|  | 125 | this->chip_delay = 50; | 
| Thomas Gleixner | 6dfc6d2 | 2006-05-23 12:00:46 +0200 | [diff] [blame] | 126 | this->ecc.mode = NAND_ECC_SOFT; | 
| Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 127 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /* Scan to find existence of the device */ | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 129 | if (nand_scan(h1910_nand_mtd, 1)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | printk(KERN_NOTICE "No NAND device - returning -ENXIO\n"); | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 131 | kfree(h1910_nand_mtd); | 
|  | 132 | iounmap((void *)nandaddr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return -ENXIO; | 
|  | 134 | } | 
| 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 | /* Register the partitions */ | 
| Artem Bityutskiy | 42d7fbe | 2012-03-09 19:24:26 +0200 | [diff] [blame] | 137 | mtd_device_parse_register(h1910_nand_mtd, NULL, NULL, partition_info, | 
|  | 138 | NUM_PARTITIONS); | 
| 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 | /* Return happy */ | 
|  | 141 | return 0; | 
|  | 142 | } | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 143 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | module_init(h1910_init); | 
|  | 145 |  | 
|  | 146 | /* | 
|  | 147 | * Clean up routine | 
|  | 148 | */ | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 149 | static void __exit h1910_cleanup(void) | 
| 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 | struct nand_chip *this = (struct nand_chip *)&h1910_nand_mtd[1]; | 
| 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 | /* Release resources, unregister device */ | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 154 | nand_release(h1910_nand_mtd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 |  | 
|  | 156 | /* Release io resource */ | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 157 | iounmap((void *)this->IO_ADDR_W); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 |  | 
|  | 159 | /* Free the MTD device structure */ | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 160 | kfree(h1910_nand_mtd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } | 
| David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 162 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | module_exit(h1910_cleanup); | 
|  | 164 |  | 
|  | 165 | MODULE_LICENSE("GPL"); | 
|  | 166 | MODULE_AUTHOR("Joshua Wise <joshua at joshuawise dot com>"); | 
|  | 167 | MODULE_DESCRIPTION("NAND flash driver for iPAQ h1910"); |