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