Commit graph

21 commits

Author SHA1 Message Date
Ksawlii
5bd693c00e Revert "i2c: xiic: Fix broken locking on tx_msg"
This reverts commit e058cb79b6.
2024-11-24 00:23:12 +01:00
Ksawlii
dfea2d46b2 Revert "i2c: xiic: Switch from waitqueue to completion"
This reverts commit af4a7e1828.
2024-11-24 00:23:11 +01:00
Ksawlii
9589eca099 Revert "i2c: xiic: Fix RX IRQ busy check"
This reverts commit 088b9bc083.
2024-11-24 00:23:11 +01:00
Ksawlii
d10de7671b Revert "i2c: xiic: xiic_xfer(): Fix runtime PM leak on error path"
This reverts commit 46ed34aa9f.
2024-11-24 00:23:11 +01:00
Ksawlii
85e2f2e500 Revert "i2c: xiic: improve error message when transfer fails to start"
This reverts commit e498760685.
2024-11-24 00:23:11 +01:00
Ksawlii
61b6acbdcf Revert "i2c: xiic: Try re-initialization on bus busy timeout"
This reverts commit 697cea0298.
2024-11-24 00:23:11 +01:00
Ksawlii
4dcf30060d Revert "i2c: xiic: Wait for TX empty to avoid missed TX NAKs"
This reverts commit b66ee2f40f.
2024-11-24 00:23:05 +01:00
Ksawlii
9411ef0547 Revert "i2c: xiic: Simplify with dev_err_probe()"
This reverts commit b8ab3cd966.
2024-11-24 00:23:01 +01:00
Ksawlii
4a9666c457 Revert "i2c: xiic: Use devm_clk_get_enabled()"
This reverts commit ece3f22d54.
2024-11-24 00:23:01 +01:00
Ksawlii
f88bd7f937 Revert "i2c: xiic: Fix pm_runtime_set_suspended() with runtime pm enabled"
This reverts commit 125a4ee1ba.
2024-11-24 00:23:01 +01:00
Jinjie Ruan
125a4ee1ba i2c: xiic: Fix pm_runtime_set_suspended() with runtime pm enabled
[ Upstream commit 0c8d604dea437b69a861479b413d629bc9b3da70 ]

It is not valid to call pm_runtime_set_suspended() for devices
with runtime PM enabled because it returns -EAGAIN if it is enabled
already and working. So, call pm_runtime_disable() before to fix it.

Fixes: 36ecbcab84d0 ("i2c: xiic: Implement power management")
Cc: <stable@vger.kernel.org> # v4.6+
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-23 23:21:46 +01:00
Andi Shyti
ece3f22d54 i2c: xiic: Use devm_clk_get_enabled()
[ Upstream commit 8390dc7477e49e4acc9e553f385f4ff59d186efe ]

Replace the pair of functions, devm_clk_get() and clk_prepare_enable(),
with a single function devm_clk_get_enabled().

Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Acked-by: Michal Simek <michal.simek@amd.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
Stable-dep-of: 0c8d604dea43 ("i2c: xiic: Fix pm_runtime_set_suspended() with runtime pm enabled")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-23 23:21:46 +01:00
Krzysztof Kozlowski
b8ab3cd966 i2c: xiic: Simplify with dev_err_probe()
[ Upstream commit 9dbba3f87c7823cf35e63fb7a2449a5d54b3b799 ]

Common pattern of handling deferred probe can be simplified with
dev_err_probe().  Less code and the error value gets printed.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
Acked-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
Stable-dep-of: 0c8d604dea43 ("i2c: xiic: Fix pm_runtime_set_suspended() with runtime pm enabled")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-23 23:21:46 +01:00
Robert Hancock
b66ee2f40f i2c: xiic: Wait for TX empty to avoid missed TX NAKs
commit 521da1e9225450bd323db5fa5bca942b1dc485b7 upstream.

Frequently an I2C write will be followed by a read, such as a register
address write followed by a read of the register value. In this driver,
when the TX FIFO half empty interrupt was raised and it was determined
that there was enough space in the TX FIFO to send the following read
command, it would do so without waiting for the TX FIFO to actually
empty.

Unfortunately it appears that in some cases this can result in a NAK
that was raised by the target device on the write, such as due to an
unsupported register address, being ignored and the subsequent read
being done anyway. This can potentially put the I2C bus into an
invalid state and/or result in invalid read data being processed.

To avoid this, once a message has been fully written to the TX FIFO,
wait for the TX FIFO empty interrupt before moving on to the next
message, to ensure NAKs are handled properly.

Fixes: e1d5b6598cdc ("i2c: Add support for Xilinx XPS IIC Bus Interface")
Signed-off-by: Robert Hancock <robert.hancock@calian.com>
Cc: <stable@vger.kernel.org> # v2.6.34+
Reviewed-by: Manikanta Guntupalli <manikanta.guntupalli@amd.com>
Acked-by: Michal Simek <michal.simek@amd.com>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-11-23 23:21:42 +01:00
Robert Hancock
697cea0298 i2c: xiic: Try re-initialization on bus busy timeout
[ Upstream commit 1d4a1adbed2582444aaf97671858b7d12915bd05 ]

In the event that the I2C bus was powered down when the I2C controller
driver loads, or some spurious pulses occur on the I2C bus, it's
possible that the controller detects a spurious I2C "start" condition.
In this situation it may continue to report the bus is busy indefinitely
and block the controller from working.

The "single-master" DT flag can be specified to disable bus busy checks
entirely, but this may not be safe to use in situations where other I2C
masters may potentially exist.

In the event that the controller reports "bus busy" for too long when
starting a transaction, we can try reinitializing the controller to see
if the busy condition clears. This allows recovering from this scenario.

Fixes: e1d5b6598cdc ("i2c: Add support for Xilinx XPS IIC Bus Interface")
Signed-off-by: Robert Hancock <robert.hancock@calian.com>
Cc: <stable@vger.kernel.org> # v2.6.34+
Reviewed-by: Manikanta Guntupalli <manikanta.guntupalli@amd.com>
Acked-by: Michal Simek <michal.simek@amd.com>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-23 23:21:36 +01:00
Marc Ferland
e498760685 i2c: xiic: improve error message when transfer fails to start
[ Upstream commit ee1691d0ae103ba7fd9439800ef454674fadad27 ]

xiic_start_xfer can fail for different reasons:

- EBUSY: bus is busy or i2c messages still in tx_msg or rx_msg
- ETIMEDOUT: timed-out trying to clear the RX fifo
- EINVAL: wrong clock settings

Both EINVAL and ETIMEDOUT will currently print a specific error
message followed by a generic one, for example:

    Failed to clear rx fifo
    Error xiic_start_xfer

however EBUSY will simply output the generic message:

    Error xiic_start_xfer

which is not really helpful.

This commit adds a new error message when a busy condition is detected
and also removes the generic message since it does not provide any
relevant information to the user.

Signed-off-by: Marc Ferland <marc.ferland@sonatest.com>
Acked-by: Michal Simek <michal.simek@amd.com>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Stable-dep-of: 1d4a1adbed25 ("i2c: xiic: Try re-initialization on bus busy timeout")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-23 23:21:36 +01:00
Lars-Peter Clausen
46ed34aa9f i2c: xiic: xiic_xfer(): Fix runtime PM leak on error path
[ Upstream commit d663d93bb47e7ab45602b227701022d8aa16040a ]

The xiic_xfer() function gets a runtime PM reference when the function is
entered. This reference is released when the function is exited. There is
currently one error path where the function exits directly, which leads to
a leak of the runtime PM reference.

Make sure that this error path also releases the runtime PM reference.

Fixes: fdacc3c7405d ("i2c: xiic: Switch from waitqueue to completion")
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Reviewed-by: Michal Simek <michal.simek@amd.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
Stable-dep-of: 1d4a1adbed25 ("i2c: xiic: Try re-initialization on bus busy timeout")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-23 23:21:36 +01:00
Marek Vasut
088b9bc083 i2c: xiic: Fix RX IRQ busy check
[ Upstream commit 294b29f15469e90893c2b72a738a962ee02a12eb ]

In case the XIIC does TX/RX transfer, make sure no other kernel thread
can start another TX transfer at the same time. This could happen since
the driver only checks tx_msg for being non-NULL and returns -EBUSY in
that case, however it is necessary to check also rx_msg for the same.

Signed-off-by: Marek Vasut <marex@denx.de>
Acked-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
Stable-dep-of: 1d4a1adbed25 ("i2c: xiic: Try re-initialization on bus busy timeout")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-23 23:21:36 +01:00
Marek Vasut
af4a7e1828 i2c: xiic: Switch from waitqueue to completion
[ Upstream commit fdacc3c7405d1fc33c1f2771699a4fc24551e480 ]

There will never be threads queueing up in the xiic_xmit(), use
completion synchronization primitive to wait for the interrupt
handler thread to complete instead as it is much better fit and
there is no need to overload it for this purpose.

Signed-off-by: Marek Vasut <marex@denx.de>
Acked-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
Stable-dep-of: 1d4a1adbed25 ("i2c: xiic: Try re-initialization on bus busy timeout")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-23 23:21:36 +01:00
Marek Vasut
e058cb79b6 i2c: xiic: Fix broken locking on tx_msg
[ Upstream commit c119e7d00c916881913011e6f4c6ac349a41e4e2 ]

The tx_msg is set from multiple places, sometimes without locking,
which fall apart on any SMP system. Only ever access tx_msg inside
the driver mutex.

Signed-off-by: Marek Vasut <marex@denx.de>
Acked-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
Stable-dep-of: 1d4a1adbed25 ("i2c: xiic: Try re-initialization on bus busy timeout")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-23 23:21:36 +01:00
Gabriel2392
7ed7ee9edf Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00