Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Flash memory support for various TI OMAP boards |
| 3 | * |
| 4 | * Copyright (C) 2001-2002 MontaVista Software Inc. |
| 5 | * Copyright (C) 2003-2004 Texas Instruments |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 6 | * Copyright (C) 2004 Nokia Corporation |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 7 | * |
| 8 | * Assembled using driver code copyright the companies above |
| 9 | * and written by David Brownell, Jian Zhang <jzhang@ti.com>, |
| 10 | * Tony Lindgren <tony@atomide.com> and others. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License as published by the |
| 14 | * Free Software Foundation; either version 2 of the License, or (at your |
| 15 | * option) any later version. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
| 20 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 23 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 24 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | * You should have received a copy of the GNU General Public License along |
| 29 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 30 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 31 | */ |
| 32 | |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 33 | #include <linux/platform_device.h> |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 34 | #include <linux/module.h> |
| 35 | #include <linux/types.h> |
| 36 | #include <linux/kernel.h> |
| 37 | #include <linux/init.h> |
| 38 | #include <linux/ioport.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 39 | #include <linux/slab.h> |
| 40 | |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 41 | #include <linux/mtd/mtd.h> |
| 42 | #include <linux/mtd/map.h> |
| 43 | #include <linux/mtd/partitions.h> |
| 44 | |
| 45 | #include <asm/io.h> |
| 46 | #include <asm/hardware.h> |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 47 | #include <asm/mach/flash.h> |
| 48 | #include <asm/arch/tc.h> |
| 49 | |
| 50 | #ifdef CONFIG_MTD_PARTITIONS |
| 51 | static const char *part_probes[] = { /* "RedBoot", */ "cmdlinepart", NULL }; |
| 52 | #endif |
| 53 | |
| 54 | struct omapflash_info { |
| 55 | struct mtd_partition *parts; |
| 56 | struct mtd_info *mtd; |
| 57 | struct map_info map; |
| 58 | }; |
| 59 | |
| 60 | static void omap_set_vpp(struct map_info *map, int enable) |
| 61 | { |
| 62 | static int count; |
| 63 | |
| 64 | if (enable) { |
| 65 | if (count++ == 0) |
| 66 | OMAP_EMIFS_CONFIG_REG |= OMAP_EMIFS_CONFIG_WP; |
| 67 | } else { |
| 68 | if (count && (--count == 0)) |
| 69 | OMAP_EMIFS_CONFIG_REG &= ~OMAP_EMIFS_CONFIG_WP; |
| 70 | } |
| 71 | } |
| 72 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 73 | static int __devinit omapflash_probe(struct platform_device *pdev) |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 74 | { |
| 75 | int err; |
| 76 | struct omapflash_info *info; |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 77 | struct flash_platform_data *pdata = pdev->dev.platform_data; |
| 78 | struct resource *res = pdev->resource; |
| 79 | unsigned long size = res->end - res->start + 1; |
| 80 | |
Burman Yan | 95b93a0 | 2006-11-15 21:10:29 +0200 | [diff] [blame] | 81 | info = kzalloc(sizeof(struct omapflash_info), GFP_KERNEL); |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 82 | if (!info) |
| 83 | return -ENOMEM; |
| 84 | |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 85 | if (!request_mem_region(res->start, size, "flash")) { |
| 86 | err = -EBUSY; |
| 87 | goto out_free_info; |
| 88 | } |
| 89 | |
| 90 | info->map.virt = ioremap(res->start, size); |
| 91 | if (!info->map.virt) { |
| 92 | err = -ENOMEM; |
| 93 | goto out_release_mem_region; |
| 94 | } |
| 95 | info->map.name = pdev->dev.bus_id; |
| 96 | info->map.phys = res->start; |
| 97 | info->map.size = size; |
| 98 | info->map.bankwidth = pdata->width; |
| 99 | info->map.set_vpp = omap_set_vpp; |
| 100 | |
| 101 | simple_map_init(&info->map); |
| 102 | info->mtd = do_map_probe(pdata->map_name, &info->map); |
| 103 | if (!info->mtd) { |
| 104 | err = -EIO; |
| 105 | goto out_iounmap; |
| 106 | } |
| 107 | info->mtd->owner = THIS_MODULE; |
| 108 | |
| 109 | #ifdef CONFIG_MTD_PARTITIONS |
| 110 | err = parse_mtd_partitions(info->mtd, part_probes, &info->parts, 0); |
| 111 | if (err > 0) |
| 112 | add_mtd_partitions(info->mtd, info->parts, err); |
| 113 | else if (err < 0 && pdata->parts) |
| 114 | add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts); |
| 115 | else |
| 116 | #endif |
| 117 | add_mtd_device(info->mtd); |
| 118 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 119 | platform_set_drvdata(pdev, info); |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 120 | |
| 121 | return 0; |
| 122 | |
| 123 | out_iounmap: |
| 124 | iounmap(info->map.virt); |
| 125 | out_release_mem_region: |
| 126 | release_mem_region(res->start, size); |
| 127 | out_free_info: |
| 128 | kfree(info); |
| 129 | |
| 130 | return err; |
| 131 | } |
| 132 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 133 | static int __devexit omapflash_remove(struct platform_device *pdev) |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 134 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 135 | struct omapflash_info *info = platform_get_drvdata(pdev); |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 136 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 137 | platform_set_drvdata(pdev, NULL); |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 138 | |
| 139 | if (info) { |
| 140 | if (info->parts) { |
| 141 | del_mtd_partitions(info->mtd); |
| 142 | kfree(info->parts); |
| 143 | } else |
| 144 | del_mtd_device(info->mtd); |
| 145 | map_destroy(info->mtd); |
| 146 | release_mem_region(info->map.phys, info->map.size); |
| 147 | iounmap((void __iomem *) info->map.virt); |
| 148 | kfree(info); |
| 149 | } |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 154 | static struct platform_driver omapflash_driver = { |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 155 | .probe = omapflash_probe, |
| 156 | .remove = __devexit_p(omapflash_remove), |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 157 | .driver = { |
| 158 | .name = "omapflash", |
Kay Sievers | 41d867c | 2008-04-18 13:44:26 -0700 | [diff] [blame] | 159 | .owner = THIS_MODULE, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 160 | }, |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | static int __init omapflash_init(void) |
| 164 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 165 | return platform_driver_register(&omapflash_driver); |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static void __exit omapflash_exit(void) |
| 169 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 170 | platform_driver_unregister(&omapflash_driver); |
Todd Poynor | 10c96f2 | 2005-07-02 02:53:28 +0100 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | module_init(omapflash_init); |
| 174 | module_exit(omapflash_exit); |
| 175 | |
| 176 | MODULE_LICENSE("GPL"); |
| 177 | MODULE_DESCRIPTION("MTD NOR map driver for TI OMAP boards"); |
Kay Sievers | 41d867c | 2008-04-18 13:44:26 -0700 | [diff] [blame] | 178 | MODULE_ALIAS("platform:omapflash"); |