ad9832.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * AD9832 SPI DDS driver
  3. *
  4. * Copyright 2011 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #ifndef IIO_DDS_AD9832_H_
  9. #define IIO_DDS_AD9832_H_
  10. /* Registers */
  11. #define AD9832_FREQ0LL 0x0
  12. #define AD9832_FREQ0HL 0x1
  13. #define AD9832_FREQ0LM 0x2
  14. #define AD9832_FREQ0HM 0x3
  15. #define AD9832_FREQ1LL 0x4
  16. #define AD9832_FREQ1HL 0x5
  17. #define AD9832_FREQ1LM 0x6
  18. #define AD9832_FREQ1HM 0x7
  19. #define AD9832_PHASE0L 0x8
  20. #define AD9832_PHASE0H 0x9
  21. #define AD9832_PHASE1L 0xA
  22. #define AD9832_PHASE1H 0xB
  23. #define AD9832_PHASE2L 0xC
  24. #define AD9832_PHASE2H 0xD
  25. #define AD9832_PHASE3L 0xE
  26. #define AD9832_PHASE3H 0xF
  27. #define AD9832_PHASE_SYM 0x10
  28. #define AD9832_FREQ_SYM 0x11
  29. #define AD9832_PINCTRL_EN 0x12
  30. #define AD9832_OUTPUT_EN 0x13
  31. /* Command Control Bits */
  32. #define AD9832_CMD_PHA8BITSW 0x1
  33. #define AD9832_CMD_PHA16BITSW 0x0
  34. #define AD9832_CMD_FRE8BITSW 0x3
  35. #define AD9832_CMD_FRE16BITSW 0x2
  36. #define AD9832_CMD_FPSELECT 0x6
  37. #define AD9832_CMD_SYNCSELSRC 0x8
  38. #define AD9832_CMD_SLEEPRESCLR 0xC
  39. #define AD9832_FREQ BIT(11)
  40. #define AD9832_PHASE(x) (((x) & 3) << 9)
  41. #define AD9832_SYNC BIT(13)
  42. #define AD9832_SELSRC BIT(12)
  43. #define AD9832_SLEEP BIT(13)
  44. #define AD9832_RESET BIT(12)
  45. #define AD9832_CLR BIT(11)
  46. #define CMD_SHIFT 12
  47. #define ADD_SHIFT 8
  48. #define AD9832_FREQ_BITS 32
  49. #define AD9832_PHASE_BITS 12
  50. #define RES_MASK(bits) ((1 << (bits)) - 1)
  51. /**
  52. * struct ad9832_state - driver instance specific data
  53. * @spi: spi_device
  54. * @reg: supply regulator
  55. * @mclk: external master clock
  56. * @ctrl_fp: cached frequency/phase control word
  57. * @ctrl_ss: cached sync/selsrc control word
  58. * @ctrl_src: cached sleep/reset/clr word
  59. * @xfer: default spi transfer
  60. * @msg: default spi message
  61. * @freq_xfer: tuning word spi transfer
  62. * @freq_msg: tuning word spi message
  63. * @phase_xfer: tuning word spi transfer
  64. * @phase_msg: tuning word spi message
  65. * @data: spi transmit buffer
  66. * @phase_data: tuning word spi transmit buffer
  67. * @freq_data: tuning word spi transmit buffer
  68. */
  69. struct ad9832_state {
  70. struct spi_device *spi;
  71. struct regulator *reg;
  72. unsigned long mclk;
  73. unsigned short ctrl_fp;
  74. unsigned short ctrl_ss;
  75. unsigned short ctrl_src;
  76. struct spi_transfer xfer;
  77. struct spi_message msg;
  78. struct spi_transfer freq_xfer[4];
  79. struct spi_message freq_msg;
  80. struct spi_transfer phase_xfer[2];
  81. struct spi_message phase_msg;
  82. /*
  83. * DMA (thus cache coherency maintenance) requires the
  84. * transfer buffers to live in their own cache lines.
  85. */
  86. union {
  87. __be16 freq_data[4]____cacheline_aligned;
  88. __be16 phase_data[2];
  89. __be16 data;
  90. };
  91. };
  92. /*
  93. * TODO: struct ad9832_platform_data needs to go into include/linux/iio
  94. */
  95. /**
  96. * struct ad9832_platform_data - platform specific information
  97. * @mclk: master clock in Hz
  98. * @freq0: power up freq0 tuning word in Hz
  99. * @freq1: power up freq1 tuning word in Hz
  100. * @phase0: power up phase0 value [0..4095] correlates with 0..2PI
  101. * @phase1: power up phase1 value [0..4095] correlates with 0..2PI
  102. * @phase2: power up phase2 value [0..4095] correlates with 0..2PI
  103. * @phase3: power up phase3 value [0..4095] correlates with 0..2PI
  104. */
  105. struct ad9832_platform_data {
  106. unsigned long mclk;
  107. unsigned long freq0;
  108. unsigned long freq1;
  109. unsigned short phase0;
  110. unsigned short phase1;
  111. unsigned short phase2;
  112. unsigned short phase3;
  113. };
  114. #endif /* IIO_DDS_AD9832_H_ */