Daily Archives: 2014-07-20

VoCore: SPI & MicroSD 3

In linux kernel, there are several important files for SPI/MMC part.

spi.c
spi.h
mmc_spi.c
mmc_spi.h
of_mmc_spi.c

From openwrt side, one file related to it.
spi-rt2880.c

But spi-rt2880.c only supports one SPI device, the flash chip.
There is a patch but not work, after I apply that, get the following error log.

[   15.050000] mmc_spi spi32766.1: OF: voltage-ranges unspecified
[   15.060000] mmc_spi spi32766.1: ASSUMING 3.2-3.4 V slot power
[   15.100000] mmc_spi spi32766.1: TX failed, err=-145
[   15.110000] mmc_spi spi32766.1: TX failed, err=-145
[   15.120000] mmc_spi spi32766.1: setup: unsupported mode bits 4
[   15.130000] mmc_spi spi32766.1: can't change chip-select polarity
[   15.140000] mmc_spi spi32766.1: setup: requested speed is too low 400000 Hz
[   15.180000] mmc_spi spi32766.1: SD/MMC host mmc0, no DMA, no WP, no poweroff

In the datasheet, RT5350 SPI is so good. All SPI features are supported, even SPI slave mode.

RT5350 SPI have the following features:
1. MSB first or LSB first
2. SPI clock default state 0 or 1
3. RX/TX data captured on the rising or falling edge of the SPI clock signal.(So RT5350 supports all the four modes of SPI)
4. SPI polarity indicator low active or high active.

Looks like there is no hardware problem to make the microSD over SPI come true. 🙂

[   15.050000] mmc_spi spi32766.1: OF: voltage-ranges unspecified
[   15.060000] mmc_spi spi32766.1: ASSUMING 3.2-3.4 V slot power
[   15.100000] mmc_spi spi32766.1: TX failed, err=-145
[   15.110000] mmc_spi spi32766.1: TX failed, err=-145

In dts, I did not add the voltage-ranges, after add that line, this fixed.
This voltage-ranges is useless but necessary to compatible with mmc-spi/spi driver, RT5350F do not have hardware support that feature.

[   15.120000] mmc_spi spi32766.1: setup: unsupported mode bits 4

This is caused by SPI_CS_HIGH(0x04) is not proper supported by rt2880-spi driver.

[   15.130000] mmc_spi spi32766.1: can't change chip-select polarity

rt2880-spi driver do not support that too, old driver only support one spi slave, do not need that. The patch has some code about that, but there might be bug.

[   15.140000] mmc_spi spi32766.1: setup: requested speed is too low 400000 Hz

This is not a real problem, the dts error stopped platform struct init, so setup is trying to setup the speed to zero.

Now, code is the only solution. 🙂
First, I will try to fix the patched rt2880-spi driver.
Then try to write a new one(rt5350-spi.c?) support all 5350 SPI features, so it will have a better compatible with linux SPI driver or other device based on SPI.