sun_uflash.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* $Id: sun_uflash.c,v 1.13 2005/11/07 11:14:28 gleixner Exp $
  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. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/fs.h>
  15. #include <linux/errno.h>
  16. #include <linux/init.h>
  17. #include <linux/ioport.h>
  18. #include <asm/ebus.h>
  19. #include <asm/oplib.h>
  20. #include <asm/prom.h>
  21. #include <asm/uaccess.h>
  22. #include <asm/io.h>
  23. #include <linux/mtd/mtd.h>
  24. #include <linux/mtd/map.h>
  25. #define UFLASH_OBPNAME "flashprom"
  26. #define UFLASH_DEVNAME "userflash"
  27. #define UFLASH_WINDOW_SIZE 0x200000
  28. #define UFLASH_BUSWIDTH 1 /* EBus is 8-bit */
  29. MODULE_AUTHOR("Eric Brower <ebrower@usa.net>");
  30. MODULE_DESCRIPTION("User-programmable flash device on Sun Microsystems boardsets");
  31. MODULE_SUPPORTED_DEVICE("userflash");
  32. MODULE_LICENSE("GPL");
  33. MODULE_VERSION("2.0");
  34. static LIST_HEAD(device_list);
  35. struct uflash_dev {
  36. const char *name; /* device name */
  37. struct map_info map; /* mtd map info */
  38. struct mtd_info *mtd; /* mtd info */
  39. };
  40. struct map_info uflash_map_templ = {
  41. .name = "SUNW,???-????",
  42. .size = UFLASH_WINDOW_SIZE,
  43. .bankwidth = UFLASH_BUSWIDTH,
  44. };
  45. int uflash_devinit(struct linux_ebus_device *edev, struct device_node *dp)
  46. {
  47. struct uflash_dev *up;
  48. struct resource *res;
  49. res = &edev->resource[0];
  50. if (edev->num_addrs != 1) {
  51. /* Non-CFI userflash device-- once I find one we
  52. * can work on supporting it.
  53. */
  54. printk("%s: unsupported device at 0x%llx (%d regs): " \
  55. "email ebrower@usa.net\n",
  56. dp->full_name, (unsigned long long)res->start,
  57. edev->num_addrs);
  58. return -ENODEV;
  59. }
  60. up = kzalloc(sizeof(struct uflash_dev), GFP_KERNEL);
  61. if (!up)
  62. return -ENOMEM;
  63. /* copy defaults and tweak parameters */
  64. memcpy(&up->map, &uflash_map_templ, sizeof(uflash_map_templ));
  65. up->map.size = (res->end - res->start) + 1UL;
  66. up->name = of_get_property(dp, "model", NULL);
  67. if (up->name && 0 < strlen(up->name))
  68. up->map.name = (char *)up->name;
  69. up->map.phys = res->start;
  70. up->map.virt = ioremap_nocache(res->start, up->map.size);
  71. if (!up->map.virt) {
  72. printk("%s: Failed to map device.\n", dp->full_name);
  73. kfree(up);
  74. return -EINVAL;
  75. }
  76. simple_map_init(&up->map);
  77. /* MTD registration */
  78. up->mtd = do_map_probe("cfi_probe", &up->map);
  79. if (!up->mtd) {
  80. iounmap(up->map.virt);
  81. kfree(up);
  82. return -ENXIO;
  83. }
  84. up->mtd->owner = THIS_MODULE;
  85. add_mtd_device(up->mtd);
  86. dev_set_drvdata(&edev->ofdev.dev, up);
  87. return 0;
  88. }
  89. static int __devinit uflash_probe(struct of_device *dev, const struct of_device_id *match)
  90. {
  91. struct linux_ebus_device *edev = to_ebus_device(&dev->dev);
  92. struct device_node *dp = dev->node;
  93. if (of_find_property(dp, "user", NULL))
  94. return -ENODEV;
  95. return uflash_devinit(edev, dp);
  96. }
  97. static int __devexit uflash_remove(struct of_device *dev)
  98. {
  99. struct uflash_dev *up = dev_get_drvdata(&dev->dev);
  100. if (up->mtd) {
  101. del_mtd_device(up->mtd);
  102. map_destroy(up->mtd);
  103. }
  104. if (up->map.virt) {
  105. iounmap(up->map.virt);
  106. up->map.virt = NULL;
  107. }
  108. kfree(up);
  109. return 0;
  110. }
  111. static struct of_device_id uflash_match[] = {
  112. {
  113. .name = UFLASH_OBPNAME,
  114. },
  115. {},
  116. };
  117. MODULE_DEVICE_TABLE(of, uflash_match);
  118. static struct of_platform_driver uflash_driver = {
  119. .name = UFLASH_DEVNAME,
  120. .match_table = uflash_match,
  121. .probe = uflash_probe,
  122. .remove = __devexit_p(uflash_remove),
  123. };
  124. static int __init uflash_init(void)
  125. {
  126. return of_register_driver(&uflash_driver, &ebus_bus_type);
  127. }
  128. static void __exit uflash_exit(void)
  129. {
  130. of_unregister_driver(&uflash_driver);
  131. }
  132. module_init(uflash_init);
  133. module_exit(uflash_exit);