public inbox for linux-i3c@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2] i3c: master: Improve initialization of numbered I2C adapters
@ 2024-12-12  9:17 Defa Li
  2024-12-19 20:08 ` Frank Li
  2025-01-12 23:04 ` Alexandre Belloni
  0 siblings, 2 replies; 3+ messages in thread
From: Defa Li @ 2024-12-12  9:17 UTC (permalink / raw)
  To: Alexandre Belloni, Matthias Brugger, AngeloGioacchino Del Regno
  Cc: linux-i3c, linux-kernel, linux-arm-kernel, linux-mediatek,
	wsd_upstream, mingchang.jia, yuhan.wei, hao.lin, Defa Li

Add logic to initialize I2C adapters with a specific ID if available,
improving device identification and configuration.

For mixed buses, in addition to the i3c alias, an i2c alias can be added to
assign a fixed bus number to the i2c adapter.

This allows an alias node such as:
    aliases {
        i2c2 = &mixed_bus_a,
        i3c2 = &mixed_bus_a,
        i3c4 = &mixed_bus_b,
    };

    /* assigned "i3c-2" and "i2c-2" */
    mixed_bus_a: i3c-master {
    };

If there is no i2c alias for a mixed bus, the i2c adapter numbers will
remain as is and will be assigned starting after the highest fixed bus
number.

    /* assigned "i3c-4" and likely assigned "i2c-3" */
    mixed_bus_b: i3c-master {
    };

v2:
  - Modify commit message and code format issues

Signed-off-by: Defa Li <defa.li@mediatek.com>
---
 drivers/i3c/master.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 42310c9a00c2..92223e0b6e59 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -2486,7 +2486,7 @@ static int i3c_master_i2c_adapter_init(struct i3c_master_controller *master)
 	struct i2c_adapter *adap = i3c_master_to_i2c_adapter(master);
 	struct i2c_dev_desc *i2cdev;
 	struct i2c_dev_boardinfo *i2cboardinfo;
-	int ret;
+	int ret, id = -ENODEV;
 
 	adap->dev.parent = master->dev.parent;
 	adap->owner = master->dev.parent->driver->owner;
@@ -2497,7 +2497,15 @@ static int i3c_master_i2c_adapter_init(struct i3c_master_controller *master)
 	adap->timeout = 1000;
 	adap->retries = 3;
 
-	ret = i2c_add_adapter(adap);
+	if (master->dev.of_node)
+		id = of_alias_get_id(master->dev.of_node, "i2c");
+
+	if (id >= 0) {
+		adap->nr = id;
+		ret = i2c_add_numbered_adapter(adap);
+	} else {
+		ret = i2c_add_adapter(adap);
+	}
 	if (ret)
 		return ret;
 
-- 
2.46.0


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] i3c: master: Improve initialization of numbered I2C adapters
  2024-12-12  9:17 [PATCH v2] i3c: master: Improve initialization of numbered I2C adapters Defa Li
@ 2024-12-19 20:08 ` Frank Li
  2025-01-12 23:04 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Frank Li @ 2024-12-19 20:08 UTC (permalink / raw)
  To: Defa Li
  Cc: Alexandre Belloni, Matthias Brugger, AngeloGioacchino Del Regno,
	linux-i3c, linux-kernel, linux-arm-kernel, linux-mediatek,
	wsd_upstream, mingchang.jia, yuhan.wei, hao.lin

On Thu, Dec 12, 2024 at 05:17:53PM +0800, Defa Li wrote:
> Add logic to initialize I2C adapters with a specific ID if available,
> improving device identification and configuration.
>
> For mixed buses, in addition to the i3c alias, an i2c alias can be added to
> assign a fixed bus number to the i2c adapter.
>
> This allows an alias node such as:
>     aliases {
>         i2c2 = &mixed_bus_a,
>         i3c2 = &mixed_bus_a,
>         i3c4 = &mixed_bus_b,
>     };
>
>     /* assigned "i3c-2" and "i2c-2" */
>     mixed_bus_a: i3c-master {
>     };
>
> If there is no i2c alias for a mixed bus, the i2c adapter numbers will
> remain as is and will be assigned starting after the highest fixed bus
> number.
>
>     /* assigned "i3c-4" and likely assigned "i2c-3" */
>     mixed_bus_b: i3c-master {
>     };
>
> v2:
>   - Modify commit message and code format issues

v2: ...
 should be after "---"

>
> Signed-off-by: Defa Li <defa.li@mediatek.com>

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> ---
>  drivers/i3c/master.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 42310c9a00c2..92223e0b6e59 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -2486,7 +2486,7 @@ static int i3c_master_i2c_adapter_init(struct i3c_master_controller *master)
>  	struct i2c_adapter *adap = i3c_master_to_i2c_adapter(master);
>  	struct i2c_dev_desc *i2cdev;
>  	struct i2c_dev_boardinfo *i2cboardinfo;
> -	int ret;
> +	int ret, id = -ENODEV;
>
>  	adap->dev.parent = master->dev.parent;
>  	adap->owner = master->dev.parent->driver->owner;
> @@ -2497,7 +2497,15 @@ static int i3c_master_i2c_adapter_init(struct i3c_master_controller *master)
>  	adap->timeout = 1000;
>  	adap->retries = 3;
>
> -	ret = i2c_add_adapter(adap);
> +	if (master->dev.of_node)
> +		id = of_alias_get_id(master->dev.of_node, "i2c");
> +
> +	if (id >= 0) {
> +		adap->nr = id;
> +		ret = i2c_add_numbered_adapter(adap);
> +	} else {
> +		ret = i2c_add_adapter(adap);
> +	}
>  	if (ret)
>  		return ret;
>
> --
> 2.46.0
>
>
> --
> linux-i3c mailing list
> linux-i3c@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-i3c

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] i3c: master: Improve initialization of numbered I2C adapters
  2024-12-12  9:17 [PATCH v2] i3c: master: Improve initialization of numbered I2C adapters Defa Li
  2024-12-19 20:08 ` Frank Li
@ 2025-01-12 23:04 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2025-01-12 23:04 UTC (permalink / raw)
  To: Matthias Brugger, AngeloGioacchino Del Regno, Defa Li
  Cc: linux-i3c, linux-kernel, linux-arm-kernel, linux-mediatek,
	wsd_upstream, mingchang.jia, yuhan.wei, hao.lin

On Thu, 12 Dec 2024 17:17:53 +0800, Defa Li wrote:
> Add logic to initialize I2C adapters with a specific ID if available,
> improving device identification and configuration.
> 
> For mixed buses, in addition to the i3c alias, an i2c alias can be added to
> assign a fixed bus number to the i2c adapter.
> 
> This allows an alias node such as:
>     aliases {
>         i2c2 = &mixed_bus_a,
>         i3c2 = &mixed_bus_a,
>         i3c4 = &mixed_bus_b,
>     };
> 
> [...]

Applied, thanks!

[1/1] i3c: master: Improve initialization of numbered I2C adapters
      https://git.kernel.org/abelloni/c/5eb6d3561f6c

Best regards,

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-12 23:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-12  9:17 [PATCH v2] i3c: master: Improve initialization of numbered I2C adapters Defa Li
2024-12-19 20:08 ` Frank Li
2025-01-12 23:04 ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox