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

Jacky Huang ychuang570808 at gmail.com
Sun Apr 21 21:10:39 PDT 2024


Dear Andy,


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),
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?


Best Regards,
Jacky Huang






More information about the linux-arm-kernel mailing list