Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/drivers/ad9152/ad9152.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ad9152.c
3 * @brief Implementation of AD9152 Driver.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2015-2016(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 /******************************************************************************/
41 /***************************** Include Files **********************************/
42 /******************************************************************************/
43 #include "ad9152.h"
44
45 /***************************************************************************//**
46 * @brief ad9152_spi_read
47 *******************************************************************************/
48 int32_t ad9152_spi_read(spi_device *dev,
49 uint16_t reg_addr,
50 uint8_t *reg_data)
51 {
52 uint8_t buf[3];
53 int32_t ret;
54
55 buf[0] = 0x80 | (reg_addr >> 8);
56 buf[1] = reg_addr & 0xFF;
57 buf[2] = 0x00;
58
59 ret = ad_spi_xfer(dev, buf, 3);
60 *reg_data = buf[2];
61
62 return ret;
63 }
64
65 /***************************************************************************//**
66 * @brief ad9152_spi_write
67 *******************************************************************************/
68 int32_t ad9152_spi_write(spi_device *dev,
69 uint16_t reg_addr,
70 uint8_t reg_data)
71 {
72 uint8_t buf[3];
73 int32_t ret;
74
75 buf[0] = reg_addr >> 8;
76 buf[1] = reg_addr & 0xFF;
77 buf[2] = reg_data;
78
79 ret = ad_spi_xfer(dev, buf, 3);
80
81 return ret;
82 }
83
84 /***************************************************************************//**
85 * @brief ad9152_setup
86 *******************************************************************************/
87 int32_t ad9152_setup(spi_device *dev,
88 ad9152_init_param init_param)
89 {
90 uint8_t chip_id;
91 uint8_t pll_stat;
92 int32_t ret;
93
94 ret = 0;
95
96 ad9152_spi_read(dev, REG_SPI_PRODIDL, &chip_id);
97 if(chip_id != AD9152_CHIP_ID)
98 {
99 ad_printf("AD9152: Invalid CHIP ID (0x%x)!\n", chip_id);
100 return -1;
101 }
102
103 // power-up and dac initialization
104 mdelay(5);
105
106 ad9152_spi_write(dev, REG_SPI_INTFCONFA, SOFTRESET_M | SOFTRESET); // reset
107 ad9152_spi_write(dev, REG_SPI_INTFCONFA, 0x00); // reset
108
109 mdelay(4);
110
111 ad9152_spi_write(dev, 0x011, 0x00); // dacs - power up everything
112 ad9152_spi_write(dev, 0x080, 0x00); // clocks - power up everything
113 ad9152_spi_write(dev, 0x081, 0x00); // sysref - power up/falling edge
114
115 // digital data path
116
117 ad9152_spi_write(dev, 0x112, 0x00); // interpolation (bypass)
118 ad9152_spi_write(dev, 0x110, 0x00); // 2's complement
119
120 // transport layer
121
122 ad9152_spi_write(dev, 0x200, 0x00); // phy - power up
123 ad9152_spi_write(dev, 0x201, 0x00); // phy - power up
124 ad9152_spi_write(dev, 0x230, 0x28); // half-rate CDR
125 ad9152_spi_write(dev, 0x312, 0x20); // half-rate CDR
126 ad9152_spi_write(dev, 0x300, 0x01); // single link - link 0
127 ad9152_spi_write(dev, 0x450, 0x00); // device id (0x400)
128 ad9152_spi_write(dev, 0x451, 0x00); // bank id (0x401)
129 ad9152_spi_write(dev, 0x452, 0x04); // lane-id (0x402)
130 ad9152_spi_write(dev, 0x453, 0x83); // descrambling, 4 lanes
131 ad9152_spi_write(dev, 0x454, 0x00); // octects per frame per lane (1)
132 ad9152_spi_write(dev, 0x455, 0x1f); // mult-frame - framecount (32)
133 ad9152_spi_write(dev, 0x456, 0x01); // no-of-converters (2)
134 ad9152_spi_write(dev, 0x457, 0x0f); // no CS bits, 16bit dac
135 ad9152_spi_write(dev, 0x458, 0x2f); // subclass 1, 16bits per sample
136 ad9152_spi_write(dev, 0x459, 0x20); // jesd204b, 1 samples per converter per device
137 ad9152_spi_write(dev, 0x45a, 0x80); // HD mode, no CS bits
138 ad9152_spi_write(dev, 0x45d, 0x49); // check-sum of 0x450 to 0x45c
139 ad9152_spi_write(dev, 0x478, 0x01); // ilas mf count
140 ad9152_spi_write(dev, 0x46c, 0x0f); // enable deskew for all lanes
141 ad9152_spi_write(dev, 0x476, 0x01); // frame - bytecount (1)
142 ad9152_spi_write(dev, 0x47d, 0x0f); // enable all lanes
143
144 // physical layer
145 ad9152_spi_write(dev, 0x2a6, 0x08);
146 ad9152_spi_write(dev, 0x248, 0xaa);
147 ad9152_spi_write(dev, 0x2aa, 0xb7); // jesd termination
148 ad9152_spi_write(dev, 0x2ab, 0x87); // jesd termination
149 ad9152_spi_write(dev, 0x2a7, 0x01); // input termination calibration
150 ad9152_spi_write(dev, 0x314, 0x01); // pclk == qbd master clock
151 ad9152_spi_write(dev, 0x230, 0x28); // cdr mode - halfrate, no division
152 ad9152_spi_write(dev, 0x206, 0x00); // cdr reset
153 ad9152_spi_write(dev, 0x206, 0x01); // cdr reset
154 ad9152_spi_write(dev, 0x289, 0x04); // data-rate == 10Gbps
155 ad9152_spi_write(dev, 0x280, 0x01); // enable serdes pll
156 ad9152_spi_write(dev, 0x280, 0x05); // enable serdes calibration
157 mdelay(20);
158
159 ad9152_spi_read(dev, 0x281, &pll_stat);
160 if (pll_stat == 0)
161 {
162 ad_printf("AD9152: PLL is NOT locked!.\n");
163 ret = -1;
164 }
165
166 ad9152_spi_write(dev, 0x268, 0x62); // equalizer
167
168
169 // data link layer
170
171 ad9152_spi_write(dev, 0x301, 0x01); // subclass-1
172 ad9152_spi_write(dev, 0x304, 0x00); // lmfc delay
173 ad9152_spi_write(dev, 0x306, 0x0a); // receive buffer delay
174 ad9152_spi_write(dev, 0x03a, 0x01); // sync-oneshot mode
175 ad9152_spi_write(dev, 0x03a, 0x81); // sync-enable
176 ad9152_spi_write(dev, 0x03a, 0xc1); // sysref-armed
177 ad9152_spi_write(dev, 0x300, 0x01); // enable link
178
179 ad9152_spi_write(dev, 0x0e7, 0x30); // turn off cal clock
180
181 return ret;
182 }
183
184 /***************************************************************************//**
185 * @brief ad9152_setup
186 *******************************************************************************/
187
188 int32_t ad9152_short_pattern_test(spi_device *dev, ad9152_init_param init_param)
189 {
190 uint32_t dac;
191 uint32_t sample;
192 uint8_t status;
193
194 status = 0;
195
196 for (dac = 0; dac < 2; dac++) {
197 for (sample = 0; sample < 4; sample++) {
198 ad9152_spi_write(dev, 0x32c, ((sample << 4) | (dac << 2) | 0x00));
199 ad9152_spi_write(dev, 0x32e, (init_param.stpl_samples[dac][sample]>>8));
200 ad9152_spi_write(dev, 0x32d, (init_param.stpl_samples[dac][sample]>>0));
201 ad9152_spi_write(dev, 0x32c, ((sample << 4) | (dac << 2) | 0x01));
202 ad9152_spi_write(dev, 0x32c, ((sample << 4) | (dac << 2) | 0x03));
203 ad9152_spi_write(dev, 0x32c, ((sample << 4) | (dac << 2) | 0x01));
204 mdelay(1);
205
206 ad9152_spi_read(dev, 0x32f, &status);
207 if ((status & 0x1) == 0x1)
208 ad_printf("AD9152: short-pattern-test mismatch (%x, %d, %d, %x)!.\n",
209 dac, sample, init_param.stpl_samples[dac][sample], status);
210 }
211 }
212 return(0);
213 }
214
215 /***************************************************************************//**
216 * @brief ad9152_setup
217 *******************************************************************************/
218
219 int32_t ad9152_datapath_prbs_test(spi_device *dev, ad9152_init_param init_param)
220 {
221
222 uint8_t status;
223 int32_t ret;
224
225 status = 0;
226 ret = 0;
227
228 if (init_param.interpolation == 1)
229 return(ret);
230
231 ad9152_spi_write(dev, REG_PRBS, ((init_param.prbs_type << 2) | 0x03));
232 ad9152_spi_write(dev, REG_PRBS, ((init_param.prbs_type << 2) | 0x01));
233 mdelay(100);
234
235 ad9152_spi_read(dev, REG_PRBS, &status);
236 if ((status & 0xc0) != 0xc0)
237 {
238 ad_printf("AD9152: PRBS OUT OF SYNC (%x)!.\n", status);
239 ret = -1;
240 }
241 ad9152_spi_read(dev, REG_PRBS_ERROR_I, &status);
242 if (status != 0x00)
243 {
244 ad_printf("AD9152: PRBS I channel ERRORS (%x)!.\n", status);
245 ret = -1;
246 }
247 ad9152_spi_read(dev, REG_PRBS_ERROR_Q, &status);
248 if (status != 0x00)
249 {
250 ad_printf("AD9152: PRBS Q channel ERRORS (%x)!.\n", status);
251 ret = -1;
252 }
253
254 return(ret);
255 }
256
257 /***************************************************************************//**
258 * @brief ad9152_setup
259 *******************************************************************************/
260
261 int32_t ad9152_status(spi_device *dev)
262 {
263
264 uint8_t status;
265 int32_t ret;
266
267 status = 0;
268 ret = 0;
269
270 // check for jesd status on all lanes
271 // failures on top are 100% guaranteed to make subsequent status checks fail
272
273 ad9152_spi_read(dev, REG_CODEGRPSYNCFLG, &status);
274 if (status != 0x0f)
275 {
276 ad_printf("AD9152: CGS NOT received (%x)!.\n", status);
277 ret = -1;
278 }
279 ad9152_spi_read(dev, REG_INITLANESYNCFLG, &status);
280 if (status != 0x0f)
281 {
282 ad_printf("AD9152: ILAS NOT received (%x)!.\n", status);
283 ret = -1;
284 }
285 ad9152_spi_read(dev, REG_FRAMESYNCFLG, &status);
286 if (status != 0x0f)
287 {
288 ad_printf("AD9152: framer OUT OF SYNC (%x)!.\n", status);
289 ret = -1;
290 }
291 ad9152_spi_read(dev, REG_GOODCHKSUMFLG, &status);
292 if (status != 0x0f)
293 {
294 ad_printf("AD9152: check-sum MISMATCH (%x)!.\n", status);
295 ret = -1;
296 }
297
298 return(ret);
299 }
300