Linux Kernel SPI bus driver analysis (2)

Source: Internet
Author: User

SPI driver writing

 

In short, the writing of the SPI driver is divided:

1. Build and register the spi_device

Add in the Board FileSpi_board_info, which is called in the init function of the Board FileSpi_register_board_info (cloud_spi_devs, array_size (cloud_spi_devs ));

Spi_register_board_info(Cloud_spi_devs, array_size (cloud_spi_devs); // register spi_board_info. This code registers spi_board_info to the linked list board_list. Spi_device encapsulates a spi_master struct. In fact, the registration of spi_master will call scan_boardinfo to scan board_list and find the SPI device attached to it after spi_register_board_info, then create and register the spi_device.

 

2.Build and register 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)// Register spi_driver

 

Spi_register_driver (& m25p80_driver );Spi_deviceCall probe later

 

(3) Implement the probe operation:

 

 

 

 

 

Spi_transfer (which integrates data Buf space addresses and other information)

 

Construction of spi_message (a collection of spi_transfer;

 

Spi_message_init (initialize spi_message)

 

Spi_message_add_tail (Add the new spi_transfer to the end of the spi_message Queue)

 

 

Spi_sync function call (call spi_master to send spi_message)

 

For example:

 

Struct spi_transfer ST = {

 

 

 

.........

 

 

};

 

// Fill in spi_transfer

 

 

Struct spi_message Meg;

 

 

// Define message

 

 

Spi_init_message (& MEG );

 

// Initialize Meg

 

 

Spi_message_add_tail (& St, & MEG );

 

 

// Put the st at the end of the message queue

 

 

Spi_sync (spi_device, & MEG );

 

 

// Associate message with spi_device and send Meg

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.