Messages in this thread | | | From | Andy Shevchenko <> | Date | Sun, 19 Jun 2022 12:51:26 +0200 | Subject | Re: [PATCH v3 10/16] iio: adc: axp20x_adc: Minor code cleanups |
| |
On Sat, Jun 18, 2022 at 11:40 PM Aidan MacDonald <aidanmacdonald.0x0@gmail.com> 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
| |