linux核心SPI匯流排驅動分析(二)

來源:互聯網
上載者:User

SPI驅動編寫

 

簡而言之,SPI驅動的編寫分為:

1.spi_device就構建並註冊 

 在板檔案中添加spi_board_info,並在板檔案的init函數中調用spi_register_board_info(s3c_spi_devs,ARRAY_SIZE(s3c_spi_devs));

spi_register_board_info(s3c_spi_devs,ARRAY_SIZE(s3c_spi_devs));//註冊spi_board_info。這個代碼會把spi_board_info註冊到鏈表board_list上。spi_device封裝了一個spi_master結構體,事實上spi_master的註冊會在spi_register_board_info之後,spi_master註冊的過程中會調用scan_boardinfo掃描board_list,找到掛接在它上面的spi裝置,然後建立並註冊spi_device。

 

2. spi_driver的構建與註冊

(1)

static struct spi_driver   m25p80_driver = { 

 

.driver = {

        .name   ="m25p80",

        .bus    =&spi_bus_type,

        .owner  = THIS_MODULE,

    },

    .probe  = m25p_probe,

    .remove =__devexit_p(m25p_remove),

};

(2)//spi_driver的註冊

 

spi_register_driver(&m25p80_driver);當匹配了spi_device以後調用probe

 

(3)實現probe操作:

 

 

 

 

 

spi_transfer(裡面整合了資料buf空間地址等資訊)

 

spi_message(是spi_transfer的集合)的構建;

 

spi_message_init(初始化spi_message)

 

spi_message_add_tail(將新的spi_transfer添加到spi_message隊列尾部)

 

 

spi_sync函數的調用(調用spi_master發送spi_message)

 

例如:

 

struct spi_transfer st={

 

 

 

。。。。。。。。。

 

 

};

 

//填充spi_transfer  

 

 

struct spi_message meg;

 

 

//定義message

 

 

spi_init_message(&meg);

 

//初始化meg

 

 

spi_message_add_tail(&st,&meg);

 

 

//將st放在message隊列尾部

 

 

Spi_sync(spi_device,&meg);

 

 

//將message與spi_device關聯,發送meg

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.