tsunami_flash.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:2k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

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