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