嵌入式Linux SPI驱动

1. Linux下SPI驱动框架

1.1 SPI主机驱动

Linux使用spi_master结构体表示spi主机驱动,定义在 drivers/linux/spi/spi.h
transfer : 数据传输函数
transfer_one_message: SPI发送护具函数,发送一个spi_message数据

1.2 SPI设备驱动

Linux内核使用spi_driver结构体表示spi设备驱动, 定义在 include/linux/spi/spi.h

struct spi_driver {
	const struct spi_device_id *id_table;
	int			(*probe)(struct spi_device *spi);
	int			(*remove)(struct spi_device *spi);
	void			(*shutdown)(struct spi_device *spi);
	struct device_driver	driver;
};
1.3 SPI设备和驱动匹配过程

SPI设备和驱动的匹配过程是由SPI总线完成的,SPI总线为spi_bus_type,定义在 drivers/spi/spi.c

struct bus_type spi_bus_type = {
	.name		= "spi",
	.dev_groups	= spi_dev_groups,
	.match		= spi_match_device,
	.uevent		= spi_uevent,
};

spi设备和驱动的匹配函数是spi_match_device ,函数定义如下:

static int spi_match_device(struct device *dev, struct device_driver *drv)
{
	const struct spi_device	*spi = to_spi_device(dev);
	const struct spi_driver	*sdrv = to_spi_driver(drv);

	/* Attempt an OF style match */
	if (of_driver_match_device(dev, drv))
		return 1;

	/* Then try ACPI */
	if (acpi_driver_match_device(dev, drv))
		return 1;

	if (sdrv->id_table)
		return !!spi_match_id(sdrv->id_table, spi);

	return strcmp(spi->modalias, drv->name) == 0;
}

2. I.MX6U SPI 主机驱动分析

你可能感兴趣的:(嵌入式Linux-IMX6UL)