Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 1 | /* $Id: sun_uflash.c,v 1.13 2005/11/07 11:14:28 gleixner Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 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. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 21 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #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. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 34 | MODULE_AUTHOR("Eric Brower <ebrower@usa.net>"); |
| 35 | MODULE_DESCRIPTION("User-programmable flash device on Sun Microsystems boardsets"); |
| 36 | MODULE_SUPPORTED_DEVICE("userflash"); |
| 37 | MODULE_LICENSE("GPL"); |
| 38 | MODULE_VERSION("2.0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | static LIST_HEAD(device_list); |
| 41 | struct uflash_dev { |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 42 | char *name; /* device name */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | struct map_info map; /* mtd map info */ |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 44 | struct mtd_info *mtd; /* mtd info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | |
| 48 | struct map_info uflash_map_templ = { |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 49 | .name = "SUNW,???-????", |
| 50 | .size = UFLASH_WINDOW_SIZE, |
| 51 | .bankwidth = UFLASH_BUSWIDTH, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 54 | int uflash_devinit(struct linux_ebus_device *edev, struct device_node *dp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 56 | struct uflash_dev *up; |
| 57 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 59 | res = &edev->resource[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 61 | if (edev->num_addrs != 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | /* Non-CFI userflash device-- once I find one we |
| 63 | * can work on supporting it. |
| 64 | */ |
| 65 | printk("%s: unsupported device at 0x%lx (%d regs): " \ |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 66 | "email ebrower@usa.net\n", |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 67 | dp->full_name, res->start, edev->num_addrs); |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | return -ENODEV; |
| 70 | } |
| 71 | |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 72 | up = kzalloc(sizeof(struct uflash_dev), GFP_KERNEL); |
| 73 | if (!up) |
| 74 | return -ENOMEM; |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* copy defaults and tweak parameters */ |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 77 | memcpy(&up->map, &uflash_map_templ, sizeof(uflash_map_templ)); |
| 78 | up->map.size = (res->end - res->start) + 1UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 80 | up->name = of_get_property(dp, "model", NULL); |
| 81 | if (up->name && 0 < strlen(up->name)) |
| 82 | up->map.name = up->name; |
| 83 | |
| 84 | up->map.phys = res->start; |
| 85 | |
| 86 | up->map.virt = ioremap_nocache(res->start, up->map.size); |
| 87 | if (!up->map.virt) { |
| 88 | printk("%s: Failed to map device.\n", dp->full_name); |
| 89 | kfree(up); |
| 90 | |
| 91 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 94 | simple_map_init(&up->map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* MTD registration */ |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 97 | up->mtd = do_map_probe("cfi_probe", &up->map); |
| 98 | if (!up->mtd) { |
| 99 | iounmap(up->map.virt); |
| 100 | kfree(up); |
| 101 | |
| 102 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 105 | up->mtd->owner = THIS_MODULE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 107 | add_mtd_device(up->mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 109 | dev_set_drvdata(&edev->ofdev.dev, up); |
| 110 | |
| 111 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 114 | static int __devinit uflash_probe(struct of_device *dev, const struct of_device_id *match) |
| 115 | { |
| 116 | struct linux_ebus_device *edev = to_ebus_device(&dev->dev); |
| 117 | struct device_node *dp = dev->node; |
| 118 | |
| 119 | if (of_find_property(dp, "user", NULL)) |
| 120 | return -ENODEV; |
| 121 | |
| 122 | return uflash_devinit(edev, dp); |
| 123 | } |
| 124 | |
| 125 | static int __devexit uflash_remove(struct of_device *dev) |
| 126 | { |
| 127 | struct uflash_dev *up = dev_get_drvdata(&dev->dev); |
| 128 | |
| 129 | if (up->mtd) { |
| 130 | del_mtd_device(up->mtd); |
| 131 | map_destroy(up->mtd); |
| 132 | } |
| 133 | if (up->map.virt) { |
| 134 | iounmap(up->map.virt); |
| 135 | up->map.virt = NULL; |
| 136 | } |
| 137 | |
| 138 | kfree(up); |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | static struct of_device_id uflash_match[] = { |
| 144 | { |
| 145 | .name = UFLASH_OBPNAME, |
| 146 | }, |
| 147 | {}, |
| 148 | }; |
| 149 | |
| 150 | MODULE_DEVICE_TABLE(of, uflash_match); |
| 151 | |
| 152 | static struct of_platform_driver uflash_driver = { |
| 153 | .name = UFLASH_DEVNAME, |
| 154 | .match_table = uflash_match, |
| 155 | .probe = uflash_probe, |
| 156 | .remove = __devexit_p(uflash_remove), |
| 157 | }; |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | static int __init uflash_init(void) |
| 160 | { |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 161 | return of_register_driver(&uflash_driver, &ebus_bus_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 164 | static void __exit uflash_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | { |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 166 | of_unregister_driver(&uflash_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | module_init(uflash_init); |
David S. Miller | 29f7ac7 | 2006-06-24 23:27:00 -0700 | [diff] [blame^] | 170 | module_exit(uflash_exit); |