2020-01-06 01:07:41

by Dmitry Osipenko

[permalink] [raw]
Subject: [PATCH v3 0/9] NVIDIA Tegra I2C driver fixes and improvements

Hello,

This patchset adds support for atomic transfers which are required for
shutting down machine properly. Secondly, a (not)suspending I2C and some
other things are fixed/improved by this small series as well. Please review
and apply, thanks in advance!

Changelog:

v3: The "Prevent interrupt triggering after transfer timeout" and "Support
atomic transfers" patches got extra very minor improvements. The
completion now is passed directly to tegra_i2c_poll_completion_timeout(),
for consistency.

Added two new patches that firm up DMA transfer handling:

i2c: tegra: Always terminate DMA transfer
i2c: tegra: Check DMA completion status in addition to left time

v2: The series is renamed from "Tegra I2C: Support atomic transfers and
correct suspend/resume" to "NVIDIA Tegra I2C driver fixes and
improvements" because it now contains some more various changes.

New patches in v2:

i2c: tegra: Correct unwinding order on driver's probe error
i2c: tegra: Prevent interrupt triggering after transfer timeout
i2c: tegra: Use relaxed versions of readl/writel

The "Rename I2C_PIO_MODE_MAX_LEN to I2C_PIO_MODE_PREFERRED_LEN" got an
improved wording for the code's comment to I2C_PIO_MODE_PREFERRED_LEN.

The "Support atomic transfers" also got some very minor tuning, like
s/in_interrupt()/i2c_dev->is_curr_atomic_xfer/ in dvc_writel() that was
missed in v1.

v1: The "i2c: tegra: Support atomic transfers" previously was sent out as
a separate patch, but later I spotted that suspend/resume doesn't
work properly. The "i2c: tegra: Fix suspending in active runtime PM
state" patch depends on the atomic patch because there is a need to
active IRQ-safe mode for the runtime PM by both patches.

I fixed a missed doc-comment of the newly added "is_curr_atomic_xfer"
structure field and added additional comment that explains why IRQ needs
to be disabled for the atomic transfer in the "Support atomic transfers"
patch.

Lastly, I added a minor "i2c: tegra: Rename .." patch that helps to
follow driver's code.

Dmitry Osipenko (9):
i2c: tegra: Fix suspending in active runtime PM state
i2c: tegra: Properly disable runtime PM on driver's probe error
i2c: tegra: Prevent interrupt triggering after transfer timeout
i2c: tegra: Support atomic transfers
i2c: tegra: Rename I2C_PIO_MODE_MAX_LEN to I2C_PIO_MODE_PREFERRED_LEN
i2c: tegra: Use relaxed versions of readl/writel
clk: tegra: Fix double-free in tegra_clk_init()
i2c: tegra: Always terminate DMA transfer
i2c: tegra: Check DMA completion status in addition to left time

drivers/clk/tegra/clk.c | 4 +-
drivers/i2c/busses/i2c-tegra.c | 216 ++++++++++++++++++++++-----------
2 files changed, 147 insertions(+), 73 deletions(-)

--
2.24.0


2020-01-06 01:07:55

by Dmitry Osipenko

[permalink] [raw]
Subject: [PATCH v3 6/9] i2c: tegra: Use relaxed versions of readl/writel

There is nothing to synchronize in regards to memory accesses for PIO
transfers and for DMA transfers the DMA API takes care of the syncing.

Signed-off-by: Dmitry Osipenko <[email protected]>
---
drivers/i2c/busses/i2c-tegra.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index e0eb8f5dcd6b..1a390e1bff72 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -284,12 +284,12 @@ struct tegra_i2c_dev {
static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val,
unsigned long reg)
{
- writel(val, i2c_dev->base + reg);
+ writel_relaxed(val, i2c_dev->base + reg);
}

static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg)
{
- return readl(i2c_dev->base + reg);
+ return readl_relaxed(i2c_dev->base + reg);
}

/*
@@ -307,16 +307,16 @@ static unsigned long tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev,
static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val,
unsigned long reg)
{
- writel(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
+ writel_relaxed(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));

/* Read back register to make sure that register writes completed */
if (reg != I2C_TX_FIFO)
- readl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
+ readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
}

static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg)
{
- return readl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
+ return readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
}

static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data,
@@ -689,12 +689,13 @@ static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev)
i2c_writel(i2c_dev, I2C_MSTR_CONFIG_LOAD, I2C_CONFIG_LOAD);

if (i2c_dev->is_curr_atomic_xfer)
- err = readl_poll_timeout_atomic(addr, val, val == 0,
- 1000,
- I2C_CONFIG_LOAD_TIMEOUT);
+ err = readl_relaxed_poll_timeout_atomic(
+ addr, val, val == 0, 1000,
+ I2C_CONFIG_LOAD_TIMEOUT);
else
- err = readl_poll_timeout(addr, val, val == 0, 1000,
- I2C_CONFIG_LOAD_TIMEOUT);
+ err = readl_relaxed_poll_timeout(
+ addr, val, val == 0, 1000,
+ I2C_CONFIG_LOAD_TIMEOUT);

if (err) {
dev_warn(i2c_dev->dev,
--
2.24.0

2020-01-07 12:39:54

by Thierry Reding

[permalink] [raw]
Subject: Re: [PATCH v3 0/9] NVIDIA Tegra I2C driver fixes and improvements

On Mon, Jan 06, 2020 at 04:04:14AM +0300, Dmitry Osipenko wrote:
> Hello,
>
> This patchset adds support for atomic transfers which are required for
> shutting down machine properly. Secondly, a (not)suspending I2C and some
> other things are fixed/improved by this small series as well. Please review
> and apply, thanks in advance!
>
> Changelog:
>
> v3: The "Prevent interrupt triggering after transfer timeout" and "Support
> atomic transfers" patches got extra very minor improvements. The
> completion now is passed directly to tegra_i2c_poll_completion_timeout(),
> for consistency.
>
> Added two new patches that firm up DMA transfer handling:
>
> i2c: tegra: Always terminate DMA transfer
> i2c: tegra: Check DMA completion status in addition to left time
>
> v2: The series is renamed from "Tegra I2C: Support atomic transfers and
> correct suspend/resume" to "NVIDIA Tegra I2C driver fixes and
> improvements" because it now contains some more various changes.
>
> New patches in v2:
>
> i2c: tegra: Correct unwinding order on driver's probe error
> i2c: tegra: Prevent interrupt triggering after transfer timeout
> i2c: tegra: Use relaxed versions of readl/writel
>
> The "Rename I2C_PIO_MODE_MAX_LEN to I2C_PIO_MODE_PREFERRED_LEN" got an
> improved wording for the code's comment to I2C_PIO_MODE_PREFERRED_LEN.
>
> The "Support atomic transfers" also got some very minor tuning, like
> s/in_interrupt()/i2c_dev->is_curr_atomic_xfer/ in dvc_writel() that was
> missed in v1.
>
> v1: The "i2c: tegra: Support atomic transfers" previously was sent out as
> a separate patch, but later I spotted that suspend/resume doesn't
> work properly. The "i2c: tegra: Fix suspending in active runtime PM
> state" patch depends on the atomic patch because there is a need to
> active IRQ-safe mode for the runtime PM by both patches.
>
> I fixed a missed doc-comment of the newly added "is_curr_atomic_xfer"
> structure field and added additional comment that explains why IRQ needs
> to be disabled for the atomic transfer in the "Support atomic transfers"
> patch.
>
> Lastly, I added a minor "i2c: tegra: Rename .." patch that helps to
> follow driver's code.
>
> Dmitry Osipenko (9):
> i2c: tegra: Fix suspending in active runtime PM state
> i2c: tegra: Properly disable runtime PM on driver's probe error
> i2c: tegra: Prevent interrupt triggering after transfer timeout
> i2c: tegra: Support atomic transfers
> i2c: tegra: Rename I2C_PIO_MODE_MAX_LEN to I2C_PIO_MODE_PREFERRED_LEN
> i2c: tegra: Use relaxed versions of readl/writel
> clk: tegra: Fix double-free in tegra_clk_init()
> i2c: tegra: Always terminate DMA transfer
> i2c: tegra: Check DMA completion status in addition to left time
>
> drivers/clk/tegra/clk.c | 4 +-
> drivers/i2c/busses/i2c-tegra.c | 216 ++++++++++++++++++++++-----------
> 2 files changed, 147 insertions(+), 73 deletions(-)

I'm still a bit on the fence about that second patch because I don't
think force-suspend is the right thing to do.

You should probably split the clk subsystem patch out of this series so
that it can be picked up into the clk tree (or I can pick it up into the
Tegra tree).

Other than that, I ran this through the testfarm and didn't see any
regressions:

Test results:
13 builds: 13 pass, 0 fail
11 boots: 11 pass, 0 fail
38 tests: 38 pass, 0 fail

Linux version: 5.5.0-rc5-g258d134300af
Boards tested: tegra20-ventana, tegra30-cardhu-a04, tegra124-jetson-tk1,
tegra186-p2771-0000, tegra194-p2972-0000,
tegra210-p2371-2180

I'll reply to the individual patches with a Tested-by for patchwork to
pick up.

Thierry


Attachments:
(No filename) (3.81 kB)
signature.asc (849.00 B)
Download all attachments

2020-01-07 12:40:37

by Thierry Reding

[permalink] [raw]
Subject: Re: [PATCH v3 6/9] i2c: tegra: Use relaxed versions of readl/writel

On Mon, 06 Jan 2020 04:04:20 +0300, Dmitry Osipenko wrote:
> There is nothing to synchronize in regards to memory accesses for PIO
> transfers and for DMA transfers the DMA API takes care of the syncing.
>
> Signed-off-by: Dmitry Osipenko <[email protected]>
> ---
> drivers/i2c/busses/i2c-tegra.c | 21 +++++++++++----------
> 1 file changed, 11 insertions(+), 10 deletions(-)

Tested-by: Thierry Reding <[email protected]>

2020-01-07 16:40:53

by Dmitry Osipenko

[permalink] [raw]
Subject: Re: [PATCH v3 0/9] NVIDIA Tegra I2C driver fixes and improvements

Hello Thierry,

07.01.2020 15:38, Thierry Reding пишет:
> On Mon, Jan 06, 2020 at 04:04:14AM +0300, Dmitry Osipenko wrote:
>> Hello,
>>
>> This patchset adds support for atomic transfers which are required for
>> shutting down machine properly. Secondly, a (not)suspending I2C and some
>> other things are fixed/improved by this small series as well. Please review
>> and apply, thanks in advance!
>>
>> Changelog:
>>
>> v3: The "Prevent interrupt triggering after transfer timeout" and "Support
>> atomic transfers" patches got extra very minor improvements. The
>> completion now is passed directly to tegra_i2c_poll_completion_timeout(),
>> for consistency.
>>
>> Added two new patches that firm up DMA transfer handling:
>>
>> i2c: tegra: Always terminate DMA transfer
>> i2c: tegra: Check DMA completion status in addition to left time
>>
>> v2: The series is renamed from "Tegra I2C: Support atomic transfers and
>> correct suspend/resume" to "NVIDIA Tegra I2C driver fixes and
>> improvements" because it now contains some more various changes.
>>
>> New patches in v2:
>>
>> i2c: tegra: Correct unwinding order on driver's probe error
>> i2c: tegra: Prevent interrupt triggering after transfer timeout
>> i2c: tegra: Use relaxed versions of readl/writel
>>
>> The "Rename I2C_PIO_MODE_MAX_LEN to I2C_PIO_MODE_PREFERRED_LEN" got an
>> improved wording for the code's comment to I2C_PIO_MODE_PREFERRED_LEN.
>>
>> The "Support atomic transfers" also got some very minor tuning, like
>> s/in_interrupt()/i2c_dev->is_curr_atomic_xfer/ in dvc_writel() that was
>> missed in v1.
>>
>> v1: The "i2c: tegra: Support atomic transfers" previously was sent out as
>> a separate patch, but later I spotted that suspend/resume doesn't
>> work properly. The "i2c: tegra: Fix suspending in active runtime PM
>> state" patch depends on the atomic patch because there is a need to
>> active IRQ-safe mode for the runtime PM by both patches.
>>
>> I fixed a missed doc-comment of the newly added "is_curr_atomic_xfer"
>> structure field and added additional comment that explains why IRQ needs
>> to be disabled for the atomic transfer in the "Support atomic transfers"
>> patch.
>>
>> Lastly, I added a minor "i2c: tegra: Rename .." patch that helps to
>> follow driver's code.
>>
>> Dmitry Osipenko (9):
>> i2c: tegra: Fix suspending in active runtime PM state
>> i2c: tegra: Properly disable runtime PM on driver's probe error
>> i2c: tegra: Prevent interrupt triggering after transfer timeout
>> i2c: tegra: Support atomic transfers
>> i2c: tegra: Rename I2C_PIO_MODE_MAX_LEN to I2C_PIO_MODE_PREFERRED_LEN
>> i2c: tegra: Use relaxed versions of readl/writel
>> clk: tegra: Fix double-free in tegra_clk_init()
>> i2c: tegra: Always terminate DMA transfer
>> i2c: tegra: Check DMA completion status in addition to left time
>>
>> drivers/clk/tegra/clk.c | 4 +-
>> drivers/i2c/busses/i2c-tegra.c | 216 ++++++++++++++++++++++-----------
>> 2 files changed, 147 insertions(+), 73 deletions(-)
>
> I'm still a bit on the fence about that second patch because I don't
> think force-suspend is the right thing to do.

Technically the force-suspend does absolutely the right thing. That's
what other drivers do, including some of the Tegra drivers. Personally
I'm feeling confident that it should be correct. Of course it would be
better to get a confirmation, unfortunately Rafael didn't answer
anything yet. We can always make another patch if it will turn out that
something is wrong.

> You should probably split the clk subsystem patch out of this series so
> that it can be picked up into the clk tree (or I can pick it up into the
> Tegra tree).

I made a mistake during rebase and didn't notice that, the clk patch is
already applied to the clk tree by Stephen Boyd. I'll fix the rebase and
send out v4, thanks!

> Other than that, I ran this through the testfarm and didn't see any
> regressions:
>
> Test results:
> 13 builds: 13 pass, 0 fail
> 11 boots: 11 pass, 0 fail
> 38 tests: 38 pass, 0 fail
>
> Linux version: 5.5.0-rc5-g258d134300af
> Boards tested: tegra20-ventana, tegra30-cardhu-a04, tegra124-jetson-tk1,
> tegra186-p2771-0000, tegra194-p2972-0000,
> tegra210-p2371-2180
>
> I'll reply to the individual patches with a Tested-by for patchwork to
> pick up.

Thanks!