i2c: piix4: Move SMBus port selection into function
authorTerry Bowman <terry.bowman@amd.com>
Wed, 9 Feb 2022 17:27:13 +0000 (11:27 -0600)
committerWolfram Sang <wsa@kernel.org>
Fri, 11 Feb 2022 14:34:50 +0000 (15:34 +0100)
Move port selection code into a separate function. Refactor is in
preparation for following MMIO changes.

Signed-off-by: Terry Bowman <terry.bowman@amd.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
drivers/i2c/busses/i2c-piix4.c

index 132ded7..efe51f6 100644 (file)
@@ -698,6 +698,20 @@ static void piix4_imc_wakeup(void)
        release_region(KERNCZ_IMC_IDX, 2);
 }
 
+static int piix4_sb800_port_sel(u8 port)
+{
+       u8 smba_en_lo, val;
+
+       outb_p(piix4_port_sel_sb800, SB800_PIIX4_SMB_IDX);
+       smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1);
+
+       val = (smba_en_lo & ~piix4_port_mask_sb800) | port;
+       if (smba_en_lo != val)
+               outb_p(val, SB800_PIIX4_SMB_IDX + 1);
+
+       return (smba_en_lo & piix4_port_mask_sb800);
+}
+
 /*
  * Handles access to multiple SMBus ports on the SB800.
  * The port is selected by bits 2:1 of the smb_en register (0x2c).
@@ -714,8 +728,7 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr,
        unsigned short piix4_smba = adapdata->smba;
        int retries = MAX_TIMEOUT;
        int smbslvcnt;
-       u8 smba_en_lo;
-       u8 port;
+       u8 prev_port;
        int retval;
 
        retval = piix4_sb800_region_request(&adap->dev);
@@ -775,18 +788,12 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr,
                }
        }
 
-       outb_p(piix4_port_sel_sb800, SB800_PIIX4_SMB_IDX);
-       smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1);
-
-       port = adapdata->port;
-       if ((smba_en_lo & piix4_port_mask_sb800) != port)
-               outb_p((smba_en_lo & ~piix4_port_mask_sb800) | port,
-                      SB800_PIIX4_SMB_IDX + 1);
+       prev_port = piix4_sb800_port_sel(adapdata->port);
 
        retval = piix4_access(adap, addr, flags, read_write,
                              command, size, data);
 
-       outb_p(smba_en_lo, SB800_PIIX4_SMB_IDX + 1);
+       piix4_sb800_port_sel(prev_port);
 
        /* Release the semaphore */
        outb_p(smbslvcnt | 0x20, SMBSLVCNT);