h720x-flash.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. /*
  57. * Initialize FLASH support
  58. */
  59. static int __init h720x_mtd_init(void)
  60. {
  61. char *part_type = NULL;
  62. h720x_map.virt = ioremap(h720x_map.phys, h720x_map.size);
  63. if (!h720x_map.virt) {
  64. printk(KERN_ERR "H720x-MTD: ioremap failed\n");
  65. return -EIO;
  66. }
  67. simple_map_init(&h720x_map);
  68. // Probe for flash bankwidth 4
  69. printk (KERN_INFO "H720x-MTD probing 32bit FLASH\n");
  70. mymtd = do_map_probe("cfi_probe", &h720x_map);
  71. if (!mymtd) {
  72. printk (KERN_INFO "H720x-MTD probing 16bit FLASH\n");
  73. // Probe for bankwidth 2
  74. h720x_map.bankwidth = 2;
  75. mymtd = do_map_probe("cfi_probe", &h720x_map);
  76. }
  77. if (mymtd) {
  78. mymtd->owner = THIS_MODULE;
  79. nr_mtd_parts = parse_mtd_partitions(mymtd, NULL, &mtd_parts, 0);
  80. if (nr_mtd_parts > 0)
  81. part_type = "command line";
  82. if (nr_mtd_parts <= 0) {
  83. mtd_parts = h720x_partitions;
  84. nr_mtd_parts = NUM_PARTITIONS;
  85. part_type = "builtin";
  86. }
  87. printk(KERN_INFO "Using %s partition table\n", part_type);
  88. mtd_device_register(mymtd, mtd_parts, nr_mtd_parts);
  89. return 0;
  90. }
  91. iounmap((void *)h720x_map.virt);
  92. return -ENXIO;
  93. }
  94. /*
  95. * Cleanup
  96. */
  97. static void __exit h720x_mtd_cleanup(void)
  98. {
  99. if (mymtd) {
  100. mtd_device_unregister(mymtd);
  101. map_destroy(mymtd);
  102. }
  103. /* Free partition info, if commandline partition was used */
  104. if (mtd_parts && (mtd_parts != h720x_partitions))
  105. kfree (mtd_parts);
  106. if (h720x_map.virt) {
  107. iounmap((void *)h720x_map.virt);
  108. h720x_map.virt = 0;
  109. }
  110. }
  111. module_init(h720x_mtd_init);
  112. module_exit(h720x_mtd_cleanup);
  113. MODULE_LICENSE("GPL");
  114. MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
  115. MODULE_DESCRIPTION("MTD map driver for Hynix evaluation boards");