1 2 # SPDX-License-Identifier: GPL-2.0 3 4 # Overrides functions in gpio-mockup.sh to tes 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_SYSF 11 12 PLATFORM_SYSFS=$SYSFS/devices/platform 13 14 sysfs_nr= 15 sysfs_ldir= 16 17 # determine the sysfs GPIO number given the $c 18 # e.g. gpiochip1:32 19 find_sysfs_nr() 20 { 21 # e.g. /sys/devices/platform/gpio-mock 22 local platform=$(find $PLATFORM_SYSFS 23 [ "$platform" ] || fail "can't find pl 24 # e.g. /sys/devices/platform/gpio-mock 25 local base=$(find ${platform%/*}/gpio/ 26 [ "$base" ] || fail "can't find base o 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 $(< 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/ 52 ;; 53 active-low) 54 echo 1 > "$sysfs_ldir/ 55 ;; 56 input) 57 echo "in" > "$sysfs_ld 58 ;; 59 0) 60 echo "out" > "$sysfs_l 61 echo 0 > "$sysfs_ldir/ 62 ;; 63 1) 64 echo "out" > "$sysfs_l 65 echo 1 > "$sysfs_ldir/ 66 ;; 67 esac 68 done 69 } 70 71 release_line() 72 { 73 [ "$sysfs_nr" ] || return 0 74 echo "$sysfs_nr" > "$GPIO_SYSFS/unexpo 75 sysfs_nr= 76 sysfs_ldir= 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.