aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/moxa.c
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2009-01-02 08:45:05 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-02 13:19:38 -0500
commit31f35939d1d9bcfb3099b32c67b896d2792603f9 (patch)
tree39b6ceaf0e7477e0357ff8235814f579adad3f28 /drivers/char/moxa.c
parentc9b3976e3fec266be25c5001a70aa0a890b6c476 (diff)
tty_port: Add a port level carrier detect operation
This is the first step to generalising the various pieces of waiting logic duplicated in all sorts of serial drivers. Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char/moxa.c')
-rw-r--r--drivers/char/moxa.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 12d327a2c9ba..8b0da97d5293 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -206,6 +206,7 @@ static void moxa_poll(unsigned long);
206static void moxa_set_tty_param(struct tty_struct *, struct ktermios *); 206static void moxa_set_tty_param(struct tty_struct *, struct ktermios *);
207static void moxa_setup_empty_event(struct tty_struct *); 207static void moxa_setup_empty_event(struct tty_struct *);
208static void moxa_shut_down(struct tty_struct *); 208static void moxa_shut_down(struct tty_struct *);
209static int moxa_carrier_raised(struct tty_port *);
209/* 210/*
210 * moxa board interface functions: 211 * moxa board interface functions:
211 */ 212 */
@@ -405,6 +406,10 @@ static const struct tty_operations moxa_ops = {
405 .tiocmset = moxa_tiocmset, 406 .tiocmset = moxa_tiocmset,
406}; 407};
407 408
409static const struct tty_port_operations moxa_port_ops = {
410 .carrier_raised = moxa_carrier_raised,
411};
412
408static struct tty_driver *moxaDriver; 413static struct tty_driver *moxaDriver;
409static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0); 414static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0);
410static DEFINE_SPINLOCK(moxa_lock); 415static DEFINE_SPINLOCK(moxa_lock);
@@ -826,6 +831,7 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
826 831
827 for (i = 0, p = brd->ports; i < MAX_PORTS_PER_BOARD; i++, p++) { 832 for (i = 0, p = brd->ports; i < MAX_PORTS_PER_BOARD; i++, p++) {
828 tty_port_init(&p->port); 833 tty_port_init(&p->port);
834 p->port.ops = &moxa_port_ops;
829 p->type = PORT_16550A; 835 p->type = PORT_16550A;
830 p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 836 p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
831 } 837 }
@@ -1115,15 +1121,27 @@ static void moxa_close_port(struct tty_struct *tty)
1115 tty_port_tty_set(&ch->port, NULL); 1121 tty_port_tty_set(&ch->port, NULL);
1116} 1122}
1117 1123
1124static int moxa_carrier_raised(struct tty_port *port)
1125{
1126 struct moxa_port *ch = container_of(port, struct moxa_port, port);
1127 int dcd;
1128
1129 spin_lock_bh(&moxa_lock);
1130 dcd = ch->DCDState;
1131 spin_unlock_bh(&moxa_lock);
1132 return dcd;
1133}
1134
1118static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp, 1135static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
1119 struct moxa_port *ch) 1136 struct moxa_port *ch)
1120{ 1137{
1138 struct tty_port *port = &ch->port;
1121 DEFINE_WAIT(wait); 1139 DEFINE_WAIT(wait);
1122 int retval = 0; 1140 int retval = 0;
1123 u8 dcd; 1141 u8 dcd;
1124 1142
1125 while (1) { 1143 while (1) {
1126 prepare_to_wait(&ch->port.open_wait, &wait, TASK_INTERRUPTIBLE); 1144 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE);
1127 if (tty_hung_up_p(filp)) { 1145 if (tty_hung_up_p(filp)) {
1128#ifdef SERIAL_DO_RESTART 1146#ifdef SERIAL_DO_RESTART
1129 retval = -ERESTARTSYS; 1147 retval = -ERESTARTSYS;
@@ -1132,9 +1150,7 @@ static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
1132#endif 1150#endif
1133 break; 1151 break;
1134 } 1152 }
1135 spin_lock_bh(&moxa_lock); 1153 dcd = tty_port_carrier_raised(port);
1136 dcd = ch->DCDState;
1137 spin_unlock_bh(&moxa_lock);
1138 if (dcd) 1154 if (dcd)
1139 break; 1155 break;
1140 1156
@@ -1144,7 +1160,7 @@ static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
1144 } 1160 }
1145 schedule(); 1161 schedule();
1146 } 1162 }
1147 finish_wait(&ch->port.open_wait, &wait); 1163 finish_wait(&port->open_wait, &wait);
1148 1164
1149 return retval; 1165 return retval;
1150} 1166}