Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/ad9361/sw/platform_linux/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 #include "stdint.h"
46 #include "../util.h"
47
48 /******************************************************************************/
49 /********************** Macros and Constants Definitions **********************/
50 /******************************************************************************/
51 #define ADI_REG_VERSION 0x0000
52
53 #define ADI_REG_ID 0x0004
54
55 #define ADI_REG_RSTN 0x0040
56 #define ADI_RSTN (1 << 0)
57 #define ADI_MMCM_RSTN (1 << 1)
58
59 #define ADI_REG_CNTRL 0x0044
60 #define ADI_R1_MODE (1 << 2)
61 #define ADI_DDR_EDGESEL (1 << 1)
62 #define ADI_PIN_MODE (1 << 0)
63
64 #define ADI_REG_STATUS 0x005C
65 #define ADI_MUX_PN_ERR (1 << 3)
66 #define ADI_MUX_PN_OOS (1 << 2)
67 #define ADI_MUX_OVER_RANGE (1 << 1)
68 #define ADI_STATUS (1 << 0)
69
70 #define ADI_REG_DELAY_CNTRL 0x0060 /* <= v8.0 */
71 #define ADI_DELAY_SEL (1 << 17)
72 #define ADI_DELAY_RWN (1 << 16)
73 #define ADI_DELAY_ADDRESS(x) (((x) & 0xFF) << 8)
74 #define ADI_TO_DELAY_ADDRESS(x) (((x) >> 8) & 0xFF)
75 #define ADI_DELAY_WDATA(x) (((x) & 0x1F) << 0)
76 #define ADI_TO_DELAY_WDATA(x) (((x) >> 0) & 0x1F)
77
78 #define ADI_REG_CHAN_CNTRL(c) (0x0400 + (c) * 0x40)
79 #define ADI_PN_SEL (1 << 10) /* !v8.0 */
80 #define ADI_IQCOR_ENB (1 << 9)
81 #define ADI_DCFILT_ENB (1 << 8)
82 #define ADI_FORMAT_SIGNEXT (1 << 6)
83 #define ADI_FORMAT_TYPE (1 << 5)
84 #define ADI_FORMAT_ENABLE (1 << 4)
85 #define ADI_PN23_TYPE (1 << 1) /* !v8.0 */
86 #define ADI_ENABLE (1 << 0)
87
88 #define ADI_REG_CHAN_STATUS(c) (0x0404 + (c) * 0x40)
89 #define ADI_PN_ERR (1 << 2)
90 #define ADI_PN_OOS (1 << 1)
91 #define ADI_OVER_RANGE (1 << 0)
92
93 #define ADI_REG_CHAN_CNTRL_1(c) (0x0410 + (c) * 0x40)
94 #define ADI_DCFILT_OFFSET(x) (((x) & 0xFFFF) << 16)
95 #define ADI_TO_DCFILT_OFFSET(x) (((x) >> 16) & 0xFFFF)
96 #define ADI_DCFILT_COEFF(x) (((x) & 0xFFFF) << 0)
97 #define ADI_TO_DCFILT_COEFF(x) (((x) >> 0) & 0xFFFF)
98
99 #define ADI_REG_CHAN_CNTRL_2(c) (0x0414 + (c) * 0x40)
100 #define ADI_IQCOR_COEFF_1(x) (((x) & 0xFFFF) << 16)
101 #define ADI_TO_IQCOR_COEFF_1(x) (((x) >> 16) & 0xFFFF)
102 #define ADI_IQCOR_COEFF_2(x) (((x) & 0xFFFF) << 0)
103 #define ADI_TO_IQCOR_COEFF_2(x) (((x) >> 0) & 0xFFFF)
104
105 #define PCORE_VERSION(major, minor, letter) ((major << 16) | (minor << 8) | letter)
106 #define PCORE_VERSION_MAJOR(version) (version >> 16)
107 #define PCORE_VERSION_MINOR(version) ((version >> 8) & 0xff)
108 #define PCORE_VERSION_LETTER(version) (version & 0xff)
109
110 #define ADI_REG_CHAN_CNTRL_3(c) (0x0418 + (c) * 0x40) /* v8.0 */
111 #define ADI_ADC_PN_SEL(x) (((x) & 0xF) << 16)
112 #define ADI_TO_ADC_PN_SEL(x) (((x) >> 16) & 0xF)
113 #define ADI_ADC_DATA_SEL(x) (((x) & 0xF) << 0)
114 #define ADI_TO_ADC_DATA_SEL(x) (((x) >> 0) & 0xF)
115
116 /* PCORE Version > 8.00 */
117 #define ADI_REG_DELAY(l) (0x0800 + (l) * 0x4)
118
119 enum adc_pn_sel {
120 ADC_PN9 = 0,
121 ADC_PN23A = 1,
122 ADC_PN7 = 4,
123 ADC_PN15 = 5,
124 ADC_PN23 = 6,
125 ADC_PN31 = 7,
126 ADC_PN_CUSTOM = 9,
127 ADC_PN_END = 10,
128 };
129
130 enum adc_data_sel {
131 ADC_DATA_SEL_NORM,
132 ADC_DATA_SEL_LB, /* DAC loopback */
133 ADC_DATA_SEL_RAMP, /* TBD */
134 };
135
136 /******************************************************************************/
137 /************************ Functions Declarations ******************************/
138 /******************************************************************************/
139 int32_t spi_init(uint32_t device_id,
140 uint8_t clk_pha,
141 uint8_t clk_pol);
142 int spi_write_then_read(struct spi_device *spi,
143 const unsigned char *txbuf, unsigned n_tx,
144 unsigned char *rxbuf, unsigned n_rx);
145 void gpio_init(uint32_t device_id);
146 void gpio_direction(uint16_t pin, uint8_t direction);
147 bool gpio_is_valid(int number);
148 void gpio_set_value(unsigned gpio, int value);
149 void udelay(unsigned long usecs);
150 void mdelay(unsigned long msecs);
151 unsigned long msleep_interruptible(unsigned int msecs);
152 void axiadc_init(struct ad9361_rf_phy *phy);
153 int axiadc_post_setup(struct ad9361_rf_phy *phy);
154 unsigned int axiadc_read(struct axiadc_state *st, unsigned long reg);
155 void axiadc_write(struct axiadc_state *st, unsigned reg, unsigned val);
156 int axiadc_set_pnsel(struct axiadc_state *st, int channel, enum adc_pn_sel sel);
157 void axiadc_idelay_set(struct axiadc_state *st, unsigned lane, unsigned val);
158 #endif