pxa2xx-flash.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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, NULL, flash->parts,
  83. flash->nr_parts);
  84. platform_set_drvdata(pdev, info);
  85. return 0;
  86. }
  87. static int __devexit pxa2xx_flash_remove(struct platform_device *dev)
  88. {
  89. struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
  90. platform_set_drvdata(dev, NULL);
  91. mtd_device_unregister(info->mtd);
  92. map_destroy(info->mtd);
  93. iounmap(info->map.virt);
  94. if (info->map.cached)
  95. iounmap(info->map.cached);
  96. kfree(info);
  97. return 0;
  98. }
  99. #ifdef CONFIG_PM
  100. static void pxa2xx_flash_shutdown(struct platform_device *dev)
  101. {
  102. struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
  103. if (info && mtd_suspend(info->mtd) == 0)
  104. mtd_resume(info->mtd);
  105. }
  106. #else
  107. #define pxa2xx_flash_shutdown NULL
  108. #endif
  109. static struct platform_driver pxa2xx_flash_driver = {
  110. .driver = {
  111. .name = "pxa2xx-flash",
  112. .owner = THIS_MODULE,
  113. },
  114. .probe = pxa2xx_flash_probe,
  115. .remove = __devexit_p(pxa2xx_flash_remove),
  116. .shutdown = pxa2xx_flash_shutdown,
  117. };
  118. module_platform_driver(pxa2xx_flash_driver);
  119. MODULE_LICENSE("GPL");
  120. MODULE_AUTHOR("Nicolas Pitre <nico@fluxnic.net>");
  121. MODULE_DESCRIPTION("MTD map driver for Intel XScale PXA2xx");