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