All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>
To: "linux-spi@vger.kernel.org" <linux-spi@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>,
	Oleksandr Suvorov <cryosay@gmail.com>,
	Marcel Ziswiler <marcel.ziswiler@toradex.com>,
	Igor Opanyuk <igor.opanyuk@toradex.com>,
	Philippe Schenker <philippe.schenker@toradex.com>,
	Mark Brown <broonie@kernel.org>
Subject: [PATCH 1/2] spi: fsl-lpspi: remove unneeded array
Date: Thu, 20 Feb 2020 14:11:48 +0000	[thread overview]
Message-ID: <20200220141143.3902922-2-oleksandr.suvorov@toradex.com> (raw)
In-Reply-To: <20200220141143.3902922-1-oleksandr.suvorov@toradex.com>

- replace the array with the shift operation
- remove the extra comparing operation.

Signed-off-by: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>
---

 drivers/spi/spi-fsl-lpspi.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index d0b8cc741a24..298329b781d2 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -86,8 +86,6 @@
 #define TCR_RXMSK	BIT(19)
 #define TCR_TXMSK	BIT(18)
 
-static int clkdivs[] = {1, 2, 4, 8, 16, 32, 64, 128};
-
 struct lpspi_config {
 	u8 bpw;
 	u8 chip_select;
@@ -331,15 +329,14 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
 	}
 
 	for (prescale = 0; prescale < 8; prescale++) {
-		scldiv = perclk_rate /
-			 (clkdivs[prescale] * config.speed_hz) - 2;
+		scldiv = perclk_rate / config.speed_hz / (1 << prescale) - 2;
 		if (scldiv < 256) {
 			fsl_lpspi->config.prescale = prescale;
 			break;
 		}
 	}
 
-	if (prescale == 8 && scldiv >= 256)
+	if (scldiv >= 256)
 		return -EINVAL;
 
 	writel(scldiv | (scldiv << 8) | ((scldiv >> 1) << 16),
-- 
2.24.1


WARNING: multiple messages have this Message-ID (diff)
From: Oleksandr Suvorov <oleksandr.suvorov-2KBjVHiyJgBBDgjK7y7TUQ@public.gmane.org>
To: "linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: Oleksandr Suvorov
	<oleksandr.suvorov-2KBjVHiyJgBBDgjK7y7TUQ@public.gmane.org>,
	Oleksandr Suvorov
	<cryosay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Marcel Ziswiler
	<marcel.ziswiler-2KBjVHiyJgBBDgjK7y7TUQ@public.gmane.org>,
	Igor Opanyuk
	<igor.opanyuk-2KBjVHiyJgBBDgjK7y7TUQ@public.gmane.org>,
	Philippe Schenker
	<philippe.schenker-2KBjVHiyJgBBDgjK7y7TUQ@public.gmane.org>,
	Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Subject: [PATCH 1/2] spi: fsl-lpspi: remove unneeded array
Date: Thu, 20 Feb 2020 14:11:48 +0000	[thread overview]
Message-ID: <20200220141143.3902922-2-oleksandr.suvorov@toradex.com> (raw)
In-Reply-To: <20200220141143.3902922-1-oleksandr.suvorov-2KBjVHiyJgBBDgjK7y7TUQ@public.gmane.org>

- replace the array with the shift operation
- remove the extra comparing operation.

Signed-off-by: Oleksandr Suvorov <oleksandr.suvorov-2KBjVHiyJgBBDgjK7y7TUQ@public.gmane.org>
---

 drivers/spi/spi-fsl-lpspi.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index d0b8cc741a24..298329b781d2 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -86,8 +86,6 @@
 #define TCR_RXMSK	BIT(19)
 #define TCR_TXMSK	BIT(18)
 
-static int clkdivs[] = {1, 2, 4, 8, 16, 32, 64, 128};
-
 struct lpspi_config {
 	u8 bpw;
 	u8 chip_select;
@@ -331,15 +329,14 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
 	}
 
 	for (prescale = 0; prescale < 8; prescale++) {
-		scldiv = perclk_rate /
-			 (clkdivs[prescale] * config.speed_hz) - 2;
+		scldiv = perclk_rate / config.speed_hz / (1 << prescale) - 2;
 		if (scldiv < 256) {
 			fsl_lpspi->config.prescale = prescale;
 			break;
 		}
 	}
 
-	if (prescale == 8 && scldiv >= 256)
+	if (scldiv >= 256)
 		return -EINVAL;
 
 	writel(scldiv | (scldiv << 8) | ((scldiv >> 1) << 16),
-- 
2.24.1

  reply	other threads:[~2020-02-20 14:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-20 14:11 [PATCH 0/2] trivial fixes for fsl-spi and spidev Oleksandr Suvorov
2020-02-20 14:11 ` Oleksandr Suvorov
2020-02-20 14:11 ` Oleksandr Suvorov [this message]
2020-02-20 14:11   ` [PATCH 1/2] spi: fsl-lpspi: remove unneeded array Oleksandr Suvorov
2020-03-03 17:08   ` Applied "spi: fsl-lpspi: remove unneeded array" to the spi tree Mark Brown
2020-03-03 17:08     ` Mark Brown
2020-02-20 14:11 ` [PATCH 2/2] spi: spidev: fix a max speed setting Oleksandr Suvorov
2020-02-20 18:42   ` Mark Brown
2020-02-20 18:42     ` Mark Brown
2020-02-21 12:43     ` Oleksandr Suvorov
2020-02-21 12:43       ` Oleksandr Suvorov
2020-02-20 16:47 ` [PATCH 0/2] trivial fixes for fsl-spi and spidev Mark Brown
2020-02-20 16:47   ` 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=20200220141143.3902922-2-oleksandr.suvorov@toradex.com \
    --to=oleksandr.suvorov@toradex.com \
    --cc=broonie@kernel.org \
    --cc=cryosay@gmail.com \
    --cc=igor.opanyuk@toradex.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=marcel.ziswiler@toradex.com \
    --cc=philippe.schenker@toradex.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.