Commit 338818fd802a6baacb7e5b6910d52c8996ca6d28

Authored by Alan Cox
Committed by Greg Kroah-Hartman
1 parent 047e9658ae

tty: istallion: tty port open/close methods

Slice/dice/repeat as with the stallion driver this is just code shuffling
and removal

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 1 changed file with 60 additions and 117 deletions Side-by-side Diff

drivers/char/istallion.c
... ... @@ -213,7 +213,6 @@
213 213 * with the slave. Most of them need to be updated atomically, so always
214 214 * use the bit setting operations (unless protected by cli/sti).
215 215 */
216   -#define ST_INITIALIZING 1
217 216 #define ST_OPENING 2
218 217 #define ST_CLOSING 3
219 218 #define ST_CMDING 4
220 219  
221 220  
... ... @@ -783,13 +782,32 @@
783 782  
784 783 /*****************************************************************************/
785 784  
  785 +/*
  786 + * On the first open of the device setup the port hardware, and
  787 + * initialize the per port data structure. Since initializing the port
  788 + * requires several commands to the board we will need to wait for any
  789 + * other open that is already initializing the port.
  790 + *
  791 + * Locking: protected by the port mutex.
  792 + */
  793 +
  794 +static int stli_activate(struct tty_port *port, struct tty_struct *tty)
  795 +{
  796 + struct stliport *portp = container_of(port, struct stliport, port);
  797 + struct stlibrd *brdp = stli_brds[portp->brdnr];
  798 + int rc;
  799 +
  800 + if ((rc = stli_initopen(tty, brdp, portp)) >= 0)
  801 + clear_bit(TTY_IO_ERROR, &tty->flags);
  802 + wake_up_interruptible(&portp->raw_wait);
  803 + return rc;
  804 +}
  805 +
786 806 static int stli_open(struct tty_struct *tty, struct file *filp)
787 807 {
788 808 struct stlibrd *brdp;
789 809 struct stliport *portp;
790   - struct tty_port *port;
791 810 unsigned int minordev, brdnr, portnr;
792   - int rc;
793 811  
794 812 minordev = tty->index;
795 813 brdnr = MINOR2BRD(minordev);
796 814  
797 815  
798 816  
799 817  
800 818  
801 819  
802 820  
803 821  
804 822  
805 823  
806 824  
807 825  
... ... @@ -809,97 +827,58 @@
809 827 return -ENODEV;
810 828 if (portp->devnr < 1)
811 829 return -ENODEV;
812   - port = &portp->port;
813   -
814   -/*
815   - * On the first open of the device setup the port hardware, and
816   - * initialize the per port data structure. Since initializing the port
817   - * requires several commands to the board we will need to wait for any
818   - * other open that is already initializing the port.
819   - *
820   - * Review - locking
821   - */
822   - tty_port_tty_set(port, tty);
823   - tty->driver_data = portp;
824   - port->count++;
825   -
826   - wait_event_interruptible(portp->raw_wait,
827   - !test_bit(ST_INITIALIZING, &portp->state));
828   - if (signal_pending(current))
829   - return -ERESTARTSYS;
830   -
831   - if ((portp->port.flags & ASYNC_INITIALIZED) == 0) {
832   - set_bit(ST_INITIALIZING, &portp->state);
833   - if ((rc = stli_initopen(tty, brdp, portp)) >= 0) {
834   - /* Locking */
835   - port->flags |= ASYNC_INITIALIZED;
836   - clear_bit(TTY_IO_ERROR, &tty->flags);
837   - }
838   - clear_bit(ST_INITIALIZING, &portp->state);
839   - wake_up_interruptible(&portp->raw_wait);
840   - if (rc < 0)
841   - return rc;
842   - }
843   - return tty_port_block_til_ready(&portp->port, tty, filp);
  830 + return tty_port_open(&portp->port, tty, filp);
844 831 }
845 832  
  833 +
846 834 /*****************************************************************************/
847 835  
848   -static void stli_close(struct tty_struct *tty, struct file *filp)
  836 +static void stli_shutdown(struct tty_port *port)
849 837 {
850 838 struct stlibrd *brdp;
851   - struct stliport *portp;
852   - struct tty_port *port;
  839 + unsigned long ftype;
853 840 unsigned long flags;
  841 + struct stliport *portp = container_of(port, struct stliport, port);
854 842  
855   - portp = tty->driver_data;
856   - if (portp == NULL)
  843 + if (portp->brdnr >= stli_nrbrds)
857 844 return;
858   - port = &portp->port;
859   -
860   - if (tty_port_close_start(port, tty, filp) == 0)
  845 + brdp = stli_brds[portp->brdnr];
  846 + if (brdp == NULL)
861 847 return;
862 848  
863   -/*
864   - * May want to wait for data to drain before closing. The BUSY flag
865   - * keeps track of whether we are still transmitting or not. It is
866   - * updated by messages from the slave - indicating when all chars
867   - * really have drained.
868   - */
869   - spin_lock_irqsave(&stli_lock, flags);
870   - if (tty == stli_txcooktty)
871   - stli_flushchars(tty);
872   - spin_unlock_irqrestore(&stli_lock, flags);
  849 + /*
  850 + * May want to wait for data to drain before closing. The BUSY
  851 + * flag keeps track of whether we are still transmitting or not.
  852 + * It is updated by messages from the slave - indicating when all
  853 + * chars really have drained.
  854 + */
873 855  
874   - /* We end up doing this twice for the moment. This needs looking at
875   - eventually. Note we still use portp->closing_wait as a result */
876   - if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
877   - tty_wait_until_sent(tty, portp->closing_wait);
  856 + if (!test_bit(ST_CLOSING, &portp->state))
  857 + stli_rawclose(brdp, portp, 0, 0);
878 858  
879   - /* FIXME: port locking here needs attending to */
880   - port->flags &= ~ASYNC_INITIALIZED;
881   -
882   - brdp = stli_brds[portp->brdnr];
883   - stli_rawclose(brdp, portp, 0, 0);
884   - if (tty->termios->c_cflag & HUPCL) {
885   - stli_mkasysigs(&portp->asig, 0, 0);
886   - if (test_bit(ST_CMDING, &portp->state))
887   - set_bit(ST_DOSIGS, &portp->state);
888   - else
889   - stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
890   - sizeof(asysigs_t), 0);
891   - }
  859 + spin_lock_irqsave(&stli_lock, flags);
892 860 clear_bit(ST_TXBUSY, &portp->state);
893 861 clear_bit(ST_RXSTOP, &portp->state);
894   - set_bit(TTY_IO_ERROR, &tty->flags);
895   - tty_ldisc_flush(tty);
896   - set_bit(ST_DOFLUSHRX, &portp->state);
897   - stli_flushbuffer(tty);
  862 + spin_unlock_irqrestore(&stli_lock, flags);
898 863  
899   - tty_port_close_end(port, tty);
900   - tty_port_tty_set(port, NULL);
  864 + ftype = FLUSHTX | FLUSHRX;
  865 + stli_cmdwait(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
901 866 }
902 867  
  868 +static void stli_close(struct tty_struct *tty, struct file *filp)
  869 +{
  870 + struct stliport *portp = tty->driver_data;
  871 + unsigned long flags;
  872 + if (portp == NULL)
  873 + return;
  874 + spin_lock_irqsave(&stli_lock, flags);
  875 + /* Flush any internal buffering out first */
  876 + if (tty == stli_txcooktty)
  877 + stli_flushchars(tty);
  878 + spin_unlock_irqrestore(&stli_lock, flags);
  879 + tty_port_close(&portp->port, tty, filp);
  880 +}
  881 +
903 882 /*****************************************************************************/
904 883  
905 884 /*
... ... @@ -1724,6 +1703,7 @@
1724 1703  
1725 1704 /*****************************************************************************/
1726 1705  
  1706 +
1727 1707 /*
1728 1708 * Hangup this port. This is pretty much like closing the port, only
1729 1709 * a little more brutal. No waiting for data to drain. Shutdown the
... ... @@ -1733,47 +1713,8 @@
1733 1713  
1734 1714 static void stli_hangup(struct tty_struct *tty)
1735 1715 {
1736   - struct stliport *portp;
1737   - struct stlibrd *brdp;
1738   - struct tty_port *port;
1739   - unsigned long flags;
1740   -
1741   - portp = tty->driver_data;
1742   - if (portp == NULL)
1743   - return;
1744   - if (portp->brdnr >= stli_nrbrds)
1745   - return;
1746   - brdp = stli_brds[portp->brdnr];
1747   - if (brdp == NULL)
1748   - return;
1749   - port = &portp->port;
1750   -
1751   - spin_lock_irqsave(&port->lock, flags);
1752   - port->flags &= ~ASYNC_INITIALIZED;
1753   - spin_unlock_irqrestore(&port->lock, flags);
1754   -
1755   - if (!test_bit(ST_CLOSING, &portp->state))
1756   - stli_rawclose(brdp, portp, 0, 0);
1757   -
1758   - spin_lock_irqsave(&stli_lock, flags);
1759   - if (tty->termios->c_cflag & HUPCL) {
1760   - stli_mkasysigs(&portp->asig, 0, 0);
1761   - if (test_bit(ST_CMDING, &portp->state)) {
1762   - set_bit(ST_DOSIGS, &portp->state);
1763   - set_bit(ST_DOFLUSHTX, &portp->state);
1764   - set_bit(ST_DOFLUSHRX, &portp->state);
1765   - } else {
1766   - stli_sendcmd(brdp, portp, A_SETSIGNALSF,
1767   - &portp->asig, sizeof(asysigs_t), 0);
1768   - }
1769   - }
1770   -
1771   - clear_bit(ST_TXBUSY, &portp->state);
1772   - clear_bit(ST_RXSTOP, &portp->state);
1773   - set_bit(TTY_IO_ERROR, &tty->flags);
1774   - spin_unlock_irqrestore(&stli_lock, flags);
1775   -
1776   - tty_port_hangup(port);
  1716 + struct stliport *portp = tty->driver_data;
  1717 + tty_port_hangup(&portp->port);
1777 1718 }
1778 1719  
1779 1720 /*****************************************************************************/
... ... @@ -4420,6 +4361,8 @@
4420 4361 static const struct tty_port_operations stli_port_ops = {
4421 4362 .carrier_raised = stli_carrier_raised,
4422 4363 .dtr_rts = stli_dtr_rts,
  4364 + .activate = stli_activate,
  4365 + .shutdown = stli_shutdown,
4423 4366 };
4424 4367  
4425 4368 /*****************************************************************************/