From: franck.jullien@gmail.com
To: barebox@lists.infradead.org
Subject: [PATCH 4/4] spi/altera_spi: Add cs_change support
Date: Wed, 23 Nov 2011 22:12:28 +0100 [thread overview]
Message-ID: <1322082748-17409-5-git-send-email-franck.jullien@gmail.com> (raw)
In-Reply-To: <1322082748-17409-1-git-send-email-franck.jullien@gmail.com>
From: Franck Jullien <franck.jullien@gmail.com>
The Linux kernel says (spi.h) :
* All SPI transfers start with the relevant chipselect active. Normally
* it stays selected until after the last transfer in a message. Drivers
* can affect the chipselect signal using cs_change.
*
* (i) If the transfer isn't the last one in the message, this flag is
* used to make the chipselect briefly go inactive in the middle of the
* message. Toggling chipselect in this way may be needed to terminate
* a chip command, letting a single spi_message perform all of group of
* chip transactions together.
*
* (ii) When the transfer is the last one in the message, the chip may
* stay selected until the next transfer. On multi-device SPI busses
* with nothing blocking messages going to other devices, this is just
* a performance hint; starting a message to another device deselects
* this one. But in other cases, this can be used to ensure correctness.
* Some devices need protocol transactions to be built from a series of
* spi_message submissions, where the content of one message is
* determined by the results of previous messages and where the whole
* transaction
* ends when the chipselect goes intactive.
In other words, cs_change changes the default chipselect *behavior*.
Support of cs_change is necessary to implement the mci spi driver.
This patch also fix few things:
Passing the bus number to the brand new master device.
Disable chipselect during master->setup.
Signed-off-by: Franck Jullien <franck.jullien@gmail.com>
---
arch/nios2/include/asm/spi.h | 1 +
drivers/spi/altera_spi.c | 27 ++++++++++++++++++++++++++-
2 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/arch/nios2/include/asm/spi.h b/arch/nios2/include/asm/spi.h
index 4e576b9..6c5740c 100644
--- a/arch/nios2/include/asm/spi.h
+++ b/arch/nios2/include/asm/spi.h
@@ -8,6 +8,7 @@ struct spi_altera_master {
int spi_mode;
int databits;
int speed;
+ int bus_num;
};
struct altera_spi {
diff --git a/drivers/spi/altera_spi.c b/drivers/spi/altera_spi.c
index 4fd82fb..d63dce3 100644
--- a/drivers/spi/altera_spi.c
+++ b/drivers/spi/altera_spi.c
@@ -25,6 +25,9 @@
#include <io.h>
#include <asm/spi.h>
#include <asm/nios2-io.h>
+#include <clock.h>
+
+static void altera_spi_cs_inactive(struct spi_device *spi);
static int altera_spi_setup(struct spi_device *spi)
{
@@ -49,6 +52,8 @@ static int altera_spi_setup(struct spi_device *spi)
return -1;
}
+ altera_spi_cs_inactive(spi);
+
dev_dbg(master->dev, " mode 0x%08x, bits_per_word: %d, speed: %d\n",
spi->mode, spi->bits_per_word, altera_spi->speed);
@@ -167,19 +172,38 @@ static int altera_spi_transfer(struct spi_device *spi, struct spi_message *mesg)
struct altera_spi *altera_spi = container_of(spi->master, struct altera_spi, master);
struct nios_spi *nios_spi = altera_spi->regs;
struct spi_transfer *t;
+ unsigned int cs_change;
+ const int nsecs = 50;
altera_spi_cs_active(spi);
+ cs_change = 0;
+
mesg->actual_length = 0;
list_for_each_entry(t, &mesg->transfers, transfer_list) {
+
+ if (cs_change) {
+ ndelay(nsecs);
+ altera_spi_cs_inactive(spi);
+ ndelay(nsecs);
+ altera_spi_cs_active(spi);
+ }
+
+ cs_change = t->cs_change;
+
mesg->actual_length += altera_spi_do_xfer(spi, t);
+
+ if (cs_change) {
+ altera_spi_cs_active(spi);
+ }
}
/* Wait the end of any pending transfer */
while ((readl(&nios_spi->status) & NIOS_SPI_TMT) == 0);
- altera_spi_cs_inactive(spi);
+ if(!cs_change)
+ altera_spi_cs_inactive(spi);
return 0;
}
@@ -199,6 +223,7 @@ static int altera_spi_probe(struct device_d *dev)
master->setup = altera_spi_setup;
master->transfer = altera_spi_transfer;
master->num_chipselect = pdata->num_chipselect;
+ master->bus_num = pdata->bus_num;
altera_spi->regs = dev_request_mem_region(dev, 0);
altera_spi->databits = pdata->databits;
--
1.7.7
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2011-11-23 21:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-23 21:12 [PATCH 0/4] Add MCI over SPI support franck.jullien
2011-11-23 21:12 ` [PATCH 1/4] crypto: Add crc7 function franck.jullien
2011-11-23 21:12 ` [PATCH 2/4] mci: Add MCI over SPI support franck.jullien
2011-11-24 9:17 ` Sascha Hauer
2011-11-23 21:12 ` [PATCH 3/4] nios2: Include asm/unaligned.h franck.jullien
2011-11-24 9:36 ` Sascha Hauer
2011-11-23 21:12 ` franck.jullien [this message]
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=1322082748-17409-5-git-send-email-franck.jullien@gmail.com \
--to=franck.jullien@gmail.com \
--cc=barebox@lists.infradead.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