Skip to content

Commit e6282fc

Browse files
andy-shevWolfram Sang
authored andcommitted
i2c: core: Provide generic definitions for bus frequencies
There are few maximum bus frequencies being used in the I²C core code. Provide generic definitions for bus frequencies and use them in the core. The drivers may use predefined constants where it is appropriate. Some of them are already using these under slightly different names. We will convert them later to use newly introduced defines. Note, the name of modes are chosen to follow well established naming scheme [1]. These definitions will also help to avoid typos in the numbers that may lead to subtle errors. [1]: https://en.wikipedia.org/wiki/I%C2%B2C#Differences_between_modes Acked-by: Mika Westerberg <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent e7c69fd commit e6282fc

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

drivers/i2c/i2c-core-acpi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static acpi_status i2c_acpi_lookup_speed(acpi_handle handle, u32 level,
318318
lookup->min_speed = lookup->speed;
319319

320320
if (acpi_match_device_ids(adev, i2c_acpi_force_400khz_device_ids) == 0)
321-
lookup->force_speed = 400000;
321+
lookup->force_speed = I2C_MAX_FAST_MODE_FREQ;
322322

323323
return AE_OK;
324324
}

drivers/i2c/i2c-core-base.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,21 +1612,21 @@ void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t, bool use_de
16121612

16131613
ret = device_property_read_u32(dev, "clock-frequency", &t->bus_freq_hz);
16141614
if (ret && use_defaults)
1615-
t->bus_freq_hz = 100000;
1615+
t->bus_freq_hz = I2C_MAX_STANDARD_MODE_FREQ;
16161616

16171617
ret = device_property_read_u32(dev, "i2c-scl-rising-time-ns", &t->scl_rise_ns);
16181618
if (ret && use_defaults) {
1619-
if (t->bus_freq_hz <= 100000)
1619+
if (t->bus_freq_hz <= I2C_MAX_STANDARD_MODE_FREQ)
16201620
t->scl_rise_ns = 1000;
1621-
else if (t->bus_freq_hz <= 400000)
1621+
else if (t->bus_freq_hz <= I2C_MAX_FAST_MODE_FREQ)
16221622
t->scl_rise_ns = 300;
16231623
else
16241624
t->scl_rise_ns = 120;
16251625
}
16261626

16271627
ret = device_property_read_u32(dev, "i2c-scl-falling-time-ns", &t->scl_fall_ns);
16281628
if (ret && use_defaults) {
1629-
if (t->bus_freq_hz <= 400000)
1629+
if (t->bus_freq_hz <= I2C_MAX_FAST_MODE_FREQ)
16301630
t->scl_fall_ns = 300;
16311631
else
16321632
t->scl_fall_ns = 120;

include/linux/i2c.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ enum i2c_slave_event;
3939
typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
4040
enum i2c_slave_event event, u8 *val);
4141

42+
/* I2C Frequency Modes */
43+
#define I2C_MAX_STANDARD_MODE_FREQ 100000
44+
#define I2C_MAX_FAST_MODE_FREQ 400000
45+
#define I2C_MAX_FAST_MODE_PLUS_FREQ 1000000
46+
#define I2C_MAX_TURBO_MODE_FREQ 1400000
47+
#define I2C_MAX_HIGH_SPEED_MODE_FREQ 3400000
48+
#define I2C_MAX_ULTRA_FAST_MODE_FREQ 5000000
49+
4250
struct module;
4351
struct property_entry;
4452

0 commit comments

Comments
 (0)