public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: designware: Fix bus speed in !CONFIG_ACPI case
@ 2020-06-23  8:31 Jarkko Nikula
  2020-06-23  8:46 ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Jarkko Nikula @ 2020-06-23  8:31 UTC (permalink / raw)
  To: linux-i2c; +Cc: Wolfram Sang, John Stultz, Andy Shevchenko, Jarkko Nikula

John Stultz reported that commit f9288fcc5c615 ("i2c: designware: Move
ACPI parts into common module") caused a regression on the HiKey board
where adv7511 HDMI bridge driver wasn't probing anymore due the I2C bus
failed to start.

It seems the change caused the bus speed being zero when CONFIG_ACPI
not set and neither speed based on "clock-frequency" device property or
default fast mode is set.

Fix this by moving bus speed setting back to dw_i2c_plat_probe() and let
the i2c_dw_acpi_adjust_bus_speed() adjust only speed from ACPI.

Fixes: f9288fcc5c615 ("i2c: designware: Move ACPI parts into common module")
Reported-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
Hi John. Would this fix the issue you are seeing?
---
 drivers/i2c/busses/i2c-designware-common.c  | 17 ++---------------
 drivers/i2c/busses/i2c-designware-core.h    |  4 ++--
 drivers/i2c/busses/i2c-designware-platdrv.c | 13 ++++++++++++-
 3 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c
index e3a8640db7da..ee86efe94f7f 100644
--- a/drivers/i2c/busses/i2c-designware-common.c
+++ b/drivers/i2c/busses/i2c-designware-common.c
@@ -286,10 +286,8 @@ int i2c_dw_acpi_configure(struct device *device)
 }
 EXPORT_SYMBOL_GPL(i2c_dw_acpi_configure);
 
-void i2c_dw_acpi_adjust_bus_speed(struct device *device)
+u32 i2c_dw_acpi_adjust_bus_speed(struct device *device)
 {
-	struct dw_i2c_dev *dev = dev_get_drvdata(device);
-	struct i2c_timings *t = &dev->timings;
 	u32 acpi_speed;
 	int i;
 
@@ -302,18 +300,7 @@ void i2c_dw_acpi_adjust_bus_speed(struct device *device)
 		if (acpi_speed >= supported_speeds[i])
 			break;
 	}
-	acpi_speed = i < ARRAY_SIZE(supported_speeds) ? supported_speeds[i] : 0;
-
-	/*
-	 * Find bus speed from the "clock-frequency" device property, ACPI
-	 * or by using fast mode if neither is set.
-	 */
-	if (acpi_speed && t->bus_freq_hz)
-		t->bus_freq_hz = min(t->bus_freq_hz, acpi_speed);
-	else if (acpi_speed || t->bus_freq_hz)
-		t->bus_freq_hz = max(t->bus_freq_hz, acpi_speed);
-	else
-		t->bus_freq_hz = I2C_MAX_FAST_MODE_FREQ;
+	return (i < ARRAY_SIZE(supported_speeds) ? supported_speeds[i] : 0);
 }
 EXPORT_SYMBOL_GPL(i2c_dw_acpi_adjust_bus_speed);
 
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 556673a1f61b..2f1e72d07194 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -364,8 +364,8 @@ int i2c_dw_validate_speed(struct dw_i2c_dev *dev);
 
 #if IS_ENABLED(CONFIG_ACPI)
 int i2c_dw_acpi_configure(struct device *device);
-void i2c_dw_acpi_adjust_bus_speed(struct device *device);
+u32 i2c_dw_acpi_adjust_bus_speed(struct device *device);
 #else
 static inline int i2c_dw_acpi_configure(struct device *device) { return -ENODEV; }
-static inline void i2c_dw_acpi_adjust_bus_speed(struct device *device) {}
+static inline u32 i2c_dw_acpi_adjust_bus_speed(struct device *device) { return 0; }
 #endif
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index 0de4e302fc6a..b53aa91e64dc 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -197,6 +197,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
 	struct i2c_adapter *adap;
 	struct dw_i2c_dev *dev;
 	struct i2c_timings *t;
+	u32 acpi_speed;
 	int irq, ret;
 
 	irq = platform_get_irq(pdev, 0);
@@ -228,7 +229,17 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
 	else
 		i2c_parse_fw_timings(&pdev->dev, t, false);
 
-	i2c_dw_acpi_adjust_bus_speed(&pdev->dev);
+	acpi_speed = i2c_dw_acpi_adjust_bus_speed(&pdev->dev);
+	/*
+	 * Find bus speed from the "clock-frequency" device property, ACPI
+	 * or by using fast mode if neither is set.
+	 */
+	if (acpi_speed && t->bus_freq_hz)
+		t->bus_freq_hz = min(t->bus_freq_hz, acpi_speed);
+	else if (acpi_speed || t->bus_freq_hz)
+		t->bus_freq_hz = max(t->bus_freq_hz, acpi_speed);
+	else
+		t->bus_freq_hz = I2C_MAX_FAST_MODE_FREQ;
 
 	if (pdev->dev.of_node)
 		dw_i2c_of_configure(pdev);
-- 
2.27.0


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

* Re: [PATCH] i2c: designware: Fix bus speed in !CONFIG_ACPI case
  2020-06-23  8:31 [PATCH] i2c: designware: Fix bus speed in !CONFIG_ACPI case Jarkko Nikula
@ 2020-06-23  8:46 ` Andy Shevchenko
  2020-06-23  8:47   ` Andy Shevchenko
  2020-06-23  9:15   ` Andy Shevchenko
  0 siblings, 2 replies; 5+ messages in thread
From: Andy Shevchenko @ 2020-06-23  8:46 UTC (permalink / raw)
  To: Jarkko Nikula; +Cc: linux-i2c, Wolfram Sang, John Stultz

On Tue, Jun 23, 2020 at 11:31:13AM +0300, Jarkko Nikula wrote:
> John Stultz reported that commit f9288fcc5c615 ("i2c: designware: Move
> ACPI parts into common module") caused a regression on the HiKey board
> where adv7511 HDMI bridge driver wasn't probing anymore due the I2C bus
> failed to start.
> 
> It seems the change caused the bus speed being zero when CONFIG_ACPI
> not set and neither speed based on "clock-frequency" device property or
> default fast mode is set.
> 
> Fix this by moving bus speed setting back to dw_i2c_plat_probe() and let
> the i2c_dw_acpi_adjust_bus_speed() adjust only speed from ACPI.

I have slightly different idea, I'll send a patch soon after testing.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] i2c: designware: Fix bus speed in !CONFIG_ACPI case
  2020-06-23  8:46 ` Andy Shevchenko
@ 2020-06-23  8:47   ` Andy Shevchenko
  2020-06-23 10:47     ` Jarkko Nikula
  2020-06-23  9:15   ` Andy Shevchenko
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2020-06-23  8:47 UTC (permalink / raw)
  To: Jarkko Nikula; +Cc: linux-i2c, Wolfram Sang, John Stultz

On Tue, Jun 23, 2020 at 11:46:35AM +0300, Andy Shevchenko wrote:
> On Tue, Jun 23, 2020 at 11:31:13AM +0300, Jarkko Nikula wrote:
> > John Stultz reported that commit f9288fcc5c615 ("i2c: designware: Move
> > ACPI parts into common module") caused a regression on the HiKey board
> > where adv7511 HDMI bridge driver wasn't probing anymore due the I2C bus
> > failed to start.
> > 
> > It seems the change caused the bus speed being zero when CONFIG_ACPI
> > not set and neither speed based on "clock-frequency" device property or
> > default fast mode is set.
> > 
> > Fix this by moving bus speed setting back to dw_i2c_plat_probe() and let
> > the i2c_dw_acpi_adjust_bus_speed() adjust only speed from ACPI.
> 
> I have slightly different idea, I'll send a patch soon after testing.

Note, your patch breaks PCI case.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] i2c: designware: Fix bus speed in !CONFIG_ACPI case
  2020-06-23  8:46 ` Andy Shevchenko
  2020-06-23  8:47   ` Andy Shevchenko
@ 2020-06-23  9:15   ` Andy Shevchenko
  1 sibling, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2020-06-23  9:15 UTC (permalink / raw)
  To: Jarkko Nikula; +Cc: linux-i2c, Wolfram Sang, John Stultz

On Tue, Jun 23, 2020 at 11:46:35AM +0300, Andy Shevchenko wrote:
> On Tue, Jun 23, 2020 at 11:31:13AM +0300, Jarkko Nikula wrote:
> > John Stultz reported that commit f9288fcc5c615 ("i2c: designware: Move
> > ACPI parts into common module") caused a regression on the HiKey board
> > where adv7511 HDMI bridge driver wasn't probing anymore due the I2C bus
> > failed to start.
> > 
> > It seems the change caused the bus speed being zero when CONFIG_ACPI
> > not set and neither speed based on "clock-frequency" device property or
> > default fast mode is set.
> > 
> > Fix this by moving bus speed setting back to dw_i2c_plat_probe() and let
> > the i2c_dw_acpi_adjust_bus_speed() adjust only speed from ACPI.
> 
> I have slightly different idea, I'll send a patch soon after testing.

Just sent a patch. Please, review.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] i2c: designware: Fix bus speed in !CONFIG_ACPI case
  2020-06-23  8:47   ` Andy Shevchenko
@ 2020-06-23 10:47     ` Jarkko Nikula
  0 siblings, 0 replies; 5+ messages in thread
From: Jarkko Nikula @ 2020-06-23 10:47 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-i2c, Wolfram Sang, John Stultz

On 6/23/20 11:47 AM, Andy Shevchenko wrote:
> On Tue, Jun 23, 2020 at 11:46:35AM +0300, Andy Shevchenko wrote:
>> On Tue, Jun 23, 2020 at 11:31:13AM +0300, Jarkko Nikula wrote:
>>> John Stultz reported that commit f9288fcc5c615 ("i2c: designware: Move
>>> ACPI parts into common module") caused a regression on the HiKey board
>>> where adv7511 HDMI bridge driver wasn't probing anymore due the I2C bus
>>> failed to start.
>>>
>>> It seems the change caused the bus speed being zero when CONFIG_ACPI
>>> not set and neither speed based on "clock-frequency" device property or
>>> default fast mode is set.
>>>
>>> Fix this by moving bus speed setting back to dw_i2c_plat_probe() and let
>>> the i2c_dw_acpi_adjust_bus_speed() adjust only speed from ACPI.
>>
>> I have slightly different idea, I'll send a patch soon after testing.
> 
> Note, your patch breaks PCI case.
> 
Ah, indeed. So please ignore my patch.

-- 
Jarkko

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

end of thread, other threads:[~2020-06-23 10:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-23  8:31 [PATCH] i2c: designware: Fix bus speed in !CONFIG_ACPI case Jarkko Nikula
2020-06-23  8:46 ` Andy Shevchenko
2020-06-23  8:47   ` Andy Shevchenko
2020-06-23 10:47     ` Jarkko Nikula
2020-06-23  9:15   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox