Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: adc: ad7091r: Move generic AD7091R code to base driver and header file

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>

authored by

Marcelo Schmitt and committed by
Jonathan Cameron
5b035ed0 e71c5c89

+42 -37
+4 -25
drivers/iio/adc/ad7091r-base.c
··· 16 16 17 17 #include "ad7091r-base.h" 18 18 19 - #define AD7091R_REG_RESULT 0 20 - #define AD7091R_REG_CHANNEL 1 21 - #define AD7091R_REG_CONF 2 22 - #define AD7091R_REG_ALERT 3 23 - #define AD7091R_REG_CH_LOW_LIMIT(ch) ((ch) * 3 + 4) 24 - #define AD7091R_REG_CH_HIGH_LIMIT(ch) ((ch) * 3 + 5) 25 - #define AD7091R_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6) 26 - 27 19 /* AD7091R_REG_RESULT */ 28 20 #define AD7091R_REG_RESULT_CH_ID(x) (((x) >> 13) & 0x3) 29 21 #define AD7091R_REG_RESULT_CONV_RESULT(x) ((x) & 0xfff) ··· 27 35 28 36 #define AD7091R_REG_CONF_MODE_MASK \ 29 37 (AD7091R_REG_CONF_AUTO | AD7091R_REG_CONF_CMD) 30 - 31 - enum ad7091r_mode { 32 - AD7091R_MODE_SAMPLE, 33 - AD7091R_MODE_COMMAND, 34 - AD7091R_MODE_AUTOCYCLE, 35 - }; 36 - 37 - struct ad7091r_state { 38 - struct device *dev; 39 - struct regmap *map; 40 - struct regulator *vref; 41 - const struct ad7091r_chip_info *chip_info; 42 - enum ad7091r_mode mode; 43 - struct mutex lock; /*lock to prevent concurent reads */ 44 - }; 45 38 46 39 const struct iio_event_spec ad7091r_events[] = { 47 40 { ··· 409 432 } 410 433 EXPORT_SYMBOL_NS_GPL(ad7091r_probe, IIO_AD7091R); 411 434 412 - static bool ad7091r_writeable_reg(struct device *dev, unsigned int reg) 435 + bool ad7091r_writeable_reg(struct device *dev, unsigned int reg) 413 436 { 414 437 switch (reg) { 415 438 case AD7091R_REG_RESULT: ··· 419 442 return true; 420 443 } 421 444 } 445 + EXPORT_SYMBOL_NS_GPL(ad7091r_writeable_reg, IIO_AD7091R); 422 446 423 - static bool ad7091r_volatile_reg(struct device *dev, unsigned int reg) 447 + bool ad7091r_volatile_reg(struct device *dev, unsigned int reg) 424 448 { 425 449 switch (reg) { 426 450 case AD7091R_REG_RESULT: ··· 431 453 return false; 432 454 } 433 455 } 456 + EXPORT_SYMBOL_NS_GPL(ad7091r_volatile_reg, IIO_AD7091R); 434 457 435 458 const struct regmap_config ad7091r_regmap_config = { 436 459 .reg_bits = 8,
+38 -1
drivers/iio/adc/ad7091r-base.h
··· 8 8 #ifndef __DRIVERS_IIO_ADC_AD7091R_BASE_H__ 9 9 #define __DRIVERS_IIO_ADC_AD7091R_BASE_H__ 10 10 11 + #define AD7091R_REG_RESULT 0 12 + #define AD7091R_REG_CHANNEL 1 13 + #define AD7091R_REG_CONF 2 14 + #define AD7091R_REG_ALERT 3 15 + #define AD7091R_REG_CH_LOW_LIMIT(ch) ((ch) * 3 + 4) 16 + #define AD7091R_REG_CH_HIGH_LIMIT(ch) ((ch) * 3 + 5) 17 + #define AD7091R_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6) 18 + 11 19 #define AD7091R_REG_CONF_INT_VREF BIT(0) 12 20 13 21 /* AD7091R_REG_CH_LIMIT */ 14 22 #define AD7091R_HIGH_LIMIT 0xFFF 15 23 #define AD7091R_LOW_LIMIT 0x0 16 24 25 + #define AD7091R_CHANNEL(idx, bits, ev, num_ev) { \ 26 + .type = IIO_VOLTAGE, \ 27 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 28 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 29 + .indexed = 1, \ 30 + .channel = idx, \ 31 + .event_spec = ev, \ 32 + .num_event_specs = num_ev, \ 33 + .scan_type.storagebits = 16, \ 34 + .scan_type.realbits = bits, \ 35 + } 36 + 17 37 struct device; 18 - struct ad7091r_state; 38 + 39 + enum ad7091r_mode { 40 + AD7091R_MODE_SAMPLE, 41 + AD7091R_MODE_COMMAND, 42 + AD7091R_MODE_AUTOCYCLE, 43 + }; 44 + 45 + struct ad7091r_state { 46 + struct device *dev; 47 + struct regmap *map; 48 + struct regulator *vref; 49 + const struct ad7091r_chip_info *chip_info; 50 + enum ad7091r_mode mode; 51 + struct mutex lock; /*lock to prevent concurent reads */ 52 + }; 19 53 20 54 struct ad7091r_chip_info { 21 55 unsigned int num_channels; ··· 64 30 int ad7091r_probe(struct device *dev, const char *name, 65 31 const struct ad7091r_chip_info *chip_info, 66 32 struct regmap *map, int irq); 33 + 34 + bool ad7091r_volatile_reg(struct device *dev, unsigned int reg); 35 + bool ad7091r_writeable_reg(struct device *dev, unsigned int reg); 67 36 68 37 #endif /* __DRIVERS_IIO_ADC_AD7091R_BASE_H__ */
-11
drivers/iio/adc/ad7091r5.c
··· 12 12 13 13 #include "ad7091r-base.h" 14 14 15 - #define AD7091R_CHANNEL(idx, bits, ev, num_ev) { \ 16 - .type = IIO_VOLTAGE, \ 17 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 18 - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 19 - .indexed = 1, \ 20 - .channel = idx, \ 21 - .event_spec = ev, \ 22 - .num_event_specs = num_ev, \ 23 - .scan_type.storagebits = 16, \ 24 - .scan_type.realbits = bits, \ 25 - } 26 15 static const struct iio_chan_spec ad7091r5_channels_irq[] = { 27 16 AD7091R_CHANNEL(0, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)), 28 17 AD7091R_CHANNEL(1, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),