From: Andrew Jeffery <andrew@aj.id.au>
To: Yong Li <sdliyong@gmail.com>,
linus.walleij@linaro.org, joel@jms.id.au, arnd@arndb.de,
raltherr@google.com, robh@kernel.org, linux-gpio@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] pinctrl: aspeed: Fix ast2500 strap register write logic
Date: Mon, 14 Aug 2017 10:23:13 +0930 [thread overview]
Message-ID: <1502671993.7946.25.camel@aj.id.au> (raw)
In-Reply-To: <1502461363-70990-1-git-send-email-sdliyong@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3971 bytes --]
Hi Yong,
On Fri, 2017-08-11 at 22:22 +0800, Yong Li wrote:
> On AST2500, the hardware strap register(SCU70) only accepts write ‘1’,
> to clear it to ‘0’, must set bits(write ‘1’) to SCU7C
>
> > Signed-off-by: Yong Li <sdliyong@gmail.com>
> ---
> drivers/pinctrl/aspeed/pinctrl-aspeed.c | 20 ++++++++++++++++++--
> drivers/pinctrl/aspeed/pinctrl-aspeed.h | 1 +
> 2 files changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pinctrl/aspeed/pinctrl-aspeed.c b/drivers/pinctrl/aspeed/pinctrl-aspeed.c
> index a86a4d6..9d2b2e9 100644
> --- a/drivers/pinctrl/aspeed/pinctrl-aspeed.c
> +++ b/drivers/pinctrl/aspeed/pinctrl-aspeed.c
> @@ -183,6 +183,7 @@ static int aspeed_sig_expr_set(const struct aspeed_sig_expr *expr,
> {
> > int ret;
> > int i;
> > + unsigned int rev_id;
>
> > for (i = 0; i < expr->ndescs; i++) {
> > const struct aspeed_sig_desc *desc = &expr->descs[i];
> @@ -213,8 +214,23 @@ static int aspeed_sig_expr_set(const struct aspeed_sig_expr *expr,
> > if (desc->ip == ASPEED_IP_SCU && desc->reg == HW_STRAP2)
> > continue;
>
> > - ret = regmap_update_bits(maps[desc->ip], desc->reg,
> > - desc->mask, val);
> > + /* On AST2500, Set bits in SCU7C are cleared from SCU70 */
> > + if (desc->ip == ASPEED_IP_SCU && desc->reg == HW_STRAP1 &&
> + val == 0) {
The AST2500 strapping register contains several multi-bit bit-fields.
Currently we know we'll only reach this test if we're modifying the
GPIO passthrough bits for bank D and E (bits 21 and 22 respectively),
so the 'val == 0' test is functional but I wonder if we shouldn't be
more flexible. If we're more flexible here then we may only need to
modify the strap register test above this hunk to change the behaviour,
rather than needing to rework your additions here as well. More on this
below.
> + ret = regmap_read(maps[ASPEED_IP_SCU],
> > + HW_REVISION_ID, &rev_id);
> > + if (ret < 0)
> > + return ret;
> +
> > + if (0x04 == ((rev_id >> 24) & 0xff))
> > + ret = regmap_update_bits(maps[desc->ip],
> + HW_REVISION_ID, desc->mask, desc->mask);
regmap_update_bits() will do a read-modify-write operation whilst only
taking the regmap lock once, making the modification atomic. However,
HW_REVISION_ID is a W1C (write 1 to clear) register associated with
SCU70, so we don't actually need the read operation under the lock. We
can simply use regmap_write() here.
Addressing my comment on 'val == 0' above, I think we can remove that
test if we instead write this as:
ret = regmap_write(maps[ desc->ip], HW_REVISION_ID, (~val & desc->mask));
That way if we ever expand the HW_STRAP1 capabilites to cover the
bitfields (e.g. maybe we want to be able to dynamically switch SPI into
debug mode) the code should (hopefully) just work.
Cheers,
Andrew
> + else
> > + ret = regmap_update_bits(maps[desc->ip],
> > + desc->reg, desc->mask, val);
> > + } else
> + ret = regmap_update_bits(maps[desc->ip], desc->reg,
> > + desc->mask, val);
>
> > if (ret)
> > return ret;
> diff --git a/drivers/pinctrl/aspeed/pinctrl-aspeed.h b/drivers/pinctrl/aspeed/pinctrl-aspeed.h
> index fa125db..d4d7f03 100644
> --- a/drivers/pinctrl/aspeed/pinctrl-aspeed.h
> +++ b/drivers/pinctrl/aspeed/pinctrl-aspeed.h
> @@ -251,6 +251,7 @@
> #define SCU3C 0x3C /* System Reset Control/Status Register */
> #define SCU48 0x48 /* MAC Interface Clock Delay Setting */
> #define HW_STRAP1 0x70 /* AST2400 strapping is 33 bits, is split */
> +#define HW_REVISION_ID 0x7C /* Silicon revision ID register */
> #define SCU80 0x80 /* Multi-function Pin Control #1 */
> #define SCU84 0x84 /* Multi-function Pin Control #2 */
> #define SCU88 0x88 /* Multi-function Pin Control #3 */
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
prev parent reply other threads:[~2017-08-14 0:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-11 14:22 Yong Li
2017-08-14 0:53 ` Andrew Jeffery [this message]
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=1502671993.7946.25.camel@aj.id.au \
--to=andrew@aj.id.au \
--cc=arnd@arndb.de \
--cc=joel@jms.id.au \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=raltherr@google.com \
--cc=robh@kernel.org \
--cc=sdliyong@gmail.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
all inboxes | Powered by JetHome®