walnut.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Mapping for Walnut flash
  3. * (used ebony.c as a "framework")
  4. *
  5. * Heikki Lindholm <holindho@infradead.org>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/map.h>
  19. #include <linux/mtd/partitions.h>
  20. #include <asm/io.h>
  21. #include <asm/ibm4xx.h>
  22. #include <platforms/4xx/walnut.h>
  23. /* these should be in platforms/4xx/walnut.h ? */
  24. #define WALNUT_FLASH_ONBD_N(x) (x & 0x02)
  25. #define WALNUT_FLASH_SRAM_SEL(x) (x & 0x01)
  26. #define WALNUT_FLASH_LOW 0xFFF00000
  27. #define WALNUT_FLASH_HIGH 0xFFF80000
  28. #define WALNUT_FLASH_SIZE 0x80000
  29. static struct mtd_info *flash;
  30. static struct map_info walnut_map = {
  31. .name = "Walnut flash",
  32. .size = WALNUT_FLASH_SIZE,
  33. .bankwidth = 1,
  34. };
  35. /* Actually, OpenBIOS is the last 128 KiB of the flash - better
  36. * partitioning could be made */
  37. static struct mtd_partition walnut_partitions[] = {
  38. {
  39. .name = "OpenBIOS",
  40. .offset = 0x0,
  41. .size = WALNUT_FLASH_SIZE,
  42. /*.mask_flags = MTD_WRITEABLE, */ /* force read-only */
  43. }
  44. };
  45. int __init init_walnut(void)
  46. {
  47. u8 fpga_brds1;
  48. void *fpga_brds1_adr;
  49. void *fpga_status_adr;
  50. unsigned long flash_base;
  51. /* this should already be mapped (platform/4xx/walnut.c) */
  52. fpga_status_adr = ioremap(WALNUT_FPGA_BASE, 8);
  53. if (!fpga_status_adr)
  54. return -ENOMEM;
  55. fpga_brds1_adr = fpga_status_adr+5;
  56. fpga_brds1 = readb(fpga_brds1_adr);
  57. /* iounmap(fpga_status_adr); */
  58. if (WALNUT_FLASH_ONBD_N(fpga_brds1)) {
  59. printk("The on-board flash is disabled (U79 sw 5)!");
  60. iounmap(fpga_status_adr);
  61. return -EIO;
  62. }
  63. if (WALNUT_FLASH_SRAM_SEL(fpga_brds1))
  64. flash_base = WALNUT_FLASH_LOW;
  65. else
  66. flash_base = WALNUT_FLASH_HIGH;
  67. walnut_map.phys = flash_base;
  68. walnut_map.virt =
  69. (void __iomem *)ioremap(flash_base, walnut_map.size);
  70. if (!walnut_map.virt) {
  71. printk("Failed to ioremap flash.\n");
  72. iounmap(fpga_status_adr);
  73. return -EIO;
  74. }
  75. simple_map_init(&walnut_map);
  76. flash = do_map_probe("jedec_probe", &walnut_map);
  77. if (flash) {
  78. flash->owner = THIS_MODULE;
  79. add_mtd_partitions(flash, walnut_partitions,
  80. ARRAY_SIZE(walnut_partitions));
  81. } else {
  82. printk("map probe failed for flash\n");
  83. iounmap(fpga_status_adr);
  84. return -ENXIO;
  85. }
  86. iounmap(fpga_status_adr);
  87. return 0;
  88. }
  89. static void __exit cleanup_walnut(void)
  90. {
  91. if (flash) {
  92. del_mtd_partitions(flash);
  93. map_destroy(flash);
  94. }
  95. if (walnut_map.virt) {
  96. iounmap((void *)walnut_map.virt);
  97. walnut_map.virt = 0;
  98. }
  99. }
  100. module_init(init_walnut);
  101. module_exit(cleanup_walnut);
  102. MODULE_LICENSE("GPL");
  103. MODULE_AUTHOR("Heikki Lindholm <holindho@infradead.org>");
  104. MODULE_DESCRIPTION("MTD map and partitions for IBM 405GP Walnut boards");