From: "Thomas Richard (congatec GmbH)" <thomas.richard@bootlin.com>
To: Lee Jones <lee@kernel.org>, Andi Shyti <andi.shyti@kernel.org>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
Werner Gartner <Werner.Gartner@congatec.com>,
mfd@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-i2c@vger.kernel.org,
"Thomas Richard (congatec GmbH)" <thomas.richard@bootlin.com>
Subject: [PATCH v4 6/9] i2c: cgbc: Add support for fixed frequency buses
Date: Fri, 02 Oct 2026 13:12:44 +0200 [thread overview]
Message-ID: <20261002-cgbc-i2c-storage-devices-support-v4-6-eb42e0f1df59@bootlin.com> (raw)
In-Reply-To: <20261002-cgbc-i2c-storage-devices-support-v4-0-eb42e0f1df59@bootlin.com>
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
next prev parent reply other threads:[~2026-10-02 11:13 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
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-16 6:47 ` Lee Jones
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 ` Thomas Richard (congatec GmbH) [this message]
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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261002-cgbc-i2c-storage-devices-support-v4-6-eb42e0f1df59@bootlin.com \
--to=thomas.richard@bootlin.com \
--cc=Werner.Gartner@congatec.com \
--cc=andi.shyti@kernel.org \
--cc=lee@kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mfd@lists.linux.dev \
--cc=thomas.petazzoni@bootlin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®