sun_uflash.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* sun_uflash.c - Driver for user-programmable flash on
  2. * Sun Microsystems SME boardsets.
  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)
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/fs.h>
  12. #include <linux/errno.h>
  13. #include <linux/init.h>
  14. #include <linux/ioport.h>
  15. #include <linux/of.h>
  16. #include <linux/of_device.h>
  17. #include <linux/slab.h>
  18. #include <asm/prom.h>
  19. #include <asm/uaccess.h>
  20. #include <asm/io.h>
  21. #include <linux/mtd/mtd.h>
  22. #include <linux/mtd/map.h>
  23. #define UFLASH_OBPNAME "flashprom"
  24. #define DRIVER_NAME "sun_uflash"
  25. #define PFX DRIVER_NAME ": "
  26. #define UFLASH_WINDOW_SIZE 0x200000
  27. #define UFLASH_BUSWIDTH 1 /* EBus is 8-bit */
  28. MODULE_AUTHOR("Eric Brower <ebrower@usa.net>");
  29. MODULE_DESCRIPTION("User-programmable flash device on Sun Microsystems boardsets");
  30. MODULE_SUPPORTED_DEVICE(DRIVER_NAME);
  31. MODULE_LICENSE("GPL");
  32. MODULE_VERSION("2.1");
  33. struct uflash_dev {
  34. const char *name; /* device name */
  35. struct map_info map; /* mtd map info */
  36. struct mtd_info *mtd; /* mtd info */
  37. };
  38. struct map_info uflash_map_templ = {
  39. .name = "SUNW,???-????",
  40. .size = UFLASH_WINDOW_SIZE,
  41. .bankwidth = UFLASH_BUSWIDTH,
  42. };
  43. int uflash_devinit(struct platform_device *op, struct device_node *dp)
  44. {
  45. struct uflash_dev *up;
  46. if (op->resource[1].flags) {
  47. /* Non-CFI userflash device-- once I find one we
  48. * can work on supporting it.
  49. */
  50. printk(KERN_ERR PFX "Unsupported device at %s, 0x%llx\n",
  51. dp->full_name, (unsigned long long)op->resource[0].start);
  52. return -ENODEV;
  53. }
  54. up = kzalloc(sizeof(struct uflash_dev), GFP_KERNEL);
  55. if (!up) {
  56. printk(KERN_ERR PFX "Cannot allocate struct uflash_dev\n");
  57. return -ENOMEM;
  58. }
  59. /* copy defaults and tweak parameters */
  60. memcpy(&up->map, &uflash_map_templ, sizeof(uflash_map_templ));
  61. up->map.size = resource_size(&op->resource[0]);
  62. up->name = of_get_property(dp, "model", NULL);
  63. if (up->name && 0 < strlen(up->name))
  64. up->map.name = (char *)up->name;
  65. up->map.phys = op->resource[0].start;
  66. up->map.virt = of_ioremap(&op->resource[0], 0, up->map.size,
  67. DRIVER_NAME);
  68. if (!up->map.virt) {
  69. printk(KERN_ERR PFX "Failed to map device.\n");
  70. kfree(up);
  71. return -EINVAL;
  72. }
  73. simple_map_init(&up->map);
  74. /* MTD registration */
  75. up->mtd = do_map_probe("cfi_probe", &up->map);
  76. if (!up->mtd) {
  77. of_iounmap(&op->resource[0], up->map.virt, up->map.size);
  78. kfree(up);
  79. return -ENXIO;
  80. }
  81. up->mtd->owner = THIS_MODULE;
  82. mtd_device_register(up->mtd, NULL, 0);
  83. dev_set_drvdata(&op->dev, up);
  84. return 0;
  85. }
  86. static int __devinit uflash_probe(struct platform_device *op)
  87. {
  88. struct device_node *dp = op->dev.of_node;
  89. /* Flashprom must have the "user" property in order to
  90. * be used by this driver.
  91. */
  92. if (!of_find_property(dp, "user", NULL))
  93. return -ENODEV;
  94. return uflash_devinit(op, dp);
  95. }
  96. static int __devexit uflash_remove(struct platform_device *op)
  97. {
  98. struct uflash_dev *up = dev_get_drvdata(&op->dev);
  99. if (up->mtd) {
  100. mtd_device_unregister(up->mtd);
  101. map_destroy(up->mtd);
  102. }
  103. if (up->map.virt) {
  104. of_iounmap(&op->resource[0], up->map.virt, up->map.size);
  105. up->map.virt = NULL;
  106. }
  107. kfree(up);
  108. return 0;
  109. }
  110. static const struct of_device_id uflash_match[] = {
  111. {
  112. .name = UFLASH_OBPNAME,
  113. },
  114. {},
  115. };
  116. MODULE_DEVICE_TABLE(of, uflash_match);
  117. static struct platform_driver uflash_driver = {
  118. .driver = {
  119. .name = DRIVER_NAME,
  120. .owner = THIS_MODULE,
  121. .of_match_table = uflash_match,
  122. },
  123. .probe = uflash_probe,
  124. .remove = __devexit_p(uflash_remove),
  125. };
  126. module_platform_driver(uflash_driver);