xilinx-xadc.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Xilinx XADC driver
  3. *
  4. * Copyright 2013 Analog Devices Inc.
  5. * Author: Lars-Peter Clauen <lars@metafoo.de>
  6. *
  7. * Licensed under the GPL-2.
  8. */
  9. #ifndef __IIO_XILINX_XADC__
  10. #define __IIO_XILINX_XADC__
  11. #include <linux/interrupt.h>
  12. #include <linux/mutex.h>
  13. #include <linux/spinlock.h>
  14. struct iio_dev;
  15. struct clk;
  16. struct xadc_ops;
  17. struct platform_device;
  18. void xadc_handle_events(struct iio_dev *indio_dev, unsigned long events);
  19. int xadc_read_event_config(struct iio_dev *indio_dev,
  20. const struct iio_chan_spec *chan, enum iio_event_type type,
  21. enum iio_event_direction dir);
  22. int xadc_write_event_config(struct iio_dev *indio_dev,
  23. const struct iio_chan_spec *chan, enum iio_event_type type,
  24. enum iio_event_direction dir, int state);
  25. int xadc_read_event_value(struct iio_dev *indio_dev,
  26. const struct iio_chan_spec *chan, enum iio_event_type type,
  27. enum iio_event_direction dir, enum iio_event_info info,
  28. int *val, int *val2);
  29. int xadc_write_event_value(struct iio_dev *indio_dev,
  30. const struct iio_chan_spec *chan, enum iio_event_type type,
  31. enum iio_event_direction dir, enum iio_event_info info,
  32. int val, int val2);
  33. enum xadc_external_mux_mode {
  34. XADC_EXTERNAL_MUX_NONE,
  35. XADC_EXTERNAL_MUX_SINGLE,
  36. XADC_EXTERNAL_MUX_DUAL,
  37. };
  38. struct xadc {
  39. void __iomem *base;
  40. struct clk *clk;
  41. const struct xadc_ops *ops;
  42. uint16_t threshold[16];
  43. uint16_t temp_hysteresis;
  44. unsigned int alarm_mask;
  45. uint16_t *data;
  46. struct iio_trigger *trigger;
  47. struct iio_trigger *convst_trigger;
  48. struct iio_trigger *samplerate_trigger;
  49. enum xadc_external_mux_mode external_mux_mode;
  50. unsigned int zynq_masked_alarm;
  51. unsigned int zynq_intmask;
  52. struct delayed_work zynq_unmask_work;
  53. struct mutex mutex;
  54. spinlock_t lock;
  55. struct completion completion;
  56. };
  57. struct xadc_ops {
  58. int (*read)(struct xadc *, unsigned int, uint16_t *);
  59. int (*write)(struct xadc *, unsigned int, uint16_t);
  60. int (*setup)(struct platform_device *pdev, struct iio_dev *indio_dev,
  61. int irq);
  62. void (*update_alarm)(struct xadc *, unsigned int);
  63. unsigned long (*get_dclk_rate)(struct xadc *);
  64. irqreturn_t (*interrupt_handler)(int, void *);
  65. unsigned int flags;
  66. };
  67. static inline int _xadc_read_adc_reg(struct xadc *xadc, unsigned int reg,
  68. uint16_t *val)
  69. {
  70. lockdep_assert_held(&xadc->mutex);
  71. return xadc->ops->read(xadc, reg, val);
  72. }
  73. static inline int _xadc_write_adc_reg(struct xadc *xadc, unsigned int reg,
  74. uint16_t val)
  75. {
  76. lockdep_assert_held(&xadc->mutex);
  77. return xadc->ops->write(xadc, reg, val);
  78. }
  79. static inline int xadc_read_adc_reg(struct xadc *xadc, unsigned int reg,
  80. uint16_t *val)
  81. {
  82. int ret;
  83. mutex_lock(&xadc->mutex);
  84. ret = _xadc_read_adc_reg(xadc, reg, val);
  85. mutex_unlock(&xadc->mutex);
  86. return ret;
  87. }
  88. static inline int xadc_write_adc_reg(struct xadc *xadc, unsigned int reg,
  89. uint16_t val)
  90. {
  91. int ret;
  92. mutex_lock(&xadc->mutex);
  93. ret = _xadc_write_adc_reg(xadc, reg, val);
  94. mutex_unlock(&xadc->mutex);
  95. return ret;
  96. }
  97. /* XADC hardmacro register definitions */
  98. #define XADC_REG_TEMP 0x00
  99. #define XADC_REG_VCCINT 0x01
  100. #define XADC_REG_VCCAUX 0x02
  101. #define XADC_REG_VPVN 0x03
  102. #define XADC_REG_VREFP 0x04
  103. #define XADC_REG_VREFN 0x05
  104. #define XADC_REG_VCCBRAM 0x06
  105. #define XADC_REG_VCCPINT 0x0d
  106. #define XADC_REG_VCCPAUX 0x0e
  107. #define XADC_REG_VCCO_DDR 0x0f
  108. #define XADC_REG_VAUX(x) (0x10 + (x))
  109. #define XADC_REG_MAX_TEMP 0x20
  110. #define XADC_REG_MAX_VCCINT 0x21
  111. #define XADC_REG_MAX_VCCAUX 0x22
  112. #define XADC_REG_MAX_VCCBRAM 0x23
  113. #define XADC_REG_MIN_TEMP 0x24
  114. #define XADC_REG_MIN_VCCINT 0x25
  115. #define XADC_REG_MIN_VCCAUX 0x26
  116. #define XADC_REG_MIN_VCCBRAM 0x27
  117. #define XADC_REG_MAX_VCCPINT 0x28
  118. #define XADC_REG_MAX_VCCPAUX 0x29
  119. #define XADC_REG_MAX_VCCO_DDR 0x2a
  120. #define XADC_REG_MIN_VCCPINT 0x2c
  121. #define XADC_REG_MIN_VCCPAUX 0x2d
  122. #define XADC_REG_MIN_VCCO_DDR 0x2e
  123. #define XADC_REG_CONF0 0x40
  124. #define XADC_REG_CONF1 0x41
  125. #define XADC_REG_CONF2 0x42
  126. #define XADC_REG_SEQ(x) (0x48 + (x))
  127. #define XADC_REG_INPUT_MODE(x) (0x4c + (x))
  128. #define XADC_REG_THRESHOLD(x) (0x50 + (x))
  129. #define XADC_REG_FLAG 0x3f
  130. #define XADC_CONF0_EC BIT(9)
  131. #define XADC_CONF0_ACQ BIT(8)
  132. #define XADC_CONF0_MUX BIT(11)
  133. #define XADC_CONF0_CHAN(x) (x)
  134. #define XADC_CONF1_SEQ_MASK (0xf << 12)
  135. #define XADC_CONF1_SEQ_DEFAULT (0 << 12)
  136. #define XADC_CONF1_SEQ_SINGLE_PASS (1 << 12)
  137. #define XADC_CONF1_SEQ_CONTINUOUS (2 << 12)
  138. #define XADC_CONF1_SEQ_SINGLE_CHANNEL (3 << 12)
  139. #define XADC_CONF1_SEQ_SIMULTANEOUS (4 << 12)
  140. #define XADC_CONF1_SEQ_INDEPENDENT (8 << 12)
  141. #define XADC_CONF1_ALARM_MASK 0x0f0f
  142. #define XADC_CONF2_DIV_MASK 0xff00
  143. #define XADC_CONF2_DIV_OFFSET 8
  144. #define XADC_CONF2_PD_MASK (0x3 << 4)
  145. #define XADC_CONF2_PD_NONE (0x0 << 4)
  146. #define XADC_CONF2_PD_ADC_B (0x2 << 4)
  147. #define XADC_CONF2_PD_BOTH (0x3 << 4)
  148. #define XADC_ALARM_TEMP_MASK BIT(0)
  149. #define XADC_ALARM_VCCINT_MASK BIT(1)
  150. #define XADC_ALARM_VCCAUX_MASK BIT(2)
  151. #define XADC_ALARM_OT_MASK BIT(3)
  152. #define XADC_ALARM_VCCBRAM_MASK BIT(4)
  153. #define XADC_ALARM_VCCPINT_MASK BIT(5)
  154. #define XADC_ALARM_VCCPAUX_MASK BIT(6)
  155. #define XADC_ALARM_VCCODDR_MASK BIT(7)
  156. #define XADC_THRESHOLD_TEMP_MAX 0x0
  157. #define XADC_THRESHOLD_VCCINT_MAX 0x1
  158. #define XADC_THRESHOLD_VCCAUX_MAX 0x2
  159. #define XADC_THRESHOLD_OT_MAX 0x3
  160. #define XADC_THRESHOLD_TEMP_MIN 0x4
  161. #define XADC_THRESHOLD_VCCINT_MIN 0x5
  162. #define XADC_THRESHOLD_VCCAUX_MIN 0x6
  163. #define XADC_THRESHOLD_OT_MIN 0x7
  164. #define XADC_THRESHOLD_VCCBRAM_MAX 0x8
  165. #define XADC_THRESHOLD_VCCPINT_MAX 0x9
  166. #define XADC_THRESHOLD_VCCPAUX_MAX 0xa
  167. #define XADC_THRESHOLD_VCCODDR_MAX 0xb
  168. #define XADC_THRESHOLD_VCCBRAM_MIN 0xc
  169. #define XADC_THRESHOLD_VCCPINT_MIN 0xd
  170. #define XADC_THRESHOLD_VCCPAUX_MIN 0xe
  171. #define XADC_THRESHOLD_VCCODDR_MIN 0xf
  172. #endif