为啥在/dev目录下不能生成spidev1.0的设备文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为啥在/dev目录下不能生成spidev1.0的设备文件相关的知识,希望对你有一定的参考价值。

参考技术A 在Linux中只有字符设备才有设备号,设备号分为主设备号和次设备号,主设备号是为了区分不同类型的设备,次设备号是为了区分同一类型的不同设备。

说明:注意看c字符开头的文件是字符设备,所以都有主设备号(红框)以及次设备号(绿框)。

linux SPI驱动——spidev之deive

1.定义board设备
   1:  struct spi_board_info {
   2:      /* the device name and module name are 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];
  10:      const void    *platform_data;
  11:      void        *controller_data;
  12:      int        irq;
  13:   
  14:      /* slower signaling on noisy or low voltage boards */
  15:      u32        max_speed_hz;
  16:   
  17:   
  18:      /* bus_num is board specific and matches the bus_num of some
  19:       * spi_master that will probably be registered later.
  20:       *
  21:       * chip_select reflects how this chip is wired to that master;
  22:       * it‘s less than num_chipselect.
  23:       */
  24:      u16        bus_num;
  25:      u16        chip_select;
  26:   
  27:      /* mode becomes spi_device.mode, and is essential for chips
  28:       * where the default of SPI_CS_HIGH = 0 is wrong.
  29:       */
  30:      u8        mode;
  31:   
  32:      /* ... may need additional spi_device chip config data here.
  33:       * avoid stuff protocol drivers can set; but include stuff
  34:       * needed to behave without being bound to a driver:
  35:       *  - quirks like clock rate mattering when not selected
  36:       */
   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,
  10:      },
  11:  };
  12:  int jz_spi0_devs_size = ARRAY_SIZE(jz_spi0_board_info);
 
 
   1:  int __init
   2:  spi_register_board_info(struct spi_board_info const *info, unsigned n)
   3:  {
   4:      struct boardinfo *bi;
   5:      int i;
   6:   
   7:      bi = kzalloc(n * sizeof(*bi), GFP_KERNEL);
   8:      if (!bi)
   9:          return -ENOMEM;
  10:   
  11:      for (i = 0; i < n; i++, bi++, info++) {
  12:          struct spi_master *master;
  13:   
  14:          memcpy(&bi->board_info, info, sizeof(*info));
  15:          mutex_lock(&board_lock);
  16:          list_add_tail(&bi->list, &board_list);
  17:          /* 
  18:              如果master先注册,则执行spi_match_master_to_boardinfo匹配,
  19:              否则在master注册的时候匹配device 
  20:          */
  21:          list_for_each_entry(master, &spi_master_list, list)
  22:              spi_match_master_to_boardinfo(master, &bi->board_info);
  23:          mutex_unlock(&board_lock);
  24:      }
  25:   
  26:      return 0;
  27:  }
   1:  spi_register_board_info(jz_spi0_board_info, jz_spi0_devs_size);

 

总结:

1. list_add_tail(&bi->list, &board_list); 讲board添加在board_list

2.当master已经注册,则通过spi_match_master_to_boardinfo和spi_new_device创建spi device。

以上是关于为啥在/dev目录下不能生成spidev1.0的设备文件的主要内容,如果未能解决你的问题,请参考以下文章

linux在ls /dev/就只有tty这个设备,但是我有两个串口ttyS0和ttyS1,为啥在dev目录下找不到他们呢?

为啥小弟我的linux分区下没有/dev/sda3

linux下fstab文件如下,为啥相应目录系统启动后不能自动挂载?

为啥linux在/dev目录中使用ls -l命令看到有的设备没有主设备号

Linux /dev下各种文件是何时挂载,怎么挂载的?

bat内容DIR*.*/B>目录.txt提取文件目录,为啥生成的 目录.txt 里面没有内容?