[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220118221152.300444-3-terry.bowman@amd.com>
Date: Tue, 18 Jan 2022 16:11:46 -0600
From: Terry Bowman <terry.bowman@....com>
To: <terry.bowman@....com>, <linux@...ck-us.net>,
<linux-watchdog@...r.kernel.org>, <jdelvare@...e.com>,
<linux-i2c@...r.kernel.org>, <wsa@...nel.org>,
<andy.shevchenko@...il.com>, <rafael.j.wysocki@...el.com>
CC: <linux-kernel@...r.kernel.org>, <wim@...ux-watchdog.org>,
<rrichter@....com>, <thomas.lendacky@....com>,
<sudheesh.mavila@....com>, <Nehal-bakulchandra.Shah@....com>,
<Basavaraj.Natikar@....com>, <Shyam-sundar.S-k@....com>,
<Mario.Limonciello@....com>
Subject: [PATCH v2 2/8] i2c: piix4: Move port I/O region request/release code into functions
Move duplicated region request and release code into a function. Move is
in preparation for following MMIO changes.
Signed-off-by: Terry Bowman <terry.bowman@....com>
To: Guenter Roeck <linux@...ck-us.net>
To: linux-watchdog@...r.kernel.org
To: Jean Delvare <jdelvare@...e.com>
To: linux-i2c@...r.kernel.org
To: Wolfram Sang <wsa@...nel.org>
To: Andy Shevchenko <andy.shevchenko@...il.com>
To: Rafael J. Wysocki <rafael.j.wysocki@...el.com>
Cc: linux-kernel@...r.kernel.org
Cc: Wim Van Sebroeck <wim@...ux-watchdog.org>
Cc: Robert Richter <rrichter@....com>
Cc: Thomas Lendacky <thomas.lendacky@....com>
---
drivers/i2c/busses/i2c-piix4.c | 43 +++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 14 deletions(-)
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index b88d990b013f..14324e03fe24 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -165,6 +165,26 @@ struct i2c_piix4_adapdata {
u8 port; /* Port number, shifted */
};
+static int piix4_sb800_region_setup(struct device *dev)
+{
+ if (!request_muxed_region(SB800_PIIX4_SMB_IDX,
+ SB800_PIIX4_SMB_MAP_SIZE,
+ "sb800_piix4_smb")) {
+ dev_err(dev,
+ "SMB base address index region 0x%x already in use.\n",
+ SB800_PIIX4_SMB_IDX);
+ return -EBUSY;
+ }
+
+ return 0;
+}
+
+static void piix4_sb800_region_release(struct device *dev)
+{
+ release_region(SB800_PIIX4_SMB_IDX,
+ SB800_PIIX4_SMB_MAP_SIZE);
+}
+
static int piix4_setup(struct pci_dev *PIIX4_dev,
const struct pci_device_id *id)
{
@@ -270,6 +290,7 @@ static int piix4_setup_sb800(struct pci_dev *PIIX4_dev,
unsigned short piix4_smba;
u8 smba_en_lo, smba_en_hi, smb_en, smb_en_status, port_sel;
u8 i2ccfg, i2ccfg_offset = 0x10;
+ int retval;
/* SB800 and later SMBus does not support forcing address */
if (force || force_addr) {
@@ -291,21 +312,16 @@ static int piix4_setup_sb800(struct pci_dev *PIIX4_dev,
else
smb_en = (aux) ? 0x28 : 0x2c;
- if (!request_muxed_region(SB800_PIIX4_SMB_IDX,
- SB800_PIIX4_SMB_MAP_SIZE,
- "sb800_piix4_smb")) {
- dev_err(&PIIX4_dev->dev,
- "SMB base address index region 0x%x already in use.\n",
- SB800_PIIX4_SMB_IDX);
- return -EBUSY;
- }
+ retval = piix4_sb800_region_setup(&PIIX4_dev->dev);
+ if (retval)
+ return retval;
outb_p(smb_en, SB800_PIIX4_SMB_IDX);
smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1);
outb_p(smb_en + 1, SB800_PIIX4_SMB_IDX);
smba_en_hi = inb_p(SB800_PIIX4_SMB_IDX + 1);
- release_region(SB800_PIIX4_SMB_IDX, SB800_PIIX4_SMB_MAP_SIZE);
+ piix4_sb800_region_release(&PIIX4_dev->dev);
if (!smb_en) {
smb_en_status = smba_en_lo & 0x10;
@@ -686,10 +702,9 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr,
u8 port;
int retval;
- if (!request_muxed_region(SB800_PIIX4_SMB_IDX,
- SB800_PIIX4_SMB_MAP_SIZE,
- "sb800_piix4_smb"))
- return -EBUSY;
+ retval = piix4_sb800_region_setup(&adap->dev);
+ if (retval)
+ return retval;
/* Request the SMBUS semaphore, avoid conflicts with the IMC */
smbslvcnt = inb_p(SMBSLVCNT);
@@ -764,7 +779,7 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr,
piix4_imc_wakeup();
release:
- release_region(SB800_PIIX4_SMB_IDX, SB800_PIIX4_SMB_MAP_SIZE);
+ piix4_sb800_region_release(&adap->dev);
return retval;
}
--
2.30.2
Powered by blists - more mailing lists