mxser: clean up the rest of MUST helpers
authorJiri Slaby <jslaby@suse.cz>
Fri, 18 Jun 2021 06:14:48 +0000 (08:14 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 18 Jun 2021 11:10:01 +0000 (13:10 +0200)
Clean up the rest of MUST helpers. They all can use the newly added
mxser_must_set_EFR. And passing a bool instead of having two functions
(_enable+_disable) simplifies the code a lot too.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-43-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/mxser.c

index 392aee47c8038d43262424c4af890d1ef967a529..ff85a6e15d9d186900a510bc5774908d0df9940d 100644 (file)
@@ -391,81 +391,21 @@ static void mxser_must_set_enhance_mode(unsigned long baseio, bool enable)
                        enable ? MOXA_MUST_EFR_EFRB_ENABLE : 0);
 }
 
-static void SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(unsigned long baseio)
+static void mxser_must_no_sw_flow_control(unsigned long baseio)
 {
-       u8 oldlcr;
-       u8 efr;
-
-       oldlcr = inb(baseio + UART_LCR);
-       outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
-
-       efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
-       efr &= ~MOXA_MUST_EFR_SF_MASK;
-
-       outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
-       outb(oldlcr, baseio + UART_LCR);
-}
-
-static void mxser_enable_must_tx_software_flow_control(unsigned long baseio)
-{
-       u8 oldlcr;
-       u8 efr;
-
-       oldlcr = inb(baseio + UART_LCR);
-       outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
-
-       efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
-       efr &= ~MOXA_MUST_EFR_SF_TX_MASK;
-       efr |= MOXA_MUST_EFR_SF_TX1;
-
-       outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
-       outb(oldlcr, baseio + UART_LCR);
-}
-
-static void mxser_disable_must_tx_software_flow_control(unsigned long baseio)
-{
-       u8 oldlcr;
-       u8 efr;
-
-       oldlcr = inb(baseio + UART_LCR);
-       outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
-
-       efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
-       efr &= ~MOXA_MUST_EFR_SF_TX_MASK;
-
-       outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
-       outb(oldlcr, baseio + UART_LCR);
+       mxser_must_set_EFR(baseio, MOXA_MUST_EFR_SF_MASK, 0);
 }
 
-static void mxser_enable_must_rx_software_flow_control(unsigned long baseio)
+static void mxser_must_set_tx_sw_flow_control(unsigned long baseio, bool enable)
 {
-       u8 oldlcr;
-       u8 efr;
-
-       oldlcr = inb(baseio + UART_LCR);
-       outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
-
-       efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
-       efr &= ~MOXA_MUST_EFR_SF_RX_MASK;
-       efr |= MOXA_MUST_EFR_SF_RX1;
-
-       outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
-       outb(oldlcr, baseio + UART_LCR);
+       mxser_must_set_EFR(baseio, MOXA_MUST_EFR_SF_TX_MASK,
+                       enable ? MOXA_MUST_EFR_SF_TX1 : 0);
 }
 
-static void mxser_disable_must_rx_software_flow_control(unsigned long baseio)
+static void mxser_must_set_rx_sw_flow_control(unsigned long baseio, bool enable)
 {
-       u8 oldlcr;
-       u8 efr;
-
-       oldlcr = inb(baseio + UART_LCR);
-       outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
-
-       efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
-       efr &= ~MOXA_MUST_EFR_SF_RX_MASK;
-
-       outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
-       outb(oldlcr, baseio + UART_LCR);
+       mxser_must_set_EFR(baseio, MOXA_MUST_EFR_SF_RX_MASK,
+                       enable ? MOXA_MUST_EFR_SF_RX1 : 0);
 }
 
 static enum mxser_must_hwid mxser_must_get_hwid(unsigned long io)
@@ -746,20 +686,8 @@ static void mxser_change_speed(struct tty_struct *tty)
        if (info->board->must_hwid) {
                mxser_set_must_xon1_value(info->ioaddr, START_CHAR(tty));
                mxser_set_must_xoff1_value(info->ioaddr, STOP_CHAR(tty));
-               if (I_IXON(tty)) {
-                       mxser_enable_must_rx_software_flow_control(
-                                       info->ioaddr);
-               } else {
-                       mxser_disable_must_rx_software_flow_control(
-                                       info->ioaddr);
-               }
-               if (I_IXOFF(tty)) {
-                       mxser_enable_must_tx_software_flow_control(
-                                       info->ioaddr);
-               } else {
-                       mxser_disable_must_tx_software_flow_control(
-                                       info->ioaddr);
-               }
+               mxser_must_set_rx_sw_flow_control(info->ioaddr, I_IXON(tty));
+               mxser_must_set_tx_sw_flow_control(info->ioaddr, I_IXOFF(tty));
        }
 
 
@@ -946,7 +874,7 @@ static void mxser_shutdown_port(struct tty_port *port)
 
 
        if (info->board->must_hwid)
-               SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->ioaddr);
+               mxser_must_no_sw_flow_control(info->ioaddr);
 
        spin_unlock_irqrestore(&info->slock, flags);
 }
@@ -1585,8 +1513,7 @@ static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termi
 
                if (info->board->must_hwid) {
                        spin_lock_irqsave(&info->slock, flags);
-                       mxser_disable_must_rx_software_flow_control(
-                                       info->ioaddr);
+                       mxser_must_set_rx_sw_flow_control(info->ioaddr, false);
                        spin_unlock_irqrestore(&info->slock, flags);
                }