Monday, January 10, 2022

[Linux kernel] SPI 實作

Linux SPI 子系統將驅動程式分為三種類型

SPI bus driver:主要目的為提供 API 給下層的 master driver 及上層的 protocol driver (稍後會提) 註冊,並傳
送封包至下層的 driver。 (spi_device)

SPI Master driver:主要工作為初始化控制器,並負責對暫存器寫入以及中斷處理

SPI protocol driver :主要為發送 SPI 訊息封包至所選擇的裝置

訊息封包的格式定義在 spi.h 的 spi_message 結構中

==============================================

struct spi_message {

  struct list_head transfers;

  struct spi_device *spi;

  unsgined is_dma_mapped


/* completion is reported through a callback */

  void (*complete)(void *context);

  void *context;

  unsigned actual_length;

  int status;

  list_head queue;

  void *state;

}

==============================================

呼叫 spi_sync 以起始傳送

或者也可直接呼叫 spi_read/spi_write

在平台初始化時預先定義系統包含那些 SPI 周邊,而子系統也定義一個結構 spi_board_info 提供給開發者填入相對應的資訊

==============================================

static struct spi_board_info devkit8000_spi_board_info[] __initdata = {

{

/* [PDA9320]TSC3006 TouchScreen Driver Porting

.modalias= "tsc2006", //"ads7846",

.bus_num= 3, //2,

.chip_select= 0,

.max_speed_hz= 1500000,

.controller_data= &tsc2006_mcspi_config, //&ads7846_mcspi_config,

.irq= OMAP_GPIO_IRQ(OMAP3_DEVKIT_TS_GPIO),

.platform_data= &tsc2006_config, //&ads7846_config,

}

};

==============================================

modalias 欄位的值必須與 protocol driver 註冊的名字相同


No comments:

Post a Comment

n8n index

 【n8n免費本地端部署】Windows版|程式安裝x指令大補帖  【一鍵安裝 n8n】圖文教學,獲得無限額度自動化工具&限時免費升級企業版功能