Linux-GPIO Archive mirror
 help / color / mirror / Atom feed
From: Jacky Huang <ychuang570808@gmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: linus.walleij@linaro.org, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
	p.zabel@pengutronix.de, j.neuschaefer@gmx.net,
	linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	ychuang3@nuvoton.com, schung@nuvoton.com
Subject: Re: [PATCH v7 3/3] pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver
Date: Mon, 22 Apr 2024 17:19:15 +0800	[thread overview]
Message-ID: <843c3c2a-2f46-4d49-aed4-ad07ebcb7b27@gmail.com> (raw)
In-Reply-To: <CAHp75VfMb_=XKoQNbbVphLg-eQgc6eJbZOW36g_hU=-iK2bSOQ@mail.gmail.com>

Dear Andy,


On 2024/4/22 下午 04:16, Andy Shevchenko wrote:
> On Mon, Apr 22, 2024 at 7:10 AM Jacky Huang <ychuang570808@gmail.com> wrote:
>> On 2024/4/10 下午 04:54, Andy Shevchenko wrote:
> ...
>
>>>> +#define MA35_GP_MODE_MASK_WIDTH              2
>>>> +
>>>> +#define MA35_GP_SLEWCTL_MASK_WIDTH   2
>>> I looked at the code how you use these... Oh, please switch to FIELD_GET() /
>>> FIELD_PREP() (don't forget to include bitfield.h)
>>>
>>> ...
>>>
>>> ...
>>>> +             regval &= ~GENMASK(setting->shift + MA35_MFP_BITS_PER_PORT - 1,
>>>> +                                setting->shift);
>>> This will generate an awful code. Use respective FIELD_*() macros.
>>>
>>> ...
>>>
>>>> +     regval &= ~GENMASK(gpio * MA35_GP_MODE_MASK_WIDTH - 1,
>>>> +                        gpio * MA35_GP_MODE_MASK_WIDTH);
>>>> +     regval |= mode << gpio * MA35_GP_MODE_MASK_WIDTH;
>>> Ditto.
>>>
>>> ...
>>>
>>>> +     regval &= GENMASK(gpio * MA35_GP_MODE_MASK_WIDTH - 1,
>>>> +                       gpio * MA35_GP_MODE_MASK_WIDTH);
>>>> +
>>>> +     return regval >> gpio * MA35_GP_MODE_MASK_WIDTH;
>>> Ditto.
> ...
>
>> Allow me to remove irrelevant parts.
>>
>> I attempted to follow your advice and use FIELD_GET() and FIELD_PREP(),
>> but found
>> it impractical. The reason is that these two macros require their 'mask'
>> argument
>> to be a constant, otherwise compilation errors occur, which is the issue
>> I encountered.
>> Since the mask here is calculated and not a constant, compilation errors
>> occur.
>>
>> Taking MA35_GP_REG_MODE as an example, within 32 bits, every 2 bits
>> represent
>> the mode of a GPIO pin, and the mask is obtained by GENMASK(gpio * 2 -1,
>> gpio * 2),
> This is not good for the compiler, it can't figure out (at least in
> some _supported_ by Linux kernel versions on some architectures) that
> GENMASK can be constant here just left-shifted by arbitrary bits.
>
>> where the 'gpio' argument is a variable, not a constant, leading to
>> compilation
>> errors.
>>
>> Due to this reason, I will leave this part unchanged, or do you have any
>> other suggestions?
> If you need non-constant field_get()/field_prep(), add a new patch
> that moves them from drivers/iio/temperature/mlx90614.c (and there are
> more custom implementations:
> https://elixir.bootlin.com/linux/latest/A/ident/field_get) to the
> bitfield.h and use them in your code.
>

Thank you. It works for me. I will adopt the approach used in mlx90614.c.


Best Regards,
Jacky Huang


      reply	other threads:[~2024-04-22  9:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-09  9:56 [PATCH v7 0/3] Add support for nuvoton ma35d1 pin control Jacky Huang
2024-04-09  9:56 ` [PATCH v7 1/3] dt-bindings: reset: Add syscon to nuvoton ma35d1 system-management node Jacky Huang
2024-04-09  9:56 ` [PATCH v7 2/3] dt-bindings: pinctrl: Document nuvoton ma35d1 pin control Jacky Huang
2024-04-09 16:29   ` Rob Herring
2024-04-10  2:53     ` Jacky Huang
2024-04-09  9:56 ` [PATCH v7 3/3] pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver Jacky Huang
2024-04-10  8:54   ` Andy Shevchenko
2024-04-15  1:18     ` Jacky Huang
2024-04-22  4:10     ` Jacky Huang
2024-04-22  8:16       ` Andy Shevchenko
2024-04-22  9:19         ` Jacky Huang [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=843c3c2a-2f46-4d49-aed4-ad07ebcb7b27@gmail.com \
    --to=ychuang570808@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=j.neuschaefer@gmx.net \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --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=p.zabel@pengutronix.de \
    --cc=robh+dt@kernel.org \
    --cc=schung@nuvoton.com \
    --cc=ychuang3@nuvoton.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).