From: Maxime Ripard <maxime.ripard@free-electrons.com>
To: Chen-Yu Tsai <wens@csie.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com
Subject: Re: [PATCH 3/3] pinctrl: sunxi: Make sunxi_pconf_group_set use sunxi_pconf_reg helper
Date: Tue, 4 Oct 2016 10:07:07 +0200 [thread overview]
Message-ID: <20161004080707.GL5228@lukather> (raw)
In-Reply-To: <20161004015112.20833-4-wens@csie.org>
[-- Attachment #1: Type: text/plain, Size: 2514 bytes --]
On Tue, Oct 04, 2016 at 09:51:12AM +0800, Chen-Yu Tsai wrote:
> The sunxi_pconf_reg helper introduced in the last patch gives us the
> chance to rework sunxi_pconf_group_set to have it match the structure
> of sunxi_pconf_(group_)get and make it easier to understand.
>
> For each config to set, it:
>
> 1. checks if the parameter is supported.
> 2. checks if the argument is within limits.
> 3. converts argument to the register value.
> 4. writes to the register with spinlock held.
>
> As a result the function now blocks unsupported config parameters,
> instead of silently ignoring them.
>
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> ---
> drivers/pinctrl/sunxi/pinctrl-sunxi.c | 65 +++++++++++++++++++----------------
> drivers/pinctrl/sunxi/pinctrl-sunxi.h | 1 -
> 2 files changed, 35 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> index 236272a2339d..1f02c4cd55c7 100644
> --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> @@ -364,23 +364,27 @@ static int sunxi_pconf_group_set(struct pinctrl_dev *pctldev,
> {
> struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
> struct sunxi_pinctrl_group *g = &pctl->groups[group];
> - unsigned long flags;
> unsigned pin = g->pin - pctl->desc->pin_base;
> - u32 val, mask;
> - u16 strength;
> - u8 dlevel;
> int i;
>
> - spin_lock_irqsave(&pctl->lock, flags);
> -
> for (i = 0; i < num_configs; i++) {
> - switch (pinconf_to_config_param(configs[i])) {
> + enum pin_config_param param;
> + unsigned long flags;
> + u32 offset, shift, mask, val;
> + u16 arg;
> + int ret;
> +
> + param = pinconf_to_config_param(configs[i]);
> + arg = pinconf_to_config_argument(configs[i]);
> +
> + ret = sunxi_pconf_reg(pin, param, &offset, &shift, &mask);
> + if (ret < 0)
> + return ret;
> +
> + switch (param) {
> case PIN_CONFIG_DRIVE_STRENGTH:
> - strength = pinconf_to_config_argument(configs[i]);
> - if (strength > 40) {
> - spin_unlock_irqrestore(&pctl->lock, flags);
> + if (arg < 10 || arg > 40)
This is a nitpick, but I'd really like to store the value in a
separate variable, to have a distinction between the value that was
given us as an argument, and what we're going to write.
Thanks!
Maxime
--
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2016-10-04 15:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-04 1:51 [PATCH 0/3] pinctrl: sunxi: Support generic pinconf functions Chen-Yu Tsai
[not found] ` <20161004015112.20833-1-wens-jdAy2FN1RRM@public.gmane.org>
2016-10-04 1:51 ` [PATCH 1/3] pinctrl: sunxi: Add support for fetching pinconf settings from hardware Chen-Yu Tsai
[not found] ` <20161004015112.20833-2-wens-jdAy2FN1RRM@public.gmane.org>
2016-10-04 8:02 ` Maxime Ripard
2016-10-04 15:49 ` Chen-Yu Tsai
2016-10-04 1:51 ` [PATCH 2/3] pinctrl: sunxi: Fix PIN_CONFIG_BIAS_PULL_{DOWN,UP} argument Chen-Yu Tsai
2016-10-04 1:51 ` [PATCH 3/3] pinctrl: sunxi: Make sunxi_pconf_group_set use sunxi_pconf_reg helper Chen-Yu Tsai
2016-10-04 8:07 ` Maxime Ripard [this message]
2016-10-20 13:13 ` [PATCH 0/3] pinctrl: sunxi: Support generic pinconf functions Linus Walleij
[not found] ` <CACRpkdZHTQqnsuHcm3+iYQJc2picLu95W2OKeMiXFq+XNzDV3g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-10-20 13:24 ` 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=20161004080707.GL5228@lukather \
--to=maxime.ripard@free-electrons.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-sunxi@googlegroups.com \
--cc=wens@csie.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).