h720x-flash.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 = H720X_FLASH_SIZE,
  24. .phys = H720X_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. static int __init h720x_mtd_init(void)
  61. {
  62. char *part_type = NULL;
  63. h720x_map.virt = ioremap(h720x_map.phys, h720x_map.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. nr_mtd_parts = parse_mtd_partitions(mymtd, probes, &mtd_parts, 0);
  81. if (nr_mtd_parts > 0)
  82. part_type = "command line";
  83. if (nr_mtd_parts <= 0) {
  84. mtd_parts = h720x_partitions;
  85. nr_mtd_parts = NUM_PARTITIONS;
  86. part_type = "builtin";
  87. }
  88. printk(KERN_INFO "Using %s partition table\n", part_type);
  89. mtd_device_register(mymtd, mtd_parts, nr_mtd_parts);
  90. return 0;
  91. }
  92. iounmap((void *)h720x_map.virt);
  93. return -ENXIO;
  94. }
  95. /*
  96. * Cleanup
  97. */
  98. static void __exit h720x_mtd_cleanup(void)
  99. {
  100. if (mymtd) {
  101. mtd_device_unregister(mymtd);
  102. map_destroy(mymtd);
  103. }
  104. /* Free partition info, if commandline partition was used */
  105. if (mtd_parts && (mtd_parts != h720x_partitions))
  106. kfree (mtd_parts);
  107. if (h720x_map.virt) {
  108. iounmap((void *)h720x_map.virt);
  109. h720x_map.virt = 0;
  110. }
  111. }
  112. module_init(h720x_mtd_init);
  113. module_exit(h720x_mtd_cleanup);
  114. MODULE_LICENSE("GPL");
  115. MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
  116. MODULE_DESCRIPTION("MTD map driver for Hynix evaluation boards");