Some I2C drivers like Designware and HiSilicon will print the
bus frequency mode information, so add a public one that everyone
can make use of.
Tested-by: Jarkko Nikula <[email protected]>
Reviewed-by: Jarkko Nikula <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Signed-off-by: Yicong Yang <[email protected]>
---
drivers/i2c/i2c-core-base.c | 21 +++++++++++++++++++++
include/linux/i2c.h | 3 +++
2 files changed, 24 insertions(+)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index de9402c..775b8cc 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -76,6 +76,27 @@ void i2c_transfer_trace_unreg(void)
static_branch_dec(&i2c_trace_msg_key);
}
+const char *i2c_freq_mode_string(u32 bus_freq_hz)
+{
+ switch (bus_freq_hz) {
+ case I2C_MAX_STANDARD_MODE_FREQ:
+ return "Standard Mode (100 kHz)";
+ case I2C_MAX_FAST_MODE_FREQ:
+ return "Fast Mode (400 kHz)";
+ case I2C_MAX_FAST_MODE_PLUS_FREQ:
+ return "Fast Mode Plus (1.0 MHz)";
+ case I2C_MAX_TURBO_MODE_FREQ:
+ return "Turbo Mode (1.4 MHz)";
+ case I2C_MAX_HIGH_SPEED_MODE_FREQ:
+ return "High Speed Mode (3.4 MHz)";
+ case I2C_MAX_ULTRA_FAST_MODE_FREQ:
+ return "Ultra Fast Mode (5.0 MHz)";
+ default:
+ return "Unknown Mode";
+ }
+}
+EXPORT_SYMBOL_GPL(i2c_freq_mode_string);
+
const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
const struct i2c_client *client)
{
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 10bd0b0..0813be1 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -51,6 +51,9 @@ struct module;
struct property_entry;
#if IS_ENABLED(CONFIG_I2C)
+/* Return the Frequency mode string based on the bus frequency */
+const char *i2c_freq_mode_string(u32 bus_freq_hz);
+
/*
* The master routines are the ones normally used to transmit data to devices
* on a bus (or read from them). Apart from two basic transfer functions to
--
2.8.1
> +const char *i2c_freq_mode_string(u32 bus_freq_hz)
> +{
> + switch (bus_freq_hz) {
> + case I2C_MAX_STANDARD_MODE_FREQ:
> + return "Standard Mode (100 kHz)";
Sorry, I just noticed just now. Shouldn't we also support lower
frequencies than the maximum one? I.e.
if (bus_freq_hz <= I2C_MAX_STANDARD_MODE_FREQ)
return "Standard Mode (max 100 kHz)";
else if (bus_freq_hz <= ... )
?
On Thu, Apr 08, 2021 at 10:55:51PM +0200, Wolfram Sang wrote:
>
> > +const char *i2c_freq_mode_string(u32 bus_freq_hz)
> > +{
> > + switch (bus_freq_hz) {
> > + case I2C_MAX_STANDARD_MODE_FREQ:
> > + return "Standard Mode (100 kHz)";
>
> Sorry, I just noticed just now. Shouldn't we also support lower
> frequencies than the maximum one? I.e.
>
> if (bus_freq_hz <= I2C_MAX_STANDARD_MODE_FREQ)
> return "Standard Mode (max 100 kHz)";
> else if (bus_freq_hz <= ... )
>
> ?
Can we add this later if needed?
Because in such case additionally printing bus_freq_hz will be fine, no?
But putting max to each frequency representation in the list of strings sounds
good to me.
--
With Best Regards,
Andy Shevchenko
> Can we add this later if needed?
> Because in such case additionally printing bus_freq_hz will be fine, no?
Yes, we can do that.
> But putting max to each frequency representation in the list of strings sounds
> good to me.
It is not important to me if we are going to change that later anyhow.
I'll leave it to you guys.
On Fri, Apr 9, 2021 at 2:37 PM Wolfram Sang <[email protected]> wrote:
>
>
> > Can we add this later if needed?
> > Because in such case additionally printing bus_freq_hz will be fine, no?
>
> Yes, we can do that.
>
> > But putting max to each frequency representation in the list of strings sounds
> > good to me.
>
> It is not important to me if we are going to change that later anyhow.
> I'll leave it to you guys.
Thanks, I think the series is okay to go as is.
--
With Best Regards,
Andy Shevchenko
On 2021/4/9 19:40, Andy Shevchenko wrote:
> On Fri, Apr 9, 2021 at 2:37 PM Wolfram Sang <[email protected]> wrote:
>>
>>
>>> Can we add this later if needed?
>>> Because in such case additionally printing bus_freq_hz will be fine, no?
>>
>> Yes, we can do that.
>>
>>> But putting max to each frequency representation in the list of strings sounds
>>> good to me.
>>
>> It is not important to me if we are going to change that later anyhow.
>> I'll leave it to you guys.
>
> Thanks, I think the series is okay to go as is.
>
sorry for the late reply. we can have this series applied if possible,
or you may apply the changed patch below (please let me know if you
want the whole series updated).
I didn't realize this, sorry. our two users don't have this situation.
thanks Wolfram and Andy!
Yicong.
From 14da3be8d85536c16adbc4006fc12c6837ef7474 Mon Sep 17 00:00:00 2001
From: Yicong Yang <[email protected]>
Date: Sat, 27 Mar 2021 11:48:25 +0800
Subject: [PATCH] i2c: core: add api to provide frequency mode strings
Some I2C drivers like Designware and HiSilicon will print the
bus frequency mode information, so add a public one that everyone
can make use of.
Tested-by: Jarkko Nikula <[email protected]>
Reviewed-by: Jarkko Nikula <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Signed-off-by: Yicong Yang <[email protected]>
---
drivers/i2c/i2c-core-base.c | 19 +++++++++++++++++++
include/linux/i2c.h | 3 +++
2 files changed, 22 insertions(+)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index de9402c..53836b5 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -76,6 +76,25 @@ void i2c_transfer_trace_unreg(void)
static_branch_dec(&i2c_trace_msg_key);
}
+const char *i2c_freq_mode_string(u32 bus_freq_hz)
+{
+ if (bus_freq_hz <= I2C_MAX_STANDARD_MODE_FREQ)
+ return "Standard Mode (max 100 kHz)";
+ else if (bus_freq_hz <= I2C_MAX_FAST_MODE_FREQ)
+ return "Fast Mode (max 400 kHz)";
+ else if (bus_freq_hz <= I2C_MAX_FAST_MODE_PLUS_FREQ)
+ return "Fast Mode Plus (max 1.0 MHz)";
+ else if (bus_freq_hz <= I2C_MAX_TURBO_MODE_FREQ)
+ return "Turbo Mode (max 1.4 MHz)";
+ else if (bus_freq_hz <= I2C_MAX_HIGH_SPEED_MODE_FREQ)
+ return "High Speed Mode (max 3.4 MHz)";
+ else if (bus_freq_hz <= I2C_MAX_ULTRA_FAST_MODE_FREQ)
+ return "Ultra Fast Mode (max 5.0 MHz)";
+ else
+ return "Unknown Mode";
+}
+EXPORT_SYMBOL_GPL(i2c_freq_mode_string);
+
const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
const struct i2c_client *client)
{
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 10bd0b0..0813be1 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -51,6 +51,9 @@ struct module;
struct property_entry;
#if IS_ENABLED(CONFIG_I2C)
+/* Return the Frequency mode string based on the bus frequency */
+const char *i2c_freq_mode_string(u32 bus_freq_hz);
+
/*
* The master routines are the ones normally used to transmit data to devices
* on a bus (or read from them). Apart from two basic transfer functions to
--
2.8.1