1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
// SPDX-License-Identifier: GPL-2.0

/***************************************************************************
 *    copyright            : (C) 2001, 2002 by Frank Mori Hess
 ***************************************************************************/

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#define dev_fmt pr_fmt

#include <linux/ioport.h>
#include <linux/sched.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/bitops.h>
#include <asm/dma.h>
#include <linux/dma-mapping.h>
#include <linux/string.h>
#include <linux/init.h>
#include "nec7210.h"
#include "gpibP.h"

// struct which defines private_data for pc2 driver
struct pc2_priv {
	struct nec7210_priv nec7210_priv;
	unsigned int irq;
	// io address that clears interrupt for pc2a (0x2f0 + irq)
	unsigned int clear_intr_addr;
};

// pc2 uses 8 consecutive io addresses
static const int pc2_iosize = 8;
static const int pc2a_iosize = 8;
static const int pc2_2a_iosize = 16;

// offset between io addresses of successive nec7210 registers
static const int pc2a_reg_offset = 0x400;
static const int pc2_reg_offset = 1;

//interrupt service routine
static irqreturn_t pc2_interrupt(int irq, void *arg);
static irqreturn_t pc2a_interrupt(int irq, void *arg);

// pc2 specific registers and bits

// interrupt clear register address
static const int pc2a_clear_intr_iobase = 0x2f0;
static inline unsigned int CLEAR_INTR_REG(unsigned int irq)
{
	return pc2a_clear_intr_iobase + irq;
}

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("GPIB driver for PC2/PC2a and compatible devices");

/*
 * GPIB interrupt service routines
 */

irqreturn_t pc2_interrupt(int irq, void *arg)
{
	struct gpib_board *board = arg;
	struct pc2_priv *priv = board->private_data;
	unsigned long flags;
	irqreturn_t retval;

	spin_lock_irqsave(&board->spinlock, flags);
	retval = nec7210_interrupt(board, &priv->nec7210_priv);
	spin_unlock_irqrestore(&board->spinlock, flags);
	return retval;
}

irqreturn_t pc2a_interrupt(int irq, void *arg)
{
	struct gpib_board *board = arg;
	struct pc2_priv *priv = board->private_data;
	int status1, status2;
	unsigned long flags;
	irqreturn_t retval;

	spin_lock_irqsave(&board->spinlock, flags);
	// read interrupt status (also clears status)
	status1 = read_byte(&priv->nec7210_priv, ISR1);
	status2 = read_byte(&priv->nec7210_priv, ISR2);
	/* clear interrupt circuit */
	if (priv->irq)
		outb(0xff, CLEAR_INTR_REG(priv->irq));
	retval = nec7210_interrupt_have_status(board, &priv->nec7210_priv, status1, status2);
	spin_unlock_irqrestore(&board->spinlock, flags);
	return retval;
}

// wrappers for interface functions
static int pc2_read(struct gpib_board *board, uint8_t *buffer, size_t length, int *end,
		    size_t *bytes_read)
{
	struct pc2_priv *priv = board->private_data;

	return nec7210_read(board, &priv->nec7210_priv, buffer, length, end, bytes_read);
}

static int pc2_write(struct gpib_board *board, uint8_t *buffer, size_t length, int send_eoi,
		     size_t *bytes_written)
{
	struct pc2_priv *priv = board->private_data;

	return nec7210_write(board, &priv->nec7210_priv, buffer, length, send_eoi, bytes_written);
}

static int pc2_command(struct gpib_board *board, uint8_t *buffer, size_t length, size_t *bytes_written)
{
	struct pc2_priv *priv = board->private_data;

	return nec7210_command(board, &priv->nec7210_priv, buffer, length, bytes_written);
}

static int pc2_take_control(struct gpib_board *board, int synchronous)
{
	struct pc2_priv *priv = board->private_data;

	return nec7210_take_control(board, &priv->nec7210_priv, synchronous);
}

static int pc2_go_to_standby(struct gpib_board *board)
{
	struct pc2_priv *priv = board->private_data;

	return nec7210_go_to_standby(board, &priv->nec7210_priv);
}

static void pc2_request_system_control(struct gpib_board *board, int request_control)
{
	struct pc2_priv *priv = board->private_data;

	nec7210_request_system_control(board, &priv->nec7210_priv, request_control);
}

static void pc2_interface_clear(struct gpib_board *board, int assert)
{
	struct pc2_priv *priv = board->private_data;

	nec7210_interface_clear(board, &priv->nec7210_priv, assert);
}

static void pc2_remote_enable(struct gpib_board *board, int enable)
{
	struct pc2_priv *priv = board->private_data;

	nec7210_remote_enable(board, &priv->nec7210_priv, enable);
}

static int pc2_enable_eos(struct gpib_board *board, uint8_t eos_byte, int compare_8_bits)
{
	struct pc2_priv *priv = board->private_data;

	return nec7210_enable_eos(board, &priv->nec7210_priv, eos_byte, compare_8_bits);
}

static void pc2_disable_eos(struct gpib_board *board)
{
	struct pc2_priv *priv = board->private_data;

	nec7210_disable_eos(board, &priv->nec7210_priv);
}

static unsigned int pc2_update_status(struct gpib_board *board, unsigned int clear_mask)
{
	struct pc2_priv *priv = board->private_data;

	return nec7210_update_status(board, &priv->nec7210_priv, clear_mask);
}

static int pc2_primary_address(struct gpib_board *board, unsigned int address)
{
	struct pc2_priv *priv = board->private_data;

	return nec7210_primary_address(board, &priv->nec7210_priv, address);
}

static int pc2_secondary_address(struct gpib_board *board, unsigned int address, int enable)
{
	struct pc2_priv *priv = board->private_data;

	return nec7210_secondary_address(board, &priv->nec7210_priv, address, enable);
}

static int pc2_parallel_poll(struct gpib_board *board, uint8_t *result)
{
	struct pc2_priv *priv = board->private_data;

	return nec7210_parallel_poll(board, &priv->nec7210_priv, result);
}

static void pc2_parallel_poll_configure(struct gpib_board *board, uint8_t config)
{
	struct pc2_priv *priv = board->private_data;

	nec7210_parallel_poll_configure(board, &priv->nec7210_priv, config);
}

static void pc2_parallel_poll_response(struct gpib_board *board, int ist)
{
	struct pc2_priv *priv = board->private_data;

	nec7210_parallel_poll_response(board, &priv->nec7210_priv, ist);
}

static void pc2_serial_poll_response(struct gpib_board *board, uint8_t status)
{
	struct pc2_priv *priv = board->private_data;

	nec7210_serial_poll_response(board, &priv->nec7210_priv, status);
}

static uint8_t pc2_serial_poll_status(struct gpib_board *board)
{
	struct pc2_priv *priv = board->private_data;

	return nec7210_serial_poll_status(board, &priv->nec7210_priv);
}

static int pc2_t1_delay(struct gpib_board *board, unsigned int nano_sec)
{
	struct pc2_priv *priv = board->private_data;

	return nec7210_t1_delay(board, &priv->nec7210_priv, nano_sec);
}

static void pc2_return_to_local(struct gpib_board *board)
{
	struct pc2_priv *priv = board->private_data;

	nec7210_return_to_local(board, &priv->nec7210_priv);
}

static int allocate_private(struct gpib_board *board)
{
	struct pc2_priv *priv;

	board->private_data = kmalloc(sizeof(struct pc2_priv), GFP_KERNEL);
	if (!board->private_data)
		return -1;
	priv = board->private_data;
	memset(priv, 0, sizeof(struct pc2_priv));
	init_nec7210_private(&priv->nec7210_priv);
	return 0;
}

static void free_private(struct gpib_board *board)
{
	kfree(board->private_data);
	board->private_data = NULL;
}

static int pc2_generic_attach(struct gpib_board *board, const gpib_board_config_t *config,
			      enum nec7210_chipset chipset)
{
	struct pc2_priv *pc2_priv;
	struct nec7210_priv *nec_priv;

	board->status = 0;
	if (allocate_private(board))
		return -ENOMEM;
	pc2_priv = board->private_data;
	nec_priv = &pc2_priv->nec7210_priv;
	nec_priv->read_byte = nec7210_ioport_read_byte;
	nec_priv->write_byte = nec7210_ioport_write_byte;
	nec_priv->type = chipset;

#ifndef PC2_DMA
	/* board->dev hasn't been initialized, so forget about DMA until this driver
	 *  is adapted to use isa_register_driver.
	 */
	if (config->ibdma)
	// driver needs to be adapted to use isa_register_driver to get a struct device*
		dev_err(board->gpib_dev, "DMA disabled for pc2 gpib");
#else
	if (config->ibdma) {
		nec_priv->dma_buffer_length = 0x1000;
		nec_priv->dma_buffer = dma_alloc_coherent(board->dev,
							  nec_priv->dma_buffer_length, &
							  nec_priv->dma_buffer_addr, GFP_ATOMIC);
		if (!nec_priv->dma_buffer)
			return -ENOMEM;

		// request isa dma channel
		if (request_dma(config->ibdma, "pc2")) {
			dev_err(board->gpib_dev, "can't request DMA %d\n", config->ibdma);
			return -1;
		}
		nec_priv->dma_channel = config->ibdma;
	}
#endif

	return 0;
}

static int pc2_attach(struct gpib_board *board, const gpib_board_config_t *config)
{
	int isr_flags = 0;
	struct pc2_priv *pc2_priv;
	struct nec7210_priv *nec_priv;
	int retval;

	retval = pc2_generic_attach(board, config, NEC7210);
	if (retval)
		return retval;

	pc2_priv = board->private_data;
	nec_priv = &pc2_priv->nec7210_priv;
	nec_priv->offset = pc2_reg_offset;

	if (!request_region(config->ibbase, pc2_iosize, "pc2")) {
		dev_err(board->gpib_dev, "ioports are already in use\n");
		return -EBUSY;
	}
	nec_priv->iobase = config->ibbase;

	nec7210_board_reset(nec_priv, board);

	// install interrupt handler
	if (config->ibirq) {
		if (request_irq(config->ibirq, pc2_interrupt, isr_flags, "pc2", board))	{
			dev_err(board->gpib_dev, "can't request IRQ %d\n", config->ibirq);
			return -EBUSY;
		}
	}
	pc2_priv->irq = config->ibirq;
	/* poll so we can detect assertion of ATN */
	if (gpib_request_pseudo_irq(board, pc2_interrupt)) {
		dev_err(board->gpib_dev, "failed to allocate pseudo_irq\n");
		return -1;
	}
	/* set internal counter register for 8 MHz input clock */
	write_byte(nec_priv, ICR | 8, AUXMR);

	nec7210_board_online(nec_priv, board);

	return 0;
}

static void pc2_detach(struct gpib_board *board)
{
	struct pc2_priv *pc2_priv = board->private_data;
	struct nec7210_priv *nec_priv;

	if (pc2_priv) {
		nec_priv = &pc2_priv->nec7210_priv;
#ifdef PC2_DMA
		if (nec_priv->dma_channel)
			free_dma(nec_priv->dma_channel);
#endif
		gpib_free_pseudo_irq(board);
		if (pc2_priv->irq)
			free_irq(pc2_priv->irq, board);
		if (nec_priv->iobase) {
			nec7210_board_reset(nec_priv, board);
			release_region(nec_priv->iobase, pc2_iosize);
		}
		if (nec_priv->dma_buffer) {
			dma_free_coherent(board->dev, nec_priv->dma_buffer_length,
					  nec_priv->dma_buffer, nec_priv->dma_buffer_addr);
			nec_priv->dma_buffer = NULL;
		}
	}
	free_private(board);
}

static int pc2a_common_attach(struct gpib_board *board, const gpib_board_config_t *config,
			      unsigned int num_registers, enum nec7210_chipset chipset)
{
	unsigned int i, j;
	struct pc2_priv *pc2_priv;
	struct nec7210_priv *nec_priv;
	int retval;

	retval = pc2_generic_attach(board, config, chipset);
	if (retval)
		return retval;

	pc2_priv = board->private_data;
	nec_priv = &pc2_priv->nec7210_priv;
	nec_priv->offset = pc2a_reg_offset;

	switch (config->ibbase) {
	case 0x02e1:
	case 0x22e1:
	case 0x42e1:
	case 0x62e1:
		break;
	default:
		dev_err(board->gpib_dev, "PCIIa base range invalid, must be one of 0x[0246]2e1, but is 0x%x\n",
			config->ibbase);
		return -1;
	}

	if (config->ibirq) {
		if (config->ibirq < 2 || config->ibirq > 7) {
			dev_err(board->gpib_dev, "illegal interrupt level %i\n",
				config->ibirq);
			return -1;
		}
	} else	{
		dev_err(board->gpib_dev, "interrupt disabled, using polling mode (slow)\n");
	}
#ifdef CHECK_IOPORTS
	unsigned int err = 0;

	for (i = 0; i < num_registers; i++) {
		if (check_region(config->ibbase + i * pc2a_reg_offset, 1))
			err++;
	}
	if (config->ibirq && check_region(pc2a_clear_intr_iobase + config->ibirq, 1))
		err++;
	if (err) {
		dev_err(board->gpib_dev, "ioports are already in use");
		return -EBUSY;
	}
#endif
	for (i = 0; i < num_registers; i++) {
		if (!request_region(config->ibbase +
					i * pc2a_reg_offset, 1, "pc2a")) {
			dev_err(board->gpib_dev, "ioports are already in use");
			for (j = 0; j < i; j++)
				release_region(config->ibbase +
					j * pc2a_reg_offset, 1);
			return -EBUSY;
		}
	}
	nec_priv->iobase = config->ibbase;
	if (config->ibirq) {
		if (!request_region(pc2a_clear_intr_iobase + config->ibirq, 1, "pc2a"))  {
			dev_err(board->gpib_dev, "ioports are already in use");
			return -1;
		}
		pc2_priv->clear_intr_addr = pc2a_clear_intr_iobase + config->ibirq;
		if (request_irq(config->ibirq, pc2a_interrupt, 0, "pc2a", board)) {
			dev_err(board->gpib_dev, "can't request IRQ %d\n", config->ibirq);
			return -EBUSY;
		}
	}
	pc2_priv->irq = config->ibirq;
	/* poll so we can detect assertion of ATN */
	if (gpib_request_pseudo_irq(board, pc2_interrupt)) {
		dev_err(board->gpib_dev, "failed to allocate pseudo_irq\n");
		return -1;
	}

	// make sure interrupt is clear
	if (pc2_priv->irq)
		outb(0xff, CLEAR_INTR_REG(pc2_priv->irq));

	nec7210_board_reset(nec_priv, board);

	/* set internal counter register for 8 MHz input clock */
	write_byte(nec_priv, ICR | 8, AUXMR);

	nec7210_board_online(nec_priv, board);

	return 0;
}

static int pc2a_attach(struct gpib_board *board, const gpib_board_config_t *config)
{
	return pc2a_common_attach(board, config, pc2a_iosize, NEC7210);
}

static int pc2a_cb7210_attach(struct gpib_board *board, const gpib_board_config_t *config)
{
	return pc2a_common_attach(board, config, pc2a_iosize, CB7210);
}

static int pc2_2a_attach(struct gpib_board *board, const gpib_board_config_t *config)
{
	return pc2a_common_attach(board, config, pc2_2a_iosize, NAT4882);
}

static void pc2a_common_detach(struct gpib_board *board, unsigned int num_registers)
{
	int i;
	struct pc2_priv *pc2_priv = board->private_data;
	struct nec7210_priv *nec_priv;

	if (pc2_priv) {
		nec_priv = &pc2_priv->nec7210_priv;
#ifdef PC2_DMA
		if (nec_priv->dma_channel)
			free_dma(nec_priv->dma_channel);
#endif
		gpib_free_pseudo_irq(board);
		if (pc2_priv->irq)
			free_irq(pc2_priv->irq, board);
		if (nec_priv->iobase) {
			nec7210_board_reset(nec_priv, board);
			for (i = 0; i < num_registers; i++)
				release_region(nec_priv->iobase +
					       i * pc2a_reg_offset, 1);
		}
		if (pc2_priv->clear_intr_addr)
			release_region(pc2_priv->clear_intr_addr, 1);
		if (nec_priv->dma_buffer) {
			dma_free_coherent(board->dev, nec_priv->dma_buffer_length,
					  nec_priv->dma_buffer,
					  nec_priv->dma_buffer_addr);
			nec_priv->dma_buffer = NULL;
		}
	}
	free_private(board);
}

static void pc2a_detach(struct gpib_board *board)
{
	pc2a_common_detach(board, pc2a_iosize);
}

static void pc2_2a_detach(struct gpib_board *board)
{
	pc2a_common_detach(board, pc2_2a_iosize);
}

static gpib_interface_t pc2_interface = {
	.name =	"pcII",
	.attach =	pc2_attach,
	.detach =	pc2_detach,
	.read =	pc2_read,
	.write =	pc2_write,
	.command =	pc2_command,
	.take_control =	pc2_take_control,
	.go_to_standby =	pc2_go_to_standby,
	.request_system_control =	pc2_request_system_control,
	.interface_clear =	pc2_interface_clear,
	.remote_enable =	pc2_remote_enable,
	.enable_eos =	pc2_enable_eos,
	.disable_eos =	pc2_disable_eos,
	.parallel_poll =	pc2_parallel_poll,
	.parallel_poll_configure =	pc2_parallel_poll_configure,
	.parallel_poll_response =	pc2_parallel_poll_response,
	.local_parallel_poll_mode = NULL, // XXX
	.line_status =	NULL,
	.update_status =	pc2_update_status,
	.primary_address =	pc2_primary_address,
	.secondary_address =	pc2_secondary_address,
	.serial_poll_response =	pc2_serial_poll_response,
	.serial_poll_status =	pc2_serial_poll_status,
	.t1_delay = pc2_t1_delay,
	.return_to_local = pc2_return_to_local,
};

static gpib_interface_t pc2a_interface = {
	.name =	"pcIIa",
	.attach =	pc2a_attach,
	.detach =	pc2a_detach,
	.read =	pc2_read,
	.write =	pc2_write,
	.command =	pc2_command,
	.take_control =	pc2_take_control,
	.go_to_standby =	pc2_go_to_standby,
	.request_system_control =	pc2_request_system_control,
	.interface_clear =	pc2_interface_clear,
	.remote_enable =	pc2_remote_enable,
	.enable_eos =	pc2_enable_eos,
	.disable_eos =	pc2_disable_eos,
	.parallel_poll =	pc2_parallel_poll,
	.parallel_poll_configure =	pc2_parallel_poll_configure,
	.parallel_poll_response =	pc2_parallel_poll_response,
	.local_parallel_poll_mode = NULL, // XXX
	.line_status =	NULL,
	.update_status =	pc2_update_status,
	.primary_address =	pc2_primary_address,
	.secondary_address =	pc2_secondary_address,
	.serial_poll_response =	pc2_serial_poll_response,
	.serial_poll_status =	pc2_serial_poll_status,
	.t1_delay = pc2_t1_delay,
	.return_to_local = pc2_return_to_local,
};

static gpib_interface_t pc2a_cb7210_interface = {
	.name =	"pcIIa_cb7210",
	.attach =	pc2a_cb7210_attach,
	.detach =	pc2a_detach,
	.read =	pc2_read,
	.write =	pc2_write,
	.command =	pc2_command,
	.take_control =	pc2_take_control,
	.go_to_standby =	pc2_go_to_standby,
	.request_system_control =	pc2_request_system_control,
	.interface_clear =	pc2_interface_clear,
	.remote_enable =	pc2_remote_enable,
	.enable_eos =	pc2_enable_eos,
	.disable_eos =	pc2_disable_eos,
	.parallel_poll =	pc2_parallel_poll,
	.parallel_poll_configure =	pc2_parallel_poll_configure,
	.parallel_poll_response =	pc2_parallel_poll_response,
	.local_parallel_poll_mode = NULL, // XXX
	.line_status =	NULL, //XXX
	.update_status =	pc2_update_status,
	.primary_address =	pc2_primary_address,
	.secondary_address =	pc2_secondary_address,
	.serial_poll_response =	pc2_serial_poll_response,
	.serial_poll_status =	pc2_serial_poll_status,
	.t1_delay = pc2_t1_delay,
	.return_to_local = pc2_return_to_local,
};

static gpib_interface_t pc2_2a_interface = {
	.name =	"pcII_IIa",
	.attach =	pc2_2a_attach,
	.detach =	pc2_2a_detach,
	.read =	pc2_read,
	.write =	pc2_write,
	.command =	pc2_command,
	.take_control =	pc2_take_control,
	.go_to_standby =	pc2_go_to_standby,
	.request_system_control =	pc2_request_system_control,
	.interface_clear =	pc2_interface_clear,
	.remote_enable =	pc2_remote_enable,
	.enable_eos =	pc2_enable_eos,
	.disable_eos =	pc2_disable_eos,
	.parallel_poll =	pc2_parallel_poll,
	.parallel_poll_configure =	pc2_parallel_poll_configure,
	.parallel_poll_response =	pc2_parallel_poll_response,
	.local_parallel_poll_mode = NULL, // XXX
	.line_status =	NULL,
	.update_status =	pc2_update_status,
	.primary_address =	pc2_primary_address,
	.secondary_address =	pc2_secondary_address,
	.serial_poll_response =	pc2_serial_poll_response,
	.serial_poll_status =	pc2_serial_poll_status,
	.t1_delay = pc2_t1_delay,
	.return_to_local = pc2_return_to_local,
};

static int __init pc2_init_module(void)
{
	int ret;

	ret = gpib_register_driver(&pc2_interface, THIS_MODULE);
	if (ret) {
		pr_err("gpib_register_driver failed: error = %d\n", ret);
		return ret;
	}

	ret = gpib_register_driver(&pc2a_interface, THIS_MODULE);
	if (ret) {
		pr_err("gpib_register_driver failed: error = %d\n", ret);
		goto err_pc2a;
	}

	ret = gpib_register_driver(&pc2a_cb7210_interface, THIS_MODULE);
	if (ret) {
		pr_err("gpib_register_driver failed: error = %d\n", ret);
		goto err_cb7210;
	}

	ret = gpib_register_driver(&pc2_2a_interface, THIS_MODULE);
	if (ret) {
		pr_err("gpib_register_driver failed: error = %d\n", ret);
		goto err_pc2_2a;
	}

	return 0;

err_pc2_2a:
	gpib_unregister_driver(&pc2a_cb7210_interface);
err_cb7210:
	gpib_unregister_driver(&pc2a_interface);
err_pc2a:
	gpib_unregister_driver(&pc2_interface);

	return ret;
}

static void __exit pc2_exit_module(void)
{
	gpib_unregister_driver(&pc2_interface);
	gpib_unregister_driver(&pc2a_interface);
	gpib_unregister_driver(&pc2a_cb7210_interface);
	gpib_unregister_driver(&pc2_2a_interface);
}

module_init(pc2_init_module);
module_exit(pc2_exit_module);

以智者之名,为愚者代辩