zmatt

gpio-demo.dts (raw overlay format)

Jan 21st, 2021
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /dts-v1/;
  2. /plugin/;
  3.  
  4. #include <dt-bindings/board/am335x-bbw-bbb-base.h>
  5. #include <dt-bindings/pinctrl/am33xx.h>
  6. #include <dt-bindings/gpio/gpio.h>
  7.  
  8. / {
  9.     // file identification
  10.     fragment@0 {
  11.         target-path = "/chosen";
  12.         __overlay__ {
  13.             overlays {
  14.                 // XXX change property name to the name of this overlay (excluding .dts file suffix)
  15.                 gpio-demo = __TIMESTAMP__;
  16.             };
  17.         };
  18.     };
  19.  
  20.     // XXX caution: not compatible with cape-universal!
  21.  
  22.     // A udev rule along these lines is recommended to create symlinks in /dev/gpio/
  23.     //
  24.     //  SUBSYSTEM=="subsystem", KERNEL=="gpio", ACTION=="add", \
  25.     //      RUN+="/bin/mkdir -p /dev/gpio"
  26.     //
  27.     //  SUBSYSTEM=="gpio", ACTION=="add", TEST=="value", ATTR{label}!="sysfs", \
  28.     //      RUN+="/bin/ln -sT '/sys/class/gpio/%k' /dev/gpio/%s{label}"
  29.  
  30.     fragment@1 {
  31.         target-path = "/";
  32.         __overlay__ {
  33.             // If you want to use multiple overlays that do gpio configuration, be
  34.             // sure that each uses a different device tree node!
  35.             gpio-demo {
  36.                 compatible = "gpio-of-helper";
  37.  
  38.                 // It is usually not *strictly* required to perform pinmux for
  39.                 // GPIOs since this is typically their default, but it's good
  40.                 // practice to do it anyway since:
  41.                 // 1. it makes *sure* the pinmux is right
  42.                 // 2. you can configure internal pull-up/down
  43.                 // 3. it lets the kernel know the pins are in use
  44.                 pinctrl-names = "default";
  45.                 pinctrl-0 = <&gpio_demo_pins>;
  46.  
  47.                 // Note that gpio numbers for each pin can be found in the
  48.                 // comments in include/bone/black.h
  49.  
  50.                 // input only, active-low; connect button between pin and gnd.
  51.                 // declaring the gpio as ACTIVE_LOW means the value reads as 1
  52.                 // when the button is pressed.
  53.                 button {
  54.                     gpio = <&gpio2 2 GPIO_ACTIVE_LOW>;  // P8.07
  55.                     input;
  56.                 };
  57.  
  58.                 // output only, active-low, initially high (inactive)
  59.                 reset-thing {
  60.                     gpio = <&gpio2 3 GPIO_ACTIVE_LOW>;  // P8.08
  61.                     init-high;
  62.                 };
  63.  
  64.                 // note: GPIO_ACTIVE_LOW inverts the meaning of the value, but it
  65.                 // does not invert the meaning of "init-low" / "init-high" !
  66.  
  67.  
  68.                 // bidirectional, initially input
  69.                 input-bidi {
  70.                     gpio = <&gpio2 5 GPIO_ACTIVE_HIGH>;  // P8.09
  71.                     input;
  72.                     dir-changeable;
  73.                 };
  74.  
  75.                 // bidirectional, initially output, initially low (inactive)
  76.                 output-bidi {
  77.                     gpio = <&gpio2 4 GPIO_ACTIVE_HIGH>;  // P8.10
  78.                     init-low;
  79.                     dir-changeable;
  80.                 };
  81.             };
  82.         };
  83.     };
  84.  
  85.     fragment@2 {
  86.         target = <&am33xx_pinmux>;
  87.         __overlay__ {
  88.             gpio_demo_pins: gpio-demo {
  89.                 pinctrl-single,pins = <
  90.                     BONE_P8_07 (PIN_INPUT_PULLUP | MUX_MODE7 )  // gpio 2.02 / button
  91.                     BONE_P8_08 (PIN_INPUT_PULLUP | MUX_MODE7 )  // gpio 2.03 / reset-thing
  92.                     BONE_P8_09 (PIN_INPUT_PULLUP | MUX_MODE7 )  // gpio 2.05 / input-bidi
  93.                     BONE_P8_10 (PIN_INPUT_PULLUP | MUX_MODE7 )  // gpio 2.04 / output-bidi
  94.                 >;
  95.             };
  96.         };
  97.     };
  98. };
Add Comment
Please, Sign In to add comment