diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/parport/parport_serial.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/parport/parport_serial.c')
-rw-r--r-- | drivers/parport/parport_serial.c | 485 |
1 files changed, 485 insertions, 0 deletions
diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c new file mode 100644 index 000000000000..6715a17b5d0f --- /dev/null +++ b/drivers/parport/parport_serial.c | |||
@@ -0,0 +1,485 @@ | |||
1 | /* | ||
2 | * Support for common PCI multi-I/O cards (which is most of them) | ||
3 | * | ||
4 | * Copyright (C) 2001 Tim Waugh <twaugh@redhat.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * | ||
12 | * Multi-function PCI cards are supposed to present separate logical | ||
13 | * devices on the bus. A common thing to do seems to be to just use | ||
14 | * one logical device with lots of base address registers for both | ||
15 | * parallel ports and serial ports. This driver is for dealing with | ||
16 | * that. | ||
17 | * | ||
18 | */ | ||
19 | |||
20 | #include <linux/types.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/pci.h> | ||
24 | #include <linux/parport.h> | ||
25 | #include <linux/parport_pc.h> | ||
26 | #include <linux/serial.h> | ||
27 | #include <linux/serialP.h> | ||
28 | #include <linux/list.h> | ||
29 | #include <linux/8250_pci.h> | ||
30 | |||
31 | #include <asm/serial.h> | ||
32 | |||
33 | enum parport_pc_pci_cards { | ||
34 | titan_110l = 0, | ||
35 | titan_210l, | ||
36 | netmos_9xx5_combo, | ||
37 | avlab_1s1p, | ||
38 | avlab_1s1p_650, | ||
39 | avlab_1s1p_850, | ||
40 | avlab_1s2p, | ||
41 | avlab_1s2p_650, | ||
42 | avlab_1s2p_850, | ||
43 | avlab_2s1p, | ||
44 | avlab_2s1p_650, | ||
45 | avlab_2s1p_850, | ||
46 | siig_1s1p_10x, | ||
47 | siig_2s1p_10x, | ||
48 | siig_2p1s_20x, | ||
49 | siig_1s1p_20x, | ||
50 | siig_2s1p_20x, | ||
51 | }; | ||
52 | |||
53 | /* each element directly indexed from enum list, above */ | ||
54 | struct parport_pc_pci { | ||
55 | int numports; | ||
56 | struct { /* BAR (base address registers) numbers in the config | ||
57 | space header */ | ||
58 | int lo; | ||
59 | int hi; /* -1 if not there, >6 for offset-method (max | ||
60 | BAR is 6) */ | ||
61 | } addr[4]; | ||
62 | |||
63 | /* If set, this is called immediately after pci_enable_device. | ||
64 | * If it returns non-zero, no probing will take place and the | ||
65 | * ports will not be used. */ | ||
66 | int (*preinit_hook) (struct pci_dev *pdev, struct parport_pc_pci *card, | ||
67 | int autoirq, int autodma); | ||
68 | |||
69 | /* If set, this is called after probing for ports. If 'failed' | ||
70 | * is non-zero we couldn't use any of the ports. */ | ||
71 | void (*postinit_hook) (struct pci_dev *pdev, | ||
72 | struct parport_pc_pci *card, int failed); | ||
73 | }; | ||
74 | |||
75 | static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc_pci *card, int autoirq, int autodma) | ||
76 | { | ||
77 | /* | ||
78 | * Netmos uses the subdevice ID to indicate the number of parallel | ||
79 | * and serial ports. The form is 0x00PS, where <P> is the number of | ||
80 | * parallel ports and <S> is the number of serial ports. | ||
81 | */ | ||
82 | card->numports = (dev->subsystem_device & 0xf0) >> 4; | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | static struct parport_pc_pci cards[] __devinitdata = { | ||
87 | /* titan_110l */ { 1, { { 3, -1 }, } }, | ||
88 | /* titan_210l */ { 1, { { 3, -1 }, } }, | ||
89 | /* netmos_9xx5_combo */ { 1, { { 2, -1 }, }, netmos_parallel_init }, | ||
90 | /* avlab_1s1p */ { 1, { { 1, 2}, } }, | ||
91 | /* avlab_1s1p_650 */ { 1, { { 1, 2}, } }, | ||
92 | /* avlab_1s1p_850 */ { 1, { { 1, 2}, } }, | ||
93 | /* avlab_1s2p */ { 2, { { 1, 2}, { 3, 4 },} }, | ||
94 | /* avlab_1s2p_650 */ { 2, { { 1, 2}, { 3, 4 },} }, | ||
95 | /* avlab_1s2p_850 */ { 2, { { 1, 2}, { 3, 4 },} }, | ||
96 | /* avlab_2s1p */ { 1, { { 2, 3}, } }, | ||
97 | /* avlab_2s1p_650 */ { 1, { { 2, 3}, } }, | ||
98 | /* avlab_2s1p_850 */ { 1, { { 2, 3}, } }, | ||
99 | /* siig_1s1p_10x */ { 1, { { 3, 4 }, } }, | ||
100 | /* siig_2s1p_10x */ { 1, { { 4, 5 }, } }, | ||
101 | /* siig_2p1s_20x */ { 2, { { 1, 2 }, { 3, 4 }, } }, | ||
102 | /* siig_1s1p_20x */ { 1, { { 1, 2 }, } }, | ||
103 | /* siig_2s1p_20x */ { 1, { { 2, 3 }, } }, | ||
104 | }; | ||
105 | |||
106 | static struct pci_device_id parport_serial_pci_tbl[] = { | ||
107 | /* PCI cards */ | ||
108 | { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_110L, | ||
109 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_110l }, | ||
110 | { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_210L, | ||
111 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_210l }, | ||
112 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9735, | ||
113 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, | ||
114 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9745, | ||
115 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, | ||
116 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835, | ||
117 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, | ||
118 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835, | ||
119 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, | ||
120 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9845, | ||
121 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, | ||
122 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855, | ||
123 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, | ||
124 | /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/ | ||
125 | { 0x14db, 0x2110, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p}, | ||
126 | { 0x14db, 0x2111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p_650}, | ||
127 | { 0x14db, 0x2112, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p_850}, | ||
128 | { 0x14db, 0x2140, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p}, | ||
129 | { 0x14db, 0x2141, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p_650}, | ||
130 | { 0x14db, 0x2142, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p_850}, | ||
131 | { 0x14db, 0x2160, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p}, | ||
132 | { 0x14db, 0x2161, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p_650}, | ||
133 | { 0x14db, 0x2162, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p_850}, | ||
134 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_550, | ||
135 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x }, | ||
136 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_650, | ||
137 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x }, | ||
138 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_850, | ||
139 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x }, | ||
140 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_550, | ||
141 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x }, | ||
142 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_650, | ||
143 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x }, | ||
144 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_850, | ||
145 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x }, | ||
146 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_550, | ||
147 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x }, | ||
148 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_650, | ||
149 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x }, | ||
150 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_850, | ||
151 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x }, | ||
152 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_550, | ||
153 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x }, | ||
154 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_650, | ||
155 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x }, | ||
156 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_850, | ||
157 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x }, | ||
158 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_550, | ||
159 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x }, | ||
160 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_650, | ||
161 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x }, | ||
162 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_850, | ||
163 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x }, | ||
164 | |||
165 | { 0, } /* terminate list */ | ||
166 | }; | ||
167 | MODULE_DEVICE_TABLE(pci,parport_serial_pci_tbl); | ||
168 | |||
169 | struct pci_board_no_ids { | ||
170 | int flags; | ||
171 | int num_ports; | ||
172 | int base_baud; | ||
173 | int uart_offset; | ||
174 | int reg_shift; | ||
175 | int (*init_fn)(struct pci_dev *dev, struct pci_board_no_ids *board, | ||
176 | int enable); | ||
177 | int first_uart_offset; | ||
178 | }; | ||
179 | |||
180 | static int __devinit siig10x_init_fn(struct pci_dev *dev, struct pci_board_no_ids *board, int enable) | ||
181 | { | ||
182 | return pci_siig10x_fn(dev, enable); | ||
183 | } | ||
184 | |||
185 | static int __devinit siig20x_init_fn(struct pci_dev *dev, struct pci_board_no_ids *board, int enable) | ||
186 | { | ||
187 | return pci_siig20x_fn(dev, enable); | ||
188 | } | ||
189 | |||
190 | static int __devinit netmos_serial_init(struct pci_dev *dev, struct pci_board_no_ids *board, int enable) | ||
191 | { | ||
192 | board->num_ports = dev->subsystem_device & 0xf; | ||
193 | return 0; | ||
194 | } | ||
195 | |||
196 | static struct pci_board_no_ids pci_boards[] __devinitdata = { | ||
197 | /* | ||
198 | * PCI Flags, Number of Ports, Base (Maximum) Baud Rate, | ||
199 | * Offset to get to next UART's registers, | ||
200 | * Register shift to use for memory-mapped I/O, | ||
201 | * Initialization function, first UART offset | ||
202 | */ | ||
203 | |||
204 | // Cards not tested are marked n/t | ||
205 | // If you have one of these cards and it works for you, please tell me.. | ||
206 | |||
207 | /* titan_110l */ { SPCI_FL_BASE1 | SPCI_FL_BASE_TABLE, 1, 921600 }, | ||
208 | /* titan_210l */ { SPCI_FL_BASE1 | SPCI_FL_BASE_TABLE, 2, 921600 }, | ||
209 | /* netmos_9xx5_combo */ { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200, 0, 0, netmos_serial_init }, | ||
210 | /* avlab_1s1p (n/t) */ { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 }, | ||
211 | /* avlab_1s1p_650 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 }, | ||
212 | /* avlab_1s1p_850 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 }, | ||
213 | /* avlab_1s2p (n/t) */ { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 }, | ||
214 | /* avlab_1s2p_650 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 }, | ||
215 | /* avlab_1s2p_850 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 }, | ||
216 | /* avlab_2s1p (n/t) */ { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 115200 }, | ||
217 | /* avlab_2s1p_650 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 115200 }, | ||
218 | /* avlab_2s1p_850 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 115200 }, | ||
219 | /* siig_1s1p_10x */ { SPCI_FL_BASE2, 1, 460800, 0, 0, siig10x_init_fn }, | ||
220 | /* siig_2s1p_10x */ { SPCI_FL_BASE2, 1, 921600, 0, 0, siig10x_init_fn }, | ||
221 | /* siig_2p1s_20x */ { SPCI_FL_BASE0, 1, 921600, 0, 0, siig20x_init_fn }, | ||
222 | /* siig_1s1p_20x */ { SPCI_FL_BASE0, 1, 921600, 0, 0, siig20x_init_fn }, | ||
223 | /* siig_2s1p_20x */ { SPCI_FL_BASE0, 1, 921600, 0, 0, siig20x_init_fn }, | ||
224 | }; | ||
225 | |||
226 | struct parport_serial_private { | ||
227 | int num_ser; | ||
228 | int line[20]; | ||
229 | struct pci_board_no_ids ser; | ||
230 | int num_par; | ||
231 | struct parport *port[PARPORT_MAX]; | ||
232 | struct parport_pc_pci par; | ||
233 | }; | ||
234 | |||
235 | static int __devinit get_pci_port (struct pci_dev *dev, | ||
236 | struct pci_board_no_ids *board, | ||
237 | struct serial_struct *req, | ||
238 | int idx) | ||
239 | { | ||
240 | unsigned long port; | ||
241 | int base_idx; | ||
242 | int max_port; | ||
243 | int offset; | ||
244 | |||
245 | base_idx = SPCI_FL_GET_BASE(board->flags); | ||
246 | if (board->flags & SPCI_FL_BASE_TABLE) | ||
247 | base_idx += idx; | ||
248 | |||
249 | if (board->flags & SPCI_FL_REGION_SZ_CAP) { | ||
250 | max_port = pci_resource_len(dev, base_idx) / 8; | ||
251 | if (idx >= max_port) | ||
252 | return 1; | ||
253 | } | ||
254 | |||
255 | offset = board->first_uart_offset; | ||
256 | |||
257 | /* Timedia/SUNIX uses a mixture of BARs and offsets */ | ||
258 | /* Ugh, this is ugly as all hell --- TYT */ | ||
259 | if(dev->vendor == PCI_VENDOR_ID_TIMEDIA ) /* 0x1409 */ | ||
260 | switch(idx) { | ||
261 | case 0: base_idx=0; | ||
262 | break; | ||
263 | case 1: base_idx=0; offset=8; | ||
264 | break; | ||
265 | case 2: base_idx=1; | ||
266 | break; | ||
267 | case 3: base_idx=1; offset=8; | ||
268 | break; | ||
269 | case 4: /* BAR 2*/ | ||
270 | case 5: /* BAR 3 */ | ||
271 | case 6: /* BAR 4*/ | ||
272 | case 7: base_idx=idx-2; /* BAR 5*/ | ||
273 | } | ||
274 | |||
275 | port = pci_resource_start(dev, base_idx) + offset; | ||
276 | |||
277 | if ((board->flags & SPCI_FL_BASE_TABLE) == 0) | ||
278 | port += idx * (board->uart_offset ? board->uart_offset : 8); | ||
279 | |||
280 | if (pci_resource_flags (dev, base_idx) & IORESOURCE_IO) { | ||
281 | int high_bits_offset = ((sizeof(long)-sizeof(int))*8); | ||
282 | req->port = port; | ||
283 | if (high_bits_offset) | ||
284 | req->port_high = port >> high_bits_offset; | ||
285 | else | ||
286 | req->port_high = 0; | ||
287 | return 0; | ||
288 | } | ||
289 | req->io_type = SERIAL_IO_MEM; | ||
290 | req->iomem_base = ioremap(port, board->uart_offset); | ||
291 | req->iomem_reg_shift = board->reg_shift; | ||
292 | req->port = 0; | ||
293 | return req->iomem_base ? 0 : 1; | ||
294 | } | ||
295 | |||
296 | /* Register the serial port(s) of a PCI card. */ | ||
297 | static int __devinit serial_register (struct pci_dev *dev, | ||
298 | const struct pci_device_id *id) | ||
299 | { | ||
300 | struct pci_board_no_ids *board; | ||
301 | struct parport_serial_private *priv = pci_get_drvdata (dev); | ||
302 | struct serial_struct serial_req; | ||
303 | int base_baud; | ||
304 | int k; | ||
305 | int success = 0; | ||
306 | |||
307 | priv->ser = pci_boards[id->driver_data]; | ||
308 | board = &priv->ser; | ||
309 | if (board->init_fn && ((board->init_fn) (dev, board, 1) != 0)) | ||
310 | return 1; | ||
311 | |||
312 | base_baud = board->base_baud; | ||
313 | if (!base_baud) | ||
314 | base_baud = BASE_BAUD; | ||
315 | memset (&serial_req, 0, sizeof (serial_req)); | ||
316 | |||
317 | for (k = 0; k < board->num_ports; k++) { | ||
318 | int line; | ||
319 | |||
320 | if (priv->num_ser == ARRAY_SIZE (priv->line)) { | ||
321 | printk (KERN_WARNING | ||
322 | "parport_serial: %s: only %u serial lines " | ||
323 | "supported (%d reported)\n", pci_name (dev), | ||
324 | ARRAY_SIZE (priv->line), board->num_ports); | ||
325 | break; | ||
326 | } | ||
327 | |||
328 | serial_req.irq = dev->irq; | ||
329 | if (get_pci_port (dev, board, &serial_req, k)) | ||
330 | break; | ||
331 | serial_req.flags = ASYNC_SKIP_TEST | ASYNC_AUTOPROBE; | ||
332 | serial_req.baud_base = base_baud; | ||
333 | line = register_serial (&serial_req); | ||
334 | if (line < 0) { | ||
335 | printk (KERN_DEBUG | ||
336 | "parport_serial: register_serial failed\n"); | ||
337 | continue; | ||
338 | } | ||
339 | priv->line[priv->num_ser++] = line; | ||
340 | success = 1; | ||
341 | } | ||
342 | |||
343 | return success ? 0 : 1; | ||
344 | } | ||
345 | |||
346 | /* Register the parallel port(s) of a PCI card. */ | ||
347 | static int __devinit parport_register (struct pci_dev *dev, | ||
348 | const struct pci_device_id *id) | ||
349 | { | ||
350 | struct parport_pc_pci *card; | ||
351 | struct parport_serial_private *priv = pci_get_drvdata (dev); | ||
352 | int i = id->driver_data, n; | ||
353 | int success = 0; | ||
354 | |||
355 | priv->par = cards[id->driver_data]; | ||
356 | card = &priv->par; | ||
357 | if (card->preinit_hook && | ||
358 | card->preinit_hook (dev, card, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) | ||
359 | return -ENODEV; | ||
360 | |||
361 | for (n = 0; n < card->numports; n++) { | ||
362 | struct parport *port; | ||
363 | int lo = card->addr[n].lo; | ||
364 | int hi = card->addr[n].hi; | ||
365 | unsigned long io_lo, io_hi; | ||
366 | |||
367 | if (priv->num_par == ARRAY_SIZE (priv->port)) { | ||
368 | printk (KERN_WARNING | ||
369 | "parport_serial: %s: only %u parallel ports " | ||
370 | "supported (%d reported)\n", pci_name (dev), | ||
371 | ARRAY_SIZE (priv->port), card->numports); | ||
372 | break; | ||
373 | } | ||
374 | |||
375 | io_lo = pci_resource_start (dev, lo); | ||
376 | io_hi = 0; | ||
377 | if ((hi >= 0) && (hi <= 6)) | ||
378 | io_hi = pci_resource_start (dev, hi); | ||
379 | else if (hi > 6) | ||
380 | io_lo += hi; /* Reinterpret the meaning of | ||
381 | "hi" as an offset (see SYBA | ||
382 | def.) */ | ||
383 | /* TODO: test if sharing interrupts works */ | ||
384 | printk (KERN_DEBUG "PCI parallel port detected: %04x:%04x, " | ||
385 | "I/O at %#lx(%#lx)\n", | ||
386 | parport_serial_pci_tbl[i].vendor, | ||
387 | parport_serial_pci_tbl[i].device, io_lo, io_hi); | ||
388 | port = parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE, | ||
389 | PARPORT_DMA_NONE, dev); | ||
390 | if (port) { | ||
391 | priv->port[priv->num_par++] = port; | ||
392 | success = 1; | ||
393 | } | ||
394 | } | ||
395 | |||
396 | if (card->postinit_hook) | ||
397 | card->postinit_hook (dev, card, !success); | ||
398 | |||
399 | return success ? 0 : 1; | ||
400 | } | ||
401 | |||
402 | static int __devinit parport_serial_pci_probe (struct pci_dev *dev, | ||
403 | const struct pci_device_id *id) | ||
404 | { | ||
405 | struct parport_serial_private *priv; | ||
406 | int err; | ||
407 | |||
408 | priv = kmalloc (sizeof *priv, GFP_KERNEL); | ||
409 | if (!priv) | ||
410 | return -ENOMEM; | ||
411 | priv->num_ser = priv->num_par = 0; | ||
412 | pci_set_drvdata (dev, priv); | ||
413 | |||
414 | err = pci_enable_device (dev); | ||
415 | if (err) { | ||
416 | pci_set_drvdata (dev, NULL); | ||
417 | kfree (priv); | ||
418 | return err; | ||
419 | } | ||
420 | |||
421 | if (parport_register (dev, id)) { | ||
422 | pci_set_drvdata (dev, NULL); | ||
423 | kfree (priv); | ||
424 | return -ENODEV; | ||
425 | } | ||
426 | |||
427 | if (serial_register (dev, id)) { | ||
428 | int i; | ||
429 | for (i = 0; i < priv->num_par; i++) | ||
430 | parport_pc_unregister_port (priv->port[i]); | ||
431 | pci_set_drvdata (dev, NULL); | ||
432 | kfree (priv); | ||
433 | return -ENODEV; | ||
434 | } | ||
435 | |||
436 | return 0; | ||
437 | } | ||
438 | |||
439 | static void __devexit parport_serial_pci_remove (struct pci_dev *dev) | ||
440 | { | ||
441 | struct parport_serial_private *priv = pci_get_drvdata (dev); | ||
442 | int i; | ||
443 | |||
444 | // Serial ports | ||
445 | for (i = 0; i < priv->num_ser; i++) { | ||
446 | unregister_serial (priv->line[i]); | ||
447 | |||
448 | if (priv->ser.init_fn) | ||
449 | (priv->ser.init_fn) (dev, &priv->ser, 0); | ||
450 | } | ||
451 | pci_set_drvdata (dev, NULL); | ||
452 | |||
453 | // Parallel ports | ||
454 | for (i = 0; i < priv->num_par; i++) | ||
455 | parport_pc_unregister_port (priv->port[i]); | ||
456 | |||
457 | kfree (priv); | ||
458 | return; | ||
459 | } | ||
460 | |||
461 | static struct pci_driver parport_serial_pci_driver = { | ||
462 | .name = "parport_serial", | ||
463 | .id_table = parport_serial_pci_tbl, | ||
464 | .probe = parport_serial_pci_probe, | ||
465 | .remove = __devexit_p(parport_serial_pci_remove), | ||
466 | }; | ||
467 | |||
468 | |||
469 | static int __init parport_serial_init (void) | ||
470 | { | ||
471 | return pci_module_init (&parport_serial_pci_driver); | ||
472 | } | ||
473 | |||
474 | static void __exit parport_serial_exit (void) | ||
475 | { | ||
476 | pci_unregister_driver (&parport_serial_pci_driver); | ||
477 | return; | ||
478 | } | ||
479 | |||
480 | MODULE_AUTHOR("Tim Waugh <twaugh@redhat.com>"); | ||
481 | MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards"); | ||
482 | MODULE_LICENSE("GPL"); | ||
483 | |||
484 | module_init(parport_serial_init); | ||
485 | module_exit(parport_serial_exit); | ||