diff mbox series

[i2c-next,v4,3/6] i2c: mux: mlxcpld: Get rid of adapter numbers enforcement

Message ID 20210204162451.29518-4-vadimp@nvidia.com
State Superseded
Headers show
Series i2c: mux: mlxcpld: Extend driver functionality | expand

Commit Message

Vadim Pasternak Feb. 4, 2021, 4:24 p.m. UTC
Do not set the argument 'force_nr' of i2c_mux_add_adapter() routine,
instead provide argument 'chan_id'.
Rename mux ids array from 'adap_ids' to 'chan_ids'.

The motivation is to prepare infrastructure to be able to:
- Create only the child adapters which are actually needed - for which
  channel ids are specified.
- To assign 'nrs' to these child adapters dynamically, with no 'nr'
  enforcement.

Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>
---
v3->v4:
 Comments pointed out by Peter:
 - Extend patch with the code from the next patches dealing with
   argument two and three of the i2c_mux_add_adapter() routine.
v2->v3:
 Changes added by Vadim:
 - Rename patch from "Rename mux ids array" to "Get rid of adapter
   numbers enforcement".
---
 drivers/i2c/muxes/i2c-mux-mlxcpld.c   | 11 ++---------
 include/linux/platform_data/mlxcpld.h |  4 ++--
 2 files changed, 4 insertions(+), 11 deletions(-)

Comments

Peter Rosin Feb. 8, 2021, 7:41 a.m. UTC | #1
On 2021-02-04 17:24, Vadim Pasternak wrote:
> Do not set the argument 'force_nr' of i2c_mux_add_adapter() routine,

> instead provide argument 'chan_id'.

> Rename mux ids array from 'adap_ids' to 'chan_ids'.

> 

> The motivation is to prepare infrastructure to be able to:

> - Create only the child adapters which are actually needed - for which

>   channel ids are specified.

> - To assign 'nrs' to these child adapters dynamically, with no 'nr'

>   enforcement.

> 

> Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>

> ---

> v3->v4:

>  Comments pointed out by Peter:

>  - Extend patch with the code from the next patches dealing with

>    argument two and three of the i2c_mux_add_adapter() routine.

> v2->v3:

>  Changes added by Vadim:

>  - Rename patch from "Rename mux ids array" to "Get rid of adapter

>    numbers enforcement".

> ---

>  drivers/i2c/muxes/i2c-mux-mlxcpld.c   | 11 ++---------

>  include/linux/platform_data/mlxcpld.h |  4 ++--

>  2 files changed, 4 insertions(+), 11 deletions(-)

> 

> diff --git a/drivers/i2c/muxes/i2c-mux-mlxcpld.c b/drivers/i2c/muxes/i2c-mux-mlxcpld.c

> index 113ad84cdd94..388fe5c080aa 100644

> --- a/drivers/i2c/muxes/i2c-mux-mlxcpld.c

> +++ b/drivers/i2c/muxes/i2c-mux-mlxcpld.c

> @@ -101,9 +101,8 @@ static int mlxcpld_mux_probe(struct platform_device *pdev)

>  	struct mlxcpld_mux_plat_data *pdata = dev_get_platdata(&pdev->dev);

>  	struct i2c_client *client = to_i2c_client(pdev->dev.parent);

>  	struct i2c_mux_core *muxc;

> -	int num, force;

>  	struct mlxcpld_mux *data;

> -	int err;

> +	int num, err;

>  

>  	if (!pdata)

>  		return -EINVAL;

> @@ -126,13 +125,7 @@ static int mlxcpld_mux_probe(struct platform_device *pdev)

>  

>  	/* Create an adapter for each channel. */

>  	for (num = 0; num < CPLD_MUX_MAX_NCHANS; num++) {

> -		if (num >= pdata->num_adaps)

> -			/* discard unconfigured channels */

> -			break;


It's premature to remove this check here. At this stage, the loop must
still be broken when either CPLD_MUX_MAX_NCHANS (can't hold more adapters)
or pdata->num_adaps (no more chan_ids are provided) is reached.

So, move these three lines to 5/6 where you actually change the loop
condition. With that change I think we're done with this series. Yay!

Cheers,
Peter

> -

> -		force = pdata->adap_ids[num];

> -

> -		err = i2c_mux_add_adapter(muxc, force, num, 0);

> +		err = i2c_mux_add_adapter(muxc, 0, pdata->chan_ids[num], 0);

>  		if (err)

>  			goto virt_reg_failed;

>  	}

> diff --git a/include/linux/platform_data/mlxcpld.h b/include/linux/platform_data/mlxcpld.h

> index e6c18bf017dd..04d93c563c04 100644

> --- a/include/linux/platform_data/mlxcpld.h

> +++ b/include/linux/platform_data/mlxcpld.h

> @@ -11,12 +11,12 @@

>  /* Platform data for the CPLD I2C multiplexers */

>  

>  /* mlxcpld_mux_plat_data - per mux data, used with i2c_register_board_info

> - * @adap_ids - adapter array

> + * @chan_ids - channels array

>   * @num_adaps - number of adapters

>   * @sel_reg_addr - mux select register offset in CPLD space

>   */

>  struct mlxcpld_mux_plat_data {

> -	int *adap_ids;

> +	int *chan_ids;

>  	int num_adaps;

>  	int sel_reg_addr;

>  };

>
diff mbox series

Patch

diff --git a/drivers/i2c/muxes/i2c-mux-mlxcpld.c b/drivers/i2c/muxes/i2c-mux-mlxcpld.c
index 113ad84cdd94..388fe5c080aa 100644
--- a/drivers/i2c/muxes/i2c-mux-mlxcpld.c
+++ b/drivers/i2c/muxes/i2c-mux-mlxcpld.c
@@ -101,9 +101,8 @@  static int mlxcpld_mux_probe(struct platform_device *pdev)
 	struct mlxcpld_mux_plat_data *pdata = dev_get_platdata(&pdev->dev);
 	struct i2c_client *client = to_i2c_client(pdev->dev.parent);
 	struct i2c_mux_core *muxc;
-	int num, force;
 	struct mlxcpld_mux *data;
-	int err;
+	int num, err;
 
 	if (!pdata)
 		return -EINVAL;
@@ -126,13 +125,7 @@  static int mlxcpld_mux_probe(struct platform_device *pdev)
 
 	/* Create an adapter for each channel. */
 	for (num = 0; num < CPLD_MUX_MAX_NCHANS; num++) {
-		if (num >= pdata->num_adaps)
-			/* discard unconfigured channels */
-			break;
-
-		force = pdata->adap_ids[num];
-
-		err = i2c_mux_add_adapter(muxc, force, num, 0);
+		err = i2c_mux_add_adapter(muxc, 0, pdata->chan_ids[num], 0);
 		if (err)
 			goto virt_reg_failed;
 	}
diff --git a/include/linux/platform_data/mlxcpld.h b/include/linux/platform_data/mlxcpld.h
index e6c18bf017dd..04d93c563c04 100644
--- a/include/linux/platform_data/mlxcpld.h
+++ b/include/linux/platform_data/mlxcpld.h
@@ -11,12 +11,12 @@ 
 /* Platform data for the CPLD I2C multiplexers */
 
 /* mlxcpld_mux_plat_data - per mux data, used with i2c_register_board_info
- * @adap_ids - adapter array
+ * @chan_ids - channels array
  * @num_adaps - number of adapters
  * @sel_reg_addr - mux select register offset in CPLD space
  */
 struct mlxcpld_mux_plat_data {
-	int *adap_ids;
+	int *chan_ids;
 	int num_adaps;
 	int sel_reg_addr;
 };