iio: adc: ad7091r: Move generic AD7091R code to base driver and header file
authorMarcelo Schmitt <marcelo.schmitt@analog.com>
Tue, 19 Dec 2023 20:27:04 +0000 (17:27 -0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 26 Dec 2023 15:40:41 +0000 (15:40 +0000)
Some code generic to AD7091R devices such as channel definitions were in
the AD7091R-5 driver. There was also some generic register definitions
declared in the base driver which would make more sense to be in the
header file.
The device state struct will be needed for the ad7091r8 driver in a
follow up patch so that ought to be moved to the header file as well.
Lastly, a couple of regmap callback functions are also capable of
abstracting characteristics of different AD7091R devices and those are
now being exported to IIO_AD7091R name space.

Move AD7091R generic code either to the base driver or to the header
file so both the ad7091r5 and the ad7091r8 driver can use those
declaration in follow up patches.

Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
Link: https://lore.kernel.org/r/6376fc523ee503d47ec499e2cd2ef13bfb5fd8ba.1703013352.git.marcelo.schmitt1@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad7091r-base.c
drivers/iio/adc/ad7091r-base.h
drivers/iio/adc/ad7091r5.c

index 7ccc9b44dcd88c4e70b523aa3ec4d529f32b0b9f..3f05e94c756fc5dd6cc7b0ff930e37abe001a61d 100644 (file)
 
 #include "ad7091r-base.h"
 
-#define AD7091R_REG_RESULT  0
-#define AD7091R_REG_CHANNEL 1
-#define AD7091R_REG_CONF    2
-#define AD7091R_REG_ALERT   3
-#define AD7091R_REG_CH_LOW_LIMIT(ch) ((ch) * 3 + 4)
-#define AD7091R_REG_CH_HIGH_LIMIT(ch) ((ch) * 3 + 5)
-#define AD7091R_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6)
-
 /* AD7091R_REG_RESULT */
 #define AD7091R_REG_RESULT_CH_ID(x)        (((x) >> 13) & 0x3)
 #define AD7091R_REG_RESULT_CONV_RESULT(x)   ((x) & 0xfff)
 #define AD7091R_REG_CONF_MODE_MASK  \
        (AD7091R_REG_CONF_AUTO | AD7091R_REG_CONF_CMD)
 
-enum ad7091r_mode {
-       AD7091R_MODE_SAMPLE,
-       AD7091R_MODE_COMMAND,
-       AD7091R_MODE_AUTOCYCLE,
-};
-
-struct ad7091r_state {
-       struct device *dev;
-       struct regmap *map;
-       struct regulator *vref;
-       const struct ad7091r_chip_info *chip_info;
-       enum ad7091r_mode mode;
-       struct mutex lock; /*lock to prevent concurent reads */
-};
-
 const struct iio_event_spec ad7091r_events[] = {
        {
                .type = IIO_EV_TYPE_THRESH,
@@ -432,7 +409,7 @@ int ad7091r_probe(struct device *dev, const char *name,
 }
 EXPORT_SYMBOL_NS_GPL(ad7091r_probe, IIO_AD7091R);
 
-static bool ad7091r_writeable_reg(struct device *dev, unsigned int reg)
+bool ad7091r_writeable_reg(struct device *dev, unsigned int reg)
 {
        switch (reg) {
        case AD7091R_REG_RESULT:
@@ -442,8 +419,9 @@ static bool ad7091r_writeable_reg(struct device *dev, unsigned int reg)
                return true;
        }
 }
+EXPORT_SYMBOL_NS_GPL(ad7091r_writeable_reg, IIO_AD7091R);
 
-static bool ad7091r_volatile_reg(struct device *dev, unsigned int reg)
+bool ad7091r_volatile_reg(struct device *dev, unsigned int reg)
 {
        switch (reg) {
        case AD7091R_REG_RESULT:
@@ -453,6 +431,7 @@ static bool ad7091r_volatile_reg(struct device *dev, unsigned int reg)
                return false;
        }
 }
+EXPORT_SYMBOL_NS_GPL(ad7091r_volatile_reg, IIO_AD7091R);
 
 const struct regmap_config ad7091r_regmap_config = {
        .reg_bits = 8,
index b9e1c8bf3440a494ff5e06199d84908838c6ce14..b63c658a9d2384dcb64908ed2ebaded6725d0873 100644 (file)
@@ -8,14 +8,48 @@
 #ifndef __DRIVERS_IIO_ADC_AD7091R_BASE_H__
 #define __DRIVERS_IIO_ADC_AD7091R_BASE_H__
 
+#define AD7091R_REG_RESULT  0
+#define AD7091R_REG_CHANNEL 1
+#define AD7091R_REG_CONF    2
+#define AD7091R_REG_ALERT   3
+#define AD7091R_REG_CH_LOW_LIMIT(ch) ((ch) * 3 + 4)
+#define AD7091R_REG_CH_HIGH_LIMIT(ch) ((ch) * 3 + 5)
+#define AD7091R_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6)
+
 #define AD7091R_REG_CONF_INT_VREF      BIT(0)
 
 /* AD7091R_REG_CH_LIMIT */
 #define AD7091R_HIGH_LIMIT             0xFFF
 #define AD7091R_LOW_LIMIT              0x0
 
+#define AD7091R_CHANNEL(idx, bits, ev, num_ev) {                       \
+       .type = IIO_VOLTAGE,                                            \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),                   \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),           \
+       .indexed = 1,                                                   \
+       .channel = idx,                                                 \
+       .event_spec = ev,                                               \
+       .num_event_specs = num_ev,                                      \
+       .scan_type.storagebits = 16,                                    \
+       .scan_type.realbits = bits,                                     \
+}
+
 struct device;
-struct ad7091r_state;
+
+enum ad7091r_mode {
+       AD7091R_MODE_SAMPLE,
+       AD7091R_MODE_COMMAND,
+       AD7091R_MODE_AUTOCYCLE,
+};
+
+struct ad7091r_state {
+       struct device *dev;
+       struct regmap *map;
+       struct regulator *vref;
+       const struct ad7091r_chip_info *chip_info;
+       enum ad7091r_mode mode;
+       struct mutex lock; /*lock to prevent concurent reads */
+};
 
 struct ad7091r_chip_info {
        unsigned int num_channels;
@@ -31,4 +65,7 @@ int ad7091r_probe(struct device *dev, const char *name,
                const struct ad7091r_chip_info *chip_info,
                struct regmap *map, int irq);
 
+bool ad7091r_volatile_reg(struct device *dev, unsigned int reg);
+bool ad7091r_writeable_reg(struct device *dev, unsigned int reg);
+
 #endif /* __DRIVERS_IIO_ADC_AD7091R_BASE_H__ */
index dae98c95ebb87b370455164be030aaec0e543cbd..9d3ccfca94eccab42fe06c165374a009dde8341b 100644 (file)
 
 #include "ad7091r-base.h"
 
-#define AD7091R_CHANNEL(idx, bits, ev, num_ev) { \
-       .type = IIO_VOLTAGE, \
-       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
-       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
-       .indexed = 1, \
-       .channel = idx, \
-       .event_spec = ev, \
-       .num_event_specs = num_ev, \
-       .scan_type.storagebits = 16, \
-       .scan_type.realbits = bits, \
-}
 static const struct iio_chan_spec ad7091r5_channels_irq[] = {
        AD7091R_CHANNEL(0, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
        AD7091R_CHANNEL(1, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),