From: Chen-Yu Tsai <wenst@chromium.org>
To: Sean Wang <sean.wang@kernel.org>,
Linus Walleij <linus.walleij@linaro.org>,
Matthias Brugger <matthias.bgg@gmail.com>
Cc: linux-mediatek@lists.infradead.org, linux-gpio@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Zhiyong Tao <zhiyong.tao@mediatek.com>,
Guodong Liu <guodong.liu@mediatek.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>
Subject: Re: [PATCH 7/7] pinctrl: mediatek: paris: Support generic PIN_CONFIG_DRIVE_STRENGTH_UA
Date: Wed, 12 Jan 2022 16:53:31 +0800 [thread overview]
Message-ID: <CAGXv+5Gq0uH-eA799f1MRgzeUU9fsfi-Xz0XyW7ZJW==i_mcYg@mail.gmail.com> (raw)
In-Reply-To: <20220111112244.1483783-8-wenst@chromium.org>
On Tue, Jan 11, 2022 at 7:23 PM Chen-Yu Tsai <wenst@chromium.org> wrote:
>
> Some of the MediaTek chips that utilize the Paris pinctrl driver library
> support a lower drive strength (<= 1mA) than the standard drive strength
> settings (2~16 mA) on certain pins. This was previously supported by the
> custom MTK_PIN_CONFIG_DRV_ADV parameter along with the
> "mediatek,drive-strength-adv" device tree property.
>
> The drive strength values for this hardware are 125, 250, 500, and 1000 mA,
> and can be readily described by the existing "drive-strength-microamp",
> which then gets parsed by the generic pinconf library into the parameter
> PIN_CONFIG_DRIVE_STRENGTH_UA.
So I am actually unsure how to implement support for this properly.
My intention was to map "mediatek,drive-strength-adv" to
"drive-strength-microamp". This implies using the advanced mode if
the property is present, and vice versa.
(Also unsure if such a binding would be acceptable.)
However the pin configs are passed in one-by-one within the driver, so
it doesn't seem viable to check for the absence of a certain parameter.
This might involve a bit more rewriting.
ChenYu
> Add support for PIN_CONFIG_DRIVE_STRENGTH_UA while keeping the old
> custom parameter around for backward compatibility.
>
> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
> ---
>
> The indentation in the switch/case blocks is getting somewhat out of
> control. I also have some cleanup changes to reverse the logic of the
> if/break statements. Not sure if it should be done before or after this
> patch though.
>
> ---
> drivers/pinctrl/mediatek/pinctrl-paris.c | 84 ++++++++++++++++++++++++
> 1 file changed, 84 insertions(+)
>
> diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/mediatek/pinctrl-paris.c
> index 678c8aa33012..5a94903ae372 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-paris.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-paris.c
> @@ -48,6 +48,53 @@ static const char * const mtk_gpio_functions[] = {
> "func12", "func13", "func14", "func15",
> };
>
> +/*
> + * This section supports converting to/from custom MTK_PIN_CONFIG_DRV_ADV
> + * and standard PIN_CONFIG_DRIVE_STRENGTH_UA pin configs.
> + *
> + * The custom value encodes three hardware bits as follows:
> + *
> + * | Bits |
> + * | 2 (E1) | 1 (E0) | 0 (EN) | drive strength (uA)
> + * ------------------------------------------------
> + * | x | x | 0 | disabled, use standard drive strength
> + * -------------------------------------
> + * | 0 | 0 | 1 | 125 uA
> + * | 0 | 1 | 1 | 250 uA
> + * | 1 | 0 | 1 | 500 uA
> + * | 1 | 1 | 1 | 1000 uA
> + */
> +static const int mtk_drv_adv_uA[] = { 125, 250, 500, 1000 };
> +
> +static int mtk_drv_adv_to_uA(int val)
> +{
> + /* This should never happen. */
> + if (WARN_ON_ONCE(val < 0 || val > 7))
> + return -EINVAL;
> +
> + /* Bit 0 simply enables this hardware part */
> + if (!(val & BIT(0)))
> + return -EINVAL;
> +
> + return mtk_drv_adv_uA[(val >> 1)];
> +}
> +
> +static int mtk_drv_uA_to_adv(int val)
> +{
> + switch (val) {
> + case 125:
> + return 0x1;
> + case 250:
> + return 0x3;
> + case 500:
> + return 0x5;
> + case 1000:
> + return 0x7;
> + }
> +
> + return -EINVAL;
> +}
> +
> static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev *pctldev,
> struct pinctrl_gpio_range *range,
> unsigned int pin)
> @@ -151,11 +198,38 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
>
> break;
> case PIN_CONFIG_DRIVE_STRENGTH:
> + if (hw->soc->adv_drive_get) {
> + err = hw->soc->adv_drive_get(hw, desc, &ret);
> + if (!err) {
> + err = mtk_drv_adv_to_uA(ret);
> + if (err > 0) {
> + /* PIN_CONFIG_DRIVE_STRENGTH_UA used */
> + err = -EINVAL;
> + break;
> + }
> + }
> + }
> +
> if (hw->soc->drive_get)
> err = hw->soc->drive_get(hw, desc, &ret);
> else
> err = -ENOTSUPP;
> break;
> + case PIN_CONFIG_DRIVE_STRENGTH_UA:
> + if (hw->soc->adv_drive_get) {
> + err = hw->soc->adv_drive_get(hw, desc, &ret);
> + if (err)
> + break;
> + err = mtk_drv_adv_to_uA(ret);
> + if (err < 0)
> + break;
> +
> + ret = err;
> + err = 0;
> + } else {
> + err = -ENOTSUPP;
> + }
> + break;
> case MTK_PIN_CONFIG_TDSEL:
> case MTK_PIN_CONFIG_RDSEL:
> reg = (param == MTK_PIN_CONFIG_TDSEL) ?
> @@ -271,6 +345,16 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
> else
> err = -ENOTSUPP;
> break;
> + case PIN_CONFIG_DRIVE_STRENGTH_UA:
> + if (hw->soc->adv_drive_set) {
> + err = mtk_drv_uA_to_adv(arg);
> + if (err < 0)
> + break;
> + err = hw->soc->adv_drive_set(hw, desc, err);
> + } else {
> + err = -ENOTSUPP;
> + }
> + break;
> case MTK_PIN_CONFIG_TDSEL:
> case MTK_PIN_CONFIG_RDSEL:
> reg = (param == MTK_PIN_CONFIG_TDSEL) ?
> --
> 2.34.1.575.g55b058a8bb-goog
>
next prev parent reply other threads:[~2022-01-12 8:53 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-11 11:22 [PATCH 0/7] pinctrl: mediatek: Fixes and minor improvements Chen-Yu Tsai
2022-01-11 11:22 ` [PATCH 1/7] pinctrl: pinconf-generic: Print arguments for bias-pull-* Chen-Yu Tsai
2022-01-11 13:42 ` AngeloGioacchino Del Regno
2022-01-12 7:02 ` Chen-Yu Tsai
2022-01-11 11:22 ` [PATCH 2/7] pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_DISABLE readback Chen-Yu Tsai
2022-01-11 13:42 ` AngeloGioacchino Del Regno
2022-01-19 1:42 ` Guodong Liu
2022-01-19 5:57 ` Chen-Yu Tsai
2022-01-20 1:47 ` Guodong Liu
2022-01-11 11:22 ` [PATCH 3/7] pinctrl: mediatek: paris: Fix "argument" argument type for mtk_pinconf_get() Chen-Yu Tsai
2022-01-11 13:42 ` AngeloGioacchino Del Regno
2022-01-11 11:22 ` [PATCH 4/7] pinctrl: mediatek: paris: Fix pingroup pin config state readback Chen-Yu Tsai
2022-01-11 13:42 ` AngeloGioacchino Del Regno
2022-01-11 11:22 ` [PATCH 5/7] pinctrl: mediatek: paris: Drop extra newline in mtk_pctrl_show_one_pin() Chen-Yu Tsai
2022-01-11 13:42 ` AngeloGioacchino Del Regno
2022-01-11 11:22 ` [PATCH 6/7] pinctrl: mediatek: paris: Skip custom extra pin config dump for vrtual GPIOs Chen-Yu Tsai
2022-01-11 13:41 ` AngeloGioacchino Del Regno
2022-01-11 11:22 ` [PATCH 7/7] pinctrl: mediatek: paris: Support generic PIN_CONFIG_DRIVE_STRENGTH_UA Chen-Yu Tsai
2022-01-11 13:41 ` AngeloGioacchino Del Regno
2022-01-11 13:42 ` AngeloGioacchino Del Regno
2022-01-12 8:53 ` Chen-Yu Tsai [this message]
[not found] ` <b1d5ca006860c85edd971ea9e20880ec8ba7f842.camel@mediatek.com>
2022-01-18 2:55 ` Chen-Yu Tsai
2022-01-16 0:49 ` [PATCH 0/7] pinctrl: mediatek: Fixes and minor improvements Linus Walleij
2022-01-18 3:47 ` Chen-Yu Tsai
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='CAGXv+5Gq0uH-eA799f1MRgzeUU9fsfi-Xz0XyW7ZJW==i_mcYg@mail.gmail.com' \
--to=wenst@chromium.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=guodong.liu@mediatek.com \
--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=matthias.bgg@gmail.com \
--cc=sean.wang@kernel.org \
--cc=zhiyong.tao@mediatek.com \
/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).