* [PATCH 2/2] spi_txx9: Fix bit rate calculation
@ 2009-09-03 13:59 Atsushi Nemoto
2009-09-04 16:32 ` Ralf Baechle
0 siblings, 1 reply; 4+ messages in thread
From: Atsushi Nemoto @ 2009-09-03 13:59 UTC (permalink / raw)
To: linux-mips; +Cc: ralf, spi-devel-general, david-b
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>
---
drivers/spi/spi_txx9.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/spi/spi_txx9.c b/drivers/spi/spi_txx9.c
index 96057de..19f7562 100644
--- a/drivers/spi/spi_txx9.c
+++ b/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 txx9spi *c, struct spi_message *m)
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 platform_device *dev)
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)
--
1.5.6.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] spi_txx9: Fix bit rate calculation
2009-09-03 13:59 [PATCH 2/2] spi_txx9: Fix bit rate calculation Atsushi Nemoto
@ 2009-09-04 16:32 ` Ralf Baechle
2009-09-24 17:10 ` Atsushi Nemoto
0 siblings, 1 reply; 4+ messages in thread
From: Ralf Baechle @ 2009-09-04 16:32 UTC (permalink / raw)
To: Atsushi Nemoto; +Cc: linux-mips, spi-devel-general, david-b
On Thu, Sep 03, 2009 at 10:59:01PM +0900, Atsushi Nemoto wrote:
Atsushi's patches should probably be merged together. I can take care of
that if the SPI bit is acked by a maintainer.
Thanks,
Ralf
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] spi_txx9: Fix bit rate calculation
2009-09-04 16:32 ` Ralf Baechle
@ 2009-09-24 17:10 ` Atsushi Nemoto
2009-10-14 10:44 ` Ralf Baechle
0 siblings, 1 reply; 4+ messages in thread
From: Atsushi Nemoto @ 2009-09-24 17:10 UTC (permalink / raw)
To: david-b; +Cc: linux-mips, spi-devel-general, ralf
On Fri, 4 Sep 2009 17:32:27 +0100, Ralf Baechle <ralf@linux-mips.org> wrote:
> Atsushi's patches should probably be merged together. I can take care of
> that if the SPI bit is acked by a maintainer.
David, could you give us Ack ?
[PATCH 1/2] txx9: Fix spi-baseclk value
[PATCH 2/2] spi_txx9: Fix bit rate calculation
---
Atsushi Nemoto
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] spi_txx9: Fix bit rate calculation
2009-09-24 17:10 ` Atsushi Nemoto
@ 2009-10-14 10:44 ` Ralf Baechle
0 siblings, 0 replies; 4+ messages in thread
From: Ralf Baechle @ 2009-10-14 10:44 UTC (permalink / raw)
To: Atsushi Nemoto; +Cc: david-b, linux-mips, spi-devel-general
On Fri, Sep 25, 2009 at 02:10:39AM +0900, Atsushi Nemoto wrote:
> On Fri, 4 Sep 2009 17:32:27 +0100, Ralf Baechle <ralf@linux-mips.org> wrote:
> > Atsushi's patches should probably be merged together. I can take care of
> > that if the SPI bit is acked by a maintainer.
>
> David, could you give us Ack ?
>
> [PATCH 1/2] txx9: Fix spi-baseclk value
> [PATCH 2/2] spi_txx9: Fix bit rate calculation
Nothing heared so I've just merged these two fixes and will push them to
Linus asap.
Ralf
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-10-14 10:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-03 13:59 [PATCH 2/2] spi_txx9: Fix bit rate calculation Atsushi Nemoto
2009-09-04 16:32 ` Ralf Baechle
2009-09-24 17:10 ` Atsushi Nemoto
2009-10-14 10:44 ` Ralf Baechle
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.