Re: [PATCH v7 2/3] iio: (bma400) add driver for the BMA400

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

 



On Fri, Dec 20, 2019 at 6:48 AM Dan Robertson <dan@xxxxxxxxxxxxxxx> wrote:
> On Thu, Dec 19, 2019 at 01:02:28PM +0200, Andy Shevchenko wrote:
> > On Thu, Dec 19, 2019 at 6:27 AM Dan Robertson <dan@xxxxxxxxxxxxxxx> wrote:

> > > +static int bma400_set_accel_output_data_rate(struct bma400_data *data,
> > > +                                            int hz, int uhz)
> > > +{
> > > +       unsigned int idx;
> > > +       unsigned int odr;
> > > +       unsigned int val;
> > > +       int ret;
> > > +
> > > +       if (hz >= BMA400_ACC_ODR_MIN_WHOLE_HZ) {
> > > +               if (uhz || hz % BMA400_ACC_ODR_MIN_WHOLE_HZ)
> > > +                       return -EINVAL;
> > > +
> > > +               val = hz / BMA400_ACC_ODR_MIN_WHOLE_HZ;
> >
> > Again, AFAICS division may be avoided in both cases (% and / above)
> > because of is_power_of_2() check below.
> > Can you revisit this?
>
> Yeah I can update this in the next patchset, but I don't know if it is much more
> readable this way.

You may describe the algo in the comment.

Let's see how it might look like

  if (uhz)
    return -EINVAL;
  idx = __ffs(val);
  /* We're expecting value to be 2^n * ODR_MIN_WHOLE_HZ */
  if ((val >> idx) != BMA400_ACC_ODR_MIN_WHOLE_HZ)
    retutn -EINVAL;
  idx += BMA400_ACC_ODR_MIN_RAW + 1;

Would it work?

> > > +               if (!is_power_of_2(val))
> > > +                       return -EINVAL;
> > > +
> > > +               idx = __ffs(val) + BMA400_ACC_ODR_MIN_RAW + 1;


-- 
With Best Regards,
Andy Shevchenko



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux