1
2
3
4
5
6
7
8
9
10
11
12#include <linux/mod_devicetable.h>
13#include <linux/device.h>
14#include <linux/interrupt.h>
15
16#define IPACK_IDPROM_OFFSET_I 0x01
17#define IPACK_IDPROM_OFFSET_P 0x03
18#define IPACK_IDPROM_OFFSET_A 0x05
19#define IPACK_IDPROM_OFFSET_C 0x07
20#define IPACK_IDPROM_OFFSET_MANUFACTURER_ID 0x09
21#define IPACK_IDPROM_OFFSET_MODEL 0x0B
22#define IPACK_IDPROM_OFFSET_REVISION 0x0D
23#define IPACK_IDPROM_OFFSET_RESERVED 0x0F
24#define IPACK_IDPROM_OFFSET_DRIVER_ID_L 0x11
25#define IPACK_IDPROM_OFFSET_DRIVER_ID_H 0x13
26#define IPACK_IDPROM_OFFSET_NUM_BYTES 0x15
27#define IPACK_IDPROM_OFFSET_CRC 0x17
28
29
30
31
32
33
34#define IPACK_ID_VERSION_INVALID 0x00
35#define IPACK_ID_VERSION_1 0x01
36#define IPACK_ID_VERSION_2 0x02
37
38
39#define IPACK1_VENDOR_ID_RESERVED1 0x00
40#define IPACK1_VENDOR_ID_RESERVED2 0xFF
41#define IPACK1_VENDOR_ID_UNREGISTRED01 0x01
42#define IPACK1_VENDOR_ID_UNREGISTRED02 0x02
43#define IPACK1_VENDOR_ID_UNREGISTRED03 0x03
44#define IPACK1_VENDOR_ID_UNREGISTRED04 0x04
45#define IPACK1_VENDOR_ID_UNREGISTRED05 0x05
46#define IPACK1_VENDOR_ID_UNREGISTRED06 0x06
47#define IPACK1_VENDOR_ID_UNREGISTRED07 0x07
48#define IPACK1_VENDOR_ID_UNREGISTRED08 0x08
49#define IPACK1_VENDOR_ID_UNREGISTRED09 0x09
50#define IPACK1_VENDOR_ID_UNREGISTRED10 0x0A
51#define IPACK1_VENDOR_ID_UNREGISTRED11 0x0B
52#define IPACK1_VENDOR_ID_UNREGISTRED12 0x0C
53#define IPACK1_VENDOR_ID_UNREGISTRED13 0x0D
54#define IPACK1_VENDOR_ID_UNREGISTRED14 0x0E
55#define IPACK1_VENDOR_ID_UNREGISTRED15 0x0F
56
57#define IPACK1_VENDOR_ID_SBS 0xF0
58#define IPACK1_DEVICE_ID_SBS_OCTAL_232 0x22
59#define IPACK1_DEVICE_ID_SBS_OCTAL_422 0x2A
60#define IPACK1_DEVICE_ID_SBS_OCTAL_485 0x48
61
62struct ipack_bus_ops;
63struct ipack_driver;
64
65enum ipack_space {
66 IPACK_IO_SPACE = 0,
67 IPACK_ID_SPACE,
68 IPACK_INT_SPACE,
69 IPACK_MEM8_SPACE,
70 IPACK_MEM16_SPACE,
71
72
73 IPACK_SPACE_COUNT,
74};
75
76
77
78struct ipack_region {
79 phys_addr_t start;
80 size_t size;
81};
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97struct ipack_device {
98 unsigned int slot;
99 struct ipack_bus_device *bus;
100 struct device dev;
101 void (*release) (struct ipack_device *dev);
102 struct ipack_region region[IPACK_SPACE_COUNT];
103 u8 *id;
104 size_t id_avail;
105 u32 id_vendor;
106 u32 id_device;
107 u8 id_format;
108 unsigned int id_crc_correct:1;
109 unsigned int speed_8mhz:1;
110 unsigned int speed_32mhz:1;
111};
112
113
114
115
116
117
118
119
120
121struct ipack_driver_ops {
122 int (*probe) (struct ipack_device *dev);
123 void (*remove) (struct ipack_device *dev);
124};
125
126
127
128
129
130
131
132struct ipack_driver {
133 struct device_driver driver;
134 const struct ipack_device_id *id_table;
135 const struct ipack_driver_ops *ops;
136};
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155struct ipack_bus_ops {
156 int (*request_irq) (struct ipack_device *dev,
157 irqreturn_t (*handler)(void *), void *arg);
158 int (*free_irq) (struct ipack_device *dev);
159 int (*get_clockrate) (struct ipack_device *dev);
160 int (*set_clockrate) (struct ipack_device *dev, int mherz);
161 int (*get_error) (struct ipack_device *dev);
162 int (*get_timeout) (struct ipack_device *dev);
163 int (*reset_timeout) (struct ipack_device *dev);
164};
165
166
167
168
169
170
171
172
173
174struct ipack_bus_device {
175 struct device *parent;
176 int slots;
177 int bus_nr;
178 const struct ipack_bus_ops *ops;
179};
180
181
182
183
184
185
186
187
188
189
190
191struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
192 const struct ipack_bus_ops *ops);
193
194
195
196
197int ipack_bus_unregister(struct ipack_bus_device *bus);
198
199
200
201
202
203
204
205int ipack_driver_register(struct ipack_driver *edrv, struct module *owner,
206 const char *name);
207void ipack_driver_unregister(struct ipack_driver *edrv);
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225int ipack_device_init(struct ipack_device *dev);
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240int ipack_device_add(struct ipack_device *dev);
241void ipack_device_del(struct ipack_device *dev);
242
243void ipack_get_device(struct ipack_device *dev);
244void ipack_put_device(struct ipack_device *dev);
245
246
247
248
249
250
251
252
253#define DEFINE_IPACK_DEVICE_TABLE(_table) \
254 const struct ipack_device_id _table[]
255
256
257
258
259
260
261
262
263
264#define IPACK_DEVICE(_format, vend, dev) \
265 .format = (_format), \
266 .vendor = (vend), \
267 .device = (dev)
268