blob: fead4e5f7b520440d181b207be28662cd94a8afb [file] [log] [blame]
Thomas Gleixner74ba9202019-05-20 09:19:02 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Michael Krufky6ca04de2007-11-23 16:52:15 -03002/*
3 tda18271-priv.h - private header for the NXP TDA18271 silicon tuner
4
Michael Krufky59067f72008-01-02 01:58:26 -03005 Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
Michael Krufky6ca04de2007-11-23 16:52:15 -03006
Michael Krufky6ca04de2007-11-23 16:52:15 -03007*/
8
9#ifndef __TDA18271_PRIV_H__
10#define __TDA18271_PRIV_H__
11
Mauro Carvalho Chehab36dba132016-09-05 07:21:18 -030012#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
Michael Krufkyb5f3e1e2007-12-02 16:36:05 -030014#include <linux/kernel.h>
Michael Krufky6ca04de2007-11-23 16:52:15 -030015#include <linux/types.h>
Michael Krufky8d316bf2008-01-06 15:31:35 -030016#include <linux/mutex.h>
Michael Krufkyf9e315a2008-04-22 14:41:54 -030017#include "tuner-i2c.h"
Michael Krufkyd3714212007-12-24 14:38:41 -030018#include "tda18271.h"
Michael Krufky6ca04de2007-11-23 16:52:15 -030019
20#define R_ID 0x00 /* ID byte */
21#define R_TM 0x01 /* Thermo byte */
22#define R_PL 0x02 /* Power level byte */
23#define R_EP1 0x03 /* Easy Prog byte 1 */
24#define R_EP2 0x04 /* Easy Prog byte 2 */
25#define R_EP3 0x05 /* Easy Prog byte 3 */
26#define R_EP4 0x06 /* Easy Prog byte 4 */
27#define R_EP5 0x07 /* Easy Prog byte 5 */
28#define R_CPD 0x08 /* Cal Post-Divider byte */
29#define R_CD1 0x09 /* Cal Divider byte 1 */
30#define R_CD2 0x0a /* Cal Divider byte 2 */
31#define R_CD3 0x0b /* Cal Divider byte 3 */
32#define R_MPD 0x0c /* Main Post-Divider byte */
33#define R_MD1 0x0d /* Main Divider byte 1 */
34#define R_MD2 0x0e /* Main Divider byte 2 */
35#define R_MD3 0x0f /* Main Divider byte 3 */
36#define R_EB1 0x10 /* Extended byte 1 */
37#define R_EB2 0x11 /* Extended byte 2 */
38#define R_EB3 0x12 /* Extended byte 3 */
39#define R_EB4 0x13 /* Extended byte 4 */
40#define R_EB5 0x14 /* Extended byte 5 */
41#define R_EB6 0x15 /* Extended byte 6 */
42#define R_EB7 0x16 /* Extended byte 7 */
43#define R_EB8 0x17 /* Extended byte 8 */
44#define R_EB9 0x18 /* Extended byte 9 */
45#define R_EB10 0x19 /* Extended byte 10 */
46#define R_EB11 0x1a /* Extended byte 11 */
47#define R_EB12 0x1b /* Extended byte 12 */
48#define R_EB13 0x1c /* Extended byte 13 */
49#define R_EB14 0x1d /* Extended byte 14 */
50#define R_EB15 0x1e /* Extended byte 15 */
51#define R_EB16 0x1f /* Extended byte 16 */
52#define R_EB17 0x20 /* Extended byte 17 */
53#define R_EB18 0x21 /* Extended byte 18 */
54#define R_EB19 0x22 /* Extended byte 19 */
55#define R_EB20 0x23 /* Extended byte 20 */
56#define R_EB21 0x24 /* Extended byte 21 */
57#define R_EB22 0x25 /* Extended byte 22 */
58#define R_EB23 0x26 /* Extended byte 23 */
59
60#define TDA18271_NUM_REGS 39
61
Michael Krufkyd3714212007-12-24 14:38:41 -030062/*---------------------------------------------------------------------*/
63
Michael Krufky255b5112008-01-01 22:52:09 -030064struct 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;
Michael Krufky3a6b49fe2009-09-27 23:10:20 -030073 s32 rf_a1;
74 s32 rf_b1;
75 s32 rf_a2;
76 s32 rf_b2;
Michael Krufky255b5112008-01-01 22:52:09 -030077};
78
Michael Krufky4efb0ca2008-04-22 14:46:23 -030079enum tda18271_pll {
80 TDA18271_MAIN_PLL,
81 TDA18271_CAL_PLL,
82};
83
Michael Krufky255b5112008-01-01 22:52:09 -030084struct tda18271_map_layout;
85
86enum tda18271_ver {
87 TDA18271HDC1,
88 TDA18271HDC2,
89};
90
Michael Krufkyd3714212007-12-24 14:38:41 -030091struct tda18271_priv {
Michael Krufkyd3714212007-12-24 14:38:41 -030092 unsigned char tda18271_regs[TDA18271_NUM_REGS];
93
Michael Krufkyf9e315a2008-04-22 14:41:54 -030094 struct list_head hybrid_tuner_instance_list;
95 struct tuner_i2c_props i2c_props;
Michael Krufkya4f263b2008-01-06 15:52:56 -030096
Michael Krufkyd3714212007-12-24 14:38:41 -030097 enum tda18271_mode mode;
Michael Krufky868f5cc2008-04-22 14:46:23 -030098 enum tda18271_role role;
Michael Krufkyd3714212007-12-24 14:38:41 -030099 enum tda18271_i2c_gate gate;
Michael Krufky255b5112008-01-01 22:52:09 -0300100 enum tda18271_ver id;
Michael Krufky4240b462009-08-29 16:25:37 -0300101 enum tda18271_output_options output_opt;
Michael Krufky1724c8f2009-10-23 02:47:49 -0300102 enum tda18271_small_i2c small_i2c;
Michael Krufky255b5112008-01-01 22:52:09 -0300103
Michael Krufkyadcc4b32009-03-04 19:42:06 -0300104 unsigned int config; /* interface to saa713x / tda829x */
Michael Krufky255b5112008-01-01 22:52:09 -0300105 unsigned int cal_initialized:1;
106
Michael Krufky3a6b49fe2009-09-27 23:10:20 -0300107 u8 tm_rfcal;
108
Michael Krufky255b5112008-01-01 22:52:09 -0300109 struct tda18271_map_layout *maps;
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300110 struct tda18271_std_map std;
Michael Krufky255b5112008-01-01 22:52:09 -0300111 struct tda18271_rf_tracking_filter_cal rf_cal_state[8];
112
Michael Krufky8d316bf2008-01-06 15:31:35 -0300113 struct mutex lock;
114
Michael Krufky8c8ee112011-11-03 09:59:42 -0300115 u16 if_freq;
116
Michael Krufkyd3714212007-12-24 14:38:41 -0300117 u32 frequency;
118 u32 bandwidth;
119};
120
121/*---------------------------------------------------------------------*/
122
Michael Krufkyb5f3e1e2007-12-02 16:36:05 -0300123extern int tda18271_debug;
Michael Krufky6ca04de2007-11-23 16:52:15 -0300124
Michael Krufkyb5f3e1e2007-12-02 16:36:05 -0300125#define DBG_INFO 1
126#define DBG_MAP 2
127#define DBG_REG 4
Michael Krufky255b5112008-01-01 22:52:09 -0300128#define DBG_ADV 8
Michael Krufkycf04d292008-01-09 00:34:30 -0300129#define DBG_CAL 16
Michael Krufky6ca04de2007-11-23 16:52:15 -0300130
Joe Perchesbe85fef2011-07-31 01:37:10 -0300131__attribute__((format(printf, 4, 5)))
Joe Perches0f531e72014-09-22 14:50:35 -0300132void _tda_printk(struct tda18271_priv *state, const char *level,
133 const char *func, const char *fmt, ...);
Joe Perchesbe85fef2011-07-31 01:37:10 -0300134
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...) \
139do { \
140 if (tda18271_debug & lvl) \
141 tda_printk(st, KERN_DEBUG, fmt, ##arg); \
Michael Krufkyc0faeee2009-09-28 03:13:49 -0300142} while (0)
Michael Krufky182519f2007-12-25 15:10:11 -0300143
Joe Perchesbe85fef2011-07-31 01:37:10 -0300144#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)
Michael Krufkyb5f3e1e2007-12-02 16:36:05 -0300151
Michael Krufky4bd5d102008-05-04 21:32:21 -0300152#define tda_fail(ret) \
153({ \
154 int __ret; \
155 __ret = (ret < 0); \
156 if (__ret) \
Michael Krufkyc0faeee2009-09-28 03:13:49 -0300157 tda_printk(priv, KERN_ERR, \
158 "error %d on line %d\n", ret, __LINE__); \
Michael Krufky4bd5d102008-05-04 21:32:21 -0300159 __ret; \
160})
161
Michael Krufkyb5f3e1e2007-12-02 16:36:05 -0300162/*---------------------------------------------------------------------*/
163
Michael Krufky2f27dfc2007-12-25 00:39:37 -0300164enum tda18271_map_type {
165 /* tda18271_pll_map */
166 MAIN_PLL,
167 CAL_PLL,
168 /* tda18271_map */
169 RF_CAL,
170 RF_CAL_KMCO,
Michael Krufky255b5112008-01-01 22:52:09 -0300171 RF_CAL_DC_OVER_DT,
Michael Krufky2f27dfc2007-12-25 00:39:37 -0300172 BP_FILTER,
173 RF_BAND,
174 GAIN_TAPER,
175 IR_MEASURE,
176};
Michael Krufkyb5f3e1e2007-12-02 16:36:05 -0300177
Michael Krufky255b5112008-01-01 22:52:09 -0300178extern int tda18271_lookup_pll_map(struct dvb_frontend *fe,
179 enum tda18271_map_type map_type,
Michael Krufky2f27dfc2007-12-25 00:39:37 -0300180 u32 *freq, u8 *post_div, u8 *div);
Michael Krufky255b5112008-01-01 22:52:09 -0300181extern int tda18271_lookup_map(struct dvb_frontend *fe,
182 enum tda18271_map_type map_type,
Michael Krufky2f27dfc2007-12-25 00:39:37 -0300183 u32 *freq, u8 *val);
Michael Krufky6ca04de2007-11-23 16:52:15 -0300184
Michael Krufky255b5112008-01-01 22:52:09 -0300185extern 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
Michael Krufky59067f72008-01-02 01:58:26 -0300196/*---------------------------------------------------------------------*/
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
Michael Krufky4efb0ca2008-04-22 14:46:23 -0300203extern int tda18271_charge_pump_source(struct dvb_frontend *fe,
204 enum tda18271_pll pll, int force);
Michael Krufky518d8732008-01-13 17:01:01 -0300205extern int tda18271_set_standby_mode(struct dvb_frontend *fe,
206 int sm, int sm_lt, int sm_xt);
207
Michael Krufky59067f72008-01-02 01:58:26 -0300208extern 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
Michael Krufky6ca04de2007-11-23 16:52:15 -0300218#endif /* __TDA18271_PRIV_H__ */