pxa2xx-flash.c 3.4 KB

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