I start this SPI driver blog because it is pretty useful and it can be a tutorial for kernel develop.
Currently the SPI driver is from mt7621/mt7620, it works well. I think maybe there is someway to improve it? I have done similar to i2c driver, and for myself it is much better than the original one.
Let’s check openwrt spi-mt7621.c first…
static inline int mt7621_spi_wait_till_ready(struct spi_device *spi)
{
struct mt7621_spi *rs = spidev_to_mt7621_spi(spi);
int i;
for (i = 0; i < RALINK_SPI_WAIT_MAX_LOOP; i++) {
u32 status;
status = mt7621_spi_read(rs, MT7621_SPI_TRANS);
if ((status & SPITRANS_BUSY) == 0) {
return 0;
}
cpu_relax();
udelay(1);
}
return -ETIMEDOUT;
}
From this code, means we are using busy wait for every bit. This will consume a lot of CPU time and increase VoCore2 current. Busy wait is never a good idea, but easy to develop.
Check datasheet again, 0x10000b28 bit 9 is Interrupt Enable. That means we might have a way avoid busy wait, even more, we might have a way to use DMA for mass data transfer.
Tomorrow I will try to make some test. I can directly write to SPI register in user space by mmap.
To be continue...