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