physmap.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * $Id: physmap.c,v 1.37 2004/11/28 09:40:40 dwmw2 Exp $
  3. *
  4. * Normal mappings of chips in physical memory
  5. *
  6. * Copyright (C) 2003 MontaVista Software Inc.
  7. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
  8. *
  9. * 031022 - [jsun] add run-time configure and partition setup
  10. */
  11. #include <linux/module.h>
  12. #include <linux/types.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/slab.h>
  16. #include <asm/io.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/map.h>
  19. #include <linux/config.h>
  20. #include <linux/mtd/partitions.h>
  21. static struct mtd_info *mymtd;
  22. struct map_info physmap_map = {
  23. .name = "phys_mapped_flash",
  24. .phys = CONFIG_MTD_PHYSMAP_START,
  25. .size = CONFIG_MTD_PHYSMAP_LEN,
  26. .bankwidth = CONFIG_MTD_PHYSMAP_BANKWIDTH,
  27. };
  28. #ifdef CONFIG_MTD_PARTITIONS
  29. static struct mtd_partition *mtd_parts;
  30. static int mtd_parts_nb;
  31. static int num_physmap_partitions;
  32. static struct mtd_partition *physmap_partitions;
  33. static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL};
  34. void physmap_set_partitions(struct mtd_partition *parts, int num_parts)
  35. {
  36. physmap_partitions=parts;
  37. num_physmap_partitions=num_parts;
  38. }
  39. #endif /* CONFIG_MTD_PARTITIONS */
  40. static int __init init_physmap(void)
  41. {
  42. static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
  43. const char **type;
  44. printk(KERN_NOTICE "physmap flash device: %lx at %lx\n", physmap_map.size, physmap_map.phys);
  45. physmap_map.virt = ioremap(physmap_map.phys, physmap_map.size);
  46. if (!physmap_map.virt) {
  47. printk("Failed to ioremap\n");
  48. return -EIO;
  49. }
  50. simple_map_init(&physmap_map);
  51. mymtd = NULL;
  52. type = rom_probe_types;
  53. for(; !mymtd && *type; type++) {
  54. mymtd = do_map_probe(*type, &physmap_map);
  55. }
  56. if (mymtd) {
  57. mymtd->owner = THIS_MODULE;
  58. #ifdef CONFIG_MTD_PARTITIONS
  59. mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes,
  60. &mtd_parts, 0);
  61. if (mtd_parts_nb > 0)
  62. {
  63. add_mtd_partitions (mymtd, mtd_parts, mtd_parts_nb);
  64. return 0;
  65. }
  66. if (num_physmap_partitions != 0)
  67. {
  68. printk(KERN_NOTICE
  69. "Using physmap partition definition\n");
  70. add_mtd_partitions (mymtd, physmap_partitions, num_physmap_partitions);
  71. return 0;
  72. }
  73. #endif
  74. add_mtd_device(mymtd);
  75. return 0;
  76. }
  77. iounmap(physmap_map.virt);
  78. return -ENXIO;
  79. }
  80. static void __exit cleanup_physmap(void)
  81. {
  82. #ifdef CONFIG_MTD_PARTITIONS
  83. if (mtd_parts_nb) {
  84. del_mtd_partitions(mymtd);
  85. kfree(mtd_parts);
  86. } else if (num_physmap_partitions) {
  87. del_mtd_partitions(mymtd);
  88. } else {
  89. del_mtd_device(mymtd);
  90. }
  91. #else
  92. del_mtd_device(mymtd);
  93. #endif
  94. map_destroy(mymtd);
  95. iounmap(physmap_map.virt);
  96. physmap_map.virt = NULL;
  97. }
  98. module_init(init_physmap);
  99. module_exit(cleanup_physmap);
  100. MODULE_LICENSE("GPL");
  101. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  102. MODULE_DESCRIPTION("Generic configurable MTD map driver");