1 /* SPDX-License-Identifier: GPL-2.0-only */
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)
8 * Author Karsten Keil <keil@isdn4linux.de>
10 * Copyright 2009 by Karsten Keil <keil@isdn4linux.de>
16 typedef u8 (read_reg_func
)(void *hwp
, u8 offset
);
17 typedef void (write_reg_func
)(void *hwp
, u8 offset
, u8 value
);
18 typedef void (fifo_func
)(void *hwp
, u8 offset
, u8
*datap
, int size
);
25 #define IOFUNC_IO(name, hws, ap) \
26 static u8 Read##name##_IO(void *p, u8 off) { \
28 return inb(hw->ap.port + off); \
30 static void Write##name##_IO(void *p, u8 off, u8 val) { \
32 outb(val, hw->ap.port + off); \
34 static void ReadFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) { \
36 insb(hw->ap.port + off, dp, size); \
38 static void WriteFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) { \
40 outsb(hw->ap.port + off, dp, size); \
43 #define IOFUNC_IND(name, hws, ap) \
44 static u8 Read##name##_IND(void *p, u8 off) { \
46 outb(off, hw->ap.ale); \
47 return inb(hw->ap.port); \
49 static void Write##name##_IND(void *p, u8 off, u8 val) { \
51 outb(off, hw->ap.ale); \
52 outb(val, hw->ap.port); \
54 static void ReadFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) { \
56 outb(off, hw->ap.ale); \
57 insb(hw->ap.port, dp, size); \
59 static void WriteFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) { \
61 outb(off, hw->ap.ale); \
62 outsb(hw->ap.port, dp, size); \
65 #define IOFUNC_MEMIO(name, hws, typ, adr) \
66 static u8 Read##name##_MIO(void *p, u8 off) { \
68 return readb(((typ *)hw->adr) + off); \
70 static void Write##name##_MIO(void *p, u8 off, u8 val) { \
72 writeb(val, ((typ *)hw->adr) + off); \
74 static void ReadFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) { \
77 *dp++ = readb(((typ *)hw->adr) + off); \
79 static void WriteFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) { \
82 writeb(*dp++, ((typ *)hw->adr) + off); \
85 #define ASSIGN_FUNC(typ, name, dest) do { \
86 dest.read_reg = &Read##name##_##typ; \
87 dest.write_reg = &Write##name##_##typ; \
88 dest.read_fifo = &ReadFiFo##name##_##typ; \
89 dest.write_fifo = &WriteFiFo##name##_##typ; \
91 #define ASSIGN_FUNC_IPAC(typ, target) do { \
92 ASSIGN_FUNC(typ, ISAC, target.isac); \
93 ASSIGN_FUNC(typ, IPAC, target); \