1 |
d5be5374
|
Harald Welte
|
#ifndef _E4K_TUNER_H
|
2 |
|
|
#define _E4K_TUNER_H
|
3 |
|
|
|
4 |
d5c4d1ed
|
Harald Welte
|
/* (C) 2011-2012 by Harald Welte <laforge@gnumonks.org>
|
5 |
|
|
*
|
6 |
|
|
* All Rights Reserved
|
7 |
|
|
*
|
8 |
|
|
* This program is free software; you can redistribute it and/or modify
|
9 |
|
|
* it under the terms of the GNU General Public License as published by
|
10 |
|
|
* the Free Software Foundation; either version 3 of the License, or
|
11 |
|
|
* (at your option) any later version.
|
12 |
|
|
*
|
13 |
|
|
* This program is distributed in the hope that it will be useful,
|
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
* GNU General Public License for more details.
|
17 |
|
|
*
|
18 |
|
|
* You should have received a copy of the GNU General Public License
|
19 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20 |
|
|
*/
|
21 |
|
|
|
22 |
180193ce
|
Christian Daniel
|
#define E4K_CHECK_ADDR 0x02
|
23 |
|
|
#define E4K_CHECK_VAL 0x40
|
24 |
|
|
|
25 |
d5be5374
|
Harald Welte
|
enum e4k_reg {
|
26 |
|
|
E4K_REG_MASTER1 = 0x00,
|
27 |
|
|
E4K_REG_MASTER2 = 0x01,
|
28 |
|
|
E4K_REG_MASTER3 = 0x02,
|
29 |
|
|
E4K_REG_MASTER4 = 0x03,
|
30 |
|
|
E4K_REG_MASTER5 = 0x04,
|
31 |
|
|
E4K_REG_CLK_INP = 0x05,
|
32 |
|
|
E4K_REG_REF_CLK = 0x06,
|
33 |
|
|
E4K_REG_SYNTH1 = 0x07,
|
34 |
|
|
E4K_REG_SYNTH2 = 0x08,
|
35 |
|
|
E4K_REG_SYNTH3 = 0x09,
|
36 |
|
|
E4K_REG_SYNTH4 = 0x0a,
|
37 |
|
|
E4K_REG_SYNTH5 = 0x0b,
|
38 |
|
|
E4K_REG_SYNTH6 = 0x0c,
|
39 |
|
|
E4K_REG_SYNTH7 = 0x0d,
|
40 |
|
|
E4K_REG_SYNTH8 = 0x0e,
|
41 |
|
|
E4K_REG_SYNTH9 = 0x0f,
|
42 |
|
|
E4K_REG_FILT1 = 0x10,
|
43 |
|
|
E4K_REG_FILT2 = 0x11,
|
44 |
|
|
E4K_REG_FILT3 = 0x12,
|
45 |
|
|
// gap
|
46 |
|
|
E4K_REG_GAIN1 = 0x14,
|
47 |
|
|
E4K_REG_GAIN2 = 0x15,
|
48 |
|
|
E4K_REG_GAIN3 = 0x16,
|
49 |
|
|
E4K_REG_GAIN4 = 0x17,
|
50 |
|
|
// gap
|
51 |
|
|
E4K_REG_AGC1 = 0x1a,
|
52 |
|
|
E4K_REG_AGC2 = 0x1b,
|
53 |
|
|
E4K_REG_AGC3 = 0x1c,
|
54 |
|
|
E4K_REG_AGC4 = 0x1d,
|
55 |
|
|
E4K_REG_AGC5 = 0x1e,
|
56 |
|
|
E4K_REG_AGC6 = 0x1f,
|
57 |
|
|
E4K_REG_AGC7 = 0x20,
|
58 |
|
|
E4K_REG_AGC8 = 0x21,
|
59 |
|
|
// gap
|
60 |
|
|
E4K_REG_AGC11 = 0x24,
|
61 |
|
|
E4K_REG_AGC12 = 0x25,
|
62 |
|
|
// gap
|
63 |
|
|
E4K_REG_DC1 = 0x29,
|
64 |
|
|
E4K_REG_DC2 = 0x2a,
|
65 |
|
|
E4K_REG_DC3 = 0x2b,
|
66 |
|
|
E4K_REG_DC4 = 0x2c,
|
67 |
|
|
E4K_REG_DC5 = 0x2d,
|
68 |
|
|
E4K_REG_DC6 = 0x2e,
|
69 |
|
|
E4K_REG_DC7 = 0x2f,
|
70 |
|
|
E4K_REG_DC8 = 0x30,
|
71 |
|
|
// gap
|
72 |
|
|
E4K_REG_QLUT0 = 0x50,
|
73 |
|
|
E4K_REG_QLUT1 = 0x51,
|
74 |
|
|
E4K_REG_QLUT2 = 0x52,
|
75 |
|
|
E4K_REG_QLUT3 = 0x53,
|
76 |
|
|
// gap
|
77 |
|
|
E4K_REG_ILUT0 = 0x60,
|
78 |
|
|
E4K_REG_ILUT1 = 0x61,
|
79 |
|
|
E4K_REG_ILUT2 = 0x62,
|
80 |
|
|
E4K_REG_ILUT3 = 0x63,
|
81 |
|
|
// gap
|
82 |
|
|
E4K_REG_DCTIME1 = 0x70,
|
83 |
|
|
E4K_REG_DCTIME2 = 0x71,
|
84 |
|
|
E4K_REG_DCTIME3 = 0x72,
|
85 |
|
|
E4K_REG_DCTIME4 = 0x73,
|
86 |
|
|
E4K_REG_PWM1 = 0x74,
|
87 |
|
|
E4K_REG_PWM2 = 0x75,
|
88 |
|
|
E4K_REG_PWM3 = 0x76,
|
89 |
|
|
E4K_REG_PWM4 = 0x77,
|
90 |
|
|
E4K_REG_BIAS = 0x78,
|
91 |
|
|
E4K_REG_CLKOUT_PWDN = 0x7a,
|
92 |
|
|
E4K_REG_CHFILT_CALIB = 0x7b,
|
93 |
|
|
E4K_REG_I2C_REG_ADDR = 0x7d,
|
94 |
|
|
// FIXME
|
95 |
|
|
};
|
96 |
|
|
|
97 |
|
|
#define E4K_MASTER1_RESET (1 << 0)
|
98 |
|
|
#define E4K_MASTER1_NORM_STBY (1 << 1)
|
99 |
|
|
#define E4K_MASTER1_POR_DET (1 << 2)
|
100 |
|
|
|
101 |
|
|
#define E4K_SYNTH1_PLL_LOCK (1 << 0)
|
102 |
|
|
#define E4K_SYNTH1_BAND_SHIF 1
|
103 |
|
|
|
104 |
|
|
#define E4K_SYNTH7_3PHASE_EN (1 << 3)
|
105 |
|
|
|
106 |
|
|
#define E4K_SYNTH8_VCOCAL_UPD (1 << 2)
|
107 |
|
|
|
108 |
|
|
#define E4K_FILT3_DISABLE (1 << 5)
|
109 |
|
|
|
110 |
|
|
#define E4K_AGC1_LIN_MODE (1 << 4)
|
111 |
|
|
#define E4K_AGC1_LNA_UPDATE (1 << 5)
|
112 |
|
|
#define E4K_AGC1_LNA_G_LOW (1 << 6)
|
113 |
|
|
#define E4K_AGC1_LNA_G_HIGH (1 << 7)
|
114 |
|
|
|
115 |
|
|
#define E4K_AGC6_LNA_CAL_REQ (1 << 4)
|
116 |
|
|
|
117 |
|
|
#define E4K_AGC7_MIX_GAIN_AUTO (1 << 0)
|
118 |
|
|
#define E4K_AGC7_GAIN_STEP_5dB (1 << 5)
|
119 |
|
|
|
120 |
|
|
#define E4K_AGC8_SENS_LIN_AUTO (1 << 0)
|
121 |
|
|
|
122 |
|
|
#define E4K_AGC11_LNA_GAIN_ENH (1 << 0)
|
123 |
|
|
|
124 |
|
|
#define E4K_DC1_CAL_REQ (1 << 0)
|
125 |
|
|
|
126 |
|
|
#define E4K_DC5_I_LUT_EN (1 << 0)
|
127 |
|
|
#define E4K_DC5_Q_LUT_EN (1 << 1)
|
128 |
|
|
#define E4K_DC5_RANGE_DET_EN (1 << 2)
|
129 |
|
|
#define E4K_DC5_RANGE_EN (1 << 3)
|
130 |
|
|
#define E4K_DC5_TIMEVAR_EN (1 << 4)
|
131 |
|
|
|
132 |
|
|
#define E4K_CLKOUT_DISABLE 0x96
|
133 |
|
|
|
134 |
|
|
#define E4K_CHFCALIB_CMD (1 << 0)
|
135 |
|
|
|
136 |
|
|
#define E4K_AGC1_MOD_MASK 0xF
|
137 |
|
|
|
138 |
|
|
enum e4k_agc_mode {
|
139 |
|
|
E4K_AGC_MOD_SERIAL = 0x0,
|
140 |
|
|
E4K_AGC_MOD_IF_PWM_LNA_SERIAL = 0x1,
|
141 |
|
|
E4K_AGC_MOD_IF_PWM_LNA_AUTONL = 0x2,
|
142 |
|
|
E4K_AGC_MOD_IF_PWM_LNA_SUPERV = 0x3,
|
143 |
|
|
E4K_AGC_MOD_IF_SERIAL_LNA_PWM = 0x4,
|
144 |
|
|
E4K_AGC_MOD_IF_PWM_LNA_PWM = 0x5,
|
145 |
|
|
E4K_AGC_MOD_IF_DIG_LNA_SERIAL = 0x6,
|
146 |
|
|
E4K_AGC_MOD_IF_DIG_LNA_AUTON = 0x7,
|
147 |
|
|
E4K_AGC_MOD_IF_DIG_LNA_SUPERV = 0x8,
|
148 |
|
|
E4K_AGC_MOD_IF_SERIAL_LNA_AUTON = 0x9,
|
149 |
|
|
E4K_AGC_MOD_IF_SERIAL_LNA_SUPERV = 0xa,
|
150 |
|
|
};
|
151 |
|
|
|
152 |
|
|
enum e4k_band {
|
153 |
|
|
E4K_BAND_VHF2 = 0,
|
154 |
|
|
E4K_BAND_VHF3 = 1,
|
155 |
|
|
E4K_BAND_UHF = 2,
|
156 |
|
|
E4K_BAND_L = 3,
|
157 |
|
|
};
|
158 |
|
|
|
159 |
|
|
enum e4k_mixer_filter_bw {
|
160 |
|
|
E4K_F_MIX_BW_27M = 0,
|
161 |
|
|
E4K_F_MIX_BW_4M6 = 8,
|
162 |
|
|
E4K_F_MIX_BW_4M2 = 9,
|
163 |
|
|
E4K_F_MIX_BW_3M8 = 10,
|
164 |
|
|
E4K_F_MIX_BW_3M4 = 11,
|
165 |
|
|
E4K_F_MIX_BW_3M = 12,
|
166 |
|
|
E4K_F_MIX_BW_2M7 = 13,
|
167 |
|
|
E4K_F_MIX_BW_2M3 = 14,
|
168 |
|
|
E4K_F_MIX_BW_1M9 = 15,
|
169 |
|
|
};
|
170 |
|
|
|
171 |
|
|
enum e4k_if_filter {
|
172 |
|
|
E4K_IF_FILTER_MIX,
|
173 |
|
|
E4K_IF_FILTER_CHAN,
|
174 |
|
|
E4K_IF_FILTER_RC
|
175 |
|
|
};
|
176 |
|
|
struct e4k_pll_params {
|
177 |
|
|
uint32_t fosc;
|
178 |
|
|
uint32_t intended_flo;
|
179 |
|
|
uint32_t flo;
|
180 |
|
|
uint16_t x;
|
181 |
|
|
uint8_t z;
|
182 |
|
|
uint8_t r;
|
183 |
|
|
uint8_t r_idx;
|
184 |
|
|
uint8_t threephase;
|
185 |
|
|
};
|
186 |
|
|
|
187 |
|
|
struct e4k_state {
|
188 |
50731d24
|
Harald Welte
|
void *i2c_dev;
|
189 |
d5be5374
|
Harald Welte
|
uint8_t i2c_addr;
|
190 |
|
|
enum e4k_band band;
|
191 |
|
|
struct e4k_pll_params vco;
|
192 |
180193ce
|
Christian Daniel
|
void *rtl_dev;
|
193 |
d5be5374
|
Harald Welte
|
};
|
194 |
|
|
|
195 |
|
|
int e4k_init(struct e4k_state *e4k);
|
196 |
|
|
int e4k_if_gain_set(struct e4k_state *e4k, uint8_t stage, int8_t value);
|
197 |
9ce29d79
|
Harald Welte
|
int e4k_mixer_gain_set(struct e4k_state *e4k, int8_t value);
|
198 |
463a3f9c
|
Christian Daniel
|
int e4k_commonmode_set(struct e4k_state *e4k, int8_t value);
|
199 |
d5be5374
|
Harald Welte
|
int e4k_tune_freq(struct e4k_state *e4k, uint32_t freq);
|
200 |
|
|
int e4k_tune_params(struct e4k_state *e4k, struct e4k_pll_params *p);
|
201 |
180193ce
|
Christian Daniel
|
uint32_t e4k_compute_pll_params(struct e4k_pll_params *oscp, uint32_t fosc, uint32_t intended_flo);
|
202 |
d5be5374
|
Harald Welte
|
int e4k_if_filter_bw_get(struct e4k_state *e4k, enum e4k_if_filter filter);
|
203 |
180193ce
|
Christian Daniel
|
int e4k_if_filter_bw_set(struct e4k_state *e4k, enum e4k_if_filter filter, uint32_t bandwidth);
|
204 |
088d5312
|
Sylvain Munaut
|
int e4k_if_filter_chan_enable(struct e4k_state *e4k, int on);
|
205 |
d5be5374
|
Harald Welte
|
int e4k_rf_filter_set(struct e4k_state *e4k);
|
206 |
|
|
|
207 |
50731d24
|
Harald Welte
|
int e4k_reg_write(struct e4k_state *e4k, uint8_t reg, uint8_t val);
|
208 |
180193ce
|
Christian Daniel
|
uint8_t e4k_reg_read(struct e4k_state *e4k, uint8_t reg);
|
209 |
4683c1c2
|
Christian Daniel
|
|
210 |
|
|
int e4k_manual_dc_offset(struct e4k_state *e4k, int8_t iofs, int8_t irange, int8_t qofs, int8_t qrange);
|
211 |
c4c7c6ad
|
Harald Welte
|
int e4k_dc_offset_calibrate(struct e4k_state *e4k);
|
212 |
|
|
int e4k_dc_offset_gen_table(struct e4k_state *e4k);
|
213 |
|
|
|
214 |
180193ce
|
Christian Daniel
|
int e4k_set_lna_gain(struct e4k_state *e4k, int32_t gain);
|
215 |
|
|
int e4k_enable_manual_gain(struct e4k_state *e4k, uint8_t manual);
|
216 |
|
|
int e4k_set_enh_gain(struct e4k_state *e4k, int32_t gain);
|
217 |
|
|
|
218 |
b93708ed
|
Christian Daniel
|
int e4k_dump(struct e4k_state *e4k);
|
219 |
|
|
|
220 |
d5be5374
|
Harald Welte
|
#endif /* _E4K_TUNER_H */
|