From: Baolin Wang <baolin.wang@spreadtrum.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
Rob Herring <robh+dt@kernel.org>,
"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Mark Brown <broonie@kernel.org>,
Baolin Wang <baolin.wang@linaro.org>
Subject: Re: [PATCH 2/2] pinctrl: sprd: Add Spreadtrum pin control driver
Date: Wed, 31 May 2017 16:00:12 +0800 [thread overview]
Message-ID: <20170531080012.GB31518@spreadtrum.com> (raw)
In-Reply-To: <CACRpkdaBcGNTeUDCcVgK9JKZUPKD-qfO8PVHURR2F_pgvEgViQ@mail.gmail.com>
Hi Linus,
On 一, 5月 29, 2017 at 06:28:49下午 +0200, Linus Walleij wrote:
> On Sat, May 27, 2017 at 7:56 AM, Baolin Wang <baolin.wang@spreadtrum.com> wrote:
>
> > This patch adds the pin control driver for Spreadtrum SC9860 platform.
> >
> > Signed-off-by: Baolin Wang <baolin.wang@spreadtrum.com>
>
> Overall I see that you want to store functions and groups in the device tree
> using the current helpers from Tony. That is OK if you want to take that
> approach, though I prefer the pins/groups/function encoding in plaintext.
>
> But when it comes to pin config:
>
> > +static int sprd_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin_id,
> > + unsigned long *config)
> > +{
> > + struct sprd_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
> > + struct sprd_pin *pin = sprd_pinctrl_get_pin_by_id(pctl, pin_id);
> > +
> > + if (!pin)
> > + return -EINVAL;
> > +
> > + if (pin->type == GLOBAL_CTRL_PIN) {
> > + *config = (readl((void __iomem *)pin->reg) >>
> > + pin->bit_offset) & PINCTRL_BIT_MASK(pin->bit_width);
> > + } else {
> > + *config = readl((void __iomem *)pin->reg);
> > + }
> > +
> > + return 0;
> > +}
> > +
> > +static int sprd_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin_id,
> > + unsigned long *configs, unsigned int num_configs)
> > +{
> > + struct sprd_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
> > + struct sprd_pin *pin = sprd_pinctrl_get_pin_by_id(pctl, pin_id);
> > + unsigned long reg;
> > + int i;
> > +
> > + if (!pin)
> > + return -EINVAL;
> > +
> > + for (i = 0; i < num_configs; i++) {
> > + if (pin->type == GLOBAL_CTRL_PIN) {
> > + reg = readl((void __iomem *)pin->reg);
> > + reg &= ~(PINCTRL_BIT_MASK(pin->bit_width)
> > + << pin->bit_offset);
> > + reg |= (configs[i] & PINCTRL_BIT_MASK(pin->bit_width))
> > + << pin->bit_offset;
> > + writel(reg, (void __iomem *)pin->reg);
> > + } else {
> > + writel(configs[i], (void __iomem *)pin->reg);
> > + }
> > + pin->config = configs[i];
> > + }
> > +
> > + return 0;
> > +}
>
> This is just hammering the register values, you have effectively defined your
> register layout as your device tree ABI.
>
> Please don't do this, please use genric pin config and use the approach
> other drivers take with explicit strings encoding the pin configuration.
Make sense. I will try to use genric pin config instead of the magic number.
Thanks for your comments.
>
> Even pinctrl-single that maintain quite a bit of muxing data in the device
> tree still use the generic pin config API, see:
> drivers/pinctrl/pinctrl-single.c
> pcs_pinconf_get(), pcs_pinconf_set()
>
> Same for group config.
>
> Yours,
> Linus Walleij
next prev parent reply other threads:[~2017-05-31 8:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-27 5:56 [PATCH 1/2] DT: pinctrl: Add binding documentation for Spreadtrum pin controller Baolin Wang
2017-05-27 5:56 ` [PATCH 2/2] pinctrl: sprd: Add Spreadtrum pin control driver Baolin Wang
2017-05-29 16:28 ` Linus Walleij
2017-05-31 8:00 ` Baolin Wang [this message]
2017-05-29 16:18 ` [PATCH 1/2] DT: pinctrl: Add binding documentation for Spreadtrum pin controller Linus Walleij
2017-05-31 7:58 ` Baolin Wang
2017-06-09 7:59 ` Linus Walleij
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=20170531080012.GB31518@spreadtrum.com \
--to=baolin.wang@spreadtrum.com \
--cc=baolin.wang@linaro.org \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=robh+dt@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