[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / mtd / maps / ixp2000.c
blobc5b5f447e34b6a72c14f35e6eb7dcf3d315c8175
1 /*
2 * $Id: ixp2000.c,v 1.5 2004/11/16 17:15:48 dsaxena Exp $
4 * drivers/mtd/maps/ixp2000.c
6 * Mapping for the Intel XScale IXP2000 based systems
8 * Copyright (C) 2002 Intel Corp.
9 * Copyright (C) 2003-2004 MontaVista Software, Inc.
11 * Original Author: Naeem M Afzal <naeem.m.afzal@intel.com>
12 * Maintainer: Deepak Saxena <dsaxena@plexity.net>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
20 #include <linux/module.h>
21 #include <linux/types.h>
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/string.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/map.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/ioport.h>
29 #include <linux/device.h>
31 #include <asm/io.h>
32 #include <asm/hardware.h>
33 #include <asm/mach-types.h>
34 #include <asm/mach/flash.h>
36 #include <linux/reboot.h>
38 struct ixp2000_flash_info {
39 struct mtd_info *mtd;
40 struct map_info map;
41 struct mtd_partition *partitions;
42 struct resource *res;
43 int nr_banks;
46 static inline unsigned long flash_bank_setup(struct map_info *map, unsigned long ofs)
48 unsigned long (*set_bank)(unsigned long) =
49 (unsigned long(*)(unsigned long))map->map_priv_2;
51 return (set_bank ? set_bank(ofs) : ofs);
54 #ifdef __ARMEB__
56 * Rev A0 and A1 of IXP2400 silicon have a broken addressing unit which
57 * causes the lower address bits to be XORed with 0x11 on 8 bit accesses
58 * and XORed with 0x10 on 16 bit accesses. See the spec update, erratum 44.
60 static int erratum44_workaround = 0;
62 static inline unsigned long address_fix8_write(unsigned long addr)
64 if (erratum44_workaround) {
65 return (addr ^ 3);
67 return addr;
69 #else
71 #define address_fix8_write(x) (x)
72 #endif
74 static map_word ixp2000_flash_read8(struct map_info *map, unsigned long ofs)
76 map_word val;
78 val.x[0] = *((u8 *)(map->map_priv_1 + flash_bank_setup(map, ofs)));
79 return val;
83 * We can't use the standard memcpy due to the broken SlowPort
84 * address translation on rev A0 and A1 silicon and the fact that
85 * we have banked flash.
87 static void ixp2000_flash_copy_from(struct map_info *map, void *to,
88 unsigned long from, ssize_t len)
90 from = flash_bank_setup(map, from);
91 while(len--)
92 *(__u8 *) to++ = *(__u8 *)(map->map_priv_1 + from++);
95 static void ixp2000_flash_write8(struct map_info *map, map_word d, unsigned long ofs)
97 *(__u8 *) (address_fix8_write(map->map_priv_1 +
98 flash_bank_setup(map, ofs))) = d.x[0];
101 static void ixp2000_flash_copy_to(struct map_info *map, unsigned long to,
102 const void *from, ssize_t len)
104 to = flash_bank_setup(map, to);
105 while(len--) {
106 unsigned long tmp = address_fix8_write(map->map_priv_1 + to++);
107 *(__u8 *)(tmp) = *(__u8 *)(from++);
112 static int ixp2000_flash_remove(struct device *_dev)
114 struct platform_device *dev = to_platform_device(_dev);
115 struct flash_platform_data *plat = dev->dev.platform_data;
116 struct ixp2000_flash_info *info = dev_get_drvdata(&dev->dev);
118 dev_set_drvdata(&dev->dev, NULL);
120 if(!info)
121 return 0;
123 if (info->mtd) {
124 del_mtd_partitions(info->mtd);
125 map_destroy(info->mtd);
127 if (info->map.map_priv_1)
128 iounmap((void *) info->map.map_priv_1);
130 if (info->partitions) {
131 kfree(info->partitions); }
133 if (info->res) {
134 release_resource(info->res);
135 kfree(info->res);
138 if (plat->exit)
139 plat->exit();
141 return 0;
145 static int ixp2000_flash_probe(struct device *_dev)
147 static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
148 struct platform_device *dev = to_platform_device(_dev);
149 struct ixp2000_flash_data *ixp_data = dev->dev.platform_data;
150 struct flash_platform_data *plat;
151 struct ixp2000_flash_info *info;
152 unsigned long window_size;
153 int err = -1;
155 if (!ixp_data)
156 return -ENODEV;
158 plat = ixp_data->platform_data;
159 if (!plat)
160 return -ENODEV;
162 window_size = dev->resource->end - dev->resource->start + 1;
163 dev_info(_dev, "Probe of IXP2000 flash(%d banks x %dMiB)\n",
164 ixp_data->nr_banks, ((u32)window_size >> 20));
166 if (plat->width != 1) {
167 dev_err(_dev, "IXP2000 MTD map only supports 8-bit mode, asking for %d\n",
168 plat->width * 8);
169 return -EIO;
172 info = kmalloc(sizeof(struct ixp2000_flash_info), GFP_KERNEL);
173 if(!info) {
174 err = -ENOMEM;
175 goto Error;
177 memzero(info, sizeof(struct ixp2000_flash_info));
179 dev_set_drvdata(&dev->dev, info);
182 * Tell the MTD layer we're not 1:1 mapped so that it does
183 * not attempt to do a direct access on us.
185 info->map.phys = NO_XIP;
187 info->nr_banks = ixp_data->nr_banks;
188 info->map.size = ixp_data->nr_banks * window_size;
189 info->map.bankwidth = 1;
192 * map_priv_2 is used to store a ptr to to the bank_setup routine
194 info->map.map_priv_2 = (void __iomem *) ixp_data->bank_setup;
196 info->map.name = dev->dev.bus_id;
197 info->map.read = ixp2000_flash_read8;
198 info->map.write = ixp2000_flash_write8;
199 info->map.copy_from = ixp2000_flash_copy_from;
200 info->map.copy_to = ixp2000_flash_copy_to;
202 info->res = request_mem_region(dev->resource->start,
203 dev->resource->end - dev->resource->start + 1,
204 dev->dev.bus_id);
205 if (!info->res) {
206 dev_err(_dev, "Could not reserve memory region\n");
207 err = -ENOMEM;
208 goto Error;
211 info->map.map_priv_1 = ioremap(dev->resource->start,
212 dev->resource->end - dev->resource->start + 1);
213 if (!info->map.map_priv_1) {
214 dev_err(_dev, "Failed to ioremap flash region\n");
215 err = -EIO;
216 goto Error;
220 * Setup read mode for FLASH
222 *IXP2000_SLOWPORT_FRM = 1;
224 #if defined(__ARMEB__)
226 * Enable erratum 44 workaround for NPUs with broken slowport
229 erratum44_workaround = ixp2000_has_broken_slowport();
230 dev_info(_dev, "Erratum 44 workaround %s\n",
231 erratum44_workaround ? "enabled" : "disabled");
232 #endif
234 info->mtd = do_map_probe(plat->map_name, &info->map);
235 if (!info->mtd) {
236 dev_err(_dev, "map_probe failed\n");
237 err = -ENXIO;
238 goto Error;
240 info->mtd->owner = THIS_MODULE;
242 err = parse_mtd_partitions(info->mtd, probes, &info->partitions, 0);
243 if (err > 0) {
244 err = add_mtd_partitions(info->mtd, info->partitions, err);
245 if(err)
246 dev_err(_dev, "Could not parse partitions\n");
249 if (err)
250 goto Error;
252 return 0;
254 Error:
255 ixp2000_flash_remove(_dev);
256 return err;
259 static struct device_driver ixp2000_flash_driver = {
260 .name = "IXP2000-Flash",
261 .bus = &platform_bus_type,
262 .probe = &ixp2000_flash_probe,
263 .remove = &ixp2000_flash_remove
266 static int __init ixp2000_flash_init(void)
268 return driver_register(&ixp2000_flash_driver);
271 static void __exit ixp2000_flash_exit(void)
273 driver_unregister(&ixp2000_flash_driver);
276 module_init(ixp2000_flash_init);
277 module_exit(ixp2000_flash_exit);
278 MODULE_LICENSE("GPL");
279 MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");