physmap.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * $Id: physmap.c,v 1.39 2005/11/29 14:49:36 gleixner 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. #include <linux/mtd/physmap.h>
  22. static struct mtd_info *mymtd;
  23. struct map_info physmap_map = {
  24. .name = "phys_mapped_flash",
  25. .phys = CONFIG_MTD_PHYSMAP_START,
  26. .size = CONFIG_MTD_PHYSMAP_LEN,
  27. .bankwidth = CONFIG_MTD_PHYSMAP_BANKWIDTH,
  28. };
  29. #ifdef CONFIG_MTD_PARTITIONS
  30. static struct mtd_partition *mtd_parts;
  31. static int mtd_parts_nb;
  32. static int num_physmap_partitions;
  33. static struct mtd_partition *physmap_partitions;
  34. static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL};
  35. void physmap_set_partitions(struct mtd_partition *parts, int num_parts)
  36. {
  37. physmap_partitions=parts;
  38. num_physmap_partitions=num_parts;
  39. }
  40. #endif /* CONFIG_MTD_PARTITIONS */
  41. static int __init init_physmap(void)
  42. {
  43. static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
  44. const char **type;
  45. printk(KERN_NOTICE "physmap flash device: %lx at %lx\n", physmap_map.size, physmap_map.phys);
  46. physmap_map.virt = ioremap(physmap_map.phys, physmap_map.size);
  47. if (!physmap_map.virt) {
  48. printk("Failed to ioremap\n");
  49. return -EIO;
  50. }
  51. simple_map_init(&physmap_map);
  52. mymtd = NULL;
  53. type = rom_probe_types;
  54. for(; !mymtd && *type; type++) {
  55. mymtd = do_map_probe(*type, &physmap_map);
  56. }
  57. if (mymtd) {
  58. mymtd->owner = THIS_MODULE;
  59. #ifdef CONFIG_MTD_PARTITIONS
  60. mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes,
  61. &mtd_parts, 0);
  62. if (mtd_parts_nb > 0)
  63. {
  64. add_mtd_partitions (mymtd, mtd_parts, mtd_parts_nb);
  65. return 0;
  66. }
  67. if (num_physmap_partitions != 0)
  68. {
  69. printk(KERN_NOTICE
  70. "Using physmap partition definition\n");
  71. add_mtd_partitions (mymtd, physmap_partitions, num_physmap_partitions);
  72. return 0;
  73. }
  74. #endif
  75. add_mtd_device(mymtd);
  76. return 0;
  77. }
  78. iounmap(physmap_map.virt);
  79. return -ENXIO;
  80. }
  81. static void __exit cleanup_physmap(void)
  82. {
  83. #ifdef CONFIG_MTD_PARTITIONS
  84. if (mtd_parts_nb) {
  85. del_mtd_partitions(mymtd);
  86. kfree(mtd_parts);
  87. } else if (num_physmap_partitions) {
  88. del_mtd_partitions(mymtd);
  89. } else {
  90. del_mtd_device(mymtd);
  91. }
  92. #else
  93. del_mtd_device(mymtd);
  94. #endif
  95. map_destroy(mymtd);
  96. iounmap(physmap_map.virt);
  97. physmap_map.virt = NULL;
  98. }
  99. module_init(init_physmap);
  100. module_exit(cleanup_physmap);
  101. MODULE_LICENSE("GPL");
  102. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  103. MODULE_DESCRIPTION("Generic configurable MTD map driver");