2 * $Id: ixp4xx.c,v 1.4 2004/10/19 06:41:34 gerg Exp $
4 * drivers/mtd/maps/ixp425.c
6 * MTD Map file for IXP4XX based systems. Please do not make per-board
7 * map driver as the code will be 90% identical. For now just add
8 * if(machine_is_XXX()) checks to the code. I'll clean this stuff to
9 * use platform_data in the the future so we can get rid of that too.
11 * Original Author: Intel Corporation
12 * Maintainer: Deepak Saxena <dsaxena@mvista.com>
14 * Copyright (C) 2002 Intel Corporation
15 * Copyright (C) 2003 MontaVista Software, Inc.
19 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/init.h>
22 #include <linux/kernel.h>
23 #include <linux/string.h>
24 #include <linux/mtd/mtd.h>
25 #include <linux/mtd/map.h>
26 #include <linux/mtd/partitions.h>
27 #include <linux/ioport.h>
28 #include <linux/device.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/flash.h>
33 #include <linux/reboot.h>
36 #define BYTE0(h) ((h) & 0xFF)
37 #define BYTE1(h) (((h) >> 8) & 0xFF)
39 #define BYTE0(h) (((h) >> 8) & 0xFF)
40 #define BYTE1(h) ((h) & 0xFF)
43 static map_word
ixp4xx_read16(struct map_info
*map
, unsigned long ofs
)
46 val
.x
[0] = *(__u16
*) (map
->map_priv_1
+ ofs
);
51 * The IXP4XX expansion bus only allows 16-bit wide acceses
52 * when attached to a 16-bit wide device (such as the 28F128J3A),
53 * so we can't just memcpy_fromio().
55 static void ixp4xx_copy_from(struct map_info
*map
, void *to
,
56 unsigned long from
, ssize_t len
)
60 u16
*src
= (u16
*) (map
->map_priv_1
+ from
);
63 for (i
= 0; i
< (len
/ 2); i
++) {
69 dest
[i
* 2] = BYTE0(data
);
70 dest
[i
* 2 + 1] = BYTE1(data
);
75 dest
[len
- 1] = BYTE0(src
[i
]);
77 dest
[len
- 1] = BYTE0(src
[i
^ 1]);
82 * Unaligned writes are ignored, causing the 8-bit
83 * probe to fail and proceed to the 16-bit probe (which succeeds).
85 static void ixp4xx_probe_write16(struct map_info
*map
, map_word d
, unsigned long adr
)
88 *(__u16
*) (map
->map_priv_1
+ adr
) = d
.x
[0];
92 * Fast write16 function without the probing check above
94 static void ixp4xx_write16(struct map_info
*map
, map_word d
, unsigned long adr
)
96 *(__u16
*) (map
->map_priv_1
+ adr
) = d
.x
[0];
99 struct ixp425_flash_info
{
100 struct mtd_info
*mtd
;
102 struct mtd_partition
*partitions
;
103 struct resource
*res
;
106 static const char *probes
[] = { "RedBoot", "cmdlinepart", NULL
};
108 static int ixp4xx_flash_remove(struct device
*_dev
)
110 struct platform_device
*dev
= to_platform_device(_dev
);
111 struct flash_platform_data
*plat
= dev
->dev
.platform_data
;
112 struct ixp4xx_flash_info
*info
= dev_get_drvdata(&dev
->dev
);
115 dev_set_drvdata(&dev
->dev
, NULL
);
121 ixp4xx_write16(&info
->map
, d
, 0x55 * 0x2);
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
);
134 release_resource(info
->res
);
138 /* Disable flash write */
139 *IXP4XX_EXP_CS0
&= ~IXP4XX_FLASH_WRITABLE
;
144 static int ixp425_flash_probe(struct device
*_dev
)
146 struct platform_device
*dev
= to_platform_device(_dev
);
147 struct flash_platform_data
*plat
= dev
->dev
.platform_data
;
148 struct ixp425_flash_info
*info
;
151 info
= kmalloc(sizeof(struct ixp425_flash_info
), GFP_KERNEL
);
156 memzero(info
, sizeof(struct ixp425_flash_info
));
158 dev_set_drvdata(&dev
->dev
, info
);
160 /* Enable flash write */
161 *IXP4XX_EXP_CS0
|= IXP4XX_FLASH_WRITABLE
;
164 * We only support 16-bit accesses for now. If and when
165 * any board use 8-bit access, we'll fixup the driver to
168 info
->map
.bankwidth
= 2;
169 info
->map
.name
= dev
->dev
.bus_id
;
170 info
->map
.read
= ixp4xx_read16
,
171 info
->map
.write
= ixp4xx_probe_write16
,
172 info
->map
.copy_from
= ixp4xx_copy_from
,
174 info
->res
= request_mem_region(dev
->resource
->start
,
175 dev
->resource
->end
- dev
->resource
->start
+ 1,
178 printk(KERN_ERR
"IXP4XXFlash: Could not reserve memory region\n");
183 info
->map
.map_priv_1
=
184 (void __iomem
*) ioremap(dev
->resource
->start
,
185 dev
->resource
->end
- dev
->resource
->start
+ 1);
186 if (!info
->map
.map_priv_1
) {
187 printk(KERN_ERR
"IXP4XXFlash: Failed to ioremap region\n");
192 info
->mtd
= do_map_probe(plat
->map_name
, &info
->map
);
194 printk(KERN_ERR
"IXP4XXFlash: map_probe failed\n");
198 info
->mtd
->owner
= THIS_MODULE
;
200 /* Use the fast version */
201 info
->map
.write
= ixp4xx_write16
,
203 err
= parse_mtd_partitions(info
->mtd
, probes
, &info
->partitions
, 0);
205 err
= add_mtd_partitions(info
->mtd
, info
->partitions
, err
);
207 printk(KERN_ERR
"Could not parse partitions\n");
216 ixp425_flash_remove(_dev
);
220 static struct device_driver ixp425_flash_driver
= {
221 .name
= "IXP4XX-Flash",
222 .bus
= &platform_bus_type
,
223 .probe
= ixp425_flash_probe
,
224 .remove
= ixp425_flash_remove
,
227 static int __init
ixp425_flash_init(void)
229 return driver_register(&ixp425_flash_driver
);
232 static void __exit
ixp425_flash_exit(void)
234 driver_unregister(&ixp425_flash_driver
);
238 module_init(ixp425_flash_init
);
239 module_exit(ixp425_flash_exit
);
241 MODULE_LICENSE("GPL");
242 MODULE_DESCRIPTION("MTD map driver for ixp425 evaluation board");
243 MODULE_AUTHOR("Deepak Saxena");