34 #include <linux/module.h>
36 #include <linux/slab.h>
37 #include <linux/sched.h>
40 #include <linux/tty.h>
43 #include <linux/device.h>
45 #include <asm/uaccess.h>
57 static int ircomm_tty_open(
struct tty_struct *tty,
struct file *filp);
58 static void ircomm_tty_close(
struct tty_struct * tty,
struct file *filp);
59 static int ircomm_tty_write(
struct tty_struct * tty,
60 const unsigned char *
buf,
int count);
61 static int ircomm_tty_write_room(
struct tty_struct *tty);
62 static void ircomm_tty_throttle(
struct tty_struct *tty);
63 static void ircomm_tty_unthrottle(
struct tty_struct *tty);
64 static int ircomm_tty_chars_in_buffer(
struct tty_struct *tty);
65 static void ircomm_tty_flush_buffer(
struct tty_struct *tty);
66 static void ircomm_tty_send_xchar(
struct tty_struct *tty,
char ch);
67 static void ircomm_tty_wait_until_sent(
struct tty_struct *tty,
int timeout);
68 static void ircomm_tty_hangup(
struct tty_struct *tty);
71 static void ircomm_tty_stop(
struct tty_struct *tty);
73 static int ircomm_tty_data_indication(
void *instance,
void *sap,
75 static int ircomm_tty_control_indication(
void *instance,
void *sap,
77 static void ircomm_tty_flow_indication(
void *instance,
void *sap,
87 .install = ircomm_tty_install,
88 .open = ircomm_tty_open,
89 .close = ircomm_tty_close,
90 .write = ircomm_tty_write,
91 .write_room = ircomm_tty_write_room,
92 .chars_in_buffer = ircomm_tty_chars_in_buffer,
93 .flush_buffer = ircomm_tty_flush_buffer,
97 .throttle = ircomm_tty_throttle,
98 .unthrottle = ircomm_tty_unthrottle,
99 .send_xchar = ircomm_tty_send_xchar,
101 .stop = ircomm_tty_stop,
103 .hangup = ircomm_tty_hangup,
104 .wait_until_sent = ircomm_tty_wait_until_sent,
105 #ifdef CONFIG_PROC_FS
106 .proc_fops = &ircomm_tty_proc_fops,
110 static void ircomm_port_raise_dtr_rts(
struct tty_port *
port,
int raise)
127 static int ircomm_port_carrier_raised(
struct tty_port *port)
135 .dtr_rts = ircomm_port_raise_dtr_rts,
136 .carrier_raised = ircomm_port_carrier_raised,
145 static int __init ircomm_tty_init(
void)
151 if (ircomm_tty ==
NULL) {
152 IRDA_ERROR(
"%s(), can't allocate hashbin!\n", __func__);
158 driver->
name =
"ircomm";
168 IRDA_ERROR(
"%s(): Couldn't register serial driver\n",
183 ircomm_tty_shutdown(
self);
195 static void __exit ircomm_tty_cleanup(
void)
203 IRDA_ERROR(
"%s(), failed to unregister driver\n",
230 IRDA_DEBUG(2,
"%s(), already open so break out!\n", __func__ );
249 self->ircomm =
ircomm_open(¬ify, self->service_type,
255 self->slsap_sel =
self->ircomm->slsap_sel;
260 IRDA_ERROR(
"%s(), error attaching cable!\n", __func__);
276 static int ircomm_tty_block_til_ready(
struct ircomm_tty_cb *
self,
279 struct tty_port *port = &
self->port;
282 int do_clocal = 0, extra_count = 0;
294 IRDA_DEBUG(1,
"%s(), O_NONBLOCK requested!\n", __func__ );
298 if (tty->termios.c_cflag &
CLOCAL) {
299 IRDA_DEBUG(1,
"%s(), doing CLOCAL!\n", __func__ );
313 IRDA_DEBUG(2,
"%s(%d):block_til_ready before block on %s open_count=%d\n",
314 __FILE__, __LINE__, tty->
driver->name, port->
count);
321 spin_unlock_irqrestore(&port->
lock, flags);
325 if (tty->termios.c_cflag &
CBAUD)
354 IRDA_DEBUG(1,
"%s(%d):block_til_ready blocking on %s open_count=%d\n",
355 __FILE__, __LINE__, tty->
driver->name, port->
count);
367 spin_unlock_irqrestore(&port->
lock, flags);
371 IRDA_DEBUG(1,
"%s(%d):block_til_ready after blocking on %s open_count=%d\n",
372 __FILE__, __LINE__, tty->
driver->name, port->
count);
392 IRDA_ERROR(
"%s(), kmalloc failed!\n", __func__);
397 self->port.ops = &ircomm_port_ops;
402 INIT_WORK(&self->tqueue, ircomm_tty_do_softint);
417 tty->termios.c_iflag = 0;
418 tty->termios.c_oflag = 0;
436 static int ircomm_tty_open(
struct tty_struct *tty,
struct file *filp)
447 spin_unlock_irqrestore(&self->port.lock, flags);
451 self->line, self->port.count);
472 IRDA_WARNING(
"%s - got signal while blocking on ASYNC_CLOSING!\n",
477 #ifdef SERIAL_DO_RESTART
486 if (self->line < 0x10) {
491 IRDA_DEBUG(2,
"%s(), IrCOMM device\n", __func__ );
493 IRDA_DEBUG(2,
"%s(), IrLPT device\n", __func__ );
498 ret = ircomm_tty_startup(
self);
502 ret = ircomm_tty_block_til_ready(
self, tty, filp);
505 "%s(), returning after block_til_ready with %d\n", __func__ ,
519 static void ircomm_tty_close(
struct tty_struct *tty,
struct file *filp)
522 struct tty_port *port = &self->port;
532 ircomm_tty_shutdown(
self);
546 static void ircomm_tty_flush_buffer(
struct tty_struct *tty)
587 ctrl_skb =
self->ctrl_skb;
588 self->ctrl_skb =
NULL;
590 spin_unlock_irqrestore(&self->spinlock, flags);
597 dev_kfree_skb(ctrl_skb);
609 spin_unlock_irqrestore(&self->spinlock, flags);
632 static int ircomm_tty_write(
struct tty_struct *tty,
633 const unsigned char *
buf,
int count)
642 IRDA_DEBUG(2,
"%s(), count=%d, hw_stopped=%d\n", __func__ , count,
665 IRDA_DEBUG(1,
"%s() : not initialised\n", __func__);
666 #ifdef IRCOMM_NO_TX_BEFORE_INIT
693 if (
size > self->max_data_size)
694 size =
self->max_data_size;
710 if ((tailroom = (self->tx_data_size - skb->
len)) > 0) {
723 skb = alloc_skb(self->max_data_size+
724 self->max_header_size,
727 spin_unlock_irqrestore(&self->spinlock, flags);
730 skb_reserve(skb, self->max_header_size);
734 self->tx_data_size =
self->max_data_size;
744 spin_unlock_irqrestore(&self->spinlock, flags);
765 static int ircomm_tty_write_room(
struct tty_struct *tty)
774 #ifdef IRCOMM_NO_TX_BEFORE_INIT
789 ret =
self->tx_data_size -
self->tx_skb->len;
791 ret =
self->max_data_size;
792 spin_unlock_irqrestore(&self->spinlock, flags);
794 IRDA_DEBUG(2,
"%s(), ret=%d\n", __func__ , ret);
805 static void ircomm_tty_wait_until_sent(
struct tty_struct *tty,
int timeout)
808 unsigned long orig_jiffies, poll_time;
822 while (self->tx_skb && self->tx_skb->len) {
823 spin_unlock_irqrestore(&self->spinlock, flags);
828 if (timeout &&
time_after(jiffies, orig_jiffies + timeout))
831 spin_unlock_irqrestore(&self->spinlock, flags);
842 static void ircomm_tty_throttle(
struct tty_struct *tty)
853 ircomm_tty_send_xchar(tty,
STOP_CHAR(tty));
856 if (tty->termios.c_cflag &
CRTSCTS) {
873 static void ircomm_tty_unthrottle(
struct tty_struct *tty)
888 if (tty->termios.c_cflag &
CRTSCTS) {
892 IRDA_DEBUG(1,
"%s(), FLOW_START\n", __func__ );
903 static int ircomm_tty_chars_in_buffer(
struct tty_struct *tty)
915 len =
self->tx_skb->len;
917 spin_unlock_irqrestore(&self->spinlock, flags);
941 if (self->ctrl_skb) {
942 dev_kfree_skb(self->ctrl_skb);
943 self->ctrl_skb =
NULL;
948 dev_kfree_skb(self->tx_skb);
957 spin_unlock_irqrestore(&self->spinlock, flags);
967 static void ircomm_tty_hangup(
struct tty_struct *tty)
970 struct tty_port *port = &self->port;
979 ircomm_tty_shutdown(
self);
989 spin_unlock_irqrestore(&port->
lock, flags);
1000 static void ircomm_tty_send_xchar(
struct tty_struct *tty,
char ch)
1002 IRDA_DEBUG(0,
"%s(), not impl\n", __func__ );
1024 static void ircomm_tty_stop(
struct tty_struct *tty)
1053 status =
self->settings.dce;
1060 "%s(), ircomm%d CD now %s...\n", __func__ , self->line,
1063 if (status & IRCOMM_CD) {
1067 "%s(), Doing serial hangup..\n", __func__ );
1075 if (tty && tty_port_cts_enabled(&self->port)) {
1079 "%s(), CTS tx start...\n", __func__ );
1091 "%s(), CTS tx stop...\n", __func__ );
1106 static int ircomm_tty_data_indication(
void *instance,
void *sap,
1130 if (tty->hw_stopped && (self->flow ==
FLOW_START)) {
1131 IRDA_DEBUG(0,
"%s(), polling for line settings!\n", __func__ );
1143 tty_insert_flip_string(tty, skb->
data, skb->
len);
1158 static int ircomm_tty_control_indication(
void *instance,
void *sap,
1170 clen = skb->
data[0];
1187 static void ircomm_tty_flow_indication(
void *instance,
void *sap,
1200 IRDA_DEBUG(2,
"%s(), hw start!\n", __func__ );
1209 IRDA_DEBUG(2,
"%s(), hw stopped!\n", __func__ );
1219 #ifdef CONFIG_PROC_FS
1235 seq_puts(m,
"No common service type!\n");
1238 seq_printf(m,
"Port name: %s\n", self->settings.port_name);
1273 if (!self->settings.null_modem)
1276 seq_puts(m,
"DTE <-> DTE (null modem emulation)\n");
1278 seq_printf(m,
"Data rate: %d\n", self->settings.data_rate);
1318 if (tty_port_cts_enabled(&self->port)) {
1344 seq_printf(m,
"Role: %s\n", self->client ?
"client" :
"server");
1346 seq_printf(m,
"Max data size: %d\n", self->max_data_size);
1347 seq_printf(m,
"Max header size: %d\n", self->max_header_size);
1357 static int ircomm_tty_proc_show(
struct seq_file *m,
void *
v)
1360 unsigned long flags;
1365 while (
self !=
NULL) {
1369 ircomm_tty_line_info(
self, m);
1372 spin_unlock_irqrestore(&ircomm_tty->
hb_spinlock, flags);
1383 .open = ircomm_tty_proc_open,