1
2
3
4
5
6
7
8
9 #ifndef __TDA18271_PRIV_H__
10 #define __TDA18271_PRIV_H__
11
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14 #include <linux/kernel.h>
15 #include <linux/types.h>
16 #include <linux/mutex.h>
17 #include "tuner-i2c.h"
18 #include "tda18271.h"
19
20 #define R_ID 0x00
21 #define R_TM 0x01
22 #define R_PL 0x02
23 #define R_EP1 0x03
24 #define R_EP2 0x04
25 #define R_EP3 0x05
26 #define R_EP4 0x06
27 #define R_EP5 0x07
28 #define R_CPD 0x08
29 #define R_CD1 0x09
30 #define R_CD2 0x0a
31 #define R_CD3 0x0b
32 #define R_MPD 0x0c
33 #define R_MD1 0x0d
34 #define R_MD2 0x0e
35 #define R_MD3 0x0f
36 #define R_EB1 0x10
37 #define R_EB2 0x11
38 #define R_EB3 0x12
39 #define R_EB4 0x13
40 #define R_EB5 0x14
41 #define R_EB6 0x15
42 #define R_EB7 0x16
43 #define R_EB8 0x17
44 #define R_EB9 0x18
45 #define R_EB10 0x19
46 #define R_EB11 0x1a
47 #define R_EB12 0x1b
48 #define R_EB13 0x1c
49 #define R_EB14 0x1d
50 #define R_EB15 0x1e
51 #define R_EB16 0x1f
52 #define R_EB17 0x20
53 #define R_EB18 0x21
54 #define R_EB19 0x22
55 #define R_EB20 0x23
56 #define R_EB21 0x24
57 #define R_EB22 0x25
58 #define R_EB23 0x26
59
60 #define TDA18271_NUM_REGS 39
61
62
63
64 struct tda18271_rf_tracking_filter_cal {
65 u32 rfmax;
66 u8 rfband;
67 u32 rf1_def;
68 u32 rf2_def;
69 u32 rf3_def;
70 u32 rf1;
71 u32 rf2;
72 u32 rf3;
73 s32 rf_a1;
74 s32 rf_b1;
75 s32 rf_a2;
76 s32 rf_b2;
77 };
78
79 enum tda18271_pll {
80 TDA18271_MAIN_PLL,
81 TDA18271_CAL_PLL,
82 };
83
84 struct tda18271_map_layout;
85
86 enum tda18271_ver {
87 TDA18271HDC1,
88 TDA18271HDC2,
89 };
90
91 struct tda18271_priv {
92 unsigned char tda18271_regs[TDA18271_NUM_REGS];
93
94 struct list_head hybrid_tuner_instance_list;
95 struct tuner_i2c_props i2c_props;
96
97 enum tda18271_mode mode;
98 enum tda18271_role role;
99 enum tda18271_i2c_gate gate;
100 enum tda18271_ver id;
101 enum tda18271_output_options output_opt;
102 enum tda18271_small_i2c small_i2c;
103
104 unsigned int config;
105 unsigned int cal_initialized:1;
106
107 u8 tm_rfcal;
108
109 struct tda18271_map_layout *maps;
110 struct tda18271_std_map std;
111 struct tda18271_rf_tracking_filter_cal rf_cal_state[8];
112
113 struct mutex lock;
114
115 u16 if_freq;
116
117 u32 frequency;
118 u32 bandwidth;
119 };
120
121
122
123 extern int tda18271_debug;
124
125 #define DBG_INFO 1
126 #define DBG_MAP 2
127 #define DBG_REG 4
128 #define DBG_ADV 8
129 #define DBG_CAL 16
130
131 __attribute__((format(printf, 4, 5)))
132 void _tda_printk(struct tda18271_priv *state, const char *level,
133 const char *func, const char *fmt, ...);
134
135 #define tda_printk(st, lvl, fmt, arg...) \
136 _tda_printk(st, lvl, __func__, fmt, ##arg)
137
138 #define tda_dprintk(st, lvl, fmt, arg...) \
139 do { \
140 if (tda18271_debug & lvl) \
141 tda_printk(st, KERN_DEBUG, fmt, ##arg); \
142 } while (0)
143
144 #define tda_info(fmt, arg...) pr_info(fmt, ##arg)
145 #define tda_warn(fmt, arg...) tda_printk(priv, KERN_WARNING, fmt, ##arg)
146 #define tda_err(fmt, arg...) tda_printk(priv, KERN_ERR, fmt, ##arg)
147 #define tda_dbg(fmt, arg...) tda_dprintk(priv, DBG_INFO, fmt, ##arg)
148 #define tda_map(fmt, arg...) tda_dprintk(priv, DBG_MAP, fmt, ##arg)
149 #define tda_reg(fmt, arg...) tda_dprintk(priv, DBG_REG, fmt, ##arg)
150 #define tda_cal(fmt, arg...) tda_dprintk(priv, DBG_CAL, fmt, ##arg)
151
152 #define tda_fail(ret) \
153 ({ \
154 int __ret; \
155 __ret = (ret < 0); \
156 if (__ret) \
157 tda_printk(priv, KERN_ERR, \
158 "error %d on line %d\n", ret, __LINE__); \
159 __ret; \
160 })
161
162
163
164 enum tda18271_map_type {
165
166 MAIN_PLL,
167 CAL_PLL,
168
169 RF_CAL,
170 RF_CAL_KMCO,
171 RF_CAL_DC_OVER_DT,
172 BP_FILTER,
173 RF_BAND,
174 GAIN_TAPER,
175 IR_MEASURE,
176 };
177
178 extern int tda18271_lookup_pll_map(struct dvb_frontend *fe,
179 enum tda18271_map_type map_type,
180 u32 *freq, u8 *post_div, u8 *div);
181 extern int tda18271_lookup_map(struct dvb_frontend *fe,
182 enum tda18271_map_type map_type,
183 u32 *freq, u8 *val);
184
185 extern int tda18271_lookup_thermometer(struct dvb_frontend *fe);
186
187 extern int tda18271_lookup_rf_band(struct dvb_frontend *fe,
188 u32 *freq, u8 *rf_band);
189
190 extern int tda18271_lookup_cid_target(struct dvb_frontend *fe,
191 u32 *freq, u8 *cid_target,
192 u16 *count_limit);
193
194 extern int tda18271_assign_map_layout(struct dvb_frontend *fe);
195
196
197
198 extern int tda18271_read_regs(struct dvb_frontend *fe);
199 extern int tda18271_read_extended(struct dvb_frontend *fe);
200 extern int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len);
201 extern int tda18271_init_regs(struct dvb_frontend *fe);
202
203 extern int tda18271_charge_pump_source(struct dvb_frontend *fe,
204 enum tda18271_pll pll, int force);
205 extern int tda18271_set_standby_mode(struct dvb_frontend *fe,
206 int sm, int sm_lt, int sm_xt);
207
208 extern int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq);
209 extern int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq);
210
211 extern int tda18271_calc_bp_filter(struct dvb_frontend *fe, u32 *freq);
212 extern int tda18271_calc_km(struct dvb_frontend *fe, u32 *freq);
213 extern int tda18271_calc_rf_band(struct dvb_frontend *fe, u32 *freq);
214 extern int tda18271_calc_gain_taper(struct dvb_frontend *fe, u32 *freq);
215 extern int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq);
216 extern int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq);
217
218 #endif