blob: 342a3de6c67400ad9d039a72ca73bec0d236304a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/pci.h>
Alan Cox51dcdfe2009-04-07 15:30:57 +010025#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/parport.h>
27#include <linux/parport_pc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/8250_pci.h>
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030enum parport_pc_pci_cards {
31 titan_110l = 0,
32 titan_210l,
33 netmos_9xx5_combo,
Martin Schitter44e58a62005-06-23 00:09:55 -070034 netmos_9855,
Philippe De Muyter50db9d82009-04-02 16:58:53 -070035 netmos_9855_2p,
Nicos Gollan7808edc2011-05-05 21:00:37 +020036 netmos_9900,
37 netmos_9900_2p,
38 netmos_99xx_1p,
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 avlab_1s1p,
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 avlab_1s2p,
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 avlab_2s1p,
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 siig_1s1p_10x,
43 siig_2s1p_10x,
44 siig_2p1s_20x,
45 siig_1s1p_20x,
46 siig_2s1p_20x,
47};
48
49/* each element directly indexed from enum list, above */
50struct parport_pc_pci {
51 int numports;
52 struct { /* BAR (base address registers) numbers in the config
53 space header */
54 int lo;
55 int hi; /* -1 if not there, >6 for offset-method (max
56 BAR is 6) */
57 } addr[4];
58
59 /* If set, this is called immediately after pci_enable_device.
60 * If it returns non-zero, no probing will take place and the
61 * ports will not be used. */
62 int (*preinit_hook) (struct pci_dev *pdev, struct parport_pc_pci *card,
63 int autoirq, int autodma);
64
65 /* If set, this is called after probing for ports. If 'failed'
66 * is non-zero we couldn't use any of the ports. */
67 void (*postinit_hook) (struct pci_dev *pdev,
68 struct parport_pc_pci *card, int failed);
69};
70
Philippe De Muyter50db9d82009-04-02 16:58:53 -070071static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc_pci *par, int autoirq, int autodma)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
Jiri Slaby3abdbf92009-02-11 13:04:40 -080073 /* the rule described below doesn't hold for this device */
74 if (dev->device == PCI_DEVICE_ID_NETMOS_9835 &&
75 dev->subsystem_vendor == PCI_VENDOR_ID_IBM &&
76 dev->subsystem_device == 0x0299)
77 return -ENODEV;
Nicos Gollan7808edc2011-05-05 21:00:37 +020078
79 if (dev->device == PCI_DEVICE_ID_NETMOS_9912) {
80 par->numports = 1;
81 } else {
82 /*
83 * Netmos uses the subdevice ID to indicate the number of parallel
84 * and serial ports. The form is 0x00PS, where <P> is the number of
85 * parallel ports and <S> is the number of serial ports.
86 */
87 par->numports = (dev->subsystem_device & 0xf0) >> 4;
88 if (par->numports > ARRAY_SIZE(par->addr))
89 par->numports = ARRAY_SIZE(par->addr);
90 }
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 return 0;
93}
94
95static struct parport_pc_pci cards[] __devinitdata = {
96 /* titan_110l */ { 1, { { 3, -1 }, } },
97 /* titan_210l */ { 1, { { 3, -1 }, } },
98 /* netmos_9xx5_combo */ { 1, { { 2, -1 }, }, netmos_parallel_init },
Philippe De Muyter50db9d82009-04-02 16:58:53 -070099 /* netmos_9855 */ { 1, { { 0, -1 }, }, netmos_parallel_init },
100 /* netmos_9855_2p */ { 2, { { 0, -1 }, { 2, -1 }, } },
Nicos Gollan7808edc2011-05-05 21:00:37 +0200101 /* netmos_9900 */ {1, { { 3, 4 }, }, netmos_parallel_init },
102 /* netmos_9900_2p */ {2, { { 0, 1 }, { 3, 4 }, } },
103 /* netmos_99xx_1p */ {1, { { 0, 1 }, } },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 /* avlab_1s1p */ { 1, { { 1, 2}, } },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /* avlab_1s2p */ { 2, { { 1, 2}, { 3, 4 },} },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 /* avlab_2s1p */ { 1, { { 2, 3}, } },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 /* siig_1s1p_10x */ { 1, { { 3, 4 }, } },
108 /* siig_2s1p_10x */ { 1, { { 4, 5 }, } },
109 /* siig_2p1s_20x */ { 2, { { 1, 2 }, { 3, 4 }, } },
110 /* siig_1s1p_20x */ { 1, { { 1, 2 }, } },
111 /* siig_2s1p_20x */ { 1, { { 2, 3 }, } },
112};
113
114static struct pci_device_id parport_serial_pci_tbl[] = {
115 /* PCI cards */
116 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_110L,
117 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_110l },
118 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_210L,
119 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_210l },
120 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9735,
121 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
122 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9745,
123 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
124 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835,
125 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9845,
127 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
128 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
Philippe De Muyter50db9d82009-04-02 16:58:53 -0700129 0x1000, 0x0020, 0, 0, netmos_9855_2p },
130 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
131 0x1000, 0x0022, 0, 0, netmos_9855_2p },
132 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
Martin Schitter44e58a62005-06-23 00:09:55 -0700133 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9855 },
Nicos Gollan7808edc2011-05-05 21:00:37 +0200134 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9900,
135 0xA000, 0x3011, 0, 0, netmos_9900 },
136 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9900,
137 0xA000, 0x3012, 0, 0, netmos_9900 },
138 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9900,
139 0xA000, 0x3020, 0, 0, netmos_9900_2p },
140 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9912,
141 0xA000, 0x2000, 0, 0, netmos_99xx_1p },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
Russell King91bca4b2006-03-20 20:08:22 +0000143 { PCI_VENDOR_ID_AFAVLAB, 0x2110,
144 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
145 { PCI_VENDOR_ID_AFAVLAB, 0x2111,
146 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
147 { PCI_VENDOR_ID_AFAVLAB, 0x2112,
148 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
149 { PCI_VENDOR_ID_AFAVLAB, 0x2140,
150 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
151 { PCI_VENDOR_ID_AFAVLAB, 0x2141,
152 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
153 { PCI_VENDOR_ID_AFAVLAB, 0x2142,
154 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
155 { PCI_VENDOR_ID_AFAVLAB, 0x2160,
156 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
157 { PCI_VENDOR_ID_AFAVLAB, 0x2161,
158 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
159 { PCI_VENDOR_ID_AFAVLAB, 0x2162,
160 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_550,
162 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
163 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_650,
164 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
165 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_850,
166 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
167 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_550,
168 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
169 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_650,
170 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
171 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_850,
172 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
173 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_550,
174 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
175 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_650,
176 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
177 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_850,
178 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
179 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_550,
180 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
181 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_650,
182 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
183 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_850,
184 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
185 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_550,
186 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
187 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_650,
188 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
189 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_850,
190 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
191
192 { 0, } /* terminate list */
193};
194MODULE_DEVICE_TABLE(pci,parport_serial_pci_tbl);
195
Russell King05caac52005-07-27 11:41:18 +0100196/*
197 * This table describes the serial "geometry" of these boards. Any
198 * quirks for these can be found in drivers/serial/8250_pci.c
199 *
200 * Cards not tested are marked n/t
201 * If you have one of these cards and it works for you, please tell me..
202 */
203static struct pciserial_board pci_parport_serial_boards[] __devinitdata = {
204 [titan_110l] = {
205 .flags = FL_BASE1 | FL_BASE_BARS,
206 .num_ports = 1,
207 .base_baud = 921600,
208 .uart_offset = 8,
209 },
210 [titan_210l] = {
211 .flags = FL_BASE1 | FL_BASE_BARS,
212 .num_ports = 2,
213 .base_baud = 921600,
214 .uart_offset = 8,
215 },
216 [netmos_9xx5_combo] = {
217 .flags = FL_BASE0 | FL_BASE_BARS,
218 .num_ports = 1,
219 .base_baud = 115200,
220 .uart_offset = 8,
221 },
222 [netmos_9855] = {
Philippe De Muyter50db9d82009-04-02 16:58:53 -0700223 .flags = FL_BASE2 | FL_BASE_BARS,
224 .num_ports = 1,
225 .base_baud = 115200,
226 .uart_offset = 8,
227 },
228 [netmos_9855_2p] = {
Christian Pellegrinc01106e2008-02-06 01:37:44 -0800229 .flags = FL_BASE4 | FL_BASE_BARS,
Russell King05caac52005-07-27 11:41:18 +0100230 .num_ports = 1,
231 .base_baud = 115200,
232 .uart_offset = 8,
233 },
Nicos Gollan7808edc2011-05-05 21:00:37 +0200234 [netmos_9900] = { /* n/t */
235 .flags = FL_BASE0 | FL_BASE_BARS,
236 .num_ports = 1,
237 .base_baud = 115200,
238 .uart_offset = 8,
239 },
240 [netmos_9900_2p] = { /* parallel only */ /* n/t */
241 .flags = FL_BASE0,
242 .num_ports = 0,
243 .base_baud = 115200,
244 .uart_offset = 8,
245 },
246 [netmos_99xx_1p] = { /* parallel only */ /* n/t */
247 .flags = FL_BASE0,
248 .num_ports = 0,
249 .base_baud = 115200,
250 .uart_offset = 8,
251 },
Russell King05caac52005-07-27 11:41:18 +0100252 [avlab_1s1p] = { /* n/t */
253 .flags = FL_BASE0 | FL_BASE_BARS,
254 .num_ports = 1,
255 .base_baud = 115200,
256 .uart_offset = 8,
257 },
Russell King05caac52005-07-27 11:41:18 +0100258 [avlab_1s2p] = { /* n/t */
259 .flags = FL_BASE0 | FL_BASE_BARS,
260 .num_ports = 1,
261 .base_baud = 115200,
262 .uart_offset = 8,
263 },
Russell King05caac52005-07-27 11:41:18 +0100264 [avlab_2s1p] = { /* n/t */
265 .flags = FL_BASE0 | FL_BASE_BARS,
266 .num_ports = 2,
267 .base_baud = 115200,
268 .uart_offset = 8,
269 },
Russell King05caac52005-07-27 11:41:18 +0100270 [siig_1s1p_10x] = {
271 .flags = FL_BASE2,
272 .num_ports = 1,
273 .base_baud = 460800,
274 .uart_offset = 8,
275 },
276 [siig_2s1p_10x] = {
277 .flags = FL_BASE2,
278 .num_ports = 1,
279 .base_baud = 921600,
280 .uart_offset = 8,
281 },
282 [siig_2p1s_20x] = {
283 .flags = FL_BASE0,
284 .num_ports = 1,
285 .base_baud = 921600,
286 .uart_offset = 8,
287 },
288 [siig_1s1p_20x] = {
289 .flags = FL_BASE0,
290 .num_ports = 1,
291 .base_baud = 921600,
292 .uart_offset = 8,
293 },
294 [siig_2s1p_20x] = {
295 .flags = FL_BASE0,
296 .num_ports = 1,
297 .base_baud = 921600,
298 .uart_offset = 8,
299 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300};
301
302struct parport_serial_private {
Russell King05caac52005-07-27 11:41:18 +0100303 struct serial_private *serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 int num_par;
305 struct parport *port[PARPORT_MAX];
306 struct parport_pc_pci par;
307};
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/* Register the serial port(s) of a PCI card. */
310static int __devinit serial_register (struct pci_dev *dev,
311 const struct pci_device_id *id)
312{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 struct parport_serial_private *priv = pci_get_drvdata (dev);
Russell King05caac52005-07-27 11:41:18 +0100314 struct pciserial_board *board;
315 struct serial_private *serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Russell King05caac52005-07-27 11:41:18 +0100317 board = &pci_parport_serial_boards[id->driver_data];
Nicos Gollan7808edc2011-05-05 21:00:37 +0200318
319 if (board->num_ports == 0)
320 return 0;
321
Russell King05caac52005-07-27 11:41:18 +0100322 serial = pciserial_init_ports(dev, board);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Russell King05caac52005-07-27 11:41:18 +0100324 if (IS_ERR(serial))
325 return PTR_ERR(serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Russell King05caac52005-07-27 11:41:18 +0100327 priv->serial = serial;
328 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329}
330
331/* Register the parallel port(s) of a PCI card. */
332static int __devinit parport_register (struct pci_dev *dev,
333 const struct pci_device_id *id)
334{
335 struct parport_pc_pci *card;
336 struct parport_serial_private *priv = pci_get_drvdata (dev);
Russell King7a171cd2006-03-05 00:31:22 +0000337 int n, success = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 priv->par = cards[id->driver_data];
340 card = &priv->par;
341 if (card->preinit_hook &&
342 card->preinit_hook (dev, card, PARPORT_IRQ_NONE, PARPORT_DMA_NONE))
343 return -ENODEV;
344
345 for (n = 0; n < card->numports; n++) {
346 struct parport *port;
347 int lo = card->addr[n].lo;
348 int hi = card->addr[n].hi;
349 unsigned long io_lo, io_hi;
Alan Cox51dcdfe2009-04-07 15:30:57 +0100350 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352 if (priv->num_par == ARRAY_SIZE (priv->port)) {
353 printk (KERN_WARNING
Andrew Mortonf4f64e92006-02-03 03:04:02 -0800354 "parport_serial: %s: only %zu parallel ports "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 "supported (%d reported)\n", pci_name (dev),
Andrew Mortonf4f64e92006-02-03 03:04:02 -0800356 ARRAY_SIZE(priv->port), card->numports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 break;
358 }
359
360 io_lo = pci_resource_start (dev, lo);
361 io_hi = 0;
362 if ((hi >= 0) && (hi <= 6))
363 io_hi = pci_resource_start (dev, hi);
364 else if (hi > 6)
365 io_lo += hi; /* Reinterpret the meaning of
366 "hi" as an offset (see SYBA
367 def.) */
368 /* TODO: test if sharing interrupts works */
Alan Cox51dcdfe2009-04-07 15:30:57 +0100369 irq = dev->irq;
370 if (irq == IRQ_NONE) {
371 dev_dbg(&dev->dev,
372 "PCI parallel port detected: I/O at %#lx(%#lx)\n",
373 io_lo, io_hi);
374 irq = PARPORT_IRQ_NONE;
375 } else {
376 dev_dbg(&dev->dev,
377 "PCI parallel port detected: I/O at %#lx(%#lx), IRQ %d\n",
378 io_lo, io_hi, irq);
Alan Cox51dcdfe2009-04-07 15:30:57 +0100379 }
380 port = parport_pc_probe_port (io_lo, io_hi, irq,
381 PARPORT_DMA_NONE, &dev->dev, IRQF_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 if (port) {
383 priv->port[priv->num_par++] = port;
384 success = 1;
385 }
386 }
387
388 if (card->postinit_hook)
389 card->postinit_hook (dev, card, !success);
390
Russell King7a171cd2006-03-05 00:31:22 +0000391 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392}
393
394static int __devinit parport_serial_pci_probe (struct pci_dev *dev,
395 const struct pci_device_id *id)
396{
397 struct parport_serial_private *priv;
398 int err;
399
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700400 priv = kzalloc (sizeof *priv, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 if (!priv)
402 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 pci_set_drvdata (dev, priv);
404
405 err = pci_enable_device (dev);
406 if (err) {
407 pci_set_drvdata (dev, NULL);
408 kfree (priv);
409 return err;
410 }
411
412 if (parport_register (dev, id)) {
413 pci_set_drvdata (dev, NULL);
414 kfree (priv);
415 return -ENODEV;
416 }
417
418 if (serial_register (dev, id)) {
419 int i;
420 for (i = 0; i < priv->num_par; i++)
421 parport_pc_unregister_port (priv->port[i]);
422 pci_set_drvdata (dev, NULL);
423 kfree (priv);
424 return -ENODEV;
425 }
426
427 return 0;
428}
429
430static void __devexit parport_serial_pci_remove (struct pci_dev *dev)
431{
432 struct parport_serial_private *priv = pci_get_drvdata (dev);
433 int i;
434
Russell King05caac52005-07-27 11:41:18 +0100435 pci_set_drvdata(dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Russell King05caac52005-07-27 11:41:18 +0100437 // Serial ports
438 if (priv->serial)
439 pciserial_remove_ports(priv->serial);
440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 // Parallel ports
442 for (i = 0; i < priv->num_par; i++)
443 parport_pc_unregister_port (priv->port[i]);
444
445 kfree (priv);
446 return;
447}
448
Alexey Dobriyan7dd7d692006-09-29 02:00:16 -0700449#ifdef CONFIG_PM
Russell King05caac52005-07-27 11:41:18 +0100450static int parport_serial_pci_suspend(struct pci_dev *dev, pm_message_t state)
451{
452 struct parport_serial_private *priv = pci_get_drvdata(dev);
453
454 if (priv->serial)
455 pciserial_suspend_ports(priv->serial);
456
457 /* FIXME: What about parport? */
458
459 pci_save_state(dev);
460 pci_set_power_state(dev, pci_choose_state(dev, state));
461 return 0;
462}
463
464static int parport_serial_pci_resume(struct pci_dev *dev)
465{
466 struct parport_serial_private *priv = pci_get_drvdata(dev);
Randy Dunlap10f8a592007-05-08 00:29:01 -0700467 int err;
Russell King05caac52005-07-27 11:41:18 +0100468
469 pci_set_power_state(dev, PCI_D0);
470 pci_restore_state(dev);
471
472 /*
473 * The device may have been disabled. Re-enable it.
474 */
Randy Dunlap10f8a592007-05-08 00:29:01 -0700475 err = pci_enable_device(dev);
476 if (err) {
477 printk(KERN_ERR "parport_serial: %s: error enabling "
478 "device for resume (%d)\n", pci_name(dev), err);
479 return err;
480 }
Russell King05caac52005-07-27 11:41:18 +0100481
482 if (priv->serial)
483 pciserial_resume_ports(priv->serial);
484
485 /* FIXME: What about parport? */
486
487 return 0;
488}
Alexey Dobriyan7dd7d692006-09-29 02:00:16 -0700489#endif
Russell King05caac52005-07-27 11:41:18 +0100490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491static struct pci_driver parport_serial_pci_driver = {
492 .name = "parport_serial",
493 .id_table = parport_serial_pci_tbl,
494 .probe = parport_serial_pci_probe,
495 .remove = __devexit_p(parport_serial_pci_remove),
Alexey Dobriyan7dd7d692006-09-29 02:00:16 -0700496#ifdef CONFIG_PM
Russell King05caac52005-07-27 11:41:18 +0100497 .suspend = parport_serial_pci_suspend,
498 .resume = parport_serial_pci_resume,
Alexey Dobriyan7dd7d692006-09-29 02:00:16 -0700499#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500};
501
502
503static int __init parport_serial_init (void)
504{
Richard Knutsson93b47682005-11-30 01:00:35 +0100505 return pci_register_driver (&parport_serial_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506}
507
508static void __exit parport_serial_exit (void)
509{
510 pci_unregister_driver (&parport_serial_pci_driver);
511 return;
512}
513
514MODULE_AUTHOR("Tim Waugh <twaugh@redhat.com>");
515MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards");
516MODULE_LICENSE("GPL");
517
518module_init(parport_serial_init);
519module_exit(parport_serial_exit);