Re: [PATCH v3] iio: imu: Add initial support for Bosch BMI160

From: Daniel Baluta
Date: Fri Apr 15 2016 - 10:49:57 EST


On Sun, Apr 10, 2016 at 5:35 PM, Jonathan Cameron <jic23@xxxxxxxxxx> wrote:
> On 06/04/16 15:58, Daniel Baluta wrote:
>> BMI160 is an Inertial Measurement Unit (IMU) which provides acceleration
>> and angular rate measurement. It also offers a secondary I2C interface
>> for connecting a magnetometer sensor (usually BMM160).
>>
>> Current driver offers support for accelerometer and gyroscope readings
>> via sysfs or via buffer interface using an external trigger (e.g.
>> hrtimer). Data is retrieved from IMU via I2C or SPI interface.
>>
>> Datasheet is at:
>> http://www.mouser.com/ds/2/783/BST-BMI160-DS000-07-786474.pdf
>>
>> Signed-off-by: Daniel Baluta <daniel.baluta@xxxxxxxxx>
> I'm still a little unconvinced abou the data handling in the trigger_handler.
> Sample should be __le16 I think which would make it all rather more
> obvious.

<snip>

>> +static irqreturn_t bmi160_trigger_handler(int irq, void *p)
>> +{
>> + struct iio_poll_func *pf = p;
>> + struct iio_dev *indio_dev = pf->indio_dev;
>> + struct bmi160_data *data = iio_priv(indio_dev);
>> + s16 buf[16]; /* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */
>> + int i, ret, sample, j = 0, base = BMI160_REG_DATA_MAGN_XOUT_L;
>> +
>> + for_each_set_bit(i, indio_dev->active_scan_mask,
>> + indio_dev->masklength) {
>> + ret = regmap_bulk_read(data->regmap, base + i * sizeof(__le16),
>> + &sample, sizeof(__le16));
> Shouldn't sample be an __le16 ideally? Then you could use sizeof(sample)
> as well which would be more obviously right...

But will keep sizeof(__le16) similar with bmi160_get_data

>
>> + if (ret < 0)
>> + goto done;
>> + buf[j++] = sample;
> Probably makes sense to make buf __le16 buf[16] as well though that one isn't
> as important (and perhaps missleading in some ways)

Agree, will make sample an __le16 and keep s16 buf[16].

Daniel.