diff mbox series

[v4,3/9] i2c: piix4: Move port I/O region request/release code into functions

Message ID 20220130184130.176646-4-terry.bowman@amd.com
State New
Headers show
Series i2c: piix4: Replace cd6h/cd7h port I/O accesses with MMIO accesses | expand

Commit Message

Terry Bowman Jan. 30, 2022, 6:41 p.m. UTC
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@amd.com>
---
 drivers/i2c/busses/i2c-piix4.c | 39 +++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 12 deletions(-)

Comments

Jean Delvare Feb. 8, 2022, 2:45 p.m. UTC | #1
Hi Terry,

On Sun, 30 Jan 2022 12:41:24 -0600, Terry Bowman wrote:
> 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@amd.com>
> ---
>  drivers/i2c/busses/i2c-piix4.c | 39 +++++++++++++++++++++++-----------
>  1 file changed, 27 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
> index 3ff68967034e..5a98970ac60a 100644
> --- a/drivers/i2c/busses/i2c-piix4.c
> +++ b/drivers/i2c/busses/i2c-piix4.c
> @@ -165,6 +165,24 @@ struct i2c_piix4_adapdata {
>  	u8 port;		/* Port number, shifted */
>  };
>  
> +static int piix4_sb800_region_request(struct device *dev)
> +{
> +	if (!request_muxed_region(SB800_PIIX4_SMB_IDX, SB800_PIIX4_SMB_MAP_SIZE,
> +				  "sb800_piix4_smb")) {
> +		dev_err(dev,
> +			"SMBus 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 +288,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,20 +310,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_request(&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;
> @@ -685,9 +700,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_request(&adap->dev);
> +	if (retval)
> +		return retval;
>  
>  	/* Request the SMBUS semaphore, avoid conflicts with the IMC */
>  	smbslvcnt  = inb_p(SMBSLVCNT);
> @@ -762,7 +777,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;
>  }
>  

There's a third occurrence of request_muxed_region(SB800_PIIX4_SMB_IDX,
...) / release_region(SB800_PIIX4_SMB_IDX, ...) in function
piix4_setup_sb800. Any reason why you don't make use of the new helper
functions there as well?

OK, I see that this part of the code is specific to the original (ATI)
SB800, so it can't use MMIO, therefore you don't *have* to call the
helper functions. But for consistency, wouldn't it still make sense to
use them?
Terry Bowman Feb. 8, 2022, 3:15 p.m. UTC | #2
Hi Jean,

On 2/8/22 08:45, Jean Delvare wrote:
> Hi Terry,
> 
> On Sun, 30 Jan 2022 12:41:24 -0600, Terry Bowman wrote:
>> 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@amd.com>
>> ---
>>  drivers/i2c/busses/i2c-piix4.c | 39 +++++++++++++++++++++++-----------
>>  1 file changed, 27 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
>> index 3ff68967034e..5a98970ac60a 100644
>> --- a/drivers/i2c/busses/i2c-piix4.c
>> +++ b/drivers/i2c/busses/i2c-piix4.c
>> @@ -165,6 +165,24 @@ struct i2c_piix4_adapdata {
>>  	u8 port;		/* Port number, shifted */
>>  };
>>  
>> +static int piix4_sb800_region_request(struct device *dev)
>> +{
>> +	if (!request_muxed_region(SB800_PIIX4_SMB_IDX, SB800_PIIX4_SMB_MAP_SIZE,
>> +				  "sb800_piix4_smb")) {
>> +		dev_err(dev,
>> +			"SMBus 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 +288,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,20 +310,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_request(&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;
>> @@ -685,9 +700,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_request(&adap->dev);
>> +	if (retval)
>> +		return retval;
>>  
>>  	/* Request the SMBUS semaphore, avoid conflicts with the IMC */
>>  	smbslvcnt  = inb_p(SMBSLVCNT);
>> @@ -762,7 +777,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;
>>  }
>>  
> 
> There's a third occurrence of request_muxed_region(SB800_PIIX4_SMB_IDX,
> ...) / release_region(SB800_PIIX4_SMB_IDX, ...) in function
> piix4_setup_sb800. Any reason why you don't make use of the new helper
> functions there as well?
> 

I didn't update the other occurrence because it was outside the codepath
for the device we are addressing. At the time I wanted to minimize changes
particularly for other devices.

> OK, I see that this part of the code is specific to the original (ATI)
> SB800, so it can't use MMIO, therefore you don't *have* to call the
> helper functions. But for consistency, wouldn't it still make sense to
> use them?
> 

Yes, it would be more consistent if it used the helper function. 

Regards,
Terry
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 3ff68967034e..5a98970ac60a 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -165,6 +165,24 @@  struct i2c_piix4_adapdata {
 	u8 port;		/* Port number, shifted */
 };
 
+static int piix4_sb800_region_request(struct device *dev)
+{
+	if (!request_muxed_region(SB800_PIIX4_SMB_IDX, SB800_PIIX4_SMB_MAP_SIZE,
+				  "sb800_piix4_smb")) {
+		dev_err(dev,
+			"SMBus 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 +288,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,20 +310,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_request(&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;
@@ -685,9 +700,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_request(&adap->dev);
+	if (retval)
+		return retval;
 
 	/* Request the SMBUS semaphore, avoid conflicts with the IMC */
 	smbslvcnt  = inb_p(SMBSLVCNT);
@@ -762,7 +777,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;
 }