summaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
authorMarek Vasut <marex@denx.de>2021-01-04 13:31:14 +0100
committerMark Brown <broonie@kernel.org>2021-01-13 12:19:51 +0000
commit970e8eaa08195a26ba99ec0843968cbc7ad8e947 (patch)
tree3e26871645d2191871c326ef4548d73e536272cf /drivers/spi
parenteaecba8767835783bdd2f4e72406668cda7d8d54 (diff)
downloadlinux-970e8eaa08195a26ba99ec0843968cbc7ad8e947.tar.bz2
spi: stm32: Simplify stm32h7_spi_prepare_fthlv()
Simplify stm32h7_spi_prepare_fthlv() function implementation, no functional change intended. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Alain Volmat <alain.volmat@st.com> Cc: Alexandre Torgue <alexandre.torgue@st.com> Cc: Amelie Delaunay <amelie.delaunay@st.com> Cc: Antonio Borneo <antonio.borneo@st.com> Cc: Mark Brown <broonie@kernel.org> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com> Cc: Roman Guskov <rguskov@dh-electronics.com> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-stm32@st-md-mailman.stormreply.com To: linux-spi@vger.kernel.org Link: https://lore.kernel.org/r/20210104123114.261596-1-marex@denx.de Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/spi-stm32.c28
1 files changed, 4 insertions, 24 deletions
diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index be0fb169d7a7..db3e305d9ec4 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -473,34 +473,14 @@ static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz,
*/
static u32 stm32h7_spi_prepare_fthlv(struct stm32_spi *spi, u32 xfer_len)
{
- u32 fthlv, half_fifo, packet;
+ u32 packet, bpw;
/* data packet should not exceed 1/2 of fifo space */
- half_fifo = (spi->fifo_size / 2);
-
- /* data_packet should not exceed transfer length */
- if (half_fifo > xfer_len)
- packet = xfer_len;
- else
- packet = half_fifo;
-
- if (spi->cur_bpw <= 8)
- fthlv = packet;
- else if (spi->cur_bpw <= 16)
- fthlv = packet / 2;
- else
- fthlv = packet / 4;
+ packet = clamp(xfer_len, 1U, spi->fifo_size / 2);
/* align packet size with data registers access */
- if (spi->cur_bpw > 8)
- fthlv += (fthlv % 2) ? 1 : 0;
- else
- fthlv += (fthlv % 4) ? (4 - (fthlv % 4)) : 0;
-
- if (!fthlv)
- fthlv = 1;
-
- return fthlv;
+ bpw = DIV_ROUND_UP(spi->cur_bpw, 8);
+ return DIV_ROUND_UP(packet, bpw);
}
/**