pxa2xx-flash.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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/platform_device.h>
  16. #include <linux/mtd/mtd.h>
  17. #include <linux/mtd/map.h>
  18. #include <linux/mtd/partitions.h>
  19. #include <asm/io.h>
  20. #include <mach/hardware.h>
  21. #include <asm/mach/flash.h>
  22. #define CACHELINESIZE 32
  23. static void pxa2xx_map_inval_cache(struct map_info *map, unsigned long from,
  24. ssize_t len)
  25. {
  26. unsigned long start = (unsigned long)map->cached + from;
  27. unsigned long end = start + len;
  28. start &= ~(CACHELINESIZE - 1);
  29. while (start < end) {
  30. /* invalidate D cache line */
  31. asm volatile ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
  32. start += CACHELINESIZE;
  33. }
  34. }
  35. struct pxa2xx_flash_info {
  36. struct mtd_info *mtd;
  37. struct map_info map;
  38. };
  39. static const char * const probes[] = { "RedBoot", "cmdlinepart", NULL };
  40. static int pxa2xx_flash_probe(struct platform_device *pdev)
  41. {
  42. struct flash_platform_data *flash = dev_get_platdata(&pdev->dev);
  43. struct pxa2xx_flash_info *info;
  44. struct resource *res;
  45. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  46. if (!res)
  47. return -ENODEV;
  48. info = kzalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL);
  49. if (!info)
  50. return -ENOMEM;
  51. info->map.name = flash->name;
  52. info->map.bankwidth = flash->width;
  53. info->map.phys = res->start;
  54. info->map.size = resource_size(res);
  55. info->map.virt = ioremap(info->map.phys, info->map.size);
  56. if (!info->map.virt) {
  57. printk(KERN_WARNING "Failed to ioremap %s\n",
  58. info->map.name);
  59. return -ENOMEM;
  60. }
  61. info->map.cached = memremap(info->map.phys, info->map.size,
  62. MEMREMAP_WB);
  63. if (!info->map.cached)
  64. printk(KERN_WARNING "Failed to ioremap cached %s\n",
  65. info->map.name);
  66. info->map.inval_cache = pxa2xx_map_inval_cache;
  67. simple_map_init(&info->map);
  68. printk(KERN_NOTICE
  69. "Probing %s at physical address 0x%08lx"
  70. " (%d-bit bankwidth)\n",
  71. info->map.name, (unsigned long)info->map.phys,
  72. info->map.bankwidth * 8);
  73. info->mtd = do_map_probe(flash->map_name, &info->map);
  74. if (!info->mtd) {
  75. iounmap((void *)info->map.virt);
  76. if (info->map.cached)
  77. iounmap(info->map.cached);
  78. return -EIO;
  79. }
  80. info->mtd->dev.parent = &pdev->dev;
  81. mtd_device_parse_register(info->mtd, probes, NULL, flash->parts,
  82. flash->nr_parts);
  83. platform_set_drvdata(pdev, info);
  84. return 0;
  85. }
  86. static int pxa2xx_flash_remove(struct platform_device *dev)
  87. {
  88. struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
  89. mtd_device_unregister(info->mtd);
  90. map_destroy(info->mtd);
  91. iounmap(info->map.virt);
  92. if (info->map.cached)
  93. memunmap(info->map.cached);
  94. kfree(info);
  95. return 0;
  96. }
  97. #ifdef CONFIG_PM
  98. static void pxa2xx_flash_shutdown(struct platform_device *dev)
  99. {
  100. struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
  101. if (info && mtd_suspend(info->mtd) == 0)
  102. mtd_resume(info->mtd);
  103. }
  104. #else
  105. #define pxa2xx_flash_shutdown NULL
  106. #endif
  107. static struct platform_driver pxa2xx_flash_driver = {
  108. .driver = {
  109. .name = "pxa2xx-flash",
  110. },
  111. .probe = pxa2xx_flash_probe,
  112. .remove = pxa2xx_flash_remove,
  113. .shutdown = pxa2xx_flash_shutdown,
  114. };
  115. module_platform_driver(pxa2xx_flash_driver);
  116. MODULE_LICENSE("GPL");
  117. MODULE_AUTHOR("Nicolas Pitre <nico@fluxnic.net>");
  118. MODULE_DESCRIPTION("MTD map driver for Intel XScale PXA2xx");