iohelper.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * iohelper.h
  4. * helper for define functions to access ISDN hardware
  5. * supported are memory mapped IO
  6. * indirect port IO (one port for address, one for data)
  7. *
  8. * Author Karsten Keil <[email protected]>
  9. *
  10. * Copyright 2009 by Karsten Keil <[email protected]>
  11. */
  12. #ifndef _IOHELPER_H
  13. #define _IOHELPER_H
  14. typedef u8 (read_reg_func)(void *hwp, u8 offset);
  15. typedef void (write_reg_func)(void *hwp, u8 offset, u8 value);
  16. typedef void (fifo_func)(void *hwp, u8 offset, u8 *datap, int size);
  17. struct _ioport {
  18. u32 port;
  19. u32 ale;
  20. };
  21. #define IOFUNC_IO(name, hws, ap) \
  22. static u8 Read##name##_IO(void *p, u8 off) { \
  23. struct hws *hw = p; \
  24. return inb(hw->ap.port + off); \
  25. } \
  26. static void Write##name##_IO(void *p, u8 off, u8 val) { \
  27. struct hws *hw = p; \
  28. outb(val, hw->ap.port + off); \
  29. } \
  30. static void ReadFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) { \
  31. struct hws *hw = p; \
  32. insb(hw->ap.port + off, dp, size); \
  33. } \
  34. static void WriteFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) { \
  35. struct hws *hw = p; \
  36. outsb(hw->ap.port + off, dp, size); \
  37. }
  38. #define IOFUNC_IND(name, hws, ap) \
  39. static u8 Read##name##_IND(void *p, u8 off) { \
  40. struct hws *hw = p; \
  41. outb(off, hw->ap.ale); \
  42. return inb(hw->ap.port); \
  43. } \
  44. static void Write##name##_IND(void *p, u8 off, u8 val) { \
  45. struct hws *hw = p; \
  46. outb(off, hw->ap.ale); \
  47. outb(val, hw->ap.port); \
  48. } \
  49. static void ReadFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) { \
  50. struct hws *hw = p; \
  51. outb(off, hw->ap.ale); \
  52. insb(hw->ap.port, dp, size); \
  53. } \
  54. static void WriteFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) { \
  55. struct hws *hw = p; \
  56. outb(off, hw->ap.ale); \
  57. outsb(hw->ap.port, dp, size); \
  58. }
  59. #define IOFUNC_MEMIO(name, hws, typ, adr) \
  60. static u8 Read##name##_MIO(void *p, u8 off) { \
  61. struct hws *hw = p; \
  62. return readb(((typ *)hw->adr) + off); \
  63. } \
  64. static void Write##name##_MIO(void *p, u8 off, u8 val) { \
  65. struct hws *hw = p; \
  66. writeb(val, ((typ *)hw->adr) + off); \
  67. } \
  68. static void ReadFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) { \
  69. struct hws *hw = p; \
  70. while (size--) \
  71. *dp++ = readb(((typ *)hw->adr) + off); \
  72. } \
  73. static void WriteFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) { \
  74. struct hws *hw = p; \
  75. while (size--) \
  76. writeb(*dp++, ((typ *)hw->adr) + off); \
  77. }
  78. #define ASSIGN_FUNC(typ, name, dest) do { \
  79. dest.read_reg = &Read##name##_##typ; \
  80. dest.write_reg = &Write##name##_##typ; \
  81. dest.read_fifo = &ReadFiFo##name##_##typ; \
  82. dest.write_fifo = &WriteFiFo##name##_##typ; \
  83. } while (0)
  84. #define ASSIGN_FUNC_IPAC(typ, target) do { \
  85. ASSIGN_FUNC(typ, ISAC, target.isac); \
  86. ASSIGN_FUNC(typ, IPAC, target); \
  87. } while (0)
  88. #endif