xref: /openbmc/linux/tools/testing/selftests/gpio/gpio-sim.sh (revision fd5e9fccbd504c5179ab57ff695c610bca8809d6)
11d96b8f6SBartosz Golaszewski#!/bin/sh
21d96b8f6SBartosz Golaszewski# SPDX-License-Identifier: GPL-2.0
31d96b8f6SBartosz Golaszewski# Copyright (C) 2021 Bartosz Golaszewski <brgl@bgdev.pl>
41d96b8f6SBartosz Golaszewski
51d96b8f6SBartosz GolaszewskiBASE_DIR=`dirname $0`
61d96b8f6SBartosz GolaszewskiCONFIGFS_DIR="/sys/kernel/config/gpio-sim"
71d96b8f6SBartosz GolaszewskiMODULE="gpio-sim"
81d96b8f6SBartosz Golaszewski
91d96b8f6SBartosz Golaszewskifail() {
101d96b8f6SBartosz Golaszewski	echo "$*" >&2
111d96b8f6SBartosz Golaszewski	echo "GPIO $MODULE test FAIL"
121d96b8f6SBartosz Golaszewski	exit 1
131d96b8f6SBartosz Golaszewski}
141d96b8f6SBartosz Golaszewski
151d96b8f6SBartosz Golaszewskiskip() {
161d96b8f6SBartosz Golaszewski	echo "$*" >&2
171d96b8f6SBartosz Golaszewski	echo "GPIO $MODULE test SKIP"
181d96b8f6SBartosz Golaszewski	exit 4
191d96b8f6SBartosz Golaszewski}
201d96b8f6SBartosz Golaszewski
211d96b8f6SBartosz Golaszewskiremove_chip() {
221d96b8f6SBartosz Golaszewski	local CHIP=$1
231d96b8f6SBartosz Golaszewski
241d96b8f6SBartosz Golaszewski	for FILE in $CONFIGFS_DIR/$CHIP/*; do
251d96b8f6SBartosz Golaszewski		BANK=`basename $FILE`
2636ccddf8SBartosz Golaszewski		if [ "$BANK" = "live" -o "$BANK" = "dev_name" ]; then
271d96b8f6SBartosz Golaszewski			continue
281d96b8f6SBartosz Golaszewski		fi
291d96b8f6SBartosz Golaszewski
30ba702906STiezhu Yang		LINES=`ls $CONFIGFS_DIR/$CHIP/$BANK/ | grep -E ^line`
31f7eda6feSBartosz Golaszewski		if [ "$?" = 0 ]; then
321d96b8f6SBartosz Golaszewski			for LINE in $LINES; do
331d96b8f6SBartosz Golaszewski				if [ -e $CONFIGFS_DIR/$CHIP/$BANK/$LINE/hog ]; then
341d96b8f6SBartosz Golaszewski					rmdir $CONFIGFS_DIR/$CHIP/$BANK/$LINE/hog || \
351d96b8f6SBartosz Golaszewski						fail "Unable to remove the hog"
361d96b8f6SBartosz Golaszewski				fi
371d96b8f6SBartosz Golaszewski
381d96b8f6SBartosz Golaszewski				rmdir $CONFIGFS_DIR/$CHIP/$BANK/$LINE || \
391d96b8f6SBartosz Golaszewski					fail "Unable to remove the line"
401d96b8f6SBartosz Golaszewski			done
411d96b8f6SBartosz Golaszewski		fi
421d96b8f6SBartosz Golaszewski
431d96b8f6SBartosz Golaszewski		rmdir $CONFIGFS_DIR/$CHIP/$BANK
441d96b8f6SBartosz Golaszewski	done
451d96b8f6SBartosz Golaszewski
461d96b8f6SBartosz Golaszewski	rmdir $CONFIGFS_DIR/$CHIP || fail "Unable to remove the chip"
471d96b8f6SBartosz Golaszewski}
481d96b8f6SBartosz Golaszewski
491d96b8f6SBartosz Golaszewskicreate_chip() {
501d96b8f6SBartosz Golaszewski	local CHIP=$1
511d96b8f6SBartosz Golaszewski
521d96b8f6SBartosz Golaszewski	mkdir $CONFIGFS_DIR/$CHIP
531d96b8f6SBartosz Golaszewski}
541d96b8f6SBartosz Golaszewski
551d96b8f6SBartosz Golaszewskicreate_bank() {
561d96b8f6SBartosz Golaszewski	local CHIP=$1
571d96b8f6SBartosz Golaszewski	local BANK=$2
581d96b8f6SBartosz Golaszewski
591d96b8f6SBartosz Golaszewski	mkdir $CONFIGFS_DIR/$CHIP/$BANK
601d96b8f6SBartosz Golaszewski}
611d96b8f6SBartosz Golaszewski
621d96b8f6SBartosz Golaszewskiset_label() {
631d96b8f6SBartosz Golaszewski	local CHIP=$1
641d96b8f6SBartosz Golaszewski	local BANK=$2
651d96b8f6SBartosz Golaszewski	local LABEL=$3
661d96b8f6SBartosz Golaszewski
671d96b8f6SBartosz Golaszewski	echo $LABEL > $CONFIGFS_DIR/$CHIP/$BANK/label || fail "Unable to set the chip label"
681d96b8f6SBartosz Golaszewski}
691d96b8f6SBartosz Golaszewski
701d96b8f6SBartosz Golaszewskiset_num_lines() {
711d96b8f6SBartosz Golaszewski	local CHIP=$1
721d96b8f6SBartosz Golaszewski	local BANK=$2
731d96b8f6SBartosz Golaszewski	local NUM_LINES=$3
741d96b8f6SBartosz Golaszewski
751d96b8f6SBartosz Golaszewski	echo $NUM_LINES > $CONFIGFS_DIR/$CHIP/$BANK/num_lines || \
761d96b8f6SBartosz Golaszewski		fail "Unable to set the number of lines"
771d96b8f6SBartosz Golaszewski}
781d96b8f6SBartosz Golaszewski
791d96b8f6SBartosz Golaszewskiset_line_name() {
801d96b8f6SBartosz Golaszewski	local CHIP=$1
811d96b8f6SBartosz Golaszewski	local BANK=$2
821d96b8f6SBartosz Golaszewski	local OFFSET=$3
831d96b8f6SBartosz Golaszewski	local NAME=$4
841d96b8f6SBartosz Golaszewski	local LINE_DIR=$CONFIGFS_DIR/$CHIP/$BANK/line$OFFSET
851d96b8f6SBartosz Golaszewski
861d96b8f6SBartosz Golaszewski	test -d $LINE_DIR || mkdir $LINE_DIR
871d96b8f6SBartosz Golaszewski	echo $NAME > $LINE_DIR/name || fail "Unable to set the line name"
881d96b8f6SBartosz Golaszewski}
891d96b8f6SBartosz Golaszewski
901d96b8f6SBartosz Golaszewskienable_chip() {
911d96b8f6SBartosz Golaszewski	local CHIP=$1
921d96b8f6SBartosz Golaszewski
931d96b8f6SBartosz Golaszewski	echo 1 > $CONFIGFS_DIR/$CHIP/live || fail "Unable to enable the chip"
941d96b8f6SBartosz Golaszewski}
951d96b8f6SBartosz Golaszewski
961d96b8f6SBartosz Golaszewskidisable_chip() {
971d96b8f6SBartosz Golaszewski	local CHIP=$1
981d96b8f6SBartosz Golaszewski
991d96b8f6SBartosz Golaszewski	echo 0 > $CONFIGFS_DIR/$CHIP/live || fail "Unable to disable the chip"
1001d96b8f6SBartosz Golaszewski}
1011d96b8f6SBartosz Golaszewski
102*3d9f63e2SKoichiro Denconfigfs_cleanup() {
103*3d9f63e2SKoichiro Den	for CHIP in `ls $CONFIGFS_DIR/`; do
104*3d9f63e2SKoichiro Den		disable_chip $CHIP
105*3d9f63e2SKoichiro Den		remove_chip $CHIP
106*3d9f63e2SKoichiro Den	done
107*3d9f63e2SKoichiro Den}
108*3d9f63e2SKoichiro Den
1091d96b8f6SBartosz Golaszewskiconfigfs_chip_name() {
1101d96b8f6SBartosz Golaszewski	local CHIP=$1
1111d96b8f6SBartosz Golaszewski	local BANK=$2
1121d96b8f6SBartosz Golaszewski
1131d96b8f6SBartosz Golaszewski	cat $CONFIGFS_DIR/$CHIP/$BANK/chip_name 2> /dev/null || \
1141d96b8f6SBartosz Golaszewski		fail "unable to read the chip name from configfs"
1151d96b8f6SBartosz Golaszewski}
1161d96b8f6SBartosz Golaszewski
1171d96b8f6SBartosz Golaszewskiconfigfs_dev_name() {
1181d96b8f6SBartosz Golaszewski	local CHIP=$1
1191d96b8f6SBartosz Golaszewski
1201d96b8f6SBartosz Golaszewski	cat $CONFIGFS_DIR/$CHIP/dev_name 2> /dev/null || \
1211d96b8f6SBartosz Golaszewski		fail "unable to read the device name from configfs"
1221d96b8f6SBartosz Golaszewski}
1231d96b8f6SBartosz Golaszewski
1241d96b8f6SBartosz Golaszewskiget_chip_num_lines() {
1251d96b8f6SBartosz Golaszewski	local CHIP=$1
1261d96b8f6SBartosz Golaszewski	local BANK=$2
1271d96b8f6SBartosz Golaszewski
1281d96b8f6SBartosz Golaszewski	$BASE_DIR/gpio-chip-info /dev/`configfs_chip_name $CHIP $BANK` num-lines || \
1291d96b8f6SBartosz Golaszewski		fail "unable to read the number of lines from the character device"
1301d96b8f6SBartosz Golaszewski}
1311d96b8f6SBartosz Golaszewski
1321d96b8f6SBartosz Golaszewskiget_chip_label() {
1331d96b8f6SBartosz Golaszewski	local CHIP=$1
1341d96b8f6SBartosz Golaszewski	local BANK=$2
1351d96b8f6SBartosz Golaszewski
1361d96b8f6SBartosz Golaszewski	$BASE_DIR/gpio-chip-info /dev/`configfs_chip_name $CHIP $BANK` label || \
1371d96b8f6SBartosz Golaszewski		fail "unable to read the chip label from the character device"
1381d96b8f6SBartosz Golaszewski}
1391d96b8f6SBartosz Golaszewski
1401d96b8f6SBartosz Golaszewskiget_line_name() {
1411d96b8f6SBartosz Golaszewski	local CHIP=$1
1421d96b8f6SBartosz Golaszewski	local BANK=$2
1431d96b8f6SBartosz Golaszewski	local OFFSET=$3
1441d96b8f6SBartosz Golaszewski
1451d96b8f6SBartosz Golaszewski	$BASE_DIR/gpio-line-name /dev/`configfs_chip_name $CHIP $BANK` $OFFSET || \
1461d96b8f6SBartosz Golaszewski		fail "unable to read the line name from the character device"
1471d96b8f6SBartosz Golaszewski}
1481d96b8f6SBartosz Golaszewski
1491d96b8f6SBartosz Golaszewskisysfs_set_pull() {
1501d96b8f6SBartosz Golaszewski	local DEV=$1
1511d96b8f6SBartosz Golaszewski	local BANK=$2
1521d96b8f6SBartosz Golaszewski	local OFFSET=$3
1531d96b8f6SBartosz Golaszewski	local PULL=$4
1541d96b8f6SBartosz Golaszewski	local DEVNAME=`configfs_dev_name $DEV`
1551d96b8f6SBartosz Golaszewski	local CHIPNAME=`configfs_chip_name $DEV $BANK`
15661c65a8bSAndy Shevchenko	local SYSFS_PATH="/sys/devices/platform/$DEVNAME/$CHIPNAME/sim_gpio$OFFSET/pull"
1571d96b8f6SBartosz Golaszewski
15861c65a8bSAndy Shevchenko	echo $PULL > $SYSFS_PATH || fail "Unable to set line pull in sysfs"
1591d96b8f6SBartosz Golaszewski}
1601d96b8f6SBartosz Golaszewski
1611d96b8f6SBartosz Golaszewski# Load the gpio-sim module. This will pull in configfs if needed too.
1621d96b8f6SBartosz Golaszewskimodprobe gpio-sim || skip "unable to load the gpio-sim module"
1631d96b8f6SBartosz Golaszewski# Make sure configfs is mounted at /sys/kernel/config. Wait a bit if needed.
1641d96b8f6SBartosz Golaszewskifor IDX in `seq 5`; do
1651d96b8f6SBartosz Golaszewski	if [ "$IDX" -eq "5" ]; then
1661d96b8f6SBartosz Golaszewski		skip "configfs not mounted at /sys/kernel/config"
1671d96b8f6SBartosz Golaszewski	fi
1681d96b8f6SBartosz Golaszewski
1691d96b8f6SBartosz Golaszewski	mountpoint -q /sys/kernel/config && break
1701d96b8f6SBartosz Golaszewski	sleep 0.1
1711d96b8f6SBartosz Golaszewskidone
1721d96b8f6SBartosz Golaszewski# If the module was already loaded: remove all previous chips
1731d96b8f6SBartosz Golaszewskiconfigfs_cleanup
1741d96b8f6SBartosz Golaszewski
1751d96b8f6SBartosz Golaszewskitrap "exit 1" SIGTERM SIGINT
1761d96b8f6SBartosz Golaszewskitrap configfs_cleanup EXIT
1771d96b8f6SBartosz Golaszewski
1781d96b8f6SBartosz Golaszewskiecho "1. chip_name and dev_name attributes"
1791d96b8f6SBartosz Golaszewski
1801d96b8f6SBartosz Golaszewskiecho "1.1. Chip name is communicated to user"
1811d96b8f6SBartosz Golaszewskicreate_chip chip
1821d96b8f6SBartosz Golaszewskicreate_bank chip bank
1831d96b8f6SBartosz Golaszewskienable_chip chip
1841d96b8f6SBartosz Golaszewskitest -n `cat $CONFIGFS_DIR/chip/bank/chip_name` || fail "chip_name doesn't work"
185*3d9f63e2SKoichiro Dendisable_chip chip
1861d96b8f6SBartosz Golaszewskiremove_chip chip
1871d96b8f6SBartosz Golaszewski
1881d96b8f6SBartosz Golaszewskiecho "1.2. chip_name returns 'none' if the chip is still pending"
1891d96b8f6SBartosz Golaszewskicreate_chip chip
1901d96b8f6SBartosz Golaszewskicreate_bank chip bank
1911d96b8f6SBartosz Golaszewskitest "`cat $CONFIGFS_DIR/chip/bank/chip_name`" = "none" || \
1921d96b8f6SBartosz Golaszewski	fail "chip_name doesn't return 'none' for a pending chip"
1931d96b8f6SBartosz Golaszewskiremove_chip chip
1941d96b8f6SBartosz Golaszewski
1951d96b8f6SBartosz Golaszewskiecho "1.3. Device name is communicated to user"
1961d96b8f6SBartosz Golaszewskicreate_chip chip
1971d96b8f6SBartosz Golaszewskicreate_bank chip bank
1981d96b8f6SBartosz Golaszewskienable_chip chip
1991d96b8f6SBartosz Golaszewskitest -n `cat $CONFIGFS_DIR/chip/dev_name` || fail "dev_name doesn't work"
200*3d9f63e2SKoichiro Dendisable_chip chip
2011d96b8f6SBartosz Golaszewskiremove_chip chip
2021d96b8f6SBartosz Golaszewski
2031d96b8f6SBartosz Golaszewskiecho "2. Creating and configuring simulated chips"
2041d96b8f6SBartosz Golaszewski
2051d96b8f6SBartosz Golaszewskiecho "2.1. Default number of lines is 1"
2061d96b8f6SBartosz Golaszewskicreate_chip chip
2071d96b8f6SBartosz Golaszewskicreate_bank chip bank
2081d96b8f6SBartosz Golaszewskienable_chip chip
2091d96b8f6SBartosz Golaszewskitest "`get_chip_num_lines chip bank`" = "1" || fail "default number of lines is not 1"
210*3d9f63e2SKoichiro Dendisable_chip chip
2111d96b8f6SBartosz Golaszewskiremove_chip chip
2121d96b8f6SBartosz Golaszewski
2131d96b8f6SBartosz Golaszewskiecho "2.2. Number of lines can be specified"
2141d96b8f6SBartosz Golaszewskicreate_chip chip
2151d96b8f6SBartosz Golaszewskicreate_bank chip bank
2161d96b8f6SBartosz Golaszewskiset_num_lines chip bank 16
2171d96b8f6SBartosz Golaszewskienable_chip chip
2181d96b8f6SBartosz Golaszewskitest "`get_chip_num_lines chip bank`" = "16" || fail "number of lines is not 16"
219*3d9f63e2SKoichiro Dendisable_chip chip
2201d96b8f6SBartosz Golaszewskiremove_chip chip
2211d96b8f6SBartosz Golaszewski
2221d96b8f6SBartosz Golaszewskiecho "2.3. Label can be set"
2231d96b8f6SBartosz Golaszewskicreate_chip chip
2241d96b8f6SBartosz Golaszewskicreate_bank chip bank
2251d96b8f6SBartosz Golaszewskiset_label chip bank foobar
2261d96b8f6SBartosz Golaszewskienable_chip chip
2271d96b8f6SBartosz Golaszewskitest "`get_chip_label chip bank`" = "foobar" || fail "label is incorrect"
228*3d9f63e2SKoichiro Dendisable_chip chip
2291d96b8f6SBartosz Golaszewskiremove_chip chip
2301d96b8f6SBartosz Golaszewski
2311d96b8f6SBartosz Golaszewskiecho "2.4. Label can be left empty"
2321d96b8f6SBartosz Golaszewskicreate_chip chip
2331d96b8f6SBartosz Golaszewskicreate_bank chip bank
2341d96b8f6SBartosz Golaszewskienable_chip chip
2351d96b8f6SBartosz Golaszewskitest -z "`cat $CONFIGFS_DIR/chip/bank/label`" || fail "label is not empty"
236*3d9f63e2SKoichiro Dendisable_chip chip
2371d96b8f6SBartosz Golaszewskiremove_chip chip
2381d96b8f6SBartosz Golaszewski
2391d96b8f6SBartosz Golaszewskiecho "2.5. Line names can be configured"
2401d96b8f6SBartosz Golaszewskicreate_chip chip
2411d96b8f6SBartosz Golaszewskicreate_bank chip bank
2421d96b8f6SBartosz Golaszewskiset_num_lines chip bank 16
2431d96b8f6SBartosz Golaszewskiset_line_name chip bank 0 foo
2441d96b8f6SBartosz Golaszewskiset_line_name chip bank 2 bar
2451d96b8f6SBartosz Golaszewskienable_chip chip
2461d96b8f6SBartosz Golaszewskitest "`get_line_name chip bank 0`" = "foo" || fail "line name is incorrect"
2471d96b8f6SBartosz Golaszewskitest "`get_line_name chip bank 2`" = "bar" || fail "line name is incorrect"
248*3d9f63e2SKoichiro Dendisable_chip chip
2491d96b8f6SBartosz Golaszewskiremove_chip chip
2501d96b8f6SBartosz Golaszewski
2511d96b8f6SBartosz Golaszewskiecho "2.6. Line config can remain unused if offset is greater than number of lines"
2521d96b8f6SBartosz Golaszewskicreate_chip chip
2531d96b8f6SBartosz Golaszewskicreate_bank chip bank
2541d96b8f6SBartosz Golaszewskiset_num_lines chip bank 2
2551d96b8f6SBartosz Golaszewskiset_line_name chip bank 5 foobar
2561d96b8f6SBartosz Golaszewskienable_chip chip
2571d96b8f6SBartosz Golaszewskitest "`get_line_name chip bank 0`" = "" || fail "line name is incorrect"
2581d96b8f6SBartosz Golaszewskitest "`get_line_name chip bank 1`" = "" || fail "line name is incorrect"
259*3d9f63e2SKoichiro Dendisable_chip chip
2601d96b8f6SBartosz Golaszewskiremove_chip chip
2611d96b8f6SBartosz Golaszewski
2621d96b8f6SBartosz Golaszewskiecho "2.7. Line configfs directory names are sanitized"
2631d96b8f6SBartosz Golaszewskicreate_chip chip
2641d96b8f6SBartosz Golaszewskicreate_bank chip bank
2651d96b8f6SBartosz Golaszewskimkdir $CONFIGFS_DIR/chip/bank/line12foobar 2> /dev/null && \
2661d96b8f6SBartosz Golaszewski	fail "invalid configfs line name accepted"
2671d96b8f6SBartosz Golaszewskimkdir $CONFIGFS_DIR/chip/bank/line_no_offset 2> /dev/null && \
2681d96b8f6SBartosz Golaszewski	fail "invalid configfs line name accepted"
2691d96b8f6SBartosz Golaszewskiremove_chip chip
2701d96b8f6SBartosz Golaszewski
2711d96b8f6SBartosz Golaszewskiecho "2.8. Multiple chips can be created"
2721d96b8f6SBartosz GolaszewskiCHIPS="chip0 chip1 chip2"
2731d96b8f6SBartosz Golaszewskifor CHIP in $CHIPS; do
2741d96b8f6SBartosz Golaszewski	create_chip $CHIP
2751d96b8f6SBartosz Golaszewski	create_bank $CHIP bank
2761d96b8f6SBartosz Golaszewski	enable_chip $CHIP
2771d96b8f6SBartosz Golaszewskidone
2781d96b8f6SBartosz Golaszewskifor CHIP in $CHIPS; do
279*3d9f63e2SKoichiro Den  disable_chip $CHIP
2801d96b8f6SBartosz Golaszewski	remove_chip $CHIP
2811d96b8f6SBartosz Golaszewskidone
2821d96b8f6SBartosz Golaszewski
2831d96b8f6SBartosz Golaszewskiecho "2.9. Can't modify settings when chip is live"
2841d96b8f6SBartosz Golaszewskicreate_chip chip
2851d96b8f6SBartosz Golaszewskicreate_bank chip bank
2861d96b8f6SBartosz Golaszewskienable_chip chip
2871d96b8f6SBartosz Golaszewskiecho foobar > $CONFIGFS_DIR/chip/bank/label 2> /dev/null && \
2881d96b8f6SBartosz Golaszewski	fail "Setting label of a live chip should fail"
2891d96b8f6SBartosz Golaszewskiecho 8 > $CONFIGFS_DIR/chip/bank/num_lines 2> /dev/null && \
2901d96b8f6SBartosz Golaszewski	fail "Setting number of lines of a live chip should fail"
291*3d9f63e2SKoichiro Dendisable_chip chip
2921d96b8f6SBartosz Golaszewskiremove_chip chip
2931d96b8f6SBartosz Golaszewski
2941d96b8f6SBartosz Golaszewskiecho "2.10. Can't create line items when chip is live"
2951d96b8f6SBartosz Golaszewskicreate_chip chip
2961d96b8f6SBartosz Golaszewskicreate_bank chip bank
2971d96b8f6SBartosz Golaszewskienable_chip chip
2981d96b8f6SBartosz Golaszewskimkdir $CONFIGFS_DIR/chip/bank/line0 2> /dev/null && fail "Creating line item should fail"
299*3d9f63e2SKoichiro Dendisable_chip chip
3001d96b8f6SBartosz Golaszewskiremove_chip chip
3011d96b8f6SBartosz Golaszewski
3021d96b8f6SBartosz Golaszewskiecho "2.11. Probe errors are propagated to user-space"
3031d96b8f6SBartosz Golaszewskicreate_chip chip
3041d96b8f6SBartosz Golaszewskicreate_bank chip bank
3051d96b8f6SBartosz Golaszewskiset_num_lines chip bank 99999
3061d96b8f6SBartosz Golaszewskiecho 1 > $CONFIGFS_DIR/chip/live 2> /dev/null && fail "Probe error was not propagated"
3071d96b8f6SBartosz Golaszewskiremove_chip chip
3081d96b8f6SBartosz Golaszewski
3091d96b8f6SBartosz Golaszewskiecho "2.12. Cannot enable a chip without any GPIO banks"
3101d96b8f6SBartosz Golaszewskicreate_chip chip
3111d96b8f6SBartosz Golaszewskiecho 1 > $CONFIGFS_DIR/chip/live 2> /dev/null && fail "Chip enabled without any GPIO banks"
3121d96b8f6SBartosz Golaszewskiremove_chip chip
3131d96b8f6SBartosz Golaszewski
3141d96b8f6SBartosz Golaszewskiecho "2.13. Duplicate chip labels are not allowed"
3151d96b8f6SBartosz Golaszewskicreate_chip chip
3161d96b8f6SBartosz Golaszewskicreate_bank chip bank0
3171d96b8f6SBartosz Golaszewskiset_label chip bank0 foobar
3181d96b8f6SBartosz Golaszewskicreate_bank chip bank1
3191d96b8f6SBartosz Golaszewskiset_label chip bank1 foobar
3201d96b8f6SBartosz Golaszewskiecho 1 > $CONFIGFS_DIR/chip/live 2> /dev/null && fail "Duplicate chip labels were not rejected"
3211d96b8f6SBartosz Golaszewskiremove_chip chip
3221d96b8f6SBartosz Golaszewski
3231d96b8f6SBartosz Golaszewskiecho "2.14. Lines can be hogged"
3241d96b8f6SBartosz Golaszewskicreate_chip chip
3251d96b8f6SBartosz Golaszewskicreate_bank chip bank
3261d96b8f6SBartosz Golaszewskiset_num_lines chip bank 8
3271d96b8f6SBartosz Golaszewskimkdir -p $CONFIGFS_DIR/chip/bank/line4/hog
3281d96b8f6SBartosz Golaszewskienable_chip chip
3291d96b8f6SBartosz Golaszewski$BASE_DIR/gpio-mockup-cdev -s 1 /dev/`configfs_chip_name chip bank` 4 2> /dev/null && \
3301d96b8f6SBartosz Golaszewski	fail "Setting the value of a hogged line shouldn't succeed"
331*3d9f63e2SKoichiro Dendisable_chip chip
3321d96b8f6SBartosz Golaszewskiremove_chip chip
3331d96b8f6SBartosz Golaszewski
3341d96b8f6SBartosz Golaszewskiecho "3. Controlling simulated chips"
3351d96b8f6SBartosz Golaszewski
3361d96b8f6SBartosz Golaszewskiecho "3.1. Pull can be set over sysfs"
3371d96b8f6SBartosz Golaszewskicreate_chip chip
3381d96b8f6SBartosz Golaszewskicreate_bank chip bank
3391d96b8f6SBartosz Golaszewskiset_num_lines chip bank 8
3401d96b8f6SBartosz Golaszewskienable_chip chip
3411d96b8f6SBartosz Golaszewskisysfs_set_pull chip bank 0 pull-up
3421d96b8f6SBartosz Golaszewski$BASE_DIR/gpio-mockup-cdev /dev/`configfs_chip_name chip bank` 0
3431d96b8f6SBartosz Golaszewskitest "$?" = "1" || fail "pull set incorrectly"
3441d96b8f6SBartosz Golaszewskisysfs_set_pull chip bank 0 pull-down
3451d96b8f6SBartosz Golaszewski$BASE_DIR/gpio-mockup-cdev /dev/`configfs_chip_name chip bank` 1
3461d96b8f6SBartosz Golaszewskitest "$?" = "0" || fail "pull set incorrectly"
347*3d9f63e2SKoichiro Dendisable_chip chip
3481d96b8f6SBartosz Golaszewskiremove_chip chip
3491d96b8f6SBartosz Golaszewski
3501d96b8f6SBartosz Golaszewskiecho "3.2. Pull can be read from sysfs"
3511d96b8f6SBartosz Golaszewskicreate_chip chip
3521d96b8f6SBartosz Golaszewskicreate_bank chip bank
3531d96b8f6SBartosz Golaszewskiset_num_lines chip bank 8
3541d96b8f6SBartosz Golaszewskienable_chip chip
3551d96b8f6SBartosz GolaszewskiDEVNAME=`configfs_dev_name chip`
3561d96b8f6SBartosz GolaszewskiCHIPNAME=`configfs_chip_name chip bank`
3571d96b8f6SBartosz GolaszewskiSYSFS_PATH=/sys/devices/platform/$DEVNAME/$CHIPNAME/sim_gpio0/pull
3581d96b8f6SBartosz Golaszewskitest `cat $SYSFS_PATH` = "pull-down" || fail "reading the pull failed"
3591d96b8f6SBartosz Golaszewskisysfs_set_pull chip bank 0 pull-up
3601d96b8f6SBartosz Golaszewskitest `cat $SYSFS_PATH` = "pull-up" || fail "reading the pull failed"
361*3d9f63e2SKoichiro Dendisable_chip chip
3621d96b8f6SBartosz Golaszewskiremove_chip chip
3631d96b8f6SBartosz Golaszewski
3641d96b8f6SBartosz Golaszewskiecho "3.3. Incorrect input in sysfs is rejected"
3651d96b8f6SBartosz Golaszewskicreate_chip chip
3661d96b8f6SBartosz Golaszewskicreate_bank chip bank
3671d96b8f6SBartosz Golaszewskiset_num_lines chip bank 8
3681d96b8f6SBartosz Golaszewskienable_chip chip
3691d96b8f6SBartosz GolaszewskiDEVNAME=`configfs_dev_name chip`
3701d96b8f6SBartosz GolaszewskiCHIPNAME=`configfs_chip_name chip bank`
3711d96b8f6SBartosz GolaszewskiSYSFS_PATH="/sys/devices/platform/$DEVNAME/$CHIPNAME/sim_gpio0/pull"
3721d96b8f6SBartosz Golaszewskiecho foobar > $SYSFS_PATH 2> /dev/null && fail "invalid input not detected"
373*3d9f63e2SKoichiro Dendisable_chip chip
3741d96b8f6SBartosz Golaszewskiremove_chip chip
3751d96b8f6SBartosz Golaszewski
3761d96b8f6SBartosz Golaszewskiecho "3.4. Can't write to value"
3771d96b8f6SBartosz Golaszewskicreate_chip chip
3781d96b8f6SBartosz Golaszewskicreate_bank chip bank
3791d96b8f6SBartosz Golaszewskienable_chip chip
3801d96b8f6SBartosz GolaszewskiDEVNAME=`configfs_dev_name chip`
3811d96b8f6SBartosz GolaszewskiCHIPNAME=`configfs_chip_name chip bank`
3821d96b8f6SBartosz GolaszewskiSYSFS_PATH="/sys/devices/platform/$DEVNAME/$CHIPNAME/sim_gpio0/value"
3831d96b8f6SBartosz Golaszewskiecho 1 > $SYSFS_PATH 2> /dev/null && fail "writing to 'value' succeeded unexpectedly"
384*3d9f63e2SKoichiro Dendisable_chip chip
3851d96b8f6SBartosz Golaszewskiremove_chip chip
3861d96b8f6SBartosz Golaszewski
3871d96b8f6SBartosz Golaszewskiecho "4. Simulated GPIO chips are functional"
3881d96b8f6SBartosz Golaszewski
3891d96b8f6SBartosz Golaszewskiecho "4.1. Values can be read from sysfs"
3901d96b8f6SBartosz Golaszewskicreate_chip chip
3911d96b8f6SBartosz Golaszewskicreate_bank chip bank
3921d96b8f6SBartosz Golaszewskiset_num_lines chip bank 8
3931d96b8f6SBartosz Golaszewskienable_chip chip
3941d96b8f6SBartosz GolaszewskiDEVNAME=`configfs_dev_name chip`
3951d96b8f6SBartosz GolaszewskiCHIPNAME=`configfs_chip_name chip bank`
3961d96b8f6SBartosz GolaszewskiSYSFS_PATH="/sys/devices/platform/$DEVNAME/$CHIPNAME/sim_gpio0/value"
3971d96b8f6SBartosz Golaszewskitest `cat $SYSFS_PATH` = "0" || fail "incorrect value read from sysfs"
3981d96b8f6SBartosz Golaszewski$BASE_DIR/gpio-mockup-cdev -s 1 /dev/`configfs_chip_name chip bank` 0 &
3991d96b8f6SBartosz Golaszewskisleep 0.1 # FIXME Any better way?
4001d96b8f6SBartosz Golaszewskitest `cat $SYSFS_PATH` = "1" || fail "incorrect value read from sysfs"
4011d96b8f6SBartosz Golaszewskikill $!
402*3d9f63e2SKoichiro Dendisable_chip chip
4031d96b8f6SBartosz Golaszewskiremove_chip chip
4041d96b8f6SBartosz Golaszewski
4051d96b8f6SBartosz Golaszewskiecho "4.2. Bias settings work correctly"
4061d96b8f6SBartosz Golaszewskicreate_chip chip
4071d96b8f6SBartosz Golaszewskicreate_bank chip bank
4081d96b8f6SBartosz Golaszewskiset_num_lines chip bank 8
4091d96b8f6SBartosz Golaszewskienable_chip chip
410976d3c67SMirsad TodorovacDEVNAME=`configfs_dev_name chip`
411976d3c67SMirsad TodorovacCHIPNAME=`configfs_chip_name chip bank`
412976d3c67SMirsad TodorovacSYSFS_PATH="/sys/devices/platform/$DEVNAME/$CHIPNAME/sim_gpio0/value"
4131d96b8f6SBartosz Golaszewski$BASE_DIR/gpio-mockup-cdev -b pull-up /dev/`configfs_chip_name chip bank` 0
4141d96b8f6SBartosz Golaszewskitest `cat $SYSFS_PATH` = "1" || fail "bias setting does not work"
415*3d9f63e2SKoichiro Dendisable_chip chip
4161d96b8f6SBartosz Golaszewskiremove_chip chip
4171d96b8f6SBartosz Golaszewski
4181d96b8f6SBartosz Golaszewskiecho "GPIO $MODULE test PASS"
419