linux 使用gpio模拟spi总线的驱动文件是kernel/drivers/spi/spi_gpio.c,它里面包含了spi总线的注册,
而具体的通过GPIO模拟spi读写方法的会在里面调用 kerneldriversSpi/Spi_bitbang.c中的方法,这个方法
封装在 kerneldriversSpi/Spi_bitbang_txrx.h中的bitbang_txrx_be_cpha0()/bitbang_txrx_be_cpha1()函数中,此函数会有setmosi();和
getmiso();函数方法设置具体的GPIO电平,来达到模拟SPI总线的目的。其中SPI又有几种模式,分别体现在bitbang_txrx_be_cpha0()/bitbang_txrx_be_cpha1()函数中。
一、GPIO模拟SPI总线驱动
1、首先,你需要配置CONFIG。
config SPI_GPIO
tristate "GPIO-based bitbanging SPI Master"
depends on GENERIC_GPIO
select SPI_BITBANG
2、其次,你需要在你的平台注册platform_device,保证能让spi_gpio.c能执行到probe函数。
/kernel/arch/arm/mach-rkpx2/board-rkpx2-sdk.c
//add by Andy for spi_gpio_bus start
static struct spi_gpio_platform_data spi_gpio_bus_data = {
.sck = RK30_PIN4_PD1,//0
.mosi = RK30_PIN4_PD2,//1