From: Alan Cox <alan@linux.intel.com>
To: greg@kroah.com, linux-serial@vger.kernel.org
Subject: [PATCH 2/4] serial: add port helpers
Date: Wed, 19 May 2010 13:14:02 +0100 [thread overview]
Message-ID: <20100519121401.18011.12819.stgit@localhost.localdomain> (raw)
In-Reply-To: <20100519121234.18011.51870.stgit@localhost.localdomain>
We can make this the same as the ones that will be needed by the tty_port
helper logic that we want to move to but still call them from the existing
code base.
Signed-off-by: Alan Cox <alan@linux.intel.com>
---
drivers/serial/serial_core.c | 51 ++++++++++++++++++++++++++++++------------
1 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 424b1c7..2379045 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -1501,6 +1501,34 @@ static void uart_update_termios(struct tty_struct *tty,
}
}
+static int uart_carrier_raised(struct tty_port *port)
+{
+ struct uart_state *state = container_of(port, struct uart_state, port);
+ struct uart_port *uport = state->uart_port;
+ int mctrl;
+ mutex_lock(&port->mutex);
+ spin_lock_irq(&uport->lock);
+ uport->ops->enable_ms(uport);
+ mctrl = uport->ops->get_mctrl(uport);
+ spin_unlock_irq(&uport->lock);
+ mutex_unlock(&port->mutex);
+ if (mctrl & TIOCM_CAR)
+ return 1;
+ return 0;
+}
+
+static void uart_dtr_rts(struct tty_port *port, int onoff)
+{
+ struct uart_state *state = container_of(port, struct uart_state, port);
+ struct uart_port *uport = state->uart_port;
+ mutex_lock(&port->mutex);
+ if (onoff)
+ uart_set_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
+ else
+ uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
+ mutex_unlock(&port->mutex);
+}
+
/*
* Block the open until the port is ready. We must be called with
* the per-port semaphore held.
@@ -1509,9 +1537,7 @@ static int
uart_block_til_ready(struct file *filp, struct uart_state *state)
{
DECLARE_WAITQUEUE(wait, current);
- struct uart_port *uport = state->uart_port;
struct tty_port *port = &state->port;
- unsigned int mctrl;
unsigned long flags;
spin_lock_irqsave(&port->lock, flags);
@@ -1555,23 +1581,14 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
* not set RTS here - we want to make sure we catch
* the data from the modem.
*/
- if (port->tty->termios->c_cflag & CBAUD) {
- mutex_lock(&port->mutex);
- uart_set_mctrl(uport, TIOCM_DTR);
- mutex_unlock(&port->mutex);
- }
+ if (port->tty->termios->c_cflag & CBAUD)
+ tty_port_raise_dtr_rts(port);
/*
* and wait for the carrier to indicate that the
* modem is ready for us.
*/
- mutex_lock(&port->mutex);
- spin_lock_irq(&uport->lock);
- uport->ops->enable_ms(uport);
- mctrl = uport->ops->get_mctrl(uport);
- spin_unlock_irq(&uport->lock);
- mutex_unlock(&port->mutex);
- if (mctrl & TIOCM_CAR)
+ if (tty_port_carrier_raised(port))
break;
schedule();
@@ -2349,6 +2366,11 @@ static const struct tty_operations uart_ops = {
#endif
};
+static const struct tty_port_operations uart_port_ops = {
+ .carrier_raised = uart_carrier_raised,
+ .dtr_rts = uart_dtr_rts,
+};
+
/**
* uart_register_driver - register a driver with the uart core layer
* @drv: low level driver structure
@@ -2405,6 +2427,7 @@ int uart_register_driver(struct uart_driver *drv)
struct tty_port *port = &state->port;
tty_port_init(port);
+ port->ops = &uart_port_ops;
port->close_delay = 500; /* .5 seconds */
port->closing_wait = 30000; /* 30 seconds */
tasklet_init(&state->tlet, uart_tasklet_action,
next prev parent reply other threads:[~2010-05-19 12:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-19 12:13 [PATCH 0/4] serial: move towards tty_port Alan Cox
2010-05-19 12:13 ` [PATCH 1/4] serial: Change the wait for carrier locking Alan Cox
2010-05-19 12:14 ` Alan Cox [this message]
2010-05-19 12:14 ` [PATCH 3/4] serial: trim locking on the helpers Alan Cox
2010-05-19 12:14 ` [PATCH 4/4] serial: Use block_til_ready helper Alan Cox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100519121401.18011.12819.stgit@localhost.localdomain \
--to=alan@linux.intel.com \
--cc=greg@kroah.com \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).