* [PATCH] spi: atmel: add support for changing message transfer speed
@ 2013-11-07 9:34 Richard Genoud
[not found] ` <1383816846-10561-1-git-send-email-richard.genoud-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Richard Genoud @ 2013-11-07 9:34 UTC (permalink / raw)
To: Nicolas Ferre, Mark Brown
Cc: Wenyou Yang, linux-spi-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Richard Genoud
The only speed available was max_speed (the maximum speed declared for a
device).
This patch adds the support for spi_tranfer->speed_hz parameter.
We can now set a different speed for each spi message.
Signed-off-by: Richard Genoud <richard.genoud-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/spi/spi-atmel.c | 92 ++++++++++++++++++++++++++++-------------------
1 file changed, 55 insertions(+), 37 deletions(-)
diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index 656ed36e729e..d0dd564cd7b3 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -694,6 +694,54 @@ static void atmel_spi_next_xfer_data(struct spi_master *master,
*plen = len;
}
+static int atmel_spi_set_xfer_speed(struct atmel_spi *as,
+ struct spi_device *spi,
+ struct spi_transfer *xfer)
+{
+ u32 scbr, csr;
+ unsigned long bus_hz;
+
+ /* v1 chips start out at half the peripheral bus speed. */
+ bus_hz = clk_get_rate(as->clk);
+ if (!atmel_spi_is_v2(as))
+ bus_hz /= 2;
+
+ /*
+ * Calculate the lowest divider that satisfies the
+ * constraint, assuming div32/fdiv/mbz == 0.
+ */
+ if (xfer->speed_hz)
+ scbr = DIV_ROUND_UP(bus_hz, xfer->speed_hz);
+ else
+ /*
+ * This can happend if max_speed is null.
+ * In this case, we set the lowest possible speed
+ */
+ scbr = 0xff;
+
+ /*
+ * If the resulting divider doesn't fit into the
+ * register bitfield, we can't satisfy the constraint.
+ */
+ if (scbr >= (1 << SPI_SCBR_SIZE)) {
+ dev_err(&spi->dev,
+ "setup: %d Hz too slow, scbr %u; min %ld Hz\n",
+ xfer->speed_hz, scbr, bus_hz/255);
+ return -EINVAL;
+ }
+ if (scbr == 0) {
+ dev_err(&spi->dev,
+ "setup: %d Hz too high, scbr %u; max %ld Hz\n",
+ xfer->speed_hz, scbr, bus_hz);
+ return -EINVAL;
+ }
+ csr = spi_readl(as, CSR0 + 4 * spi->chip_select);
+ csr = SPI_BFINS(SCBR, scbr, csr);
+ spi_writel(as, CSR0 + 4 * spi->chip_select, csr);
+
+ return 0;
+}
+
/*
* Submit next transfer for PDC.
* lock is held, spi irq is blocked
@@ -731,6 +779,8 @@ static void atmel_spi_pdc_next_xfer(struct spi_master *master,
spi_writel(as, RCR, len);
spi_writel(as, TCR, len);
+ atmel_spi_set_xfer_speed(as, msg->spi, xfer);
+
dev_dbg(&msg->spi->dev,
" start xfer %p: len %u tx %p/%08llx rx %p/%08llx\n",
xfer, xfer->len, xfer->tx_buf,
@@ -823,6 +873,7 @@ static void atmel_spi_dma_next_xfer(struct spi_master *master,
as->current_transfer = xfer;
len = xfer->len;
+ atmel_spi_set_xfer_speed(as, msg->spi, xfer);
}
if (atmel_spi_use_dma(as, xfer)) {
@@ -1264,9 +1315,8 @@ static int atmel_spi_setup(struct spi_device *spi)
{
struct atmel_spi *as;
struct atmel_spi_device *asd;
- u32 scbr, csr;
+ u32 csr;
unsigned int bits = spi->bits_per_word;
- unsigned long bus_hz;
unsigned int npcs_pin;
int ret;
@@ -1290,33 +1340,7 @@ static int atmel_spi_setup(struct spi_device *spi)
return -EINVAL;
}
- /* v1 chips start out at half the peripheral bus speed. */
- bus_hz = clk_get_rate(as->clk);
- if (!atmel_spi_is_v2(as))
- bus_hz /= 2;
-
- if (spi->max_speed_hz) {
- /*
- * Calculate the lowest divider that satisfies the
- * constraint, assuming div32/fdiv/mbz == 0.
- */
- scbr = DIV_ROUND_UP(bus_hz, spi->max_speed_hz);
-
- /*
- * If the resulting divider doesn't fit into the
- * register bitfield, we can't satisfy the constraint.
- */
- if (scbr >= (1 << SPI_SCBR_SIZE)) {
- dev_dbg(&spi->dev,
- "setup: %d Hz too slow, scbr %u; min %ld Hz\n",
- spi->max_speed_hz, scbr, bus_hz/255);
- return -EINVAL;
- }
- } else
- /* speed zero means "as slow as possible" */
- scbr = 0xff;
-
- csr = SPI_BF(SCBR, scbr) | SPI_BF(BITS, bits - 8);
+ csr = SPI_BF(BITS, bits - 8);
if (spi->mode & SPI_CPOL)
csr |= SPI_BIT(CPOL);
if (!(spi->mode & SPI_CPHA))
@@ -1363,8 +1387,8 @@ static int atmel_spi_setup(struct spi_device *spi)
asd->csr = csr;
dev_dbg(&spi->dev,
- "setup: %lu Hz bpw %u mode 0x%x -> csr%d %08x\n",
- bus_hz / scbr, bits, spi->mode, spi->chip_select, csr);
+ "setup: bpw %u mode 0x%x -> csr%d %08x\n",
+ bits, spi->mode, spi->chip_select, csr);
if (!atmel_spi_is_v2(as))
spi_writel(as, CSR0 + 4 * spi->chip_select, csr);
@@ -1414,12 +1438,6 @@ static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *msg)
}
}
- /* FIXME implement these protocol options!! */
- if (xfer->speed_hz < spi->max_speed_hz) {
- dev_dbg(&spi->dev, "can't change speed in transfer\n");
- return -ENOPROTOOPT;
- }
-
/*
* DMA map early, for performance (empties dcache ASAP) and
* better fault reporting.
--
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] spi: atmel: add support for changing message transfer speed
[not found] ` <1383816846-10561-1-git-send-email-richard.genoud-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2013-11-08 11:11 ` Mark Brown
[not found] ` <20131108111152.GL2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2013-11-08 11:11 UTC (permalink / raw)
To: Richard Genoud
Cc: Nicolas Ferre, Wenyou Yang, linux-spi-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 292 bytes --]
On Thu, Nov 07, 2013 at 10:34:06AM +0100, Richard Genoud wrote:
> The only speed available was max_speed (the maximum speed declared for a
> device).
> This patch adds the support for spi_tranfer->speed_hz parameter.
> We can now set a different speed for each spi message.
Applied, thanks.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] spi: atmel: add support for changing message transfer speed
[not found] ` <20131108111152.GL2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2014-01-08 10:15 ` Richard Genoud
[not found] ` <CACQ1gAhsKeQUB_vN9iJDbBsJ+7CiOZH8O=ZPg96pP8qRDHf15g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Richard Genoud @ 2014-01-08 10:15 UTC (permalink / raw)
To: Mark Brown
Cc: Nicolas Ferre, Wenyou Yang,
linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
2013/11/8 Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>:
> On Thu, Nov 07, 2013 at 10:34:06AM +0100, Richard Genoud wrote:
>> The only speed available was max_speed (the maximum speed declared for a
>> device).
>> This patch adds the support for spi_tranfer->speed_hz parameter.
>> We can now set a different speed for each spi message.
>
> Applied, thanks.
It seems that this patch got lost (or I missed something).
As it will now conflict with Wenyou patch "Refactor spi-atmel to use
SPI framework queue",
should I resent it based on wenyou's path ?
or on broonie/spi.git for-next and wenyou will rebase his patch on mine ?
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] spi: atmel: add support for changing message transfer speed
[not found] ` <CACQ1gAhsKeQUB_vN9iJDbBsJ+7CiOZH8O=ZPg96pP8qRDHf15g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-01-08 13:01 ` Mark Brown
[not found] ` <20140108130154.GD31886-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2014-01-08 13:01 UTC (permalink / raw)
To: Richard Genoud
Cc: Nicolas Ferre, Wenyou Yang,
linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
[-- Attachment #1: Type: text/plain, Size: 398 bytes --]
On Wed, Jan 08, 2014 at 11:15:13AM +0100, Richard Genoud wrote:
> It seems that this patch got lost (or I missed something).
> As it will now conflict with Wenyou patch "Refactor spi-atmel to use
> SPI framework queue",
> should I resent it based on wenyou's path ?
> or on broonie/spi.git for-next and wenyou will rebase his patch on mine ?
It was applied but not pushed out, pushed it out now.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] spi: atmel: add support for changing message transfer speed
[not found] ` <20140108130154.GD31886-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2014-01-08 13:05 ` Richard Genoud
0 siblings, 0 replies; 5+ messages in thread
From: Richard Genoud @ 2014-01-08 13:05 UTC (permalink / raw)
To: Mark Brown
Cc: Nicolas Ferre, Wenyou Yang,
linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
2014/1/8 Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>:
> On Wed, Jan 08, 2014 at 11:15:13AM +0100, Richard Genoud wrote:
>
>> It seems that this patch got lost (or I missed something).
>> As it will now conflict with Wenyou patch "Refactor spi-atmel to use
>> SPI framework queue",
>> should I resent it based on wenyou's path ?
>> or on broonie/spi.git for-next and wenyou will rebase his patch on mine ?
>
> It was applied but not pushed out, pushed it out now.
Ok, thanks !
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-01-08 13:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-07 9:34 [PATCH] spi: atmel: add support for changing message transfer speed Richard Genoud
[not found] ` <1383816846-10561-1-git-send-email-richard.genoud-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-11-08 11:11 ` Mark Brown
[not found] ` <20131108111152.GL2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-01-08 10:15 ` Richard Genoud
[not found] ` <CACQ1gAhsKeQUB_vN9iJDbBsJ+7CiOZH8O=ZPg96pP8qRDHf15g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-01-08 13:01 ` Mark Brown
[not found] ` <20140108130154.GD31886-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-01-08 13:05 ` Richard Genoud
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).