~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/gpio/gpio-mockup-sysfs.sh

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 
  2 # SPDX-License-Identifier: GPL-2.0
  3 
  4 # Overrides functions in gpio-mockup.sh to test using the GPIO SYSFS uAPI
  5 
  6 SYSFS=`grep -w sysfs /proc/mounts | cut -f2 -d' '`
  7 [ -d "$SYSFS" ] || skip "sysfs is not mounted"
  8 
  9 GPIO_SYSFS="${SYSFS}/class/gpio"
 10 [ -d "$GPIO_SYSFS" ] || skip "CONFIG_GPIO_SYSFS is not selected"
 11 
 12 PLATFORM_SYSFS=$SYSFS/devices/platform
 13 
 14 sysfs_nr=
 15 sysfs_ldir=
 16 
 17 # determine the sysfs GPIO number given the $chip and $offset
 18 # e.g. gpiochip1:32
 19 find_sysfs_nr()
 20 {
 21         # e.g. /sys/devices/platform/gpio-mockup.1/gpiochip1
 22         local platform=$(find $PLATFORM_SYSFS -mindepth 2 -maxdepth 2 -type d -name $chip)
 23         [ "$platform" ] || fail "can't find platform of $chip"
 24         # e.g. /sys/devices/platform/gpio-mockup.1/gpio/gpiochip508/base
 25         local base=$(find ${platform%/*}/gpio/ -mindepth 2 -maxdepth 2 -type f -name base)
 26         [ "$base" ] || fail "can't find base of $chip"
 27         sysfs_nr=$(($(< "$base") + $offset))
 28         sysfs_ldir="$GPIO_SYSFS/gpio$sysfs_nr"
 29 }
 30 
 31 acquire_line()
 32 {
 33         [ "$sysfs_nr" ] && return
 34         find_sysfs_nr
 35         echo "$sysfs_nr" > "$GPIO_SYSFS/export"
 36 }
 37 
 38 # The helpers being overridden...
 39 get_line()
 40 {
 41         [ -e "$sysfs_ldir/value" ] && echo $(< "$sysfs_ldir/value")
 42 }
 43 
 44 set_line()
 45 {
 46         acquire_line
 47 
 48         for option in $*; do
 49                 case $option in
 50                 active-high)
 51                         echo 0 > "$sysfs_ldir/active_low"
 52                         ;;
 53                 active-low)
 54                         echo 1 > "$sysfs_ldir/active_low"
 55                         ;;
 56                 input)
 57                         echo "in" > "$sysfs_ldir/direction"
 58                         ;;
 59                 0)
 60                         echo "out" > "$sysfs_ldir/direction"
 61                         echo 0 > "$sysfs_ldir/value"
 62                         ;;
 63                 1)
 64                         echo "out" > "$sysfs_ldir/direction"
 65                         echo 1 > "$sysfs_ldir/value"
 66                         ;;
 67                 esac
 68         done
 69 }
 70 
 71 release_line()
 72 {
 73         [ "$sysfs_nr" ] || return 0
 74         echo "$sysfs_nr" > "$GPIO_SYSFS/unexport"
 75         sysfs_nr=
 76         sysfs_ldir=
 77 }

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php