Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/drivers/adf4350/adf4350.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file adf4350.h
3 * @brief Header file of ADF4350 Driver.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2012-2015(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 *******************************************************************************/
40 #ifndef __ADF4350_H__
41 #define __ADF4350_H__
42
43 /******************************************************************************/
44 /***************************** Include Files **********************************/
45 /******************************************************************************/
46 #include <stdint.h>
47
48 /******************************************************************************/
49 /********************** Macros and Constants Definitions **********************/
50 /******************************************************************************/
51
52 /* Channels */
53 #define ADF4350_RX_CHANNEL 0
54 #define ADF4350_TX_CHANNEL 1
55
56 /* Registers */
57 #define ADF4350_REG0 0
58 #define ADF4350_REG1 1
59 #define ADF4350_REG2 2
60 #define ADF4350_REG3 3
61 #define ADF4350_REG4 4
62 #define ADF4350_REG5 5
63
64 /* REG0 Bit Definitions */
65 #define ADF4350_REG0_FRACT(x) (((x) & 0xFFF) << 3)
66 #define ADF4350_REG0_INT(x) (((x) & 0xFFFF) << 15)
67
68 /* REG1 Bit Definitions */
69 #define ADF4350_REG1_MOD(x) (((x) & 0xFFF) << 3)
70 #define ADF4350_REG1_PHASE(x) (((x) & 0xFFF) << 15)
71 #define ADF4350_REG1_PRESCALER (1 << 27)
72
73 /* REG2 Bit Definitions */
74 #define ADF4350_REG2_COUNTER_RESET_EN (1 << 3)
75 #define ADF4350_REG2_CP_THREESTATE_EN (1 << 4)
76 #define ADF4350_REG2_POWER_DOWN_EN (1 << 5)
77 #define ADF4350_REG2_PD_POLARITY_POS (1 << 6)
78 #define ADF4350_REG2_LDP_6ns (1 << 7)
79 #define ADF4350_REG2_LDP_10ns (0 << 7)
80 #define ADF4350_REG2_LDF_FRACT_N (0 << 8)
81 #define ADF4350_REG2_LDF_INT_N (1 << 8)
82 #define ADF4350_REG2_CHARGE_PUMP_CURR_uA(x) (((((x)-312) / 312) & 0xF) << 9)
83 #define ADF4350_REG2_DOUBLE_BUFF_EN (1 << 13)
84 #define ADF4350_REG2_10BIT_R_CNT(x) ((x) << 14)
85 #define ADF4350_REG2_RDIV2_EN (1 << 24)
86 #define ADF4350_REG2_RMULT2_EN (1 << 25)
87 #define ADF4350_REG2_MUXOUT(x) ((x) << 26)
88 #define ADF4350_REG2_NOISE_MODE(x) ((x) << 29)
89
90 /* REG3 Bit Definitions */
91 #define ADF4350_REG3_12BIT_CLKDIV(x) ((x) << 3)
92 #define ADF4350_REG3_12BIT_CLKDIV_MODE(x) ((x) << 16)
93 #define ADF4350_REG3_12BIT_CSR_EN (1 << 18)
94 #define ADF4351_REG3_CHARGE_CANCELLATION_EN (1 << 21)
95 #define ADF4351_REG3_ANTI_BACKLASH_3ns_EN (1 << 22)
96 #define ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH (1 << 23)
97
98 /* REG4 Bit Definitions */
99 #define ADF4350_REG4_OUTPUT_PWR(x) ((x) << 3)
100 #define ADF4350_REG4_RF_OUT_EN (1 << 5)
101 #define ADF4350_REG4_AUX_OUTPUT_PWR(x) ((x) << 6)
102 #define ADF4350_REG4_AUX_OUTPUT_EN (1 << 8)
103 #define ADF4350_REG4_AUX_OUTPUT_FUND (1 << 9)
104 #define ADF4350_REG4_AUX_OUTPUT_DIV (0 << 9)
105 #define ADF4350_REG4_MUTE_TILL_LOCK_EN (1 << 10)
106 #define ADF4350_REG4_VCO_PWRDOWN_EN (1 << 11)
107 #define ADF4350_REG4_8BIT_BAND_SEL_CLKDIV(x) ((x) << 12)
108 #define ADF4350_REG4_RF_DIV_SEL(x) ((x) << 20)
109 #define ADF4350_REG4_FEEDBACK_DIVIDED (0 << 23)
110 #define ADF4350_REG4_FEEDBACK_FUND (1 << 23)
111
112 /* REG5 Bit Definitions */
113 #define ADF4350_REG5_LD_PIN_MODE_LOW (0 << 22)
114 #define ADF4350_REG5_LD_PIN_MODE_DIGITAL (1 << 22)
115 #define ADF4350_REG5_LD_PIN_MODE_HIGH (3 << 22)
116
117 /* Specifications */
118 #define ADF4350_MAX_OUT_FREQ 4400000000ULL /* Hz */
119 #define ADF4350_MIN_OUT_FREQ 34375000 /* Hz */
120 #define ADF4350_MIN_VCO_FREQ 2200000000ULL /* Hz */
121 #define ADF4350_MAX_FREQ_45_PRESC 3000000000ULL /* Hz */
122 #define ADF4350_MAX_FREQ_PFD 32000000 /* Hz */
123 #define ADF4350_MAX_BANDSEL_CLK 125000 /* Hz */
124 #define ADF4350_MAX_FREQ_REFIN 250000000 /* Hz */
125 #define ADF4350_MAX_MODULUS 4095
126 #define ADF4350_MAX_R_CNT 1023
127
128 /******************************************************************************/
129 /************************ Types Definitions ***********************************/
130 /******************************************************************************/
131 struct adf4350_platform_data
132 {
133 uint32_t clkin;
134 uint32_t channel_spacing;
135 uint64_t power_up_frequency;
136
137 uint16_t ref_div_factor; /* 10-bit R counter */
138 uint8_t ref_doubler_en;
139 uint8_t ref_div2_en;
140
141 uint32_t r2_user_settings;
142 uint32_t r3_user_settings;
143 uint32_t r4_user_settings;
144 int32_t gpio_lock_detect;
145 };
146
147 typedef struct
148 {
149 /* SPI */
150 uint8_t spi_chip_select;
151 spi_mode spi_mode;
152 spi_type spi_type;
153 uint32_t spi_device_id;
154
155 /* Device settings */
156 uint32_t clkin;
157 uint32_t channel_spacing;
158 uint32_t power_up_frequency;
159 uint32_t reference_div_factor;
160 uint8_t reference_doubler_enable;
161 uint8_t reference_div2_enable;
162
163 /* r2_user_settings */
164 uint8_t phase_detector_polarity_positive_enable;
165 uint8_t lock_detect_precision_6ns_enable;
166 uint8_t lock_detect_function_integer_n_enable;
167 uint32_t charge_pump_current;
168 uint32_t muxout_select;
169 uint8_t low_spur_mode_enable;
170
171 /* r3_user_settings */
172 uint8_t cycle_slip_reduction_enable;
173 uint8_t charge_cancellation_enable;
174 uint8_t anti_backlash_3ns_enable;
175 uint8_t band_select_clock_mode_high_enable;
176 uint32_t clk_divider_12bit;
177 uint32_t clk_divider_mode;
178
179 /* r4_user_settings */
180 uint8_t aux_output_enable;
181 uint8_t aux_output_fundamental_enable;
182 uint8_t mute_till_lock_enable;
183 uint32_t output_power;
184 uint32_t aux_output_power;
185 }adf4350_init_param;
186
187 typedef struct {
188 spi_device spi_dev;
189 struct adf4350_platform_data *pdata;
190 uint32_t clkin;
191 uint32_t chspc; /* Channel Spacing */
192 uint32_t fpfd; /* Phase Frequency Detector */
193 uint32_t min_out_freq;
194 uint32_t r0_fract;
195 uint32_t r0_int;
196 uint32_t r1_mod;
197 uint32_t r4_rf_div_sel;
198 uint32_t regs[6];
199 uint32_t regs_hw[6];
200 uint32_t val;
201 } adf4350_dev;
202
203 /******************************************************************************/
204 /************************ Functions Declarations ******************************/
205 /******************************************************************************/
206 /*! Initializes the ADF4350. */
207 int32_t adf4350_setup(adf4350_dev **device,
208 adf4350_init_param init_param);
209 /*! Writes 4 bytes of data to ADF4350. */
210 int32_t adf4350_write(adf4350_dev *dev,
211 uint32_t data);
212 /*! Stores PLL 0 frequency in Hz. */
213 int64_t adf4350_out_altvoltage0_frequency(adf4350_dev *dev,
214 int64_t Hz);
215 /*! Stores PLL 0 frequency resolution/channel spacing in Hz. */
216 int32_t adf4350_out_altvoltage0_frequency_resolution(adf4350_dev *dev,
217 int32_t Hz);
218 /*! Sets PLL 0 REFin frequency in Hz. */
219 int64_t adf4350_out_altvoltage0_refin_frequency(adf4350_dev *dev,
220 int64_t Hz);
221 /*! Powers down the PLL. */
222 int32_t adf4350_out_altvoltage0_powerdown(adf4350_dev *dev,
223 int32_t pwd);
224
225 #endif // __ADF4350_H__