ad9834.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * AD9833/AD9834/AD9837/AD9838 SPI DDS driver
  3. *
  4. * Copyright 2010-2011 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2.
  7. */
  8. #ifndef IIO_DDS_AD9834_H_
  9. #define IIO_DDS_AD9834_H_
  10. /* Registers */
  11. #define AD9834_REG_CMD 0
  12. #define AD9834_REG_FREQ0 BIT(14)
  13. #define AD9834_REG_FREQ1 BIT(15)
  14. #define AD9834_REG_PHASE0 (BIT(15) | BIT(14))
  15. #define AD9834_REG_PHASE1 (BIT(15) | BIT(14) | BIT(13))
  16. /* Command Control Bits */
  17. #define AD9834_B28 BIT(13)
  18. #define AD9834_HLB BIT(12)
  19. #define AD9834_FSEL BIT(11)
  20. #define AD9834_PSEL BIT(10)
  21. #define AD9834_PIN_SW BIT(9)
  22. #define AD9834_RESET BIT(8)
  23. #define AD9834_SLEEP1 BIT(7)
  24. #define AD9834_SLEEP12 BIT(6)
  25. #define AD9834_OPBITEN BIT(5)
  26. #define AD9834_SIGN_PIB BIT(4)
  27. #define AD9834_DIV2 BIT(3)
  28. #define AD9834_MODE BIT(1)
  29. #define AD9834_FREQ_BITS 28
  30. #define AD9834_PHASE_BITS 12
  31. #define RES_MASK(bits) (BIT(bits) - 1)
  32. /**
  33. * struct ad9834_state - driver instance specific data
  34. * @spi: spi_device
  35. * @reg: supply regulator
  36. * @mclk: external master clock
  37. * @control: cached control word
  38. * @xfer: default spi transfer
  39. * @msg: default spi message
  40. * @freq_xfer: tuning word spi transfer
  41. * @freq_msg: tuning word spi message
  42. * @data: spi transmit buffer
  43. * @freq_data: tuning word spi transmit buffer
  44. */
  45. struct ad9834_state {
  46. struct spi_device *spi;
  47. struct regulator *reg;
  48. unsigned int mclk;
  49. unsigned short control;
  50. unsigned short devid;
  51. struct spi_transfer xfer;
  52. struct spi_message msg;
  53. struct spi_transfer freq_xfer[2];
  54. struct spi_message freq_msg;
  55. /*
  56. * DMA (thus cache coherency maintenance) requires the
  57. * transfer buffers to live in their own cache lines.
  58. */
  59. __be16 data ____cacheline_aligned;
  60. __be16 freq_data[2];
  61. };
  62. /*
  63. * TODO: struct ad7887_platform_data needs to go into include/linux/iio
  64. */
  65. /**
  66. * struct ad9834_platform_data - platform specific information
  67. * @mclk: master clock in Hz
  68. * @freq0: power up freq0 tuning word in Hz
  69. * @freq1: power up freq1 tuning word in Hz
  70. * @phase0: power up phase0 value [0..4095] correlates with 0..2PI
  71. * @phase1: power up phase1 value [0..4095] correlates with 0..2PI
  72. * @en_div2: digital output/2 is passed to the SIGN BIT OUT pin
  73. * @en_signbit_msb_out: the MSB (or MSB/2) of the DAC data is connected to the
  74. * SIGN BIT OUT pin. en_div2 controls whether it is the MSB
  75. * or MSB/2 that is output. if en_signbit_msb_out=false,
  76. * the on-board comparator is connected to SIGN BIT OUT
  77. */
  78. struct ad9834_platform_data {
  79. unsigned int mclk;
  80. unsigned int freq0;
  81. unsigned int freq1;
  82. unsigned short phase0;
  83. unsigned short phase1;
  84. bool en_div2;
  85. bool en_signbit_msb_out;
  86. };
  87. /**
  88. * ad9834_supported_device_ids:
  89. */
  90. enum ad9834_supported_device_ids {
  91. ID_AD9833,
  92. ID_AD9834,
  93. ID_AD9837,
  94. ID_AD9838,
  95. };
  96. #endif /* IIO_DDS_AD9834_H_ */