1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Realtek RTL2832 DVB-T demodulator driver
5 * Copyright (C) 2012 Thomas Mair <thomas.mair86@gmail.com>
6 * Copyright (C) 2012-2014 Antti Palosaari <crope@iki.fi>
10 #define RTL2832_PRIV_H
12 #include <linux/regmap.h>
13 #include <linux/math64.h>
14 #include <linux/bitops.h>
16 #include <media/dvb_frontend.h>
17 #include <media/dvb_math.h>
21 struct rtl2832_platform_data
*pdata
;
22 struct i2c_client
*client
;
23 struct regmap_config regmap_config
;
24 struct regmap
*regmap
;
25 struct i2c_mux_core
*muxc
;
26 struct dvb_frontend fe
;
27 enum fe_status fe_status
;
28 u64 post_bit_error_prev
; /* for old DVBv3 read_ber() calculation */
32 struct delayed_work i2c_gate_work
;
33 unsigned long filters
; /* PID filter */
37 struct rtl2832_reg_entry
{
43 struct rtl2832_reg_value
{
48 /* Demod register bit names */
49 enum DVBT_REG_BIT_NAME
{
53 DVBT_RSD_BER_FAIL_VAL
,
114 DVBT_CFREQ_OFF_RATIO
,
149 DVBT_AGC_TARG_VAL_8_1
,
180 DVBT_MPEG_IO_OPT_2_2
,
181 DVBT_MPEG_IO_OPT_1_0
,
238 DVBT_REG_BIT_NAME_ITEM_TERMINATOR
,
241 static const struct rtl2832_reg_value rtl2832_tuner_init_fc2580
[] = {
242 {DVBT_DAGC_TRG_VAL
, 0x39},
243 {DVBT_AGC_TARG_VAL_0
, 0x0},
244 {DVBT_AGC_TARG_VAL_8_1
, 0x5a},
245 {DVBT_AAGC_LOOP_GAIN
, 0x16},
246 {DVBT_LOOP_GAIN2_3_0
, 0x6},
247 {DVBT_LOOP_GAIN2_4
, 0x1},
248 {DVBT_LOOP_GAIN3
, 0x16},
256 {DVBT_IF_AGC_MIN
, 0x80},
257 {DVBT_IF_AGC_MAX
, 0x7f},
258 {DVBT_RF_AGC_MIN
, 0x9c},
259 {DVBT_RF_AGC_MAX
, 0x7f},
260 {DVBT_POLAR_RF_AGC
, 0x0},
261 {DVBT_POLAR_IF_AGC
, 0x0},
262 {DVBT_AD7_SETTING
, 0xe9f4},
265 static const struct rtl2832_reg_value rtl2832_tuner_init_tua9001
[] = {
266 {DVBT_DAGC_TRG_VAL
, 0x39},
267 {DVBT_AGC_TARG_VAL_0
, 0x0},
268 {DVBT_AGC_TARG_VAL_8_1
, 0x5a},
269 {DVBT_AAGC_LOOP_GAIN
, 0x16},
270 {DVBT_LOOP_GAIN2_3_0
, 0x6},
271 {DVBT_LOOP_GAIN2_4
, 0x1},
272 {DVBT_LOOP_GAIN3
, 0x16},
280 {DVBT_IF_AGC_MIN
, 0x80},
281 {DVBT_IF_AGC_MAX
, 0x7f},
282 {DVBT_RF_AGC_MIN
, 0x9c},
283 {DVBT_RF_AGC_MAX
, 0x7f},
284 {DVBT_POLAR_RF_AGC
, 0x0},
285 {DVBT_POLAR_IF_AGC
, 0x0},
286 {DVBT_AD7_SETTING
, 0xe9f4},
287 {DVBT_OPT_ADC_IQ
, 0x1},
290 {DVBT_SPEC_INV
, 0x0},
293 static const struct rtl2832_reg_value rtl2832_tuner_init_fc0012
[] = {
294 {DVBT_DAGC_TRG_VAL
, 0x5a},
295 {DVBT_AGC_TARG_VAL_0
, 0x0},
296 {DVBT_AGC_TARG_VAL_8_1
, 0x5a},
297 {DVBT_AAGC_LOOP_GAIN
, 0x16},
298 {DVBT_LOOP_GAIN2_3_0
, 0x6},
299 {DVBT_LOOP_GAIN2_4
, 0x1},
300 {DVBT_LOOP_GAIN3
, 0x16},
308 {DVBT_IF_AGC_MIN
, 0x80},
309 {DVBT_IF_AGC_MAX
, 0x7f},
310 {DVBT_RF_AGC_MIN
, 0x80},
311 {DVBT_RF_AGC_MAX
, 0x7f},
312 {DVBT_POLAR_RF_AGC
, 0x0},
313 {DVBT_POLAR_IF_AGC
, 0x0},
314 {DVBT_AD7_SETTING
, 0xe9bf},
315 {DVBT_EN_GI_PGA
, 0x0},
316 {DVBT_THD_LOCK_UP
, 0x0},
317 {DVBT_THD_LOCK_DW
, 0x0},
318 {DVBT_THD_UP1
, 0x11},
319 {DVBT_THD_DW1
, 0xef},
320 {DVBT_INTER_CNT_LEN
, 0xc},
321 {DVBT_GI_PGA_STATE
, 0x0},
322 {DVBT_EN_AGC_PGA
, 0x1},
323 {DVBT_IF_AGC_MAN
, 0x0},
324 {DVBT_SPEC_INV
, 0x0},
327 static const struct rtl2832_reg_value rtl2832_tuner_init_e4000
[] = {
328 {DVBT_DAGC_TRG_VAL
, 0x5a},
329 {DVBT_AGC_TARG_VAL_0
, 0x0},
330 {DVBT_AGC_TARG_VAL_8_1
, 0x5a},
331 {DVBT_AAGC_LOOP_GAIN
, 0x18},
332 {DVBT_LOOP_GAIN2_3_0
, 0x8},
333 {DVBT_LOOP_GAIN2_4
, 0x1},
334 {DVBT_LOOP_GAIN3
, 0x18},
342 {DVBT_IF_AGC_MIN
, 0x80},
343 {DVBT_IF_AGC_MAX
, 0x7f},
344 {DVBT_RF_AGC_MIN
, 0x80},
345 {DVBT_RF_AGC_MAX
, 0x7f},
346 {DVBT_POLAR_RF_AGC
, 0x0},
347 {DVBT_POLAR_IF_AGC
, 0x0},
348 {DVBT_AD7_SETTING
, 0xe9d4},
349 {DVBT_EN_GI_PGA
, 0x0},
350 {DVBT_THD_LOCK_UP
, 0x0},
351 {DVBT_THD_LOCK_DW
, 0x0},
352 {DVBT_THD_UP1
, 0x14},
353 {DVBT_THD_DW1
, 0xec},
354 {DVBT_INTER_CNT_LEN
, 0xc},
355 {DVBT_GI_PGA_STATE
, 0x0},
356 {DVBT_EN_AGC_PGA
, 0x1},
359 {DVBT_REG_MONSEL
, 0x1},
361 {DVBT_REG_4MSEL
, 0x0},
362 {DVBT_SPEC_INV
, 0x0},
365 static const struct rtl2832_reg_value rtl2832_tuner_init_r820t
[] = {
366 {DVBT_DAGC_TRG_VAL
, 0x39},
367 {DVBT_AGC_TARG_VAL_0
, 0x0},
368 {DVBT_AGC_TARG_VAL_8_1
, 0x40},
369 {DVBT_AAGC_LOOP_GAIN
, 0x16},
370 {DVBT_LOOP_GAIN2_3_0
, 0x8},
371 {DVBT_LOOP_GAIN2_4
, 0x1},
372 {DVBT_LOOP_GAIN3
, 0x18},
380 {DVBT_IF_AGC_MIN
, 0x80},
381 {DVBT_IF_AGC_MAX
, 0x7f},
382 {DVBT_RF_AGC_MIN
, 0x80},
383 {DVBT_RF_AGC_MAX
, 0x7f},
384 {DVBT_POLAR_RF_AGC
, 0x0},
385 {DVBT_POLAR_IF_AGC
, 0x0},
386 {DVBT_AD7_SETTING
, 0xe9f4},
387 {DVBT_SPEC_INV
, 0x1},
390 static const struct rtl2832_reg_value rtl2832_tuner_init_si2157
[] = {
391 {DVBT_DAGC_TRG_VAL
, 0x39},
392 {DVBT_AGC_TARG_VAL_0
, 0x0},
393 {DVBT_AGC_TARG_VAL_8_1
, 0x40},
394 {DVBT_AAGC_LOOP_GAIN
, 0x16},
395 {DVBT_LOOP_GAIN2_3_0
, 0x8},
396 {DVBT_LOOP_GAIN2_4
, 0x1},
397 {DVBT_LOOP_GAIN3
, 0x18},
405 {DVBT_IF_AGC_MIN
, 0x80},
406 {DVBT_IF_AGC_MAX
, 0x7f},
407 {DVBT_RF_AGC_MIN
, 0x80},
408 {DVBT_RF_AGC_MAX
, 0x7f},
409 {DVBT_POLAR_RF_AGC
, 0x0},
410 {DVBT_POLAR_IF_AGC
, 0x0},
411 {DVBT_AD7_SETTING
, 0xe9f4},
412 {DVBT_SPEC_INV
, 0x0},
415 #endif /* RTL2832_PRIV_H */