integrator-flash.c 4.9 KB

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