linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Franklin S Cooper Jr <fcooper@ti.com>
To: <broonie@kernel.org>, <nsekhar@ti.com>, <ssantosh@kernel.org>
Cc: <devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-spi@vger.kernel.org>, <khilman@deeprootsystems.com>,
	<linux@arm.linux.org.uk>, <galak@codeaurora.org>,
	<ijc+devicetree@hellion.org.uk>, <mark.rutland@arm.com>,
	<pawel.moll@arm.com>, <robh+dt@kernel.org>,
	<linux-arm-kernel@list.infradead.org>,
	Franklin S Cooper Jr <fcooper@ti.com>
Subject: [RESEND][PATCH 1/4] spi: davinci: Set prescale value based on register value
Date: Wed, 22 Jul 2015 07:32:21 -0500	[thread overview]
Message-ID: <1437568344-18889-2-git-send-email-fcooper@ti.com> (raw)
In-Reply-To: <1437568344-18889-1-git-send-email-fcooper@ti.com>

Within davinci_spi_get_prescale() the prescale has two meanings. First one
being the calculated prescale value and then at the end translates it to the
prescale value that will be written to the SPI register.

At first glance this can be confusing especially when comparing the minimum
prescale value against what is seen in the TRM.

To simplify things make it clear that the calculated prescale value will always
be based on the value that will be written into the SPI register.

Signed-off-by: Franklin S Cooper Jr <fcooper@ti.com>
---
 drivers/spi/spi-davinci.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index 987afeb..b4605c4 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -255,7 +255,7 @@ static void davinci_spi_chipselect(struct spi_device *spi, int value)
  * This function calculates the prescale value that generates a clock rate
  * less than or equal to the specified maximum.
  *
- * Returns: calculated prescale - 1 for easy programming into SPI registers
+ * Returns: calculated prescale value for easy programming into SPI registers
  * or negative error number if valid prescalar cannot be updated.
  */
 static inline int davinci_spi_get_prescale(struct davinci_spi *dspi,
@@ -263,12 +263,13 @@ static inline int davinci_spi_get_prescale(struct davinci_spi *dspi,
 {
 	int ret;
 
-	ret = DIV_ROUND_UP(clk_get_rate(dspi->clk), max_speed_hz);
+	/* Subtract 1 to match what will be programmed into SPI register. */
+	ret = DIV_ROUND_UP(clk_get_rate(dspi->clk), max_speed_hz) - 1;
 
-	if (ret < 1 || ret > 256)
+	if (ret < 0 || ret > 255)
 		return -EINVAL;
 
-	return ret - 1;
+	return ret;
 }
 
 /**
-- 
1.9.1

  reply	other threads:[~2015-07-22 12:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-22 12:32 [RESEND][PATCH 0/4] spi: davinci: Improve prescaler limit support Franklin S Cooper Jr
2015-07-22 12:32 ` Franklin S Cooper Jr [this message]
     [not found] ` <1437568344-18889-1-git-send-email-fcooper-l0cyMroinI0@public.gmane.org>
2015-07-22 12:32   ` [RESEND][PATCH 2/4] spi: davinci: Choose correct pre-scaler limit based on SOC Franklin S Cooper Jr
     [not found]     ` <1437568344-18889-3-git-send-email-fcooper-l0cyMroinI0@public.gmane.org>
2015-07-24 11:49       ` Sekhar Nori
2015-07-22 12:32   ` [RESEND][PATCH 4/4] ARM: dts: keystone: Add ti,keystone-spi for SPI Franklin S Cooper Jr
2015-07-22 16:17     ` santosh shilimkar
     [not found]       ` <55AFC207.3050100-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2015-08-24 13:36         ` Franklin S Cooper Jr.
     [not found]           ` <55DB1DC5.7060607-l0cyMroinI0@public.gmane.org>
2015-08-24 16:15             ` santosh shilimkar
2015-07-22 12:32 ` [RESEND][PATCH 3/4] ARM: davinci: Set proper SPI prescale limit value Franklin S Cooper Jr
2015-07-24 11:50   ` Sekhar Nori
     [not found]     ` <55B22681.3060000-l0cyMroinI0@public.gmane.org>
2015-08-10 23:47       ` Franklin S Cooper Jr.
     [not found]         ` <55C9380D.1060802-l0cyMroinI0@public.gmane.org>
2015-08-11  6:58           ` Sekhar Nori
     [not found]             ` <55C99D0D.9050605-l0cyMroinI0@public.gmane.org>
2015-08-11  9:03               ` Mark Brown
     [not found]                 ` <20150811090342.GG10748-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-08-11  9:24                   ` Sekhar Nori
     [not found]                     ` <55C9BF51.5080401-l0cyMroinI0@public.gmane.org>
2015-08-11  9:28                       ` 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=1437568344-18889-2-git-send-email-fcooper@ti.com \
    --to=fcooper@ti.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=khilman@deeprootsystems.com \
    --cc=linux-arm-kernel@list.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=mark.rutland@arm.com \
    --cc=nsekhar@ti.com \
    --cc=pawel.moll@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=ssantosh@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).