Debian Codegraph @

thirdparty/analogdevicesinc/no-OS_local/platform_bladerf2_headless/platform.h

raw symbols SCIP
1 /*******************************************************************************
2 * @file platform.h
3 * @brief Header file of Platform driver.
4 * @author DBogdan ([email protected])
5 *******************************************************************************
6 * Copyright 2014(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 #ifndef PLATFORM_H_
40 #define PLATFORM_H_
41
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45
46 #include "config.h"
47 #include "stdint.h"
48 #include "util.h"
49
50 /******************************************************************************/
51 /********************** Macros and Constants Definitions **********************/
52 /******************************************************************************/
53 #define ADI_REG_VERSION 0x0000
54
55 #define ADI_REG_ID 0x0004
56
57 #define ADI_REG_RSTN 0x0040
58 #define ADI_RSTN (1 << 0)
59 #define ADI_MMCM_RSTN (1 << 1)
60
61 #define ADI_REG_CNTRL 0x0044
62 #define ADI_R1_MODE (1 << 2)
63 #define ADI_DDR_EDGESEL (1 << 1)
64 #define ADI_PIN_MODE (1 << 0)
65
66 #define ADI_REG_STATUS 0x005C
67 #define ADI_MUX_PN_ERR (1 << 3)
68 #define ADI_MUX_PN_OOS (1 << 2)
69 #define ADI_MUX_OVER_RANGE (1 << 1)
70 #define ADI_STATUS (1 << 0)
71
72 #define ADI_REG_DELAY_CNTRL 0x0060 /* <= v8.0 */
73 #define ADI_DELAY_SEL (1 << 17)
74 #define ADI_DELAY_RWN (1 << 16)
75 #define ADI_DELAY_ADDRESS(x) (((x)&0xFF) << 8)
76 #define ADI_TO_DELAY_ADDRESS(x) (((x) >> 8) & 0xFF)
77 #define ADI_DELAY_WDATA(x) (((x)&0x1F) << 0)
78 #define ADI_TO_DELAY_WDATA(x) (((x) >> 0) & 0x1F)
79
80 #define ADI_REG_CHAN_CNTRL(c) (0x0400 + (c)*0x40)
81 #define ADI_PN_SEL (1 << 10) /* !v8.0 */
82 #define ADI_IQCOR_ENB (1 << 9)
83 #define ADI_DCFILT_ENB (1 << 8)
84 #define ADI_FORMAT_SIGNEXT (1 << 6)
85 #define ADI_FORMAT_TYPE (1 << 5)
86 #define ADI_FORMAT_ENABLE (1 << 4)
87 #define ADI_PN23_TYPE (1 << 1) /* !v8.0 */
88 #define ADI_ENABLE (1 << 0)
89
90 #define ADI_REG_CHAN_STATUS(c) (0x0404 + (c)*0x40)
91 #define ADI_PN_ERR (1 << 2)
92 #define ADI_PN_OOS (1 << 1)
93 #define ADI_OVER_RANGE (1 << 0)
94
95 #define ADI_REG_CHAN_CNTRL_1(c) (0x0410 + (c)*0x40)
96 #define ADI_DCFILT_OFFSET(x) (((x)&0xFFFF) << 16)
97 #define ADI_TO_DCFILT_OFFSET(x) (((x) >> 16) & 0xFFFF)
98 #define ADI_DCFILT_COEFF(x) (((x)&0xFFFF) << 0)
99 #define ADI_TO_DCFILT_COEFF(x) (((x) >> 0) & 0xFFFF)
100
101 #define ADI_REG_CHAN_CNTRL_2(c) (0x0414 + (c)*0x40)
102 #define ADI_IQCOR_COEFF_1(x) (((x)&0xFFFF) << 16)
103 #define ADI_TO_IQCOR_COEFF_1(x) (((x) >> 16) & 0xFFFF)
104 #define ADI_IQCOR_COEFF_2(x) (((x)&0xFFFF) << 0)
105 #define ADI_TO_IQCOR_COEFF_2(x) (((x) >> 0) & 0xFFFF)
106
107 #define PCORE_VERSION(major, minor, letter) \
108 ((major << 16) | (minor << 8) | letter)
109 #define PCORE_VERSION_MAJOR(version) (version >> 16)
110 #define PCORE_VERSION_MINOR(version) ((version >> 8) & 0xff)
111 #define PCORE_VERSION_LETTER(version) (version & 0xff)
112
113 #define ADI_REG_CHAN_CNTRL_3(c) (0x0418 + (c)*0x40) /* v8.0 */
114 #define ADI_ADC_PN_SEL(x) (((x)&0xF) << 16)
115 #define ADI_TO_ADC_PN_SEL(x) (((x) >> 16) & 0xF)
116 #define ADI_ADC_DATA_SEL(x) (((x)&0xF) << 0)
117 #define ADI_TO_ADC_DATA_SEL(x) (((x) >> 0) & 0xF)
118
119 /* PCORE Version > 8.00 */
120 #define ADI_REG_DELAY(l) (0x0800 + (l)*0x4)
121
122 enum adc_pn_sel {
123 ADC_PN9 = 0,
124 ADC_PN23A = 1,
125 ADC_PN7 = 4,
126 ADC_PN15 = 5,
127 ADC_PN23 = 6,
128 ADC_PN31 = 7,
129 ADC_PN_CUSTOM = 9,
130 ADC_PN_END = 10,
131 };
132
133 enum adc_data_sel {
134 ADC_DATA_SEL_NORM,
135 ADC_DATA_SEL_LB, /* DAC loopback */
136 ADC_DATA_SEL_RAMP, /* TBD */
137 };
138
139 /* Bitwise positions of GPOs in RFFE control register */
140 #define RFFE_CONTROL_RESET_N 0
141 #define RFFE_CONTROL_SYNC_IN 4
142
143 /******************************************************************************/
144 /************************ Functions Declarations ******************************/
145 /******************************************************************************/
146
147 int spi_init(struct ad9361_rf_phy *phy, void *userdata);
148 int spi_write(struct spi_device *spi,
149 uint16_t cmd,
150 const uint8_t *buf,
151 unsigned int len);
152 int spi_read(struct spi_device *spi,
153 uint16_t cmd,
154 uint8_t *buf,
155 unsigned int len);
156
157 int gpio_init(struct ad9361_rf_phy *phy, void *userdata);
158 bool gpio_is_valid(struct gpio_device *gpio, int32_t number);
159 int gpio_set_value(struct gpio_device *gpio, int32_t number, bool value);
160
161 void udelay(unsigned long usecs);
162 void mdelay(unsigned long msecs);
163 unsigned long msleep_interruptible(unsigned int msecs);
164
165 #ifndef AXI_ADC_NOT_PRESENT
166 int axiadc_init(struct ad9361_rf_phy *phy, void *userdata);
167 int axiadc_post_setup(struct ad9361_rf_phy *phy);
168 int axiadc_read(struct axiadc_state *st, uint32_t addr, uint32_t *data);
169 int axiadc_write(struct axiadc_state *st, uint32_t addr, uint32_t data);
170 int axiadc_set_pnsel(struct axiadc_state *st,
171 unsigned int channel,
172 enum adc_pn_sel sel);
173 int axiadc_idelay_set(struct axiadc_state *st,
174 unsigned int lane,
175 unsigned int val);
176 #endif
177
178 #endif