Rockchip SPI 功能特点
SPI (serial peripheral interface),以下是 linux 4.4 spi 驱动支持的一些特性︰
- 默认采用摩托罗拉 SPI 协议
- 支持 8 位和 16 位
- 软件可编程时钟频率和传输速率高达 50MHz
- 支持 SPI 4 种传输模式配置
- 每个 SPI 控制器支持一个到两个片选
除以上支持,linux 4.19 新增以下特性: - 框架支持 slave 和 master 两种模式
代码路径
内核配置
DTS 节点配置
spi1: spi@fe620000 {
compatible = "rockchip,rk3066-spi";
reg = <0x0 0xfe620000 0x0 0x1000>;
interrupts = <0 104 4>;
#address-cells = <1>;
#size-cells = <0>;
clocks = <&cru 340>, <&cru 339>;
clock-names = "spiclk", "apb_pclk";
dmas = <&dmac0 22>, <&dmac0 23>;
dma-names = "tx", "rx";
pinctrl-names = "default", "high_speed";
pinctrl-0 = <&spi1m0_cs0 &spi1m0_cs1 &spi1m0_pins>;
pinctrl-1 = <&spi1m0_cs0 &spi1m0_cs1 &spi1m0_pins_hs>;
status = "disabled";
};
&spi1 : 引用spi 控制器节点
clocks:指定 SPI sclk,可以通过查看 dtsi 中命名为 spiclk 的时钟
dmas 、dma-names : 使能DMA模式,一般通讯字节少于32字节的不建议用,dtsi 中默认设定,可通过置空赋值去掉使能;
spi 读写操作
对 spi 读写操作请参考 include/linux/spi/spi.h,以下简单列出几个:
spi_write
/**
* spi_write - SPI synchronous write
* @spi: device to which data will be written
* @buf: data buffer
* @len: data buffer size
* Context: can sleep
*
* This function writes the buffer @buf.
* Callable only from contexts that can sleep.
*
* Return: zero on success, else a negative error code.
*/
static inline int
spi_write(struct spi_device *spi, const void *buf, size_t len)
{
struct spi_transfer t = {
.tx_buf = buf,
.len = len,
};
return spi_sync_transfer(spi, &t, 1);
}
spi_read
/**
* spi_read - SPI synchronous read
* @spi: device from which data will be read
* @buf: data buffer
* @len: data buffer size
* Context: can sleep
*
* This function reads the buffer @buf.
* Callable only from contexts that can sleep.
*
* Return: zero on success, else a negative error code.
*/
static inline int
spi_read(struct