Skip to content

Commit 3b4c747

Browse files
Yicong Yangwsakernel
authored andcommitted
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]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 07740c9 commit 3b4c747

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

drivers/i2c/i2c-core-base.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,27 @@ void i2c_transfer_trace_unreg(void)
7676
static_branch_dec(&i2c_trace_msg_key);
7777
}
7878

79+
const char *i2c_freq_mode_string(u32 bus_freq_hz)
80+
{
81+
switch (bus_freq_hz) {
82+
case I2C_MAX_STANDARD_MODE_FREQ:
83+
return "Standard Mode (100 kHz)";
84+
case I2C_MAX_FAST_MODE_FREQ:
85+
return "Fast Mode (400 kHz)";
86+
case I2C_MAX_FAST_MODE_PLUS_FREQ:
87+
return "Fast Mode Plus (1.0 MHz)";
88+
case I2C_MAX_TURBO_MODE_FREQ:
89+
return "Turbo Mode (1.4 MHz)";
90+
case I2C_MAX_HIGH_SPEED_MODE_FREQ:
91+
return "High Speed Mode (3.4 MHz)";
92+
case I2C_MAX_ULTRA_FAST_MODE_FREQ:
93+
return "Ultra Fast Mode (5.0 MHz)";
94+
default:
95+
return "Unknown Mode";
96+
}
97+
}
98+
EXPORT_SYMBOL_GPL(i2c_freq_mode_string);
99+
79100
const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
80101
const struct i2c_client *client)
81102
{

include/linux/i2c.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ struct module;
5151
struct property_entry;
5252

5353
#if IS_ENABLED(CONFIG_I2C)
54+
/* Return the Frequency mode string based on the bus frequency */
55+
const char *i2c_freq_mode_string(u32 bus_freq_hz);
56+
5457
/*
5558
* The master routines are the ones normally used to transmit data to devices
5659
* on a bus (or read from them). Apart from two basic transfer functions to

0 commit comments

Comments
 (0)