Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
iohelper.h
Go to the documentation of this file.
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 <[email protected]>
8  *
9  * Copyright 2009 by Karsten Keil <[email protected]>
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 
26 #ifndef _IOHELPER_H
27 #define _IOHELPER_H
28 
29 typedef u8 (read_reg_func)(void *hwp, u8 offset);
30  typedef void (write_reg_func)(void *hwp, u8 offset, u8 value);
31  typedef void (fifo_func)(void *hwp, u8 offset, u8 *datap, int size);
32 
33  struct _ioport {
36  };
37 
38 #define IOFUNC_IO(name, hws, ap) \
39  static u8 Read##name##_IO(void *p, u8 off) { \
40  struct hws *hw = p; \
41  return inb(hw->ap.port + off); \
42  } \
43  static void Write##name##_IO(void *p, u8 off, u8 val) { \
44  struct hws *hw = p; \
45  outb(val, hw->ap.port + off); \
46  } \
47  static void ReadFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) { \
48  struct hws *hw = p; \
49  insb(hw->ap.port + off, dp, size); \
50  } \
51  static void WriteFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) { \
52  struct hws *hw = p; \
53  outsb(hw->ap.port + off, dp, size); \
54  }
55 
56 #define IOFUNC_IND(name, hws, ap) \
57  static u8 Read##name##_IND(void *p, u8 off) { \
58  struct hws *hw = p; \
59  outb(off, hw->ap.ale); \
60  return inb(hw->ap.port); \
61  } \
62  static void Write##name##_IND(void *p, u8 off, u8 val) { \
63  struct hws *hw = p; \
64  outb(off, hw->ap.ale); \
65  outb(val, hw->ap.port); \
66  } \
67  static void ReadFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) { \
68  struct hws *hw = p; \
69  outb(off, hw->ap.ale); \
70  insb(hw->ap.port, dp, size); \
71  } \
72  static void WriteFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) { \
73  struct hws *hw = p; \
74  outb(off, hw->ap.ale); \
75  outsb(hw->ap.port, dp, size); \
76  }
77 
78 #define IOFUNC_MEMIO(name, hws, typ, adr) \
79  static u8 Read##name##_MIO(void *p, u8 off) { \
80  struct hws *hw = p; \
81  return readb(((typ *)hw->adr) + off); \
82  } \
83  static void Write##name##_MIO(void *p, u8 off, u8 val) { \
84  struct hws *hw = p; \
85  writeb(val, ((typ *)hw->adr) + off); \
86  } \
87  static void ReadFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) { \
88  struct hws *hw = p; \
89  while (size--) \
90  *dp++ = readb(((typ *)hw->adr) + off); \
91  } \
92  static void WriteFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) { \
93  struct hws *hw = p; \
94  while (size--) \
95  writeb(*dp++, ((typ *)hw->adr) + off); \
96  }
97 
98 #define ASSIGN_FUNC(typ, name, dest) do { \
99  dest.read_reg = &Read##name##_##typ; \
100  dest.write_reg = &Write##name##_##typ; \
101  dest.read_fifo = &ReadFiFo##name##_##typ; \
102  dest.write_fifo = &WriteFiFo##name##_##typ; \
103  } while (0)
104 #define ASSIGN_FUNC_IPAC(typ, target) do { \
105  ASSIGN_FUNC(typ, ISAC, target.isac); \
106  ASSIGN_FUNC(typ, IPAC, target); \
107  } while (0)
108 
109 #endif