xilinx-xadc.h 5.6 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. int irq;
  57. };
  58. struct xadc_ops {
  59. int (*read)(struct xadc *xadc, unsigned int reg, uint16_t *val);
  60. int (*write)(struct xadc *xadc, unsigned int reg, uint16_t val);
  61. int (*setup)(struct platform_device *pdev, struct iio_dev *indio_dev,
  62. int irq);
  63. void (*update_alarm)(struct xadc *xadc, unsigned int alarm);
  64. unsigned long (*get_dclk_rate)(struct xadc *xadc);
  65. irqreturn_t (*interrupt_handler)(int irq, void *devid);
  66. unsigned int flags;
  67. };
  68. static inline int _xadc_read_adc_reg(struct xadc *xadc, unsigned int reg,
  69. uint16_t *val)
  70. {
  71. lockdep_assert_held(&xadc->mutex);
  72. return xadc->ops->read(xadc, reg, val);
  73. }
  74. static inline int _xadc_write_adc_reg(struct xadc *xadc, unsigned int reg,
  75. uint16_t val)
  76. {
  77. lockdep_assert_held(&xadc->mutex);
  78. return xadc->ops->write(xadc, reg, val);
  79. }
  80. static inline int xadc_read_adc_reg(struct xadc *xadc, unsigned int reg,
  81. uint16_t *val)
  82. {
  83. int ret;
  84. mutex_lock(&xadc->mutex);
  85. ret = _xadc_read_adc_reg(xadc, reg, val);
  86. mutex_unlock(&xadc->mutex);
  87. return ret;
  88. }
  89. static inline int xadc_write_adc_reg(struct xadc *xadc, unsigned int reg,
  90. uint16_t val)
  91. {
  92. int ret;
  93. mutex_lock(&xadc->mutex);
  94. ret = _xadc_write_adc_reg(xadc, reg, val);
  95. mutex_unlock(&xadc->mutex);
  96. return ret;
  97. }
  98. /* XADC hardmacro register definitions */
  99. #define XADC_REG_TEMP 0x00
  100. #define XADC_REG_VCCINT 0x01
  101. #define XADC_REG_VCCAUX 0x02
  102. #define XADC_REG_VPVN 0x03
  103. #define XADC_REG_VREFP 0x04
  104. #define XADC_REG_VREFN 0x05
  105. #define XADC_REG_VCCBRAM 0x06
  106. #define XADC_REG_VCCPINT 0x0d
  107. #define XADC_REG_VCCPAUX 0x0e
  108. #define XADC_REG_VCCO_DDR 0x0f
  109. #define XADC_REG_VAUX(x) (0x10 + (x))
  110. #define XADC_REG_MAX_TEMP 0x20
  111. #define XADC_REG_MAX_VCCINT 0x21
  112. #define XADC_REG_MAX_VCCAUX 0x22
  113. #define XADC_REG_MAX_VCCBRAM 0x23
  114. #define XADC_REG_MIN_TEMP 0x24
  115. #define XADC_REG_MIN_VCCINT 0x25
  116. #define XADC_REG_MIN_VCCAUX 0x26
  117. #define XADC_REG_MIN_VCCBRAM 0x27
  118. #define XADC_REG_MAX_VCCPINT 0x28
  119. #define XADC_REG_MAX_VCCPAUX 0x29
  120. #define XADC_REG_MAX_VCCO_DDR 0x2a
  121. #define XADC_REG_MIN_VCCPINT 0x2c
  122. #define XADC_REG_MIN_VCCPAUX 0x2d
  123. #define XADC_REG_MIN_VCCO_DDR 0x2e
  124. #define XADC_REG_CONF0 0x40
  125. #define XADC_REG_CONF1 0x41
  126. #define XADC_REG_CONF2 0x42
  127. #define XADC_REG_SEQ(x) (0x48 + (x))
  128. #define XADC_REG_INPUT_MODE(x) (0x4c + (x))
  129. #define XADC_REG_THRESHOLD(x) (0x50 + (x))
  130. #define XADC_REG_FLAG 0x3f
  131. #define XADC_CONF0_EC BIT(9)
  132. #define XADC_CONF0_ACQ BIT(8)
  133. #define XADC_CONF0_MUX BIT(11)
  134. #define XADC_CONF0_CHAN(x) (x)
  135. #define XADC_CONF1_SEQ_MASK (0xf << 12)
  136. #define XADC_CONF1_SEQ_DEFAULT (0 << 12)
  137. #define XADC_CONF1_SEQ_SINGLE_PASS (1 << 12)
  138. #define XADC_CONF1_SEQ_CONTINUOUS (2 << 12)
  139. #define XADC_CONF1_SEQ_SINGLE_CHANNEL (3 << 12)
  140. #define XADC_CONF1_SEQ_SIMULTANEOUS (4 << 12)
  141. #define XADC_CONF1_SEQ_INDEPENDENT (8 << 12)
  142. #define XADC_CONF1_ALARM_MASK 0x0f0f
  143. #define XADC_CONF2_DIV_MASK 0xff00
  144. #define XADC_CONF2_DIV_OFFSET 8
  145. #define XADC_CONF2_PD_MASK (0x3 << 4)
  146. #define XADC_CONF2_PD_NONE (0x0 << 4)
  147. #define XADC_CONF2_PD_ADC_B (0x2 << 4)
  148. #define XADC_CONF2_PD_BOTH (0x3 << 4)
  149. #define XADC_ALARM_TEMP_MASK BIT(0)
  150. #define XADC_ALARM_VCCINT_MASK BIT(1)
  151. #define XADC_ALARM_VCCAUX_MASK BIT(2)
  152. #define XADC_ALARM_OT_MASK BIT(3)
  153. #define XADC_ALARM_VCCBRAM_MASK BIT(4)
  154. #define XADC_ALARM_VCCPINT_MASK BIT(5)
  155. #define XADC_ALARM_VCCPAUX_MASK BIT(6)
  156. #define XADC_ALARM_VCCODDR_MASK BIT(7)
  157. #define XADC_THRESHOLD_TEMP_MAX 0x0
  158. #define XADC_THRESHOLD_VCCINT_MAX 0x1
  159. #define XADC_THRESHOLD_VCCAUX_MAX 0x2
  160. #define XADC_THRESHOLD_OT_MAX 0x3
  161. #define XADC_THRESHOLD_TEMP_MIN 0x4
  162. #define XADC_THRESHOLD_VCCINT_MIN 0x5
  163. #define XADC_THRESHOLD_VCCAUX_MIN 0x6
  164. #define XADC_THRESHOLD_OT_MIN 0x7
  165. #define XADC_THRESHOLD_VCCBRAM_MAX 0x8
  166. #define XADC_THRESHOLD_VCCPINT_MAX 0x9
  167. #define XADC_THRESHOLD_VCCPAUX_MAX 0xa
  168. #define XADC_THRESHOLD_VCCODDR_MAX 0xb
  169. #define XADC_THRESHOLD_VCCBRAM_MIN 0xc
  170. #define XADC_THRESHOLD_VCCPINT_MIN 0xd
  171. #define XADC_THRESHOLD_VCCPAUX_MIN 0xe
  172. #define XADC_THRESHOLD_VCCODDR_MIN 0xf
  173. #endif