From patchwork Fri Oct 25 19:45:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 13851497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2281D149EB for ; Fri, 25 Oct 2024 20:06:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=a/dp60hBeGDxqbrgc11djchryi537nAURD/0Na12alQ=; b=ZXHfyPOU7jzso3NLZGAILIvtDi gWi9ehjr9tPPzqcmRAjbFrw3iGJSFn+RtNWpV0uQrMX6Lpzkm7ud+wv2uEW+9Nfyzwx5inMZawFOV n8Bj2z2O+MGdZlmjGgUd4/JxyT2YFeJ4KhZJXoMWggjoHbAfZKphIaWUlZq7Ne9rVmGQ8s65RyzjG 5GfE0W5BWotxHYnMPd358Izn3c45HOrdsJAjYcOZ/x2+3pUB7f9VDWl2zASGoPUaRPVl8hINOx8ka 9NzRYhwQ4pUX/NjaTwUpFuGcN79dc94Uuo+0pNm6nrjnP7Tq30DH150zC1USk03pF8RRWlZNFC7wW QDwmhAag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4QZs-000000054GZ-0Jcw; Fri, 25 Oct 2024 20:06:32 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4QGs-000000052ET-1nF8; Fri, 25 Oct 2024 19:46:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=a/dp60hBeGDxqbrgc11djchryi537nAURD/0Na12alQ=; b=XBbu3kO2H6wcTh+NYUCEGnpGHc K6LNqp8/iq5tcmordkg9e1i++TFPiwld6jvmh4dgvF+n82SGQU7uA4RhcyaHrE4hp71pT9QWsDdvR Qts3laYXp0EiHYcPVcqTh9YFgNXJ71WzNEuzFHj5ERGyH7ogeAW+f+/VMI9oWNnnOaQDkA//TLbjj TL3EHkRQa0FyGCiCgkCeV7MjHC4LvgqgGXo6934BayWxvj/vSwFwP+eudb05qFSGBRZHVkdHF5OL0 nE8cjnjkcPZDXSd27tioW6/ooh11irGF135HlHLa777dM9XkovugPmzO1s0NHHzjiuk/9cyH0ILZ1 KnLmHSJg==; Received: from bali.collaboradmins.com ([148.251.105.195]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4QGH-000000093VL-2Bao; Fri, 25 Oct 2024 19:46:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1729885570; bh=xueF8NL4biPM6Tjkyld4sBVF/E87RcWAqU59Qy6ahiw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JfRE3Bf5Gfu+OpGxQvbs1PSFqG70Pn28Sq2qOU7LQ4hw4W+nB67hd9iDvxcsSREL8 p1A7xZIQW0LnL0uAlmfFuyju47fyw5wCkybqvrQ0iysKmk0CNN/IeRPvsgskBfFpfb cRQGmn6gx9uvcSH/pBtOzK0eVcgHQZikWjxJHsRD4O9G6cSR18lERuuHtsvdKEB1UM uM+ELKf6iGPCJBfwkMCVILAsdRpXs271f0T1OL3D5U5/vJpffLXEoCfyUxbhT1VLTt Y38wrzXU4n1z55CNULfAO3TrDzcM8kEj5S+zjESHfZhrVuLDf2sx0Hg4KTI6Y9mBIK CtVOFr7/XZBLA== Received: from [192.168.1.54] (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 BFB6817E3706; Fri, 25 Oct 2024 21:46:08 +0200 (CEST) From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Date: Fri, 25 Oct 2024 15:45:36 -0400 Subject: [PATCH RFC v2 1/5] pinctrl: mediatek: paris: Expose more configurations to GPIO set_config MIME-Version: 1.0 Message-Id: <20241025-kselftest-gpio-set-get-config-v2-1-040d748840bb@collabora.com> References: <20241025-kselftest-gpio-set-get-config-v2-0-040d748840bb@collabora.com> In-Reply-To: <20241025-kselftest-gpio-set-get-config-v2-0-040d748840bb@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?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241025_204626_486607_11A4E077 X-CRM114-Status: GOOD ( 14.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently the set_config callback in the gpio_chip registered by the pinctrl_paris driver only supports configuring a single parameter on specific pins (the input debounce of the EINT controller, on pins that support it), even though many other configurations are already 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ícolas F. R. A. Prado Reviewed-by: Chen-Yu Tsai --- drivers/pinctrl/mediatek/pinctrl-paris.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/mediatek/pinctrl-paris.c index 87e958d827bf939aa6006794287698be4936f25e..c9455de266a447ab7f5446c1511bef0ef9c9128e 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; } -static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin, - enum pin_config_param param, u32 arg) +static int mtk_paris_pin_config_set(struct mtk_pinctrl *hw, unsigned int pin, + enum pin_config_param param, u32 arg) { - struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev); const struct mtk_pin_desc *desc; int err = -ENOTSUPP; u32 reg; @@ -795,9 +794,9 @@ static int mtk_pconf_group_set(struct pinctrl_dev *pctldev, unsigned group, int i, ret; for (i = 0; i < num_configs; i++) { - ret = mtk_pinconf_set(pctldev, grp->pin, - pinconf_to_config_param(configs[i]), - pinconf_to_config_argument(configs[i])); + ret = mtk_paris_pin_config_set(hw, grp->pin, + pinconf_to_config_param(configs[i]), + pinconf_to_config_argument(configs[i])); if (ret < 0) return ret; @@ -937,18 +936,19 @@ static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned int offset, { struct mtk_pinctrl *hw = gpiochip_get_data(chip); const struct mtk_pin_desc *desc; - u32 debounce; + enum pin_config_param param = pinconf_to_config_param(config); + u32 arg = pinconf_to_config_argument(config); desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset]; - if (!hw->eint || - pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE || - desc->eint.eint_n == EINT_NA) - return -ENOTSUPP; + if (param == PIN_CONFIG_INPUT_DEBOUNCE) { + if (!hw->eint || desc->eint.eint_n == EINT_NA) + return -ENOTSUPP; - debounce = pinconf_to_config_argument(config); + return mtk_eint_set_debounce(hw->eint, desc->eint.eint_n, arg); + } - return mtk_eint_set_debounce(hw->eint, desc->eint.eint_n, debounce); + return mtk_paris_pin_config_set(hw, offset, param, arg); } static int mtk_build_gpiochip(struct mtk_pinctrl *hw) From patchwork Fri Oct 25 19:45:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 13851519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C081CD149EE for ; Fri, 25 Oct 2024 20:14:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=B62dRs4rmHHqh7GA2KSwK4wkGiK9CfddcCRoULiOGAw=; b=cHE/DJGnw54ls1hYZXIR9mQSJS EKWQhBM3UDCISAnFd4Mj2ZUEWvVvTIxyISnoxk8F6peP2uFtKPNZntqXvzORij/7Wd+1uJ2xuK5Il M0jeXa/PDR6/NIiwQauWaJSKcFPbudCD0NvmThwv6gNpAb52TIm4RekwWEc9rWsh5SmkdW21r4rZK j5QlX4HsGru22TDf+Mbc+HnTk5JpDXf2dGpxJ07qfI8C4foJLPP4PS65n3uGAbKjRKS+Q3eR4xZKt 3BThEFtd+5aRPljh2rrJIWwNU1ExVatkYV/ZemViTg3SKPIUKJ6erX4+z/kH1FnHveiXrG+DCmN51 ZGDSGRsw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4Qha-0000000555p-24jp; Fri, 25 Oct 2024 20:14:30 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4QHH-000000052Ko-2m3I; Fri, 25 Oct 2024 19:47:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=B62dRs4rmHHqh7GA2KSwK4wkGiK9CfddcCRoULiOGAw=; b=Oj0fK3bMEF/AU8EyQ1ZrG4Kpeu /M0K7mMWsxAjb+FWXdwf7Bwd2VnVahs6S5x36KfGmrKj1ksm27n2ZtRbXvOT15wHOx6C8Qi8IQXHB oGGN3l5V9snBobCszKdZEEiLjgiISTusnh8baK1K73xgyA7X2Yle2ELvVnEqDFtRhHU2dACJ48oAs 0cpu/5cKbysfOuuPdSG1gEaceKsgwO4zQ4X52S9KZXycFNizI/XW+kYZv9unGqCS+ZtMvyCxn11HI HbY+mKP/cBt+TbTjjeDRrSNAT7qw7fp/QRwI7EhYH3z6z5JCkzkpd6G3ouMPGaqcF5szsDM1RPy6W 5wkByi9w==; Received: from bali.collaboradmins.com ([148.251.105.195]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4QGH-000000093VN-2Bjm; Fri, 25 Oct 2024 19:47:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1729885572; bh=BZGfBFrKIINPs6yptzv0R7eWZsixtmBhUqvIulVpKls=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eapTpgFUxbd9k0Inn2l/vN2uk/MCxVaLR6/GJHm9jOJaxnBcrj106zTy3wtIdIQ8l qHvSwUdt8OiPrHodJ+xAKc7leYQiDMdkkuGnrZv2WJKMRacv9PrHn4w2wjiE/i76i1 G3sS+LjWkxYOxQpJoU9Qeb7H4MXvK8MADAeZ31fokX26fERTersesRiNWNjACC5yaE 0x5DVz2S1bf6sRCKNIE+vneHG+lm6GUOhow6EsQ84Ev0ZRpzwlLJta6YLRSVFW/Yo1 +Z7rqBWLMNBv8dDuzI74MgDiYvV1h4zFefYZTPyAn8JGMnnrX/+oZu2Z7M96oZnYCu 2BCdKH2/2+KDg== Received: from [192.168.1.54] (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 990F417E374E; Fri, 25 Oct 2024 21:46:10 +0200 (CEST) From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Date: Fri, 25 Oct 2024 15:45:37 -0400 Subject: [PATCH RFC v2 2/5] pinctrl: mediatek: moore: Expose more configurations to GPIO set_config MIME-Version: 1.0 Message-Id: <20241025-kselftest-gpio-set-get-config-v2-2-040d748840bb@collabora.com> References: <20241025-kselftest-gpio-set-get-config-v2-0-040d748840bb@collabora.com> In-Reply-To: <20241025-kselftest-gpio-set-get-config-v2-0-040d748840bb@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?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241025_204713_707276_BD9425DC X-CRM114-Status: GOOD ( 17.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently the set_config callback in the gpio_chip registered by the pinctrl_moore driver only supports configuring a single parameter on specific pins (the input debounce of the EINT controller, on pins that support it), even though many other configurations are already 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ícolas F. R. A. Prado Reviewed-by: Chen-Yu Tsai --- drivers/pinctrl/mediatek/pinctrl-moore.c | 283 ++++++++++++++++--------------- 1 file changed, 144 insertions(+), 139 deletions(-) diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c b/drivers/pinctrl/mediatek/pinctrl-moore.c index aad4891223d3e060431a990bfabb6bd2cbb82087..de3494e9f228cef7f2eadf6a6ea2b3b708f1fb25 100644 --- a/drivers/pinctrl/mediatek/pinctrl-moore.c +++ b/drivers/pinctrl/mediatek/pinctrl-moore.c @@ -246,156 +246,160 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev, return 0; } -static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin, - unsigned long *configs, unsigned int num_configs) +static int mtk_moore_pin_config_set(struct mtk_pinctrl *hw, unsigned int pin, + enum pin_config_param param, u32 arg) { - struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev); const struct mtk_pin_desc *desc; - u32 reg, param, arg; - int cfg, err = 0; + u32 reg; + int err = 0; desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; if (!desc->name) return -ENOTSUPP; - for (cfg = 0; cfg < num_configs; cfg++) { - param = pinconf_to_config_param(configs[cfg]); - arg = pinconf_to_config_argument(configs[cfg]); - - switch (param) { - case PIN_CONFIG_BIAS_DISABLE: - if (hw->soc->bias_set_combo) { - err = hw->soc->bias_set_combo(hw, desc, 0, MTK_DISABLE); - if (err) - return err; - } else if (hw->soc->bias_disable_set) { - err = hw->soc->bias_disable_set(hw, desc); - if (err) - return err; - } else { - return -ENOTSUPP; - } - break; - case PIN_CONFIG_BIAS_PULL_UP: - if (hw->soc->bias_set_combo) { - err = hw->soc->bias_set_combo(hw, desc, 1, arg); - if (err) - return err; - } else if (hw->soc->bias_set) { - err = hw->soc->bias_set(hw, desc, 1); - if (err) - return err; - } else { - return -ENOTSUPP; - } - break; - case PIN_CONFIG_BIAS_PULL_DOWN: - if (hw->soc->bias_set_combo) { - err = hw->soc->bias_set_combo(hw, desc, 0, arg); - if (err) - return err; - } else if (hw->soc->bias_set) { - err = hw->soc->bias_set(hw, desc, 0); - if (err) - return err; - } else { - return -ENOTSUPP; - } - break; - case PIN_CONFIG_OUTPUT_ENABLE: - err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, - MTK_DISABLE); - if (err) - goto err; - - err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, - MTK_OUTPUT); + switch ((u32)param) { + case PIN_CONFIG_BIAS_DISABLE: + if (hw->soc->bias_set_combo) { + err = hw->soc->bias_set_combo(hw, desc, 0, MTK_DISABLE); if (err) - goto err; - break; - case PIN_CONFIG_INPUT_ENABLE: - - if (hw->soc->ies_present) { - mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES, - MTK_ENABLE); - } - - err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, - MTK_INPUT); + return err; + } else if (hw->soc->bias_disable_set) { + err = hw->soc->bias_disable_set(hw, desc); if (err) - goto err; - break; - case PIN_CONFIG_SLEW_RATE: - err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SR, - arg); + return err; + } else { + return -ENOTSUPP; + } + break; + case PIN_CONFIG_BIAS_PULL_UP: + if (hw->soc->bias_set_combo) { + err = hw->soc->bias_set_combo(hw, desc, 1, arg); if (err) - goto err; - - break; - case PIN_CONFIG_OUTPUT: - err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, - MTK_OUTPUT); + return err; + } else if (hw->soc->bias_set) { + err = hw->soc->bias_set(hw, desc, 1); if (err) - goto err; - - err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO, - arg); + return err; + } else { + return -ENOTSUPP; + } + break; + case PIN_CONFIG_BIAS_PULL_DOWN: + if (hw->soc->bias_set_combo) { + err = hw->soc->bias_set_combo(hw, desc, 0, arg); if (err) - goto err; - break; - case PIN_CONFIG_INPUT_SCHMITT_ENABLE: - /* arg = 1: Input mode & SMT enable ; - * arg = 0: Output mode & SMT disable - */ - arg = arg ? 2 : 1; - err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, - arg & 1); + return err; + } else if (hw->soc->bias_set) { + err = hw->soc->bias_set(hw, desc, 0); if (err) - goto err; + return err; + } else { + return -ENOTSUPP; + } + break; + case PIN_CONFIG_OUTPUT_ENABLE: + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, MTK_DISABLE); + if (err) + return err; + + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_OUTPUT); + if (err) + return err; + break; + case PIN_CONFIG_INPUT_ENABLE: + + if (hw->soc->ies_present) { + mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES, MTK_ENABLE); + } + + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_INPUT); + if (err) + return err; + break; + case PIN_CONFIG_SLEW_RATE: + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SR, arg); + if (err) + return err; + + break; + case PIN_CONFIG_OUTPUT: + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_OUTPUT); + if (err) + return err; + + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO, arg); + if (err) + return err; + break; + case PIN_CONFIG_INPUT_SCHMITT_ENABLE: + /* arg = 1: Input mode & SMT enable ; + * arg = 0: Output mode & SMT disable + */ + arg = arg ? 2 : 1; + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, arg & 1); + if (err) + return err; - err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, - !!(arg & 2)); + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, !!(arg & 2)); + if (err) + return err; + break; + case PIN_CONFIG_DRIVE_STRENGTH: + if (hw->soc->drive_set) { + err = hw->soc->drive_set(hw, desc, arg); if (err) - goto err; - break; - case PIN_CONFIG_DRIVE_STRENGTH: - if (hw->soc->drive_set) { - err = hw->soc->drive_set(hw, desc, arg); - if (err) - return err; - } else { - err = -ENOTSUPP; - } - break; - case MTK_PIN_CONFIG_TDSEL: - case MTK_PIN_CONFIG_RDSEL: - reg = (param == MTK_PIN_CONFIG_TDSEL) ? - PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL; - - err = mtk_hw_set_value(hw, desc, reg, arg); + return err; + } else { + return -ENOTSUPP; + } + break; + case MTK_PIN_CONFIG_TDSEL: + case MTK_PIN_CONFIG_RDSEL: + reg = (param == MTK_PIN_CONFIG_TDSEL) ? + PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL; + + err = mtk_hw_set_value(hw, desc, reg, arg); + if (err) + return err; + break; + case MTK_PIN_CONFIG_PU_ADV: + case MTK_PIN_CONFIG_PD_ADV: + if (hw->soc->adv_pull_set) { + bool pullup; + + pullup = param == MTK_PIN_CONFIG_PU_ADV; + err = hw->soc->adv_pull_set(hw, desc, pullup, arg); if (err) - goto err; - break; - case MTK_PIN_CONFIG_PU_ADV: - case MTK_PIN_CONFIG_PD_ADV: - if (hw->soc->adv_pull_set) { - bool pullup; - - pullup = param == MTK_PIN_CONFIG_PU_ADV; - err = hw->soc->adv_pull_set(hw, desc, pullup, - arg); - if (err) - return err; - } else { - return -ENOTSUPP; - } - break; - default: - err = -ENOTSUPP; + return err; + } else { + return -ENOTSUPP; } + break; + default: + return -ENOTSUPP; + } + + return 0; +} + +static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin, + unsigned long *configs, unsigned int num_configs) +{ + struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev); + enum pin_config_param param; + int cfg, err = 0; + u32 arg; + + for (cfg = 0; cfg < num_configs; cfg++) { + param = pinconf_to_config_param(configs[cfg]); + arg = pinconf_to_config_argument(configs[cfg]); + + err = mtk_moore_pin_config_set(hw, pin, param, arg); + if (err) + return err; } -err: - return err; + + return 0; } static int mtk_pinconf_group_get(struct pinctrl_dev *pctldev, @@ -539,20 +543,21 @@ static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned int offset, { struct mtk_pinctrl *hw = gpiochip_get_data(chip); const struct mtk_pin_desc *desc; - u32 debounce; + enum pin_config_param param = pinconf_to_config_param(config); + u32 arg = pinconf_to_config_argument(config); desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset]; if (!desc->name) return -ENOTSUPP; - if (!hw->eint || - pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE || - desc->eint.eint_n == (u16)EINT_NA) - return -ENOTSUPP; + if (param == PIN_CONFIG_INPUT_DEBOUNCE) { + if (!hw->eint || desc->eint.eint_n == (u16)EINT_NA) + return -ENOTSUPP; - debounce = pinconf_to_config_argument(config); + return mtk_eint_set_debounce(hw->eint, desc->eint.eint_n, arg); + } - return mtk_eint_set_debounce(hw->eint, desc->eint.eint_n, debounce); + return mtk_moore_pin_config_set(hw, offset, param, arg); } static int mtk_build_gpiochip(struct mtk_pinctrl *hw) From patchwork Fri Oct 25 19:45:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 13851837 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3D0D2D149F3 for ; Fri, 25 Oct 2024 21:16:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xaOYDKDFzL3plG01sUZwTV6ucQ677i5/nFx9cmqwF3U=; b=3B3qLl0ffOlufG94vgbZneHp+6 XccqfRJmM+bBoM+L52f07OZDaYr98qjs6uhjxdZ1PppEN5p3stmWI7uZjIwhFN2hp1HTpD2tL/tqj qY0Y6lbBJcCy9SRNdvyciaIQ3c+Rq8QVnlneiMV/QAUsrp7uTsPNrLmBZgkkOC77wViyLYIT15Hb3 EaZ1Lz3zJ18XOJaKVm98CZ9RYzuEcqWdybftiL/xue+f28HPPxSnbNy5j5omWOOSyops3nrBRduoN fLb+37XIcg9hAe7I79lLeOR6lDskBJwYWpKYurzwGueWSvMgSeuofLFDWuEY5elcbucVO3vFjG24h je2j7PpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4RfY-00000005HWR-394D; Fri, 25 Oct 2024 21:16:28 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4QGu-000000052G2-1Wda; Fri, 25 Oct 2024 19:46:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=xaOYDKDFzL3plG01sUZwTV6ucQ677i5/nFx9cmqwF3U=; b=InzesxfQIk0kiC27/GIy6RJvhn 5ZWBBWDAu3HFxPnnJgA0Jbbg3zK6DEP5KJCM4ON3lj7zfDnA8dkEgAp2K2aVEs4POsgVTCnzoeNkF fnnjEZO7vvlFuNavkpLtSow22qA2/JMotY+z6JsvXCWMMB7FR0ksnDl1CpNMpAcyic98Bjocu2eF4 bnA9CyOGkBObjC7rV9tMVZ/57O1s0ml9aemiG10U90XOWoui8Cz7frHqBi5I7rYpFKHJ1pPaH2vHv 4ium6qN8xfloVLZat8n+455gtsRpn9KgBi3qj7NRuO2VlWw6wZerRID1GxpODnxp7xVVWOPtmwdm2 ExFrBKkg==; Received: from bali.collaboradmins.com ([2a01:4f8:201:9162::2]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4QGH-000000093VW-2CKT; Fri, 25 Oct 2024 19:46:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1729885574; bh=IHDKkPuL6bGyn5e67txu92IjSUnnKlLm5rnqXrHDXfA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=UvWdNBT8E+GAvnMABd12C2gfjEy/go+AclK2eXCzTWQodocmtcvFeSHDBB7BtvLYn beJF7K7beKxA/8UIldFBb2Fyd3xtK2p2jDm97aF4rmFpj1yjV/cECCVNpDcUipjwCR bZtRbOPxPyS8ajt+WL4xSH/Jy1vmDYQtxB3Q3NwW3Wdvj5j15DqZ8SlnlrJsyjyBJH g7c2gZIsmkj1Gd+alM3oY5/ApuW/3xFSCqPxXmVqeNqGegcwteqgI6hfbSMvxaS/GX AwneRLNuHMKz3lSYYGdHSgNGaD+gn4TQewucuYm6jsNCBv3ExSHJRzi9KOfCGc8qXv gKmVw+uA/mt4A== Received: from [192.168.1.54] (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 A5C9D17E3750; Fri, 25 Oct 2024 21:46:12 +0200 (CEST) From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Date: Fri, 25 Oct 2024 15:45:38 -0400 Subject: [PATCH RFC v2 3/5] pinctrl: mediatek: common: Expose more configurations to GPIO set_config MIME-Version: 1.0 Message-Id: <20241025-kselftest-gpio-set-get-config-v2-3-040d748840bb@collabora.com> References: <20241025-kselftest-gpio-set-get-config-v2-0-040d748840bb@collabora.com> In-Reply-To: <20241025-kselftest-gpio-set-get-config-v2-0-040d748840bb@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?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241025_204627_830838_D7835A1A X-CRM114-Status: GOOD ( 17.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently the set_config callback in the gpio_chip registered by the pinctrl-mtk-common driver only supports configuring a single parameter on specific pins (the input debounce of the EINT controller, on pins that support it), even though many other configurations are already 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. Reviewed-by: Chen-Yu Tsai Signed-off-by: Nícolas F. R. A. Prado --- drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 48 ++++++++++++++++----------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c index 91edb539925a49b4302866b9ac36f580cc189fb5..7f9764b474c4e7d0d4c3d6e542bdb7df0264daec 100644 --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c @@ -62,13 +62,12 @@ static unsigned int mtk_get_port(struct mtk_pinctrl *pctl, unsigned long pin) << pctl->devdata->port_shf; } -static int mtk_pmx_gpio_set_direction(struct pinctrl_dev *pctldev, - struct pinctrl_gpio_range *range, unsigned offset, - bool input) +static int mtk_common_pin_set_direction(struct mtk_pinctrl *pctl, + unsigned int offset, + bool input) { unsigned int reg_addr; unsigned int bit; - struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); reg_addr = mtk_get_port(pctl, offset) + pctl->devdata->dir_offset; bit = BIT(offset & pctl->devdata->mode_mask); @@ -86,6 +85,15 @@ static int mtk_pmx_gpio_set_direction(struct pinctrl_dev *pctldev, return 0; } +static int mtk_pmx_gpio_set_direction(struct pinctrl_dev *pctldev, + struct pinctrl_gpio_range *range, unsigned int offset, + bool input) +{ + struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); + + return mtk_common_pin_set_direction(pctl, offset, input); +} + static void mtk_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { unsigned int reg_addr; @@ -363,12 +371,11 @@ static int mtk_pconf_set_pull_select(struct mtk_pinctrl *pctl, return 0; } -static int mtk_pconf_parse_conf(struct pinctrl_dev *pctldev, +static int mtk_pconf_parse_conf(struct mtk_pinctrl *pctl, unsigned int pin, enum pin_config_param param, - enum pin_config_param arg) + u32 arg) { int ret = 0; - struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); switch (param) { case PIN_CONFIG_BIAS_DISABLE: @@ -381,15 +388,15 @@ static int mtk_pconf_parse_conf(struct pinctrl_dev *pctldev, ret = mtk_pconf_set_pull_select(pctl, pin, true, false, arg); break; case PIN_CONFIG_INPUT_ENABLE: - mtk_pmx_gpio_set_direction(pctldev, NULL, pin, true); + mtk_common_pin_set_direction(pctl, pin, true); ret = mtk_pconf_set_ies_smt(pctl, pin, arg, param); break; case PIN_CONFIG_OUTPUT: mtk_gpio_set(pctl->chip, pin, arg); - ret = mtk_pmx_gpio_set_direction(pctldev, NULL, pin, false); + ret = mtk_common_pin_set_direction(pctl, pin, false); break; case PIN_CONFIG_INPUT_SCHMITT_ENABLE: - mtk_pmx_gpio_set_direction(pctldev, NULL, pin, true); + mtk_common_pin_set_direction(pctl, pin, true); ret = mtk_pconf_set_ies_smt(pctl, pin, arg, param); break; case PIN_CONFIG_DRIVE_STRENGTH: @@ -421,7 +428,7 @@ static int mtk_pconf_group_set(struct pinctrl_dev *pctldev, unsigned group, int i, ret; for (i = 0; i < num_configs; i++) { - ret = mtk_pconf_parse_conf(pctldev, g->pin, + ret = mtk_pconf_parse_conf(pctl, g->pin, pinconf_to_config_param(configs[i]), pinconf_to_config_argument(configs[i])); if (ret < 0) @@ -870,19 +877,20 @@ static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned offset, struct mtk_pinctrl *pctl = gpiochip_get_data(chip); const struct mtk_desc_pin *pin; unsigned long eint_n; - u32 debounce; + enum pin_config_param param = pinconf_to_config_param(config); + u32 arg = pinconf_to_config_argument(config); - if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE) - return -ENOTSUPP; + if (param == PIN_CONFIG_INPUT_DEBOUNCE) { + pin = pctl->devdata->pins + offset; + if (pin->eint.eintnum == NO_EINT_SUPPORT) + return -EINVAL; - pin = pctl->devdata->pins + offset; - if (pin->eint.eintnum == NO_EINT_SUPPORT) - return -EINVAL; + eint_n = pin->eint.eintnum; - debounce = pinconf_to_config_argument(config); - eint_n = pin->eint.eintnum; + return mtk_eint_set_debounce(pctl->eint, eint_n, arg); + } - return mtk_eint_set_debounce(pctl->eint, eint_n, debounce); + return mtk_pconf_parse_conf(pctl, offset, param, arg); } static const struct gpio_chip mtk_gpio_chip = { From patchwork Fri Oct 25 19:45:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 13851504 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16520D149EB for ; Fri, 25 Oct 2024 20:11:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=q2im7bplI6+ld2nl/ZOGzfS9UgtHuRxkRimQVbodUE4=; b=IHWjAg/qsOMwQXv6wkZTIRTDoK z1AH9p/OXyFOSeHJ52Kd7Ks4vijUKsLz540DduXD8uhv2ceXOxTJ6C2dLvUkH63YQfxQOWl4O8vw6 jbgZy6Lo9nVsv58klq+OxLKVTABhZ2zj3yf5DRYBDKo5VP4wmAlJnvGAfCTfzDKNw+EtYoLaBoPBl by28TkV53rI/g5sePvbezVWLACo+BCvm1x2YVZqQdHYF4IoCbchh+IGfLQV3XhpxSwmj1zsrVNmNu 5VxidlKdwU87qIABmZj1bvffsoLRV0jU90laEs8ZVhcQhs84gFMRohvTWyFOIcQbgurOTrktJ64yD 47WV8NNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4QeU-000000054kf-24H8; Fri, 25 Oct 2024 20:11:18 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4QH1-000000052Hn-3a07; Fri, 25 Oct 2024 19:47:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=q2im7bplI6+ld2nl/ZOGzfS9UgtHuRxkRimQVbodUE4=; b=SDQ9pPRacGZHNAH4liLgzBbAKg +SzRq7B2L/UYPfETOIO9YykcvS5s36UkQZh2fZgnC9AnDvycs7u+X0W/IJh+Ma++eRGsHTqxiU/Vx uOwQLtMGT/uLesdgo6yqBWvIS6w08bjp6mtyKYsPkBGzoVPnFp9wwbZunUoeoDzzM3Ibb8Dw1cKpj ZbgAKxgQzU/fwMUeFuWiD3MQBlbuClExSW/bNkPNYh/mBuIGRbPmxRTyF26BezooNNQdLhryPO42V D0zrxsjD8PHHVtjDW9I3HprGNL1gbyVroR8uKpumiuWOAZ9vDM6gTiTlLEHgFpCQvzQu/YhIhLT1y iPb7wpNA==; Received: from bali.collaboradmins.com ([148.251.105.195]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4QGH-000000093Vd-2uld; Fri, 25 Oct 2024 19:46:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1729885576; bh=f8c7443BrlIy7kGWqHO1w3bVU9UBo745msa/mryqajY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=f2p8AAeeEWHrq78LD1YvK3uDCGFvRD3XFQmXKcObGF+E9KS4NKAU55wZFkuX7KD6v 08WsSx1fR4bA7bYVkjHF9iAgpMqBaZRhNG+c4J0cZKGUkuUrIjEV/HzCihMoDQLkzO 8JkoXhdUtKZv36mPwTf8icc6mTFuvNSyjmzlpAZoFfraSdUh5HJ4IfrXWhtTfebpdV XBbBVOZZwueWF6BfQ0G6m1k+u/onX9n+dvPFIjEeKrpSdN5kLg3BuxK3P5VEy5CUV8 5ZBq1nc7OBkHovb7uD48LPxmmYHp+22q9MfKrySgpCRZIT8OrqQKgfNuWfxlZ/s5ew PdNdMwd1V1Ogw== Received: from [192.168.1.54] (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 B3AD217E3756; Fri, 25 Oct 2024 21:46:14 +0200 (CEST) From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Date: Fri, 25 Oct 2024 15:45:39 -0400 Subject: [PATCH RFC v2 4/5] selftest: gpio: Add wait flag to gpio-mockup-cdev MIME-Version: 1.0 Message-Id: <20241025-kselftest-gpio-set-get-config-v2-4-040d748840bb@collabora.com> References: <20241025-kselftest-gpio-set-get-config-v2-0-040d748840bb@collabora.com> In-Reply-To: <20241025-kselftest-gpio-set-get-config-v2-0-040d748840bb@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?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241025_204626_853278_A3534FFC X-CRM114-Status: GOOD ( 15.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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ícolas 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/testing/selftests/gpio/gpio-mockup-cdev.c index d1640f44f8ac2a6fda7a5f75605f83fcaa165dc0..f674dcafa60a02cb1739f3cfae8963dc09efba74 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 #define CONSUMER "gpio-mockup-cdev" @@ -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 = 0, abiv; uint32_t flags_v1; uint64_t flags_v2; + bool wait = false; abiv = 2; ret = 0; flags_v1 = GPIOHANDLE_REQUEST_INPUT; flags_v2 = GPIO_V2_LINE_FLAG_INPUT; - while ((opt = getopt(argc, argv, "lb:s:u:")) != -1) { + while ((opt = getopt(argc, argv, "lb:s:u:w")) != -1) { switch (opt) { case 'l': flags_v1 |= GPIOHANDLE_REQUEST_ACTIVE_LOW; @@ -150,10 +153,14 @@ int main(int argc, char *argv[]) flags_v1 |= GPIOHANDLE_REQUEST_OUTPUT; flags_v2 &= ~GPIO_V2_LINE_FLAG_INPUT; flags_v2 |= GPIO_V2_LINE_FLAG_OUTPUT; + wait = true; break; case 'u': abiv = atoi(optarg); break; + case 'w': + wait = true; + break; default: usage(argv[0]); } @@ -183,9 +190,10 @@ int main(int argc, char *argv[]) return lfd; } - if (flags_v2 & GPIO_V2_LINE_FLAG_OUTPUT) { + if (wait) wait_signal(); - } else { + + if (flags_v2 & GPIO_V2_LINE_FLAG_INPUT) { if (abiv == 1) ret = get_value_v1(lfd); else From patchwork Fri Oct 25 19:45:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 13851518 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E34A1D149EE for ; Fri, 25 Oct 2024 20:13:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jrGPYiQVrR1mRwXfSLHdF++IDgBP/SolJ9GIk6NTtsk=; b=JJOuijz9t1YNFxN7vpff+4vFKV U3wObG1gO+ZZwDJ6/94z4wZjdzGZoYWNU8V9kaBgKlqAaaMbTuvwTJrharSIOPMHpKTJMCe/yoiKm OBY9U8F3SiE03xrCjfAWzyKLGczLVKHrzh3NkX8yCM5ovxwuUjPEIyaOSTXTLy2Im6wtA7mBtUYw1 vwiJt/F8MSOfrQIY0xQWaGu5YxpR6BpJQ+WCjzuz7y/PdirI9AqOJ7JZ2mssTNuK+I9fcd2BjToHi n+fvNkR89JA6SND17HZEIXZ5Ap5qD7FbrQewcS04ihF8K7POSeicZZNgWASLouD76rLqE/qtHyHBN lhB6NOKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4Qg1-000000054uU-3Qay; Fri, 25 Oct 2024 20:12:53 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4QH8-000000052Jl-2C0c; Fri, 25 Oct 2024 19:47:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=jrGPYiQVrR1mRwXfSLHdF++IDgBP/SolJ9GIk6NTtsk=; b=c8FiDd0ke0+6xZIS3fAQ8tRIwb TF6MZG7YypyEXtRDAwkPcxkdq040HwZguGTM7G6WEwJnB8gl5HAmQEnAvEawmnszsZssqNuLzE5uO bF0p/HzDxNS14cIZifA8qhCnHnN1jHbnxekMt26NDmWpBpWA3IRCEbO9W8vj+815x486DC9y53UQ+ eO4H0u27dwsZGIxw1tFy+3yrV5k7gRva0amdPbwn1rPiZqLTmGdyrCdnj4XFWFOkG2gRcsUaPYG3b OQqQPZNOIBQilXN6jIx+1BQA1Iz03dYahSv5eeN9ovykmO0VyNMouj0knWBaku4fnKqDqG4g42Rw1 GkVzwMPg==; Received: from bali.collaboradmins.com ([148.251.105.195]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4QGs-000000093Yu-0ckz; Fri, 25 Oct 2024 19:47:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1729885578; bh=Y20wuHcunjSHNH2lvGmo0duSBcWHshdPVJCm96/MJWk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XA3f1BOxjZQzKihOQ5/lKl5uNMehsUMPCC17wk23yjR0Wkl2ubgqxG/lYj+8qMmKL rWkt5JenztqPzdRq43WZGAlf6i8DzZN5KV/vi+lCke6TpjWcvSZdoNx12A8tggKIG9 t3896nMc3GECQayVzzcJ+PWfVfU68cLhHuiU1cMGFs4I1Jd2IK7gDyEXjtqDjPYlZ3 X3dhcYbaqNNWq1KpIywA55yN72LCsakpOazsN615dG436TLK8vuxDf/XWRkcJCdXt+ qnxUrEKhOqOuvv/M6mO88IlcOhkpySKDizpmbwaKXG+uRufUyDBPrLIQHV/FKj6D7w Bd4L3+HnOKFMA== Received: from [192.168.1.54] (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 D7CC917E3757; Fri, 25 Oct 2024 21:46:16 +0200 (CEST) From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Date: Fri, 25 Oct 2024 15:45:40 -0400 Subject: [PATCH RFC v2 5/5] selftest: gpio: Add a new set-get config test MIME-Version: 1.0 Message-Id: <20241025-kselftest-gpio-set-get-config-v2-5-040d748840bb@collabora.com> References: <20241025-kselftest-gpio-set-get-config-v2-0-040d748840bb@collabora.com> In-Reply-To: <20241025-kselftest-gpio-set-get-config-v2-0-040d748840bb@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?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241025_204658_950612_9BA5A816 X-CRM114-Status: GOOD ( 18.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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ícolas 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/selftests/gpio/Makefile index e0884390447dcfffe4ca0b4fa0f1669463bb669c..bdfeb0c9aaddc436df77ada1d5ac0c80890960a7 100644 --- a/tools/testing/selftests/gpio/Makefile +++ b/tools/testing/selftests/gpio/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -TEST_PROGS := gpio-mockup.sh gpio-sim.sh +TEST_PROGS := gpio-mockup.sh gpio-sim.sh gpio-set-get-config.py TEST_FILES := gpio-mockup-sysfs.sh TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name CFLAGS += -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-plan.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3b749be3c8dcf6822b7531424a6b1f8fca840a65 --- /dev/null +++ b/tools/testing/selftests/gpio/gpio-set-get-config-example-test-plan.yaml @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 +# Top-level contains a list of the GPIO chips that will be tested. Each one 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 are + # 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/testing/selftests/gpio/gpio-set-get-config.py new file mode 100755 index 0000000000000000000000000000000000000000..6f1444c8d46bcfc226f414520b74f4a59725854f --- /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 = 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 = [] + if pin_config.get("bias"): + flags += f"-b {pin_config['bias']}".split() + flags += ["-w", chip_dev, str(pin_config["pin"])] + gpio_mockup_cdev_path = 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 = 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 = True + + if pin_config.get("bias"): + bias = get_bias_debugfs(chip_debugfs_dir, pin_config["pin"]) + # Convert "pull up" / "pull down" to "pull-up" / "pull-down" + bias = bias.replace(" ", "-") + if bias != pin_config["bias"]: + ksft.print_msg( + f"Bias doesn't match: Expected {pin_config['bias']}, read {bias}." + ) + test_passed = 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 = os.path.join(this_dir, 'gpio-chip-info') + for f in glob.glob("/dev/gpiochip*"): + proc = subprocess.run( + f"{gpio_chip_info_path} {f} label".split(), capture_output=True, text=True + ) + if proc.returncode: + ksft.print_msg(f"Error opening gpio device {f}: {proc.returncode}") + ksft.exit_fail() + + if chip_dict["label"] in proc.stdout: + return f + + +def get_debugfs_chip_dir(chip): + pinctrl_debugfs = "/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 = yaml.safe_load(f) + + num_tests = 0 + for chip in plan: + num_tests += len(chip["tests"]) + + ksft.set_plan(num_tests) + + for chip in plan: + chip_dev = 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 = get_debugfs_chip_dir(chip) + if not chip_debugfs_dir: + ksft.print_msg("Couldn't find pinctrl folder in debugfs for GPIO chip") + ksft.exit_fail() + for pin_config in chip["tests"]: + proc = 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 = [] + + dt_board_compatible_file = "/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 = [compat for compat in line.split("\0") if compat] + filenames.extend(compatibles) + else: + dmi_id_dir = "/sys/devices/virtual/dmi/id" + vendor_dmi_file = os.path.join(dmi_id_dir, "sys_vendor") + product_dmi_file = os.path.join(dmi_id_dir, "product_name") + + with open(vendor_dmi_file) as f: + vendor = f.read().replace("\n", "") + with open(product_dmi_file) as f: + product = f.read().replace("\n", "") + + filenames = [vendor + "," + product] + + return filenames + + +def get_test_plan_filename(test_plan_dir): + chosen_test_plan_filename = "" + full_test_plan_paths = [ + 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 = path + break + + if not chosen_test_plan_filename: + tried_paths = ",".join(["'" + p + "'" for p in full_test_plan_paths]) + ksft.print_msg(f"No matching test plan file found (tried {tried_paths})") + ksft.print_cnts() + sys.exit(4) + + return chosen_test_plan_filename + + +parser = argparse.ArgumentParser() +parser.add_argument( + "--test-plan-dir", default=".", help="Directory containing the test plan files" +) +parser.add_argument("--test-plan", help="Test plan file to use") +args = parser.parse_args() + +ksft.print_header() + +if args.test_plan: + test_plan_filename = 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 = get_test_plan_filename(args.test_plan_dir) + +run_test(test_plan_filename) + +ksft.finished()