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]

 



Dear Andy,


On 2024/4/22 下午 04:16, Andy Shevchenko wrote:
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.


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


Best Regards,
Jacky Huang





[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux