pxa2xx-flash.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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/cacheflush.h>
  22. #include <asm/mach/flash.h>
  23. static void pxa2xx_map_inval_cache(struct map_info *map, unsigned long from,
  24. ssize_t len)
  25. {
  26. flush_ioremap_region(map->phys, map->cached, from, len);
  27. }
  28. struct pxa2xx_flash_info {
  29. struct mtd_partition *parts;
  30. int nr_parts;
  31. struct mtd_info *mtd;
  32. struct map_info map;
  33. };
  34. static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
  35. static int __init pxa2xx_flash_probe(struct platform_device *pdev)
  36. {
  37. struct flash_platform_data *flash = pdev->dev.platform_data;
  38. struct pxa2xx_flash_info *info;
  39. struct mtd_partition *parts;
  40. struct resource *res;
  41. int ret = 0;
  42. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  43. if (!res)
  44. return -ENODEV;
  45. info = kmalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL);
  46. if (!info)
  47. return -ENOMEM;
  48. memset(info, 0, sizeof(struct pxa2xx_flash_info));
  49. info->map.name = (char *) flash->name;
  50. info->map.bankwidth = flash->width;
  51. info->map.phys = res->start;
  52. info->map.size = res->end - res->start + 1;
  53. info->parts = flash->parts;
  54. info->nr_parts = flash->nr_parts;
  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 =
  62. ioremap_cached(info->map.phys, info->map.size);
  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->owner = THIS_MODULE;
  81. #ifdef CONFIG_MTD_PARTITIONS
  82. ret = parse_mtd_partitions(info->mtd, probes, &parts, 0);
  83. if (ret > 0) {
  84. info->nr_parts = ret;
  85. info->parts = parts;
  86. }
  87. #endif
  88. if (info->nr_parts) {
  89. add_mtd_partitions(info->mtd, info->parts,
  90. info->nr_parts);
  91. } else {
  92. printk("Registering %s as whole device\n",
  93. info->map.name);
  94. add_mtd_device(info->mtd);
  95. }
  96. platform_set_drvdata(pdev, info);
  97. return 0;
  98. }
  99. static int __devexit pxa2xx_flash_remove(struct platform_device *dev)
  100. {
  101. struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
  102. platform_set_drvdata(dev, NULL);
  103. #ifdef CONFIG_MTD_PARTITIONS
  104. if (info->nr_parts)
  105. del_mtd_partitions(info->mtd);
  106. else
  107. #endif
  108. del_mtd_device(info->mtd);
  109. map_destroy(info->mtd);
  110. iounmap(info->map.virt);
  111. if (info->map.cached)
  112. iounmap(info->map.cached);
  113. kfree(info->parts);
  114. kfree(info);
  115. return 0;
  116. }
  117. #ifdef CONFIG_PM
  118. static int pxa2xx_flash_suspend(struct platform_device *dev, pm_message_t state)
  119. {
  120. struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
  121. int ret = 0;
  122. if (info->mtd && info->mtd->suspend)
  123. ret = info->mtd->suspend(info->mtd);
  124. return ret;
  125. }
  126. static int pxa2xx_flash_resume(struct platform_device *dev)
  127. {
  128. struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
  129. if (info->mtd && info->mtd->resume)
  130. info->mtd->resume(info->mtd);
  131. return 0;
  132. }
  133. static void pxa2xx_flash_shutdown(struct platform_device *dev)
  134. {
  135. struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
  136. if (info && info->mtd->suspend(info->mtd) == 0)
  137. info->mtd->resume(info->mtd);
  138. }
  139. #else
  140. #define pxa2xx_flash_suspend NULL
  141. #define pxa2xx_flash_resume NULL
  142. #define pxa2xx_flash_shutdown NULL
  143. #endif
  144. static struct platform_driver pxa2xx_flash_driver = {
  145. .driver = {
  146. .name = "pxa2xx-flash",
  147. .owner = THIS_MODULE,
  148. },
  149. .probe = pxa2xx_flash_probe,
  150. .remove = __devexit_p(pxa2xx_flash_remove),
  151. .suspend = pxa2xx_flash_suspend,
  152. .resume = pxa2xx_flash_resume,
  153. .shutdown = pxa2xx_flash_shutdown,
  154. };
  155. static int __init init_pxa2xx_flash(void)
  156. {
  157. return platform_driver_register(&pxa2xx_flash_driver);
  158. }
  159. static void __exit cleanup_pxa2xx_flash(void)
  160. {
  161. platform_driver_unregister(&pxa2xx_flash_driver);
  162. }
  163. module_init(init_pxa2xx_flash);
  164. module_exit(cleanup_pxa2xx_flash);
  165. MODULE_LICENSE("GPL");
  166. MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
  167. MODULE_DESCRIPTION("MTD map driver for Intel XScale PXA2xx");