Re: [PATCH v7 3/3] pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 22, 2024 at 7:10 AM Jacky Huang <ychuang570808@xxxxxxxxx> 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.

-- 
With Best Regards,
Andy Shevchenko





[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux