2 * $Id: ixp4xx.c,v 1.7 2004/11/04 13:24:15 gleixner Exp $
4 * drivers/mtd/maps/ixp4xx.c
6 * MTD Map file for IXP4XX based systems. Please do not make per-board
7 * changes in here. If your board needs special setup, do it in your
8 * platform level code in arch/arm/mach-ixp4xx/board-setup.c
10 * Original Author: Intel Corporation
11 * Maintainer: Deepak Saxena <dsaxena@mvista.com>
13 * Copyright (C) 2002 Intel Corporation
14 * Copyright (C) 2003-2004 MontaVista Software, Inc.
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/string.h>
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/map.h>
25 #include <linux/mtd/partitions.h>
26 #include <linux/ioport.h>
27 #include <linux/device.h>
29 #include <asm/mach/flash.h>
31 #include <linux/reboot.h>
34 #define BYTE0(h) ((h) & 0xFF)
35 #define BYTE1(h) (((h) >> 8) & 0xFF)
37 #define BYTE0(h) (((h) >> 8) & 0xFF)
38 #define BYTE1(h) ((h) & 0xFF)
41 static map_word ixp4xx_read16(struct map_info *map, unsigned long ofs)
44 val.x[0] = *(__u16 *) (map->map_priv_1 + ofs);
49 * The IXP4xx expansion bus only allows 16-bit wide acceses
50 * when attached to a 16-bit wide device (such as the 28F128J3A),
51 * so we can't just memcpy_fromio().
53 static void ixp4xx_copy_from(struct map_info *map, void *to,
54 unsigned long from, ssize_t len)
58 u16 *src = (u16 *) (map->map_priv_1 + from);
61 for (i = 0; i < (len / 2); i++) {
63 dest[i * 2] = BYTE0(data);
64 dest[i * 2 + 1] = BYTE1(data);
68 dest[len - 1] = BYTE0(src[i]);
72 * Unaligned writes are ignored, causing the 8-bit
73 * probe to fail and proceed to the 16-bit probe (which succeeds).
75 static void ixp4xx_probe_write16(struct map_info *map, map_word d, unsigned long adr)
78 *(__u16 *) (map->map_priv_1 + adr) = d.x[0];
82 * Fast write16 function without the probing check above
84 static void ixp4xx_write16(struct map_info *map, map_word d, unsigned long adr)
86 *(__u16 *) (map->map_priv_1 + adr) = d.x[0];
89 struct ixp4xx_flash_info {
92 struct mtd_partition *partitions;
96 static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
98 static int ixp4xx_flash_remove(struct device *_dev)
100 struct platform_device *dev = to_platform_device(_dev);
101 struct flash_platform_data *plat = dev->dev.platform_data;
102 struct ixp4xx_flash_info *info = dev_get_drvdata(&dev->dev);
105 dev_set_drvdata(&dev->dev, NULL);
111 * This is required for a soft reboot to work.
114 ixp4xx_write16(&info->map, d, 0x55 * 0x2);
117 del_mtd_partitions(info->mtd);
118 map_destroy(info->mtd);
120 if (info->map.map_priv_1)
121 iounmap((void *) info->map.map_priv_1);
123 if (info->partitions)
124 kfree(info->partitions);
127 release_resource(info->res);
134 /* Disable flash write */
135 *IXP4XX_EXP_CS0 &= ~IXP4XX_FLASH_WRITABLE;
140 static int ixp4xx_flash_probe(struct device *_dev)
142 struct platform_device *dev = to_platform_device(_dev);
143 struct flash_platform_data *plat = dev->dev.platform_data;
144 struct ixp4xx_flash_info *info;
156 info = kmalloc(sizeof(struct ixp4xx_flash_info), GFP_KERNEL);
161 memzero(info, sizeof(struct ixp4xx_flash_info));
163 dev_set_drvdata(&dev->dev, info);
167 * TODO: Move this out to board specific code
169 *IXP4XX_EXP_CS0 |= IXP4XX_FLASH_WRITABLE;
172 * Tell the MTD layer we're not 1:1 mapped so that it does
173 * not attempt to do a direct access on us.
175 info->map.phys = NO_XIP;
176 info->map.size = dev->resource->end - dev->resource->start + 1;
179 * We only support 16-bit accesses for now. If and when
180 * any board use 8-bit access, we'll fixup the driver to
183 info->map.bankwidth = 2;
184 info->map.name = dev->dev.bus_id;
185 info->map.read = ixp4xx_read16,
186 info->map.write = ixp4xx_probe_write16,
187 info->map.copy_from = ixp4xx_copy_from,
189 info->res = request_mem_region(dev->resource->start,
190 dev->resource->end - dev->resource->start + 1,
193 printk(KERN_ERR "IXP4XXFlash: Could not reserve memory region\n");
198 info->map.map_priv_1 = ioremap(dev->resource->start,
199 dev->resource->end - dev->resource->start + 1);
200 if (!info->map.map_priv_1) {
201 printk(KERN_ERR "IXP4XXFlash: Failed to ioremap region\n");
206 info->mtd = do_map_probe(plat->map_name, &info->map);
208 printk(KERN_ERR "IXP4XXFlash: map_probe failed\n");
212 info->mtd->owner = THIS_MODULE;
214 /* Use the fast version */
215 info->map.write = ixp4xx_write16,
217 err = parse_mtd_partitions(info->mtd, probes, &info->partitions, 0);
219 err = add_mtd_partitions(info->mtd, info->partitions, err);
221 printk(KERN_ERR "Could not parse partitions\n");
230 ixp4xx_flash_remove(_dev);
234 static struct device_driver ixp4xx_flash_driver = {
235 .name = "IXP4XX-Flash",
236 .bus = &platform_bus_type,
237 .probe = ixp4xx_flash_probe,
238 .remove = ixp4xx_flash_remove,
241 static int __init ixp4xx_flash_init(void)
243 return driver_register(&ixp4xx_flash_driver);
246 static void __exit ixp4xx_flash_exit(void)
248 driver_unregister(&ixp4xx_flash_driver);
252 module_init(ixp4xx_flash_init);
253 module_exit(ixp4xx_flash_exit);
255 MODULE_LICENSE("GPL");
256 MODULE_DESCRIPTION("MTD map driver for Intel IXP4xx systems");
257 MODULE_AUTHOR("Deepak Saxena");