ad5592r-base.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * AD5592R / AD5593R Digital <-> Analog converters driver
  3. *
  4. * Copyright 2015-2016 Analog Devices Inc.
  5. * Author: Paul Cercueil <paul.cercueil@analog.com>
  6. *
  7. * Licensed under the GPL-2.
  8. */
  9. #ifndef __DRIVERS_IIO_DAC_AD5592R_BASE_H__
  10. #define __DRIVERS_IIO_DAC_AD5592R_BASE_H__
  11. #include <linux/types.h>
  12. #include <linux/cache.h>
  13. #include <linux/mutex.h>
  14. #include <linux/gpio/driver.h>
  15. struct device;
  16. struct ad5592r_state;
  17. enum ad5592r_registers {
  18. AD5592R_REG_NOOP = 0x0,
  19. AD5592R_REG_DAC_READBACK = 0x1,
  20. AD5592R_REG_ADC_SEQ = 0x2,
  21. AD5592R_REG_CTRL = 0x3,
  22. AD5592R_REG_ADC_EN = 0x4,
  23. AD5592R_REG_DAC_EN = 0x5,
  24. AD5592R_REG_PULLDOWN = 0x6,
  25. AD5592R_REG_LDAC = 0x7,
  26. AD5592R_REG_GPIO_OUT_EN = 0x8,
  27. AD5592R_REG_GPIO_SET = 0x9,
  28. AD5592R_REG_GPIO_IN_EN = 0xA,
  29. AD5592R_REG_PD = 0xB,
  30. AD5592R_REG_OPEN_DRAIN = 0xC,
  31. AD5592R_REG_TRISTATE = 0xD,
  32. AD5592R_REG_RESET = 0xF,
  33. };
  34. #define AD5592R_REG_PD_EN_REF BIT(9)
  35. #define AD5592R_REG_CTRL_ADC_RANGE BIT(5)
  36. #define AD5592R_REG_CTRL_DAC_RANGE BIT(4)
  37. struct ad5592r_rw_ops {
  38. int (*write_dac)(struct ad5592r_state *st, unsigned chan, u16 value);
  39. int (*read_adc)(struct ad5592r_state *st, unsigned chan, u16 *value);
  40. int (*reg_write)(struct ad5592r_state *st, u8 reg, u16 value);
  41. int (*reg_read)(struct ad5592r_state *st, u8 reg, u16 *value);
  42. int (*gpio_read)(struct ad5592r_state *st, u8 *value);
  43. };
  44. struct ad5592r_state {
  45. struct device *dev;
  46. struct regulator *reg;
  47. struct gpio_chip gpiochip;
  48. struct mutex gpio_lock; /* Protect cached gpio_out, gpio_val, etc. */
  49. unsigned int num_channels;
  50. const struct ad5592r_rw_ops *ops;
  51. int scale_avail[2][2];
  52. u16 cached_dac[8];
  53. u16 cached_gp_ctrl;
  54. u8 channel_modes[8];
  55. u8 channel_offstate[8];
  56. u8 gpio_map;
  57. u8 gpio_out;
  58. u8 gpio_in;
  59. u8 gpio_val;
  60. __be16 spi_msg ____cacheline_aligned;
  61. __be16 spi_msg_nop;
  62. };
  63. int ad5592r_probe(struct device *dev, const char *name,
  64. const struct ad5592r_rw_ops *ops);
  65. int ad5592r_remove(struct device *dev);
  66. #endif /* __DRIVERS_IIO_DAC_AD5592R_BASE_H__ */