h720x-flash.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Flash memory access on Hynix GMS30C7201/HMS30C7202 based
  3. * evaluation boards
  4. *
  5. * (C) 2002 Jungjun Kim <jungjun.kim@hynix.com>
  6. * 2003 Thomas Gleixner <tglx@linutronix.de>
  7. */
  8. #include <linux/module.h>
  9. #include <linux/types.h>
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/errno.h>
  13. #include <linux/slab.h>
  14. #include <linux/mtd/mtd.h>
  15. #include <linux/mtd/map.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <mach/hardware.h>
  18. #include <asm/io.h>
  19. static struct mtd_info *mymtd;
  20. static struct map_info h720x_map = {
  21. .name = "H720X",
  22. .bankwidth = 4,
  23. .size = FLASH_SIZE,
  24. .phys = FLASH_PHYS,
  25. };
  26. static struct mtd_partition h720x_partitions[] = {
  27. {
  28. .name = "ArMon",
  29. .size = 0x00080000,
  30. .offset = 0,
  31. .mask_flags = MTD_WRITEABLE
  32. },{
  33. .name = "Env",
  34. .size = 0x00040000,
  35. .offset = 0x00080000,
  36. .mask_flags = MTD_WRITEABLE
  37. },{
  38. .name = "Kernel",
  39. .size = 0x00180000,
  40. .offset = 0x000c0000,
  41. .mask_flags = MTD_WRITEABLE
  42. },{
  43. .name = "Ramdisk",
  44. .size = 0x00400000,
  45. .offset = 0x00240000,
  46. .mask_flags = MTD_WRITEABLE
  47. },{
  48. .name = "jffs2",
  49. .size = MTDPART_SIZ_FULL,
  50. .offset = MTDPART_OFS_APPEND
  51. }
  52. };
  53. #define NUM_PARTITIONS ARRAY_SIZE(h720x_partitions)
  54. static int nr_mtd_parts;
  55. static struct mtd_partition *mtd_parts;
  56. static const char *probes[] = { "cmdlinepart", NULL };
  57. /*
  58. * Initialize FLASH support
  59. */
  60. int __init h720x_mtd_init(void)
  61. {
  62. char *part_type = NULL;
  63. h720x_map.virt = ioremap(FLASH_PHYS, FLASH_SIZE);
  64. if (!h720x_map.virt) {
  65. printk(KERN_ERR "H720x-MTD: ioremap failed\n");
  66. return -EIO;
  67. }
  68. simple_map_init(&h720x_map);
  69. // Probe for flash bankwidth 4
  70. printk (KERN_INFO "H720x-MTD probing 32bit FLASH\n");
  71. mymtd = do_map_probe("cfi_probe", &h720x_map);
  72. if (!mymtd) {
  73. printk (KERN_INFO "H720x-MTD probing 16bit FLASH\n");
  74. // Probe for bankwidth 2
  75. h720x_map.bankwidth = 2;
  76. mymtd = do_map_probe("cfi_probe", &h720x_map);
  77. }
  78. if (mymtd) {
  79. mymtd->owner = THIS_MODULE;
  80. #ifdef CONFIG_MTD_PARTITIONS
  81. nr_mtd_parts = parse_mtd_partitions(mymtd, probes, &mtd_parts, 0);
  82. if (nr_mtd_parts > 0)
  83. part_type = "command line";
  84. #endif
  85. if (nr_mtd_parts <= 0) {
  86. mtd_parts = h720x_partitions;
  87. nr_mtd_parts = NUM_PARTITIONS;
  88. part_type = "builtin";
  89. }
  90. printk(KERN_INFO "Using %s partition table\n", part_type);
  91. add_mtd_partitions(mymtd, mtd_parts, nr_mtd_parts);
  92. return 0;
  93. }
  94. iounmap((void *)h720x_map.virt);
  95. return -ENXIO;
  96. }
  97. /*
  98. * Cleanup
  99. */
  100. static void __exit h720x_mtd_cleanup(void)
  101. {
  102. if (mymtd) {
  103. del_mtd_partitions(mymtd);
  104. map_destroy(mymtd);
  105. }
  106. /* Free partition info, if commandline partition was used */
  107. if (mtd_parts && (mtd_parts != h720x_partitions))
  108. kfree (mtd_parts);
  109. if (h720x_map.virt) {
  110. iounmap((void *)h720x_map.virt);
  111. h720x_map.virt = 0;
  112. }
  113. }
  114. module_init(h720x_mtd_init);
  115. module_exit(h720x_mtd_cleanup);
  116. MODULE_LICENSE("GPL");
  117. MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
  118. MODULE_DESCRIPTION("MTD map driver for Hynix evaluation boards");