iio: adc: max1027: Prepare the introduction of different resolutions

Maxim's max1027/29/31 series returns the measured voltages with a
resolution of 10 bits. There is a very similar series, max1227/29/31
which works identically but uses a resolution of 12 bits. Prepare the
support for these chips by turning the 'depth' into a macro parameter
instead of hardcoding it everywhere. Also reorganize just a bit the
macros at the top to avoid repeating tens of lines when adding support
for a new chip.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
Miquel Raynal 2019-10-11 16:43:43 +02:00 коммит произвёл Jonathan Cameron
Родитель db033831b4
Коммит 7af5257d84
1 изменённых файлов: 32 добавлений и 42 удалений

Просмотреть файл

@ -83,7 +83,7 @@ static const struct of_device_id max1027_adc_dt_ids[] = {
MODULE_DEVICE_TABLE(of, max1027_adc_dt_ids); MODULE_DEVICE_TABLE(of, max1027_adc_dt_ids);
#endif #endif
#define MAX1027_V_CHAN(index) \ #define MAX1027_V_CHAN(index, depth) \
{ \ { \
.type = IIO_VOLTAGE, \ .type = IIO_VOLTAGE, \
.indexed = 1, \ .indexed = 1, \
@ -93,7 +93,7 @@ MODULE_DEVICE_TABLE(of, max1027_adc_dt_ids);
.scan_index = index + 1, \ .scan_index = index + 1, \
.scan_type = { \ .scan_type = { \
.sign = 'u', \ .sign = 'u', \
.realbits = 10, \ .realbits = depth, \
.storagebits = 16, \ .storagebits = 16, \
.shift = 2, \ .shift = 2, \
.endianness = IIO_BE, \ .endianness = IIO_BE, \
@ -115,52 +115,42 @@ MODULE_DEVICE_TABLE(of, max1027_adc_dt_ids);
}, \ }, \
} }
#define MAX1X27_CHANNELS(depth) \
MAX1027_T_CHAN, \
MAX1027_V_CHAN(0, depth), \
MAX1027_V_CHAN(1, depth), \
MAX1027_V_CHAN(2, depth), \
MAX1027_V_CHAN(3, depth), \
MAX1027_V_CHAN(4, depth), \
MAX1027_V_CHAN(5, depth), \
MAX1027_V_CHAN(6, depth), \
MAX1027_V_CHAN(7, depth)
#define MAX1X29_CHANNELS(depth) \
MAX1X27_CHANNELS(depth), \
MAX1027_V_CHAN(8, depth), \
MAX1027_V_CHAN(9, depth), \
MAX1027_V_CHAN(10, depth), \
MAX1027_V_CHAN(11, depth)
#define MAX1X31_CHANNELS(depth) \
MAX1X27_CHANNELS(depth), \
MAX1X29_CHANNELS(depth), \
MAX1027_V_CHAN(12, depth), \
MAX1027_V_CHAN(13, depth), \
MAX1027_V_CHAN(14, depth), \
MAX1027_V_CHAN(15, depth)
static const struct iio_chan_spec max1027_channels[] = { static const struct iio_chan_spec max1027_channels[] = {
MAX1027_T_CHAN, MAX1X27_CHANNELS(10),
MAX1027_V_CHAN(0),
MAX1027_V_CHAN(1),
MAX1027_V_CHAN(2),
MAX1027_V_CHAN(3),
MAX1027_V_CHAN(4),
MAX1027_V_CHAN(5),
MAX1027_V_CHAN(6),
MAX1027_V_CHAN(7)
}; };
static const struct iio_chan_spec max1029_channels[] = { static const struct iio_chan_spec max1029_channels[] = {
MAX1027_T_CHAN, MAX1X29_CHANNELS(10),
MAX1027_V_CHAN(0),
MAX1027_V_CHAN(1),
MAX1027_V_CHAN(2),
MAX1027_V_CHAN(3),
MAX1027_V_CHAN(4),
MAX1027_V_CHAN(5),
MAX1027_V_CHAN(6),
MAX1027_V_CHAN(7),
MAX1027_V_CHAN(8),
MAX1027_V_CHAN(9),
MAX1027_V_CHAN(10),
MAX1027_V_CHAN(11)
}; };
static const struct iio_chan_spec max1031_channels[] = { static const struct iio_chan_spec max1031_channels[] = {
MAX1027_T_CHAN, MAX1X31_CHANNELS(10),
MAX1027_V_CHAN(0),
MAX1027_V_CHAN(1),
MAX1027_V_CHAN(2),
MAX1027_V_CHAN(3),
MAX1027_V_CHAN(4),
MAX1027_V_CHAN(5),
MAX1027_V_CHAN(6),
MAX1027_V_CHAN(7),
MAX1027_V_CHAN(8),
MAX1027_V_CHAN(9),
MAX1027_V_CHAN(10),
MAX1027_V_CHAN(11),
MAX1027_V_CHAN(12),
MAX1027_V_CHAN(13),
MAX1027_V_CHAN(14),
MAX1027_V_CHAN(15)
}; };
static const unsigned long max1027_available_scan_masks[] = { static const unsigned long max1027_available_scan_masks[] = {
@ -284,7 +274,7 @@ static int max1027_read_raw(struct iio_dev *indio_dev,
break; break;
case IIO_VOLTAGE: case IIO_VOLTAGE:
*val = 2500; *val = 2500;
*val2 = 10; *val2 = chan->scan_type.realbits;
ret = IIO_VAL_FRACTIONAL_LOG2; ret = IIO_VAL_FRACTIONAL_LOG2;
break; break;
default: default: