blob: 001af7f7dddad5273164cac453f4ea3367386f91 [file] [log] [blame]
Thomas Gleixner69f34c92005-11-07 11:15:40 +00001/* $Id: sun_uflash.c,v 1.13 2005/11/07 11:14:28 gleixner Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * sun_uflash - Driver implementation for user-programmable flash
4 * present on many Sun Microsystems SME boardsets.
5 *
6 * This driver does NOT provide access to the OBP-flash for
7 * safety reasons-- use <linux>/drivers/sbus/char/flash.c instead.
8 *
9 * Copyright (c) 2001 Eric Brower (ebrower@usa.net)
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/fs.h>
16#include <linux/errno.h>
17#include <linux/init.h>
18#include <linux/ioport.h>
19#include <asm/ebus.h>
20#include <asm/oplib.h>
David S. Miller29f7ac72006-06-24 23:27:00 -070021#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/uaccess.h>
23#include <asm/io.h>
24
25#include <linux/mtd/mtd.h>
26#include <linux/mtd/map.h>
27
28#define UFLASH_OBPNAME "flashprom"
29#define UFLASH_DEVNAME "userflash"
30
31#define UFLASH_WINDOW_SIZE 0x200000
32#define UFLASH_BUSWIDTH 1 /* EBus is 8-bit */
33
David S. Miller29f7ac72006-06-24 23:27:00 -070034MODULE_AUTHOR("Eric Brower <ebrower@usa.net>");
35MODULE_DESCRIPTION("User-programmable flash device on Sun Microsystems boardsets");
36MODULE_SUPPORTED_DEVICE("userflash");
37MODULE_LICENSE("GPL");
38MODULE_VERSION("2.0");
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40static LIST_HEAD(device_list);
41struct uflash_dev {
Stephen Rothwellccf0dec2007-03-29 00:49:54 -070042 const char *name; /* device name */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 struct map_info map; /* mtd map info */
David S. Miller29f7ac72006-06-24 23:27:00 -070044 struct mtd_info *mtd; /* mtd info */
Linus Torvalds1da177e2005-04-16 15:20:36 -070045};
46
47
48struct map_info uflash_map_templ = {
David S. Miller29f7ac72006-06-24 23:27:00 -070049 .name = "SUNW,???-????",
50 .size = UFLASH_WINDOW_SIZE,
51 .bankwidth = UFLASH_BUSWIDTH,
Linus Torvalds1da177e2005-04-16 15:20:36 -070052};
53
David S. Miller29f7ac72006-06-24 23:27:00 -070054int uflash_devinit(struct linux_ebus_device *edev, struct device_node *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
David S. Miller29f7ac72006-06-24 23:27:00 -070056 struct uflash_dev *up;
57 struct resource *res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
David S. Miller29f7ac72006-06-24 23:27:00 -070059 res = &edev->resource[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
David S. Miller29f7ac72006-06-24 23:27:00 -070061 if (edev->num_addrs != 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 /* Non-CFI userflash device-- once I find one we
63 * can work on supporting it.
64 */
Greg Kroah-Hartman176dfc62006-06-12 15:15:17 -070065 printk("%s: unsupported device at 0x%llx (%d regs): " \
Thomas Gleixner69f34c92005-11-07 11:15:40 +000066 "email ebrower@usa.net\n",
Greg Kroah-Hartman176dfc62006-06-12 15:15:17 -070067 dp->full_name, (unsigned long long)res->start,
68 edev->num_addrs);
David S. Miller29f7ac72006-06-24 23:27:00 -070069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 return -ENODEV;
71 }
72
David S. Miller29f7ac72006-06-24 23:27:00 -070073 up = kzalloc(sizeof(struct uflash_dev), GFP_KERNEL);
74 if (!up)
75 return -ENOMEM;
Thomas Gleixner69f34c92005-11-07 11:15:40 +000076
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 /* copy defaults and tweak parameters */
David S. Miller29f7ac72006-06-24 23:27:00 -070078 memcpy(&up->map, &uflash_map_templ, sizeof(uflash_map_templ));
79 up->map.size = (res->end - res->start) + 1UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
David S. Miller29f7ac72006-06-24 23:27:00 -070081 up->name = of_get_property(dp, "model", NULL);
82 if (up->name && 0 < strlen(up->name))
Stephen Rothwellccf0dec2007-03-29 00:49:54 -070083 up->map.name = (char *)up->name;
David S. Miller29f7ac72006-06-24 23:27:00 -070084
85 up->map.phys = res->start;
86
87 up->map.virt = ioremap_nocache(res->start, up->map.size);
88 if (!up->map.virt) {
89 printk("%s: Failed to map device.\n", dp->full_name);
90 kfree(up);
91
92 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 }
94
David S. Miller29f7ac72006-06-24 23:27:00 -070095 simple_map_init(&up->map);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97 /* MTD registration */
David S. Miller29f7ac72006-06-24 23:27:00 -070098 up->mtd = do_map_probe("cfi_probe", &up->map);
99 if (!up->mtd) {
100 iounmap(up->map.virt);
101 kfree(up);
102
103 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 }
105
David S. Miller29f7ac72006-06-24 23:27:00 -0700106 up->mtd->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
David S. Miller29f7ac72006-06-24 23:27:00 -0700108 add_mtd_device(up->mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
David S. Miller29f7ac72006-06-24 23:27:00 -0700110 dev_set_drvdata(&edev->ofdev.dev, up);
111
112 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
David S. Miller29f7ac72006-06-24 23:27:00 -0700115static int __devinit uflash_probe(struct of_device *dev, const struct of_device_id *match)
116{
117 struct linux_ebus_device *edev = to_ebus_device(&dev->dev);
118 struct device_node *dp = dev->node;
119
120 if (of_find_property(dp, "user", NULL))
121 return -ENODEV;
122
123 return uflash_devinit(edev, dp);
124}
125
126static int __devexit uflash_remove(struct of_device *dev)
127{
128 struct uflash_dev *up = dev_get_drvdata(&dev->dev);
129
130 if (up->mtd) {
131 del_mtd_device(up->mtd);
132 map_destroy(up->mtd);
133 }
134 if (up->map.virt) {
135 iounmap(up->map.virt);
136 up->map.virt = NULL;
137 }
138
139 kfree(up);
140
141 return 0;
142}
143
144static struct of_device_id uflash_match[] = {
145 {
146 .name = UFLASH_OBPNAME,
147 },
148 {},
149};
150
151MODULE_DEVICE_TABLE(of, uflash_match);
152
153static struct of_platform_driver uflash_driver = {
154 .name = UFLASH_DEVNAME,
155 .match_table = uflash_match,
156 .probe = uflash_probe,
157 .remove = __devexit_p(uflash_remove),
158};
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160static int __init uflash_init(void)
161{
David S. Miller29f7ac72006-06-24 23:27:00 -0700162 return of_register_driver(&uflash_driver, &ebus_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
David S. Miller29f7ac72006-06-24 23:27:00 -0700165static void __exit uflash_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
David S. Miller29f7ac72006-06-24 23:27:00 -0700167 of_unregister_driver(&uflash_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
170module_init(uflash_init);
David S. Miller29f7ac72006-06-24 23:27:00 -0700171module_exit(uflash_exit);