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 Thu, Dec 19, 2019 at 6:27 AM Dan Robertson <dan@xxxxxxxxxxxxxxx> wrote:
> Add a IIO driver for the Bosch BMA400 3-axes ultra-low power accelerometer.
> The driver supports reading from the acceleration and temperature
> registers. The driver also supports reading and configuring the output data
> rate, oversampling ratio, and scale.

...

> +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?

> +               if (!is_power_of_2(val))
> +                       return -EINVAL;
> +
> +               idx = __ffs(val) + BMA400_ACC_ODR_MIN_RAW + 1;
> +       } else if (hz == BMA400_ACC_ODR_MIN_HZ && uhz == 500000) {
> +               idx = BMA400_ACC_ODR_MIN_RAW;
> +       } else {
> +               return -EINVAL;
> +       }
> +
> +       ret = regmap_read(data->regmap, BMA400_ACC_CONFIG1_REG, &val);
> +       if (ret)
> +               return ret;
> +
> +       /* preserve the range and normal mode osr */

> +       odr = idx | (~BMA400_ACC_ODR_MASK & val);

Yoda style?

> +
> +       ret = regmap_write(data->regmap, BMA400_ACC_CONFIG1_REG, odr);
> +       if (ret)
> +               return ret;
> +
> +       bma400_output_data_rate_from_raw(idx, &data->sample_freq.hz,
> +                                        &data->sample_freq.uhz);
> +       return 0;
> +}
...

> +int bma400_accel_scale_to_raw(struct bma400_data *data, unsigned int val)
> +{
> +       int scale = val / BMA400_SCALE_MIN;
> +       int raw;
> +
> +       if (scale == 0)
> +               return -EINVAL;
> +
> +       raw = __ffs(scale);
> +
> +       if (val % BMA400_SCALE_MIN || !is_power_of_2(scale))
> +               return -EINVAL;

Ditto.

> +
> +       return raw;
> +}

...

> +out:

Make a little sense. Why not return directly?

> +       return ret;

...

> +       ret = bma400_init(data);
> +       if (ret < 0)

May it be positive value returned?

> +               return ret;

...

> +static int bma400_i2c_probe(struct i2c_client *client,
> +                           const struct i2c_device_id *id)
> +{
> +       struct regmap *regmap;
> +
> +       regmap = devm_regmap_init_i2c(client, &bma400_regmap_config);

> +

Redundant blank line.

> +       if (IS_ERR(regmap)) {
> +               dev_err(&client->dev, "failed to create regmap\n");
> +               return PTR_ERR(regmap);
> +       }
> +
> +       return bma400_probe(&client->dev, regmap, id->name);
> +}

-- 
With Best Regards,
Andy Shevchenko



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux