h720x-flash.c 3.3 KB

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