Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/8250_pci.h> |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | enum parport_pc_pci_cards { |
| 29 | titan_110l = 0, |
| 30 | titan_210l, |
| 31 | netmos_9xx5_combo, |
Martin Schitter | 44e58a6 | 2005-06-23 00:09:55 -0700 | [diff] [blame] | 32 | netmos_9855, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | avlab_1s1p, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | avlab_1s2p, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | avlab_2s1p, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | siig_1s1p_10x, |
| 37 | siig_2s1p_10x, |
| 38 | siig_2p1s_20x, |
| 39 | siig_1s1p_20x, |
| 40 | siig_2s1p_20x, |
| 41 | }; |
| 42 | |
| 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]; |
| 52 | |
| 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); |
| 58 | |
| 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); |
| 63 | }; |
| 64 | |
| 65 | static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc_pci *card, int autoirq, int autodma) |
| 66 | { |
| 67 | /* |
| 68 | * Netmos uses the subdevice ID to indicate the number of parallel |
| 69 | * and serial ports. The form is 0x00PS, where <P> is the number of |
| 70 | * parallel ports and <S> is the number of serial ports. |
| 71 | */ |
| 72 | card->numports = (dev->subsystem_device & 0xf0) >> 4; |
Takashi Iwai | 36be47d | 2008-12-01 13:13:49 -0800 | [diff] [blame] | 73 | if (card->numports > ARRAY_SIZE(card->addr)) |
| 74 | card->numports = ARRAY_SIZE(card->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static struct parport_pc_pci cards[] __devinitdata = { |
| 79 | /* titan_110l */ { 1, { { 3, -1 }, } }, |
| 80 | /* titan_210l */ { 1, { { 3, -1 }, } }, |
| 81 | /* netmos_9xx5_combo */ { 1, { { 2, -1 }, }, netmos_parallel_init }, |
Christian Pellegrin | c01106e | 2008-02-06 01:37:44 -0800 | [diff] [blame] | 82 | /* netmos_9855 */ { 1, { { 2, -1 }, }, netmos_parallel_init }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* avlab_1s1p */ { 1, { { 1, 2}, } }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* avlab_1s2p */ { 2, { { 1, 2}, { 3, 4 },} }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* avlab_2s1p */ { 1, { { 2, 3}, } }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* siig_1s1p_10x */ { 1, { { 3, 4 }, } }, |
| 87 | /* siig_2s1p_10x */ { 1, { { 4, 5 }, } }, |
| 88 | /* siig_2p1s_20x */ { 2, { { 1, 2 }, { 3, 4 }, } }, |
| 89 | /* siig_1s1p_20x */ { 1, { { 1, 2 }, } }, |
| 90 | /* siig_2s1p_20x */ { 1, { { 2, 3 }, } }, |
| 91 | }; |
| 92 | |
| 93 | static struct pci_device_id parport_serial_pci_tbl[] = { |
| 94 | /* PCI cards */ |
| 95 | { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_110L, |
| 96 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_110l }, |
| 97 | { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_210L, |
| 98 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_210l }, |
| 99 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9735, |
| 100 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, |
| 101 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9745, |
| 102 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, |
| 103 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835, |
| 104 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9845, |
| 106 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, |
| 107 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855, |
Martin Schitter | 44e58a6 | 2005-06-23 00:09:55 -0700 | [diff] [blame] | 108 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9855 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/ |
Russell King | 91bca4b | 2006-03-20 20:08:22 +0000 | [diff] [blame] | 110 | { PCI_VENDOR_ID_AFAVLAB, 0x2110, |
| 111 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p }, |
| 112 | { PCI_VENDOR_ID_AFAVLAB, 0x2111, |
| 113 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p }, |
| 114 | { PCI_VENDOR_ID_AFAVLAB, 0x2112, |
| 115 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p }, |
| 116 | { PCI_VENDOR_ID_AFAVLAB, 0x2140, |
| 117 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p }, |
| 118 | { PCI_VENDOR_ID_AFAVLAB, 0x2141, |
| 119 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p }, |
| 120 | { PCI_VENDOR_ID_AFAVLAB, 0x2142, |
| 121 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p }, |
| 122 | { PCI_VENDOR_ID_AFAVLAB, 0x2160, |
| 123 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p }, |
| 124 | { PCI_VENDOR_ID_AFAVLAB, 0x2161, |
| 125 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p }, |
| 126 | { PCI_VENDOR_ID_AFAVLAB, 0x2162, |
| 127 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_550, |
| 129 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x }, |
| 130 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_650, |
| 131 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x }, |
| 132 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_850, |
| 133 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x }, |
| 134 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_550, |
| 135 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x }, |
| 136 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_650, |
| 137 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x }, |
| 138 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_850, |
| 139 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x }, |
| 140 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_550, |
| 141 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x }, |
| 142 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_650, |
| 143 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x }, |
| 144 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_850, |
| 145 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x }, |
| 146 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_550, |
| 147 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x }, |
| 148 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_650, |
| 149 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x }, |
| 150 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_850, |
| 151 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x }, |
| 152 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_550, |
| 153 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x }, |
| 154 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_650, |
| 155 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x }, |
| 156 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_850, |
| 157 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x }, |
| 158 | |
| 159 | { 0, } /* terminate list */ |
| 160 | }; |
| 161 | MODULE_DEVICE_TABLE(pci,parport_serial_pci_tbl); |
| 162 | |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 163 | /* |
| 164 | * This table describes the serial "geometry" of these boards. Any |
| 165 | * quirks for these can be found in drivers/serial/8250_pci.c |
| 166 | * |
| 167 | * Cards not tested are marked n/t |
| 168 | * If you have one of these cards and it works for you, please tell me.. |
| 169 | */ |
| 170 | static struct pciserial_board pci_parport_serial_boards[] __devinitdata = { |
| 171 | [titan_110l] = { |
| 172 | .flags = FL_BASE1 | FL_BASE_BARS, |
| 173 | .num_ports = 1, |
| 174 | .base_baud = 921600, |
| 175 | .uart_offset = 8, |
| 176 | }, |
| 177 | [titan_210l] = { |
| 178 | .flags = FL_BASE1 | FL_BASE_BARS, |
| 179 | .num_ports = 2, |
| 180 | .base_baud = 921600, |
| 181 | .uart_offset = 8, |
| 182 | }, |
| 183 | [netmos_9xx5_combo] = { |
| 184 | .flags = FL_BASE0 | FL_BASE_BARS, |
| 185 | .num_ports = 1, |
| 186 | .base_baud = 115200, |
| 187 | .uart_offset = 8, |
| 188 | }, |
| 189 | [netmos_9855] = { |
Christian Pellegrin | c01106e | 2008-02-06 01:37:44 -0800 | [diff] [blame] | 190 | .flags = FL_BASE4 | FL_BASE_BARS, |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 191 | .num_ports = 1, |
| 192 | .base_baud = 115200, |
| 193 | .uart_offset = 8, |
| 194 | }, |
| 195 | [avlab_1s1p] = { /* n/t */ |
| 196 | .flags = FL_BASE0 | FL_BASE_BARS, |
| 197 | .num_ports = 1, |
| 198 | .base_baud = 115200, |
| 199 | .uart_offset = 8, |
| 200 | }, |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 201 | [avlab_1s2p] = { /* n/t */ |
| 202 | .flags = FL_BASE0 | FL_BASE_BARS, |
| 203 | .num_ports = 1, |
| 204 | .base_baud = 115200, |
| 205 | .uart_offset = 8, |
| 206 | }, |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 207 | [avlab_2s1p] = { /* n/t */ |
| 208 | .flags = FL_BASE0 | FL_BASE_BARS, |
| 209 | .num_ports = 2, |
| 210 | .base_baud = 115200, |
| 211 | .uart_offset = 8, |
| 212 | }, |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 213 | [siig_1s1p_10x] = { |
| 214 | .flags = FL_BASE2, |
| 215 | .num_ports = 1, |
| 216 | .base_baud = 460800, |
| 217 | .uart_offset = 8, |
| 218 | }, |
| 219 | [siig_2s1p_10x] = { |
| 220 | .flags = FL_BASE2, |
| 221 | .num_ports = 1, |
| 222 | .base_baud = 921600, |
| 223 | .uart_offset = 8, |
| 224 | }, |
| 225 | [siig_2p1s_20x] = { |
| 226 | .flags = FL_BASE0, |
| 227 | .num_ports = 1, |
| 228 | .base_baud = 921600, |
| 229 | .uart_offset = 8, |
| 230 | }, |
| 231 | [siig_1s1p_20x] = { |
| 232 | .flags = FL_BASE0, |
| 233 | .num_ports = 1, |
| 234 | .base_baud = 921600, |
| 235 | .uart_offset = 8, |
| 236 | }, |
| 237 | [siig_2s1p_20x] = { |
| 238 | .flags = FL_BASE0, |
| 239 | .num_ports = 1, |
| 240 | .base_baud = 921600, |
| 241 | .uart_offset = 8, |
| 242 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | }; |
| 244 | |
| 245 | struct parport_serial_private { |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 246 | struct serial_private *serial; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | int num_par; |
| 248 | struct parport *port[PARPORT_MAX]; |
| 249 | struct parport_pc_pci par; |
| 250 | }; |
| 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | /* Register the serial port(s) of a PCI card. */ |
| 253 | static int __devinit serial_register (struct pci_dev *dev, |
| 254 | const struct pci_device_id *id) |
| 255 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | struct parport_serial_private *priv = pci_get_drvdata (dev); |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 257 | struct pciserial_board *board; |
| 258 | struct serial_private *serial; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 260 | board = &pci_parport_serial_boards[id->driver_data]; |
| 261 | serial = pciserial_init_ports(dev, board); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 263 | if (IS_ERR(serial)) |
| 264 | return PTR_ERR(serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 266 | priv->serial = serial; |
| 267 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /* Register the parallel port(s) of a PCI card. */ |
| 271 | static int __devinit parport_register (struct pci_dev *dev, |
| 272 | const struct pci_device_id *id) |
| 273 | { |
| 274 | struct parport_pc_pci *card; |
| 275 | struct parport_serial_private *priv = pci_get_drvdata (dev); |
Russell King | 7a171cd | 2006-03-05 00:31:22 +0000 | [diff] [blame] | 276 | int n, success = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | priv->par = cards[id->driver_data]; |
| 279 | card = &priv->par; |
| 280 | if (card->preinit_hook && |
| 281 | card->preinit_hook (dev, card, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) |
| 282 | return -ENODEV; |
| 283 | |
| 284 | for (n = 0; n < card->numports; n++) { |
| 285 | struct parport *port; |
| 286 | int lo = card->addr[n].lo; |
| 287 | int hi = card->addr[n].hi; |
| 288 | unsigned long io_lo, io_hi; |
| 289 | |
| 290 | if (priv->num_par == ARRAY_SIZE (priv->port)) { |
| 291 | printk (KERN_WARNING |
Andrew Morton | f4f64e9 | 2006-02-03 03:04:02 -0800 | [diff] [blame] | 292 | "parport_serial: %s: only %zu parallel ports " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | "supported (%d reported)\n", pci_name (dev), |
Andrew Morton | f4f64e9 | 2006-02-03 03:04:02 -0800 | [diff] [blame] | 294 | ARRAY_SIZE(priv->port), card->numports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | break; |
| 296 | } |
| 297 | |
| 298 | io_lo = pci_resource_start (dev, lo); |
| 299 | io_hi = 0; |
| 300 | if ((hi >= 0) && (hi <= 6)) |
| 301 | io_hi = pci_resource_start (dev, hi); |
| 302 | else if (hi > 6) |
| 303 | io_lo += hi; /* Reinterpret the meaning of |
| 304 | "hi" as an offset (see SYBA |
| 305 | def.) */ |
| 306 | /* TODO: test if sharing interrupts works */ |
Russell King | 7a171cd | 2006-03-05 00:31:22 +0000 | [diff] [blame] | 307 | dev_dbg(&dev->dev, "PCI parallel port detected: I/O at " |
| 308 | "%#lx(%#lx)\n", io_lo, io_hi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | port = parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE, |
David Brownell | c15a383 | 2007-05-08 00:27:35 -0700 | [diff] [blame] | 310 | PARPORT_DMA_NONE, &dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | if (port) { |
| 312 | priv->port[priv->num_par++] = port; |
| 313 | success = 1; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | if (card->postinit_hook) |
| 318 | card->postinit_hook (dev, card, !success); |
| 319 | |
Russell King | 7a171cd | 2006-03-05 00:31:22 +0000 | [diff] [blame] | 320 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | static int __devinit parport_serial_pci_probe (struct pci_dev *dev, |
| 324 | const struct pci_device_id *id) |
| 325 | { |
| 326 | struct parport_serial_private *priv; |
| 327 | int err; |
| 328 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 329 | priv = kzalloc (sizeof *priv, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | if (!priv) |
| 331 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | pci_set_drvdata (dev, priv); |
| 333 | |
| 334 | err = pci_enable_device (dev); |
| 335 | if (err) { |
| 336 | pci_set_drvdata (dev, NULL); |
| 337 | kfree (priv); |
| 338 | return err; |
| 339 | } |
| 340 | |
| 341 | if (parport_register (dev, id)) { |
| 342 | pci_set_drvdata (dev, NULL); |
| 343 | kfree (priv); |
| 344 | return -ENODEV; |
| 345 | } |
| 346 | |
| 347 | if (serial_register (dev, id)) { |
| 348 | int i; |
| 349 | for (i = 0; i < priv->num_par; i++) |
| 350 | parport_pc_unregister_port (priv->port[i]); |
| 351 | pci_set_drvdata (dev, NULL); |
| 352 | kfree (priv); |
| 353 | return -ENODEV; |
| 354 | } |
| 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | static void __devexit parport_serial_pci_remove (struct pci_dev *dev) |
| 360 | { |
| 361 | struct parport_serial_private *priv = pci_get_drvdata (dev); |
| 362 | int i; |
| 363 | |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 364 | pci_set_drvdata(dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 366 | // Serial ports |
| 367 | if (priv->serial) |
| 368 | pciserial_remove_ports(priv->serial); |
| 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | // Parallel ports |
| 371 | for (i = 0; i < priv->num_par; i++) |
| 372 | parport_pc_unregister_port (priv->port[i]); |
| 373 | |
| 374 | kfree (priv); |
| 375 | return; |
| 376 | } |
| 377 | |
Alexey Dobriyan | 7dd7d69 | 2006-09-29 02:00:16 -0700 | [diff] [blame] | 378 | #ifdef CONFIG_PM |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 379 | static int parport_serial_pci_suspend(struct pci_dev *dev, pm_message_t state) |
| 380 | { |
| 381 | struct parport_serial_private *priv = pci_get_drvdata(dev); |
| 382 | |
| 383 | if (priv->serial) |
| 384 | pciserial_suspend_ports(priv->serial); |
| 385 | |
| 386 | /* FIXME: What about parport? */ |
| 387 | |
| 388 | pci_save_state(dev); |
| 389 | pci_set_power_state(dev, pci_choose_state(dev, state)); |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | static int parport_serial_pci_resume(struct pci_dev *dev) |
| 394 | { |
| 395 | struct parport_serial_private *priv = pci_get_drvdata(dev); |
Randy Dunlap | 10f8a59 | 2007-05-08 00:29:01 -0700 | [diff] [blame] | 396 | int err; |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 397 | |
| 398 | pci_set_power_state(dev, PCI_D0); |
| 399 | pci_restore_state(dev); |
| 400 | |
| 401 | /* |
| 402 | * The device may have been disabled. Re-enable it. |
| 403 | */ |
Randy Dunlap | 10f8a59 | 2007-05-08 00:29:01 -0700 | [diff] [blame] | 404 | err = pci_enable_device(dev); |
| 405 | if (err) { |
| 406 | printk(KERN_ERR "parport_serial: %s: error enabling " |
| 407 | "device for resume (%d)\n", pci_name(dev), err); |
| 408 | return err; |
| 409 | } |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 410 | |
| 411 | if (priv->serial) |
| 412 | pciserial_resume_ports(priv->serial); |
| 413 | |
| 414 | /* FIXME: What about parport? */ |
| 415 | |
| 416 | return 0; |
| 417 | } |
Alexey Dobriyan | 7dd7d69 | 2006-09-29 02:00:16 -0700 | [diff] [blame] | 418 | #endif |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | static struct pci_driver parport_serial_pci_driver = { |
| 421 | .name = "parport_serial", |
| 422 | .id_table = parport_serial_pci_tbl, |
| 423 | .probe = parport_serial_pci_probe, |
| 424 | .remove = __devexit_p(parport_serial_pci_remove), |
Alexey Dobriyan | 7dd7d69 | 2006-09-29 02:00:16 -0700 | [diff] [blame] | 425 | #ifdef CONFIG_PM |
Russell King | 05caac5 | 2005-07-27 11:41:18 +0100 | [diff] [blame] | 426 | .suspend = parport_serial_pci_suspend, |
| 427 | .resume = parport_serial_pci_resume, |
Alexey Dobriyan | 7dd7d69 | 2006-09-29 02:00:16 -0700 | [diff] [blame] | 428 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | }; |
| 430 | |
| 431 | |
| 432 | static int __init parport_serial_init (void) |
| 433 | { |
Richard Knutsson | 93b4768 | 2005-11-30 01:00:35 +0100 | [diff] [blame] | 434 | return pci_register_driver (&parport_serial_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | static void __exit parport_serial_exit (void) |
| 438 | { |
| 439 | pci_unregister_driver (&parport_serial_pci_driver); |
| 440 | return; |
| 441 | } |
| 442 | |
| 443 | MODULE_AUTHOR("Tim Waugh <twaugh@redhat.com>"); |
| 444 | MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards"); |
| 445 | MODULE_LICENSE("GPL"); |
| 446 | |
| 447 | module_init(parport_serial_init); |
| 448 | module_exit(parport_serial_exit); |