sun_uflash.c 3.5 KB

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