mxser: introduce mxser_must_select_bank and use it
authorJiri Slaby <jslaby@suse.cz>
Fri, 18 Jun 2021 06:14:47 +0000 (08:14 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 18 Jun 2021 11:10:01 +0000 (13:10 +0200)
Again, selecting a bank in the EFR register is duplicated many times.
Extract it to a separate function (mxser_must_select_bank) and use it on
all the places.

This cleans up most of the helpers. And mxser_get_must_hardware_id now
returns the HW ID directly, not via a by-reference parameter.

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

index 7caf369..392aee4 100644 (file)
@@ -334,53 +334,29 @@ static u8 __mxser_must_set_EFR(unsigned long baseio, u8 clear, u8 set,
        return oldlcr;
 }
 
-static void mxser_set_must_xon1_value(unsigned long baseio, u8 value)
+static u8 mxser_must_select_bank(unsigned long baseio, u8 bank)
 {
-       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_BANK_MASK;
-       efr |= MOXA_MUST_EFR_BANK0;
+       return __mxser_must_set_EFR(baseio, MOXA_MUST_EFR_BANK_MASK, bank,
+                       false);
+}
 
-       outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
+static void mxser_set_must_xon1_value(unsigned long baseio, u8 value)
+{
+       u8 oldlcr = mxser_must_select_bank(baseio, MOXA_MUST_EFR_BANK0);
        outb(value, baseio + MOXA_MUST_XON1_REGISTER);
        outb(oldlcr, baseio + UART_LCR);
 }
 
 static void mxser_set_must_xoff1_value(unsigned long baseio, u8 value)
 {
-       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_BANK_MASK;
-       efr |= MOXA_MUST_EFR_BANK0;
-
-       outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
+       u8 oldlcr = mxser_must_select_bank(baseio, MOXA_MUST_EFR_BANK0);
        outb(value, baseio + MOXA_MUST_XOFF1_REGISTER);
        outb(oldlcr, baseio + UART_LCR);
 }
 
 static void mxser_set_must_fifo_value(struct mxser_port *info)
 {
-       u8 oldlcr;
-       u8 efr;
-
-       oldlcr = inb(info->ioaddr + UART_LCR);
-       outb(MOXA_MUST_ENTER_ENCHANCE, info->ioaddr + UART_LCR);
-
-       efr = inb(info->ioaddr + MOXA_MUST_EFR_REGISTER);
-       efr &= ~MOXA_MUST_EFR_BANK_MASK;
-       efr |= MOXA_MUST_EFR_BANK1;
-
-       outb(efr, info->ioaddr + MOXA_MUST_EFR_REGISTER);
+       u8 oldlcr = mxser_must_select_bank(info->ioaddr, MOXA_MUST_EFR_BANK1);
        outb(info->rx_high_water, info->ioaddr + MOXA_MUST_RBRTH_REGISTER);
        outb(info->rx_high_water, info->ioaddr + MOXA_MUST_RBRTI_REGISTER);
        outb(info->rx_low_water, info->ioaddr + MOXA_MUST_RBRTL_REGISTER);
@@ -389,36 +365,18 @@ static void mxser_set_must_fifo_value(struct mxser_port *info)
 
 static void mxser_set_must_enum_value(unsigned long baseio, u8 value)
 {
-       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_BANK_MASK;
-       efr |= MOXA_MUST_EFR_BANK2;
-
-       outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
+       u8 oldlcr = mxser_must_select_bank(baseio, MOXA_MUST_EFR_BANK2);
        outb(value, baseio + MOXA_MUST_ENUM_REGISTER);
        outb(oldlcr, baseio + UART_LCR);
 }
 
-static void mxser_get_must_hardware_id(unsigned long baseio, u8 *pId)
+static u8 mxser_get_must_hardware_id(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_BANK_MASK;
-       efr |= MOXA_MUST_EFR_BANK2;
-
-       outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
-       *pId = inb(baseio + MOXA_MUST_HWID_REGISTER);
+       u8 oldlcr = mxser_must_select_bank(baseio, MOXA_MUST_EFR_BANK2);
+       u8 id = inb(baseio + MOXA_MUST_HWID_REGISTER);
        outb(oldlcr, baseio + UART_LCR);
+
+       return id;
 }
 
 static void mxser_must_set_EFR(unsigned long baseio, u8 clear, u8 set)
@@ -525,7 +483,7 @@ static enum mxser_must_hwid mxser_must_get_hwid(unsigned long io)
                return MOXA_OTHER_UART;
        }
 
-       mxser_get_must_hardware_id(io, &hwid);
+       hwid = mxser_get_must_hardware_id(io);
        for (i = 1; i < UART_INFO_NUM; i++) /* 0 = OTHER_UART */
                if (hwid == Gpci_uart_info[i].type)
                        return hwid;