[MTD] maps/ixp4xx: kill some warnings
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / mtd / maps / ixp4xx.c
blobc510c736ed97233af0606ec5a073ce424b89015e
1 /*
2 * $Id: ixp4xx.c,v 1.11 2005/11/06 11:15:51 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/slab.h>
24 #include <linux/ioport.h>
25 #include <linux/device.h>
26 #include <linux/platform_device.h>
28 #include <linux/mtd/mtd.h>
29 #include <linux/mtd/map.h>
30 #include <linux/mtd/partitions.h>
32 #include <asm/io.h>
33 #include <asm/mach/flash.h>
35 #include <linux/reboot.h>
37 #ifndef __ARMEB__
38 #define BYTE0(h) ((h) & 0xFF)
39 #define BYTE1(h) (((h) >> 8) & 0xFF)
40 #else
41 #define BYTE0(h) (((h) >> 8) & 0xFF)
42 #define BYTE1(h) ((h) & 0xFF)
43 #endif
45 static map_word ixp4xx_read16(struct map_info *map, unsigned long ofs)
47 map_word val;
48 val.x[0] = le16_to_cpu(readw(map->virt + ofs));
49 return val;
53 * The IXP4xx expansion bus only allows 16-bit wide acceses
54 * when attached to a 16-bit wide device (such as the 28F128J3A),
55 * so we can't just memcpy_fromio().
57 static void ixp4xx_copy_from(struct map_info *map, void *to,
58 unsigned long from, ssize_t len)
60 int i;
61 u8 *dest = (u8 *) to;
62 void __iomem *src = map->virt + from;
63 u16 data;
65 for (i = 0; i < (len / 2); i++) {
66 data = le16_to_cpu(readw(src + 2*i));
67 dest[i * 2] = BYTE0(data);
68 dest[i * 2 + 1] = BYTE1(data);
71 if (len & 1)
72 dest[len - 1] = BYTE0(le16_to_cpu(readw(src + 2*i)));
75 /*
76 * Unaligned writes are ignored, causing the 8-bit
77 * probe to fail and proceed to the 16-bit probe (which succeeds).
79 static void ixp4xx_probe_write16(struct map_info *map, map_word d, unsigned long adr)
81 if (!(adr & 1))
82 writew(cpu_to_le16(d.x[0]), map->virt + adr);
85 /*
86 * Fast write16 function without the probing check above
88 static void ixp4xx_write16(struct map_info *map, map_word d, unsigned long adr)
90 writew(cpu_to_le16(d.x[0]), map->virt + adr);
93 struct ixp4xx_flash_info {
94 struct mtd_info *mtd;
95 struct map_info map;
96 struct mtd_partition *partitions;
97 struct resource *res;
100 static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
102 static int ixp4xx_flash_remove(struct device *_dev)
104 struct platform_device *dev = to_platform_device(_dev);
105 struct flash_platform_data *plat = dev->dev.platform_data;
106 struct ixp4xx_flash_info *info = dev_get_drvdata(&dev->dev);
108 dev_set_drvdata(&dev->dev, NULL);
110 if(!info)
111 return 0;
113 if (info->mtd) {
114 del_mtd_partitions(info->mtd);
115 map_destroy(info->mtd);
117 if (info->map.virt)
118 iounmap(info->map.virt);
120 if (info->partitions)
121 kfree(info->partitions);
123 if (info->res) {
124 release_resource(info->res);
125 kfree(info->res);
128 if (plat->exit)
129 plat->exit();
131 return 0;
134 static int ixp4xx_flash_probe(struct device *_dev)
136 struct platform_device *dev = to_platform_device(_dev);
137 struct flash_platform_data *plat = dev->dev.platform_data;
138 struct ixp4xx_flash_info *info;
139 int err = -1;
141 if (!plat)
142 return -ENODEV;
144 if (plat->init) {
145 err = plat->init();
146 if (err)
147 return err;
150 info = kmalloc(sizeof(struct ixp4xx_flash_info), GFP_KERNEL);
151 if(!info) {
152 err = -ENOMEM;
153 goto Error;
155 memzero(info, sizeof(struct ixp4xx_flash_info));
157 dev_set_drvdata(&dev->dev, info);
160 * Tell the MTD layer we're not 1:1 mapped so that it does
161 * not attempt to do a direct access on us.
163 info->map.phys = NO_XIP;
164 info->map.size = dev->resource->end - dev->resource->start + 1;
167 * We only support 16-bit accesses for now. If and when
168 * any board use 8-bit access, we'll fixup the driver to
169 * handle that.
171 info->map.bankwidth = 2;
172 info->map.name = dev->dev.bus_id;
173 info->map.read = ixp4xx_read16,
174 info->map.write = ixp4xx_probe_write16,
175 info->map.copy_from = ixp4xx_copy_from,
177 info->res = request_mem_region(dev->resource->start,
178 dev->resource->end - dev->resource->start + 1,
179 "IXP4XXFlash");
180 if (!info->res) {
181 printk(KERN_ERR "IXP4XXFlash: Could not reserve memory region\n");
182 err = -ENOMEM;
183 goto Error;
186 info->map.virt = ioremap(dev->resource->start,
187 dev->resource->end - dev->resource->start + 1);
188 if (!info->map.virt) {
189 printk(KERN_ERR "IXP4XXFlash: Failed to ioremap region\n");
190 err = -EIO;
191 goto Error;
194 info->mtd = do_map_probe(plat->map_name, &info->map);
195 if (!info->mtd) {
196 printk(KERN_ERR "IXP4XXFlash: map_probe failed\n");
197 err = -ENXIO;
198 goto Error;
200 info->mtd->owner = THIS_MODULE;
202 /* Use the fast version */
203 info->map.write = ixp4xx_write16,
205 err = parse_mtd_partitions(info->mtd, probes, &info->partitions, 0);
206 if (err > 0) {
207 err = add_mtd_partitions(info->mtd, info->partitions, err);
208 if(err)
209 printk(KERN_ERR "Could not parse partitions\n");
212 if (err)
213 goto Error;
215 return 0;
217 Error:
218 ixp4xx_flash_remove(_dev);
219 return err;
222 static struct device_driver ixp4xx_flash_driver = {
223 .name = "IXP4XX-Flash",
224 .bus = &platform_bus_type,
225 .probe = ixp4xx_flash_probe,
226 .remove = ixp4xx_flash_remove,
229 static int __init ixp4xx_flash_init(void)
231 return driver_register(&ixp4xx_flash_driver);
234 static void __exit ixp4xx_flash_exit(void)
236 driver_unregister(&ixp4xx_flash_driver);
240 module_init(ixp4xx_flash_init);
241 module_exit(ixp4xx_flash_exit);
243 MODULE_LICENSE("GPL");
244 MODULE_DESCRIPTION("MTD map driver for Intel IXP4xx systems");
245 MODULE_AUTHOR("Deepak Saxena");