All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabrizio Castro <fabrizio.castro.jz@renesas.com>
To: Mark Brown <broonie@kernel.org>,
	Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Fabrizio Castro <fabrizio.castro.jz@renesas.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Chris Paterson <Chris.Paterson2@renesas.com>,
	Biju Das <biju.das@bp.renesas.com>,
	Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>,
	linux-renesas-soc@vger.kernel.org
Subject: [PATCH 09/10] spi: rzv2m-csi: Get rid of the x_trg{_words} tables
Date: Sat, 15 Jul 2023 02:04:06 +0100	[thread overview]
Message-ID: <20230715010407.1751715-10-fabrizio.castro.jz@renesas.com> (raw)
In-Reply-To: <20230715010407.1751715-1-fabrizio.castro.jz@renesas.com>

Table x_trg can be replaced with ilog2(), and table x_trg_words
can be replaced with rounddown_pow_of_two().
Replace the tables usage with the corresponding macros.
While at it, remove a couple of unnecessary empty lines.

Signed-off-by: Fabrizio Castro <fabrizio.castro.jz@renesas.com>
---
 drivers/spi/spi-rzv2m-csi.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/drivers/spi/spi-rzv2m-csi.c b/drivers/spi/spi-rzv2m-csi.c
index 1e5ed1089f42..1874ca1c2747 100644
--- a/drivers/spi/spi-rzv2m-csi.c
+++ b/drivers/spi/spi-rzv2m-csi.c
@@ -10,6 +10,7 @@
 #include <linux/count_zeros.h>
 #include <linux/interrupt.h>
 #include <linux/iopoll.h>
+#include <linux/log2.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
 #include <linux/spi/spi.h>
@@ -99,20 +100,6 @@ struct rzv2m_csi_priv {
 	u32 status;
 };
 
-static const unsigned char x_trg[] = {
-	0, 1, 1, 2, 2, 2, 2, 3,
-	3, 3, 3, 3, 3, 3, 3, 4,
-	4, 4, 4, 4, 4, 4, 4, 4,
-	4, 4, 4, 4, 4, 4, 4, 5
-};
-
-static const unsigned char x_trg_words[] = {
-	1,  2,  2,  4,  4,  4,  4,  8,
-	8,  8,  8,  8,  8,  8,  8,  16,
-	16, 16, 16, 16, 16, 16, 16, 16,
-	16, 16, 16, 16, 16, 16, 16, 32
-};
-
 static void rzv2m_csi_reg_write_bit(const struct rzv2m_csi_priv *csi,
 				    int reg_offs, int bit_mask, u32 value)
 {
@@ -216,7 +203,7 @@ static inline void rzv2m_csi_calc_current_transfer(struct rzv2m_csi_priv *csi)
 	 * less than or equal to the number of bytes we need to transfer.
 	 * This may result in multiple smaller transfers.
 	 */
-	csi->words_to_transfer = x_trg_words[to_transfer - 1];
+	csi->words_to_transfer = rounddown_pow_of_two(to_transfer);
 
 	if (csi->bytes_per_word == 2)
 		csi->bytes_to_transfer = csi->words_to_transfer << 1;
@@ -227,7 +214,7 @@ static inline void rzv2m_csi_calc_current_transfer(struct rzv2m_csi_priv *csi)
 static inline void rzv2m_csi_set_rx_fifo_trigger_level(struct rzv2m_csi_priv *csi)
 {
 	rzv2m_csi_reg_write_bit(csi, CSI_FIFOTRG, CSI_FIFOTRG_R_TRG,
-				x_trg[csi->words_to_transfer - 1]);
+				ilog2(csi->words_to_transfer));
 }
 
 static inline void rzv2m_csi_enable_rx_trigger(struct rzv2m_csi_priv *csi,
@@ -300,7 +287,6 @@ static int rzv2m_csi_wait_for_tx_empty(struct rzv2m_csi_priv *csi)
 		return 0;
 
 	ret = rzv2m_csi_wait_for_interrupt(csi, CSI_INT_TREND, CSI_CNT_TREND_E);
-
 	if (ret == -ETIMEDOUT)
 		csi->errors |= TX_TIMEOUT_ERROR;
 
@@ -316,7 +302,6 @@ static inline int rzv2m_csi_wait_for_rx_ready(struct rzv2m_csi_priv *csi)
 
 	ret = rzv2m_csi_wait_for_interrupt(csi, CSI_INT_R_TRGR,
 					   CSI_CNT_R_TRGR_E);
-
 	if (ret == -ETIMEDOUT)
 		csi->errors |= RX_TIMEOUT_ERROR;
 
-- 
2.34.1


  parent reply	other threads:[~2023-07-15  1:05 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-15  1:03 [PATCH 00/10] spi: rzv2m-csi: Code refactoring Fabrizio Castro
2023-07-15  1:03 ` [PATCH 01/10] spi: rzv2m-csi: Add missing include Fabrizio Castro
2023-07-15  1:03 ` [PATCH 02/10] spi: rzv2m-csi: Adopt HZ_PER_MHZ for max spi clock Fabrizio Castro
2023-07-17  9:24   ` Geert Uytterhoeven
2023-07-15  1:04 ` [PATCH 03/10] spi: rzv2m-csi: Rework CSI_CKS_MAX definition Fabrizio Castro
2023-07-17  9:27   ` Geert Uytterhoeven
2023-07-15  1:04 ` [PATCH 04/10] spi: rzv2m-csi: Leave readl_poll_timeout calls for last Fabrizio Castro
2023-07-17  9:29   ` Geert Uytterhoeven
2023-07-15  1:04 ` [PATCH 05/10] spi: rzv2m-csi: Replace unnecessary ternary operators Fabrizio Castro
2023-07-17  9:30   ` Geert Uytterhoeven
2023-07-15  1:04 ` [PATCH 06/10] spi: rzv2m-csi: Squash timing settings into one statement Fabrizio Castro
2023-07-15  7:54   ` Andy Shevchenko
2023-07-17 10:44     ` Fabrizio Castro
2023-07-17 11:15       ` Andy Shevchenko
2023-07-15  1:04 ` [PATCH 07/10] spi: rzv2m-csi: Switch to using {read,write}s{b,w} Fabrizio Castro
2023-07-17  9:37   ` Geert Uytterhoeven
2023-07-17 10:36     ` Fabrizio Castro
2023-07-17 11:18       ` Andy Shevchenko
2023-07-17 13:00         ` Fabrizio Castro
2023-07-17 16:31           ` Fabrizio Castro
2023-07-15  1:04 ` [PATCH 08/10] spi: rzv2m-csi: Improve data types and alignment Fabrizio Castro
2023-07-17  9:44   ` Geert Uytterhoeven
2023-07-15  1:04 ` Fabrizio Castro [this message]
2023-07-15  7:57   ` [PATCH 09/10] spi: rzv2m-csi: Get rid of the x_trg{_words} tables Andy Shevchenko
2023-07-17  9:49   ` Geert Uytterhoeven
2023-07-15  1:04 ` [PATCH 10/10] spi: rzv2m-csi: Make use of device_set_node Fabrizio Castro
2023-07-15  7:58   ` Andy Shevchenko
2023-07-17 15:05     ` Fabrizio Castro
2023-07-15  8:00 ` [PATCH 00/10] spi: rzv2m-csi: Code refactoring Andy Shevchenko
2023-07-18 18:46 ` (subset) " Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230715010407.1751715-10-fabrizio.castro.jz@renesas.com \
    --to=fabrizio.castro.jz@renesas.com \
    --cc=Chris.Paterson2@renesas.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=biju.das@bp.renesas.com \
    --cc=broonie@kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.