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