omap_nor.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Flash memory support for various TI OMAP boards
  3. *
  4. * Copyright (C) 2001-2002 MontaVista Software Inc.
  5. * Copyright (C) 2003-2004 Texas Instruments
  6. * Copyright (C) 2004 Nokia Corporation
  7. *
  8. * Assembled using driver code copyright the companies above
  9. * and written by David Brownell, Jian Zhang <jzhang@ti.com>,
  10. * Tony Lindgren <tony@atomide.com> and others.
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. *
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  20. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  23. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  24. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * You should have received a copy of the GNU General Public License along
  29. * with this program; if not, write to the Free Software Foundation, Inc.,
  30. * 675 Mass Ave, Cambridge, MA 02139, USA.
  31. */
  32. #include <linux/platform_device.h>
  33. #include <linux/module.h>
  34. #include <linux/types.h>
  35. #include <linux/kernel.h>
  36. #include <linux/init.h>
  37. #include <linux/ioport.h>
  38. #include <linux/slab.h>
  39. #include <linux/mtd/mtd.h>
  40. #include <linux/mtd/map.h>
  41. #include <linux/mtd/partitions.h>
  42. #include <asm/io.h>
  43. #include <mach/hardware.h>
  44. #include <asm/mach/flash.h>
  45. #include <mach/tc.h>
  46. #ifdef CONFIG_MTD_PARTITIONS
  47. static const char *part_probes[] = { /* "RedBoot", */ "cmdlinepart", NULL };
  48. #endif
  49. struct omapflash_info {
  50. struct mtd_partition *parts;
  51. struct mtd_info *mtd;
  52. struct map_info map;
  53. };
  54. static void omap_set_vpp(struct map_info *map, int enable)
  55. {
  56. static int count;
  57. u32 l;
  58. if (cpu_class_is_omap1()) {
  59. if (enable) {
  60. if (count++ == 0) {
  61. l = omap_readl(EMIFS_CONFIG);
  62. l |= OMAP_EMIFS_CONFIG_WP;
  63. omap_writel(l, EMIFS_CONFIG);
  64. }
  65. } else {
  66. if (count && (--count == 0)) {
  67. l = omap_readl(EMIFS_CONFIG);
  68. l &= ~OMAP_EMIFS_CONFIG_WP;
  69. omap_writel(l, EMIFS_CONFIG);
  70. }
  71. }
  72. }
  73. }
  74. static int __init omapflash_probe(struct platform_device *pdev)
  75. {
  76. int err;
  77. struct omapflash_info *info;
  78. struct flash_platform_data *pdata = pdev->dev.platform_data;
  79. struct resource *res = pdev->resource;
  80. unsigned long size = res->end - res->start + 1;
  81. info = kzalloc(sizeof(struct omapflash_info), GFP_KERNEL);
  82. if (!info)
  83. return -ENOMEM;
  84. if (!request_mem_region(res->start, size, "flash")) {
  85. err = -EBUSY;
  86. goto out_free_info;
  87. }
  88. info->map.virt = ioremap(res->start, size);
  89. if (!info->map.virt) {
  90. err = -ENOMEM;
  91. goto out_release_mem_region;
  92. }
  93. info->map.name = pdev->dev.bus_id;
  94. info->map.phys = res->start;
  95. info->map.size = size;
  96. info->map.bankwidth = pdata->width;
  97. info->map.set_vpp = omap_set_vpp;
  98. simple_map_init(&info->map);
  99. info->mtd = do_map_probe(pdata->map_name, &info->map);
  100. if (!info->mtd) {
  101. err = -EIO;
  102. goto out_iounmap;
  103. }
  104. info->mtd->owner = THIS_MODULE;
  105. #ifdef CONFIG_MTD_PARTITIONS
  106. err = parse_mtd_partitions(info->mtd, part_probes, &info->parts, 0);
  107. if (err > 0)
  108. add_mtd_partitions(info->mtd, info->parts, err);
  109. else if (err <= 0 && pdata->parts)
  110. add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts);
  111. else
  112. #endif
  113. add_mtd_device(info->mtd);
  114. platform_set_drvdata(pdev, info);
  115. return 0;
  116. out_iounmap:
  117. iounmap(info->map.virt);
  118. out_release_mem_region:
  119. release_mem_region(res->start, size);
  120. out_free_info:
  121. kfree(info);
  122. return err;
  123. }
  124. static int __exit omapflash_remove(struct platform_device *pdev)
  125. {
  126. struct omapflash_info *info = platform_get_drvdata(pdev);
  127. platform_set_drvdata(pdev, NULL);
  128. if (info) {
  129. if (info->parts) {
  130. del_mtd_partitions(info->mtd);
  131. kfree(info->parts);
  132. } else
  133. del_mtd_device(info->mtd);
  134. map_destroy(info->mtd);
  135. release_mem_region(info->map.phys, info->map.size);
  136. iounmap((void __iomem *) info->map.virt);
  137. kfree(info);
  138. }
  139. return 0;
  140. }
  141. static struct platform_driver omapflash_driver = {
  142. .remove = __exit_p(omapflash_remove),
  143. .driver = {
  144. .name = "omapflash",
  145. .owner = THIS_MODULE,
  146. },
  147. };
  148. static int __init omapflash_init(void)
  149. {
  150. return platform_driver_probe(&omapflash_driver, omapflash_probe);
  151. }
  152. static void __exit omapflash_exit(void)
  153. {
  154. platform_driver_unregister(&omapflash_driver);
  155. }
  156. module_init(omapflash_init);
  157. module_exit(omapflash_exit);
  158. MODULE_LICENSE("GPL");
  159. MODULE_DESCRIPTION("MTD NOR map driver for TI OMAP boards");
  160. MODULE_ALIAS("platform:omapflash");