linux设备树of常用API
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                linux设备树of常用API
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                以下是一個tinker board 2s使用的完整的設備樹文件,路徑為 arch/arm64/boot/dts/rockchip/rk3399-tinker_board_2.dts
/** Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd** This file is dual-licensed: you can use it either under the terms* of the GPL or the X11 license, at your option. Note that this dual* licensing only applies to this file, and not this project as a* whole.** a) This file is free software; you can redistribute it and/or* modify it under the terms of the GNU General Public License as* published by the Free Software Foundation; either version 2 of the* License, or (at your option) any later version.** This file is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** Or, alternatively,** b) Permission is hereby granted, free of charge, to any person* obtaining a copy of this software and associated documentation* files (the "Software"), to deal in the Software without* restriction, including without limitation the rights to use,* copy, modify, merge, publish, distribute, sublicense, and/or* sell copies of the Software, and to permit persons to whom the* Software is furnished to do so, subject to the following* conditions:** The above copyright notice and this permission notice shall be* included in all copies or substantial portions of the Software.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR* OTHER DEALINGS IN THE SOFTWARE.*//dts-v1/;#include "rk3399-tinker_board_2.dtsi" #include <dt-bindings/input/input.h>/ {model = "ASUS Tinker Board 2 (Linux Opensource)";compatible = "rockchip,rk3399-tinker_board_2", "rockchip,rk3399";vcc_lcd: vcc-lcd {compatible = "regulator-fixed";regulator-name = "vcc_lcd";gpio = <&gpio4 30 GPIO_ACTIVE_HIGH>;startup-delay-us = <20000>;enable-active-high;regulator-min-microvolt = <3300000>;regulator-max-microvolt = <3300000>;regulator-boot-on;vin-supply = <&vcc5v0_sys>;};vccadc_ref: vccadc-ref {compatible = "regulator-fixed";regulator-name = "vcc1v8_sys";regulator-always-on;regulator-boot-on;regulator-min-microvolt = <1800000>;regulator-max-microvolt = <1800000>;};adc_keys: adc-keys {compatible = "adc-keys";io-channels = <&saradc 1>;io-channel-names = "buttons";poll-interval = <100>;keyup-threshold-microvolt = <1800000>;esc-key {linux,code = <KEY_ESC>;label = "esc";press-threshold-microvolt = <1310000>;};menu-key {linux,code = <KEY_MENU>;label = "menu";press-threshold-microvolt = <987000>;};vol-down-key {linux,code = <KEY_VOLUMEDOWN>;label = "volume down";press-threshold-microvolt = <300000>;};vol-up-key {linux,code = <KEY_VOLUMEUP>;label = "volume up";press-threshold-microvolt = <17000>;};};gpio_keys: gpio-keys {compatible = "gpio-keys";#address-cells = <1>;#size-cells = <0>;autorepeat;pinctrl-names = "default";pinctrl-0 = <&pwrbtn>;button@0 {gpios = <&gpio0 5 GPIO_ACTIVE_LOW>;linux,code = <KEY_POWER>;label = "GPIO Key Power";linux,input-type = <1>;gpio-key,wakeup = <1>;debounce-interval = <100>;};};ext_cam_clk: external-camera-clock {compatible = "fixed-clock";clock-frequency = <27000000>;clock-output-names = "CLK_CAMERA_27MHZ";#clock-cells = <0>;};/delete-node/ rt5651-sound;rt5651_sound: rt5651-sound {compatible = "rockchip,multicodecs-card";rockchip,card-name = "realtek,rt5651-codec";rockchip,codec-hp-det;rockchip,mclk-fs = <256>;rockchip,cpu = <&i2s0>;rockchip,codec = <&rt5651>;status = "okay";};test_power: test-power {status = "okay";};gpio-leds {compatible = "gpio-leds";pwr-led {gpios = <&gpio0 RK_PA4 GPIO_ACTIVE_HIGH>;linux,default-trigger = "default-on";retain-state-suspended = <1>;};act-led {gpios = <&gpio0 RK_PA3 GPIO_ACTIVE_HIGH>;linux,default-trigger="mmc0";};rsv-led {gpios = <&gpio0 RK_PB2 GPIO_ACTIVE_HIGH>;linux,default-trigger="none";};};board_info: board-info {compatible = "board-info";hw-id0 = <&gpio4 RK_PA7 GPIO_ACTIVE_HIGH>;hw-id1 = <&gpio4 RK_PA6 GPIO_ACTIVE_HIGH>;hw-id2 = <&gpio4 RK_PA5 GPIO_ACTIVE_HIGH>;pid-id0 = <&gpio2 RK_PA5 GPIO_ACTIVE_HIGH>;pid-id1 = <&gpio2 RK_PA3 GPIO_ACTIVE_HIGH>;pid-id2 = <&gpio2 RK_PA2 GPIO_ACTIVE_HIGH>;ddr-id1 = <&gpio4 RK_PA4 GPIO_ACTIVE_HIGH>;ddr-id2 = <&gpio4 RK_PA0 GPIO_ACTIVE_HIGH>;pmic-reset = <&gpio1 RK_PA6 GPIO_ACTIVE_HIGH>;}; };&pinctrl {pinctrl-names = "default";pinctrl-0 = <&gpio_init &test_clkout2>;gpio_init_config {gpio_init: gpio_init {rockchip,pins =<1 7 0 &pcfg_pull_none>,<1 8 0 &pcfg_pull_none>,<1 9 0 &pcfg_pull_none>,<1 10 0 &pcfg_pull_none>,<2 19 0 &pcfg_pull_none>;};};testclk {test_clkout2: test-clkout2 {rockchip,pins =<0 8 RK_FUNC_3 &pcfg_pull_none>;};}; };&pwm0 {status = "disabled"; };&backlight {status = "disabled";compatible = "pwm-backlight";pwms = <&pwm0 0 400000 0>;//f=2500 t=400,000nsbrightness-levels = <0 1 2 3 4 5 6 79 10 11 12 13 14 15 1617 18 19 20 21 22 23 2425 26 27 28 29 30 31 3233 34 35 37 37 38 38 3940 41 42 43 44 45 46 4748 49 50 51 52 53 54 5556 57 58 59 60 61 62 6364 65 66 67 68 69 70 7172 73 74 75 76 77 78 7980 81 82 83 84 85 86 8788 89 90 91 92 93 94 9596 97 98 99 100 101 102 103104 105 106 107 108 109 110 111112 113 114 115 116 117 118 119120 121 122 123 124 125 126 127128 129 130 131 132 133 134 135136 137 138 139 140 141 142 143144 145 146 147 148 149 150 151152 153 154 155 156 157 158 159160 161 162 163 164 165 166 167168 169 170 171 172 173 174 175176 177 178 179 180 181 182 183184 185 186 187 188 189 190 191192 193 194 195 196 197 198 199200 201 202 203 204 205 206 207208 209 210 211 212 213 214 215216 217 218 219 220 221 222 223224 225 226 227 228 229 230 231232 233 234 235 236 237 238 239240 241 242 243 244 245 246 247248 249 250 251 252 253 254 255>;default-brightness-level = <200>;minimal-brightness-level = <26>;soc_enablekl-gpios = <&gpio1 RK_PB0 GPIO_ACTIVE_HIGH>;enable_delay = <15>;disable_delay = <5>;pinctrl-names = "default";pinctrl-0 = <&pinctrl_lvds_bl_en>; };&display_subsystem {status = "okay"; };&dsi {status = "okay";mipi_panel: mipi-panel {compatible ="asus-dsi-panel";reg = <0>;status = "okay";};port@2 {mipi_dsi_out: endpoint3 {remote-endpoint = <&sn65dsi84_in>;};};port@3 {mipi_dsi_to_edp_out: endpoint {remote-endpoint = <&sn65dsi86_in>;};}; };&dsi_in_vopb {status = "disabled"; };&edp {status = "disabled"; };&edp_in_vopb {status = "disabled"; };&edp_in_vopl {status = "disabled"; };&dp_in_vopb {status = "disabled"; };&hdmi {status = "okay";pinctrl-0 = <&hdmi_i2c_xfer>, <&hdmi_cec>;#sound-dai-cells = <0>;rockchip,phy-table =<74250000 0x8009 0x0004 0x0272>,<165000000 0x802b 0x0004 0x0209>,<297000000 0x8039 0x0005 0x028d>,<594000000 0x8039 0x0000 0x00f6>,<000000000 0x0000 0x0000 0x0000>; };&hdmi_in_vopl {status = "disabled"; };&route_hdmi {status = "okay";connect = <&vopb_out_hdmi>; };&fusb0 {vbus-5v-gpios = <&gpio1 RK_PA3 GPIO_ACTIVE_HIGH>;status = "okay"; };&i2c1 {status = "okay";gsl3673: gsl3673@40 {compatible = "GSL,GSL3673";reg = <0x40>;screen_max_x = <1536>;screen_max_y = <2048>;irq_gpio_number = <&gpio1 20 IRQ_TYPE_LEVEL_LOW>;rst_gpio_number = <&gpio4 22 GPIO_ACTIVE_HIGH>;};imx219: imx219@10 {compatible = "sony,imx219";status = "okay";reg = <0x10>;clocks = <&cru SCLK_CIF_OUT>;clock-names = "xvclk";pinctrl-names = "rockchip,camera_default";pinctrl-0 = <&cif_clkout>;enable-gpios = <&gpio4 RK_PA3 GPIO_ACTIVE_HIGH>;rockchip,camera-module-index = <0>;rockchip,camera-module-facing = "back";rockchip,camera-module-name = "RPi_v21";rockchip,camera-module-lens-name = "default";port {imx219_out: endpoint {remote-endpoint = <&mipi_in_ucam0>;data-lanes = <1 2>;};};};ov5647: ov5647@36 {compatible = "ovti,ov5647";status = "disabled";reg = <0x36>;clocks = <&cru SCLK_CIF_OUT>;clock-names = "xvclk";pinctrl-names = "rockchip,camera_default";pinctrl-0 = <&cif_clkout>;enable-gpios = <&gpio4 RK_PA3 GPIO_ACTIVE_HIGH>;rockchip,camera-module-index = <0>;rockchip,camera-module-facing = "back";rockchip,camera-module-name = "RPi_v13";rockchip,camera-module-lens-name = "default";port {ov5647_out: endpoint {};};}; };&i2c4 {status = "okay";clock-frequency = <400000>; };&i2c2 {status = "okay";i2c-scl-rising-time-ns = <345>;i2c-scl-falling-time-ns = <11>; };&i2c6 {status = "disable"; };&i2c7 {status = "disable"; };&i2c8 {status = "okay";m24c08@50 {compatible = "at,24c08";reg = <0x50>;};dsi_edp_bridge: sn65dsi86@2d {compatible = "asus,sn65dsi86";status = "disabled";reg = <0x2d>;backlight = <&backlight>;edp-width-mm = <344>;edp-height-mm = <193>;data-lanes = <0 1>;lane-polarities = <0 0 0 0>;t1=<0>;t2=<0>;t3=<200>;t4=<20>;t5=<0>;t6=<0>;t7=<0>;t8=<100>;t12= <500>;t14= <15>;t15 = <15>;t16= <15>;t17 = <15>;bpc=<8>;bus-format = <0x100A>;//<MEDIA_BUS_FMT_RGB888_1X24>;dsi,flags = <0x3>;dsi,format = <0>;//MIPI_DSI_FMT_RGB888:dsi-lanes = <4>;pinctrl-names = "default";pinctrl-0 = <&pinctrl_sn65dsi84_en>, <&pinctrl_lvds_vdd_en>, <&pinctrl_sn65dsi84_irq>, <&pinctrl_pwr_source>;//<&pinctrl_lvds_bl_en>;EN-gpios = <&gpio1 RK_PA7 GPIO_ACTIVE_HIGH>;edp_vdd_en-gpios = <&gpio1 RK_PB1 GPIO_ACTIVE_HIGH>;//dsi86_vbl_en-gpios = <&gpio1 RK_PB0 GPIO_ACTIVE_HIGH>;dsi86_irq-gpios = <&gpio1 RK_PB2 GPIO_ACTIVE_HIGH>;pwr_source-gpios = <&gpio0 RK_PA6 GPIO_ACTIVE_HIGH>;display-timings {edp {clock-frequency = <142000000>;hactive = <1920>;vactive = <1080>;hfront-porch = <108>;hsync-len = <48>;hback-porch = <24>;vfront-porch = <10>;vsync-len = <10>;vback-porch = <26>;hsync-active = <0>;vsync-active = <0>;de-active = <1>;pixelclk-active = <0>;};};port {sn65dsi86_in: endpoint2 {remote-endpoint = <&mipi_dsi_to_edp_out>;};};};dsi_lvds_bridge: sn65dsi84@2c {compatible = "asus,sn65dsi84";status = "disabled";reg = <0x2c>;backlight = <&backlight>;lvds-clk-rate = <72000000>;lvds-format = <2>;lvds-bpp = <24>;lvds-width-mm = <476>;lvds-height-mm = <267>;sync_delay = <33>;//dual-link;//test-pattern;t1=<0>;t2=<1>;t3=<500>;t4=<200>;t5=<1>;t6=<0>;t7=<1000>;bpc=<8>;bus-format = <0x100a>;//<MEDIA_BUS_FMT_RGB888_1X24>;dsi,flags = <0x3>;dsi,format = <0>;//MIPI_DSI_FMT_RGB888:dsi-lanes = <4>;pinctrl-names = "default";pinctrl-0 = <&pinctrl_sn65dsi84_en>, <&pinctrl_lvds_vdd_en>, <&pinctrl_sn65dsi84_irq>, <&pinctrl_pwr_source>;//<&pinctrl_lvds_hdmi_sel>/*lvds_hdmi_sel-gpios = <&5 23 GPIO_ACTIVE_HIGH>;*/EN-gpios = <&gpio1 RK_PA7 GPIO_ACTIVE_HIGH>;lvds_vdd_en-gpios = <&gpio1 RK_PB1 GPIO_ACTIVE_HIGH>;dsi84_irq-gpios = <&gpio1 RK_PB2 GPIO_ACTIVE_HIGH>;pwr_source-gpios = <&gpio0 RK_PA6 GPIO_ACTIVE_HIGH>;display-timings {lvds {clock-frequency = <144000000>;hactive = <1920>;vactive = <1080>;hfront-porch = <96>;hback-porch = <96>;hsync-len = <64>;vfront-porch = <8>;vsync-len = <4>;vback-porch = <8>;hsync-active = <0>;vsync-active = <0>;de-active = <1>;pixelclk-active = <0>;};};port {sn65dsi84_in: endpoint2 {remote-endpoint = <&mipi_dsi_out>;};};};tinker_mcu: tinker_mcu@45 {compatible = "tinker_mcu";reg = <0x45>;};tinker_mcu_ili9881c: tinker_mcu_ili9881c@36 {compatible = "tinker_mcu_ili9881c";reg = <0x36>;};tinker_ft5406: tinker_ft5406@38 {compatible = "tinker_ft5406";reg = <0x38>;}; };&spi1 {status = "disable";max-freq = <48000000>; /* spi internal clk, don't modify */spi_dev@0 {compatible = "rockchip,spidev";reg = <0>;spi-max-frequency = <48000000>;spi-lsb-first;}; };&spi5 {status = "disable";max-freq = <48000000>; //spi internal clk, don't modifyspi_dev@0 {compatible = "rockchip,spidev";reg = <0>; //chip select 0:cs0 1:cs1id = <0>;spi-max-frequency = <48000000>; //spi output clock}; };&uart0 {status = "disable"; };&uart4 {status = "disable"; };&pwm1 {status = "disable"; };&pwm3 {status = "disable"; };&iep {status = "okay"; };&iep_mmu {status = "okay"; };&isp0_mmu {status = "okay"; };&isp1_mmu {status = "disabled"; };&mipi_dphy_rx0 {status = "okay";ports {#address-cells = <1>;#size-cells = <0>;port@0 {reg = <0>;#address-cells = <1>;#size-cells = <0>;mipi_in_ucam0: endpoint@1 {reg = <1>;remote-endpoint = <&imx219_out>;data-lanes = <1 2>;};};port@1 {reg = <1>;#address-cells = <1>;#size-cells = <0>;dphy_rx0_out: endpoint@0 {reg = <0>;remote-endpoint = <&isp0_mipi_in>;};};}; };&mipi_dphy_tx1rx1 {status = "disabled";ports {#address-cells = <1>;#size-cells = <0>;port@0 {reg = <0>;#address-cells = <1>;#size-cells = <0>;mipi_in_ucam1: endpoint@1 {reg = <1>;/* Unlinked camera *///remote-endpoint = <&ucam_out1>;data-lanes = <1 2>;};};port@1 {reg = <1>;#address-cells = <1>;#size-cells = <0>;dphy_tx1rx1_out: endpoint@0 {reg = <0>;remote-endpoint = <&isp1_mipi_in>;};};}; };&pcie_phy {status = "okay"; };&pcie0 {status = "okay"; };&rkisp1_0 {status = "okay";port {#address-cells = <1>;#size-cells = <0>;isp0_mipi_in: endpoint@0 {reg = <0>;remote-endpoint = <&dphy_rx0_out>;};}; };&rkisp1_1 {status = "disabled";port {#address-cells = <1>;#size-cells = <0>;isp1_mipi_in: endpoint@0 {reg = <0>;remote-endpoint = <&dphy_tx1rx1_out>;};}; };&route_edp {status = "disabled"; };&saradc {vref-supply = <&vccadc_ref>; };&sdmmc {sd-uhs-sdr12;sd-uhs-sdr25;sd-uhs-sdr50;sd-uhs-sdr104;supports-emmc; };&vopb {assigned-clocks = <&cru DCLK_VOP0_DIV>;assigned-clock-parents = <&cru PLL_VPLL>;status = "okay"; };&vopb_mmu {status = "okay"; };&vopl {assigned-clocks = <&cru DCLK_VOP1_DIV>;assigned-clock-parents = <&cru PLL_CPLL>;status = "okay"; };&vopl_mmu {status = "okay"; };&rockchip_suspend {status = "okay";rockchip,wakeup-config = <(0| RKPM_GPIO_WKUP_EN| RKPM_PWM_WKUP_EN| RKPM_USB_WKUP_EN| RKPM_USB_LINESTATE_WKUP_EN)>; };&pinctrl {buttons {pwrbtn: pwrbtn {rockchip,pins = <0 5 RK_FUNC_GPIO &pcfg_pull_up>;};};mipi_to_lvds {/*pinctrl_lvds_hdmi_sel: lvds_hdmi_sel {rockchip,pins = <0 5 RK_FUNC_GPIO &pcfg_pull_none>;};*/pinctrl_sn65dsi84_irq: sn65dsi84_irq{rockchip,pins = <1 RK_PB2 RK_FUNC_GPIO &pcfg_pull_none>;};pinctrl_sn65dsi84_en: sn65dsi84_en {rockchip,pins = <1 RK_PA7 RK_FUNC_GPIO &pcfg_pull_none>;};pinctrl_lvds_bl_en: lvds_bl_en {rockchip,pins = <1 RK_PB0 RK_FUNC_GPIO &pcfg_pull_none>;};pinctrl_lvds_vdd_en: lvds_vdd_en {rockchip,pins = <1 RK_PB1 RK_FUNC_GPIO &pcfg_pull_none>;};pinctrl_pwr_source: pwr_source {rockchip,pins = <0 RK_PA6 RK_FUNC_GPIO &pcfg_pull_none>;};}; };&fiq_debugger {rockchip,baudrate = <115200>; };/* DON'T PUT ANYTHING BELOW HERE. PUT IT ABOVE PINCTRL */ /* DON'T PUT ANYTHING BELOW HERE. PUT IT ABOVE PINCTRL */ /* DON'T PUT ANYTHING BELOW HERE. PUT IT ABOVE PINCTRL */常用的API 有:
 找這個節點
 test_device_node = of_find_node_by_path(“/adc-keys”); //在設備樹節點中查//找test這個節點
 孩子個數
 ret=of_get_child_count(test_device_node);
屬性是否存在
if(**of_property_read_bool**(test_device_node,"enable-active-high")){printk("enable-active-high\n");};如果屬性是string類型的,讀取它。
 ret = of_property_read_string(test_device_node, “compatible”, &str);
數字類型的
 ret = of_property_read_u32(test_device_node, “startup-delay-us”, out_values);
孩子數目:
 count =of_get_child_count(np);
第一個孩子:
 child = of_get_next_child(np, NULL);
總結
以上是生活随笔為你收集整理的linux设备树of常用API的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Hisi内核线程CPU占用高的问题
- 下一篇: 定量预测方法总结及案例实践
