[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID:
<CY4PR03MB33991208029C4877760B528D9B772@CY4PR03MB3399.namprd03.prod.outlook.com>
Date: Tue, 1 Oct 2024 11:53:18 +0000
From: "Miclaus, Antoniu" <Antoniu.Miclaus@...log.com>
To: Jonathan Cameron <jic23@...nel.org>
CC: Lars-Peter Clausen <lars@...afoo.de>,
"Hennerich, Michael"
<Michael.Hennerich@...log.com>,
Rob Herring <robh@...nel.org>,
Krzysztof
Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, "Sa,
Nuno" <Nuno.Sa@...log.com>,
Olivier Moysan <olivier.moysan@...s.st.com>,
Uwe Kleine-König <ukleinek@...nel.org>,
Andy Shevchenko
<andy@...nel.org>,
David Lechner <dlechner@...libre.com>,
"Schmitt, Marcelo"
<Marcelo.Schmitt@...log.com>,
João Paulo Gonçalves
<joao.goncalves@...adex.com>,
Mike Looijmans <mike.looijmans@...ic.nl>,
Dumitru Ceclan <mitrutzceclan@...il.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@...labora.com>,
Alisa-Dariana Roman
<alisadariana@...il.com>,
"Cuciurean, Sergiu" <Sergiu.Cuciurean@...log.com>,
"Bogdan, Dragos" <Dragos.Bogdan@...log.com>,
"linux-iio@...r.kernel.org"
<linux-iio@...r.kernel.org>,
"linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>,
"devicetree@...r.kernel.org"
<devicetree@...r.kernel.org>,
"linux-pwm@...r.kernel.org"
<linux-pwm@...r.kernel.org>
Subject: RE: [PATCH 6/7] iio: adc: ad485x: add ad485x driver
> > +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;
> > +}
...
Powered by blists - more mailing lists