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