iio: Add macro to populate struct iio_map array
authorLukas Wunner <lukas@wunner.de>
Sat, 25 Nov 2017 08:38:17 +0000 (09:38 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 2 Dec 2017 13:28:21 +0000 (13:28 +0000)
The GPIO core provides a handy GPIO_LOOKUP() macro to populate a struct
gpiod_lookup array without having to spell out attribute names (but
still avoid breakage when attributes within the struct are rearranged
or added).

The axp288_adc.c driver uses a similar macro to populate a struct
iio_map array.  Make it available to others.

Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Acked-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/axp288_adc.c
include/linux/iio/machine.h

index 60c9e85..031d568 100644 (file)
@@ -92,22 +92,14 @@ static const struct iio_chan_spec axp288_adc_channels[] = {
        },
 };
 
-#define AXP288_ADC_MAP(_adc_channel_label, _consumer_dev_name, \
-               _consumer_channel)                              \
-       {                                                       \
-               .adc_channel_label = _adc_channel_label,        \
-               .consumer_dev_name = _consumer_dev_name,        \
-               .consumer_channel = _consumer_channel,          \
-       }
-
 /* for consumer drivers */
 static struct iio_map axp288_adc_default_maps[] = {
-       AXP288_ADC_MAP("TS_PIN", "axp288-batt", "axp288-batt-temp"),
-       AXP288_ADC_MAP("PMIC_TEMP", "axp288-pmic", "axp288-pmic-temp"),
-       AXP288_ADC_MAP("GPADC", "axp288-gpadc", "axp288-system-temp"),
-       AXP288_ADC_MAP("BATT_CHG_I", "axp288-chrg", "axp288-chrg-curr"),
-       AXP288_ADC_MAP("BATT_DISCHRG_I", "axp288-chrg", "axp288-chrg-d-curr"),
-       AXP288_ADC_MAP("BATT_V", "axp288-batt", "axp288-batt-volt"),
+       IIO_MAP("TS_PIN", "axp288-batt", "axp288-batt-temp"),
+       IIO_MAP("PMIC_TEMP", "axp288-pmic", "axp288-pmic-temp"),
+       IIO_MAP("GPADC", "axp288-gpadc", "axp288-system-temp"),
+       IIO_MAP("BATT_CHG_I", "axp288-chrg", "axp288-chrg-curr"),
+       IIO_MAP("BATT_DISCHRG_I", "axp288-chrg", "axp288-chrg-d-curr"),
+       IIO_MAP("BATT_V", "axp288-batt", "axp288-batt-volt"),
        {},
 };
 
index 1601a2a..5e1cfa7 100644 (file)
@@ -28,4 +28,11 @@ struct iio_map {
        void *consumer_data;
 };
 
+#define IIO_MAP(_provider_channel, _consumer_dev_name, _consumer_channel) \
+{                                                                        \
+       .adc_channel_label = _provider_channel,                           \
+       .consumer_dev_name = _consumer_dev_name,                          \
+       .consumer_channel  = _consumer_channel,                           \
+}
+
 #endif