dbox2-flash.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * D-Box 2 flash driver
  3. */
  4. #include <linux/module.h>
  5. #include <linux/types.h>
  6. #include <linux/kernel.h>
  7. #include <linux/init.h>
  8. #include <asm/io.h>
  9. #include <linux/mtd/mtd.h>
  10. #include <linux/mtd/map.h>
  11. #include <linux/mtd/partitions.h>
  12. #include <linux/errno.h>
  13. /* partition_info gives details on the logical partitions that the split the
  14. * single flash device into. If the size if zero we use up to the end of the
  15. * device. */
  16. static struct mtd_partition partition_info[]= {
  17. {
  18. .name = "BR bootloader",
  19. .size = 128 * 1024,
  20. .offset = 0,
  21. .mask_flags = MTD_WRITEABLE
  22. },
  23. {
  24. .name = "FLFS (U-Boot)",
  25. .size = 128 * 1024,
  26. .offset = MTDPART_OFS_APPEND,
  27. .mask_flags = 0
  28. },
  29. {
  30. .name = "Root (SquashFS)",
  31. .size = 7040 * 1024,
  32. .offset = MTDPART_OFS_APPEND,
  33. .mask_flags = 0
  34. },
  35. {
  36. .name = "var (JFFS2)",
  37. .size = 896 * 1024,
  38. .offset = MTDPART_OFS_APPEND,
  39. .mask_flags = 0
  40. },
  41. {
  42. .name = "Flash without bootloader",
  43. .size = MTDPART_SIZ_FULL,
  44. .offset = 128 * 1024,
  45. .mask_flags = 0
  46. },
  47. {
  48. .name = "Complete Flash",
  49. .size = MTDPART_SIZ_FULL,
  50. .offset = 0,
  51. .mask_flags = MTD_WRITEABLE
  52. }
  53. };
  54. #define NUM_PARTITIONS ARRAY_SIZE(partition_info)
  55. #define WINDOW_ADDR 0x10000000
  56. #define WINDOW_SIZE 0x800000
  57. static struct mtd_info *mymtd;
  58. struct map_info dbox2_flash_map = {
  59. .name = "D-Box 2 flash memory",
  60. .size = WINDOW_SIZE,
  61. .bankwidth = 4,
  62. .phys = WINDOW_ADDR,
  63. };
  64. static int __init init_dbox2_flash(void)
  65. {
  66. printk(KERN_NOTICE "D-Box 2 flash driver (size->0x%X mem->0x%X)\n", WINDOW_SIZE, WINDOW_ADDR);
  67. dbox2_flash_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
  68. if (!dbox2_flash_map.virt) {
  69. printk("Failed to ioremap\n");
  70. return -EIO;
  71. }
  72. simple_map_init(&dbox2_flash_map);
  73. // Probe for dual Intel 28F320 or dual AMD
  74. mymtd = do_map_probe("cfi_probe", &dbox2_flash_map);
  75. if (!mymtd) {
  76. // Probe for single Intel 28F640
  77. dbox2_flash_map.bankwidth = 2;
  78. mymtd = do_map_probe("cfi_probe", &dbox2_flash_map);
  79. }
  80. if (mymtd) {
  81. mymtd->owner = THIS_MODULE;
  82. /* Create MTD devices for each partition. */
  83. mtd_device_register(mymtd, partition_info, NUM_PARTITIONS);
  84. return 0;
  85. }
  86. iounmap((void *)dbox2_flash_map.virt);
  87. return -ENXIO;
  88. }
  89. static void __exit cleanup_dbox2_flash(void)
  90. {
  91. if (mymtd) {
  92. mtd_device_unregister(mymtd);
  93. map_destroy(mymtd);
  94. }
  95. if (dbox2_flash_map.virt) {
  96. iounmap((void *)dbox2_flash_map.virt);
  97. dbox2_flash_map.virt = 0;
  98. }
  99. }
  100. module_init(init_dbox2_flash);
  101. module_exit(cleanup_dbox2_flash);
  102. MODULE_LICENSE("GPL");
  103. MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>, Bastian Blank <waldi@tuxbox.org>, Alexander Wild <wild@te-elektronik.com>");
  104. MODULE_DESCRIPTION("MTD map driver for D-Box 2 board");