Skip to content

Commit b77c248

Browse files
iio: adc: Correct some values to properly reflect the IIO_CHAN_INFO_SCALE return value
- Remove max14001_get_scale method - Fix typo Signed-off-by: Marilene A Garcia <marilene.agarcia@gmail.com>
1 parent 42f812b commit b77c248

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

drivers/iio/adc/max14001.c

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@
7676
#define MAX14001_REG_WEN_WRITE_ENABLE 0x294
7777
#define MAX14001_REG_WEN_WRITE_DISABLE 0x0
7878

79-
/* MAX14001 10-bit ADC */
80-
#define MAX14001_NUMBER_OF_DATA_BITS 10
81-
#define MAX14001_BIT_DIV (1 << 10)
82-
8379
enum max14001_chip_model {
8480
max14001,
8581
max14002,
@@ -102,30 +98,21 @@ static struct max14001_chip_info max14001_chip_info_tbl[] = {
10298
struct max14001_state {
10399
struct spi_device *spi;
104100
const struct max14001_chip_info *chip_info;
105-
int vref_mV;
101+
int vref_mv;
106102
};
107103

108-
static int max14001_get_scale(struct max14001_state *st)
109-
{
110-
int scale;
111-
112-
/* scale = range / 2^10 */
113-
scale = st->vref_mV / MAX14001_BIT_DIV;
114-
return scale;
115-
}
116-
117-
static int max14001_get_vref_mV(struct max14001_state *st)
104+
static int max14001_get_vref_mv(struct max14001_state *st)
118105
{
119106
struct device *dev = &st->spi->dev;
120107
int ret = 0;
121108

122109
ret = devm_regulator_get_enable_read_voltage(dev, "vrefin");
123110
if (ret < 0){
124-
st->vref_mV = 1250000 / 1000;
125-
dev_info(&st->spi->dev, "%s: vrefin not found. vref_mV %d\n", __func__, st->vref_mV);
111+
st->vref_mv = 1250000 / 1000;
112+
dev_info(&st->spi->dev, "%s: vrefin not found. vref_mv %d\n", __func__, st->vref_mv);
126113
} else {
127-
st->vref_mV = ret / 1000;
128-
dev_info(&st->spi->dev, "%s: vrefin found. vref_mV %d\n", __func__, st->vref_mV);
114+
st->vref_mv = ret / 1000;
115+
dev_info(&st->spi->dev, "%s: vrefin found. vref_mv %d\n", __func__, st->vref_mv);
129116
}
130117

131118
return ret;
@@ -230,23 +217,22 @@ static int max14001_read_raw(struct iio_dev *indio_dev,
230217
switch (mask) {
231218
case IIO_CHAN_INFO_RAW:
232219
ret = max14001_spi_read(st, MAX14001_REG_ADC, val);
233-
dev_info(&st->spi->dev, "%s: IIO_CHAN_INFO_RAW: channel: %d, val: %d\n", __func__, chan->channel, val);
220+
dev_info(&st->spi->dev, "%s: IIO_CHAN_INFO_RAW: channel: %d, val: %d\n", __func__, chan->channel, *val);
234221
if (ret < 0)
235222
return ret;
236223

237224
return IIO_VAL_INT;
238225
case IIO_CHAN_INFO_AVERAGE_RAW:
239226
ret = max14001_spi_read(st, MAX14001_REG_FADC, val);
240-
dev_info(&st->spi->dev, "%s: IIO_CHAN_INFO_AVERAGE_RAW: channel: %d, val: %d\n", __func__, chan->channel, val);
227+
dev_info(&st->spi->dev, "%s: IIO_CHAN_INFO_AVERAGE_RAW: channel: %d, val: %d\n", __func__, chan->channel, *val);
241228
if (ret < 0)
242229
return ret;
243230

244231
return IIO_VAL_INT;
245232
case IIO_CHAN_INFO_SCALE:
246-
ret = max14001_get_scale(st);
247-
*val = ret;
248-
*val2 = MAX14001_NUMBER_OF_DATA_BITS;
249-
dev_info(&st->spi->dev, "%s: IIO_CHAN_INFO_SCALE: val: %d, val2: %d\n", __func__, val, val2);
233+
*val = st->vref_mv;
234+
*val2 = 10;
235+
dev_info(&st->spi->dev, "%s: IIO_CHAN_INFO_SCALE: val: %d, val2: %d\n", __func__, *val, *val2);
250236

251237
return IIO_VAL_FRACTIONAL_LOG2;
252238
}
@@ -262,7 +248,6 @@ static int max14001_write_raw(struct iio_dev *indio_dev,
262248
struct max14001_state *st = iio_priv(indio_dev);
263249

264250
switch (mask) {
265-
266251
}
267252

268253
return -EINVAL;
@@ -337,7 +322,7 @@ static int max14001_probe(struct spi_device *spi)
337322
dev_info(&st->spi->dev, "%s: probe\n", __func__);
338323

339324
max14001_init_required_regulators(st);
340-
max14001_get_vref_mV(st);
325+
max14001_get_vref_mv(st);
341326

342327
return devm_iio_device_register(&spi->dev, indio_dev);
343328
}

0 commit comments

Comments
 (0)