mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-kernel@vger.kernel.org
Cc: Alan Cox <alan@linux.intel.com>, Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 47/58] tty: moxa: Use more tty_port ops
Date: Fri, 11 Dec 2009 15:28:31 -0800	[thread overview]
Message-ID: <1260574122-10676-47-git-send-email-gregkh@suse.de> (raw)
In-Reply-To: <20091211232805.GA10652@kroah.com>

From: Alan Cox <alan@linux.intel.com>

Rework a few bits of this into tty_port format

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/char/moxa.c |  137 ++++++++-------------------------------------------
 1 files changed, 21 insertions(+), 116 deletions(-)

diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index dd0083b..d8bcbed 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -206,8 +206,9 @@ static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
 static void moxa_poll(unsigned long);
 static void moxa_set_tty_param(struct tty_struct *, struct ktermios *);
 static void moxa_setup_empty_event(struct tty_struct *);
-static void moxa_shut_down(struct tty_struct *);
+static void moxa_shutdown(struct tty_port *);
 static int moxa_carrier_raised(struct tty_port *);
+static void moxa_dtr_rts(struct tty_port *, int);
 /*
  * moxa board interface functions:
  */
@@ -409,6 +410,8 @@ static const struct tty_operations moxa_ops = {
 
 static const struct tty_port_operations moxa_port_ops = {
 	.carrier_raised = moxa_carrier_raised,
+	.dtr_rts = moxa_dtr_rts,
+	.shutdown = moxa_shutdown,
 };
 
 static struct tty_driver *moxaDriver;
@@ -1112,14 +1115,12 @@ static void __exit moxa_exit(void)
 module_init(moxa_init);
 module_exit(moxa_exit);
 
-static void moxa_close_port(struct tty_struct *tty)
+static void moxa_shutdown(struct tty_port *port)
 {
-	struct moxa_port *ch = tty->driver_data;
-	moxa_shut_down(tty);
+	struct moxa_port *ch = container_of(port, struct moxa_port, port);
+        MoxaPortDisable(ch);
 	MoxaPortFlushData(ch, 2);
-	ch->port.flags &= ~ASYNC_NORMAL_ACTIVE;
-	tty->driver_data = NULL;
-	tty_port_tty_set(&ch->port, NULL);
+	clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
 }
 
 static int moxa_carrier_raised(struct tty_port *port)
@@ -1133,39 +1134,13 @@ static int moxa_carrier_raised(struct tty_port *port)
 	return dcd;
 }
 
-static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
-			    struct moxa_port *ch)
+static void moxa_dtr_rts(struct tty_port *port, int onoff)
 {
-	struct tty_port *port = &ch->port;
-	DEFINE_WAIT(wait);
-	int retval = 0;
-	u8 dcd;
-
-	while (1) {
-		prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE);
-		if (tty_hung_up_p(filp)) {
-#ifdef SERIAL_DO_RESTART
-			retval = -ERESTARTSYS;
-#else
-			retval = -EAGAIN;
-#endif
-			break;
-		}
-		dcd = tty_port_carrier_raised(port);
-		if (dcd)
-			break;
-
-		if (signal_pending(current)) {
-			retval = -ERESTARTSYS;
-			break;
-		}
-		schedule();
-	}
-	finish_wait(&port->open_wait, &wait);
-
-	return retval;
+	struct moxa_port *ch = container_of(port, struct moxa_port, port);
+	MoxaPortLineCtrl(ch, onoff, onoff);
 }
 
+
 static int moxa_open(struct tty_struct *tty, struct file *filp)
 {
 	struct moxa_board_conf *brd;
@@ -1194,6 +1169,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
 	ch->port.count++;
 	tty->driver_data = ch;
 	tty_port_tty_set(&ch->port, tty);
+	mutex_lock(&ch->port.mutex);
 	if (!(ch->port.flags & ASYNC_INITIALIZED)) {
 		ch->statusflags = 0;
 		moxa_set_tty_param(tty, tty->termios);
@@ -1202,57 +1178,21 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
 		MoxaSetFifo(ch, ch->type == PORT_16550A);
 		ch->port.flags |= ASYNC_INITIALIZED;
 	}
+	mutex_unlock(&ch->port.mutex);
 	mutex_unlock(&moxa_openlock);
 
-	retval = 0;
-	if (!(filp->f_flags & O_NONBLOCK) && !C_CLOCAL(tty))
-		retval = moxa_block_till_ready(tty, filp, ch);
-	mutex_lock(&moxa_openlock);
-	if (retval) {
-		if (ch->port.count) /* 0 means already hung up... */
-			if (--ch->port.count == 0)
-				moxa_close_port(tty);
-	} else
-		ch->port.flags |= ASYNC_NORMAL_ACTIVE;
-	mutex_unlock(&moxa_openlock);
-
+	retval = tty_port_block_til_ready(&ch->port, tty, filp);
+	if (retval == 0)
+	        set_bit(ASYNCB_NORMAL_ACTIVE, &ch->port.flags);
 	return retval;
 }
 
 static void moxa_close(struct tty_struct *tty, struct file *filp)
 {
-	struct moxa_port *ch;
-	int port;
-
-	port = tty->index;
-	if (port == MAX_PORTS || tty_hung_up_p(filp))
-		return;
-
-	mutex_lock(&moxa_openlock);
-	ch = tty->driver_data;
-	if (ch == NULL)
-		goto unlock;
-	if (tty->count == 1 && ch->port.count != 1) {
-		printk(KERN_WARNING "moxa_close: bad serial port count; "
-			"tty->count is 1, ch->port.count is %d\n", ch->port.count);
-		ch->port.count = 1;
-	}
-	if (--ch->port.count < 0) {
-		printk(KERN_WARNING "moxa_close: bad serial port count, "
-			"device=%s\n", tty->name);
-		ch->port.count = 0;
-	}
-	if (ch->port.count)
-		goto unlock;
-
+	struct moxa_port *ch = tty->driver_data;
 	ch->cflag = tty->termios->c_cflag;
-	if (ch->port.flags & ASYNC_INITIALIZED) {
-		moxa_setup_empty_event(tty);
-		tty_wait_until_sent(tty, 30 * HZ);	/* 30 seconds timeout */
-	}
-
-	moxa_close_port(tty);
-unlock:
+	mutex_lock(&moxa_openlock);
+	tty_port_close(&ch->port, tty, filp);
 	mutex_unlock(&moxa_openlock);
 }
 
@@ -1300,14 +1240,6 @@ static int moxa_chars_in_buffer(struct tty_struct *tty)
 	struct moxa_port *ch = tty->driver_data;
 	int chars;
 
-	/*
-	 * Sigh...I have to check if driver_data is NULL here, because
-	 * if an open() fails, the TTY subsystem eventually calls
-	 * tty_wait_until_sent(), which calls the driver's chars_in_buffer()
-	 * routine.  And since the open() failed, we return 0 here.  TDJ
-	 */
-	if (ch == NULL)
-		return 0;
 	lock_kernel();
 	chars = MoxaPortTxQueue(ch);
 	if (chars) {
@@ -1436,15 +1368,8 @@ static void moxa_hangup(struct tty_struct *tty)
 
 	mutex_lock(&moxa_openlock);
 	ch = tty->driver_data;
-	if (ch == NULL) {
-		mutex_unlock(&moxa_openlock);
-		return;
-	}
-	ch->port.count = 0;
-	moxa_close_port(tty);
+	tty_port_hangup(&ch->port);
 	mutex_unlock(&moxa_openlock);
-
-	wake_up_interruptible(&ch->port.open_wait);
 }
 
 static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
@@ -1597,26 +1522,6 @@ static void moxa_setup_empty_event(struct tty_struct *tty)
 	spin_unlock_bh(&moxa_lock);
 }
 
-static void moxa_shut_down(struct tty_struct *tty)
-{
-	struct moxa_port *ch = tty->driver_data;
-
-	if (!(ch->port.flags & ASYNC_INITIALIZED))
-		return;
-
-	MoxaPortDisable(ch);
-
-	/*
-	 * If we're a modem control device and HUPCL is on, drop RTS & DTR.
-	 */
-	if (C_HUPCL(tty))
-		MoxaPortLineCtrl(ch, 0, 0);
-
-	spin_lock_bh(&moxa_lock);
-	ch->port.flags &= ~ASYNC_INITIALIZED;
-	spin_unlock_bh(&moxa_lock);
-}
-
 /*****************************************************************************
  *	Driver level functions: 					     *
  *****************************************************************************/
-- 
1.6.5.5


  parent reply	other threads:[~2009-12-11 23:33 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-11 23:28 [GIT PATCH] TTY patches for 2.6.33-git Greg KH
2009-12-11 23:27 ` [PATCH 01/58] jsm: IRQ handlers doesn't need to have IRQ_DISABLED enabled Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 02/58] jsm: Rewriting a bad log message Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 03/58] jsm: remove the ch_custom_speed field Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 04/58] jsm: removing ch_old_baud field Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 05/58] jsm: Remove ch_cpstime field Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 06/58] jsm: Removing unused jsm_channel->ch_wopen field Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 07/58] jsm: removing the field jsm_board->intr_count Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 08/58] jsm: adding EEH handlers Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 09/58] tty: const: constify remaining tty_operations Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 10/58] tty: esp: remove broken driver Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 11/58] tty: istallion: Kill off the BKL ioctl Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 12/58] tty: stallion: kill " Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 13/58] tty_port: add "tty_port_open" helper Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 14/58] tty_port: coding style cleaning pass Greg Kroah-Hartman
2009-12-11 23:27 ` [PATCH 15/58] usb_serial: Use the shutdown() operation Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 16/58] usb_serial: Kill port mutex Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 17/58] opticon: Fix resume logic Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 18/58] serial: fix NULL pointer dereference Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 19/58] serial: cascade needless conditionals Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 20/58] serial, 8250: calculate irqflags bitmask before loop Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 21/58] Serial: pxa: work around Errata #75 Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 22/58] tty: docs: serial/tty, add to ldisc methods Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 23/58] Serial: Do not read IIR in serial8250_start_tx when UART_BUG_TXEN Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 24/58] devpts_get_tty() should validate inode Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 25/58] tty_port: Move hupcl handling Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 26/58] sdio_uart: use tty_port Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 27/58] sdio_uart: Fix oops caused by the previous changeset Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 28/58] sdio_uart: refcount the tty objects Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 29/58] sdio_uart: Move the open lock Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 30/58] tty: sdio_uart: Switch to the open/close helpers Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 31/58] tty: sdio_uart: Fix termios handling Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 32/58] tty: sdio_uart: Style fixes Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 33/58] tty: sdio_uart: add modem functionality Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 34/58] tty: sdio_uart: Fix the locking on "func" for new code Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 35/58] tty: tty_port: Change the buffer allocator locking Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 36/58] tty: riscom8: switch to the tty_port_open API Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 37/58] tty: tty_port: Add IO_ERROR bit handling Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 38/58] tty: tty_port: Move the IO_ERROR clear Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 39/58] tty: stallion: Convert to the tty_port_open/close methods Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 40/58] tty: istallion: tty port open/close methods Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 41/58] tty: tty_port: Add a kref object to the tty port Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 42/58] tty: isicom: switch to the new tty_port_open helper Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 43/58] tty: isicom: sort out the board init logic Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 44/58] tty: mxser: use the tty_port_open method Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 45/58] tty: mxser: Use the new locking rules to fix setserial properly Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 46/58] tty: isicom: fix deadlock on shutdown Greg Kroah-Hartman
2009-12-11 23:28 ` Greg Kroah-Hartman [this message]
2009-12-11 23:28 ` [PATCH 48/58] tty: moxa: rework the locking a bit Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 49/58] tty: moxa: Locking clean up Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 50/58] tty: moxa: Kill off the throttle method Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 51/58] tty: moxa: Fix modem op locking Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 52/58] tty: moxa: Kill the use of lock_kernel Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 53/58] tty: moxa: split open lock Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 54/58] tty: push the BKL down into the handlers a bit Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 55/58] tty: Push the lock down further into the ldisc code Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 56/58] tty: Push the bkl down a bit in the hangup code Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 57/58] tty: Move the leader test in disassociate Greg Kroah-Hartman
2009-12-11 23:28 ` [PATCH 58/58] tty: split the lock up a bit further Greg Kroah-Hartman
2009-12-12  8:46 ` [GIT PATCH] TTY patches for 2.6.33-git Ingo Molnar
2009-12-12  9:39   ` Andrew Morton
2009-12-12 10:06     ` Ingo Molnar
2009-12-12 10:15       ` Ingo Molnar
2009-12-12 10:41         ` Andrew Morton
2009-12-12 10:52           ` Ingo Molnar
2009-12-12 10:10     ` Ingo Molnar
2009-12-12 10:36       ` Andrew Morton
2009-12-12 17:16         ` Linus Torvalds
2009-12-12 17:26           ` Linus Torvalds
2009-12-12 21:42             ` Alan Cox
2009-12-12 21:48               ` Thomas Gleixner
2009-12-12 22:25                 ` Linus Torvalds
2009-12-12 22:31                   ` Thomas Gleixner
2009-12-12 22:21               ` Linus Torvalds
2009-12-12 22:33                 ` Thomas Gleixner
2009-12-12 23:17                   ` Linus Torvalds
2009-12-13  6:58                     ` Ingo Molnar
2009-12-13 11:36                       ` Alan Cox
2009-12-13 12:13                         ` Ingo Molnar
2009-12-13 17:46                       ` Linus Torvalds
2009-12-13 18:17                         ` Ingo Molnar
2009-12-13 18:33                           ` Trond Myklebust
2009-12-13 19:07                             ` Linus Torvalds
2009-12-13 19:17                               ` Trond Myklebust
2009-12-13 19:04                           ` Frederic Weisbecker
2009-12-13 19:09                             ` Trond Myklebust
2009-12-13 19:19                               ` Linus Torvalds
2009-12-13 20:04                                 ` Trond Myklebust
2009-12-13 19:20                               ` Frederic Weisbecker
2009-12-13 17:55                       ` Arjan van de Ven
2009-12-13 19:16                         ` Frederic Weisbecker
2009-12-14  5:30                           ` Arjan van de Ven
2009-12-14 10:39                             ` Oliver Neukum
2009-12-14 16:02                               ` Arjan van de Ven
2009-12-16  9:15                             ` Arnd Bergmann
2009-12-12 11:02     ` Alan Cox
2009-12-12 22:34       ` Thomas Gleixner
2009-12-12 10:42   ` Alan Cox
2009-12-12 10:42     ` Ingo Molnar

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=1260574122-10676-47-git-send-email-gregkh@suse.de \
    --to=gregkh@suse.de \
    --cc=alan@linux.intel.com \
    --cc=linux-kernel@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

Powered by JetHome