x86, mce, cmci: disable CMCI on rebooting
[linux-2.6/mini2440.git] / drivers / parport / parport_serial.c
blob032db815b0f9784f6835548d68333edc4c376022
1 /*
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
16 * that.
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/8250_pci.h>
28 enum parport_pc_pci_cards {
29 titan_110l = 0,
30 titan_210l,
31 netmos_9xx5_combo,
32 netmos_9855,
33 avlab_1s1p,
34 avlab_1s2p,
35 avlab_2s1p,
36 siig_1s1p_10x,
37 siig_2s1p_10x,
38 siig_2p1s_20x,
39 siig_1s1p_20x,
40 siig_2s1p_20x,
43 /* each element directly indexed from enum list, above */
44 struct parport_pc_pci {
45 int numports;
46 struct { /* BAR (base address registers) numbers in the config
47 space header */
48 int lo;
49 int hi; /* -1 if not there, >6 for offset-method (max
50 BAR is 6) */
51 } addr[4];
53 /* If set, this is called immediately after pci_enable_device.
54 * If it returns non-zero, no probing will take place and the
55 * ports will not be used. */
56 int (*preinit_hook) (struct pci_dev *pdev, struct parport_pc_pci *card,
57 int autoirq, int autodma);
59 /* If set, this is called after probing for ports. If 'failed'
60 * is non-zero we couldn't use any of the ports. */
61 void (*postinit_hook) (struct pci_dev *pdev,
62 struct parport_pc_pci *card, int failed);
65 static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc_pci *card, int autoirq, int autodma)
67 /* the rule described below doesn't hold for this device */
68 if (dev->device == PCI_DEVICE_ID_NETMOS_9835 &&
69 dev->subsystem_vendor == PCI_VENDOR_ID_IBM &&
70 dev->subsystem_device == 0x0299)
71 return -ENODEV;
73 * Netmos uses the subdevice ID to indicate the number of parallel
74 * and serial ports. The form is 0x00PS, where <P> is the number of
75 * parallel ports and <S> is the number of serial ports.
77 card->numports = (dev->subsystem_device & 0xf0) >> 4;
78 if (card->numports > ARRAY_SIZE(card->addr))
79 card->numports = ARRAY_SIZE(card->addr);
80 return 0;
83 static struct parport_pc_pci cards[] __devinitdata = {
84 /* titan_110l */ { 1, { { 3, -1 }, } },
85 /* titan_210l */ { 1, { { 3, -1 }, } },
86 /* netmos_9xx5_combo */ { 1, { { 2, -1 }, }, netmos_parallel_init },
87 /* netmos_9855 */ { 1, { { 2, -1 }, }, netmos_parallel_init },
88 /* avlab_1s1p */ { 1, { { 1, 2}, } },
89 /* avlab_1s2p */ { 2, { { 1, 2}, { 3, 4 },} },
90 /* avlab_2s1p */ { 1, { { 2, 3}, } },
91 /* siig_1s1p_10x */ { 1, { { 3, 4 }, } },
92 /* siig_2s1p_10x */ { 1, { { 4, 5 }, } },
93 /* siig_2p1s_20x */ { 2, { { 1, 2 }, { 3, 4 }, } },
94 /* siig_1s1p_20x */ { 1, { { 1, 2 }, } },
95 /* siig_2s1p_20x */ { 1, { { 2, 3 }, } },
98 static struct pci_device_id parport_serial_pci_tbl[] = {
99 /* PCI cards */
100 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_110L,
101 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_110l },
102 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_210L,
103 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_210l },
104 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9735,
105 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
106 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9745,
107 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
108 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835,
109 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
110 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9845,
111 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
112 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
113 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9855 },
114 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
115 { PCI_VENDOR_ID_AFAVLAB, 0x2110,
116 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
117 { PCI_VENDOR_ID_AFAVLAB, 0x2111,
118 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
119 { PCI_VENDOR_ID_AFAVLAB, 0x2112,
120 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
121 { PCI_VENDOR_ID_AFAVLAB, 0x2140,
122 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
123 { PCI_VENDOR_ID_AFAVLAB, 0x2141,
124 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
125 { PCI_VENDOR_ID_AFAVLAB, 0x2142,
126 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
127 { PCI_VENDOR_ID_AFAVLAB, 0x2160,
128 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
129 { PCI_VENDOR_ID_AFAVLAB, 0x2161,
130 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
131 { PCI_VENDOR_ID_AFAVLAB, 0x2162,
132 PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
133 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_550,
134 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
135 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_650,
136 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
137 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_850,
138 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
139 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_550,
140 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
141 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_650,
142 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
143 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_850,
144 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
145 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_550,
146 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
147 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_650,
148 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
149 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_850,
150 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
151 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_550,
152 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
153 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_650,
154 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
155 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_850,
156 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
157 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_550,
158 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
159 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_650,
160 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
161 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_850,
162 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
164 { 0, } /* terminate list */
166 MODULE_DEVICE_TABLE(pci,parport_serial_pci_tbl);
169 * This table describes the serial "geometry" of these boards. Any
170 * quirks for these can be found in drivers/serial/8250_pci.c
172 * Cards not tested are marked n/t
173 * If you have one of these cards and it works for you, please tell me..
175 static struct pciserial_board pci_parport_serial_boards[] __devinitdata = {
176 [titan_110l] = {
177 .flags = FL_BASE1 | FL_BASE_BARS,
178 .num_ports = 1,
179 .base_baud = 921600,
180 .uart_offset = 8,
182 [titan_210l] = {
183 .flags = FL_BASE1 | FL_BASE_BARS,
184 .num_ports = 2,
185 .base_baud = 921600,
186 .uart_offset = 8,
188 [netmos_9xx5_combo] = {
189 .flags = FL_BASE0 | FL_BASE_BARS,
190 .num_ports = 1,
191 .base_baud = 115200,
192 .uart_offset = 8,
194 [netmos_9855] = {
195 .flags = FL_BASE4 | FL_BASE_BARS,
196 .num_ports = 1,
197 .base_baud = 115200,
198 .uart_offset = 8,
200 [avlab_1s1p] = { /* n/t */
201 .flags = FL_BASE0 | FL_BASE_BARS,
202 .num_ports = 1,
203 .base_baud = 115200,
204 .uart_offset = 8,
206 [avlab_1s2p] = { /* n/t */
207 .flags = FL_BASE0 | FL_BASE_BARS,
208 .num_ports = 1,
209 .base_baud = 115200,
210 .uart_offset = 8,
212 [avlab_2s1p] = { /* n/t */
213 .flags = FL_BASE0 | FL_BASE_BARS,
214 .num_ports = 2,
215 .base_baud = 115200,
216 .uart_offset = 8,
218 [siig_1s1p_10x] = {
219 .flags = FL_BASE2,
220 .num_ports = 1,
221 .base_baud = 460800,
222 .uart_offset = 8,
224 [siig_2s1p_10x] = {
225 .flags = FL_BASE2,
226 .num_ports = 1,
227 .base_baud = 921600,
228 .uart_offset = 8,
230 [siig_2p1s_20x] = {
231 .flags = FL_BASE0,
232 .num_ports = 1,
233 .base_baud = 921600,
234 .uart_offset = 8,
236 [siig_1s1p_20x] = {
237 .flags = FL_BASE0,
238 .num_ports = 1,
239 .base_baud = 921600,
240 .uart_offset = 8,
242 [siig_2s1p_20x] = {
243 .flags = FL_BASE0,
244 .num_ports = 1,
245 .base_baud = 921600,
246 .uart_offset = 8,
250 struct parport_serial_private {
251 struct serial_private *serial;
252 int num_par;
253 struct parport *port[PARPORT_MAX];
254 struct parport_pc_pci par;
257 /* Register the serial port(s) of a PCI card. */
258 static int __devinit serial_register (struct pci_dev *dev,
259 const struct pci_device_id *id)
261 struct parport_serial_private *priv = pci_get_drvdata (dev);
262 struct pciserial_board *board;
263 struct serial_private *serial;
265 board = &pci_parport_serial_boards[id->driver_data];
266 serial = pciserial_init_ports(dev, board);
268 if (IS_ERR(serial))
269 return PTR_ERR(serial);
271 priv->serial = serial;
272 return 0;
275 /* Register the parallel port(s) of a PCI card. */
276 static int __devinit parport_register (struct pci_dev *dev,
277 const struct pci_device_id *id)
279 struct parport_pc_pci *card;
280 struct parport_serial_private *priv = pci_get_drvdata (dev);
281 int n, success = 0;
283 priv->par = cards[id->driver_data];
284 card = &priv->par;
285 if (card->preinit_hook &&
286 card->preinit_hook (dev, card, PARPORT_IRQ_NONE, PARPORT_DMA_NONE))
287 return -ENODEV;
289 for (n = 0; n < card->numports; n++) {
290 struct parport *port;
291 int lo = card->addr[n].lo;
292 int hi = card->addr[n].hi;
293 unsigned long io_lo, io_hi;
295 if (priv->num_par == ARRAY_SIZE (priv->port)) {
296 printk (KERN_WARNING
297 "parport_serial: %s: only %zu parallel ports "
298 "supported (%d reported)\n", pci_name (dev),
299 ARRAY_SIZE(priv->port), card->numports);
300 break;
303 io_lo = pci_resource_start (dev, lo);
304 io_hi = 0;
305 if ((hi >= 0) && (hi <= 6))
306 io_hi = pci_resource_start (dev, hi);
307 else if (hi > 6)
308 io_lo += hi; /* Reinterpret the meaning of
309 "hi" as an offset (see SYBA
310 def.) */
311 /* TODO: test if sharing interrupts works */
312 dev_dbg(&dev->dev, "PCI parallel port detected: I/O at "
313 "%#lx(%#lx)\n", io_lo, io_hi);
314 port = parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE,
315 PARPORT_DMA_NONE, &dev->dev);
316 if (port) {
317 priv->port[priv->num_par++] = port;
318 success = 1;
322 if (card->postinit_hook)
323 card->postinit_hook (dev, card, !success);
325 return 0;
328 static int __devinit parport_serial_pci_probe (struct pci_dev *dev,
329 const struct pci_device_id *id)
331 struct parport_serial_private *priv;
332 int err;
334 priv = kzalloc (sizeof *priv, GFP_KERNEL);
335 if (!priv)
336 return -ENOMEM;
337 pci_set_drvdata (dev, priv);
339 err = pci_enable_device (dev);
340 if (err) {
341 pci_set_drvdata (dev, NULL);
342 kfree (priv);
343 return err;
346 if (parport_register (dev, id)) {
347 pci_set_drvdata (dev, NULL);
348 kfree (priv);
349 return -ENODEV;
352 if (serial_register (dev, id)) {
353 int i;
354 for (i = 0; i < priv->num_par; i++)
355 parport_pc_unregister_port (priv->port[i]);
356 pci_set_drvdata (dev, NULL);
357 kfree (priv);
358 return -ENODEV;
361 return 0;
364 static void __devexit parport_serial_pci_remove (struct pci_dev *dev)
366 struct parport_serial_private *priv = pci_get_drvdata (dev);
367 int i;
369 pci_set_drvdata(dev, NULL);
371 // Serial ports
372 if (priv->serial)
373 pciserial_remove_ports(priv->serial);
375 // Parallel ports
376 for (i = 0; i < priv->num_par; i++)
377 parport_pc_unregister_port (priv->port[i]);
379 kfree (priv);
380 return;
383 #ifdef CONFIG_PM
384 static int parport_serial_pci_suspend(struct pci_dev *dev, pm_message_t state)
386 struct parport_serial_private *priv = pci_get_drvdata(dev);
388 if (priv->serial)
389 pciserial_suspend_ports(priv->serial);
391 /* FIXME: What about parport? */
393 pci_save_state(dev);
394 pci_set_power_state(dev, pci_choose_state(dev, state));
395 return 0;
398 static int parport_serial_pci_resume(struct pci_dev *dev)
400 struct parport_serial_private *priv = pci_get_drvdata(dev);
401 int err;
403 pci_set_power_state(dev, PCI_D0);
404 pci_restore_state(dev);
407 * The device may have been disabled. Re-enable it.
409 err = pci_enable_device(dev);
410 if (err) {
411 printk(KERN_ERR "parport_serial: %s: error enabling "
412 "device for resume (%d)\n", pci_name(dev), err);
413 return err;
416 if (priv->serial)
417 pciserial_resume_ports(priv->serial);
419 /* FIXME: What about parport? */
421 return 0;
423 #endif
425 static struct pci_driver parport_serial_pci_driver = {
426 .name = "parport_serial",
427 .id_table = parport_serial_pci_tbl,
428 .probe = parport_serial_pci_probe,
429 .remove = __devexit_p(parport_serial_pci_remove),
430 #ifdef CONFIG_PM
431 .suspend = parport_serial_pci_suspend,
432 .resume = parport_serial_pci_resume,
433 #endif
437 static int __init parport_serial_init (void)
439 return pci_register_driver (&parport_serial_pci_driver);
442 static void __exit parport_serial_exit (void)
444 pci_unregister_driver (&parport_serial_pci_driver);
445 return;
448 MODULE_AUTHOR("Tim Waugh <twaugh@redhat.com>");
449 MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards");
450 MODULE_LICENSE("GPL");
452 module_init(parport_serial_init);
453 module_exit(parport_serial_exit);