I am using QorIQ P1013 processor in Linux (3.10.18), where my NVRAM Chip is connected via SPI interface.
The NVRAM Write timings calculated using Chipscope are as follows:
1 byte write time with 1 MHz SPI clock = 310 - 330 usec (approx)
1 byte write time with 10 MHz SPI clock = 260 - 280 usec (approx)
As per Chipscope calculated timing, the actual write operation are performed in correct span of time as:
For 1 MHz SPI Clock :
8 bit SPI write enable = 9 usecs (approx)
40 bit message (opcode + address + data) write = 48 usecs (approx)
For 10 MHz SPI Clock :
8 bit SPI write enable = 800 nsecs (approx)
40 bit message (opcode + address + data) write = 4 usecs (approx)
But it takes 125 - 130 usecs for wait in write completion in both 1 MHz and 10 MHz clock.
I am using standard Linux SPI driver interface where SPI write performs the following sequence of operations:
- spi_message_init
- spi_message_add_tail
- spi_sync
The spi_sync() function uses kernel task wait_for_completion() to hold the state for write completion.
As per my test results, this consumes the wait time of 125 - 130 usecs, thus adding an extra 250 - 260 usecs time in SPI write for 1 byte data.
Any suggestion or feedback to this will help in optimizing my timing requirements.
Thanks in advance,
Kingshuk
Instead of waiting please add another SPI command to read the status of write operation from the NVRAM Chip.
Hi,
Thank you for the response.
My NVRAM driver is implemented by using the standard SPI driver calls (see previous message) for performing read/write operations.
The spi_sync() function implementation, that waits for write completion, is part of standard SPI driver (drivers/spi/spi.c), and thus is applicable for any device connected to the SPI interface.
Refer below code snippet:
static int __spi_sync(struct spi_device *spi, struct spi_message *message, int bus_locked)
{
DECLARE_COMPLETION_ONSTACK(done);
int status;
struct spi_master *master = spi->master;
message->complete = spi_complete;
message->context = &done;
if (!bus_locked)
mutex_lock(&master->bus_lock_mutex);
status = spi_async_locked(spi, message);
if (!bus_locked)
mutex_unlock(&master->bus_lock_mutex);
if (status == 0) {
wait_for_completion(&done);
status = message->status;
}
message->context = NULL;
return status;
}
Please tell me how the implementation specific to NVRAM write completion can be achieved using the Linux SPI driver calls.
Thanks again,
Kingshuk