[PATCH v7 10/11] i2c: cgbc: Register known I2C devices on the bus

From: Thomas Richard (congatec GmbH)

Date: Fri Nov 27 2026 - 12:58:47 EST


Register any I2C devices defined for the bus at probe time.

Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@xxxxxxxxxxx>
---
drivers/i2c/busses/i2c-cgbc.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-cgbc.c b/drivers/i2c/busses/i2c-cgbc.c
index 85cbe709bcde..5105b920e919 100644
--- a/drivers/i2c/busses/i2c-cgbc.c
+++ b/drivers/i2c/busses/i2c-cgbc.c
@@ -364,7 +364,8 @@ static int cgbc_i2c_probe(struct platform_device *pdev)
struct cgbc_device_data *cgbc = dev_get_drvdata(dev->parent);
struct cgbc_i2c_platform_data *pdata;
struct cgbc_i2c_data *i2c;
- int ret;
+ struct i2c_client *client;
+ int ret, i;

i2c = devm_kzalloc_obj(dev, *i2c);
if (!i2c)
@@ -393,7 +394,20 @@ static int cgbc_i2c_probe(struct platform_device *pdev)
if (ret)
return dev_err_probe(i2c->dev, ret, "Failed to get I2C bus frequency");

- return i2c_add_numbered_adapter(&i2c->adap);
+ ret = i2c_add_numbered_adapter(&i2c->adap);
+ if (ret)
+ return ret;
+
+ /* Add known devices to the bus */
+ for (i = 0; i < pdata->nb_devices; i++) {
+ client = i2c_new_client_device(&i2c->adap, pdata->devices + i);
+ if (IS_ERR(client)) {
+ i2c_del_adapter(&i2c->adap);
+ return PTR_ERR(client);
+ }
+ }
+
+ return 0;
}

static void cgbc_i2c_remove(struct platform_device *pdev)

--
2.53.0