librtlsdr  UNKNOWN
RTL-SDR library
tuner_r82xx.h
1 /*
2  * Rafael Micro R820T/R828D driver
3  *
4  * Copyright (C) 2013 Mauro Carvalho Chehab <mchehab@redhat.com>
5  * Copyright (C) 2013 Steve Markgraf <steve@steve-m.de>
6  *
7  * This driver is a heavily modified version of the driver found in the
8  * Linux kernel:
9  * http://git.linuxtv.org/linux-2.6.git/history/HEAD:/drivers/media/tuners/r820t.c
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 #ifndef R82XX_H
26 #define R82XX_H
27 
28 #define R820T_I2C_ADDR 0x34
29 #define R828D_I2C_ADDR 0x74
30 #define R828D_XTAL_FREQ 16000000
31 
32 #define R82XX_CHECK_ADDR 0x00
33 #define R82XX_CHECK_VAL 0x69
34 
35 #define R82XX_IF_FREQ 3570000
36 
37 #define REG_SHADOW_START 5
38 #define NUM_REGS 30
39 #define NUM_IMR 5
40 #define IMR_TRIAL 9
41 
42 #define VER_NUM 49
43 
44 enum r82xx_chip {
45  CHIP_R820T,
46  CHIP_R620D,
47  CHIP_R828D,
48  CHIP_R828,
49  CHIP_R828S,
50  CHIP_R820C,
51 };
52 
53 enum r82xx_tuner_type {
54  TUNER_RADIO = 1,
55  TUNER_ANALOG_TV,
56  TUNER_DIGITAL_TV
57 };
58 
59 enum r82xx_xtal_cap_value {
60  XTAL_LOW_CAP_30P = 0,
61  XTAL_LOW_CAP_20P,
62  XTAL_LOW_CAP_10P,
63  XTAL_LOW_CAP_0P,
64  XTAL_HIGH_CAP_0P
65 };
66 
67 struct r82xx_config {
68  uint8_t i2c_addr;
69  uint32_t xtal;
70  enum r82xx_chip rafael_chip;
71  unsigned int max_i2c_msg_len;
72  int use_predetect;
73 };
74 
75 struct r82xx_priv {
76  struct r82xx_config *cfg;
77 
78  uint8_t regs[NUM_REGS];
79  uint8_t buf[NUM_REGS + 1];
80  enum r82xx_xtal_cap_value xtal_cap_sel;
81  uint16_t pll; /* kHz */
82  uint32_t int_freq;
83  uint8_t fil_cal_code;
84  uint8_t input;
85  int has_lock;
86  int init_done;
87 
88  /* Store current mode */
89  uint32_t delsys;
90  enum r82xx_tuner_type type;
91 
92  uint32_t bw; /* in MHz */
93 
94  void *rtl_dev;
95 };
96 
98  uint32_t freq;
99  uint8_t open_d;
100  uint8_t rf_mux_ploy;
101  uint8_t tf_c;
102  uint8_t xtal_cap20p;
103  uint8_t xtal_cap10p;
104  uint8_t xtal_cap0p;
105 };
106 
107 enum r82xx_delivery_system {
108  SYS_UNDEFINED,
109  SYS_DVBT,
110  SYS_DVBT2,
111  SYS_ISDBT,
112 };
113 
114 int r82xx_standby(struct r82xx_priv *priv);
115 int r82xx_init(struct r82xx_priv *priv);
116 int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq);
117 int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain);
118 
119 #endif