blob: 76dd077e3184f7ed85f3a78de3c8c66a29753199 [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>
23#include <linux/pci.h>
24#include <linux/parport.h>
25#include <linux/parport_pc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/8250_pci.h>
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028enum parport_pc_pci_cards {
29 titan_110l = 0,
30 titan_210l,
31 netmos_9xx5_combo,
Martin Schitter44e58a62005-06-23 00:09:55 -070032 netmos_9855,
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 avlab_1s1p,
34 avlab_1s1p_650,
35 avlab_1s1p_850,
36 avlab_1s2p,
37 avlab_1s2p_650,
38 avlab_1s2p_850,
39 avlab_2s1p,
40 avlab_2s1p_650,
41 avlab_2s1p_850,
42 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
71static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc_pci *card, int autoirq, int autodma)
72{
73 /*
74 * Netmos uses the subdevice ID to indicate the number of parallel
75 * and serial ports. The form is 0x00PS, where <P> is the number of
76 * parallel ports and <S> is the number of serial ports.
77 */
78 card->numports = (dev->subsystem_device & 0xf0) >> 4;
79 return 0;
80}
81
82static struct parport_pc_pci cards[] __devinitdata = {
83 /* titan_110l */ { 1, { { 3, -1 }, } },
84 /* titan_210l */ { 1, { { 3, -1 }, } },
85 /* netmos_9xx5_combo */ { 1, { { 2, -1 }, }, netmos_parallel_init },
Martin Schitter44e58a62005-06-23 00:09:55 -070086 /* netmos_9855 */ { 1, { { 0, -1 }, }, netmos_parallel_init },
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 /* avlab_1s1p */ { 1, { { 1, 2}, } },
88 /* avlab_1s1p_650 */ { 1, { { 1, 2}, } },
89 /* avlab_1s1p_850 */ { 1, { { 1, 2}, } },
90 /* avlab_1s2p */ { 2, { { 1, 2}, { 3, 4 },} },
91 /* avlab_1s2p_650 */ { 2, { { 1, 2}, { 3, 4 },} },
92 /* avlab_1s2p_850 */ { 2, { { 1, 2}, { 3, 4 },} },
93 /* avlab_2s1p */ { 1, { { 2, 3}, } },
94 /* avlab_2s1p_650 */ { 1, { { 2, 3}, } },
95 /* avlab_2s1p_850 */ { 1, { { 2, 3}, } },
96 /* siig_1s1p_10x */ { 1, { { 3, 4 }, } },
97 /* siig_2s1p_10x */ { 1, { { 4, 5 }, } },
98 /* siig_2p1s_20x */ { 2, { { 1, 2 }, { 3, 4 }, } },
99 /* siig_1s1p_20x */ { 1, { { 1, 2 }, } },
100 /* siig_2s1p_20x */ { 1, { { 2, 3 }, } },
101};
102
103static struct pci_device_id parport_serial_pci_tbl[] = {
104 /* PCI cards */
105 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_110L,
106 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_110l },
107 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_210L,
108 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_210l },
109 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9735,
110 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
111 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9745,
112 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
113 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835,
114 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
115 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835,
116 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
117 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9845,
118 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
119 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
Martin Schitter44e58a62005-06-23 00:09:55 -0700120 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9855 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
122 { 0x14db, 0x2110, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p},
123 { 0x14db, 0x2111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p_650},
124 { 0x14db, 0x2112, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p_850},
125 { 0x14db, 0x2140, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p},
126 { 0x14db, 0x2141, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p_650},
127 { 0x14db, 0x2142, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p_850},
128 { 0x14db, 0x2160, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p},
129 { 0x14db, 0x2161, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p_650},
130 { 0x14db, 0x2162, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p_850},
131 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_550,
132 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
133 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_650,
134 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
135 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_850,
136 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
137 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_550,
138 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
139 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_650,
140 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
141 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_850,
142 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
143 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_550,
144 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
145 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_650,
146 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
147 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_850,
148 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
149 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_550,
150 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
151 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_650,
152 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
153 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_850,
154 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
155 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_550,
156 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
157 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_650,
158 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
159 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_850,
160 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
161
162 { 0, } /* terminate list */
163};
164MODULE_DEVICE_TABLE(pci,parport_serial_pci_tbl);
165
Russell King05caac52005-07-27 11:41:18 +0100166/*
167 * This table describes the serial "geometry" of these boards. Any
168 * quirks for these can be found in drivers/serial/8250_pci.c
169 *
170 * Cards not tested are marked n/t
171 * If you have one of these cards and it works for you, please tell me..
172 */
173static struct pciserial_board pci_parport_serial_boards[] __devinitdata = {
174 [titan_110l] = {
175 .flags = FL_BASE1 | FL_BASE_BARS,
176 .num_ports = 1,
177 .base_baud = 921600,
178 .uart_offset = 8,
179 },
180 [titan_210l] = {
181 .flags = FL_BASE1 | FL_BASE_BARS,
182 .num_ports = 2,
183 .base_baud = 921600,
184 .uart_offset = 8,
185 },
186 [netmos_9xx5_combo] = {
187 .flags = FL_BASE0 | FL_BASE_BARS,
188 .num_ports = 1,
189 .base_baud = 115200,
190 .uart_offset = 8,
191 },
192 [netmos_9855] = {
193 .flags = FL_BASE2 | FL_BASE_BARS,
194 .num_ports = 1,
195 .base_baud = 115200,
196 .uart_offset = 8,
197 },
198 [avlab_1s1p] = { /* n/t */
199 .flags = FL_BASE0 | FL_BASE_BARS,
200 .num_ports = 1,
201 .base_baud = 115200,
202 .uart_offset = 8,
203 },
204 [avlab_1s1p_650] = { /* nt */
205 .flags = FL_BASE0 | FL_BASE_BARS,
206 .num_ports = 1,
207 .base_baud = 115200,
208 .uart_offset = 8,
209 },
210 [avlab_1s1p_850] = { /* nt */
211 .flags = FL_BASE0 | FL_BASE_BARS,
212 .num_ports = 1,
213 .base_baud = 115200,
214 .uart_offset = 8,
215 },
216 [avlab_1s2p] = { /* n/t */
217 .flags = FL_BASE0 | FL_BASE_BARS,
218 .num_ports = 1,
219 .base_baud = 115200,
220 .uart_offset = 8,
221 },
222 [avlab_1s2p_650] = { /* nt */
223 .flags = FL_BASE0 | FL_BASE_BARS,
224 .num_ports = 1,
225 .base_baud = 115200,
226 .uart_offset = 8,
227 },
228 [avlab_1s2p_850] = { /* nt */
229 .flags = FL_BASE0 | FL_BASE_BARS,
230 .num_ports = 1,
231 .base_baud = 115200,
232 .uart_offset = 8,
233 },
234 [avlab_2s1p] = { /* n/t */
235 .flags = FL_BASE0 | FL_BASE_BARS,
236 .num_ports = 2,
237 .base_baud = 115200,
238 .uart_offset = 8,
239 },
240 [avlab_2s1p_650] = { /* nt */
241 .flags = FL_BASE0 | FL_BASE_BARS,
242 .num_ports = 2,
243 .base_baud = 115200,
244 .uart_offset = 8,
245 },
246 [avlab_2s1p_850] = { /* nt */
247 .flags = FL_BASE0 | FL_BASE_BARS,
248 .num_ports = 2,
249 .base_baud = 115200,
250 .uart_offset = 8,
251 },
252 [siig_1s1p_10x] = {
253 .flags = FL_BASE2,
254 .num_ports = 1,
255 .base_baud = 460800,
256 .uart_offset = 8,
257 },
258 [siig_2s1p_10x] = {
259 .flags = FL_BASE2,
260 .num_ports = 1,
261 .base_baud = 921600,
262 .uart_offset = 8,
263 },
264 [siig_2p1s_20x] = {
265 .flags = FL_BASE0,
266 .num_ports = 1,
267 .base_baud = 921600,
268 .uart_offset = 8,
269 },
270 [siig_1s1p_20x] = {
271 .flags = FL_BASE0,
272 .num_ports = 1,
273 .base_baud = 921600,
274 .uart_offset = 8,
275 },
276 [siig_2s1p_20x] = {
277 .flags = FL_BASE0,
278 .num_ports = 1,
279 .base_baud = 921600,
280 .uart_offset = 8,
281 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282};
283
284struct parport_serial_private {
Russell King05caac52005-07-27 11:41:18 +0100285 struct serial_private *serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 int num_par;
287 struct parport *port[PARPORT_MAX];
288 struct parport_pc_pci par;
289};
290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291/* Register the serial port(s) of a PCI card. */
292static int __devinit serial_register (struct pci_dev *dev,
293 const struct pci_device_id *id)
294{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 struct parport_serial_private *priv = pci_get_drvdata (dev);
Russell King05caac52005-07-27 11:41:18 +0100296 struct pciserial_board *board;
297 struct serial_private *serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Russell King05caac52005-07-27 11:41:18 +0100299 board = &pci_parport_serial_boards[id->driver_data];
300 serial = pciserial_init_ports(dev, board);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Russell King05caac52005-07-27 11:41:18 +0100302 if (IS_ERR(serial))
303 return PTR_ERR(serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Russell King05caac52005-07-27 11:41:18 +0100305 priv->serial = serial;
306 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
308
309/* Register the parallel port(s) of a PCI card. */
310static int __devinit parport_register (struct pci_dev *dev,
311 const struct pci_device_id *id)
312{
313 struct parport_pc_pci *card;
314 struct parport_serial_private *priv = pci_get_drvdata (dev);
315 int i = id->driver_data, n;
316 int success = 0;
317
318 priv->par = cards[id->driver_data];
319 card = &priv->par;
320 if (card->preinit_hook &&
321 card->preinit_hook (dev, card, PARPORT_IRQ_NONE, PARPORT_DMA_NONE))
322 return -ENODEV;
323
324 for (n = 0; n < card->numports; n++) {
325 struct parport *port;
326 int lo = card->addr[n].lo;
327 int hi = card->addr[n].hi;
328 unsigned long io_lo, io_hi;
329
330 if (priv->num_par == ARRAY_SIZE (priv->port)) {
331 printk (KERN_WARNING
332 "parport_serial: %s: only %u parallel ports "
333 "supported (%d reported)\n", pci_name (dev),
334 ARRAY_SIZE (priv->port), card->numports);
335 break;
336 }
337
338 io_lo = pci_resource_start (dev, lo);
339 io_hi = 0;
340 if ((hi >= 0) && (hi <= 6))
341 io_hi = pci_resource_start (dev, hi);
342 else if (hi > 6)
343 io_lo += hi; /* Reinterpret the meaning of
344 "hi" as an offset (see SYBA
345 def.) */
346 /* TODO: test if sharing interrupts works */
347 printk (KERN_DEBUG "PCI parallel port detected: %04x:%04x, "
348 "I/O at %#lx(%#lx)\n",
349 parport_serial_pci_tbl[i].vendor,
350 parport_serial_pci_tbl[i].device, io_lo, io_hi);
351 port = parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE,
352 PARPORT_DMA_NONE, dev);
353 if (port) {
354 priv->port[priv->num_par++] = port;
355 success = 1;
356 }
357 }
358
359 if (card->postinit_hook)
360 card->postinit_hook (dev, card, !success);
361
362 return success ? 0 : 1;
363}
364
365static int __devinit parport_serial_pci_probe (struct pci_dev *dev,
366 const struct pci_device_id *id)
367{
368 struct parport_serial_private *priv;
369 int err;
370
371 priv = kmalloc (sizeof *priv, GFP_KERNEL);
372 if (!priv)
373 return -ENOMEM;
Russell King05caac52005-07-27 11:41:18 +0100374 memset(priv, 0, sizeof(struct parport_serial_private));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 pci_set_drvdata (dev, priv);
376
377 err = pci_enable_device (dev);
378 if (err) {
379 pci_set_drvdata (dev, NULL);
380 kfree (priv);
381 return err;
382 }
383
384 if (parport_register (dev, id)) {
385 pci_set_drvdata (dev, NULL);
386 kfree (priv);
387 return -ENODEV;
388 }
389
390 if (serial_register (dev, id)) {
391 int i;
392 for (i = 0; i < priv->num_par; i++)
393 parport_pc_unregister_port (priv->port[i]);
394 pci_set_drvdata (dev, NULL);
395 kfree (priv);
396 return -ENODEV;
397 }
398
399 return 0;
400}
401
402static void __devexit parport_serial_pci_remove (struct pci_dev *dev)
403{
404 struct parport_serial_private *priv = pci_get_drvdata (dev);
405 int i;
406
Russell King05caac52005-07-27 11:41:18 +0100407 pci_set_drvdata(dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Russell King05caac52005-07-27 11:41:18 +0100409 // Serial ports
410 if (priv->serial)
411 pciserial_remove_ports(priv->serial);
412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 // Parallel ports
414 for (i = 0; i < priv->num_par; i++)
415 parport_pc_unregister_port (priv->port[i]);
416
417 kfree (priv);
418 return;
419}
420
Russell King05caac52005-07-27 11:41:18 +0100421static int parport_serial_pci_suspend(struct pci_dev *dev, pm_message_t state)
422{
423 struct parport_serial_private *priv = pci_get_drvdata(dev);
424
425 if (priv->serial)
426 pciserial_suspend_ports(priv->serial);
427
428 /* FIXME: What about parport? */
429
430 pci_save_state(dev);
431 pci_set_power_state(dev, pci_choose_state(dev, state));
432 return 0;
433}
434
435static int parport_serial_pci_resume(struct pci_dev *dev)
436{
437 struct parport_serial_private *priv = pci_get_drvdata(dev);
438
439 pci_set_power_state(dev, PCI_D0);
440 pci_restore_state(dev);
441
442 /*
443 * The device may have been disabled. Re-enable it.
444 */
445 pci_enable_device(dev);
446
447 if (priv->serial)
448 pciserial_resume_ports(priv->serial);
449
450 /* FIXME: What about parport? */
451
452 return 0;
453}
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455static struct pci_driver parport_serial_pci_driver = {
456 .name = "parport_serial",
457 .id_table = parport_serial_pci_tbl,
458 .probe = parport_serial_pci_probe,
459 .remove = __devexit_p(parport_serial_pci_remove),
Russell King05caac52005-07-27 11:41:18 +0100460 .suspend = parport_serial_pci_suspend,
461 .resume = parport_serial_pci_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462};
463
464
465static int __init parport_serial_init (void)
466{
Richard Knutsson93b47682005-11-30 01:00:35 +0100467 return pci_register_driver (&parport_serial_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}
469
470static void __exit parport_serial_exit (void)
471{
472 pci_unregister_driver (&parport_serial_pci_driver);
473 return;
474}
475
476MODULE_AUTHOR("Tim Waugh <twaugh@redhat.com>");
477MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards");
478MODULE_LICENSE("GPL");
479
480module_init(parport_serial_init);
481module_exit(parport_serial_exit);