DT / Device Tree メモ

  • 呼ぶ側

いわゆるターゲットボード。 init_machine で指定する関数で of_platform_populate を呼ぶ必要がある。 呼ばないと、DTにデータを書いても各ドライバが probeされない。

of_machine_is_compatible

  • 呼ばれる側

いわゆるデバイス。

struct device_node ** of_match_device デバイスのマッチを行う。

static struct of_device_id foo_of_match[] __devinitdata = { 
    { .compatible = "foo-bar", },
    { },
};
...
struct of_device_id id = of_match_device(foo_of_match, &pdev->dev);
  • of_find_matching_node

  • of_address_to_resource(dev->of_node, 0, &res_mem);

  • irq_of_parse_and_map(dev->of_node, 0)

  • of_find_property(dev->of_node, "iwamatsu,timer-alwon", NULL))

  • of_property_read_string_index(dev->of_node, "iwamatsu,hwmods", 0, &oh_name);

  • of_parse_phandle_with_args(np, "list", "#list-cells", 2, &args);

    phandle1: node1 {
        #list-cells = <2>; 
    };  
    
    
    phandle2: node2 {
        #list-cells = <1>; 
    };  
    
    
    node3 {
        list = <&phandle1 1 2 &phandle2 3>;
    };
    

    とあった場合に of_parse_phandle_with_args(np, "list", "#list-cells", 1, &foo); とすると、node2 の list-cells が foo.args_count に入る。 foo.args[0] に 3 が入る。

  • ドライバで使われる関数

  • DT の書き方 ** address-cells アドレス の最大セル数

** interrupt-cells 割り込みの最大セル数

** interrupt

 interrupt-cells = 2;
 interrupts = < 0 2 1 2 >;

とあったら、2つのセルで1個の要素。最初が割り込み番号で、次が割り込みのタイプ。 最初は0 2 なので 割り込み番号0でFALLING_EDGE。