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> | |
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 |
33 | MODULE_AUTHOR("Eric Brower <ebrower@usa.net>"); |
34 | MODULE_DESCRIPTION("User-programmable flash device on Sun Microsystems boardsets"); | |
0e52fe8c | 35 | MODULE_SUPPORTED_DEVICE(DRIVER_NAME); |
29f7ac7e | 36 | MODULE_LICENSE("GPL"); |
0e52fe8c | 37 | MODULE_VERSION("2.1"); |
1da177e4 | 38 | |
1da177e4 | 39 | struct 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 | 45 | struct map_info uflash_map_templ = { |
29f7ac7e DM |
46 | .name = "SUNW,???-????", |
47 | .size = UFLASH_WINDOW_SIZE, | |
48 | .bankwidth = UFLASH_BUSWIDTH, | |
1da177e4 LT |
49 | }; |
50 | ||
2dc11581 | 51 | int uflash_devinit(struct platform_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 | |
ee0e87b1 | 104 | mtd_device_register(up->mtd, NULL, 0); |
1da177e4 | 105 | |
0e52fe8c | 106 | dev_set_drvdata(&op->dev, up); |
29f7ac7e DM |
107 | |
108 | return 0; | |
1da177e4 LT |
109 | } |
110 | ||
1c48a5c9 | 111 | static int __devinit uflash_probe(struct platform_device *op) |
1da177e4 | 112 | { |
61c7a080 | 113 | struct device_node *dp = op->dev.of_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 | ||
2dc11581 | 124 | static int __devexit uflash_remove(struct platform_device *op) |
1da177e4 | 125 | { |
0e52fe8c | 126 | struct uflash_dev *up = dev_get_drvdata(&op->dev); |
29f7ac7e DM |
127 | |
128 | if (up->mtd) { | |
ee0e87b1 | 129 | mtd_device_unregister(up->mtd); |
29f7ac7e | 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 | 142 | static const struct of_device_id uflash_match[] = { |
29f7ac7e DM |
143 | { |
144 | .name = UFLASH_OBPNAME, | |
145 | }, | |
146 | {}, | |
147 | }; | |
148 | ||
149 | MODULE_DEVICE_TABLE(of, uflash_match); | |
150 | ||
1c48a5c9 | 151 | static struct platform_driver uflash_driver = { |
4018294b GL |
152 | .driver = { |
153 | .name = DRIVER_NAME, | |
154 | .owner = THIS_MODULE, | |
155 | .of_match_table = uflash_match, | |
156 | }, | |
29f7ac7e DM |
157 | .probe = uflash_probe, |
158 | .remove = __devexit_p(uflash_remove), | |
159 | }; | |
160 | ||
f99640de | 161 | module_platform_driver(uflash_driver); |