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. $Id: integrator-flash.c,v 1.20 2005/11/07 11:14:27 gleixner Exp $
  19. ======================================================================*/
  20. #include <linux/module.h>
  21. #include <linux/types.h>
  22. #include <linux/kernel.h>
  23. #include <linux/slab.h>
  24. #include <linux/ioport.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/init.h>
  27. #include <linux/mtd/mtd.h>
  28. #include <linux/mtd/map.h>
  29. #include <linux/mtd/partitions.h>
  30. #include <asm/mach/flash.h>
  31. #include <asm/hardware.h>
  32. #include <asm/io.h>
  33. #include <asm/system.h>
  34. #ifdef CONFIG_ARCH_P720T
  35. #define FLASH_BASE (0x04000000)
  36. #define FLASH_SIZE (64*1024*1024)
  37. #endif
  38. struct armflash_info {
  39. struct flash_platform_data *plat;
  40. struct resource *res;
  41. struct mtd_partition *parts;
  42. struct mtd_info *mtd;
  43. struct map_info map;
  44. };
  45. static void armflash_set_vpp(struct map_info *map, int on)
  46. {
  47. struct armflash_info *info = container_of(map, struct armflash_info, map);
  48. if (info->plat && info->plat->set_vpp)
  49. info->plat->set_vpp(on);
  50. }
  51. static const char *probes[] = { "cmdlinepart", "RedBoot", "afs", NULL };
  52. static int armflash_probe(struct platform_device *dev)
  53. {
  54. struct flash_platform_data *plat = dev->dev.platform_data;
  55. struct resource *res = dev->resource;
  56. unsigned int size = res->end - res->start + 1;
  57. struct armflash_info *info;
  58. int err;
  59. void __iomem *base;
  60. info = kzalloc(sizeof(struct armflash_info), GFP_KERNEL);
  61. if (!info) {
  62. err = -ENOMEM;
  63. goto out;
  64. }
  65. info->plat = plat;
  66. if (plat && plat->init) {
  67. err = plat->init();
  68. if (err)
  69. goto no_resource;
  70. }
  71. info->res = request_mem_region(res->start, size, "armflash");
  72. if (!info->res) {
  73. err = -EBUSY;
  74. goto no_resource;
  75. }
  76. base = ioremap(res->start, size);
  77. if (!base) {
  78. err = -ENOMEM;
  79. goto no_mem;
  80. }
  81. /*
  82. * look for CFI based flash parts fitted to this board
  83. */
  84. info->map.size = size;
  85. info->map.bankwidth = plat->width;
  86. info->map.phys = res->start;
  87. info->map.virt = base;
  88. info->map.name = dev->dev.bus_id;
  89. info->map.set_vpp = armflash_set_vpp;
  90. simple_map_init(&info->map);
  91. /*
  92. * Also, the CFI layer automatically works out what size
  93. * of chips we have, and does the necessary identification
  94. * for us automatically.
  95. */
  96. info->mtd = do_map_probe(plat->map_name, &info->map);
  97. if (!info->mtd) {
  98. err = -ENXIO;
  99. goto no_device;
  100. }
  101. info->mtd->owner = THIS_MODULE;
  102. err = parse_mtd_partitions(info->mtd, probes, &info->parts, 0);
  103. if (err > 0) {
  104. err = add_mtd_partitions(info->mtd, info->parts, err);
  105. if (err)
  106. printk(KERN_ERR
  107. "mtd partition registration failed: %d\n", err);
  108. }
  109. if (err == 0)
  110. platform_set_drvdata(dev, info);
  111. /*
  112. * If we got an error, free all resources.
  113. */
  114. if (err < 0) {
  115. if (info->mtd) {
  116. del_mtd_partitions(info->mtd);
  117. map_destroy(info->mtd);
  118. }
  119. kfree(info->parts);
  120. no_device:
  121. iounmap(base);
  122. no_mem:
  123. release_mem_region(res->start, size);
  124. no_resource:
  125. if (plat && plat->exit)
  126. plat->exit();
  127. kfree(info);
  128. }
  129. out:
  130. return err;
  131. }
  132. static int armflash_remove(struct platform_device *dev)
  133. {
  134. struct armflash_info *info = platform_get_drvdata(dev);
  135. platform_set_drvdata(dev, NULL);
  136. if (info) {
  137. if (info->mtd) {
  138. del_mtd_partitions(info->mtd);
  139. map_destroy(info->mtd);
  140. }
  141. kfree(info->parts);
  142. iounmap(info->map.virt);
  143. release_resource(info->res);
  144. kfree(info->res);
  145. if (info->plat && info->plat->exit)
  146. info->plat->exit();
  147. kfree(info);
  148. }
  149. return 0;
  150. }
  151. static struct platform_driver armflash_driver = {
  152. .probe = armflash_probe,
  153. .remove = armflash_remove,
  154. .driver = {
  155. .name = "armflash",
  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");