]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
spi: spacemit: Correct TX FIFO slot calculation
authorZhengyu He <hezhy472013@gmail.com>
Wed, 15 Jul 2026 12:52:15 +0000 (20:52 +0800)
committerMark Brown <broonie@kernel.org>
Sun, 19 Jul 2026 21:12:52 +0000 (22:12 +0100)
commita88df1d92fcf23d848e5fa6d7d2a1c38fd0174ed
tree367d8b07ea8d81dec3f8559fa335398cd6e43c78
parent1590cf0329716306e948a8fc29f1d3ee87d3989f
spi: spacemit: Correct TX FIFO slot calculation

In k1_spi_write, the count variable is intended to represent the number
of slots available for writing into the TX FIFO.

The current implementation uses FIELD_GET(SSP_STATUS_TFL, val) in an
attempt to determine this count, but this register field returns the
number of occupied slots, not the available space. The previous
implementation attempted to handle this via a ternary operator (? :
K1_SPI_FIFO_SIZE), which incorrectly assumed that the hardware returned
0 when the FIFO was empty (meaning all slots were available), leading to
incorrect accounting of the buffer space.

Fix this by calculating the free slots: count = K1_SPI_FIFO_SIZE -
FIELD_GET(SSP_STATUS_TFL, val);

The associated comment has been updated to reflect the logic change: The
old comment reflected an incorrect assumption about the hardware
behavior, which was the root cause of the previous buggy logic.

This patch accurately and concisely describes the purpose of the new
calculation.

Signed-off-by: Peixin Xie <peixin.xie@spacemit.com>
Signed-off-by: Zhengyu He <hezhy472013@gmail.com>
Link: https://patch.msgid.link/20260715-k1-spi-tx-fifo-fix-v1-for-next-v1-1-02024223b08a@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-spacemit-k1.c