blob: a44614c7af21feb70827f92d27508370cffa86c7 [file] [log] [blame]
Thomas Mair82041c02012-05-18 14:47:40 -03001/*
2 * Realtek RTL2832 DVB-T demodulator driver
3 *
4 * Copyright (C) 2012 Thomas Mair <thomas.mair86@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#ifndef RTL2832_PRIV_H
22#define RTL2832_PRIV_H
23
24#include "dvb_frontend.h"
25#include "rtl2832.h"
Antti Palosaari8823f022013-11-26 12:53:46 -030026#include <linux/i2c-mux.h>
Antti Palosaarid1016582014-12-14 04:45:57 -030027#include <linux/regmap.h>
Antti Palosaarif7caf932014-12-14 10:05:49 -030028#include <linux/math64.h>
Thomas Mair82041c02012-05-18 14:47:40 -030029
Antti Palosaari038c6f22014-12-13 00:37:43 -030030struct rtl2832_dev {
Antti Palosaarie1174d72014-12-13 05:26:27 -030031 struct rtl2832_platform_data *pdata;
Antti Palosaaric2c83862014-12-02 10:55:17 -030032 struct i2c_client *client;
Antti Palosaarid1016582014-12-14 04:45:57 -030033 struct regmap *regmap;
Antti Palosaari8823f022013-11-26 12:53:46 -030034 struct i2c_adapter *i2c_adapter;
Antti Palosaari0ea872d2013-12-03 18:19:39 -030035 struct i2c_adapter *i2c_adapter_tuner;
Thomas Mair82041c02012-05-18 14:47:40 -030036 struct dvb_frontend fe;
Antti Palosaari19d273d2014-12-14 06:55:43 -030037 struct delayed_work stat_work;
38 fe_status_t fe_status;
Antti Palosaari084330b2014-12-14 10:10:22 -030039 u64 post_bit_error_prev; /* for old DVBv3 read_ber() calculation */
Antti Palosaari6b4fd012014-12-14 09:59:20 -030040 u64 post_bit_error;
41 u64 post_bit_count;
Thomas Mair82041c02012-05-18 14:47:40 -030042 bool i2c_gate_state;
43 bool sleeping;
Antti Palosaari92d20d92014-02-08 03:50:04 -030044 struct delayed_work i2c_gate_work;
Thomas Mair82041c02012-05-18 14:47:40 -030045};
46
47struct rtl2832_reg_entry {
48 u8 page;
49 u8 start_address;
50 u8 msb;
51 u8 lsb;
52};
53
54struct rtl2832_reg_value {
55 int reg;
56 u32 value;
57};
58
59
60/* Demod register bit names */
61enum DVBT_REG_BIT_NAME {
62 DVBT_SOFT_RST,
63 DVBT_IIC_REPEAT,
64 DVBT_TR_WAIT_MIN_8K,
65 DVBT_RSD_BER_FAIL_VAL,
66 DVBT_EN_BK_TRK,
67 DVBT_REG_PI,
68 DVBT_REG_PFREQ_1_0,
69 DVBT_PD_DA8,
70 DVBT_LOCK_TH,
71 DVBT_BER_PASS_SCAL,
72 DVBT_CE_FFSM_BYPASS,
73 DVBT_ALPHAIIR_N,
74 DVBT_ALPHAIIR_DIF,
75 DVBT_EN_TRK_SPAN,
76 DVBT_LOCK_TH_LEN,
77 DVBT_CCI_THRE,
78 DVBT_CCI_MON_SCAL,
79 DVBT_CCI_M0,
80 DVBT_CCI_M1,
81 DVBT_CCI_M2,
82 DVBT_CCI_M3,
83 DVBT_SPEC_INIT_0,
84 DVBT_SPEC_INIT_1,
85 DVBT_SPEC_INIT_2,
86 DVBT_AD_EN_REG,
87 DVBT_AD_EN_REG1,
88 DVBT_EN_BBIN,
89 DVBT_MGD_THD0,
90 DVBT_MGD_THD1,
91 DVBT_MGD_THD2,
92 DVBT_MGD_THD3,
93 DVBT_MGD_THD4,
94 DVBT_MGD_THD5,
95 DVBT_MGD_THD6,
96 DVBT_MGD_THD7,
97 DVBT_EN_CACQ_NOTCH,
98 DVBT_AD_AV_REF,
99 DVBT_PIP_ON,
100 DVBT_SCALE1_B92,
101 DVBT_SCALE1_B93,
102 DVBT_SCALE1_BA7,
103 DVBT_SCALE1_BA9,
104 DVBT_SCALE1_BAA,
105 DVBT_SCALE1_BAB,
106 DVBT_SCALE1_BAC,
107 DVBT_SCALE1_BB0,
108 DVBT_SCALE1_BB1,
109 DVBT_KB_P1,
110 DVBT_KB_P2,
111 DVBT_KB_P3,
112 DVBT_OPT_ADC_IQ,
113 DVBT_AD_AVI,
114 DVBT_AD_AVQ,
115 DVBT_K1_CR_STEP12,
116 DVBT_TRK_KS_P2,
117 DVBT_TRK_KS_I2,
118 DVBT_TR_THD_SET2,
119 DVBT_TRK_KC_P2,
120 DVBT_TRK_KC_I2,
121 DVBT_CR_THD_SET2,
122 DVBT_PSET_IFFREQ,
123 DVBT_SPEC_INV,
124 DVBT_BW_INDEX,
125 DVBT_RSAMP_RATIO,
126 DVBT_CFREQ_OFF_RATIO,
127 DVBT_FSM_STAGE,
128 DVBT_RX_CONSTEL,
129 DVBT_RX_HIER,
130 DVBT_RX_C_RATE_LP,
131 DVBT_RX_C_RATE_HP,
132 DVBT_GI_IDX,
133 DVBT_FFT_MODE_IDX,
134 DVBT_RSD_BER_EST,
135 DVBT_CE_EST_EVM,
136 DVBT_RF_AGC_VAL,
137 DVBT_IF_AGC_VAL,
138 DVBT_DAGC_VAL,
139 DVBT_SFREQ_OFF,
140 DVBT_CFREQ_OFF,
141 DVBT_POLAR_RF_AGC,
142 DVBT_POLAR_IF_AGC,
143 DVBT_AAGC_HOLD,
144 DVBT_EN_RF_AGC,
145 DVBT_EN_IF_AGC,
146 DVBT_IF_AGC_MIN,
147 DVBT_IF_AGC_MAX,
148 DVBT_RF_AGC_MIN,
149 DVBT_RF_AGC_MAX,
150 DVBT_IF_AGC_MAN,
151 DVBT_IF_AGC_MAN_VAL,
152 DVBT_RF_AGC_MAN,
153 DVBT_RF_AGC_MAN_VAL,
154 DVBT_DAGC_TRG_VAL,
155 DVBT_AGC_TARG_VAL,
156 DVBT_LOOP_GAIN_3_0,
157 DVBT_LOOP_GAIN_4,
158 DVBT_VTOP,
159 DVBT_KRF,
160 DVBT_AGC_TARG_VAL_0,
161 DVBT_AGC_TARG_VAL_8_1,
162 DVBT_AAGC_LOOP_GAIN,
163 DVBT_LOOP_GAIN2_3_0,
164 DVBT_LOOP_GAIN2_4,
165 DVBT_LOOP_GAIN3,
166 DVBT_VTOP1,
167 DVBT_VTOP2,
168 DVBT_VTOP3,
169 DVBT_KRF1,
170 DVBT_KRF2,
171 DVBT_KRF3,
172 DVBT_KRF4,
173 DVBT_EN_GI_PGA,
174 DVBT_THD_LOCK_UP,
175 DVBT_THD_LOCK_DW,
176 DVBT_THD_UP1,
177 DVBT_THD_DW1,
178 DVBT_INTER_CNT_LEN,
179 DVBT_GI_PGA_STATE,
180 DVBT_EN_AGC_PGA,
181 DVBT_CKOUTPAR,
182 DVBT_CKOUT_PWR,
183 DVBT_SYNC_DUR,
184 DVBT_ERR_DUR,
185 DVBT_SYNC_LVL,
186 DVBT_ERR_LVL,
187 DVBT_VAL_LVL,
188 DVBT_SERIAL,
189 DVBT_SER_LSB,
190 DVBT_CDIV_PH0,
191 DVBT_CDIV_PH1,
192 DVBT_MPEG_IO_OPT_2_2,
193 DVBT_MPEG_IO_OPT_1_0,
194 DVBT_CKOUTPAR_PIP,
195 DVBT_CKOUT_PWR_PIP,
196 DVBT_SYNC_LVL_PIP,
197 DVBT_ERR_LVL_PIP,
198 DVBT_VAL_LVL_PIP,
199 DVBT_CKOUTPAR_PID,
200 DVBT_CKOUT_PWR_PID,
201 DVBT_SYNC_LVL_PID,
202 DVBT_ERR_LVL_PID,
203 DVBT_VAL_LVL_PID,
204 DVBT_SM_PASS,
205 DVBT_UPDATE_REG_2,
206 DVBT_BTHD_P3,
207 DVBT_BTHD_D3,
208 DVBT_FUNC4_REG0,
209 DVBT_FUNC4_REG1,
210 DVBT_FUNC4_REG2,
211 DVBT_FUNC4_REG3,
212 DVBT_FUNC4_REG4,
213 DVBT_FUNC4_REG5,
214 DVBT_FUNC4_REG6,
215 DVBT_FUNC4_REG7,
216 DVBT_FUNC4_REG8,
217 DVBT_FUNC4_REG9,
218 DVBT_FUNC4_REG10,
219 DVBT_FUNC5_REG0,
220 DVBT_FUNC5_REG1,
221 DVBT_FUNC5_REG2,
222 DVBT_FUNC5_REG3,
223 DVBT_FUNC5_REG4,
224 DVBT_FUNC5_REG5,
225 DVBT_FUNC5_REG6,
226 DVBT_FUNC5_REG7,
227 DVBT_FUNC5_REG8,
228 DVBT_FUNC5_REG9,
229 DVBT_FUNC5_REG10,
230 DVBT_FUNC5_REG11,
231 DVBT_FUNC5_REG12,
232 DVBT_FUNC5_REG13,
233 DVBT_FUNC5_REG14,
234 DVBT_FUNC5_REG15,
235 DVBT_FUNC5_REG16,
236 DVBT_FUNC5_REG17,
237 DVBT_FUNC5_REG18,
238 DVBT_AD7_SETTING,
239 DVBT_RSSI_R,
240 DVBT_ACI_DET_IND,
241 DVBT_REG_MON,
242 DVBT_REG_MONSEL,
243 DVBT_REG_GPE,
244 DVBT_REG_GPO,
245 DVBT_REG_4MSEL,
246 DVBT_TEST_REG_1,
247 DVBT_TEST_REG_2,
248 DVBT_TEST_REG_3,
249 DVBT_TEST_REG_4,
250 DVBT_REG_BIT_NAME_ITEM_TERMINATOR,
251};
252
Antti Palosaari5db41872012-09-11 22:27:08 -0300253static const struct rtl2832_reg_value rtl2832_tuner_init_tua9001[] = {
254 {DVBT_DAGC_TRG_VAL, 0x39},
255 {DVBT_AGC_TARG_VAL_0, 0x0},
256 {DVBT_AGC_TARG_VAL_8_1, 0x5a},
257 {DVBT_AAGC_LOOP_GAIN, 0x16},
258 {DVBT_LOOP_GAIN2_3_0, 0x6},
259 {DVBT_LOOP_GAIN2_4, 0x1},
260 {DVBT_LOOP_GAIN3, 0x16},
261 {DVBT_VTOP1, 0x35},
262 {DVBT_VTOP2, 0x21},
263 {DVBT_VTOP3, 0x21},
264 {DVBT_KRF1, 0x0},
265 {DVBT_KRF2, 0x40},
266 {DVBT_KRF3, 0x10},
267 {DVBT_KRF4, 0x10},
268 {DVBT_IF_AGC_MIN, 0x80},
269 {DVBT_IF_AGC_MAX, 0x7f},
270 {DVBT_RF_AGC_MIN, 0x9c},
271 {DVBT_RF_AGC_MAX, 0x7f},
272 {DVBT_POLAR_RF_AGC, 0x0},
273 {DVBT_POLAR_IF_AGC, 0x0},
274 {DVBT_AD7_SETTING, 0xe9f4},
275 {DVBT_OPT_ADC_IQ, 0x1},
276 {DVBT_AD_AVI, 0x0},
277 {DVBT_AD_AVQ, 0x0},
Antti Palosaari3ca24182013-10-13 00:06:44 -0300278 {DVBT_SPEC_INV, 0x0},
Antti Palosaari5db41872012-09-11 22:27:08 -0300279};
280
Antti Palosaari832cc7c2012-09-11 22:27:04 -0300281static const struct rtl2832_reg_value rtl2832_tuner_init_fc0012[] = {
282 {DVBT_DAGC_TRG_VAL, 0x5a},
283 {DVBT_AGC_TARG_VAL_0, 0x0},
284 {DVBT_AGC_TARG_VAL_8_1, 0x5a},
285 {DVBT_AAGC_LOOP_GAIN, 0x16},
286 {DVBT_LOOP_GAIN2_3_0, 0x6},
287 {DVBT_LOOP_GAIN2_4, 0x1},
288 {DVBT_LOOP_GAIN3, 0x16},
289 {DVBT_VTOP1, 0x35},
290 {DVBT_VTOP2, 0x21},
291 {DVBT_VTOP3, 0x21},
292 {DVBT_KRF1, 0x0},
293 {DVBT_KRF2, 0x40},
294 {DVBT_KRF3, 0x10},
295 {DVBT_KRF4, 0x10},
296 {DVBT_IF_AGC_MIN, 0x80},
297 {DVBT_IF_AGC_MAX, 0x7f},
298 {DVBT_RF_AGC_MIN, 0x80},
299 {DVBT_RF_AGC_MAX, 0x7f},
300 {DVBT_POLAR_RF_AGC, 0x0},
301 {DVBT_POLAR_IF_AGC, 0x0},
302 {DVBT_AD7_SETTING, 0xe9bf},
303 {DVBT_EN_GI_PGA, 0x0},
304 {DVBT_THD_LOCK_UP, 0x0},
305 {DVBT_THD_LOCK_DW, 0x0},
306 {DVBT_THD_UP1, 0x11},
307 {DVBT_THD_DW1, 0xef},
308 {DVBT_INTER_CNT_LEN, 0xc},
309 {DVBT_GI_PGA_STATE, 0x0},
310 {DVBT_EN_AGC_PGA, 0x1},
311 {DVBT_IF_AGC_MAN, 0x0},
Antti Palosaari3ca24182013-10-13 00:06:44 -0300312 {DVBT_SPEC_INV, 0x0},
Antti Palosaari832cc7c2012-09-11 22:27:04 -0300313};
314
Antti Palosaari7e688de2012-09-17 17:53:04 -0300315static const struct rtl2832_reg_value rtl2832_tuner_init_e4000[] = {
316 {DVBT_DAGC_TRG_VAL, 0x5a},
317 {DVBT_AGC_TARG_VAL_0, 0x0},
318 {DVBT_AGC_TARG_VAL_8_1, 0x5a},
319 {DVBT_AAGC_LOOP_GAIN, 0x18},
320 {DVBT_LOOP_GAIN2_3_0, 0x8},
321 {DVBT_LOOP_GAIN2_4, 0x1},
322 {DVBT_LOOP_GAIN3, 0x18},
323 {DVBT_VTOP1, 0x35},
324 {DVBT_VTOP2, 0x21},
325 {DVBT_VTOP3, 0x21},
326 {DVBT_KRF1, 0x0},
327 {DVBT_KRF2, 0x40},
328 {DVBT_KRF3, 0x10},
329 {DVBT_KRF4, 0x10},
330 {DVBT_IF_AGC_MIN, 0x80},
331 {DVBT_IF_AGC_MAX, 0x7f},
332 {DVBT_RF_AGC_MIN, 0x80},
333 {DVBT_RF_AGC_MAX, 0x7f},
334 {DVBT_POLAR_RF_AGC, 0x0},
335 {DVBT_POLAR_IF_AGC, 0x0},
336 {DVBT_AD7_SETTING, 0xe9d4},
337 {DVBT_EN_GI_PGA, 0x0},
338 {DVBT_THD_LOCK_UP, 0x0},
339 {DVBT_THD_LOCK_DW, 0x0},
340 {DVBT_THD_UP1, 0x14},
341 {DVBT_THD_DW1, 0xec},
342 {DVBT_INTER_CNT_LEN, 0xc},
343 {DVBT_GI_PGA_STATE, 0x0},
344 {DVBT_EN_AGC_PGA, 0x1},
345 {DVBT_REG_GPE, 0x1},
346 {DVBT_REG_GPO, 0x1},
347 {DVBT_REG_MONSEL, 0x1},
348 {DVBT_REG_MON, 0x1},
349 {DVBT_REG_4MSEL, 0x0},
Antti Palosaari3ca24182013-10-13 00:06:44 -0300350 {DVBT_SPEC_INV, 0x0},
Mauro Carvalho Chehabfa4bfd22013-04-09 18:19:50 -0300351};
352
353static const struct rtl2832_reg_value rtl2832_tuner_init_r820t[] = {
Antti Palosaari3ca24182013-10-13 00:06:44 -0300354 {DVBT_DAGC_TRG_VAL, 0x39},
355 {DVBT_AGC_TARG_VAL_0, 0x0},
356 {DVBT_AGC_TARG_VAL_8_1, 0x40},
357 {DVBT_AAGC_LOOP_GAIN, 0x16},
358 {DVBT_LOOP_GAIN2_3_0, 0x8},
359 {DVBT_LOOP_GAIN2_4, 0x1},
360 {DVBT_LOOP_GAIN3, 0x18},
361 {DVBT_VTOP1, 0x35},
362 {DVBT_VTOP2, 0x21},
363 {DVBT_VTOP3, 0x21},
364 {DVBT_KRF1, 0x0},
365 {DVBT_KRF2, 0x40},
366 {DVBT_KRF3, 0x10},
367 {DVBT_KRF4, 0x10},
368 {DVBT_IF_AGC_MIN, 0x80},
369 {DVBT_IF_AGC_MAX, 0x7f},
370 {DVBT_RF_AGC_MIN, 0x80},
371 {DVBT_RF_AGC_MAX, 0x7f},
372 {DVBT_POLAR_RF_AGC, 0x0},
373 {DVBT_POLAR_IF_AGC, 0x0},
374 {DVBT_AD7_SETTING, 0xe9f4},
375 {DVBT_SPEC_INV, 0x1},
Antti Palosaari7e688de2012-09-17 17:53:04 -0300376};
377
Thomas Mair82041c02012-05-18 14:47:40 -0300378#endif /* RTL2832_PRIV_H */