tsunami_flash.c 2.5 KB

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