Re: [PATCH v3 10/16] iio: adc: axp20x_adc: Minor code cleanups

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

 



On Sat, Jun 18, 2022 at 11:40 PM Aidan MacDonald
<aidanmacdonald.0x0@xxxxxxxxx> wrote:
>
> The code may be clearer if parameters are not re-purposed to hold
> temporary results like register values, so introduce local variables
> as necessary to avoid that. Also, use the common FIELD_PREP macro

FIELD_PREP()

> instead of a hand-rolled version.

...

>  #include <linux/property.h>
>  #include <linux/regmap.h>
>  #include <linux/thermal.h>
> +#include <linux/bitfield.h>

Keep it sorted?

...

> -       val = val ? 1 : 0;
> +       regval = val ? 1 : 0;
>

I think you may drop these two lines (including blank line) and...

>         switch (chan->channel) {
>         case AXP20X_GPIO0_V:
> -               reg = AXP20X_GPIO10_IN_RANGE_GPIO0;
> -               regval = AXP20X_GPIO10_IN_RANGE_GPIO0_VAL(val);
> +               regmask = AXP20X_GPIO10_IN_RANGE_GPIO0;
> +               regval = FIELD_PREP(AXP20X_GPIO10_IN_RANGE_GPIO0, regval);

...use !!val as an argument here...

>                 break;
>
>         case AXP20X_GPIO1_V:
> -               reg = AXP20X_GPIO10_IN_RANGE_GPIO1;
> -               regval = AXP20X_GPIO10_IN_RANGE_GPIO1_VAL(val);
> +               regmask = AXP20X_GPIO10_IN_RANGE_GPIO1;
> +               regval = FIELD_PREP(AXP20X_GPIO10_IN_RANGE_GPIO1, regval);

...and here.

>                 break;
>
>         default:
>                 return -EINVAL;
>         }

-- 
With Best Regards,
Andy Shevchenko



[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