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 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, PCI_VENDOR_ID_PLX, 375 PCI_SUBDEVICE_ID_INES_GPIB, 0, 0, 0}, 376 {PCI_VENDOR_ID_AMCC, PCI_DEVICE_ID_INES_GPIB_AMCC, PCI_VENDOR_ID_AMCC, 377 PCI_SUBDEVICE_ID_INES_GPIB, 0, 0, 0}, 378 {PCI_VENDOR_ID_INES_QUICKLOGIC, PCI_DEVICE_ID_INES_GPIB_QL5030, 379 PCI_VENDOR_ID_INES_QUICKLOGIC, PCI_DEVICE_ID_INES_GPIB_QL5030, 0, 0, 0}, 380 {PCI_DEVICE(PCI_VENDOR_ID_QUANCOM, PCI_DEVICE_ID_QUANCOM_GPIB)}, 381 {0} 382 }; 383 MODULE_DEVICE_TABLE(pci, ines_pci_table); 384 385 struct ines_pci_id { 386 unsigned int vendor_id; 387 unsigned int device_id; 388 int subsystem_vendor_id; 389 int subsystem_device_id; 390 unsigned int gpib_region; 391 unsigned int io_offset; 392 enum ines_pci_chip pci_chip_type; 393 }; 394 395 static struct ines_pci_id pci_ids[] = { 396 {.vendor_id = PCI_VENDOR_ID_PLX, 397 .device_id = PCI_DEVICE_ID_PLX_9050, 398 .subsystem_vendor_id = PCI_VENDOR_ID_PLX, 399 .subsystem_device_id = PCI_SUBDEVICE_ID_INES_GPIB, 400 .gpib_region = 2, 401 .io_offset = 1, 402 .pci_chip_type = PCI_CHIP_PLX9050, 403 }, 404 {.vendor_id = PCI_VENDOR_ID_AMCC, 405 .device_id = PCI_DEVICE_ID_INES_GPIB_AMCC, 406 .subsystem_vendor_id = PCI_VENDOR_ID_AMCC, 407 .subsystem_device_id = PCI_SUBDEVICE_ID_INES_GPIB, 408 .gpib_region = 1, 409 .io_offset = 1, 410 .pci_chip_type = PCI_CHIP_AMCC5920, 411 }, 412 {.vendor_id = PCI_VENDOR_ID_INES_QUICKLOGIC, 413 .device_id = PCI_DEVICE_ID_INES_GPIB_QL5030, 414 .subsystem_vendor_id = PCI_VENDOR_ID_INES_QUICKLOGIC, 415 .subsystem_device_id = PCI_DEVICE_ID_INES_GPIB_QL5030, 416 .gpib_region = 1, 417 .io_offset = 1, 418 .pci_chip_type = PCI_CHIP_QUICKLOGIC5030, 419 }, 420 {.vendor_id = PCI_VENDOR_ID_QUANCOM, 421 .device_id = PCI_DEVICE_ID_QUANCOM_GPIB, 422 .subsystem_vendor_id = -1, 423 .subsystem_device_id = -1, 424 .gpib_region = 0, 425 .io_offset = 4, 426 .pci_chip_type = PCI_CHIP_QUANCOM, 427 }, 428 }; 429 430 static const int num_pci_chips = ARRAY_SIZE(pci_ids); 431 432 // wrappers for interface functions 433 static int ines_read(struct gpib_board *board, u8 *buffer, size_t length, 434 int *end, size_t *bytes_read) 435 { 436 struct ines_priv *priv = board->private_data; 437 struct nec7210_priv *nec_priv = &priv->nec7210_priv; 438 ssize_t retval; 439 int dummy; 440 441 retval = nec7210_read(board, &priv->nec7210_priv, buffer, length, end, bytes_read); 442 if (retval < 0) { 443 write_byte(nec_priv, INES_RFD_HLD_IMMEDIATE, AUXMR); 444 445 set_bit(RFD_HOLDOFF_BN, &nec_priv->state); 446 447 nec7210_read_data_in(board, nec_priv, &dummy); 448 } 449 return retval; 450 } 451 452 static int ines_write(struct gpib_board *board, u8 *buffer, size_t length, int send_eoi, 453 size_t *bytes_written) 454 { 455 struct ines_priv *priv = board->private_data; 456 457 return nec7210_write(board, &priv->nec7210_priv, buffer, length, send_eoi, bytes_written); 458 } 459 460 static int ines_command(struct gpib_board *board, u8 *buffer, size_t length, size_t *bytes_written) 461 { 462 struct ines_priv *priv = board->private_data; 463 464 return nec7210_command(board, &priv->nec7210_priv, buffer, length, bytes_written); 465 } 466 467 static int ines_take_control(struct gpib_board *board, int synchronous) 468 { 469 struct ines_priv *priv = board->private_data; 470 471 return nec7210_take_control(board, &priv->nec7210_priv, synchronous); 472 } 473 474 static int ines_go_to_standby(struct gpib_board *board) 475 { 476 struct ines_priv *priv = board->private_data; 477 478 return nec7210_go_to_standby(board, &priv->nec7210_priv); 479 } 480 481 static int ines_request_system_control(struct gpib_board *board, int request_control) 482 { 483 struct ines_priv *priv = board->private_data; 484 485 return nec7210_request_system_control(board, &priv->nec7210_priv, request_control); 486 } 487 488 static void ines_interface_clear(struct gpib_board *board, int assert) 489 { 490 struct ines_priv *priv = board->private_data; 491 492 nec7210_interface_clear(board, &priv->nec7210_priv, assert); 493 } 494 495 static void ines_remote_enable(struct gpib_board *board, int enable) 496 { 497 struct ines_priv *priv = board->private_data; 498 499 nec7210_remote_enable(board, &priv->nec7210_priv, enable); 500 } 501 502 static int ines_enable_eos(struct gpib_board *board, u8 eos_byte, int compare_8_bits) 503 { 504 struct ines_priv *priv = board->private_data; 505 506 return nec7210_enable_eos(board, &priv->nec7210_priv, eos_byte, compare_8_bits); 507 } 508 509 static void ines_disable_eos(struct gpib_board *board) 510 { 511 struct ines_priv *priv = board->private_data; 512 513 nec7210_disable_eos(board, &priv->nec7210_priv); 514 } 515 516 static unsigned int ines_update_status(struct gpib_board *board, unsigned int clear_mask) 517 { 518 struct ines_priv *priv = board->private_data; 519 520 return nec7210_update_status(board, &priv->nec7210_priv, clear_mask); 521 } 522 523 static int ines_primary_address(struct gpib_board *board, unsigned int address) 524 { 525 struct ines_priv *priv = board->private_data; 526 527 return nec7210_primary_address(board, &priv->nec7210_priv, address); 528 } 529 530 static int ines_secondary_address(struct gpib_board *board, unsigned int address, int enable) 531 { 532 struct ines_priv *priv = board->private_data; 533 534 return nec7210_secondary_address(board, &priv->nec7210_priv, address, enable); 535 } 536 537 static int ines_parallel_poll(struct gpib_board *board, u8 *result) 538 { 539 struct ines_priv *priv = board->private_data; 540 541 return nec7210_parallel_poll(board, &priv->nec7210_priv, result); 542 } 543 544 static void ines_parallel_poll_configure(struct gpib_board *board, u8 config) 545 { 546 struct ines_priv *priv = board->private_data; 547 548 nec7210_parallel_poll_configure(board, &priv->nec7210_priv, config); 549 } 550 551 static void ines_parallel_poll_response(struct gpib_board *board, int ist) 552 { 553 struct ines_priv *priv = board->private_data; 554 555 nec7210_parallel_poll_response(board, &priv->nec7210_priv, ist); 556 } 557 558 static void ines_serial_poll_response(struct gpib_board *board, u8 status) 559 { 560 struct ines_priv *priv = board->private_data; 561 562 nec7210_serial_poll_response(board, &priv->nec7210_priv, status); 563 } 564 565 static u8 ines_serial_poll_status(struct gpib_board *board) 566 { 567 struct ines_priv *priv = board->private_data; 568 569 return nec7210_serial_poll_status(board, &priv->nec7210_priv); 570 } 571 572 static void ines_return_to_local(struct gpib_board *board) 573 { 574 struct ines_priv *priv = board->private_data; 575 576 nec7210_return_to_local(board, &priv->nec7210_priv); 577 } 578 579 static struct gpib_interface ines_pci_unaccel_interface = { 580 .name = "ines_pci_unaccel", 581 .attach = ines_pci_attach, 582 .detach = ines_pci_detach, 583 .read = ines_read, 584 .write = ines_write, 585 .command = ines_command, 586 .take_control = ines_take_control, 587 .go_to_standby = ines_go_to_standby, 588 .request_system_control = ines_request_system_control, 589 .interface_clear = ines_interface_clear, 590 .remote_enable = ines_remote_enable, 591 .enable_eos = ines_enable_eos, 592 .disable_eos = ines_disable_eos, 593 .parallel_poll = ines_parallel_poll, 594 .parallel_poll_configure = ines_parallel_poll_configure, 595 .parallel_poll_response = ines_parallel_poll_response, 596 .local_parallel_poll_mode = NULL, // XXX 597 .line_status = ines_line_status, 598 .update_status = ines_update_status, 599 .primary_address = ines_primary_address, 600 .secondary_address = ines_secondary_address, 601 .serial_poll_response = ines_serial_poll_response, 602 .serial_poll_status = ines_serial_poll_status, 603 .t1_delay = ines_t1_delay, 604 .return_to_local = ines_return_to_local, 605 }; 606 607 static struct gpib_interface ines_pci_xl_interface = { 608 .name = "ines_pci_xl", 609 .attach = ines_pci_xl_attach, 610 .detach = ines_pci_detach, 611 .read = ines_read, 612 .write = ines_write, 613 .command = ines_command, 614 .take_control = ines_take_control, 615 .go_to_standby = ines_go_to_standby, 616 .request_system_control = ines_request_system_control, 617 .interface_clear = ines_interface_clear, 618 .remote_enable = ines_remote_enable, 619 .enable_eos = ines_enable_eos, 620 .disable_eos = ines_disable_eos, 621 .parallel_poll = ines_parallel_poll, 622 .parallel_poll_configure = ines_parallel_poll_configure, 623 .parallel_poll_response = ines_parallel_poll_response, 624 .local_parallel_poll_mode = NULL, // XXX 625 .line_status = ines72130_line_status, 626 .update_status = ines_update_status, 627 .primary_address = ines_primary_address, 628 .secondary_address = ines_secondary_address, 629 .serial_poll_response = ines_serial_poll_response, 630 .serial_poll_status = ines_serial_poll_status, 631 .t1_delay = ines_t1_delay, 632 .return_to_local = ines_return_to_local, 633 }; 634 635 static struct gpib_interface ines_pci_interface = { 636 .name = "ines_pci", 637 .attach = ines_pci_accel_attach, 638 .detach = ines_pci_detach, 639 .read = ines_accel_read, 640 .write = ines_accel_write, 641 .command = ines_command, 642 .take_control = ines_take_control, 643 .go_to_standby = ines_go_to_standby, 644 .request_system_control = ines_request_system_control, 645 .interface_clear = ines_interface_clear, 646 .remote_enable = ines_remote_enable, 647 .enable_eos = ines_enable_eos, 648 .disable_eos = ines_disable_eos, 649 .parallel_poll = ines_parallel_poll, 650 .parallel_poll_configure = ines_parallel_poll_configure, 651 .parallel_poll_response = ines_parallel_poll_response, 652 .local_parallel_poll_mode = NULL, // XXX 653 .line_status = ines_line_status, 654 .update_status = ines_update_status, 655 .primary_address = ines_primary_address, 656 .secondary_address = ines_secondary_address, 657 .serial_poll_response = ines_serial_poll_response, 658 .serial_poll_status = ines_serial_poll_status, 659 .t1_delay = ines_t1_delay, 660 .return_to_local = ines_return_to_local, 661 }; 662 663 static struct gpib_interface ines_pci_accel_interface = { 664 .name = "ines_pci_accel", 665 .attach = ines_pci_accel_attach, 666 .detach = ines_pci_detach, 667 .read = ines_accel_read, 668 .write = ines_accel_write, 669 .command = ines_command, 670 .take_control = ines_take_control, 671 .go_to_standby = ines_go_to_standby, 672 .request_system_control = ines_request_system_control, 673 .interface_clear = ines_interface_clear, 674 .remote_enable = ines_remote_enable, 675 .enable_eos = ines_enable_eos, 676 .disable_eos = ines_disable_eos, 677 .parallel_poll = ines_parallel_poll, 678 .parallel_poll_configure = ines_parallel_poll_configure, 679 .parallel_poll_response = ines_parallel_poll_response, 680 .local_parallel_poll_mode = NULL, // XXX 681 .line_status = ines_line_status, 682 .update_status = ines_update_status, 683 .primary_address = ines_primary_address, 684 .secondary_address = ines_secondary_address, 685 .serial_poll_response = ines_serial_poll_response, 686 .serial_poll_status = ines_serial_poll_status, 687 .t1_delay = ines_t1_delay, 688 .return_to_local = ines_return_to_local, 689 }; 690 691 static struct gpib_interface ines_isa_interface = { 692 .name = "ines_isa", 693 .attach = ines_isa_attach, 694 .detach = ines_isa_detach, 695 .read = ines_accel_read, 696 .write = ines_accel_write, 697 .command = ines_command, 698 .take_control = ines_take_control, 699 .go_to_standby = ines_go_to_standby, 700 .request_system_control = ines_request_system_control, 701 .interface_clear = ines_interface_clear, 702 .remote_enable = ines_remote_enable, 703 .enable_eos = ines_enable_eos, 704 .disable_eos = ines_disable_eos, 705 .parallel_poll = ines_parallel_poll, 706 .parallel_poll_configure = ines_parallel_poll_configure, 707 .parallel_poll_response = ines_parallel_poll_response, 708 .local_parallel_poll_mode = NULL, // XXX 709 .line_status = ines_line_status, 710 .update_status = ines_update_status, 711 .primary_address = ines_primary_address, 712 .secondary_address = ines_secondary_address, 713 .serial_poll_response = ines_serial_poll_response, 714 .serial_poll_status = ines_serial_poll_status, 715 .t1_delay = ines_t1_delay, 716 .return_to_local = ines_return_to_local, 717 }; 718 719 static int ines_allocate_private(struct gpib_board *board) 720 { 721 struct ines_priv *priv; 722 723 board->private_data = kzalloc_obj(struct ines_priv); 724 if (!board->private_data) 725 return -ENOMEM; 726 priv = board->private_data; 727 init_nec7210_private(&priv->nec7210_priv); 728 return 0; 729 } 730 731 static void ines_free_private(struct gpib_board *board) 732 { 733 kfree(board->private_data); 734 board->private_data = NULL; 735 } 736 737 static int ines_generic_attach(struct gpib_board *board) 738 { 739 struct ines_priv *ines_priv; 740 struct nec7210_priv *nec_priv; 741 int retval; 742 743 board->status = 0; 744 745 retval = ines_allocate_private(board); 746 if (retval) 747 return retval; 748 ines_priv = board->private_data; 749 nec_priv = &ines_priv->nec7210_priv; 750 nec_priv->read_byte = nec7210_ioport_read_byte; 751 nec_priv->write_byte = nec7210_ioport_write_byte; 752 nec_priv->offset = 1; 753 nec_priv->type = IGPIB7210; 754 ines_priv->pci_chip_type = PCI_CHIP_NONE; 755 756 return 0; 757 } 758 759 static void ines_online(struct ines_priv *ines_priv, const struct gpib_board *board, int use_accel) 760 { 761 struct nec7210_priv *nec_priv = &ines_priv->nec7210_priv; 762 763 /* ines doesn't seem to use internal count register */ 764 write_byte(nec_priv, ICR | 0, AUXMR); 765 766 write_byte(nec_priv, INES_AUX_XMODE, AUXMR); 767 write_byte(nec_priv, INES_RFD_HLD_IMMEDIATE, AUXMR); 768 769 set_bit(RFD_HOLDOFF_BN, &nec_priv->state); 770 771 write_byte(nec_priv, INES_AUXD | 0, AUXMR); 772 ines_outb(ines_priv, 0, XDMA_CONTROL); 773 ines_priv->extend_mode_bits = 0; 774 ines_outb(ines_priv, ines_priv->extend_mode_bits, EXTEND_MODE); 775 if (use_accel) { 776 ines_outb(ines_priv, 0x80, OUT_FIFO_WATERMARK); 777 ines_outb(ines_priv, 0x80, IN_FIFO_WATERMARK); 778 ines_outb(ines_priv, IFC_ACTIVE_BIT | ATN_ACTIVE_BIT | 779 FIFO_ERROR_BIT | XFER_COUNT_BIT, IMR3); 780 ines_outb(ines_priv, IN_FIFO_WATERMARK_BIT | IN_FIFO_FULL_BIT | 781 OUT_FIFO_WATERMARK_BIT | OUT_FIFO_EMPTY_BIT, IMR4); 782 } else { 783 nec7210_set_reg_bits(nec_priv, ADMR, IN_FIFO_ENABLE_BIT | OUT_FIFO_ENABLE_BIT, 0); 784 ines_outb(ines_priv, IFC_ACTIVE_BIT | FIFO_ERROR_BIT, IMR3); 785 ines_outb(ines_priv, 0, IMR4); 786 } 787 788 nec7210_board_online(nec_priv, board); 789 if (use_accel) 790 nec7210_set_reg_bits(nec_priv, IMR1, HR_DOIE | HR_DIIE, 0); 791 } 792 793 static int ines_common_pci_attach(struct gpib_board *board, const struct gpib_board_config *config) 794 { 795 struct ines_priv *ines_priv; 796 struct nec7210_priv *nec_priv; 797 int isr_flags = 0; 798 int retval; 799 struct ines_pci_id found_id; 800 unsigned int i; 801 struct pci_dev *pdev; 802 803 memset(&found_id, 0, sizeof(found_id)); 804 805 retval = ines_generic_attach(board); 806 if (retval) 807 return retval; 808 809 ines_priv = board->private_data; 810 nec_priv = &ines_priv->nec7210_priv; 811 812 // find board 813 ines_priv->pci_device = NULL; 814 for (i = 0; i < num_pci_chips && !ines_priv->pci_device; i++) { 815 pdev = NULL; 816 do { 817 if (pci_ids[i].subsystem_vendor_id >= 0 && 818 pci_ids[i].subsystem_device_id >= 0) 819 pdev = pci_get_subsys(pci_ids[i].vendor_id, pci_ids[i].device_id, 820 pci_ids[i].subsystem_vendor_id, 821 pci_ids[i].subsystem_device_id, pdev); 822 else 823 pdev = pci_get_device(pci_ids[i].vendor_id, pci_ids[i].device_id, 824 pdev); 825 if (!pdev) 826 break; 827 if (config->pci_bus >= 0 && config->pci_bus != pdev->bus->number) 828 continue; 829 if (config->pci_slot >= 0 && config->pci_slot != PCI_SLOT(pdev->devfn)) 830 continue; 831 found_id = pci_ids[i]; 832 ines_priv->pci_device = pdev; 833 break; 834 } while (1); 835 } 836 if (!ines_priv->pci_device) { 837 dev_err(board->gpib_dev, "could not find ines PCI board\n"); 838 return -1; 839 } 840 841 if (pci_enable_device(ines_priv->pci_device)) { 842 dev_err(board->gpib_dev, "error enabling pci device\n"); 843 return -1; 844 } 845 846 if (pci_request_regions(ines_priv->pci_device, DRV_NAME)) 847 return -1; 848 nec_priv->iobase = pci_resource_start(ines_priv->pci_device, 849 found_id.gpib_region); 850 851 ines_priv->pci_chip_type = found_id.pci_chip_type; 852 nec_priv->offset = found_id.io_offset; 853 switch (ines_priv->pci_chip_type) { 854 case PCI_CHIP_PLX9050: 855 ines_priv->plx_iobase = pci_resource_start(ines_priv->pci_device, 1); 856 break; 857 case PCI_CHIP_AMCC5920: 858 ines_priv->amcc_iobase = pci_resource_start(ines_priv->pci_device, 0); 859 break; 860 case PCI_CHIP_QUANCOM: 861 break; 862 case PCI_CHIP_QUICKLOGIC5030: 863 break; 864 default: 865 dev_err(board->gpib_dev, "unspecified chip type? (bug)\n"); 866 nec_priv->iobase = 0; 867 pci_release_regions(ines_priv->pci_device); 868 return -1; 869 } 870 871 nec7210_board_reset(nec_priv, board); 872 #ifdef QUANCOM_PCI 873 if (ines_priv->pci_chip_type == PCI_CHIP_QUANCOM) { 874 /* change interrupt polarity */ 875 nec_priv->auxb_bits |= HR_INV; 876 ines_outb(ines_priv, nec_priv->auxb_bits, AUXMR); 877 } 878 #endif 879 isr_flags |= IRQF_SHARED; 880 if (request_irq(ines_priv->pci_device->irq, ines_pci_interrupt, isr_flags, 881 DRV_NAME, board)) { 882 dev_err(board->gpib_dev, "can't request IRQ %d\n", ines_priv->pci_device->irq); 883 return -1; 884 } 885 ines_priv->irq = ines_priv->pci_device->irq; 886 887 // enable interrupts on pci chip 888 switch (ines_priv->pci_chip_type) { 889 case PCI_CHIP_PLX9050: 890 outl(PLX9050_LINTR1_EN_BIT | PLX9050_LINTR1_POLARITY_BIT | PLX9050_PCI_INTR_EN_BIT, 891 ines_priv->plx_iobase + PLX9050_INTCSR_REG); 892 break; 893 case PCI_CHIP_AMCC5920: 894 { 895 static const int region = 1; 896 static const int num_wait_states = 7; 897 u32 bits; 898 899 bits = amcc_prefetch_bits(region, PREFETCH_DISABLED); 900 bits |= amcc_PTADR_mode_bit(region); 901 bits |= amcc_disable_write_fifo_bit(region); 902 bits |= amcc_wait_state_bits(region, num_wait_states); 903 outl(bits, ines_priv->amcc_iobase + AMCC_PASS_THRU_REG); 904 outl(AMCC_ADDON_INTR_ENABLE_BIT, ines_priv->amcc_iobase + AMCC_INTCS_REG); 905 } 906 break; 907 case PCI_CHIP_QUANCOM: 908 outb(QUANCOM_IRQ_ENABLE_BIT, nec_priv->iobase + 909 QUANCOM_IRQ_CONTROL_STATUS_REG); 910 break; 911 case PCI_CHIP_QUICKLOGIC5030: 912 break; 913 default: 914 dev_err(board->gpib_dev, "unspecified chip type? (bug)\n"); 915 return -1; 916 } 917 918 return 0; 919 } 920 921 static int ines_pci_attach(struct gpib_board *board, const struct gpib_board_config *config) 922 { 923 struct ines_priv *ines_priv; 924 int retval; 925 926 retval = ines_common_pci_attach(board, config); 927 if (retval < 0) 928 return retval; 929 930 ines_priv = board->private_data; 931 ines_online(ines_priv, board, 0); 932 933 return 0; 934 } 935 936 static int ines_pci_xl_attach(struct gpib_board *board, const struct gpib_board_config *config) 937 { 938 struct ines_priv *ines_priv; 939 struct nec7210_priv *nec_priv; 940 int retval; 941 942 retval = ines_common_pci_attach(board, config); 943 if (retval < 0) 944 return retval; 945 946 ines_priv = board->private_data; 947 ines_priv->pci_chip_type = PCI_CHIP_INES_72130; 948 nec_priv = &ines_priv->nec7210_priv; 949 nec7210_board_online(nec_priv, board); 950 951 return 0; 952 } 953 954 static int ines_pci_accel_attach(struct gpib_board *board, const struct gpib_board_config *config) 955 { 956 struct ines_priv *ines_priv; 957 int retval; 958 959 retval = ines_common_pci_attach(board, config); 960 if (retval < 0) 961 return retval; 962 963 ines_priv = board->private_data; 964 ines_online(ines_priv, board, 1); 965 966 return 0; 967 } 968 969 static const int ines_isa_iosize = 0x20; 970 971 static int ines_isa_attach(struct gpib_board *board, const struct gpib_board_config *config) 972 { 973 struct ines_priv *ines_priv; 974 struct nec7210_priv *nec_priv; 975 int isr_flags = 0; 976 int retval; 977 978 retval = ines_generic_attach(board); 979 if (retval) 980 return retval; 981 982 ines_priv = board->private_data; 983 nec_priv = &ines_priv->nec7210_priv; 984 985 if (!request_region(config->ibbase, ines_isa_iosize, DRV_NAME)) { 986 dev_err(board->gpib_dev, "ioports at 0x%x already in use\n", 987 config->ibbase); 988 return -EBUSY; 989 } 990 nec_priv->iobase = config->ibbase; 991 nec_priv->offset = 1; 992 nec7210_board_reset(nec_priv, board); 993 if (request_irq(config->ibirq, ines_pci_interrupt, isr_flags, DRV_NAME, board)) { 994 dev_err(board->gpib_dev, "failed to allocate IRQ %d\n", config->ibirq); 995 return -1; 996 } 997 ines_priv->irq = config->ibirq; 998 ines_online(ines_priv, board, 1); 999 return 0; 1000 } 1001 1002 static void ines_pci_detach(struct gpib_board *board) 1003 { 1004 struct ines_priv *ines_priv = board->private_data; 1005 struct nec7210_priv *nec_priv; 1006 1007 if (ines_priv) { 1008 nec_priv = &ines_priv->nec7210_priv; 1009 if (ines_priv->irq) { 1010 // disable interrupts 1011 switch (ines_priv->pci_chip_type) { 1012 case PCI_CHIP_AMCC5920: 1013 if (ines_priv->plx_iobase) 1014 outl(0, ines_priv->plx_iobase + PLX9050_INTCSR_REG); 1015 break; 1016 case PCI_CHIP_QUANCOM: 1017 if (nec_priv->iobase) 1018 outb(0, nec_priv->iobase + 1019 QUANCOM_IRQ_CONTROL_STATUS_REG); 1020 break; 1021 default: 1022 break; 1023 } 1024 free_irq(ines_priv->irq, board); 1025 } 1026 if (nec_priv->iobase) { 1027 nec7210_board_reset(nec_priv, board); 1028 pci_release_regions(ines_priv->pci_device); 1029 } 1030 if (ines_priv->pci_device) 1031 pci_dev_put(ines_priv->pci_device); 1032 } 1033 ines_free_private(board); 1034 } 1035 1036 static void ines_isa_detach(struct gpib_board *board) 1037 { 1038 struct ines_priv *ines_priv = board->private_data; 1039 struct nec7210_priv *nec_priv; 1040 1041 if (ines_priv) { 1042 nec_priv = &ines_priv->nec7210_priv; 1043 if (ines_priv->irq) 1044 free_irq(ines_priv->irq, board); 1045 if (nec_priv->iobase) { 1046 nec7210_board_reset(nec_priv, board); 1047 release_region(nec_priv->iobase, ines_isa_iosize); 1048 } 1049 } 1050 ines_free_private(board); 1051 } 1052 1053 static int ines_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) 1054 { 1055 return 0; 1056 } 1057 1058 static struct pci_driver ines_pci_driver = { 1059 .name = "ines_gpib", 1060 .id_table = ines_pci_table, 1061 .probe = &ines_pci_probe 1062 }; 1063 1064 #ifdef CONFIG_GPIB_PCMCIA 1065 1066 #include <linux/kernel.h> 1067 #include <linux/ptrace.h> 1068 #include <linux/string.h> 1069 #include <linux/timer.h> 1070 1071 #include <pcmcia/cistpl.h> 1072 #include <pcmcia/ds.h> 1073 #include <pcmcia/cisreg.h> 1074 1075 static const int ines_pcmcia_iosize = 0x20; 1076 1077 /* 1078 * The event() function is this driver's Card Services event handler. 1079 * It will be called by Card Services when an appropriate card status 1080 * event is received. The config() and release() entry points are 1081 * used to configure or release a socket, in response to card insertion 1082 * and ejection events. They are invoked from the gpib event 1083 * handler. 1084 */ 1085 1086 static int ines_gpib_config(struct pcmcia_device *link); 1087 static void ines_gpib_release(struct pcmcia_device *link); 1088 static int ines_pcmcia_attach(struct gpib_board *board, const struct gpib_board_config *config); 1089 static int ines_pcmcia_accel_attach(struct gpib_board *board, 1090 const struct gpib_board_config *config); 1091 static void ines_pcmcia_detach(struct gpib_board *board); 1092 static int ines_common_pcmcia_attach(struct gpib_board *board); 1093 /* 1094 * A linked list of "instances" of the gpib device. Each actual 1095 * PCMCIA card corresponds to one device instance, and is described 1096 * by one dev_link_t structure (defined in ds.h). 1097 * 1098 * You may not want to use a linked list for this -- for example, the 1099 * memory card driver uses an array of dev_link_t pointers, where minor 1100 * device numbers are used to derive the corresponding array index. 1101 */ 1102 1103 static struct pcmcia_device *curr_dev; 1104 1105 /* 1106 * A dev_link_t structure has fields for most things that are needed 1107 * to keep track of a socket, but there will usually be some device 1108 * specific information that also needs to be kept track of. The 1109 * 'priv' pointer in a dev_link_t structure can be used to point to 1110 * a device-specific private data structure, like this. 1111 * 1112 * A driver needs to provide a dev_node_t structure for each device 1113 * on a card. In some cases, there is only one device per card (for 1114 * example, ethernet cards, modems). In other cases, there may be 1115 * many actual or logical devices (SCSI adapters, memory cards with 1116 * multiple partitions). The dev_node_t structures need to be kept 1117 * in a linked list starting at the 'dev' field of a dev_link_t 1118 * structure. We allocate them in the card's private data structure, 1119 * because they generally can't be allocated dynamically. 1120 */ 1121 1122 struct local_info { 1123 struct pcmcia_device *p_dev; 1124 struct gpib_board *dev; 1125 u_short manfid; 1126 u_short cardid; 1127 }; 1128 1129 /* 1130 * gpib_attach() creates an "instance" of the driver, allocating 1131 * local data structures for one device. The device is registered 1132 * with Card Services. 1133 * 1134 * The dev_link structure is initialized, but we don't actually 1135 * configure the card at this point -- we wait until we receive a 1136 * card insertion event. 1137 */ 1138 static int ines_gpib_probe(struct pcmcia_device *link) 1139 { 1140 struct local_info *info; 1141 1142 // int ret, i; 1143 1144 /* Allocate space for private device-specific data */ 1145 info = kzalloc_obj(*info); 1146 if (!info) 1147 return -ENOMEM; 1148 1149 info->p_dev = link; 1150 link->priv = info; 1151 1152 /* The io structure describes IO port mapping */ 1153 link->resource[0]->end = 32; 1154 link->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; 1155 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; 1156 link->io_lines = 5; 1157 1158 /* General socket configuration */ 1159 link->config_flags = CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; 1160 1161 /* Register with Card Services */ 1162 curr_dev = link; 1163 return ines_gpib_config(link); 1164 } 1165 1166 /* 1167 * This deletes a driver "instance". The device is de-registered 1168 * with Card Services. If it has been released, all local data 1169 * structures are freed. Otherwise, the structures will be freed 1170 * when the device is released. 1171 */ 1172 static void ines_gpib_remove(struct pcmcia_device *link) 1173 { 1174 struct local_info *info = link->priv; 1175 //struct struct gpib_board *dev = info->dev; 1176 1177 if (info->dev) 1178 ines_pcmcia_detach(info->dev); 1179 ines_gpib_release(link); 1180 1181 //free_netdev(dev); 1182 kfree(info); 1183 } 1184 1185 static int ines_gpib_config_iteration(struct pcmcia_device *link, void *priv_data) 1186 { 1187 return pcmcia_request_io(link); 1188 } 1189 1190 /* 1191 * gpib_config() is scheduled to run after a CARD_INSERTION event 1192 * is received, to configure the PCMCIA socket, and to make the 1193 * device available to the system. 1194 */ 1195 static int ines_gpib_config(struct pcmcia_device *link) 1196 { 1197 int retval; 1198 void __iomem *virt; 1199 1200 retval = pcmcia_loop_config(link, &ines_gpib_config_iteration, NULL); 1201 if (retval) { 1202 dev_warn(&link->dev, "no configuration found\n"); 1203 ines_gpib_release(link); 1204 return -ENODEV; 1205 } 1206 1207 dev_dbg(&link->dev, "ines_cs: manufacturer: 0x%x card: 0x%x\n", 1208 link->manf_id, link->card_id); 1209 1210 /* 1211 * for the ines card we have to setup the configuration registers in 1212 * attribute memory here 1213 */ 1214 link->resource[2]->flags |= WIN_MEMORY_TYPE_AM | WIN_DATA_WIDTH_8 | WIN_ENABLE; 1215 link->resource[2]->end = 0x1000; 1216 retval = pcmcia_request_window(link, link->resource[2], 250); 1217 if (retval) { 1218 dev_warn(&link->dev, "pcmcia_request_window failed\n"); 1219 ines_gpib_release(link); 1220 return -ENODEV; 1221 } 1222 retval = pcmcia_map_mem_page(link, link->resource[2], 0); 1223 if (retval) { 1224 dev_warn(&link->dev, "pcmcia_map_mem_page failed\n"); 1225 ines_gpib_release(link); 1226 return -ENODEV; 1227 } 1228 virt = ioremap(link->resource[2]->start, resource_size(link->resource[2])); 1229 writeb((link->resource[2]->start >> 2) & 0xff, virt + 0xf0); // IOWindow base 1230 iounmap(virt); 1231 1232 /* 1233 * This actually configures the PCMCIA socket -- setting up 1234 * the I/O windows and the interrupt mapping. 1235 */ 1236 retval = pcmcia_enable_device(link); 1237 if (retval) { 1238 ines_gpib_release(link); 1239 return -ENODEV; 1240 } 1241 return 0; 1242 } /* gpib_config */ 1243 1244 /* 1245 * After a card is removed, gpib_release() will unregister the net 1246 * device, and release the PCMCIA configuration. If the device is 1247 * still open, this will be postponed until it is closed. 1248 */ 1249 1250 static void ines_gpib_release(struct pcmcia_device *link) 1251 { 1252 pcmcia_disable_device(link); 1253 } /* gpib_release */ 1254 1255 static int ines_gpib_suspend(struct pcmcia_device *link) 1256 { 1257 //struct local_info *info = link->priv; 1258 //struct struct gpib_board *dev = info->dev; 1259 1260 if (link->open) 1261 dev_err(&link->dev, "Device still open\n"); 1262 //netif_device_detach(dev); 1263 1264 return 0; 1265 } 1266 1267 static int ines_gpib_resume(struct pcmcia_device *link) 1268 { 1269 //struct local_info_t *info = link->priv; 1270 //struct struct gpib_board *dev = info->dev; 1271 1272 /*if (link->open) { 1273 * ni_gpib_probe(dev); / really? 1274 * //netif_device_attach(dev); 1275 *} 1276 */ 1277 return ines_gpib_config(link); 1278 } 1279 1280 static struct pcmcia_device_id ines_pcmcia_ids[] = { 1281 PCMCIA_DEVICE_MANF_CARD(0x01b4, 0x4730), 1282 PCMCIA_DEVICE_NULL 1283 }; 1284 MODULE_DEVICE_TABLE(pcmcia, ines_pcmcia_ids); 1285 1286 static struct pcmcia_driver ines_gpib_cs_driver = { 1287 .owner = THIS_MODULE, 1288 .name = "ines_gpib_cs", 1289 .id_table = ines_pcmcia_ids, 1290 .probe = ines_gpib_probe, 1291 .remove = ines_gpib_remove, 1292 .suspend = ines_gpib_suspend, 1293 .resume = ines_gpib_resume, 1294 }; 1295 1296 static void ines_pcmcia_cleanup_module(void) 1297 { 1298 pcmcia_unregister_driver(&ines_gpib_cs_driver); 1299 } 1300 1301 static struct gpib_interface ines_pcmcia_unaccel_interface = { 1302 .name = "ines_pcmcia_unaccel", 1303 .attach = ines_pcmcia_attach, 1304 .detach = ines_pcmcia_detach, 1305 .read = ines_read, 1306 .write = ines_write, 1307 .command = ines_command, 1308 .take_control = ines_take_control, 1309 .go_to_standby = ines_go_to_standby, 1310 .request_system_control = ines_request_system_control, 1311 .interface_clear = ines_interface_clear, 1312 .remote_enable = ines_remote_enable, 1313 .enable_eos = ines_enable_eos, 1314 .disable_eos = ines_disable_eos, 1315 .parallel_poll = ines_parallel_poll, 1316 .parallel_poll_configure = ines_parallel_poll_configure, 1317 .parallel_poll_response = ines_parallel_poll_response, 1318 .local_parallel_poll_mode = NULL, // XXX 1319 .line_status = ines_line_status, 1320 .update_status = ines_update_status, 1321 .primary_address = ines_primary_address, 1322 .secondary_address = ines_secondary_address, 1323 .serial_poll_response = ines_serial_poll_response, 1324 .serial_poll_status = ines_serial_poll_status, 1325 .t1_delay = ines_t1_delay, 1326 .return_to_local = ines_return_to_local, 1327 }; 1328 1329 static struct gpib_interface ines_pcmcia_accel_interface = { 1330 .name = "ines_pcmcia_accel", 1331 .attach = ines_pcmcia_accel_attach, 1332 .detach = ines_pcmcia_detach, 1333 .read = ines_accel_read, 1334 .write = ines_accel_write, 1335 .command = ines_command, 1336 .take_control = ines_take_control, 1337 .go_to_standby = ines_go_to_standby, 1338 .request_system_control = ines_request_system_control, 1339 .interface_clear = ines_interface_clear, 1340 .remote_enable = ines_remote_enable, 1341 .enable_eos = ines_enable_eos, 1342 .disable_eos = ines_disable_eos, 1343 .parallel_poll = ines_parallel_poll, 1344 .parallel_poll_configure = ines_parallel_poll_configure, 1345 .parallel_poll_response = ines_parallel_poll_response, 1346 .local_parallel_poll_mode = NULL, // XXX 1347 .line_status = ines_line_status, 1348 .update_status = ines_update_status, 1349 .primary_address = ines_primary_address, 1350 .secondary_address = ines_secondary_address, 1351 .serial_poll_response = ines_serial_poll_response, 1352 .serial_poll_status = ines_serial_poll_status, 1353 .t1_delay = ines_t1_delay, 1354 .return_to_local = ines_return_to_local, 1355 }; 1356 1357 static struct gpib_interface ines_pcmcia_interface = { 1358 .name = "ines_pcmcia", 1359 .attach = ines_pcmcia_accel_attach, 1360 .detach = ines_pcmcia_detach, 1361 .read = ines_accel_read, 1362 .write = ines_accel_write, 1363 .command = ines_command, 1364 .take_control = ines_take_control, 1365 .go_to_standby = ines_go_to_standby, 1366 .request_system_control = ines_request_system_control, 1367 .interface_clear = ines_interface_clear, 1368 .remote_enable = ines_remote_enable, 1369 .enable_eos = ines_enable_eos, 1370 .disable_eos = ines_disable_eos, 1371 .parallel_poll = ines_parallel_poll, 1372 .parallel_poll_configure = ines_parallel_poll_configure, 1373 .parallel_poll_response = ines_parallel_poll_response, 1374 .local_parallel_poll_mode = NULL, // XXX 1375 .line_status = ines_line_status, 1376 .update_status = ines_update_status, 1377 .primary_address = ines_primary_address, 1378 .secondary_address = ines_secondary_address, 1379 .serial_poll_response = ines_serial_poll_response, 1380 .serial_poll_status = ines_serial_poll_status, 1381 .t1_delay = ines_t1_delay, 1382 .return_to_local = ines_return_to_local, 1383 }; 1384 1385 static irqreturn_t ines_pcmcia_interrupt(int irq, void *arg) 1386 { 1387 struct gpib_board *board = arg; 1388 1389 return ines_interrupt(board); 1390 } 1391 1392 static int ines_common_pcmcia_attach(struct gpib_board *board) 1393 { 1394 struct ines_priv *ines_priv; 1395 struct nec7210_priv *nec_priv; 1396 int retval; 1397 1398 if (!curr_dev) { 1399 dev_err(board->gpib_dev, "no ines pcmcia cards found\n"); 1400 return -1; 1401 } 1402 1403 retval = ines_generic_attach(board); 1404 if (retval) 1405 return retval; 1406 1407 ines_priv = board->private_data; 1408 nec_priv = &ines_priv->nec7210_priv; 1409 1410 if (!request_region(curr_dev->resource[0]->start, 1411 resource_size(curr_dev->resource[0]), DRV_NAME)) { 1412 dev_err(board->gpib_dev, "ioports at 0x%lx already in use\n", 1413 (unsigned long)(curr_dev->resource[0]->start)); 1414 return -1; 1415 } 1416 1417 nec_priv->iobase = curr_dev->resource[0]->start; 1418 1419 nec7210_board_reset(nec_priv, board); 1420 1421 if (request_irq(curr_dev->irq, ines_pcmcia_interrupt, IRQF_SHARED, 1422 "pcmcia-gpib", board)) { 1423 dev_err(board->gpib_dev, "can't request IRQ %d\n", curr_dev->irq); 1424 return -1; 1425 } 1426 ines_priv->irq = curr_dev->irq; 1427 1428 return 0; 1429 } 1430 1431 static int ines_pcmcia_attach(struct gpib_board *board, const struct gpib_board_config *config) 1432 { 1433 struct ines_priv *ines_priv; 1434 int retval; 1435 1436 retval = ines_common_pcmcia_attach(board); 1437 if (retval < 0) 1438 return retval; 1439 1440 ines_priv = board->private_data; 1441 ines_online(ines_priv, board, 0); 1442 1443 return 0; 1444 } 1445 1446 static int ines_pcmcia_accel_attach(struct gpib_board *board, 1447 const struct gpib_board_config *config) 1448 { 1449 struct ines_priv *ines_priv; 1450 int retval; 1451 1452 retval = ines_common_pcmcia_attach(board); 1453 if (retval < 0) 1454 return retval; 1455 1456 ines_priv = board->private_data; 1457 ines_online(ines_priv, board, 1); 1458 1459 return 0; 1460 } 1461 1462 static void ines_pcmcia_detach(struct gpib_board *board) 1463 { 1464 struct ines_priv *ines_priv = board->private_data; 1465 struct nec7210_priv *nec_priv; 1466 1467 if (ines_priv) { 1468 nec_priv = &ines_priv->nec7210_priv; 1469 if (ines_priv->irq) 1470 free_irq(ines_priv->irq, board); 1471 if (nec_priv->iobase) { 1472 nec7210_board_reset(nec_priv, board); 1473 release_region(nec_priv->iobase, ines_pcmcia_iosize); 1474 } 1475 } 1476 ines_free_private(board); 1477 } 1478 1479 #endif /* CONFIG_GPIB_PCMCIA */ 1480 1481 static int __init ines_init_module(void) 1482 { 1483 int ret; 1484 1485 ret = pci_register_driver(&ines_pci_driver); 1486 if (ret) { 1487 pr_err("pci_register_driver failed: error = %d\n", ret); 1488 return ret; 1489 } 1490 1491 ret = gpib_register_driver(&ines_pci_interface, THIS_MODULE); 1492 if (ret) { 1493 pr_err("gpib_register_driver failed: error = %d\n", ret); 1494 goto err_pci; 1495 } 1496 1497 ret = gpib_register_driver(&ines_pci_unaccel_interface, THIS_MODULE); 1498 if (ret) { 1499 pr_err("gpib_register_driver failed: error = %d\n", ret); 1500 goto err_pci_unaccel; 1501 } 1502 1503 ret = gpib_register_driver(&ines_pci_xl_interface, THIS_MODULE); 1504 if (ret) { 1505 pr_err("gpib_register_driver failed: error = %d\n", ret); 1506 goto err_pci_xl; 1507 } 1508 1509 ret = gpib_register_driver(&ines_pci_accel_interface, THIS_MODULE); 1510 if (ret) { 1511 pr_err("gpib_register_driver failed: error = %d\n", ret); 1512 goto err_pci_accel; 1513 } 1514 1515 ret = gpib_register_driver(&ines_isa_interface, THIS_MODULE); 1516 if (ret) { 1517 pr_err("gpib_register_driver failed: error = %d\n", ret); 1518 goto err_isa; 1519 } 1520 1521 #ifdef CONFIG_GPIB_PCMCIA 1522 ret = gpib_register_driver(&ines_pcmcia_interface, THIS_MODULE); 1523 if (ret) { 1524 pr_err("gpib_register_driver failed: error = %d\n", ret); 1525 goto err_pcmcia; 1526 } 1527 1528 ret = gpib_register_driver(&ines_pcmcia_unaccel_interface, THIS_MODULE); 1529 if (ret) { 1530 pr_err("gpib_register_driver failed: error = %d\n", ret); 1531 goto err_pcmcia_unaccel; 1532 } 1533 1534 ret = gpib_register_driver(&ines_pcmcia_accel_interface, THIS_MODULE); 1535 if (ret) { 1536 pr_err("gpib_register_driver failed: error = %d\n", ret); 1537 goto err_pcmcia_accel; 1538 } 1539 1540 ret = pcmcia_register_driver(&ines_gpib_cs_driver); 1541 if (ret) { 1542 pr_err("pcmcia_register_driver failed: error = %d\n", ret); 1543 goto err_pcmcia_driver; 1544 } 1545 #endif 1546 1547 return 0; 1548 1549 #ifdef CONFIG_GPIB_PCMCIA 1550 err_pcmcia_driver: 1551 gpib_unregister_driver(&ines_pcmcia_accel_interface); 1552 err_pcmcia_accel: 1553 gpib_unregister_driver(&ines_pcmcia_unaccel_interface); 1554 err_pcmcia_unaccel: 1555 gpib_unregister_driver(&ines_pcmcia_interface); 1556 err_pcmcia: 1557 #endif 1558 gpib_unregister_driver(&ines_isa_interface); 1559 err_isa: 1560 gpib_unregister_driver(&ines_pci_accel_interface); 1561 err_pci_accel: 1562 gpib_unregister_driver(&ines_pci_unaccel_interface); 1563 err_pci_xl: 1564 gpib_unregister_driver(&ines_pci_xl_interface); 1565 err_pci_unaccel: 1566 gpib_unregister_driver(&ines_pci_interface); 1567 err_pci: 1568 pci_unregister_driver(&ines_pci_driver); 1569 1570 return ret; 1571 } 1572 1573 static void __exit ines_exit_module(void) 1574 { 1575 gpib_unregister_driver(&ines_pci_interface); 1576 gpib_unregister_driver(&ines_pci_unaccel_interface); 1577 gpib_unregister_driver(&ines_pci_xl_interface); 1578 gpib_unregister_driver(&ines_pci_accel_interface); 1579 gpib_unregister_driver(&ines_isa_interface); 1580 #ifdef CONFIG_GPIB_PCMCIA 1581 gpib_unregister_driver(&ines_pcmcia_interface); 1582 gpib_unregister_driver(&ines_pcmcia_unaccel_interface); 1583 gpib_unregister_driver(&ines_pcmcia_accel_interface); 1584 ines_pcmcia_cleanup_module(); 1585 #endif 1586 1587 pci_unregister_driver(&ines_pci_driver); 1588 } 1589 1590 module_init(ines_init_module); 1591 module_exit(ines_exit_module); 1592