zmatt

gpio-demo.dts (modern dtc)

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