V4L/DVB (13110): tda18271: use temporary variables in tda18271_rf_tracking_filters_init
[linux-2.6-block.git] / drivers / media / common / tuners / tda18271-priv.h
CommitLineData
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
b5f3e1e1 24#include <linux/kernel.h>
6ca04de3 25#include <linux/types.h>
8d316bf5 26#include <linux/mutex.h>
f9e315a1 27#include "tuner-i2c.h"
d3714210 28#include "tda18271.h"
6ca04de3
MK
29
30#define R_ID 0x00 /* ID byte */
31#define R_TM 0x01 /* Thermo byte */
32#define R_PL 0x02 /* Power level byte */
33#define R_EP1 0x03 /* Easy Prog byte 1 */
34#define R_EP2 0x04 /* Easy Prog byte 2 */
35#define R_EP3 0x05 /* Easy Prog byte 3 */
36#define R_EP4 0x06 /* Easy Prog byte 4 */
37#define R_EP5 0x07 /* Easy Prog byte 5 */
38#define R_CPD 0x08 /* Cal Post-Divider byte */
39#define R_CD1 0x09 /* Cal Divider byte 1 */
40#define R_CD2 0x0a /* Cal Divider byte 2 */
41#define R_CD3 0x0b /* Cal Divider byte 3 */
42#define R_MPD 0x0c /* Main Post-Divider byte */
43#define R_MD1 0x0d /* Main Divider byte 1 */
44#define R_MD2 0x0e /* Main Divider byte 2 */
45#define R_MD3 0x0f /* Main Divider byte 3 */
46#define R_EB1 0x10 /* Extended byte 1 */
47#define R_EB2 0x11 /* Extended byte 2 */
48#define R_EB3 0x12 /* Extended byte 3 */
49#define R_EB4 0x13 /* Extended byte 4 */
50#define R_EB5 0x14 /* Extended byte 5 */
51#define R_EB6 0x15 /* Extended byte 6 */
52#define R_EB7 0x16 /* Extended byte 7 */
53#define R_EB8 0x17 /* Extended byte 8 */
54#define R_EB9 0x18 /* Extended byte 9 */
55#define R_EB10 0x19 /* Extended byte 10 */
56#define R_EB11 0x1a /* Extended byte 11 */
57#define R_EB12 0x1b /* Extended byte 12 */
58#define R_EB13 0x1c /* Extended byte 13 */
59#define R_EB14 0x1d /* Extended byte 14 */
60#define R_EB15 0x1e /* Extended byte 15 */
61#define R_EB16 0x1f /* Extended byte 16 */
62#define R_EB17 0x20 /* Extended byte 17 */
63#define R_EB18 0x21 /* Extended byte 18 */
64#define R_EB19 0x22 /* Extended byte 19 */
65#define R_EB20 0x23 /* Extended byte 20 */
66#define R_EB21 0x24 /* Extended byte 21 */
67#define R_EB22 0x25 /* Extended byte 22 */
68#define R_EB23 0x26 /* Extended byte 23 */
69
70#define TDA18271_NUM_REGS 39
71
d3714210
MK
72/*---------------------------------------------------------------------*/
73
255b5113
MK
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 int rf_a1;
84 int rf_b1;
85 int rf_a2;
86 int rf_b2;
87};
88
4efb0ca5
MK
89enum tda18271_pll {
90 TDA18271_MAIN_PLL,
91 TDA18271_CAL_PLL,
92};
93
255b5113
MK
94struct tda18271_map_layout;
95
96enum tda18271_ver {
97 TDA18271HDC1,
98 TDA18271HDC2,
99};
100
d3714210 101struct tda18271_priv {
d3714210
MK
102 unsigned char tda18271_regs[TDA18271_NUM_REGS];
103
f9e315a1
MK
104 struct list_head hybrid_tuner_instance_list;
105 struct tuner_i2c_props i2c_props;
a4f263b5 106
d3714210 107 enum tda18271_mode mode;
868f5ccd 108 enum tda18271_role role;
d3714210 109 enum tda18271_i2c_gate gate;
255b5113 110 enum tda18271_ver id;
4240b460 111 enum tda18271_output_options output_opt;
255b5113 112
adcc4b3e 113 unsigned int config; /* interface to saa713x / tda829x */
09f83c4f 114 unsigned int tm_rfcal;
255b5113 115 unsigned int cal_initialized:1;
5555309c 116 unsigned int small_i2c:1;
255b5113 117
255b5113 118 struct tda18271_map_layout *maps;
f21e0d7f 119 struct tda18271_std_map std;
255b5113
MK
120 struct tda18271_rf_tracking_filter_cal rf_cal_state[8];
121
8d316bf5
MK
122 struct mutex lock;
123
d3714210
MK
124 u32 frequency;
125 u32 bandwidth;
126};
127
128/*---------------------------------------------------------------------*/
129
b5f3e1e1
MK
130extern int tda18271_debug;
131
b5f3e1e1
MK
132#define DBG_INFO 1
133#define DBG_MAP 2
134#define DBG_REG 4
255b5113 135#define DBG_ADV 8
cf04d29c 136#define DBG_CAL 16
b5f3e1e1 137
182519f4 138#define tda_printk(kern, fmt, arg...) \
271ddbf7 139 printk(kern "%s: " fmt, __func__, ##arg)
182519f4 140
1b6b7333 141#define tda_dprintk(lvl, fmt, arg...) do {\
182519f4 142 if (tda18271_debug & lvl) \
1b6b7333 143 tda_printk(KERN_DEBUG, fmt, ##arg); } while (0)
182519f4 144
ee8145d5
MK
145#define tda_info(fmt, arg...) printk(KERN_INFO fmt, ##arg)
146#define tda_warn(fmt, arg...) tda_printk(KERN_WARNING, fmt, ##arg)
147#define tda_err(fmt, arg...) tda_printk(KERN_ERR, fmt, ##arg)
148#define tda_dbg(fmt, arg...) tda_dprintk(DBG_INFO, fmt, ##arg)
149#define tda_map(fmt, arg...) tda_dprintk(DBG_MAP, fmt, ##arg)
150#define tda_reg(fmt, arg...) tda_dprintk(DBG_REG, fmt, ##arg)
151#define tda_cal(fmt, arg...) tda_dprintk(DBG_CAL, fmt, ##arg)
b5f3e1e1 152
4bd5d107
MK
153#define tda_fail(ret) \
154({ \
155 int __ret; \
156 __ret = (ret < 0); \
157 if (__ret) \
158 tda_printk(KERN_ERR, "error %d on line %d\n", ret, __LINE__);\
159 __ret; \
160})
161
b5f3e1e1
MK
162/*---------------------------------------------------------------------*/
163
2f27dfc9
MK
164enum tda18271_map_type {
165 /* tda18271_pll_map */
166 MAIN_PLL,
167 CAL_PLL,
168 /* tda18271_map */
169 RF_CAL,
170 RF_CAL_KMCO,
255b5113 171 RF_CAL_DC_OVER_DT,
2f27dfc9
MK
172 BP_FILTER,
173 RF_BAND,
174 GAIN_TAPER,
175 IR_MEASURE,
176};
177
255b5113
MK
178extern int tda18271_lookup_pll_map(struct dvb_frontend *fe,
179 enum tda18271_map_type map_type,
2f27dfc9 180 u32 *freq, u8 *post_div, u8 *div);
255b5113
MK
181extern int tda18271_lookup_map(struct dvb_frontend *fe,
182 enum tda18271_map_type map_type,
2f27dfc9 183 u32 *freq, u8 *val);
6ca04de3 184
255b5113
MK
185extern int tda18271_lookup_thermometer(struct dvb_frontend *fe);
186
187extern int tda18271_lookup_rf_band(struct dvb_frontend *fe,
188 u32 *freq, u8 *rf_band);
189
190extern int tda18271_lookup_cid_target(struct dvb_frontend *fe,
191 u32 *freq, u8 *cid_target,
192 u16 *count_limit);
193
194extern int tda18271_assign_map_layout(struct dvb_frontend *fe);
195
59067f7e
MK
196/*---------------------------------------------------------------------*/
197
198extern int tda18271_read_regs(struct dvb_frontend *fe);
199extern int tda18271_read_extended(struct dvb_frontend *fe);
200extern int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len);
201extern int tda18271_init_regs(struct dvb_frontend *fe);
202
4efb0ca5
MK
203extern int tda18271_charge_pump_source(struct dvb_frontend *fe,
204 enum tda18271_pll pll, int force);
518d8739
MK
205extern int tda18271_set_standby_mode(struct dvb_frontend *fe,
206 int sm, int sm_lt, int sm_xt);
207
59067f7e
MK
208extern int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq);
209extern int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq);
210
211extern int tda18271_calc_bp_filter(struct dvb_frontend *fe, u32 *freq);
212extern int tda18271_calc_km(struct dvb_frontend *fe, u32 *freq);
213extern int tda18271_calc_rf_band(struct dvb_frontend *fe, u32 *freq);
214extern int tda18271_calc_gain_taper(struct dvb_frontend *fe, u32 *freq);
215extern int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq);
216extern int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq);
217
6ca04de3
MK
218#endif /* __TDA18271_PRIV_H__ */
219
220/*
221 * Overrides for Emacs so that we follow Linus's tabbing style.
222 * ---------------------------------------------------------------------------
223 * Local variables:
224 * c-basic-offset: 8
225 * End:
226 */