]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/parport/parport_serial.c
[SERIAL] Expose 8250_pci setup/removal/suspend/resume functions
[mirror_ubuntu-artful-kernel.git] / drivers / parport / parport_serial.c
CommitLineData
1da177e4
LT
1/*
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
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>
30
31#include <asm/serial.h>
32
33enum parport_pc_pci_cards {
34 titan_110l = 0,
35 titan_210l,
36 netmos_9xx5_combo,
44e58a6a 37 netmos_9855,
1da177e4
LT
38 avlab_1s1p,
39 avlab_1s1p_650,
40 avlab_1s1p_850,
41 avlab_1s2p,
42 avlab_1s2p_650,
43 avlab_1s2p_850,
44 avlab_2s1p,
45 avlab_2s1p_650,
46 avlab_2s1p_850,
47 siig_1s1p_10x,
48 siig_2s1p_10x,
49 siig_2p1s_20x,
50 siig_1s1p_20x,
51 siig_2s1p_20x,
52};
53
54/* each element directly indexed from enum list, above */
55struct parport_pc_pci {
56 int numports;
57 struct { /* BAR (base address registers) numbers in the config
58 space header */
59 int lo;
60 int hi; /* -1 if not there, >6 for offset-method (max
61 BAR is 6) */
62 } addr[4];
63
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);
69
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);
74};
75
76static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc_pci *card, int autoirq, int autodma)
77{
78 /*
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.
82 */
83 card->numports = (dev->subsystem_device & 0xf0) >> 4;
84 return 0;
85}
86
87static 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 },
44e58a6a 91 /* netmos_9855 */ { 1, { { 0, -1 }, }, netmos_parallel_init },
1da177e4
LT
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 }, } },
106};
107
108static struct pci_device_id parport_serial_pci_tbl[] = {
109 /* PCI cards */
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,
44e58a6a 125 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9855 },
1da177e4
LT
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 },
166
167 { 0, } /* terminate list */
168};
169MODULE_DEVICE_TABLE(pci,parport_serial_pci_tbl);
170
171struct pci_board_no_ids {
172 int flags;
173 int num_ports;
174 int base_baud;
175 int uart_offset;
176 int reg_shift;
177 int (*init_fn)(struct pci_dev *dev, struct pci_board_no_ids *board,
178 int enable);
179 int first_uart_offset;
180};
181
182static int __devinit siig10x_init_fn(struct pci_dev *dev, struct pci_board_no_ids *board, int enable)
183{
184 return pci_siig10x_fn(dev, enable);
185}
186
187static int __devinit siig20x_init_fn(struct pci_dev *dev, struct pci_board_no_ids *board, int enable)
188{
189 return pci_siig20x_fn(dev, enable);
190}
191
192static int __devinit netmos_serial_init(struct pci_dev *dev, struct pci_board_no_ids *board, int enable)
193{
194 board->num_ports = dev->subsystem_device & 0xf;
195 return 0;
196}
197
198static struct pci_board_no_ids pci_boards[] __devinitdata = {
199 /*
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
204 */
205
206// Cards not tested are marked n/t
207// If you have one of these cards and it works for you, please tell me..
208
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 },
44e58a6a 212/* netmos_9855 */ { SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 1, 115200, 0, 0, netmos_serial_init },
1da177e4
LT
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 },
227};
228
229struct parport_serial_private {
230 int num_ser;
231 int line[20];
232 struct pci_board_no_ids ser;
233 int num_par;
234 struct parport *port[PARPORT_MAX];
235 struct parport_pc_pci par;
236};
237
238static int __devinit get_pci_port (struct pci_dev *dev,
239 struct pci_board_no_ids *board,
240 struct serial_struct *req,
241 int idx)
242{
243 unsigned long port;
244 int base_idx;
245 int max_port;
246 int offset;
247
248 base_idx = SPCI_FL_GET_BASE(board->flags);
249 if (board->flags & SPCI_FL_BASE_TABLE)
250 base_idx += idx;
251
252 if (board->flags & SPCI_FL_REGION_SZ_CAP) {
253 max_port = pci_resource_len(dev, base_idx) / 8;
254 if (idx >= max_port)
255 return 1;
256 }
257
258 offset = board->first_uart_offset;
259
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 */
263 switch(idx) {
264 case 0: base_idx=0;
265 break;
266 case 1: base_idx=0; offset=8;
267 break;
268 case 2: base_idx=1;
269 break;
270 case 3: base_idx=1; offset=8;
271 break;
272 case 4: /* BAR 2*/
273 case 5: /* BAR 3 */
274 case 6: /* BAR 4*/
275 case 7: base_idx=idx-2; /* BAR 5*/
276 }
277
278 port = pci_resource_start(dev, base_idx) + offset;
279
280 if ((board->flags & SPCI_FL_BASE_TABLE) == 0)
281 port += idx * (board->uart_offset ? board->uart_offset : 8);
282
283 if (pci_resource_flags (dev, base_idx) & IORESOURCE_IO) {
284 int high_bits_offset = ((sizeof(long)-sizeof(int))*8);
285 req->port = port;
286 if (high_bits_offset)
287 req->port_high = port >> high_bits_offset;
288 else
289 req->port_high = 0;
290 return 0;
291 }
292 req->io_type = SERIAL_IO_MEM;
293 req->iomem_base = ioremap(port, board->uart_offset);
294 req->iomem_reg_shift = board->reg_shift;
295 req->port = 0;
296 return req->iomem_base ? 0 : 1;
297}
298
299/* Register the serial port(s) of a PCI card. */
300static int __devinit serial_register (struct pci_dev *dev,
301 const struct pci_device_id *id)
302{
303 struct pci_board_no_ids *board;
304 struct parport_serial_private *priv = pci_get_drvdata (dev);
305 struct serial_struct serial_req;
306 int base_baud;
307 int k;
308 int success = 0;
309
310 priv->ser = pci_boards[id->driver_data];
311 board = &priv->ser;
312 if (board->init_fn && ((board->init_fn) (dev, board, 1) != 0))
313 return 1;
314
315 base_baud = board->base_baud;
316 if (!base_baud)
317 base_baud = BASE_BAUD;
318 memset (&serial_req, 0, sizeof (serial_req));
319
320 for (k = 0; k < board->num_ports; k++) {
321 int line;
322
323 if (priv->num_ser == ARRAY_SIZE (priv->line)) {
324 printk (KERN_WARNING
325 "parport_serial: %s: only %u serial lines "
326 "supported (%d reported)\n", pci_name (dev),
327 ARRAY_SIZE (priv->line), board->num_ports);
328 break;
329 }
330
331 serial_req.irq = dev->irq;
332 if (get_pci_port (dev, board, &serial_req, k))
333 break;
334 serial_req.flags = ASYNC_SKIP_TEST | ASYNC_AUTOPROBE;
335 serial_req.baud_base = base_baud;
336 line = register_serial (&serial_req);
337 if (line < 0) {
338 printk (KERN_DEBUG
339 "parport_serial: register_serial failed\n");
340 continue;
341 }
342 priv->line[priv->num_ser++] = line;
343 success = 1;
344 }
345
346 return success ? 0 : 1;
347}
348
349/* Register the parallel port(s) of a PCI card. */
350static int __devinit parport_register (struct pci_dev *dev,
351 const struct pci_device_id *id)
352{
353 struct parport_pc_pci *card;
354 struct parport_serial_private *priv = pci_get_drvdata (dev);
355 int i = id->driver_data, n;
356 int success = 0;
357
358 priv->par = cards[id->driver_data];
359 card = &priv->par;
360 if (card->preinit_hook &&
361 card->preinit_hook (dev, card, PARPORT_IRQ_NONE, PARPORT_DMA_NONE))
362 return -ENODEV;
363
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;
369
370 if (priv->num_par == ARRAY_SIZE (priv->port)) {
371 printk (KERN_WARNING
372 "parport_serial: %s: only %u parallel ports "
373 "supported (%d reported)\n", pci_name (dev),
374 ARRAY_SIZE (priv->port), card->numports);
375 break;
376 }
377
378 io_lo = pci_resource_start (dev, lo);
379 io_hi = 0;
380 if ((hi >= 0) && (hi <= 6))
381 io_hi = pci_resource_start (dev, hi);
382 else if (hi > 6)
383 io_lo += hi; /* Reinterpret the meaning of
384 "hi" as an offset (see SYBA
385 def.) */
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);
393 if (port) {
394 priv->port[priv->num_par++] = port;
395 success = 1;
396 }
397 }
398
399 if (card->postinit_hook)
400 card->postinit_hook (dev, card, !success);
401
402 return success ? 0 : 1;
403}
404
405static int __devinit parport_serial_pci_probe (struct pci_dev *dev,
406 const struct pci_device_id *id)
407{
408 struct parport_serial_private *priv;
409 int err;
410
411 priv = kmalloc (sizeof *priv, GFP_KERNEL);
412 if (!priv)
413 return -ENOMEM;
414 priv->num_ser = priv->num_par = 0;
415 pci_set_drvdata (dev, priv);
416
417 err = pci_enable_device (dev);
418 if (err) {
419 pci_set_drvdata (dev, NULL);
420 kfree (priv);
421 return err;
422 }
423
424 if (parport_register (dev, id)) {
425 pci_set_drvdata (dev, NULL);
426 kfree (priv);
427 return -ENODEV;
428 }
429
430 if (serial_register (dev, id)) {
431 int i;
432 for (i = 0; i < priv->num_par; i++)
433 parport_pc_unregister_port (priv->port[i]);
434 pci_set_drvdata (dev, NULL);
435 kfree (priv);
436 return -ENODEV;
437 }
438
439 return 0;
440}
441
442static void __devexit parport_serial_pci_remove (struct pci_dev *dev)
443{
444 struct parport_serial_private *priv = pci_get_drvdata (dev);
445 int i;
446
447 // Serial ports
448 for (i = 0; i < priv->num_ser; i++) {
449 unregister_serial (priv->line[i]);
450
451 if (priv->ser.init_fn)
452 (priv->ser.init_fn) (dev, &priv->ser, 0);
453 }
454 pci_set_drvdata (dev, NULL);
455
456 // Parallel ports
457 for (i = 0; i < priv->num_par; i++)
458 parport_pc_unregister_port (priv->port[i]);
459
460 kfree (priv);
461 return;
462}
463
464static 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),
469};
470
471
472static int __init parport_serial_init (void)
473{
474 return pci_module_init (&parport_serial_pci_driver);
475}
476
477static void __exit parport_serial_exit (void)
478{
479 pci_unregister_driver (&parport_serial_pci_driver);
480 return;
481}
482
483MODULE_AUTHOR("Tim Waugh <twaugh@redhat.com>");
484MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards");
485MODULE_LICENSE("GPL");
486
487module_init(parport_serial_init);
488module_exit(parport_serial_exit);