1 // SPDX-License-Identifier: GPL-2.0
2
3 /***************************************************************************
4 * National Instruments boards using tnt4882 or compatible chips (at-gpib, etc).
5 * copyright : (C) 2001, 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 <linux/ioport.h>
13 #include <linux/sched.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/pci.h>
17 #include <linux/pci_ids.h>
18 #include <linux/string.h>
19 #include <linux/init.h>
20 #include <linux/delay.h>
21 #include <linux/isapnp.h>
22
23 #include "nec7210.h"
24 #include "gpibP.h"
25 #include "mite.h"
26 #include "tnt4882_registers.h"
27
28 static const int ISAPNP_VENDOR_ID_NI = ISAPNP_VENDOR('N', 'I', 'C');
29 static const int ISAPNP_ID_NI_ATGPIB_TNT = 0xc601;
30 enum {
31 PCI_DEVICE_ID_NI_GPIB = 0xc801,
32 PCI_DEVICE_ID_NI_GPIB_PLUS = 0xc811,
33 PCI_DEVICE_ID_NI_GPIB_PLUS2 = 0x71ad,
34 PCI_DEVICE_ID_NI_PXIGPIB = 0xc821,
35 PCI_DEVICE_ID_NI_PMCGPIB = 0xc831,
36 PCI_DEVICE_ID_NI_PCIEGPIB = 0x70cf,
37 PCI_DEVICE_ID_NI_PCIE2GPIB = 0x710e,
38 // Measurement Computing PCI-488 same design as PCI-GPIB with TNT5004
39 PCI_DEVICE_ID_MC_PCI488 = 0x7259,
40 PCI_DEVICE_ID_CEC_NI_GPIB = 0x7258
41 };
42
43 // struct which defines private_data for tnt4882 devices
44 struct tnt4882_priv {
45 struct nec7210_priv nec7210_priv;
46 struct mite_struct *mite;
47 struct pnp_dev *pnp_dev;
48 unsigned int irq;
49 unsigned short imr0_bits;
50 unsigned short imr3_bits;
51 unsigned short auxg_bits; // bits written to auxiliary register G
52 };
53
54 static irqreturn_t tnt4882_internal_interrupt(struct gpib_board *board);
55
56 // register offset for nec7210 compatible registers
57 static const int atgpib_reg_offset = 2;
58
59 // number of ioports used
60 static const int atgpib_iosize = 32;
61
62 /* paged io */
tnt_paged_readb(struct tnt4882_priv * priv,unsigned long offset)63 static inline unsigned int tnt_paged_readb(struct tnt4882_priv *priv, unsigned long offset)
64 {
65 iowrite8(AUX_PAGEIN, priv->nec7210_priv.mmiobase + AUXMR * priv->nec7210_priv.offset);
66 udelay(1);
67 return ioread8(priv->nec7210_priv.mmiobase + offset);
68 }
69
tnt_paged_writeb(struct tnt4882_priv * priv,unsigned int value,unsigned long offset)70 static inline void tnt_paged_writeb(struct tnt4882_priv *priv, unsigned int value,
71 unsigned long offset)
72 {
73 iowrite8(AUX_PAGEIN, priv->nec7210_priv.mmiobase + AUXMR * priv->nec7210_priv.offset);
74 udelay(1);
75 iowrite8(value, priv->nec7210_priv.mmiobase + offset);
76 }
77
78 /* readb/writeb wrappers */
tnt_readb(struct tnt4882_priv * priv,unsigned long offset)79 static inline unsigned short tnt_readb(struct tnt4882_priv *priv, unsigned long offset)
80 {
81 void __iomem *address = priv->nec7210_priv.mmiobase + offset;
82 unsigned long flags;
83 unsigned short retval;
84 spinlock_t *register_lock = &priv->nec7210_priv.register_page_lock;
85
86 spin_lock_irqsave(register_lock, flags);
87 switch (offset) {
88 case CSR:
89 case SASR:
90 case ISR0:
91 case BSR:
92 switch (priv->nec7210_priv.type) {
93 case TNT4882:
94 case TNT5004:
95 retval = ioread8(address);
96 break;
97 case NAT4882:
98 retval = tnt_paged_readb(priv, offset - tnt_pagein_offset);
99 break;
100 case NEC7210:
101 retval = 0;
102 break;
103 default:
104 retval = 0;
105 break;
106 }
107 break;
108 default:
109 retval = ioread8(address);
110 break;
111 }
112 spin_unlock_irqrestore(register_lock, flags);
113 return retval;
114 }
115
tnt_writeb(struct tnt4882_priv * priv,unsigned short value,unsigned long offset)116 static inline void tnt_writeb(struct tnt4882_priv *priv, unsigned short value, unsigned long offset)
117 {
118 void __iomem *address = priv->nec7210_priv.mmiobase + offset;
119 unsigned long flags;
120 spinlock_t *register_lock = &priv->nec7210_priv.register_page_lock;
121
122 spin_lock_irqsave(register_lock, flags);
123 switch (offset) {
124 case KEYREG:
125 case IMR0:
126 case BCR:
127 switch (priv->nec7210_priv.type) {
128 case TNT4882:
129 case TNT5004:
130 iowrite8(value, address);
131 break;
132 case NAT4882:
133 tnt_paged_writeb(priv, value, offset - tnt_pagein_offset);
134 break;
135 case NEC7210:
136 break;
137 default:
138 break;
139 }
140 break;
141 default:
142 iowrite8(value, address);
143 break;
144 }
145 spin_unlock_irqrestore(register_lock, flags);
146 }
147
148 MODULE_LICENSE("GPL");
149 MODULE_DESCRIPTION("GPIB driver for National Instruments boards using tnt4882 or compatible chips");
150
tnt4882_line_status(const struct gpib_board * board)151 static int tnt4882_line_status(const struct gpib_board *board)
152 {
153 int status = VALID_ALL;
154 int bcsr_bits;
155 struct tnt4882_priv *tnt_priv;
156
157 tnt_priv = board->private_data;
158
159 bcsr_bits = tnt_readb(tnt_priv, BSR);
160
161 if (bcsr_bits & BCSR_REN_BIT)
162 status |= BUS_REN;
163 if (bcsr_bits & BCSR_IFC_BIT)
164 status |= BUS_IFC;
165 if (bcsr_bits & BCSR_SRQ_BIT)
166 status |= BUS_SRQ;
167 if (bcsr_bits & BCSR_EOI_BIT)
168 status |= BUS_EOI;
169 if (bcsr_bits & BCSR_NRFD_BIT)
170 status |= BUS_NRFD;
171 if (bcsr_bits & BCSR_NDAC_BIT)
172 status |= BUS_NDAC;
173 if (bcsr_bits & BCSR_DAV_BIT)
174 status |= BUS_DAV;
175 if (bcsr_bits & BCSR_ATN_BIT)
176 status |= BUS_ATN;
177
178 return status;
179 }
180
tnt4882_t1_delay(struct gpib_board * board,unsigned int nano_sec)181 static int tnt4882_t1_delay(struct gpib_board *board, unsigned int nano_sec)
182 {
183 struct tnt4882_priv *tnt_priv = board->private_data;
184 struct nec7210_priv *nec_priv = &tnt_priv->nec7210_priv;
185 unsigned int retval;
186
187 retval = nec7210_t1_delay(board, nec_priv, nano_sec);
188 if (nec_priv->type == NEC7210)
189 return retval;
190
191 if (nano_sec <= 350) {
192 tnt_writeb(tnt_priv, MSTD, KEYREG);
193 retval = 350;
194 } else {
195 tnt_writeb(tnt_priv, 0, KEYREG);
196 }
197 if (nano_sec > 500 && nano_sec <= 1100) {
198 write_byte(nec_priv, AUXRI | USTD, AUXMR);
199 retval = 1100;
200 } else {
201 write_byte(nec_priv, AUXRI, AUXMR);
202 }
203 return retval;
204 }
205
fifo_word_available(struct tnt4882_priv * tnt_priv)206 static int fifo_word_available(struct tnt4882_priv *tnt_priv)
207 {
208 int status2;
209 int retval;
210
211 status2 = tnt_readb(tnt_priv, STS2);
212 retval = (status2 & AEFN) && (status2 & BEFN);
213
214 return retval;
215 }
216
fifo_byte_available(struct tnt4882_priv * tnt_priv)217 static int fifo_byte_available(struct tnt4882_priv *tnt_priv)
218 {
219 int status2;
220 int retval;
221
222 status2 = tnt_readb(tnt_priv, STS2);
223 retval = (status2 & AEFN) || (status2 & BEFN);
224
225 return retval;
226 }
227
fifo_xfer_done(struct tnt4882_priv * tnt_priv)228 static int fifo_xfer_done(struct tnt4882_priv *tnt_priv)
229 {
230 int status1;
231 int retval;
232
233 status1 = tnt_readb(tnt_priv, STS1);
234 retval = status1 & (S_DONE | S_HALT);
235
236 return retval;
237 }
238
drain_fifo_words(struct tnt4882_priv * tnt_priv,u8 * buffer,int num_bytes)239 static int drain_fifo_words(struct tnt4882_priv *tnt_priv, u8 *buffer, int num_bytes)
240 {
241 int count = 0;
242 struct nec7210_priv *nec_priv = &tnt_priv->nec7210_priv;
243
244 while (fifo_word_available(tnt_priv) && count + 2 <= num_bytes) {
245 short word;
246
247 word = ioread16(nec_priv->mmiobase + FIFOB);
248 buffer[count++] = word & 0xff;
249 buffer[count++] = (word >> 8) & 0xff;
250 }
251 return count;
252 }
253
tnt4882_release_holdoff(struct gpib_board * board,struct tnt4882_priv * tnt_priv)254 static void tnt4882_release_holdoff(struct gpib_board *board, struct tnt4882_priv *tnt_priv)
255 {
256 struct nec7210_priv *nec_priv = &tnt_priv->nec7210_priv;
257 unsigned short sasr_bits;
258
259 sasr_bits = tnt_readb(tnt_priv, SASR);
260
261 /*
262 * tnt4882 not in one-chip mode won't always release holdoff unless we
263 * are in the right mode when release handshake command is given
264 */
265 if (sasr_bits & AEHS_BIT) /* holding off due to holdoff on end mode*/ {
266 nec7210_set_handshake_mode(board, nec_priv, HR_HLDE);
267 write_byte(nec_priv, AUX_FH, AUXMR);
268 } else if (sasr_bits & ANHS1_BIT) { /* held off due to holdoff on all data mode*/
269 nec7210_set_handshake_mode(board, nec_priv, HR_HLDA);
270 write_byte(nec_priv, AUX_FH, AUXMR);
271 nec7210_set_handshake_mode(board, nec_priv, HR_HLDE);
272 } else { /* held off due to holdoff immediately command */
273 nec7210_set_handshake_mode(board, nec_priv, HR_HLDE);
274 write_byte(nec_priv, AUX_FH, AUXMR);
275 }
276 }
277
tnt4882_accel_read(struct gpib_board * board,u8 * buffer,size_t length,int * end,size_t * bytes_read)278 static int tnt4882_accel_read(struct gpib_board *board, u8 *buffer, size_t length, int *end,
279 size_t *bytes_read)
280 {
281 size_t count = 0;
282 ssize_t retval = 0;
283 struct tnt4882_priv *tnt_priv = board->private_data;
284 struct nec7210_priv *nec_priv = &tnt_priv->nec7210_priv;
285 unsigned int bits;
286 s32 hw_count;
287 unsigned long flags;
288
289 *bytes_read = 0;
290 // FIXME: really, DEV_CLEAR_BN should happen elsewhere to prevent race
291 clear_bit(DEV_CLEAR_BN, &nec_priv->state);
292 clear_bit(ADR_CHANGE_BN, &nec_priv->state);
293
294 nec7210_set_reg_bits(nec_priv, IMR1, HR_ENDIE, HR_ENDIE);
295 if (nec_priv->type != TNT4882 && nec_priv->type != TNT5004)
296 nec7210_set_reg_bits(nec_priv, IMR2, HR_DMAI, HR_DMAI);
297 else
298 nec7210_set_reg_bits(nec_priv, IMR2, HR_DMAI, 0);
299 tnt_writeb(tnt_priv, nec_priv->auxa_bits | HR_HLDA, CCR);
300 bits = TNT_B_16BIT | TNT_IN | TNT_CCEN;
301 tnt_writeb(tnt_priv, bits, CFG);
302 tnt_writeb(tnt_priv, RESET_FIFO, CMDR);
303 udelay(1);
304 // load 2's complement of count into hardware counters
305 hw_count = -length;
306 tnt_writeb(tnt_priv, hw_count & 0xff, CNT0);
307 tnt_writeb(tnt_priv, (hw_count >> 8) & 0xff, CNT1);
308 tnt_writeb(tnt_priv, (hw_count >> 16) & 0xff, CNT2);
309 tnt_writeb(tnt_priv, (hw_count >> 24) & 0xff, CNT3);
310
311 tnt4882_release_holdoff(board, tnt_priv);
312
313 tnt_writeb(tnt_priv, GO, CMDR);
314 udelay(1);
315
316 spin_lock_irqsave(&board->spinlock, flags);
317 tnt_priv->imr3_bits |= HR_DONE | HR_NEF;
318 tnt_writeb(tnt_priv, tnt_priv->imr3_bits, IMR3);
319 spin_unlock_irqrestore(&board->spinlock, flags);
320
321 while (count + 2 <= length &&
322 test_bit(RECEIVED_END_BN, &nec_priv->state) == 0 &&
323 fifo_xfer_done(tnt_priv) == 0) {
324 // wait until a word is ready
325 if (wait_event_interruptible(board->wait,
326 fifo_word_available(tnt_priv) ||
327 fifo_xfer_done(tnt_priv) ||
328 test_bit(RECEIVED_END_BN, &nec_priv->state) ||
329 test_bit(DEV_CLEAR_BN, &nec_priv->state) ||
330 test_bit(ADR_CHANGE_BN, &nec_priv->state) ||
331 test_bit(TIMO_NUM, &board->status))) {
332 retval = -ERESTARTSYS;
333 break;
334 }
335 if (test_bit(TIMO_NUM, &board->status)) {
336 retval = -ETIMEDOUT;
337 break;
338 }
339 if (test_bit(DEV_CLEAR_BN, &nec_priv->state)) {
340 retval = -EINTR;
341 break;
342 }
343 if (test_bit(ADR_CHANGE_BN, &nec_priv->state)) {
344 retval = -EINTR;
345 break;
346 }
347
348 spin_lock_irqsave(&board->spinlock, flags);
349 count += drain_fifo_words(tnt_priv, &buffer[count], length - count);
350 tnt_priv->imr3_bits |= HR_NEF;
351 tnt_writeb(tnt_priv, tnt_priv->imr3_bits, IMR3);
352 spin_unlock_irqrestore(&board->spinlock, flags);
353
354 if (need_resched())
355 schedule();
356 }
357 // wait for last byte
358 if (count < length) {
359 spin_lock_irqsave(&board->spinlock, flags);
360 tnt_priv->imr3_bits |= HR_DONE | HR_NEF;
361 tnt_writeb(tnt_priv, tnt_priv->imr3_bits, IMR3);
362 spin_unlock_irqrestore(&board->spinlock, flags);
363
364 if (wait_event_interruptible(board->wait,
365 fifo_xfer_done(tnt_priv) ||
366 test_bit(RECEIVED_END_BN, &nec_priv->state) ||
367 test_bit(DEV_CLEAR_BN, &nec_priv->state) ||
368 test_bit(ADR_CHANGE_BN, &nec_priv->state) ||
369 test_bit(TIMO_NUM, &board->status))) {
370 retval = -ERESTARTSYS;
371 }
372 if (test_bit(TIMO_NUM, &board->status))
373 retval = -ETIMEDOUT;
374 if (test_bit(DEV_CLEAR_BN, &nec_priv->state))
375 retval = -EINTR;
376 if (test_bit(ADR_CHANGE_BN, &nec_priv->state))
377 retval = -EINTR;
378 count += drain_fifo_words(tnt_priv, &buffer[count], length - count);
379 if (fifo_byte_available(tnt_priv) && count < length)
380 buffer[count++] = tnt_readb(tnt_priv, FIFOB);
381 }
382 if (count < length)
383 tnt_writeb(tnt_priv, STOP, CMDR);
384 udelay(1);
385
386 nec7210_set_reg_bits(nec_priv, IMR1, HR_ENDIE, 0);
387 nec7210_set_reg_bits(nec_priv, IMR2, HR_DMAI, 0);
388 /*
389 * force handling of any pending interrupts (seems to be needed
390 * to keep interrupts from getting hosed, plus for syncing
391 * with RECEIVED_END below)
392 */
393 tnt4882_internal_interrupt(board);
394 /* RECEIVED_END should be in sync now */
395 if (test_and_clear_bit(RECEIVED_END_BN, &nec_priv->state))
396 *end = 1;
397 if (retval < 0) {
398 // force immediate holdoff
399 write_byte(nec_priv, AUX_HLDI, AUXMR);
400
401 set_bit(RFD_HOLDOFF_BN, &nec_priv->state);
402 }
403 *bytes_read = count;
404
405 return retval;
406 }
407
fifo_space_available(struct tnt4882_priv * tnt_priv)408 static int fifo_space_available(struct tnt4882_priv *tnt_priv)
409 {
410 int status2;
411 int retval;
412
413 status2 = tnt_readb(tnt_priv, STS2);
414 retval = (status2 & AFFN) && (status2 & BFFN);
415
416 return retval;
417 }
418
tnt_transfer_count(struct tnt4882_priv * tnt_priv)419 static unsigned int tnt_transfer_count(struct tnt4882_priv *tnt_priv)
420 {
421 unsigned int count = 0;
422
423 count |= tnt_readb(tnt_priv, CNT0) & 0xff;
424 count |= (tnt_readb(tnt_priv, CNT1) << 8) & 0xff00;
425 count |= (tnt_readb(tnt_priv, CNT2) << 16) & 0xff0000;
426 count |= (tnt_readb(tnt_priv, CNT3) << 24) & 0xff000000;
427 // return two's complement
428 return -count;
429 };
430
write_wait(struct gpib_board * board,struct tnt4882_priv * tnt_priv,int wait_for_done,int send_commands)431 static int write_wait(struct gpib_board *board, struct tnt4882_priv *tnt_priv,
432 int wait_for_done, int send_commands)
433 {
434 struct nec7210_priv *nec_priv = &tnt_priv->nec7210_priv;
435
436 if (wait_event_interruptible(board->wait,
437 (!wait_for_done && fifo_space_available(tnt_priv)) ||
438 fifo_xfer_done(tnt_priv) ||
439 test_bit(BUS_ERROR_BN, &nec_priv->state) ||
440 test_bit(DEV_CLEAR_BN, &nec_priv->state) ||
441 test_bit(TIMO_NUM, &board->status)))
442 return -ERESTARTSYS;
443
444 if (test_bit(TIMO_NUM, &board->status))
445 return -ETIMEDOUT;
446 if (test_and_clear_bit(BUS_ERROR_BN, &nec_priv->state))
447 return (send_commands) ? -ENOTCONN : -ECOMM;
448 if (test_bit(DEV_CLEAR_BN, &nec_priv->state))
449 return -EINTR;
450 return 0;
451 }
452
generic_write(struct gpib_board * board,u8 * buffer,size_t length,int send_eoi,int send_commands,size_t * bytes_written)453 static int generic_write(struct gpib_board *board, u8 *buffer, size_t length,
454 int send_eoi, int send_commands, size_t *bytes_written)
455 {
456 size_t count = 0;
457 ssize_t retval = 0;
458 struct tnt4882_priv *tnt_priv = board->private_data;
459 struct nec7210_priv *nec_priv = &tnt_priv->nec7210_priv;
460 unsigned int bits;
461 s32 hw_count;
462 unsigned long flags;
463
464 *bytes_written = 0;
465 // FIXME: really, DEV_CLEAR_BN should happen elsewhere to prevent race
466 clear_bit(DEV_CLEAR_BN, &nec_priv->state);
467
468 nec7210_set_reg_bits(nec_priv, IMR1, HR_ERRIE, HR_ERRIE);
469
470 if (nec_priv->type != TNT4882 && nec_priv->type != TNT5004)
471 nec7210_set_reg_bits(nec_priv, IMR2, HR_DMAO, HR_DMAO);
472 else
473 nec7210_set_reg_bits(nec_priv, IMR2, HR_DMAO, 0);
474
475 tnt_writeb(tnt_priv, RESET_FIFO, CMDR);
476 udelay(1);
477
478 bits = TNT_B_16BIT;
479 if (send_eoi) {
480 bits |= TNT_CCEN;
481 if (nec_priv->type != TNT4882 && nec_priv->type != TNT5004)
482 tnt_writeb(tnt_priv, AUX_SEOI, CCR);
483 }
484 if (send_commands)
485 bits |= TNT_COMMAND;
486 tnt_writeb(tnt_priv, bits, CFG);
487
488 // load 2's complement of count into hardware counters
489 hw_count = -length;
490 tnt_writeb(tnt_priv, hw_count & 0xff, CNT0);
491 tnt_writeb(tnt_priv, (hw_count >> 8) & 0xff, CNT1);
492 tnt_writeb(tnt_priv, (hw_count >> 16) & 0xff, CNT2);
493 tnt_writeb(tnt_priv, (hw_count >> 24) & 0xff, CNT3);
494
495 tnt_writeb(tnt_priv, GO, CMDR);
496 udelay(1);
497
498 spin_lock_irqsave(&board->spinlock, flags);
499 tnt_priv->imr3_bits |= HR_DONE;
500 tnt_writeb(tnt_priv, tnt_priv->imr3_bits, IMR3);
501 spin_unlock_irqrestore(&board->spinlock, flags);
502
503 while (count < length) {
504 // wait until byte is ready to be sent
505 retval = write_wait(board, tnt_priv, 0, send_commands);
506 if (retval < 0)
507 break;
508 if (fifo_xfer_done(tnt_priv))
509 break;
510 spin_lock_irqsave(&board->spinlock, flags);
511 while (fifo_space_available(tnt_priv) && count < length) {
512 u16 word;
513
514 word = buffer[count++] & 0xff;
515 if (count < length)
516 word |= (buffer[count++] << 8) & 0xff00;
517 iowrite16(word, nec_priv->mmiobase + FIFOB);
518 }
519 // avoid unnecessary HR_NFF interrupts
520 // tnt_priv->imr3_bits |= HR_NFF;
521 // tnt_writeb(tnt_priv, tnt_priv->imr3_bits, IMR3);
522 spin_unlock_irqrestore(&board->spinlock, flags);
523
524 if (need_resched())
525 schedule();
526 }
527 // wait last byte has been sent
528 if (retval == 0)
529 retval = write_wait(board, tnt_priv, 1, send_commands);
530
531 tnt_writeb(tnt_priv, STOP, CMDR);
532 udelay(1);
533
534 nec7210_set_reg_bits(nec_priv, IMR1, HR_ERR, 0x0);
535 nec7210_set_reg_bits(nec_priv, IMR2, HR_DMAO, 0x0);
536 /*
537 * force handling of any interrupts that happened
538 * while they were masked (this appears to be needed)
539 */
540 tnt4882_internal_interrupt(board);
541 *bytes_written = length - tnt_transfer_count(tnt_priv);
542 return retval;
543 }
544
tnt4882_accel_write(struct gpib_board * board,u8 * buffer,size_t length,int send_eoi,size_t * bytes_written)545 static int tnt4882_accel_write(struct gpib_board *board, u8 *buffer,
546 size_t length, int send_eoi, size_t *bytes_written)
547 {
548 return generic_write(board, buffer, length, send_eoi, 0, bytes_written);
549 }
550
tnt4882_command(struct gpib_board * board,u8 * buffer,size_t length,size_t * bytes_written)551 static int tnt4882_command(struct gpib_board *board, u8 *buffer, size_t length,
552 size_t *bytes_written)
553 {
554 return generic_write(board, buffer, length, 0, 1, bytes_written);
555 }
556
tnt4882_internal_interrupt(struct gpib_board * board)557 static irqreturn_t tnt4882_internal_interrupt(struct gpib_board *board)
558 {
559 struct tnt4882_priv *priv = board->private_data;
560 int isr0_bits, isr3_bits, imr3_bits;
561 unsigned long flags;
562
563 spin_lock_irqsave(&board->spinlock, flags);
564
565 nec7210_interrupt(board, &priv->nec7210_priv);
566
567 isr0_bits = tnt_readb(priv, ISR0);
568 isr3_bits = tnt_readb(priv, ISR3);
569 imr3_bits = priv->imr3_bits;
570
571 if (isr0_bits & TNT_IFCI_BIT)
572 push_gpib_event(board, EVENT_IFC);
573 // XXX don't need this wakeup, one below should do?
574 // wake_up_interruptible(&board->wait);
575
576 if (isr3_bits & HR_NFF)
577 priv->imr3_bits &= ~HR_NFF;
578 if (isr3_bits & HR_NEF)
579 priv->imr3_bits &= ~HR_NEF;
580 if (isr3_bits & HR_DONE)
581 priv->imr3_bits &= ~HR_DONE;
582 if (isr3_bits & (HR_INTR | HR_TLCI)) {
583 dev_dbg(board->gpib_dev, "minor %i isr0 0x%x imr0 0x%x isr3 0x%x imr3 0x%x\n",
584 board->minor, isr0_bits, priv->imr0_bits, isr3_bits, imr3_bits);
585 tnt_writeb(priv, priv->imr3_bits, IMR3);
586 wake_up_interruptible(&board->wait);
587 }
588 spin_unlock_irqrestore(&board->spinlock, flags);
589 return IRQ_HANDLED;
590 }
591
tnt4882_interrupt(int irq,void * arg)592 static irqreturn_t tnt4882_interrupt(int irq, void *arg)
593 {
594 return tnt4882_internal_interrupt(arg);
595 }
596
597 // wrappers for interface functions
tnt4882_read(struct gpib_board * board,u8 * buffer,size_t length,int * end,size_t * bytes_read)598 static int tnt4882_read(struct gpib_board *board, u8 *buffer, size_t length, int *end,
599 size_t *bytes_read)
600 {
601 struct tnt4882_priv *priv = board->private_data;
602 struct nec7210_priv *nec_priv = &priv->nec7210_priv;
603 int retval;
604 int dummy;
605
606 retval = nec7210_read(board, &priv->nec7210_priv, buffer, length, end, bytes_read);
607
608 if (retval < 0) { // force immediate holdoff
609 write_byte(nec_priv, AUX_HLDI, AUXMR);
610
611 set_bit(RFD_HOLDOFF_BN, &nec_priv->state);
612
613 nec7210_read_data_in(board, nec_priv, &dummy);
614 }
615 return retval;
616 }
617
tnt4882_write(struct gpib_board * board,u8 * buffer,size_t length,int send_eoi,size_t * bytes_written)618 static int tnt4882_write(struct gpib_board *board, u8 *buffer, size_t length, int send_eoi,
619 size_t *bytes_written)
620 {
621 struct tnt4882_priv *priv = board->private_data;
622
623 return nec7210_write(board, &priv->nec7210_priv, buffer, length, send_eoi, bytes_written);
624 }
625
tnt4882_command_unaccel(struct gpib_board * board,u8 * buffer,size_t length,size_t * bytes_written)626 static int tnt4882_command_unaccel(struct gpib_board *board, u8 *buffer,
627 size_t length, size_t *bytes_written)
628 {
629 struct tnt4882_priv *priv = board->private_data;
630
631 return nec7210_command(board, &priv->nec7210_priv, buffer, length, bytes_written);
632 }
633
tnt4882_take_control(struct gpib_board * board,int synchronous)634 static int tnt4882_take_control(struct gpib_board *board, int synchronous)
635 {
636 struct tnt4882_priv *priv = board->private_data;
637
638 return nec7210_take_control(board, &priv->nec7210_priv, synchronous);
639 }
640
tnt4882_go_to_standby(struct gpib_board * board)641 static int tnt4882_go_to_standby(struct gpib_board *board)
642 {
643 struct tnt4882_priv *priv = board->private_data;
644
645 return nec7210_go_to_standby(board, &priv->nec7210_priv);
646 }
647
tnt4882_request_system_control(struct gpib_board * board,int request_control)648 static int tnt4882_request_system_control(struct gpib_board *board, int request_control)
649 {
650 struct tnt4882_priv *priv = board->private_data;
651 int retval;
652
653 if (request_control) {
654 tnt_writeb(priv, SETSC, CMDR);
655 udelay(1);
656 }
657 retval = nec7210_request_system_control(board, &priv->nec7210_priv, request_control);
658 if (!request_control) {
659 tnt_writeb(priv, CLRSC, CMDR);
660 udelay(1);
661 }
662 return retval;
663 }
664
tnt4882_interface_clear(struct gpib_board * board,int assert)665 static void tnt4882_interface_clear(struct gpib_board *board, int assert)
666 {
667 struct tnt4882_priv *priv = board->private_data;
668
669 nec7210_interface_clear(board, &priv->nec7210_priv, assert);
670 }
671
tnt4882_remote_enable(struct gpib_board * board,int enable)672 static void tnt4882_remote_enable(struct gpib_board *board, int enable)
673 {
674 struct tnt4882_priv *priv = board->private_data;
675
676 nec7210_remote_enable(board, &priv->nec7210_priv, enable);
677 }
678
tnt4882_enable_eos(struct gpib_board * board,u8 eos_byte,int compare_8_bits)679 static int tnt4882_enable_eos(struct gpib_board *board, u8 eos_byte, int compare_8_bits)
680 {
681 struct tnt4882_priv *priv = board->private_data;
682
683 return nec7210_enable_eos(board, &priv->nec7210_priv, eos_byte, compare_8_bits);
684 }
685
tnt4882_disable_eos(struct gpib_board * board)686 static void tnt4882_disable_eos(struct gpib_board *board)
687 {
688 struct tnt4882_priv *priv = board->private_data;
689
690 nec7210_disable_eos(board, &priv->nec7210_priv);
691 }
692
tnt4882_update_status(struct gpib_board * board,unsigned int clear_mask)693 static unsigned int tnt4882_update_status(struct gpib_board *board, unsigned int clear_mask)
694 {
695 unsigned long flags;
696 u8 line_status;
697 struct tnt4882_priv *priv = board->private_data;
698
699 spin_lock_irqsave(&board->spinlock, flags);
700 board->status &= ~clear_mask;
701 nec7210_update_status_nolock(board, &priv->nec7210_priv);
702 /* set / clear SRQ state since it is not cleared by interrupt */
703 line_status = tnt_readb(priv, BSR);
704 if (line_status & BCSR_SRQ_BIT)
705 set_bit(SRQI_NUM, &board->status);
706 else
707 clear_bit(SRQI_NUM, &board->status);
708 spin_unlock_irqrestore(&board->spinlock, flags);
709 return board->status;
710 }
711
tnt4882_primary_address(struct gpib_board * board,unsigned int address)712 static int tnt4882_primary_address(struct gpib_board *board, unsigned int address)
713 {
714 struct tnt4882_priv *priv = board->private_data;
715
716 return nec7210_primary_address(board, &priv->nec7210_priv, address);
717 }
718
tnt4882_secondary_address(struct gpib_board * board,unsigned int address,int enable)719 static int tnt4882_secondary_address(struct gpib_board *board, unsigned int address, int enable)
720 {
721 struct tnt4882_priv *priv = board->private_data;
722
723 return nec7210_secondary_address(board, &priv->nec7210_priv, address, enable);
724 }
725
tnt4882_parallel_poll(struct gpib_board * board,u8 * result)726 static int tnt4882_parallel_poll(struct gpib_board *board, u8 *result)
727 {
728 struct tnt4882_priv *tnt_priv = board->private_data;
729
730 if (tnt_priv->nec7210_priv.type != NEC7210) {
731 tnt_priv->auxg_bits |= RPP2_BIT;
732 write_byte(&tnt_priv->nec7210_priv, tnt_priv->auxg_bits, AUXMR);
733 udelay(2); // FIXME use parallel poll timeout
734 *result = read_byte(&tnt_priv->nec7210_priv, CPTR);
735 tnt_priv->auxg_bits &= ~RPP2_BIT;
736 write_byte(&tnt_priv->nec7210_priv, tnt_priv->auxg_bits, AUXMR);
737 return 0;
738 } else {
739 return nec7210_parallel_poll(board, &tnt_priv->nec7210_priv, result);
740 }
741 }
742
tnt4882_parallel_poll_configure(struct gpib_board * board,u8 config)743 static void tnt4882_parallel_poll_configure(struct gpib_board *board, u8 config)
744 {
745 struct tnt4882_priv *priv = board->private_data;
746
747 if (priv->nec7210_priv.type == TNT5004) {
748 /* configure locally */
749 write_byte(&priv->nec7210_priv, AUXRI | 0x4, AUXMR);
750 if (config)
751 /* set response + clear sense */
752 write_byte(&priv->nec7210_priv, PPR | config, AUXMR);
753 else
754 /* disable ppoll */
755 write_byte(&priv->nec7210_priv, PPR | 0x10, AUXMR);
756 } else {
757 nec7210_parallel_poll_configure(board, &priv->nec7210_priv, config);
758 }
759 }
760
tnt4882_parallel_poll_response(struct gpib_board * board,int ist)761 static void tnt4882_parallel_poll_response(struct gpib_board *board, int ist)
762 {
763 struct tnt4882_priv *priv = board->private_data;
764
765 nec7210_parallel_poll_response(board, &priv->nec7210_priv, ist);
766 }
767
768 /*
769 * this is just used by the old nec7210 isa interfaces, the newer
770 * boards use tnt4882_serial_poll_response2
771 */
tnt4882_serial_poll_response(struct gpib_board * board,u8 status)772 static void tnt4882_serial_poll_response(struct gpib_board *board, u8 status)
773 {
774 struct tnt4882_priv *priv = board->private_data;
775
776 nec7210_serial_poll_response(board, &priv->nec7210_priv, status);
777 }
778
tnt4882_serial_poll_response2(struct gpib_board * board,u8 status,int new_reason_for_service)779 static void tnt4882_serial_poll_response2(struct gpib_board *board, u8 status,
780 int new_reason_for_service)
781 {
782 struct tnt4882_priv *priv = board->private_data;
783 unsigned long flags;
784 const int MSS = status & request_service_bit;
785 const int reqt = MSS && new_reason_for_service;
786 const int reqf = MSS == 0;
787
788 spin_lock_irqsave(&board->spinlock, flags);
789 if (reqt) {
790 priv->nec7210_priv.srq_pending = 1;
791 clear_bit(SPOLL_NUM, &board->status);
792 } else {
793 if (reqf)
794 priv->nec7210_priv.srq_pending = 0;
795 }
796 if (reqt)
797 /*
798 * It may seem like a race to issue reqt before updating
799 * the status byte, but it is not. The chip does not
800 * issue the reqt until the SPMR is written to at
801 * a later time.
802 */
803 write_byte(&priv->nec7210_priv, AUX_REQT, AUXMR);
804 else if (reqf)
805 write_byte(&priv->nec7210_priv, AUX_REQF, AUXMR);
806 /*
807 * We need to always zero bit 6 of the status byte before writing it to
808 * the SPMR to insure we are using
809 * serial poll mode SP1, and not accidentally triggering mode SP3.
810 */
811 write_byte(&priv->nec7210_priv, status & ~request_service_bit, SPMR);
812 spin_unlock_irqrestore(&board->spinlock, flags);
813 }
814
tnt4882_serial_poll_status(struct gpib_board * board)815 static u8 tnt4882_serial_poll_status(struct gpib_board *board)
816 {
817 struct tnt4882_priv *priv = board->private_data;
818
819 return nec7210_serial_poll_status(board, &priv->nec7210_priv);
820 }
821
tnt4882_return_to_local(struct gpib_board * board)822 static void tnt4882_return_to_local(struct gpib_board *board)
823 {
824 struct tnt4882_priv *priv = board->private_data;
825
826 nec7210_return_to_local(board, &priv->nec7210_priv);
827 }
828
tnt4882_board_reset(struct tnt4882_priv * tnt_priv,struct gpib_board * board)829 static void tnt4882_board_reset(struct tnt4882_priv *tnt_priv, struct gpib_board *board)
830 {
831 struct nec7210_priv *nec_priv = &tnt_priv->nec7210_priv;
832
833 tnt_priv->imr0_bits = 0;
834 tnt_writeb(tnt_priv, tnt_priv->imr0_bits, IMR0);
835 tnt_priv->imr3_bits = 0;
836 tnt_writeb(tnt_priv, tnt_priv->imr3_bits, IMR3);
837 tnt_readb(tnt_priv, IMR0);
838 tnt_readb(tnt_priv, IMR3);
839 nec7210_board_reset(nec_priv, board);
840 }
841
tnt4882_allocate_private(struct gpib_board * board)842 static int tnt4882_allocate_private(struct gpib_board *board)
843 {
844 struct tnt4882_priv *tnt_priv;
845
846 board->private_data = kzalloc_obj(struct tnt4882_priv);
847 if (!board->private_data)
848 return -ENOMEM;
849 tnt_priv = board->private_data;
850 init_nec7210_private(&tnt_priv->nec7210_priv);
851 return 0;
852 }
853
tnt4882_free_private(struct gpib_board * board)854 static void tnt4882_free_private(struct gpib_board *board)
855 {
856 kfree(board->private_data);
857 board->private_data = NULL;
858 }
859
tnt4882_init(struct tnt4882_priv * tnt_priv,const struct gpib_board * board)860 static void tnt4882_init(struct tnt4882_priv *tnt_priv, const struct gpib_board *board)
861 {
862 struct nec7210_priv *nec_priv = &tnt_priv->nec7210_priv;
863
864 /* Turbo488 software reset */
865 tnt_writeb(tnt_priv, SOFT_RESET, CMDR);
866 udelay(1);
867
868 // turn off one-chip mode
869 tnt_writeb(tnt_priv, NODMA, HSSEL);
870 tnt_writeb(tnt_priv, 0, ACCWR);
871 // make sure we are in 7210 mode
872 tnt_writeb(tnt_priv, AUX_7210, AUXCR);
873 udelay(1);
874 // registers might be swapped, so write it to the swapped address too
875 tnt_writeb(tnt_priv, AUX_7210, SWAPPED_AUXCR);
876 udelay(1);
877 // turn on one-chip mode
878 if (nec_priv->type == TNT4882 || nec_priv->type == TNT5004)
879 tnt_writeb(tnt_priv, NODMA | TNT_ONE_CHIP_BIT, HSSEL);
880 else
881 tnt_writeb(tnt_priv, NODMA, HSSEL);
882
883 nec7210_board_reset(nec_priv, board);
884 // read-clear isr0
885 tnt_readb(tnt_priv, ISR0);
886
887 // enable passing of nat4882 interrupts
888 tnt_priv->imr3_bits = HR_TLCI;
889 tnt_writeb(tnt_priv, tnt_priv->imr3_bits, IMR3);
890
891 // enable interrupt
892 tnt_writeb(tnt_priv, 0x1, INTRT);
893
894 // force immediate holdoff
895 write_byte(&tnt_priv->nec7210_priv, AUX_HLDI, AUXMR);
896
897 set_bit(RFD_HOLDOFF_BN, &nec_priv->state);
898
899 tnt_priv->auxg_bits = AUXRG | NTNL_BIT;
900 write_byte(&tnt_priv->nec7210_priv, tnt_priv->auxg_bits, AUXMR);
901
902 nec7210_board_online(nec_priv, board);
903 // enable interface clear interrupt for event queue
904 tnt_priv->imr0_bits = TNT_IMR0_ALWAYS_BITS | TNT_ATNI_BIT | TNT_IFCIE_BIT;
905 tnt_writeb(tnt_priv, tnt_priv->imr0_bits, IMR0);
906 }
907
ni_pci_attach(struct gpib_board * board,const struct gpib_board_config * config)908 static int ni_pci_attach(struct gpib_board *board, const struct gpib_board_config *config)
909 {
910 struct tnt4882_priv *tnt_priv;
911 struct nec7210_priv *nec_priv;
912 int isr_flags = IRQF_SHARED;
913 int retval;
914 struct mite_struct *mite;
915
916 board->status = 0;
917
918 retval = tnt4882_allocate_private(board);
919 if (retval)
920 return retval;
921 tnt_priv = board->private_data;
922 nec_priv = &tnt_priv->nec7210_priv;
923 nec_priv->type = TNT4882;
924 nec_priv->read_byte = nec7210_locking_iomem_read_byte;
925 nec_priv->write_byte = nec7210_locking_iomem_write_byte;
926 nec_priv->offset = atgpib_reg_offset;
927
928 if (!mite_devices)
929 return -ENODEV;
930
931 for (mite = mite_devices; mite; mite = mite->next) {
932 short found_board;
933
934 if (mite->used)
935 continue;
936 if (config->pci_bus >= 0 && config->pci_bus != mite->pcidev->bus->number)
937 continue;
938 if (config->pci_slot >= 0 && config->pci_slot != PCI_SLOT(mite->pcidev->devfn))
939 continue;
940 switch (mite_device_id(mite)) {
941 case PCI_DEVICE_ID_NI_GPIB:
942 case PCI_DEVICE_ID_NI_GPIB_PLUS:
943 case PCI_DEVICE_ID_NI_GPIB_PLUS2:
944 case PCI_DEVICE_ID_NI_PXIGPIB:
945 case PCI_DEVICE_ID_NI_PMCGPIB:
946 case PCI_DEVICE_ID_NI_PCIEGPIB:
947 case PCI_DEVICE_ID_NI_PCIE2GPIB:
948 // support for Measurement Computing PCI-488
949 case PCI_DEVICE_ID_MC_PCI488:
950 case PCI_DEVICE_ID_CEC_NI_GPIB:
951 found_board = 1;
952 break;
953 default:
954 found_board = 0;
955 break;
956 }
957 if (found_board)
958 break;
959 }
960 if (!mite)
961 return -ENODEV;
962
963 tnt_priv->mite = mite;
964 retval = mite_setup(tnt_priv->mite);
965 if (retval < 0)
966 return retval;
967
968 nec_priv->mmiobase = tnt_priv->mite->daq_io_addr;
969
970 // get irq
971 retval = request_irq(mite_irq(tnt_priv->mite), tnt4882_interrupt, isr_flags, "ni-pci-gpib",
972 board);
973 if (retval) {
974 dev_err(board->gpib_dev, "failed to obtain pci irq %d\n", mite_irq(tnt_priv->mite));
975 return retval;
976 }
977 tnt_priv->irq = mite_irq(tnt_priv->mite);
978
979 // TNT5004 detection
980 switch (tnt_readb(tnt_priv, CSR) & 0xf0) {
981 case 0x30:
982 nec_priv->type = TNT4882;
983 break;
984 case 0x40:
985 nec_priv->type = TNT5004;
986 break;
987 }
988 tnt4882_init(tnt_priv, board);
989
990 return 0;
991 }
992
ni_pci_detach(struct gpib_board * board)993 static void ni_pci_detach(struct gpib_board *board)
994 {
995 struct tnt4882_priv *tnt_priv = board->private_data;
996 struct nec7210_priv *nec_priv;
997
998 if (tnt_priv) {
999 nec_priv = &tnt_priv->nec7210_priv;
1000
1001 if (nec_priv->mmiobase)
1002 tnt4882_board_reset(tnt_priv, board);
1003 if (tnt_priv->irq)
1004 free_irq(tnt_priv->irq, board);
1005 if (tnt_priv->mite)
1006 mite_unsetup(tnt_priv->mite);
1007 }
1008 tnt4882_free_private(board);
1009 }
1010
ni_isapnp_find(struct pnp_dev ** dev)1011 static int ni_isapnp_find(struct pnp_dev **dev)
1012 {
1013 *dev = pnp_find_dev(NULL, ISAPNP_VENDOR_ID_NI,
1014 ISAPNP_FUNCTION(ISAPNP_ID_NI_ATGPIB_TNT), NULL);
1015 if (!*dev || !(*dev)->card)
1016 return -ENODEV;
1017 if (pnp_device_attach(*dev) < 0)
1018 return -EBUSY;
1019 if (pnp_activate_dev(*dev) < 0) {
1020 pnp_device_detach(*dev);
1021 return -EAGAIN;
1022 }
1023 if (!pnp_port_valid(*dev, 0) || !pnp_irq_valid(*dev, 0)) {
1024 pnp_device_detach(*dev);
1025 return -EINVAL;
1026 }
1027 return 0;
1028 }
1029
ni_isa_attach_common(struct gpib_board * board,const struct gpib_board_config * config,enum nec7210_chipset chipset)1030 static int ni_isa_attach_common(struct gpib_board *board, const struct gpib_board_config *config,
1031 enum nec7210_chipset chipset)
1032 {
1033 struct tnt4882_priv *tnt_priv;
1034 struct nec7210_priv *nec_priv;
1035 int isr_flags = 0;
1036 u32 iobase;
1037 int irq;
1038 int retval;
1039
1040 board->status = 0;
1041
1042 retval = tnt4882_allocate_private(board);
1043 if (retval)
1044 return retval;
1045 tnt_priv = board->private_data;
1046 nec_priv = &tnt_priv->nec7210_priv;
1047 nec_priv->type = chipset;
1048 nec_priv->read_byte = nec7210_locking_ioport_read_byte;
1049 nec_priv->write_byte = nec7210_locking_ioport_write_byte;
1050 nec_priv->offset = atgpib_reg_offset;
1051
1052 // look for plug-n-play board
1053 if (config->ibbase == 0) {
1054 struct pnp_dev *dev;
1055
1056 retval = ni_isapnp_find(&dev);
1057 if (retval < 0)
1058 return retval;
1059 tnt_priv->pnp_dev = dev;
1060 iobase = pnp_port_start(dev, 0);
1061 irq = pnp_irq(dev, 0);
1062 } else {
1063 iobase = config->ibbase;
1064 irq = config->ibirq;
1065 }
1066 // allocate ioports
1067 if (!request_region(iobase, atgpib_iosize, "atgpib"))
1068 return -EBUSY;
1069
1070 nec_priv->mmiobase = ioport_map(iobase, atgpib_iosize);
1071 if (!nec_priv->mmiobase)
1072 return -EBUSY;
1073
1074 // get irq
1075 retval = request_irq(irq, tnt4882_interrupt, isr_flags, "atgpib", board);
1076 if (retval) {
1077 dev_err(board->gpib_dev, "failed to request ISA irq %d\n", irq);
1078 return retval;
1079 }
1080 tnt_priv->irq = irq;
1081
1082 tnt4882_init(tnt_priv, board);
1083
1084 return 0;
1085 }
1086
ni_tnt_isa_attach(struct gpib_board * board,const struct gpib_board_config * config)1087 static int ni_tnt_isa_attach(struct gpib_board *board, const struct gpib_board_config *config)
1088 {
1089 return ni_isa_attach_common(board, config, TNT4882);
1090 }
1091
ni_nat4882_isa_attach(struct gpib_board * board,const struct gpib_board_config * config)1092 static int ni_nat4882_isa_attach(struct gpib_board *board, const struct gpib_board_config *config)
1093 {
1094 return ni_isa_attach_common(board, config, NAT4882);
1095 }
1096
ni_nec_isa_attach(struct gpib_board * board,const struct gpib_board_config * config)1097 static int ni_nec_isa_attach(struct gpib_board *board, const struct gpib_board_config *config)
1098 {
1099 return ni_isa_attach_common(board, config, NEC7210);
1100 }
1101
ni_isa_detach(struct gpib_board * board)1102 static void ni_isa_detach(struct gpib_board *board)
1103 {
1104 struct tnt4882_priv *tnt_priv = board->private_data;
1105 struct nec7210_priv *nec_priv;
1106
1107 if (tnt_priv) {
1108 nec_priv = &tnt_priv->nec7210_priv;
1109 if (nec_priv->iobase)
1110 tnt4882_board_reset(tnt_priv, board);
1111 if (tnt_priv->irq)
1112 free_irq(tnt_priv->irq, board);
1113 if (nec_priv->mmiobase)
1114 ioport_unmap(nec_priv->mmiobase);
1115 if (nec_priv->iobase)
1116 release_region(nec_priv->iobase, atgpib_iosize);
1117 if (tnt_priv->pnp_dev)
1118 pnp_device_detach(tnt_priv->pnp_dev);
1119 }
1120 tnt4882_free_private(board);
1121 }
1122
tnt4882_pci_probe(struct pci_dev * dev,const struct pci_device_id * id)1123 static int tnt4882_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
1124 {
1125 return 0;
1126 }
1127
1128 static struct gpib_interface ni_pci_interface = {
1129 .name = "ni_pci",
1130 .attach = ni_pci_attach,
1131 .detach = ni_pci_detach,
1132 .read = tnt4882_accel_read,
1133 .write = tnt4882_accel_write,
1134 .command = tnt4882_command,
1135 .take_control = tnt4882_take_control,
1136 .go_to_standby = tnt4882_go_to_standby,
1137 .request_system_control = tnt4882_request_system_control,
1138 .interface_clear = tnt4882_interface_clear,
1139 .remote_enable = tnt4882_remote_enable,
1140 .enable_eos = tnt4882_enable_eos,
1141 .disable_eos = tnt4882_disable_eos,
1142 .parallel_poll = tnt4882_parallel_poll,
1143 .parallel_poll_configure = tnt4882_parallel_poll_configure,
1144 .parallel_poll_response = tnt4882_parallel_poll_response,
1145 .local_parallel_poll_mode = NULL, // XXX
1146 .line_status = tnt4882_line_status,
1147 .update_status = tnt4882_update_status,
1148 .primary_address = tnt4882_primary_address,
1149 .secondary_address = tnt4882_secondary_address,
1150 .serial_poll_response2 = tnt4882_serial_poll_response2,
1151 .serial_poll_status = tnt4882_serial_poll_status,
1152 .t1_delay = tnt4882_t1_delay,
1153 .return_to_local = tnt4882_return_to_local,
1154 };
1155
1156 static struct gpib_interface ni_pci_accel_interface = {
1157 .name = "ni_pci_accel",
1158 .attach = ni_pci_attach,
1159 .detach = ni_pci_detach,
1160 .read = tnt4882_accel_read,
1161 .write = tnt4882_accel_write,
1162 .command = tnt4882_command,
1163 .take_control = tnt4882_take_control,
1164 .go_to_standby = tnt4882_go_to_standby,
1165 .request_system_control = tnt4882_request_system_control,
1166 .interface_clear = tnt4882_interface_clear,
1167 .remote_enable = tnt4882_remote_enable,
1168 .enable_eos = tnt4882_enable_eos,
1169 .disable_eos = tnt4882_disable_eos,
1170 .parallel_poll = tnt4882_parallel_poll,
1171 .parallel_poll_configure = tnt4882_parallel_poll_configure,
1172 .parallel_poll_response = tnt4882_parallel_poll_response,
1173 .local_parallel_poll_mode = NULL, // XXX
1174 .line_status = tnt4882_line_status,
1175 .update_status = tnt4882_update_status,
1176 .primary_address = tnt4882_primary_address,
1177 .secondary_address = tnt4882_secondary_address,
1178 .serial_poll_response2 = tnt4882_serial_poll_response2,
1179 .serial_poll_status = tnt4882_serial_poll_status,
1180 .t1_delay = tnt4882_t1_delay,
1181 .return_to_local = tnt4882_return_to_local,
1182 };
1183
1184 static struct gpib_interface ni_isa_interface = {
1185 .name = "ni_isa",
1186 .attach = ni_tnt_isa_attach,
1187 .detach = ni_isa_detach,
1188 .read = tnt4882_accel_read,
1189 .write = tnt4882_accel_write,
1190 .command = tnt4882_command,
1191 .take_control = tnt4882_take_control,
1192 .go_to_standby = tnt4882_go_to_standby,
1193 .request_system_control = tnt4882_request_system_control,
1194 .interface_clear = tnt4882_interface_clear,
1195 .remote_enable = tnt4882_remote_enable,
1196 .enable_eos = tnt4882_enable_eos,
1197 .disable_eos = tnt4882_disable_eos,
1198 .parallel_poll = tnt4882_parallel_poll,
1199 .parallel_poll_configure = tnt4882_parallel_poll_configure,
1200 .parallel_poll_response = tnt4882_parallel_poll_response,
1201 .local_parallel_poll_mode = NULL, // XXX
1202 .line_status = tnt4882_line_status,
1203 .update_status = tnt4882_update_status,
1204 .primary_address = tnt4882_primary_address,
1205 .secondary_address = tnt4882_secondary_address,
1206 .serial_poll_response2 = tnt4882_serial_poll_response2,
1207 .serial_poll_status = tnt4882_serial_poll_status,
1208 .t1_delay = tnt4882_t1_delay,
1209 .return_to_local = tnt4882_return_to_local,
1210 };
1211
1212 static struct gpib_interface ni_nat4882_isa_interface = {
1213 .name = "ni_nat4882_isa",
1214 .attach = ni_nat4882_isa_attach,
1215 .detach = ni_isa_detach,
1216 .read = tnt4882_read,
1217 .write = tnt4882_write,
1218 .command = tnt4882_command_unaccel,
1219 .take_control = tnt4882_take_control,
1220 .go_to_standby = tnt4882_go_to_standby,
1221 .request_system_control = tnt4882_request_system_control,
1222 .interface_clear = tnt4882_interface_clear,
1223 .remote_enable = tnt4882_remote_enable,
1224 .enable_eos = tnt4882_enable_eos,
1225 .disable_eos = tnt4882_disable_eos,
1226 .parallel_poll = tnt4882_parallel_poll,
1227 .parallel_poll_configure = tnt4882_parallel_poll_configure,
1228 .parallel_poll_response = tnt4882_parallel_poll_response,
1229 .local_parallel_poll_mode = NULL, // XXX
1230 .line_status = tnt4882_line_status,
1231 .update_status = tnt4882_update_status,
1232 .primary_address = tnt4882_primary_address,
1233 .secondary_address = tnt4882_secondary_address,
1234 .serial_poll_response2 = tnt4882_serial_poll_response2,
1235 .serial_poll_status = tnt4882_serial_poll_status,
1236 .t1_delay = tnt4882_t1_delay,
1237 .return_to_local = tnt4882_return_to_local,
1238 };
1239
1240 static struct gpib_interface ni_nec_isa_interface = {
1241 .name = "ni_nec_isa",
1242 .attach = ni_nec_isa_attach,
1243 .detach = ni_isa_detach,
1244 .read = tnt4882_read,
1245 .write = tnt4882_write,
1246 .command = tnt4882_command_unaccel,
1247 .take_control = tnt4882_take_control,
1248 .go_to_standby = tnt4882_go_to_standby,
1249 .request_system_control = tnt4882_request_system_control,
1250 .interface_clear = tnt4882_interface_clear,
1251 .remote_enable = tnt4882_remote_enable,
1252 .enable_eos = tnt4882_enable_eos,
1253 .disable_eos = tnt4882_disable_eos,
1254 .parallel_poll = tnt4882_parallel_poll,
1255 .parallel_poll_configure = tnt4882_parallel_poll_configure,
1256 .parallel_poll_response = tnt4882_parallel_poll_response,
1257 .local_parallel_poll_mode = NULL, // XXX
1258 .line_status = NULL,
1259 .update_status = tnt4882_update_status,
1260 .primary_address = tnt4882_primary_address,
1261 .secondary_address = tnt4882_secondary_address,
1262 .serial_poll_response = tnt4882_serial_poll_response,
1263 .serial_poll_status = tnt4882_serial_poll_status,
1264 .t1_delay = tnt4882_t1_delay,
1265 .return_to_local = tnt4882_return_to_local,
1266 };
1267
1268 static struct gpib_interface ni_isa_accel_interface = {
1269 .name = "ni_isa_accel",
1270 .attach = ni_tnt_isa_attach,
1271 .detach = ni_isa_detach,
1272 .read = tnt4882_accel_read,
1273 .write = tnt4882_accel_write,
1274 .command = tnt4882_command,
1275 .take_control = tnt4882_take_control,
1276 .go_to_standby = tnt4882_go_to_standby,
1277 .request_system_control = tnt4882_request_system_control,
1278 .interface_clear = tnt4882_interface_clear,
1279 .remote_enable = tnt4882_remote_enable,
1280 .enable_eos = tnt4882_enable_eos,
1281 .disable_eos = tnt4882_disable_eos,
1282 .parallel_poll = tnt4882_parallel_poll,
1283 .parallel_poll_configure = tnt4882_parallel_poll_configure,
1284 .parallel_poll_response = tnt4882_parallel_poll_response,
1285 .local_parallel_poll_mode = NULL, // XXX
1286 .line_status = tnt4882_line_status,
1287 .update_status = tnt4882_update_status,
1288 .primary_address = tnt4882_primary_address,
1289 .secondary_address = tnt4882_secondary_address,
1290 .serial_poll_response2 = tnt4882_serial_poll_response2,
1291 .serial_poll_status = tnt4882_serial_poll_status,
1292 .t1_delay = tnt4882_t1_delay,
1293 .return_to_local = tnt4882_return_to_local,
1294 };
1295
1296 static struct gpib_interface ni_nat4882_isa_accel_interface = {
1297 .name = "ni_nat4882_isa_accel",
1298 .attach = ni_nat4882_isa_attach,
1299 .detach = ni_isa_detach,
1300 .read = tnt4882_accel_read,
1301 .write = tnt4882_accel_write,
1302 .command = tnt4882_command_unaccel,
1303 .take_control = tnt4882_take_control,
1304 .go_to_standby = tnt4882_go_to_standby,
1305 .request_system_control = tnt4882_request_system_control,
1306 .interface_clear = tnt4882_interface_clear,
1307 .remote_enable = tnt4882_remote_enable,
1308 .enable_eos = tnt4882_enable_eos,
1309 .disable_eos = tnt4882_disable_eos,
1310 .parallel_poll = tnt4882_parallel_poll,
1311 .parallel_poll_configure = tnt4882_parallel_poll_configure,
1312 .parallel_poll_response = tnt4882_parallel_poll_response,
1313 .local_parallel_poll_mode = NULL, // XXX
1314 .line_status = tnt4882_line_status,
1315 .update_status = tnt4882_update_status,
1316 .primary_address = tnt4882_primary_address,
1317 .secondary_address = tnt4882_secondary_address,
1318 .serial_poll_response2 = tnt4882_serial_poll_response2,
1319 .serial_poll_status = tnt4882_serial_poll_status,
1320 .t1_delay = tnt4882_t1_delay,
1321 .return_to_local = tnt4882_return_to_local,
1322 };
1323
1324 static struct gpib_interface ni_nec_isa_accel_interface = {
1325 .name = "ni_nec_isa_accel",
1326 .attach = ni_nec_isa_attach,
1327 .detach = ni_isa_detach,
1328 .read = tnt4882_accel_read,
1329 .write = tnt4882_accel_write,
1330 .command = tnt4882_command_unaccel,
1331 .take_control = tnt4882_take_control,
1332 .go_to_standby = tnt4882_go_to_standby,
1333 .request_system_control = tnt4882_request_system_control,
1334 .interface_clear = tnt4882_interface_clear,
1335 .remote_enable = tnt4882_remote_enable,
1336 .enable_eos = tnt4882_enable_eos,
1337 .disable_eos = tnt4882_disable_eos,
1338 .parallel_poll = tnt4882_parallel_poll,
1339 .parallel_poll_configure = tnt4882_parallel_poll_configure,
1340 .parallel_poll_response = tnt4882_parallel_poll_response,
1341 .local_parallel_poll_mode = NULL, // XXX
1342 .line_status = NULL,
1343 .update_status = tnt4882_update_status,
1344 .primary_address = tnt4882_primary_address,
1345 .secondary_address = tnt4882_secondary_address,
1346 .serial_poll_response = tnt4882_serial_poll_response,
1347 .serial_poll_status = tnt4882_serial_poll_status,
1348 .t1_delay = tnt4882_t1_delay,
1349 .return_to_local = tnt4882_return_to_local,
1350 };
1351
1352 static const struct pci_device_id tnt4882_pci_table[] = {
1353 {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_NI_GPIB)},
1354 {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_NI_GPIB_PLUS)},
1355 {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_NI_GPIB_PLUS2)},
1356 {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_NI_PXIGPIB)},
1357 {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_NI_PMCGPIB)},
1358 {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_NI_PCIEGPIB)},
1359 {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_NI_PCIE2GPIB)},
1360 // support for Measurement Computing PCI-488
1361 {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_MC_PCI488)},
1362 {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_CEC_NI_GPIB)},
1363 { 0 }
1364 };
1365 MODULE_DEVICE_TABLE(pci, tnt4882_pci_table);
1366
1367 static struct pci_driver tnt4882_pci_driver = {
1368 .name = DRV_NAME,
1369 .id_table = tnt4882_pci_table,
1370 .probe = &tnt4882_pci_probe
1371 };
1372
1373 #if 0
1374 /* unused, will be needed when the driver is turned into a pnp_driver */
1375 static const struct pnp_device_id tnt4882_pnp_table[] = {
1376 {.id = "NICC601"},
1377 {.id = ""}
1378 };
1379 MODULE_DEVICE_TABLE(pnp, tnt4882_pnp_table);
1380 #endif
1381
1382 #ifdef CONFIG_GPIB_PCMCIA
1383 static struct gpib_interface ni_pcmcia_interface;
1384 static struct gpib_interface ni_pcmcia_accel_interface;
1385 static int __init init_ni_gpib_cs(void);
1386 static void __exit exit_ni_gpib_cs(void);
1387 #endif
1388
tnt4882_init_module(void)1389 static int __init tnt4882_init_module(void)
1390 {
1391 int result;
1392
1393 result = pci_register_driver(&tnt4882_pci_driver);
1394 if (result) {
1395 pr_err("pci_register_driver failed: error = %d\n", result);
1396 return result;
1397 }
1398
1399 result = gpib_register_driver(&ni_isa_interface, THIS_MODULE);
1400 if (result) {
1401 pr_err("gpib_register_driver failed: error = %d\n", result);
1402 goto err_isa;
1403 }
1404
1405 result = gpib_register_driver(&ni_isa_accel_interface, THIS_MODULE);
1406 if (result) {
1407 pr_err("gpib_register_driver failed: error = %d\n", result);
1408 goto err_isa_accel;
1409 }
1410
1411 result = gpib_register_driver(&ni_nat4882_isa_interface, THIS_MODULE);
1412 if (result) {
1413 pr_err("gpib_register_driver failed: error = %d\n", result);
1414 goto err_nat4882_isa;
1415 }
1416
1417 result = gpib_register_driver(&ni_nat4882_isa_accel_interface, THIS_MODULE);
1418 if (result) {
1419 pr_err("gpib_register_driver failed: error = %d\n", result);
1420 goto err_nat4882_isa_accel;
1421 }
1422
1423 result = gpib_register_driver(&ni_nec_isa_interface, THIS_MODULE);
1424 if (result) {
1425 pr_err("gpib_register_driver failed: error = %d\n", result);
1426 goto err_nec_isa;
1427 }
1428
1429 result = gpib_register_driver(&ni_nec_isa_accel_interface, THIS_MODULE);
1430 if (result) {
1431 pr_err("gpib_register_driver failed: error = %d\n", result);
1432 goto err_nec_isa_accel;
1433 }
1434
1435 result = gpib_register_driver(&ni_pci_interface, THIS_MODULE);
1436 if (result) {
1437 pr_err("gpib_register_driver failed: error = %d\n", result);
1438 goto err_pci;
1439 }
1440
1441 result = gpib_register_driver(&ni_pci_accel_interface, THIS_MODULE);
1442 if (result) {
1443 pr_err("gpib_register_driver failed: error = %d\n", result);
1444 goto err_pci_accel;
1445 }
1446
1447 #ifdef CONFIG_GPIB_PCMCIA
1448 result = gpib_register_driver(&ni_pcmcia_interface, THIS_MODULE);
1449 if (result) {
1450 pr_err("gpib_register_driver failed: error = %d\n", result);
1451 goto err_pcmcia;
1452 }
1453
1454 result = gpib_register_driver(&ni_pcmcia_accel_interface, THIS_MODULE);
1455 if (result) {
1456 pr_err("gpib_register_driver failed: error = %d\n", result);
1457 goto err_pcmcia_accel;
1458 }
1459
1460 result = init_ni_gpib_cs();
1461 if (result) {
1462 pr_err("pcmcia_register_driver failed: error = %d\n", result);
1463 goto err_pcmcia_driver;
1464 }
1465 #endif
1466
1467 mite_init();
1468
1469 return 0;
1470
1471 #ifdef CONFIG_GPIB_PCMCIA
1472 err_pcmcia_driver:
1473 gpib_unregister_driver(&ni_pcmcia_accel_interface);
1474 err_pcmcia_accel:
1475 gpib_unregister_driver(&ni_pcmcia_interface);
1476 err_pcmcia:
1477 #endif
1478 gpib_unregister_driver(&ni_pci_accel_interface);
1479 err_pci_accel:
1480 gpib_unregister_driver(&ni_pci_interface);
1481 err_pci:
1482 gpib_unregister_driver(&ni_nec_isa_accel_interface);
1483 err_nec_isa_accel:
1484 gpib_unregister_driver(&ni_nec_isa_interface);
1485 err_nec_isa:
1486 gpib_unregister_driver(&ni_nat4882_isa_accel_interface);
1487 err_nat4882_isa_accel:
1488 gpib_unregister_driver(&ni_nat4882_isa_interface);
1489 err_nat4882_isa:
1490 gpib_unregister_driver(&ni_isa_accel_interface);
1491 err_isa_accel:
1492 gpib_unregister_driver(&ni_isa_interface);
1493 err_isa:
1494 pci_unregister_driver(&tnt4882_pci_driver);
1495
1496 return result;
1497 }
1498
tnt4882_exit_module(void)1499 static void __exit tnt4882_exit_module(void)
1500 {
1501 gpib_unregister_driver(&ni_isa_interface);
1502 gpib_unregister_driver(&ni_isa_accel_interface);
1503 gpib_unregister_driver(&ni_nat4882_isa_interface);
1504 gpib_unregister_driver(&ni_nat4882_isa_accel_interface);
1505 gpib_unregister_driver(&ni_nec_isa_interface);
1506 gpib_unregister_driver(&ni_nec_isa_accel_interface);
1507 gpib_unregister_driver(&ni_pci_interface);
1508 gpib_unregister_driver(&ni_pci_accel_interface);
1509 #ifdef CONFIG_GPIB_PCMCIA
1510 gpib_unregister_driver(&ni_pcmcia_interface);
1511 gpib_unregister_driver(&ni_pcmcia_accel_interface);
1512 exit_ni_gpib_cs();
1513 #endif
1514
1515 mite_cleanup();
1516
1517 pci_unregister_driver(&tnt4882_pci_driver);
1518 }
1519
1520 #ifdef CONFIG_GPIB_PCMCIA
1521
1522 #include <linux/kernel.h>
1523 #include <linux/moduleparam.h>
1524 #include <linux/ptrace.h>
1525 #include <linux/timer.h>
1526 #include <linux/io.h>
1527
1528 #include <pcmcia/cistpl.h>
1529 #include <pcmcia/cisreg.h>
1530 #include <pcmcia/ds.h>
1531
1532 static int ni_gpib_config(struct pcmcia_device *link);
1533 static void ni_gpib_release(struct pcmcia_device *link);
1534 static void ni_pcmcia_detach(struct gpib_board *board);
1535
1536 /*
1537 * A linked list of "instances" of the dummy device. Each actual
1538 * PCMCIA card corresponds to one device instance, and is described
1539 * by one dev_link_t structure (defined in ds.h).
1540 *
1541 * You may not want to use a linked list for this -- for example, the
1542 * memory card driver uses an array of dev_link_t pointers, where minor
1543 * device numbers are used to derive the corresponding array index.
1544 *
1545 * I think this dev_list is obsolete but the pointer is needed to keep
1546 * the module instance for the ni_pcmcia_attach function.
1547 */
1548
1549 static struct pcmcia_device *curr_dev;
1550
1551 struct local_info_t {
1552 struct pcmcia_device *p_dev;
1553 struct gpib_board *dev;
1554 int stop;
1555 struct bus_operations *bus;
1556 };
1557
1558 /*
1559 * ni_gpib_probe() creates an "instance" of the driver, allocating
1560 * local data structures for one device. The device is registered
1561 * with Card Services.
1562 */
1563
ni_gpib_probe(struct pcmcia_device * link)1564 static int ni_gpib_probe(struct pcmcia_device *link)
1565 {
1566 struct local_info_t *info;
1567 //struct struct gpib_board *dev;
1568
1569 /* Allocate space for private device-specific data */
1570 info = kzalloc_obj(*info);
1571 if (!info)
1572 return -ENOMEM;
1573
1574 info->p_dev = link;
1575 link->priv = info;
1576
1577 /*
1578 * General socket configuration defaults can go here. In this
1579 * client, we assume very little, and rely on the CIS for almost
1580 * everything. In most clients, many details (i.e., number, sizes,
1581 * and attributes of IO windows) are fixed by the nature of the
1582 * device, and can be hard-wired here.
1583 */
1584 link->config_flags = CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
1585
1586 /* Register with Card Services */
1587 curr_dev = link;
1588 return ni_gpib_config(link);
1589 }
1590
1591 /*
1592 * This deletes a driver "instance". The device is de-registered
1593 * with Card Services. If it has been released, all local data
1594 * structures are freed. Otherwise, the structures will be freed
1595 * when the device is released.
1596 */
ni_gpib_remove(struct pcmcia_device * link)1597 static void ni_gpib_remove(struct pcmcia_device *link)
1598 {
1599 struct local_info_t *info = link->priv;
1600 //struct struct gpib_board *dev = info->dev;
1601
1602 if (info->dev)
1603 ni_pcmcia_detach(info->dev);
1604 ni_gpib_release(link);
1605
1606 //free_netdev(dev);
1607 kfree(info);
1608 }
1609
ni_gpib_config_iteration(struct pcmcia_device * link,void * priv_data)1610 static int ni_gpib_config_iteration(struct pcmcia_device *link, void *priv_data)
1611 {
1612 int retval;
1613
1614 retval = pcmcia_request_io(link);
1615 if (retval != 0)
1616 return retval;
1617
1618 return 0;
1619 }
1620
1621 /*
1622 * ni_gpib_config() is scheduled to run after a CARD_INSERTION event
1623 * is received, to configure the PCMCIA socket, and to make the
1624 * device available to the system.
1625 */
ni_gpib_config(struct pcmcia_device * link)1626 static int ni_gpib_config(struct pcmcia_device *link)
1627 {
1628 //struct local_info_t *info = link->priv;
1629 //struct gpib_board *dev = info->dev;
1630 int last_ret;
1631
1632 last_ret = pcmcia_loop_config(link, &ni_gpib_config_iteration, NULL);
1633 if (last_ret) {
1634 dev_warn(&link->dev, "no configuration found\n");
1635 ni_gpib_release(link);
1636 return last_ret;
1637 }
1638
1639 last_ret = pcmcia_enable_device(link);
1640 if (last_ret) {
1641 ni_gpib_release(link);
1642 return last_ret;
1643 }
1644 return 0;
1645 } /* ni_gpib_config */
1646
1647 /*
1648 * After a card is removed, ni_gpib_release() will unregister the
1649 * device, and release the PCMCIA configuration. If the device is
1650 * still open, this will be postponed until it is closed.
1651 */
ni_gpib_release(struct pcmcia_device * link)1652 static void ni_gpib_release(struct pcmcia_device *link)
1653 {
1654 pcmcia_disable_device(link);
1655 } /* ni_gpib_release */
1656
ni_gpib_suspend(struct pcmcia_device * link)1657 static int ni_gpib_suspend(struct pcmcia_device *link)
1658 {
1659 //struct local_info_t *info = link->priv;
1660 //struct struct gpib_board *dev = info->dev;
1661
1662 if (link->open)
1663 dev_warn(&link->dev, "Device still open\n");
1664 //netif_device_detach(dev);
1665
1666 return 0;
1667 }
1668
ni_gpib_resume(struct pcmcia_device * link)1669 static int ni_gpib_resume(struct pcmcia_device *link)
1670 {
1671 //struct local_info_t *info = link->priv;
1672 //struct struct gpib_board *dev = info->dev;
1673
1674 /*if (link->open) {
1675 * ni_gpib_probe(dev); / really?
1676 * //netif_device_attach(dev);
1677 *}
1678 */
1679 return ni_gpib_config(link);
1680 }
1681
1682 static struct pcmcia_device_id ni_pcmcia_ids[] = {
1683 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x4882),
1684 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0c71), // NI PCMCIA-GPIB+
1685 PCMCIA_DEVICE_NULL
1686 };
1687
1688 MODULE_DEVICE_TABLE(pcmcia, ni_pcmcia_ids);
1689
1690 static struct pcmcia_driver ni_gpib_cs_driver = {
1691 .name = "ni_gpib_cs",
1692 .owner = THIS_MODULE,
1693 .drv = { .name = "ni_gpib_cs", },
1694 .id_table = ni_pcmcia_ids,
1695 .probe = ni_gpib_probe,
1696 .remove = ni_gpib_remove,
1697 .suspend = ni_gpib_suspend,
1698 .resume = ni_gpib_resume,
1699 };
1700
init_ni_gpib_cs(void)1701 static int __init init_ni_gpib_cs(void)
1702 {
1703 return pcmcia_register_driver(&ni_gpib_cs_driver);
1704 }
1705
exit_ni_gpib_cs(void)1706 static void __exit exit_ni_gpib_cs(void)
1707 {
1708 pcmcia_unregister_driver(&ni_gpib_cs_driver);
1709 }
1710
1711 static const int pcmcia_gpib_iosize = 32;
1712
ni_pcmcia_attach(struct gpib_board * board,const struct gpib_board_config * config)1713 static int ni_pcmcia_attach(struct gpib_board *board, const struct gpib_board_config *config)
1714 {
1715 struct local_info_t *info;
1716 struct tnt4882_priv *tnt_priv;
1717 struct nec7210_priv *nec_priv;
1718 int isr_flags = IRQF_SHARED;
1719 int retval;
1720
1721 if (!curr_dev)
1722 return -ENODEV;
1723
1724 info = curr_dev->priv;
1725 info->dev = board;
1726
1727 board->status = 0;
1728
1729 retval = tnt4882_allocate_private(board);
1730 if (retval)
1731 return retval;
1732
1733 tnt_priv = board->private_data;
1734 nec_priv = &tnt_priv->nec7210_priv;
1735 nec_priv->type = TNT4882;
1736 nec_priv->read_byte = nec7210_locking_ioport_read_byte;
1737 nec_priv->write_byte = nec7210_locking_ioport_write_byte;
1738 nec_priv->offset = atgpib_reg_offset;
1739
1740 if (!request_region(curr_dev->resource[0]->start, resource_size(curr_dev->resource[0]),
1741 DRV_NAME))
1742 return -ENOMEM;
1743
1744 nec_priv->mmiobase = ioport_map(curr_dev->resource[0]->start,
1745 resource_size(curr_dev->resource[0]));
1746 if (!nec_priv->mmiobase)
1747 return -ENOMEM;
1748
1749 // get irq
1750 retval = request_irq(curr_dev->irq, tnt4882_interrupt, isr_flags, DRV_NAME, board);
1751 if (retval) {
1752 dev_err(board->gpib_dev, "failed to obtain PCMCIA irq %d\n", curr_dev->irq);
1753 return retval;
1754 }
1755 tnt_priv->irq = curr_dev->irq;
1756
1757 tnt4882_init(tnt_priv, board);
1758
1759 return 0;
1760 }
1761
ni_pcmcia_detach(struct gpib_board * board)1762 static void ni_pcmcia_detach(struct gpib_board *board)
1763 {
1764 struct tnt4882_priv *tnt_priv = board->private_data;
1765 struct nec7210_priv *nec_priv;
1766
1767 if (tnt_priv) {
1768 nec_priv = &tnt_priv->nec7210_priv;
1769 if (tnt_priv->irq)
1770 free_irq(tnt_priv->irq, board);
1771 if (nec_priv->mmiobase)
1772 ioport_unmap(nec_priv->mmiobase);
1773 if (nec_priv->iobase) {
1774 tnt4882_board_reset(tnt_priv, board);
1775 release_region(nec_priv->iobase, pcmcia_gpib_iosize);
1776 }
1777 }
1778 tnt4882_free_private(board);
1779 }
1780
1781 static struct gpib_interface ni_pcmcia_interface = {
1782 .name = "ni_pcmcia",
1783 .attach = ni_pcmcia_attach,
1784 .detach = ni_pcmcia_detach,
1785 .read = tnt4882_accel_read,
1786 .write = tnt4882_accel_write,
1787 .command = tnt4882_command,
1788 .take_control = tnt4882_take_control,
1789 .go_to_standby = tnt4882_go_to_standby,
1790 .request_system_control = tnt4882_request_system_control,
1791 .interface_clear = tnt4882_interface_clear,
1792 .remote_enable = tnt4882_remote_enable,
1793 .enable_eos = tnt4882_enable_eos,
1794 .disable_eos = tnt4882_disable_eos,
1795 .parallel_poll = tnt4882_parallel_poll,
1796 .parallel_poll_configure = tnt4882_parallel_poll_configure,
1797 .parallel_poll_response = tnt4882_parallel_poll_response,
1798 .local_parallel_poll_mode = NULL, // XXX
1799 .line_status = tnt4882_line_status,
1800 .update_status = tnt4882_update_status,
1801 .primary_address = tnt4882_primary_address,
1802 .secondary_address = tnt4882_secondary_address,
1803 .serial_poll_response = tnt4882_serial_poll_response,
1804 .serial_poll_status = tnt4882_serial_poll_status,
1805 .t1_delay = tnt4882_t1_delay,
1806 .return_to_local = tnt4882_return_to_local,
1807 };
1808
1809 static struct gpib_interface ni_pcmcia_accel_interface = {
1810 .name = "ni_pcmcia_accel",
1811 .attach = ni_pcmcia_attach,
1812 .detach = ni_pcmcia_detach,
1813 .read = tnt4882_accel_read,
1814 .write = tnt4882_accel_write,
1815 .command = tnt4882_command,
1816 .take_control = tnt4882_take_control,
1817 .go_to_standby = tnt4882_go_to_standby,
1818 .request_system_control = tnt4882_request_system_control,
1819 .interface_clear = tnt4882_interface_clear,
1820 .remote_enable = tnt4882_remote_enable,
1821 .enable_eos = tnt4882_enable_eos,
1822 .disable_eos = tnt4882_disable_eos,
1823 .parallel_poll = tnt4882_parallel_poll,
1824 .parallel_poll_configure = tnt4882_parallel_poll_configure,
1825 .parallel_poll_response = tnt4882_parallel_poll_response,
1826 .local_parallel_poll_mode = NULL, // XXX
1827 .line_status = tnt4882_line_status,
1828 .update_status = tnt4882_update_status,
1829 .primary_address = tnt4882_primary_address,
1830 .secondary_address = tnt4882_secondary_address,
1831 .serial_poll_response = tnt4882_serial_poll_response,
1832 .serial_poll_status = tnt4882_serial_poll_status,
1833 .t1_delay = tnt4882_t1_delay,
1834 .return_to_local = tnt4882_return_to_local,
1835 };
1836
1837 #endif // CONFIG_GPIB_PCMCIA
1838
1839 module_init(tnt4882_init_module);
1840 module_exit(tnt4882_exit_module);
1841