aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial
diff options
context:
space:
mode:
authorAlan Cox <alan@linux.intel.com>2009-09-19 16:13:29 -0400
committerLive-CD User <linux@linux.site>2009-09-19 16:13:29 -0400
commit46d57a449aa13d9c6adcc9d1dbc7b9a0ecfb69d8 (patch)
treec89087fd06012fef52302ed1f7d4f3b07e2b7d92 /drivers/serial
parent5e99df561fc830730d63672d795a0b02ef8cdd6f (diff)
serial: use tty_port pointers in the core code
Extract out a lot of the x.port. uses and also show up where there are things left to be isolated that prevent use using the port helpers in the serial layer at this point Signed-off-by: Alan Cox <alan@linux.intel.com>
Diffstat (limited to 'drivers/serial')
-rw-r--r--drivers/serial/serial_core.c288
1 files changed, 146 insertions, 142 deletions
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 2d63b13e2f7e..0ffefb3f1d8f 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -141,7 +141,8 @@ uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear)
141 */ 141 */
142static int uart_startup(struct uart_state *state, int init_hw) 142static int uart_startup(struct uart_state *state, int init_hw)
143{ 143{
144 struct uart_port *port = state->uart_port; 144 struct uart_port *uport = state->uart_port;
145 struct tty_port *port = &state->port;
145 unsigned long page; 146 unsigned long page;
146 int retval = 0; 147 int retval = 0;
147 148
@@ -153,9 +154,9 @@ static int uart_startup(struct uart_state *state, int init_hw)
153 * once we have successfully opened the port. Also set 154 * once we have successfully opened the port. Also set
154 * up the tty->alt_speed kludge 155 * up the tty->alt_speed kludge
155 */ 156 */
156 set_bit(TTY_IO_ERROR, &state->port.tty->flags); 157 set_bit(TTY_IO_ERROR, &port->tty->flags);
157 158
158 if (port->type == PORT_UNKNOWN) 159 if (uport->type == PORT_UNKNOWN)
159 return 0; 160 return 0;
160 161
161 /* 162 /*
@@ -172,7 +173,7 @@ static int uart_startup(struct uart_state *state, int init_hw)
172 uart_circ_clear(&state->xmit); 173 uart_circ_clear(&state->xmit);
173 } 174 }
174 175
175 retval = port->ops->startup(port); 176 retval = uport->ops->startup(uport);
176 if (retval == 0) { 177 if (retval == 0) {
177 if (init_hw) { 178 if (init_hw) {
178 /* 179 /*
@@ -184,20 +185,20 @@ static int uart_startup(struct uart_state *state, int init_hw)
184 * Setup the RTS and DTR signals once the 185 * Setup the RTS and DTR signals once the
185 * port is open and ready to respond. 186 * port is open and ready to respond.
186 */ 187 */
187 if (state->port.tty->termios->c_cflag & CBAUD) 188 if (port->tty->termios->c_cflag & CBAUD)
188 uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR); 189 uart_set_mctrl(uport, TIOCM_RTS | TIOCM_DTR);
189 } 190 }
190 191
191 if (state->flags & UIF_CTS_FLOW) { 192 if (state->flags & UIF_CTS_FLOW) {
192 spin_lock_irq(&port->lock); 193 spin_lock_irq(&uport->lock);
193 if (!(port->ops->get_mctrl(port) & TIOCM_CTS)) 194 if (!(uport->ops->get_mctrl(uport) & TIOCM_CTS))
194 state->port.tty->hw_stopped = 1; 195 port->tty->hw_stopped = 1;
195 spin_unlock_irq(&port->lock); 196 spin_unlock_irq(&uport->lock);
196 } 197 }
197 198
198 state->flags |= UIF_INITIALIZED; 199 state->flags |= UIF_INITIALIZED;
199 200
200 clear_bit(TTY_IO_ERROR, &state->port.tty->flags); 201 clear_bit(TTY_IO_ERROR, &port->tty->flags);
201 } 202 }
202 203
203 if (retval && capable(CAP_SYS_ADMIN)) 204 if (retval && capable(CAP_SYS_ADMIN))
@@ -672,7 +673,8 @@ static int uart_set_info(struct uart_state *state,
672 struct serial_struct __user *newinfo) 673 struct serial_struct __user *newinfo)
673{ 674{
674 struct serial_struct new_serial; 675 struct serial_struct new_serial;
675 struct uart_port *port = state->uart_port; 676 struct uart_port *uport = state->uart_port;
677 struct tty_port *port = &state->port;
676 unsigned long new_port; 678 unsigned long new_port;
677 unsigned int change_irq, change_port, closing_wait; 679 unsigned int change_irq, change_port, closing_wait;
678 unsigned int old_custom_divisor, close_delay; 680 unsigned int old_custom_divisor, close_delay;
@@ -700,47 +702,47 @@ static int uart_set_info(struct uart_state *state,
700 */ 702 */
701 mutex_lock(&state->mutex); 703 mutex_lock(&state->mutex);
702 704
703 change_irq = !(port->flags & UPF_FIXED_PORT) 705 change_irq = !(uport->flags & UPF_FIXED_PORT)
704 && new_serial.irq != port->irq; 706 && new_serial.irq != uport->irq;
705 707
706 /* 708 /*
707 * Since changing the 'type' of the port changes its resource 709 * Since changing the 'type' of the port changes its resource
708 * allocations, we should treat type changes the same as 710 * allocations, we should treat type changes the same as
709 * IO port changes. 711 * IO port changes.
710 */ 712 */
711 change_port = !(port->flags & UPF_FIXED_PORT) 713 change_port = !(uport->flags & UPF_FIXED_PORT)
712 && (new_port != port->iobase || 714 && (new_port != uport->iobase ||
713 (unsigned long)new_serial.iomem_base != port->mapbase || 715 (unsigned long)new_serial.iomem_base != uport->mapbase ||
714 new_serial.hub6 != port->hub6 || 716 new_serial.hub6 != uport->hub6 ||
715 new_serial.io_type != port->iotype || 717 new_serial.io_type != uport->iotype ||
716 new_serial.iomem_reg_shift != port->regshift || 718 new_serial.iomem_reg_shift != uport->regshift ||
717 new_serial.type != port->type); 719 new_serial.type != uport->type);
718 720
719 old_flags = port->flags; 721 old_flags = uport->flags;
720 new_flags = new_serial.flags; 722 new_flags = new_serial.flags;
721 old_custom_divisor = port->custom_divisor; 723 old_custom_divisor = uport->custom_divisor;
722 724
723 if (!capable(CAP_SYS_ADMIN)) { 725 if (!capable(CAP_SYS_ADMIN)) {
724 retval = -EPERM; 726 retval = -EPERM;
725 if (change_irq || change_port || 727 if (change_irq || change_port ||
726 (new_serial.baud_base != port->uartclk / 16) || 728 (new_serial.baud_base != uport->uartclk / 16) ||
727 (close_delay != state->port.close_delay) || 729 (close_delay != port->close_delay) ||
728 (closing_wait != state->port.closing_wait) || 730 (closing_wait != port->closing_wait) ||
729 (new_serial.xmit_fifo_size && 731 (new_serial.xmit_fifo_size &&
730 new_serial.xmit_fifo_size != port->fifosize) || 732 new_serial.xmit_fifo_size != uport->fifosize) ||
731 (((new_flags ^ old_flags) & ~UPF_USR_MASK) != 0)) 733 (((new_flags ^ old_flags) & ~UPF_USR_MASK) != 0))
732 goto exit; 734 goto exit;
733 port->flags = ((port->flags & ~UPF_USR_MASK) | 735 uport->flags = ((uport->flags & ~UPF_USR_MASK) |
734 (new_flags & UPF_USR_MASK)); 736 (new_flags & UPF_USR_MASK));
735 port->custom_divisor = new_serial.custom_divisor; 737 uport->custom_divisor = new_serial.custom_divisor;
736 goto check_and_exit; 738 goto check_and_exit;
737 } 739 }
738 740
739 /* 741 /*
740 * Ask the low level driver to verify the settings. 742 * Ask the low level driver to verify the settings.
741 */ 743 */
742 if (port->ops->verify_port) 744 if (uport->ops->verify_port)
743 retval = port->ops->verify_port(port, &new_serial); 745 retval = uport->ops->verify_port(uport, &new_serial);
744 746
745 if ((new_serial.irq >= nr_irqs) || (new_serial.irq < 0) || 747 if ((new_serial.irq >= nr_irqs) || (new_serial.irq < 0) ||
746 (new_serial.baud_base < 9600)) 748 (new_serial.baud_base < 9600))
@@ -769,31 +771,31 @@ static int uart_set_info(struct uart_state *state,
769 unsigned long old_iobase, old_mapbase; 771 unsigned long old_iobase, old_mapbase;
770 unsigned int old_type, old_iotype, old_hub6, old_shift; 772 unsigned int old_type, old_iotype, old_hub6, old_shift;
771 773
772 old_iobase = port->iobase; 774 old_iobase = uport->iobase;
773 old_mapbase = port->mapbase; 775 old_mapbase = uport->mapbase;
774 old_type = port->type; 776 old_type = uport->type;
775 old_hub6 = port->hub6; 777 old_hub6 = uport->hub6;
776 old_iotype = port->iotype; 778 old_iotype = uport->iotype;
777 old_shift = port->regshift; 779 old_shift = uport->regshift;
778 780
779 /* 781 /*
780 * Free and release old regions 782 * Free and release old regions
781 */ 783 */
782 if (old_type != PORT_UNKNOWN) 784 if (old_type != PORT_UNKNOWN)
783 port->ops->release_port(port); 785 uport->ops->release_port(uport);
784 786
785 port->iobase = new_port; 787 uport->iobase = new_port;
786 port->type = new_serial.type; 788 uport->type = new_serial.type;
787 port->hub6 = new_serial.hub6; 789 uport->hub6 = new_serial.hub6;
788 port->iotype = new_serial.io_type; 790 uport->iotype = new_serial.io_type;
789 port->regshift = new_serial.iomem_reg_shift; 791 uport->regshift = new_serial.iomem_reg_shift;
790 port->mapbase = (unsigned long)new_serial.iomem_base; 792 uport->mapbase = (unsigned long)new_serial.iomem_base;
791 793
792 /* 794 /*
793 * Claim and map the new regions 795 * Claim and map the new regions
794 */ 796 */
795 if (port->type != PORT_UNKNOWN) { 797 if (uport->type != PORT_UNKNOWN) {
796 retval = port->ops->request_port(port); 798 retval = uport->ops->request_port(uport);
797 } else { 799 } else {
798 /* Always success - Jean II */ 800 /* Always success - Jean II */
799 retval = 0; 801 retval = 0;
@@ -804,19 +806,19 @@ static int uart_set_info(struct uart_state *state,
804 * new port, try to restore the old settings. 806 * new port, try to restore the old settings.
805 */ 807 */
806 if (retval && old_type != PORT_UNKNOWN) { 808 if (retval && old_type != PORT_UNKNOWN) {
807 port->iobase = old_iobase; 809 uport->iobase = old_iobase;
808 port->type = old_type; 810 uport->type = old_type;
809 port->hub6 = old_hub6; 811 uport->hub6 = old_hub6;
810 port->iotype = old_iotype; 812 uport->iotype = old_iotype;
811 port->regshift = old_shift; 813 uport->regshift = old_shift;
812 port->mapbase = old_mapbase; 814 uport->mapbase = old_mapbase;
813 retval = port->ops->request_port(port); 815 retval = uport->ops->request_port(uport);
814 /* 816 /*
815 * If we failed to restore the old settings, 817 * If we failed to restore the old settings,
816 * we fail like this. 818 * we fail like this.
817 */ 819 */
818 if (retval) 820 if (retval)
819 port->type = PORT_UNKNOWN; 821 uport->type = PORT_UNKNOWN;
820 822
821 /* 823 /*
822 * We failed anyway. 824 * We failed anyway.
@@ -828,38 +830,38 @@ static int uart_set_info(struct uart_state *state,
828 } 830 }
829 831
830 if (change_irq) 832 if (change_irq)
831 port->irq = new_serial.irq; 833 uport->irq = new_serial.irq;
832 if (!(port->flags & UPF_FIXED_PORT)) 834 if (!(uport->flags & UPF_FIXED_PORT))
833 port->uartclk = new_serial.baud_base * 16; 835 uport->uartclk = new_serial.baud_base * 16;
834 port->flags = (port->flags & ~UPF_CHANGE_MASK) | 836 uport->flags = (uport->flags & ~UPF_CHANGE_MASK) |
835 (new_flags & UPF_CHANGE_MASK); 837 (new_flags & UPF_CHANGE_MASK);
836 port->custom_divisor = new_serial.custom_divisor; 838 uport->custom_divisor = new_serial.custom_divisor;
837 state->port.close_delay = close_delay; 839 port->close_delay = close_delay;
838 state->port.closing_wait = closing_wait; 840 port->closing_wait = closing_wait;
839 if (new_serial.xmit_fifo_size) 841 if (new_serial.xmit_fifo_size)
840 port->fifosize = new_serial.xmit_fifo_size; 842 uport->fifosize = new_serial.xmit_fifo_size;
841 if (state->port.tty) 843 if (port->tty)
842 state->port.tty->low_latency = 844 port->tty->low_latency =
843 (port->flags & UPF_LOW_LATENCY) ? 1 : 0; 845 (uport->flags & UPF_LOW_LATENCY) ? 1 : 0;
844 846
845 check_and_exit: 847 check_and_exit:
846 retval = 0; 848 retval = 0;
847 if (port->type == PORT_UNKNOWN) 849 if (uport->type == PORT_UNKNOWN)
848 goto exit; 850 goto exit;
849 if (state->flags & UIF_INITIALIZED) { 851 if (state->flags & UIF_INITIALIZED) {
850 if (((old_flags ^ port->flags) & UPF_SPD_MASK) || 852 if (((old_flags ^ uport->flags) & UPF_SPD_MASK) ||
851 old_custom_divisor != port->custom_divisor) { 853 old_custom_divisor != uport->custom_divisor) {
852 /* 854 /*
853 * If they're setting up a custom divisor or speed, 855 * If they're setting up a custom divisor or speed,
854 * instead of clearing it, then bitch about it. No 856 * instead of clearing it, then bitch about it. No
855 * need to rate-limit; it's CAP_SYS_ADMIN only. 857 * need to rate-limit; it's CAP_SYS_ADMIN only.
856 */ 858 */
857 if (port->flags & UPF_SPD_MASK) { 859 if (uport->flags & UPF_SPD_MASK) {
858 char buf[64]; 860 char buf[64];
859 printk(KERN_NOTICE 861 printk(KERN_NOTICE
860 "%s sets custom speed on %s. This " 862 "%s sets custom speed on %s. This "
861 "is deprecated.\n", current->comm, 863 "is deprecated.\n", current->comm,
862 tty_name(state->port.tty, buf)); 864 tty_name(port->tty, buf));
863 } 865 }
864 uart_change_speed(state, NULL); 866 uart_change_speed(state, NULL);
865 } 867 }
@@ -878,10 +880,11 @@ static int uart_set_info(struct uart_state *state,
878static int uart_get_lsr_info(struct uart_state *state, 880static int uart_get_lsr_info(struct uart_state *state,
879 unsigned int __user *value) 881 unsigned int __user *value)
880{ 882{
881 struct uart_port *port = state->uart_port; 883 struct uart_port *uport = state->uart_port;
884 struct tty_port *port = &state->port;
882 unsigned int result; 885 unsigned int result;
883 886
884 result = port->ops->tx_empty(port); 887 result = uport->ops->tx_empty(uport);
885 888
886 /* 889 /*
887 * If we're about to load something into the transmit 890 * If we're about to load something into the transmit
@@ -889,9 +892,9 @@ static int uart_get_lsr_info(struct uart_state *state,
889 * avoid a race condition (depending on when the transmit 892 * avoid a race condition (depending on when the transmit
890 * interrupt happens). 893 * interrupt happens).
891 */ 894 */
892 if (port->x_char || 895 if (uport->x_char ||
893 ((uart_circ_chars_pending(&state->xmit) > 0) && 896 ((uart_circ_chars_pending(&state->xmit) > 0) &&
894 !state->port.tty->stopped && !state->port.tty->hw_stopped)) 897 !port->tty->stopped && !port->tty->hw_stopped))
895 result &= ~TIOCSER_TEMT; 898 result &= ~TIOCSER_TEMT;
896 899
897 return put_user(result, value); 900 return put_user(result, value);
@@ -900,17 +903,17 @@ static int uart_get_lsr_info(struct uart_state *state,
900static int uart_tiocmget(struct tty_struct *tty, struct file *file) 903static int uart_tiocmget(struct tty_struct *tty, struct file *file)
901{ 904{
902 struct uart_state *state = tty->driver_data; 905 struct uart_state *state = tty->driver_data;
903 struct uart_port *port = state->uart_port; 906 struct uart_port *uport = state->uart_port;
904 int result = -EIO; 907 int result = -EIO;
905 908
906 mutex_lock(&state->mutex); 909 mutex_lock(&state->mutex);
907 if ((!file || !tty_hung_up_p(file)) && 910 if ((!file || !tty_hung_up_p(file)) &&
908 !(tty->flags & (1 << TTY_IO_ERROR))) { 911 !(tty->flags & (1 << TTY_IO_ERROR))) {
909 result = port->mctrl; 912 result = uport->mctrl;
910 913
911 spin_lock_irq(&port->lock); 914 spin_lock_irq(&uport->lock);
912 result |= port->ops->get_mctrl(port); 915 result |= uport->ops->get_mctrl(uport);
913 spin_unlock_irq(&port->lock); 916 spin_unlock_irq(&uport->lock);
914 } 917 }
915 mutex_unlock(&state->mutex); 918 mutex_unlock(&state->mutex);
916 919
@@ -922,13 +925,13 @@ uart_tiocmset(struct tty_struct *tty, struct file *file,
922 unsigned int set, unsigned int clear) 925 unsigned int set, unsigned int clear)
923{ 926{
924 struct uart_state *state = tty->driver_data; 927 struct uart_state *state = tty->driver_data;
925 struct uart_port *port = state->uart_port; 928 struct uart_port *uport = state->uart_port;
926 int ret = -EIO; 929 int ret = -EIO;
927 930
928 mutex_lock(&state->mutex); 931 mutex_lock(&state->mutex);
929 if ((!file || !tty_hung_up_p(file)) && 932 if ((!file || !tty_hung_up_p(file)) &&
930 !(tty->flags & (1 << TTY_IO_ERROR))) { 933 !(tty->flags & (1 << TTY_IO_ERROR))) {
931 uart_update_mctrl(port, set, clear); 934 uart_update_mctrl(uport, set, clear);
932 ret = 0; 935 ret = 0;
933 } 936 }
934 mutex_unlock(&state->mutex); 937 mutex_unlock(&state->mutex);
@@ -938,12 +941,12 @@ uart_tiocmset(struct tty_struct *tty, struct file *file,
938static int uart_break_ctl(struct tty_struct *tty, int break_state) 941static int uart_break_ctl(struct tty_struct *tty, int break_state)
939{ 942{
940 struct uart_state *state = tty->driver_data; 943 struct uart_state *state = tty->driver_data;
941 struct uart_port *port = state->uart_port; 944 struct uart_port *uport = state->uart_port;
942 945
943 mutex_lock(&state->mutex); 946 mutex_lock(&state->mutex);
944 947
945 if (port->type != PORT_UNKNOWN) 948 if (uport->type != PORT_UNKNOWN)
946 port->ops->break_ctl(port, break_state); 949 uport->ops->break_ctl(uport, break_state);
947 950
948 mutex_unlock(&state->mutex); 951 mutex_unlock(&state->mutex);
949 return 0; 952 return 0;
@@ -951,7 +954,7 @@ static int uart_break_ctl(struct tty_struct *tty, int break_state)
951 954
952static int uart_do_autoconfig(struct uart_state *state) 955static int uart_do_autoconfig(struct uart_state *state)
953{ 956{
954 struct uart_port *port = state->uart_port; 957 struct uart_port *uport = state->uart_port;
955 int flags, ret; 958 int flags, ret;
956 959
957 if (!capable(CAP_SYS_ADMIN)) 960 if (!capable(CAP_SYS_ADMIN))
@@ -973,18 +976,18 @@ static int uart_do_autoconfig(struct uart_state *state)
973 * If we already have a port type configured, 976 * If we already have a port type configured,
974 * we must release its resources. 977 * we must release its resources.
975 */ 978 */
976 if (port->type != PORT_UNKNOWN) 979 if (uport->type != PORT_UNKNOWN)
977 port->ops->release_port(port); 980 uport->ops->release_port(uport);
978 981
979 flags = UART_CONFIG_TYPE; 982 flags = UART_CONFIG_TYPE;
980 if (port->flags & UPF_AUTO_IRQ) 983 if (uport->flags & UPF_AUTO_IRQ)
981 flags |= UART_CONFIG_IRQ; 984 flags |= UART_CONFIG_IRQ;
982 985
983 /* 986 /*
984 * This will claim the ports resources if 987 * This will claim the ports resources if
985 * a port is found. 988 * a port is found.
986 */ 989 */
987 port->ops->config_port(port, flags); 990 uport->ops->config_port(uport, flags);
988 991
989 ret = uart_startup(state, 1); 992 ret = uart_startup(state, 1);
990 } 993 }
@@ -1001,7 +1004,7 @@ static int uart_do_autoconfig(struct uart_state *state)
1001static int 1004static int
1002uart_wait_modem_status(struct uart_state *state, unsigned long arg) 1005uart_wait_modem_status(struct uart_state *state, unsigned long arg)
1003{ 1006{
1004 struct uart_port *port = state->uart_port; 1007 struct uart_port *uport = state->uart_port;
1005 DECLARE_WAITQUEUE(wait, current); 1008 DECLARE_WAITQUEUE(wait, current);
1006 struct uart_icount cprev, cnow; 1009 struct uart_icount cprev, cnow;
1007 int ret; 1010 int ret;
@@ -1009,20 +1012,20 @@ uart_wait_modem_status(struct uart_state *state, unsigned long arg)
1009 /* 1012 /*
1010 * note the counters on entry 1013 * note the counters on entry
1011 */ 1014 */
1012 spin_lock_irq(&port->lock); 1015 spin_lock_irq(&uport->lock);
1013 memcpy(&cprev, &port->icount, sizeof(struct uart_icount)); 1016 memcpy(&cprev, &uport->icount, sizeof(struct uart_icount));
1014 1017
1015 /* 1018 /*
1016 * Force modem status interrupts on 1019 * Force modem status interrupts on
1017 */ 1020 */
1018 port->ops->enable_ms(port); 1021 uport->ops->enable_ms(uport);
1019 spin_unlock_irq(&port->lock); 1022 spin_unlock_irq(&uport->lock);
1020 1023
1021 add_wait_queue(&state->delta_msr_wait, &wait); 1024 add_wait_queue(&state->delta_msr_wait, &wait);
1022 for (;;) { 1025 for (;;) {
1023 spin_lock_irq(&port->lock); 1026 spin_lock_irq(&uport->lock);
1024 memcpy(&cnow, &port->icount, sizeof(struct uart_icount)); 1027 memcpy(&cnow, &uport->icount, sizeof(struct uart_icount));
1025 spin_unlock_irq(&port->lock); 1028 spin_unlock_irq(&uport->lock);
1026 1029
1027 set_current_state(TASK_INTERRUPTIBLE); 1030 set_current_state(TASK_INTERRUPTIBLE);
1028 1031
@@ -1062,11 +1065,11 @@ static int uart_get_count(struct uart_state *state,
1062{ 1065{
1063 struct serial_icounter_struct icount; 1066 struct serial_icounter_struct icount;
1064 struct uart_icount cnow; 1067 struct uart_icount cnow;
1065 struct uart_port *port = state->uart_port; 1068 struct uart_port *uport = state->uart_port;
1066 1069
1067 spin_lock_irq(&port->lock); 1070 spin_lock_irq(&uport->lock);
1068 memcpy(&cnow, &port->icount, sizeof(struct uart_icount)); 1071 memcpy(&cnow, &uport->icount, sizeof(struct uart_icount));
1069 spin_unlock_irq(&port->lock); 1072 spin_unlock_irq(&uport->lock);
1070 1073
1071 icount.cts = cnow.cts; 1074 icount.cts = cnow.cts;
1072 icount.dsr = cnow.dsr; 1075 icount.dsr = cnow.dsr;
@@ -1158,9 +1161,9 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
1158 break; 1161 break;
1159 1162
1160 default: { 1163 default: {
1161 struct uart_port *port = state->uart_port; 1164 struct uart_port *uport = state->uart_port;
1162 if (port->ops->ioctl) 1165 if (uport->ops->ioctl)
1163 ret = port->ops->ioctl(port, cmd, arg); 1166 ret = uport->ops->ioctl(uport, cmd, arg);
1164 break; 1167 break;
1165 } 1168 }
1166 } 1169 }
@@ -1173,10 +1176,10 @@ out:
1173static void uart_set_ldisc(struct tty_struct *tty) 1176static void uart_set_ldisc(struct tty_struct *tty)
1174{ 1177{
1175 struct uart_state *state = tty->driver_data; 1178 struct uart_state *state = tty->driver_data;
1176 struct uart_port *port = state->uart_port; 1179 struct uart_port *uport = state->uart_port;
1177 1180
1178 if (port->ops->set_ldisc) 1181 if (uport->ops->set_ldisc)
1179 port->ops->set_ldisc(port); 1182 uport->ops->set_ldisc(uport);
1180} 1183}
1181 1184
1182static void uart_set_termios(struct tty_struct *tty, 1185static void uart_set_termios(struct tty_struct *tty,
@@ -1254,16 +1257,15 @@ static void uart_set_termios(struct tty_struct *tty,
1254static void uart_close(struct tty_struct *tty, struct file *filp) 1257static void uart_close(struct tty_struct *tty, struct file *filp)
1255{ 1258{
1256 struct uart_state *state = tty->driver_data; 1259 struct uart_state *state = tty->driver_data;
1257 struct uart_port *port; 1260 struct tty_port *port;
1261 struct uart_port *uport;
1258 1262
1259 BUG_ON(!kernel_locked()); 1263 BUG_ON(!kernel_locked());
1260 1264
1261 if (!state || !state->uart_port) 1265 uport = state->uart_port;
1262 return; 1266 port = &state->port;
1263
1264 port = state->uart_port;
1265 1267
1266 pr_debug("uart_close(%d) called\n", port->line); 1268 pr_debug("uart_close(%d) called\n", uport->line);
1267 1269
1268 mutex_lock(&state->mutex); 1270 mutex_lock(&state->mutex);
1269 1271
@@ -1297,8 +1299,8 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1297 */ 1299 */
1298 tty->closing = 1; 1300 tty->closing = 1;
1299 1301
1300 if (state->port.closing_wait != USF_CLOSING_WAIT_NONE) 1302 if (port->closing_wait != USF_CLOSING_WAIT_NONE)
1301 tty_wait_until_sent(tty, msecs_to_jiffies(state->port.closing_wait)); 1303 tty_wait_until_sent(tty, msecs_to_jiffies(port->closing_wait));
1302 1304
1303 /* 1305 /*
1304 * At this point, we stop accepting input. To do this, we 1306 * At this point, we stop accepting input. To do this, we
@@ -1307,14 +1309,14 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1307 if (state->flags & UIF_INITIALIZED) { 1309 if (state->flags & UIF_INITIALIZED) {
1308 unsigned long flags; 1310 unsigned long flags;
1309 spin_lock_irqsave(&port->lock, flags); 1311 spin_lock_irqsave(&port->lock, flags);
1310 port->ops->stop_rx(port); 1312 uport->ops->stop_rx(uport);
1311 spin_unlock_irqrestore(&port->lock, flags); 1313 spin_unlock_irqrestore(&port->lock, flags);
1312 /* 1314 /*
1313 * Before we drop DTR, make sure the UART transmitter 1315 * Before we drop DTR, make sure the UART transmitter
1314 * has completely drained; this is especially 1316 * has completely drained; this is especially
1315 * important if there is a transmit FIFO! 1317 * important if there is a transmit FIFO!
1316 */ 1318 */
1317 uart_wait_until_sent(tty, port->timeout); 1319 uart_wait_until_sent(tty, uport->timeout);
1318 } 1320 }
1319 1321
1320 uart_shutdown(state); 1322 uart_shutdown(state);
@@ -1323,12 +1325,12 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1323 tty_ldisc_flush(tty); 1325 tty_ldisc_flush(tty);
1324 1326
1325 tty->closing = 0; 1327 tty->closing = 0;
1326 state->port.tty = NULL; 1328 port->tty = NULL;
1327 1329
1328 if (state->port.blocked_open) { 1330 if (port->blocked_open) {
1329 if (state->port.close_delay) 1331 if (port->close_delay)
1330 msleep_interruptible(state->port.close_delay); 1332 msleep_interruptible(port->close_delay);
1331 } else if (!uart_console(port)) { 1333 } else if (!uart_console(uport)) {
1332 uart_change_pm(state, 3); 1334 uart_change_pm(state, 3);
1333 } 1335 }
1334 1336
@@ -1336,9 +1338,9 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1336 * Wake up anyone trying to open this port. 1338 * Wake up anyone trying to open this port.
1337 */ 1339 */
1338 state->flags &= ~UIF_NORMAL_ACTIVE; 1340 state->flags &= ~UIF_NORMAL_ACTIVE;
1339 wake_up_interruptible(&state->port.open_wait); 1341 wake_up_interruptible(&port->open_wait);
1340 1342
1341 done: 1343done:
1342 mutex_unlock(&state->mutex); 1344 mutex_unlock(&state->mutex);
1343} 1345}
1344 1346
@@ -1410,6 +1412,7 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
1410static void uart_hangup(struct tty_struct *tty) 1412static void uart_hangup(struct tty_struct *tty)
1411{ 1413{
1412 struct uart_state *state = tty->driver_data; 1414 struct uart_state *state = tty->driver_data;
1415 struct tty_port *port = &state->port;
1413 1416
1414 BUG_ON(!kernel_locked()); 1417 BUG_ON(!kernel_locked());
1415 pr_debug("uart_hangup(%d)\n", state->uart_port->line); 1418 pr_debug("uart_hangup(%d)\n", state->uart_port->line);
@@ -1420,8 +1423,8 @@ static void uart_hangup(struct tty_struct *tty)
1420 uart_shutdown(state); 1423 uart_shutdown(state);
1421 state->count = 0; 1424 state->count = 0;
1422 state->flags &= ~UIF_NORMAL_ACTIVE; 1425 state->flags &= ~UIF_NORMAL_ACTIVE;
1423 state->port.tty = NULL; 1426 port->tty = NULL;
1424 wake_up_interruptible(&state->port.open_wait); 1427 wake_up_interruptible(&port->open_wait);
1425 wake_up_interruptible(&state->delta_msr_wait); 1428 wake_up_interruptible(&state->delta_msr_wait);
1426 } 1429 }
1427 mutex_unlock(&state->mutex); 1430 mutex_unlock(&state->mutex);
@@ -1470,20 +1473,21 @@ static int
1470uart_block_til_ready(struct file *filp, struct uart_state *state) 1473uart_block_til_ready(struct file *filp, struct uart_state *state)
1471{ 1474{
1472 DECLARE_WAITQUEUE(wait, current); 1475 DECLARE_WAITQUEUE(wait, current);
1473 struct uart_port *port = state->uart_port; 1476 struct uart_port *uport = state->uart_port;
1477 struct tty_port *port = &state->port;
1474 unsigned int mctrl; 1478 unsigned int mctrl;
1475 1479
1476 state->port.blocked_open++; 1480 port->blocked_open++;
1477 state->count--; 1481 state->count--;
1478 1482
1479 add_wait_queue(&state->port.open_wait, &wait); 1483 add_wait_queue(&port->open_wait, &wait);
1480 while (1) { 1484 while (1) {
1481 set_current_state(TASK_INTERRUPTIBLE); 1485 set_current_state(TASK_INTERRUPTIBLE);
1482 1486
1483 /* 1487 /*
1484 * If we have been hung up, tell userspace/restart open. 1488 * If we have been hung up, tell userspace/restart open.
1485 */ 1489 */
1486 if (tty_hung_up_p(filp) || state->port.tty == NULL) 1490 if (tty_hung_up_p(filp) || port->tty == NULL)
1487 break; 1491 break;
1488 1492
1489 /* 1493 /*
@@ -1502,8 +1506,8 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
1502 * have set TTY_IO_ERROR for a non-existant port. 1506 * have set TTY_IO_ERROR for a non-existant port.
1503 */ 1507 */
1504 if ((filp->f_flags & O_NONBLOCK) || 1508 if ((filp->f_flags & O_NONBLOCK) ||
1505 (state->port.tty->termios->c_cflag & CLOCAL) || 1509 (port->tty->termios->c_cflag & CLOCAL) ||
1506 (state->port.tty->flags & (1 << TTY_IO_ERROR))) 1510 (port->tty->flags & (1 << TTY_IO_ERROR)))
1507 break; 1511 break;
1508 1512
1509 /* 1513 /*
@@ -1511,17 +1515,17 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
1511 * not set RTS here - we want to make sure we catch 1515 * not set RTS here - we want to make sure we catch
1512 * the data from the modem. 1516 * the data from the modem.
1513 */ 1517 */
1514 if (state->port.tty->termios->c_cflag & CBAUD) 1518 if (port->tty->termios->c_cflag & CBAUD)
1515 uart_set_mctrl(port, TIOCM_DTR); 1519 uart_set_mctrl(uport, TIOCM_DTR);
1516 1520
1517 /* 1521 /*
1518 * and wait for the carrier to indicate that the 1522 * and wait for the carrier to indicate that the
1519 * modem is ready for us. 1523 * modem is ready for us.
1520 */ 1524 */
1521 spin_lock_irq(&port->lock); 1525 spin_lock_irq(&uport->lock);
1522 port->ops->enable_ms(port); 1526 uport->ops->enable_ms(uport);
1523 mctrl = port->ops->get_mctrl(port); 1527 mctrl = uport->ops->get_mctrl(uport);
1524 spin_unlock_irq(&port->lock); 1528 spin_unlock_irq(&uport->lock);
1525 if (mctrl & TIOCM_CAR) 1529 if (mctrl & TIOCM_CAR)
1526 break; 1530 break;
1527 1531
@@ -1533,15 +1537,15 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
1533 break; 1537 break;
1534 } 1538 }
1535 set_current_state(TASK_RUNNING); 1539 set_current_state(TASK_RUNNING);
1536 remove_wait_queue(&state->port.open_wait, &wait); 1540 remove_wait_queue(&port->open_wait, &wait);
1537 1541
1538 state->count++; 1542 state->count++;
1539 state->port.blocked_open--; 1543 port->blocked_open--;
1540 1544
1541 if (signal_pending(current)) 1545 if (signal_pending(current))
1542 return -ERESTARTSYS; 1546 return -ERESTARTSYS;
1543 1547
1544 if (!state->port.tty || tty_hung_up_p(filp)) 1548 if (!port->tty || tty_hung_up_p(filp))
1545 return -EAGAIN; 1549 return -EAGAIN;
1546 1550
1547 return 0; 1551 return 0;