xref: /linux/drivers/gpib/pc2/pc2_gpib.c (revision 94c37d42cb7ca362aee9633bec2dbeed787edf3e)
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;
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 
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 
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
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
236 static int allocate_private(struct gpib_board *board)
237 {
238 	struct pc2_priv *priv;
239 
240 	board->private_data = kzalloc(sizeof(struct pc2_priv), GFP_KERNEL);
241 	if (!board->private_data)
242 		return -ENOMEM;
243 	priv = board->private_data;
244 	init_nec7210_private(&priv->nec7210_priv);
245 	return 0;
246 }
247 
248 static void free_private(struct gpib_board *board)
249 {
250 	kfree(board->private_data);
251 	board->private_data = NULL;
252 }
253 
254 static int pc2_generic_attach(struct gpib_board *board, const struct gpib_board_config *config,
255 			      enum nec7210_chipset chipset)
256 {
257 	struct pc2_priv *pc2_priv;
258 	struct nec7210_priv *nec_priv;
259 	int retval;
260 
261 	board->status = 0;
262 	retval = allocate_private(board);
263 	if (retval)
264 		return retval;
265 	pc2_priv = board->private_data;
266 	nec_priv = &pc2_priv->nec7210_priv;
267 	nec_priv->read_byte = nec7210_ioport_read_byte;
268 	nec_priv->write_byte = nec7210_ioport_write_byte;
269 	nec_priv->type = chipset;
270 
271 #ifndef PC2_DMA
272 	/*
273 	 * board->dev hasn't been initialized, so forget about DMA until this driver
274 	 * is adapted to use isa_register_driver.
275 	 */
276 	if (config->ibdma)
277 	// driver needs to be adapted to use isa_register_driver to get a struct device*
278 		dev_err(board->gpib_dev, "DMA disabled for pc2 gpib");
279 #else
280 	if (config->ibdma) {
281 		nec_priv->dma_buffer_length = 0x1000;
282 		nec_priv->dma_buffer = dma_alloc_coherent(board->dev,
283 							  nec_priv->dma_buffer_length, &
284 							  nec_priv->dma_buffer_addr, GFP_ATOMIC);
285 		if (!nec_priv->dma_buffer)
286 			return -ENOMEM;
287 
288 		// request isa dma channel
289 		if (request_dma(config->ibdma, "pc2")) {
290 			dev_err(board->gpib_dev, "can't request DMA %d\n", config->ibdma);
291 			return -1;
292 		}
293 		nec_priv->dma_channel = config->ibdma;
294 	}
295 #endif
296 
297 	return 0;
298 }
299 
300 static int pc2_attach(struct gpib_board *board, const struct gpib_board_config *config)
301 {
302 	int isr_flags = 0;
303 	struct pc2_priv *pc2_priv;
304 	struct nec7210_priv *nec_priv;
305 	int retval;
306 
307 	retval = pc2_generic_attach(board, config, NEC7210);
308 	if (retval)
309 		return retval;
310 
311 	pc2_priv = board->private_data;
312 	nec_priv = &pc2_priv->nec7210_priv;
313 	nec_priv->offset = pc2_reg_offset;
314 
315 	if (!request_region(config->ibbase, pc2_iosize, "pc2")) {
316 		dev_err(board->gpib_dev, "ioports are already in use\n");
317 		return -EBUSY;
318 	}
319 	nec_priv->iobase = config->ibbase;
320 
321 	nec7210_board_reset(nec_priv, board);
322 
323 	// install interrupt handler
324 	if (config->ibirq) {
325 		if (request_irq(config->ibirq, pc2_interrupt, isr_flags, "pc2", board))	{
326 			dev_err(board->gpib_dev, "can't request IRQ %d\n", config->ibirq);
327 			return -EBUSY;
328 		}
329 	}
330 	pc2_priv->irq = config->ibirq;
331 	/* poll so we can detect assertion of ATN */
332 	if (gpib_request_pseudo_irq(board, pc2_interrupt)) {
333 		dev_err(board->gpib_dev, "failed to allocate pseudo_irq\n");
334 		return -1;
335 	}
336 	/* set internal counter register for 8 MHz input clock */
337 	write_byte(nec_priv, ICR | 8, AUXMR);
338 
339 	nec7210_board_online(nec_priv, board);
340 
341 	return 0;
342 }
343 
344 static void pc2_detach(struct gpib_board *board)
345 {
346 	struct pc2_priv *pc2_priv = board->private_data;
347 	struct nec7210_priv *nec_priv;
348 
349 	if (pc2_priv) {
350 		nec_priv = &pc2_priv->nec7210_priv;
351 #ifdef PC2_DMA
352 		if (nec_priv->dma_channel)
353 			free_dma(nec_priv->dma_channel);
354 #endif
355 		gpib_free_pseudo_irq(board);
356 		if (pc2_priv->irq)
357 			free_irq(pc2_priv->irq, board);
358 		if (nec_priv->iobase) {
359 			nec7210_board_reset(nec_priv, board);
360 			release_region(nec_priv->iobase, pc2_iosize);
361 		}
362 		if (nec_priv->dma_buffer) {
363 			dma_free_coherent(board->dev, nec_priv->dma_buffer_length,
364 					  nec_priv->dma_buffer, nec_priv->dma_buffer_addr);
365 			nec_priv->dma_buffer = NULL;
366 		}
367 	}
368 	free_private(board);
369 }
370 
371 static int pc2a_common_attach(struct gpib_board *board, const struct gpib_board_config *config,
372 			      unsigned int num_registers, enum nec7210_chipset chipset)
373 {
374 	unsigned int i, j;
375 	struct pc2_priv *pc2_priv;
376 	struct nec7210_priv *nec_priv;
377 	int retval;
378 
379 	retval = pc2_generic_attach(board, config, chipset);
380 	if (retval)
381 		return retval;
382 
383 	pc2_priv = board->private_data;
384 	nec_priv = &pc2_priv->nec7210_priv;
385 	nec_priv->offset = pc2a_reg_offset;
386 
387 	switch (config->ibbase) {
388 	case 0x02e1:
389 	case 0x22e1:
390 	case 0x42e1:
391 	case 0x62e1:
392 		break;
393 	default:
394 		dev_err(board->gpib_dev, "PCIIa base range invalid, must be one of 0x[0246]2e1, but is 0x%x\n",
395 			config->ibbase);
396 		return -1;
397 	}
398 
399 	if (config->ibirq) {
400 		if (config->ibirq < 2 || config->ibirq > 7) {
401 			dev_err(board->gpib_dev, "illegal interrupt level %i\n",
402 				config->ibirq);
403 			return -1;
404 		}
405 	} else	{
406 		dev_err(board->gpib_dev, "interrupt disabled, using polling mode (slow)\n");
407 	}
408 #ifdef CHECK_IOPORTS
409 	unsigned int err = 0;
410 
411 	for (i = 0; i < num_registers; i++) {
412 		if (check_region(config->ibbase + i * pc2a_reg_offset, 1))
413 			err++;
414 	}
415 	if (config->ibirq && check_region(pc2a_clear_intr_iobase + config->ibirq, 1))
416 		err++;
417 	if (err) {
418 		dev_err(board->gpib_dev, "ioports are already in use");
419 		return -EBUSY;
420 	}
421 #endif
422 	for (i = 0; i < num_registers; i++) {
423 		if (!request_region(config->ibbase +
424 					i * pc2a_reg_offset, 1, "pc2a")) {
425 			dev_err(board->gpib_dev, "ioports are already in use");
426 			for (j = 0; j < i; j++)
427 				release_region(config->ibbase +
428 					j * pc2a_reg_offset, 1);
429 			return -EBUSY;
430 		}
431 	}
432 	nec_priv->iobase = config->ibbase;
433 	if (config->ibirq) {
434 		if (!request_region(pc2a_clear_intr_iobase + config->ibirq, 1, "pc2a"))  {
435 			dev_err(board->gpib_dev, "ioports are already in use");
436 			return -1;
437 		}
438 		pc2_priv->clear_intr_addr = pc2a_clear_intr_iobase + config->ibirq;
439 		if (request_irq(config->ibirq, pc2a_interrupt, 0, "pc2a", board)) {
440 			dev_err(board->gpib_dev, "can't request IRQ %d\n", config->ibirq);
441 			return -EBUSY;
442 		}
443 	}
444 	pc2_priv->irq = config->ibirq;
445 	/* poll so we can detect assertion of ATN */
446 	if (gpib_request_pseudo_irq(board, pc2_interrupt)) {
447 		dev_err(board->gpib_dev, "failed to allocate pseudo_irq\n");
448 		return -1;
449 	}
450 
451 	// make sure interrupt is clear
452 	if (pc2_priv->irq)
453 		outb(0xff, CLEAR_INTR_REG(pc2_priv->irq));
454 
455 	nec7210_board_reset(nec_priv, board);
456 
457 	/* set internal counter register for 8 MHz input clock */
458 	write_byte(nec_priv, ICR | 8, AUXMR);
459 
460 	nec7210_board_online(nec_priv, board);
461 
462 	return 0;
463 }
464 
465 static int pc2a_attach(struct gpib_board *board, const struct gpib_board_config *config)
466 {
467 	return pc2a_common_attach(board, config, pc2a_iosize, NEC7210);
468 }
469 
470 static int pc2a_cb7210_attach(struct gpib_board *board, const struct gpib_board_config *config)
471 {
472 	return pc2a_common_attach(board, config, pc2a_iosize, CB7210);
473 }
474 
475 static int pc2_2a_attach(struct gpib_board *board, const struct gpib_board_config *config)
476 {
477 	return pc2a_common_attach(board, config, pc2_2a_iosize, NAT4882);
478 }
479 
480 static void pc2a_common_detach(struct gpib_board *board, unsigned int num_registers)
481 {
482 	int i;
483 	struct pc2_priv *pc2_priv = board->private_data;
484 	struct nec7210_priv *nec_priv;
485 
486 	if (pc2_priv) {
487 		nec_priv = &pc2_priv->nec7210_priv;
488 #ifdef PC2_DMA
489 		if (nec_priv->dma_channel)
490 			free_dma(nec_priv->dma_channel);
491 #endif
492 		gpib_free_pseudo_irq(board);
493 		if (pc2_priv->irq)
494 			free_irq(pc2_priv->irq, board);
495 		if (nec_priv->iobase) {
496 			nec7210_board_reset(nec_priv, board);
497 			for (i = 0; i < num_registers; i++)
498 				release_region(nec_priv->iobase +
499 					       i * pc2a_reg_offset, 1);
500 		}
501 		if (pc2_priv->clear_intr_addr)
502 			release_region(pc2_priv->clear_intr_addr, 1);
503 		if (nec_priv->dma_buffer) {
504 			dma_free_coherent(board->dev, nec_priv->dma_buffer_length,
505 					  nec_priv->dma_buffer,
506 					  nec_priv->dma_buffer_addr);
507 			nec_priv->dma_buffer = NULL;
508 		}
509 	}
510 	free_private(board);
511 }
512 
513 static void pc2a_detach(struct gpib_board *board)
514 {
515 	pc2a_common_detach(board, pc2a_iosize);
516 }
517 
518 static void pc2_2a_detach(struct gpib_board *board)
519 {
520 	pc2a_common_detach(board, pc2_2a_iosize);
521 }
522 
523 static struct gpib_interface pc2_interface = {
524 	.name =	"pcII",
525 	.attach =	pc2_attach,
526 	.detach =	pc2_detach,
527 	.read =	pc2_read,
528 	.write =	pc2_write,
529 	.command =	pc2_command,
530 	.take_control =	pc2_take_control,
531 	.go_to_standby =	pc2_go_to_standby,
532 	.request_system_control =	pc2_request_system_control,
533 	.interface_clear =	pc2_interface_clear,
534 	.remote_enable =	pc2_remote_enable,
535 	.enable_eos =	pc2_enable_eos,
536 	.disable_eos =	pc2_disable_eos,
537 	.parallel_poll =	pc2_parallel_poll,
538 	.parallel_poll_configure =	pc2_parallel_poll_configure,
539 	.parallel_poll_response =	pc2_parallel_poll_response,
540 	.local_parallel_poll_mode = NULL, // XXX
541 	.line_status =	NULL,
542 	.update_status =	pc2_update_status,
543 	.primary_address =	pc2_primary_address,
544 	.secondary_address =	pc2_secondary_address,
545 	.serial_poll_response =	pc2_serial_poll_response,
546 	.serial_poll_status =	pc2_serial_poll_status,
547 	.t1_delay = pc2_t1_delay,
548 	.return_to_local = pc2_return_to_local,
549 };
550 
551 static struct gpib_interface pc2a_interface = {
552 	.name =	"pcIIa",
553 	.attach =	pc2a_attach,
554 	.detach =	pc2a_detach,
555 	.read =	pc2_read,
556 	.write =	pc2_write,
557 	.command =	pc2_command,
558 	.take_control =	pc2_take_control,
559 	.go_to_standby =	pc2_go_to_standby,
560 	.request_system_control =	pc2_request_system_control,
561 	.interface_clear =	pc2_interface_clear,
562 	.remote_enable =	pc2_remote_enable,
563 	.enable_eos =	pc2_enable_eos,
564 	.disable_eos =	pc2_disable_eos,
565 	.parallel_poll =	pc2_parallel_poll,
566 	.parallel_poll_configure =	pc2_parallel_poll_configure,
567 	.parallel_poll_response =	pc2_parallel_poll_response,
568 	.local_parallel_poll_mode = NULL, // XXX
569 	.line_status =	NULL,
570 	.update_status =	pc2_update_status,
571 	.primary_address =	pc2_primary_address,
572 	.secondary_address =	pc2_secondary_address,
573 	.serial_poll_response =	pc2_serial_poll_response,
574 	.serial_poll_status =	pc2_serial_poll_status,
575 	.t1_delay = pc2_t1_delay,
576 	.return_to_local = pc2_return_to_local,
577 };
578 
579 static struct gpib_interface pc2a_cb7210_interface = {
580 	.name =	"pcIIa_cb7210",
581 	.attach =	pc2a_cb7210_attach,
582 	.detach =	pc2a_detach,
583 	.read =	pc2_read,
584 	.write =	pc2_write,
585 	.command =	pc2_command,
586 	.take_control =	pc2_take_control,
587 	.go_to_standby =	pc2_go_to_standby,
588 	.request_system_control =	pc2_request_system_control,
589 	.interface_clear =	pc2_interface_clear,
590 	.remote_enable =	pc2_remote_enable,
591 	.enable_eos =	pc2_enable_eos,
592 	.disable_eos =	pc2_disable_eos,
593 	.parallel_poll =	pc2_parallel_poll,
594 	.parallel_poll_configure =	pc2_parallel_poll_configure,
595 	.parallel_poll_response =	pc2_parallel_poll_response,
596 	.local_parallel_poll_mode = NULL, // XXX
597 	.line_status =	NULL, // XXX
598 	.update_status =	pc2_update_status,
599 	.primary_address =	pc2_primary_address,
600 	.secondary_address =	pc2_secondary_address,
601 	.serial_poll_response =	pc2_serial_poll_response,
602 	.serial_poll_status =	pc2_serial_poll_status,
603 	.t1_delay = pc2_t1_delay,
604 	.return_to_local = pc2_return_to_local,
605 };
606 
607 static struct gpib_interface pc2_2a_interface = {
608 	.name =	"pcII_IIa",
609 	.attach =	pc2_2a_attach,
610 	.detach =	pc2_2a_detach,
611 	.read =	pc2_read,
612 	.write =	pc2_write,
613 	.command =	pc2_command,
614 	.take_control =	pc2_take_control,
615 	.go_to_standby =	pc2_go_to_standby,
616 	.request_system_control =	pc2_request_system_control,
617 	.interface_clear =	pc2_interface_clear,
618 	.remote_enable =	pc2_remote_enable,
619 	.enable_eos =	pc2_enable_eos,
620 	.disable_eos =	pc2_disable_eos,
621 	.parallel_poll =	pc2_parallel_poll,
622 	.parallel_poll_configure =	pc2_parallel_poll_configure,
623 	.parallel_poll_response =	pc2_parallel_poll_response,
624 	.local_parallel_poll_mode = NULL, // XXX
625 	.line_status =	NULL,
626 	.update_status =	pc2_update_status,
627 	.primary_address =	pc2_primary_address,
628 	.secondary_address =	pc2_secondary_address,
629 	.serial_poll_response =	pc2_serial_poll_response,
630 	.serial_poll_status =	pc2_serial_poll_status,
631 	.t1_delay = pc2_t1_delay,
632 	.return_to_local = pc2_return_to_local,
633 };
634 
635 static int __init pc2_init_module(void)
636 {
637 	int ret;
638 
639 	ret = gpib_register_driver(&pc2_interface, THIS_MODULE);
640 	if (ret) {
641 		pr_err("gpib_register_driver failed: error = %d\n", ret);
642 		return ret;
643 	}
644 
645 	ret = gpib_register_driver(&pc2a_interface, THIS_MODULE);
646 	if (ret) {
647 		pr_err("gpib_register_driver failed: error = %d\n", ret);
648 		goto err_pc2a;
649 	}
650 
651 	ret = gpib_register_driver(&pc2a_cb7210_interface, THIS_MODULE);
652 	if (ret) {
653 		pr_err("gpib_register_driver failed: error = %d\n", ret);
654 		goto err_cb7210;
655 	}
656 
657 	ret = gpib_register_driver(&pc2_2a_interface, THIS_MODULE);
658 	if (ret) {
659 		pr_err("gpib_register_driver failed: error = %d\n", ret);
660 		goto err_pc2_2a;
661 	}
662 
663 	return 0;
664 
665 err_pc2_2a:
666 	gpib_unregister_driver(&pc2a_cb7210_interface);
667 err_cb7210:
668 	gpib_unregister_driver(&pc2a_interface);
669 err_pc2a:
670 	gpib_unregister_driver(&pc2_interface);
671 
672 	return ret;
673 }
674 
675 static void __exit pc2_exit_module(void)
676 {
677 	gpib_unregister_driver(&pc2_interface);
678 	gpib_unregister_driver(&pc2a_interface);
679 	gpib_unregister_driver(&pc2a_cb7210_interface);
680 	gpib_unregister_driver(&pc2_2a_interface);
681 }
682 
683 module_init(pc2_init_module);
684 module_exit(pc2_exit_module);
685 
686