walnut.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * $Id: walnut.c,v 1.3 2005/11/07 11:14:29 gleixner 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 <asm/io.h>
  24. #include <asm/ibm4xx.h>
  25. #include <platforms/4xx/walnut.h>
  26. /* these should be in platforms/4xx/walnut.h ? */
  27. #define WALNUT_FLASH_ONBD_N(x) (x & 0x02)
  28. #define WALNUT_FLASH_SRAM_SEL(x) (x & 0x01)
  29. #define WALNUT_FLASH_LOW 0xFFF00000
  30. #define WALNUT_FLASH_HIGH 0xFFF80000
  31. #define WALNUT_FLASH_SIZE 0x80000
  32. static struct mtd_info *flash;
  33. static struct map_info walnut_map = {
  34. .name = "Walnut flash",
  35. .size = WALNUT_FLASH_SIZE,
  36. .bankwidth = 1,
  37. };
  38. /* Actually, OpenBIOS is the last 128 KiB of the flash - better
  39. * partitioning could be made */
  40. static struct mtd_partition walnut_partitions[] = {
  41. {
  42. .name = "OpenBIOS",
  43. .offset = 0x0,
  44. .size = WALNUT_FLASH_SIZE,
  45. /*.mask_flags = MTD_WRITEABLE, */ /* force read-only */
  46. }
  47. };
  48. int __init init_walnut(void)
  49. {
  50. u8 fpga_brds1;
  51. void *fpga_brds1_adr;
  52. void *fpga_status_adr;
  53. unsigned long flash_base;
  54. /* this should already be mapped (platform/4xx/walnut.c) */
  55. fpga_status_adr = ioremap(WALNUT_FPGA_BASE, 8);
  56. if (!fpga_status_adr)
  57. return -ENOMEM;
  58. fpga_brds1_adr = fpga_status_adr+5;
  59. fpga_brds1 = readb(fpga_brds1_adr);
  60. /* iounmap(fpga_status_adr); */
  61. if (WALNUT_FLASH_ONBD_N(fpga_brds1)) {
  62. printk("The on-board flash is disabled (U79 sw 5)!");
  63. return -EIO;
  64. }
  65. if (WALNUT_FLASH_SRAM_SEL(fpga_brds1))
  66. flash_base = WALNUT_FLASH_LOW;
  67. else
  68. flash_base = WALNUT_FLASH_HIGH;
  69. walnut_map.phys = flash_base;
  70. walnut_map.virt =
  71. (void __iomem *)ioremap(flash_base, walnut_map.size);
  72. if (!walnut_map.virt) {
  73. printk("Failed to ioremap flash.\n");
  74. return -EIO;
  75. }
  76. simple_map_init(&walnut_map);
  77. flash = do_map_probe("jedec_probe", &walnut_map);
  78. if (flash) {
  79. flash->owner = THIS_MODULE;
  80. add_mtd_partitions(flash, walnut_partitions,
  81. ARRAY_SIZE(walnut_partitions));
  82. } else {
  83. printk("map probe failed for flash\n");
  84. return -ENXIO;
  85. }
  86. return 0;
  87. }
  88. static void __exit cleanup_walnut(void)
  89. {
  90. if (flash) {
  91. del_mtd_partitions(flash);
  92. map_destroy(flash);
  93. }
  94. if (walnut_map.virt) {
  95. iounmap((void *)walnut_map.virt);
  96. walnut_map.virt = 0;
  97. }
  98. }
  99. module_init(init_walnut);
  100. module_exit(cleanup_walnut);
  101. MODULE_LICENSE("GPL");
  102. MODULE_AUTHOR("Heikki Lindholm <holindho@infradead.org>");
  103. MODULE_DESCRIPTION("MTD map and partitions for IBM 405GP Walnut boards");