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
{
55 /* each element directly indexed from enum list, above */
56 static struct parport_pc_pci
{
58 struct { /* BAR (base address registers) numbers in the config
61 int hi
; /* -1 if not there, >6 for offset-method (max
65 /* If set, this is called immediately after pci_enable_device.
66 * If it returns non-zero, no probing will take place and the
67 * ports will not be used. */
68 int (*preinit_hook
) (struct pci_dev
*pdev
, 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
, int failed
);
73 } cards
[] __devinitdata
= {
74 /* titan_110l */ { 1, { { 3, -1 }, } },
75 /* titan_210l */ { 1, { { 3, -1 }, } },
76 /* netmos_9735 (not tested) */ { 1, { { 2, -1 }, } },
77 /* netmos_9835 */ { 1, { { 2, -1 }, } },
78 /* avlab_1s1p */ { 1, { { 1, 2}, } },
79 /* avlab_1s1p_650 */ { 1, { { 1, 2}, } },
80 /* avlab_1s1p_850 */ { 1, { { 1, 2}, } },
81 /* avlab_1s2p */ { 2, { { 1, 2}, { 3, 4 },} },
82 /* avlab_1s2p_650 */ { 2, { { 1, 2}, { 3, 4 },} },
83 /* avlab_1s2p_850 */ { 2, { { 1, 2}, { 3, 4 },} },
84 /* avlab_2s1p */ { 1, { { 2, 3}, } },
85 /* avlab_2s1p_650 */ { 1, { { 2, 3}, } },
86 /* avlab_2s1p_850 */ { 1, { { 2, 3}, } },
87 /* siig_1s1p_10x */ { 1, { { 3, 4 }, } },
88 /* siig_2s1p_10x */ { 1, { { 4, 5 }, } },
89 /* siig_2p1s_20x */ { 2, { { 1, 2 }, { 3, 4 }, } },
90 /* siig_1s1p_20x */ { 1, { { 1, 2 }, } },
91 /* siig_2s1p_20x */ { 1, { { 2, 3 }, } },
94 static struct pci_device_id parport_serial_pci_tbl
[] = {
96 { PCI_VENDOR_ID_TITAN
, PCI_DEVICE_ID_TITAN_110L
,
97 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, titan_110l
},
98 { PCI_VENDOR_ID_TITAN
, PCI_DEVICE_ID_TITAN_210L
,
99 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, titan_210l
},
100 { PCI_VENDOR_ID_NETMOS
, PCI_DEVICE_ID_NETMOS_9735
,
101 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, netmos_9735
},
102 { PCI_VENDOR_ID_NETMOS
, PCI_DEVICE_ID_NETMOS_9835
,
103 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, netmos_9835
},
104 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
105 { 0x14db, 0x2110, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_1s1p
},
106 { 0x14db, 0x2111, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_1s1p_650
},
107 { 0x14db, 0x2112, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_1s1p_850
},
108 { 0x14db, 0x2140, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_1s2p
},
109 { 0x14db, 0x2141, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_1s2p_650
},
110 { 0x14db, 0x2142, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_1s2p_850
},
111 { 0x14db, 0x2160, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_2s1p
},
112 { 0x14db, 0x2161, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_2s1p_650
},
113 { 0x14db, 0x2162, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_2s1p_850
},
114 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_550
,
115 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_10x
},
116 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_650
,
117 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_10x
},
118 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_850
,
119 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_10x
},
120 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_550
,
121 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_10x
},
122 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_650
,
123 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_10x
},
124 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_850
,
125 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_10x
},
126 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_550
,
127 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2p1s_20x
},
128 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_650
,
129 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2p1s_20x
},
130 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_850
,
131 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2p1s_20x
},
132 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_550
,
133 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_20x
},
134 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_650
,
135 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_20x
},
136 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_850
,
137 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_20x
},
138 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_550
,
139 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_20x
},
140 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_650
,
141 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_20x
},
142 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_850
,
143 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_20x
},
145 { 0, } /* terminate list */
147 MODULE_DEVICE_TABLE(pci
,parport_serial_pci_tbl
);
149 struct pci_board_no_ids
{
155 int (*init_fn
)(struct pci_dev
*dev
, struct pci_board_no_ids
*board
,
157 int first_uart_offset
;
160 static int __devinit
siig10x_init_fn(struct pci_dev
*dev
, struct pci_board_no_ids
*board
, int enable
)
162 return pci_siig10x_fn(dev
, enable
);
165 static int __devinit
siig20x_init_fn(struct pci_dev
*dev
, struct pci_board_no_ids
*board
, int enable
)
167 return pci_siig20x_fn(dev
, enable
);
170 static struct pci_board_no_ids pci_boards
[] __devinitdata
= {
172 * PCI Flags, Number of Ports, Base (Maximum) Baud Rate,
173 * Offset to get to next UART's registers,
174 * Register shift to use for memory-mapped I/O,
175 * Initialization function, first UART offset
178 // Cards not tested are marked n/t
179 // If you have one of these cards and it works for you, please tell me..
181 /* titan_110l */ { SPCI_FL_BASE1
| SPCI_FL_BASE_TABLE
, 1, 921600 },
182 /* titan_210l */ { SPCI_FL_BASE1
| SPCI_FL_BASE_TABLE
, 2, 921600 },
183 /* netmos_9735 (n/t)*/ { SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 115200 },
184 /* netmos_9835 */ { SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 115200 },
185 /* avlab_1s1p (n/t) */ { SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 1, 115200 },
186 /* avlab_1s1p_650 (nt)*/{ SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 1, 115200 },
187 /* avlab_1s1p_850 (nt)*/{ SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 1, 115200 },
188 /* avlab_1s2p (n/t) */ { SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 1, 115200 },
189 /* avlab_1s2p_650 (nt)*/{ SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 1, 115200 },
190 /* avlab_1s2p_850 (nt)*/{ SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 1, 115200 },
191 /* avlab_2s1p (n/t) */ { SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 115200 },
192 /* avlab_2s1p_650 (nt)*/{ SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 115200 },
193 /* avlab_2s1p_850 (nt)*/{ SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 115200 },
194 /* siig_1s1p_10x */ { SPCI_FL_BASE2
, 1, 460800, 0, 0, siig10x_init_fn
},
195 /* siig_2s1p_10x */ { SPCI_FL_BASE2
, 1, 921600, 0, 0, siig10x_init_fn
},
196 /* siig_2p1s_20x */ { SPCI_FL_BASE0
, 1, 921600, 0, 0, siig20x_init_fn
},
197 /* siig_1s1p_20x */ { SPCI_FL_BASE0
, 1, 921600, 0, 0, siig20x_init_fn
},
198 /* siig_2s1p_20x */ { SPCI_FL_BASE0
, 1, 921600, 0, 0, siig20x_init_fn
},
201 struct parport_serial_private
{
204 struct pci_board_no_ids ser
;
206 struct parport
*port
[PARPORT_MAX
];
209 static int __devinit
get_pci_port (struct pci_dev
*dev
,
210 struct pci_board_no_ids
*board
,
211 struct serial_struct
*req
,
219 base_idx
= SPCI_FL_GET_BASE(board
->flags
);
220 if (board
->flags
& SPCI_FL_BASE_TABLE
)
223 if (board
->flags
& SPCI_FL_REGION_SZ_CAP
) {
224 max_port
= pci_resource_len(dev
, base_idx
) / 8;
229 offset
= board
->first_uart_offset
;
231 /* Timedia/SUNIX uses a mixture of BARs and offsets */
232 /* Ugh, this is ugly as all hell --- TYT */
233 if(dev
->vendor
== PCI_VENDOR_ID_TIMEDIA
) /* 0x1409 */
237 case 1: base_idx
=0; offset
=8;
241 case 3: base_idx
=1; offset
=8;
246 case 7: base_idx
=idx
-2; /* BAR 5*/
249 port
= pci_resource_start(dev
, base_idx
) + offset
;
251 if ((board
->flags
& SPCI_FL_BASE_TABLE
) == 0)
252 port
+= idx
* (board
->uart_offset
? board
->uart_offset
: 8);
254 if (pci_resource_flags (dev
, base_idx
) & IORESOURCE_IO
) {
255 int high_bits_offset
= ((sizeof(long)-sizeof(int))*8);
257 if (high_bits_offset
)
258 req
->port_high
= port
>> high_bits_offset
;
263 req
->io_type
= SERIAL_IO_MEM
;
264 req
->iomem_base
= ioremap(port
, board
->uart_offset
);
265 req
->iomem_reg_shift
= board
->reg_shift
;
267 return req
->iomem_base
? 0 : 1;
270 /* Register the serial port(s) of a PCI card. */
271 static int __devinit
serial_register (struct pci_dev
*dev
,
272 const struct pci_device_id
*id
)
274 struct pci_board_no_ids
*board
= &pci_boards
[id
->driver_data
];
275 struct parport_serial_private
*priv
= pci_get_drvdata (dev
);
276 struct serial_struct serial_req
;
282 if (board
->init_fn
&& ((board
->init_fn
) (dev
, board
, 1) != 0))
285 base_baud
= board
->base_baud
;
287 base_baud
= BASE_BAUD
;
288 memset (&serial_req
, 0, sizeof (serial_req
));
290 for (k
= 0; k
< board
->num_ports
; k
++) {
292 serial_req
.irq
= dev
->irq
;
293 if (get_pci_port (dev
, board
, &serial_req
, k
))
295 serial_req
.flags
= ASYNC_SKIP_TEST
| ASYNC_AUTOPROBE
;
296 serial_req
.baud_base
= base_baud
;
297 line
= register_serial (&serial_req
);
300 "parport_serial: register_serial failed\n");
303 priv
->line
[priv
->num_ser
++] = line
;
307 return success
? 0 : 1;
310 /* Register the parallel port(s) of a PCI card. */
311 static int __devinit
parport_register (struct pci_dev
*dev
,
312 const struct pci_device_id
*id
)
314 struct parport_serial_private
*priv
= pci_get_drvdata (dev
);
315 int i
= id
->driver_data
, n
;
318 if (cards
[i
].preinit_hook
&&
319 cards
[i
].preinit_hook (dev
, PARPORT_IRQ_NONE
, PARPORT_DMA_NONE
))
322 for (n
= 0; n
< cards
[i
].numports
; n
++) {
323 struct parport
*port
;
324 int lo
= cards
[i
].addr
[n
].lo
;
325 int hi
= cards
[i
].addr
[n
].hi
;
326 unsigned long io_lo
, io_hi
;
327 io_lo
= pci_resource_start (dev
, lo
);
329 if ((hi
>= 0) && (hi
<= 6))
330 io_hi
= pci_resource_start (dev
, hi
);
332 io_lo
+= hi
; /* Reinterpret the meaning of
333 "hi" as an offset (see SYBA
335 /* TODO: test if sharing interrupts works */
336 printk (KERN_DEBUG
"PCI parallel port detected: %04x:%04x, "
337 "I/O at %#lx(%#lx)\n",
338 parport_serial_pci_tbl
[i
].vendor
,
339 parport_serial_pci_tbl
[i
].device
, io_lo
, io_hi
);
340 port
= parport_pc_probe_port (io_lo
, io_hi
, PARPORT_IRQ_NONE
,
341 PARPORT_DMA_NONE
, dev
);
343 priv
->port
[priv
->num_par
++] = port
;
348 if (cards
[i
].postinit_hook
)
349 cards
[i
].postinit_hook (dev
, !success
);
351 return success
? 0 : 1;
354 static int __devinit
parport_serial_pci_probe (struct pci_dev
*dev
,
355 const struct pci_device_id
*id
)
357 struct parport_serial_private
*priv
;
360 priv
= kmalloc (sizeof *priv
, GFP_KERNEL
);
363 priv
->num_ser
= priv
->num_par
= 0;
364 pci_set_drvdata (dev
, priv
);
366 err
= pci_enable_device (dev
);
368 pci_set_drvdata (dev
, NULL
);
373 if (parport_register (dev
, id
)) {
374 pci_set_drvdata (dev
, NULL
);
379 if (serial_register (dev
, id
)) {
381 for (i
= 0; i
< priv
->num_par
; i
++)
382 parport_pc_unregister_port (priv
->port
[i
]);
383 pci_set_drvdata (dev
, NULL
);
391 static void __devexit
parport_serial_pci_remove (struct pci_dev
*dev
)
393 struct parport_serial_private
*priv
= pci_get_drvdata (dev
);
397 for (i
= 0; i
< priv
->num_ser
; i
++) {
398 unregister_serial (priv
->line
[i
]);
400 if (priv
->ser
.init_fn
)
401 (priv
->ser
.init_fn
) (dev
, &priv
->ser
, 0);
403 pci_set_drvdata (dev
, NULL
);
406 for (i
= 0; i
< priv
->num_par
; i
++)
407 parport_pc_unregister_port (priv
->port
[i
]);
413 static struct pci_driver parport_serial_pci_driver
= {
414 .name
= "parport_serial",
415 .id_table
= parport_serial_pci_tbl
,
416 .probe
= parport_serial_pci_probe
,
417 .remove
= __devexit_p(parport_serial_pci_remove
),
421 static int __init
parport_serial_init (void)
423 return pci_module_init (&parport_serial_pci_driver
);
426 static void __exit
parport_serial_exit (void)
428 pci_unregister_driver (&parport_serial_pci_driver
);
432 MODULE_AUTHOR("Tim Waugh <twaugh@redhat.com>");
433 MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards");
434 MODULE_LICENSE("GPL");
436 module_init(parport_serial_init
);
437 module_exit(parport_serial_exit
);