pxa2xx-flash.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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/kernel.h>
  14. #include <linux/init.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_partition *parts;
  37. int nr_parts;
  38. struct mtd_info *mtd;
  39. struct map_info map;
  40. };
  41. static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
  42. static int __init pxa2xx_flash_probe(struct platform_device *pdev)
  43. {
  44. struct flash_platform_data *flash = pdev->dev.platform_data;
  45. struct pxa2xx_flash_info *info;
  46. struct mtd_partition *parts;
  47. struct resource *res;
  48. int ret = 0;
  49. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  50. if (!res)
  51. return -ENODEV;
  52. info = kmalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL);
  53. if (!info)
  54. return -ENOMEM;
  55. memset(info, 0, sizeof(struct pxa2xx_flash_info));
  56. info->map.name = (char *) flash->name;
  57. info->map.bankwidth = flash->width;
  58. info->map.phys = res->start;
  59. info->map.size = res->end - res->start + 1;
  60. info->parts = flash->parts;
  61. info->nr_parts = flash->nr_parts;
  62. info->map.virt = ioremap(info->map.phys, info->map.size);
  63. if (!info->map.virt) {
  64. printk(KERN_WARNING "Failed to ioremap %s\n",
  65. info->map.name);
  66. return -ENOMEM;
  67. }
  68. info->map.cached =
  69. ioremap_cached(info->map.phys, info->map.size);
  70. if (!info->map.cached)
  71. printk(KERN_WARNING "Failed to ioremap cached %s\n",
  72. info->map.name);
  73. info->map.inval_cache = pxa2xx_map_inval_cache;
  74. simple_map_init(&info->map);
  75. printk(KERN_NOTICE
  76. "Probing %s at physical address 0x%08lx"
  77. " (%d-bit bankwidth)\n",
  78. info->map.name, (unsigned long)info->map.phys,
  79. info->map.bankwidth * 8);
  80. info->mtd = do_map_probe(flash->map_name, &info->map);
  81. if (!info->mtd) {
  82. iounmap((void *)info->map.virt);
  83. if (info->map.cached)
  84. iounmap(info->map.cached);
  85. return -EIO;
  86. }
  87. info->mtd->owner = THIS_MODULE;
  88. #ifdef CONFIG_MTD_PARTITIONS
  89. ret = parse_mtd_partitions(info->mtd, probes, &parts, 0);
  90. if (ret > 0) {
  91. info->nr_parts = ret;
  92. info->parts = parts;
  93. }
  94. #endif
  95. if (info->nr_parts) {
  96. add_mtd_partitions(info->mtd, info->parts,
  97. info->nr_parts);
  98. } else {
  99. printk("Registering %s as whole device\n",
  100. info->map.name);
  101. add_mtd_device(info->mtd);
  102. }
  103. platform_set_drvdata(pdev, info);
  104. return 0;
  105. }
  106. static int __devexit pxa2xx_flash_remove(struct platform_device *dev)
  107. {
  108. struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
  109. platform_set_drvdata(dev, NULL);
  110. #ifdef CONFIG_MTD_PARTITIONS
  111. if (info->nr_parts)
  112. del_mtd_partitions(info->mtd);
  113. else
  114. #endif
  115. del_mtd_device(info->mtd);
  116. map_destroy(info->mtd);
  117. iounmap(info->map.virt);
  118. if (info->map.cached)
  119. iounmap(info->map.cached);
  120. kfree(info->parts);
  121. kfree(info);
  122. return 0;
  123. }
  124. #ifdef CONFIG_PM
  125. static void pxa2xx_flash_shutdown(struct platform_device *dev)
  126. {
  127. struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
  128. if (info && info->mtd->suspend(info->mtd) == 0)
  129. info->mtd->resume(info->mtd);
  130. }
  131. #else
  132. #define pxa2xx_flash_shutdown NULL
  133. #endif
  134. static struct platform_driver pxa2xx_flash_driver = {
  135. .driver = {
  136. .name = "pxa2xx-flash",
  137. .owner = THIS_MODULE,
  138. },
  139. .probe = pxa2xx_flash_probe,
  140. .remove = __devexit_p(pxa2xx_flash_remove),
  141. .shutdown = pxa2xx_flash_shutdown,
  142. };
  143. static int __init init_pxa2xx_flash(void)
  144. {
  145. return platform_driver_register(&pxa2xx_flash_driver);
  146. }
  147. static void __exit cleanup_pxa2xx_flash(void)
  148. {
  149. platform_driver_unregister(&pxa2xx_flash_driver);
  150. }
  151. module_init(init_pxa2xx_flash);
  152. module_exit(cleanup_pxa2xx_flash);
  153. MODULE_LICENSE("GPL");
  154. MODULE_AUTHOR("Nicolas Pitre <nico@fluxnic.net>");
  155. MODULE_DESCRIPTION("MTD map driver for Intel XScale PXA2xx");