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
{
53 /* each element directly indexed from enum list, above */
54 struct parport_pc_pci
{
56 struct { /* BAR (base address registers) numbers in the config
59 int hi
; /* -1 if not there, >6 for offset-method (max
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
);
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
);
75 static int __devinit
netmos_parallel_init(struct pci_dev
*dev
, struct parport_pc_pci
*card
, int autoirq
, int autodma
)
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.
82 card
->numports
= (dev
->subsystem_device
& 0xf0) >> 4;
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 }, } },
106 static struct pci_device_id parport_serial_pci_tbl
[] = {
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
},
165 { 0, } /* terminate list */
167 MODULE_DEVICE_TABLE(pci
,parport_serial_pci_tbl
);
169 struct pci_board_no_ids
{
175 int (*init_fn
)(struct pci_dev
*dev
, struct pci_board_no_ids
*board
,
177 int first_uart_offset
;
180 static int __devinit
siig10x_init_fn(struct pci_dev
*dev
, struct pci_board_no_ids
*board
, int enable
)
182 return pci_siig10x_fn(dev
, enable
);
185 static int __devinit
siig20x_init_fn(struct pci_dev
*dev
, struct pci_board_no_ids
*board
, int enable
)
187 return pci_siig20x_fn(dev
, enable
);
190 static int __devinit
netmos_serial_init(struct pci_dev
*dev
, struct pci_board_no_ids
*board
, int enable
)
192 board
->num_ports
= dev
->subsystem_device
& 0xf;
196 static struct pci_board_no_ids pci_boards
[] __devinitdata
= {
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
204 // Cards not tested are marked n/t
205 // If you have one of these cards and it works for you, please tell me..
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
},
226 struct parport_serial_private
{
229 struct pci_board_no_ids ser
;
231 struct parport
*port
[PARPORT_MAX
];
232 struct parport_pc_pci par
;
235 static int __devinit
get_pci_port (struct pci_dev
*dev
,
236 struct pci_board_no_ids
*board
,
237 struct serial_struct
*req
,
245 base_idx
= SPCI_FL_GET_BASE(board
->flags
);
246 if (board
->flags
& SPCI_FL_BASE_TABLE
)
249 if (board
->flags
& SPCI_FL_REGION_SZ_CAP
) {
250 max_port
= pci_resource_len(dev
, base_idx
) / 8;
255 offset
= board
->first_uart_offset
;
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 */
263 case 1: base_idx
=0; offset
=8;
267 case 3: base_idx
=1; offset
=8;
272 case 7: base_idx
=idx
-2; /* BAR 5*/
275 port
= pci_resource_start(dev
, base_idx
) + offset
;
277 if ((board
->flags
& SPCI_FL_BASE_TABLE
) == 0)
278 port
+= idx
* (board
->uart_offset
? board
->uart_offset
: 8);
280 if (pci_resource_flags (dev
, base_idx
) & IORESOURCE_IO
) {
281 int high_bits_offset
= ((sizeof(long)-sizeof(int))*8);
283 if (high_bits_offset
)
284 req
->port_high
= port
>> high_bits_offset
;
289 req
->io_type
= SERIAL_IO_MEM
;
290 req
->iomem_base
= ioremap(port
, board
->uart_offset
);
291 req
->iomem_reg_shift
= board
->reg_shift
;
293 return req
->iomem_base
? 0 : 1;
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
)
300 struct pci_board_no_ids
*board
;
301 struct parport_serial_private
*priv
= pci_get_drvdata (dev
);
302 struct serial_struct serial_req
;
307 priv
->ser
= pci_boards
[id
->driver_data
];
309 if (board
->init_fn
&& ((board
->init_fn
) (dev
, board
, 1) != 0))
312 base_baud
= board
->base_baud
;
314 base_baud
= BASE_BAUD
;
315 memset (&serial_req
, 0, sizeof (serial_req
));
317 for (k
= 0; k
< board
->num_ports
; k
++) {
320 if (priv
->num_ser
== ARRAY_SIZE (priv
->line
)) {
322 "parport_serial: %s: only %u serial lines "
323 "supported (%d reported)\n", pci_name (dev
),
324 ARRAY_SIZE (priv
->line
), board
->num_ports
);
328 serial_req
.irq
= dev
->irq
;
329 if (get_pci_port (dev
, board
, &serial_req
, k
))
331 serial_req
.flags
= ASYNC_SKIP_TEST
| ASYNC_AUTOPROBE
;
332 serial_req
.baud_base
= base_baud
;
333 line
= register_serial (&serial_req
);
336 "parport_serial: register_serial failed\n");
339 priv
->line
[priv
->num_ser
++] = line
;
343 return success
? 0 : 1;
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
)
350 struct parport_pc_pci
*card
;
351 struct parport_serial_private
*priv
= pci_get_drvdata (dev
);
352 int i
= id
->driver_data
, n
;
355 priv
->par
= cards
[id
->driver_data
];
357 if (card
->preinit_hook
&&
358 card
->preinit_hook (dev
, card
, PARPORT_IRQ_NONE
, PARPORT_DMA_NONE
))
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
;
367 if (priv
->num_par
== ARRAY_SIZE (priv
->port
)) {
369 "parport_serial: %s: only %u parallel ports "
370 "supported (%d reported)\n", pci_name (dev
),
371 ARRAY_SIZE (priv
->port
), card
->numports
);
375 io_lo
= pci_resource_start (dev
, lo
);
377 if ((hi
>= 0) && (hi
<= 6))
378 io_hi
= pci_resource_start (dev
, hi
);
380 io_lo
+= hi
; /* Reinterpret the meaning of
381 "hi" as an offset (see SYBA
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
);
391 priv
->port
[priv
->num_par
++] = port
;
396 if (card
->postinit_hook
)
397 card
->postinit_hook (dev
, card
, !success
);
399 return success
? 0 : 1;
402 static int __devinit
parport_serial_pci_probe (struct pci_dev
*dev
,
403 const struct pci_device_id
*id
)
405 struct parport_serial_private
*priv
;
408 priv
= kmalloc (sizeof *priv
, GFP_KERNEL
);
411 priv
->num_ser
= priv
->num_par
= 0;
412 pci_set_drvdata (dev
, priv
);
414 err
= pci_enable_device (dev
);
416 pci_set_drvdata (dev
, NULL
);
421 if (parport_register (dev
, id
)) {
422 pci_set_drvdata (dev
, NULL
);
427 if (serial_register (dev
, id
)) {
429 for (i
= 0; i
< priv
->num_par
; i
++)
430 parport_pc_unregister_port (priv
->port
[i
]);
431 pci_set_drvdata (dev
, NULL
);
439 static void __devexit
parport_serial_pci_remove (struct pci_dev
*dev
)
441 struct parport_serial_private
*priv
= pci_get_drvdata (dev
);
445 for (i
= 0; i
< priv
->num_ser
; i
++) {
446 unregister_serial (priv
->line
[i
]);
448 if (priv
->ser
.init_fn
)
449 (priv
->ser
.init_fn
) (dev
, &priv
->ser
, 0);
451 pci_set_drvdata (dev
, NULL
);
454 for (i
= 0; i
< priv
->num_par
; i
++)
455 parport_pc_unregister_port (priv
->port
[i
]);
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
),
469 static int __init
parport_serial_init (void)
471 return pci_module_init (&parport_serial_pci_driver
);
474 static void __exit
parport_serial_exit (void)
476 pci_unregister_driver (&parport_serial_pci_driver
);
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");
484 module_init(parport_serial_init
);
485 module_exit(parport_serial_exit
);