integrator-flash.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*======================================================================
  2. drivers/mtd/maps/integrator-flash.c: ARM Integrator flash map driver
  3. Copyright (C) 2000 ARM Limited
  4. Copyright (C) 2003 Deep Blue Solutions Ltd.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. This is access code for flashes using ARM's flash partitioning
  17. standards.
  18. ======================================================================*/
  19. #include <linux/module.h>
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/slab.h>
  23. #include <linux/ioport.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/init.h>
  26. #include <linux/mtd/mtd.h>
  27. #include <linux/mtd/map.h>
  28. #include <linux/mtd/partitions.h>
  29. #include <asm/mach/flash.h>
  30. #include <mach/hardware.h>
  31. #include <asm/io.h>
  32. #include <asm/system.h>
  33. #ifdef CONFIG_ARCH_P720T
  34. #define FLASH_BASE (0x04000000)
  35. #define FLASH_SIZE (64*1024*1024)
  36. #endif
  37. struct armflash_info {
  38. struct flash_platform_data *plat;
  39. struct resource *res;
  40. struct mtd_partition *parts;
  41. struct mtd_info *mtd;
  42. struct map_info map;
  43. };
  44. static void armflash_set_vpp(struct map_info *map, int on)
  45. {
  46. struct armflash_info *info = container_of(map, struct armflash_info, map);
  47. if (info->plat && info->plat->set_vpp)
  48. info->plat->set_vpp(on);
  49. }
  50. static const char *probes[] = { "cmdlinepart", "RedBoot", "afs", NULL };
  51. static int armflash_probe(struct platform_device *dev)
  52. {
  53. struct flash_platform_data *plat = dev->dev.platform_data;
  54. struct resource *res = dev->resource;
  55. unsigned int size = res->end - res->start + 1;
  56. struct armflash_info *info;
  57. int err;
  58. void __iomem *base;
  59. info = kzalloc(sizeof(struct armflash_info), GFP_KERNEL);
  60. if (!info) {
  61. err = -ENOMEM;
  62. goto out;
  63. }
  64. info->plat = plat;
  65. if (plat && plat->init) {
  66. err = plat->init();
  67. if (err)
  68. goto no_resource;
  69. }
  70. info->res = request_mem_region(res->start, size, "armflash");
  71. if (!info->res) {
  72. err = -EBUSY;
  73. goto no_resource;
  74. }
  75. base = ioremap(res->start, size);
  76. if (!base) {
  77. err = -ENOMEM;
  78. goto no_mem;
  79. }
  80. /*
  81. * look for CFI based flash parts fitted to this board
  82. */
  83. info->map.size = size;
  84. info->map.bankwidth = plat->width;
  85. info->map.phys = res->start;
  86. info->map.virt = base;
  87. info->map.name = dev->dev.bus_id;
  88. info->map.set_vpp = armflash_set_vpp;
  89. simple_map_init(&info->map);
  90. /*
  91. * Also, the CFI layer automatically works out what size
  92. * of chips we have, and does the necessary identification
  93. * for us automatically.
  94. */
  95. info->mtd = do_map_probe(plat->map_name, &info->map);
  96. if (!info->mtd) {
  97. err = -ENXIO;
  98. goto no_device;
  99. }
  100. info->mtd->owner = THIS_MODULE;
  101. err = parse_mtd_partitions(info->mtd, probes, &info->parts, 0);
  102. if (err > 0) {
  103. err = add_mtd_partitions(info->mtd, info->parts, err);
  104. if (err)
  105. printk(KERN_ERR
  106. "mtd partition registration failed: %d\n", err);
  107. }
  108. if (err == 0)
  109. platform_set_drvdata(dev, info);
  110. /*
  111. * If we got an error, free all resources.
  112. */
  113. if (err < 0) {
  114. if (info->mtd) {
  115. del_mtd_partitions(info->mtd);
  116. map_destroy(info->mtd);
  117. }
  118. kfree(info->parts);
  119. no_device:
  120. iounmap(base);
  121. no_mem:
  122. release_mem_region(res->start, size);
  123. no_resource:
  124. if (plat && plat->exit)
  125. plat->exit();
  126. kfree(info);
  127. }
  128. out:
  129. return err;
  130. }
  131. static int armflash_remove(struct platform_device *dev)
  132. {
  133. struct armflash_info *info = platform_get_drvdata(dev);
  134. platform_set_drvdata(dev, NULL);
  135. if (info) {
  136. if (info->mtd) {
  137. del_mtd_partitions(info->mtd);
  138. map_destroy(info->mtd);
  139. }
  140. kfree(info->parts);
  141. iounmap(info->map.virt);
  142. release_resource(info->res);
  143. kfree(info->res);
  144. if (info->plat && info->plat->exit)
  145. info->plat->exit();
  146. kfree(info);
  147. }
  148. return 0;
  149. }
  150. static struct platform_driver armflash_driver = {
  151. .probe = armflash_probe,
  152. .remove = armflash_remove,
  153. .driver = {
  154. .name = "armflash",
  155. .owner = THIS_MODULE,
  156. },
  157. };
  158. static int __init armflash_init(void)
  159. {
  160. return platform_driver_register(&armflash_driver);
  161. }
  162. static void __exit armflash_exit(void)
  163. {
  164. platform_driver_unregister(&armflash_driver);
  165. }
  166. module_init(armflash_init);
  167. module_exit(armflash_exit);
  168. MODULE_AUTHOR("ARM Ltd");
  169. MODULE_DESCRIPTION("ARM Integrator CFI map driver");
  170. MODULE_LICENSE("GPL");
  171. MODULE_ALIAS("platform:armflash");