linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Wolfram Sang <wsa@the-dreams.de>, linux-i2c@vger.kernel.org
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Jarkko Nikula <jarkko.nikula@linux.intel.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [PATCH v1 11/40] i2c: designware: Use generic definitions for bus frequencies
Date: Mon, 24 Feb 2020 17:15:01 +0200	[thread overview]
Message-ID: <20200224151530.31713-11-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20200224151530.31713-1-andriy.shevchenko@linux.intel.com>

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

  parent reply	other threads:[~2020-02-24 15:15 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Andy Shevchenko [this message]
2020-02-24 16:30   ` [PATCH v1 11/40] i2c: designware: " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200224151530.31713-11-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).