devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
To: Frank Wunderlich <linux@fw-web.de>,
	Linus Walleij <linus.walleij@linaro.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Sean Wang <sean.wang@kernel.org>
Cc: Frank Wunderlich <frank-w@public-files.de>,
	linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, daniel@makrotopia.org,
	john@phrozen.org, ansuelsmth@gmail.com, eladwf@gmail.com
Subject: Re: [PATCH v4 1/4] pinctrl: mediatek: add support for MTK_PULL_PD_TYPE
Date: Thu, 10 Oct 2024 11:42:08 +0200	[thread overview]
Message-ID: <ce926e0c-74f3-4c7b-987f-3dc50b81a3aa@collabora.com> (raw)
In-Reply-To: <20241009165222.5670-2-linux@fw-web.de>

Il 09/10/24 18:52, Frank Wunderlich ha scritto:
> From: Daniel Golle <daniel@makrotopia.org>
> 
> The MediaTek MT7988 SoC got some pins which only got configurable
> pull-down but unlike previous designs there is no pull-up option.
> Add new type MTK_PULL_PD_TYPE to support configuring such pins.
> 
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
> ---
>   .../pinctrl/mediatek/pinctrl-mtk-common-v2.c  | 59 +++++++++++++++++++
>   .../pinctrl/mediatek/pinctrl-mtk-common-v2.h  |  1 +
>   2 files changed, 60 insertions(+)
> 
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
> index 54301fbba524..eff2aecd31dd 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
> @@ -601,6 +601,30 @@ static int mtk_pinconf_bias_set_pu_pd(struct mtk_pinctrl *hw,
>   	return err;
>   }
>   
> +static int mtk_pinconf_bias_set_pd(struct mtk_pinctrl *hw,
> +				const struct mtk_pin_desc *desc,
> +				u32 pullup, u32 arg)
> +{
> +	int err, pd;
> +
> +	if (arg == MTK_DISABLE)

if (arg != MTK_DISABLE && arg != MTK_ENABLE)
	return -EINVAL

/* Either this */
if (arg == MTK_DISABLE || pullup)
	pd = 0;
else if (!pullup)
	pd = 1

/* Or this (but it's probably a bit too cryptic) */
pd = !(arg == MTK_DISABLE || pullup);

return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd);



...but then, you could otherwise modify mtk_pinconf_bias_set_pu_pd(), so that

static int mtk_pinconf_bias_set_pu_pd(struct mtk_pinctrl *hw,
				const struct mtk_pin_desc *desc,
				u32 pullup, u32 arg, bool pd_only)
{
	int err, pu, pd;

	if (arg == MTK_DISABLE) {
		pu = 0;
		pd = 0;
	} else if ((arg == MTK_ENABLE) && pullup) {
		pu = 1;
		pd = 0;
	} else if ((arg == MTK_ENABLE) && !pullup) {
		pu = 0;
		pd = 1;
	} else {
		return -EINVAL;
	}

	if (!pd_only) {
		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, pu);
		if (err)
			return err;
	}

	return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd);
}

> +		pd = 0;
> +	else if ((arg == MTK_ENABLE) && pullup)
> +		pd = 0;
> +	else if ((arg == MTK_ENABLE) && !pullup)
> +		pd = 1;
> +	else {
> +		err = -EINVAL;
> +		goto out;
> +	}
> +
> +	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd);
> +
> +out:
> +	return err;
> +
> +}
> +
>   static int mtk_pinconf_bias_set_pullsel_pullen(struct mtk_pinctrl *hw,
>   				const struct mtk_pin_desc *desc,
>   				u32 pullup, u32 arg)
> @@ -758,6 +782,12 @@ int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw,
>   			return 0;
>   	}
>   
> +	if (try_all_type & MTK_PULL_PD_TYPE) {
> +		err = mtk_pinconf_bias_set_pd(hw, desc, pullup, arg);

so if it is PD_TYPE, mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg, true);

> +		if (!err)
> +			return err;
> +	}
> +
>   	if (try_all_type & MTK_PULL_PU_PD_TYPE) {
>   		err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg);

mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg, false);

>   		if (!err)
> @@ -878,6 +908,29 @@ static int mtk_pinconf_bias_get_pu_pd(struct mtk_pinctrl *hw,
>   	return err;
>   }
>   
> +static int mtk_pinconf_bias_get_pd(struct mtk_pinctrl *hw,
> +				const struct mtk_pin_desc *desc,
> +				u32 *pullup, u32 *enable)
> +{

this one you can keep it as it is, because I don't think that you can get
the get_pu_pd function to work with pd_only without making it .. well, messy.

> +	int err, pd;
> +
> +	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &pd);
> +	if (err)
> +		goto out;
> +
> +	if (pd == 0) {
> +		*pullup = 0;
> +		*enable = MTK_DISABLE;
> +	} else if (pd == 1) {
> +		*pullup = 0;
> +		*enable = MTK_ENABLE;
> +	} else
> +		err = -EINVAL;
> +
> +out:
> +	return err;
> +}
> +
>   static int mtk_pinconf_bias_get_pullsel_pullen(struct mtk_pinctrl *hw,
>   				const struct mtk_pin_desc *desc,
>   				u32 *pullup, u32 *enable)
> @@ -947,6 +1000,12 @@ int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw,
>   			return 0;
>   	}
>   
> +	if (try_all_type & MTK_PULL_PD_TYPE) {
> +		err = mtk_pinconf_bias_get_pd(hw, desc, pullup, enable);
> +		if (!err)
> +			return err;
> +	}
> +
>   	if (try_all_type & MTK_PULL_PU_PD_TYPE) {
>   		err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable);
>   		if (!err)
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
> index 23688ca6d04e..9c271dc2b521 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
> @@ -24,6 +24,7 @@
>    * turned on/off itself. But it can't be selected pull up/down
>    */
>   #define MTK_PULL_RSEL_TYPE		BIT(3)
> +#define MTK_PULL_PD_TYPE        BIT(4)
>   /* MTK_PULL_PU_PD_RSEL_TYPE is a type which is controlled by
>    * MTK_PULL_PU_PD_TYPE and MTK_PULL_RSEL_TYPE.
>    */


Cheers,
Angelo



  reply	other threads:[~2024-10-10  9:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-09 16:52 [PATCH v4 0/4] Add pinctrl support for mt7988 Frank Wunderlich
2024-10-09 16:52 ` [PATCH v4 1/4] pinctrl: mediatek: add support for MTK_PULL_PD_TYPE Frank Wunderlich
2024-10-10  9:42   ` AngeloGioacchino Del Regno [this message]
2024-10-09 16:52 ` [PATCH v4 2/4] pinctrl: mediatek: add MT7988 pinctrl driver Frank Wunderlich
2024-10-10 12:28   ` AngeloGioacchino Del Regno
2024-10-18 15:22     ` Aw: " Frank Wunderlich
2024-10-09 16:52 ` [PATCH v4 3/4] dt-bindings: pinctrl: add binding for MT7988 SoC Frank Wunderlich
2024-10-09 21:19   ` Rob Herring (Arm)
2024-10-11 14:39     ` Aw: " Frank Wunderlich
2024-10-09 16:52 ` [PATCH v4 4/4] arm64: dts: mediatek: mt7988: add pinctrl support Frank Wunderlich
2024-10-10 12:36   ` AngeloGioacchino Del Regno
2024-10-11 12:53     ` Aw: " Frank Wunderlich
2024-10-14  8:15       ` AngeloGioacchino Del Regno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ce926e0c-74f3-4c7b-987f-3dc50b81a3aa@collabora.com \
    --to=angelogioacchino.delregno@collabora.com \
    --cc=ansuelsmth@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=daniel@makrotopia.org \
    --cc=devicetree@vger.kernel.org \
    --cc=eladwf@gmail.com \
    --cc=frank-w@public-files.de \
    --cc=john@phrozen.org \
    --cc=krzk+dt@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux@fw-web.de \
    --cc=matthias.bgg@gmail.com \
    --cc=robh@kernel.org \
    --cc=sean.wang@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).