RK356X SPI 使用

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
  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值