pxa2xx-flash.c 4.5 KB

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