2 * Support for common PCI multi-I/O cards (which is most of them)
4 * Copyright (C) 2001 Tim Waugh <twaugh@redhat.com>
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.
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
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>
31 #include <asm/serial.h>
33 enum parport_pc_pci_cards {
54 /* each element directly indexed from enum list, above */
55 struct parport_pc_pci {
57 struct { /* BAR (base address registers) numbers in the config
60 int hi; /* -1 if not there, >6 for offset-method (max
64 /* If set, this is called immediately after pci_enable_device.
65 * If it returns non-zero, no probing will take place and the
66 * ports will not be used. */
67 int (*preinit_hook) (struct pci_dev *pdev, struct parport_pc_pci *card,
68 int autoirq, int autodma);
70 /* If set, this is called after probing for ports. If 'failed'
71 * is non-zero we couldn't use any of the ports. */
72 void (*postinit_hook) (struct pci_dev *pdev,
73 struct parport_pc_pci *card, int failed);
76 static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc_pci *card, int autoirq, int autodma)
79 * Netmos uses the subdevice ID to indicate the number of parallel
80 * and serial ports. The form is 0x00PS, where <P> is the number of
81 * parallel ports and <S> is the number of serial ports.
83 card->numports = (dev->subsystem_device & 0xf0) >> 4;
87 static struct parport_pc_pci cards[] __devinitdata = {
88 /* titan_110l */ { 1, { { 3, -1 }, } },
89 /* titan_210l */ { 1, { { 3, -1 }, } },
90 /* netmos_9xx5_combo */ { 1, { { 2, -1 }, }, netmos_parallel_init },
91 /* netmos_9855 */ { 1, { { 0, -1 }, }, netmos_parallel_init },
92 /* avlab_1s1p */ { 1, { { 1, 2}, } },
93 /* avlab_1s1p_650 */ { 1, { { 1, 2}, } },
94 /* avlab_1s1p_850 */ { 1, { { 1, 2}, } },
95 /* avlab_1s2p */ { 2, { { 1, 2}, { 3, 4 },} },
96 /* avlab_1s2p_650 */ { 2, { { 1, 2}, { 3, 4 },} },
97 /* avlab_1s2p_850 */ { 2, { { 1, 2}, { 3, 4 },} },
98 /* avlab_2s1p */ { 1, { { 2, 3}, } },
99 /* avlab_2s1p_650 */ { 1, { { 2, 3}, } },
100 /* avlab_2s1p_850 */ { 1, { { 2, 3}, } },
101 /* siig_1s1p_10x */ { 1, { { 3, 4 }, } },
102 /* siig_2s1p_10x */ { 1, { { 4, 5 }, } },
103 /* siig_2p1s_20x */ { 2, { { 1, 2 }, { 3, 4 }, } },
104 /* siig_1s1p_20x */ { 1, { { 1, 2 }, } },
105 /* siig_2s1p_20x */ { 1, { { 2, 3 }, } },
108 static struct pci_device_id parport_serial_pci_tbl[] = {
110 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_110L,
111 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_110l },
112 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_210L,
113 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_210l },
114 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9735,
115 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
116 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9745,
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_9835,
121 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
122 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9845,
123 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
124 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
125 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9855 },
126 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
127 { 0x14db, 0x2110, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p},
128 { 0x14db, 0x2111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p_650},
129 { 0x14db, 0x2112, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p_850},
130 { 0x14db, 0x2140, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p},
131 { 0x14db, 0x2141, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p_650},
132 { 0x14db, 0x2142, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p_850},
133 { 0x14db, 0x2160, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p},
134 { 0x14db, 0x2161, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p_650},
135 { 0x14db, 0x2162, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p_850},
136 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_550,
137 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
138 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_650,
139 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
140 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_850,
141 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
142 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_550,
143 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
144 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_650,
145 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
146 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_850,
147 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
148 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_550,
149 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
150 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_650,
151 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
152 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_850,
153 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
154 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_550,
155 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
156 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_650,
157 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
158 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_850,
159 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
160 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_550,
161 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
162 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_650,
163 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
164 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_850,
165 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
167 { 0, } /* terminate list */
169 MODULE_DEVICE_TABLE(pci,parport_serial_pci_tbl);
171 struct pci_board_no_ids {
177 int (*init_fn)(struct pci_dev *dev, struct pci_board_no_ids *board,
179 int first_uart_offset;
182 static int __devinit siig10x_init_fn(struct pci_dev *dev, struct pci_board_no_ids *board, int enable)
184 return pci_siig10x_fn(dev, enable);
187 static int __devinit siig20x_init_fn(struct pci_dev *dev, struct pci_board_no_ids *board, int enable)
189 return pci_siig20x_fn(dev, enable);
192 static int __devinit netmos_serial_init(struct pci_dev *dev, struct pci_board_no_ids *board, int enable)
194 board->num_ports = dev->subsystem_device & 0xf;
198 static struct pci_board_no_ids pci_boards[] __devinitdata = {
200 * PCI Flags, Number of Ports, Base (Maximum) Baud Rate,
201 * Offset to get to next UART's registers,
202 * Register shift to use for memory-mapped I/O,
203 * Initialization function, first UART offset
206 // Cards not tested are marked n/t
207 // If you have one of these cards and it works for you, please tell me..
209 /* titan_110l */ { SPCI_FL_BASE1 | SPCI_FL_BASE_TABLE, 1, 921600 },
210 /* titan_210l */ { SPCI_FL_BASE1 | SPCI_FL_BASE_TABLE, 2, 921600 },
211 /* netmos_9xx5_combo */ { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200, 0, 0, netmos_serial_init },
212 /* netmos_9855 */ { SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 1, 115200, 0, 0, netmos_serial_init },
213 /* avlab_1s1p (n/t) */ { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 },
214 /* avlab_1s1p_650 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 },
215 /* avlab_1s1p_850 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 },
216 /* avlab_1s2p (n/t) */ { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 },
217 /* avlab_1s2p_650 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 },
218 /* avlab_1s2p_850 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 },
219 /* avlab_2s1p (n/t) */ { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 115200 },
220 /* avlab_2s1p_650 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 115200 },
221 /* avlab_2s1p_850 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 115200 },
222 /* siig_1s1p_10x */ { SPCI_FL_BASE2, 1, 460800, 0, 0, siig10x_init_fn },
223 /* siig_2s1p_10x */ { SPCI_FL_BASE2, 1, 921600, 0, 0, siig10x_init_fn },
224 /* siig_2p1s_20x */ { SPCI_FL_BASE0, 1, 921600, 0, 0, siig20x_init_fn },
225 /* siig_1s1p_20x */ { SPCI_FL_BASE0, 1, 921600, 0, 0, siig20x_init_fn },
226 /* siig_2s1p_20x */ { SPCI_FL_BASE0, 1, 921600, 0, 0, siig20x_init_fn },
229 struct parport_serial_private {
232 struct pci_board_no_ids ser;
234 struct parport *port[PARPORT_MAX];
235 struct parport_pc_pci par;
238 static int __devinit get_pci_port (struct pci_dev *dev,
239 struct pci_board_no_ids *board,
240 struct serial_struct *req,
248 base_idx = SPCI_FL_GET_BASE(board->flags);
249 if (board->flags & SPCI_FL_BASE_TABLE)
252 if (board->flags & SPCI_FL_REGION_SZ_CAP) {
253 max_port = pci_resource_len(dev, base_idx) / 8;
258 offset = board->first_uart_offset;
260 /* Timedia/SUNIX uses a mixture of BARs and offsets */
261 /* Ugh, this is ugly as all hell --- TYT */
262 if(dev->vendor == PCI_VENDOR_ID_TIMEDIA ) /* 0x1409 */
266 case 1: base_idx=0; offset=8;
270 case 3: base_idx=1; offset=8;
275 case 7: base_idx=idx-2; /* BAR 5*/
278 port = pci_resource_start(dev, base_idx) + offset;
280 if ((board->flags & SPCI_FL_BASE_TABLE) == 0)
281 port += idx * (board->uart_offset ? board->uart_offset : 8);
283 if (pci_resource_flags (dev, base_idx) & IORESOURCE_IO) {
284 int high_bits_offset = ((sizeof(long)-sizeof(int))*8);
286 if (high_bits_offset)
287 req->port_high = port >> high_bits_offset;
292 req->io_type = SERIAL_IO_MEM;
293 req->iomem_base = ioremap(port, board->uart_offset);
294 req->iomem_reg_shift = board->reg_shift;
296 return req->iomem_base ? 0 : 1;
299 /* Register the serial port(s) of a PCI card. */
300 static int __devinit serial_register (struct pci_dev *dev,
301 const struct pci_device_id *id)
303 struct pci_board_no_ids *board;
304 struct parport_serial_private *priv = pci_get_drvdata (dev);
305 struct serial_struct serial_req;
310 priv->ser = pci_boards[id->driver_data];
312 if (board->init_fn && ((board->init_fn) (dev, board, 1) != 0))
315 base_baud = board->base_baud;
317 base_baud = BASE_BAUD;
318 memset (&serial_req, 0, sizeof (serial_req));
320 for (k = 0; k < board->num_ports; k++) {
323 if (priv->num_ser == ARRAY_SIZE (priv->line)) {
325 "parport_serial: %s: only %u serial lines "
326 "supported (%d reported)\n", pci_name (dev),
327 ARRAY_SIZE (priv->line), board->num_ports);
331 serial_req.irq = dev->irq;
332 if (get_pci_port (dev, board, &serial_req, k))
334 serial_req.flags = ASYNC_SKIP_TEST | ASYNC_AUTOPROBE;
335 serial_req.baud_base = base_baud;
336 line = register_serial (&serial_req);
339 "parport_serial: register_serial failed\n");
342 priv->line[priv->num_ser++] = line;
346 return success ? 0 : 1;
349 /* Register the parallel port(s) of a PCI card. */
350 static int __devinit parport_register (struct pci_dev *dev,
351 const struct pci_device_id *id)
353 struct parport_pc_pci *card;
354 struct parport_serial_private *priv = pci_get_drvdata (dev);
355 int i = id->driver_data, n;
358 priv->par = cards[id->driver_data];
360 if (card->preinit_hook &&
361 card->preinit_hook (dev, card, PARPORT_IRQ_NONE, PARPORT_DMA_NONE))
364 for (n = 0; n < card->numports; n++) {
365 struct parport *port;
366 int lo = card->addr[n].lo;
367 int hi = card->addr[n].hi;
368 unsigned long io_lo, io_hi;
370 if (priv->num_par == ARRAY_SIZE (priv->port)) {
372 "parport_serial: %s: only %u parallel ports "
373 "supported (%d reported)\n", pci_name (dev),
374 ARRAY_SIZE (priv->port), card->numports);
378 io_lo = pci_resource_start (dev, lo);
380 if ((hi >= 0) && (hi <= 6))
381 io_hi = pci_resource_start (dev, hi);
383 io_lo += hi; /* Reinterpret the meaning of
384 "hi" as an offset (see SYBA
386 /* TODO: test if sharing interrupts works */
387 printk (KERN_DEBUG "PCI parallel port detected: %04x:%04x, "
388 "I/O at %#lx(%#lx)\n",
389 parport_serial_pci_tbl[i].vendor,
390 parport_serial_pci_tbl[i].device, io_lo, io_hi);
391 port = parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE,
392 PARPORT_DMA_NONE, dev);
394 priv->port[priv->num_par++] = port;
399 if (card->postinit_hook)
400 card->postinit_hook (dev, card, !success);
402 return success ? 0 : 1;
405 static int __devinit parport_serial_pci_probe (struct pci_dev *dev,
406 const struct pci_device_id *id)
408 struct parport_serial_private *priv;
411 priv = kmalloc (sizeof *priv, GFP_KERNEL);
414 priv->num_ser = priv->num_par = 0;
415 pci_set_drvdata (dev, priv);
417 err = pci_enable_device (dev);
419 pci_set_drvdata (dev, NULL);
424 if (parport_register (dev, id)) {
425 pci_set_drvdata (dev, NULL);
430 if (serial_register (dev, id)) {
432 for (i = 0; i < priv->num_par; i++)
433 parport_pc_unregister_port (priv->port[i]);
434 pci_set_drvdata (dev, NULL);
442 static void __devexit parport_serial_pci_remove (struct pci_dev *dev)
444 struct parport_serial_private *priv = pci_get_drvdata (dev);
448 for (i = 0; i < priv->num_ser; i++) {
449 unregister_serial (priv->line[i]);
451 if (priv->ser.init_fn)
452 (priv->ser.init_fn) (dev, &priv->ser, 0);
454 pci_set_drvdata (dev, NULL);
457 for (i = 0; i < priv->num_par; i++)
458 parport_pc_unregister_port (priv->port[i]);
464 static struct pci_driver parport_serial_pci_driver = {
465 .name = "parport_serial",
466 .id_table = parport_serial_pci_tbl,
467 .probe = parport_serial_pci_probe,
468 .remove = __devexit_p(parport_serial_pci_remove),
472 static int __init parport_serial_init (void)
474 return pci_module_init (&parport_serial_pci_driver);
477 static void __exit parport_serial_exit (void)
479 pci_unregister_driver (&parport_serial_pci_driver);
483 MODULE_AUTHOR("Tim Waugh <twaugh@redhat.com>");
484 MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards");
485 MODULE_LICENSE("GPL");
487 module_init(parport_serial_init);
488 module_exit(parport_serial_exit);