Devicetree
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@mailbox.org>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski <brgl@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Linus Walleij <linusw@kernel.org>, Rob Herring <robh@kernel.org>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH 2/2] gpio: rcar: Add R-Car X5H (R8A78000) support
Date: Mon, 7 Sep 2026 14:10:21 +0200	[thread overview]
Message-ID: <43eccc85-fca3-4c69-9114-b45ab5e1b487@mailbox.org> (raw)
In-Reply-To: <CAMuHMdWb2Qk=heWhwFh4TsEggHOmzTd4Lj-vG6kXjRVMDDUG2A@mail.gmail.com>

On 9/7/26 9:53 AM, Geert Uytterhoeven wrote:

Hello Geert,

> On Sat, 5 Sept 2026 at 23:57, Marek Vasut <marek.vasut@mailbox.org> wrote:
>> On 9/4/26 1:15 PM, Geert Uytterhoeven wrote:
>>>> +++ b/drivers/gpio/gpio-rcar.c
>>>
>>>> @@ -65,14 +66,59 @@ struct gpio_rcar_priv {
>>>>
>>>>    #define RCAR_MAX_GPIO_PER_BANK         32
>>>>
>>>> +static inline int gpio_rcar_remap_offset(struct gpio_rcar_priv *p, int *offs)
>>>
>>> IMO passing a pointer to offs complicates the code.  Perhaps pass offs
>>> by value, and return the adjusted offset or a negative error code?
>>
>> I want to avoid that, since if I only return error value, I can then do
>> simple:
>>
>> ret = gpio_rcar_remap_offset(...);
>> if (ret)
>>     return ret;
>>
>> in gpio_rcar_read() and gpio_rcar_write(), which are the only two call
>> sites of this function.
> 
> gpio_rcar_read() and gpio_rcar_write() do not return error codes.
> I was thinking of
> 
>      offs = gpio_rcar_remap_offset(p, offs);
>      if (offs < 0)
>              return 0;
> 
> which is almost the same, but avoids passing offs by address.

Is there any benefit to it, compared to keeping the value and return 
code separate ?

>>>> +{
>>>> +       /* R-Car Gen4 and older do not need any offset remap. */
>>>> +       if (!p->info.has_layout_gen5)
>>>> +               return 0;
>>>> +
>>>> +       /*
>>>> +        * R-Car Gen5 register layout is slightly different and the offsets
>>>> +        * that have to be added to or subtracted from each register offset
>>>> +        * can be divided into five groups, listed below.
>>>> +        */
>>>> +       switch (*offs) {
>>>> +       case IOINTSEL...OUTDT:
>>>> +               return 0;
>>>> +       case INDT:
>>>> +               *offs += 0x10;
>>>> +               return 0;
>>>> +       case INTDT...EDGLEVEL:
>>>> +               fallthrough;
>>>> +       case BOTHEDGE:
>>>> +               *offs += 0x70;
>>>> +               return 0;
>>>> +       case OUTDTSEL:
>>>> +               *offs -= 0x34;
>>>> +               return 0;
>>>> +       case INEN:
>>>> +               *offs -= 0x38;
>>>> +               return 0;
>>>> +       default:
>>>> +               /*
>>>> +                * This here must never be reached, if this is reached, that
>>>> +                * means there is a catastrophic failure in the driver. Skip
>>>> +                * any IO read/write to prevent further damage.
>>>> +                */
>>>> +               WARN_ON(1);
>>>
>>> A build-time failure would be better.  I tried BUILD_BUG() instead,
>>> but unfortunately gcc is not smart enough to notice this case is
>>> never reached.  __always_inline doesn't seem to help either.
>> I had one more idea -- how about we convert the driver to mmio regmap,
>> use opaque register numbers throughout the driver to identify registers
>> to the regmap (maybe not a great idea), and then implement .read/.write
>> callbacks in the regmap_config which instead of doing plain
>> readl()/writel() for register IO would instead do this remapping ?
>> Regmap could validate that the opaque register numbers are only the
>> expected register numbers and reject all the others. Maybe the opaque
>> register numbers could instead of Gen4 register offsets. What do you think ?
> 
> That's similar (but more complex?) than the array look-up
> in drivers/tty/serial/sh-sci.c I pointed to before.
> drivers/i2c/busses/i2c-riic.c uses the same method.

Those do not use regmap (drivers/base/regmap/), do they ?

> I.e. just convert the existing register defines into an enum, and use
> that to index a table with the family-specific offsets?
Are we back to the table look up discussion instead of remap function ?

  reply	other threads:[~2026-09-07 16:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-04 15:13 [PATCH 1/2] dt-bindings: gpio: renesas,rcar-gpio: Document R-Car X5H (R8A78000) support Marek Vasut
2026-07-04 15:13 ` [PATCH 2/2] gpio: rcar: Add " Marek Vasut
2026-07-06  9:19   ` Bartosz Golaszewski
2026-07-06 13:06     ` Marek Vasut
2026-07-07  6:52       ` Geert Uytterhoeven
2026-07-08 22:31         ` Marek Vasut
2026-07-07 13:48       ` Bartosz Golaszewski
2026-07-07 13:53         ` Geert Uytterhoeven
2026-09-04 11:15   ` Geert Uytterhoeven
2026-09-05 21:57     ` Marek Vasut
2026-09-07  7:53       ` Geert Uytterhoeven
2026-09-07 12:10         ` Marek Vasut [this message]
2026-09-08  7:49           ` Geert Uytterhoeven
2026-09-09  1:34             ` Marek Vasut
2026-09-09  7:09               ` Geert Uytterhoeven
2026-07-05 14:40 ` [PATCH 1/2] dt-bindings: gpio: renesas,rcar-gpio: Document " Conor Dooley
2026-09-04 11:11 ` Geert Uytterhoeven

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=43eccc85-fca3-4c69-9114-b45ab5e1b487@mailbox.org \
    --to=marek.vasut@mailbox.org \
    --cc=brgl@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=krzk+dt@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@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