SUBSYSTEM=="input", GROUP="input", MODE="0660"
SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660"
SUBSYSTEM=="spidev", GROUP="spi", MODE="0660"
SUBSYSTEM=="*gpiomem*", GROUP="gpio", MODE="0660"
SUBSYSTEM=="rpivid-*", GROUP="video", MODE="0660"
SUBSYSTEM=="gpio", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chgrp -R gpio /sys/class/gpio && chmod -R g=u /sys/class/gpio'"
SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="/bin/sh -c 'chgrp -R gpio /sys%p && chmod -R g=u /sys%p'"
# PWM export results in a "change" action on the pwmchip device (not "add" of a new device), so match actions other than "remove".
SUBSYSTEM=="pwm", ACTION!="remove", PROGRAM="/bin/sh -c 'chgrp -R gpio /sys%p && chmod -R g=u /sys%p'"
KERNEL=="ttyAMA[0-9]*|ttyS[0-9]*", PROGRAM="/bin/sh -c '\
ALIASES=/proc/device-tree/aliases; \
TTYNODE=$$(readlink /sys/class/tty/%k/device | sed -e 's/.*\\//\\/soc\\/serial@/' -e 's/\\..*//' -e 's/@\\\(20\\\|3f\\\|fe\\\)/@7e/' ); \
if [ -e $$ALIASES/console ]; then \
CONSOLENODE=$$(strings $$ALIASES/console); \
if [ $$TTYNODE = $$CONSOLENODE ]; then \
echo 0; \
elif [ -e $$ALIASES/bluetooth ] && [ $$TTYNODE/bluetooth = $$(strings $$ALIASES/bluetooth) ]; then \
echo 1; \
elif [ $$TTYNODE = $$(echo $$CONSOLENODE | sed -e 's/.*\\//\\/soc\\//' -e 's/serial@/serial@10/' ) ]; then \
echo 0; \
elif [ $$TTYNODE = $$(echo $$CONSOLENODE | sed 's/.*rp1\\/serial@/\\/soc\\/serial@1f000/' ) ]; then \
echo 0; \
else \
exit 1; \
fi \
elif [ -e $$ALIASES/serial0 ] && [ $$TTYNODE = $$(strings $$ALIASES/serial0) ]; then \
echo 0; \
elif [ -e $$ALIASES/serial1 ] && [ $$TTYNODE = $$(strings $$ALIASES/serial1) ]; then \
echo 1; \
elif [ -e $$ALIASES/uart0 ] && [ $$TTYNODE = $$(strings $$ALIASES/uart0 | sed 's/.*rp1\\/serial@/\\/soc\\/serial@1f000/' ) ]; then \
echo 0; \
elif [ -e $$ALIASES/uart10 ] && [ $$TTYNODE = $$(strings $$ALIASES/uart10 | sed -e 's/.*\\//\\/soc\\//' -e 's/serial@/serial@10/' ) ]; then \
echo 0; \
else \
exit 1; \
fi \
'", SYMLINK+="serial%c"
ACTION=="add", SUBSYSTEM=="vtconsole", KERNEL=="vtcon1", RUN+="/bin/sh -c '\
if echo RPi-Sense FB | cmp -s /sys/class/graphics/fb0/name; then \
echo 0 > /sys$devpath/bind; \
fi; \
'"