Debian Codegraph @

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

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ad9680.c
3 * @brief Implementation of AD9680 Driver.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2014-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
44 #include "ad9680.h"
45
46 /***************************************************************************//**
47 * @brief ad9680_spi_read
48 *******************************************************************************/
49 int32_t ad9680_spi_read(spi_device *dev,
50 uint16_t reg_addr,
51 uint8_t *reg_data)
52 {
53 uint8_t buf[3];
54 int32_t ret;
55
56 buf[0] = 0x80 | (reg_addr >> 8);
57 buf[1] = reg_addr & 0xFF;
58 buf[2] = 0x00;
59
60 ret = ad_spi_xfer(dev, buf, 3);
61 *reg_data = buf[2];
62
63 return ret;
64 }
65
66 /***************************************************************************//**
67 * @brief ad9680_spi_write
68 *******************************************************************************/
69 int32_t ad9680_spi_write(spi_device *dev,
70 uint16_t reg_addr,
71 uint8_t reg_data)
72 {
73 uint8_t buf[3];
74 int32_t ret;
75
76 buf[0] = reg_addr >> 8;
77 buf[1] = reg_addr & 0xFF;
78 buf[2] = reg_data;
79
80 ret = ad_spi_xfer(dev, buf, 3);
81
82 return ret;
83 }
84
85 /***************************************************************************//**
86 * @brief ad9680_setup
87 *******************************************************************************/
88 int32_t ad9680_test(spi_device *dev,
89 uint32_t test_mode)
90 {
91 ad9680_spi_write(dev, AD9680_REG_ADC_TEST_MODE, test_mode);
92 if (test_mode == AD9680_TEST_OFF)
93 ad9680_spi_write(dev, AD9680_REG_OUTPUT_MODE, AD9680_FORMAT_2S_COMPLEMENT);
94 else
95 ad9680_spi_write(dev, AD9680_REG_OUTPUT_MODE, AD9680_FORMAT_OFFSET_BINARY);
96 return(0);
97 }
98
99 /***************************************************************************//**
100 * @brief ad9680_setup
101 *******************************************************************************/
102 int32_t ad9680_setup(spi_device *dev,
103 ad9680_init_param init_param)
104 {
105 uint8_t chip_id;
106 uint8_t pll_stat;
107 int32_t ret;
108
109 ret = 0;
110
111 ad9680_spi_read(dev, AD9680_REG_CHIP_ID_LOW, &chip_id);
112 if(chip_id != AD9680_CHIP_ID)
113 {
114 ad_printf("AD9680: Invalid CHIP ID (0x%x).\n", chip_id);
115 return -1;
116 }
117
118 ad9680_spi_write(dev, AD9680_REG_INTERFACE_CONF_A, 0x81); // RESET
119 mdelay(250);
120
121 ad9680_spi_write(dev, AD9680_REG_LINK_CONTROL, 0x15); // disable link, ilas enable
122 ad9680_spi_write(dev, AD9680_REG_JESD204B_MF_CTRL, 0x1f); // mf-frame-count
123 ad9680_spi_write(dev, AD9680_REG_JESD204B_CSN_CONFIG, 0x2d); // 14-bit
124 ad9680_spi_write(dev, AD9680_REG_JESD204B_SUBCLASS_CONFIG, 0x2f); // subclass-1, N'=16
125 ad9680_spi_write(dev, AD9680_REG_JESD204B_QUICK_CONFIG, 0x88); // m=2, l=4, f= 1
126 if (init_param.lane_rate_kbps < 6250000)
127 ad9680_spi_write(dev, AD9680_REG_JESD204B_LANE_RATE_CTRL, 0x10); // low line rate mode must be enabled
128 else
129 ad9680_spi_write(dev, AD9680_REG_JESD204B_LANE_RATE_CTRL, 0x00); // low line rate mode must be disabled
130 ad9680_spi_write(dev, AD9680_REG_LINK_CONTROL, 0x14); // link enable
131 mdelay(250);
132
133 ad9680_spi_read(dev, AD9680_REG_JESD204B_PLL_LOCK_STATUS, &pll_stat);
134 if ((pll_stat & 0x80) != 0x80)
135 {
136 ad_printf("AD9680: PLL is NOT locked!\n");
137 ret = -1;
138 }
139
140 return ret;
141 }