4 * driver for the GE IP-OCTAL boards
5 * Copyright (c) 2009 Nicolas Serafini, EIC2 SA
6 * Copyright (c) 2010,2011 Samuel Iglesias Gonsalvez <siglesia@cern.ch>, CERN
7 * Copyright (c) 2012 Samuel Iglesias Gonsalvez <siglesias@igalia.com>, Igalia
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; version 2 of the License.
14 #include <linux/device.h>
15 #include <linux/module.h>
16 #include <linux/interrupt.h>
17 #include <linux/sched.h>
18 #include <linux/tty.h>
19 #include <linux/serial.h>
20 #include <linux/tty_flip.h>
21 #include <linux/slab.h>
22 #include <linux/atomic.h>
28 #define IP_OCTAL_ID_SPACE_VECTOR 0x41
29 #define IP_OCTAL_NB_BLOCKS 4
31 static const struct tty_operations ipoctal_fops;
34 struct list_head list;
35 struct ipack_device *dev;
36 unsigned int board_id;
37 union scc2698_channel __iomem *chan_regs;
38 union scc2698_block __iomem *block_regs;
39 struct ipoctal_stats chan_stats[NR_CHANNELS];
40 unsigned int nb_bytes[NR_CHANNELS];
41 unsigned int count_wr[NR_CHANNELS];
42 wait_queue_head_t queue[NR_CHANNELS];
43 spinlock_t lock[NR_CHANNELS];
44 unsigned int pointer_read[NR_CHANNELS];
45 unsigned int pointer_write[NR_CHANNELS];
46 atomic_t open[NR_CHANNELS];
48 struct tty_port tty_port[NR_CHANNELS];
49 struct tty_driver *tty_drv;
52 /* Linked list to save the registered devices */
53 static LIST_HEAD(ipoctal_list);
55 static inline void ipoctal_write_io_reg(struct ipoctal *ipoctal,
59 iowrite8(value, dest);
62 static inline void ipoctal_write_cr_cmd(struct ipoctal *ipoctal,
66 ipoctal_write_io_reg(ipoctal, dest, value);
69 static inline unsigned char ipoctal_read_io_reg(struct ipoctal *ipoctal,
75 static struct ipoctal *ipoctal_find_board(struct tty_struct *tty)
79 list_for_each_entry(p, &ipoctal_list, list) {
80 if (tty->driver->major == p->tty_drv->major)
87 static int ipoctal_port_activate(struct tty_port *port, struct tty_struct *tty)
89 struct ipoctal *ipoctal;
90 int channel = tty->index;
92 ipoctal = ipoctal_find_board(tty);
94 if (ipoctal == NULL) {
95 dev_err(tty->dev, "Device not found. Major %d\n",
100 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].w.cr,
105 static int ipoctal_open(struct tty_struct *tty, struct file *file)
107 int channel = tty->index;
109 struct ipoctal *ipoctal;
111 ipoctal = ipoctal_find_board(tty);
113 if (ipoctal == NULL) {
114 dev_err(tty->dev, "Device not found. Major %d\n",
119 if (atomic_read(&ipoctal->open[channel]))
122 tty->driver_data = ipoctal;
124 res = tty_port_open(&ipoctal->tty_port[channel], tty, file);
128 atomic_inc(&ipoctal->open[channel]);
132 static void ipoctal_reset_stats(struct ipoctal_stats *stats)
136 stats->rcv_break = 0;
137 stats->framing_err = 0;
138 stats->overrun_err = 0;
139 stats->parity_err = 0;
142 static void ipoctal_free_channel(struct tty_struct *tty)
144 int channel = tty->index;
145 struct ipoctal *ipoctal = tty->driver_data;
150 ipoctal_reset_stats(&ipoctal->chan_stats[channel]);
151 ipoctal->pointer_read[channel] = 0;
152 ipoctal->pointer_write[channel] = 0;
153 ipoctal->nb_bytes[channel] = 0;
156 static void ipoctal_close(struct tty_struct *tty, struct file *filp)
158 int channel = tty->index;
159 struct ipoctal *ipoctal = tty->driver_data;
161 tty_port_close(&ipoctal->tty_port[channel], tty, filp);
163 if (atomic_dec_and_test(&ipoctal->open[channel]))
164 ipoctal_free_channel(tty);
167 static int ipoctal_get_icount(struct tty_struct *tty,
168 struct serial_icounter_struct *icount)
170 struct ipoctal *ipoctal = tty->driver_data;
171 int channel = tty->index;
177 icount->rx = ipoctal->chan_stats[channel].rx;
178 icount->tx = ipoctal->chan_stats[channel].tx;
179 icount->frame = ipoctal->chan_stats[channel].framing_err;
180 icount->parity = ipoctal->chan_stats[channel].parity_err;
181 icount->brk = ipoctal->chan_stats[channel].rcv_break;
185 static int ipoctal_irq_handler(void *arg)
187 unsigned int channel;
191 unsigned char isr_tx_rdy, isr_rx_rdy;
194 struct tty_struct *tty;
195 struct ipoctal *ipoctal = (struct ipoctal *) arg;
197 /* Check all channels */
198 for (channel = 0; channel < NR_CHANNELS; channel++) {
199 /* If there is no client, skip the check */
200 if (!atomic_read(&ipoctal->open[channel]))
203 tty = tty_port_tty_get(&ipoctal->tty_port[channel]);
208 * The HW is organized in pair of channels.
209 * See which register we need to read from
212 isr = ipoctal_read_io_reg(ipoctal,
213 &ipoctal->block_regs[block].r.isr);
214 sr = ipoctal_read_io_reg(ipoctal,
215 &ipoctal->chan_regs[channel].r.sr);
217 if ((channel % 2) == 1) {
218 isr_tx_rdy = isr & ISR_TxRDY_B;
219 isr_rx_rdy = isr & ISR_RxRDY_FFULL_B;
221 isr_tx_rdy = isr & ISR_TxRDY_A;
222 isr_rx_rdy = isr & ISR_RxRDY_FFULL_A;
225 /* In case of RS-485, change from TX to RX when finishing TX.
228 if ((ipoctal->board_id == IPACK1_DEVICE_ID_SBS_OCTAL_485) &&
229 (sr & SR_TX_EMPTY) &&
230 (ipoctal->nb_bytes[channel] == 0)) {
231 ipoctal_write_io_reg(ipoctal,
232 &ipoctal->chan_regs[channel].w.cr,
234 ipoctal_write_cr_cmd(ipoctal,
235 &ipoctal->chan_regs[channel].w.cr,
237 ipoctal_write_io_reg(ipoctal,
238 &ipoctal->chan_regs[channel].w.cr,
241 wake_up_interruptible(&ipoctal->queue[channel]);
245 if (isr_rx_rdy && (sr & SR_RX_READY)) {
246 value = ipoctal_read_io_reg(ipoctal,
247 &ipoctal->chan_regs[channel].r.rhr);
250 /* Error: count statistics */
252 ipoctal_write_cr_cmd(ipoctal,
253 &ipoctal->chan_regs[channel].w.cr,
254 CR_CMD_RESET_ERR_STATUS);
256 if (sr & SR_OVERRUN_ERROR) {
257 ipoctal->chan_stats[channel].overrun_err++;
258 /* Overrun doesn't affect the current character*/
259 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
261 if (sr & SR_PARITY_ERROR) {
262 ipoctal->chan_stats[channel].parity_err++;
265 if (sr & SR_FRAMING_ERROR) {
266 ipoctal->chan_stats[channel].framing_err++;
269 if (sr & SR_RECEIVED_BREAK) {
270 ipoctal->chan_stats[channel].rcv_break++;
275 tty_insert_flip_char(tty, value, flag);
278 /* TX of each character */
279 if (isr_tx_rdy && (sr & SR_TX_READY)) {
280 unsigned int *pointer_write =
281 &ipoctal->pointer_write[channel];
283 if (ipoctal->nb_bytes[channel] <= 0) {
284 ipoctal->nb_bytes[channel] = 0;
288 value = ipoctal->tty_port[channel].xmit_buf[*pointer_write];
289 ipoctal_write_io_reg(ipoctal,
290 &ipoctal->chan_regs[channel].w.thr,
292 ipoctal->chan_stats[channel].tx++;
293 ipoctal->count_wr[channel]++;
295 *pointer_write = *pointer_write % PAGE_SIZE;
296 ipoctal->nb_bytes[channel]--;
298 if ((ipoctal->nb_bytes[channel] == 0) &&
299 (waitqueue_active(&ipoctal->queue[channel]))) {
301 if (ipoctal->board_id != IPACK1_DEVICE_ID_SBS_OCTAL_485) {
303 wake_up_interruptible(&ipoctal->queue[channel]);
308 tty_flip_buffer_push(tty);
314 static int ipoctal_check_model(struct ipack_device *dev, unsigned char *id)
316 unsigned char manufacturerID;
317 unsigned char board_id;
320 manufacturerID = ioread8(dev->id_space.address + IPACK_IDPROM_OFFSET_MANUFACTURER_ID);
321 if (manufacturerID != IPACK1_VENDOR_ID_SBS)
324 board_id = ioread8(dev->id_space.address + IPACK_IDPROM_OFFSET_MODEL);
326 case IPACK1_DEVICE_ID_SBS_OCTAL_232:
327 case IPACK1_DEVICE_ID_SBS_OCTAL_422:
328 case IPACK1_DEVICE_ID_SBS_OCTAL_485:
338 static const struct tty_port_operations ipoctal_tty_port_ops = {
340 .activate = ipoctal_port_activate,
343 static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr,
344 unsigned int slot, unsigned int vector)
348 struct tty_driver *tty;
350 unsigned char board_id;
352 res = ipoctal->dev->bus->ops->map_space(ipoctal->dev, 0,
355 dev_err(&ipoctal->dev->dev,
356 "Unable to map slot [%d:%d] ID space!\n",
361 res = ipoctal_check_model(ipoctal->dev, &board_id);
363 ipoctal->dev->bus->ops->unmap_space(ipoctal->dev,
365 goto out_unregister_id_space;
367 ipoctal->board_id = board_id;
369 res = ipoctal->dev->bus->ops->map_space(ipoctal->dev, 0,
372 dev_err(&ipoctal->dev->dev,
373 "Unable to map slot [%d:%d] IO space!\n",
375 goto out_unregister_id_space;
378 res = ipoctal->dev->bus->ops->map_space(ipoctal->dev,
379 0x8000, IPACK_MEM_SPACE);
381 dev_err(&ipoctal->dev->dev,
382 "Unable to map slot [%d:%d] MEM space!\n",
384 goto out_unregister_io_space;
387 /* Save the virtual address to access the registers easily */
389 (union scc2698_channel __iomem *) ipoctal->dev->io_space.address;
390 ipoctal->block_regs =
391 (union scc2698_block __iomem *) ipoctal->dev->io_space.address;
393 /* Disable RX and TX before touching anything */
394 for (i = 0; i < NR_CHANNELS ; i++) {
395 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[i].w.cr,
396 CR_DISABLE_RX | CR_DISABLE_TX);
397 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[i].w.cr,
399 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[i].w.cr,
401 ipoctal_write_io_reg(ipoctal,
402 &ipoctal->chan_regs[i].w.mr,
403 MR1_CHRL_8_BITS | MR1_ERROR_CHAR |
404 MR1_RxINT_RxRDY); /* mr1 */
405 ipoctal_write_io_reg(ipoctal,
406 &ipoctal->chan_regs[i].w.mr,
408 ipoctal_write_io_reg(ipoctal,
409 &ipoctal->chan_regs[i].w.csr,
410 TX_CLK_9600 | RX_CLK_9600);
413 for (i = 0; i < IP_OCTAL_NB_BLOCKS; i++) {
414 ipoctal_write_io_reg(ipoctal,
415 &ipoctal->block_regs[i].w.acr,
417 ipoctal_write_io_reg(ipoctal,
418 &ipoctal->block_regs[i].w.opcr,
419 OPCR_MPP_OUTPUT | OPCR_MPOa_RTSN |
421 ipoctal_write_io_reg(ipoctal,
422 &ipoctal->block_regs[i].w.imr,
423 IMR_TxRDY_A | IMR_RxRDY_FFULL_A |
424 IMR_DELTA_BREAK_A | IMR_TxRDY_B |
425 IMR_RxRDY_FFULL_B | IMR_DELTA_BREAK_B);
429 * IP-OCTAL has different addresses to copy its IRQ vector.
430 * Depending of the carrier these addresses are accesible or not.
431 * More info in the datasheet.
433 ipoctal->dev->bus->ops->request_irq(ipoctal->dev, vector,
434 ipoctal_irq_handler, ipoctal);
435 iowrite8(vector, ipoctal->dev->mem_space.address + 1);
437 /* Register the TTY device */
439 /* Each IP-OCTAL channel is a TTY port */
440 tty = alloc_tty_driver(NR_CHANNELS);
444 goto out_unregister_slot_unmap;
447 /* Fill struct tty_driver with ipoctal data */
448 tty->owner = THIS_MODULE;
449 tty->driver_name = "ipoctal";
450 sprintf(name, "ipoctal.%d.%d.", bus_nr, slot);
454 tty->minor_start = 0;
455 tty->type = TTY_DRIVER_TYPE_SERIAL;
456 tty->subtype = SERIAL_TYPE_NORMAL;
457 tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
458 tty->init_termios = tty_std_termios;
459 tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
460 tty->init_termios.c_ispeed = 9600;
461 tty->init_termios.c_ospeed = 9600;
463 tty_set_operations(tty, &ipoctal_fops);
464 res = tty_register_driver(tty);
466 dev_err(&ipoctal->dev->dev, "Can't register tty driver.\n");
468 goto out_unregister_slot_unmap;
471 /* Save struct tty_driver for use it when uninstalling the device */
472 ipoctal->tty_drv = tty;
474 for (i = 0; i < NR_CHANNELS; i++) {
475 tty_port_init(&ipoctal->tty_port[i]);
476 tty_port_alloc_xmit_buf(&ipoctal->tty_port[i]);
477 ipoctal->tty_port[i].ops = &ipoctal_tty_port_ops;
479 ipoctal_reset_stats(&ipoctal->chan_stats[i]);
480 ipoctal->nb_bytes[i] = 0;
481 init_waitqueue_head(&ipoctal->queue[i]);
483 spin_lock_init(&ipoctal->lock[i]);
484 ipoctal->pointer_read[i] = 0;
485 ipoctal->pointer_write[i] = 0;
486 ipoctal->nb_bytes[i] = 0;
487 tty_register_device(tty, i, NULL);
490 * Enable again the RX. TX will be enabled when
491 * there is something to send
493 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[i].w.cr,
499 out_unregister_slot_unmap:
500 ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_ID_SPACE);
501 out_unregister_io_space:
502 ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_IO_SPACE);
503 out_unregister_id_space:
504 ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_MEM_SPACE);
508 static inline int ipoctal_copy_write_buffer(struct ipoctal *ipoctal,
509 unsigned int channel,
510 const unsigned char *buf,
515 unsigned int *pointer_read = &ipoctal->pointer_read[channel];
517 /* Copy the bytes from the user buffer to the internal one */
518 for (i = 0; i < count; i++) {
519 if (i <= (PAGE_SIZE - ipoctal->nb_bytes[channel])) {
520 spin_lock_irqsave(&ipoctal->lock[channel], flags);
521 ipoctal->tty_port[channel].xmit_buf[*pointer_read] = buf[i];
522 *pointer_read = (*pointer_read + 1) % PAGE_SIZE;
523 ipoctal->nb_bytes[channel]++;
524 spin_unlock_irqrestore(&ipoctal->lock[channel], flags);
532 static int ipoctal_write(struct ipoctal *ipoctal, unsigned int channel,
533 const unsigned char *buf, int count)
535 ipoctal->nb_bytes[channel] = 0;
536 ipoctal->count_wr[channel] = 0;
538 ipoctal_copy_write_buffer(ipoctal, channel, buf, count);
540 /* As the IP-OCTAL 485 only supports half duplex, do it manually */
541 if (ipoctal->board_id == IPACK1_DEVICE_ID_SBS_OCTAL_485) {
542 ipoctal_write_io_reg(ipoctal,
543 &ipoctal->chan_regs[channel].w.cr,
545 ipoctal_write_cr_cmd(ipoctal,
546 &ipoctal->chan_regs[channel].w.cr,
551 * Send a packet and then disable TX to avoid failure after several send
554 ipoctal_write_io_reg(ipoctal,
555 &ipoctal->chan_regs[channel].w.cr,
557 wait_event_interruptible(ipoctal->queue[channel], ipoctal->write);
558 ipoctal_write_io_reg(ipoctal,
559 &ipoctal->chan_regs[channel].w.cr,
563 return ipoctal->count_wr[channel];
566 static int ipoctal_write_tty(struct tty_struct *tty,
567 const unsigned char *buf, int count)
569 unsigned int channel = tty->index;
570 struct ipoctal *ipoctal = tty->driver_data;
572 return ipoctal_write(ipoctal, channel, buf, count);
575 static int ipoctal_write_room(struct tty_struct *tty)
577 int channel = tty->index;
578 struct ipoctal *ipoctal = tty->driver_data;
580 return PAGE_SIZE - ipoctal->nb_bytes[channel];
583 static int ipoctal_chars_in_buffer(struct tty_struct *tty)
585 int channel = tty->index;
586 struct ipoctal *ipoctal = tty->driver_data;
588 return ipoctal->nb_bytes[channel];
591 static void ipoctal_set_termios(struct tty_struct *tty,
592 struct ktermios *old_termios)
595 unsigned char mr1 = 0;
596 unsigned char mr2 = 0;
597 unsigned char csr = 0;
598 unsigned int channel = tty->index;
599 struct ipoctal *ipoctal = tty->driver_data;
602 cflag = tty->termios->c_cflag;
604 /* Disable and reset everything before change the setup */
605 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].w.cr,
606 CR_DISABLE_RX | CR_DISABLE_TX);
607 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].w.cr,
609 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].w.cr,
611 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].w.cr,
612 CR_CMD_RESET_ERR_STATUS);
613 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].w.cr,
616 /* Set Bits per chars */
617 switch (cflag & CSIZE) {
619 mr1 |= MR1_CHRL_6_BITS;
622 mr1 |= MR1_CHRL_7_BITS;
626 mr1 |= MR1_CHRL_8_BITS;
627 /* By default, select CS8 */
628 tty->termios->c_cflag = (cflag & ~CSIZE) | CS8;
635 mr1 |= MR1_PARITY_ON | MR1_PARITY_ODD;
637 mr1 |= MR1_PARITY_ON | MR1_PARITY_EVEN;
639 mr1 |= MR1_PARITY_OFF;
641 /* Mark or space parity is not supported */
642 tty->termios->c_cflag &= ~CMSPAR;
646 mr2 |= MR2_STOP_BITS_LENGTH_2;
648 mr2 |= MR2_STOP_BITS_LENGTH_1;
650 /* Set the flow control */
651 switch (ipoctal->board_id) {
652 case IPACK1_DEVICE_ID_SBS_OCTAL_232:
653 if (cflag & CRTSCTS) {
654 mr1 |= MR1_RxRTS_CONTROL_ON;
655 mr2 |= MR2_TxRTS_CONTROL_OFF | MR2_CTS_ENABLE_TX_ON;
657 mr1 |= MR1_RxRTS_CONTROL_OFF;
658 mr2 |= MR2_TxRTS_CONTROL_OFF | MR2_CTS_ENABLE_TX_OFF;
661 case IPACK1_DEVICE_ID_SBS_OCTAL_422:
662 mr1 |= MR1_RxRTS_CONTROL_OFF;
663 mr2 |= MR2_TxRTS_CONTROL_OFF | MR2_CTS_ENABLE_TX_OFF;
665 case IPACK1_DEVICE_ID_SBS_OCTAL_485:
666 mr1 |= MR1_RxRTS_CONTROL_OFF;
667 mr2 |= MR2_TxRTS_CONTROL_ON | MR2_CTS_ENABLE_TX_OFF;
674 baud = tty_get_baud_rate(tty);
675 tty_termios_encode_baud_rate(tty->termios, baud, baud);
678 switch (tty->termios->c_ospeed) {
680 csr |= TX_CLK_75 | RX_CLK_75;
683 csr |= TX_CLK_110 | RX_CLK_110;
686 csr |= TX_CLK_150 | RX_CLK_150;
689 csr |= TX_CLK_300 | RX_CLK_300;
692 csr |= TX_CLK_600 | RX_CLK_600;
695 csr |= TX_CLK_1200 | RX_CLK_1200;
698 csr |= TX_CLK_1800 | RX_CLK_1800;
701 csr |= TX_CLK_2000 | RX_CLK_2000;
704 csr |= TX_CLK_2400 | RX_CLK_2400;
707 csr |= TX_CLK_4800 | RX_CLK_4800;
710 csr |= TX_CLK_9600 | RX_CLK_9600;
713 csr |= TX_CLK_19200 | RX_CLK_19200;
717 csr |= TX_CLK_38400 | RX_CLK_38400;
718 /* In case of default, we establish 38400 bps */
719 tty_termios_encode_baud_rate(tty->termios, 38400, 38400);
723 mr1 |= MR1_ERROR_CHAR;
724 mr1 |= MR1_RxINT_RxRDY;
726 /* Write the control registers */
727 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].w.mr, mr1);
728 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].w.mr, mr2);
729 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].w.csr, csr);
731 /* Enable again the RX */
732 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].w.cr,
736 static void ipoctal_hangup(struct tty_struct *tty)
739 int channel = tty->index;
740 struct ipoctal *ipoctal = tty->driver_data;
745 spin_lock_irqsave(&ipoctal->lock[channel], flags);
746 ipoctal->nb_bytes[channel] = 0;
747 ipoctal->pointer_read[channel] = 0;
748 ipoctal->pointer_write[channel] = 0;
749 spin_unlock_irqrestore(&ipoctal->lock[channel], flags);
751 tty_port_hangup(&ipoctal->tty_port[channel]);
753 ipoctal_write_io_reg(ipoctal, &ipoctal->chan_regs[channel].w.cr,
754 CR_DISABLE_RX | CR_DISABLE_TX);
755 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].w.cr,
757 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].w.cr,
759 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].w.cr,
760 CR_CMD_RESET_ERR_STATUS);
761 ipoctal_write_cr_cmd(ipoctal, &ipoctal->chan_regs[channel].w.cr,
764 clear_bit(ASYNCB_INITIALIZED, &ipoctal->tty_port[channel].flags);
765 wake_up_interruptible(&ipoctal->tty_port[channel].open_wait);
768 static const struct tty_operations ipoctal_fops = {
770 .open = ipoctal_open,
771 .close = ipoctal_close,
772 .write = ipoctal_write_tty,
773 .set_termios = ipoctal_set_termios,
774 .write_room = ipoctal_write_room,
775 .chars_in_buffer = ipoctal_chars_in_buffer,
776 .get_icount = ipoctal_get_icount,
777 .hangup = ipoctal_hangup,
780 static int ipoctal_probe(struct ipack_device *dev)
783 struct ipoctal *ipoctal;
785 ipoctal = kzalloc(sizeof(struct ipoctal), GFP_KERNEL);
790 res = ipoctal_inst_slot(ipoctal, dev->bus_nr, dev->slot, dev->irq);
794 list_add_tail(&ipoctal->list, &ipoctal_list);
802 static void __ipoctal_remove(struct ipoctal *ipoctal)
806 for (i = 0; i < NR_CHANNELS; i++) {
807 tty_unregister_device(ipoctal->tty_drv, i);
808 tty_port_free_xmit_buf(&ipoctal->tty_port[i]);
811 tty_unregister_driver(ipoctal->tty_drv);
812 put_tty_driver(ipoctal->tty_drv);
813 list_del(&ipoctal->list);
817 static void ipoctal_remove(struct ipack_device *device)
819 struct ipoctal *ipoctal, *next;
821 list_for_each_entry_safe(ipoctal, next, &ipoctal_list, list) {
822 if (ipoctal->dev == device)
823 __ipoctal_remove(ipoctal);
827 static DEFINE_IPACK_DEVICE_TABLE(ipoctal_ids) = {
828 { IPACK_DEVICE(IPACK_ID_VERSION_1, IPACK1_VENDOR_ID_SBS,
829 IPACK1_DEVICE_ID_SBS_OCTAL_232) },
830 { IPACK_DEVICE(IPACK_ID_VERSION_1, IPACK1_VENDOR_ID_SBS,
831 IPACK1_DEVICE_ID_SBS_OCTAL_422) },
832 { IPACK_DEVICE(IPACK_ID_VERSION_1, IPACK1_VENDOR_ID_SBS,
833 IPACK1_DEVICE_ID_SBS_OCTAL_485) },
837 MODULE_DEVICE_TABLE(ipack, ipoctal_ids);
839 static const struct ipack_driver_ops ipoctal_drv_ops = {
840 .probe = ipoctal_probe,
841 .remove = ipoctal_remove,
844 static struct ipack_driver driver = {
845 .ops = &ipoctal_drv_ops,
846 .id_table = ipoctal_ids,
849 static int __init ipoctal_init(void)
851 return ipack_driver_register(&driver, THIS_MODULE, KBUILD_MODNAME);
854 static void __exit ipoctal_exit(void)
856 ipack_driver_unregister(&driver);
859 MODULE_DESCRIPTION("IP-Octal 232, 422 and 485 device driver");
860 MODULE_LICENSE("GPL");
862 module_init(ipoctal_init);
863 module_exit(ipoctal_exit);