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