integrator-flash.c 5.0 KB

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