pxa2xx-flash.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 device *dev)
  36. {
  37. struct platform_device *pdev = to_platform_device(dev);
  38. struct flash_platform_data *flash = pdev->dev.platform_data;
  39. struct pxa2xx_flash_info *info;
  40. struct mtd_partition *parts;
  41. struct resource *res;
  42. int ret = 0;
  43. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  44. if (!res)
  45. return -ENODEV;
  46. info = kmalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL);
  47. if (!info)
  48. return -ENOMEM;
  49. memset(info, 0, sizeof(struct pxa2xx_flash_info));
  50. info->map.name = (char *) flash->name;
  51. info->map.bankwidth = flash->width;
  52. info->map.phys = res->start;
  53. info->map.size = res->end - res->start + 1;
  54. info->parts = flash->parts;
  55. info->nr_parts = flash->nr_parts;
  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. #ifdef CONFIG_MTD_PARTITIONS
  83. ret = parse_mtd_partitions(info->mtd, probes, &parts, 0);
  84. if (ret > 0) {
  85. info->nr_parts = ret;
  86. info->parts = parts;
  87. }
  88. #endif
  89. if (info->nr_parts) {
  90. add_mtd_partitions(info->mtd, info->parts,
  91. info->nr_parts);
  92. } else {
  93. printk("Registering %s as whole device\n",
  94. info->map.name);
  95. add_mtd_device(info->mtd);
  96. }
  97. dev_set_drvdata(dev, info);
  98. return 0;
  99. }
  100. static int __exit pxa2xx_flash_remove(struct device *dev)
  101. {
  102. struct pxa2xx_flash_info *info = dev_get_drvdata(dev);
  103. dev_set_drvdata(dev, NULL);
  104. #ifdef CONFIG_MTD_PARTITIONS
  105. if (info->nr_parts)
  106. del_mtd_partitions(info->mtd);
  107. else
  108. #endif
  109. del_mtd_device(info->mtd);
  110. map_destroy(info->mtd);
  111. iounmap(info->map.virt);
  112. if (info->map.cached)
  113. iounmap(info->map.cached);
  114. kfree(info->parts);
  115. kfree(info);
  116. return 0;
  117. }
  118. #ifdef CONFIG_PM
  119. static int pxa2xx_flash_suspend(struct device *dev, pm_message_t state)
  120. {
  121. struct pxa2xx_flash_info *info = dev_get_drvdata(dev);
  122. int ret = 0;
  123. if (info->mtd && info->mtd->suspend)
  124. ret = info->mtd->suspend(info->mtd);
  125. return ret;
  126. }
  127. static int pxa2xx_flash_resume(struct device *dev)
  128. {
  129. struct pxa2xx_flash_info *info = dev_get_drvdata(dev);
  130. if (info->mtd && info->mtd->resume)
  131. info->mtd->resume(info->mtd);
  132. return 0;
  133. }
  134. static void pxa2xx_flash_shutdown(struct device *dev)
  135. {
  136. struct pxa2xx_flash_info *info = dev_get_drvdata(dev);
  137. if (info && info->mtd->suspend(info->mtd) == 0)
  138. info->mtd->resume(info->mtd);
  139. }
  140. #else
  141. #define pxa2xx_flash_suspend NULL
  142. #define pxa2xx_flash_resume NULL
  143. #define pxa2xx_flash_shutdown NULL
  144. #endif
  145. static struct device_driver pxa2xx_flash_driver = {
  146. .name = "pxa2xx-flash",
  147. .bus = &platform_bus_type,
  148. .probe = pxa2xx_flash_probe,
  149. .remove = __exit_p(pxa2xx_flash_remove),
  150. .suspend = pxa2xx_flash_suspend,
  151. .resume = pxa2xx_flash_resume,
  152. .shutdown = pxa2xx_flash_shutdown,
  153. };
  154. static int __init init_pxa2xx_flash(void)
  155. {
  156. return driver_register(&pxa2xx_flash_driver);
  157. }
  158. static void __exit cleanup_pxa2xx_flash(void)
  159. {
  160. driver_unregister(&pxa2xx_flash_driver);
  161. }
  162. module_init(init_pxa2xx_flash);
  163. module_exit(cleanup_pxa2xx_flash);
  164. MODULE_LICENSE("GPL");
  165. MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
  166. MODULE_DESCRIPTION("MTD map driver for Intel XScale PXA2xx");