From c7c61df094b7b10a357578318afa886f6afe04a8 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Wed, 19 Jun 2024 08:25:06 -0400 Subject: [PATCH] Fixes for 5.4 Signed-off-by: Sasha Levin --- ...-functionality-flags-of-the-slave-on.patch | 44 + ...-generic-definitions-for-bus-frequen.patch | 103 ++ ...etect-the-fifo-size-in-the-common-co.patch | 153 ++ ...iscard-i2c_dw_read_comp_param-functi.patch | 54 + ...ix-the-functionality-flags-of-the-sl.patch | 46 + ...ove-configuration-routines-to-respec.patch | 168 ++ ...generic-definitions-for-bus-frequenc.patch | 1429 +++++++++++++++++ queue-5.4/series | 8 + ...da-check-whether-the-media-is-initia.patch | 61 + 9 files changed, 2066 insertions(+) create mode 100644 queue-5.4/i2c-at91-fix-the-functionality-flags-of-the-slave-on.patch create mode 100644 queue-5.4/i2c-core-provide-generic-definitions-for-bus-frequen.patch create mode 100644 queue-5.4/i2c-designware-detect-the-fifo-size-in-the-common-co.patch create mode 100644 queue-5.4/i2c-designware-discard-i2c_dw_read_comp_param-functi.patch create mode 100644 queue-5.4/i2c-designware-fix-the-functionality-flags-of-the-sl.patch create mode 100644 queue-5.4/i2c-designware-move-configuration-routines-to-respec.patch create mode 100644 queue-5.4/i2c-drivers-use-generic-definitions-for-bus-frequenc.patch create mode 100644 queue-5.4/usb-storage-alauda-check-whether-the-media-is-initia.patch diff --git a/queue-5.4/i2c-at91-fix-the-functionality-flags-of-the-slave-on.patch b/queue-5.4/i2c-at91-fix-the-functionality-flags-of-the-slave-on.patch new file mode 100644 index 00000000000..7ed6ae55dd3 --- /dev/null +++ b/queue-5.4/i2c-at91-fix-the-functionality-flags-of-the-slave-on.patch @@ -0,0 +1,44 @@ +From 4b0ea14af0fa8e0271cfabe79c9220b89b9122e5 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 31 May 2024 11:19:14 +0200 +Subject: i2c: at91: Fix the functionality flags of the slave-only interface + +From: Jean Delvare + +[ Upstream commit d6d5645e5fc1233a7ba950de4a72981c394a2557 ] + +When an I2C adapter acts only as a slave, it should not claim to +support I2C master capabilities. + +Fixes: 9d3ca54b550c ("i2c: at91: added slave mode support") +Signed-off-by: Jean Delvare +Cc: Juergen Fitschen +Cc: Ludovic Desroches +Cc: Codrin Ciubotariu +Cc: Andi Shyti +Cc: Nicolas Ferre +Cc: Alexandre Belloni +Cc: Claudiu Beznea +Signed-off-by: Andi Shyti +Signed-off-by: Sasha Levin +--- + drivers/i2c/busses/i2c-at91-slave.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/drivers/i2c/busses/i2c-at91-slave.c b/drivers/i2c/busses/i2c-at91-slave.c +index d6eeea5166c04..131a67d9d4a68 100644 +--- a/drivers/i2c/busses/i2c-at91-slave.c ++++ b/drivers/i2c/busses/i2c-at91-slave.c +@@ -106,8 +106,7 @@ static int at91_unreg_slave(struct i2c_client *slave) + + static u32 at91_twi_func(struct i2c_adapter *adapter) + { +- return I2C_FUNC_SLAVE | I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL +- | I2C_FUNC_SMBUS_READ_BLOCK_DATA; ++ return I2C_FUNC_SLAVE; + } + + static const struct i2c_algorithm at91_twi_algorithm_slave = { +-- +2.43.0 + diff --git a/queue-5.4/i2c-core-provide-generic-definitions-for-bus-frequen.patch b/queue-5.4/i2c-core-provide-generic-definitions-for-bus-frequen.patch new file mode 100644 index 00000000000..6c181f7cb29 --- /dev/null +++ b/queue-5.4/i2c-core-provide-generic-definitions-for-bus-frequen.patch @@ -0,0 +1,103 @@ +From f691d0cbdf9b9b179ffef64a78ada25c3e42d2ff Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 24 Mar 2020 14:32:11 +0200 +Subject: i2c: core: Provide generic definitions for bus frequencies +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Andy Shevchenko + +[ Upstream commit e6282fc6f889debe4d6eb6332dc6e49739faa5cb ] + +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 +Signed-off-by: Andy Shevchenko +Signed-off-by: Wolfram Sang +Stable-dep-of: cbf3fb5b29e9 ("i2c: designware: Fix the functionality flags of the slave-only interface") +Signed-off-by: Sasha Levin +--- + drivers/i2c/i2c-core-acpi.c | 2 +- + drivers/i2c/i2c-core-base.c | 8 ++++---- + include/linux/i2c.h | 8 ++++++++ + 3 files changed, 13 insertions(+), 5 deletions(-) + +diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c +index fe466ee4c49bf..17640e2230b61 100644 +--- a/drivers/i2c/i2c-core-acpi.c ++++ b/drivers/i2c/i2c-core-acpi.c +@@ -328,7 +328,7 @@ static acpi_status i2c_acpi_lookup_speed(acpi_handle handle, u32 level, + lookup->min_speed = lookup->speed; + + if (acpi_match_device_ids(adev, i2c_acpi_force_400khz_device_ids) == 0) +- lookup->force_speed = 400000; ++ lookup->force_speed = I2C_MAX_FAST_MODE_FREQ; + + return AE_OK; + } +diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c +index cf9ad03bb34de..4972cc0f9f9ac 100644 +--- a/drivers/i2c/i2c-core-base.c ++++ b/drivers/i2c/i2c-core-base.c +@@ -1650,13 +1650,13 @@ void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t, bool use_de + + ret = device_property_read_u32(dev, "clock-frequency", &t->bus_freq_hz); + if (ret && use_defaults) +- t->bus_freq_hz = 100000; ++ t->bus_freq_hz = I2C_MAX_STANDARD_MODE_FREQ; + + ret = device_property_read_u32(dev, "i2c-scl-rising-time-ns", &t->scl_rise_ns); + if (ret && use_defaults) { +- if (t->bus_freq_hz <= 100000) ++ if (t->bus_freq_hz <= I2C_MAX_STANDARD_MODE_FREQ) + t->scl_rise_ns = 1000; +- else if (t->bus_freq_hz <= 400000) ++ else if (t->bus_freq_hz <= I2C_MAX_FAST_MODE_FREQ) + t->scl_rise_ns = 300; + else + t->scl_rise_ns = 120; +@@ -1664,7 +1664,7 @@ void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t, bool use_de + + ret = device_property_read_u32(dev, "i2c-scl-falling-time-ns", &t->scl_fall_ns); + if (ret && use_defaults) { +- if (t->bus_freq_hz <= 400000) ++ if (t->bus_freq_hz <= I2C_MAX_FAST_MODE_FREQ) + t->scl_fall_ns = 300; + else + t->scl_fall_ns = 120; +diff --git a/include/linux/i2c.h b/include/linux/i2c.h +index af2b799d7a665..3d0008c41bed8 100644 +--- a/include/linux/i2c.h ++++ b/include/linux/i2c.h +@@ -39,6 +39,14 @@ enum i2c_slave_event; + typedef int (*i2c_slave_cb_t)(struct i2c_client *client, + enum i2c_slave_event event, u8 *val); + ++/* I2C Frequency Modes */ ++#define I2C_MAX_STANDARD_MODE_FREQ 100000 ++#define I2C_MAX_FAST_MODE_FREQ 400000 ++#define I2C_MAX_FAST_MODE_PLUS_FREQ 1000000 ++#define I2C_MAX_TURBO_MODE_FREQ 1400000 ++#define I2C_MAX_HIGH_SPEED_MODE_FREQ 3400000 ++#define I2C_MAX_ULTRA_FAST_MODE_FREQ 5000000 ++ + struct module; + struct property_entry; + +-- +2.43.0 + diff --git a/queue-5.4/i2c-designware-detect-the-fifo-size-in-the-common-co.patch b/queue-5.4/i2c-designware-detect-the-fifo-size-in-the-common-co.patch new file mode 100644 index 00000000000..29e6c88814e --- /dev/null +++ b/queue-5.4/i2c-designware-detect-the-fifo-size-in-the-common-co.patch @@ -0,0 +1,153 @@ +From d566760563316f41fe836ccce70069d512958423 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 6 Mar 2020 16:19:54 +0300 +Subject: i2c: designware: Detect the FIFO size in the common code + +From: Serge Semin + +[ Upstream commit 1f1a714658307a1a5ec65b0a23d87a87da64c86f ] + +The problem with detecting the FIFO depth in the platform driver +is that in order to implement this we have to access the controller +IC_COMP_PARAM_1 register. Currently it's done before the +i2c_dw_set_reg_access() method execution, which is errors prone since +the method determines the registers endianness and access mode and we +can't use dw_readl/dw_writel accessors before this information is +retrieved. We also can't move the i2c_dw_set_reg_access() function +invocation to after the master/slave probe functions call (when endianness +and access mode are determined), since the FIFO depth information is used +by them for initializations. So in order to fix the problem we have no +choice but to move the FIFO size detection methods to the common code and +call it at the probe stage. + +Signed-off-by: Serge Semin +Signed-off-by: Alexey Malahov +Reviewed-by: Andy Shevchenko +Acked-by: Jarkko Nikula +Signed-off-by: Wolfram Sang +Stable-dep-of: cbf3fb5b29e9 ("i2c: designware: Fix the functionality flags of the slave-only interface") +Signed-off-by: Sasha Levin +--- + drivers/i2c/busses/i2c-designware-common.c | 22 +++++++++++++++++++ + drivers/i2c/busses/i2c-designware-core.h | 1 + + drivers/i2c/busses/i2c-designware-master.c | 2 ++ + drivers/i2c/busses/i2c-designware-platdrv.c | 24 --------------------- + drivers/i2c/busses/i2c-designware-slave.c | 2 ++ + 5 files changed, 27 insertions(+), 24 deletions(-) + +diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c +index c9036675bd779..2abfed2b3e875 100644 +--- a/drivers/i2c/busses/i2c-designware-common.c ++++ b/drivers/i2c/busses/i2c-designware-common.c +@@ -341,6 +341,28 @@ int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev) + return -EIO; + } + ++void i2c_dw_set_fifo_size(struct dw_i2c_dev *dev) ++{ ++ u32 param, tx_fifo_depth, rx_fifo_depth; ++ ++ /* ++ * Try to detect the FIFO depth if not set by interface driver, ++ * the depth could be from 2 to 256 from HW spec. ++ */ ++ param = dw_readl(dev, DW_IC_COMP_PARAM_1); ++ tx_fifo_depth = ((param >> 16) & 0xff) + 1; ++ rx_fifo_depth = ((param >> 8) & 0xff) + 1; ++ if (!dev->tx_fifo_depth) { ++ dev->tx_fifo_depth = tx_fifo_depth; ++ dev->rx_fifo_depth = rx_fifo_depth; ++ } else if (tx_fifo_depth >= 2) { ++ dev->tx_fifo_depth = min_t(u32, dev->tx_fifo_depth, ++ tx_fifo_depth); ++ dev->rx_fifo_depth = min_t(u32, dev->rx_fifo_depth, ++ rx_fifo_depth); ++ } ++} ++ + u32 i2c_dw_func(struct i2c_adapter *adap) + { + struct dw_i2c_dev *dev = i2c_get_adapdata(adap); +diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h +index 67edbbde1070a..3fbc9f22fcf1c 100644 +--- a/drivers/i2c/busses/i2c-designware-core.h ++++ b/drivers/i2c/busses/i2c-designware-core.h +@@ -297,6 +297,7 @@ int i2c_dw_acquire_lock(struct dw_i2c_dev *dev); + void i2c_dw_release_lock(struct dw_i2c_dev *dev); + int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev); + int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev); ++void i2c_dw_set_fifo_size(struct dw_i2c_dev *dev); + u32 i2c_dw_func(struct i2c_adapter *adap); + void i2c_dw_disable(struct dw_i2c_dev *dev); + void i2c_dw_disable_int(struct dw_i2c_dev *dev); +diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c +index e8b328242256e..05da900cf3759 100644 +--- a/drivers/i2c/busses/i2c-designware-master.c ++++ b/drivers/i2c/busses/i2c-designware-master.c +@@ -698,6 +698,8 @@ int i2c_dw_probe(struct dw_i2c_dev *dev) + if (ret) + return ret; + ++ i2c_dw_set_fifo_size(dev); ++ + ret = dev->init(dev); + if (ret) + return ret; +diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c +index 75313c80f132f..3a094ce343f43 100644 +--- a/drivers/i2c/busses/i2c-designware-platdrv.c ++++ b/drivers/i2c/busses/i2c-designware-platdrv.c +@@ -218,28 +218,6 @@ static void i2c_dw_configure_slave(struct dw_i2c_dev *dev) + dev->mode = DW_IC_SLAVE; + } + +-static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev) +-{ +- u32 param, tx_fifo_depth, rx_fifo_depth; +- +- /* +- * Try to detect the FIFO depth if not set by interface driver, +- * the depth could be from 2 to 256 from HW spec. +- */ +- param = i2c_dw_read_comp_param(dev); +- tx_fifo_depth = ((param >> 16) & 0xff) + 1; +- rx_fifo_depth = ((param >> 8) & 0xff) + 1; +- if (!dev->tx_fifo_depth) { +- dev->tx_fifo_depth = tx_fifo_depth; +- dev->rx_fifo_depth = rx_fifo_depth; +- } else if (tx_fifo_depth >= 2) { +- dev->tx_fifo_depth = min_t(u32, dev->tx_fifo_depth, +- tx_fifo_depth); +- dev->rx_fifo_depth = min_t(u32, dev->rx_fifo_depth, +- rx_fifo_depth); +- } +-} +- + static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev) + { + pm_runtime_disable(dev->dev); +@@ -370,8 +348,6 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) + div_u64(clk_khz * t->sda_hold_ns + 500000, 1000000); + } + +- dw_i2c_set_fifo_size(dev); +- + adap = &dev->adapter; + adap->owner = THIS_MODULE; + adap->class = I2C_CLASS_DEPRECATED; +diff --git a/drivers/i2c/busses/i2c-designware-slave.c b/drivers/i2c/busses/i2c-designware-slave.c +index f5f001738df5e..0fc3aa31d46aa 100644 +--- a/drivers/i2c/busses/i2c-designware-slave.c ++++ b/drivers/i2c/busses/i2c-designware-slave.c +@@ -260,6 +260,8 @@ int i2c_dw_probe_slave(struct dw_i2c_dev *dev) + if (ret) + return ret; + ++ i2c_dw_set_fifo_size(dev); ++ + ret = dev->init(dev); + if (ret) + return ret; +-- +2.43.0 + diff --git a/queue-5.4/i2c-designware-discard-i2c_dw_read_comp_param-functi.patch b/queue-5.4/i2c-designware-discard-i2c_dw_read_comp_param-functi.patch new file mode 100644 index 00000000000..248e1bd0db4 --- /dev/null +++ b/queue-5.4/i2c-designware-discard-i2c_dw_read_comp_param-functi.patch @@ -0,0 +1,54 @@ +From 7d20a99f7db1c4a8974b44e67fc93119400238f9 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 6 Mar 2020 16:19:56 +0300 +Subject: i2c: designware: Discard i2c_dw_read_comp_param() function + +From: Serge Semin + +[ Upstream commit d816f216c36445d1f9180b32ac30a3094317d6bb ] + +There is no code left in the kernel which would be using the function. +So just remove it. + +Signed-off-by: Serge Semin +Signed-off-by: Alexey Malahov +Acked-by: Jarkko Nikula +Signed-off-by: Wolfram Sang +Stable-dep-of: cbf3fb5b29e9 ("i2c: designware: Fix the functionality flags of the slave-only interface") +Signed-off-by: Sasha Levin +--- + drivers/i2c/busses/i2c-designware-common.c | 6 ------ + drivers/i2c/busses/i2c-designware-core.h | 1 - + 2 files changed, 7 deletions(-) + +diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c +index 2abfed2b3e875..8ebe2ca13c8f6 100644 +--- a/drivers/i2c/busses/i2c-designware-common.c ++++ b/drivers/i2c/busses/i2c-designware-common.c +@@ -385,11 +385,5 @@ void i2c_dw_disable_int(struct dw_i2c_dev *dev) + dw_writel(dev, 0, DW_IC_INTR_MASK); + } + +-u32 i2c_dw_read_comp_param(struct dw_i2c_dev *dev) +-{ +- return dw_readl(dev, DW_IC_COMP_PARAM_1); +-} +-EXPORT_SYMBOL_GPL(i2c_dw_read_comp_param); +- + MODULE_DESCRIPTION("Synopsys DesignWare I2C bus adapter core"); + MODULE_LICENSE("GPL"); +diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h +index 3fbc9f22fcf1c..b220ad64c38d7 100644 +--- a/drivers/i2c/busses/i2c-designware-core.h ++++ b/drivers/i2c/busses/i2c-designware-core.h +@@ -314,7 +314,6 @@ static inline void __i2c_dw_disable_nowait(struct dw_i2c_dev *dev) + + void __i2c_dw_disable(struct dw_i2c_dev *dev); + +-extern u32 i2c_dw_read_comp_param(struct dw_i2c_dev *dev); + extern int i2c_dw_probe(struct dw_i2c_dev *dev); + #if IS_ENABLED(CONFIG_I2C_DESIGNWARE_SLAVE) + extern int i2c_dw_probe_slave(struct dw_i2c_dev *dev); +-- +2.43.0 + diff --git a/queue-5.4/i2c-designware-fix-the-functionality-flags-of-the-sl.patch b/queue-5.4/i2c-designware-fix-the-functionality-flags-of-the-sl.patch new file mode 100644 index 00000000000..a3314204c15 --- /dev/null +++ b/queue-5.4/i2c-designware-fix-the-functionality-flags-of-the-sl.patch @@ -0,0 +1,46 @@ +From 231b0a8a10455d45900268361d468e59e23475c4 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 31 May 2024 11:17:48 +0200 +Subject: i2c: designware: Fix the functionality flags of the slave-only + interface + +From: Jean Delvare + +[ Upstream commit cbf3fb5b29e99e3689d63a88c3cddbffa1b8de99 ] + +When an I2C adapter acts only as a slave, it should not claim to +support I2C master capabilities. + +Fixes: 5b6d721b266a ("i2c: designware: enable SLAVE in platform module") +Signed-off-by: Jean Delvare +Cc: Luis Oliveira +Cc: Jarkko Nikula +Cc: Andy Shevchenko +Cc: Mika Westerberg +Cc: Jan Dabros +Cc: Andi Shyti +Reviewed-by: Andy Shevchenko +Acked-by: Jarkko Nikula +Tested-by: Jarkko Nikula +Signed-off-by: Andi Shyti +Signed-off-by: Sasha Levin +--- + drivers/i2c/busses/i2c-designware-slave.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/i2c/busses/i2c-designware-slave.c b/drivers/i2c/busses/i2c-designware-slave.c +index 52a0f118917e1..4ef8e9d7e545b 100644 +--- a/drivers/i2c/busses/i2c-designware-slave.c ++++ b/drivers/i2c/busses/i2c-designware-slave.c +@@ -243,7 +243,7 @@ static const struct i2c_algorithm i2c_dw_algo = { + + void i2c_dw_configure_slave(struct dw_i2c_dev *dev) + { +- dev->functionality = I2C_FUNC_SLAVE | DW_IC_DEFAULT_FUNCTIONALITY; ++ dev->functionality = I2C_FUNC_SLAVE; + + dev->slave_cfg = DW_IC_CON_RX_FIFO_FULL_HLD_CTRL | + DW_IC_CON_RESTART_EN | DW_IC_CON_STOP_DET_IFADDRESSED; +-- +2.43.0 + diff --git a/queue-5.4/i2c-designware-move-configuration-routines-to-respec.patch b/queue-5.4/i2c-designware-move-configuration-routines-to-respec.patch new file mode 100644 index 00000000000..dce77e29cb8 --- /dev/null +++ b/queue-5.4/i2c-designware-move-configuration-routines-to-respec.patch @@ -0,0 +1,168 @@ +From 41c964e72952bac10934f86768c4cce98101b147 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sat, 25 Apr 2020 16:44:45 +0300 +Subject: i2c: designware: Move configuration routines to respective modules + +From: Andy Shevchenko + +[ Upstream commit 3ebe40ed1c39016eeae947acc9fd57d6b10d43b2 ] + +Move configuration routines to respective modules, i.e. master and slave. + +Signed-off-by: Andy Shevchenko +Signed-off-by: Wolfram Sang +Stable-dep-of: cbf3fb5b29e9 ("i2c: designware: Fix the functionality flags of the slave-only interface") +Signed-off-by: Sasha Levin +--- + drivers/i2c/busses/i2c-designware-core.h | 12 +++++++ + drivers/i2c/busses/i2c-designware-master.c | 24 +++++++++++++ + drivers/i2c/busses/i2c-designware-platdrv.c | 38 +-------------------- + drivers/i2c/busses/i2c-designware-slave.c | 11 ++++++ + 4 files changed, 48 insertions(+), 37 deletions(-) + +diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h +index b220ad64c38d7..b2f894f685233 100644 +--- a/drivers/i2c/busses/i2c-designware-core.h ++++ b/drivers/i2c/busses/i2c-designware-core.h +@@ -314,13 +314,25 @@ static inline void __i2c_dw_disable_nowait(struct dw_i2c_dev *dev) + + void __i2c_dw_disable(struct dw_i2c_dev *dev); + ++extern void i2c_dw_configure_master(struct dw_i2c_dev *dev); + extern int i2c_dw_probe(struct dw_i2c_dev *dev); ++ + #if IS_ENABLED(CONFIG_I2C_DESIGNWARE_SLAVE) ++extern void i2c_dw_configure_slave(struct dw_i2c_dev *dev); + extern int i2c_dw_probe_slave(struct dw_i2c_dev *dev); + #else ++static inline void i2c_dw_configure_slave(struct dw_i2c_dev *dev) { } + static inline int i2c_dw_probe_slave(struct dw_i2c_dev *dev) { return -EINVAL; } + #endif + ++static inline void i2c_dw_configure(struct dw_i2c_dev *dev) ++{ ++ if (i2c_detect_slave_mode(dev->dev)) ++ i2c_dw_configure_slave(dev); ++ else ++ i2c_dw_configure_master(dev); ++} ++ + #if IS_ENABLED(CONFIG_I2C_DESIGNWARE_BAYTRAIL) + extern int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev); + #else +diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c +index 05da900cf3759..9a52ad00c4db5 100644 +--- a/drivers/i2c/busses/i2c-designware-master.c ++++ b/drivers/i2c/busses/i2c-designware-master.c +@@ -632,6 +632,30 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) + return IRQ_HANDLED; + } + ++void i2c_dw_configure_master(struct dw_i2c_dev *dev) ++{ ++ struct i2c_timings *t = &dev->timings; ++ ++ dev->functionality = I2C_FUNC_10BIT_ADDR | DW_IC_DEFAULT_FUNCTIONALITY; ++ ++ dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | ++ DW_IC_CON_RESTART_EN; ++ ++ dev->mode = DW_IC_MASTER; ++ ++ switch (t->bus_freq_hz) { ++ case I2C_MAX_STANDARD_MODE_FREQ: ++ dev->master_cfg |= DW_IC_CON_SPEED_STD; ++ break; ++ case I2C_MAX_HIGH_SPEED_MODE_FREQ: ++ dev->master_cfg |= DW_IC_CON_SPEED_HIGH; ++ break; ++ default: ++ dev->master_cfg |= DW_IC_CON_SPEED_FAST; ++ } ++} ++EXPORT_SYMBOL_GPL(i2c_dw_configure_master); ++ + static void i2c_dw_prepare_recovery(struct i2c_adapter *adap) + { + struct dw_i2c_dev *dev = i2c_get_adapdata(adap); +diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c +index 50a9e29df9152..a4f0e94833aa2 100644 +--- a/drivers/i2c/busses/i2c-designware-platdrv.c ++++ b/drivers/i2c/busses/i2c-designware-platdrv.c +@@ -185,39 +185,6 @@ static inline int dw_i2c_of_configure(struct platform_device *pdev) + } + #endif + +-static void i2c_dw_configure_master(struct dw_i2c_dev *dev) +-{ +- struct i2c_timings *t = &dev->timings; +- +- dev->functionality = I2C_FUNC_10BIT_ADDR | DW_IC_DEFAULT_FUNCTIONALITY; +- +- dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | +- DW_IC_CON_RESTART_EN; +- +- dev->mode = DW_IC_MASTER; +- +- switch (t->bus_freq_hz) { +- case I2C_MAX_STANDARD_MODE_FREQ: +- dev->master_cfg |= DW_IC_CON_SPEED_STD; +- break; +- case I2C_MAX_HIGH_SPEED_MODE_FREQ: +- dev->master_cfg |= DW_IC_CON_SPEED_HIGH; +- break; +- default: +- dev->master_cfg |= DW_IC_CON_SPEED_FAST; +- } +-} +- +-static void i2c_dw_configure_slave(struct dw_i2c_dev *dev) +-{ +- dev->functionality = I2C_FUNC_SLAVE | DW_IC_DEFAULT_FUNCTIONALITY; +- +- dev->slave_cfg = DW_IC_CON_RX_FIFO_FULL_HLD_CTRL | +- DW_IC_CON_RESTART_EN | DW_IC_CON_STOP_DET_IFADDRESSED; +- +- dev->mode = DW_IC_SLAVE; +-} +- + static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev) + { + pm_runtime_disable(dev->dev); +@@ -322,10 +289,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) + if (ret) + goto exit_reset; + +- if (i2c_detect_slave_mode(&pdev->dev)) +- i2c_dw_configure_slave(dev); +- else +- i2c_dw_configure_master(dev); ++ i2c_dw_configure(dev); + + /* Optional interface clock */ + dev->pclk = devm_clk_get_optional(&pdev->dev, "pclk"); +diff --git a/drivers/i2c/busses/i2c-designware-slave.c b/drivers/i2c/busses/i2c-designware-slave.c +index 0fc3aa31d46aa..52a0f118917e1 100644 +--- a/drivers/i2c/busses/i2c-designware-slave.c ++++ b/drivers/i2c/busses/i2c-designware-slave.c +@@ -241,6 +241,17 @@ static const struct i2c_algorithm i2c_dw_algo = { + .unreg_slave = i2c_dw_unreg_slave, + }; + ++void i2c_dw_configure_slave(struct dw_i2c_dev *dev) ++{ ++ dev->functionality = I2C_FUNC_SLAVE | DW_IC_DEFAULT_FUNCTIONALITY; ++ ++ dev->slave_cfg = DW_IC_CON_RX_FIFO_FULL_HLD_CTRL | ++ DW_IC_CON_RESTART_EN | DW_IC_CON_STOP_DET_IFADDRESSED; ++ ++ dev->mode = DW_IC_SLAVE; ++} ++EXPORT_SYMBOL_GPL(i2c_dw_configure_slave); ++ + int i2c_dw_probe_slave(struct dw_i2c_dev *dev) + { + struct i2c_adapter *adap = &dev->adapter; +-- +2.43.0 + diff --git a/queue-5.4/i2c-drivers-use-generic-definitions-for-bus-frequenc.patch b/queue-5.4/i2c-drivers-use-generic-definitions-for-bus-frequenc.patch new file mode 100644 index 00000000000..813dcf490b4 --- /dev/null +++ b/queue-5.4/i2c-drivers-use-generic-definitions-for-bus-frequenc.patch @@ -0,0 +1,1429 @@ +From 2b5a3c53e82a21b67aa5ae5a837043fc795b125e Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 24 Mar 2020 14:32:16 +0200 +Subject: i2c: drivers: Use generic definitions for bus frequencies + +From: Andy Shevchenko + +[ Upstream commit 90224e6468e15d5eb22a10ae1849cf8ca2e7360a ] + +Since we have generic definitions for bus frequencies, let's use them. + +Reviewed-by: Nicolas Saenz Julienne +Acked-by: Robert Richter +Reviewed-by: Thor Thayer +Acked-by: Elie Morisse +Acked-by: Nehal Shah +Reviewed-by: Brendan Higgins +Acked-by: Scott Branden +Reviewed-by: Mika Westerberg +Acked-by: Jarkko Nikula +Acked-by: Baruch Siach +Reviewed-by: Guenter Roeck +Acked-by: Oleksij Rempel +Acked-by: Vladimir Zapolskiy +Acked-by: Gregory CLEMENT +Reviewed-by: Linus Walleij +Reviewed-by: Manivannan Sadhasivam +Reviewed-by: Chris Brandt +Reviewed-by: Baolin Wang +Reviewed-by: Pierre-Yves MORDRET +Acked-by: Patrice Chotard +Acked-by: Ard Biesheuvel +Reviewed-by: Dmitry Osipenko +Acked-by: Masahiro Yamada +Signed-off-by: Andy Shevchenko +Signed-off-by: Wolfram Sang +Stable-dep-of: cbf3fb5b29e9 ("i2c: designware: Fix the functionality flags of the slave-only interface") +Signed-off-by: Sasha Levin +--- + drivers/i2c/busses/i2c-altera.c | 6 ++-- + drivers/i2c/busses/i2c-amd-mp2-plat.c | 27 +++++++++------ + drivers/i2c/busses/i2c-aspeed.c | 2 +- + drivers/i2c/busses/i2c-axxia.c | 4 +-- + drivers/i2c/busses/i2c-bcm-iproc.c | 14 ++++---- + drivers/i2c/busses/i2c-bcm-kona.c | 8 ++--- + drivers/i2c/busses/i2c-bcm2835.c | 2 +- + drivers/i2c/busses/i2c-cadence.c | 7 ++-- + drivers/i2c/busses/i2c-designware-platdrv.c | 37 ++++++++++++--------- + drivers/i2c/busses/i2c-digicolor.c | 3 +- + drivers/i2c/busses/i2c-diolan-u2c.c | 12 +++---- + drivers/i2c/busses/i2c-efm32.c | 2 +- + drivers/i2c/busses/i2c-exynos5.c | 18 ++++------ + drivers/i2c/busses/i2c-hix5hd2.c | 10 +++--- + drivers/i2c/busses/i2c-img-scb.c | 4 +-- + drivers/i2c/busses/i2c-imx-lpi2c.c | 16 +++------ + drivers/i2c/busses/i2c-imx.c | 5 +-- + drivers/i2c/busses/i2c-lpc2k.c | 6 ++-- + drivers/i2c/busses/i2c-mt65xx.c | 21 +++++------- + drivers/i2c/busses/i2c-mt7621.c | 2 +- + drivers/i2c/busses/i2c-mv64xxx.c | 6 ++-- + drivers/i2c/busses/i2c-mxs.c | 4 +-- + drivers/i2c/busses/i2c-nomadik.c | 8 ++--- + drivers/i2c/busses/i2c-omap.c | 2 +- + drivers/i2c/busses/i2c-owl.c | 9 ++--- + drivers/i2c/busses/i2c-qup.c | 11 ++---- + drivers/i2c/busses/i2c-riic.c | 6 ++-- + drivers/i2c/busses/i2c-rk3x.c | 12 +++---- + drivers/i2c/busses/i2c-s3c2410.c | 4 +-- + drivers/i2c/busses/i2c-sh_mobile.c | 9 ++--- + drivers/i2c/busses/i2c-sirf.c | 3 +- + drivers/i2c/busses/i2c-sprd.c | 9 ++--- + drivers/i2c/busses/i2c-st.c | 6 ++-- + drivers/i2c/busses/i2c-stm32f4.c | 10 +++--- + drivers/i2c/busses/i2c-stu300.c | 6 ++-- + drivers/i2c/busses/i2c-sun6i-p2wi.c | 2 +- + drivers/i2c/busses/i2c-synquacer.c | 6 ++-- + drivers/i2c/busses/i2c-tegra.c | 18 ++++------ + drivers/i2c/busses/i2c-thunderx-pcidrv.c | 2 +- + drivers/i2c/busses/i2c-uniphier-f.c | 6 ++-- + drivers/i2c/busses/i2c-uniphier.c | 7 ++-- + drivers/i2c/busses/i2c-wmt.c | 2 +- + drivers/i2c/busses/i2c-xlp9xx.c | 8 ++--- + drivers/i2c/busses/i2c-xlr.c | 2 +- + 44 files changed, 165 insertions(+), 199 deletions(-) + +diff --git a/drivers/i2c/busses/i2c-altera.c b/drivers/i2c/busses/i2c-altera.c +index a600424313701..16ddc26c00e65 100644 +--- a/drivers/i2c/busses/i2c-altera.c ++++ b/drivers/i2c/busses/i2c-altera.c +@@ -149,7 +149,7 @@ static void altr_i2c_init(struct altr_i2c_dev *idev) + (ALTR_I2C_THRESHOLD << ALTR_I2C_CTRL_TCT_SHFT); + u32 t_high, t_low; + +- if (idev->bus_clk_rate <= 100000) { ++ if (idev->bus_clk_rate <= I2C_MAX_STANDARD_MODE_FREQ) { + tmp &= ~ALTR_I2C_CTRL_BSPEED; + /* Standard mode SCL 50/50 */ + t_high = divisor * 1 / 2; +@@ -430,10 +430,10 @@ static int altr_i2c_probe(struct platform_device *pdev) + &idev->bus_clk_rate); + if (ret) { + dev_err(&pdev->dev, "Default to 100kHz\n"); +- idev->bus_clk_rate = 100000; /* default clock rate */ ++ idev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */ + } + +- if (idev->bus_clk_rate > 400000) { ++ if (idev->bus_clk_rate > I2C_MAX_FAST_MODE_FREQ) { + dev_err(&pdev->dev, "invalid clock-frequency %d\n", + idev->bus_clk_rate); + return -EINVAL; +diff --git a/drivers/i2c/busses/i2c-amd-mp2-plat.c b/drivers/i2c/busses/i2c-amd-mp2-plat.c +index f5b3f00c6559f..17df9e8845b67 100644 +--- a/drivers/i2c/busses/i2c-amd-mp2-plat.c ++++ b/drivers/i2c/busses/i2c-amd-mp2-plat.c +@@ -201,32 +201,37 @@ static int i2c_amd_resume(struct amd_i2c_common *i2c_common) + } + #endif + ++static const u32 supported_speeds[] = { ++ I2C_MAX_HIGH_SPEED_MODE_FREQ, ++ I2C_MAX_TURBO_MODE_FREQ, ++ I2C_MAX_FAST_MODE_PLUS_FREQ, ++ I2C_MAX_FAST_MODE_FREQ, ++ I2C_MAX_STANDARD_MODE_FREQ, ++}; ++ + static enum speed_enum i2c_amd_get_bus_speed(struct platform_device *pdev) + { + u32 acpi_speed; + int i; +- static const u32 supported_speeds[] = { +- 0, 100000, 400000, 1000000, 1400000, 3400000 +- }; + + acpi_speed = i2c_acpi_find_bus_speed(&pdev->dev); + /* round down to the lowest standard speed */ +- for (i = 1; i < ARRAY_SIZE(supported_speeds); i++) { +- if (acpi_speed < supported_speeds[i]) ++ for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) { ++ if (acpi_speed >= supported_speeds[i]) + break; + } +- acpi_speed = supported_speeds[i - 1]; ++ acpi_speed = i < ARRAY_SIZE(supported_speeds) ? supported_speeds[i] : 0; + + switch (acpi_speed) { +- case 100000: ++ case I2C_MAX_STANDARD_MODE_FREQ: + return speed100k; +- case 400000: ++ case I2C_MAX_FAST_MODE_FREQ: + return speed400k; +- case 1000000: ++ case I2C_MAX_FAST_MODE_PLUS_FREQ: + return speed1000k; +- case 1400000: ++ case I2C_MAX_TURBO_MODE_FREQ: + return speed1400k; +- case 3400000: ++ case I2C_MAX_HIGH_SPEED_MODE_FREQ: + return speed3400k; + default: + return speed400k; +diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c +index 3f0b072a4cc84..1c0ec6924aa1d 100644 +--- a/drivers/i2c/busses/i2c-aspeed.c ++++ b/drivers/i2c/busses/i2c-aspeed.c +@@ -1018,7 +1018,7 @@ static int aspeed_i2c_probe_bus(struct platform_device *pdev) + if (ret < 0) { + dev_err(&pdev->dev, + "Could not read bus-frequency property\n"); +- bus->bus_frequency = 100000; ++ bus->bus_frequency = I2C_MAX_STANDARD_MODE_FREQ; + } + + match = of_match_node(aspeed_i2c_bus_of_table, pdev->dev.of_node); +diff --git a/drivers/i2c/busses/i2c-axxia.c b/drivers/i2c/busses/i2c-axxia.c +index 0214daa913ff1..be3681d08a8da 100644 +--- a/drivers/i2c/busses/i2c-axxia.c ++++ b/drivers/i2c/busses/i2c-axxia.c +@@ -199,7 +199,7 @@ static int axxia_i2c_init(struct axxia_i2c_dev *idev) + /* Enable Master Mode */ + writel(0x1, idev->base + GLOBAL_CONTROL); + +- if (idev->bus_clk_rate <= 100000) { ++ if (idev->bus_clk_rate <= I2C_MAX_STANDARD_MODE_FREQ) { + /* Standard mode SCL 50/50, tSU:DAT = 250 ns */ + t_high = divisor * 1 / 2; + t_low = divisor * 1 / 2; +@@ -765,7 +765,7 @@ static int axxia_i2c_probe(struct platform_device *pdev) + + of_property_read_u32(np, "clock-frequency", &idev->bus_clk_rate); + if (idev->bus_clk_rate == 0) +- idev->bus_clk_rate = 100000; /* default clock rate */ ++ idev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */ + + ret = clk_prepare_enable(idev->i2c_clk); + if (ret) { +diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c +index cae34c55ae08b..d66df7f9cf3a0 100644 +--- a/drivers/i2c/busses/i2c-bcm-iproc.c ++++ b/drivers/i2c/busses/i2c-bcm-iproc.c +@@ -952,25 +952,25 @@ static int bcm_iproc_i2c_cfg_speed(struct bcm_iproc_i2c_dev *iproc_i2c) + if (ret < 0) { + dev_info(iproc_i2c->device, + "unable to interpret clock-frequency DT property\n"); +- bus_speed = 100000; ++ bus_speed = I2C_MAX_STANDARD_MODE_FREQ; + } + +- if (bus_speed < 100000) { ++ if (bus_speed < I2C_MAX_STANDARD_MODE_FREQ) { + dev_err(iproc_i2c->device, "%d Hz bus speed not supported\n", + bus_speed); + dev_err(iproc_i2c->device, + "valid speeds are 100khz and 400khz\n"); + return -EINVAL; +- } else if (bus_speed < 400000) { +- bus_speed = 100000; ++ } else if (bus_speed < I2C_MAX_FAST_MODE_FREQ) { ++ bus_speed = I2C_MAX_STANDARD_MODE_FREQ; + } else { +- bus_speed = 400000; ++ bus_speed = I2C_MAX_FAST_MODE_FREQ; + } + + iproc_i2c->bus_speed = bus_speed; + val = iproc_i2c_rd_reg(iproc_i2c, TIM_CFG_OFFSET); + val &= ~BIT(TIM_CFG_MODE_400_SHIFT); +- val |= (bus_speed == 400000) << TIM_CFG_MODE_400_SHIFT; ++ val |= (bus_speed == I2C_MAX_FAST_MODE_FREQ) << TIM_CFG_MODE_400_SHIFT; + iproc_i2c_wr_reg(iproc_i2c, TIM_CFG_OFFSET, val); + + dev_info(iproc_i2c->device, "bus set to %u Hz\n", bus_speed); +@@ -1123,7 +1123,7 @@ static int bcm_iproc_i2c_resume(struct device *dev) + /* configure to the desired bus speed */ + val = iproc_i2c_rd_reg(iproc_i2c, TIM_CFG_OFFSET); + val &= ~BIT(TIM_CFG_MODE_400_SHIFT); +- val |= (iproc_i2c->bus_speed == 400000) << TIM_CFG_MODE_400_SHIFT; ++ val |= (iproc_i2c->bus_speed == I2C_MAX_FAST_MODE_FREQ) << TIM_CFG_MODE_400_SHIFT; + iproc_i2c_wr_reg(iproc_i2c, TIM_CFG_OFFSET, val); + + bcm_iproc_i2c_enable_disable(iproc_i2c, true); +diff --git a/drivers/i2c/busses/i2c-bcm-kona.c b/drivers/i2c/busses/i2c-bcm-kona.c +index 4e489a9d16fb3..572aebbb254e7 100644 +--- a/drivers/i2c/busses/i2c-bcm-kona.c ++++ b/drivers/i2c/busses/i2c-bcm-kona.c +@@ -722,16 +722,16 @@ static int bcm_kona_i2c_assign_bus_speed(struct bcm_kona_i2c_dev *dev) + } + + switch (bus_speed) { +- case 100000: ++ case I2C_MAX_STANDARD_MODE_FREQ: + dev->std_cfg = &std_cfg_table[BCM_SPD_100K]; + break; +- case 400000: ++ case I2C_MAX_FAST_MODE_FREQ: + dev->std_cfg = &std_cfg_table[BCM_SPD_400K]; + break; +- case 1000000: ++ case I2C_MAX_FAST_MODE_PLUS_FREQ: + dev->std_cfg = &std_cfg_table[BCM_SPD_1MHZ]; + break; +- case 3400000: ++ case I2C_MAX_HIGH_SPEED_MODE_FREQ: + /* Send mastercode at 100k */ + dev->std_cfg = &std_cfg_table[BCM_SPD_100K]; + dev->hs_cfg = &hs_cfg_table[BCM_SPD_3P4MHZ]; +diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c +index c265fe4621621..1e23838fb4375 100644 +--- a/drivers/i2c/busses/i2c-bcm2835.c ++++ b/drivers/i2c/busses/i2c-bcm2835.c +@@ -444,7 +444,7 @@ static int bcm2835_i2c_probe(struct platform_device *pdev) + if (ret < 0) { + dev_warn(&pdev->dev, + "Could not read clock-frequency property\n"); +- bus_clk_rate = 100000; ++ bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; + } + + ret = clk_set_rate_exclusive(i2c_dev->bus_clk, bus_clk_rate); +diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c +index 72699fdd5d113..a8d84b968da6f 100644 +--- a/drivers/i2c/busses/i2c-cadence.c ++++ b/drivers/i2c/busses/i2c-cadence.c +@@ -104,9 +104,6 @@ + + #define DRIVER_NAME "cdns-i2c" + +-#define CDNS_I2C_SPEED_MAX 400000 +-#define CDNS_I2C_SPEED_DEFAULT 100000 +- + #define CDNS_I2C_DIVA_MAX 4 + #define CDNS_I2C_DIVB_MAX 64 + +@@ -934,8 +931,8 @@ static int cdns_i2c_probe(struct platform_device *pdev) + + ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency", + &id->i2c_clk); +- if (ret || (id->i2c_clk > CDNS_I2C_SPEED_MAX)) +- id->i2c_clk = CDNS_I2C_SPEED_DEFAULT; ++ if (ret || (id->i2c_clk > I2C_MAX_FAST_MODE_FREQ)) ++ id->i2c_clk = I2C_MAX_STANDARD_MODE_FREQ; + + cdns_i2c_writereg(CDNS_I2C_CR_ACK_EN | CDNS_I2C_CR_NEA | CDNS_I2C_CR_MS, + CDNS_I2C_CR_OFFSET); +diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c +index 3a094ce343f43..50a9e29df9152 100644 +--- a/drivers/i2c/busses/i2c-designware-platdrv.c ++++ b/drivers/i2c/busses/i2c-designware-platdrv.c +@@ -99,16 +99,16 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev) + dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt, &fs_ht); + + switch (t->bus_freq_hz) { +- case 100000: ++ case I2C_MAX_STANDARD_MODE_FREQ: + dev->sda_hold_time = ss_ht; + break; +- case 1000000: ++ case I2C_MAX_FAST_MODE_PLUS_FREQ: + dev->sda_hold_time = fp_ht; + break; +- case 3400000: ++ case I2C_MAX_HIGH_SPEED_MODE_FREQ: + dev->sda_hold_time = hs_ht; + break; +- case 400000: ++ case I2C_MAX_FAST_MODE_FREQ: + default: + dev->sda_hold_time = fs_ht; + break; +@@ -197,10 +197,10 @@ static void i2c_dw_configure_master(struct dw_i2c_dev *dev) + dev->mode = DW_IC_MASTER; + + switch (t->bus_freq_hz) { +- case 100000: ++ case I2C_MAX_STANDARD_MODE_FREQ: + dev->master_cfg |= DW_IC_CON_SPEED_STD; + break; +- case 3400000: ++ case I2C_MAX_HIGH_SPEED_MODE_FREQ: + dev->master_cfg |= DW_IC_CON_SPEED_HIGH; + break; + default: +@@ -226,6 +226,13 @@ static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev) + pm_runtime_put_noidle(dev->dev); + } + ++static const u32 supported_speeds[] = { ++ I2C_MAX_HIGH_SPEED_MODE_FREQ, ++ I2C_MAX_FAST_MODE_PLUS_FREQ, ++ I2C_MAX_FAST_MODE_FREQ, ++ I2C_MAX_STANDARD_MODE_FREQ, ++}; ++ + static int dw_i2c_plat_probe(struct platform_device *pdev) + { + struct dw_i2c_platform_data *pdata = dev_get_platdata(&pdev->dev); +@@ -235,9 +242,6 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) + u32 acpi_speed; + struct resource *mem; + int i, irq, ret; +- static const int supported_speeds[] = { +- 0, 100000, 400000, 1000000, 3400000 +- }; + + irq = platform_get_irq(pdev, 0); + if (irq < 0) +@@ -273,11 +277,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) + * Some DSTDs use a non standard speed, round down to the lowest + * standard speed. + */ +- for (i = 1; i < ARRAY_SIZE(supported_speeds); i++) { +- if (acpi_speed < supported_speeds[i]) ++ for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) { ++ if (acpi_speed >= supported_speeds[i]) + break; + } +- acpi_speed = supported_speeds[i - 1]; ++ acpi_speed = i < ARRAY_SIZE(supported_speeds) ? supported_speeds[i] : 0; + + /* + * Find bus speed from the "clock-frequency" device property, ACPI +@@ -288,7 +292,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) + else if (acpi_speed || t->bus_freq_hz) + t->bus_freq_hz = max(t->bus_freq_hz, acpi_speed); + else +- t->bus_freq_hz = 400000; ++ t->bus_freq_hz = I2C_MAX_FAST_MODE_FREQ; + + dev->flags |= (uintptr_t)device_get_match_data(&pdev->dev); + +@@ -302,8 +306,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) + * Only standard mode at 100kHz, fast mode at 400kHz, + * fast mode plus at 1MHz and high speed mode at 3.4MHz are supported. + */ +- if (t->bus_freq_hz != 100000 && t->bus_freq_hz != 400000 && +- t->bus_freq_hz != 1000000 && t->bus_freq_hz != 3400000) { ++ for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) { ++ if (t->bus_freq_hz == supported_speeds[i]) ++ break; ++ } ++ if (i == ARRAY_SIZE(supported_speeds)) { + dev_err(&pdev->dev, + "%d Hz is unsupported, only 100kHz, 400kHz, 1MHz and 3.4MHz are supported\n", + t->bus_freq_hz); +diff --git a/drivers/i2c/busses/i2c-digicolor.c b/drivers/i2c/busses/i2c-digicolor.c +index 3adf72540db13..056a5c4f0833c 100644 +--- a/drivers/i2c/busses/i2c-digicolor.c ++++ b/drivers/i2c/busses/i2c-digicolor.c +@@ -18,7 +18,6 @@ + #include + #include + +-#define DEFAULT_FREQ 100000 + #define TIMEOUT_MS 100 + + #define II_CONTROL 0x0 +@@ -300,7 +299,7 @@ static int dc_i2c_probe(struct platform_device *pdev) + + if (of_property_read_u32(pdev->dev.of_node, "clock-frequency", + &i2c->frequency)) +- i2c->frequency = DEFAULT_FREQ; ++ i2c->frequency = I2C_MAX_STANDARD_MODE_FREQ; + + i2c->dev = &pdev->dev; + platform_set_drvdata(pdev, i2c); +diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c +index 382f105e0fe3b..b48b7888936fe 100644 +--- a/drivers/i2c/busses/i2c-diolan-u2c.c ++++ b/drivers/i2c/busses/i2c-diolan-u2c.c +@@ -64,8 +64,6 @@ + #define U2C_I2C_SPEED_2KHZ 242 /* 2 kHz, minimum speed */ + #define U2C_I2C_SPEED(f) ((DIV_ROUND_UP(1000000, (f)) - 10) / 2 + 1) + +-#define U2C_I2C_FREQ_FAST 400000 +-#define U2C_I2C_FREQ_STD 100000 + #define U2C_I2C_FREQ(s) (1000000 / (2 * (s - 1) + 10)) + + #define DIOLAN_USB_TIMEOUT 100 /* in ms */ +@@ -87,7 +85,7 @@ struct i2c_diolan_u2c { + int ocount; /* Number of enqueued messages */ + }; + +-static uint frequency = U2C_I2C_FREQ_STD; /* I2C clock frequency in Hz */ ++static uint frequency = I2C_MAX_STANDARD_MODE_FREQ; /* I2C clock frequency in Hz */ + + module_param(frequency, uint, S_IRUGO | S_IWUSR); + MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz"); +@@ -299,12 +297,12 @@ static int diolan_init(struct i2c_diolan_u2c *dev) + { + int speed, ret; + +- if (frequency >= 200000) { ++ if (frequency >= 2 * I2C_MAX_STANDARD_MODE_FREQ) { + speed = U2C_I2C_SPEED_FAST; +- frequency = U2C_I2C_FREQ_FAST; +- } else if (frequency >= 100000 || frequency == 0) { ++ frequency = I2C_MAX_FAST_MODE_FREQ; ++ } else if (frequency >= I2C_MAX_STANDARD_MODE_FREQ || frequency == 0) { + speed = U2C_I2C_SPEED_STD; +- frequency = U2C_I2C_FREQ_STD; ++ frequency = I2C_MAX_STANDARD_MODE_FREQ; + } else { + speed = U2C_I2C_SPEED(frequency); + if (speed > U2C_I2C_SPEED_2KHZ) +diff --git a/drivers/i2c/busses/i2c-efm32.c b/drivers/i2c/busses/i2c-efm32.c +index a8c6323e7f44c..18cca8f56da87 100644 +--- a/drivers/i2c/busses/i2c-efm32.c ++++ b/drivers/i2c/busses/i2c-efm32.c +@@ -388,7 +388,7 @@ static int efm32_i2c_probe(struct platform_device *pdev) + if (!ret) { + dev_dbg(&pdev->dev, "using frequency %u\n", frequency); + } else { +- frequency = 100000; ++ frequency = I2C_MAX_STANDARD_MODE_FREQ; + dev_info(&pdev->dev, "defaulting to 100 kHz\n"); + } + ddata->frequency = frequency; +diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c +index e7514c16b756c..527030953ba13 100644 +--- a/drivers/i2c/busses/i2c-exynos5.c ++++ b/drivers/i2c/busses/i2c-exynos5.c +@@ -164,13 +164,6 @@ + #define HSI2C_MASTER_ID(x) ((x & 0xff) << 24) + #define MASTER_ID(x) ((x & 0x7) + 0x08) + +-/* +- * Controller operating frequency, timing values for operation +- * are calculated against this frequency +- */ +-#define HSI2C_HS_TX_CLOCK 1000000 +-#define HSI2C_FS_TX_CLOCK 100000 +- + #define EXYNOS5_I2C_TIMEOUT (msecs_to_jiffies(100)) + + enum i2c_type_exynos { +@@ -264,6 +257,9 @@ static void exynos5_i2c_clr_pend_irq(struct exynos5_i2c *i2c) + * exynos5_i2c_set_timing: updates the registers with appropriate + * timing values calculated + * ++ * Timing values for operation are calculated against either 100kHz ++ * or 1MHz controller operating frequency. ++ * + * Returns 0 on success, -EINVAL if the cycle length cannot + * be calculated. + */ +@@ -281,7 +277,7 @@ static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, bool hs_timings) + unsigned int t_ftl_cycle; + unsigned int clkin = clk_get_rate(i2c->clk); + unsigned int op_clk = hs_timings ? i2c->op_clock : +- (i2c->op_clock >= HSI2C_HS_TX_CLOCK) ? HSI2C_FS_TX_CLOCK : ++ (i2c->op_clock >= I2C_MAX_FAST_MODE_PLUS_FREQ) ? I2C_MAX_STANDARD_MODE_FREQ : + i2c->op_clock; + int div, clk_cycle, temp; + +@@ -353,7 +349,7 @@ static int exynos5_hsi2c_clock_setup(struct exynos5_i2c *i2c) + /* always set Fast Speed timings */ + int ret = exynos5_i2c_set_timing(i2c, false); + +- if (ret < 0 || i2c->op_clock < HSI2C_HS_TX_CLOCK) ++ if (ret < 0 || i2c->op_clock < I2C_MAX_FAST_MODE_PLUS_FREQ) + return ret; + + return exynos5_i2c_set_timing(i2c, true); +@@ -376,7 +372,7 @@ static void exynos5_i2c_init(struct exynos5_i2c *i2c) + i2c->regs + HSI2C_CTL); + writel(HSI2C_TRAILING_COUNT, i2c->regs + HSI2C_TRAILIG_CTL); + +- if (i2c->op_clock >= HSI2C_HS_TX_CLOCK) { ++ if (i2c->op_clock >= I2C_MAX_FAST_MODE_PLUS_FREQ) { + writel(HSI2C_MASTER_ID(MASTER_ID(i2c->adap.nr)), + i2c->regs + HSI2C_ADDR); + i2c_conf |= HSI2C_HS_MODE; +@@ -748,7 +744,7 @@ static int exynos5_i2c_probe(struct platform_device *pdev) + return -ENOMEM; + + if (of_property_read_u32(np, "clock-frequency", &i2c->op_clock)) +- i2c->op_clock = HSI2C_FS_TX_CLOCK; ++ i2c->op_clock = I2C_MAX_STANDARD_MODE_FREQ; + + strlcpy(i2c->adap.name, "exynos5-i2c", sizeof(i2c->adap.name)); + i2c->adap.owner = THIS_MODULE; +diff --git a/drivers/i2c/busses/i2c-hix5hd2.c b/drivers/i2c/busses/i2c-hix5hd2.c +index 224f830f77f9b..6610304b6dc61 100644 +--- a/drivers/i2c/busses/i2c-hix5hd2.c ++++ b/drivers/i2c/busses/i2c-hix5hd2.c +@@ -68,8 +68,6 @@ + #define I2C_ARBITRATE_INTR BIT(1) + #define I2C_OVER_INTR BIT(0) + +-#define HIX5I2C_MAX_FREQ 400000 /* 400k */ +- + enum hix5hd2_i2c_state { + HIX5I2C_STAT_RW_ERR = -1, + HIX5I2C_STAT_INIT, +@@ -400,12 +398,12 @@ static int hix5hd2_i2c_probe(struct platform_device *pdev) + + if (of_property_read_u32(np, "clock-frequency", &freq)) { + /* use 100k as default value */ +- priv->freq = 100000; ++ priv->freq = I2C_MAX_STANDARD_MODE_FREQ; + } else { +- if (freq > HIX5I2C_MAX_FREQ) { +- priv->freq = HIX5I2C_MAX_FREQ; ++ if (freq > I2C_MAX_FAST_MODE_FREQ) { ++ priv->freq = I2C_MAX_FAST_MODE_FREQ; + dev_warn(priv->dev, "use max freq %d instead\n", +- HIX5I2C_MAX_FREQ); ++ I2C_MAX_FAST_MODE_FREQ); + } else { + priv->freq = freq; + } +diff --git a/drivers/i2c/busses/i2c-img-scb.c b/drivers/i2c/busses/i2c-img-scb.c +index a1f8a9a91213a..cac941e377f30 100644 +--- a/drivers/i2c/busses/i2c-img-scb.c ++++ b/drivers/i2c/busses/i2c-img-scb.c +@@ -304,7 +304,7 @@ static struct img_i2c_timings timings[] = { + /* Standard mode */ + { + .name = "standard", +- .max_bitrate = 100000, ++ .max_bitrate = I2C_MAX_STANDARD_MODE_FREQ, + .tckh = 4000, + .tckl = 4700, + .tsdh = 4700, +@@ -316,7 +316,7 @@ static struct img_i2c_timings timings[] = { + /* Fast mode */ + { + .name = "fast", +- .max_bitrate = 400000, ++ .max_bitrate = I2C_MAX_FAST_MODE_FREQ, + .tckh = 600, + .tckl = 1300, + .tsdh = 600, +diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c +index 89faef6f013b4..890cf04552c1e 100644 +--- a/drivers/i2c/busses/i2c-imx-lpi2c.c ++++ b/drivers/i2c/busses/i2c-imx-lpi2c.c +@@ -75,12 +75,6 @@ + #define I2C_CLK_RATIO 2 + #define CHUNK_DATA 256 + +-#define LPI2C_DEFAULT_RATE 100000 +-#define STARDARD_MAX_BITRATE 400000 +-#define FAST_MAX_BITRATE 1000000 +-#define FAST_PLUS_MAX_BITRATE 3400000 +-#define HIGHSPEED_MAX_BITRATE 5000000 +- + #define I2C_PM_TIMEOUT 10 /* ms */ + + enum lpi2c_imx_mode { +@@ -152,13 +146,13 @@ static void lpi2c_imx_set_mode(struct lpi2c_imx_struct *lpi2c_imx) + unsigned int bitrate = lpi2c_imx->bitrate; + enum lpi2c_imx_mode mode; + +- if (bitrate < STARDARD_MAX_BITRATE) ++ if (bitrate < I2C_MAX_FAST_MODE_FREQ) + mode = STANDARD; +- else if (bitrate < FAST_MAX_BITRATE) ++ else if (bitrate < I2C_MAX_FAST_MODE_PLUS_FREQ) + mode = FAST; +- else if (bitrate < FAST_PLUS_MAX_BITRATE) ++ else if (bitrate < I2C_MAX_HIGH_SPEED_MODE_FREQ) + mode = FAST_PLUS; +- else if (bitrate < HIGHSPEED_MAX_BITRATE) ++ else if (bitrate < I2C_MAX_ULTRA_FAST_MODE_FREQ) + mode = HS; + else + mode = ULTRA_FAST; +@@ -584,7 +578,7 @@ static int lpi2c_imx_probe(struct platform_device *pdev) + ret = of_property_read_u32(pdev->dev.of_node, + "clock-frequency", &lpi2c_imx->bitrate); + if (ret) +- lpi2c_imx->bitrate = LPI2C_DEFAULT_RATE; ++ lpi2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ; + + ret = devm_request_irq(&pdev->dev, irq, lpi2c_imx_isr, 0, + pdev->name, lpi2c_imx); +diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c +index 9d3f42fd63522..64aa886e05fa0 100644 +--- a/drivers/i2c/busses/i2c-imx.c ++++ b/drivers/i2c/busses/i2c-imx.c +@@ -49,9 +49,6 @@ + /* This will be the driver name the kernel reports */ + #define DRIVER_NAME "imx-i2c" + +-/* Default value */ +-#define IMX_I2C_BIT_RATE 100000 /* 100kHz */ +- + /* + * Enable DMA if transfer byte size is bigger than this threshold. + * As the hardware request, it must bigger than 4 bytes.\ +@@ -1167,7 +1164,7 @@ static int i2c_imx_probe(struct platform_device *pdev) + } + + /* Set up clock divider */ +- i2c_imx->bitrate = IMX_I2C_BIT_RATE; ++ i2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ; + ret = of_property_read_u32(pdev->dev.of_node, + "clock-frequency", &i2c_imx->bitrate); + if (ret < 0 && pdata && pdata->bitrate) +diff --git a/drivers/i2c/busses/i2c-lpc2k.c b/drivers/i2c/busses/i2c-lpc2k.c +index deea18b14add5..13b0c12e2dbaf 100644 +--- a/drivers/i2c/busses/i2c-lpc2k.c ++++ b/drivers/i2c/busses/i2c-lpc2k.c +@@ -396,7 +396,7 @@ static int i2c_lpc2k_probe(struct platform_device *pdev) + ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency", + &bus_clk_rate); + if (ret) +- bus_clk_rate = 100000; /* 100 kHz default clock rate */ ++ bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; + + clkrate = clk_get_rate(i2c->clk); + if (clkrate == 0) { +@@ -407,9 +407,9 @@ static int i2c_lpc2k_probe(struct platform_device *pdev) + + /* Setup I2C dividers to generate clock with proper duty cycle */ + clkrate = clkrate / bus_clk_rate; +- if (bus_clk_rate <= 100000) ++ if (bus_clk_rate <= I2C_MAX_STANDARD_MODE_FREQ) + scl_high = (clkrate * I2C_STD_MODE_DUTY) / 100; +- else if (bus_clk_rate <= 400000) ++ else if (bus_clk_rate <= I2C_MAX_FAST_MODE_FREQ) + scl_high = (clkrate * I2C_FAST_MODE_DUTY) / 100; + else + scl_high = (clkrate * I2C_FAST_MODE_PLUS_DUTY) / 100; +diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c +index 5587e7c549c4f..6ff2137c9a0be 100644 +--- a/drivers/i2c/busses/i2c-mt65xx.c ++++ b/drivers/i2c/busses/i2c-mt65xx.c +@@ -56,9 +56,6 @@ + #define I2C_DMA_4G_MODE 0x0001 + + #define I2C_DEFAULT_CLK_DIV 5 +-#define I2C_DEFAULT_SPEED 100000 /* hz */ +-#define MAX_FS_MODE_SPEED 400000 +-#define MAX_HS_MODE_SPEED 3400000 + #define MAX_SAMPLE_CNT_DIV 8 + #define MAX_STEP_CNT_DIV 64 + #define MAX_HS_STEP_CNT_DIV 8 +@@ -450,10 +447,10 @@ static int mtk_i2c_calculate_speed(struct mtk_i2c *i2c, unsigned int clk_src, + unsigned int best_mul; + unsigned int cnt_mul; + +- if (target_speed > MAX_HS_MODE_SPEED) +- target_speed = MAX_HS_MODE_SPEED; ++ if (target_speed > I2C_MAX_FAST_MODE_PLUS_FREQ) ++ target_speed = I2C_MAX_FAST_MODE_PLUS_FREQ; + +- if (target_speed > MAX_FS_MODE_SPEED) ++ if (target_speed > I2C_MAX_FAST_MODE_FREQ) + max_step_cnt = MAX_HS_STEP_CNT_DIV; + else + max_step_cnt = MAX_STEP_CNT_DIV; +@@ -514,9 +511,9 @@ static int mtk_i2c_set_speed(struct mtk_i2c *i2c, unsigned int parent_clk) + clk_src = parent_clk / i2c->clk_src_div; + target_speed = i2c->speed_hz; + +- if (target_speed > MAX_FS_MODE_SPEED) { ++ if (target_speed > I2C_MAX_FAST_MODE_FREQ) { + /* Set master code speed register */ +- ret = mtk_i2c_calculate_speed(i2c, clk_src, MAX_FS_MODE_SPEED, ++ ret = mtk_i2c_calculate_speed(i2c, clk_src, I2C_MAX_FAST_MODE_FREQ, + &l_step_cnt, &l_sample_cnt); + if (ret < 0) + return ret; +@@ -581,7 +578,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs, + + control_reg = mtk_i2c_readw(i2c, OFFSET_CONTROL) & + ~(I2C_CONTROL_DIR_CHANGE | I2C_CONTROL_RS); +- if ((i2c->speed_hz > MAX_FS_MODE_SPEED) || (left_num >= 1)) ++ if ((i2c->speed_hz > I2C_MAX_FAST_MODE_FREQ) || (left_num >= 1)) + control_reg |= I2C_CONTROL_RS; + + if (i2c->op == I2C_MASTER_WRRD) +@@ -590,7 +587,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs, + mtk_i2c_writew(i2c, control_reg, OFFSET_CONTROL); + + /* set start condition */ +- if (i2c->speed_hz <= I2C_DEFAULT_SPEED) ++ if (i2c->speed_hz <= I2C_MAX_STANDARD_MODE_FREQ) + mtk_i2c_writew(i2c, I2C_ST_START_CON, OFFSET_EXT_CONF); + else + mtk_i2c_writew(i2c, I2C_FS_START_CON, OFFSET_EXT_CONF); +@@ -798,7 +795,7 @@ static int mtk_i2c_transfer(struct i2c_adapter *adap, + } + } + +- if (i2c->auto_restart && num >= 2 && i2c->speed_hz > MAX_FS_MODE_SPEED) ++ if (i2c->auto_restart && num >= 2 && i2c->speed_hz > I2C_MAX_FAST_MODE_FREQ) + /* ignore the first restart irq after the master code, + * otherwise the first transfer will be discarded. + */ +@@ -893,7 +890,7 @@ static int mtk_i2c_parse_dt(struct device_node *np, struct mtk_i2c *i2c) + + ret = of_property_read_u32(np, "clock-frequency", &i2c->speed_hz); + if (ret < 0) +- i2c->speed_hz = I2C_DEFAULT_SPEED; ++ i2c->speed_hz = I2C_MAX_STANDARD_MODE_FREQ; + + ret = of_property_read_u32(np, "clock-div", &i2c->clk_src_div); + if (ret < 0) +diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c +index 65e72101b393b..901f0fb04fee4 100644 +--- a/drivers/i2c/busses/i2c-mt7621.c ++++ b/drivers/i2c/busses/i2c-mt7621.c +@@ -300,7 +300,7 @@ static int mtk_i2c_probe(struct platform_device *pdev) + + if (of_property_read_u32(pdev->dev.of_node, "clock-frequency", + &i2c->bus_freq)) +- i2c->bus_freq = 100000; ++ i2c->bus_freq = I2C_MAX_STANDARD_MODE_FREQ; + + if (i2c->bus_freq == 0) { + dev_warn(i2c->dev, "clock-frequency 0 not supported\n"); +diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c +index a5a95ea5b81a7..e65c51e508db7 100644 +--- a/drivers/i2c/busses/i2c-mv64xxx.c ++++ b/drivers/i2c/busses/i2c-mv64xxx.c +@@ -810,7 +810,7 @@ mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data, + tclk = clk_get_rate(drv_data->clk); + + if (of_property_read_u32(np, "clock-frequency", &bus_freq)) +- bus_freq = 100000; /* 100kHz by default */ ++ bus_freq = I2C_MAX_STANDARD_MODE_FREQ; /* 100kHz by default */ + + if (of_device_is_compatible(np, "allwinner,sun4i-a10-i2c") || + of_device_is_compatible(np, "allwinner,sun6i-a31-i2c")) +@@ -846,14 +846,14 @@ mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data, + if (of_device_is_compatible(np, "marvell,mv78230-i2c")) { + drv_data->offload_enabled = true; + /* The delay is only needed in standard mode (100kHz) */ +- if (bus_freq <= 100000) ++ if (bus_freq <= I2C_MAX_STANDARD_MODE_FREQ) + drv_data->errata_delay = true; + } + + if (of_device_is_compatible(np, "marvell,mv78230-a0-i2c")) { + drv_data->offload_enabled = false; + /* The delay is only needed in standard mode (100kHz) */ +- if (bus_freq <= 100000) ++ if (bus_freq <= I2C_MAX_STANDARD_MODE_FREQ) + drv_data->errata_delay = true; + } + +diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c +index 081a1169ecea3..9473abb52e730 100644 +--- a/drivers/i2c/busses/i2c-mxs.c ++++ b/drivers/i2c/busses/i2c-mxs.c +@@ -735,7 +735,7 @@ static void mxs_i2c_derive_timing(struct mxs_i2c_dev *i2c, uint32_t speed) + * This is compensated for by subtracting the respective constants + * from the values written to the timing registers. + */ +- if (speed > 100000) { ++ if (speed > I2C_MAX_STANDARD_MODE_FREQ) { + /* fast mode */ + low_count = DIV_ROUND_CLOSEST(divider * 13, (13 + 6)); + high_count = DIV_ROUND_CLOSEST(divider * 6, (13 + 6)); +@@ -773,7 +773,7 @@ static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c) + ret = of_property_read_u32(node, "clock-frequency", &speed); + if (ret) { + dev_warn(dev, "No I2C speed selected, using 100kHz\n"); +- speed = 100000; ++ speed = I2C_MAX_STANDARD_MODE_FREQ; + } + + mxs_i2c_derive_timing(i2c, speed); +diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c +index 01a7d72e55111..e1e8d4ef9aa72 100644 +--- a/drivers/i2c/busses/i2c-nomadik.c ++++ b/drivers/i2c/busses/i2c-nomadik.c +@@ -396,7 +396,7 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev) + * 2 whereas it is 3 for fast and fastplus mode of + * operation. TODO - high speed support. + */ +- div = (dev->clk_freq > 100000) ? 3 : 2; ++ div = (dev->clk_freq > I2C_MAX_STANDARD_MODE_FREQ) ? 3 : 2; + + /* + * generate the mask for baud rate counters. The controller +@@ -420,7 +420,7 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev) + if (dev->sm > I2C_FREQ_MODE_FAST) { + dev_err(&dev->adev->dev, + "do not support this mode defaulting to std. mode\n"); +- brcr2 = i2c_clk/(100000 * 2) & 0xffff; ++ brcr2 = i2c_clk / (I2C_MAX_STANDARD_MODE_FREQ * 2) & 0xffff; + writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR); + writel(I2C_FREQ_MODE_STANDARD << 4, + dev->virtbase + I2C_CR); +@@ -949,10 +949,10 @@ static void nmk_i2c_of_probe(struct device_node *np, + { + /* Default to 100 kHz if no frequency is given in the node */ + if (of_property_read_u32(np, "clock-frequency", &nmk->clk_freq)) +- nmk->clk_freq = 100000; ++ nmk->clk_freq = I2C_MAX_STANDARD_MODE_FREQ; + + /* This driver only supports 'standard' and 'fast' modes of operation. */ +- if (nmk->clk_freq <= 100000) ++ if (nmk->clk_freq <= I2C_MAX_STANDARD_MODE_FREQ) + nmk->sm = I2C_FREQ_MODE_STANDARD; + else + nmk->sm = I2C_FREQ_MODE_FAST; +diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c +index a788f2e706779..435652646842f 100644 +--- a/drivers/i2c/busses/i2c-omap.c ++++ b/drivers/i2c/busses/i2c-omap.c +@@ -1382,7 +1382,7 @@ omap_i2c_probe(struct platform_device *pdev) + + match = of_match_device(of_match_ptr(omap_i2c_of_match), &pdev->dev); + if (match) { +- u32 freq = 100000; /* default to 100000 Hz */ ++ u32 freq = I2C_MAX_STANDARD_MODE_FREQ; + + pdata = match->data; + omap->flags = pdata->flags; +diff --git a/drivers/i2c/busses/i2c-owl.c b/drivers/i2c/busses/i2c-owl.c +index a567fd2b295e1..03631f34c0637 100644 +--- a/drivers/i2c/busses/i2c-owl.c ++++ b/drivers/i2c/busses/i2c-owl.c +@@ -87,9 +87,6 @@ + + #define OWL_I2C_MAX_RETRIES 50 + +-#define OWL_I2C_DEF_SPEED_HZ 100000 +-#define OWL_I2C_MAX_SPEED_HZ 400000 +- + struct owl_i2c_dev { + struct i2c_adapter adap; + struct i2c_msg *msg; +@@ -425,11 +422,11 @@ static int owl_i2c_probe(struct platform_device *pdev) + + if (of_property_read_u32(dev->of_node, "clock-frequency", + &i2c_dev->bus_freq)) +- i2c_dev->bus_freq = OWL_I2C_DEF_SPEED_HZ; ++ i2c_dev->bus_freq = I2C_MAX_STANDARD_MODE_FREQ; + + /* We support only frequencies of 100k and 400k for now */ +- if (i2c_dev->bus_freq != OWL_I2C_DEF_SPEED_HZ && +- i2c_dev->bus_freq != OWL_I2C_MAX_SPEED_HZ) { ++ if (i2c_dev->bus_freq != I2C_MAX_STANDARD_MODE_FREQ && ++ i2c_dev->bus_freq != I2C_MAX_FAST_MODE_FREQ) { + dev_err(dev, "invalid clock-frequency %d\n", i2c_dev->bus_freq); + return -EINVAL; + } +diff --git a/drivers/i2c/busses/i2c-qup.c b/drivers/i2c/busses/i2c-qup.c +index 3417f7dffa943..f2e8206e02e2a 100644 +--- a/drivers/i2c/busses/i2c-qup.c ++++ b/drivers/i2c/busses/i2c-qup.c +@@ -136,13 +136,8 @@ + */ + #define TOUT_MIN 2 + +-/* I2C Frequency Modes */ +-#define I2C_STANDARD_FREQ 100000 +-#define I2C_FAST_MODE_FREQ 400000 +-#define I2C_FAST_MODE_PLUS_FREQ 1000000 +- + /* Default values. Use these if FW query fails */ +-#define DEFAULT_CLK_FREQ I2C_STANDARD_FREQ ++#define DEFAULT_CLK_FREQ I2C_MAX_STANDARD_MODE_FREQ + #define DEFAULT_SRC_CLK 20000000 + + /* +@@ -1757,7 +1752,7 @@ static int qup_i2c_probe(struct platform_device *pdev) + + nodma: + /* We support frequencies up to FAST Mode Plus (1MHz) */ +- if (!clk_freq || clk_freq > I2C_FAST_MODE_PLUS_FREQ) { ++ if (!clk_freq || clk_freq > I2C_MAX_FAST_MODE_PLUS_FREQ) { + dev_err(qup->dev, "clock frequency not supported %d\n", + clk_freq); + return -EINVAL; +@@ -1862,7 +1857,7 @@ static int qup_i2c_probe(struct platform_device *pdev) + qup->in_fifo_sz = qup->in_blk_sz * (2 << size); + + hs_div = 3; +- if (clk_freq <= I2C_STANDARD_FREQ) { ++ if (clk_freq <= I2C_MAX_STANDARD_MODE_FREQ) { + fs_div = ((src_clk_freq / clk_freq) / 2) - 3; + qup->clk_ctl = (hs_div << 8) | (fs_div & 0xff); + } else { +diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c +index 800414886f6b5..4eccc0f69861f 100644 +--- a/drivers/i2c/busses/i2c-riic.c ++++ b/drivers/i2c/busses/i2c-riic.c +@@ -287,10 +287,10 @@ static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t) + + pm_runtime_get_sync(riic->adapter.dev.parent); + +- if (t->bus_freq_hz > 400000) { ++ if (t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ) { + dev_err(&riic->adapter.dev, +- "unsupported bus speed (%dHz). 400000 max\n", +- t->bus_freq_hz); ++ "unsupported bus speed (%dHz). %d max\n", ++ t->bus_freq_hz, I2C_MAX_FAST_MODE_FREQ); + ret = -EINVAL; + goto out; + } +diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c +index 74dd378446c13..2b2071717535f 100644 +--- a/drivers/i2c/busses/i2c-rk3x.c ++++ b/drivers/i2c/busses/i2c-rk3x.c +@@ -541,9 +541,9 @@ static irqreturn_t rk3x_i2c_irq(int irqno, void *dev_id) + */ + static const struct i2c_spec_values *rk3x_i2c_get_spec(unsigned int speed) + { +- if (speed <= 100000) ++ if (speed <= I2C_MAX_STANDARD_MODE_FREQ) + return &standard_mode_spec; +- else if (speed <= 400000) ++ else if (speed <= I2C_MAX_FAST_MODE_FREQ) + return &fast_mode_spec; + else + return &fast_mode_plus_spec; +@@ -579,8 +579,8 @@ static int rk3x_i2c_v0_calc_timings(unsigned long clk_rate, + int ret = 0; + + /* Only support standard-mode and fast-mode */ +- if (WARN_ON(t->bus_freq_hz > 400000)) +- t->bus_freq_hz = 400000; ++ if (WARN_ON(t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ)) ++ t->bus_freq_hz = I2C_MAX_FAST_MODE_FREQ; + + /* prevent scl_rate_khz from becoming 0 */ + if (WARN_ON(t->bus_freq_hz < 1000)) +@@ -758,8 +758,8 @@ static int rk3x_i2c_v1_calc_timings(unsigned long clk_rate, + int ret = 0; + + /* Support standard-mode, fast-mode and fast-mode plus */ +- if (WARN_ON(t->bus_freq_hz > 1000000)) +- t->bus_freq_hz = 1000000; ++ if (WARN_ON(t->bus_freq_hz > I2C_MAX_FAST_MODE_PLUS_FREQ)) ++ t->bus_freq_hz = I2C_MAX_FAST_MODE_PLUS_FREQ; + + /* prevent scl_rate_khz from becoming 0 */ + if (WARN_ON(t->bus_freq_hz < 1000)) +diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c +index 7402f71dd24d5..c1cc86b5c569e 100644 +--- a/drivers/i2c/busses/i2c-s3c2410.c ++++ b/drivers/i2c/busses/i2c-s3c2410.c +@@ -840,11 +840,11 @@ static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got) + int freq; + + i2c->clkrate = clkin; +- clkin /= 1000; /* clkin now in KHz */ ++ clkin /= 1000; /* clkin now in KHz */ + + dev_dbg(i2c->dev, "pdata desired frequency %lu\n", pdata->frequency); + +- target_frequency = pdata->frequency ? pdata->frequency : 100000; ++ target_frequency = pdata->frequency ?: I2C_MAX_STANDARD_MODE_FREQ; + + target_frequency /= 1000; /* Target frequency now in KHz */ + +diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c +index 0dc2494f1a37b..36801457f1f3b 100644 +--- a/drivers/i2c/busses/i2c-sh_mobile.c ++++ b/drivers/i2c/busses/i2c-sh_mobile.c +@@ -146,9 +146,6 @@ struct sh_mobile_dt_config { + + #define IIC_FLAG_HAS_ICIC67 (1 << 0) + +-#define STANDARD_MODE 100000 +-#define FAST_MODE 400000 +- + /* Register offsets */ + #define ICDR 0x00 + #define ICCR 0x04 +@@ -271,11 +268,11 @@ static int sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd) + + i2c_clk_khz = clk_get_rate(pd->clk) / 1000 / pd->clks_per_count; + +- if (pd->bus_speed == STANDARD_MODE) { ++ if (pd->bus_speed == I2C_MAX_STANDARD_MODE_FREQ) { + tLOW = 47; /* tLOW = 4.7 us */ + tHIGH = 40; /* tHD;STA = tHIGH = 4.0 us */ + tf = 3; /* tf = 0.3 us */ +- } else if (pd->bus_speed == FAST_MODE) { ++ } else if (pd->bus_speed == I2C_MAX_FAST_MODE_FREQ) { + tLOW = 13; /* tLOW = 1.3 us */ + tHIGH = 6; /* tHD;STA = tHIGH = 0.6 us */ + tf = 3; /* tf = 0.3 us */ +@@ -897,7 +894,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) + return PTR_ERR(pd->reg); + + ret = of_property_read_u32(dev->dev.of_node, "clock-frequency", &bus_speed); +- pd->bus_speed = (ret || !bus_speed) ? STANDARD_MODE : bus_speed; ++ pd->bus_speed = (ret || !bus_speed) ? I2C_MAX_STANDARD_MODE_FREQ : bus_speed; + pd->clks_per_count = 1; + + /* Newer variants come with two new bits in ICIC */ +diff --git a/drivers/i2c/busses/i2c-sirf.c b/drivers/i2c/busses/i2c-sirf.c +index fb7a046b3226b..a459e00c6851f 100644 +--- a/drivers/i2c/busses/i2c-sirf.c ++++ b/drivers/i2c/busses/i2c-sirf.c +@@ -62,7 +62,6 @@ + #define SIRFSOC_I2C_STOP BIT(6) + #define SIRFSOC_I2C_START BIT(7) + +-#define SIRFSOC_I2C_DEFAULT_SPEED 100000 + #define SIRFSOC_I2C_ERR_NOACK 1 + #define SIRFSOC_I2C_ERR_TIMEOUT 2 + +@@ -353,7 +352,7 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev) + err = of_property_read_u32(pdev->dev.of_node, + "clock-frequency", &bitrate); + if (err < 0) +- bitrate = SIRFSOC_I2C_DEFAULT_SPEED; ++ bitrate = I2C_MAX_STANDARD_MODE_FREQ; + + /* + * Due to some hardware design issues, we need to tune the formula. +diff --git a/drivers/i2c/busses/i2c-sprd.c b/drivers/i2c/busses/i2c-sprd.c +index ef0dc06a3778e..a69fb07fe6edb 100644 +--- a/drivers/i2c/busses/i2c-sprd.c ++++ b/drivers/i2c/busses/i2c-sprd.c +@@ -343,9 +343,9 @@ static void sprd_i2c_set_clk(struct sprd_i2c *i2c_dev, u32 freq) + writel(div1, i2c_dev->base + ADDR_DVD1); + + /* Start hold timing = hold time(us) * source clock */ +- if (freq == 400000) ++ if (freq == I2C_MAX_FAST_MODE_FREQ) + writel((6 * apb_clk) / 10000000, i2c_dev->base + ADDR_STA0_DVD); +- else if (freq == 100000) ++ else if (freq == I2C_MAX_STANDARD_MODE_FREQ) + writel((4 * apb_clk) / 1000000, i2c_dev->base + ADDR_STA0_DVD); + } + +@@ -508,7 +508,7 @@ static int sprd_i2c_probe(struct platform_device *pdev) + snprintf(i2c_dev->adap.name, sizeof(i2c_dev->adap.name), + "%s", "sprd-i2c"); + +- i2c_dev->bus_freq = 100000; ++ i2c_dev->bus_freq = I2C_MAX_STANDARD_MODE_FREQ; + i2c_dev->adap.owner = THIS_MODULE; + i2c_dev->dev = dev; + i2c_dev->adap.retries = 3; +@@ -522,7 +522,8 @@ static int sprd_i2c_probe(struct platform_device *pdev) + i2c_dev->bus_freq = prop; + + /* We only support 100k and 400k now, otherwise will return error. */ +- if (i2c_dev->bus_freq != 100000 && i2c_dev->bus_freq != 400000) ++ if (i2c_dev->bus_freq != I2C_MAX_STANDARD_MODE_FREQ && ++ i2c_dev->bus_freq != I2C_MAX_FAST_MODE_FREQ) + return -EINVAL; + + ret = sprd_i2c_clk_init(i2c_dev); +diff --git a/drivers/i2c/busses/i2c-st.c b/drivers/i2c/busses/i2c-st.c +index f7f7b5b64720e..faa81a95551fe 100644 +--- a/drivers/i2c/busses/i2c-st.c ++++ b/drivers/i2c/busses/i2c-st.c +@@ -213,7 +213,7 @@ static inline void st_i2c_clr_bits(void __iomem *reg, u32 mask) + */ + static struct st_i2c_timings i2c_timings[] = { + [I2C_MODE_STANDARD] = { +- .rate = 100000, ++ .rate = I2C_MAX_STANDARD_MODE_FREQ, + .rep_start_hold = 4400, + .rep_start_setup = 5170, + .start_hold = 4400, +@@ -222,7 +222,7 @@ static struct st_i2c_timings i2c_timings[] = { + .bus_free_time = 5170, + }, + [I2C_MODE_FAST] = { +- .rate = 400000, ++ .rate = I2C_MAX_FAST_MODE_FREQ, + .rep_start_hold = 660, + .rep_start_setup = 660, + .start_hold = 660, +@@ -836,7 +836,7 @@ static int st_i2c_probe(struct platform_device *pdev) + + i2c_dev->mode = I2C_MODE_STANDARD; + ret = of_property_read_u32(np, "clock-frequency", &clk_rate); +- if ((!ret) && (clk_rate == 400000)) ++ if (!ret && (clk_rate == I2C_MAX_FAST_MODE_FREQ)) + i2c_dev->mode = I2C_MODE_FAST; + + i2c_dev->dev = &pdev->dev; +diff --git a/drivers/i2c/busses/i2c-stm32f4.c b/drivers/i2c/busses/i2c-stm32f4.c +index ba600d77a3f88..d6a69dfcac3f6 100644 +--- a/drivers/i2c/busses/i2c-stm32f4.c ++++ b/drivers/i2c/busses/i2c-stm32f4.c +@@ -232,10 +232,10 @@ static void stm32f4_i2c_set_speed_mode(struct stm32f4_i2c_dev *i2c_dev) + * In standard mode: + * t_scl_high = t_scl_low = CCR * I2C parent clk period + * So to reach 100 kHz, we have: +- * CCR = I2C parent rate / 100 kHz >> 1 ++ * CCR = I2C parent rate / (100 kHz * 2) + * + * For example with parent rate = 2 MHz: +- * CCR = 2000000 / (100000 << 1) = 10 ++ * CCR = 2000000 / (100000 * 2) = 10 + * t_scl_high = t_scl_low = 10 * (1 / 2000000) = 5000 ns + * t_scl_high + t_scl_low = 10000 ns so 100 kHz is reached + * +@@ -243,7 +243,7 @@ static void stm32f4_i2c_set_speed_mode(struct stm32f4_i2c_dev *i2c_dev) + * parent rate is not higher than 46 MHz . As a result val + * is at most 8 bits wide and so fits into the CCR bits [11:0]. + */ +- val = i2c_dev->parent_rate / (100000 << 1); ++ val = i2c_dev->parent_rate / (I2C_MAX_STANDARD_MODE_FREQ * 2); + } else { + /* + * In fast mode, we compute CCR with duty = 0 as with low +@@ -263,7 +263,7 @@ static void stm32f4_i2c_set_speed_mode(struct stm32f4_i2c_dev *i2c_dev) + * parent rate is not higher than 46 MHz . As a result val + * is at most 6 bits wide and so fits into the CCR bits [11:0]. + */ +- val = DIV_ROUND_UP(i2c_dev->parent_rate, 400000 * 3); ++ val = DIV_ROUND_UP(i2c_dev->parent_rate, I2C_MAX_FAST_MODE_FREQ * 3); + + /* Select Fast mode */ + ccr |= STM32F4_I2C_CCR_FS; +@@ -807,7 +807,7 @@ static int stm32f4_i2c_probe(struct platform_device *pdev) + + i2c_dev->speed = STM32_I2C_SPEED_STANDARD; + ret = of_property_read_u32(np, "clock-frequency", &clk_rate); +- if (!ret && clk_rate >= 400000) ++ if (!ret && clk_rate >= I2C_MAX_FAST_MODE_FREQ) + i2c_dev->speed = STM32_I2C_SPEED_FAST; + + i2c_dev->dev = &pdev->dev; +diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c +index 8c3e2d409d63f..1c285095adeaa 100644 +--- a/drivers/i2c/busses/i2c-stu300.c ++++ b/drivers/i2c/busses/i2c-stu300.c +@@ -132,7 +132,7 @@ enum stu300_error { + #define NUM_ADDR_RESEND_ATTEMPTS 12 + + /* I2C clock speed, in Hz 0-400kHz*/ +-static unsigned int scl_frequency = 100000; ++static unsigned int scl_frequency = I2C_MAX_STANDARD_MODE_FREQ; + module_param(scl_frequency, uint, 0644); + + /** +@@ -497,7 +497,7 @@ static int stu300_set_clk(struct stu300_dev *dev, unsigned long clkrate) + dev_dbg(&dev->pdev->dev, "Clock rate %lu Hz, I2C bus speed %d Hz " + "virtbase %p\n", clkrate, dev->speed, dev->virtbase); + +- if (dev->speed > 100000) ++ if (dev->speed > I2C_MAX_STANDARD_MODE_FREQ) + /* Fast Mode I2C */ + val = ((clkrate/dev->speed) - 9)/3 + 1; + else +@@ -518,7 +518,7 @@ static int stu300_set_clk(struct stu300_dev *dev, unsigned long clkrate) + return -EINVAL; + } + +- if (dev->speed > 100000) { ++ if (dev->speed > I2C_MAX_STANDARD_MODE_FREQ) { + /* CC6..CC0 */ + stu300_wr8((val & I2C_CCR_CC_MASK) | I2C_CCR_FMSM, + dev->virtbase + I2C_CCR); +diff --git a/drivers/i2c/busses/i2c-sun6i-p2wi.c b/drivers/i2c/busses/i2c-sun6i-p2wi.c +index 540c33f4e3500..62231c89dcb16 100644 +--- a/drivers/i2c/busses/i2c-sun6i-p2wi.c ++++ b/drivers/i2c/busses/i2c-sun6i-p2wi.c +@@ -186,7 +186,7 @@ static int p2wi_probe(struct platform_device *pdev) + struct device_node *np = dev->of_node; + struct device_node *childnp; + unsigned long parent_clk_freq; +- u32 clk_freq = 100000; ++ u32 clk_freq = I2C_MAX_STANDARD_MODE_FREQ; + struct resource *r; + struct p2wi *p2wi; + u32 slave_addr; +diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-synquacer.c +index 39762f0611b18..179495e496821 100644 +--- a/drivers/i2c/busses/i2c-synquacer.c ++++ b/drivers/i2c/busses/i2c-synquacer.c +@@ -67,10 +67,10 @@ + + /* STANDARD MODE frequency */ + #define SYNQUACER_I2C_CLK_MASTER_STD(rate) \ +- DIV_ROUND_UP(DIV_ROUND_UP((rate), 100000) - 2, 2) ++ DIV_ROUND_UP(DIV_ROUND_UP((rate), I2C_MAX_STANDARD_MODE_FREQ) - 2, 2) + /* FAST MODE frequency */ + #define SYNQUACER_I2C_CLK_MASTER_FAST(rate) \ +- DIV_ROUND_UP((DIV_ROUND_UP((rate), 400000) - 2) * 2, 3) ++ DIV_ROUND_UP((DIV_ROUND_UP((rate), I2C_MAX_FAST_MODE_FREQ) - 2) * 2, 3) + + /* (clkrate <= 18000000) */ + /* calculate the value of CS bits in CCR register on standard mode */ +@@ -602,7 +602,7 @@ static int synquacer_i2c_probe(struct platform_device *pdev) + i2c->adapter.nr = pdev->id; + init_completion(&i2c->completion); + +- if (bus_speed < 400000) ++ if (bus_speed < I2C_MAX_FAST_MODE_FREQ) + i2c->speed_khz = SYNQUACER_I2C_SPEED_SM; + else + i2c->speed_khz = SYNQUACER_I2C_SPEED_FM; +diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c +index db94e96aed77e..f52822156269f 100644 +--- a/drivers/i2c/busses/i2c-tegra.c ++++ b/drivers/i2c/busses/i2c-tegra.c +@@ -122,10 +122,6 @@ + #define I2C_THIGH_SHIFT 8 + #define I2C_INTERFACE_TIMING_1 0x98 + +-#define I2C_STANDARD_MODE 100000 +-#define I2C_FAST_MODE 400000 +-#define I2C_FAST_PLUS_MODE 1000000 +- + /* Packet header size in bytes */ + #define I2C_PACKET_HEADER_SIZE 12 + +@@ -731,8 +727,8 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit) + I2C_CLK_DIVISOR_STD_FAST_MODE_SHIFT; + i2c_writel(i2c_dev, clk_divisor, I2C_CLK_DIVISOR); + +- if (i2c_dev->bus_clk_rate > I2C_STANDARD_MODE && +- i2c_dev->bus_clk_rate <= I2C_FAST_PLUS_MODE) { ++ if (i2c_dev->bus_clk_rate > I2C_MAX_STANDARD_MODE_FREQ && ++ i2c_dev->bus_clk_rate <= I2C_MAX_FAST_MODE_PLUS_FREQ) { + tlow = i2c_dev->hw->tlow_fast_fastplus_mode; + thigh = i2c_dev->hw->thigh_fast_fastplus_mode; + tsu_thd = i2c_dev->hw->setup_hold_time_fast_fast_plus_mode; +@@ -1291,7 +1287,7 @@ static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) + ret = of_property_read_u32(np, "clock-frequency", + &i2c_dev->bus_clk_rate); + if (ret) +- i2c_dev->bus_clk_rate = 100000; /* default clock rate */ ++ i2c_dev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */ + + multi_mode = of_property_read_bool(np, "multi-master"); + i2c_dev->is_multimaster_mode = multi_mode; +@@ -1589,12 +1585,12 @@ static int tegra_i2c_probe(struct platform_device *pdev) + } + } + +- if (i2c_dev->bus_clk_rate > I2C_FAST_MODE && +- i2c_dev->bus_clk_rate <= I2C_FAST_PLUS_MODE) ++ if (i2c_dev->bus_clk_rate > I2C_MAX_FAST_MODE_FREQ && ++ i2c_dev->bus_clk_rate <= I2C_MAX_FAST_MODE_PLUS_FREQ) + i2c_dev->clk_divisor_non_hs_mode = + i2c_dev->hw->clk_divisor_fast_plus_mode; +- else if (i2c_dev->bus_clk_rate > I2C_STANDARD_MODE && +- i2c_dev->bus_clk_rate <= I2C_FAST_MODE) ++ else if (i2c_dev->bus_clk_rate > I2C_MAX_STANDARD_MODE_FREQ && ++ i2c_dev->bus_clk_rate <= I2C_MAX_FAST_MODE_FREQ) + i2c_dev->clk_divisor_non_hs_mode = + i2c_dev->hw->clk_divisor_fast_mode; + else +diff --git a/drivers/i2c/busses/i2c-thunderx-pcidrv.c b/drivers/i2c/busses/i2c-thunderx-pcidrv.c +index 107aeb8b54da4..21ba3018c11a3 100644 +--- a/drivers/i2c/busses/i2c-thunderx-pcidrv.c ++++ b/drivers/i2c/busses/i2c-thunderx-pcidrv.c +@@ -178,7 +178,7 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev, + thunder_i2c_clock_enable(dev, i2c); + ret = device_property_read_u32(dev, "clock-frequency", &i2c->twsi_freq); + if (ret) +- i2c->twsi_freq = 100000; ++ i2c->twsi_freq = I2C_MAX_STANDARD_MODE_FREQ; + + init_waitqueue_head(&i2c->queue); + +diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c +index 4241aac79e7ef..2b258d54d68cf 100644 +--- a/drivers/i2c/busses/i2c-uniphier-f.c ++++ b/drivers/i2c/busses/i2c-uniphier-f.c +@@ -73,8 +73,6 @@ + #define UNIPHIER_FI2C_BYTE_WISE BIT(3) + #define UNIPHIER_FI2C_DEFER_STOP_COMP BIT(4) + +-#define UNIPHIER_FI2C_DEFAULT_SPEED 100000 +-#define UNIPHIER_FI2C_MAX_SPEED 400000 + #define UNIPHIER_FI2C_FIFO_SIZE 8 + + struct uniphier_fi2c_priv { +@@ -537,9 +535,9 @@ static int uniphier_fi2c_probe(struct platform_device *pdev) + } + + if (of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed)) +- bus_speed = UNIPHIER_FI2C_DEFAULT_SPEED; ++ bus_speed = I2C_MAX_STANDARD_MODE_FREQ; + +- if (!bus_speed || bus_speed > UNIPHIER_FI2C_MAX_SPEED) { ++ if (!bus_speed || bus_speed > I2C_MAX_FAST_MODE_FREQ) { + dev_err(dev, "invalid clock-frequency %d\n", bus_speed); + return -EINVAL; + } +diff --git a/drivers/i2c/busses/i2c-uniphier.c b/drivers/i2c/busses/i2c-uniphier.c +index 0270090c03603..668b1fa2b0ef4 100644 +--- a/drivers/i2c/busses/i2c-uniphier.c ++++ b/drivers/i2c/busses/i2c-uniphier.c +@@ -35,9 +35,6 @@ + #define UNIPHIER_I2C_NOISE 0x1c /* noise filter control */ + #define UNIPHIER_I2C_SETUP 0x20 /* setup time control */ + +-#define UNIPHIER_I2C_DEFAULT_SPEED 100000 +-#define UNIPHIER_I2C_MAX_SPEED 400000 +- + struct uniphier_i2c_priv { + struct completion comp; + struct i2c_adapter adap; +@@ -333,9 +330,9 @@ static int uniphier_i2c_probe(struct platform_device *pdev) + } + + if (of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed)) +- bus_speed = UNIPHIER_I2C_DEFAULT_SPEED; ++ bus_speed = I2C_MAX_STANDARD_MODE_FREQ; + +- if (!bus_speed || bus_speed > UNIPHIER_I2C_MAX_SPEED) { ++ if (!bus_speed || bus_speed > I2C_MAX_FAST_MODE_FREQ) { + dev_err(dev, "invalid clock-frequency %d\n", bus_speed); + return -EINVAL; + } +diff --git a/drivers/i2c/busses/i2c-wmt.c b/drivers/i2c/busses/i2c-wmt.c +index 524017f7034e8..88f5aafdce5b4 100644 +--- a/drivers/i2c/busses/i2c-wmt.c ++++ b/drivers/i2c/busses/i2c-wmt.c +@@ -399,7 +399,7 @@ static int wmt_i2c_probe(struct platform_device *pdev) + + i2c_dev->mode = I2C_MODE_STANDARD; + err = of_property_read_u32(np, "clock-frequency", &clk_rate); +- if ((!err) && (clk_rate == 400000)) ++ if (!err && (clk_rate == I2C_MAX_FAST_MODE_FREQ)) + i2c_dev->mode = I2C_MODE_FAST; + + i2c_dev->dev = &pdev->dev; +diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c +index 8a873975cf125..f678f8d9abd67 100644 +--- a/drivers/i2c/busses/i2c-xlp9xx.c ++++ b/drivers/i2c/busses/i2c-xlp9xx.c +@@ -71,8 +71,6 @@ + #define XLP9XX_I2C_SLAVEADDR_ADDR_SHIFT 1 + + #define XLP9XX_I2C_IP_CLK_FREQ 133000000UL +-#define XLP9XX_I2C_DEFAULT_FREQ 100000 +-#define XLP9XX_I2C_HIGH_FREQ 400000 + #define XLP9XX_I2C_FIFO_SIZE 0x80U + #define XLP9XX_I2C_TIMEOUT_MS 1000 + #define XLP9XX_I2C_BUSY_TIMEOUT 50 +@@ -476,12 +474,12 @@ static int xlp9xx_i2c_get_frequency(struct platform_device *pdev, + + err = device_property_read_u32(&pdev->dev, "clock-frequency", &freq); + if (err) { +- freq = XLP9XX_I2C_DEFAULT_FREQ; ++ freq = I2C_MAX_STANDARD_MODE_FREQ; + dev_dbg(&pdev->dev, "using default frequency %u\n", freq); +- } else if (freq == 0 || freq > XLP9XX_I2C_HIGH_FREQ) { ++ } else if (freq == 0 || freq > I2C_MAX_FAST_MODE_FREQ) { + dev_warn(&pdev->dev, "invalid frequency %u, using default\n", + freq); +- freq = XLP9XX_I2C_DEFAULT_FREQ; ++ freq = I2C_MAX_STANDARD_MODE_FREQ; + } + priv->clk_hz = freq; + +diff --git a/drivers/i2c/busses/i2c-xlr.c b/drivers/i2c/busses/i2c-xlr.c +index dda6cb848405b..adc15e7eac8cf 100644 +--- a/drivers/i2c/busses/i2c-xlr.c ++++ b/drivers/i2c/busses/i2c-xlr.c +@@ -404,7 +404,7 @@ static int xlr_i2c_probe(struct platform_device *pdev) + + if (of_property_read_u32(pdev->dev.of_node, "clock-frequency", + &busfreq)) +- busfreq = 100000; ++ busfreq = I2C_MAX_STANDARD_MODE_FREQ; + + clk = devm_clk_get(&pdev->dev, NULL); + if (!IS_ERR(clk)) { +-- +2.43.0 + diff --git a/queue-5.4/series b/queue-5.4/series index 1a3ef134aaa..e82b2d3b2cc 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -98,3 +98,11 @@ hv_utils-drain-the-timesync-packets-on-onchannelcallback.patch hugetlb_encode.h-fix-undefined-behaviour-34-26.patch netfilter-nftables-exthdr-fix-4-byte-stack-oob-write.patch greybus-fix-use-after-free-bug-in-gb_interface_release-due-to-race-condition.patch +usb-storage-alauda-check-whether-the-media-is-initia.patch +i2c-at91-fix-the-functionality-flags-of-the-slave-on.patch +i2c-designware-detect-the-fifo-size-in-the-common-co.patch +i2c-designware-discard-i2c_dw_read_comp_param-functi.patch +i2c-core-provide-generic-definitions-for-bus-frequen.patch +i2c-drivers-use-generic-definitions-for-bus-frequenc.patch +i2c-designware-move-configuration-routines-to-respec.patch +i2c-designware-fix-the-functionality-flags-of-the-sl.patch diff --git a/queue-5.4/usb-storage-alauda-check-whether-the-media-is-initia.patch b/queue-5.4/usb-storage-alauda-check-whether-the-media-is-initia.patch new file mode 100644 index 00000000000..ce4cb6de01c --- /dev/null +++ b/queue-5.4/usb-storage-alauda-check-whether-the-media-is-initia.patch @@ -0,0 +1,61 @@ +From d069d6c205205f613128692495f9db820e05e2f2 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 26 May 2024 09:27:45 +0800 +Subject: usb-storage: alauda: Check whether the media is initialized + +From: Shichao Lai + +[ Upstream commit 16637fea001ab3c8df528a8995b3211906165a30 ] + +The member "uzonesize" of struct alauda_info will remain 0 +if alauda_init_media() fails, potentially causing divide errors +in alauda_read_data() and alauda_write_lba(). +- Add a member "media_initialized" to struct alauda_info. +- Change a condition in alauda_check_media() to ensure the + first initialization. +- Add an error check for the return value of alauda_init_media(). + +Fixes: e80b0fade09e ("[PATCH] USB Storage: add alauda support") +Reported-by: xingwei lee +Reported-by: yue sun +Reviewed-by: Alan Stern +Signed-off-by: Shichao Lai +Link: https://lore.kernel.org/r/20240526012745.2852061-1-shichaorai@gmail.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/usb/storage/alauda.c | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) + +diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c +index dcc4778d1ae99..17fe35083f048 100644 +--- a/drivers/usb/storage/alauda.c ++++ b/drivers/usb/storage/alauda.c +@@ -105,6 +105,8 @@ struct alauda_info { + unsigned char sense_key; + unsigned long sense_asc; /* additional sense code */ + unsigned long sense_ascq; /* additional sense code qualifier */ ++ ++ bool media_initialized; + }; + + #define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) ) +@@ -476,11 +478,12 @@ static int alauda_check_media(struct us_data *us) + } + + /* Check for media change */ +- if (status[0] & 0x08) { ++ if (status[0] & 0x08 || !info->media_initialized) { + usb_stor_dbg(us, "Media change detected\n"); + alauda_free_maps(&MEDIA_INFO(us)); +- alauda_init_media(us); +- ++ rc = alauda_init_media(us); ++ if (rc == USB_STOR_TRANSPORT_GOOD) ++ info->media_initialized = true; + info->sense_key = UNIT_ATTENTION; + info->sense_asc = 0x28; + info->sense_ascq = 0x00; +-- +2.43.0 + -- 2.47.3