[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20091121134007.16090.92417.stgit@srv002.fuzzey.net>
Date: Sat, 21 Nov 2009 14:40:07 +0100
From: Martin Fuzzey <mfuzzey@...il.com>
To: tsbogend@...ha.franken.de, linux-serial@...r.kernel.org
Cc: linux-kernel@...r.kernel.org
Subject: [RFC PATCH 4/9] Serial: sc26xx - add accessor function for driver
data.
Extract container_of and port -= line to a helper function
to avoid slightly opaque modification of port pointer.
Signed-off-by: Martin Fuzzey <mfuzzey@...il.com>
---
drivers/serial/sc26xx.c | 31 ++++++++++++-------------------
1 files changed, 12 insertions(+), 19 deletions(-)
diff --git a/drivers/serial/sc26xx.c b/drivers/serial/sc26xx.c
index ca74bf6..dc47d4f 100644
--- a/drivers/serial/sc26xx.c
+++ b/drivers/serial/sc26xx.c
@@ -95,6 +95,12 @@ struct uart_sc26xx_port {
#define IMR_RXRDY (1 << 1)
#define IMR_TXRDY (1 << 0)
+static struct uart_sc26xx_port *driver_info(struct uart_port *port)
+{
+ port -= port->line;
+ return container_of(port, struct uart_sc26xx_port, port[0]);
+}
+
/* access port register */
static inline u8 read_sc_port(struct uart_port *p, u8 reg)
{
@@ -111,25 +117,17 @@ static inline void write_sc_port(struct uart_port *p, u8 reg, u8 val)
static void sc26xx_enable_irq(struct uart_port *port, int mask)
{
- struct uart_sc26xx_port *up;
- int line = port->line;
-
- port -= line;
- up = container_of(port, struct uart_sc26xx_port, port[0]);
+ struct uart_sc26xx_port *up = driver_info(port);
- up->imr |= mask << (line * 4);
+ up->imr |= mask << (port->line * 4);
WRITE_SC(port, IMR, up->imr);
}
static void sc26xx_disable_irq(struct uart_port *port, int mask)
{
- struct uart_sc26xx_port *up;
- int line = port->line;
-
- port -= line;
- up = container_of(port, struct uart_sc26xx_port, port[0]);
+ struct uart_sc26xx_port *up = driver_info(port);
- up->imr &= ~(mask << (line * 4));
+ up->imr &= ~(mask << (port->line * 4));
WRITE_SC(port, IMR, up->imr);
}
@@ -257,12 +255,9 @@ static unsigned int sc26xx_tx_empty(struct uart_port *port)
/* port->lock held by caller. */
static void sc26xx_set_mctrl(struct uart_port *port, unsigned int mctrl)
{
- struct uart_sc26xx_port *up;
+ struct uart_sc26xx_port *up = driver_info(port);
int line = port->line;
- port -= line;
- up = container_of(port, struct uart_sc26xx_port, port[0]);
-
if (up->dtr_mask[line]) {
if (mctrl & TIOCM_DTR)
WRITE_SC(port, OPR_SET, up->dtr_mask[line]);
@@ -280,13 +275,11 @@ static void sc26xx_set_mctrl(struct uart_port *port, unsigned int mctrl)
/* port->lock is held by caller and interrupts are disabled. */
static unsigned int sc26xx_get_mctrl(struct uart_port *port)
{
- struct uart_sc26xx_port *up;
+ struct uart_sc26xx_port *up = driver_info(port);
int line = port->line;
unsigned int mctrl = TIOCM_DSR | TIOCM_CTS | TIOCM_CAR;
u8 ipr;
- port -= line;
- up = container_of(port, struct uart_sc26xx_port, port[0]);
ipr = READ_SC(port, IPR) ^ 0xff;
if (up->dsr_mask[line]) {
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists