122f6592bSBamvor Jian Zhang 2*b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 322f6592bSBamvor Jian Zhangis_consistent() 422f6592bSBamvor Jian Zhang{ 522f6592bSBamvor Jian Zhang val= 622f6592bSBamvor Jian Zhang 722f6592bSBamvor Jian Zhang active_low_sysfs=`cat $GPIO_SYSFS/gpio$nr/active_low` 822f6592bSBamvor Jian Zhang val_sysfs=`cat $GPIO_SYSFS/gpio$nr/value` 922f6592bSBamvor Jian Zhang dir_sysfs=`cat $GPIO_SYSFS/gpio$nr/direction` 1022f6592bSBamvor Jian Zhang 1122f6592bSBamvor Jian Zhang gpio_this_debugfs=`cat $GPIO_DEBUGFS |grep "gpio-$nr" | sed "s/(.*)//g"` 1222f6592bSBamvor Jian Zhang dir_debugfs=`echo $gpio_this_debugfs | awk '{print $2}'` 1322f6592bSBamvor Jian Zhang val_debugfs=`echo $gpio_this_debugfs | awk '{print $3}'` 1422f6592bSBamvor Jian Zhang if [ $val_debugfs = "lo" ]; then 1522f6592bSBamvor Jian Zhang val=0 1622f6592bSBamvor Jian Zhang elif [ $val_debugfs = "hi" ]; then 1722f6592bSBamvor Jian Zhang val=1 1822f6592bSBamvor Jian Zhang fi 1922f6592bSBamvor Jian Zhang 2022f6592bSBamvor Jian Zhang if [ $active_low_sysfs = "1" ]; then 2122f6592bSBamvor Jian Zhang if [ $val = "0" ]; then 2222f6592bSBamvor Jian Zhang val="1" 2322f6592bSBamvor Jian Zhang else 2422f6592bSBamvor Jian Zhang val="0" 2522f6592bSBamvor Jian Zhang fi 2622f6592bSBamvor Jian Zhang fi 2722f6592bSBamvor Jian Zhang 2822f6592bSBamvor Jian Zhang if [ $val_sysfs = $val ] && [ $dir_sysfs = $dir_debugfs ]; then 2922f6592bSBamvor Jian Zhang echo -n "." 3022f6592bSBamvor Jian Zhang else 3122f6592bSBamvor Jian Zhang echo "test fail, exit" 3222f6592bSBamvor Jian Zhang die 3322f6592bSBamvor Jian Zhang fi 3422f6592bSBamvor Jian Zhang} 3522f6592bSBamvor Jian Zhang 3622f6592bSBamvor Jian Zhangtest_pin_logic() 3722f6592bSBamvor Jian Zhang{ 3822f6592bSBamvor Jian Zhang nr=$1 3922f6592bSBamvor Jian Zhang direction=$2 4022f6592bSBamvor Jian Zhang active_low=$3 4122f6592bSBamvor Jian Zhang value=$4 4222f6592bSBamvor Jian Zhang 4322f6592bSBamvor Jian Zhang echo $direction > $GPIO_SYSFS/gpio$nr/direction 4422f6592bSBamvor Jian Zhang echo $active_low > $GPIO_SYSFS/gpio$nr/active_low 4522f6592bSBamvor Jian Zhang if [ $direction = "out" ]; then 4622f6592bSBamvor Jian Zhang echo $value > $GPIO_SYSFS/gpio$nr/value 4722f6592bSBamvor Jian Zhang fi 4822f6592bSBamvor Jian Zhang is_consistent $nr 4922f6592bSBamvor Jian Zhang} 5022f6592bSBamvor Jian Zhang 5122f6592bSBamvor Jian Zhangtest_one_pin() 5222f6592bSBamvor Jian Zhang{ 5322f6592bSBamvor Jian Zhang nr=$1 5422f6592bSBamvor Jian Zhang 5522f6592bSBamvor Jian Zhang echo -n "test pin<$nr>" 5622f6592bSBamvor Jian Zhang 5722f6592bSBamvor Jian Zhang echo $nr > $GPIO_SYSFS/export 2>/dev/null 5822f6592bSBamvor Jian Zhang 5922f6592bSBamvor Jian Zhang if [ X$? != X0 ]; then 6022f6592bSBamvor Jian Zhang echo "test GPIO pin $nr failed" 6122f6592bSBamvor Jian Zhang die 6222f6592bSBamvor Jian Zhang fi 6322f6592bSBamvor Jian Zhang 6422f6592bSBamvor Jian Zhang #"Checking if the sysfs is consistent with debugfs: " 6522f6592bSBamvor Jian Zhang is_consistent $nr 6622f6592bSBamvor Jian Zhang 6722f6592bSBamvor Jian Zhang #"Checking the logic of active_low: " 6822f6592bSBamvor Jian Zhang test_pin_logic $nr out 1 1 6922f6592bSBamvor Jian Zhang test_pin_logic $nr out 1 0 7022f6592bSBamvor Jian Zhang test_pin_logic $nr out 0 1 7122f6592bSBamvor Jian Zhang test_pin_logic $nr out 0 0 7222f6592bSBamvor Jian Zhang 7322f6592bSBamvor Jian Zhang #"Checking the logic of direction: " 7422f6592bSBamvor Jian Zhang test_pin_logic $nr in 1 1 7522f6592bSBamvor Jian Zhang test_pin_logic $nr out 1 0 7622f6592bSBamvor Jian Zhang test_pin_logic $nr low 0 1 7722f6592bSBamvor Jian Zhang test_pin_logic $nr high 0 0 7822f6592bSBamvor Jian Zhang 7922f6592bSBamvor Jian Zhang echo $nr > $GPIO_SYSFS/unexport 8022f6592bSBamvor Jian Zhang 8122f6592bSBamvor Jian Zhang echo "successful" 8222f6592bSBamvor Jian Zhang} 8322f6592bSBamvor Jian Zhang 8422f6592bSBamvor Jian Zhangtest_one_pin_fail() 8522f6592bSBamvor Jian Zhang{ 8622f6592bSBamvor Jian Zhang nr=$1 8722f6592bSBamvor Jian Zhang 8822f6592bSBamvor Jian Zhang echo $nr > $GPIO_SYSFS/export 2>/dev/null 8922f6592bSBamvor Jian Zhang 9022f6592bSBamvor Jian Zhang if [ X$? != X0 ]; then 9122f6592bSBamvor Jian Zhang echo "test invalid pin $nr successful" 9222f6592bSBamvor Jian Zhang else 9322f6592bSBamvor Jian Zhang echo "test invalid pin $nr failed" 9422f6592bSBamvor Jian Zhang echo $nr > $GPIO_SYSFS/unexport 2>/dev/null 9522f6592bSBamvor Jian Zhang die 9622f6592bSBamvor Jian Zhang fi 9722f6592bSBamvor Jian Zhang} 9822f6592bSBamvor Jian Zhang 9922f6592bSBamvor Jian Zhanglist_chip() 10022f6592bSBamvor Jian Zhang{ 10122f6592bSBamvor Jian Zhang echo `ls -d $GPIO_DRV_SYSFS/gpiochip* 2>/dev/null` 10222f6592bSBamvor Jian Zhang} 10322f6592bSBamvor Jian Zhang 10422f6592bSBamvor Jian Zhangtest_chip() 10522f6592bSBamvor Jian Zhang{ 10622f6592bSBamvor Jian Zhang chip=$1 10722f6592bSBamvor Jian Zhang name=`basename $chip` 10822f6592bSBamvor Jian Zhang base=`cat $chip/base` 10922f6592bSBamvor Jian Zhang ngpio=`cat $chip/ngpio` 11022f6592bSBamvor Jian Zhang printf "%-10s %-5s %-5s\n" $name $base $ngpio 11122f6592bSBamvor Jian Zhang if [ $ngpio = "0" ]; then 11222f6592bSBamvor Jian Zhang echo "number of gpio is zero is not allowed". 11322f6592bSBamvor Jian Zhang fi 11422f6592bSBamvor Jian Zhang test_one_pin $base 11522f6592bSBamvor Jian Zhang test_one_pin $(($base + $ngpio - 1)) 11622f6592bSBamvor Jian Zhang test_one_pin $((( RANDOM % $ngpio ) + $base )) 11722f6592bSBamvor Jian Zhang} 11822f6592bSBamvor Jian Zhang 11922f6592bSBamvor Jian Zhangtest_chips_sysfs() 12022f6592bSBamvor Jian Zhang{ 12122f6592bSBamvor Jian Zhang gpiochip=`list_chip $module` 12222f6592bSBamvor Jian Zhang if [ X"$gpiochip" = X ]; then 12322f6592bSBamvor Jian Zhang if [ X"$valid" = Xfalse ]; then 12422f6592bSBamvor Jian Zhang echo "successful" 12522f6592bSBamvor Jian Zhang else 12622f6592bSBamvor Jian Zhang echo "fail" 12722f6592bSBamvor Jian Zhang die 12822f6592bSBamvor Jian Zhang fi 12922f6592bSBamvor Jian Zhang else 13022f6592bSBamvor Jian Zhang for chip in $gpiochip; do 13122f6592bSBamvor Jian Zhang test_chip $chip 13222f6592bSBamvor Jian Zhang done 13322f6592bSBamvor Jian Zhang fi 13422f6592bSBamvor Jian Zhang} 13522f6592bSBamvor Jian Zhang 136