2 * drivers/mtd/maps/ixp4xx.c
4 * MTD Map file for IXP4XX based systems. Please do not make per-board
5 * changes in here. If your board needs special setup, do it in your
6 * platform level code in arch/arm/mach-ixp4xx/board-setup.c
8 * Original Author: Intel Corporation
9 * Maintainer: Deepak Saxena <dsaxena@mvista.com>
11 * Copyright (C) 2002 Intel Corporation
12 * Copyright (C) 2003-2004 MontaVista Software, Inc.
16 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/string.h>
21 #include <linux/slab.h>
22 #include <linux/ioport.h>
23 #include <linux/device.h>
24 #include <linux/platform_device.h>
26 #include <linux/mtd/mtd.h>
27 #include <linux/mtd/map.h>
28 #include <linux/mtd/partitions.h>
31 #include <asm/mach/flash.h>
33 #include <linux/reboot.h>
36 * Read/write a 16 bit word from flash address 'addr'.
38 * When the cpu is in little-endian mode it swizzles the address lines
39 * ('address coherency') so we need to undo the swizzling to ensure commands
40 * and the like end up on the correct flash address.
42 * To further complicate matters, due to the way the expansion bus controller
43 * handles 32 bit reads, the byte stream ABCD is stored on the flash as:
50 * This means that on LE systems each 16 bit word must be swapped. Note that
51 * this requires CONFIG_MTD_CFI_BE_BYTE_SWAP to be enabled to 'unswap' the CFI
52 * data and other flash commands which are always in D7-D0.
55 #ifndef CONFIG_MTD_CFI_BE_BYTE_SWAP
56 # error CONFIG_MTD_CFI_BE_BYTE_SWAP required
59 static inline u16
flash_read16(void __iomem
*addr
)
61 return be16_to_cpu(__raw_readw((void __iomem
*)((unsigned long)addr
^ 0x2)));
64 static inline void flash_write16(u16 d
, void __iomem
*addr
)
66 __raw_writew(cpu_to_be16(d
), (void __iomem
*)((unsigned long)addr
^ 0x2));
69 #define BYTE0(h) ((h) & 0xFF)
70 #define BYTE1(h) (((h) >> 8) & 0xFF)
74 static inline u16
flash_read16(const void __iomem
*addr
)
76 return __raw_readw(addr
);
79 static inline void flash_write16(u16 d
, void __iomem
*addr
)
81 __raw_writew(d
, addr
);
84 #define BYTE0(h) (((h) >> 8) & 0xFF)
85 #define BYTE1(h) ((h) & 0xFF)
88 static map_word
ixp4xx_read16(struct map_info
*map
, unsigned long ofs
)
91 val
.x
[0] = flash_read16(map
->virt
+ ofs
);
96 * The IXP4xx expansion bus only allows 16-bit wide acceses
97 * when attached to a 16-bit wide device (such as the 28F128J3A),
98 * so we can't just memcpy_fromio().
100 static void ixp4xx_copy_from(struct map_info
*map
, void *to
,
101 unsigned long from
, ssize_t len
)
103 u8
*dest
= (u8
*) to
;
104 void __iomem
*src
= map
->virt
+ from
;
110 *dest
++ = BYTE1(flash_read16(src
-1));
116 u16 data
= flash_read16(src
);
117 *dest
++ = BYTE0(data
);
118 *dest
++ = BYTE1(data
);
124 *dest
++ = BYTE0(flash_read16(src
));
128 * Unaligned writes are ignored, causing the 8-bit
129 * probe to fail and proceed to the 16-bit probe (which succeeds).
131 static void ixp4xx_probe_write16(struct map_info
*map
, map_word d
, unsigned long adr
)
134 flash_write16(d
.x
[0], map
->virt
+ adr
);
138 * Fast write16 function without the probing check above
140 static void ixp4xx_write16(struct map_info
*map
, map_word d
, unsigned long adr
)
142 flash_write16(d
.x
[0], map
->virt
+ adr
);
145 struct ixp4xx_flash_info
{
146 struct mtd_info
*mtd
;
148 struct resource
*res
;
151 static const char *probes
[] = { "RedBoot", "cmdlinepart", NULL
};
153 static int ixp4xx_flash_remove(struct platform_device
*dev
)
155 struct flash_platform_data
*plat
= dev
->dev
.platform_data
;
156 struct ixp4xx_flash_info
*info
= platform_get_drvdata(dev
);
158 platform_set_drvdata(dev
, NULL
);
164 mtd_device_unregister(info
->mtd
);
165 map_destroy(info
->mtd
);
168 iounmap(info
->map
.virt
);
171 release_resource(info
->res
);
181 static int ixp4xx_flash_probe(struct platform_device
*dev
)
183 struct flash_platform_data
*plat
= dev
->dev
.platform_data
;
184 struct ixp4xx_flash_info
*info
;
196 info
= kzalloc(sizeof(struct ixp4xx_flash_info
), GFP_KERNEL
);
202 platform_set_drvdata(dev
, info
);
205 * Tell the MTD layer we're not 1:1 mapped so that it does
206 * not attempt to do a direct access on us.
208 info
->map
.phys
= NO_XIP
;
209 info
->map
.size
= resource_size(dev
->resource
);
212 * We only support 16-bit accesses for now. If and when
213 * any board use 8-bit access, we'll fixup the driver to
216 info
->map
.bankwidth
= 2;
217 info
->map
.name
= dev_name(&dev
->dev
);
218 info
->map
.read
= ixp4xx_read16
;
219 info
->map
.write
= ixp4xx_probe_write16
;
220 info
->map
.copy_from
= ixp4xx_copy_from
;
222 info
->res
= request_mem_region(dev
->resource
->start
,
223 resource_size(dev
->resource
),
226 printk(KERN_ERR
"IXP4XXFlash: Could not reserve memory region\n");
231 info
->map
.virt
= ioremap(dev
->resource
->start
,
232 resource_size(dev
->resource
));
233 if (!info
->map
.virt
) {
234 printk(KERN_ERR
"IXP4XXFlash: Failed to ioremap region\n");
239 info
->mtd
= do_map_probe(plat
->map_name
, &info
->map
);
241 printk(KERN_ERR
"IXP4XXFlash: map_probe failed\n");
245 info
->mtd
->owner
= THIS_MODULE
;
247 /* Use the fast version */
248 info
->map
.write
= ixp4xx_write16
;
250 err
= mtd_device_parse_register(info
->mtd
, probes
, dev
->resource
->start
,
251 plat
->parts
, plat
->nr_parts
);
253 printk(KERN_ERR
"Could not parse partitions\n");
260 ixp4xx_flash_remove(dev
);
264 static struct platform_driver ixp4xx_flash_driver
= {
265 .probe
= ixp4xx_flash_probe
,
266 .remove
= ixp4xx_flash_remove
,
268 .name
= "IXP4XX-Flash",
269 .owner
= THIS_MODULE
,
273 module_platform_driver(ixp4xx_flash_driver
);
275 MODULE_LICENSE("GPL");
276 MODULE_DESCRIPTION("MTD map driver for Intel IXP4xx systems");
277 MODULE_AUTHOR("Deepak Saxena");
278 MODULE_ALIAS("platform:IXP4XX-Flash");