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