Linux SPI driver--spidev deive (v)

Source: Internet
Author: User

1. Defining Board Devices
   1:  struct spi_board_info {
   2:  /    * The device name and module name is coupled, like platform_bus;
   3:       * "Modalias" is normally the driver name.
   4:       *
   5:       * Platform_data goes to Spi_device.dev.platform_data,
   6:       * Controller_data goes to Spi_device.controller_data,
   7:       * IRQ is copied too
   8:       * /
   9:      char        modalias[spi_name_size];
  Ten:      constvoid    *platform_data;
One   :      void        *controller_data;
int   :              IRQ;
  :  
*   /      * Slower signaling on noisy or low voltage boards * /
  :      u32        max_speed_hz;
  :  
  :  
*   /      * bus_num is board specific and matches the bus_num of some
* Spi_master   that  would     probably be registered later.
*   :       *
  £ º       * Chip_select reflects how the this chip was wired to that master;
  :       * It's less than num_chipselect.
At   :       * /
  :      U16        Bus_num;
  :      U16        Chip_select;
  £ º  
*   /      * mode becomes spi_device.mode, and is essential for chips
  :       * Where the default of Spi_cs_high = 0 is wrong.
  :       * /
  :      u8        mode;
  £ º  
*   /      * Need additional Spi_device chip config data here.
  :       * Avoid stuff protocol drivers can set; but include stuff
* needed to     behave without being bound to a driver:   
*-quirks like clock rate mattering if not  selected   
     *   /  
   1:  /* Add by Xuyonghong for test * /
   2:  struct spi_board_info jz_spi0_board_info[]  = {
   3:      {
   4:          . Modalias               =  "Spidev",
   5:          . Mode                     =  spi_mode_3,
   6:          . max_speed_hz           =  1000000,
   7:          . Controller_data        =  (void *) GPIO_PB (2),
   8:          . Bus_num                =  0,
   9:          . Chip_select            =  0,
  Ten:      },
One   :  };
  :  int jz_spi0_devs_size = array_size (Jz_spi0_board_info);
   1:  int __init
   2:  spi_register_board_info (structconst *info, unsigned n)
   3:  {
   4:      struct boardinfo *bi;
   5:      int i;
   6:  
   7:      sizeof(*BI), Gfp_kernel);
   8:      if (!BI)
   9:          return -enomem;
  Ten:  
One   :  for     (i = 0; i < n; i++, bi++, info++) {
  :          struct spi_master *master;
  :  
  :          sizeof(*info));
  :          mutex_lock (&board_lock);
  :          list_add_tail (&bi->list, &board_list);
  17:          
if master            first registers, then performs a spi_match_master_to_boardinfo match,   
  19:              
  :          * /
  :          list_for_each_entry (master, &spi_master_list, list)
  :              spi_match_master_to_boardinfo (master, &bi->board_info);
At   :          mutex_unlock (&board_lock);
  :      }
  :  
  :      return 0;
  :  }
   1:  spi_register_board_info (Jz_spi0_board_info, jz_spi0_devs_size);

Summarize:

1. List_add_tail (&bi->list, &board_list); Speaking board added in Board_list

2. When Master is already registered, the SPI device is created via Spi_match_master_to_boardinfo and Spi_new_device.

Linux SPI driver--spidev deive (v)

Related Article

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.