Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/adrv9371x/common.c

raw symbols SCIP
1 // ***************************************************************************
2 // ***************************************************************************
3 // Copyright 2011(c) Analog Devices, Inc.
4 //
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without modification,
8 // are permitted provided that the following conditions are met:
9 // - Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // - Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in
13 // the documentation and/or other materials provided with the
14 // distribution.
15 // - Neither the name of Analog Devices, Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived
17 // from this software without specific prior written permission.
18 // - The use of this software may or may not infringe the patent rights
19 // of one or more patent holders. This license does not release you
20 // from the requirement that you obtain separate licenses from these
21 // patent holders to use this software.
22 // - Use of the software either in source or binary form, must be run
23 // on or directly connected to an Analog Devices Inc. component.
24 //
25 // THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26 // INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
27 // PARTICULAR PURPOSE ARE DISCLAIMED.
28 //
29 // IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY
31 // RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 // BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
34 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 // ***************************************************************************
36 // ***************************************************************************
37
38 #include "common.h"
39 #include "platform_drivers.h"
40
41 /* we need to fill in the functions of common */
42
43 ADI_LOGLEVEL CMB_LOGLEVEL = ADIHAL_LOG_ERROR | ADIHAL_LOG_WARNING;
44 static uint32_t CMB_TIMEOUT_COUNT = 0;
45
46 /* close hardware pointers */
47
48 commonErr_t CMB_closeHardware(void)
49 {
50 return(COMMONERR_OK);
51 }
52
53 /* GPIO function */
54
55 commonErr_t CMB_setGPIO(uint32_t GPIO)
56 {
57 return(COMMONERR_OK);
58 }
59
60 /* hardware reset function */
61
62 commonErr_t CMB_hardReset(uint8_t spiChipSelectIndex)
63 {
64 ad_gpio_set(AD9371_RESET_B, 0x1);
65 ad_gpio_set(AD9371_RESET_B, 0x0);
66 mdelay(1);
67 ad_gpio_set(AD9371_RESET_B, 0x1);
68 mdelay(1);
69 return(COMMONERR_OK);
70 }
71
72 /* SPI read/write functions */
73
74 commonErr_t CMB_setSPIOptions(spiSettings_t *spiSettings)
75 {
76 return(COMMONERR_OK);
77 }
78
79 commonErr_t CMB_setSPIChannel(uint16_t chipSelectIndex)
80 {
81 return(COMMONERR_OK);
82 }
83
84 commonErr_t CMB_SPIWriteByte(spiSettings_t *spiSettings, uint16_t addr, uint8_t data)
85 {
86 uint8_t buf[3];
87
88 spi_device m_device;
89 ad_spi_init(&m_device);
90 m_device.chip_select = spiSettings->chipSelectIndex;
91
92 buf[0] = (uint8_t) ((addr >> 8) & 0x7f);
93 buf[1] = (uint8_t) (addr & 0xff);
94 buf[2] = (uint8_t) data;
95
96 ad_spi_xfer(&m_device, buf, 3);
97 return(COMMONERR_OK);
98 }
99
100 commonErr_t CMB_SPIWriteBytes(spiSettings_t *spiSettings, uint16_t *addr, uint8_t *data, uint32_t count)
101 {
102 uint32_t index;
103
104 for (index = 0; index < count; index++)
105 {
106 if (CMB_SPIWriteByte(spiSettings, *(addr + index), *(data + index)) != COMMONERR_OK)
107 return(COMMONERR_FAILED);
108 }
109
110 return(COMMONERR_OK);
111 }
112
113 commonErr_t CMB_SPIReadByte(spiSettings_t *spiSettings, uint16_t addr, uint8_t *readdata)
114 {
115 uint8_t buf[3];
116
117 spi_device m_device;
118 ad_spi_init(&m_device);
119 m_device.chip_select = spiSettings->chipSelectIndex;
120
121 buf[0] = (uint8_t) ((addr >> 8) | 0x80);
122 buf[1] = (uint8_t) (addr & 0xff);
123 buf[2] = (uint8_t) 0x00;
124
125 ad_spi_xfer(&m_device, buf, 3);
126 *readdata = buf[2];
127 return(COMMONERR_OK);
128 }
129
130 commonErr_t CMB_SPIWriteField(spiSettings_t *spiSettings, uint16_t addr, uint8_t field_val, uint8_t mask, uint8_t start_bit)
131 {
132 uint8_t m_data;
133
134 if (CMB_SPIReadByte(spiSettings, addr, &m_data) != COMMONERR_OK)
135 return(COMMONERR_FAILED);
136
137 m_data = (m_data & ~mask) | ((field_val << start_bit) & mask);
138
139 if (CMB_SPIWriteByte(spiSettings, addr, m_data) != COMMONERR_OK)
140 return(COMMONERR_FAILED);
141
142 return(COMMONERR_OK);
143 }
144
145 commonErr_t CMB_SPIReadField(spiSettings_t *spiSettings, uint16_t addr, uint8_t *field_val, uint8_t mask, uint8_t start_bit)
146 {
147 uint8_t m_data;
148
149 if (CMB_SPIReadByte(spiSettings, addr, &m_data) != COMMONERR_OK)
150 return(COMMONERR_FAILED);
151
152 m_data = (m_data & mask) >> start_bit;
153 *field_val = m_data;
154 return(COMMONERR_OK);
155 }
156
157 /* platform timer functions */
158
159 commonErr_t CMB_wait_ms(uint32_t time_ms)
160 {
161 mdelay(time_ms);
162 return(COMMONERR_OK);
163 }
164
165 commonErr_t CMB_wait_us(uint32_t time_us)
166 {
167 udelay(time_us);
168 return(COMMONERR_OK);
169 }
170
171 commonErr_t CMB_setTimeout_ms(uint32_t timeOut_ms)
172 {
173 CMB_TIMEOUT_COUNT = timeOut_ms * 1000;
174 return(COMMONERR_OK);
175 }
176
177 commonErr_t CMB_setTimeout_us(uint32_t timeOut_us)
178 {
179 CMB_TIMEOUT_COUNT = timeOut_us;
180 return(COMMONERR_OK);
181 }
182
183 commonErr_t CMB_hasTimeoutExpired()
184 {
185 udelay(1);
186 CMB_TIMEOUT_COUNT = CMB_TIMEOUT_COUNT - 1;
187 if (CMB_TIMEOUT_COUNT > 0)
188 return(COMMONERR_OK);
189
190 return(COMMONERR_FAILED);
191 }
192
193 /* platform logging functions */
194
195 commonErr_t CMB_openLog(const char *filename)
196 {
197 return(COMMONERR_OK);
198 }
199
200 commonErr_t CMB_closeLog(void)
201 {
202 return(COMMONERR_OK);
203 }
204
205 commonErr_t CMB_writeToLog(ADI_LOGLEVEL level, uint8_t deviceIndex, uint32_t errorCode, const char *comment)
206 {
207 if (level == ADIHAL_LOG_ERROR)
208 ad_printf("AD9371-ERROR[%d]: %s\n", errorCode, comment);
209
210 if (level == ADIHAL_LOG_WARNING)
211 ad_printf("AD9371-WARNING[%d]: %s\n", errorCode, comment);
212
213 return(COMMONERR_OK);
214 }
215
216 commonErr_t CMB_flushLog(void)
217 {
218 return(COMMONERR_OK);
219 }
220
221 /* platform FPGA AXI register read/write functions */
222
223 commonErr_t CMB_regRead(uint32_t offset, uint32_t *data)
224 {
225 return(COMMONERR_OK);
226 }
227
228 commonErr_t CMB_regWrite(uint32_t offset, uint32_t data)
229 {
230 return(COMMONERR_OK);
231 }
232
233 /* platform DDR3 memory read/write functions */
234
235 commonErr_t CMB_memRead(uint32_t offset, uint32_t *data, uint32_t len)
236 {
237 return(COMMONERR_OK);
238 }
239
240 commonErr_t CMB_memWrite(uint32_t offset, uint32_t *data, uint32_t len)
241 {
242 return(COMMONERR_OK);
243 }
244
245 // ***************************************************************************
246 // ***************************************************************************