1 // SPDX-License-Identifier: GPL-2.0+
3 * Support for common PCI multi-I/O cards (which is most of them)
5 * Copyright (C) 2001 Tim Waugh <twaugh@redhat.com>
7 * Multi-function PCI cards are supposed to present separate logical
8 * devices on the bus. A common thing to do seems to be to just use
9 * one logical device with lots of base address registers for both
10 * parallel ports and serial ports. This driver is for dealing with
14 #include <linux/interrupt.h>
15 #include <linux/module.h>
16 #include <linux/parport.h>
17 #include <linux/parport_pc.h>
18 #include <linux/pci.h>
19 #include <linux/slab.h>
20 #include <linux/types.h>
22 #include <linux/8250_pci.h>
24 enum parport_pc_pci_cards
{
66 /* each element directly indexed from enum list, above */
67 struct parport_pc_pci
{
69 struct { /* BAR (base address registers) numbers in the config
72 int hi
; /* -1 if not there, >6 for offset-method (max
76 /* If set, this is called immediately after pci_enable_device.
77 * If it returns non-zero, no probing will take place and the
78 * ports will not be used. */
79 int (*preinit_hook
) (struct pci_dev
*pdev
, struct parport_pc_pci
*card
,
80 int autoirq
, int autodma
);
82 /* If set, this is called after probing for ports. If 'failed'
83 * is non-zero we couldn't use any of the ports. */
84 void (*postinit_hook
) (struct pci_dev
*pdev
,
85 struct parport_pc_pci
*card
, int failed
);
88 static int netmos_parallel_init(struct pci_dev
*dev
, struct parport_pc_pci
*par
,
89 int autoirq
, int autodma
)
91 /* the rule described below doesn't hold for this device */
92 if (dev
->device
== PCI_DEVICE_ID_NETMOS_9835
&&
93 dev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
&&
94 dev
->subsystem_device
== 0x0299)
97 if (dev
->device
== PCI_DEVICE_ID_NETMOS_9912
) {
101 * Netmos uses the subdevice ID to indicate the number of parallel
102 * and serial ports. The form is 0x00PS, where <P> is the number of
103 * parallel ports and <S> is the number of serial ports.
105 par
->numports
= (dev
->subsystem_device
& 0xf0) >> 4;
106 if (par
->numports
> ARRAY_SIZE(par
->addr
))
107 par
->numports
= ARRAY_SIZE(par
->addr
);
113 static struct parport_pc_pci cards
[] = {
114 /* titan_110l */ { 1, { { 3, -1 }, } },
115 /* titan_210l */ { 1, { { 3, -1 }, } },
116 /* netmos_9xx5_combo */ { 1, { { 2, -1 }, }, netmos_parallel_init
},
117 /* netmos_9855 */ { 1, { { 0, -1 }, }, netmos_parallel_init
},
118 /* netmos_9855_2p */ { 2, { { 0, -1 }, { 2, -1 }, } },
119 /* netmos_9900 */ {1, { { 3, 4 }, }, netmos_parallel_init
},
120 /* netmos_9900_2p */ {2, { { 0, 1 }, { 3, 4 }, } },
121 /* netmos_99xx_1p */ {1, { { 0, 1 }, } },
122 /* avlab_1s1p */ { 1, { { 1, 2}, } },
123 /* avlab_1s2p */ { 2, { { 1, 2}, { 3, 4 },} },
124 /* avlab_2s1p */ { 1, { { 2, 3}, } },
125 /* siig_1s1p_10x */ { 1, { { 3, 4 }, } },
126 /* siig_2s1p_10x */ { 1, { { 4, 5 }, } },
127 /* siig_2p1s_20x */ { 2, { { 1, 2 }, { 3, 4 }, } },
128 /* siig_1s1p_20x */ { 1, { { 1, 2 }, } },
129 /* siig_2s1p_20x */ { 1, { { 2, 3 }, } },
130 /* timedia_4078a */ { 1, { { 2, -1 }, } },
131 /* timedia_4079h */ { 1, { { 2, 3 }, } },
132 /* timedia_4085h */ { 2, { { 2, -1 }, { 4, -1 }, } },
133 /* timedia_4088a */ { 2, { { 2, 3 }, { 4, 5 }, } },
134 /* timedia_4089a */ { 2, { { 2, 3 }, { 4, 5 }, } },
135 /* timedia_4095a */ { 2, { { 2, 3 }, { 4, 5 }, } },
136 /* timedia_4096a */ { 2, { { 2, 3 }, { 4, 5 }, } },
137 /* timedia_4078u */ { 1, { { 2, -1 }, } },
138 /* timedia_4079a */ { 1, { { 2, 3 }, } },
139 /* timedia_4085u */ { 2, { { 2, -1 }, { 4, -1 }, } },
140 /* timedia_4079r */ { 1, { { 2, 3 }, } },
141 /* timedia_4079s */ { 1, { { 2, 3 }, } },
142 /* timedia_4079d */ { 1, { { 2, 3 }, } },
143 /* timedia_4079e */ { 1, { { 2, 3 }, } },
144 /* timedia_4079f */ { 1, { { 2, 3 }, } },
145 /* timedia_9079a */ { 1, { { 2, 3 }, } },
146 /* timedia_9079b */ { 1, { { 2, 3 }, } },
147 /* timedia_9079c */ { 1, { { 2, 3 }, } },
148 /* wch_ch353_1s1p*/ { 1, { { 1, -1}, } },
149 /* wch_ch353_2s1p*/ { 1, { { 2, -1}, } },
150 /* wch_ch382_2s1p*/ { 1, { { 2, -1}, } },
151 /* brainboxes_5s1p */ { 1, { { 3, -1 }, } },
152 /* sunix_2s1p */ { 1, { { 3, -1 }, } },
155 static struct pci_device_id parport_serial_pci_tbl
[] = {
157 { PCI_VENDOR_ID_TITAN
, PCI_DEVICE_ID_TITAN_110L
,
158 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, titan_110l
},
159 { PCI_VENDOR_ID_TITAN
, PCI_DEVICE_ID_TITAN_210L
,
160 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, titan_210l
},
161 { PCI_VENDOR_ID_NETMOS
, PCI_DEVICE_ID_NETMOS_9735
,
162 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, netmos_9xx5_combo
},
163 { PCI_VENDOR_ID_NETMOS
, PCI_DEVICE_ID_NETMOS_9745
,
164 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, netmos_9xx5_combo
},
165 { PCI_VENDOR_ID_NETMOS
, PCI_DEVICE_ID_NETMOS_9835
,
166 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, netmos_9xx5_combo
},
167 { PCI_VENDOR_ID_NETMOS
, PCI_DEVICE_ID_NETMOS_9845
,
168 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, netmos_9xx5_combo
},
169 { PCI_VENDOR_ID_NETMOS
, PCI_DEVICE_ID_NETMOS_9855
,
170 0x1000, 0x0020, 0, 0, netmos_9855_2p
},
171 { PCI_VENDOR_ID_NETMOS
, PCI_DEVICE_ID_NETMOS_9855
,
172 0x1000, 0x0022, 0, 0, netmos_9855_2p
},
173 { PCI_VENDOR_ID_NETMOS
, PCI_DEVICE_ID_NETMOS_9855
,
174 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, netmos_9855
},
175 { PCI_VENDOR_ID_NETMOS
, PCI_DEVICE_ID_NETMOS_9900
,
176 0xA000, 0x3011, 0, 0, netmos_9900
},
177 { PCI_VENDOR_ID_NETMOS
, PCI_DEVICE_ID_NETMOS_9900
,
178 0xA000, 0x3012, 0, 0, netmos_9900
},
179 { PCI_VENDOR_ID_NETMOS
, PCI_DEVICE_ID_NETMOS_9900
,
180 0xA000, 0x3020, 0, 0, netmos_9900_2p
},
181 { PCI_VENDOR_ID_NETMOS
, PCI_DEVICE_ID_NETMOS_9912
,
182 0xA000, 0x2000, 0, 0, netmos_99xx_1p
},
183 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
184 { PCI_VENDOR_ID_AFAVLAB
, 0x2110,
185 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_1s1p
},
186 { PCI_VENDOR_ID_AFAVLAB
, 0x2111,
187 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_1s1p
},
188 { PCI_VENDOR_ID_AFAVLAB
, 0x2112,
189 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_1s1p
},
190 { PCI_VENDOR_ID_AFAVLAB
, 0x2140,
191 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_1s2p
},
192 { PCI_VENDOR_ID_AFAVLAB
, 0x2141,
193 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_1s2p
},
194 { PCI_VENDOR_ID_AFAVLAB
, 0x2142,
195 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_1s2p
},
196 { PCI_VENDOR_ID_AFAVLAB
, 0x2160,
197 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_2s1p
},
198 { PCI_VENDOR_ID_AFAVLAB
, 0x2161,
199 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_2s1p
},
200 { PCI_VENDOR_ID_AFAVLAB
, 0x2162,
201 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, avlab_2s1p
},
202 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_550
,
203 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_10x
},
204 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_650
,
205 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_10x
},
206 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_850
,
207 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_10x
},
208 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_550
,
209 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_10x
},
210 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_650
,
211 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_10x
},
212 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_850
,
213 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_10x
},
214 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_550
,
215 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2p1s_20x
},
216 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_650
,
217 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2p1s_20x
},
218 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_850
,
219 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2p1s_20x
},
220 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_550
,
221 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_20x
},
222 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_650
,
223 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_20x
},
224 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_850
,
225 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_20x
},
226 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_550
,
227 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_20x
},
228 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_650
,
229 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_20x
},
230 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_850
,
231 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_20x
},
232 /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/
233 { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a
},
234 { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h
},
235 { 0x1409, 0x7168, 0x1409, 0x4085, 0, 0, timedia_4085h
},
236 { 0x1409, 0x7168, 0x1409, 0x4088, 0, 0, timedia_4088a
},
237 { 0x1409, 0x7168, 0x1409, 0x4089, 0, 0, timedia_4089a
},
238 { 0x1409, 0x7168, 0x1409, 0x4095, 0, 0, timedia_4095a
},
239 { 0x1409, 0x7168, 0x1409, 0x4096, 0, 0, timedia_4096a
},
240 { 0x1409, 0x7168, 0x1409, 0x5078, 0, 0, timedia_4078u
},
241 { 0x1409, 0x7168, 0x1409, 0x5079, 0, 0, timedia_4079a
},
242 { 0x1409, 0x7168, 0x1409, 0x5085, 0, 0, timedia_4085u
},
243 { 0x1409, 0x7168, 0x1409, 0x6079, 0, 0, timedia_4079r
},
244 { 0x1409, 0x7168, 0x1409, 0x7079, 0, 0, timedia_4079s
},
245 { 0x1409, 0x7168, 0x1409, 0x8079, 0, 0, timedia_4079d
},
246 { 0x1409, 0x7168, 0x1409, 0x9079, 0, 0, timedia_4079e
},
247 { 0x1409, 0x7168, 0x1409, 0xa079, 0, 0, timedia_4079f
},
248 { 0x1409, 0x7168, 0x1409, 0xb079, 0, 0, timedia_9079a
},
249 { 0x1409, 0x7168, 0x1409, 0xc079, 0, 0, timedia_9079b
},
250 { 0x1409, 0x7168, 0x1409, 0xd079, 0, 0, timedia_9079c
},
253 { 0x4348, 0x5053, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, wch_ch353_1s1p
},
254 { 0x4348, 0x7053, 0x4348, 0x3253, 0, 0, wch_ch353_2s1p
},
255 { 0x1c00, 0x3250, 0x1c00, 0x3250, 0, 0, wch_ch382_2s1p
},
257 /* BrainBoxes PX272/PX306 MIO card */
258 { PCI_VENDOR_ID_INTASHIELD
, 0x4100,
259 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, brainboxes_5s1p
},
262 * More SUNIX variations. At least one of these has part number
263 * '5079A but subdevice 0x102. That board reports 0x0708 as
266 { PCI_VENDOR_ID_SUNIX
, PCI_DEVICE_ID_SUNIX_1999
, PCI_VENDOR_ID_SUNIX
,
267 0x0102, 0, 0, sunix_2s1p
},
269 { 0, } /* terminate list */
271 MODULE_DEVICE_TABLE(pci
,parport_serial_pci_tbl
);
274 * This table describes the serial "geometry" of these boards. Any
275 * quirks for these can be found in drivers/serial/8250_pci.c
277 * Cards not tested are marked n/t
278 * If you have one of these cards and it works for you, please tell me..
280 static struct pciserial_board pci_parport_serial_boards
[] = {
282 .flags
= FL_BASE1
| FL_BASE_BARS
,
288 .flags
= FL_BASE1
| FL_BASE_BARS
,
293 [netmos_9xx5_combo
] = {
294 .flags
= FL_BASE0
| FL_BASE_BARS
,
300 .flags
= FL_BASE2
| FL_BASE_BARS
,
306 .flags
= FL_BASE4
| FL_BASE_BARS
,
311 [netmos_9900
] = { /* n/t */
312 .flags
= FL_BASE0
| FL_BASE_BARS
,
317 [netmos_9900_2p
] = { /* parallel only */ /* n/t */
323 [netmos_99xx_1p
] = { /* parallel only */ /* n/t */
329 [avlab_1s1p
] = { /* n/t */
330 .flags
= FL_BASE0
| FL_BASE_BARS
,
335 [avlab_1s2p
] = { /* n/t */
336 .flags
= FL_BASE0
| FL_BASE_BARS
,
341 [avlab_2s1p
] = { /* n/t */
342 .flags
= FL_BASE0
| FL_BASE_BARS
,
378 .flags
= FL_BASE0
|FL_BASE_BARS
,
384 .flags
= FL_BASE0
|FL_BASE_BARS
,
390 .flags
= FL_BASE0
|FL_BASE_BARS
,
396 .flags
= FL_BASE0
|FL_BASE_BARS
,
402 .flags
= FL_BASE0
|FL_BASE_BARS
,
408 .flags
= FL_BASE0
|FL_BASE_BARS
,
414 .flags
= FL_BASE0
|FL_BASE_BARS
,
420 .flags
= FL_BASE0
|FL_BASE_BARS
,
426 .flags
= FL_BASE0
|FL_BASE_BARS
,
432 .flags
= FL_BASE0
|FL_BASE_BARS
,
438 .flags
= FL_BASE0
|FL_BASE_BARS
,
444 .flags
= FL_BASE0
|FL_BASE_BARS
,
450 .flags
= FL_BASE0
|FL_BASE_BARS
,
456 .flags
= FL_BASE0
|FL_BASE_BARS
,
462 .flags
= FL_BASE0
|FL_BASE_BARS
,
468 .flags
= FL_BASE0
|FL_BASE_BARS
,
474 .flags
= FL_BASE0
|FL_BASE_BARS
,
480 .flags
= FL_BASE0
|FL_BASE_BARS
,
486 .flags
= FL_BASE0
|FL_BASE_BARS
,
492 .flags
= FL_BASE0
|FL_BASE_BARS
,
502 .first_offset
= 0xC0,
504 [brainboxes_5s1p
] = {
511 .flags
= FL_BASE0
|FL_BASE_BARS
,
518 struct parport_serial_private
{
519 struct serial_private
*serial
;
521 struct parport
*port
[PARPORT_MAX
];
522 struct parport_pc_pci par
;
525 /* Register the serial port(s) of a PCI card. */
526 static int serial_register(struct pci_dev
*dev
, const struct pci_device_id
*id
)
528 struct parport_serial_private
*priv
= pci_get_drvdata (dev
);
529 struct pciserial_board
*board
;
530 struct serial_private
*serial
;
532 board
= &pci_parport_serial_boards
[id
->driver_data
];
533 if (board
->num_ports
== 0)
536 serial
= pciserial_init_ports(dev
, board
);
538 return PTR_ERR(serial
);
540 priv
->serial
= serial
;
544 /* Register the parallel port(s) of a PCI card. */
545 static int parport_register(struct pci_dev
*dev
, const struct pci_device_id
*id
)
547 struct parport_pc_pci
*card
;
548 struct parport_serial_private
*priv
= pci_get_drvdata (dev
);
551 priv
->par
= cards
[id
->driver_data
];
553 if (card
->preinit_hook
&&
554 card
->preinit_hook (dev
, card
, PARPORT_IRQ_NONE
, PARPORT_DMA_NONE
))
557 for (n
= 0; n
< card
->numports
; n
++) {
558 struct parport
*port
;
559 int lo
= card
->addr
[n
].lo
;
560 int hi
= card
->addr
[n
].hi
;
561 unsigned long io_lo
, io_hi
;
564 if (priv
->num_par
== ARRAY_SIZE (priv
->port
)) {
566 "only %zu parallel ports supported (%d reported)\n",
567 ARRAY_SIZE(priv
->port
), card
->numports
);
571 io_lo
= pci_resource_start (dev
, lo
);
573 if ((hi
>= 0) && (hi
<= 6))
574 io_hi
= pci_resource_start (dev
, hi
);
576 io_lo
+= hi
; /* Reinterpret the meaning of
577 "hi" as an offset (see SYBA
579 /* TODO: test if sharing interrupts works */
581 if (irq
== IRQ_NONE
) {
583 "PCI parallel port detected: I/O at %#lx(%#lx)\n",
585 irq
= PARPORT_IRQ_NONE
;
588 "PCI parallel port detected: I/O at %#lx(%#lx), IRQ %d\n",
591 port
= parport_pc_probe_port (io_lo
, io_hi
, irq
,
592 PARPORT_DMA_NONE
, &dev
->dev
, IRQF_SHARED
);
594 priv
->port
[priv
->num_par
++] = port
;
599 if (card
->postinit_hook
)
600 card
->postinit_hook (dev
, card
, !success
);
605 static int parport_serial_pci_probe(struct pci_dev
*dev
,
606 const struct pci_device_id
*id
)
608 struct parport_serial_private
*priv
;
611 priv
= devm_kzalloc(&dev
->dev
, sizeof(*priv
), GFP_KERNEL
);
615 pci_set_drvdata (dev
, priv
);
617 err
= pcim_enable_device(dev
);
621 err
= parport_register(dev
, id
);
625 err
= serial_register(dev
, id
);
628 for (i
= 0; i
< priv
->num_par
; i
++)
629 parport_pc_unregister_port (priv
->port
[i
]);
636 static void parport_serial_pci_remove(struct pci_dev
*dev
)
638 struct parport_serial_private
*priv
= pci_get_drvdata (dev
);
643 pciserial_remove_ports(priv
->serial
);
646 for (i
= 0; i
< priv
->num_par
; i
++)
647 parport_pc_unregister_port (priv
->port
[i
]);
652 static int __maybe_unused
parport_serial_pci_suspend(struct device
*dev
)
654 struct pci_dev
*pdev
= to_pci_dev(dev
);
655 struct parport_serial_private
*priv
= pci_get_drvdata(pdev
);
658 pciserial_suspend_ports(priv
->serial
);
660 /* FIXME: What about parport? */
664 static int __maybe_unused
parport_serial_pci_resume(struct device
*dev
)
666 struct pci_dev
*pdev
= to_pci_dev(dev
);
667 struct parport_serial_private
*priv
= pci_get_drvdata(pdev
);
670 pciserial_resume_ports(priv
->serial
);
672 /* FIXME: What about parport? */
676 static SIMPLE_DEV_PM_OPS(parport_serial_pm_ops
,
677 parport_serial_pci_suspend
, parport_serial_pci_resume
);
679 static struct pci_driver parport_serial_pci_driver
= {
680 .name
= "parport_serial",
681 .id_table
= parport_serial_pci_tbl
,
682 .probe
= parport_serial_pci_probe
,
683 .remove
= parport_serial_pci_remove
,
685 .pm
= &parport_serial_pm_ops
,
688 module_pci_driver(parport_serial_pci_driver
);
690 MODULE_AUTHOR("Tim Waugh <twaugh@redhat.com>");
691 MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards");
692 MODULE_LICENSE("GPL");