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