Skip to content

Commit

Permalink
i2c: tegra: Restore pinmux on system resume
Browse files Browse the repository at this point in the history
Depending on the board design, the I2C controllers found on Tegra SoCs
may require pinmuxing in order to function. This is done as part of the
driver's runtime suspend/resume operations. However, the PM core does
not allow devices to go into runtime suspend during system sleep to
avoid potential races with the suspend/resume of their parents.

As a result of this, when Tegra SoCs resume from system suspend, their
I2C controllers may have lost the pinmux state in hardware, whereas the
pinctrl subsystem is not aware of this. To fix this, make sure that if
the I2C controller is not runtime suspended, the runtime suspend code is
still executed in order to disable the module clock (which we don't need
to be enabled during sleep) and set the pinmux to the idle state.

Conversely, make sure that the I2C controller is properly resumed when
waking up from sleep so that pinmux settings are properly restored.

This fixes a bug seen with DDC transactions to an HDMI monitor timing
out when resuming from system suspend.

Signed-off-by: Thierry Reding <treding@nvidia.com>
  • Loading branch information
thierryreding committed May 8, 2020
1 parent 78ad734 commit 44c9990
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions drivers/i2c/busses/i2c-tegra.c
Expand Up @@ -1769,17 +1769,25 @@ static int tegra_i2c_remove(struct platform_device *pdev)
static int __maybe_unused tegra_i2c_suspend(struct device *dev)
{
struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
int err = 0;

i2c_mark_adapter_suspended(&i2c_dev->adapter);

return 0;
if (!pm_runtime_status_suspended(dev))
err = tegra_i2c_runtime_suspend(dev);

return err;
}

static int __maybe_unused tegra_i2c_resume(struct device *dev)
{
struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
int err;

/*
* We need to ensure that clocks are enabled so that registers can be
* restored in tegra_i2c_init().
*/
err = tegra_i2c_runtime_resume(dev);
if (err)
return err;
Expand All @@ -1788,9 +1796,16 @@ static int __maybe_unused tegra_i2c_resume(struct device *dev)
if (err)
return err;

err = tegra_i2c_runtime_suspend(dev);
if (err)
return err;
/*
* In case we are runtime suspended, disable clocks again so that we
* don't unbalance the clock reference counts during the next runtime
* resume transition.
*/
if (pm_runtime_status_suspended(dev)) {
err = tegra_i2c_runtime_suspend(dev);
if (err)
return err;
}

i2c_mark_adapter_resumed(&i2c_dev->adapter);

Expand Down

0 comments on commit 44c9990

Please sign in to comment.