From: Ralf Baechle <ralf@linux-mips.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Atsushi Nemoto <anemo@mba.ocn.ne.jp>,
David Brownell <dbrownell@users.sourceforge.net>,
spi-devel-general@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: [PATCH 4/6] SPI: spi_txx9: Fix bit rate calculation
Date: Thu, 05 Nov 2009 16:26:00 +0100 [thread overview]
Message-ID: <20091105152702.283954757@linux-mips.org> (raw)
In-Reply-To: 20091105152555.227009519@linux-mips.org
[-- Attachment #1: 0005.patch --]
[-- Type: text/plain, Size: 1789 bytes --]
From: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
TXx9 SPI bit rate is calculated by:
fBR = (spi-baseclk) / (n + 1)
Fix calculation of min_speed_hz, max_speed_hz and n.
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: spi-devel-general@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
drivers/spi/spi_txx9.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
Index: upstream-linus/drivers/spi/spi_txx9.c
===================================================================
--- upstream-linus.orig/drivers/spi/spi_txx9.c
+++ upstream-linus/drivers/spi/spi_txx9.c
@@ -29,6 +29,8 @@
#define SPI_FIFO_SIZE 4
+#define SPI_MAX_DIVIDER 0xff /* Max. value for SPCR1.SER */
+#define SPI_MIN_DIVIDER 1 /* Min. value for SPCR1.SER */
#define TXx9_SPMCR 0x00
#define TXx9_SPCR0 0x04
@@ -193,11 +195,8 @@ static void txx9spi_work_one(struct txx9
if (prev_speed_hz != speed_hz
|| prev_bits_per_word != bits_per_word) {
- u32 n = (c->baseclk + speed_hz - 1) / speed_hz;
- if (n < 1)
- n = 1;
- else if (n > 0xff)
- n = 0xff;
+ int n = DIV_ROUND_UP(c->baseclk, speed_hz) - 1;
+ n = clamp(n, SPI_MIN_DIVIDER, SPI_MAX_DIVIDER);
/* enter config mode */
txx9spi_wr(c, mcr | TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR,
TXx9_SPMCR);
@@ -370,8 +369,8 @@ static int __init txx9spi_probe(struct p
goto exit;
}
c->baseclk = clk_get_rate(c->clk);
- c->min_speed_hz = (c->baseclk + 0xff - 1) / 0xff;
- c->max_speed_hz = c->baseclk;
+ c->min_speed_hz = DIV_ROUND_UP(c->baseclk, SPI_MAX_DIVIDER + 1);
+ c->max_speed_hz = c->baseclk / (SPI_MIN_DIVIDER + 1);
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
if (!res)
next prev parent reply other threads:[~2009-11-05 17:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-05 15:25 [PATCH 0/6] Misc driver fixes for 2.6.32 Ralf Baechle
2009-11-05 15:25 ` [PATCH 1/6] Staging: Octeon: Fix compile error in drivers/staging/octeon/ethernet-mdio.c Ralf Baechle
2009-11-05 15:25 ` [PATCH 2/6] Staging: Octeon: Use symbolic values for irq numbers Ralf Baechle
2009-11-05 15:25 ` [PATCH 3/6] Staging: octeon-ethernet: Assign proper MAC addresses Ralf Baechle
2009-11-05 15:26 ` Ralf Baechle [this message]
2009-11-05 15:26 ` [PATCH 5/6] VIDEO: Correct use of request_region/request_mem_region Ralf Baechle
2009-11-05 15:26 ` [PATCH 6/6] SERIAL: BCM63xx: Fix serial driver compile breakage Ralf Baechle
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=20091105152702.283954757@linux-mips.org \
--to=ralf@linux-mips.org \
--cc=anemo@mba.ocn.ne.jp \
--cc=dbrownell@users.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=spi-devel-general@lists.sourceforge.net \
--cc=torvalds@linux-foundation.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