1. 程式人生 > >裝置樹 --驅動和裝置樹互動過程

裝置樹 --驅動和裝置樹互動過程


在裝置樹中定義的資訊。
flash_SY7803:flashlight {
            compatible = "qcom,leds-gpio-flash";   //匹配引數
            status = "okay";
            pinctrl-names = "flash_default";
            pinctrl-0 = <&SY7803_default>;
            qcom,flash-en = <&msm_gpio 31 0>;
            qcom,flash-now = <&msm_gpio 32 0>;
            qcom,op-seq = "flash_en", "flash_now";  
            qcom,torch-seq-val = <0 1>;
            qcom,flash-seq-val = <1 0>;
            linux,name = "flashlight";  //屬性 linux,name  
            linux,default-trigger = "flashlight-trigger";
            };


   在驅動中如何能獲得裝置樹的資訊呢? 是通過node 節點        
  struct device_node *node = pdev->dev.of_node;  //取得node 
              

 涉及到下邊的一些用法,都是用來取得裝置樹中的資訊的

1. int of_property_read_string(struct device_node *np, const char *propname,const char **out_string)

   Find and read a string from a property
   
   rc = of_property_read_string(node, "linux,default-trigger", &temp_str); 
              
  2.
of_get_named_gpio
  of_get_named_gpio(struct device_node *np,const char *propname, int index)
      of_get_named_gpio(node, "qcom,flash-en", 0);
      // 取得的值應當是31


  3.
of_property_read_string
      int of_property_read_string(struct device_node *np, const char *propname,const char **out_string)
      
      rc = of_property_read_string(node, "linux,name", &flash_led->cdev.name);
    //flash_led->cdev.name = flashlight
    

  4.
of_property_read_u32_array
  int of_property_read_u32_array(const struct device_node *np, const char *propname, u32 *out_values,size_t sz)
 
  uint32_t array_flash_seq[2];
  rc = of_property_read_u32_array(node, "qcom,flash-seq-val",array_flash_seq, 2);
     array_flash_seq <1 0>
     

 5
.of_property_read_string_index
 
 int of_property_read_string_index(struct device_node *np, const char *propname,int index, const char **output)
                  
  rc = of_property_read_string_index(node,    "qcom,op-seq", i,     &seq_name);
  //"flash_en", "flash_now"; 
 
  -------------------
  compatible 使用來匹配驅動的
     .of_match_table = led_gpio_flash_of_match,
     
     
     
1. 裝置樹中 compatible
    鍵值對
2.driver中 
 platform_driver 結構體
     probe    
     remove

     of_match_table

     probe 中
     1.通過of函式獲得相關的資源資訊,
     2. 申請引腳資訊  pinctrl
     3.註冊裝置 classdev
     led_classdev_register

明確驅動如何找到裝置樹,然後再驅動中找到相應的程式碼分析就可以了。