Commit | Line | Data |
---|---|---|
6ca04de3 MK |
1 | /* |
2 | tda18271-priv.h - private header for the NXP TDA18271 silicon tuner | |
3 | ||
59067f7e | 4 | Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org> |
6ca04de3 MK |
5 | |
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 | */ | |
20 | ||
21 | #ifndef __TDA18271_PRIV_H__ | |
22 | #define __TDA18271_PRIV_H__ | |
23 | ||
36dba13b MCC |
24 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
25 | ||
b5f3e1e1 | 26 | #include <linux/kernel.h> |
6ca04de3 | 27 | #include <linux/types.h> |
8d316bf5 | 28 | #include <linux/mutex.h> |
f9e315a1 | 29 | #include "tuner-i2c.h" |
d3714210 | 30 | #include "tda18271.h" |
6ca04de3 MK |
31 | |
32 | #define R_ID 0x00 /* ID byte */ | |
33 | #define R_TM 0x01 /* Thermo byte */ | |
34 | #define R_PL 0x02 /* Power level byte */ | |
35 | #define R_EP1 0x03 /* Easy Prog byte 1 */ | |
36 | #define R_EP2 0x04 /* Easy Prog byte 2 */ | |
37 | #define R_EP3 0x05 /* Easy Prog byte 3 */ | |
38 | #define R_EP4 0x06 /* Easy Prog byte 4 */ | |
39 | #define R_EP5 0x07 /* Easy Prog byte 5 */ | |
40 | #define R_CPD 0x08 /* Cal Post-Divider byte */ | |
41 | #define R_CD1 0x09 /* Cal Divider byte 1 */ | |
42 | #define R_CD2 0x0a /* Cal Divider byte 2 */ | |
43 | #define R_CD3 0x0b /* Cal Divider byte 3 */ | |
44 | #define R_MPD 0x0c /* Main Post-Divider byte */ | |
45 | #define R_MD1 0x0d /* Main Divider byte 1 */ | |
46 | #define R_MD2 0x0e /* Main Divider byte 2 */ | |
47 | #define R_MD3 0x0f /* Main Divider byte 3 */ | |
48 | #define R_EB1 0x10 /* Extended byte 1 */ | |
49 | #define R_EB2 0x11 /* Extended byte 2 */ | |
50 | #define R_EB3 0x12 /* Extended byte 3 */ | |
51 | #define R_EB4 0x13 /* Extended byte 4 */ | |
52 | #define R_EB5 0x14 /* Extended byte 5 */ | |
53 | #define R_EB6 0x15 /* Extended byte 6 */ | |
54 | #define R_EB7 0x16 /* Extended byte 7 */ | |
55 | #define R_EB8 0x17 /* Extended byte 8 */ | |
56 | #define R_EB9 0x18 /* Extended byte 9 */ | |
57 | #define R_EB10 0x19 /* Extended byte 10 */ | |
58 | #define R_EB11 0x1a /* Extended byte 11 */ | |
59 | #define R_EB12 0x1b /* Extended byte 12 */ | |
60 | #define R_EB13 0x1c /* Extended byte 13 */ | |
61 | #define R_EB14 0x1d /* Extended byte 14 */ | |
62 | #define R_EB15 0x1e /* Extended byte 15 */ | |
63 | #define R_EB16 0x1f /* Extended byte 16 */ | |
64 | #define R_EB17 0x20 /* Extended byte 17 */ | |
65 | #define R_EB18 0x21 /* Extended byte 18 */ | |
66 | #define R_EB19 0x22 /* Extended byte 19 */ | |
67 | #define R_EB20 0x23 /* Extended byte 20 */ | |
68 | #define R_EB21 0x24 /* Extended byte 21 */ | |
69 | #define R_EB22 0x25 /* Extended byte 22 */ | |
70 | #define R_EB23 0x26 /* Extended byte 23 */ | |
71 | ||
72 | #define TDA18271_NUM_REGS 39 | |
73 | ||
d3714210 MK |
74 | /*---------------------------------------------------------------------*/ |
75 | ||
255b5113 MK |
76 | struct 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; | |
3a6b49fe MK |
85 | s32 rf_a1; |
86 | s32 rf_b1; | |
87 | s32 rf_a2; | |
88 | s32 rf_b2; | |
255b5113 MK |
89 | }; |
90 | ||
4efb0ca5 MK |
91 | enum tda18271_pll { |
92 | TDA18271_MAIN_PLL, | |
93 | TDA18271_CAL_PLL, | |
94 | }; | |
95 | ||
255b5113 MK |
96 | struct tda18271_map_layout; |
97 | ||
98 | enum tda18271_ver { | |
99 | TDA18271HDC1, | |
100 | TDA18271HDC2, | |
101 | }; | |
102 | ||
d3714210 | 103 | struct tda18271_priv { |
d3714210 MK |
104 | unsigned char tda18271_regs[TDA18271_NUM_REGS]; |
105 | ||
f9e315a1 MK |
106 | struct list_head hybrid_tuner_instance_list; |
107 | struct tuner_i2c_props i2c_props; | |
a4f263b5 | 108 | |
d3714210 | 109 | enum tda18271_mode mode; |
868f5ccd | 110 | enum tda18271_role role; |
d3714210 | 111 | enum tda18271_i2c_gate gate; |
255b5113 | 112 | enum tda18271_ver id; |
4240b460 | 113 | enum tda18271_output_options output_opt; |
1724c8fa | 114 | enum tda18271_small_i2c small_i2c; |
255b5113 | 115 | |
adcc4b3e | 116 | unsigned int config; /* interface to saa713x / tda829x */ |
255b5113 MK |
117 | unsigned int cal_initialized:1; |
118 | ||
3a6b49fe MK |
119 | u8 tm_rfcal; |
120 | ||
255b5113 | 121 | struct tda18271_map_layout *maps; |
f21e0d7f | 122 | struct tda18271_std_map std; |
255b5113 MK |
123 | struct tda18271_rf_tracking_filter_cal rf_cal_state[8]; |
124 | ||
8d316bf5 MK |
125 | struct mutex lock; |
126 | ||
8c8ee113 MK |
127 | u16 if_freq; |
128 | ||
d3714210 MK |
129 | u32 frequency; |
130 | u32 bandwidth; | |
131 | }; | |
132 | ||
133 | /*---------------------------------------------------------------------*/ | |
134 | ||
b5f3e1e1 MK |
135 | extern int tda18271_debug; |
136 | ||
b5f3e1e1 MK |
137 | #define DBG_INFO 1 |
138 | #define DBG_MAP 2 | |
139 | #define DBG_REG 4 | |
255b5113 | 140 | #define DBG_ADV 8 |
cf04d29c | 141 | #define DBG_CAL 16 |
b5f3e1e1 | 142 | |
be85fefe | 143 | __attribute__((format(printf, 4, 5))) |
0f531e73 JP |
144 | void _tda_printk(struct tda18271_priv *state, const char *level, |
145 | const char *func, const char *fmt, ...); | |
be85fefe JP |
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...) \ | |
151 | do { \ | |
152 | if (tda18271_debug & lvl) \ | |
153 | tda_printk(st, KERN_DEBUG, fmt, ##arg); \ | |
c0faeee5 MK |
154 | } while (0) |
155 | ||
be85fefe JP |
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) | |
b5f3e1e1 | 163 | |
4bd5d107 MK |
164 | #define tda_fail(ret) \ |
165 | ({ \ | |
166 | int __ret; \ | |
167 | __ret = (ret < 0); \ | |
168 | if (__ret) \ | |
c0faeee5 MK |
169 | tda_printk(priv, KERN_ERR, \ |
170 | "error %d on line %d\n", ret, __LINE__); \ | |
4bd5d107 MK |
171 | __ret; \ |
172 | }) | |
173 | ||
b5f3e1e1 MK |
174 | /*---------------------------------------------------------------------*/ |
175 | ||
2f27dfc9 MK |
176 | enum tda18271_map_type { |
177 | /* tda18271_pll_map */ | |
178 | MAIN_PLL, | |
179 | CAL_PLL, | |
180 | /* tda18271_map */ | |
181 | RF_CAL, | |
182 | RF_CAL_KMCO, | |
255b5113 | 183 | RF_CAL_DC_OVER_DT, |
2f27dfc9 MK |
184 | BP_FILTER, |
185 | RF_BAND, | |
186 | GAIN_TAPER, | |
187 | IR_MEASURE, | |
188 | }; | |
189 | ||
255b5113 MK |
190 | extern int tda18271_lookup_pll_map(struct dvb_frontend *fe, |
191 | enum tda18271_map_type map_type, | |
2f27dfc9 | 192 | u32 *freq, u8 *post_div, u8 *div); |
255b5113 MK |
193 | extern int tda18271_lookup_map(struct dvb_frontend *fe, |
194 | enum tda18271_map_type map_type, | |
2f27dfc9 | 195 | u32 *freq, u8 *val); |
6ca04de3 | 196 | |
255b5113 MK |
197 | extern int tda18271_lookup_thermometer(struct dvb_frontend *fe); |
198 | ||
199 | extern int tda18271_lookup_rf_band(struct dvb_frontend *fe, | |
200 | u32 *freq, u8 *rf_band); | |
201 | ||
202 | extern int tda18271_lookup_cid_target(struct dvb_frontend *fe, | |
203 | u32 *freq, u8 *cid_target, | |
204 | u16 *count_limit); | |
205 | ||
206 | extern int tda18271_assign_map_layout(struct dvb_frontend *fe); | |
207 | ||
59067f7e MK |
208 | /*---------------------------------------------------------------------*/ |
209 | ||
210 | extern int tda18271_read_regs(struct dvb_frontend *fe); | |
211 | extern int tda18271_read_extended(struct dvb_frontend *fe); | |
212 | extern int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len); | |
213 | extern int tda18271_init_regs(struct dvb_frontend *fe); | |
214 | ||
4efb0ca5 MK |
215 | extern int tda18271_charge_pump_source(struct dvb_frontend *fe, |
216 | enum tda18271_pll pll, int force); | |
518d8739 MK |
217 | extern int tda18271_set_standby_mode(struct dvb_frontend *fe, |
218 | int sm, int sm_lt, int sm_xt); | |
219 | ||
59067f7e MK |
220 | extern int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq); |
221 | extern int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq); | |
222 | ||
223 | extern int tda18271_calc_bp_filter(struct dvb_frontend *fe, u32 *freq); | |
224 | extern int tda18271_calc_km(struct dvb_frontend *fe, u32 *freq); | |
225 | extern int tda18271_calc_rf_band(struct dvb_frontend *fe, u32 *freq); | |
226 | extern int tda18271_calc_gain_taper(struct dvb_frontend *fe, u32 *freq); | |
227 | extern int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq); | |
228 | extern int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq); | |
229 | ||
6ca04de3 | 230 | #endif /* __TDA18271_PRIV_H__ */ |