blob: d141e31a52db4acf17c8da2747588792c862342d [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
Alan Cox51dcdfe2009-04-07 15:30:57 +010020#include <linux/interrupt.h>
Andy Shevchenko4af57812018-02-07 19:47:57 +000021#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/parport.h>
23#include <linux/parport_pc.h>
Andy Shevchenko4af57812018-02-07 19:47:57 +000024#include <linux/pci.h>
25#include <linux/slab.h>
26#include <linux/types.h>
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/8250_pci.h>
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030enum parport_pc_pci_cards {
31 titan_110l = 0,
32 titan_210l,
33 netmos_9xx5_combo,
Martin Schitter44e58a62005-06-23 00:09:55 -070034 netmos_9855,
Philippe De Muyter50db9d82009-04-02 16:58:53 -070035 netmos_9855_2p,
Nicos Gollan7808edc2011-05-05 21:00:37 +020036 netmos_9900,
37 netmos_9900_2p,
38 netmos_99xx_1p,
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 avlab_1s1p,
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 avlab_1s2p,
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 avlab_2s1p,
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 siig_1s1p_10x,
43 siig_2s1p_10x,
44 siig_2p1s_20x,
45 siig_1s1p_20x,
46 siig_2s1p_20x,
Frédéric Brièreb9b24552011-05-29 15:08:04 -040047 timedia_4078a,
48 timedia_4079h,
49 timedia_4085h,
50 timedia_4088a,
51 timedia_4089a,
52 timedia_4095a,
53 timedia_4096a,
54 timedia_4078u,
55 timedia_4079a,
56 timedia_4085u,
57 timedia_4079r,
58 timedia_4079s,
59 timedia_4079d,
60 timedia_4079e,
61 timedia_4079f,
62 timedia_9079a,
63 timedia_9079b,
64 timedia_9079c,
Ezequiel Garciafeb58142014-05-24 15:24:51 -030065 wch_ch353_1s1p,
Guainluca Anzolin6971c632012-09-04 15:56:12 +010066 wch_ch353_2s1p,
Sergej Pupykin2fdd8c82014-11-06 14:36:31 +030067 wch_ch382_2s1p,
Andy Shevchenkoec8e3892018-02-07 19:47:51 +000068 brainboxes_5s1p,
Stephen Chiversabd7bac2013-01-28 19:49:20 +110069 sunix_2s1p,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070};
71
72/* each element directly indexed from enum list, above */
73struct parport_pc_pci {
74 int numports;
75 struct { /* BAR (base address registers) numbers in the config
76 space header */
77 int lo;
78 int hi; /* -1 if not there, >6 for offset-method (max
79 BAR is 6) */
80 } addr[4];
81
82 /* If set, this is called immediately after pci_enable_device.
83 * If it returns non-zero, no probing will take place and the
84 * ports will not be used. */
85 int (*preinit_hook) (struct pci_dev *pdev, struct parport_pc_pci *card,
86 int autoirq, int autodma);
87
88 /* If set, this is called after probing for ports. If 'failed'
89 * is non-zero we couldn't use any of the ports. */
90 void (*postinit_hook) (struct pci_dev *pdev,
91 struct parport_pc_pci *card, int failed);
92};
93
Greg Kroah-Hartman312faca2012-12-21 13:23:14 -080094static int netmos_parallel_init(struct pci_dev *dev, struct parport_pc_pci *par,
95 int autoirq, int autodma)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Jiri Slaby3abdbf92009-02-11 13:04:40 -080097 /* the rule described below doesn't hold for this device */
98 if (dev->device == PCI_DEVICE_ID_NETMOS_9835 &&
99 dev->subsystem_vendor == PCI_VENDOR_ID_IBM &&
100 dev->subsystem_device == 0x0299)
101 return -ENODEV;
Nicos Gollan7808edc2011-05-05 21:00:37 +0200102
103 if (dev->device == PCI_DEVICE_ID_NETMOS_9912) {
104 par->numports = 1;
105 } else {
106 /*
107 * Netmos uses the subdevice ID to indicate the number of parallel
108 * and serial ports. The form is 0x00PS, where <P> is the number of
109 * parallel ports and <S> is the number of serial ports.
110 */
111 par->numports = (dev->subsystem_device & 0xf0) >> 4;
112 if (par->numports > ARRAY_SIZE(par->addr))
113 par->numports = ARRAY_SIZE(par->addr);
114 }
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return 0;
117}
118
Greg Kroah-Hartman312faca2012-12-21 13:23:14 -0800119static struct parport_pc_pci cards[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 /* titan_110l */ { 1, { { 3, -1 }, } },
121 /* titan_210l */ { 1, { { 3, -1 }, } },
122 /* netmos_9xx5_combo */ { 1, { { 2, -1 }, }, netmos_parallel_init },
Philippe De Muyter50db9d82009-04-02 16:58:53 -0700123 /* netmos_9855 */ { 1, { { 0, -1 }, }, netmos_parallel_init },
124 /* netmos_9855_2p */ { 2, { { 0, -1 }, { 2, -1 }, } },
Nicos Gollan7808edc2011-05-05 21:00:37 +0200125 /* netmos_9900 */ {1, { { 3, 4 }, }, netmos_parallel_init },
126 /* netmos_9900_2p */ {2, { { 0, 1 }, { 3, 4 }, } },
127 /* netmos_99xx_1p */ {1, { { 0, 1 }, } },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /* avlab_1s1p */ { 1, { { 1, 2}, } },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 /* avlab_1s2p */ { 2, { { 1, 2}, { 3, 4 },} },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 /* avlab_2s1p */ { 1, { { 2, 3}, } },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 /* siig_1s1p_10x */ { 1, { { 3, 4 }, } },
132 /* siig_2s1p_10x */ { 1, { { 4, 5 }, } },
133 /* siig_2p1s_20x */ { 2, { { 1, 2 }, { 3, 4 }, } },
134 /* siig_1s1p_20x */ { 1, { { 1, 2 }, } },
135 /* siig_2s1p_20x */ { 1, { { 2, 3 }, } },
Frédéric Brièreb9b24552011-05-29 15:08:04 -0400136 /* timedia_4078a */ { 1, { { 2, -1 }, } },
137 /* timedia_4079h */ { 1, { { 2, 3 }, } },
138 /* timedia_4085h */ { 2, { { 2, -1 }, { 4, -1 }, } },
139 /* timedia_4088a */ { 2, { { 2, 3 }, { 4, 5 }, } },
140 /* timedia_4089a */ { 2, { { 2, 3 }, { 4, 5 }, } },
141 /* timedia_4095a */ { 2, { { 2, 3 }, { 4, 5 }, } },
142 /* timedia_4096a */ { 2, { { 2, 3 }, { 4, 5 }, } },
143 /* timedia_4078u */ { 1, { { 2, -1 }, } },
144 /* timedia_4079a */ { 1, { { 2, 3 }, } },
145 /* timedia_4085u */ { 2, { { 2, -1 }, { 4, -1 }, } },
146 /* timedia_4079r */ { 1, { { 2, 3 }, } },
147 /* timedia_4079s */ { 1, { { 2, 3 }, } },
148 /* timedia_4079d */ { 1, { { 2, 3 }, } },
149 /* timedia_4079e */ { 1, { { 2, 3 }, } },
150 /* timedia_4079f */ { 1, { { 2, 3 }, } },
151 /* timedia_9079a */ { 1, { { 2, 3 }, } },
152 /* timedia_9079b */ { 1, { { 2, 3 }, } },
153 /* timedia_9079c */ { 1, { { 2, 3 }, } },
Ezequiel Garciafeb58142014-05-24 15:24:51 -0300154 /* wch_ch353_1s1p*/ { 1, { { 1, -1}, } },
Guainluca Anzolin6971c632012-09-04 15:56:12 +0100155 /* wch_ch353_2s1p*/ { 1, { { 2, -1}, } },
Sergej Pupykin2fdd8c82014-11-06 14:36:31 +0300156 /* wch_ch382_2s1p*/ { 1, { { 2, -1}, } },
Andy Shevchenkoec8e3892018-02-07 19:47:51 +0000157 /* brainboxes_5s1p */ { 1, { { 3, -1 }, } },
Stephen Chiversabd7bac2013-01-28 19:49:20 +1100158 /* sunix_2s1p */ { 1, { { 3, -1 }, } },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159};
160
Stephen Chiversabd7bac2013-01-28 19:49:20 +1100161#define PCI_VENDOR_ID_SUNIX 0x1fd4
162#define PCI_DEVICE_ID_SUNIX_1999 0x1999
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164static struct pci_device_id parport_serial_pci_tbl[] = {
165 /* PCI cards */
166 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_110L,
167 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_110l },
168 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_210L,
169 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_210l },
170 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9735,
171 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
172 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9745,
173 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
174 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835,
175 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9845,
177 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
178 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
Philippe De Muyter50db9d82009-04-02 16:58:53 -0700179 0x1000, 0x0020, 0, 0, netmos_9855_2p },
180 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
181 0x1000, 0x0022, 0, 0, netmos_9855_2p },
182 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
Martin Schitter44e58a62005-06-23 00:09:55 -0700183 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9855 },
Nicos Gollan7808edc2011-05-05 21:00:37 +0200184 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9900,
185 0xA000, 0x3011, 0, 0, netmos_9900 },
186 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9900,
187 0xA000, 0x3012, 0, 0, netmos_9900 },
188 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9900,
189 0xA000, 0x3020, 0, 0, netmos_9900_2p },
190 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9912,
191 0xA000, 0x2000, 0, 0, netmos_99xx_1p },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
Russell King91bca4b2006-03-20 20:08:22 +0000193 { PCI_VENDOR_ID_AFAVLAB, 0x2110,
194 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
195 { PCI_VENDOR_ID_AFAVLAB, 0x2111,
196 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
197 { PCI_VENDOR_ID_AFAVLAB, 0x2112,
198 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
199 { PCI_VENDOR_ID_AFAVLAB, 0x2140,
200 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
201 { PCI_VENDOR_ID_AFAVLAB, 0x2141,
202 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
203 { PCI_VENDOR_ID_AFAVLAB, 0x2142,
204 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
205 { PCI_VENDOR_ID_AFAVLAB, 0x2160,
206 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
207 { PCI_VENDOR_ID_AFAVLAB, 0x2161,
208 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
209 { PCI_VENDOR_ID_AFAVLAB, 0x2162,
210 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_550,
212 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
213 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_650,
214 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
215 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_850,
216 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
217 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_550,
218 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
219 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_650,
220 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
221 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_850,
222 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
223 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_550,
224 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
225 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_650,
226 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
227 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_850,
228 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
229 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_550,
230 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
231 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_650,
232 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
233 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_850,
234 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
235 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_550,
236 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
237 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_650,
238 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
239 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_850,
240 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
Frédéric Brièreb9b24552011-05-29 15:08:04 -0400241 /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/
242 { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a },
243 { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h },
244 { 0x1409, 0x7168, 0x1409, 0x4085, 0, 0, timedia_4085h },
245 { 0x1409, 0x7168, 0x1409, 0x4088, 0, 0, timedia_4088a },
246 { 0x1409, 0x7168, 0x1409, 0x4089, 0, 0, timedia_4089a },
247 { 0x1409, 0x7168, 0x1409, 0x4095, 0, 0, timedia_4095a },
248 { 0x1409, 0x7168, 0x1409, 0x4096, 0, 0, timedia_4096a },
249 { 0x1409, 0x7168, 0x1409, 0x5078, 0, 0, timedia_4078u },
250 { 0x1409, 0x7168, 0x1409, 0x5079, 0, 0, timedia_4079a },
251 { 0x1409, 0x7168, 0x1409, 0x5085, 0, 0, timedia_4085u },
252 { 0x1409, 0x7168, 0x1409, 0x6079, 0, 0, timedia_4079r },
253 { 0x1409, 0x7168, 0x1409, 0x7079, 0, 0, timedia_4079s },
254 { 0x1409, 0x7168, 0x1409, 0x8079, 0, 0, timedia_4079d },
255 { 0x1409, 0x7168, 0x1409, 0x9079, 0, 0, timedia_4079e },
256 { 0x1409, 0x7168, 0x1409, 0xa079, 0, 0, timedia_4079f },
257 { 0x1409, 0x7168, 0x1409, 0xb079, 0, 0, timedia_9079a },
258 { 0x1409, 0x7168, 0x1409, 0xc079, 0, 0, timedia_9079b },
259 { 0x1409, 0x7168, 0x1409, 0xd079, 0, 0, timedia_9079c },
Stephen Chiversabd7bac2013-01-28 19:49:20 +1100260
Guainluca Anzolin6971c632012-09-04 15:56:12 +0100261 /* WCH CARDS */
Ezequiel Garciafeb58142014-05-24 15:24:51 -0300262 { 0x4348, 0x5053, PCI_ANY_ID, PCI_ANY_ID, 0, 0, wch_ch353_1s1p},
Guainluca Anzolin6971c632012-09-04 15:56:12 +0100263 { 0x4348, 0x7053, 0x4348, 0x3253, 0, 0, wch_ch353_2s1p},
Sergej Pupykin2fdd8c82014-11-06 14:36:31 +0300264 { 0x1c00, 0x3250, 0x1c00, 0x3250, 0, 0, wch_ch382_2s1p},
Stephen Chiversabd7bac2013-01-28 19:49:20 +1100265
Andy Shevchenkoec8e3892018-02-07 19:47:51 +0000266 /* BrainBoxes PX272/PX306 MIO card */
267 { PCI_VENDOR_ID_INTASHIELD, 0x4100,
268 PCI_ANY_ID, PCI_ANY_ID, 0, 0, brainboxes_5s1p },
269
Stephen Chiversabd7bac2013-01-28 19:49:20 +1100270 /*
271 * More SUNIX variations. At least one of these has part number
272 * '5079A but subdevice 0x102. That board reports 0x0708 as
273 * its PCI Class.
274 */
275 { PCI_VENDOR_ID_SUNIX, PCI_DEVICE_ID_SUNIX_1999, PCI_VENDOR_ID_SUNIX,
276 0x0102, 0, 0, sunix_2s1p },
277
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 { 0, } /* terminate list */
279};
280MODULE_DEVICE_TABLE(pci,parport_serial_pci_tbl);
281
Russell King05caac52005-07-27 11:41:18 +0100282/*
283 * This table describes the serial "geometry" of these boards. Any
284 * quirks for these can be found in drivers/serial/8250_pci.c
285 *
286 * Cards not tested are marked n/t
287 * If you have one of these cards and it works for you, please tell me..
288 */
Greg Kroah-Hartman312faca2012-12-21 13:23:14 -0800289static struct pciserial_board pci_parport_serial_boards[] = {
Russell King05caac52005-07-27 11:41:18 +0100290 [titan_110l] = {
291 .flags = FL_BASE1 | FL_BASE_BARS,
292 .num_ports = 1,
293 .base_baud = 921600,
294 .uart_offset = 8,
295 },
296 [titan_210l] = {
297 .flags = FL_BASE1 | FL_BASE_BARS,
298 .num_ports = 2,
299 .base_baud = 921600,
300 .uart_offset = 8,
301 },
302 [netmos_9xx5_combo] = {
303 .flags = FL_BASE0 | FL_BASE_BARS,
304 .num_ports = 1,
305 .base_baud = 115200,
306 .uart_offset = 8,
307 },
308 [netmos_9855] = {
Philippe De Muyter50db9d82009-04-02 16:58:53 -0700309 .flags = FL_BASE2 | FL_BASE_BARS,
310 .num_ports = 1,
311 .base_baud = 115200,
312 .uart_offset = 8,
313 },
314 [netmos_9855_2p] = {
Christian Pellegrinc01106e2008-02-06 01:37:44 -0800315 .flags = FL_BASE4 | FL_BASE_BARS,
Russell King05caac52005-07-27 11:41:18 +0100316 .num_ports = 1,
317 .base_baud = 115200,
318 .uart_offset = 8,
319 },
Nicos Gollan7808edc2011-05-05 21:00:37 +0200320 [netmos_9900] = { /* n/t */
321 .flags = FL_BASE0 | FL_BASE_BARS,
322 .num_ports = 1,
323 .base_baud = 115200,
324 .uart_offset = 8,
325 },
326 [netmos_9900_2p] = { /* parallel only */ /* n/t */
327 .flags = FL_BASE0,
328 .num_ports = 0,
329 .base_baud = 115200,
330 .uart_offset = 8,
331 },
332 [netmos_99xx_1p] = { /* parallel only */ /* n/t */
333 .flags = FL_BASE0,
334 .num_ports = 0,
335 .base_baud = 115200,
336 .uart_offset = 8,
337 },
Russell King05caac52005-07-27 11:41:18 +0100338 [avlab_1s1p] = { /* n/t */
339 .flags = FL_BASE0 | FL_BASE_BARS,
340 .num_ports = 1,
341 .base_baud = 115200,
342 .uart_offset = 8,
343 },
Russell King05caac52005-07-27 11:41:18 +0100344 [avlab_1s2p] = { /* n/t */
345 .flags = FL_BASE0 | FL_BASE_BARS,
346 .num_ports = 1,
347 .base_baud = 115200,
348 .uart_offset = 8,
349 },
Russell King05caac52005-07-27 11:41:18 +0100350 [avlab_2s1p] = { /* n/t */
351 .flags = FL_BASE0 | FL_BASE_BARS,
352 .num_ports = 2,
353 .base_baud = 115200,
354 .uart_offset = 8,
355 },
Russell King05caac52005-07-27 11:41:18 +0100356 [siig_1s1p_10x] = {
357 .flags = FL_BASE2,
358 .num_ports = 1,
359 .base_baud = 460800,
360 .uart_offset = 8,
361 },
362 [siig_2s1p_10x] = {
363 .flags = FL_BASE2,
364 .num_ports = 1,
365 .base_baud = 921600,
366 .uart_offset = 8,
367 },
368 [siig_2p1s_20x] = {
369 .flags = FL_BASE0,
370 .num_ports = 1,
371 .base_baud = 921600,
372 .uart_offset = 8,
373 },
374 [siig_1s1p_20x] = {
375 .flags = FL_BASE0,
376 .num_ports = 1,
377 .base_baud = 921600,
378 .uart_offset = 8,
379 },
380 [siig_2s1p_20x] = {
381 .flags = FL_BASE0,
382 .num_ports = 1,
383 .base_baud = 921600,
384 .uart_offset = 8,
385 },
Frédéric Brièreb9b24552011-05-29 15:08:04 -0400386 [timedia_4078a] = {
387 .flags = FL_BASE0|FL_BASE_BARS,
388 .num_ports = 1,
389 .base_baud = 921600,
390 .uart_offset = 8,
391 },
392 [timedia_4079h] = {
393 .flags = FL_BASE0|FL_BASE_BARS,
394 .num_ports = 1,
395 .base_baud = 921600,
396 .uart_offset = 8,
397 },
398 [timedia_4085h] = {
399 .flags = FL_BASE0|FL_BASE_BARS,
400 .num_ports = 1,
401 .base_baud = 921600,
402 .uart_offset = 8,
403 },
404 [timedia_4088a] = {
405 .flags = FL_BASE0|FL_BASE_BARS,
406 .num_ports = 1,
407 .base_baud = 921600,
408 .uart_offset = 8,
409 },
410 [timedia_4089a] = {
411 .flags = FL_BASE0|FL_BASE_BARS,
412 .num_ports = 1,
413 .base_baud = 921600,
414 .uart_offset = 8,
415 },
416 [timedia_4095a] = {
417 .flags = FL_BASE0|FL_BASE_BARS,
418 .num_ports = 1,
419 .base_baud = 921600,
420 .uart_offset = 8,
421 },
422 [timedia_4096a] = {
423 .flags = FL_BASE0|FL_BASE_BARS,
424 .num_ports = 1,
425 .base_baud = 921600,
426 .uart_offset = 8,
427 },
428 [timedia_4078u] = {
429 .flags = FL_BASE0|FL_BASE_BARS,
430 .num_ports = 1,
431 .base_baud = 921600,
432 .uart_offset = 8,
433 },
434 [timedia_4079a] = {
435 .flags = FL_BASE0|FL_BASE_BARS,
436 .num_ports = 1,
437 .base_baud = 921600,
438 .uart_offset = 8,
439 },
440 [timedia_4085u] = {
441 .flags = FL_BASE0|FL_BASE_BARS,
442 .num_ports = 1,
443 .base_baud = 921600,
444 .uart_offset = 8,
445 },
446 [timedia_4079r] = {
447 .flags = FL_BASE0|FL_BASE_BARS,
448 .num_ports = 1,
449 .base_baud = 921600,
450 .uart_offset = 8,
451 },
452 [timedia_4079s] = {
453 .flags = FL_BASE0|FL_BASE_BARS,
454 .num_ports = 1,
455 .base_baud = 921600,
456 .uart_offset = 8,
457 },
458 [timedia_4079d] = {
459 .flags = FL_BASE0|FL_BASE_BARS,
460 .num_ports = 1,
461 .base_baud = 921600,
462 .uart_offset = 8,
463 },
464 [timedia_4079e] = {
465 .flags = FL_BASE0|FL_BASE_BARS,
466 .num_ports = 1,
467 .base_baud = 921600,
468 .uart_offset = 8,
469 },
470 [timedia_4079f] = {
471 .flags = FL_BASE0|FL_BASE_BARS,
472 .num_ports = 1,
473 .base_baud = 921600,
474 .uart_offset = 8,
475 },
476 [timedia_9079a] = {
477 .flags = FL_BASE0|FL_BASE_BARS,
478 .num_ports = 1,
479 .base_baud = 921600,
480 .uart_offset = 8,
481 },
482 [timedia_9079b] = {
483 .flags = FL_BASE0|FL_BASE_BARS,
484 .num_ports = 1,
485 .base_baud = 921600,
486 .uart_offset = 8,
487 },
488 [timedia_9079c] = {
489 .flags = FL_BASE0|FL_BASE_BARS,
490 .num_ports = 1,
491 .base_baud = 921600,
492 .uart_offset = 8,
493 },
Ezequiel Garciafeb58142014-05-24 15:24:51 -0300494 [wch_ch353_1s1p] = {
495 .flags = FL_BASE0|FL_BASE_BARS,
496 .num_ports = 1,
497 .base_baud = 115200,
498 .uart_offset = 8,
499 },
Guainluca Anzolin6971c632012-09-04 15:56:12 +0100500 [wch_ch353_2s1p] = {
501 .flags = FL_BASE0|FL_BASE_BARS,
502 .num_ports = 2,
503 .base_baud = 115200,
504 .uart_offset = 8,
505 },
Sergej Pupykin2fdd8c82014-11-06 14:36:31 +0300506 [wch_ch382_2s1p] = {
507 .flags = FL_BASE0,
508 .num_ports = 2,
509 .base_baud = 115200,
510 .uart_offset = 8,
511 .first_offset = 0xC0,
512 },
Andy Shevchenkoec8e3892018-02-07 19:47:51 +0000513 [brainboxes_5s1p] = {
514 .flags = FL_BASE2,
515 .num_ports = 5,
516 .base_baud = 921600,
517 .uart_offset = 8,
518 },
Stephen Chiversabd7bac2013-01-28 19:49:20 +1100519 [sunix_2s1p] = {
520 .flags = FL_BASE0|FL_BASE_BARS,
521 .num_ports = 2,
522 .base_baud = 921600,
523 .uart_offset = 8,
524 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525};
526
527struct parport_serial_private {
Russell King05caac52005-07-27 11:41:18 +0100528 struct serial_private *serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 int num_par;
530 struct parport *port[PARPORT_MAX];
531 struct parport_pc_pci par;
532};
533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534/* Register the serial port(s) of a PCI card. */
Greg Kroah-Hartman312faca2012-12-21 13:23:14 -0800535static int serial_register(struct pci_dev *dev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 struct parport_serial_private *priv = pci_get_drvdata (dev);
Russell King05caac52005-07-27 11:41:18 +0100538 struct pciserial_board *board;
539 struct serial_private *serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Russell King05caac52005-07-27 11:41:18 +0100541 board = &pci_parport_serial_boards[id->driver_data];
Nicos Gollan7808edc2011-05-05 21:00:37 +0200542 if (board->num_ports == 0)
543 return 0;
544
Russell King05caac52005-07-27 11:41:18 +0100545 serial = pciserial_init_ports(dev, board);
Russell King05caac52005-07-27 11:41:18 +0100546 if (IS_ERR(serial))
547 return PTR_ERR(serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Russell King05caac52005-07-27 11:41:18 +0100549 priv->serial = serial;
550 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551}
552
553/* Register the parallel port(s) of a PCI card. */
Greg Kroah-Hartman312faca2012-12-21 13:23:14 -0800554static int parport_register(struct pci_dev *dev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
556 struct parport_pc_pci *card;
557 struct parport_serial_private *priv = pci_get_drvdata (dev);
Russell King7a171cd2006-03-05 00:31:22 +0000558 int n, success = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
560 priv->par = cards[id->driver_data];
561 card = &priv->par;
562 if (card->preinit_hook &&
563 card->preinit_hook (dev, card, PARPORT_IRQ_NONE, PARPORT_DMA_NONE))
564 return -ENODEV;
565
566 for (n = 0; n < card->numports; n++) {
567 struct parport *port;
568 int lo = card->addr[n].lo;
569 int hi = card->addr[n].hi;
570 unsigned long io_lo, io_hi;
Alan Cox51dcdfe2009-04-07 15:30:57 +0100571 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 if (priv->num_par == ARRAY_SIZE (priv->port)) {
Andy Shevchenko82dfabf2018-02-07 19:47:55 +0000574 dev_warn(&dev->dev,
575 "only %zu parallel ports supported (%d reported)\n",
576 ARRAY_SIZE(priv->port), card->numports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 break;
578 }
579
580 io_lo = pci_resource_start (dev, lo);
581 io_hi = 0;
582 if ((hi >= 0) && (hi <= 6))
583 io_hi = pci_resource_start (dev, hi);
584 else if (hi > 6)
585 io_lo += hi; /* Reinterpret the meaning of
586 "hi" as an offset (see SYBA
587 def.) */
588 /* TODO: test if sharing interrupts works */
Alan Cox51dcdfe2009-04-07 15:30:57 +0100589 irq = dev->irq;
590 if (irq == IRQ_NONE) {
591 dev_dbg(&dev->dev,
Andy Shevchenko82dfabf2018-02-07 19:47:55 +0000592 "PCI parallel port detected: I/O at %#lx(%#lx)\n",
Alan Cox51dcdfe2009-04-07 15:30:57 +0100593 io_lo, io_hi);
594 irq = PARPORT_IRQ_NONE;
595 } else {
596 dev_dbg(&dev->dev,
Andy Shevchenko82dfabf2018-02-07 19:47:55 +0000597 "PCI parallel port detected: I/O at %#lx(%#lx), IRQ %d\n",
Alan Cox51dcdfe2009-04-07 15:30:57 +0100598 io_lo, io_hi, irq);
Alan Cox51dcdfe2009-04-07 15:30:57 +0100599 }
600 port = parport_pc_probe_port (io_lo, io_hi, irq,
601 PARPORT_DMA_NONE, &dev->dev, IRQF_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 if (port) {
603 priv->port[priv->num_par++] = port;
604 success = 1;
605 }
606 }
607
608 if (card->postinit_hook)
609 card->postinit_hook (dev, card, !success);
610
Russell King7a171cd2006-03-05 00:31:22 +0000611 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612}
613
Greg Kroah-Hartman312faca2012-12-21 13:23:14 -0800614static int parport_serial_pci_probe(struct pci_dev *dev,
615 const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616{
617 struct parport_serial_private *priv;
618 int err;
619
Andy Shevchenkoad8ce832018-02-07 19:47:53 +0000620 priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 if (!priv)
622 return -ENOMEM;
Andy Shevchenkoad8ce832018-02-07 19:47:53 +0000623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 pci_set_drvdata (dev, priv);
625
Andy Shevchenkoad8ce832018-02-07 19:47:53 +0000626 err = pcim_enable_device(dev);
627 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Andy Shevchenko96edf532018-02-07 19:47:54 +0000630 err = parport_register(dev, id);
631 if (err)
632 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Andy Shevchenko96edf532018-02-07 19:47:54 +0000634 err = serial_register(dev, id);
635 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 int i;
637 for (i = 0; i < priv->num_par; i++)
638 parport_pc_unregister_port (priv->port[i]);
Andy Shevchenko96edf532018-02-07 19:47:54 +0000639 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
641
642 return 0;
643}
644
Greg Kroah-Hartman312faca2012-12-21 13:23:14 -0800645static void parport_serial_pci_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646{
647 struct parport_serial_private *priv = pci_get_drvdata (dev);
648 int i;
649
Russell King05caac52005-07-27 11:41:18 +0100650 // Serial ports
651 if (priv->serial)
652 pciserial_remove_ports(priv->serial);
653
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 // Parallel ports
655 for (i = 0; i < priv->num_par; i++)
656 parport_pc_unregister_port (priv->port[i]);
657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 return;
659}
660
Andy Shevchenko1089c912018-02-07 19:47:52 +0000661static int __maybe_unused parport_serial_pci_suspend(struct device *dev)
Russell King05caac52005-07-27 11:41:18 +0100662{
Andy Shevchenko1089c912018-02-07 19:47:52 +0000663 struct pci_dev *pdev = to_pci_dev(dev);
664 struct parport_serial_private *priv = pci_get_drvdata(pdev);
Russell King05caac52005-07-27 11:41:18 +0100665
666 if (priv->serial)
667 pciserial_suspend_ports(priv->serial);
668
669 /* FIXME: What about parport? */
Russell King05caac52005-07-27 11:41:18 +0100670 return 0;
671}
672
Andy Shevchenko1089c912018-02-07 19:47:52 +0000673static int __maybe_unused parport_serial_pci_resume(struct device *dev)
Russell King05caac52005-07-27 11:41:18 +0100674{
Andy Shevchenko1089c912018-02-07 19:47:52 +0000675 struct pci_dev *pdev = to_pci_dev(dev);
676 struct parport_serial_private *priv = pci_get_drvdata(pdev);
Russell King05caac52005-07-27 11:41:18 +0100677
678 if (priv->serial)
679 pciserial_resume_ports(priv->serial);
680
681 /* FIXME: What about parport? */
Russell King05caac52005-07-27 11:41:18 +0100682 return 0;
683}
Andy Shevchenko1089c912018-02-07 19:47:52 +0000684
685static SIMPLE_DEV_PM_OPS(parport_serial_pm_ops,
686 parport_serial_pci_suspend, parport_serial_pci_resume);
Russell King05caac52005-07-27 11:41:18 +0100687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688static struct pci_driver parport_serial_pci_driver = {
689 .name = "parport_serial",
690 .id_table = parport_serial_pci_tbl,
691 .probe = parport_serial_pci_probe,
Greg Kroah-Hartman312faca2012-12-21 13:23:14 -0800692 .remove = parport_serial_pci_remove,
Andy Shevchenko1089c912018-02-07 19:47:52 +0000693 .driver = {
694 .pm = &parport_serial_pm_ops,
695 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696};
Andy Shevchenkob0b0a642018-02-07 19:47:56 +0000697module_pci_driver(parport_serial_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699MODULE_AUTHOR("Tim Waugh <twaugh@redhat.com>");
700MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards");
701MODULE_LICENSE("GPL");