include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[linux-2.6-block.git] / drivers / mtd / maps / sun_uflash.c
CommitLineData
0e52fe8c
DM
1/* sun_uflash.c - Driver for user-programmable flash on
2 * Sun Microsystems SME boardsets.
1da177e4
LT
3 *
4 * This driver does NOT provide access to the OBP-flash for
5 * safety reasons-- use <linux>/drivers/sbus/char/flash.c instead.
6 *
7 * Copyright (c) 2001 Eric Brower (ebrower@usa.net)
1da177e4
LT
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/fs.h>
13#include <linux/errno.h>
14#include <linux/init.h>
15#include <linux/ioport.h>
0e52fe8c
DM
16#include <linux/of.h>
17#include <linux/of_device.h>
5a0e3ad6 18#include <linux/slab.h>
29f7ac7e 19#include <asm/prom.h>
1da177e4
LT
20#include <asm/uaccess.h>
21#include <asm/io.h>
22
23#include <linux/mtd/mtd.h>
24#include <linux/mtd/map.h>
25
26#define UFLASH_OBPNAME "flashprom"
0e52fe8c
DM
27#define DRIVER_NAME "sun_uflash"
28#define PFX DRIVER_NAME ": "
1da177e4
LT
29
30#define UFLASH_WINDOW_SIZE 0x200000
31#define UFLASH_BUSWIDTH 1 /* EBus is 8-bit */
32
29f7ac7e
DM
33MODULE_AUTHOR("Eric Brower <ebrower@usa.net>");
34MODULE_DESCRIPTION("User-programmable flash device on Sun Microsystems boardsets");
0e52fe8c 35MODULE_SUPPORTED_DEVICE(DRIVER_NAME);
29f7ac7e 36MODULE_LICENSE("GPL");
0e52fe8c 37MODULE_VERSION("2.1");
1da177e4 38
1da177e4 39struct uflash_dev {
ccf0dec6 40 const char *name; /* device name */
1da177e4 41 struct map_info map; /* mtd map info */
29f7ac7e 42 struct mtd_info *mtd; /* mtd info */
1da177e4
LT
43};
44
1da177e4 45struct map_info uflash_map_templ = {
29f7ac7e
DM
46 .name = "SUNW,???-????",
47 .size = UFLASH_WINDOW_SIZE,
48 .bankwidth = UFLASH_BUSWIDTH,
1da177e4
LT
49};
50
0e52fe8c 51int uflash_devinit(struct of_device *op, struct device_node *dp)
1da177e4 52{
29f7ac7e 53 struct uflash_dev *up;
1da177e4 54
0e52fe8c 55 if (op->resource[1].flags) {
1da177e4
LT
56 /* Non-CFI userflash device-- once I find one we
57 * can work on supporting it.
58 */
0e52fe8c
DM
59 printk(KERN_ERR PFX "Unsupported device at %s, 0x%llx\n",
60 dp->full_name, (unsigned long long)op->resource[0].start);
29f7ac7e 61
1da177e4
LT
62 return -ENODEV;
63 }
64
29f7ac7e 65 up = kzalloc(sizeof(struct uflash_dev), GFP_KERNEL);
0e52fe8c
DM
66 if (!up) {
67 printk(KERN_ERR PFX "Cannot allocate struct uflash_dev\n");
29f7ac7e 68 return -ENOMEM;
0e52fe8c 69 }
69f34c98 70
1da177e4 71 /* copy defaults and tweak parameters */
29f7ac7e 72 memcpy(&up->map, &uflash_map_templ, sizeof(uflash_map_templ));
0e52fe8c
DM
73
74 up->map.size = resource_size(&op->resource[0]);
29f7ac7e
DM
75
76 up->name = of_get_property(dp, "model", NULL);
77 if (up->name && 0 < strlen(up->name))
ccf0dec6 78 up->map.name = (char *)up->name;
29f7ac7e 79
0e52fe8c 80 up->map.phys = op->resource[0].start;
29f7ac7e 81
0e52fe8c
DM
82 up->map.virt = of_ioremap(&op->resource[0], 0, up->map.size,
83 DRIVER_NAME);
29f7ac7e 84 if (!up->map.virt) {
0e52fe8c 85 printk(KERN_ERR PFX "Failed to map device.\n");
29f7ac7e
DM
86 kfree(up);
87
88 return -EINVAL;
1da177e4
LT
89 }
90
29f7ac7e 91 simple_map_init(&up->map);
1da177e4
LT
92
93 /* MTD registration */
29f7ac7e
DM
94 up->mtd = do_map_probe("cfi_probe", &up->map);
95 if (!up->mtd) {
0e52fe8c 96 of_iounmap(&op->resource[0], up->map.virt, up->map.size);
29f7ac7e
DM
97 kfree(up);
98
99 return -ENXIO;
1da177e4
LT
100 }
101
29f7ac7e 102 up->mtd->owner = THIS_MODULE;
1da177e4 103
29f7ac7e 104 add_mtd_device(up->mtd);
1da177e4 105
0e52fe8c 106 dev_set_drvdata(&op->dev, up);
29f7ac7e
DM
107
108 return 0;
1da177e4
LT
109}
110
0e52fe8c 111static int __devinit uflash_probe(struct of_device *op, const struct of_device_id *match)
1da177e4 112{
0e52fe8c 113 struct device_node *dp = op->node;
1da177e4 114
0e52fe8c
DM
115 /* Flashprom must have the "user" property in order to
116 * be used by this driver.
117 */
118 if (!of_find_property(dp, "user", NULL))
1da177e4 119 return -ENODEV;
29f7ac7e 120
0e52fe8c 121 return uflash_devinit(op, dp);
1da177e4
LT
122}
123
0e52fe8c 124static int __devexit uflash_remove(struct of_device *op)
1da177e4 125{
0e52fe8c 126 struct uflash_dev *up = dev_get_drvdata(&op->dev);
29f7ac7e
DM
127
128 if (up->mtd) {
129 del_mtd_device(up->mtd);
130 map_destroy(up->mtd);
69f34c98 131 }
29f7ac7e 132 if (up->map.virt) {
0e52fe8c 133 of_iounmap(&op->resource[0], up->map.virt, up->map.size);
29f7ac7e
DM
134 up->map.virt = NULL;
135 }
136
137 kfree(up);
138
139 return 0;
140}
141
fd098316 142static const struct of_device_id uflash_match[] = {
29f7ac7e
DM
143 {
144 .name = UFLASH_OBPNAME,
145 },
146 {},
147};
148
149MODULE_DEVICE_TABLE(of, uflash_match);
150
151static struct of_platform_driver uflash_driver = {
0e52fe8c 152 .name = DRIVER_NAME,
29f7ac7e
DM
153 .match_table = uflash_match,
154 .probe = uflash_probe,
155 .remove = __devexit_p(uflash_remove),
156};
157
158static int __init uflash_init(void)
159{
0e52fe8c 160 return of_register_driver(&uflash_driver, &of_bus_type);
29f7ac7e
DM
161}
162
163static void __exit uflash_exit(void)
164{
165 of_unregister_driver(&uflash_driver);
1da177e4
LT
166}
167
168module_init(uflash_init);
29f7ac7e 169module_exit(uflash_exit);