14 #include <linux/device.h>
15 #include <linux/module.h>
17 #include <linux/sched.h>
18 #include <linux/tty.h>
19 #include <linux/serial.h>
21 #include <linux/slab.h>
28 #define IP_OCTAL_ID_SPACE_VECTOR 0x41
29 #define IP_OCTAL_NB_BLOCKS 4
100 ipoctal_reset_stats(&channel->
stats);
106 static void ipoctal_close(
struct tty_struct *tty,
struct file *filp)
113 ipoctal_free_channel(channel);
116 static int ipoctal_get_icount(
struct tty_struct *tty,
125 icount->
rx = channel->
stats.rx;
126 icount->
tx = channel->
stats.tx;
129 icount->
brk = channel->
stats.rcv_break;
147 channel->
stats.overrun_err++;
152 channel->
stats.parity_err++;
156 channel->
stats.framing_err++;
161 channel->
stats.rcv_break++;
165 tty_insert_flip_char(tty, value, flag);
192 *pointer_write = *pointer_write %
PAGE_SIZE;
196 (waitqueue_active(&channel->
queue))) {
235 ipoctal_irq_rx(channel, tty, sr);
239 ipoctal_irq_tx(channel);
252 ipoctal_irq_channel(&ipoctal->
channel[i]);
261 static int ipoctal_check_model(
struct ipack_device *
dev,
unsigned char *
id)
263 unsigned char manufacturerID;
286 .activate = ipoctal_port_activate,
289 static int ipoctal_inst_slot(
struct ipoctal *ipoctal,
unsigned int bus_nr,
301 res = ipoctal->
dev->bus->ops->map_space(ipoctal->
dev, 0,
305 "Unable to map slot [%d:%d] ID space!\n",
310 res = ipoctal_check_model(ipoctal->
dev, &board_id);
312 ipoctal->
dev->bus->ops->unmap_space(ipoctal->
dev,
314 goto out_unregister_id_space;
318 res = ipoctal->
dev->bus->ops->map_space(ipoctal->
dev, 0,
322 "Unable to map slot [%d:%d] IO space!\n",
324 goto out_unregister_id_space;
327 res = ipoctal->
dev->bus->ops->map_space(ipoctal->
dev, 0,
331 "Unable to map slot [%d:%d] INT space!\n",
333 goto out_unregister_io_space;
336 res = ipoctal->
dev->bus->ops->map_space(ipoctal->
dev,
340 "Unable to map slot [%d:%d] MEM space!\n",
342 goto out_unregister_int_space;
354 channel->
regs = chan_regs +
i;
370 &channel->
regs->
w.mr);
378 &block_regs[i].
w.opcr);
381 &block_regs[i].
w.imr);
389 ipoctal->
dev->bus->ops->request_irq(ipoctal->
dev,
390 ipoctal_irq_handler, ipoctal);
397 tty = alloc_tty_driver(NR_CHANNELS);
401 goto out_unregister_slot_unmap;
407 sprintf(name, KBUILD_MODNAME
".%d.%d.", bus_nr, slot);
423 dev_err(&ipoctal->
dev->dev,
"Can't register tty driver.\n");
425 goto out_unregister_slot_unmap;
437 channel->
tty_port.ops = &ipoctal_tty_port_ops;
439 ipoctal_reset_stats(&channel->
stats);
447 if (IS_ERR(tty_dev)) {
448 dev_err(&ipoctal->
dev->dev,
"Failed to register tty device.\n");
462 out_unregister_slot_unmap:
464 out_unregister_int_space:
466 out_unregister_io_space:
468 out_unregister_id_space:
473 static inline int ipoctal_copy_write_buffer(
struct ipoctal_channel *channel,
474 const unsigned char *
buf,
482 for (i = 0; i <
count; i++) {
485 channel->
tty_port.xmit_buf[*pointer_read] = buf[
i];
486 *pointer_read = (*pointer_read + 1) %
PAGE_SIZE;
488 spin_unlock_irqrestore(&channel->
lock, flags);
496 static int ipoctal_write_tty(
struct tty_struct *tty,
497 const unsigned char *buf,
int count)
500 unsigned int char_copied;
502 char_copied = ipoctal_copy_write_buffer(channel, buf, count);
522 static int ipoctal_write_room(
struct tty_struct *tty)
529 static int ipoctal_chars_in_buffer(
struct tty_struct *tty)
536 static void ipoctal_set_termios(
struct tty_struct *tty,
540 unsigned char mr1 = 0;
541 unsigned char mr2 = 0;
542 unsigned char csr = 0;
546 cflag = tty->termios.c_cflag;
556 switch (cflag &
CSIZE) {
567 tty->termios.c_cflag = (cflag & ~CSIZE) |
CS8;
581 tty->termios.c_cflag &= ~
CMSPAR;
674 static void ipoctal_hangup(
struct tty_struct *tty)
686 spin_unlock_irqrestore(&channel->
lock, flags);
702 .open = ipoctal_open,
703 .close = ipoctal_close,
704 .write = ipoctal_write_tty,
705 .set_termios = ipoctal_set_termios,
706 .write_room = ipoctal_write_room,
707 .chars_in_buffer = ipoctal_chars_in_buffer,
708 .get_icount = ipoctal_get_icount,
709 .hangup = ipoctal_hangup,
715 struct ipoctal *ipoctal;
717 ipoctal = kzalloc(
sizeof(
struct ipoctal),
GFP_KERNEL);
722 res = ipoctal_inst_slot(ipoctal, dev->
bus_nr, dev->
slot);
734 static void __ipoctal_remove(
struct ipoctal *ipoctal)
738 ipoctal->
dev->bus->ops->free_irq(ipoctal->
dev);
773 .probe = ipoctal_probe,
774 .remove = ipoctal_remove,
778 .ops = &ipoctal_drv_ops,
779 .id_table = ipoctal_ids,
782 static int __init ipoctal_init(
void)
787 static void __exit ipoctal_exit(
void)