[PATCH 2/4] i2c: cgbc: Add virtual I2C bus support

"Thomas Richard (congatec GmbH)" <[email protected]> Tue, 04 Aug 2026 16:55:52 +0200
Newsgroups org.kernel.vger.linux-i2c,dev.linux.lists.mfd,org.kernel.vger.linux-kernel
Message-ID <20260804-cgbc-i2c-storage-devices-support-v1-2-fed38510671c@bootlin.com>
Internally the Board Controller has a virtual I2C bus with some virtual
storage devices on it. Add support for it by defining a i2c_adapter entry.
This virtual bus has a fixed frequency that cannot be changed.

Signed-off-by: Thomas Richard (congatec GmbH) <[email protected]>
---
 drivers/i2c/busses/i2c-cgbc.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/busses/i2c-cgbc.c b/drivers/i2c/busses/i2c-cgbc.c
index 25a74fa51aa0..c3f1c83b105a 100644
--- a/drivers/i2c/busses/i2c-cgbc.c
+++ b/drivers/i2c/busses/i2c-cgbc.c
@@ -13,6 +13,7 @@
 #include <linux/platform_device.h>
 
 #define CGBC_I2C_PRIMARY_BUS_ID	0
+#define CGBC_I2C_VIRTUAL_BUS_ID	3
 #define CGBC_I2C_PM_BUS_ID	4
 
 #define CGBC_I2C_CMD_START	0x40
@@ -147,11 +148,14 @@ static int cgbc_i2c_set_frequency(struct i2c_adapter *adap,
 	cmd[0] = CGBC_I2C_CMD_SPEED | algo_data->bus_id;
 	cmd[1] = cgbc_i2c_freq_to_reg(bus_frequency);
 
-	ret = cgbc_command(cgbc, &cmd, sizeof(cmd), &data, 1, NULL);
-	if (ret)
-		return dev_err_probe(i2c->dev, ret,
-				     "Failed to initialize I2C bus %s",
-				     adap->name);
+	/* Virtual bus has a fixed frequency */
+	if (algo_data->bus_id != CGBC_I2C_VIRTUAL_BUS_ID) {
+		ret = cgbc_command(cgbc, &cmd, sizeof(cmd), &data, 1, NULL);
+		if (ret)
+			return dev_err_probe(i2c->dev, ret,
+					     "Failed to initialize I2C bus %s",
+					     adap->name);
+	}
 
 	cmd[1] = 0x00;
 
@@ -338,6 +342,7 @@ static const struct i2c_algorithm cgbc_i2c_algorithm = {
 static struct i2c_algo_cgbc_data cgbc_i2c_algo_data[] = {
 	{ .bus_id = CGBC_I2C_PRIMARY_BUS_ID },
 	{ .bus_id = CGBC_I2C_PM_BUS_ID },
+	{ .bus_id = CGBC_I2C_VIRTUAL_BUS_ID },
 };
 
 static const struct i2c_adapter cgbc_i2c_adapter[] = {
@@ -357,6 +362,14 @@ static const struct i2c_adapter cgbc_i2c_adapter[] = {
 		.algo_data	= &cgbc_i2c_algo_data[1],
 		.nr		= -1,
 	},
+	{
+		.owner          = THIS_MODULE,
+		.name           = "Congatec Virtual I2C adapter",
+		.class          = I2C_CLASS_DEPRECATED,
+		.algo           = &cgbc_i2c_algorithm,
+		.algo_data      = &cgbc_i2c_algo_data[2],
+		.nr             = -1,
+	},
 };
 
 static int cgbc_i2c_probe(struct platform_device *pdev)

-- 
2.53.0