9
0
Fork 0

spi/altera_spi: Add cs_change support

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>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Franck Jullien 2011-11-24 21:46:34 +01:00 committed by Sascha Hauer
parent 2aad209b78
commit 146bea9b9b
2 changed files with 27 additions and 1 deletions

View File

@ -8,6 +8,7 @@ struct spi_altera_master {
int spi_mode;
int databits;
int speed;
int bus_num;
};
struct altera_spi {

View File

@ -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;