pxa2xx-flash.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Map driver for Intel XScale PXA2xx platforms.
  3. *
  4. * Author: Nicolas Pitre
  5. * Copyright: (C) 2001 MontaVista Software Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/types.h>
  13. #include <linux/slab.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/map.h>
  19. #include <linux/mtd/partitions.h>
  20. #include <asm/io.h>
  21. #include <mach/hardware.h>
  22. #include <asm/mach/flash.h>
  23. #define CACHELINESIZE 32
  24. static void pxa2xx_map_inval_cache(struct map_info *map, unsigned long from,
  25. ssize_t len)
  26. {
  27. unsigned long start = (unsigned long)map->cached + from;
  28. unsigned long end = start + len;
  29. start &= ~(CACHELINESIZE - 1);
  30. while (start < end) {
  31. /* invalidate D cache line */
  32. asm volatile ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
  33. start += CACHELINESIZE;
  34. }
  35. }
  36. struct pxa2xx_flash_info {
  37. struct mtd_info *mtd;
  38. struct map_info map;
  39. };
  40. static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
  41. static int __devinit pxa2xx_flash_probe(struct platform_device *pdev)
  42. {
  43. struct flash_platform_data *flash = pdev->dev.platform_data;
  44. struct pxa2xx_flash_info *info;
  45. struct resource *res;
  46. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  47. if (!res)
  48. return -ENODEV;
  49. info = kzalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL);
  50. if (!info)
  51. return -ENOMEM;
  52. info->map.name = (char *) flash->name;
  53. info->map.bankwidth = flash->width;
  54. info->map.phys = res->start;
  55. info->map.size = resource_size(res);
  56. info->map.virt = ioremap(info->map.phys, info->map.size);
  57. if (!info->map.virt) {
  58. printk(KERN_WARNING "Failed to ioremap %s\n",
  59. info->map.name);
  60. return -ENOMEM;
  61. }
  62. info->map.cached =
  63. ioremap_cached(info->map.phys, info->map.size);
  64. if (!info->map.cached)
  65. printk(KERN_WARNING "Failed to ioremap cached %s\n",
  66. info->map.name);
  67. info->map.inval_cache = pxa2xx_map_inval_cache;
  68. simple_map_init(&info->map);
  69. printk(KERN_NOTICE
  70. "Probing %s at physical address 0x%08lx"
  71. " (%d-bit bankwidth)\n",
  72. info->map.name, (unsigned long)info->map.phys,
  73. info->map.bankwidth * 8);
  74. info->mtd = do_map_probe(flash->map_name, &info->map);
  75. if (!info->mtd) {
  76. iounmap((void *)info->map.virt);
  77. if (info->map.cached)
  78. iounmap(info->map.cached);
  79. return -EIO;
  80. }
  81. info->mtd->owner = THIS_MODULE;
  82. mtd_device_parse_register(info->mtd, probes, 0, NULL, 0);
  83. platform_set_drvdata(pdev, info);
  84. return 0;
  85. }
  86. static int __devexit pxa2xx_flash_remove(struct platform_device *dev)
  87. {
  88. struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
  89. platform_set_drvdata(dev, NULL);
  90. mtd_device_unregister(info->mtd);
  91. map_destroy(info->mtd);
  92. iounmap(info->map.virt);
  93. if (info->map.cached)
  94. iounmap(info->map.cached);
  95. kfree(info);
  96. return 0;
  97. }
  98. #ifdef CONFIG_PM
  99. static void pxa2xx_flash_shutdown(struct platform_device *dev)
  100. {
  101. struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
  102. if (info && info->mtd->suspend(info->mtd) == 0)
  103. info->mtd->resume(info->mtd);
  104. }
  105. #else
  106. #define pxa2xx_flash_shutdown NULL
  107. #endif
  108. static struct platform_driver pxa2xx_flash_driver = {
  109. .driver = {
  110. .name = "pxa2xx-flash",
  111. .owner = THIS_MODULE,
  112. },
  113. .probe = pxa2xx_flash_probe,
  114. .remove = __devexit_p(pxa2xx_flash_remove),
  115. .shutdown = pxa2xx_flash_shutdown,
  116. };
  117. static int __init init_pxa2xx_flash(void)
  118. {
  119. return platform_driver_register(&pxa2xx_flash_driver);
  120. }
  121. static void __exit cleanup_pxa2xx_flash(void)
  122. {
  123. platform_driver_unregister(&pxa2xx_flash_driver);
  124. }
  125. module_init(init_pxa2xx_flash);
  126. module_exit(cleanup_pxa2xx_flash);
  127. MODULE_LICENSE("GPL");
  128. MODULE_AUTHOR("Nicolas Pitre <nico@fluxnic.net>");
  129. MODULE_DESCRIPTION("MTD map driver for Intel XScale PXA2xx");