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