tsunami_flash.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * tsunami_flash.c
  3. *
  4. * flash chip on alpha ds10...
  5. */
  6. #include <asm/io.h>
  7. #include <asm/core_tsunami.h>
  8. #include <linux/init.h>
  9. #include <linux/mtd/map.h>
  10. #include <linux/mtd/mtd.h>
  11. #define FLASH_ENABLE_PORT 0x00C00001
  12. #define FLASH_ENABLE_BYTE 0x01
  13. #define FLASH_DISABLE_BYTE 0x00
  14. #define MAX_TIG_FLASH_SIZE (12*1024*1024)
  15. static inline map_word tsunami_flash_read8(struct map_info *map, unsigned long offset)
  16. {
  17. map_word val;
  18. val.x[0] = tsunami_tig_readb(offset);
  19. return val;
  20. }
  21. static void tsunami_flash_write8(struct map_info *map, map_word value, unsigned long offset)
  22. {
  23. tsunami_tig_writeb(value.x[0], offset);
  24. }
  25. static void tsunami_flash_copy_from(
  26. struct map_info *map, void *addr, unsigned long offset, ssize_t len)
  27. {
  28. unsigned char *dest;
  29. dest = addr;
  30. while(len && (offset < MAX_TIG_FLASH_SIZE)) {
  31. *dest = tsunami_tig_readb(offset);
  32. offset++;
  33. dest++;
  34. len--;
  35. }
  36. }
  37. static void tsunami_flash_copy_to(
  38. struct map_info *map, unsigned long offset,
  39. const void *addr, ssize_t len)
  40. {
  41. const unsigned char *src;
  42. src = addr;
  43. while(len && (offset < MAX_TIG_FLASH_SIZE)) {
  44. tsunami_tig_writeb(*src, offset);
  45. offset++;
  46. src++;
  47. len--;
  48. }
  49. }
  50. /*
  51. * Deliberately don't provide operations wider than 8 bits. I don't
  52. * have then and it scares me to think how you could mess up if
  53. * you tried to use them. Buswidth is correctly so I'm safe.
  54. */
  55. static struct map_info tsunami_flash_map = {
  56. .name = "flash chip on the Tsunami TIG bus",
  57. .size = MAX_TIG_FLASH_SIZE,
  58. .phys = NO_XIP,
  59. .bankwidth = 1,
  60. .read = tsunami_flash_read8,
  61. .copy_from = tsunami_flash_copy_from,
  62. .write = tsunami_flash_write8,
  63. .copy_to = tsunami_flash_copy_to,
  64. };
  65. static struct mtd_info *tsunami_flash_mtd;
  66. static void __exit cleanup_tsunami_flash(void)
  67. {
  68. struct mtd_info *mtd;
  69. mtd = tsunami_flash_mtd;
  70. if (mtd) {
  71. mtd_device_unregister(mtd);
  72. map_destroy(mtd);
  73. }
  74. tsunami_flash_mtd = 0;
  75. }
  76. static const char * const rom_probe_types[] = {
  77. "cfi_probe", "jedec_probe", "map_rom", NULL };
  78. static int __init init_tsunami_flash(void)
  79. {
  80. const char * const *type;
  81. tsunami_tig_writeb(FLASH_ENABLE_BYTE, FLASH_ENABLE_PORT);
  82. tsunami_flash_mtd = 0;
  83. type = rom_probe_types;
  84. for(; !tsunami_flash_mtd && *type; type++) {
  85. tsunami_flash_mtd = do_map_probe(*type, &tsunami_flash_map);
  86. }
  87. if (tsunami_flash_mtd) {
  88. tsunami_flash_mtd->owner = THIS_MODULE;
  89. mtd_device_register(tsunami_flash_mtd, NULL, 0);
  90. return 0;
  91. }
  92. return -ENXIO;
  93. }
  94. module_init(init_tsunami_flash);
  95. module_exit(cleanup_tsunami_flash);