1 // SPDX-License-Identifier: GPL-2.0 2 3 /*************************************************************************** 4 * copyright : (C) 1999 Axel Dziemba (axel.dziemba@ines.de) 5 * (C) 2002 by Frank Mori Hess 6 ***************************************************************************/ 7 8 #include "ines.h" 9 10 #include <linux/pci.h> 11 #include <linux/pci_ids.h> 12 #include <linux/bitops.h> 13 #include <asm/dma.h> 14 #include <linux/io.h> 15 #include <linux/module.h> 16 #include <linux/init.h> 17 #include <linux/sched.h> 18 #include <linux/slab.h> 19 #include "gpib_pci_ids.h" 20 21 MODULE_LICENSE("GPL"); 22 MODULE_DESCRIPTION("GPIB driver for Ines iGPIB 72010"); 23 24 int ines_line_status(const gpib_board_t *board) 25 { 26 int status = ValidALL; 27 int bcm_bits; 28 struct ines_priv *ines_priv; 29 struct nec7210_priv *nec_priv; 30 31 ines_priv = board->private_data; 32 nec_priv = &ines_priv->nec7210_priv; 33 34 bcm_bits = ines_inb(ines_priv, BUS_CONTROL_MONITOR); 35 36 if (bcm_bits & BCM_REN_BIT) 37 status |= BusREN; 38 if (bcm_bits & BCM_IFC_BIT) 39 status |= BusIFC; 40 if (bcm_bits & BCM_SRQ_BIT) 41 status |= BusSRQ; 42 if (bcm_bits & BCM_EOI_BIT) 43 status |= BusEOI; 44 if (bcm_bits & BCM_NRFD_BIT) 45 status |= BusNRFD; 46 if (bcm_bits & BCM_NDAC_BIT) 47 status |= BusNDAC; 48 if (bcm_bits & BCM_DAV_BIT) 49 status |= BusDAV; 50 if (bcm_bits & BCM_ATN_BIT) 51 status |= BusATN; 52 53 return status; 54 } 55 56 void ines_set_xfer_counter(struct ines_priv *priv, unsigned int count) 57 { 58 if (count > 0xffff) { 59 pr_err("ines: bug! tried to set xfer counter > 0xffff\n"); 60 return; 61 } 62 ines_outb(priv, (count >> 8) & 0xff, XFER_COUNT_UPPER); 63 ines_outb(priv, count & 0xff, XFER_COUNT_LOWER); 64 } 65 66 unsigned int ines_t1_delay(gpib_board_t *board, unsigned int nano_sec) 67 { 68 struct ines_priv *ines_priv = board->private_data; 69 struct nec7210_priv *nec_priv = &ines_priv->nec7210_priv; 70 unsigned int retval; 71 72 retval = nec7210_t1_delay(board, nec_priv, nano_sec); 73 74 if (nano_sec <= 250) { 75 write_byte(nec_priv, INES_AUXD | INES_FOLLOWING_T1_250ns | 76 INES_INITIAL_T1_2000ns, AUXMR); 77 retval = 250; 78 } else if (nano_sec <= 350) { 79 write_byte(nec_priv, INES_AUXD | INES_FOLLOWING_T1_350ns | 80 INES_INITIAL_T1_2000ns, AUXMR); 81 retval = 350; 82 } else { 83 write_byte(nec_priv, INES_AUXD | INES_FOLLOWING_T1_500ns | 84 INES_INITIAL_T1_2000ns, AUXMR); 85 retval = 500; 86 } 87 88 return retval; 89 } 90 91 static inline unsigned short num_in_fifo_bytes(struct ines_priv *ines_priv) 92 { 93 return ines_inb(ines_priv, IN_FIFO_COUNT); 94 } 95 96 static ssize_t pio_read(gpib_board_t *board, struct ines_priv *ines_priv, uint8_t *buffer, 97 size_t length, size_t *nbytes) 98 { 99 ssize_t retval = 0; 100 unsigned int num_fifo_bytes, i; 101 struct nec7210_priv *nec_priv = &ines_priv->nec7210_priv; 102 103 *nbytes = 0; 104 while (*nbytes < length) { 105 if (wait_event_interruptible(board->wait, 106 num_in_fifo_bytes(ines_priv) || 107 test_bit(RECEIVED_END_BN, &nec_priv->state) || 108 test_bit(DEV_CLEAR_BN, &nec_priv->state) || 109 test_bit(TIMO_NUM, &board->status))) { 110 pr_warn("gpib: pio read wait interrupted\n"); 111 return -ERESTARTSYS; 112 } 113 if (test_bit(TIMO_NUM, &board->status)) 114 return -ETIMEDOUT; 115 if (test_bit(DEV_CLEAR_BN, &nec_priv->state)) 116 return -EINTR; 117 118 num_fifo_bytes = num_in_fifo_bytes(ines_priv); 119 if (num_fifo_bytes + *nbytes > length) { 120 pr_warn("ines: counter allowed %li extra byte(s)\n", 121 (long)(num_fifo_bytes - (length - *nbytes))); 122 num_fifo_bytes = length - *nbytes; 123 } 124 for (i = 0; i < num_fifo_bytes; i++) 125 buffer[(*nbytes)++] = read_byte(nec_priv, DIR); 126 if (test_bit(RECEIVED_END_BN, &nec_priv->state) && 127 num_in_fifo_bytes(ines_priv) == 0) 128 break; 129 if (need_resched()) 130 schedule(); 131 } 132 /* make sure RECEIVED_END is in sync */ 133 ines_interrupt(board); 134 return retval; 135 } 136 137 int ines_accel_read(gpib_board_t *board, uint8_t *buffer, 138 size_t length, int *end, size_t *bytes_read) 139 { 140 ssize_t retval = 0; 141 struct ines_priv *ines_priv = board->private_data; 142 struct nec7210_priv *nec_priv = &ines_priv->nec7210_priv; 143 int counter_setting; 144 145 *end = 0; 146 *bytes_read = 0; 147 if (length == 0) 148 return 0; 149 150 clear_bit(DEV_CLEAR_BN, &nec_priv->state); 151 152 write_byte(nec_priv, INES_RFD_HLD_IMMEDIATE, AUXMR); 153 154 //clear in fifo 155 nec7210_set_reg_bits(nec_priv, ADMR, IN_FIFO_ENABLE_BIT, 0); 156 nec7210_set_reg_bits(nec_priv, ADMR, IN_FIFO_ENABLE_BIT, IN_FIFO_ENABLE_BIT); 157 158 ines_priv->extend_mode_bits |= LAST_BYTE_HANDLING_BIT; 159 ines_priv->extend_mode_bits &= ~XFER_COUNTER_OUTPUT_BIT & ~XFER_COUNTER_ENABLE_BIT; 160 ines_outb(ines_priv, ines_priv->extend_mode_bits, EXTEND_MODE); 161 162 counter_setting = length - num_in_fifo_bytes(ines_priv); 163 if (counter_setting > 0) { 164 ines_set_xfer_counter(ines_priv, length); 165 ines_priv->extend_mode_bits |= XFER_COUNTER_ENABLE_BIT; 166 ines_outb(ines_priv, ines_priv->extend_mode_bits, EXTEND_MODE); 167 168 // holdoff on END 169 nec7210_set_handshake_mode(board, nec_priv, HR_HLDE); 170 /* release rfd holdoff */ 171 write_byte(nec_priv, AUX_FH, AUXMR); 172 } 173 174 retval = pio_read(board, ines_priv, buffer, length, bytes_read); 175 ines_priv->extend_mode_bits &= ~XFER_COUNTER_ENABLE_BIT; 176 ines_outb(ines_priv, ines_priv->extend_mode_bits, EXTEND_MODE); 177 if (retval < 0) { 178 write_byte(nec_priv, INES_RFD_HLD_IMMEDIATE, AUXMR); 179 return retval; 180 } 181 if (test_and_clear_bit(RECEIVED_END_BN, &nec_priv->state)) 182 *end = 1; 183 184 return retval; 185 } 186 187 static const int out_fifo_size = 0xff; 188 189 static inline unsigned short num_out_fifo_bytes(struct ines_priv *ines_priv) 190 { 191 return ines_inb(ines_priv, OUT_FIFO_COUNT); 192 } 193 194 static int ines_write_wait(gpib_board_t *board, struct ines_priv *ines_priv, 195 unsigned int fifo_threshold) 196 { 197 struct nec7210_priv *nec_priv = &ines_priv->nec7210_priv; 198 199 // wait until byte is ready to be sent 200 if (wait_event_interruptible(board->wait, 201 num_out_fifo_bytes(ines_priv) < fifo_threshold || 202 test_bit(BUS_ERROR_BN, &nec_priv->state) || 203 test_bit(DEV_CLEAR_BN, &nec_priv->state) || 204 test_bit(TIMO_NUM, &board->status))) { 205 dev_dbg(board->gpib_dev, "gpib write interrupted\n"); 206 return -ERESTARTSYS; 207 } 208 if (test_bit(BUS_ERROR_BN, &nec_priv->state)) 209 return -EIO; 210 if (test_bit(DEV_CLEAR_BN, &nec_priv->state)) 211 return -EINTR; 212 if (test_bit(TIMO_NUM, &board->status)) 213 return -ETIMEDOUT; 214 215 return 0; 216 } 217 218 int ines_accel_write(gpib_board_t *board, uint8_t *buffer, size_t length, 219 int send_eoi, size_t *bytes_written) 220 { 221 size_t count = 0; 222 ssize_t retval = 0; 223 struct ines_priv *ines_priv = board->private_data; 224 struct nec7210_priv *nec_priv = &ines_priv->nec7210_priv; 225 unsigned int num_bytes, i; 226 227 *bytes_written = 0; 228 //clear out fifo 229 nec7210_set_reg_bits(nec_priv, ADMR, OUT_FIFO_ENABLE_BIT, 0); 230 nec7210_set_reg_bits(nec_priv, ADMR, OUT_FIFO_ENABLE_BIT, OUT_FIFO_ENABLE_BIT); 231 232 ines_priv->extend_mode_bits |= XFER_COUNTER_OUTPUT_BIT; 233 ines_priv->extend_mode_bits &= ~XFER_COUNTER_ENABLE_BIT; 234 ines_priv->extend_mode_bits &= ~LAST_BYTE_HANDLING_BIT; 235 ines_outb(ines_priv, ines_priv->extend_mode_bits, EXTEND_MODE); 236 237 ines_set_xfer_counter(ines_priv, length); 238 if (send_eoi) 239 ines_priv->extend_mode_bits |= LAST_BYTE_HANDLING_BIT; 240 ines_priv->extend_mode_bits |= XFER_COUNTER_ENABLE_BIT; 241 ines_outb(ines_priv, ines_priv->extend_mode_bits, EXTEND_MODE); 242 243 while (count < length) { 244 retval = ines_write_wait(board, ines_priv, out_fifo_size); 245 if (retval < 0) 246 break; 247 248 num_bytes = out_fifo_size - num_out_fifo_bytes(ines_priv); 249 if (num_bytes + count > length) 250 num_bytes = length - count; 251 for (i = 0; i < num_bytes; i++) 252 write_byte(nec_priv, buffer[count++], CDOR); 253 } 254 if (retval < 0) { 255 ines_priv->extend_mode_bits &= ~XFER_COUNTER_ENABLE_BIT; 256 ines_outb(ines_priv, ines_priv->extend_mode_bits, EXTEND_MODE); 257 *bytes_written = length - num_out_fifo_bytes(ines_priv); 258 return retval; 259 } 260 // wait last byte has been sent 261 retval = ines_write_wait(board, ines_priv, 1); 262 ines_priv->extend_mode_bits &= ~XFER_COUNTER_ENABLE_BIT; 263 ines_outb(ines_priv, ines_priv->extend_mode_bits, EXTEND_MODE); 264 *bytes_written = length - num_out_fifo_bytes(ines_priv); 265 266 return retval; 267 } 268 269 irqreturn_t ines_pci_interrupt(int irq, void *arg) 270 { 271 gpib_board_t *board = arg; 272 struct ines_priv *priv = board->private_data; 273 struct nec7210_priv *nec_priv = &priv->nec7210_priv; 274 275 if (priv->pci_chip_type == PCI_CHIP_QUANCOM) { 276 if ((inb(nec_priv->iobase + 277 QUANCOM_IRQ_CONTROL_STATUS_REG) & 278 QUANCOM_IRQ_ASSERTED_BIT)) 279 outb(QUANCOM_IRQ_ENABLE_BIT, nec_priv->iobase + 280 QUANCOM_IRQ_CONTROL_STATUS_REG); 281 } 282 283 return ines_interrupt(board); 284 } 285 286 irqreturn_t ines_interrupt(gpib_board_t *board) 287 { 288 struct ines_priv *priv = board->private_data; 289 struct nec7210_priv *nec_priv = &priv->nec7210_priv; 290 unsigned int isr3_bits, isr4_bits; 291 unsigned long flags; 292 int wake = 0; 293 294 spin_lock_irqsave(&board->spinlock, flags); 295 296 nec7210_interrupt(board, nec_priv); 297 isr3_bits = ines_inb(priv, ISR3); 298 isr4_bits = ines_inb(priv, ISR4); 299 if (isr3_bits & IFC_ACTIVE_BIT) { 300 push_gpib_event(board, EventIFC); 301 wake++; 302 } 303 if (isr3_bits & FIFO_ERROR_BIT) 304 pr_err("ines gpib: fifo error\n"); 305 if (isr3_bits & XFER_COUNT_BIT) 306 wake++; 307 308 if (isr4_bits & (IN_FIFO_WATERMARK_BIT | IN_FIFO_FULL_BIT | OUT_FIFO_WATERMARK_BIT | 309 OUT_FIFO_EMPTY_BIT)) 310 wake++; 311 312 if (wake) 313 wake_up_interruptible(&board->wait); 314 spin_unlock_irqrestore(&board->spinlock, flags); 315 return IRQ_HANDLED; 316 } 317 318 static int ines_pci_attach(gpib_board_t *board, const gpib_board_config_t *config); 319 static int ines_pci_accel_attach(gpib_board_t *board, const gpib_board_config_t *config); 320 static int ines_isa_attach(gpib_board_t *board, const gpib_board_config_t *config); 321 322 static void ines_pci_detach(gpib_board_t *board); 323 static void ines_isa_detach(gpib_board_t *board); 324 325 enum ines_pci_vendor_ids { 326 PCI_VENDOR_ID_INES_QUICKLOGIC = 0x16da 327 }; 328 329 enum ines_pci_device_ids { 330 PCI_DEVICE_ID_INES_GPIB_AMCC = 0x8507, 331 PCI_DEVICE_ID_INES_GPIB_QL5030 = 0x11, 332 }; 333 334 enum ines_pci_subdevice_ids { 335 PCI_SUBDEVICE_ID_INES_GPIB = 0x1072 336 }; 337 338 static struct pci_device_id ines_pci_table[] = { 339 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, PCI_VENDOR_ID_PLX, 340 PCI_SUBDEVICE_ID_INES_GPIB, 0, 0, 0}, 341 {PCI_VENDOR_ID_AMCC, PCI_DEVICE_ID_INES_GPIB_AMCC, PCI_VENDOR_ID_AMCC, 342 PCI_SUBDEVICE_ID_INES_GPIB, 0, 0, 0}, 343 {PCI_VENDOR_ID_INES_QUICKLOGIC, PCI_DEVICE_ID_INES_GPIB_QL5030, 344 PCI_VENDOR_ID_INES_QUICKLOGIC, PCI_DEVICE_ID_INES_GPIB_QL5030, 0, 0, 0}, 345 {PCI_DEVICE(PCI_VENDOR_ID_QUANCOM, PCI_DEVICE_ID_QUANCOM_GPIB)}, 346 {0} 347 }; 348 MODULE_DEVICE_TABLE(pci, ines_pci_table); 349 350 struct ines_pci_id { 351 unsigned int vendor_id; 352 unsigned int device_id; 353 int subsystem_vendor_id; 354 int subsystem_device_id; 355 unsigned int gpib_region; 356 unsigned int io_offset; 357 enum ines_pci_chip pci_chip_type; 358 }; 359 360 static struct ines_pci_id pci_ids[] = { 361 {.vendor_id = PCI_VENDOR_ID_PLX, 362 .device_id = PCI_DEVICE_ID_PLX_9050, 363 .subsystem_vendor_id = PCI_VENDOR_ID_PLX, 364 .subsystem_device_id = PCI_SUBDEVICE_ID_INES_GPIB, 365 .gpib_region = 2, 366 .io_offset = 1, 367 .pci_chip_type = PCI_CHIP_PLX9050, 368 }, 369 {.vendor_id = PCI_VENDOR_ID_AMCC, 370 .device_id = PCI_DEVICE_ID_INES_GPIB_AMCC, 371 .subsystem_vendor_id = PCI_VENDOR_ID_AMCC, 372 .subsystem_device_id = PCI_SUBDEVICE_ID_INES_GPIB, 373 .gpib_region = 1, 374 .io_offset = 1, 375 .pci_chip_type = PCI_CHIP_AMCC5920, 376 }, 377 {.vendor_id = PCI_VENDOR_ID_INES_QUICKLOGIC, 378 .device_id = PCI_DEVICE_ID_INES_GPIB_QL5030, 379 .subsystem_vendor_id = PCI_VENDOR_ID_INES_QUICKLOGIC, 380 .subsystem_device_id = PCI_DEVICE_ID_INES_GPIB_QL5030, 381 .gpib_region = 1, 382 .io_offset = 1, 383 .pci_chip_type = PCI_CHIP_QUICKLOGIC5030, 384 }, 385 {.vendor_id = PCI_VENDOR_ID_QUANCOM, 386 .device_id = PCI_DEVICE_ID_QUANCOM_GPIB, 387 .subsystem_vendor_id = -1, 388 .subsystem_device_id = -1, 389 .gpib_region = 0, 390 .io_offset = 4, 391 .pci_chip_type = PCI_CHIP_QUANCOM, 392 }, 393 }; 394 395 static const int num_pci_chips = ARRAY_SIZE(pci_ids); 396 397 // wrappers for interface functions 398 int ines_read(gpib_board_t *board, uint8_t *buffer, size_t length, int *end, size_t *bytes_read) 399 { 400 struct ines_priv *priv = board->private_data; 401 struct nec7210_priv *nec_priv = &priv->nec7210_priv; 402 ssize_t retval; 403 int dummy; 404 405 retval = nec7210_read(board, &priv->nec7210_priv, buffer, length, end, bytes_read); 406 if (retval < 0) { 407 write_byte(nec_priv, INES_RFD_HLD_IMMEDIATE, AUXMR); 408 409 set_bit(RFD_HOLDOFF_BN, &nec_priv->state); 410 411 nec7210_read_data_in(board, nec_priv, &dummy); 412 } 413 return retval; 414 } 415 416 int ines_write(gpib_board_t *board, uint8_t *buffer, size_t length, int send_eoi, 417 size_t *bytes_written) 418 { 419 struct ines_priv *priv = board->private_data; 420 421 return nec7210_write(board, &priv->nec7210_priv, buffer, length, send_eoi, bytes_written); 422 } 423 424 int ines_command(gpib_board_t *board, uint8_t *buffer, size_t length, size_t *bytes_written) 425 { 426 struct ines_priv *priv = board->private_data; 427 428 return nec7210_command(board, &priv->nec7210_priv, buffer, length, bytes_written); 429 } 430 431 int ines_take_control(gpib_board_t *board, int synchronous) 432 { 433 struct ines_priv *priv = board->private_data; 434 435 return nec7210_take_control(board, &priv->nec7210_priv, synchronous); 436 } 437 438 int ines_go_to_standby(gpib_board_t *board) 439 { 440 struct ines_priv *priv = board->private_data; 441 442 return nec7210_go_to_standby(board, &priv->nec7210_priv); 443 } 444 445 void ines_request_system_control(gpib_board_t *board, int request_control) 446 { 447 struct ines_priv *priv = board->private_data; 448 449 nec7210_request_system_control(board, &priv->nec7210_priv, request_control); 450 } 451 452 void ines_interface_clear(gpib_board_t *board, int assert) 453 { 454 struct ines_priv *priv = board->private_data; 455 456 nec7210_interface_clear(board, &priv->nec7210_priv, assert); 457 } 458 459 void ines_remote_enable(gpib_board_t *board, int enable) 460 { 461 struct ines_priv *priv = board->private_data; 462 463 nec7210_remote_enable(board, &priv->nec7210_priv, enable); 464 } 465 466 int ines_enable_eos(gpib_board_t *board, uint8_t eos_byte, int compare_8_bits) 467 { 468 struct ines_priv *priv = board->private_data; 469 470 return nec7210_enable_eos(board, &priv->nec7210_priv, eos_byte, compare_8_bits); 471 } 472 473 void ines_disable_eos(gpib_board_t *board) 474 { 475 struct ines_priv *priv = board->private_data; 476 477 nec7210_disable_eos(board, &priv->nec7210_priv); 478 } 479 480 unsigned int ines_update_status(gpib_board_t *board, unsigned int clear_mask) 481 { 482 struct ines_priv *priv = board->private_data; 483 484 return nec7210_update_status(board, &priv->nec7210_priv, clear_mask); 485 } 486 487 int ines_primary_address(gpib_board_t *board, unsigned int address) 488 { 489 struct ines_priv *priv = board->private_data; 490 491 return nec7210_primary_address(board, &priv->nec7210_priv, address); 492 } 493 494 int ines_secondary_address(gpib_board_t *board, unsigned int address, int enable) 495 { 496 struct ines_priv *priv = board->private_data; 497 498 return nec7210_secondary_address(board, &priv->nec7210_priv, address, enable); 499 } 500 501 int ines_parallel_poll(gpib_board_t *board, uint8_t *result) 502 { 503 struct ines_priv *priv = board->private_data; 504 505 return nec7210_parallel_poll(board, &priv->nec7210_priv, result); 506 } 507 508 void ines_parallel_poll_configure(gpib_board_t *board, uint8_t config) 509 { 510 struct ines_priv *priv = board->private_data; 511 512 nec7210_parallel_poll_configure(board, &priv->nec7210_priv, config); 513 } 514 515 void ines_parallel_poll_response(gpib_board_t *board, int ist) 516 { 517 struct ines_priv *priv = board->private_data; 518 519 nec7210_parallel_poll_response(board, &priv->nec7210_priv, ist); 520 } 521 522 void ines_serial_poll_response(gpib_board_t *board, uint8_t status) 523 { 524 struct ines_priv *priv = board->private_data; 525 526 nec7210_serial_poll_response(board, &priv->nec7210_priv, status); 527 } 528 529 uint8_t ines_serial_poll_status(gpib_board_t *board) 530 { 531 struct ines_priv *priv = board->private_data; 532 533 return nec7210_serial_poll_status(board, &priv->nec7210_priv); 534 } 535 536 void ines_return_to_local(gpib_board_t *board) 537 { 538 struct ines_priv *priv = board->private_data; 539 540 nec7210_return_to_local(board, &priv->nec7210_priv); 541 } 542 543 static gpib_interface_t ines_pci_unaccel_interface = { 544 .name = "ines_pci_unaccel", 545 .attach = ines_pci_attach, 546 .detach = ines_pci_detach, 547 .read = ines_read, 548 .write = ines_write, 549 .command = ines_command, 550 .take_control = ines_take_control, 551 .go_to_standby = ines_go_to_standby, 552 .request_system_control = ines_request_system_control, 553 .interface_clear = ines_interface_clear, 554 .remote_enable = ines_remote_enable, 555 .enable_eos = ines_enable_eos, 556 .disable_eos = ines_disable_eos, 557 .parallel_poll = ines_parallel_poll, 558 .parallel_poll_configure = ines_parallel_poll_configure, 559 .parallel_poll_response = ines_parallel_poll_response, 560 .local_parallel_poll_mode = NULL, // XXX 561 .line_status = ines_line_status, 562 .update_status = ines_update_status, 563 .primary_address = ines_primary_address, 564 .secondary_address = ines_secondary_address, 565 .serial_poll_response = ines_serial_poll_response, 566 .serial_poll_status = ines_serial_poll_status, 567 .t1_delay = ines_t1_delay, 568 .return_to_local = ines_return_to_local, 569 }; 570 571 static gpib_interface_t ines_pci_interface = { 572 .name = "ines_pci", 573 .attach = ines_pci_accel_attach, 574 .detach = ines_pci_detach, 575 .read = ines_accel_read, 576 .write = ines_accel_write, 577 .command = ines_command, 578 .take_control = ines_take_control, 579 .go_to_standby = ines_go_to_standby, 580 .request_system_control = ines_request_system_control, 581 .interface_clear = ines_interface_clear, 582 .remote_enable = ines_remote_enable, 583 .enable_eos = ines_enable_eos, 584 .disable_eos = ines_disable_eos, 585 .parallel_poll = ines_parallel_poll, 586 .parallel_poll_configure = ines_parallel_poll_configure, 587 .parallel_poll_response = ines_parallel_poll_response, 588 .local_parallel_poll_mode = NULL, // XXX 589 .line_status = ines_line_status, 590 .update_status = ines_update_status, 591 .primary_address = ines_primary_address, 592 .secondary_address = ines_secondary_address, 593 .serial_poll_response = ines_serial_poll_response, 594 .serial_poll_status = ines_serial_poll_status, 595 .t1_delay = ines_t1_delay, 596 .return_to_local = ines_return_to_local, 597 }; 598 599 static gpib_interface_t ines_pci_accel_interface = { 600 .name = "ines_pci_accel", 601 .attach = ines_pci_accel_attach, 602 .detach = ines_pci_detach, 603 .read = ines_accel_read, 604 .write = ines_accel_write, 605 .command = ines_command, 606 .take_control = ines_take_control, 607 .go_to_standby = ines_go_to_standby, 608 .request_system_control = ines_request_system_control, 609 .interface_clear = ines_interface_clear, 610 .remote_enable = ines_remote_enable, 611 .enable_eos = ines_enable_eos, 612 .disable_eos = ines_disable_eos, 613 .parallel_poll = ines_parallel_poll, 614 .parallel_poll_configure = ines_parallel_poll_configure, 615 .parallel_poll_response = ines_parallel_poll_response, 616 .local_parallel_poll_mode = NULL, // XXX 617 .line_status = ines_line_status, 618 .update_status = ines_update_status, 619 .primary_address = ines_primary_address, 620 .secondary_address = ines_secondary_address, 621 .serial_poll_response = ines_serial_poll_response, 622 .serial_poll_status = ines_serial_poll_status, 623 .t1_delay = ines_t1_delay, 624 .return_to_local = ines_return_to_local, 625 }; 626 627 static gpib_interface_t ines_isa_interface = { 628 .name = "ines_isa", 629 .attach = ines_isa_attach, 630 .detach = ines_isa_detach, 631 .read = ines_accel_read, 632 .write = ines_accel_write, 633 .command = ines_command, 634 .take_control = ines_take_control, 635 .go_to_standby = ines_go_to_standby, 636 .request_system_control = ines_request_system_control, 637 .interface_clear = ines_interface_clear, 638 .remote_enable = ines_remote_enable, 639 .enable_eos = ines_enable_eos, 640 .disable_eos = ines_disable_eos, 641 .parallel_poll = ines_parallel_poll, 642 .parallel_poll_configure = ines_parallel_poll_configure, 643 .parallel_poll_response = ines_parallel_poll_response, 644 .local_parallel_poll_mode = NULL, // XXX 645 .line_status = ines_line_status, 646 .update_status = ines_update_status, 647 .primary_address = ines_primary_address, 648 .secondary_address = ines_secondary_address, 649 .serial_poll_response = ines_serial_poll_response, 650 .serial_poll_status = ines_serial_poll_status, 651 .t1_delay = ines_t1_delay, 652 .return_to_local = ines_return_to_local, 653 }; 654 655 static int ines_allocate_private(gpib_board_t *board) 656 { 657 struct ines_priv *priv; 658 659 board->private_data = kmalloc(sizeof(struct ines_priv), GFP_KERNEL); 660 if (!board->private_data) 661 return -1; 662 priv = board->private_data; 663 memset(priv, 0, sizeof(struct ines_priv)); 664 init_nec7210_private(&priv->nec7210_priv); 665 return 0; 666 } 667 668 void ines_free_private(gpib_board_t *board) 669 { 670 kfree(board->private_data); 671 board->private_data = NULL; 672 } 673 674 int ines_generic_attach(gpib_board_t *board) 675 { 676 struct ines_priv *ines_priv; 677 struct nec7210_priv *nec_priv; 678 679 board->status = 0; 680 681 if (ines_allocate_private(board)) 682 return -ENOMEM; 683 ines_priv = board->private_data; 684 nec_priv = &ines_priv->nec7210_priv; 685 nec_priv->read_byte = nec7210_ioport_read_byte; 686 nec_priv->write_byte = nec7210_ioport_write_byte; 687 nec_priv->offset = 1; 688 nec_priv->type = IGPIB7210; 689 ines_priv->pci_chip_type = PCI_CHIP_NONE; 690 691 return 0; 692 } 693 694 void ines_online(struct ines_priv *ines_priv, const gpib_board_t *board, int use_accel) 695 { 696 struct nec7210_priv *nec_priv = &ines_priv->nec7210_priv; 697 698 /* ines doesn't seem to use internal count register */ 699 write_byte(nec_priv, ICR | 0, AUXMR); 700 701 write_byte(nec_priv, INES_AUX_XMODE, AUXMR); 702 write_byte(nec_priv, INES_RFD_HLD_IMMEDIATE, AUXMR); 703 704 set_bit(RFD_HOLDOFF_BN, &nec_priv->state); 705 706 write_byte(nec_priv, INES_AUXD | 0, AUXMR); 707 ines_outb(ines_priv, 0, XDMA_CONTROL); 708 ines_priv->extend_mode_bits = 0; 709 ines_outb(ines_priv, ines_priv->extend_mode_bits, EXTEND_MODE); 710 if (use_accel) { 711 ines_outb(ines_priv, 0x80, OUT_FIFO_WATERMARK); 712 ines_outb(ines_priv, 0x80, IN_FIFO_WATERMARK); 713 ines_outb(ines_priv, IFC_ACTIVE_BIT | ATN_ACTIVE_BIT | 714 FIFO_ERROR_BIT | XFER_COUNT_BIT, IMR3); 715 ines_outb(ines_priv, IN_FIFO_WATERMARK_BIT | IN_FIFO_FULL_BIT | 716 OUT_FIFO_WATERMARK_BIT | OUT_FIFO_EMPTY_BIT, IMR4); 717 } else { 718 nec7210_set_reg_bits(nec_priv, ADMR, IN_FIFO_ENABLE_BIT | OUT_FIFO_ENABLE_BIT, 0); 719 ines_outb(ines_priv, IFC_ACTIVE_BIT | FIFO_ERROR_BIT, IMR3); 720 ines_outb(ines_priv, 0, IMR4); 721 } 722 723 nec7210_board_online(nec_priv, board); 724 if (use_accel) 725 nec7210_set_reg_bits(nec_priv, IMR1, HR_DOIE | HR_DIIE, 0); 726 } 727 728 static int ines_common_pci_attach(gpib_board_t *board, const gpib_board_config_t *config) 729 { 730 struct ines_priv *ines_priv; 731 struct nec7210_priv *nec_priv; 732 int isr_flags = 0; 733 int retval; 734 struct ines_pci_id found_id; 735 unsigned int i; 736 struct pci_dev *pdev; 737 738 memset(&found_id, 0, sizeof(found_id)); 739 740 retval = ines_generic_attach(board); 741 if (retval) 742 return retval; 743 744 ines_priv = board->private_data; 745 nec_priv = &ines_priv->nec7210_priv; 746 747 // find board 748 ines_priv->pci_device = NULL; 749 for (i = 0; i < num_pci_chips && !ines_priv->pci_device; i++) { 750 pdev = NULL; 751 do { 752 if (pci_ids[i].subsystem_vendor_id >= 0 && 753 pci_ids[i].subsystem_device_id >= 0) 754 pdev = pci_get_subsys(pci_ids[i].vendor_id, pci_ids[i].device_id, 755 pci_ids[i].subsystem_vendor_id, 756 pci_ids[i].subsystem_device_id, pdev); 757 else 758 pdev = pci_get_device(pci_ids[i].vendor_id, pci_ids[i].device_id, 759 pdev); 760 if (!pdev) 761 break; 762 if (config->pci_bus >= 0 && config->pci_bus != pdev->bus->number) 763 continue; 764 if (config->pci_slot >= 0 && config->pci_slot != PCI_SLOT(pdev->devfn)) 765 continue; 766 found_id = pci_ids[i]; 767 ines_priv->pci_device = pdev; 768 break; 769 } while (1); 770 } 771 if (!ines_priv->pci_device) { 772 pr_err("gpib: could not find ines PCI board\n"); 773 return -1; 774 } 775 776 if (pci_enable_device(ines_priv->pci_device)) { 777 pr_err("error enabling pci device\n"); 778 return -1; 779 } 780 781 if (pci_request_regions(ines_priv->pci_device, "ines-gpib")) 782 return -1; 783 nec_priv->iobase = pci_resource_start(ines_priv->pci_device, 784 found_id.gpib_region); 785 786 ines_priv->pci_chip_type = found_id.pci_chip_type; 787 nec_priv->offset = found_id.io_offset; 788 switch (ines_priv->pci_chip_type) { 789 case PCI_CHIP_PLX9050: 790 ines_priv->plx_iobase = pci_resource_start(ines_priv->pci_device, 1); 791 break; 792 case PCI_CHIP_AMCC5920: 793 ines_priv->amcc_iobase = pci_resource_start(ines_priv->pci_device, 0); 794 break; 795 case PCI_CHIP_QUANCOM: 796 break; 797 case PCI_CHIP_QUICKLOGIC5030: 798 break; 799 default: 800 pr_err("gpib: unspecified chip type? (bug)\n"); 801 nec_priv->iobase = 0; 802 pci_release_regions(ines_priv->pci_device); 803 return -1; 804 } 805 806 nec7210_board_reset(nec_priv, board); 807 #ifdef QUANCOM_PCI 808 if (ines_priv->pci_chip_type == PCI_CHIP_QUANCOM) { 809 /* change interrupt polarity */ 810 nec_priv->auxb_bits |= HR_INV; 811 ines_outb(ines_priv, nec_priv->auxb_bits, AUXMR); 812 } 813 #endif 814 isr_flags |= IRQF_SHARED; 815 if (request_irq(ines_priv->pci_device->irq, ines_pci_interrupt, isr_flags, 816 "pci-gpib", board)) { 817 pr_err("gpib: can't request IRQ %d\n", ines_priv->pci_device->irq); 818 return -1; 819 } 820 ines_priv->irq = ines_priv->pci_device->irq; 821 822 // enable interrupts on pci chip 823 switch (ines_priv->pci_chip_type) { 824 case PCI_CHIP_PLX9050: 825 outl(PLX9050_LINTR1_EN_BIT | PLX9050_LINTR1_POLARITY_BIT | PLX9050_PCI_INTR_EN_BIT, 826 ines_priv->plx_iobase + PLX9050_INTCSR_REG); 827 break; 828 case PCI_CHIP_AMCC5920: 829 { 830 static const int region = 1; 831 static const int num_wait_states = 7; 832 u32 bits; 833 834 bits = amcc_prefetch_bits(region, PREFETCH_DISABLED); 835 bits |= amcc_PTADR_mode_bit(region); 836 bits |= amcc_disable_write_fifo_bit(region); 837 bits |= amcc_wait_state_bits(region, num_wait_states); 838 outl(bits, ines_priv->amcc_iobase + AMCC_PASS_THRU_REG); 839 outl(AMCC_ADDON_INTR_ENABLE_BIT, ines_priv->amcc_iobase + AMCC_INTCS_REG); 840 } 841 break; 842 case PCI_CHIP_QUANCOM: 843 outb(QUANCOM_IRQ_ENABLE_BIT, nec_priv->iobase + 844 QUANCOM_IRQ_CONTROL_STATUS_REG); 845 break; 846 case PCI_CHIP_QUICKLOGIC5030: 847 break; 848 default: 849 pr_err("gpib: unspecified chip type? (bug)\n"); 850 return -1; 851 } 852 853 return 0; 854 } 855 856 int ines_pci_attach(gpib_board_t *board, const gpib_board_config_t *config) 857 { 858 struct ines_priv *ines_priv; 859 int retval; 860 861 retval = ines_common_pci_attach(board, config); 862 if (retval < 0) 863 return retval; 864 865 ines_priv = board->private_data; 866 ines_online(ines_priv, board, 0); 867 868 return 0; 869 } 870 871 int ines_pci_accel_attach(gpib_board_t *board, const gpib_board_config_t *config) 872 { 873 struct ines_priv *ines_priv; 874 int retval; 875 876 retval = ines_common_pci_attach(board, config); 877 if (retval < 0) 878 return retval; 879 880 ines_priv = board->private_data; 881 ines_online(ines_priv, board, 1); 882 883 return 0; 884 } 885 886 static const int ines_isa_iosize = 0x20; 887 888 int ines_isa_attach(gpib_board_t *board, const gpib_board_config_t *config) 889 { 890 struct ines_priv *ines_priv; 891 struct nec7210_priv *nec_priv; 892 int isr_flags = 0; 893 int retval; 894 895 retval = ines_generic_attach(board); 896 if (retval) 897 return retval; 898 899 ines_priv = board->private_data; 900 nec_priv = &ines_priv->nec7210_priv; 901 902 if (!request_region(config->ibbase, ines_isa_iosize, "ines_gpib")) { 903 pr_err("ines_gpib: ioports at 0x%x already in use\n", config->ibbase); 904 return -1; 905 } 906 nec_priv->iobase = config->ibbase; 907 nec_priv->offset = 1; 908 nec7210_board_reset(nec_priv, board); 909 if (request_irq(config->ibirq, ines_pci_interrupt, isr_flags, "ines_gpib", board)) { 910 pr_err("ines_gpib: failed to allocate IRQ %d\n", config->ibirq); 911 return -1; 912 } 913 ines_priv->irq = config->ibirq; 914 ines_online(ines_priv, board, 1); 915 return 0; 916 } 917 918 void ines_pci_detach(gpib_board_t *board) 919 { 920 struct ines_priv *ines_priv = board->private_data; 921 struct nec7210_priv *nec_priv; 922 923 if (ines_priv) { 924 nec_priv = &ines_priv->nec7210_priv; 925 if (ines_priv->irq) { 926 // disable interrupts 927 switch (ines_priv->pci_chip_type) { 928 case PCI_CHIP_AMCC5920: 929 if (ines_priv->plx_iobase) 930 outl(0, ines_priv->plx_iobase + PLX9050_INTCSR_REG); 931 break; 932 case PCI_CHIP_QUANCOM: 933 if (nec_priv->iobase) 934 outb(0, nec_priv->iobase + 935 QUANCOM_IRQ_CONTROL_STATUS_REG); 936 break; 937 default: 938 break; 939 } 940 free_irq(ines_priv->irq, board); 941 } 942 if (nec_priv->iobase) { 943 nec7210_board_reset(nec_priv, board); 944 pci_release_regions(ines_priv->pci_device); 945 } 946 if (ines_priv->pci_device) 947 pci_dev_put(ines_priv->pci_device); 948 } 949 ines_free_private(board); 950 } 951 952 void ines_isa_detach(gpib_board_t *board) 953 { 954 struct ines_priv *ines_priv = board->private_data; 955 struct nec7210_priv *nec_priv; 956 957 if (ines_priv) { 958 nec_priv = &ines_priv->nec7210_priv; 959 if (ines_priv->irq) 960 free_irq(ines_priv->irq, board); 961 if (nec_priv->iobase) { 962 nec7210_board_reset(nec_priv, board); 963 release_region(nec_priv->iobase, ines_isa_iosize); 964 } 965 } 966 ines_free_private(board); 967 } 968 969 static int ines_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) 970 { 971 return 0; 972 } 973 974 static struct pci_driver ines_pci_driver = { 975 .name = "ines_gpib", 976 .id_table = ines_pci_table, 977 .probe = &ines_pci_probe 978 }; 979 980 #ifdef GPIB_PCMCIA 981 982 #include <linux/kernel.h> 983 #include <linux/ptrace.h> 984 #include <linux/string.h> 985 #include <linux/timer.h> 986 987 #include <pcmcia/cistpl.h> 988 #include <pcmcia/ds.h> 989 #include <pcmcia/cisreg.h> 990 991 #ifdef PCMCIA_DEBUG 992 static int pc_debug = PCMCIA_DEBUG; 993 #define DEBUG(n, args...) do {if (pc_debug > (n)) pr_debug(args)} while (0) 994 #else 995 #define DEBUG(args...) 996 #endif 997 998 static const int ines_pcmcia_iosize = 0x20; 999 1000 /* The event() function is this driver's Card Services event handler. 1001 * It will be called by Card Services when an appropriate card status 1002 * event is received. The config() and release() entry points are 1003 * used to configure or release a socket, in response to card insertion 1004 * and ejection events. They are invoked from the gpib event 1005 * handler. 1006 */ 1007 1008 static int ines_gpib_config(struct pcmcia_device *link); 1009 static void ines_gpib_release(struct pcmcia_device *link); 1010 static int ines_pcmcia_attach(gpib_board_t *board, const gpib_board_config_t *config); 1011 static int ines_pcmcia_accel_attach(gpib_board_t *board, const gpib_board_config_t *config); 1012 static void ines_pcmcia_detach(gpib_board_t *board); 1013 static irqreturn_t ines_pcmcia_interrupt(int irq, void *arg); 1014 static int ines_common_pcmcia_attach(gpib_board_t *board); 1015 /* 1016 * A linked list of "instances" of the gpib device. Each actual 1017 * PCMCIA card corresponds to one device instance, and is described 1018 * by one dev_link_t structure (defined in ds.h). 1019 * 1020 * You may not want to use a linked list for this -- for example, the 1021 * memory card driver uses an array of dev_link_t pointers, where minor 1022 * device numbers are used to derive the corresponding array index. 1023 */ 1024 1025 static struct pcmcia_device *curr_dev; 1026 1027 /* 1028 * A dev_link_t structure has fields for most things that are needed 1029 * to keep track of a socket, but there will usually be some device 1030 * specific information that also needs to be kept track of. The 1031 * 'priv' pointer in a dev_link_t structure can be used to point to 1032 * a device-specific private data structure, like this. 1033 * 1034 * A driver needs to provide a dev_node_t structure for each device 1035 * on a card. In some cases, there is only one device per card (for 1036 * example, ethernet cards, modems). In other cases, there may be 1037 * many actual or logical devices (SCSI adapters, memory cards with 1038 * multiple partitions). The dev_node_t structures need to be kept 1039 * in a linked list starting at the 'dev' field of a dev_link_t 1040 * structure. We allocate them in the card's private data structure, 1041 * because they generally can't be allocated dynamically. 1042 */ 1043 1044 struct local_info { 1045 struct pcmcia_device *p_dev; 1046 gpib_board_t *dev; 1047 u_short manfid; 1048 u_short cardid; 1049 }; 1050 1051 /* 1052 * gpib_attach() creates an "instance" of the driver, allocating 1053 * local data structures for one device. The device is registered 1054 * with Card Services. 1055 * 1056 * The dev_link structure is initialized, but we don't actually 1057 * configure the card at this point -- we wait until we receive a 1058 * card insertion event. 1059 */ 1060 static int ines_gpib_probe(struct pcmcia_device *link) 1061 { 1062 struct local_info *info; 1063 1064 // int ret, i; 1065 1066 DEBUG(0, "%s(0x%p)\n", __func__ link); 1067 1068 /* Allocate space for private device-specific data */ 1069 info = kzalloc(sizeof(*info), GFP_KERNEL); 1070 if (!info) 1071 return -ENOMEM; 1072 1073 info->p_dev = link; 1074 link->priv = info; 1075 1076 /* The io structure describes IO port mapping */ 1077 link->resource[0]->end = 32; 1078 link->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; 1079 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; 1080 link->io_lines = 5; 1081 1082 /* General socket configuration */ 1083 link->config_flags = CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; 1084 1085 /* Register with Card Services */ 1086 curr_dev = link; 1087 return ines_gpib_config(link); 1088 } 1089 1090 /* 1091 * This deletes a driver "instance". The device is de-registered 1092 * with Card Services. If it has been released, all local data 1093 * structures are freed. Otherwise, the structures will be freed 1094 * when the device is released. 1095 */ 1096 static void ines_gpib_remove(struct pcmcia_device *link) 1097 { 1098 struct local_info *info = link->priv; 1099 //struct gpib_board_t *dev = info->dev; 1100 1101 DEBUG(0, "%s(0x%p)\n", __func__, link); 1102 1103 if (info->dev) 1104 ines_pcmcia_detach(info->dev); 1105 ines_gpib_release(link); 1106 1107 //free_netdev(dev); 1108 kfree(info); 1109 } 1110 1111 static int ines_gpib_config_iteration(struct pcmcia_device *link, void *priv_data) 1112 { 1113 return pcmcia_request_io(link); 1114 } 1115 1116 /* 1117 * gpib_config() is scheduled to run after a CARD_INSERTION event 1118 * is received, to configure the PCMCIA socket, and to make the 1119 * device available to the system. 1120 */ 1121 static int ines_gpib_config(struct pcmcia_device *link) 1122 { 1123 struct local_info *dev; 1124 int retval; 1125 void __iomem *virt; 1126 1127 dev = link->priv; 1128 DEBUG(0, "%s(0x%p)\n", __func__, link); 1129 1130 retval = pcmcia_loop_config(link, &ines_gpib_config_iteration, NULL); 1131 if (retval) { 1132 dev_warn(&link->dev, "no configuration found\n"); 1133 ines_gpib_release(link); 1134 return -ENODEV; 1135 } 1136 1137 pr_debug("ines_cs: manufacturer: 0x%x card: 0x%x\n", 1138 link->manf_id, link->card_id); 1139 1140 /* for the ines card we have to setup the configuration registers in 1141 * attribute memory here 1142 */ 1143 link->resource[2]->flags |= WIN_MEMORY_TYPE_AM | WIN_DATA_WIDTH_8 | WIN_ENABLE; 1144 link->resource[2]->end = 0x1000; 1145 retval = pcmcia_request_window(link, link->resource[2], 250); 1146 if (retval) { 1147 dev_warn(&link->dev, "pcmcia_request_window failed\n"); 1148 ines_gpib_release(link); 1149 return -ENODEV; 1150 } 1151 retval = pcmcia_map_mem_page(link, link->resource[2], 0); 1152 if (retval) { 1153 dev_warn(&link->dev, "pcmcia_map_mem_page failed\n"); 1154 ines_gpib_release(link); 1155 return -ENODEV; 1156 } 1157 virt = ioremap(link->resource[2]->start, resource_size(link->resource[2])); 1158 writeb((link->resource[2]->start >> 2) & 0xff, virt + 0xf0); // IOWindow base 1159 iounmap(virt); 1160 1161 /* 1162 * This actually configures the PCMCIA socket -- setting up 1163 * the I/O windows and the interrupt mapping. 1164 */ 1165 retval = pcmcia_enable_device(link); 1166 if (retval) { 1167 ines_gpib_release(link); 1168 return -ENODEV; 1169 } 1170 pr_info("ines gpib device loaded\n"); 1171 return 0; 1172 } /* gpib_config */ 1173 1174 /* 1175 * After a card is removed, gpib_release() will unregister the net 1176 * device, and release the PCMCIA configuration. If the device is 1177 * still open, this will be postponed until it is closed. 1178 */ 1179 1180 static void ines_gpib_release(struct pcmcia_device *link) 1181 { 1182 DEBUG(0, "%s(0x%p)\n", __func__, link); 1183 pcmcia_disable_device(link); 1184 } /* gpib_release */ 1185 1186 static int ines_gpib_suspend(struct pcmcia_device *link) 1187 { 1188 //struct local_info *info = link->priv; 1189 //struct gpib_board_t *dev = info->dev; 1190 DEBUG(0, "%s(0x%p)\n", __func__, link); 1191 1192 if (link->open) 1193 pr_err("Device still open ???\n"); 1194 //netif_device_detach(dev); 1195 1196 return 0; 1197 } 1198 1199 static int ines_gpib_resume(struct pcmcia_device *link) 1200 { 1201 //struct local_info_t *info = link->priv; 1202 //struct gpib_board_t *dev = info->dev; 1203 DEBUG(0, "%s(0x%p)\n", __func__, link); 1204 1205 /*if (link->open) { 1206 * ni_gpib_probe(dev); / really? 1207 * printk("Gpib resumed ???\n"); 1208 * //netif_device_attach(dev); 1209 *} 1210 */ 1211 return ines_gpib_config(link); 1212 } 1213 1214 static struct pcmcia_device_id ines_pcmcia_ids[] = { 1215 PCMCIA_DEVICE_MANF_CARD(0x01b4, 0x4730), 1216 PCMCIA_DEVICE_NULL 1217 }; 1218 MODULE_DEVICE_TABLE(pcmcia, ines_pcmcia_ids); 1219 1220 static struct pcmcia_driver ines_gpib_cs_driver = { 1221 .owner = THIS_MODULE, 1222 .name = "ines_gpib_cs", 1223 .id_table = ines_pcmcia_ids, 1224 .probe = ines_gpib_probe, 1225 .remove = ines_gpib_remove, 1226 .suspend = ines_gpib_suspend, 1227 .resume = ines_gpib_resume, 1228 }; 1229 1230 void ines_pcmcia_cleanup_module(void) 1231 { 1232 DEBUG(0, "ines_cs: unloading\n"); 1233 pcmcia_unregister_driver(&ines_gpib_cs_driver); 1234 } 1235 1236 static gpib_interface_t ines_pcmcia_unaccel_interface = { 1237 .name = "ines_pcmcia_unaccel", 1238 .attach = ines_pcmcia_attach, 1239 .detach = ines_pcmcia_detach, 1240 .read = ines_read, 1241 .write = ines_write, 1242 .command = ines_command, 1243 .take_control = ines_take_control, 1244 .go_to_standby = ines_go_to_standby, 1245 .request_system_control = ines_request_system_control, 1246 .interface_clear = ines_interface_clear, 1247 .remote_enable = ines_remote_enable, 1248 .enable_eos = ines_enable_eos, 1249 .disable_eos = ines_disable_eos, 1250 .parallel_poll = ines_parallel_poll, 1251 .parallel_poll_configure = ines_parallel_poll_configure, 1252 .parallel_poll_response = ines_parallel_poll_response, 1253 .local_parallel_poll_mode = NULL, // XXX 1254 .line_status = ines_line_status, 1255 .update_status = ines_update_status, 1256 .primary_address = ines_primary_address, 1257 .secondary_address = ines_secondary_address, 1258 .serial_poll_response = ines_serial_poll_response, 1259 .serial_poll_status = ines_serial_poll_status, 1260 .t1_delay = ines_t1_delay, 1261 .return_to_local = ines_return_to_local, 1262 }; 1263 1264 static gpib_interface_t ines_pcmcia_accel_interface = { 1265 .name = "ines_pcmcia_accel", 1266 .attach = ines_pcmcia_accel_attach, 1267 .detach = ines_pcmcia_detach, 1268 .read = ines_accel_read, 1269 .write = ines_accel_write, 1270 .command = ines_command, 1271 .take_control = ines_take_control, 1272 .go_to_standby = ines_go_to_standby, 1273 .request_system_control = ines_request_system_control, 1274 .interface_clear = ines_interface_clear, 1275 .remote_enable = ines_remote_enable, 1276 .enable_eos = ines_enable_eos, 1277 .disable_eos = ines_disable_eos, 1278 .parallel_poll = ines_parallel_poll, 1279 .parallel_poll_configure = ines_parallel_poll_configure, 1280 .parallel_poll_response = ines_parallel_poll_response, 1281 .local_parallel_poll_mode = NULL, // XXX 1282 .line_status = ines_line_status, 1283 .update_status = ines_update_status, 1284 .primary_address = ines_primary_address, 1285 .secondary_address = ines_secondary_address, 1286 .serial_poll_response = ines_serial_poll_response, 1287 .serial_poll_status = ines_serial_poll_status, 1288 .t1_delay = ines_t1_delay, 1289 .return_to_local = ines_return_to_local, 1290 }; 1291 1292 static gpib_interface_t ines_pcmcia_interface = { 1293 .name = "ines_pcmcia", 1294 .attach = ines_pcmcia_accel_attach, 1295 .detach = ines_pcmcia_detach, 1296 .read = ines_accel_read, 1297 .write = ines_accel_write, 1298 .command = ines_command, 1299 .take_control = ines_take_control, 1300 .go_to_standby = ines_go_to_standby, 1301 .request_system_control = ines_request_system_control, 1302 .interface_clear = ines_interface_clear, 1303 .remote_enable = ines_remote_enable, 1304 .enable_eos = ines_enable_eos, 1305 .disable_eos = ines_disable_eos, 1306 .parallel_poll = ines_parallel_poll, 1307 .parallel_poll_configure = ines_parallel_poll_configure, 1308 .parallel_poll_response = ines_parallel_poll_response, 1309 .local_parallel_poll_mode = NULL, // XXX 1310 .line_status = ines_line_status, 1311 .update_status = ines_update_status, 1312 .primary_address = ines_primary_address, 1313 .secondary_address = ines_secondary_address, 1314 .serial_poll_response = ines_serial_poll_response, 1315 .serial_poll_status = ines_serial_poll_status, 1316 .t1_delay = ines_t1_delay, 1317 .return_to_local = ines_return_to_local, 1318 }; 1319 1320 irqreturn_t ines_pcmcia_interrupt(int irq, void *arg) 1321 { 1322 gpib_board_t *board = arg; 1323 1324 return ines_interrupt(board); 1325 } 1326 1327 int ines_common_pcmcia_attach(gpib_board_t *board) 1328 { 1329 struct ines_priv *ines_priv; 1330 struct nec7210_priv *nec_priv; 1331 int retval; 1332 1333 if (!curr_dev) { 1334 pr_err("no ines pcmcia cards found\n"); 1335 return -1; 1336 } 1337 1338 retval = ines_generic_attach(board); 1339 if (retval) 1340 return retval; 1341 1342 ines_priv = board->private_data; 1343 nec_priv = &ines_priv->nec7210_priv; 1344 1345 if (!request_region(curr_dev->resource[0]->start, 1346 resource_size(curr_dev->resource[0]), "ines_gpib")) { 1347 pr_err("ines_gpib: ioports at 0x%lx already in use\n", 1348 (unsigned long)(curr_dev->resource[0]->start)); 1349 return -1; 1350 } 1351 1352 nec_priv->iobase = curr_dev->resource[0]->start; 1353 1354 nec7210_board_reset(nec_priv, board); 1355 1356 if (request_irq(curr_dev->irq, ines_pcmcia_interrupt, IRQF_SHARED, 1357 "pcmcia-gpib", board)) { 1358 pr_err("gpib: can't request IRQ %d\n", curr_dev->irq); 1359 return -1; 1360 } 1361 ines_priv->irq = curr_dev->irq; 1362 1363 return 0; 1364 } 1365 1366 int ines_pcmcia_attach(gpib_board_t *board, const gpib_board_config_t *config) 1367 { 1368 struct ines_priv *ines_priv; 1369 int retval; 1370 1371 retval = ines_common_pcmcia_attach(board); 1372 if (retval < 0) 1373 return retval; 1374 1375 ines_priv = board->private_data; 1376 ines_online(ines_priv, board, 0); 1377 1378 return 0; 1379 } 1380 1381 int ines_pcmcia_accel_attach(gpib_board_t *board, const gpib_board_config_t *config) 1382 { 1383 struct ines_priv *ines_priv; 1384 int retval; 1385 1386 retval = ines_common_pcmcia_attach(board); 1387 if (retval < 0) 1388 return retval; 1389 1390 ines_priv = board->private_data; 1391 ines_online(ines_priv, board, 1); 1392 1393 return 0; 1394 } 1395 1396 void ines_pcmcia_detach(gpib_board_t *board) 1397 { 1398 struct ines_priv *ines_priv = board->private_data; 1399 struct nec7210_priv *nec_priv; 1400 1401 if (ines_priv) { 1402 nec_priv = &ines_priv->nec7210_priv; 1403 if (ines_priv->irq) 1404 free_irq(ines_priv->irq, board); 1405 if (nec_priv->iobase) { 1406 nec7210_board_reset(nec_priv, board); 1407 release_region(nec_priv->iobase, ines_pcmcia_iosize); 1408 } 1409 } 1410 ines_free_private(board); 1411 } 1412 1413 #endif /* GPIB_PCMCIA */ 1414 1415 static int __init ines_init_module(void) 1416 { 1417 int ret; 1418 1419 ret = pci_register_driver(&ines_pci_driver); 1420 if (ret) { 1421 pr_err("ines_gpib: pci_register_driver failed: error = %d\n", ret); 1422 return ret; 1423 } 1424 1425 ret = gpib_register_driver(&ines_pci_interface, THIS_MODULE); 1426 if (ret) { 1427 pr_err("ines_gpib: gpib_register_driver failed: error = %d\n", ret); 1428 goto err_pci; 1429 } 1430 1431 ret = gpib_register_driver(&ines_pci_unaccel_interface, THIS_MODULE); 1432 if (ret) { 1433 pr_err("ines_gpib: gpib_register_driver failed: error = %d\n", ret); 1434 goto err_pci_unaccel; 1435 } 1436 1437 ret = gpib_register_driver(&ines_pci_accel_interface, THIS_MODULE); 1438 if (ret) { 1439 pr_err("ines_gpib: gpib_register_driver failed: error = %d\n", ret); 1440 goto err_pci_accel; 1441 } 1442 1443 ret = gpib_register_driver(&ines_isa_interface, THIS_MODULE); 1444 if (ret) { 1445 pr_err("ines_gpib: gpib_register_driver failed: error = %d\n", ret); 1446 goto err_isa; 1447 } 1448 1449 #ifdef GPIB_PCMCIA 1450 ret = gpib_register_driver(&ines_pcmcia_interface, THIS_MODULE); 1451 if (ret) { 1452 pr_err("ines_gpib: gpib_register_driver failed: error = %d\n", ret); 1453 goto err_pcmcia; 1454 } 1455 1456 ret = gpib_register_driver(&ines_pcmcia_unaccel_interface, THIS_MODULE); 1457 if (ret) { 1458 pr_err("ines_gpib: gpib_register_driver failed: error = %d\n", ret); 1459 goto err_pcmcia_unaccel; 1460 } 1461 1462 ret = gpib_register_driver(&ines_pcmcia_accel_interface, THIS_MODULE); 1463 if (ret) { 1464 pr_err("ines_gpib: gpib_register_driver failed: error = %d\n", ret); 1465 goto err_pcmcia_accel; 1466 } 1467 1468 ret = pcmcia_register_driver(&ines_gpib_cs_driver); 1469 if (ret) { 1470 pr_err("ines_gpib: pcmcia_register_driver failed: error = %d\n", ret); 1471 goto err_pcmcia_driver; 1472 } 1473 #endif 1474 1475 return 0; 1476 1477 #ifdef GPIB_PCMCIA 1478 err_pcmcia_driver: 1479 gpib_unregister_driver(&ines_pcmcia_accel_interface); 1480 err_pcmcia_accel: 1481 gpib_unregister_driver(&ines_pcmcia_unaccel_interface); 1482 err_pcmcia_unaccel: 1483 gpib_unregister_driver(&ines_pcmcia_interface); 1484 err_pcmcia: 1485 #endif 1486 gpib_unregister_driver(&ines_isa_interface); 1487 err_isa: 1488 gpib_unregister_driver(&ines_pci_accel_interface); 1489 err_pci_accel: 1490 gpib_unregister_driver(&ines_pci_unaccel_interface); 1491 err_pci_unaccel: 1492 gpib_unregister_driver(&ines_pci_interface); 1493 err_pci: 1494 pci_unregister_driver(&ines_pci_driver); 1495 1496 return ret; 1497 } 1498 1499 static void __exit ines_exit_module(void) 1500 { 1501 gpib_unregister_driver(&ines_pci_interface); 1502 gpib_unregister_driver(&ines_pci_unaccel_interface); 1503 gpib_unregister_driver(&ines_pci_accel_interface); 1504 gpib_unregister_driver(&ines_isa_interface); 1505 #ifdef GPIB__PCMCIA 1506 gpib_unregister_driver(&ines_pcmcia_interface); 1507 gpib_unregister_driver(&ines_pcmcia_unaccel_interface); 1508 gpib_unregister_driver(&ines_pcmcia_accel_interface); 1509 ines_pcmcia_cleanup_module(); 1510 #endif 1511 1512 pci_unregister_driver(&ines_pci_driver); 1513 } 1514 1515 module_init(ines_init_module); 1516 module_exit(ines_exit_module); 1517