RE: [PATCH 6/7] iio: adc: ad485x: add ad485x driver

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

 



> > +static int ad485x_get_calibbias(struct ad485x_state *st, int ch, int *val,
> > +				int *val2)
> > +{
> > +	unsigned int lsb, mid, msb;
> > +	int ret;
> > +
> > +	guard(mutex)(&st->lock);
> > +
> > +	ret = regmap_read(st->regmap, AD485X_REG_CHX_OFFSET_MSB(ch),
> > +			  &msb);
> > +	if (ret)
> > +		return ret;
> > +
> > +	ret = regmap_read(st->regmap, AD485X_REG_CHX_OFFSET_MID(ch),
> > +			  &mid);
> > +	if (ret)
> > +		return ret;
> > +
> > +	ret = regmap_read(st->regmap, AD485X_REG_CHX_OFFSET_LSB(ch),
> > +			  &lsb);
> > +	if (ret)
> > +		return ret;
> > +
> > +	if (st->info->resolution == 16) {
> > +		*val = msb << 8;
> > +		*val |= mid;
> > +		*val = sign_extend32(*val, 15);
> > +	} else {
> > +		*val = msb << 12;
> > +		*val |= mid << 4;
> > +		*val |= lsb >> 4;
> As below I'd use a byte array then you can do get_unaligned_be24 to
> + a right shift by 4 of the whole thing.
Regarding the bulk writes/reads, the msb/mid/lsb registers need to be read/write in a
specific order and the addresses are not incremental, so I am not sure how the bulk
functions fit. On this matter, we will need unsigned int (not u8) to store the values read via
regmap_read, and in this case we will need extra casts and assignments to use get_unaligned.
> 
> > +		*val = sign_extend32(*val, 19);
> > +	}
> > +
> > +	return IIO_VAL_INT;
> > +}
...




[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