iohelper.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * iohelper.h
  3. * helper for define functions to access ISDN hardware
  4. * supported are memory mapped IO
  5. * indirect port IO (one port for address, one for data)
  6. *
  7. * Author Karsten Keil <keil@isdn4linux.de>
  8. *
  9. * Copyright 2009 by Karsten Keil <keil@isdn4linux.de>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #ifndef _IOHELPER_H
  26. #define _IOHELPER_H
  27. typedef u8 (read_reg_func)(void *hwp, u8 offset);
  28. typedef void (write_reg_func)(void *hwp, u8 offset, u8 value);
  29. typedef void (fifo_func)(void *hwp, u8 offset, u8 *datap, int size);
  30. struct _ioport {
  31. u32 port;
  32. u32 ale;
  33. };
  34. #define IOFUNC_IO(name, hws, ap) \
  35. static u8 Read##name##_IO(void *p, u8 off) { \
  36. struct hws *hw = p; \
  37. return inb(hw->ap.port + off); \
  38. } \
  39. static void Write##name##_IO(void *p, u8 off, u8 val) { \
  40. struct hws *hw = p; \
  41. outb(val, hw->ap.port + off); \
  42. } \
  43. static void ReadFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) { \
  44. struct hws *hw = p; \
  45. insb(hw->ap.port + off, dp, size); \
  46. } \
  47. static void WriteFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) { \
  48. struct hws *hw = p; \
  49. outsb(hw->ap.port + off, dp, size); \
  50. }
  51. #define IOFUNC_IND(name, hws, ap) \
  52. static u8 Read##name##_IND(void *p, u8 off) { \
  53. struct hws *hw = p; \
  54. outb(off, hw->ap.ale); \
  55. return inb(hw->ap.port); \
  56. } \
  57. static void Write##name##_IND(void *p, u8 off, u8 val) { \
  58. struct hws *hw = p; \
  59. outb(off, hw->ap.ale); \
  60. outb(val, hw->ap.port); \
  61. } \
  62. static void ReadFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) { \
  63. struct hws *hw = p; \
  64. outb(off, hw->ap.ale); \
  65. insb(hw->ap.port, dp, size); \
  66. } \
  67. static void WriteFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) { \
  68. struct hws *hw = p; \
  69. outb(off, hw->ap.ale); \
  70. outsb(hw->ap.port, dp, size); \
  71. }
  72. #define IOFUNC_MEMIO(name, hws, typ, adr) \
  73. static u8 Read##name##_MIO(void *p, u8 off) { \
  74. struct hws *hw = p; \
  75. return readb(((typ *)hw->adr) + off); \
  76. } \
  77. static void Write##name##_MIO(void *p, u8 off, u8 val) { \
  78. struct hws *hw = p; \
  79. writeb(val, ((typ *)hw->adr) + off); \
  80. } \
  81. static void ReadFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) { \
  82. struct hws *hw = p; \
  83. while (size--) \
  84. *dp++ = readb(((typ *)hw->adr) + off); \
  85. } \
  86. static void WriteFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) { \
  87. struct hws *hw = p; \
  88. while (size--) \
  89. writeb(*dp++, ((typ *)hw->adr) + off); \
  90. }
  91. #define ASSIGN_FUNC(typ, name, dest) do { \
  92. dest.read_reg = &Read##name##_##typ; \
  93. dest.write_reg = &Write##name##_##typ; \
  94. dest.read_fifo = &ReadFiFo##name##_##typ; \
  95. dest.write_fifo = &WriteFiFo##name##_##typ; \
  96. } while (0)
  97. #define ASSIGN_FUNC_IPAC(typ, target) do { \
  98. ASSIGN_FUNC(typ, ISAC, target.isac); \
  99. ASSIGN_FUNC(typ, IPAC, target); \
  100. } while (0)
  101. #endif