ad5446.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_AD5446_H
  3. #define _LINUX_AD5446_H
  4. #include <linux/bits.h>
  5. #include <linux/compiler.h>
  6. #include <linux/iio/iio.h>
  7. #include <linux/mutex.h>
  8. #include <linux/types.h>
  9. struct device;
  10. extern const struct iio_chan_spec_ext_info ad5446_ext_info_powerdown[];
  11. #define _AD5446_CHANNEL(bits, storage, _shift, ext) { \
  12. .type = IIO_VOLTAGE, \
  13. .indexed = 1, \
  14. .output = 1, \
  15. .channel = 0, \
  16. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
  17. .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
  18. .scan_type = { \
  19. .sign = 'u', \
  20. .realbits = (bits), \
  21. .storagebits = (storage), \
  22. .shift = (_shift), \
  23. }, \
  24. .ext_info = (ext), \
  25. }
  26. #define AD5446_CHANNEL(bits, storage, shift) \
  27. _AD5446_CHANNEL(bits, storage, shift, NULL)
  28. #define AD5446_CHANNEL_POWERDOWN(bits, storage, shift) \
  29. _AD5446_CHANNEL(bits, storage, shift, ad5446_ext_info_powerdown)
  30. /**
  31. * struct ad5446_state - driver instance specific data
  32. * @dev: this device
  33. * @chip_info: chip model specific constants, available modes etc
  34. * @vref_mv: actual reference voltage used
  35. * @cached_val: store/retrieve values during power down
  36. * @pwr_down_mode: power down mode (1k, 100k or tristate)
  37. * @pwr_down: true if the device is in power down
  38. * @lock: lock to protect the data buffer during write ops
  39. */
  40. struct ad5446_state {
  41. struct device *dev;
  42. const struct ad5446_chip_info *chip_info;
  43. unsigned short vref_mv;
  44. unsigned int cached_val;
  45. unsigned int pwr_down_mode;
  46. unsigned int pwr_down;
  47. /* mutex to protect device shared data */
  48. struct mutex lock;
  49. union {
  50. __be16 d16;
  51. u8 d24[3];
  52. } __aligned(IIO_DMA_MINALIGN);
  53. };
  54. /**
  55. * struct ad5446_chip_info - chip specific information
  56. * @channel: channel spec for the DAC
  57. * @int_vref_mv: AD5620/40/60: the internal reference voltage
  58. * @write: chip specific helper function to write to the register
  59. */
  60. struct ad5446_chip_info {
  61. struct iio_chan_spec channel;
  62. u16 int_vref_mv;
  63. int (*write)(struct ad5446_state *st, unsigned int val);
  64. };
  65. int ad5446_probe(struct device *dev, const char *name,
  66. const struct ad5446_chip_info *chip_info);
  67. #endif