From: Andrew Jeffery <andrew@codeconstruct.com.au>
To: Billy Tsai <billy_tsai@aspeedtech.com>,
"linus.walleij@linaro.org" <linus.walleij@linaro.org>,
"brgl@bgdev.pl" <brgl@bgdev.pl>,
"robh@kernel.org" <robh@kernel.org>,
"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
"conor+dt@kernel.org" <conor+dt@kernel.org>,
"joel@jms.id.au" <joel@jms.id.au>,
"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-aspeed@lists.ozlabs.org" <linux-aspeed@lists.ozlabs.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
BMC-SW <BMC-SW@aspeedtech.com>
Subject: Re: [PATCH v1 2/2] gpio: Add G7 Aspeed gpio controller driver
Date: Wed, 28 Aug 2024 10:48:10 +0930 [thread overview]
Message-ID: <e629752d8c97a2d14641a7fbc0cbdb1cd01a8ac5.camel@codeconstruct.com.au> (raw)
In-Reply-To: <OSQPR06MB7252CBAEBF1DBE2C613F24748B8B2@OSQPR06MB7252.apcprd06.prod.outlook.com>
On Tue, 2024-08-27 at 02:45 +0000, Billy Tsai wrote:
> Hi Andrew,
>
> Thanks for your suggestion. As I understand it, you’re suggesting that this driver should share the
> common parts with aspeed-gpio.c, correct?
> However, I don’t think that’s necessary. You can treat it as a new GPIO controller because the
> register layout is quite different from aspeed-gpio.c.
Well, we could, but both share a lot of the same capabilities. aspeed-
gpio.c already has to abstract over the register layout because it's so
haphazard. What I was suggesting was to formalise this a bit more by
converting some of the inline functions and macros to callbacks that
can be implemented for each controller.
I haven't tried it myself, but it feels feasible?
> If I try to make it common, the driver could become too complex, potentially requiring a separate
> gpio-aspeed-common.c and necessitating changes to the existing aspeed-gpio.c
I felt the trade-off between the volume of copy/paste and the
complexity of adding a few callbacks weighed in favour of the latter.
Also, given the volume of copy/paste, I think it would be best to
retain the copyright information from aspeed-gpio.c if the outcome is
these must be separate drivers.
Many of the changes seemed to be dealing with the difference between
`struct aspeed_gpio` and `struct aspeed_gpio_g7`, which might be
addressed by some careful struct design and use of container_of().
> Maybe the discussion of merging aspeed-gpio.c and this driver can be postponed until after this one
> is accepted?
Yeah, but I suspect the discussion just won't happen if this is merged.
Now's the time to get consensus on a way forward, while the driver is
yet to be merged.
> > > +
> > > +static const int debounce_timers[4] = { 0x00, 0x04, 0x00, 0x08 };
>
> > This is all largely copy/pasted from gpio-aspeed.c. Can we split it out
> > and share the definitions?
>
> Do you mean moving them into the common header file?
> The structure is fine, but I’m unsure about the debounce_timers.
> It’s a static array, so I don’t think it needs to be shared with gpio-aspeed.c.
That can be changed though? An appropriate pointer can be point into
the driver struct.
> > > +static int aspeed_gpio_g7_get(struct gpio_chip *gc, unsigned int offset)
> > > +{
> > > + struct aspeed_gpio_g7 *gpio = gpiochip_get_data(gc);
> > > + void __iomem *addr = gpio->base + GPIO_G7_CTRL_REG_OFFSET(offset);
> > > +
> > > + return !!(field_get(GPIO_G7_IN_DATA, ioread32(addr)));
> > > +}
> > > +
> > > +static void __aspeed_gpio_g7_set(struct gpio_chip *gc, unsigned int offset, int val)
> > > +{
> > > + struct aspeed_gpio_g7 *gpio = gpiochip_get_data(gc);
> > > + void __iomem *addr = gpio->base + GPIO_G7_CTRL_REG_OFFSET(offset);
>
> > The rest of the implementation of this function is broadly the same as
> > in gpio-aspeed.c. The main difference is accounting for the address to
> > access and the bit to whack. If we define some callbacks that replace
> > GPIO_BANK()/to_bank() and GPIO_BIT() that can account for the
> > differences in register layout, perhaps this could be common?
>
> > The trade-off is some complexity vs copy-paste, but there does seem to
> > be an awful lot of the latter with only minor changes so far.
>
> Do you mean I need to create a gpio-aspeed-common.c, define the necessary common APIs,
> and have gpio-aspeed.c and this driver hook into those APIs?
Well, you may not have to do that if we can put it all in gpio-
aspeed.c?
My suspicion is the g7 support could largely become some well-chosen
callbacks.
Andrew
next prev parent reply other threads:[~2024-08-28 1:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-21 7:07 [PATCH v1 0/2] Add Aspeed G7 gpio support Billy Tsai
2024-08-21 7:07 ` [PATCH v1 1/2] dt-bindings: gpio: aspeed,ast2400-gpio: Support ast2700 Billy Tsai
2024-08-21 8:51 ` Krzysztof Kozlowski
2024-09-02 8:23 ` Billy Tsai
2024-08-21 7:07 ` [PATCH v1 2/2] gpio: Add G7 Aspeed gpio controller driver Billy Tsai
2024-08-21 12:10 ` Bartosz Golaszewski
2024-08-26 9:59 ` Billy Tsai
2024-08-21 20:51 ` kernel test robot
2024-08-21 23:13 ` kernel test robot
2024-08-22 1:31 ` Andrew Jeffery
2024-08-27 2:45 ` Billy Tsai
2024-08-28 1:18 ` Andrew Jeffery [this message]
2024-08-28 5:35 ` Billy Tsai
2024-08-22 9:16 ` kernel test robot
2024-08-26 8:37 ` Linus Walleij
2024-08-26 10:56 ` [PATCH " Markus Elfring
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=e629752d8c97a2d14641a7fbc0cbdb1cd01a8ac5.camel@codeconstruct.com.au \
--to=andrew@codeconstruct.com.au \
--cc=BMC-SW@aspeedtech.com \
--cc=billy_tsai@aspeedtech.com \
--cc=brgl@bgdev.pl \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=joel@jms.id.au \
--cc=krzk+dt@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-aspeed@lists.ozlabs.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@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).