From nobody Thu Sep 19 10:34:47 2024 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F01DE189518; Mon, 9 Sep 2024 18:38:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725907099; cv=none; b=q3/ZjUIM1XO4PAh3caxob9/TCM0sf7mAYRR7iUuwwARhiMTe9STiWKGyz8h5xNVivGgJv/JkuMRa8h3pMvSRbwdaUW0hvB24iWdraSaPz0p51X8ngy5nxHJl2lwf1Z8QdmGxlPngG06B44Yq3u4v0cMSd9gCUKYc0JIaXZzLxNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725907099; c=relaxed/simple; bh=V9HT+WFFbtvEODO7OkoAPU0v0W0Jmx2Vc+VBObPr39M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IGtHQaB22+fDjd+yM+tWKpJWSrBdxTqI787fJEGS1onP2ED9YMvneMS9Buldyd5xS1s7374fRcDsx0MZNOo+J24lm3bF9GBb2KodNtUcqpE/vQVuGwq3a70PFw2uknpoe5KYOhaQUdxB5hhNF3WWioeXr4E6JU7lolI1Lo/yEGQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=A+pCizIE; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="A+pCizIE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1725907095; bh=V9HT+WFFbtvEODO7OkoAPU0v0W0Jmx2Vc+VBObPr39M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=A+pCizIEC6YstPQ3l+iqEHe024H211npMNG0BUJmMNDTe4frB3G1Bigc/1YiYXY8w FyuznWXFONgb823F7NQzNTWLbulMhp14dWpwrZSHrWeYap6B2pZmKsPOR9I0KFkjI8 xoZmbHVW3itf5hqCx4TWVR4SA3k1cc6rDkQhym1Lpl2UMvdKTzi2/bktktZZ9hb09F AL10duXmNzRKHTNUz0AhfoA7AbDpVeU31luw5LhzeBfszoIG5WWpPEX0BT/8qVCzlF pODNtPSNigKoWIMdhLyihKTbpIP+f+M8i8jq8G354FlNCiOv/ej7HdET4e6ifYEL2j 1sOgI0iE6th5w== Received: from [192.168.1.95] (pool-100-2-116-133.nycmny.fios.verizon.net [100.2.116.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nfraprado) by bali.collaboradmins.com (Postfix) with ESMTPSA id AB12017E35FD; Mon, 9 Sep 2024 20:38:13 +0200 (CEST) From: =?utf-8?q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= Date: Mon, 09 Sep 2024 14:37:32 -0400 Subject: [PATCH RFC 1/3] pinctrl: mediatek: paris: Expose more configurations to GPIO set_config Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240909-kselftest-gpio-set-get-config-v1-1-16a065afc3c1@collabora.com> References: <20240909-kselftest-gpio-set-get-config-v1-0-16a065afc3c1@collabora.com> In-Reply-To: <20240909-kselftest-gpio-set-get-config-v1-0-16a065afc3c1@collabora.com> To: Sean Wang , Linus Walleij , Matthias Brugger , AngeloGioacchino Del Regno , Bamvor Jian Zhang , Shuah Khan Cc: kernel@collabora.com, linux-mediatek@lists.infradead.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, kernelci@lists.linux.dev, =?utf-8?q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= X-Mailer: b4 0.14.1 Currently the set_config callback in the gpio_chip registered by the pinctrl_paris driver only supports PIN_CONFIG_INPUT_DEBOUNCE, despite many other configurations already being implemented and available through the pinctrl API for configuration of pins by the Devicetree and other drivers. Expose all configurations currently implemented through the GPIO API so they can also be set from userspace, which is particularly useful to allow testing them from userspace. Signed-off-by: N=C3=ADcolas F. R. A. Prado --- drivers/pinctrl/mediatek/pinctrl-paris.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/med= iatek/pinctrl-paris.c index e12316c42698..668f8055a544 100644 --- a/drivers/pinctrl/mediatek/pinctrl-paris.c +++ b/drivers/pinctrl/mediatek/pinctrl-paris.c @@ -255,10 +255,9 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev, return err; } =20 -static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin, +static int mtk_pinconf_set(struct mtk_pinctrl *hw, unsigned int pin, enum pin_config_param param, u32 arg) { - struct mtk_pinctrl *hw =3D pinctrl_dev_get_drvdata(pctldev); const struct mtk_pin_desc *desc; int err =3D -ENOTSUPP; u32 reg; @@ -795,7 +794,7 @@ static int mtk_pconf_group_set(struct pinctrl_dev *pctl= dev, unsigned group, int i, ret; =20 for (i =3D 0; i < num_configs; i++) { - ret =3D mtk_pinconf_set(pctldev, grp->pin, + ret =3D mtk_pinconf_set(hw, grp->pin, pinconf_to_config_param(configs[i]), pinconf_to_config_argument(configs[i])); if (ret < 0) @@ -937,18 +936,19 @@ static int mtk_gpio_set_config(struct gpio_chip *chip= , unsigned int offset, { struct mtk_pinctrl *hw =3D gpiochip_get_data(chip); const struct mtk_pin_desc *desc; - u32 debounce; + enum pin_config_param param =3D pinconf_to_config_param(config); + u32 arg =3D pinconf_to_config_argument(config); =20 desc =3D (const struct mtk_pin_desc *)&hw->soc->pins[offset]; =20 - if (!hw->eint || - pinconf_to_config_param(config) !=3D PIN_CONFIG_INPUT_DEBOUNCE || - desc->eint.eint_n =3D=3D EINT_NA) - return -ENOTSUPP; + if (param =3D=3D PIN_CONFIG_INPUT_DEBOUNCE) { + if (!hw->eint || desc->eint.eint_n =3D=3D EINT_NA) + return -ENOTSUPP; =20 - debounce =3D pinconf_to_config_argument(config); + return mtk_eint_set_debounce(hw->eint, desc->eint.eint_n, arg); + } =20 - return mtk_eint_set_debounce(hw->eint, desc->eint.eint_n, debounce); + return mtk_pinconf_set(hw, offset, param, arg); } =20 static int mtk_build_gpiochip(struct mtk_pinctrl *hw) --=20 2.46.0 From nobody Thu Sep 19 10:34:47 2024 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A63F31898F7; Mon, 9 Sep 2024 18:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725907101; cv=none; b=t4HL7Srx1hc+xJjE0642TWVqTH6jXNYw4WOCq7aFNaZtfFLbX2oByKk8P1BJE714OfTSmjecDnf9VuLN5bKOhCnJSmkHmR4m+EAEyCp4ayrnSdS9Pe1OgpPwLbHaCrrmJMCENJVJkJsrwZf7AuYzzBvXrgQsudGvNbSu77oILRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725907101; c=relaxed/simple; bh=NADRXRk73DSEcKHQQvni0lrWb3AK/hH7vJ+xsFaEuFQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NPQop0By5Q6SrgcVgl09l8XymZx+iEVY7x2rJLscVCQw4sTdFsQ89i3g7isByhmcfpXf4SSKhykBaUKv4qMScPMvXA2Vzum9FMRmFJjEokneRPFq9yKuppDM3N+fT1nK22klEZ/eFZOUK/Ym2UzralLaDukRkMWZYkNCfGePbu0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=MOyVqPcq; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="MOyVqPcq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1725907097; bh=NADRXRk73DSEcKHQQvni0lrWb3AK/hH7vJ+xsFaEuFQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MOyVqPcqOprLfzy/XadLU8XC5fbGGQO9ILN+44UJ7vdDvadezUBuxbfg6endteo2I 4ngJRt9Pe/psTrCGqbHs5Jj2yuzFUo6Z5VLW+i944LZy/tEylnfVCDx51TqCxoMHoX pZeE0h8ej9VzktzoGE66zSZKXLEOyrw9oyQNp7kDbRiq83xI3vHjXYpMqDZUnv7EUB MthblXGFoaEM8MTt7WanuicQ/DPHKMqNl3C1e7j+WFBtxMz6iuFyIUY/quSwqc9MEk /eDtiM8FfrvIAboZc8bdR5NjWZzSyrCTuUptoWQY6/8JtmwnBDhUHGdQzD5R9l6u57 Q2ALrQ9fqVriw== Received: from [192.168.1.95] (pool-100-2-116-133.nycmny.fios.verizon.net [100.2.116.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nfraprado) by bali.collaboradmins.com (Postfix) with ESMTPSA id 82F8917E35FF; Mon, 9 Sep 2024 20:38:15 +0200 (CEST) From: =?utf-8?q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= Date: Mon, 09 Sep 2024 14:37:33 -0400 Subject: [PATCH RFC 2/3] selftest: gpio: Add wait flag to gpio-mockup-cdev Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240909-kselftest-gpio-set-get-config-v1-2-16a065afc3c1@collabora.com> References: <20240909-kselftest-gpio-set-get-config-v1-0-16a065afc3c1@collabora.com> In-Reply-To: <20240909-kselftest-gpio-set-get-config-v1-0-16a065afc3c1@collabora.com> To: Sean Wang , Linus Walleij , Matthias Brugger , AngeloGioacchino Del Regno , Bamvor Jian Zhang , Shuah Khan Cc: kernel@collabora.com, linux-mediatek@lists.infradead.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, kernelci@lists.linux.dev, =?utf-8?q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= X-Mailer: b4 0.14.1 Add a -w flag to the gpio-mockup-cdev utility that causes the program to wait until a signal is received before exiting, even when its behavior is to retrieve the GPIO value of the line. This allows using this utility to keep a GPIO line configured even when in input mode, which will be relied on in other tests. Signed-off-by: N=C3=ADcolas F. R. A. Prado --- tools/testing/selftests/gpio/gpio-mockup-cdev.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/gpio/gpio-mockup-cdev.c b/tools/testin= g/selftests/gpio/gpio-mockup-cdev.c index d1640f44f8ac..f674dcafa60a 100644 --- a/tools/testing/selftests/gpio/gpio-mockup-cdev.c +++ b/tools/testing/selftests/gpio/gpio-mockup-cdev.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 #define CONSUMER "gpio-mockup-cdev" =20 @@ -95,6 +96,7 @@ static void usage(char *prog) printf(" (default is to leave bias unchanged):\n"); printf(" -l: set line active low (default is active high)\n"); printf(" -s: set line value (default is to get line value)\n"); + printf(" -w: wait even in get mode\n"); printf(" -u: uAPI version to use (default is 2)\n"); exit(-1); } @@ -120,13 +122,14 @@ int main(int argc, char *argv[]) unsigned int offset, val =3D 0, abiv; uint32_t flags_v1; uint64_t flags_v2; + bool wait =3D false; =20 abiv =3D 2; ret =3D 0; flags_v1 =3D GPIOHANDLE_REQUEST_INPUT; flags_v2 =3D GPIO_V2_LINE_FLAG_INPUT; =20 - while ((opt =3D getopt(argc, argv, "lb:s:u:")) !=3D -1) { + while ((opt =3D getopt(argc, argv, "lb:s:u:w")) !=3D -1) { switch (opt) { case 'l': flags_v1 |=3D GPIOHANDLE_REQUEST_ACTIVE_LOW; @@ -150,10 +153,14 @@ int main(int argc, char *argv[]) flags_v1 |=3D GPIOHANDLE_REQUEST_OUTPUT; flags_v2 &=3D ~GPIO_V2_LINE_FLAG_INPUT; flags_v2 |=3D GPIO_V2_LINE_FLAG_OUTPUT; + wait =3D true; break; case 'u': abiv =3D atoi(optarg); break; + case 'w': + wait =3D true; + break; default: usage(argv[0]); } @@ -183,9 +190,10 @@ int main(int argc, char *argv[]) return lfd; } =20 - if (flags_v2 & GPIO_V2_LINE_FLAG_OUTPUT) { + if (wait) wait_signal(); - } else { + + if (flags_v2 & GPIO_V2_LINE_FLAG_INPUT) { if (abiv =3D=3D 1) ret =3D get_value_v1(lfd); else --=20 2.46.0 From nobody Thu Sep 19 10:34:47 2024 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28D8B189BAA; Mon, 9 Sep 2024 18:38:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725907104; cv=none; b=qwTc6s83cIl5o7+Cm/RQgCAcedIf/jukL9hevmvivhJ22dsuAju45Rm7XqN+C9qalEH/JGksmmmuWCdS211ncREIrlnvdeXGy05tu6Fo7bD7eD7e4gSQSRVIZSJDOb1TEfbE33SZpiGX4jWbjd3Iv3WmSeNpFWXXrs3UK7/8KZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725907104; c=relaxed/simple; bh=06a+4+u7GgI0QOGqHjtSNwrz0XvKnxfVsRzsa0GxZXA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VoxzQp42VfqOUviAhrl36LXueFvbrM29/wcv2E8rI+/VQE49uChAAxlMm1OwxJcsJIwQe5tqppIqaKXc2Ytfkt7xm5Y9nU0caB3mhE4KqcgsQ0qI3j2zKTzzr3Ne9TeoHSXI1rrDlASKtCY0OKFEsuo45uwgfEl0DmBgaoFUJoE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=VpO41KD6; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="VpO41KD6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1725907100; bh=06a+4+u7GgI0QOGqHjtSNwrz0XvKnxfVsRzsa0GxZXA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VpO41KD6gqD1fnD/XmWiO/f9v/wYAB7kZzmGbisUcBxy8NsZbKkfSvao9jsKWT9fZ ZIKN+L5pq03dlswz3a760hJF7mmvKLXPVoDcjh6BAsJyo5pGlQfxWB7yGWDnhA8QRL OxgjItYSkoJt5i4YbXbhUJNZfae6AjQQ6SLBV27E6Efg1FaRX+K2dhgiA1wGnyG0f+ 7glAFNub8F75u6FM6NpyfZ887qKLrCSkOL2m0CTQoaajUdQwo1eEsFNFH4bcJPvRtA fpvdWwICebJtMlZVUgD/ciJnUrexoSsgyyXEauSuD9fmejysE6yZhhTXeqckSYWyAd cm1AqwQQZsukw== Received: from [192.168.1.95] (pool-100-2-116-133.nycmny.fios.verizon.net [100.2.116.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nfraprado) by bali.collaboradmins.com (Postfix) with ESMTPSA id 6937217E35FB; Mon, 9 Sep 2024 20:38:18 +0200 (CEST) From: =?utf-8?q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= Date: Mon, 09 Sep 2024 14:37:34 -0400 Subject: [PATCH RFC 3/3] selftest: gpio: Add a new set-get config test Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240909-kselftest-gpio-set-get-config-v1-3-16a065afc3c1@collabora.com> References: <20240909-kselftest-gpio-set-get-config-v1-0-16a065afc3c1@collabora.com> In-Reply-To: <20240909-kselftest-gpio-set-get-config-v1-0-16a065afc3c1@collabora.com> To: Sean Wang , Linus Walleij , Matthias Brugger , AngeloGioacchino Del Regno , Bamvor Jian Zhang , Shuah Khan Cc: kernel@collabora.com, linux-mediatek@lists.infradead.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, kernelci@lists.linux.dev, =?utf-8?q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= X-Mailer: b4 0.14.1 Add a new kselftest that sets a configuration to a GPIO line and then gets it back to verify that it was correctly carried out by the driver. Setting a configuration is done through the GPIO uAPI, but retrieving it is done through the debugfs interface since that is the only place where it can be retrieved from userspace. The test reads the test plan from a YAML file, which includes the chips and pin settings to set and validate. Signed-off-by: N=C3=ADcolas F. R. A. Prado --- tools/testing/selftests/gpio/Makefile | 2 +- .../gpio-set-get-config-example-test-plan.yaml | 15 ++ .../testing/selftests/gpio/gpio-set-get-config.py | 183 +++++++++++++++++= ++++ 3 files changed, 199 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/gpio/Makefile b/tools/testing/selftest= s/gpio/Makefile index e0884390447d..bdfeb0c9aadd 100644 --- a/tools/testing/selftests/gpio/Makefile +++ b/tools/testing/selftests/gpio/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 =20 -TEST_PROGS :=3D gpio-mockup.sh gpio-sim.sh +TEST_PROGS :=3D gpio-mockup.sh gpio-sim.sh gpio-set-get-config.py TEST_FILES :=3D gpio-mockup-sysfs.sh TEST_GEN_PROGS_EXTENDED :=3D gpio-mockup-cdev gpio-chip-info gpio-line-name CFLAGS +=3D -O2 -g -Wall $(KHDR_INCLUDES) diff --git a/tools/testing/selftests/gpio/gpio-set-get-config-example-test-= plan.yaml b/tools/testing/selftests/gpio/gpio-set-get-config-example-test-p= lan.yaml new file mode 100644 index 000000000000..3b749be3c8dc --- /dev/null +++ b/tools/testing/selftests/gpio/gpio-set-get-config-example-test-plan.ya= ml @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 +# Top-level contains a list of the GPIO chips that will be tested. Each on= e is +# chosen based on the GPIO chip's info label. +- label: "gpiochip_device_label" + # For each GPIO chip, multiple pin configurations can be tested, which a= re + # listed under 'tests' + tests: + # pin indicates the pin number to test + - pin: 34 + # bias can be 'pull-up', 'pull-down', 'disabled' + bias: "pull-up" + - pin: 34 + bias: "pull-down" + - pin: 34 + bias: "disabled" diff --git a/tools/testing/selftests/gpio/gpio-set-get-config.py b/tools/te= sting/selftests/gpio/gpio-set-get-config.py new file mode 100755 index 000000000000..6f1444c8d46b --- /dev/null +++ b/tools/testing/selftests/gpio/gpio-set-get-config.py @@ -0,0 +1,183 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Collabora Ltd + +# +# This test validates GPIO pin configuration. It takes a test plan in YAML= (see +# gpio-set-get-config-example-test-plan.yaml) and sets and gets back each = pin +# configuration described in the plan and checks that they match in order = to +# validate that they are being applied correctly. +# +# When the file name for the test plan is not provided through --test-plan= , it +# will be guessed based on the platform ID (DT compatible or DMI). +# + +import time +import os +import sys +import argparse +import re +import subprocess +import glob +import signal + +import yaml + +# Allow ksft module to be imported from different directory +this_dir =3D os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(this_dir, "../kselftest/")) + +import ksft + + +def config_pin(chip_dev, pin_config): + flags =3D [] + if pin_config.get("bias"): + flags +=3D f"-b {pin_config['bias']}".split() + flags +=3D ["-w", chip_dev, str(pin_config["pin"])] + gpio_mockup_cdev_path =3D os.path.join(this_dir, "gpio-mockup-cdev") + return subprocess.Popen([gpio_mockup_cdev_path] + flags) + + +def get_bias_debugfs(chip_debugfs_path, pin): + with open(os.path.join(chip_debugfs_path, "pinconf-pins")) as f: + for l in f: + m =3D re.match(rf"pin {pin}.*bias (?P(pull )?\w+)", l) + if m: + return m.group("bias") + + +def check_config_pin(chip, chip_debugfs_dir, pin_config): + test_passed =3D True + + if pin_config.get("bias"): + bias =3D get_bias_debugfs(chip_debugfs_dir, pin_config["pin"]) + # Convert "pull up" / "pull down" to "pull-up" / "pull-down" + bias =3D bias.replace(" ", "-") + if bias !=3D pin_config["bias"]: + ksft.print_msg( + f"Bias doesn't match: Expected {pin_config['bias']}, read = {bias}." + ) + test_passed =3D False + + ksft.test_result( + test_passed, + f"{chip['label']}.{pin_config['pin']}.{pin_config['bias']}", + ) + + +def get_devfs_chip_file(chip_dict): + gpio_chip_info_path =3D os.path.join(this_dir, 'gpio-chip-info') + for f in glob.glob("/dev/gpiochip*"): + proc =3D subprocess.run( + f"{gpio_chip_info_path} {f} label".split(), capture_output=3DT= rue, text=3DTrue + ) + if proc.returncode: + ksft.print_msg(f"Error opening gpio device {f}: {proc.returnco= de}") + ksft.exit_fail() + + if chip_dict["label"] in proc.stdout: + return f + + +def get_debugfs_chip_dir(chip): + pinctrl_debugfs =3D "/sys/kernel/debug/pinctrl/" + + for name in os.listdir(pinctrl_debugfs): + if chip["label"] in name: + return os.path.join(pinctrl_debugfs, name) + + +def run_test(test_plan_filename): + ksft.print_msg(f"Using test plan file: {test_plan_filename}") + + with open(test_plan_filename) as f: + plan =3D yaml.safe_load(f) + + num_tests =3D 0 + for chip in plan: + num_tests +=3D len(chip["tests"]) + + ksft.set_plan(num_tests) + + for chip in plan: + chip_dev =3D get_devfs_chip_file(chip) + if not chip_dev: + ksft.print_msg("Couldn't find /dev file for GPIO chip") + ksft.exit_fail() + chip_debugfs_dir =3D get_debugfs_chip_dir(chip) + if not chip_debugfs_dir: + ksft.print_msg("Couldn't find pinctrl folder in debugfs for GP= IO chip") + ksft.exit_fail() + for pin_config in chip["tests"]: + proc =3D config_pin(chip_dev, pin_config) + time.sleep(0.1) # Give driver some time to update pin + check_config_pin(chip, chip_debugfs_dir, pin_config) + proc.send_signal(signal.SIGTERM) + proc.wait() + + +def get_possible_test_plan_filenames(): + filenames =3D [] + + dt_board_compatible_file =3D "/proc/device-tree/compatible" + if os.path.exists(dt_board_compatible_file): + with open(dt_board_compatible_file) as f: + for line in f: + compatibles =3D [compat for compat in line.split("\0") if = compat] + filenames.extend(compatibles) + else: + dmi_id_dir =3D "/sys/devices/virtual/dmi/id" + vendor_dmi_file =3D os.path.join(dmi_id_dir, "sys_vendor") + product_dmi_file =3D os.path.join(dmi_id_dir, "product_name") + + with open(vendor_dmi_file) as f: + vendor =3D f.read().replace("\n", "") + with open(product_dmi_file) as f: + product =3D f.read().replace("\n", "") + + filenames =3D [vendor + "," + product] + + return filenames + + +def get_test_plan_filename(test_plan_dir): + chosen_test_plan_filename =3D "" + full_test_plan_paths =3D [ + os.path.join(test_plan_dir, f + ".yaml") + for f in get_possible_test_plan_filenames() + ] + for path in full_test_plan_paths: + if os.path.exists(path): + chosen_test_plan_filename =3D path + break + + if not chosen_test_plan_filename: + tried_paths =3D ",".join(["'" + p + "'" for p in full_test_plan_pa= ths]) + ksft.print_msg(f"No matching test plan file found (tried {tried_pa= ths})") + ksft.print_cnts() + sys.exit(4) + + return chosen_test_plan_filename + + +parser =3D argparse.ArgumentParser() +parser.add_argument( + "--test-plan-dir", default=3D".", help=3D"Directory containing the tes= t plan files" +) +parser.add_argument("--test-plan", help=3D"Test plan file to use") +args =3D parser.parse_args() + +ksft.print_header() + +if args.test_plan: + test_plan_filename =3D os.path.join(args.test_plan_dir, args.test_plan) + if not os.path.exists(test_plan_filename): + ksft.print_msg(f"Test plan file not found: {test_plan_filename}") + ksft.exit_fail() +else: + test_plan_filename =3D get_test_plan_filename(args.test_plan_dir) + +run_test(test_plan_filename) + +ksft.finished() --=20 2.46.0