Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / mtd / maps / sun_uflash.c
blobea3aa026b55b04da3087b50068463035c9b4acdd
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* sun_uflash.c - Driver for user-programmable flash on
3 * Sun Microsystems SME boardsets.
5 * This driver does NOT provide access to the OBP-flash for
6 * safety reasons-- use <linux>/drivers/sbus/char/flash.c instead.
8 * Copyright (c) 2001 Eric Brower (ebrower@usa.net)
9 */
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/fs.h>
14 #include <linux/errno.h>
15 #include <linux/ioport.h>
16 #include <linux/of.h>
17 #include <linux/platform_device.h>
18 #include <linux/slab.h>
19 #include <asm/prom.h>
20 #include <linux/uaccess.h>
21 #include <asm/io.h>
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/map.h>
26 #define UFLASH_OBPNAME "flashprom"
27 #define DRIVER_NAME "sun_uflash"
28 #define PFX DRIVER_NAME ": "
30 #define UFLASH_WINDOW_SIZE 0x200000
31 #define UFLASH_BUSWIDTH 1 /* EBus is 8-bit */
33 MODULE_AUTHOR("Eric Brower <ebrower@usa.net>");
34 MODULE_DESCRIPTION("User-programmable flash device on Sun Microsystems boardsets");
35 MODULE_LICENSE("GPL");
36 MODULE_VERSION("2.1");
38 struct uflash_dev {
39 const char *name; /* device name */
40 struct map_info map; /* mtd map info */
41 struct mtd_info *mtd; /* mtd info */
44 struct map_info uflash_map_templ = {
45 .name = "SUNW,???-????",
46 .size = UFLASH_WINDOW_SIZE,
47 .bankwidth = UFLASH_BUSWIDTH,
50 static int uflash_devinit(struct platform_device *op, struct device_node *dp)
52 struct uflash_dev *up;
54 if (op->resource[1].flags) {
55 /* Non-CFI userflash device-- once I find one we
56 * can work on supporting it.
58 printk(KERN_ERR PFX "Unsupported device at %pOF, 0x%llx\n",
59 dp, (unsigned long long)op->resource[0].start);
61 return -ENODEV;
64 up = kzalloc(sizeof(struct uflash_dev), GFP_KERNEL);
65 if (!up)
66 return -ENOMEM;
68 /* copy defaults and tweak parameters */
69 memcpy(&up->map, &uflash_map_templ, sizeof(uflash_map_templ));
71 up->map.size = resource_size(&op->resource[0]);
73 up->name = of_get_property(dp, "model", NULL);
74 if (up->name && 0 < strlen(up->name))
75 up->map.name = up->name;
77 up->map.phys = op->resource[0].start;
79 up->map.virt = of_ioremap(&op->resource[0], 0, up->map.size,
80 DRIVER_NAME);
81 if (!up->map.virt) {
82 printk(KERN_ERR PFX "Failed to map device.\n");
83 kfree(up);
85 return -EINVAL;
88 simple_map_init(&up->map);
90 /* MTD registration */
91 up->mtd = do_map_probe("cfi_probe", &up->map);
92 if (!up->mtd) {
93 of_iounmap(&op->resource[0], up->map.virt, up->map.size);
94 kfree(up);
96 return -ENXIO;
99 up->mtd->owner = THIS_MODULE;
101 mtd_device_register(up->mtd, NULL, 0);
103 dev_set_drvdata(&op->dev, up);
105 return 0;
108 static int uflash_probe(struct platform_device *op)
110 struct device_node *dp = op->dev.of_node;
112 /* Flashprom must have the "user" property in order to
113 * be used by this driver.
115 if (!of_property_read_bool(dp, "user"))
116 return -ENODEV;
118 return uflash_devinit(op, dp);
121 static void uflash_remove(struct platform_device *op)
123 struct uflash_dev *up = dev_get_drvdata(&op->dev);
125 if (up->mtd) {
126 mtd_device_unregister(up->mtd);
127 map_destroy(up->mtd);
129 if (up->map.virt) {
130 of_iounmap(&op->resource[0], up->map.virt, up->map.size);
131 up->map.virt = NULL;
134 kfree(up);
137 static const struct of_device_id uflash_match[] = {
139 .name = UFLASH_OBPNAME,
144 MODULE_DEVICE_TABLE(of, uflash_match);
146 static struct platform_driver uflash_driver = {
147 .driver = {
148 .name = DRIVER_NAME,
149 .of_match_table = uflash_match,
151 .probe = uflash_probe,
152 .remove = uflash_remove,
155 module_platform_driver(uflash_driver);