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