diff mbox series

[v2,1/2] i2c: i2c-designware-platdrv: Cleanup setting of the adapter number

Message ID 20190312145554.25488-1-hdegoede@redhat.com
State Accepted
Headers show
Series [v2,1/2] i2c: i2c-designware-platdrv: Cleanup setting of the adapter number | expand

Commit Message

Hans de Goede March 12, 2019, 2:55 p.m. UTC
i2c-designware-platdrv assumes that if the pdev has an apci-companion
it should use a dynamic adapter-nr and otherwise it will use pdev->id
as adapter-nr.

Before this commit the setting of the adapter.nr was somewhat convoluted,
in the acpi_companion case it was set from dw_i2c_acpi_configure, in the
non acpi_companion case it was set from dw_i2c_set_fifo_size based on
tx_fifo_depth not being set yet indicating that dw_i2c_acpi_configure was
not executed.

This cleans this up, directly setting the adapter-nr from
dw_i2c_plat_probe for both cases.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
-Split out the code cleaning up the adapter.nr setting into a separate patch
---
 drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Andy Shevchenko March 12, 2019, 3:07 p.m. UTC | #1
On Tue, Mar 12, 2019 at 03:55:53PM +0100, Hans de Goede wrote:
> i2c-designware-platdrv assumes that if the pdev has an apci-companion
> it should use a dynamic adapter-nr and otherwise it will use pdev->id
> as adapter-nr.
> 
> Before this commit the setting of the adapter.nr was somewhat convoluted,
> in the acpi_companion case it was set from dw_i2c_acpi_configure, in the
> non acpi_companion case it was set from dw_i2c_set_fifo_size based on
> tx_fifo_depth not being set yet indicating that dw_i2c_acpi_configure was
> not executed.
> 
> This cleans this up, directly setting the adapter-nr from
> dw_i2c_plat_probe for both cases.
> 

As has been discussed earlier, this is good one

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> Changes in v2:
> -Split out the code cleaning up the adapter.nr setting into a separate patch
> ---
>  drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
> index ead5e7de3e4d..30529839cbd2 100644
> --- a/drivers/i2c/busses/i2c-designware-platdrv.c
> +++ b/drivers/i2c/busses/i2c-designware-platdrv.c
> @@ -86,7 +86,6 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev)
>  	struct i2c_timings *t = &dev->timings;
>  	u32 ss_ht = 0, fp_ht = 0, hs_ht = 0, fs_ht = 0;
>  
> -	dev->adapter.nr = -1;
>  	dev->tx_fifo_depth = 32;
>  	dev->rx_fifo_depth = 32;
>  
> @@ -219,7 +218,7 @@ static void i2c_dw_configure_slave(struct dw_i2c_dev *dev)
>  	dev->mode = DW_IC_SLAVE;
>  }
>  
> -static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev, int id)
> +static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev)
>  {
>  	u32 param, tx_fifo_depth, rx_fifo_depth;
>  
> @@ -233,7 +232,6 @@ static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev, int id)
>  	if (!dev->tx_fifo_depth) {
>  		dev->tx_fifo_depth = tx_fifo_depth;
>  		dev->rx_fifo_depth = rx_fifo_depth;
> -		dev->adapter.nr = id;
>  	} else if (tx_fifo_depth >= 2) {
>  		dev->tx_fifo_depth = min_t(u32, dev->tx_fifo_depth,
>  				tx_fifo_depth);
> @@ -358,13 +356,17 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
>  				div_u64(clk_khz * t->sda_hold_ns + 500000, 1000000);
>  	}
>  
> -	dw_i2c_set_fifo_size(dev, pdev->id);
> +	dw_i2c_set_fifo_size(dev);
>  
>  	adap = &dev->adapter;
>  	adap->owner = THIS_MODULE;
>  	adap->class = I2C_CLASS_DEPRECATED;
>  	ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev));
>  	adap->dev.of_node = pdev->dev.of_node;
> +	if (has_acpi_companion(&pdev->dev))
> +		adap->nr = -1;
> +	else
> +		adap->nr = pdev->id;
>  
>  	dev_pm_set_driver_flags(&pdev->dev,
>  				DPM_FLAG_SMART_PREPARE |
> -- 
> 2.20.1
>
Wolfram Sang March 12, 2019, 3:20 p.m. UTC | #2
On Tue, Mar 12, 2019 at 05:07:23PM +0200, Andy Shevchenko wrote:
> On Tue, Mar 12, 2019 at 03:55:53PM +0100, Hans de Goede wrote:
> > i2c-designware-platdrv assumes that if the pdev has an apci-companion
> > it should use a dynamic adapter-nr and otherwise it will use pdev->id
> > as adapter-nr.
> > 
> > Before this commit the setting of the adapter.nr was somewhat convoluted,
> > in the acpi_companion case it was set from dw_i2c_acpi_configure, in the
> > non acpi_companion case it was set from dw_i2c_set_fifo_size based on
> > tx_fifo_depth not being set yet indicating that dw_i2c_acpi_configure was
> > not executed.
> > 
> > This cleans this up, directly setting the adapter-nr from
> > dw_i2c_plat_probe for both cases.
> > 
> 
> As has been discussed earlier, this is good one
> 
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

The other patch, too? If so, please tag it seperately, so patchwork can
pick it up. (for bigger series, tags for the cover-letter is ok for me)
Andy Shevchenko March 12, 2019, 3:37 p.m. UTC | #3
On Tue, Mar 12, 2019 at 04:20:44PM +0100, Wolfram Sang wrote:
> On Tue, Mar 12, 2019 at 05:07:23PM +0200, Andy Shevchenko wrote:
> > On Tue, Mar 12, 2019 at 03:55:53PM +0100, Hans de Goede wrote:
> > > i2c-designware-platdrv assumes that if the pdev has an apci-companion
> > > it should use a dynamic adapter-nr and otherwise it will use pdev->id
> > > as adapter-nr.
> > > 
> > > Before this commit the setting of the adapter.nr was somewhat convoluted,
> > > in the acpi_companion case it was set from dw_i2c_acpi_configure, in the
> > > non acpi_companion case it was set from dw_i2c_set_fifo_size based on
> > > tx_fifo_depth not being set yet indicating that dw_i2c_acpi_configure was
> > > not executed.
> > > 
> > > This cleans this up, directly setting the adapter-nr from
> > > dw_i2c_plat_probe for both cases.
> > > 
> > 
> > As has been discussed earlier, this is good one
> > 
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> The other patch, too? If so, please tag it seperately, so patchwork can
> pick it up. (for bigger series, tags for the cover-letter is ok for me)

Yes, that's the plan. I have been reviewing it now.
Wolfram Sang March 12, 2019, 3:45 p.m. UTC | #4
> Yes, that's the plan. I have been reviewing it now.

Super! Sorry for being a tad impatient.
Jarkko Nikula March 13, 2019, 8:15 a.m. UTC | #5
On 3/12/19 5:07 PM, Andy Shevchenko wrote:
> On Tue, Mar 12, 2019 at 03:55:53PM +0100, Hans de Goede wrote:
>> i2c-designware-platdrv assumes that if the pdev has an apci-companion
>> it should use a dynamic adapter-nr and otherwise it will use pdev->id
>> as adapter-nr.
>>
>> Before this commit the setting of the adapter.nr was somewhat convoluted,
>> in the acpi_companion case it was set from dw_i2c_acpi_configure, in the
>> non acpi_companion case it was set from dw_i2c_set_fifo_size based on
>> tx_fifo_depth not being set yet indicating that dw_i2c_acpi_configure was
>> not executed.
>>
>> This cleans this up, directly setting the adapter-nr from
>> dw_i2c_plat_probe for both cases.
>>
> 
> As has been discussed earlier, this is good one
> 
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Wolfram Sang March 13, 2019, 5:10 p.m. UTC | #6
On Tue, Mar 12, 2019 at 03:55:53PM +0100, Hans de Goede wrote:
> i2c-designware-platdrv assumes that if the pdev has an apci-companion
> it should use a dynamic adapter-nr and otherwise it will use pdev->id
> as adapter-nr.
> 
> Before this commit the setting of the adapter.nr was somewhat convoluted,
> in the acpi_companion case it was set from dw_i2c_acpi_configure, in the
> non acpi_companion case it was set from dw_i2c_set_fifo_size based on
> tx_fifo_depth not being set yet indicating that dw_i2c_acpi_configure was
> not executed.
> 
> This cleans this up, directly setting the adapter-nr from
> dw_i2c_plat_probe for both cases.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Applied to for-current, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index ead5e7de3e4d..30529839cbd2 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -86,7 +86,6 @@  static int dw_i2c_acpi_configure(struct platform_device *pdev)
 	struct i2c_timings *t = &dev->timings;
 	u32 ss_ht = 0, fp_ht = 0, hs_ht = 0, fs_ht = 0;
 
-	dev->adapter.nr = -1;
 	dev->tx_fifo_depth = 32;
 	dev->rx_fifo_depth = 32;
 
@@ -219,7 +218,7 @@  static void i2c_dw_configure_slave(struct dw_i2c_dev *dev)
 	dev->mode = DW_IC_SLAVE;
 }
 
-static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev, int id)
+static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev)
 {
 	u32 param, tx_fifo_depth, rx_fifo_depth;
 
@@ -233,7 +232,6 @@  static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev, int id)
 	if (!dev->tx_fifo_depth) {
 		dev->tx_fifo_depth = tx_fifo_depth;
 		dev->rx_fifo_depth = rx_fifo_depth;
-		dev->adapter.nr = id;
 	} else if (tx_fifo_depth >= 2) {
 		dev->tx_fifo_depth = min_t(u32, dev->tx_fifo_depth,
 				tx_fifo_depth);
@@ -358,13 +356,17 @@  static int dw_i2c_plat_probe(struct platform_device *pdev)
 				div_u64(clk_khz * t->sda_hold_ns + 500000, 1000000);
 	}
 
-	dw_i2c_set_fifo_size(dev, pdev->id);
+	dw_i2c_set_fifo_size(dev);
 
 	adap = &dev->adapter;
 	adap->owner = THIS_MODULE;
 	adap->class = I2C_CLASS_DEPRECATED;
 	ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev));
 	adap->dev.of_node = pdev->dev.of_node;
+	if (has_acpi_companion(&pdev->dev))
+		adap->nr = -1;
+	else
+		adap->nr = pdev->id;
 
 	dev_pm_set_driver_flags(&pdev->dev,
 				DPM_FLAG_SMART_PREPARE |