integrator-flash.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 = kmalloc(sizeof(struct armflash_info), GFP_KERNEL);
  61. if (!info) {
  62. err = -ENOMEM;
  63. goto out;
  64. }
  65. memset(info, 0, sizeof(struct armflash_info));
  66. info->plat = plat;
  67. if (plat && plat->init) {
  68. err = plat->init();
  69. if (err)
  70. goto no_resource;
  71. }
  72. info->res = request_mem_region(res->start, size, "armflash");
  73. if (!info->res) {
  74. err = -EBUSY;
  75. goto no_resource;
  76. }
  77. base = ioremap(res->start, size);
  78. if (!base) {
  79. err = -ENOMEM;
  80. goto no_mem;
  81. }
  82. /*
  83. * look for CFI based flash parts fitted to this board
  84. */
  85. info->map.size = size;
  86. info->map.bankwidth = plat->width;
  87. info->map.phys = res->start;
  88. info->map.virt = base;
  89. info->map.name = dev->dev.bus_id;
  90. info->map.set_vpp = armflash_set_vpp;
  91. simple_map_init(&info->map);
  92. /*
  93. * Also, the CFI layer automatically works out what size
  94. * of chips we have, and does the necessary identification
  95. * for us automatically.
  96. */
  97. info->mtd = do_map_probe(plat->map_name, &info->map);
  98. if (!info->mtd) {
  99. err = -ENXIO;
  100. goto no_device;
  101. }
  102. info->mtd->owner = THIS_MODULE;
  103. err = parse_mtd_partitions(info->mtd, probes, &info->parts, 0);
  104. if (err > 0) {
  105. err = add_mtd_partitions(info->mtd, info->parts, err);
  106. if (err)
  107. printk(KERN_ERR
  108. "mtd partition registration failed: %d\n", err);
  109. }
  110. if (err == 0)
  111. platform_set_drvdata(dev, info);
  112. /*
  113. * If we got an error, free all resources.
  114. */
  115. if (err < 0) {
  116. if (info->mtd) {
  117. del_mtd_partitions(info->mtd);
  118. map_destroy(info->mtd);
  119. }
  120. kfree(info->parts);
  121. no_device:
  122. iounmap(base);
  123. no_mem:
  124. release_mem_region(res->start, size);
  125. no_resource:
  126. if (plat && plat->exit)
  127. plat->exit();
  128. kfree(info);
  129. }
  130. out:
  131. return err;
  132. }
  133. static int armflash_remove(struct platform_device *dev)
  134. {
  135. struct armflash_info *info = platform_get_drvdata(dev);
  136. platform_set_drvdata(dev, NULL);
  137. if (info) {
  138. if (info->mtd) {
  139. del_mtd_partitions(info->mtd);
  140. map_destroy(info->mtd);
  141. }
  142. kfree(info->parts);
  143. iounmap(info->map.virt);
  144. release_resource(info->res);
  145. kfree(info->res);
  146. if (info->plat && info->plat->exit)
  147. info->plat->exit();
  148. kfree(info);
  149. }
  150. return 0;
  151. }
  152. static struct platform_driver armflash_driver = {
  153. .probe = armflash_probe,
  154. .remove = armflash_remove,
  155. .driver = {
  156. .name = "armflash",
  157. },
  158. };
  159. static int __init armflash_init(void)
  160. {
  161. return platform_driver_register(&armflash_driver);
  162. }
  163. static void __exit armflash_exit(void)
  164. {
  165. platform_driver_unregister(&armflash_driver);
  166. }
  167. module_init(armflash_init);
  168. module_exit(armflash_exit);
  169. MODULE_AUTHOR("ARM Ltd");
  170. MODULE_DESCRIPTION("ARM Integrator CFI map driver");
  171. MODULE_LICENSE("GPL");