All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/9] Congatec Board Controller: Add storage devices support
@ 2026-10-02 11:12 Thomas Richard (congatec GmbH)
  2026-10-02 11:12 ` [PATCH v4 1/9] mfd: cgbc: Fix use of negative error code as valid session handle Thomas Richard (congatec GmbH)
                   ` (8 more replies)
  0 siblings, 9 replies; 16+ messages in thread
From: Thomas Richard (congatec GmbH) @ 2026-10-02 11:12 UTC (permalink / raw)
  To: Lee Jones, Andi Shyti
  Cc: Thomas Petazzoni, Werner Gartner, mfd, linux-kernel, linux-i2c,
	Thomas Richard (congatec GmbH), stable, Sashiko

In this v4, I moved struct cgbc_i2c_platform_data definition into MFD CGBC
header file (was in linux/platform_data/). And now MFD_CELL_NAME macros is
used.

Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
---
Changes in v4:
- Fix struct cgbc_i2c_platform_data comment (kernel-doc warning)
- Move struct cgbc_i2c_platform_data from linux/platform_data/i2c-cgbc.h to
  linux/mfd/cgbc.h
- Use MFD_CELL_NAME macros.
- Link to v3: https://patch.msgid.link/20260911-cgbc-i2c-storage-devices-support-v3-0-594b53fbc5ea@bootlin.com

Changes in v3:
- rebased on v7.3-rc2
- use PLATFORM_DEVID_AUTO for child devices
- move I2C bus and I2C device definition in the MFD driver
- Link to v2: https://patch.msgid.link/20260811-cgbc-i2c-storage-devices-support-v2-0-3efa998e0ef5@bootlin.com

Changes in v2:
- i2c: fix typo in CGBC BIOS EEPROM label.
- mfd: make cgbc_devs const
- Link to v1: https://patch.msgid.link/20260804-cgbc-i2c-storage-devices-support-v1-0-fed38510671c@bootlin.com

To: Thomas Richard <thomas.richard@bootlin.com>
To: Lee Jones <lee@kernel.org>
To: Andi Shyti <andi.shyti@kernel.org>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Werner Gartner <Werner.Gartner@congatec.com>
Cc: mfd@lists.linux.dev
Cc: linux-kernel@vger.kernel.org
Cc: linux-i2c@vger.kernel.org

---
Thomas Richard (congatec GmbH) (9):
      mfd: cgbc: Fix use of negative error code as valid session handle
      mfd: cgbc: Add I2C platform data
      i2c: cgbc: Use plateform data to get bus ID and adapter name
      mfd: cgbc: Use PLATFORM_DEVID_AUTO for child device registration
      mfd: cgbc: Use real I2C bus names
      i2c: cgbc: Add support for fixed frequency buses
      mfd: cgbc: Add virtual I2C bus support
      mfd: cgbc: Add virtual storage devices on the virtual I2C bus
      i2c: cgbc: Register known I2C devices on the bus

 drivers/i2c/busses/i2c-cgbc.c | 108 ++++++++++++------------
 drivers/mfd/cgbc-core.c       | 186 +++++++++++++++++++++++++++++++++++++++---
 include/linux/mfd/cgbc.h      |  16 ++++
 3 files changed, 243 insertions(+), 67 deletions(-)
---
base-commit: ce1e0223d8ad4211275c82a17ed6d43ab81e13d9
change-id: 20260717-cgbc-i2c-storage-devices-support-b3ee7cea3320

Best regards,
--  
Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>


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

* [PATCH v4 1/9] mfd: cgbc: Fix use of negative error code as valid session handle
  2026-10-02 11:12 [PATCH v4 0/9] Congatec Board Controller: Add storage devices support Thomas Richard (congatec GmbH)
@ 2026-10-02 11:12 ` Thomas Richard (congatec GmbH)
  2026-10-15 15:19   ` Lee Jones
  2026-10-02 11:12 ` [PATCH v4 2/9] mfd: cgbc: Add I2C platform data Thomas Richard (congatec GmbH)
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Thomas Richard (congatec GmbH) @ 2026-10-02 11:12 UTC (permalink / raw)
  To: Lee Jones, Andi Shyti
  Cc: Thomas Petazzoni, Werner Gartner, mfd, linux-kernel, linux-i2c,
	Thomas Richard (congatec GmbH), stable, Sashiko

The cgbc_session_command() return value was directly cast to u8 and used
as session handle without error checking. Casting a negative error to u8
produces a valid-looking session handle. So check if return value is
positive before to cast and use it.

Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260713-cgbc-core-fix-cgbc-remove-v1-1-79274ad62b3a%40bootlin.com?part=1
Fixes: 6f1067cfbee7 ("mfd: Add Congatec Board Controller driver")
Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
---
 drivers/mfd/cgbc-core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
index 2becaf797646..4a409234e66c 100644
--- a/drivers/mfd/cgbc-core.c
+++ b/drivers/mfd/cgbc-core.c
@@ -103,7 +103,11 @@ static int cgbc_session_request(struct cgbc_device_data *cgbc)
 	if (ret)
 		return dev_err_probe(cgbc->dev, ret, "device not found or not ready\n");
 
-	cgbc->session = cgbc_session_command(cgbc, CGBC_SESSION_CMD_REQUEST);
+	ret = cgbc_session_command(cgbc, CGBC_SESSION_CMD_REQUEST);
+	if (ret < 0)
+		return dev_err_probe(cgbc->dev, ret, "session handle request timed out\n");
+
+	cgbc->session = ret;
 
 	/* The Board Controller sent us a wrong session handle, we cannot communicate with it */
 	if (cgbc->session < CGBC_SESSION_VALID_MIN || cgbc->session > CGBC_SESSION_VALID_MAX)

-- 
2.53.0


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

* [PATCH v4 2/9] mfd: cgbc: Add I2C platform data
  2026-10-02 11:12 [PATCH v4 0/9] Congatec Board Controller: Add storage devices support Thomas Richard (congatec GmbH)
  2026-10-02 11:12 ` [PATCH v4 1/9] mfd: cgbc: Fix use of negative error code as valid session handle Thomas Richard (congatec GmbH)
@ 2026-10-02 11:12 ` Thomas Richard (congatec GmbH)
  2026-10-02 11:12 ` [PATCH v4 3/9] i2c: cgbc: Use plateform data to get bus ID and adapter name Thomas Richard (congatec GmbH)
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Thomas Richard (congatec GmbH) @ 2026-10-02 11:12 UTC (permalink / raw)
  To: Lee Jones, Andi Shyti
  Cc: Thomas Petazzoni, Werner Gartner, mfd, linux-kernel, linux-i2c,
	Thomas Richard (congatec GmbH)

Define I2C platform data for each I2C bus in the cgbc MFD driver. Platform
data passes per-bus parameters to the I2C driver, rather than being defined
inside the i2c-cgbc driver itself. This makes the i2c-cgbc driver more
generic.

Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
---
 drivers/mfd/cgbc-core.c  | 38 +++++++++++++++++++++++++++++---------
 include/linux/mfd/cgbc.h | 10 ++++++++++
 2 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
index 4a409234e66c..0cd9e6f888cb 100644
--- a/drivers/mfd/cgbc-core.c
+++ b/drivers/mfd/cgbc-core.c
@@ -55,6 +55,35 @@
 
 static struct platform_device *cgbc_pdev;
 
+static const struct cgbc_i2c_platform_data cgbc_i2c_gp_pdata = {
+	.name = "Congatec General Purpose I2C adapter",
+	.cgbc_bus_id = 0,
+};
+
+static const struct cgbc_i2c_platform_data cgbc_i2c_pm_pdata = {
+	.name  = "Congatec Power Management I2C adapter",
+	.cgbc_bus_id = 4,
+};
+
+static const struct mfd_cell cgbc_devs[] = {
+	MFD_CELL_NAME("cgbc-backlight"),
+	MFD_CELL_NAME("cgbc-gpio"),
+	MFD_CELL_NAME("cgbc-hwmon"),
+	{
+		.name = "cgbc-i2c",
+		.id = 1,
+		.platform_data = &cgbc_i2c_gp_pdata,
+		.pdata_size = sizeof(cgbc_i2c_gp_pdata),
+	},
+	{
+		.name = "cgbc-i2c",
+		.id = 2,
+		.platform_data = &cgbc_i2c_pm_pdata,
+		.pdata_size = sizeof(cgbc_i2c_pm_pdata),
+	},
+	MFD_CELL_NAME("cgbc-wdt"),
+};
+
 /* Wait the Board Controller is ready to receive some session commands */
 static int cgbc_wait_device(struct cgbc_device_data *cgbc)
 {
@@ -235,15 +264,6 @@ int cgbc_command(struct cgbc_device_data *cgbc, void *cmd, unsigned int cmd_size
 }
 EXPORT_SYMBOL_GPL(cgbc_command);
 
-static struct mfd_cell cgbc_devs[] = {
-	{ .name = "cgbc-wdt"	},
-	{ .name = "cgbc-gpio"	},
-	{ .name = "cgbc-i2c", .id = 1 },
-	{ .name = "cgbc-i2c", .id = 2 },
-	{ .name = "cgbc-hwmon"	},
-	{ .name = "cgbc-backlight" },
-};
-
 static int cgbc_map(struct cgbc_device_data *cgbc)
 {
 	struct device *dev = cgbc->dev;
diff --git a/include/linux/mfd/cgbc.h b/include/linux/mfd/cgbc.h
index 91f501e76c8f..4b6e41b9ca4a 100644
--- a/include/linux/mfd/cgbc.h
+++ b/include/linux/mfd/cgbc.h
@@ -41,4 +41,14 @@ struct cgbc_device_data {
 int cgbc_command(struct cgbc_device_data *cgbc, void *cmd, unsigned int cmd_size,
 		 void *data, unsigned int data_size, u8 *status);
 
+/**
+ * struct cgbc_i2c_platform_data - Platform data of the CGBC I2C driver
+ * @name:		I2C adapter name
+ * @cgbc_bus_id:	I2C bus ID (from Board Controller point of view)
+ */
+struct cgbc_i2c_platform_data {
+	const char *name;
+	int cgbc_bus_id;
+};
+
 #endif /*_LINUX_MFD_CGBC_H_*/

-- 
2.53.0


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

* [PATCH v4 3/9] i2c: cgbc: Use plateform data to get bus ID and adapter name
  2026-10-02 11:12 [PATCH v4 0/9] Congatec Board Controller: Add storage devices support Thomas Richard (congatec GmbH)
  2026-10-02 11:12 ` [PATCH v4 1/9] mfd: cgbc: Fix use of negative error code as valid session handle Thomas Richard (congatec GmbH)
  2026-10-02 11:12 ` [PATCH v4 2/9] mfd: cgbc: Add I2C platform data Thomas Richard (congatec GmbH)
@ 2026-10-02 11:12 ` Thomas Richard (congatec GmbH)
  2026-10-02 11:12 ` [PATCH v4 4/9] mfd: cgbc: Use PLATFORM_DEVID_AUTO for child device registration Thomas Richard (congatec GmbH)
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Thomas Richard (congatec GmbH) @ 2026-10-02 11:12 UTC (permalink / raw)
  To: Lee Jones, Andi Shyti
  Cc: Thomas Petazzoni, Werner Gartner, mfd, linux-kernel, linux-i2c,
	Thomas Richard (congatec GmbH)

Obtain the bus ID (from the BC point of view) and adapter name from
platform data. This allows the specific definitions to be removed, leaving
only a generic adapter definition.

Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
---
 drivers/i2c/busses/i2c-cgbc.c | 68 ++++++++++++++++---------------------------
 1 file changed, 25 insertions(+), 43 deletions(-)

diff --git a/drivers/i2c/busses/i2c-cgbc.c b/drivers/i2c/busses/i2c-cgbc.c
index 25a74fa51aa0..cc1cd75c4d74 100644
--- a/drivers/i2c/busses/i2c-cgbc.c
+++ b/drivers/i2c/busses/i2c-cgbc.c
@@ -12,9 +12,6 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 
-#define CGBC_I2C_PRIMARY_BUS_ID	0
-#define CGBC_I2C_PM_BUS_ID	4
-
 #define CGBC_I2C_CMD_START	0x40
 #define CGBC_I2C_CMD_STAT	0x48
 #define CGBC_I2C_CMD_DATA	0x50
@@ -60,11 +57,6 @@ enum cgbc_i2c_state {
 	CGBC_I2C_STATE_ERROR,
 };
 
-struct i2c_algo_cgbc_data {
-	u8		bus_id;
-	unsigned long	read_maxtime_us;
-};
-
 struct cgbc_i2c_data {
 	struct device		*dev;
 	struct cgbc_device_data *cgbc;
@@ -73,6 +65,8 @@ struct cgbc_i2c_data {
 	int			nmsgs;
 	int			pos;
 	enum cgbc_i2c_state	state;
+	u8			bus_id;
+	unsigned long		read_maxtime_us;
 };
 
 struct cgbc_i2c_transfer {
@@ -115,10 +109,9 @@ static unsigned int cgbc_i2c_reg_to_freq(u8 reg)
 
 static int cgbc_i2c_get_status(struct i2c_adapter *adap)
 {
-	struct i2c_algo_cgbc_data *algo_data = adap->algo_data;
 	struct cgbc_i2c_data *i2c = i2c_get_adapdata(adap);
 	struct cgbc_device_data *cgbc = i2c->cgbc;
-	u8 cmd = CGBC_I2C_CMD_STAT | algo_data->bus_id;
+	u8 cmd = CGBC_I2C_CMD_STAT | i2c->bus_id;
 	u8 status;
 	int ret;
 
@@ -132,7 +125,6 @@ static int cgbc_i2c_get_status(struct i2c_adapter *adap)
 static int cgbc_i2c_set_frequency(struct i2c_adapter *adap,
 				  unsigned int bus_frequency)
 {
-	struct i2c_algo_cgbc_data *algo_data = adap->algo_data;
 	struct cgbc_i2c_data *i2c = i2c_get_adapdata(adap);
 	struct cgbc_device_data *cgbc = i2c->cgbc;
 	u8 cmd[2], data;
@@ -144,7 +136,7 @@ static int cgbc_i2c_set_frequency(struct i2c_adapter *adap,
 		bus_frequency = I2C_MAX_STANDARD_MODE_FREQ;
 	}
 
-	cmd[0] = CGBC_I2C_CMD_SPEED | algo_data->bus_id;
+	cmd[0] = CGBC_I2C_CMD_SPEED | i2c->bus_id;
 	cmd[1] = cgbc_i2c_freq_to_reg(bus_frequency);
 
 	ret = cgbc_command(cgbc, &cmd, sizeof(cmd), &data, 1, NULL);
@@ -170,7 +162,7 @@ static int cgbc_i2c_set_frequency(struct i2c_adapter *adap,
 	 * can be read by a command is CGBC_I2C_READ_MAX_LEN.
 	 * Therefore, calculate the max time to properly size the timeout.
 	 */
-	algo_data->read_maxtime_us = (BITS_PER_BYTE + 1) * CGBC_I2C_READ_MAX_LEN
+	i2c->read_maxtime_us = (BITS_PER_BYTE + 1) * CGBC_I2C_READ_MAX_LEN
 		* USEC_PER_SEC / bus_frequency;
 
 	return 0;
@@ -200,7 +192,6 @@ static unsigned int cgbc_i2c_xfer_to_cmd(struct cgbc_i2c_transfer xfer, u8 *cmd)
 
 static int cgbc_i2c_xfer_msg(struct i2c_adapter *adap)
 {
-	struct i2c_algo_cgbc_data *algo_data = adap->algo_data;
 	struct cgbc_i2c_data *i2c = i2c_get_adapdata(adap);
 	struct cgbc_device_data *cgbc = i2c->cgbc;
 	struct i2c_msg *msg = i2c->msg;
@@ -210,7 +201,7 @@ static int cgbc_i2c_xfer_msg(struct i2c_adapter *adap)
 	u8 cmd_data;
 
 	struct cgbc_i2c_transfer xfer = {
-		.bus_id = algo_data->bus_id,
+		.bus_id = i2c->bus_id,
 		.addr = i2c_8bit_addr_from_msg(msg),
 	};
 
@@ -268,11 +259,11 @@ static int cgbc_i2c_xfer_msg(struct i2c_adapter *adap)
 
 		ret = read_poll_timeout(cgbc_i2c_get_status, ret,
 					ret != CGBC_I2C_STAT_BUSY, 0,
-					2 * algo_data->read_maxtime_us, false, adap);
+					2 * i2c->read_maxtime_us, false, adap);
 		if (ret < 0)
 			goto err;
 
-		cmd_data = CGBC_I2C_CMD_DATA | algo_data->bus_id;
+		cmd_data = CGBC_I2C_CMD_DATA | i2c->bus_id;
 		ret = cgbc_command(cgbc, &cmd_data, sizeof(cmd_data),
 				   msg->buf + i2c->pos, len, NULL);
 		if (ret)
@@ -335,44 +326,35 @@ static const struct i2c_algorithm cgbc_i2c_algorithm = {
 	.functionality = cgbc_i2c_func,
 };
 
-static struct i2c_algo_cgbc_data cgbc_i2c_algo_data[] = {
-	{ .bus_id = CGBC_I2C_PRIMARY_BUS_ID },
-	{ .bus_id = CGBC_I2C_PM_BUS_ID },
-};
-
-static const struct i2c_adapter cgbc_i2c_adapter[] = {
-	{
-		.owner		= THIS_MODULE,
-		.name		= "Congatec General Purpose I2C adapter",
-		.class		= I2C_CLASS_DEPRECATED,
-		.algo		= &cgbc_i2c_algorithm,
-		.algo_data	= &cgbc_i2c_algo_data[0],
-		.nr		= -1,
-	},
-	{
-		.owner		= THIS_MODULE,
-		.name		= "Congatec Power Management I2C adapter",
-		.class		= I2C_CLASS_DEPRECATED,
-		.algo		= &cgbc_i2c_algorithm,
-		.algo_data	= &cgbc_i2c_algo_data[1],
-		.nr		= -1,
-	},
+static const struct i2c_adapter cgbc_i2c_adapter = {
+	.owner		= THIS_MODULE,
+	.class		= I2C_CLASS_DEPRECATED,
+	.algo		= &cgbc_i2c_algorithm,
+	.nr		= -1,
 };
 
 static int cgbc_i2c_probe(struct platform_device *pdev)
 {
-	struct cgbc_device_data *cgbc = dev_get_drvdata(pdev->dev.parent);
+	struct device *dev = &pdev->dev;
+	struct cgbc_device_data *cgbc = dev_get_drvdata(dev->parent);
+	struct cgbc_i2c_platform_data *pdata;
 	struct cgbc_i2c_data *i2c;
 	int ret;
 
-	i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL);
+	i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL);
 	if (!i2c)
 		return -ENOMEM;
 
+	pdata = dev_get_platdata(dev);
+	if (!pdata)
+		return dev_err_probe(dev, -ENODEV, "missing platform_data\n");
+
 	i2c->cgbc = cgbc;
-	i2c->dev = &pdev->dev;
-	i2c->adap = cgbc_i2c_adapter[pdev->id];
+	i2c->dev = dev;
+	i2c->adap = cgbc_i2c_adapter;
 	i2c->adap.dev.parent = i2c->dev;
+	i2c->bus_id = pdata->cgbc_bus_id;
+	strscpy(i2c->adap.name, pdata->name, sizeof(i2c->adap.name));
 	i2c_set_adapdata(&i2c->adap, i2c);
 	platform_set_drvdata(pdev, i2c);
 

-- 
2.53.0


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

* [PATCH v4 4/9] mfd: cgbc: Use PLATFORM_DEVID_AUTO for child device registration
  2026-10-02 11:12 [PATCH v4 0/9] Congatec Board Controller: Add storage devices support Thomas Richard (congatec GmbH)
                   ` (2 preceding siblings ...)
  2026-10-02 11:12 ` [PATCH v4 3/9] i2c: cgbc: Use plateform data to get bus ID and adapter name Thomas Richard (congatec GmbH)
@ 2026-10-02 11:12 ` Thomas Richard (congatec GmbH)
  2026-10-15 15:27   ` Lee Jones
  2026-10-02 11:12 ` [PATCH v4 5/9] mfd: cgbc: Use real I2C bus names Thomas Richard (congatec GmbH)
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Thomas Richard (congatec GmbH) @ 2026-10-02 11:12 UTC (permalink / raw)
  To: Lee Jones, Andi Shyti
  Cc: Thomas Petazzoni, Werner Gartner, mfd, linux-kernel, linux-i2c,
	Thomas Richard (congatec GmbH)

Since parameters are now passed to the i2c-cgbc driver via platform
data, the I2C driver no longer depends on the platform device ID to probe
the correct I2C buses. Drop the hardcoded cell ID in favor of
PLATFORM_DEVID_AUTO.

Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
---
 drivers/mfd/cgbc-core.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
index 0cd9e6f888cb..8522df882509 100644
--- a/drivers/mfd/cgbc-core.c
+++ b/drivers/mfd/cgbc-core.c
@@ -71,13 +71,11 @@ static const struct mfd_cell cgbc_devs[] = {
 	MFD_CELL_NAME("cgbc-hwmon"),
 	{
 		.name = "cgbc-i2c",
-		.id = 1,
 		.platform_data = &cgbc_i2c_gp_pdata,
 		.pdata_size = sizeof(cgbc_i2c_gp_pdata),
 	},
 	{
 		.name = "cgbc-i2c",
-		.id = 2,
 		.platform_data = &cgbc_i2c_pm_pdata,
 		.pdata_size = sizeof(cgbc_i2c_pm_pdata),
 	},
@@ -349,8 +347,8 @@ static int cgbc_init_device(struct cgbc_device_data *cgbc)
 	if (ret)
 		goto release_session;
 
-	ret = mfd_add_devices(cgbc->dev, -1, cgbc_devs, ARRAY_SIZE(cgbc_devs),
-			      NULL, 0, NULL);
+	ret = mfd_add_devices(cgbc->dev, PLATFORM_DEVID_AUTO, cgbc_devs,
+			      ARRAY_SIZE(cgbc_devs), NULL, 0, NULL);
 	if (ret)
 		goto release_session;
 

-- 
2.53.0


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

* [PATCH v4 5/9] mfd: cgbc: Use real I2C bus names
  2026-10-02 11:12 [PATCH v4 0/9] Congatec Board Controller: Add storage devices support Thomas Richard (congatec GmbH)
                   ` (3 preceding siblings ...)
  2026-10-02 11:12 ` [PATCH v4 4/9] mfd: cgbc: Use PLATFORM_DEVID_AUTO for child device registration Thomas Richard (congatec GmbH)
@ 2026-10-02 11:12 ` Thomas Richard (congatec GmbH)
  2026-10-15 15:27   ` Lee Jones
  2026-10-02 11:12 ` [PATCH v4 6/9] i2c: cgbc: Add support for fixed frequency buses Thomas Richard (congatec GmbH)
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Thomas Richard (congatec GmbH) @ 2026-10-02 11:12 UTC (permalink / raw)
  To: Lee Jones, Andi Shyti
  Cc: Thomas Petazzoni, Werner Gartner, mfd, linux-kernel, linux-i2c,
	Thomas Richard (congatec GmbH)

The adapter names described the expected purpose of the buses ("General
Purpose I2C adapter", "Power Management I2C adapter") on conga-sa7 board
rather than their actual names on the Board Controller.

Rename them to the real bus names "cgbc-i2c0" and "cgbc-ddc0", matching
the naming used by Congatec, and update the variable names accordingly.

Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
---
 drivers/mfd/cgbc-core.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
index 8522df882509..a58d9ffdc277 100644
--- a/drivers/mfd/cgbc-core.c
+++ b/drivers/mfd/cgbc-core.c
@@ -55,13 +55,13 @@
 
 static struct platform_device *cgbc_pdev;
 
-static const struct cgbc_i2c_platform_data cgbc_i2c_gp_pdata = {
-	.name = "Congatec General Purpose I2C adapter",
+static const struct cgbc_i2c_platform_data cgbc_i2c_i2c0_pdata = {
+	.name = "cgbc-i2c0",
 	.cgbc_bus_id = 0,
 };
 
-static const struct cgbc_i2c_platform_data cgbc_i2c_pm_pdata = {
-	.name  = "Congatec Power Management I2C adapter",
+static const struct cgbc_i2c_platform_data cgbc_i2c_ddc0_pdata = {
+	.name  = "cgbc-ddc0",
 	.cgbc_bus_id = 4,
 };
 
@@ -71,13 +71,13 @@ static const struct mfd_cell cgbc_devs[] = {
 	MFD_CELL_NAME("cgbc-hwmon"),
 	{
 		.name = "cgbc-i2c",
-		.platform_data = &cgbc_i2c_gp_pdata,
-		.pdata_size = sizeof(cgbc_i2c_gp_pdata),
+		.platform_data = &cgbc_i2c_i2c0_pdata,
+		.pdata_size = sizeof(cgbc_i2c_i2c0_pdata),
 	},
 	{
 		.name = "cgbc-i2c",
-		.platform_data = &cgbc_i2c_pm_pdata,
-		.pdata_size = sizeof(cgbc_i2c_pm_pdata),
+		.platform_data = &cgbc_i2c_ddc0_pdata,
+		.pdata_size = sizeof(cgbc_i2c_ddc0_pdata),
 	},
 	MFD_CELL_NAME("cgbc-wdt"),
 };

-- 
2.53.0


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

* [PATCH v4 6/9] i2c: cgbc: Add support for fixed frequency buses
  2026-10-02 11:12 [PATCH v4 0/9] Congatec Board Controller: Add storage devices support Thomas Richard (congatec GmbH)
                   ` (4 preceding siblings ...)
  2026-10-02 11:12 ` [PATCH v4 5/9] mfd: cgbc: Use real I2C bus names Thomas Richard (congatec GmbH)
@ 2026-10-02 11:12 ` Thomas Richard (congatec GmbH)
  2026-10-02 11:12 ` [PATCH v4 7/9] mfd: cgbc: Add virtual I2C bus support Thomas Richard (congatec GmbH)
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Thomas Richard (congatec GmbH) @ 2026-10-02 11:12 UTC (permalink / raw)
  To: Lee Jones, Andi Shyti
  Cc: Thomas Petazzoni, Werner Gartner, mfd, linux-kernel, linux-i2c,
	Thomas Richard (congatec GmbH)

Some I2C buses run at a fixed frequency. Add a fixed_freq flag to struct
cgbc_i2c_platform_data to identify them. But the frequency is still needed
to compute read_maxtime_us, so split cgbc_i2c_set_frequency() into two
functions:
- cgbc_i2c_set_frequency(): sets the bus frequency (skipped for
  fixed-frequency buses).
- cgbc_i2c_get_frequency(): reads the bus frequency and computes
  read_maxtime_us.

Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
---
 drivers/i2c/busses/i2c-cgbc.c | 30 +++++++++++++++++++-----------
 include/linux/mfd/cgbc.h      |  2 ++
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-cgbc.c b/drivers/i2c/busses/i2c-cgbc.c
index cc1cd75c4d74..f7ddeca1d701 100644
--- a/drivers/i2c/busses/i2c-cgbc.c
+++ b/drivers/i2c/busses/i2c-cgbc.c
@@ -128,7 +128,6 @@ static int cgbc_i2c_set_frequency(struct i2c_adapter *adap,
 	struct cgbc_i2c_data *i2c = i2c_get_adapdata(adap);
 	struct cgbc_device_data *cgbc = i2c->cgbc;
 	u8 cmd[2], data;
-	int ret;
 
 	if (bus_frequency > CGBC_I2C_FREQ_MAX_HZ ||
 	    bus_frequency < CGBC_I2C_FREQ_MIN_HZ) {
@@ -139,18 +138,21 @@ static int cgbc_i2c_set_frequency(struct i2c_adapter *adap,
 	cmd[0] = CGBC_I2C_CMD_SPEED | i2c->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);
+	return cgbc_command(cgbc, &cmd, sizeof(cmd), &data, 1, NULL);
+}
 
-	cmd[1] = 0x00;
+static int cgbc_i2c_get_frequency(struct i2c_adapter *adap)
+{
+	struct cgbc_i2c_data *i2c = i2c_get_adapdata(adap);
+	struct cgbc_device_data *cgbc = i2c->cgbc;
+	u8 cmd[2] = { CGBC_I2C_CMD_SPEED | i2c->bus_id };
+	unsigned int bus_frequency;
+	u8 data;
+	int ret;
 
 	ret = cgbc_command(cgbc, &cmd, sizeof(cmd), &data, 1, NULL);
 	if (ret)
-		return dev_err_probe(i2c->dev, ret,
-				     "Failed to get I2C bus frequency");
+		return ret;
 
 	bus_frequency = cgbc_i2c_reg_to_freq(data);
 
@@ -358,9 +360,15 @@ static int cgbc_i2c_probe(struct platform_device *pdev)
 	i2c_set_adapdata(&i2c->adap, i2c);
 	platform_set_drvdata(pdev, i2c);
 
-	ret = cgbc_i2c_set_frequency(&i2c->adap, I2C_MAX_STANDARD_MODE_FREQ);
+	if (!pdata->fixed_freq) {
+		ret = cgbc_i2c_set_frequency(&i2c->adap, I2C_MAX_STANDARD_MODE_FREQ);
+		if (ret)
+			return dev_err_probe(dev, ret, "Failed to set I2C bus frequency");
+	}
+
+	ret = cgbc_i2c_get_frequency(&i2c->adap);
 	if (ret)
-		return ret;
+		return dev_err_probe(i2c->dev, ret, "Failed to get I2C bus frequency");
 
 	return i2c_add_numbered_adapter(&i2c->adap);
 }
diff --git a/include/linux/mfd/cgbc.h b/include/linux/mfd/cgbc.h
index 4b6e41b9ca4a..63fdf16fec95 100644
--- a/include/linux/mfd/cgbc.h
+++ b/include/linux/mfd/cgbc.h
@@ -45,10 +45,12 @@ int cgbc_command(struct cgbc_device_data *cgbc, void *cmd, unsigned int cmd_size
  * struct cgbc_i2c_platform_data - Platform data of the CGBC I2C driver
  * @name:		I2C adapter name
  * @cgbc_bus_id:	I2C bus ID (from Board Controller point of view)
+ * @fixed_freq:		I2C bus has a fixed frequency
  */
 struct cgbc_i2c_platform_data {
 	const char *name;
 	int cgbc_bus_id;
+	bool fixed_freq;
 };
 
 #endif /*_LINUX_MFD_CGBC_H_*/

-- 
2.53.0


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

* [PATCH v4 7/9] mfd: cgbc: Add virtual I2C bus support
  2026-10-02 11:12 [PATCH v4 0/9] Congatec Board Controller: Add storage devices support Thomas Richard (congatec GmbH)
                   ` (5 preceding siblings ...)
  2026-10-02 11:12 ` [PATCH v4 6/9] i2c: cgbc: Add support for fixed frequency buses Thomas Richard (congatec GmbH)
@ 2026-10-02 11:12 ` Thomas Richard (congatec GmbH)
  2026-10-02 11:12 ` [PATCH v4 8/9] mfd: cgbc: Add virtual storage devices on the virtual I2C bus Thomas Richard (congatec GmbH)
  2026-10-02 11:12 ` [PATCH v4 9/9] i2c: cgbc: Register known I2C devices on the bus Thomas Richard (congatec GmbH)
  8 siblings, 0 replies; 16+ messages in thread
From: Thomas Richard (congatec GmbH) @ 2026-10-02 11:12 UTC (permalink / raw)
  To: Lee Jones, Andi Shyti
  Cc: Thomas Petazzoni, Werner Gartner, mfd, linux-kernel, linux-i2c,
	Thomas Richard (congatec GmbH)

Internally the Board Controller has a virtual I2C bus with some virtual
storage devices (EEPROM and RAM). So add a new I2C cell for this I2C
virtual bus.

Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
---
 drivers/mfd/cgbc-core.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
index a58d9ffdc277..030e7eaf1dc3 100644
--- a/drivers/mfd/cgbc-core.c
+++ b/drivers/mfd/cgbc-core.c
@@ -65,6 +65,12 @@ static const struct cgbc_i2c_platform_data cgbc_i2c_ddc0_pdata = {
 	.cgbc_bus_id = 4,
 };
 
+static const struct cgbc_i2c_platform_data cgbc_i2c_i2cv_pdata = {
+	.name  = "cgbc-i2cv",
+	.cgbc_bus_id = 3,
+	.fixed_freq = true,
+};
+
 static const struct mfd_cell cgbc_devs[] = {
 	MFD_CELL_NAME("cgbc-backlight"),
 	MFD_CELL_NAME("cgbc-gpio"),
@@ -79,6 +85,11 @@ static const struct mfd_cell cgbc_devs[] = {
 		.platform_data = &cgbc_i2c_ddc0_pdata,
 		.pdata_size = sizeof(cgbc_i2c_ddc0_pdata),
 	},
+	{
+		.name = "cgbc-i2c",
+		.platform_data = &cgbc_i2c_i2cv_pdata,
+		.pdata_size = sizeof(cgbc_i2c_i2cv_pdata),
+	},
 	MFD_CELL_NAME("cgbc-wdt"),
 };
 

-- 
2.53.0


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

* [PATCH v4 8/9] mfd: cgbc: Add virtual storage devices on the virtual I2C bus
  2026-10-02 11:12 [PATCH v4 0/9] Congatec Board Controller: Add storage devices support Thomas Richard (congatec GmbH)
                   ` (6 preceding siblings ...)
  2026-10-02 11:12 ` [PATCH v4 7/9] mfd: cgbc: Add virtual I2C bus support Thomas Richard (congatec GmbH)
@ 2026-10-02 11:12 ` Thomas Richard (congatec GmbH)
  2026-10-02 11:12 ` [PATCH v4 9/9] i2c: cgbc: Register known I2C devices on the bus Thomas Richard (congatec GmbH)
  8 siblings, 0 replies; 16+ messages in thread
From: Thomas Richard (congatec GmbH) @ 2026-10-02 11:12 UTC (permalink / raw)
  To: Lee Jones, Andi Shyti
  Cc: Thomas Petazzoni, Werner Gartner, mfd, linux-kernel, linux-i2c,
	Thomas Richard (congatec GmbH)

Add support for virtual storage devices exposed by the Board Controller
on its virtual I2C bus. There are two device types: EEPROM for persistent
storage and RAM for non-persistent storage:
- Secure Data EEPROM  (64 bytes, RO): static and dynamic board info
- BIOS EEPROM         (32 bytes, RW): reserved for BIOS applications
- BC EEPROM           (32 bytes, RO): Board Controller operational params
- User EEPROM         (32 bytes, RW): user applications
- BIOS RAM            (32 bytes, RW): reserved for BIOS applications
- BC RAM               (8 bytes, RO): Board Controller operational params
- User RAM            (16 bytes, RW): user applications

Use the at24 driver with the 24c01 entry (the most generic one) for all
virtual storage devices, customizing parameters via software_node
properties (size, pagesize, read-only flag, label).

Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
---
 drivers/mfd/cgbc-core.c  | 129 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/cgbc.h |   4 ++
 2 files changed, 133 insertions(+)

diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
index 030e7eaf1dc3..edfac2b60718 100644
--- a/drivers/mfd/cgbc-core.c
+++ b/drivers/mfd/cgbc-core.c
@@ -13,10 +13,12 @@
 
 #include <linux/dmi.h>
 #include <linux/iopoll.h>
+#include <linux/i2c.h>
 #include <linux/mfd/cgbc.h>
 #include <linux/mfd/core.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/sysfs.h>
 
 #define CGBC_IO_SESSION_BASE	0x0E20
@@ -55,6 +57,131 @@
 
 static struct platform_device *cgbc_pdev;
 
+static const struct property_entry cgbc_secure_data_eeprom_props[] = {
+	PROPERTY_ENTRY_U32("size", 64),
+	PROPERTY_ENTRY_U32("pagesize", 1),
+	PROPERTY_ENTRY_BOOL("read-only"),
+	PROPERTY_ENTRY_STRING("label", "cgbc-secure-data-eeprom"),
+	{ }
+};
+
+static const struct software_node cgbc_secure_data_eeprom_node = {
+	.properties = cgbc_secure_data_eeprom_props,
+};
+
+static const struct property_entry cgbc_bc_eeprom_props[] = {
+	PROPERTY_ENTRY_U32("size", 32),
+	PROPERTY_ENTRY_U32("pagesize", 1),
+	PROPERTY_ENTRY_BOOL("read-only"),
+	PROPERTY_ENTRY_STRING("label", "cgbc-bc-eeprom"),
+	{ }
+};
+
+static const struct software_node cgbc_bc_eeprom_node = {
+	.properties = cgbc_bc_eeprom_props,
+};
+
+static const struct property_entry cgbc_user_eeprom_props[] = {
+	PROPERTY_ENTRY_U32("size", 32),
+	PROPERTY_ENTRY_U32("pagesize", 1),
+	PROPERTY_ENTRY_STRING("label", "cgbc-user-eeprom"),
+	{ }
+};
+
+static const struct software_node cgbc_user_eeprom_node = {
+	.properties = cgbc_user_eeprom_props,
+};
+
+static const struct property_entry cgbc_bios_eeprom_props[] = {
+	PROPERTY_ENTRY_U32("size", 32),
+	PROPERTY_ENTRY_U32("pagesize", 1),
+	PROPERTY_ENTRY_STRING("label", "cgbc-bios-eeprom"),
+	{ }
+};
+
+static const struct software_node cgbc_bios_eeprom_node = {
+	.properties = cgbc_bios_eeprom_props,
+};
+
+static const struct property_entry cgbc_bc_ram_props[] = {
+	PROPERTY_ENTRY_U32("size", 8),
+	PROPERTY_ENTRY_U32("pagesize", 1),
+	PROPERTY_ENTRY_BOOL("read-only"),
+	PROPERTY_ENTRY_STRING("label", "cgbc-bc-ram"),
+	{ }
+};
+
+static const struct software_node cgbc_bc_ram_node = {
+	.properties = cgbc_bc_ram_props,
+};
+
+static const struct property_entry cgbc_user_ram_props[] = {
+	PROPERTY_ENTRY_U32("size", 16),
+	PROPERTY_ENTRY_U32("pagesize", 1),
+	PROPERTY_ENTRY_STRING("label", "cgbc-user-ram"),
+	{ }
+};
+
+static const struct software_node cgbc_user_ram_node = {
+	.properties = cgbc_user_ram_props,
+};
+
+static const struct property_entry cgbc_bios_ram_props[] = {
+	PROPERTY_ENTRY_U32("size", 32),
+	PROPERTY_ENTRY_U32("pagesize", 1),
+	PROPERTY_ENTRY_STRING("label", "cgbc-bios-ram"),
+	{ }
+};
+
+static const struct software_node cgbc_bios_ram_node = {
+	.properties = cgbc_bios_ram_props,
+};
+
+static const struct i2c_board_info cgbc_i2c_i2cv_board_info[] = {
+	{
+		.type = "24c01",
+		.addr = 0x40,
+		.dev_name = "cgbc-secure-data-eeprom",
+		.swnode = &cgbc_secure_data_eeprom_node,
+	},
+	{
+		.type = "24c01",
+		.addr = 0x48,
+		.dev_name = "cgbc-bc-eeprom",
+		.swnode = &cgbc_bc_eeprom_node,
+	},
+	{
+		.type = "24c01",
+		.addr = 0x50,
+		.dev_name = "cgbc-user-eeprom",
+		.swnode = &cgbc_user_eeprom_node,
+	},
+	{
+		.type = "24c01",
+		.addr = 0x58,
+		.dev_name = "cgbc-bios-eeprom",
+		.swnode = &cgbc_bios_eeprom_node,
+	},
+	{
+		.type = "24c01",
+		.addr = 0x60,
+		.dev_name = "cgbc-bc-ram",
+		.swnode = &cgbc_bc_ram_node,
+	},
+	{
+		.type = "24c01",
+		.addr = 0x68,
+		.dev_name = "cgbc-user-ram",
+		.swnode = &cgbc_user_ram_node,
+	},
+	{
+		.type = "24c01",
+		.addr = 0x70,
+		.dev_name = "cgbc-bios-ram",
+		.swnode = &cgbc_bios_ram_node,
+	}
+};
+
 static const struct cgbc_i2c_platform_data cgbc_i2c_i2c0_pdata = {
 	.name = "cgbc-i2c0",
 	.cgbc_bus_id = 0,
@@ -69,6 +196,8 @@ static const struct cgbc_i2c_platform_data cgbc_i2c_i2cv_pdata = {
 	.name  = "cgbc-i2cv",
 	.cgbc_bus_id = 3,
 	.fixed_freq = true,
+	.devices = cgbc_i2c_i2cv_board_info,
+	.nb_devices = ARRAY_SIZE(cgbc_i2c_i2cv_board_info),
 };
 
 static const struct mfd_cell cgbc_devs[] = {
diff --git a/include/linux/mfd/cgbc.h b/include/linux/mfd/cgbc.h
index 63fdf16fec95..46e8b583bdb8 100644
--- a/include/linux/mfd/cgbc.h
+++ b/include/linux/mfd/cgbc.h
@@ -46,11 +46,15 @@ int cgbc_command(struct cgbc_device_data *cgbc, void *cmd, unsigned int cmd_size
  * @name:		I2C adapter name
  * @cgbc_bus_id:	I2C bus ID (from Board Controller point of view)
  * @fixed_freq:		I2C bus has a fixed frequency
+ * @nb_devices:		number of devices to add when the driver is probed
+ * @devices:		devices to add
  */
 struct cgbc_i2c_platform_data {
 	const char *name;
 	int cgbc_bus_id;
 	bool fixed_freq;
+	int nb_devices;
+	struct i2c_board_info const *devices;
 };
 
 #endif /*_LINUX_MFD_CGBC_H_*/

-- 
2.53.0


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

* [PATCH v4 9/9] i2c: cgbc: Register known I2C devices on the bus
  2026-10-02 11:12 [PATCH v4 0/9] Congatec Board Controller: Add storage devices support Thomas Richard (congatec GmbH)
                   ` (7 preceding siblings ...)
  2026-10-02 11:12 ` [PATCH v4 8/9] mfd: cgbc: Add virtual storage devices on the virtual I2C bus Thomas Richard (congatec GmbH)
@ 2026-10-02 11:12 ` Thomas Richard (congatec GmbH)
  8 siblings, 0 replies; 16+ messages in thread
From: Thomas Richard (congatec GmbH) @ 2026-10-02 11:12 UTC (permalink / raw)
  To: Lee Jones, Andi Shyti
  Cc: Thomas Petazzoni, Werner Gartner, mfd, linux-kernel, linux-i2c,
	Thomas Richard (congatec GmbH)

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

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

diff --git a/drivers/i2c/busses/i2c-cgbc.c b/drivers/i2c/busses/i2c-cgbc.c
index f7ddeca1d701..682ba639d887 100644
--- a/drivers/i2c/busses/i2c-cgbc.c
+++ b/drivers/i2c/busses/i2c-cgbc.c
@@ -341,7 +341,7 @@ 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;
+	int ret, i;
 
 	i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL);
 	if (!i2c)
@@ -370,7 +370,15 @@ 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++)
+		i2c_new_client_device(&i2c->adap, pdata->devices + i);
+
+	return 0;
 }
 
 static void cgbc_i2c_remove(struct platform_device *pdev)

-- 
2.53.0


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

* Re: [PATCH v4 1/9] mfd: cgbc: Fix use of negative error code as valid  session handle
  2026-10-02 11:12 ` [PATCH v4 1/9] mfd: cgbc: Fix use of negative error code as valid session handle Thomas Richard (congatec GmbH)
@ 2026-10-15 15:19   ` Lee Jones
  2026-10-15 17:53     ` Thomas Richard
  0 siblings, 1 reply; 16+ messages in thread
From: Lee Jones @ 2026-10-15 15:19 UTC (permalink / raw)
  To: Thomas Richard
  Cc: Andi Shyti, Thomas Petazzoni, Werner Gartner, mfd, linux-kernel,
	linux-i2c, stable, Sashiko

On Fri, 02 Oct 2026, Thomas Richard (congatec GmbH) wrote:

> The cgbc_session_command() return value was directly cast to u8 and used
> as session handle without error checking. Casting a negative error to u8
> produces a valid-looking session handle. So check if return value is
> positive before to cast and use it.
>
> Cc: stable@vger.kernel.org
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/patchset/20260713-cgbc-core-fix-cgbc-remove-v1-1-79274ad62b3a%40bootlin.com?part=1
> Fixes: 6f1067cfbee7 ("mfd: Add Congatec Board Controller driver")
> Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
> ---
>  drivers/mfd/cgbc-core.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
> index 2becaf797646..4a409234e66c 100644
> --- a/drivers/mfd/cgbc-core.c
> +++ b/drivers/mfd/cgbc-core.c
> @@ -103,7 +103,11 @@ static int cgbc_session_request(struct cgbc_device_data *cgbc)
>  	if (ret)
>  		return dev_err_probe(cgbc->dev, ret, "device not found or not ready\n");
>
> -	cgbc->session = cgbc_session_command(cgbc, CGBC_SESSION_CMD_REQUEST);
> +	ret = cgbc_session_command(cgbc, CGBC_SESSION_CMD_REQUEST);
> +	if (ret < 0)
> +		return dev_err_probe(cgbc->dev, ret, "session handle request timed out\n");

As previously requested, can we make this a bit more user friendly?

"Failed to start XYZ session"

> +
> +	cgbc->session = ret;
>
>  	/* The Board Controller sent us a wrong session handle, we cannot communicate with it */
>  	if (cgbc->session < CGBC_SESSION_VALID_MIN || cgbc->session > CGBC_SESSION_VALID_MAX)
>
> -- 
> 2.53.0
>

-- 
Lee Jones

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

* Re: [PATCH v4 5/9] mfd: cgbc: Use real I2C bus names
  2026-10-02 11:12 ` [PATCH v4 5/9] mfd: cgbc: Use real I2C bus names Thomas Richard (congatec GmbH)
@ 2026-10-15 15:27   ` Lee Jones
  2026-10-15 17:23     ` Thomas Richard
  0 siblings, 1 reply; 16+ messages in thread
From: Lee Jones @ 2026-10-15 15:27 UTC (permalink / raw)
  To: Thomas Richard (congatec GmbH)
  Cc: Andi Shyti, Thomas Petazzoni, Werner Gartner, mfd, linux-kernel,
	linux-i2c

On Fri, 02 Oct 2026, Thomas Richard (congatec GmbH) wrote:

> The adapter names described the expected purpose of the buses ("General
> Purpose I2C adapter", "Power Management I2C adapter") on conga-sa7 board
> rather than their actual names on the Board Controller.
> 
> Rename them to the real bus names "cgbc-i2c0" and "cgbc-ddc0", matching
> the naming used by Congatec, and update the variable names accordingly.
> 
> Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
> ---
>  drivers/mfd/cgbc-core.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
> index 8522df882509..a58d9ffdc277 100644
> --- a/drivers/mfd/cgbc-core.c
> +++ b/drivers/mfd/cgbc-core.c
> @@ -55,13 +55,13 @@
>  
>  static struct platform_device *cgbc_pdev;
>  
> -static const struct cgbc_i2c_platform_data cgbc_i2c_gp_pdata = {
> -	.name = "Congatec General Purpose I2C adapter",

This is odd.  We only just added these.

This should be fixed up into the original patch.

> +static const struct cgbc_i2c_platform_data cgbc_i2c_i2c0_pdata = {
> +	.name = "cgbc-i2c0",
>  	.cgbc_bus_id = 0,
>  };
>  
> -static const struct cgbc_i2c_platform_data cgbc_i2c_pm_pdata = {
> -	.name  = "Congatec Power Management I2C adapter",
> +static const struct cgbc_i2c_platform_data cgbc_i2c_ddc0_pdata = {
> +	.name  = "cgbc-ddc0",
>  	.cgbc_bus_id = 4,
>  };
>  
> @@ -71,13 +71,13 @@ static const struct mfd_cell cgbc_devs[] = {
>  	MFD_CELL_NAME("cgbc-hwmon"),
>  	{
>  		.name = "cgbc-i2c",
> -		.platform_data = &cgbc_i2c_gp_pdata,
> -		.pdata_size = sizeof(cgbc_i2c_gp_pdata),
> +		.platform_data = &cgbc_i2c_i2c0_pdata,
> +		.pdata_size = sizeof(cgbc_i2c_i2c0_pdata),
>  	},
>  	{
>  		.name = "cgbc-i2c",
> -		.platform_data = &cgbc_i2c_pm_pdata,
> -		.pdata_size = sizeof(cgbc_i2c_pm_pdata),
> +		.platform_data = &cgbc_i2c_ddc0_pdata,
> +		.pdata_size = sizeof(cgbc_i2c_ddc0_pdata),
>  	},
>  	MFD_CELL_NAME("cgbc-wdt"),
>  };
> 
> -- 
> 2.53.0
> 

-- 
Lee Jones

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

* Re: [PATCH v4 4/9] mfd: cgbc: Use PLATFORM_DEVID_AUTO for child device registration
  2026-10-02 11:12 ` [PATCH v4 4/9] mfd: cgbc: Use PLATFORM_DEVID_AUTO for child device registration Thomas Richard (congatec GmbH)
@ 2026-10-15 15:27   ` Lee Jones
  2026-10-15 17:48     ` Thomas Richard
  0 siblings, 1 reply; 16+ messages in thread
From: Lee Jones @ 2026-10-15 15:27 UTC (permalink / raw)
  To: Thomas Richard (congatec GmbH)
  Cc: Andi Shyti, Thomas Petazzoni, Werner Gartner, mfd, linux-kernel,
	linux-i2c

On Fri, 02 Oct 2026, Thomas Richard (congatec GmbH) wrote:

> Since parameters are now passed to the i2c-cgbc driver via platform
> data, the I2C driver no longer depends on the platform device ID to probe
> the correct I2C buses. Drop the hardcoded cell ID in favor of
> PLATFORM_DEVID_AUTO.
> 
> Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
> ---
>  drivers/mfd/cgbc-core.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
> index 0cd9e6f888cb..8522df882509 100644
> --- a/drivers/mfd/cgbc-core.c
> +++ b/drivers/mfd/cgbc-core.c
> @@ -71,13 +71,11 @@ static const struct mfd_cell cgbc_devs[] = {
>  	MFD_CELL_NAME("cgbc-hwmon"),
>  	{
>  		.name = "cgbc-i2c",
> -		.id = 1,

If you shuffled the patches around a bit, you shouldn't have to hack
your own new additions in and out, no?

>  		.platform_data = &cgbc_i2c_gp_pdata,
>  		.pdata_size = sizeof(cgbc_i2c_gp_pdata),
>  	},
>  	{
>  		.name = "cgbc-i2c",
> -		.id = 2,
>  		.platform_data = &cgbc_i2c_pm_pdata,
>  		.pdata_size = sizeof(cgbc_i2c_pm_pdata),
>  	},
> @@ -349,8 +347,8 @@ static int cgbc_init_device(struct cgbc_device_data *cgbc)
>  	if (ret)
>  		goto release_session;
>  
> -	ret = mfd_add_devices(cgbc->dev, -1, cgbc_devs, ARRAY_SIZE(cgbc_devs),
> -			      NULL, 0, NULL);
> +	ret = mfd_add_devices(cgbc->dev, PLATFORM_DEVID_AUTO, cgbc_devs,
> +			      ARRAY_SIZE(cgbc_devs), NULL, 0, NULL);
>  	if (ret)
>  		goto release_session;
>  
> 
> -- 
> 2.53.0
> 

-- 
Lee Jones

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

* Re: [PATCH v4 5/9] mfd: cgbc: Use real I2C bus names
  2026-10-15 15:27   ` Lee Jones
@ 2026-10-15 17:23     ` Thomas Richard
  0 siblings, 0 replies; 16+ messages in thread
From: Thomas Richard @ 2026-10-15 17:23 UTC (permalink / raw)
  To: Lee Jones
  Cc: Andi Shyti, Thomas Petazzoni, Werner Gartner, mfd, linux-kernel,
	linux-i2c

>> diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
>> index 8522df882509..a58d9ffdc277 100644
>> --- a/drivers/mfd/cgbc-core.c
>> +++ b/drivers/mfd/cgbc-core.c
>> @@ -55,13 +55,13 @@
>>  
>>  static struct platform_device *cgbc_pdev;
>>  
>> -static const struct cgbc_i2c_platform_data cgbc_i2c_gp_pdata = {
>> -	.name = "Congatec General Purpose I2C adapter",
> 
> This is odd.  We only just added these.
> 
> This should be fixed up into the original patch.
> 
Indeed I can fix names earlier in the series, when I2C bus names are
defined in the I2C driver, so no need to rename variables in the MFD.

Best Regards,
Thomas

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

* Re: [PATCH v4 4/9] mfd: cgbc: Use PLATFORM_DEVID_AUTO for child device registration
  2026-10-15 15:27   ` Lee Jones
@ 2026-10-15 17:48     ` Thomas Richard
  0 siblings, 0 replies; 16+ messages in thread
From: Thomas Richard @ 2026-10-15 17:48 UTC (permalink / raw)
  To: Lee Jones
  Cc: Andi Shyti, Thomas Petazzoni, Werner Gartner, mfd, linux-kernel,
	linux-i2c

On 10/15/26 5:27 PM, Lee Jones wrote:
> On Fri, 02 Oct 2026, Thomas Richard (congatec GmbH) wrote:
> 
>> Since parameters are now passed to the i2c-cgbc driver via platform
>> data, the I2C driver no longer depends on the platform device ID to probe
>> the correct I2C buses. Drop the hardcoded cell ID in favor of
>> PLATFORM_DEVID_AUTO.
>>
>> Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
>> ---
>>  drivers/mfd/cgbc-core.c | 6 ++----
>>  1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
>> index 0cd9e6f888cb..8522df882509 100644
>> --- a/drivers/mfd/cgbc-core.c
>> +++ b/drivers/mfd/cgbc-core.c
>> @@ -71,13 +71,11 @@ static const struct mfd_cell cgbc_devs[] = {
>>  	MFD_CELL_NAME("cgbc-hwmon"),
>>  	{
>>  		.name = "cgbc-i2c",
>> -		.id = 1,
> 
> If you shuffled the patches around a bit, you shouldn't have to hack
> your own new additions in and out, no?
For I2C bus names I got it, but not for id.
I need i2c_platform_data to be able to drop cell id and use
PLATFORM_DEVID_AUTO, so I don't see how I could reorder the patches.
And cell ids are there from the beginning, not really a new addition.
Maybe I misunderstood your comment, or I miss something.

Best Regards,
Thomas

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

* Re: [PATCH v4 1/9] mfd: cgbc: Fix use of negative error code as valid session handle
  2026-10-15 15:19   ` Lee Jones
@ 2026-10-15 17:53     ` Thomas Richard
  0 siblings, 0 replies; 16+ messages in thread
From: Thomas Richard @ 2026-10-15 17:53 UTC (permalink / raw)
  To: Lee Jones
  Cc: Andi Shyti, Thomas Petazzoni, Werner Gartner, mfd, linux-kernel,
	linux-i2c, stable, Sashiko

On 10/15/26 5:19 PM, Lee Jones wrote:
> On Fri, 02 Oct 2026, Thomas Richard (congatec GmbH) wrote:
> 
>> The cgbc_session_command() return value was directly cast to u8 and used
>> as session handle without error checking. Casting a negative error to u8
>> produces a valid-looking session handle. So check if return value is
>> positive before to cast and use it.
>>
>> Cc: stable@vger.kernel.org
>> Reported-by: Sashiko <sashiko-bot@kernel.org>
>> Closes: https://sashiko.dev/#/patchset/20260713-cgbc-core-fix-cgbc-remove-v1-1-79274ad62b3a%40bootlin.com?part=1
>> Fixes: 6f1067cfbee7 ("mfd: Add Congatec Board Controller driver")
>> Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@bootlin.com>
>> ---
>>  drivers/mfd/cgbc-core.c | 6 +++++-
>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
>> index 2becaf797646..4a409234e66c 100644
>> --- a/drivers/mfd/cgbc-core.c
>> +++ b/drivers/mfd/cgbc-core.c
>> @@ -103,7 +103,11 @@ static int cgbc_session_request(struct cgbc_device_data *cgbc)
>>  	if (ret)
>>  		return dev_err_probe(cgbc->dev, ret, "device not found or not ready\n");
>>
>> -	cgbc->session = cgbc_session_command(cgbc, CGBC_SESSION_CMD_REQUEST);
>> +	ret = cgbc_session_command(cgbc, CGBC_SESSION_CMD_REQUEST);
>> +	if (ret < 0)
>> +		return dev_err_probe(cgbc->dev, ret, "session handle request timed out\n");
> 
> As previously requested, can we make this a bit more user friendly?
> 
> "Failed to start XYZ session"
Oh yes, I totally forgot it. Sorry about that.

Best Regards,
Thomas

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

end of thread, other threads:[~2026-10-15 17:53 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-02 11:12 [PATCH v4 0/9] Congatec Board Controller: Add storage devices support Thomas Richard (congatec GmbH)
2026-10-02 11:12 ` [PATCH v4 1/9] mfd: cgbc: Fix use of negative error code as valid session handle Thomas Richard (congatec GmbH)
2026-10-15 15:19   ` Lee Jones
2026-10-15 17:53     ` Thomas Richard
2026-10-02 11:12 ` [PATCH v4 2/9] mfd: cgbc: Add I2C platform data Thomas Richard (congatec GmbH)
2026-10-02 11:12 ` [PATCH v4 3/9] i2c: cgbc: Use plateform data to get bus ID and adapter name Thomas Richard (congatec GmbH)
2026-10-02 11:12 ` [PATCH v4 4/9] mfd: cgbc: Use PLATFORM_DEVID_AUTO for child device registration Thomas Richard (congatec GmbH)
2026-10-15 15:27   ` Lee Jones
2026-10-15 17:48     ` Thomas Richard
2026-10-02 11:12 ` [PATCH v4 5/9] mfd: cgbc: Use real I2C bus names Thomas Richard (congatec GmbH)
2026-10-15 15:27   ` Lee Jones
2026-10-15 17:23     ` Thomas Richard
2026-10-02 11:12 ` [PATCH v4 6/9] i2c: cgbc: Add support for fixed frequency buses Thomas Richard (congatec GmbH)
2026-10-02 11:12 ` [PATCH v4 7/9] mfd: cgbc: Add virtual I2C bus support Thomas Richard (congatec GmbH)
2026-10-02 11:12 ` [PATCH v4 8/9] mfd: cgbc: Add virtual storage devices on the virtual I2C bus Thomas Richard (congatec GmbH)
2026-10-02 11:12 ` [PATCH v4 9/9] i2c: cgbc: Register known I2C devices on the bus Thomas Richard (congatec GmbH)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.