walnut.c 2.9 KB

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