[PATCH 13/70] moxa: use tty_port

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-kernel@...>
Date: Friday, June 20, 2008 - 3:59 pm

From: Alan Cox <alan@redhat.com>

Switch MOXA to use the new tty_port structure

Signed-off-by: Alan Cox <alan@redhat.com>
---

 drivers/char/moxa.c |   87 +++++++++++++++++++++++++--------------------------
 1 files changed, 42 insertions(+), 45 deletions(-)


diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index d57d3a6..bb9bcff 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -130,17 +130,14 @@ struct moxaq_str {
 };
 
 struct moxa_port {
+	struct tty_port port;
 	struct moxa_board_conf *board;
-	struct tty_struct *tty;
 	void __iomem *tableAddr;
 
 	int type;
 	int close_delay;
-	unsigned int count;
-	int asyncflags;
 	int cflag;
 	unsigned long statusflags;
-	wait_queue_head_t open_wait;
 
 	u8 DCDState;
 	u8 lineCtrl;
@@ -348,10 +345,10 @@ static int moxa_ioctl(struct tty_struct *tty, struct file *file,
 				if (status & 4)
 					tmp.dcd = 1;
 
-				if (!p->tty || !p->tty->termios)
+				if (!p->port.tty || !p->port.tty->termios)
 					tmp.cflag = p->cflag;
 				else
-					tmp.cflag = p->tty->termios->c_cflag;
+					tmp.cflag = p->port.tty->termios->c_cflag;
 copy:
 				if (copy_to_user(argm, &tmp, sizeof(tmp))) {
 					mutex_unlock(&moxa_openlock);
@@ -828,7 +825,7 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
 		p->type = PORT_16550A;
 		p->close_delay = 5 * HZ / 10;
 		p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
-		init_waitqueue_head(&p->open_wait);
+		tty_port_init(&p->port);
 	}
 
 	switch (brd->boardType) {
@@ -884,12 +881,12 @@ static void moxa_board_deinit(struct moxa_board_conf *brd)
 
 	/* pci hot-un-plug support */
 	for (a = 0; a < brd->numPorts; a++)
-		if (brd->ports[a].asyncflags & ASYNC_INITIALIZED)
-			tty_hangup(brd->ports[a].tty);
+		if (brd->ports[a].port.flags & ASYNC_INITIALIZED)
+			tty_hangup(brd->ports[a].port.tty);
 	while (1) {
 		opened = 0;
 		for (a = 0; a < brd->numPorts; a++)
-			if (brd->ports[a].asyncflags & ASYNC_INITIALIZED)
+			if (brd->ports[a].port.flags & ASYNC_INITIALIZED)
 				opened++;
 		mutex_unlock(&moxa_openlock);
 		if (!opened)
@@ -1104,9 +1101,9 @@ static void moxa_close_port(struct moxa_port *ch)
 {
 	moxa_shut_down(ch);
 	MoxaPortFlushData(ch, 2);
-	ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
-	ch->tty->driver_data = NULL;
-	ch->tty = NULL;
+	ch->port.flags &= ~ASYNC_NORMAL_ACTIVE;
+	ch->port.tty->driver_data = NULL;
+	ch->port.tty = NULL;
 }
 
 static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
@@ -1117,7 +1114,7 @@ static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
 	u8 dcd;
 
 	while (1) {
-		prepare_to_wait(&ch->open_wait, &wait, TASK_INTERRUPTIBLE);
+		prepare_to_wait(&ch->port.open_wait, &wait, TASK_INTERRUPTIBLE);
 		if (tty_hung_up_p(filp)) {
 #ifdef SERIAL_DO_RESTART
 			retval = -ERESTARTSYS;
@@ -1138,7 +1135,7 @@ static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
 		}
 		schedule();
 	}
-	finish_wait(&ch->open_wait, &wait);
+	finish_wait(&ch->port.open_wait, &wait);
 
 	return retval;
 }
@@ -1163,16 +1160,16 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
 	}
 
 	ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
-	ch->count++;
+	ch->port.count++;
 	tty->driver_data = ch;
-	ch->tty = tty;
-	if (!(ch->asyncflags & ASYNC_INITIALIZED)) {
+	ch->port.tty = tty;
+	if (!(ch->port.flags & ASYNC_INITIALIZED)) {
 		ch->statusflags = 0;
 		moxa_set_tty_param(tty, tty->termios);
 		MoxaPortLineCtrl(ch, 1, 1);
 		MoxaPortEnable(ch);
 		MoxaSetFifo(ch, ch->type == PORT_16550A);
-		ch->asyncflags |= ASYNC_INITIALIZED;
+		ch->port.flags |= ASYNC_INITIALIZED;
 	}
 	mutex_unlock(&moxa_openlock);
 
@@ -1181,11 +1178,11 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
 		retval = moxa_block_till_ready(tty, filp, ch);
 	mutex_lock(&moxa_openlock);
 	if (retval) {
-		if (ch->count) /* 0 means already hung up... */
-			if (--ch->count == 0)
+		if (ch->port.count) /* 0 means already hung up... */
+			if (--ch->port.count == 0)
 				moxa_close_port(ch);
 	} else
-		ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
+		ch->port.flags |= ASYNC_NORMAL_ACTIVE;
 	mutex_unlock(&moxa_openlock);
 
 	return retval;
@@ -1204,21 +1201,21 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)
 	ch = tty->driver_data;
 	if (ch == NULL)
 		goto unlock;
-	if (tty->count == 1 && ch->count != 1) {
+	if (tty->count == 1 && ch->port.count != 1) {
 		printk(KERN_WARNING "moxa_close: bad serial port count; "
-			"tty->count is 1, ch->count is %d\n", ch->count);
-		ch->count = 1;
+			"tty->count is 1, ch->port.count is %d\n", ch->port.count);
+		ch->port.count = 1;
 	}
-	if (--ch->count < 0) {
+	if (--ch->port.count < 0) {
 		printk(KERN_WARNING "moxa_close: bad serial port count, "
 			"device=%s\n", tty->name);
-		ch->count = 0;
+		ch->port.count = 0;
 	}
-	if (ch->count)
+	if (ch->port.count)
 		goto unlock;
 
 	ch->cflag = tty->termios->c_cflag;
-	if (ch->asyncflags & ASYNC_INITIALIZED) {
+	if (ch->port.flags & ASYNC_INITIALIZED) {
 		moxa_setup_empty_event(tty);
 		tty_wait_until_sent(tty, 30 * HZ);	/* 30 seconds timeout */
 	}
@@ -1374,7 +1371,7 @@ static void moxa_set_termios(struct tty_struct *tty,
 		return;
 	moxa_set_tty_param(tty, old_termios);
 	if (!(old_termios->c_cflag & CLOCAL) && C_CLOCAL(tty))
-		wake_up_interruptible(&ch->open_wait);
+		wake_up_interruptible(&ch->port.open_wait);
 }
 
 static void moxa_stop(struct tty_struct *tty)
@@ -1412,20 +1409,20 @@ static void moxa_hangup(struct tty_struct *tty)
 		mutex_unlock(&moxa_openlock);
 		return;
 	}
-	ch->count = 0;
+	ch->port.count = 0;
 	moxa_close_port(ch);
 	mutex_unlock(&moxa_openlock);
 
-	wake_up_interruptible(&ch->open_wait);
+	wake_up_interruptible(&ch->port.open_wait);
 }
 
 static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
 {
 	dcd = !!dcd;
 
-	if (dcd != p->DCDState && p->tty && C_CLOCAL(p->tty)) {
+	if (dcd != p->DCDState && p->port.tty && C_CLOCAL(p->port.tty)) {
 		if (!dcd)
-			tty_hangup(p->tty);
+			tty_hangup(p->port.tty);
 	}
 	p->DCDState = dcd;
 }
@@ -1433,9 +1430,9 @@ static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
 static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
 		u16 __iomem *ip)
 {
-	struct tty_struct *tty = p->tty;
+	struct tty_struct *tty = p->port.tty;
 	void __iomem *ofsAddr;
-	unsigned int inited = p->asyncflags & ASYNC_INITIALIZED;
+	unsigned int inited = p->port.flags & ASYNC_INITIALIZED;
 	u16 intr;
 
 	if (tty) {
@@ -1566,9 +1563,9 @@ static void moxa_setup_empty_event(struct tty_struct *tty)
 
 static void moxa_shut_down(struct moxa_port *ch)
 {
-	struct tty_struct *tp = ch->tty;
+	struct tty_struct *tp = ch->port.tty;
 
-	if (!(ch->asyncflags & ASYNC_INITIALIZED))
+	if (!(ch->port.flags & ASYNC_INITIALIZED))
 		return;
 
 	MoxaPortDisable(ch);
@@ -1580,7 +1577,7 @@ static void moxa_shut_down(struct moxa_port *ch)
 		MoxaPortLineCtrl(ch, 0, 0);
 
 	spin_lock_bh(&moxa_lock);
-	ch->asyncflags &= ~ASYNC_INITIALIZED;
+	ch->port.flags &= ~ASYNC_INITIALIZED;
 	spin_unlock_bh(&moxa_lock);
 }
 
@@ -1975,7 +1972,7 @@ static int MoxaPortWriteData(struct moxa_port *port,
 	c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask);
 	if (c > len)
 		c = len;
-	moxaLog.txcnt[port->tty->index] += c;
+	moxaLog.txcnt[port->port.tty->index] += c;
 	total = c;
 	if (spage == epage) {
 		bufhead = readw(ofsAddr + Ofs_txb);
@@ -2017,7 +2014,7 @@ static int MoxaPortWriteData(struct moxa_port *port,
 
 static int MoxaPortReadData(struct moxa_port *port)
 {
-	struct tty_struct *tty = port->tty;
+	struct tty_struct *tty = port->port.tty;
 	unsigned char *dst;
 	void __iomem *baseAddr, *ofsAddr, *ofs;
 	unsigned int count, len, total;
@@ -2124,8 +2121,8 @@ static int moxa_get_serial_info(struct moxa_port *info,
 {
 	struct serial_struct tmp = {
 		.type = info->type,
-		.line = info->tty->index,
-		.flags = info->asyncflags,
+		.line = info->port.tty->index,
+		.flags = info->port.flags,
 		.baud_base = 921600,
 		.close_delay = info->close_delay
 	};
@@ -2148,13 +2145,13 @@ static int moxa_set_serial_info(struct moxa_port *info,
 
 	if (!capable(CAP_SYS_ADMIN)) {
 		if (((new_serial.flags & ~ASYNC_USR_MASK) !=
-		     (info->asyncflags & ~ASYNC_USR_MASK)))
+		     (info->port.flags & ~ASYNC_USR_MASK)))
 			return -EPERM;
 	} else
 		info->close_delay = new_serial.close_delay * HZ / 100;
 
 	new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS);
-	new_serial.flags |= (info->asyncflags & ASYNC_FLAGS);
+	new_serial.flags |= (info->port.flags & ASYNC_FLAGS);
 
 	MoxaSetFifo(info, new_serial.type == PORT_16550A);
 

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/70] tty updates proposed for 2.6.27, Alan Cox, (Fri Jun 20, 3:57 pm)
Re: [PATCH 00/70] tty updates proposed for 2.6.27, Marcel Holtmann, (Sat Jun 21, 9:23 am)
Re: [PATCH 00/70] tty updates proposed for 2.6.27, Johannes Weiner, (Fri Jun 20, 7:39 pm)
[PATCH 70/70] tty-usb-mos7720: Coding style, Alan Cox, (Fri Jun 20, 4:07 pm)
[PATCH 69/70] whiteheat: remove unused variable, Alan Cox, (Fri Jun 20, 4:07 pm)
[PATCH 67/70] omninet: Use string flip functions, Alan Cox, (Fri Jun 20, 4:07 pm)
[PATCH 66/70] tty-usb-omninet: Coding style, Alan Cox, (Fri Jun 20, 4:06 pm)
[PATCH 65/70] tty-usb-option: Coding style, Alan Cox, (Fri Jun 20, 4:06 pm)
[PATCH 64/70] tty-usb-oti6858: Coding style, Alan Cox, (Fri Jun 20, 4:06 pm)
[PATCH 63/70] tty-usb-safe-serial: Coding style, Alan Cox, (Fri Jun 20, 4:06 pm)
[PATCH 62/70] tty-usb-ti-usb: Coding style, Alan Cox, (Fri Jun 20, 4:06 pm)
[PATCH 61/70] tty-usb-spcp8x5: Minor coding style, Alan Cox, (Fri Jun 20, 4:06 pm)
[PATCH 59/70] tty-usb-pl2303: Coding style, Alan Cox, (Fri Jun 20, 4:06 pm)
[PATCH 58/70] mct_u232: Use flip buffer functions, Alan Cox, (Fri Jun 20, 4:05 pm)
[PATCH 57/70] tty-usb-mct-u232: Coding style, Alan Cox, (Fri Jun 20, 4:05 pm)
[PATCH 56/70] kobil_sct: Fix ioctls, Alan Cox, (Fri Jun 20, 4:05 pm)
[PATCH 55/70] tty-usb-kobil-sct: Coding style, Alan Cox, (Fri Jun 20, 4:05 pm)
[PATCH 53/70] tty-usb-kl5kusb105: Coding style, Alan Cox, (Fri Jun 20, 4:05 pm)
[PATCH 52/70] tty-usb-keyspan-pda: Coding style, Alan Cox, (Fri Jun 20, 4:04 pm)
[PATCH 50/70] tty-usb-keyspan: Coding style, Alan Cox, (Fri Jun 20, 4:04 pm)
[PATCH 47/70] tty-usb-ipw: Coding style, Alan Cox, (Fri Jun 20, 4:04 pm)
[PATCH 46/70] ipaq: Coding style, Alan Cox, (Fri Jun 20, 4:04 pm)
[PATCH 45/70] io_ti: Minor coding style, Alan Cox, (Fri Jun 20, 4:04 pm)
[PATCH 44/70] usb-serial: Coding style, Alan Cox, (Fri Jun 20, 4:03 pm)
[PATCH 42/70] tty-usb-io_edgeport: Coding style, Alan Cox, (Fri Jun 20, 4:03 pm)
[PATCH 41/70] tty-usb-visor: Coding style, Alan Cox, (Fri Jun 20, 4:03 pm)
[PATCH 40/70] tty-usb-hp4x: Fix overlong line, Alan Cox, (Fri Jun 20, 4:03 pm)
[PATCH 39/70] tty-usb-generic: Code cleanup, Alan Cox, (Fri Jun 20, 4:03 pm)
[PATCH 38/70] garmin_gps: Coding style, Alan Cox, (Fri Jun 20, 4:03 pm)
[PATCH 37/70] funsoft: Switch to linux/uaccess, Alan Cox, (Fri Jun 20, 4:02 pm)
[PATCH 36/70] ftdi_sio: Coding style, Alan Cox, (Fri Jun 20, 4:02 pm)
[PATCH 35/70] empeg: Coding style, Alan Cox, (Fri Jun 20, 4:02 pm)
[PATCH 34/70] digi_acceleport: coding style, Alan Cox, (Fri Jun 20, 4:02 pm)
[PATCH 32/70] cypress_m8: coding style, Alan Cox, (Fri Jun 20, 4:02 pm)
[PATCH 31/70] cyberjack: Coding style, Alan Cox, (Fri Jun 20, 4:02 pm)
[PATCH 30/70] cp2101: coding style, Alan Cox, (Fri Jun 20, 4:02 pm)
[PATCH 29/70] tty-usb-console: Fix termios, Alan Cox, (Fri Jun 20, 4:01 pm)
[PATCH 27/70] usb-serial-bus: tidy coding style, Alan Cox, (Fri Jun 20, 4:01 pm)
[PATCH 26/70] belkin_sa: clean up code, Alan Cox, (Fri Jun 20, 4:01 pm)
[PATCH 24/70] whiteheat: coding style, Alan Cox, (Fri Jun 20, 4:01 pm)
[PATCH 22/70] tty: add more tty_port fields, Alan Cox, (Fri Jun 20, 4:00 pm)
[PATCH 20/70] cyclades: use tty_port, Alan Cox, (Fri Jun 20, 4:00 pm)
[PATCH 19/70] tty: Clean up tiocmset, Alan Cox, (Fri Jun 20, 4:00 pm)
[PATCH 18/70] synclink: use tty_port, Alan Cox, (Fri Jun 20, 4:00 pm)
[PATCH 17/70] stallion: use tty_port, Alan Cox, (Fri Jun 20, 4:00 pm)
[PATCH 16/70] serial: use tty_port, Alan Cox, (Fri Jun 20, 4:00 pm)
[PATCH 15/70] rocket: use tty_port, Alan Cox, (Fri Jun 20, 4:00 pm)
[PATCH 14/70] mxser: use tty_port, Alan Cox, (Fri Jun 20, 3:59 pm)
[PATCH 13/70] moxa: use tty_port, Alan Cox, (Fri Jun 20, 3:59 pm)
[PATCH 12/70] istallion: use tty_port, Alan Cox, (Fri Jun 20, 3:59 pm)
[PATCH 11/70] isicom: use tty_port, Alan Cox, (Fri Jun 20, 3:59 pm)
[PATCH 10/70] riscom8: remove bogus checks, Alan Cox, (Fri Jun 20, 3:59 pm)
[PATCH 09/70] riscom8: use tty_port, Alan Cox, (Fri Jun 20, 3:59 pm)
[PATCH 08/70] gs: use tty_port, Alan Cox, (Fri Jun 20, 3:59 pm)
[PATCH 07/70] esp: use tty_port, Alan Cox, (Fri Jun 20, 3:59 pm)
[PATCH 06/70] epca: use tty_port, Alan Cox, (Fri Jun 20, 3:59 pm)
[PATCH 05/70] tty.h: clean up, Alan Cox, (Fri Jun 20, 3:58 pm)
[PATCH 02/70] drivers/char/rio/: remove VCS tags, Alan Cox, (Fri Jun 20, 3:58 pm)
[PATCH 01/70] tty: Ldisc revamp, Alan Cox, (Fri Jun 20, 3:58 pm)
Re: [PATCH 01/70] tty: Ldisc revamp, Louis Rilling, (Mon Jun 23, 9:39 am)
Re: [PATCH 01/70] tty: Ldisc revamp, Alan Cox, (Mon Jun 23, 10:11 am)