h720x-flash.c 3.3 KB

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