1 /* sun_uflash.c - Driver for user-programmable flash on
2 * Sun Microsystems SME boardsets.
4 * This driver does NOT provide access to the OBP-flash for
5 * safety reasons-- use <linux>/drivers/sbus/char/flash.c instead.
7 * Copyright (c) 2001 Eric Brower (ebrower@usa.net)
10 #include <linux/kernel.h>
11 #include <linux/module.h>
13 #include <linux/errno.h>
14 #include <linux/ioport.h>
16 #include <linux/of_device.h>
17 #include <linux/slab.h>
19 #include <asm/uaccess.h>
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/map.h>
25 #define UFLASH_OBPNAME "flashprom"
26 #define DRIVER_NAME "sun_uflash"
27 #define PFX DRIVER_NAME ": "
29 #define UFLASH_WINDOW_SIZE 0x200000
30 #define UFLASH_BUSWIDTH 1 /* EBus is 8-bit */
32 MODULE_AUTHOR("Eric Brower <ebrower@usa.net>");
33 MODULE_DESCRIPTION("User-programmable flash device on Sun Microsystems boardsets");
34 MODULE_SUPPORTED_DEVICE(DRIVER_NAME
);
35 MODULE_LICENSE("GPL");
36 MODULE_VERSION("2.1");
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 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 %s, 0x%llx\n",
59 dp
->full_name
, (unsigned long long)op
->resource
[0].start
);
64 up
= kzalloc(sizeof(struct uflash_dev
), GFP_KERNEL
);
66 printk(KERN_ERR PFX
"Cannot allocate struct uflash_dev\n");
70 /* copy defaults and tweak parameters */
71 memcpy(&up
->map
, &uflash_map_templ
, sizeof(uflash_map_templ
));
73 up
->map
.size
= resource_size(&op
->resource
[0]);
75 up
->name
= of_get_property(dp
, "model", NULL
);
76 if (up
->name
&& 0 < strlen(up
->name
))
77 up
->map
.name
= up
->name
;
79 up
->map
.phys
= op
->resource
[0].start
;
81 up
->map
.virt
= of_ioremap(&op
->resource
[0], 0, up
->map
.size
,
84 printk(KERN_ERR PFX
"Failed to map device.\n");
90 simple_map_init(&up
->map
);
92 /* MTD registration */
93 up
->mtd
= do_map_probe("cfi_probe", &up
->map
);
95 of_iounmap(&op
->resource
[0], up
->map
.virt
, up
->map
.size
);
101 up
->mtd
->owner
= THIS_MODULE
;
103 mtd_device_register(up
->mtd
, NULL
, 0);
105 dev_set_drvdata(&op
->dev
, up
);
110 static int uflash_probe(struct platform_device
*op
)
112 struct device_node
*dp
= op
->dev
.of_node
;
114 /* Flashprom must have the "user" property in order to
115 * be used by this driver.
117 if (!of_find_property(dp
, "user", NULL
))
120 return uflash_devinit(op
, dp
);
123 static int uflash_remove(struct platform_device
*op
)
125 struct uflash_dev
*up
= dev_get_drvdata(&op
->dev
);
128 mtd_device_unregister(up
->mtd
);
129 map_destroy(up
->mtd
);
132 of_iounmap(&op
->resource
[0], up
->map
.virt
, up
->map
.size
);
141 static const struct of_device_id uflash_match
[] = {
143 .name
= UFLASH_OBPNAME
,
148 MODULE_DEVICE_TABLE(of
, uflash_match
);
150 static struct platform_driver uflash_driver
= {
153 .owner
= THIS_MODULE
,
154 .of_match_table
= uflash_match
,
156 .probe
= uflash_probe
,
157 .remove
= uflash_remove
,
160 module_platform_driver(uflash_driver
);