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