xref: /linux/drivers/staging/gpib/pc2/pc2_gpib.c (revision a100922a3855eb35ecd465f1d558546b1e144445)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 /***************************************************************************
4  *    copyright            : (C) 2001, 2002 by Frank Mori Hess
5  ***************************************************************************/
6 
7 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #define dev_fmt pr_fmt
9 
10 #include <linux/ioport.h>
11 #include <linux/sched.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/bitops.h>
15 #include <asm/dma.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/string.h>
18 #include <linux/init.h>
19 #include "nec7210.h"
20 #include "gpibP.h"
21 
22 // struct which defines private_data for pc2 driver
23 struct pc2_priv {
24 	struct nec7210_priv nec7210_priv;
25 	unsigned int irq;
26 	// io address that clears interrupt for pc2a (0x2f0 + irq)
27 	unsigned int clear_intr_addr;
28 };
29 
30 // pc2 uses 8 consecutive io addresses
31 static const int pc2_iosize = 8;
32 static const int pc2a_iosize = 8;
33 static const int pc2_2a_iosize = 16;
34 
35 // offset between io addresses of successive nec7210 registers
36 static const int pc2a_reg_offset = 0x400;
37 static const int pc2_reg_offset = 1;
38 
39 //interrupt service routine
40 static irqreturn_t pc2_interrupt(int irq, void *arg);
41 static irqreturn_t pc2a_interrupt(int irq, void *arg);
42 
43 // pc2 specific registers and bits
44 
45 // interrupt clear register address
46 static const int pc2a_clear_intr_iobase = 0x2f0;
CLEAR_INTR_REG(unsigned int irq)47 static inline unsigned int CLEAR_INTR_REG(unsigned int irq)
48 {
49 	return pc2a_clear_intr_iobase + irq;
50 }
51 
52 MODULE_LICENSE("GPL");
53 MODULE_DESCRIPTION("GPIB driver for PC2/PC2a and compatible devices");
54 
55 /*
56  * GPIB interrupt service routines
57  */
58 
pc2_interrupt(int irq,void * arg)59 irqreturn_t pc2_interrupt(int irq, void *arg)
60 {
61 	struct gpib_board *board = arg;
62 	struct pc2_priv *priv = board->private_data;
63 	unsigned long flags;
64 	irqreturn_t retval;
65 
66 	spin_lock_irqsave(&board->spinlock, flags);
67 	retval = nec7210_interrupt(board, &priv->nec7210_priv);
68 	spin_unlock_irqrestore(&board->spinlock, flags);
69 	return retval;
70 }
71 
pc2a_interrupt(int irq,void * arg)72 irqreturn_t pc2a_interrupt(int irq, void *arg)
73 {
74 	struct gpib_board *board = arg;
75 	struct pc2_priv *priv = board->private_data;
76 	int status1, status2;
77 	unsigned long flags;
78 	irqreturn_t retval;
79 
80 	spin_lock_irqsave(&board->spinlock, flags);
81 	// read interrupt status (also clears status)
82 	status1 = read_byte(&priv->nec7210_priv, ISR1);
83 	status2 = read_byte(&priv->nec7210_priv, ISR2);
84 	/* clear interrupt circuit */
85 	if (priv->irq)
86 		outb(0xff, CLEAR_INTR_REG(priv->irq));
87 	retval = nec7210_interrupt_have_status(board, &priv->nec7210_priv, status1, status2);
88 	spin_unlock_irqrestore(&board->spinlock, flags);
89 	return retval;
90 }
91 
92 // wrappers for interface functions
pc2_read(struct gpib_board * board,u8 * buffer,size_t length,int * end,size_t * bytes_read)93 static int pc2_read(struct gpib_board *board, u8 *buffer, size_t length, int *end,
94 		    size_t *bytes_read)
95 {
96 	struct pc2_priv *priv = board->private_data;
97 
98 	return nec7210_read(board, &priv->nec7210_priv, buffer, length, end, bytes_read);
99 }
100 
pc2_write(struct gpib_board * board,u8 * buffer,size_t length,int send_eoi,size_t * bytes_written)101 static int pc2_write(struct gpib_board *board, u8 *buffer, size_t length, int send_eoi,
102 		     size_t *bytes_written)
103 {
104 	struct pc2_priv *priv = board->private_data;
105 
106 	return nec7210_write(board, &priv->nec7210_priv, buffer, length, send_eoi, bytes_written);
107 }
108 
pc2_command(struct gpib_board * board,u8 * buffer,size_t length,size_t * bytes_written)109 static int pc2_command(struct gpib_board *board, u8 *buffer,
110 		       size_t length, size_t *bytes_written)
111 {
112 	struct pc2_priv *priv = board->private_data;
113 
114 	return nec7210_command(board, &priv->nec7210_priv, buffer, length, bytes_written);
115 }
116 
pc2_take_control(struct gpib_board * board,int synchronous)117 static int pc2_take_control(struct gpib_board *board, int synchronous)
118 {
119 	struct pc2_priv *priv = board->private_data;
120 
121 	return nec7210_take_control(board, &priv->nec7210_priv, synchronous);
122 }
123 
pc2_go_to_standby(struct gpib_board * board)124 static int pc2_go_to_standby(struct gpib_board *board)
125 {
126 	struct pc2_priv *priv = board->private_data;
127 
128 	return nec7210_go_to_standby(board, &priv->nec7210_priv);
129 }
130 
pc2_request_system_control(struct gpib_board * board,int request_control)131 static int pc2_request_system_control(struct gpib_board *board, int request_control)
132 {
133 	struct pc2_priv *priv = board->private_data;
134 
135 	return nec7210_request_system_control(board, &priv->nec7210_priv, request_control);
136 }
137 
pc2_interface_clear(struct gpib_board * board,int assert)138 static void pc2_interface_clear(struct gpib_board *board, int assert)
139 {
140 	struct pc2_priv *priv = board->private_data;
141 
142 	nec7210_interface_clear(board, &priv->nec7210_priv, assert);
143 }
144 
pc2_remote_enable(struct gpib_board * board,int enable)145 static void pc2_remote_enable(struct gpib_board *board, int enable)
146 {
147 	struct pc2_priv *priv = board->private_data;
148 
149 	nec7210_remote_enable(board, &priv->nec7210_priv, enable);
150 }
151 
pc2_enable_eos(struct gpib_board * board,u8 eos_byte,int compare_8_bits)152 static int pc2_enable_eos(struct gpib_board *board, u8 eos_byte, int compare_8_bits)
153 {
154 	struct pc2_priv *priv = board->private_data;
155 
156 	return nec7210_enable_eos(board, &priv->nec7210_priv, eos_byte, compare_8_bits);
157 }
158 
pc2_disable_eos(struct gpib_board * board)159 static void pc2_disable_eos(struct gpib_board *board)
160 {
161 	struct pc2_priv *priv = board->private_data;
162 
163 	nec7210_disable_eos(board, &priv->nec7210_priv);
164 }
165 
pc2_update_status(struct gpib_board * board,unsigned int clear_mask)166 static unsigned int pc2_update_status(struct gpib_board *board, unsigned int clear_mask)
167 {
168 	struct pc2_priv *priv = board->private_data;
169 
170 	return nec7210_update_status(board, &priv->nec7210_priv, clear_mask);
171 }
172 
pc2_primary_address(struct gpib_board * board,unsigned int address)173 static int pc2_primary_address(struct gpib_board *board, unsigned int address)
174 {
175 	struct pc2_priv *priv = board->private_data;
176 
177 	return nec7210_primary_address(board, &priv->nec7210_priv, address);
178 }
179 
pc2_secondary_address(struct gpib_board * board,unsigned int address,int enable)180 static int pc2_secondary_address(struct gpib_board *board, unsigned int address, int enable)
181 {
182 	struct pc2_priv *priv = board->private_data;
183 
184 	return nec7210_secondary_address(board, &priv->nec7210_priv, address, enable);
185 }
186 
pc2_parallel_poll(struct gpib_board * board,u8 * result)187 static int pc2_parallel_poll(struct gpib_board *board, u8 *result)
188 {
189 	struct pc2_priv *priv = board->private_data;
190 
191 	return nec7210_parallel_poll(board, &priv->nec7210_priv, result);
192 }
193 
pc2_parallel_poll_configure(struct gpib_board * board,u8 config)194 static void pc2_parallel_poll_configure(struct gpib_board *board, u8 config)
195 {
196 	struct pc2_priv *priv = board->private_data;
197 
198 	nec7210_parallel_poll_configure(board, &priv->nec7210_priv, config);
199 }
200 
pc2_parallel_poll_response(struct gpib_board * board,int ist)201 static void pc2_parallel_poll_response(struct gpib_board *board, int ist)
202 {
203 	struct pc2_priv *priv = board->private_data;
204 
205 	nec7210_parallel_poll_response(board, &priv->nec7210_priv, ist);
206 }
207 
pc2_serial_poll_response(struct gpib_board * board,u8 status)208 static void pc2_serial_poll_response(struct gpib_board *board, u8 status)
209 {
210 	struct pc2_priv *priv = board->private_data;
211 
212 	nec7210_serial_poll_response(board, &priv->nec7210_priv, status);
213 }
214 
pc2_serial_poll_status(struct gpib_board * board)215 static u8 pc2_serial_poll_status(struct gpib_board *board)
216 {
217 	struct pc2_priv *priv = board->private_data;
218 
219 	return nec7210_serial_poll_status(board, &priv->nec7210_priv);
220 }
221 
pc2_t1_delay(struct gpib_board * board,unsigned int nano_sec)222 static int pc2_t1_delay(struct gpib_board *board, unsigned int nano_sec)
223 {
224 	struct pc2_priv *priv = board->private_data;
225 
226 	return nec7210_t1_delay(board, &priv->nec7210_priv, nano_sec);
227 }
228 
pc2_return_to_local(struct gpib_board * board)229 static void pc2_return_to_local(struct gpib_board *board)
230 {
231 	struct pc2_priv *priv = board->private_data;
232 
233 	nec7210_return_to_local(board, &priv->nec7210_priv);
234 }
235 
allocate_private(struct gpib_board * board)236 static int allocate_private(struct gpib_board *board)
237 {
238 	struct pc2_priv *priv;
239 
240 	board->private_data = kmalloc(sizeof(struct pc2_priv), GFP_KERNEL);
241 	if (!board->private_data)
242 		return -1;
243 	priv = board->private_data;
244 	memset(priv, 0, sizeof(struct pc2_priv));
245 	init_nec7210_private(&priv->nec7210_priv);
246 	return 0;
247 }
248 
free_private(struct gpib_board * board)249 static void free_private(struct gpib_board *board)
250 {
251 	kfree(board->private_data);
252 	board->private_data = NULL;
253 }
254 
pc2_generic_attach(struct gpib_board * board,const struct gpib_board_config * config,enum nec7210_chipset chipset)255 static int pc2_generic_attach(struct gpib_board *board, const struct gpib_board_config *config,
256 			      enum nec7210_chipset chipset)
257 {
258 	struct pc2_priv *pc2_priv;
259 	struct nec7210_priv *nec_priv;
260 
261 	board->status = 0;
262 	if (allocate_private(board))
263 		return -ENOMEM;
264 	pc2_priv = board->private_data;
265 	nec_priv = &pc2_priv->nec7210_priv;
266 	nec_priv->read_byte = nec7210_ioport_read_byte;
267 	nec_priv->write_byte = nec7210_ioport_write_byte;
268 	nec_priv->type = chipset;
269 
270 #ifndef PC2_DMA
271 	/*
272 	 * board->dev hasn't been initialized, so forget about DMA until this driver
273 	 * is adapted to use isa_register_driver.
274 	 */
275 	if (config->ibdma)
276 	// driver needs to be adapted to use isa_register_driver to get a struct device*
277 		dev_err(board->gpib_dev, "DMA disabled for pc2 gpib");
278 #else
279 	if (config->ibdma) {
280 		nec_priv->dma_buffer_length = 0x1000;
281 		nec_priv->dma_buffer = dma_alloc_coherent(board->dev,
282 							  nec_priv->dma_buffer_length, &
283 							  nec_priv->dma_buffer_addr, GFP_ATOMIC);
284 		if (!nec_priv->dma_buffer)
285 			return -ENOMEM;
286 
287 		// request isa dma channel
288 		if (request_dma(config->ibdma, "pc2")) {
289 			dev_err(board->gpib_dev, "can't request DMA %d\n", config->ibdma);
290 			return -1;
291 		}
292 		nec_priv->dma_channel = config->ibdma;
293 	}
294 #endif
295 
296 	return 0;
297 }
298 
pc2_attach(struct gpib_board * board,const struct gpib_board_config * config)299 static int pc2_attach(struct gpib_board *board, const struct gpib_board_config *config)
300 {
301 	int isr_flags = 0;
302 	struct pc2_priv *pc2_priv;
303 	struct nec7210_priv *nec_priv;
304 	int retval;
305 
306 	retval = pc2_generic_attach(board, config, NEC7210);
307 	if (retval)
308 		return retval;
309 
310 	pc2_priv = board->private_data;
311 	nec_priv = &pc2_priv->nec7210_priv;
312 	nec_priv->offset = pc2_reg_offset;
313 
314 	if (!request_region(config->ibbase, pc2_iosize, "pc2")) {
315 		dev_err(board->gpib_dev, "ioports are already in use\n");
316 		return -EBUSY;
317 	}
318 	nec_priv->iobase = config->ibbase;
319 
320 	nec7210_board_reset(nec_priv, board);
321 
322 	// install interrupt handler
323 	if (config->ibirq) {
324 		if (request_irq(config->ibirq, pc2_interrupt, isr_flags, "pc2", board))	{
325 			dev_err(board->gpib_dev, "can't request IRQ %d\n", config->ibirq);
326 			return -EBUSY;
327 		}
328 	}
329 	pc2_priv->irq = config->ibirq;
330 	/* poll so we can detect assertion of ATN */
331 	if (gpib_request_pseudo_irq(board, pc2_interrupt)) {
332 		dev_err(board->gpib_dev, "failed to allocate pseudo_irq\n");
333 		return -1;
334 	}
335 	/* set internal counter register for 8 MHz input clock */
336 	write_byte(nec_priv, ICR | 8, AUXMR);
337 
338 	nec7210_board_online(nec_priv, board);
339 
340 	return 0;
341 }
342 
pc2_detach(struct gpib_board * board)343 static void pc2_detach(struct gpib_board *board)
344 {
345 	struct pc2_priv *pc2_priv = board->private_data;
346 	struct nec7210_priv *nec_priv;
347 
348 	if (pc2_priv) {
349 		nec_priv = &pc2_priv->nec7210_priv;
350 #ifdef PC2_DMA
351 		if (nec_priv->dma_channel)
352 			free_dma(nec_priv->dma_channel);
353 #endif
354 		gpib_free_pseudo_irq(board);
355 		if (pc2_priv->irq)
356 			free_irq(pc2_priv->irq, board);
357 		if (nec_priv->iobase) {
358 			nec7210_board_reset(nec_priv, board);
359 			release_region(nec_priv->iobase, pc2_iosize);
360 		}
361 		if (nec_priv->dma_buffer) {
362 			dma_free_coherent(board->dev, nec_priv->dma_buffer_length,
363 					  nec_priv->dma_buffer, nec_priv->dma_buffer_addr);
364 			nec_priv->dma_buffer = NULL;
365 		}
366 	}
367 	free_private(board);
368 }
369 
pc2a_common_attach(struct gpib_board * board,const struct gpib_board_config * config,unsigned int num_registers,enum nec7210_chipset chipset)370 static int pc2a_common_attach(struct gpib_board *board, const struct gpib_board_config *config,
371 			      unsigned int num_registers, enum nec7210_chipset chipset)
372 {
373 	unsigned int i, j;
374 	struct pc2_priv *pc2_priv;
375 	struct nec7210_priv *nec_priv;
376 	int retval;
377 
378 	retval = pc2_generic_attach(board, config, chipset);
379 	if (retval)
380 		return retval;
381 
382 	pc2_priv = board->private_data;
383 	nec_priv = &pc2_priv->nec7210_priv;
384 	nec_priv->offset = pc2a_reg_offset;
385 
386 	switch (config->ibbase) {
387 	case 0x02e1:
388 	case 0x22e1:
389 	case 0x42e1:
390 	case 0x62e1:
391 		break;
392 	default:
393 		dev_err(board->gpib_dev, "PCIIa base range invalid, must be one of 0x[0246]2e1, but is 0x%x\n",
394 			config->ibbase);
395 		return -1;
396 	}
397 
398 	if (config->ibirq) {
399 		if (config->ibirq < 2 || config->ibirq > 7) {
400 			dev_err(board->gpib_dev, "illegal interrupt level %i\n",
401 				config->ibirq);
402 			return -1;
403 		}
404 	} else	{
405 		dev_err(board->gpib_dev, "interrupt disabled, using polling mode (slow)\n");
406 	}
407 #ifdef CHECK_IOPORTS
408 	unsigned int err = 0;
409 
410 	for (i = 0; i < num_registers; i++) {
411 		if (check_region(config->ibbase + i * pc2a_reg_offset, 1))
412 			err++;
413 	}
414 	if (config->ibirq && check_region(pc2a_clear_intr_iobase + config->ibirq, 1))
415 		err++;
416 	if (err) {
417 		dev_err(board->gpib_dev, "ioports are already in use");
418 		return -EBUSY;
419 	}
420 #endif
421 	for (i = 0; i < num_registers; i++) {
422 		if (!request_region(config->ibbase +
423 					i * pc2a_reg_offset, 1, "pc2a")) {
424 			dev_err(board->gpib_dev, "ioports are already in use");
425 			for (j = 0; j < i; j++)
426 				release_region(config->ibbase +
427 					j * pc2a_reg_offset, 1);
428 			return -EBUSY;
429 		}
430 	}
431 	nec_priv->iobase = config->ibbase;
432 	if (config->ibirq) {
433 		if (!request_region(pc2a_clear_intr_iobase + config->ibirq, 1, "pc2a"))  {
434 			dev_err(board->gpib_dev, "ioports are already in use");
435 			return -1;
436 		}
437 		pc2_priv->clear_intr_addr = pc2a_clear_intr_iobase + config->ibirq;
438 		if (request_irq(config->ibirq, pc2a_interrupt, 0, "pc2a", board)) {
439 			dev_err(board->gpib_dev, "can't request IRQ %d\n", config->ibirq);
440 			return -EBUSY;
441 		}
442 	}
443 	pc2_priv->irq = config->ibirq;
444 	/* poll so we can detect assertion of ATN */
445 	if (gpib_request_pseudo_irq(board, pc2_interrupt)) {
446 		dev_err(board->gpib_dev, "failed to allocate pseudo_irq\n");
447 		return -1;
448 	}
449 
450 	// make sure interrupt is clear
451 	if (pc2_priv->irq)
452 		outb(0xff, CLEAR_INTR_REG(pc2_priv->irq));
453 
454 	nec7210_board_reset(nec_priv, board);
455 
456 	/* set internal counter register for 8 MHz input clock */
457 	write_byte(nec_priv, ICR | 8, AUXMR);
458 
459 	nec7210_board_online(nec_priv, board);
460 
461 	return 0;
462 }
463 
pc2a_attach(struct gpib_board * board,const struct gpib_board_config * config)464 static int pc2a_attach(struct gpib_board *board, const struct gpib_board_config *config)
465 {
466 	return pc2a_common_attach(board, config, pc2a_iosize, NEC7210);
467 }
468 
pc2a_cb7210_attach(struct gpib_board * board,const struct gpib_board_config * config)469 static int pc2a_cb7210_attach(struct gpib_board *board, const struct gpib_board_config *config)
470 {
471 	return pc2a_common_attach(board, config, pc2a_iosize, CB7210);
472 }
473 
pc2_2a_attach(struct gpib_board * board,const struct gpib_board_config * config)474 static int pc2_2a_attach(struct gpib_board *board, const struct gpib_board_config *config)
475 {
476 	return pc2a_common_attach(board, config, pc2_2a_iosize, NAT4882);
477 }
478 
pc2a_common_detach(struct gpib_board * board,unsigned int num_registers)479 static void pc2a_common_detach(struct gpib_board *board, unsigned int num_registers)
480 {
481 	int i;
482 	struct pc2_priv *pc2_priv = board->private_data;
483 	struct nec7210_priv *nec_priv;
484 
485 	if (pc2_priv) {
486 		nec_priv = &pc2_priv->nec7210_priv;
487 #ifdef PC2_DMA
488 		if (nec_priv->dma_channel)
489 			free_dma(nec_priv->dma_channel);
490 #endif
491 		gpib_free_pseudo_irq(board);
492 		if (pc2_priv->irq)
493 			free_irq(pc2_priv->irq, board);
494 		if (nec_priv->iobase) {
495 			nec7210_board_reset(nec_priv, board);
496 			for (i = 0; i < num_registers; i++)
497 				release_region(nec_priv->iobase +
498 					       i * pc2a_reg_offset, 1);
499 		}
500 		if (pc2_priv->clear_intr_addr)
501 			release_region(pc2_priv->clear_intr_addr, 1);
502 		if (nec_priv->dma_buffer) {
503 			dma_free_coherent(board->dev, nec_priv->dma_buffer_length,
504 					  nec_priv->dma_buffer,
505 					  nec_priv->dma_buffer_addr);
506 			nec_priv->dma_buffer = NULL;
507 		}
508 	}
509 	free_private(board);
510 }
511 
pc2a_detach(struct gpib_board * board)512 static void pc2a_detach(struct gpib_board *board)
513 {
514 	pc2a_common_detach(board, pc2a_iosize);
515 }
516 
pc2_2a_detach(struct gpib_board * board)517 static void pc2_2a_detach(struct gpib_board *board)
518 {
519 	pc2a_common_detach(board, pc2_2a_iosize);
520 }
521 
522 static struct gpib_interface pc2_interface = {
523 	.name =	"pcII",
524 	.attach =	pc2_attach,
525 	.detach =	pc2_detach,
526 	.read =	pc2_read,
527 	.write =	pc2_write,
528 	.command =	pc2_command,
529 	.take_control =	pc2_take_control,
530 	.go_to_standby =	pc2_go_to_standby,
531 	.request_system_control =	pc2_request_system_control,
532 	.interface_clear =	pc2_interface_clear,
533 	.remote_enable =	pc2_remote_enable,
534 	.enable_eos =	pc2_enable_eos,
535 	.disable_eos =	pc2_disable_eos,
536 	.parallel_poll =	pc2_parallel_poll,
537 	.parallel_poll_configure =	pc2_parallel_poll_configure,
538 	.parallel_poll_response =	pc2_parallel_poll_response,
539 	.local_parallel_poll_mode = NULL, // XXX
540 	.line_status =	NULL,
541 	.update_status =	pc2_update_status,
542 	.primary_address =	pc2_primary_address,
543 	.secondary_address =	pc2_secondary_address,
544 	.serial_poll_response =	pc2_serial_poll_response,
545 	.serial_poll_status =	pc2_serial_poll_status,
546 	.t1_delay = pc2_t1_delay,
547 	.return_to_local = pc2_return_to_local,
548 };
549 
550 static struct gpib_interface pc2a_interface = {
551 	.name =	"pcIIa",
552 	.attach =	pc2a_attach,
553 	.detach =	pc2a_detach,
554 	.read =	pc2_read,
555 	.write =	pc2_write,
556 	.command =	pc2_command,
557 	.take_control =	pc2_take_control,
558 	.go_to_standby =	pc2_go_to_standby,
559 	.request_system_control =	pc2_request_system_control,
560 	.interface_clear =	pc2_interface_clear,
561 	.remote_enable =	pc2_remote_enable,
562 	.enable_eos =	pc2_enable_eos,
563 	.disable_eos =	pc2_disable_eos,
564 	.parallel_poll =	pc2_parallel_poll,
565 	.parallel_poll_configure =	pc2_parallel_poll_configure,
566 	.parallel_poll_response =	pc2_parallel_poll_response,
567 	.local_parallel_poll_mode = NULL, // XXX
568 	.line_status =	NULL,
569 	.update_status =	pc2_update_status,
570 	.primary_address =	pc2_primary_address,
571 	.secondary_address =	pc2_secondary_address,
572 	.serial_poll_response =	pc2_serial_poll_response,
573 	.serial_poll_status =	pc2_serial_poll_status,
574 	.t1_delay = pc2_t1_delay,
575 	.return_to_local = pc2_return_to_local,
576 };
577 
578 static struct gpib_interface pc2a_cb7210_interface = {
579 	.name =	"pcIIa_cb7210",
580 	.attach =	pc2a_cb7210_attach,
581 	.detach =	pc2a_detach,
582 	.read =	pc2_read,
583 	.write =	pc2_write,
584 	.command =	pc2_command,
585 	.take_control =	pc2_take_control,
586 	.go_to_standby =	pc2_go_to_standby,
587 	.request_system_control =	pc2_request_system_control,
588 	.interface_clear =	pc2_interface_clear,
589 	.remote_enable =	pc2_remote_enable,
590 	.enable_eos =	pc2_enable_eos,
591 	.disable_eos =	pc2_disable_eos,
592 	.parallel_poll =	pc2_parallel_poll,
593 	.parallel_poll_configure =	pc2_parallel_poll_configure,
594 	.parallel_poll_response =	pc2_parallel_poll_response,
595 	.local_parallel_poll_mode = NULL, // XXX
596 	.line_status =	NULL, //XXX
597 	.update_status =	pc2_update_status,
598 	.primary_address =	pc2_primary_address,
599 	.secondary_address =	pc2_secondary_address,
600 	.serial_poll_response =	pc2_serial_poll_response,
601 	.serial_poll_status =	pc2_serial_poll_status,
602 	.t1_delay = pc2_t1_delay,
603 	.return_to_local = pc2_return_to_local,
604 };
605 
606 static struct gpib_interface pc2_2a_interface = {
607 	.name =	"pcII_IIa",
608 	.attach =	pc2_2a_attach,
609 	.detach =	pc2_2a_detach,
610 	.read =	pc2_read,
611 	.write =	pc2_write,
612 	.command =	pc2_command,
613 	.take_control =	pc2_take_control,
614 	.go_to_standby =	pc2_go_to_standby,
615 	.request_system_control =	pc2_request_system_control,
616 	.interface_clear =	pc2_interface_clear,
617 	.remote_enable =	pc2_remote_enable,
618 	.enable_eos =	pc2_enable_eos,
619 	.disable_eos =	pc2_disable_eos,
620 	.parallel_poll =	pc2_parallel_poll,
621 	.parallel_poll_configure =	pc2_parallel_poll_configure,
622 	.parallel_poll_response =	pc2_parallel_poll_response,
623 	.local_parallel_poll_mode = NULL, // XXX
624 	.line_status =	NULL,
625 	.update_status =	pc2_update_status,
626 	.primary_address =	pc2_primary_address,
627 	.secondary_address =	pc2_secondary_address,
628 	.serial_poll_response =	pc2_serial_poll_response,
629 	.serial_poll_status =	pc2_serial_poll_status,
630 	.t1_delay = pc2_t1_delay,
631 	.return_to_local = pc2_return_to_local,
632 };
633 
pc2_init_module(void)634 static int __init pc2_init_module(void)
635 {
636 	int ret;
637 
638 	ret = gpib_register_driver(&pc2_interface, THIS_MODULE);
639 	if (ret) {
640 		pr_err("gpib_register_driver failed: error = %d\n", ret);
641 		return ret;
642 	}
643 
644 	ret = gpib_register_driver(&pc2a_interface, THIS_MODULE);
645 	if (ret) {
646 		pr_err("gpib_register_driver failed: error = %d\n", ret);
647 		goto err_pc2a;
648 	}
649 
650 	ret = gpib_register_driver(&pc2a_cb7210_interface, THIS_MODULE);
651 	if (ret) {
652 		pr_err("gpib_register_driver failed: error = %d\n", ret);
653 		goto err_cb7210;
654 	}
655 
656 	ret = gpib_register_driver(&pc2_2a_interface, THIS_MODULE);
657 	if (ret) {
658 		pr_err("gpib_register_driver failed: error = %d\n", ret);
659 		goto err_pc2_2a;
660 	}
661 
662 	return 0;
663 
664 err_pc2_2a:
665 	gpib_unregister_driver(&pc2a_cb7210_interface);
666 err_cb7210:
667 	gpib_unregister_driver(&pc2a_interface);
668 err_pc2a:
669 	gpib_unregister_driver(&pc2_interface);
670 
671 	return ret;
672 }
673 
pc2_exit_module(void)674 static void __exit pc2_exit_module(void)
675 {
676 	gpib_unregister_driver(&pc2_interface);
677 	gpib_unregister_driver(&pc2a_interface);
678 	gpib_unregister_driver(&pc2a_cb7210_interface);
679 	gpib_unregister_driver(&pc2_2a_interface);
680 }
681 
682 module_init(pc2_init_module);
683 module_exit(pc2_exit_module);
684 
685