Commit | Line | Data |
---|---|---|
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> | |
1da177e4 | 14 | #include <linux/ioport.h> |
0e52fe8c DM |
15 | #include <linux/of.h> |
16 | #include <linux/of_device.h> | |
5a0e3ad6 | 17 | #include <linux/slab.h> |
29f7ac7e | 18 | #include <asm/prom.h> |
7c0f6ba6 | 19 | #include <linux/uaccess.h> |
1da177e4 LT |
20 | #include <asm/io.h> |
21 | ||
22 | #include <linux/mtd/mtd.h> | |
23 | #include <linux/mtd/map.h> | |
24 | ||
25 | #define UFLASH_OBPNAME "flashprom" | |
0e52fe8c DM |
26 | #define DRIVER_NAME "sun_uflash" |
27 | #define PFX DRIVER_NAME ": " | |
1da177e4 LT |
28 | |
29 | #define UFLASH_WINDOW_SIZE 0x200000 | |
30 | #define UFLASH_BUSWIDTH 1 /* EBus is 8-bit */ | |
31 | ||
29f7ac7e DM |
32 | MODULE_AUTHOR("Eric Brower <ebrower@usa.net>"); |
33 | MODULE_DESCRIPTION("User-programmable flash device on Sun Microsystems boardsets"); | |
0e52fe8c | 34 | MODULE_SUPPORTED_DEVICE(DRIVER_NAME); |
29f7ac7e | 35 | MODULE_LICENSE("GPL"); |
0e52fe8c | 36 | MODULE_VERSION("2.1"); |
1da177e4 | 37 | |
1da177e4 | 38 | struct uflash_dev { |
ccf0dec6 | 39 | const char *name; /* device name */ |
1da177e4 | 40 | struct map_info map; /* mtd map info */ |
29f7ac7e | 41 | struct mtd_info *mtd; /* mtd info */ |
1da177e4 LT |
42 | }; |
43 | ||
1da177e4 | 44 | struct map_info uflash_map_templ = { |
29f7ac7e DM |
45 | .name = "SUNW,???-????", |
46 | .size = UFLASH_WINDOW_SIZE, | |
47 | .bankwidth = UFLASH_BUSWIDTH, | |
1da177e4 LT |
48 | }; |
49 | ||
2dc11581 | 50 | int uflash_devinit(struct platform_device *op, struct device_node *dp) |
1da177e4 | 51 | { |
29f7ac7e | 52 | struct uflash_dev *up; |
1da177e4 | 53 | |
0e52fe8c | 54 | if (op->resource[1].flags) { |
1da177e4 LT |
55 | /* Non-CFI userflash device-- once I find one we |
56 | * can work on supporting it. | |
57 | */ | |
0e52fe8c DM |
58 | printk(KERN_ERR PFX "Unsupported device at %s, 0x%llx\n", |
59 | dp->full_name, (unsigned long long)op->resource[0].start); | |
29f7ac7e | 60 | |
1da177e4 LT |
61 | return -ENODEV; |
62 | } | |
63 | ||
29f7ac7e | 64 | up = kzalloc(sizeof(struct uflash_dev), GFP_KERNEL); |
0e52fe8c DM |
65 | if (!up) { |
66 | printk(KERN_ERR PFX "Cannot allocate struct uflash_dev\n"); | |
29f7ac7e | 67 | return -ENOMEM; |
0e52fe8c | 68 | } |
69f34c98 | 69 | |
1da177e4 | 70 | /* copy defaults and tweak parameters */ |
29f7ac7e | 71 | memcpy(&up->map, &uflash_map_templ, sizeof(uflash_map_templ)); |
0e52fe8c DM |
72 | |
73 | up->map.size = resource_size(&op->resource[0]); | |
29f7ac7e DM |
74 | |
75 | up->name = of_get_property(dp, "model", NULL); | |
76 | if (up->name && 0 < strlen(up->name)) | |
7c4bb4f8 | 77 | up->map.name = up->name; |
29f7ac7e | 78 | |
0e52fe8c | 79 | up->map.phys = op->resource[0].start; |
29f7ac7e | 80 | |
0e52fe8c DM |
81 | up->map.virt = of_ioremap(&op->resource[0], 0, up->map.size, |
82 | DRIVER_NAME); | |
29f7ac7e | 83 | if (!up->map.virt) { |
0e52fe8c | 84 | printk(KERN_ERR PFX "Failed to map device.\n"); |
29f7ac7e DM |
85 | kfree(up); |
86 | ||
87 | return -EINVAL; | |
1da177e4 LT |
88 | } |
89 | ||
29f7ac7e | 90 | simple_map_init(&up->map); |
1da177e4 LT |
91 | |
92 | /* MTD registration */ | |
29f7ac7e DM |
93 | up->mtd = do_map_probe("cfi_probe", &up->map); |
94 | if (!up->mtd) { | |
0e52fe8c | 95 | of_iounmap(&op->resource[0], up->map.virt, up->map.size); |
29f7ac7e DM |
96 | kfree(up); |
97 | ||
98 | return -ENXIO; | |
1da177e4 LT |
99 | } |
100 | ||
29f7ac7e | 101 | up->mtd->owner = THIS_MODULE; |
1da177e4 | 102 | |
ee0e87b1 | 103 | mtd_device_register(up->mtd, NULL, 0); |
1da177e4 | 104 | |
0e52fe8c | 105 | dev_set_drvdata(&op->dev, up); |
29f7ac7e DM |
106 | |
107 | return 0; | |
1da177e4 LT |
108 | } |
109 | ||
06f25510 | 110 | static int uflash_probe(struct platform_device *op) |
1da177e4 | 111 | { |
61c7a080 | 112 | struct device_node *dp = op->dev.of_node; |
1da177e4 | 113 | |
0e52fe8c DM |
114 | /* Flashprom must have the "user" property in order to |
115 | * be used by this driver. | |
116 | */ | |
117 | if (!of_find_property(dp, "user", NULL)) | |
1da177e4 | 118 | return -ENODEV; |
29f7ac7e | 119 | |
0e52fe8c | 120 | return uflash_devinit(op, dp); |
1da177e4 LT |
121 | } |
122 | ||
810b7e06 | 123 | static int uflash_remove(struct platform_device *op) |
1da177e4 | 124 | { |
0e52fe8c | 125 | struct uflash_dev *up = dev_get_drvdata(&op->dev); |
29f7ac7e DM |
126 | |
127 | if (up->mtd) { | |
ee0e87b1 | 128 | mtd_device_unregister(up->mtd); |
29f7ac7e | 129 | map_destroy(up->mtd); |
69f34c98 | 130 | } |
29f7ac7e | 131 | if (up->map.virt) { |
0e52fe8c | 132 | of_iounmap(&op->resource[0], up->map.virt, up->map.size); |
29f7ac7e DM |
133 | up->map.virt = NULL; |
134 | } | |
135 | ||
136 | kfree(up); | |
137 | ||
138 | return 0; | |
139 | } | |
140 | ||
fd098316 | 141 | static const struct of_device_id uflash_match[] = { |
29f7ac7e DM |
142 | { |
143 | .name = UFLASH_OBPNAME, | |
144 | }, | |
145 | {}, | |
146 | }; | |
147 | ||
148 | MODULE_DEVICE_TABLE(of, uflash_match); | |
149 | ||
1c48a5c9 | 150 | static struct platform_driver uflash_driver = { |
4018294b GL |
151 | .driver = { |
152 | .name = DRIVER_NAME, | |
4018294b GL |
153 | .of_match_table = uflash_match, |
154 | }, | |
29f7ac7e | 155 | .probe = uflash_probe, |
5153b88c | 156 | .remove = uflash_remove, |
29f7ac7e DM |
157 | }; |
158 | ||
f99640de | 159 | module_platform_driver(uflash_driver); |