All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h
@ 2020-02-24 15:14 Andy Shevchenko
  2020-02-24 15:14 ` [PATCH v1 02/40] i2c: algo: Use generic definitions for bus frequencies Andy Shevchenko
                   ` (39 more replies)
  0 siblings, 40 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:14 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Andy Gross, Bjorn Andersson

Move bus frequency definitions to i2c.h for wider use.

Cc: Andy Gross <agross@kernel.org>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-qup.c | 9 ++-------
 include/linux/i2c.h          | 7 +++++++
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/busses/i2c-qup.c b/drivers/i2c/busses/i2c-qup.c
index 2d7dabe12723..b9d48ace9ff2 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_STANDARD_MODE_FREQ
 #define DEFAULT_SRC_CLK 20000000
 
 /*
@@ -1861,7 +1856,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_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/include/linux/i2c.h b/include/linux/i2c.h
index f834687989f7..708ac1262a0c 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -39,6 +39,13 @@ enum i2c_slave_event;
 typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
 			      enum i2c_slave_event event, u8 *val);
 
+#define HZ_PER_KHZ			1000
+
+/* I2C Frequency Modes */
+#define I2C_STANDARD_MODE_FREQ		(100 * HZ_PER_KHZ)
+#define I2C_FAST_MODE_FREQ		(400 * HZ_PER_KHZ)
+#define I2C_FAST_MODE_PLUS_FREQ		(1000 * HZ_PER_KHZ)
+
 struct module;
 struct property_entry;
 
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 02/40] i2c: algo: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
@ 2020-02-24 15:14 ` Andy Shevchenko
  2020-02-24 15:14 ` [PATCH v1 03/40] i2c: core: " Andy Shevchenko
                   ` (38 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:14 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko

Since we have generic definitions for bus frequencies, let's use them.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/algos/i2c-algo-pca.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index 5ac93f41bfec..75e7bd708616 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -459,17 +459,17 @@ static int pca_init(struct i2c_adapter *adap)
 		/* To avoid integer overflow, use clock/100 for calculations */
 		clock = pca_clock(pca_data) / 100;
 
-		if (pca_data->i2c_clock > 1000000) {
+		if (pca_data->i2c_clock > I2C_FAST_MODE_PLUS_FREQ) {
 			mode = I2C_PCA_MODE_TURBO;
 			min_tlow = 14;
 			min_thi  = 5;
 			raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */
-		} else if (pca_data->i2c_clock > 400000) {
+		} else if (pca_data->i2c_clock > I2C_FAST_MODE_FREQ) {
 			mode = I2C_PCA_MODE_FASTP;
 			min_tlow = 17;
 			min_thi  = 9;
 			raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */
-		} else if (pca_data->i2c_clock > 100000) {
+		} else if (pca_data->i2c_clock > I2C_STANDARD_MODE_FREQ) {
 			mode = I2C_PCA_MODE_FAST;
 			min_tlow = 44;
 			min_thi  = 20;
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 03/40] i2c: core: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
  2020-02-24 15:14 ` [PATCH v1 02/40] i2c: algo: Use generic definitions for bus frequencies Andy Shevchenko
@ 2020-02-24 15:14 ` Andy Shevchenko
  2020-02-24 16:28   ` Mika Westerberg
  2020-02-24 15:14 ` [PATCH v1 04/40] i2c: altera: " Andy Shevchenko
                   ` (37 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:14 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Mika Westerberg

Since we have generic definitions for bus frequencies, let's use them.

Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/i2c-core-acpi.c | 2 +-
 drivers/i2c/i2c-core-base.c | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
index 8f3dbc97a057..b52d2d8f7258 100644
--- a/drivers/i2c/i2c-core-acpi.c
+++ b/drivers/i2c/i2c-core-acpi.c
@@ -318,7 +318,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_FAST_MODE_FREQ;
 
 	return AE_OK;
 }
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index cefad0881942..1116d0e2de6d 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1612,13 +1612,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_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_STANDARD_MODE_FREQ)
 			t->scl_rise_ns = 1000;
-		else if (t->bus_freq_hz <= 400000)
+		else if (t->bus_freq_hz <= I2C_FAST_MODE_FREQ)
 			t->scl_rise_ns = 300;
 		else
 			t->scl_rise_ns = 120;
@@ -1626,7 +1626,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_FAST_MODE_FREQ)
 			t->scl_fall_ns = 300;
 		else
 			t->scl_fall_ns = 120;
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 04/40] i2c: altera: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
  2020-02-24 15:14 ` [PATCH v1 02/40] i2c: algo: Use generic definitions for bus frequencies Andy Shevchenko
  2020-02-24 15:14 ` [PATCH v1 03/40] i2c: core: " Andy Shevchenko
@ 2020-02-24 15:14 ` Andy Shevchenko
  2020-02-25  7:30   ` Jarkko Nikula
  2020-02-24 15:14 ` [PATCH v1 05/40] i2c: amd-mp2: " Andy Shevchenko
                   ` (36 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:14 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Thor Thayer

Since we have generic definitions for bus frequencies, let's use them.

Cc: Thor Thayer <thor.thayer@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-altera.c | 8 ++++----
 include/linux/i2c.h             | 1 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-altera.c b/drivers/i2c/busses/i2c-altera.c
index 5255d3755411..1f70bbd6e084 100644
--- a/drivers/i2c/busses/i2c-altera.c
+++ b/drivers/i2c/busses/i2c-altera.c
@@ -142,12 +142,12 @@ static inline void altr_i2c_stop(struct altr_i2c_dev *idev)
 static void altr_i2c_init(struct altr_i2c_dev *idev)
 {
 	u32 divisor = clk_get_rate(idev->i2c_clk) / idev->bus_clk_rate;
-	u32 clk_mhz = clk_get_rate(idev->i2c_clk) / 1000000;
+	u32 clk_mhz = clk_get_rate(idev->i2c_clk) / HZ_PER_MHZ;
 	u32 tmp = (ALTR_I2C_THRESHOLD << ALTR_I2C_CTRL_RXT_SHFT) |
 		  (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_STANDARD_MODE_FREQ) {
 		tmp &= ~ALTR_I2C_CTRL_BSPEED;
 		/* Standard mode SCL 50/50 */
 		t_high = divisor * 1 / 2;
@@ -423,10 +423,10 @@ static int altr_i2c_probe(struct platform_device *pdev)
 				       &idev->bus_clk_rate);
 	if (val) {
 		dev_err(&pdev->dev, "Default to 100kHz\n");
-		idev->bus_clk_rate = 100000;	/* default clock rate */
+		idev->bus_clk_rate = I2C_STANDARD_MODE_FREQ;	/* default clock rate */
 	}
 
-	if (idev->bus_clk_rate > 400000) {
+	if (idev->bus_clk_rate > I2C_FAST_MODE_FREQ) {
 		dev_err(&pdev->dev, "invalid clock-frequency %d\n",
 			idev->bus_clk_rate);
 		return -EINVAL;
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 708ac1262a0c..1b9c483bd9f5 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -40,6 +40,7 @@ typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
 			      enum i2c_slave_event event, u8 *val);
 
 #define HZ_PER_KHZ			1000
+#define HZ_PER_MHZ			1000000
 
 /* I2C Frequency Modes */
 #define I2C_STANDARD_MODE_FREQ		(100 * HZ_PER_KHZ)
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 05/40] i2c: amd-mp2: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (2 preceding siblings ...)
  2020-02-24 15:14 ` [PATCH v1 04/40] i2c: altera: " Andy Shevchenko
@ 2020-02-24 15:14 ` Andy Shevchenko
  2020-02-26 17:58   ` Elie Morisse
  2020-02-27  5:06   ` Shah, Nehal-bakulchandra
  2020-02-24 15:14 ` [PATCH v1 06/40] i2c: aspeed: " Andy Shevchenko
                   ` (35 subsequent siblings)
  39 siblings, 2 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:14 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: Andy Shevchenko, Elie Morisse, Nehal Shah, Shyam Sundar S K

Since we have generic definitions for bus frequencies, let's use them.

Cc: Elie Morisse <syniurge@gmail.com>
Cc: Nehal Shah <nehal-bakulchandra.shah@amd.com>
Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-amd-mp2-plat.c | 27 ++++++++++++++++-----------
 include/linux/i2c.h                   |  2 ++
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-amd-mp2-plat.c b/drivers/i2c/busses/i2c-amd-mp2-plat.c
index f5b3f00c6559..9b9d90b98a05 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_HIGH_SPEED_MODE_FREQ,
+	I2C_TURBO_MODE_FREQ,
+	I2C_FAST_MODE_PLUS_FREQ,
+	I2C_FAST_MODE_FREQ,
+	I2C_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_STANDARD_MODE_FREQ:
 		return speed100k;
-	case 400000:
+	case I2C_FAST_MODE_FREQ:
 		return speed400k;
-	case 1000000:
+	case I2C_FAST_MODE_PLUS_FREQ:
 		return speed1000k;
-	case 1400000:
+	case I2C_TURBO_MODE_FREQ:
 		return speed1400k;
-	case 3400000:
+	case I2C_HIGH_SPEED_MODE_FREQ:
 		return speed3400k;
 	default:
 		return speed400k;
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 1b9c483bd9f5..d3022a014227 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -46,6 +46,8 @@ typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
 #define I2C_STANDARD_MODE_FREQ		(100 * HZ_PER_KHZ)
 #define I2C_FAST_MODE_FREQ		(400 * HZ_PER_KHZ)
 #define I2C_FAST_MODE_PLUS_FREQ		(1000 * HZ_PER_KHZ)
+#define I2C_TURBO_MODE_FREQ		(1400 * HZ_PER_KHZ)
+#define I2C_HIGH_SPEED_MODE_FREQ	(3400 * HZ_PER_KHZ)
 
 struct module;
 struct property_entry;
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 06/40] i2c: aspeed: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (3 preceding siblings ...)
  2020-02-24 15:14 ` [PATCH v1 05/40] i2c: amd-mp2: " Andy Shevchenko
@ 2020-02-24 15:14 ` Andy Shevchenko
  2020-02-26  3:54   ` Brendan Higgins
  2020-02-24 15:14 ` [PATCH v1 07/40] i2c: axxia: " Andy Shevchenko
                   ` (34 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:14 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Brendan Higgins

Since we have generic definitions for bus frequencies, let's use them.

Cc: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-aspeed.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c
index a7be6f24450b..ed0004a54278 100644
--- a/drivers/i2c/busses/i2c-aspeed.c
+++ b/drivers/i2c/busses/i2c-aspeed.c
@@ -997,7 +997,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_STANDARD_MODE_FREQ;
 	}
 
 	match = of_match_node(aspeed_i2c_bus_of_table, pdev->dev.of_node);
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 07/40] i2c: axxia: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (4 preceding siblings ...)
  2020-02-24 15:14 ` [PATCH v1 06/40] i2c: aspeed: " Andy Shevchenko
@ 2020-02-24 15:14 ` Andy Shevchenko
  2020-02-24 15:14 ` [PATCH v1 08/40] i2c: bcm-iproc: " Andy Shevchenko
                   ` (33 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:14 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Krzysztof Adamski

Since we have generic definitions for bus frequencies, let's use them.

Cc: Krzysztof Adamski <krzysztof.adamski@nokia.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-axxia.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-axxia.c b/drivers/i2c/busses/i2c-axxia.c
index 0214daa913ff..ac9a4b7ec7fc 100644
--- a/drivers/i2c/busses/i2c-axxia.c
+++ b/drivers/i2c/busses/i2c-axxia.c
@@ -176,7 +176,7 @@ static u32 ns_to_clk(u64 ns, u32 clk_mhz)
 static int axxia_i2c_init(struct axxia_i2c_dev *idev)
 {
 	u32 divisor = clk_get_rate(idev->i2c_clk) / idev->bus_clk_rate;
-	u32 clk_mhz = clk_get_rate(idev->i2c_clk) / 1000000;
+	u32 clk_mhz = clk_get_rate(idev->i2c_clk) / HZ_PER_MHZ;
 	u32 t_setup;
 	u32 t_high, t_low;
 	u32 tmo_clk;
@@ -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_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_STANDARD_MODE_FREQ;	/* default clock rate */
 
 	ret = clk_prepare_enable(idev->i2c_clk);
 	if (ret) {
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 08/40] i2c: bcm-iproc: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (5 preceding siblings ...)
  2020-02-24 15:14 ` [PATCH v1 07/40] i2c: axxia: " Andy Shevchenko
@ 2020-02-24 15:14 ` Andy Shevchenko
  2020-02-24 17:29   ` Scott Branden
  2020-02-24 15:14 ` [PATCH v1 09/40] i2c: bcm-kona: " Andy Shevchenko
                   ` (32 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:14 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Ray Jui, Scott Branden

Since we have generic definitions for bus frequencies, let's use them.

Cc: Ray Jui <rjui@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-bcm-iproc.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c
index 30efb7913b2e..627ad88dcf04 100644
--- a/drivers/i2c/busses/i2c-bcm-iproc.c
+++ b/drivers/i2c/busses/i2c-bcm-iproc.c
@@ -858,25 +858,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_STANDARD_MODE_FREQ;
 	}
 
-	if (bus_speed < 100000) {
+	if (bus_speed < I2C_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_FAST_MODE_FREQ) {
+		bus_speed = I2C_STANDARD_MODE_FREQ;
 	} else {
-		bus_speed = 400000;
+		bus_speed = I2C_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_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);
@@ -1029,7 +1029,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_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);
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 09/40] i2c: bcm-kona: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (6 preceding siblings ...)
  2020-02-24 15:14 ` [PATCH v1 08/40] i2c: bcm-iproc: " Andy Shevchenko
@ 2020-02-24 15:14 ` Andy Shevchenko
  2020-02-24 17:29   ` Scott Branden
  2020-02-24 15:15 ` [PATCH v1 10/40] i2c: cadence: " Andy Shevchenko
                   ` (31 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:14 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: Andy Shevchenko, Florian Fainelli, Ray Jui, Scott Branden

Since we have generic definitions for bus frequencies, let's use them.

Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Ray Jui <rjui@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-bcm-kona.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-bcm-kona.c b/drivers/i2c/busses/i2c-bcm-kona.c
index 4e489a9d16fb..2858639767da 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_STANDARD_MODE_FREQ:
 		dev->std_cfg = &std_cfg_table[BCM_SPD_100K];
 		break;
-	case 400000:
+	case I2C_FAST_MODE_FREQ:
 		dev->std_cfg = &std_cfg_table[BCM_SPD_400K];
 		break;
-	case 1000000:
+	case I2C_FAST_MODE_PLUS_FREQ:
 		dev->std_cfg = &std_cfg_table[BCM_SPD_1MHZ];
 		break;
-	case 3400000:
+	case I2C_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];
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 10/40] i2c: cadence: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (7 preceding siblings ...)
  2020-02-24 15:14 ` [PATCH v1 09/40] i2c: bcm-kona: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 11/40] i2c: designware: " Andy Shevchenko
                   ` (30 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Michal Simek

Since we have generic definitions for bus frequencies, let's use them.

Cc: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-cadence.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 1105aee6634a..9886daae505f 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
 
@@ -949,8 +946,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_FAST_MODE_FREQ))
+		id->i2c_clk = I2C_STANDARD_MODE_FREQ;
 
 	cdns_i2c_writereg(CDNS_I2C_CR_ACK_EN | CDNS_I2C_CR_NEA | CDNS_I2C_CR_MS,
 			  CDNS_I2C_CR_OFFSET);
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 11/40] i2c: designware: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (8 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 10/40] i2c: cadence: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 16:30   ` Mika Westerberg
  2020-02-24 15:15 ` [PATCH v1 12/40] i2c: digicolor: " Andy Shevchenko
                   ` (29 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Jarkko Nikula, Mika Westerberg

Since we have generic definitions for bus frequencies, let's use them.

Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-designware-platdrv.c | 37 ++++++++++++---------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index 3b7d58c2fe85..4ecc2dffeccc 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_STANDARD_MODE_FREQ:
 		dev->sda_hold_time = ss_ht;
 		break;
-	case 1000000:
+	case I2C_FAST_MODE_PLUS_FREQ:
 		dev->sda_hold_time = fp_ht;
 		break;
-	case 3400000:
+	case I2C_HIGH_SPEED_MODE_FREQ:
 		dev->sda_hold_time = hs_ht;
 		break;
-	case 400000:
+	case I2C_FAST_MODE_FREQ:
 	default:
 		dev->sda_hold_time = fs_ht;
 		break;
@@ -198,10 +198,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_STANDARD_MODE_FREQ:
 		dev->master_cfg |= DW_IC_CON_SPEED_STD;
 		break;
-	case 3400000:
+	case I2C_HIGH_SPEED_MODE_FREQ:
 		dev->master_cfg |= DW_IC_CON_SPEED_HIGH;
 		break;
 	default:
@@ -249,6 +249,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_HIGH_SPEED_MODE_FREQ,
+	I2C_FAST_MODE_PLUS_FREQ,
+	I2C_FAST_MODE_FREQ,
+	I2C_STANDARD_MODE_FREQ,
+};
+
 static int dw_i2c_plat_probe(struct platform_device *pdev)
 {
 	struct dw_i2c_platform_data *pdata = dev_get_platdata(&pdev->dev);
@@ -258,9 +265,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)
@@ -296,11 +300,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
@@ -311,7 +315,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_FAST_MODE_FREQ;
 
 	dev->flags |= (uintptr_t)device_get_match_data(&pdev->dev);
 
@@ -325,8 +329,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);
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 12/40] i2c: digicolor: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (9 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 11/40] i2c: designware: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 18:25   ` Baruch Siach
  2020-02-24 15:15 ` [PATCH v1 13/40] i2c: diolan-u2c: " Andy Shevchenko
                   ` (28 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Baruch Siach

Since we have generic definitions for bus frequencies, let's use them.

Cc: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-digicolor.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-digicolor.c b/drivers/i2c/busses/i2c-digicolor.c
index 3adf72540db1..79bf187a90b1 100644
--- a/drivers/i2c/busses/i2c-digicolor.c
+++ b/drivers/i2c/busses/i2c-digicolor.c
@@ -18,7 +18,6 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 
-#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_STANDARD_MODE_FREQ;
 
 	i2c->dev = &pdev->dev;
 	platform_set_drvdata(pdev, i2c);
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 13/40] i2c: diolan-u2c: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (10 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 12/40] i2c: digicolor: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-25 17:36   ` Guenter Roeck
  2020-02-24 15:15 ` [PATCH v1 14/40] i2c: exynos5: " Andy Shevchenko
                   ` (27 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Guenter Roeck

Since we have generic definitions for bus frequencies, let's use them.

Cc: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-diolan-u2c.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
index 382f105e0fe3..9ac79547d30b 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_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_STANDARD_MODE_FREQ) {
 		speed = U2C_I2C_SPEED_FAST;
-		frequency = U2C_I2C_FREQ_FAST;
-	} else if (frequency >= 100000 || frequency == 0) {
+		frequency = I2C_FAST_MODE_FREQ;
+	} else if (frequency >= I2C_STANDARD_MODE_FREQ || frequency == 0) {
 		speed = U2C_I2C_SPEED_STD;
-		frequency = U2C_I2C_FREQ_STD;
+		frequency = I2C_STANDARD_MODE_FREQ;
 	} else {
 		speed = U2C_I2C_SPEED(frequency);
 		if (speed > U2C_I2C_SPEED_2KHZ)
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 14/40] i2c: exynos5: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (11 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 13/40] i2c: diolan-u2c: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 15/40] i2c: hix5hd2: " Andy Shevchenko
                   ` (26 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Kukjin Kim, Krzysztof Kozlowski

Since we have generic definitions for bus frequencies, let's use them.

Cc: Kukjin Kim <kgene@kernel.org>
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-exynos5.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index e7514c16b756..82e580615d87 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
  *
+ * Controller operating frequency, timing values for operation
+ * are calculated against either 100kHz or 1MHz 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_FAST_MODE_PLUS_FREQ) ? I2C_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_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_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_STANDARD_MODE_FREQ;
 
 	strlcpy(i2c->adap.name, "exynos5-i2c", sizeof(i2c->adap.name));
 	i2c->adap.owner   = THIS_MODULE;
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 15/40] i2c: hix5hd2: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (12 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 14/40] i2c: exynos5: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 16/40] i2c: img-scb: " Andy Shevchenko
                   ` (25 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko

Since we have generic definitions for bus frequencies, let's use them.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-hix5hd2.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-hix5hd2.c b/drivers/i2c/busses/i2c-hix5hd2.c
index 8497c7a95dd4..961bc1336021 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_STANDARD_MODE_FREQ;
 	} else {
-		if (freq > HIX5I2C_MAX_FREQ) {
-			priv->freq = HIX5I2C_MAX_FREQ;
+		if (freq > I2C_FAST_MODE_FREQ) {
+			priv->freq = I2C_FAST_MODE_FREQ;
 			dev_warn(priv->dev, "use max freq %d instead\n",
-				 HIX5I2C_MAX_FREQ);
+				 I2C_FAST_MODE_FREQ);
 		} else {
 			priv->freq = freq;
 		}
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 16/40] i2c: img-scb: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (13 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 15/40] i2c: hix5hd2: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 17/40] i2c: imx-lpi2c: " Andy Shevchenko
                   ` (24 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko

Since we have generic definitions for bus frequencies, let's use them.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-img-scb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-img-scb.c b/drivers/i2c/busses/i2c-img-scb.c
index 20a4fbc53007..e5fed1814c8f 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_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_FAST_MODE_FREQ,
 		.tckh = 600,
 		.tckl = 1300,
 		.tsdh = 600,
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 17/40] i2c: imx-lpi2c: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (14 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 16/40] i2c: img-scb: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 18/40] i2c: imx: " Andy Shevchenko
                   ` (23 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: Andy Shevchenko, Dong Aisheng, Shawn Guo, Sascha Hauer

Since we have generic definitions for bus frequencies, let's use them.

Cc: Dong Aisheng <aisheng.dong@nxp.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-imx-lpi2c.c | 16 +++++-----------
 include/linux/i2c.h                |  1 +
 2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
index c92b56485fa6..eb2b0536a59f 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_FAST_MODE_FREQ)
 		mode = STANDARD;
-	else if (bitrate < FAST_MAX_BITRATE)
+	else if (bitrate < I2C_FAST_MODE_PLUS_FREQ)
 		mode = FAST;
-	else if (bitrate < FAST_PLUS_MAX_BITRATE)
+	else if (bitrate < I2C_HIGH_SPEED_MODE_FREQ)
 		mode = FAST_PLUS;
-	else if (bitrate < HIGHSPEED_MAX_BITRATE)
+	else if (bitrate < I2C_ULTRA_SPEED_MODE_FREQ)
 		mode = HS;
 	else
 		mode = ULTRA_FAST;
@@ -578,7 +572,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_STANDARD_MODE_FREQ;
 
 	ret = devm_request_irq(&pdev->dev, irq, lpi2c_imx_isr, 0,
 			       pdev->name, lpi2c_imx);
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index d3022a014227..920f670596cc 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -48,6 +48,7 @@ typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
 #define I2C_FAST_MODE_PLUS_FREQ		(1000 * HZ_PER_KHZ)
 #define I2C_TURBO_MODE_FREQ		(1400 * HZ_PER_KHZ)
 #define I2C_HIGH_SPEED_MODE_FREQ	(3400 * HZ_PER_KHZ)
+#define I2C_ULTRA_SPEED_MODE_FREQ	(5000 * HZ_PER_KHZ)
 
 struct module;
 struct property_entry;
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 18/40] i2c: imx: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (15 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 17/40] i2c: imx-lpi2c: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-25  8:18   ` Oleksij Rempel
  2020-02-24 15:15 ` [PATCH v1 19/40] i2c: lpc2k: " Andy Shevchenko
                   ` (22 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: Andy Shevchenko, Oleksij Rempel, Shawn Guo, Sascha Hauer

Since we have generic definitions for bus frequencies, let's use them.

Cc: Oleksij Rempel <linux@rempel-privat.de>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-imx.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index a3b61336fe55..f5ed0f38904c 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.\
@@ -1139,7 +1136,7 @@ static int i2c_imx_probe(struct platform_device *pdev)
 		goto rpm_disable;
 
 	/* Set up clock divider */
-	i2c_imx->bitrate = IMX_I2C_BIT_RATE;
+	i2c_imx->bitrate = I2C_STANDARD_MODE_FREQ;
 	ret = of_property_read_u32(pdev->dev.of_node,
 				   "clock-frequency", &i2c_imx->bitrate);
 	if (ret < 0 && pdata && pdata->bitrate)
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 19/40] i2c: lpc2k: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (16 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 18/40] i2c: imx: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:35   ` Vladimir Zapolskiy
  2020-02-24 15:15 ` [PATCH v1 20/40] i2c: mt65xx: " Andy Shevchenko
                   ` (21 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Vladimir Zapolskiy

Since we have generic definitions for bus frequencies, let's use them.

Cc: Vladimir Zapolskiy <vz@mleia.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-lpc2k.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-lpc2k.c b/drivers/i2c/busses/i2c-lpc2k.c
index deea18b14add..159ebec5861c 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_STANDARD_MODE_FREQ; /* 100 kHz default clock rate */
 
 	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_STANDARD_MODE_FREQ)
 		scl_high = (clkrate * I2C_STD_MODE_DUTY) / 100;
-	else if (bus_clk_rate <= 400000)
+	else if (bus_clk_rate <= I2C_FAST_MODE_FREQ)
 		scl_high = (clkrate * I2C_FAST_MODE_DUTY) / 100;
 	else
 		scl_high = (clkrate * I2C_FAST_MODE_PLUS_DUTY) / 100;
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 20/40] i2c: mt65xx: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (17 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 19/40] i2c: lpc2k: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 21/40] i2c: mv64xxx: " Andy Shevchenko
                   ` (20 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Matthias Brugger

Since we have generic definitions for bus frequencies, let's use them.

Cc: Matthias Brugger <matthias.bgg@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-mt65xx.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
index 2152ec5f535c..2647e7def4f2 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_FAST_MODE_PLUS_FREQ)
+		target_speed = I2C_FAST_MODE_PLUS_FREQ;
 
-	if (target_speed > MAX_FS_MODE_SPEED)
+	if (target_speed > I2C_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_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_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_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_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_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_STANDARD_MODE_FREQ;
 
 	ret = of_property_read_u32(np, "clock-div", &i2c->clk_src_div);
 	if (ret < 0)
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 21/40] i2c: mv64xxx: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (18 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 20/40] i2c: mt65xx: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-03-13 20:28   ` Gregory CLEMENT
  2020-02-24 15:15 ` [PATCH v1 22/40] i2c: mxs: " Andy Shevchenko
                   ` (19 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Gregory CLEMENT

Since we have generic definitions for bus frequencies, let's use them.

Cc: Gregory CLEMENT <gregory.clement@bootlin.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-mv64xxx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index febb7c7ea72b..e803c6b0a947 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_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_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_STANDARD_MODE_FREQ)
 			drv_data->errata_delay = true;
 	}
 
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 22/40] i2c: mxs: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (19 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 21/40] i2c: mv64xxx: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 23/40] i2c: nomadik: " Andy Shevchenko
                   ` (18 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Shawn Guo, Sascha Hauer

Since we have generic definitions for bus frequencies, let's use them.

Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-mxs.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c
index 89224913f578..215aa18cc4f5 100644
--- a/drivers/i2c/busses/i2c-mxs.c
+++ b/drivers/i2c/busses/i2c-mxs.c
@@ -731,18 +731,18 @@ 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_STANDARD_MODE_FREQ) {
 		/* fast mode */
 		low_count = DIV_ROUND_CLOSEST(divider * 13, (13 + 6));
 		high_count = DIV_ROUND_CLOSEST(divider * 6, (13 + 6));
-		leadin = DIV_ROUND_UP(600 * (clk / 1000000), 1000);
-		bus_free = DIV_ROUND_UP(1300 * (clk / 1000000), 1000);
+		leadin = DIV_ROUND_UP(600 * (clk / HZ_PER_MHZ), 1000);
+		bus_free = DIV_ROUND_UP(1300 * (clk / HZ_PER_MHZ), 1000);
 	} else {
 		/* normal mode */
 		low_count = DIV_ROUND_CLOSEST(divider * 47, (47 + 40));
 		high_count = DIV_ROUND_CLOSEST(divider * 40, (47 + 40));
-		leadin = DIV_ROUND_UP(4700 * (clk / 1000000), 1000);
-		bus_free = DIV_ROUND_UP(4700 * (clk / 1000000), 1000);
+		leadin = DIV_ROUND_UP(4700 * (clk / HZ_PER_MHZ), 1000);
+		bus_free = DIV_ROUND_UP(4700 * (clk / HZ_PER_MHZ), 1000);
 	}
 	rcv_count = high_count * 3 / 8;
 	xmit_count = low_count * 3 / 8;
@@ -769,7 +769,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_STANDARD_MODE_FREQ;
 	}
 
 	mxs_i2c_derive_timing(i2c, speed);
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 23/40] i2c: nomadik: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (20 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 22/40] i2c: mxs: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-25 21:57   ` Linus Walleij
  2020-02-24 15:15 ` [PATCH v1 24/40] i2c: owl: " Andy Shevchenko
                   ` (17 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Linus Walleij

Since we have generic definitions for bus frequencies, let's use them.

Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-nomadik.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index 01a7d72e5511..4aaaf48b60fb 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_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_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_STANDARD_MODE_FREQ;
 
 	/* This driver only supports 'standard' and 'fast' modes of operation. */
-	if (nmk->clk_freq <= 100000)
+	if (nmk->clk_freq <= I2C_STANDARD_MODE_FREQ)
 		nmk->sm = I2C_FREQ_MODE_STANDARD;
 	else
 		nmk->sm = I2C_FREQ_MODE_FAST;
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 24/40] i2c: owl: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (21 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 23/40] i2c: nomadik: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:27   ` Manivannan Sadhasivam
  2020-02-24 15:15 ` [PATCH v1 25/40] i2c: rcar: " Andy Shevchenko
                   ` (16 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: Andy Shevchenko, Andreas Färber, Manivannan Sadhasivam

Since we have generic definitions for bus frequencies, let's use them.

Cc: "Andreas Färber" <afaerber@suse.de>
Cc: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-owl.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-owl.c b/drivers/i2c/busses/i2c-owl.c
index b6b5a495118b..f9baeeb1a711 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;
@@ -419,11 +416,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_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_STANDARD_MODE_FREQ &&
+	    i2c_dev->bus_freq != I2C_FAST_MODE_FREQ) {
 		dev_err(dev, "invalid clock-frequency %d\n", i2c_dev->bus_freq);
 		return -EINVAL;
 	}
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 25/40] i2c: rcar: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (22 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 24/40] i2c: owl: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 26/40] i2c: riic: " Andy Shevchenko
                   ` (15 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko

Since we have generic definitions for bus frequencies, let's use them.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-rcar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 879f0e61a496..e9a2c6ba1d28 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -242,7 +242,7 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, struct i2c_timin
 	struct device *dev = rcar_i2c_priv_to_dev(priv);
 
 	/* Fall back to previously used values if not supplied */
-	t->bus_freq_hz = t->bus_freq_hz ?: 100000;
+	t->bus_freq_hz = t->bus_freq_hz ?: I2C_STANDARD_MODE_FREQ;
 	t->scl_fall_ns = t->scl_fall_ns ?: 35;
 	t->scl_rise_ns = t->scl_rise_ns ?: 200;
 	t->scl_int_delay_ns = t->scl_int_delay_ns ?: 50;
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 26/40] i2c: riic: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (23 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 25/40] i2c: rcar: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 16:48   ` Chris Brandt
  2020-02-24 15:15 ` [PATCH v1 27/40] i2c: rk3x: " Andy Shevchenko
                   ` (14 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Chris Brandt

Since we have generic definitions for bus frequencies, let's use them.

Cc: Chris Brandt <chris.brandt@renesas.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-riic.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c
index 800414886f6b..051649e2afe5 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_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_FAST_MODE_FREQ);
 		ret = -EINVAL;
 		goto out;
 	}
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 27/40] i2c: rk3x: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (24 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 26/40] i2c: riic: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 28/40] i2c: s3c2410: " Andy Shevchenko
                   ` (13 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Heiko Stuebner

Since we have generic definitions for bus frequencies, let's use them.

Cc: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-rk3x.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
index 1a33007b03e9..a621f747009b 100644
--- a/drivers/i2c/busses/i2c-rk3x.c
+++ b/drivers/i2c/busses/i2c-rk3x.c
@@ -539,9 +539,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_STANDARD_MODE_FREQ)
 		return &standard_mode_spec;
-	else if (speed <= 400000)
+	else if (speed <= I2C_FAST_MODE_FREQ)
 		return &fast_mode_spec;
 	else
 		return &fast_mode_plus_spec;
@@ -578,8 +578,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_FAST_MODE_FREQ))
+		t->bus_freq_hz = I2C_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_FAST_MODE_PLUS_FREQ))
+		t->bus_freq_hz = I2C_FAST_MODE_PLUS_FREQ;
 
 	/* prevent scl_rate_khz from becoming 0 */
 	if (WARN_ON(t->bus_freq_hz < 1000))
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 28/40] i2c: s3c2410: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (25 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 27/40] i2c: rk3x: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 29/40] i2c: sh_mobile: " Andy Shevchenko
                   ` (12 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Kukjin Kim, Krzysztof Kozlowski

Since we have generic definitions for bus frequencies, let's use them.

Cc: Kukjin Kim <kgene@kernel.org>
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-s3c2410.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index c98ef4c4a0c9..21631fa65da0 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -835,13 +835,13 @@ static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got)
 	int freq;
 
 	i2c->clkrate = clkin;
-	clkin /= 1000;		/* clkin now in KHz */
+	clkin /= HZ_PER_KHZ;	/* 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_STANDARD_MODE_FREQ;
 
-	target_frequency /= 1000; /* Target frequency now in KHz */
+	target_frequency /= HZ_PER_KHZ; /* Target frequency now in KHz */
 
 	freq = s3c24xx_i2c_calcdivisor(clkin, target_frequency, &div1, &divs);
 
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 29/40] i2c: sh_mobile: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (26 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 28/40] i2c: s3c2410: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 30/40] i2c: sirf: " Andy Shevchenko
                   ` (11 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko

Since we have generic definitions for bus frequencies, let's use them.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-sh_mobile.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index 82b3b795e0bd..dc29a29904df 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -145,9 +145,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
@@ -270,11 +267,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_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_FAST_MODE_FREQ) {
 		tLOW	= 13;	/* tLOW = 1.3 us */
 		tHIGH	= 6;	/* tHD;STA = tHIGH = 0.6 us */
 		tf	= 3;	/* tf = 0.3 us */
@@ -851,7 +848,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_STANDARD_MODE_FREQ : bus_speed;
 	pd->clks_per_count = 1;
 
 	/* Newer variants come with two new bits in ICIC */
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 30/40] i2c: sirf: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (27 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 29/40] i2c: sh_mobile: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 31/40] i2c: spdr: " Andy Shevchenko
                   ` (10 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Barry Song

Since we have generic definitions for bus frequencies, let's use them.

Cc: Barry Song <baohua@kernel.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-sirf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-sirf.c b/drivers/i2c/busses/i2c-sirf.c
index fb7a046b3226..bbd022181b13 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_STANDARD_MODE_FREQ;
 
 	/*
 	 * Due to some hardware design issues, we need to tune the formula.
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 31/40] i2c: spdr: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (28 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 30/40] i2c: sirf: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-25  0:49   ` Baolin Wang
  2020-02-24 15:15 ` [PATCH v1 32/40] i2c: stm32f4: " Andy Shevchenko
                   ` (9 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: Andy Shevchenko, Orson Zhai, Baolin Wang, Chunyan Zhang

Since we have generic definitions for bus frequencies, let's use them.

Cc: Orson Zhai <orsonzhai@gmail.com>
Cc: Baolin Wang <baolin.wang7@gmail.com>
Cc: Chunyan Zhang <zhang.lyra@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-sprd.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-sprd.c b/drivers/i2c/busses/i2c-sprd.c
index b432e7580458..4eb3ad1e5ab5 100644
--- a/drivers/i2c/busses/i2c-sprd.c
+++ b/drivers/i2c/busses/i2c-sprd.c
@@ -337,9 +337,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_FAST_MODE_FREQ)
 		writel((6 * apb_clk) / 10000000, i2c_dev->base + ADDR_STA0_DVD);
-	else if (freq == 100000)
+	else if (freq == I2C_STANDARD_MODE_FREQ)
 		writel((4 * apb_clk) / 1000000, i2c_dev->base + ADDR_STA0_DVD);
 }
 
@@ -502,7 +502,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_STANDARD_MODE_FREQ;
 	i2c_dev->adap.owner = THIS_MODULE;
 	i2c_dev->dev = dev;
 	i2c_dev->adap.retries = 3;
@@ -516,7 +516,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_STANDARD_MODE_FREQ &&
+	    i2c_dev->bus_freq != I2C_FAST_MODE_FREQ)
 		return -EINVAL;
 
 	ret = sprd_i2c_clk_init(i2c_dev);
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 32/40] i2c: stm32f4: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (29 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 31/40] i2c: spdr: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-03-02  8:39   ` Pierre Yves MORDRET
  2020-02-24 15:15 ` [PATCH v1 33/40] i2c: stm32f7: " Andy Shevchenko
                   ` (8 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: Andy Shevchenko, Pierre-Yves MORDRET, Maxime Coquelin, Alexandre Torgue

Since we have generic definitions for bus frequencies, let's use them.

Cc: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-stm32f4.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-stm32f4.c b/drivers/i2c/busses/i2c-stm32f4.c
index ba600d77a3f8..0a67b44f2755 100644
--- a/drivers/i2c/busses/i2c-stm32f4.c
+++ b/drivers/i2c/busses/i2c-stm32f4.c
@@ -91,7 +91,6 @@
 #define STM32F4_I2C_MIN_STANDARD_FREQ	2U
 #define STM32F4_I2C_MIN_FAST_FREQ	6U
 #define STM32F4_I2C_MAX_FREQ		46U
-#define HZ_TO_MHZ			1000000
 
 /**
  * struct stm32f4_i2c_msg - client specific data
@@ -154,7 +153,7 @@ static int stm32f4_i2c_set_periph_clk_freq(struct stm32f4_i2c_dev *i2c_dev)
 	u32 cr2 = 0;
 
 	i2c_dev->parent_rate = clk_get_rate(i2c_dev->clk);
-	freq = DIV_ROUND_UP(i2c_dev->parent_rate, HZ_TO_MHZ);
+	freq = DIV_ROUND_UP(i2c_dev->parent_rate, HZ_PER_MHZ);
 
 	if (i2c_dev->speed == STM32_I2C_SPEED_STANDARD) {
 		/*
@@ -190,7 +189,7 @@ static int stm32f4_i2c_set_periph_clk_freq(struct stm32f4_i2c_dev *i2c_dev)
 
 static void stm32f4_i2c_set_rise_time(struct stm32f4_i2c_dev *i2c_dev)
 {
-	u32 freq = DIV_ROUND_UP(i2c_dev->parent_rate, HZ_TO_MHZ);
+	u32 freq = DIV_ROUND_UP(i2c_dev->parent_rate, HZ_PER_MHZ);
 	u32 trise;
 
 	/*
@@ -243,7 +242,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_STANDARD_MODE_FREQ << 1);
 	} else {
 		/*
 		 * In fast mode, we compute CCR with duty = 0 as with low
@@ -263,7 +262,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_FAST_MODE_FREQ * 3);
 
 		/* Select Fast mode */
 		ccr |= STM32F4_I2C_CCR_FS;
@@ -807,7 +806,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_FAST_MODE_FREQ)
 		i2c_dev->speed = STM32_I2C_SPEED_FAST;
 
 	i2c_dev->dev = &pdev->dev;
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 33/40] i2c: stm32f7: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (30 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 32/40] i2c: stm32f4: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-03-02  8:40   ` Pierre Yves MORDRET
  2020-02-24 15:15 ` [PATCH v1 34/40] i2c: stu300: " Andy Shevchenko
                   ` (7 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: Andy Shevchenko, Pierre-Yves MORDRET, Maxime Coquelin, Alexandre Torgue

Since we have generic definitions for bus frequencies, let's use them.

Cc: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-stm32f7.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
index 5c3e8ac6ad92..9af5733ed513 100644
--- a/drivers/i2c/busses/i2c-stm32f7.c
+++ b/drivers/i2c/busses/i2c-stm32f7.c
@@ -334,9 +334,9 @@ struct stm32f7_i2c_dev {
  */
 static struct stm32f7_i2c_spec i2c_specs[] = {
 	[STM32_I2C_SPEED_STANDARD] = {
-		.rate = 100000,
-		.rate_min = 80000,
-		.rate_max = 100000,
+		.rate = I2C_STANDARD_MODE_FREQ,
+		.rate_min = I2C_STANDARD_MODE_FREQ * 8 / 10,	/* 80% */
+		.rate_max = I2C_STANDARD_MODE_FREQ,
 		.fall_max = 300,
 		.rise_max = 1000,
 		.hddat_min = 0,
@@ -346,9 +346,9 @@ static struct stm32f7_i2c_spec i2c_specs[] = {
 		.h_min = 4000,
 	},
 	[STM32_I2C_SPEED_FAST] = {
-		.rate = 400000,
-		.rate_min = 320000,
-		.rate_max = 400000,
+		.rate = I2C_FAST_MODE_FREQ,
+		.rate_min = I2C_FAST_MODE_FREQ * 8 / 10,	/* 80% */
+		.rate_max = I2C_FAST_MODE_FREQ,
 		.fall_max = 300,
 		.rise_max = 300,
 		.hddat_min = 0,
@@ -358,9 +358,9 @@ static struct stm32f7_i2c_spec i2c_specs[] = {
 		.h_min = 600,
 	},
 	[STM32_I2C_SPEED_FAST_PLUS] = {
-		.rate = 1000000,
-		.rate_min = 800000,
-		.rate_max = 1000000,
+		.rate = I2C_FAST_MODE_PLUS_FREQ,
+		.rate_min = I2C_FAST_MODE_PLUS_FREQ * 8 / 10,	/* 80% */
+		.rate_max = I2C_FAST_MODE_PLUS_FREQ,
 		.fall_max = 100,
 		.rise_max = 120,
 		.hddat_min = 0,
@@ -1894,14 +1894,14 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
 	i2c_dev->speed = STM32_I2C_SPEED_STANDARD;
 	ret = device_property_read_u32(&pdev->dev, "clock-frequency",
 				       &clk_rate);
-	if (!ret && clk_rate >= 1000000) {
+	if (!ret && clk_rate >= I2C_FAST_MODE_PLUS_FREQ) {
 		i2c_dev->speed = STM32_I2C_SPEED_FAST_PLUS;
 		ret = stm32f7_i2c_setup_fm_plus_bits(pdev, i2c_dev);
 		if (ret)
 			goto clk_free;
-	} else if (!ret && clk_rate >= 400000) {
+	} else if (!ret && clk_rate >= I2C_FAST_MODE_FREQ) {
 		i2c_dev->speed = STM32_I2C_SPEED_FAST;
-	} else if (!ret && clk_rate >= 100000) {
+	} else if (!ret && clk_rate >= I2C_STANDARD_MODE_FREQ) {
 		i2c_dev->speed = STM32_I2C_SPEED_STANDARD;
 	}
 
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 34/40] i2c: stu300: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (31 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 33/40] i2c: stm32f7: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-25 21:57   ` Linus Walleij
  2020-02-24 15:15 ` [PATCH v1 35/40] i2c: st: " Andy Shevchenko
                   ` (6 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Linus Walleij

Since we have generic definitions for bus frequencies, let's use them.

Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-stu300.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c
index 42e0a53e7fa4..d5fef98796bb 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_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_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_STANDARD_MODE_FREQ) {
 		/* CC6..CC0 */
 		stu300_wr8((val & I2C_CCR_CC_MASK) | I2C_CCR_FMSM,
 			   dev->virtbase + I2C_CCR);
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 35/40] i2c: st: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (32 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 34/40] i2c: stu300: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 36/40] i2c: synquacer: " Andy Shevchenko
                   ` (5 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Patrice Chotard

Since we have generic definitions for bus frequencies, let's use them.

Cc: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-st.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-st.c b/drivers/i2c/busses/i2c-st.c
index 54e1fc8a495e..441fc2245f25 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_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_FAST_MODE_FREQ,
 		.rep_start_hold		= 660,
 		.rep_start_setup	= 660,
 		.start_hold		= 660,
@@ -835,7 +835,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_FAST_MODE_FREQ))
 		i2c_dev->mode = I2C_MODE_FAST;
 
 	i2c_dev->dev = &pdev->dev;
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 36/40] i2c: synquacer: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (33 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 35/40] i2c: st: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:18   ` Ard Biesheuvel
  2020-02-24 15:15 ` [PATCH v1 37/40] i2c: tegra: " Andy Shevchenko
                   ` (4 subsequent siblings)
  39 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Ard Biesheuvel

Since we have generic definitions for bus frequencies, let's use them.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-synquacer.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-synquacer.c
index 86026798b4f7..ccd2ed4fa2f1 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_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_FAST_MODE_FREQ) - 2) * 2, 3)
 
 /* (clkrate <= 18000000) */
 /* calculate the value of CS bits in CCR register on standard mode */
@@ -111,11 +111,11 @@
 					& SYNQUACER_I2C_CSR_CS_MASK)
 
 /* min I2C clock frequency 14M */
-#define SYNQUACER_I2C_MIN_CLK_RATE	(14 * 1000000)
+#define SYNQUACER_I2C_MIN_CLK_RATE	(14 * HZ_PER_MHZ)
 /* max I2C clock frequency 200M */
-#define SYNQUACER_I2C_MAX_CLK_RATE	(200 * 1000000)
+#define SYNQUACER_I2C_MAX_CLK_RATE	(200 * HZ_PER_MHZ)
 /* I2C clock frequency 18M */
-#define SYNQUACER_I2C_CLK_RATE_18M	(18 * 1000000)
+#define SYNQUACER_I2C_CLK_RATE_18M	(18 * HZ_PER_MHZ)
 
 #define SYNQUACER_I2C_SPEED_FM		400	// Fast Mode
 #define SYNQUACER_I2C_SPEED_SM		100	// 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_FAST_MODE_FREQ)
 		i2c->speed_khz = SYNQUACER_I2C_SPEED_SM;
 	else
 		i2c->speed_khz = SYNQUACER_I2C_SPEED_FM;
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 37/40] i2c: tegra: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (34 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 36/40] i2c: synquacer: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 38/40] i2c: uniphier-f: " Andy Shevchenko
                   ` (3 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Laxman Dewangan, Dmitry Osipenko

Since we have generic definitions for bus frequencies, let's use them.

Cc: Laxman Dewangan <ldewangan@nvidia.com>
Cc: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-tegra.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index cbc2ad49043e..265c56952e84 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -123,10 +123,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
 
@@ -737,8 +733,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_STANDARD_MODE_FREQ &&
+	    i2c_dev->bus_clk_rate <= I2C_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;
@@ -1341,7 +1337,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_STANDARD_MODE_FREQ; /* default clock rate */
 
 	multi_mode = of_property_read_bool(np, "multi-master");
 	i2c_dev->is_multimaster_mode = multi_mode;
@@ -1640,12 +1636,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_FAST_MODE_FREQ &&
+	    i2c_dev->bus_clk_rate <= I2C_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_STANDARD_MODE_FREQ &&
+		 i2c_dev->bus_clk_rate <= I2C_FAST_MODE_FREQ)
 		i2c_dev->clk_divisor_non_hs_mode =
 				i2c_dev->hw->clk_divisor_fast_mode;
 	else
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 38/40] i2c: uniphier-f: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (35 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 37/40] i2c: tegra: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 39/40] i2c: uniphier: " Andy Shevchenko
                   ` (2 subsequent siblings)
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Masahiro Yamada

Since we have generic definitions for bus frequencies, let's use them.

Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-uniphier-f.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c
index 4241aac79e7e..47b78ebfb291 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_STANDARD_MODE_FREQ;
 
-	if (!bus_speed || bus_speed > UNIPHIER_FI2C_MAX_SPEED) {
+	if (!bus_speed || bus_speed > I2C_FAST_MODE_FREQ) {
 		dev_err(dev, "invalid clock-frequency %d\n", bus_speed);
 		return -EINVAL;
 	}
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 39/40] i2c: uniphier: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (36 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 38/40] i2c: uniphier-f: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-24 15:15 ` [PATCH v1 40/40] i2c: xlp9xx: " Andy Shevchenko
  2020-02-25 10:22 ` [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Wolfram Sang
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, Masahiro Yamada

Since we have generic definitions for bus frequencies, let's use them.

Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-uniphier.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/busses/i2c-uniphier.c b/drivers/i2c/busses/i2c-uniphier.c
index 0270090c0360..782bf452b4a9 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_STANDARD_MODE_FREQ;
 
-	if (!bus_speed || bus_speed > UNIPHIER_I2C_MAX_SPEED) {
+	if (!bus_speed || bus_speed > I2C_FAST_MODE_FREQ) {
 		dev_err(dev, "invalid clock-frequency %d\n", bus_speed);
 		return -EINVAL;
 	}
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* [PATCH v1 40/40] i2c: xlp9xx: Use generic definitions for bus frequencies
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (37 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 39/40] i2c: uniphier: " Andy Shevchenko
@ 2020-02-24 15:15 ` Andy Shevchenko
  2020-02-25 10:22 ` [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Wolfram Sang
  39 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 15:15 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko, George Cherian

Since we have generic definitions for bus frequencies, let's use them.

Cc: George Cherian <gcherian@marvell.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-xlp9xx.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c
index 8a873975cf12..4328b0fc6002 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_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_FAST_MODE_FREQ) {
 		dev_warn(&pdev->dev, "invalid frequency %u, using default\n",
 			 freq);
-		freq = XLP9XX_I2C_DEFAULT_FREQ;
+		freq = I2C_STANDARD_MODE_FREQ;
 	}
 	priv->clk_hz = freq;
 
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 36/40] i2c: synquacer: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 36/40] i2c: synquacer: " Andy Shevchenko
@ 2020-02-24 15:18   ` Ard Biesheuvel
  0 siblings, 0 replies; 68+ messages in thread
From: Ard Biesheuvel @ 2020-02-24 15:18 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Wolfram Sang, linux-i2c

On Mon, 24 Feb 2020 at 16:15, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Since we have generic definitions for bus frequencies, let's use them.
>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Acked-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>  drivers/i2c/busses/i2c-synquacer.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-synquacer.c
> index 86026798b4f7..ccd2ed4fa2f1 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_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_FAST_MODE_FREQ) - 2) * 2, 3)
>
>  /* (clkrate <= 18000000) */
>  /* calculate the value of CS bits in CCR register on standard mode */
> @@ -111,11 +111,11 @@
>                                         & SYNQUACER_I2C_CSR_CS_MASK)
>
>  /* min I2C clock frequency 14M */
> -#define SYNQUACER_I2C_MIN_CLK_RATE     (14 * 1000000)
> +#define SYNQUACER_I2C_MIN_CLK_RATE     (14 * HZ_PER_MHZ)
>  /* max I2C clock frequency 200M */
> -#define SYNQUACER_I2C_MAX_CLK_RATE     (200 * 1000000)
> +#define SYNQUACER_I2C_MAX_CLK_RATE     (200 * HZ_PER_MHZ)
>  /* I2C clock frequency 18M */
> -#define SYNQUACER_I2C_CLK_RATE_18M     (18 * 1000000)
> +#define SYNQUACER_I2C_CLK_RATE_18M     (18 * HZ_PER_MHZ)
>
>  #define SYNQUACER_I2C_SPEED_FM         400     // Fast Mode
>  #define SYNQUACER_I2C_SPEED_SM         100     // 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_FAST_MODE_FREQ)
>                 i2c->speed_khz = SYNQUACER_I2C_SPEED_SM;
>         else
>                 i2c->speed_khz = SYNQUACER_I2C_SPEED_FM;
> --
> 2.25.0
>

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 24/40] i2c: owl: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 24/40] i2c: owl: " Andy Shevchenko
@ 2020-02-24 15:27   ` Manivannan Sadhasivam
  0 siblings, 0 replies; 68+ messages in thread
From: Manivannan Sadhasivam @ 2020-02-24 15:27 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Wolfram Sang, linux-i2c, Andreas Färber

On Mon, Feb 24, 2020 at 05:15:14PM +0200, Andy Shevchenko wrote:
> Since we have generic definitions for bus frequencies, let's use them.
> 
> Cc: "Andreas Färber" <afaerber@suse.de>
> Cc: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

Thanks,
Mani

> ---
>  drivers/i2c/busses/i2c-owl.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-owl.c b/drivers/i2c/busses/i2c-owl.c
> index b6b5a495118b..f9baeeb1a711 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;
> @@ -419,11 +416,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_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_STANDARD_MODE_FREQ &&
> +	    i2c_dev->bus_freq != I2C_FAST_MODE_FREQ) {
>  		dev_err(dev, "invalid clock-frequency %d\n", i2c_dev->bus_freq);
>  		return -EINVAL;
>  	}
> -- 
> 2.25.0
> 

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 19/40] i2c: lpc2k: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 19/40] i2c: lpc2k: " Andy Shevchenko
@ 2020-02-24 15:35   ` Vladimir Zapolskiy
  2020-02-24 16:01     ` Andy Shevchenko
  0 siblings, 1 reply; 68+ messages in thread
From: Vladimir Zapolskiy @ 2020-02-24 15:35 UTC (permalink / raw)
  To: Andy Shevchenko, Wolfram Sang, linux-i2c

Hi Andy!

On 2/24/20 5:15 PM, Andy Shevchenko wrote:
> Since we have generic definitions for bus frequencies, let's use them.
> 
> Cc: Vladimir Zapolskiy <vz@mleia.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/i2c/busses/i2c-lpc2k.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-lpc2k.c b/drivers/i2c/busses/i2c-lpc2k.c
> index deea18b14add..159ebec5861c 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_STANDARD_MODE_FREQ; /* 100 kHz default clock rate */

The line above becomes longer than 80 symbols, please fix it by simply
removing the comment, note that it might be an issue through the series.

Could I2C_STD_MODE_FREQ be a shorter and still acceptable name?

>  
>  	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_STANDARD_MODE_FREQ)
>  		scl_high = (clkrate * I2C_STD_MODE_DUTY) / 100;
> -	else if (bus_clk_rate <= 400000)
> +	else if (bus_clk_rate <= I2C_FAST_MODE_FREQ)
>  		scl_high = (clkrate * I2C_FAST_MODE_DUTY) / 100;
>  	else
>  		scl_high = (clkrate * I2C_FAST_MODE_PLUS_DUTY) / 100;
> 

After the requested fix:

Acked-by: Vladimir Zapolskiy <vz@mleia.com>

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 19/40] i2c: lpc2k: Use generic definitions for bus frequencies
  2020-02-24 15:35   ` Vladimir Zapolskiy
@ 2020-02-24 16:01     ` Andy Shevchenko
  0 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-24 16:01 UTC (permalink / raw)
  To: Vladimir Zapolskiy; +Cc: Wolfram Sang, linux-i2c

On Mon, Feb 24, 2020 at 05:35:54PM +0200, Vladimir Zapolskiy wrote:
> On 2/24/20 5:15 PM, Andy Shevchenko wrote:
> > Since we have generic definitions for bus frequencies, let's use them.

> > -		bus_clk_rate = 100000; /* 100 kHz default clock rate */
> > +		bus_clk_rate = I2C_STANDARD_MODE_FREQ; /* 100 kHz default clock rate */
> 
> The line above becomes longer than 80 symbols, please fix it by simply
> removing the comment, note that it might be an issue through the series.

Will do.

> Could I2C_STD_MODE_FREQ be a shorter and still acceptable name?

I/m fine with it, but I will wait for Wolfram and others to comment.

> After the requested fix:
> 
> Acked-by: Vladimir Zapolskiy <vz@mleia.com>

Thanks!

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 03/40] i2c: core: Use generic definitions for bus frequencies
  2020-02-24 15:14 ` [PATCH v1 03/40] i2c: core: " Andy Shevchenko
@ 2020-02-24 16:28   ` Mika Westerberg
  0 siblings, 0 replies; 68+ messages in thread
From: Mika Westerberg @ 2020-02-24 16:28 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Wolfram Sang, linux-i2c

On Mon, Feb 24, 2020 at 05:14:53PM +0200, Andy Shevchenko wrote:
> Since we have generic definitions for bus frequencies, let's use them.
> 
> Cc: Mika Westerberg <mika.westerberg@linux.intel.com>

Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 11/40] i2c: designware: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 11/40] i2c: designware: " Andy Shevchenko
@ 2020-02-24 16:30   ` Mika Westerberg
  2020-02-25  7:30     ` Jarkko Nikula
  0 siblings, 1 reply; 68+ messages in thread
From: Mika Westerberg @ 2020-02-24 16:30 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Wolfram Sang, linux-i2c, Jarkko Nikula

On Mon, Feb 24, 2020 at 05:15:01PM +0200, Andy Shevchenko wrote:
> Since we have generic definitions for bus frequencies, let's use them.
> 
> Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
> Cc: Mika Westerberg <mika.westerberg@linux.intel.com>

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>

^ permalink raw reply	[flat|nested] 68+ messages in thread

* RE: [PATCH v1 26/40] i2c: riic: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 26/40] i2c: riic: " Andy Shevchenko
@ 2020-02-24 16:48   ` Chris Brandt
  0 siblings, 0 replies; 68+ messages in thread
From: Chris Brandt @ 2020-02-24 16:48 UTC (permalink / raw)
  To: Andy Shevchenko, Wolfram Sang, linux-i2c

On Mon, Feb 24, 2020 1, Andy Shevchenko wrote:
> Subject: [PATCH v1 26/40] i2c: riic: Use generic definitions for bus
> frequencies
> 
> Since we have generic definitions for bus frequencies, let's use them.
> 
> Cc: Chris Brandt <chris.brandt@renesas.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/i2c/busses/i2c-riic.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Chris Brandt <chris.brandt@renesas.com>

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 08/40] i2c: bcm-iproc: Use generic definitions for bus frequencies
  2020-02-24 15:14 ` [PATCH v1 08/40] i2c: bcm-iproc: " Andy Shevchenko
@ 2020-02-24 17:29   ` Scott Branden
  0 siblings, 0 replies; 68+ messages in thread
From: Scott Branden @ 2020-02-24 17:29 UTC (permalink / raw)
  To: Andy Shevchenko, Wolfram Sang, linux-i2c; +Cc: Ray Jui, Scott Branden

Thanks Andy.

On 2020-02-24 7:14 a.m., Andy Shevchenko wrote:
> Since we have generic definitions for bus frequencies, let's use them.
>
> Cc: Ray Jui <rjui@broadcom.com>
> Cc: Scott Branden <sbranden@broadcom.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Scott Branden <scott.branden@broadcom.com>
> ---
>   drivers/i2c/busses/i2c-bcm-iproc.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c
> index 30efb7913b2e..627ad88dcf04 100644
> --- a/drivers/i2c/busses/i2c-bcm-iproc.c
> +++ b/drivers/i2c/busses/i2c-bcm-iproc.c
> @@ -858,25 +858,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_STANDARD_MODE_FREQ;
>   	}
>   
> -	if (bus_speed < 100000) {
> +	if (bus_speed < I2C_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_FAST_MODE_FREQ) {
> +		bus_speed = I2C_STANDARD_MODE_FREQ;
>   	} else {
> -		bus_speed = 400000;
> +		bus_speed = I2C_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_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);
> @@ -1029,7 +1029,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_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);

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 09/40] i2c: bcm-kona: Use generic definitions for bus frequencies
  2020-02-24 15:14 ` [PATCH v1 09/40] i2c: bcm-kona: " Andy Shevchenko
@ 2020-02-24 17:29   ` Scott Branden
  0 siblings, 0 replies; 68+ messages in thread
From: Scott Branden @ 2020-02-24 17:29 UTC (permalink / raw)
  To: Andy Shevchenko, Wolfram Sang, linux-i2c
  Cc: Florian Fainelli, Ray Jui, Scott Branden



On 2020-02-24 7:14 a.m., Andy Shevchenko wrote:
> Since we have generic definitions for bus frequencies, let's use them.
>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Ray Jui <rjui@broadcom.com>
> Cc: Scott Branden <sbranden@broadcom.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Scott Branden <scott.branden@broadcom.com>
> ---
>   drivers/i2c/busses/i2c-bcm-kona.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-bcm-kona.c b/drivers/i2c/busses/i2c-bcm-kona.c
> index 4e489a9d16fb..2858639767da 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_STANDARD_MODE_FREQ:
>   		dev->std_cfg = &std_cfg_table[BCM_SPD_100K];
>   		break;
> -	case 400000:
> +	case I2C_FAST_MODE_FREQ:
>   		dev->std_cfg = &std_cfg_table[BCM_SPD_400K];
>   		break;
> -	case 1000000:
> +	case I2C_FAST_MODE_PLUS_FREQ:
>   		dev->std_cfg = &std_cfg_table[BCM_SPD_1MHZ];
>   		break;
> -	case 3400000:
> +	case I2C_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];

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 12/40] i2c: digicolor: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 12/40] i2c: digicolor: " Andy Shevchenko
@ 2020-02-24 18:25   ` Baruch Siach
  0 siblings, 0 replies; 68+ messages in thread
From: Baruch Siach @ 2020-02-24 18:25 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Wolfram Sang, linux-i2c

Hi Andy,

On Mon, Feb 24 2020, Andy Shevchenko wrote:
> Since we have generic definitions for bus frequencies, let's use them.
>
> Cc: Baruch Siach <baruch@tkos.co.il>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Acked-by: Baruch Siach <baruch@tkos.co.il>

baruch

> ---
>  drivers/i2c/busses/i2c-digicolor.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-digicolor.c b/drivers/i2c/busses/i2c-digicolor.c
> index 3adf72540db1..79bf187a90b1 100644
> --- a/drivers/i2c/busses/i2c-digicolor.c
> +++ b/drivers/i2c/busses/i2c-digicolor.c
> @@ -18,7 +18,6 @@
>  #include <linux/of.h>
>  #include <linux/platform_device.h>
>  
> -#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_STANDARD_MODE_FREQ;
>  
>  	i2c->dev = &pdev->dev;
>  	platform_set_drvdata(pdev, i2c);

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 31/40] i2c: spdr: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 31/40] i2c: spdr: " Andy Shevchenko
@ 2020-02-25  0:49   ` Baolin Wang
  2020-02-25 10:38     ` Andy Shevchenko
  0 siblings, 1 reply; 68+ messages in thread
From: Baolin Wang @ 2020-02-25  0:49 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Wolfram Sang, linux-i2c, Orson Zhai, Chunyan Zhang

Hi Andy,

On Mon, Feb 24, 2020 at 11:15 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Since we have generic definitions for bus frequencies, let's use them.
>
> Cc: Orson Zhai <orsonzhai@gmail.com>
> Cc: Baolin Wang <baolin.wang7@gmail.com>
> Cc: Chunyan Zhang <zhang.lyra@gmail.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Can you fix the typo in the subject line by changing 'spdr' to 'sprd'?
Otherwise looks good to me. Thanks.
Reviewed-by: Baolin Wang <baolin.wang7@gmail.com>

> ---
>  drivers/i2c/busses/i2c-sprd.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-sprd.c b/drivers/i2c/busses/i2c-sprd.c
> index b432e7580458..4eb3ad1e5ab5 100644
> --- a/drivers/i2c/busses/i2c-sprd.c
> +++ b/drivers/i2c/busses/i2c-sprd.c
> @@ -337,9 +337,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_FAST_MODE_FREQ)
>                 writel((6 * apb_clk) / 10000000, i2c_dev->base + ADDR_STA0_DVD);
> -       else if (freq == 100000)
> +       else if (freq == I2C_STANDARD_MODE_FREQ)
>                 writel((4 * apb_clk) / 1000000, i2c_dev->base + ADDR_STA0_DVD);
>  }
>
> @@ -502,7 +502,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_STANDARD_MODE_FREQ;
>         i2c_dev->adap.owner = THIS_MODULE;
>         i2c_dev->dev = dev;
>         i2c_dev->adap.retries = 3;
> @@ -516,7 +516,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_STANDARD_MODE_FREQ &&
> +           i2c_dev->bus_freq != I2C_FAST_MODE_FREQ)
>                 return -EINVAL;
>
>         ret = sprd_i2c_clk_init(i2c_dev);
> --
> 2.25.0
>

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 04/40] i2c: altera: Use generic definitions for bus frequencies
  2020-02-24 15:14 ` [PATCH v1 04/40] i2c: altera: " Andy Shevchenko
@ 2020-02-25  7:30   ` Jarkko Nikula
  0 siblings, 0 replies; 68+ messages in thread
From: Jarkko Nikula @ 2020-02-25  7:30 UTC (permalink / raw)
  To: Andy Shevchenko, Wolfram Sang, linux-i2c; +Cc: Thor Thayer

Hi

On 2/24/20 5:14 PM, Andy Shevchenko wrote:
> Since we have generic definitions for bus frequencies, let's use them.
> 
> Cc: Thor Thayer <thor.thayer@linux.intel.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>   drivers/i2c/busses/i2c-altera.c | 8 ++++----
>   include/linux/i2c.h             | 1 +
>   2 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-altera.c b/drivers/i2c/busses/i2c-altera.c
> index 5255d3755411..1f70bbd6e084 100644
> --- a/drivers/i2c/busses/i2c-altera.c
> +++ b/drivers/i2c/busses/i2c-altera.c
> @@ -142,12 +142,12 @@ static inline void altr_i2c_stop(struct altr_i2c_dev *idev)
>   static void altr_i2c_init(struct altr_i2c_dev *idev)
>   {
>   	u32 divisor = clk_get_rate(idev->i2c_clk) / idev->bus_clk_rate;
> -	u32 clk_mhz = clk_get_rate(idev->i2c_clk) / 1000000;
> +	u32 clk_mhz = clk_get_rate(idev->i2c_clk) / HZ_PER_MHZ;

IMHO these kind of defines don't improve readability in formulas. What 
is HZ_PER_MHZ? You have to go and grep it first in order to be sure. Of 
course it protects against typos like "100000" or "10000000" that are 
difficult to spot at quick look.

Better would be just "1MHz" or even better calc_something_MHz().

-- 
Jarkko

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 11/40] i2c: designware: Use generic definitions for bus frequencies
  2020-02-24 16:30   ` Mika Westerberg
@ 2020-02-25  7:30     ` Jarkko Nikula
  0 siblings, 0 replies; 68+ messages in thread
From: Jarkko Nikula @ 2020-02-25  7:30 UTC (permalink / raw)
  To: Mika Westerberg, Andy Shevchenko; +Cc: Wolfram Sang, linux-i2c

On 2/24/20 6:30 PM, Mika Westerberg wrote:
> On Mon, Feb 24, 2020 at 05:15:01PM +0200, Andy Shevchenko wrote:
>> Since we have generic definitions for bus frequencies, let's use them.
>>
>> Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
>> Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
> 
> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> 
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 18/40] i2c: imx: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 18/40] i2c: imx: " Andy Shevchenko
@ 2020-02-25  8:18   ` Oleksij Rempel
  0 siblings, 0 replies; 68+ messages in thread
From: Oleksij Rempel @ 2020-02-25  8:18 UTC (permalink / raw)
  To: Andy Shevchenko, Wolfram Sang, linux-i2c
  Cc: Oleksij Rempel, Shawn Guo, Sascha Hauer



On 24.02.20 16:15, Andy Shevchenko wrote:
> Since we have generic definitions for bus frequencies, let's use them.
> 
> Cc: Oleksij Rempel <linux@rempel-privat.de>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>

> ---
>   drivers/i2c/busses/i2c-imx.c | 5 +----
>   1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index a3b61336fe55..f5ed0f38904c 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.\
> @@ -1139,7 +1136,7 @@ static int i2c_imx_probe(struct platform_device *pdev)
>   		goto rpm_disable;
>   
>   	/* Set up clock divider */
> -	i2c_imx->bitrate = IMX_I2C_BIT_RATE;
> +	i2c_imx->bitrate = I2C_STANDARD_MODE_FREQ;
>   	ret = of_property_read_u32(pdev->dev.of_node,
>   				   "clock-frequency", &i2c_imx->bitrate);
>   	if (ret < 0 && pdata && pdata->bitrate)
> 

Kind regards,
Oleksij Rempel

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h
  2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
                   ` (38 preceding siblings ...)
  2020-02-24 15:15 ` [PATCH v1 40/40] i2c: xlp9xx: " Andy Shevchenko
@ 2020-02-25 10:22 ` Wolfram Sang
  2020-02-25 10:47   ` Andy Shevchenko
  39 siblings, 1 reply; 68+ messages in thread
From: Wolfram Sang @ 2020-02-25 10:22 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-i2c, Andy Gross, Bjorn Andersson

[-- Attachment #1: Type: text/plain, Size: 1545 bytes --]

Hi Andy,

On Mon, Feb 24, 2020 at 05:14:51PM +0200, Andy Shevchenko wrote:
> Move bus frequency definitions to i2c.h for wider use.
> 
> Cc: Andy Gross <agross@kernel.org>
> Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

A cover letter would have been nice so we could discuss the general
appraoch there. And to read more about the motivation.

> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -39,6 +39,13 @@ enum i2c_slave_event;
>  typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
>  			      enum i2c_slave_event event, u8 *val);
>  
> +#define HZ_PER_KHZ			1000

Unlike Jarkko, I think such macros help readability when calculating
frequencies within drivers. However, they shouldn't be local to I2C if
we agree on them. They should be available Linux-wide. There are some
other (few) local implementations already.

> +
> +/* I2C Frequency Modes */
> +#define I2C_STANDARD_MODE_FREQ		(100 * HZ_PER_KHZ)
> +#define I2C_FAST_MODE_FREQ		(400 * HZ_PER_KHZ)
> +#define I2C_FAST_MODE_PLUS_FREQ		(1000 * HZ_PER_KHZ)

For such a header, I'd prefer the plain number, though. There will be
enough review to make sure we get it right ;) Furthermore, I'd prefer to
have 'MAX' in there, e.g. I2C_MAX_STANDARD_MODE_FREQ etc. Just to make
clear that I2C can have other bus speeds as well.

And finally, I'd think all driver patches should be squashed into one,
and all core ones into one etc. Or?

Thanks,

   Wolfram


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 31/40] i2c: spdr: Use generic definitions for bus frequencies
  2020-02-25  0:49   ` Baolin Wang
@ 2020-02-25 10:38     ` Andy Shevchenko
  0 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-25 10:38 UTC (permalink / raw)
  To: Baolin Wang; +Cc: Wolfram Sang, linux-i2c, Orson Zhai, Chunyan Zhang

On Tue, Feb 25, 2020 at 08:49:24AM +0800, Baolin Wang wrote:
> On Mon, Feb 24, 2020 at 11:15 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > Since we have generic definitions for bus frequencies, let's use them.
> >
> > Cc: Orson Zhai <orsonzhai@gmail.com>
> > Cc: Baolin Wang <baolin.wang7@gmail.com>
> > Cc: Chunyan Zhang <zhang.lyra@gmail.com>
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Can you fix the typo in the subject line by changing 'spdr' to 'sprd'?

Sure.

> Otherwise looks good to me. Thanks.
> Reviewed-by: Baolin Wang <baolin.wang7@gmail.com>

Thanks!

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h
  2020-02-25 10:22 ` [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Wolfram Sang
@ 2020-02-25 10:47   ` Andy Shevchenko
  2020-02-25 11:44     ` Wolfram Sang
  0 siblings, 1 reply; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-25 10:47 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c, Andy Gross, Bjorn Andersson

On Tue, Feb 25, 2020 at 11:22:33AM +0100, Wolfram Sang wrote:
> On Mon, Feb 24, 2020 at 05:14:51PM +0200, Andy Shevchenko wrote:
> > Move bus frequency definitions to i2c.h for wider use.
> > 
> > Cc: Andy Gross <agross@kernel.org>
> > Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> A cover letter would have been nice so we could discuss the general
> appraoch there. And to read more about the motivation.

Motivation is simple:
 - Standardize the (small) set of mostly used bus frequences
 - Get rid of repetition of (subset) of above in many drivers
 - Reduce amount of potential typos

Let's discuss it here. I don't think new version of this would be good to have
without initial settlement.

> > --- a/include/linux/i2c.h
> > +++ b/include/linux/i2c.h
> > @@ -39,6 +39,13 @@ enum i2c_slave_event;
> >  typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
> >  			      enum i2c_slave_event event, u8 *val);
> >  
> > +#define HZ_PER_KHZ			1000
> 
> Unlike Jarkko, I think such macros help readability when calculating
> frequencies within drivers. However, they shouldn't be local to I2C if
> we agree on them. They should be available Linux-wide. There are some
> other (few) local implementations already.

I aware about that, but I would like to avoid I²C subsystem storming for
another change like this. So, let's consider this as a trampoline when in the
future we will switch entire subsystem to Linux wide header at once.

We have already same/similar definitions in the other drivers and I really
would like to avoid cross subsystem collisions.

> > +/* I2C Frequency Modes */
> > +#define I2C_STANDARD_MODE_FREQ		(100 * HZ_PER_KHZ)
> > +#define I2C_FAST_MODE_FREQ		(400 * HZ_PER_KHZ)
> > +#define I2C_FAST_MODE_PLUS_FREQ		(1000 * HZ_PER_KHZ)
> 
> For such a header, I'd prefer the plain number, though. There will be
> enough review to make sure we get it right ;)

No problem. I'm fine with either.

> Furthermore, I'd prefer to
> have 'MAX' in there, e.g. I2C_MAX_STANDARD_MODE_FREQ etc. Just to make
> clear that I2C can have other bus speeds as well.

Works for me.

Btw, what about Vladimir's comment WRT STANDARD -> STD? My personal opinion
that STD is a bit too short.

> And finally, I'd think all driver patches should be squashed into one,
> and all core ones into one etc. Or?

I'm fine with either. For reviewers it would be better I think to see only
their portion. Since I got a lot of tags already I consider I may squash it
together. So, what do you prefer?

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h
  2020-02-25 10:47   ` Andy Shevchenko
@ 2020-02-25 11:44     ` Wolfram Sang
  2020-02-25 11:56       ` Andy Shevchenko
  0 siblings, 1 reply; 68+ messages in thread
From: Wolfram Sang @ 2020-02-25 11:44 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-i2c, Andy Gross, Bjorn Andersson

[-- Attachment #1: Type: text/plain, Size: 1570 bytes --]

Hi Andy,

> Motivation is simple:
>  - Standardize the (small) set of mostly used bus frequences
>  - Get rid of repetition of (subset) of above in many drivers
>  - Reduce amount of potential typos
> 
> Let's discuss it here. I don't think new version of this would be good to have
> without initial settlement.

Well, for me, this works. I agree to the typo thing and having less
magic values. It's all OK; I think it is just nice to have some things
in a coverletter.

> I aware about that, but I would like to avoid I²C subsystem storming for
> another change like this. So, let's consider this as a trampoline when in the
> future we will switch entire subsystem to Linux wide header at once.

I can agree to that.

> > Furthermore, I'd prefer to
> > have 'MAX' in there, e.g. I2C_MAX_STANDARD_MODE_FREQ etc. Just to make
> > clear that I2C can have other bus speeds as well.
> 
> Works for me.

Thanks, that's the most important point to me.

> Btw, what about Vladimir's comment WRT STANDARD -> STD? My personal opinion
> that STD is a bit too short.

No real opinion here. I think STD is understandable enough and I
encounter it regularly. However, I also don't think the saving is huge
enough to matter. Your call here.

> I'm fine with either. For reviewers it would be better I think to see only
> their portion. Since I got a lot of tags already I consider I may squash it
> together. So, what do you prefer?

Sounds good to me. Keep collecting acks and squash all patches and tags
in v2.

Thanks,

   Wolfram


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h
  2020-02-25 11:44     ` Wolfram Sang
@ 2020-02-25 11:56       ` Andy Shevchenko
  0 siblings, 0 replies; 68+ messages in thread
From: Andy Shevchenko @ 2020-02-25 11:56 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c, Andy Gross, Bjorn Andersson

On Tue, Feb 25, 2020 at 12:44:01PM +0100, Wolfram Sang wrote:
> > Motivation is simple:
> >  - Standardize the (small) set of mostly used bus frequences
> >  - Get rid of repetition of (subset) of above in many drivers
> >  - Reduce amount of potential typos
> > 
> > Let's discuss it here. I don't think new version of this would be good to have
> > without initial settlement.
> 
> Well, for me, this works. I agree to the typo thing and having less
> magic values. It's all OK; I think it is just nice to have some things
> in a coverletter.

Since it looks like we will have only few patches at the end, I think the
commit message for the first one would be good enough to describe this all.

> > I aware about that, but I would like to avoid I²C subsystem storming for
> > another change like this. So, let's consider this as a trampoline when in the
> > future we will switch entire subsystem to Linux wide header at once.
> 
> I can agree to that.
> 
> > > Furthermore, I'd prefer to
> > > have 'MAX' in there, e.g. I2C_MAX_STANDARD_MODE_FREQ etc. Just to make
> > > clear that I2C can have other bus speeds as well.
> > 
> > Works for me.
> 
> Thanks, that's the most important point to me.
> 
> > Btw, what about Vladimir's comment WRT STANDARD -> STD? My personal opinion
> > that STD is a bit too short.
> 
> No real opinion here. I think STD is understandable enough and I
> encounter it regularly. However, I also don't think the saving is huge
> enough to matter. Your call here.

I prefer STANDARD over STD due to consistency (we don't have good abbreviations
for Fast, Fast+, High Speed, etc, anyway).

> > I'm fine with either. For reviewers it would be better I think to see only
> > their portion. Since I got a lot of tags already I consider I may squash it
> > together. So, what do you prefer?
> 
> Sounds good to me. Keep collecting acks and squash all patches and tags
> in v2.

Good, thanks for review!

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 13/40] i2c: diolan-u2c: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 13/40] i2c: diolan-u2c: " Andy Shevchenko
@ 2020-02-25 17:36   ` Guenter Roeck
  0 siblings, 0 replies; 68+ messages in thread
From: Guenter Roeck @ 2020-02-25 17:36 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Wolfram Sang, linux-i2c

On Mon, Feb 24, 2020 at 05:15:03PM +0200, Andy Shevchenko wrote:
> Since we have generic definitions for bus frequencies, let's use them.
> 
> Cc: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/i2c/busses/i2c-diolan-u2c.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
> index 382f105e0fe3..9ac79547d30b 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_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_STANDARD_MODE_FREQ) {
>  		speed = U2C_I2C_SPEED_FAST;
> -		frequency = U2C_I2C_FREQ_FAST;
> -	} else if (frequency >= 100000 || frequency == 0) {
> +		frequency = I2C_FAST_MODE_FREQ;
> +	} else if (frequency >= I2C_STANDARD_MODE_FREQ || frequency == 0) {
>  		speed = U2C_I2C_SPEED_STD;
> -		frequency = U2C_I2C_FREQ_STD;
> +		frequency = I2C_STANDARD_MODE_FREQ;
>  	} else {
>  		speed = U2C_I2C_SPEED(frequency);
>  		if (speed > U2C_I2C_SPEED_2KHZ)
> -- 
> 2.25.0
> 

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 23/40] i2c: nomadik: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 23/40] i2c: nomadik: " Andy Shevchenko
@ 2020-02-25 21:57   ` Linus Walleij
  0 siblings, 0 replies; 68+ messages in thread
From: Linus Walleij @ 2020-02-25 21:57 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Wolfram Sang, linux-i2c

On Mon, Feb 24, 2020 at 4:15 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> Since we have generic definitions for bus frequencies, let's use them.
>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Neat!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 34/40] i2c: stu300: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 34/40] i2c: stu300: " Andy Shevchenko
@ 2020-02-25 21:57   ` Linus Walleij
  0 siblings, 0 replies; 68+ messages in thread
From: Linus Walleij @ 2020-02-25 21:57 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Wolfram Sang, linux-i2c

On Mon, Feb 24, 2020 at 4:15 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> Since we have generic definitions for bus frequencies, let's use them.
>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 06/40] i2c: aspeed: Use generic definitions for bus frequencies
  2020-02-24 15:14 ` [PATCH v1 06/40] i2c: aspeed: " Andy Shevchenko
@ 2020-02-26  3:54   ` Brendan Higgins
  0 siblings, 0 replies; 68+ messages in thread
From: Brendan Higgins @ 2020-02-26  3:54 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Wolfram Sang, linux-i2c

On Mon, Feb 24, 2020 at 7:15 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Since we have generic definitions for bus frequencies, let's use them.
>
> Cc: Brendan Higgins <brendanhiggins@google.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Brendan Higgins <brendanhiggins@google.com>

Thanks!

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 05/40] i2c: amd-mp2: Use generic definitions for bus frequencies
  2020-02-24 15:14 ` [PATCH v1 05/40] i2c: amd-mp2: " Andy Shevchenko
@ 2020-02-26 17:58   ` Elie Morisse
  2020-02-27  5:06   ` Shah, Nehal-bakulchandra
  1 sibling, 0 replies; 68+ messages in thread
From: Elie Morisse @ 2020-02-26 17:58 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Wolfram Sang, linux-i2c, Nehal Shah, Shyam Sundar S K

Le lun. 24 févr. 2020 à 12:15, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> a écrit :
>
> Since we have generic definitions for bus frequencies, let's use them.
>
> Cc: Elie Morisse <syniurge@gmail.com>
> Cc: Nehal Shah <nehal-bakulchandra.shah@amd.com>
> Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/i2c/busses/i2c-amd-mp2-plat.c | 27 ++++++++++++++++-----------
>  include/linux/i2c.h                   |  2 ++
>  2 files changed, 18 insertions(+), 11 deletions(-)

Looks good to me.

Acked-by: Elie Morisse <syniurge@gmail.com>

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 05/40] i2c: amd-mp2: Use generic definitions for bus frequencies
  2020-02-24 15:14 ` [PATCH v1 05/40] i2c: amd-mp2: " Andy Shevchenko
  2020-02-26 17:58   ` Elie Morisse
@ 2020-02-27  5:06   ` Shah, Nehal-bakulchandra
  1 sibling, 0 replies; 68+ messages in thread
From: Shah, Nehal-bakulchandra @ 2020-02-27  5:06 UTC (permalink / raw)
  To: Andy Shevchenko, Wolfram Sang, linux-i2c; +Cc: Elie Morisse, Shyam Sundar S K

Hi

On 2/24/2020 8:44 PM, Andy Shevchenko wrote:
> Since we have generic definitions for bus frequencies, let's use them.
>
> Cc: Elie Morisse <syniurge@gmail.com>
> Cc: Nehal Shah <nehal-bakulchandra.shah@amd.com>
> Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/i2c/busses/i2c-amd-mp2-plat.c | 27 ++++++++++++++++-----------
>  include/linux/i2c.h                   |  2 ++
>  2 files changed, 18 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-amd-mp2-plat.c b/drivers/i2c/busses/i2c-amd-mp2-plat.c
> index f5b3f00c6559..9b9d90b98a05 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_HIGH_SPEED_MODE_FREQ,
> +	I2C_TURBO_MODE_FREQ,
> +	I2C_FAST_MODE_PLUS_FREQ,
> +	I2C_FAST_MODE_FREQ,
> +	I2C_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_STANDARD_MODE_FREQ:
>  		return speed100k;
> -	case 400000:
> +	case I2C_FAST_MODE_FREQ:
>  		return speed400k;
> -	case 1000000:
> +	case I2C_FAST_MODE_PLUS_FREQ:
>  		return speed1000k;
> -	case 1400000:
> +	case I2C_TURBO_MODE_FREQ:
>  		return speed1400k;
> -	case 3400000:
> +	case I2C_HIGH_SPEED_MODE_FREQ:
>  		return speed3400k;
>  	default:
>  		return speed400k;
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index 1b9c483bd9f5..d3022a014227 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -46,6 +46,8 @@ typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
>  #define I2C_STANDARD_MODE_FREQ		(100 * HZ_PER_KHZ)
>  #define I2C_FAST_MODE_FREQ		(400 * HZ_PER_KHZ)
>  #define I2C_FAST_MODE_PLUS_FREQ		(1000 * HZ_PER_KHZ)
> +#define I2C_TURBO_MODE_FREQ		(1400 * HZ_PER_KHZ)
> +#define I2C_HIGH_SPEED_MODE_FREQ	(3400 * HZ_PER_KHZ)
>  
>  struct module;
>  struct property_entry;

Fine for me.

Acked-by: Nehal Shah <nehal-bakulchandra.shah@amd.com>


Thanks

Nehal Shah

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 32/40] i2c: stm32f4: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 32/40] i2c: stm32f4: " Andy Shevchenko
@ 2020-03-02  8:39   ` Pierre Yves MORDRET
  0 siblings, 0 replies; 68+ messages in thread
From: Pierre Yves MORDRET @ 2020-03-02  8:39 UTC (permalink / raw)
  To: Andy Shevchenko, Wolfram Sang, linux-i2c
  Cc: Maxime Coquelin, Alexandre Torgue

Hi

Look good to me.

Reviewed-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>

Thanks

On 2/24/20 4:15 PM, Andy Shevchenko wrote:
> Since we have generic definitions for bus frequencies, let's use them.
> 
> Cc: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> Cc: Alexandre Torgue <alexandre.torgue@st.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/i2c/busses/i2c-stm32f4.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-stm32f4.c b/drivers/i2c/busses/i2c-stm32f4.c
> index ba600d77a3f8..0a67b44f2755 100644
> --- a/drivers/i2c/busses/i2c-stm32f4.c
> +++ b/drivers/i2c/busses/i2c-stm32f4.c
> @@ -91,7 +91,6 @@
>  #define STM32F4_I2C_MIN_STANDARD_FREQ	2U
>  #define STM32F4_I2C_MIN_FAST_FREQ	6U
>  #define STM32F4_I2C_MAX_FREQ		46U
> -#define HZ_TO_MHZ			1000000
>  
>  /**
>   * struct stm32f4_i2c_msg - client specific data
> @@ -154,7 +153,7 @@ static int stm32f4_i2c_set_periph_clk_freq(struct stm32f4_i2c_dev *i2c_dev)
>  	u32 cr2 = 0;
>  
>  	i2c_dev->parent_rate = clk_get_rate(i2c_dev->clk);
> -	freq = DIV_ROUND_UP(i2c_dev->parent_rate, HZ_TO_MHZ);
> +	freq = DIV_ROUND_UP(i2c_dev->parent_rate, HZ_PER_MHZ);
>  
>  	if (i2c_dev->speed == STM32_I2C_SPEED_STANDARD) {
>  		/*
> @@ -190,7 +189,7 @@ static int stm32f4_i2c_set_periph_clk_freq(struct stm32f4_i2c_dev *i2c_dev)
>  
>  static void stm32f4_i2c_set_rise_time(struct stm32f4_i2c_dev *i2c_dev)
>  {
> -	u32 freq = DIV_ROUND_UP(i2c_dev->parent_rate, HZ_TO_MHZ);
> +	u32 freq = DIV_ROUND_UP(i2c_dev->parent_rate, HZ_PER_MHZ);
>  	u32 trise;
>  
>  	/*
> @@ -243,7 +242,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_STANDARD_MODE_FREQ << 1);
>  	} else {
>  		/*
>  		 * In fast mode, we compute CCR with duty = 0 as with low
> @@ -263,7 +262,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_FAST_MODE_FREQ * 3);
>  
>  		/* Select Fast mode */
>  		ccr |= STM32F4_I2C_CCR_FS;
> @@ -807,7 +806,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_FAST_MODE_FREQ)
>  		i2c_dev->speed = STM32_I2C_SPEED_FAST;
>  
>  	i2c_dev->dev = &pdev->dev;
> 

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 33/40] i2c: stm32f7: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 33/40] i2c: stm32f7: " Andy Shevchenko
@ 2020-03-02  8:40   ` Pierre Yves MORDRET
  0 siblings, 0 replies; 68+ messages in thread
From: Pierre Yves MORDRET @ 2020-03-02  8:40 UTC (permalink / raw)
  To: Andy Shevchenko, Wolfram Sang, linux-i2c
  Cc: Maxime Coquelin, Alexandre Torgue

Hi

Look good to me.

Reviewed-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>

Thanks

On 2/24/20 4:15 PM, Andy Shevchenko wrote:
> Since we have generic definitions for bus frequencies, let's use them.
> 
> Cc: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> Cc: Alexandre Torgue <alexandre.torgue@st.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/i2c/busses/i2c-stm32f7.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
> index 5c3e8ac6ad92..9af5733ed513 100644
> --- a/drivers/i2c/busses/i2c-stm32f7.c
> +++ b/drivers/i2c/busses/i2c-stm32f7.c
> @@ -334,9 +334,9 @@ struct stm32f7_i2c_dev {
>   */
>  static struct stm32f7_i2c_spec i2c_specs[] = {
>  	[STM32_I2C_SPEED_STANDARD] = {
> -		.rate = 100000,
> -		.rate_min = 80000,
> -		.rate_max = 100000,
> +		.rate = I2C_STANDARD_MODE_FREQ,
> +		.rate_min = I2C_STANDARD_MODE_FREQ * 8 / 10,	/* 80% */
> +		.rate_max = I2C_STANDARD_MODE_FREQ,
>  		.fall_max = 300,
>  		.rise_max = 1000,
>  		.hddat_min = 0,
> @@ -346,9 +346,9 @@ static struct stm32f7_i2c_spec i2c_specs[] = {
>  		.h_min = 4000,
>  	},
>  	[STM32_I2C_SPEED_FAST] = {
> -		.rate = 400000,
> -		.rate_min = 320000,
> -		.rate_max = 400000,
> +		.rate = I2C_FAST_MODE_FREQ,
> +		.rate_min = I2C_FAST_MODE_FREQ * 8 / 10,	/* 80% */
> +		.rate_max = I2C_FAST_MODE_FREQ,
>  		.fall_max = 300,
>  		.rise_max = 300,
>  		.hddat_min = 0,
> @@ -358,9 +358,9 @@ static struct stm32f7_i2c_spec i2c_specs[] = {
>  		.h_min = 600,
>  	},
>  	[STM32_I2C_SPEED_FAST_PLUS] = {
> -		.rate = 1000000,
> -		.rate_min = 800000,
> -		.rate_max = 1000000,
> +		.rate = I2C_FAST_MODE_PLUS_FREQ,
> +		.rate_min = I2C_FAST_MODE_PLUS_FREQ * 8 / 10,	/* 80% */
> +		.rate_max = I2C_FAST_MODE_PLUS_FREQ,
>  		.fall_max = 100,
>  		.rise_max = 120,
>  		.hddat_min = 0,
> @@ -1894,14 +1894,14 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
>  	i2c_dev->speed = STM32_I2C_SPEED_STANDARD;
>  	ret = device_property_read_u32(&pdev->dev, "clock-frequency",
>  				       &clk_rate);
> -	if (!ret && clk_rate >= 1000000) {
> +	if (!ret && clk_rate >= I2C_FAST_MODE_PLUS_FREQ) {
>  		i2c_dev->speed = STM32_I2C_SPEED_FAST_PLUS;
>  		ret = stm32f7_i2c_setup_fm_plus_bits(pdev, i2c_dev);
>  		if (ret)
>  			goto clk_free;
> -	} else if (!ret && clk_rate >= 400000) {
> +	} else if (!ret && clk_rate >= I2C_FAST_MODE_FREQ) {
>  		i2c_dev->speed = STM32_I2C_SPEED_FAST;
> -	} else if (!ret && clk_rate >= 100000) {
> +	} else if (!ret && clk_rate >= I2C_STANDARD_MODE_FREQ) {
>  		i2c_dev->speed = STM32_I2C_SPEED_STANDARD;
>  	}
>  
> 

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH v1 21/40] i2c: mv64xxx: Use generic definitions for bus frequencies
  2020-02-24 15:15 ` [PATCH v1 21/40] i2c: mv64xxx: " Andy Shevchenko
@ 2020-03-13 20:28   ` Gregory CLEMENT
  0 siblings, 0 replies; 68+ messages in thread
From: Gregory CLEMENT @ 2020-03-13 20:28 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andy Shevchenko

Andy Shevchenko <andriy.shevchenko@linux.intel.com> writes:

> Since we have generic definitions for bus frequencies, let's use them.
>
> Cc: Gregory CLEMENT <gregory.clement@bootlin.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


Acked-by: Gregory CLEMENT <gregory.clement@bootlin.com>

Thanks,

Gregory


> ---
>  drivers/i2c/busses/i2c-mv64xxx.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
> index febb7c7ea72b..e803c6b0a947 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_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_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_STANDARD_MODE_FREQ)
>  			drv_data->errata_delay = true;
>  	}
>  
> -- 
> 2.25.0
>

-- 
Gregory Clement, Bootlin
Embedded Linux and Kernel engineering
http://bootlin.com

^ permalink raw reply	[flat|nested] 68+ messages in thread

end of thread, other threads:[~2020-03-13 20:28 UTC | newest]

Thread overview: 68+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-24 15:14 [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Andy Shevchenko
2020-02-24 15:14 ` [PATCH v1 02/40] i2c: algo: Use generic definitions for bus frequencies Andy Shevchenko
2020-02-24 15:14 ` [PATCH v1 03/40] i2c: core: " Andy Shevchenko
2020-02-24 16:28   ` Mika Westerberg
2020-02-24 15:14 ` [PATCH v1 04/40] i2c: altera: " Andy Shevchenko
2020-02-25  7:30   ` Jarkko Nikula
2020-02-24 15:14 ` [PATCH v1 05/40] i2c: amd-mp2: " Andy Shevchenko
2020-02-26 17:58   ` Elie Morisse
2020-02-27  5:06   ` Shah, Nehal-bakulchandra
2020-02-24 15:14 ` [PATCH v1 06/40] i2c: aspeed: " Andy Shevchenko
2020-02-26  3:54   ` Brendan Higgins
2020-02-24 15:14 ` [PATCH v1 07/40] i2c: axxia: " Andy Shevchenko
2020-02-24 15:14 ` [PATCH v1 08/40] i2c: bcm-iproc: " Andy Shevchenko
2020-02-24 17:29   ` Scott Branden
2020-02-24 15:14 ` [PATCH v1 09/40] i2c: bcm-kona: " Andy Shevchenko
2020-02-24 17:29   ` Scott Branden
2020-02-24 15:15 ` [PATCH v1 10/40] i2c: cadence: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 11/40] i2c: designware: " Andy Shevchenko
2020-02-24 16:30   ` Mika Westerberg
2020-02-25  7:30     ` Jarkko Nikula
2020-02-24 15:15 ` [PATCH v1 12/40] i2c: digicolor: " Andy Shevchenko
2020-02-24 18:25   ` Baruch Siach
2020-02-24 15:15 ` [PATCH v1 13/40] i2c: diolan-u2c: " Andy Shevchenko
2020-02-25 17:36   ` Guenter Roeck
2020-02-24 15:15 ` [PATCH v1 14/40] i2c: exynos5: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 15/40] i2c: hix5hd2: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 16/40] i2c: img-scb: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 17/40] i2c: imx-lpi2c: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 18/40] i2c: imx: " Andy Shevchenko
2020-02-25  8:18   ` Oleksij Rempel
2020-02-24 15:15 ` [PATCH v1 19/40] i2c: lpc2k: " Andy Shevchenko
2020-02-24 15:35   ` Vladimir Zapolskiy
2020-02-24 16:01     ` Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 20/40] i2c: mt65xx: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 21/40] i2c: mv64xxx: " Andy Shevchenko
2020-03-13 20:28   ` Gregory CLEMENT
2020-02-24 15:15 ` [PATCH v1 22/40] i2c: mxs: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 23/40] i2c: nomadik: " Andy Shevchenko
2020-02-25 21:57   ` Linus Walleij
2020-02-24 15:15 ` [PATCH v1 24/40] i2c: owl: " Andy Shevchenko
2020-02-24 15:27   ` Manivannan Sadhasivam
2020-02-24 15:15 ` [PATCH v1 25/40] i2c: rcar: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 26/40] i2c: riic: " Andy Shevchenko
2020-02-24 16:48   ` Chris Brandt
2020-02-24 15:15 ` [PATCH v1 27/40] i2c: rk3x: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 28/40] i2c: s3c2410: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 29/40] i2c: sh_mobile: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 30/40] i2c: sirf: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 31/40] i2c: spdr: " Andy Shevchenko
2020-02-25  0:49   ` Baolin Wang
2020-02-25 10:38     ` Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 32/40] i2c: stm32f4: " Andy Shevchenko
2020-03-02  8:39   ` Pierre Yves MORDRET
2020-02-24 15:15 ` [PATCH v1 33/40] i2c: stm32f7: " Andy Shevchenko
2020-03-02  8:40   ` Pierre Yves MORDRET
2020-02-24 15:15 ` [PATCH v1 34/40] i2c: stu300: " Andy Shevchenko
2020-02-25 21:57   ` Linus Walleij
2020-02-24 15:15 ` [PATCH v1 35/40] i2c: st: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 36/40] i2c: synquacer: " Andy Shevchenko
2020-02-24 15:18   ` Ard Biesheuvel
2020-02-24 15:15 ` [PATCH v1 37/40] i2c: tegra: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 38/40] i2c: uniphier-f: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 39/40] i2c: uniphier: " Andy Shevchenko
2020-02-24 15:15 ` [PATCH v1 40/40] i2c: xlp9xx: " Andy Shevchenko
2020-02-25 10:22 ` [PATCH v1 01/40] i2c: qup: Move bus frequency definitions to i2c.h Wolfram Sang
2020-02-25 10:47   ` Andy Shevchenko
2020-02-25 11:44     ` Wolfram Sang
2020-02-25 11:56       ` Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.