Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 1 | /* |
| 2 | tda18271-priv.h - private header for the NXP TDA18271 silicon tuner |
| 3 | |
Michael Krufky | 59067f7 | 2008-01-02 01:58:26 -0300 | [diff] [blame] | 4 | Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org> |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 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 | |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 24 | #include <linux/kernel.h> |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 25 | #include <linux/types.h> |
Michael Krufky | 8d316bf | 2008-01-06 15:31:35 -0300 | [diff] [blame] | 26 | #include <linux/mutex.h> |
Michael Krufky | f9e315a | 2008-04-22 14:41:54 -0300 | [diff] [blame] | 27 | #include "tuner-i2c.h" |
Michael Krufky | d371421 | 2007-12-24 14:38:41 -0300 | [diff] [blame] | 28 | #include "tda18271.h" |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 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 | |
Michael Krufky | d371421 | 2007-12-24 14:38:41 -0300 | [diff] [blame] | 72 | /*---------------------------------------------------------------------*/ |
| 73 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 74 | struct 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; |
Michael Krufky | 3a6b49fe | 2009-09-27 23:10:20 -0300 | [diff] [blame] | 83 | s32 rf_a1; |
| 84 | s32 rf_b1; |
| 85 | s32 rf_a2; |
| 86 | s32 rf_b2; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 87 | }; |
| 88 | |
Michael Krufky | 4efb0ca | 2008-04-22 14:46:23 -0300 | [diff] [blame] | 89 | enum tda18271_pll { |
| 90 | TDA18271_MAIN_PLL, |
| 91 | TDA18271_CAL_PLL, |
| 92 | }; |
| 93 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 94 | struct tda18271_map_layout; |
| 95 | |
| 96 | enum tda18271_ver { |
| 97 | TDA18271HDC1, |
| 98 | TDA18271HDC2, |
| 99 | }; |
| 100 | |
Michael Krufky | d371421 | 2007-12-24 14:38:41 -0300 | [diff] [blame] | 101 | struct tda18271_priv { |
Michael Krufky | d371421 | 2007-12-24 14:38:41 -0300 | [diff] [blame] | 102 | unsigned char tda18271_regs[TDA18271_NUM_REGS]; |
| 103 | |
Michael Krufky | f9e315a | 2008-04-22 14:41:54 -0300 | [diff] [blame] | 104 | struct list_head hybrid_tuner_instance_list; |
| 105 | struct tuner_i2c_props i2c_props; |
Michael Krufky | a4f263b | 2008-01-06 15:52:56 -0300 | [diff] [blame] | 106 | |
Michael Krufky | d371421 | 2007-12-24 14:38:41 -0300 | [diff] [blame] | 107 | enum tda18271_mode mode; |
Michael Krufky | 868f5cc | 2008-04-22 14:46:23 -0300 | [diff] [blame] | 108 | enum tda18271_role role; |
Michael Krufky | d371421 | 2007-12-24 14:38:41 -0300 | [diff] [blame] | 109 | enum tda18271_i2c_gate gate; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 110 | enum tda18271_ver id; |
Michael Krufky | 4240b46 | 2009-08-29 16:25:37 -0300 | [diff] [blame] | 111 | enum tda18271_output_options output_opt; |
Michael Krufky | 1724c8f | 2009-10-23 02:47:49 -0300 | [diff] [blame] | 112 | enum tda18271_small_i2c small_i2c; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 113 | |
Michael Krufky | adcc4b3 | 2009-03-04 19:42:06 -0300 | [diff] [blame] | 114 | unsigned int config; /* interface to saa713x / tda829x */ |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 115 | unsigned int cal_initialized:1; |
| 116 | |
Michael Krufky | 3a6b49fe | 2009-09-27 23:10:20 -0300 | [diff] [blame] | 117 | u8 tm_rfcal; |
| 118 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 119 | struct tda18271_map_layout *maps; |
Michael Krufky | f21e0d7 | 2008-01-02 03:01:54 -0300 | [diff] [blame] | 120 | struct tda18271_std_map std; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 121 | struct tda18271_rf_tracking_filter_cal rf_cal_state[8]; |
| 122 | |
Michael Krufky | 8d316bf | 2008-01-06 15:31:35 -0300 | [diff] [blame] | 123 | struct mutex lock; |
| 124 | |
Michael Krufky | 8c8ee11 | 2011-11-03 09:59:42 -0300 | [diff] [blame] | 125 | u16 if_freq; |
| 126 | |
Michael Krufky | d371421 | 2007-12-24 14:38:41 -0300 | [diff] [blame] | 127 | u32 frequency; |
| 128 | u32 bandwidth; |
| 129 | }; |
| 130 | |
| 131 | /*---------------------------------------------------------------------*/ |
| 132 | |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 133 | extern int tda18271_debug; |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 134 | |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 135 | #define DBG_INFO 1 |
| 136 | #define DBG_MAP 2 |
| 137 | #define DBG_REG 4 |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 138 | #define DBG_ADV 8 |
Michael Krufky | cf04d29 | 2008-01-09 00:34:30 -0300 | [diff] [blame] | 139 | #define DBG_CAL 16 |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 140 | |
Joe Perches | be85fef | 2011-07-31 01:37:10 -0300 | [diff] [blame] | 141 | __attribute__((format(printf, 4, 5))) |
| 142 | int _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...) \ |
| 149 | do { \ |
| 150 | if (tda18271_debug & lvl) \ |
| 151 | tda_printk(st, KERN_DEBUG, fmt, ##arg); \ |
Michael Krufky | c0faeee | 2009-09-28 03:13:49 -0300 | [diff] [blame] | 152 | } while (0) |
Michael Krufky | 182519f | 2007-12-25 15:10:11 -0300 | [diff] [blame] | 153 | |
Joe Perches | be85fef | 2011-07-31 01:37:10 -0300 | [diff] [blame] | 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) |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 161 | |
Michael Krufky | 4bd5d10 | 2008-05-04 21:32:21 -0300 | [diff] [blame] | 162 | #define tda_fail(ret) \ |
| 163 | ({ \ |
| 164 | int __ret; \ |
| 165 | __ret = (ret < 0); \ |
| 166 | if (__ret) \ |
Michael Krufky | c0faeee | 2009-09-28 03:13:49 -0300 | [diff] [blame] | 167 | tda_printk(priv, KERN_ERR, \ |
| 168 | "error %d on line %d\n", ret, __LINE__); \ |
Michael Krufky | 4bd5d10 | 2008-05-04 21:32:21 -0300 | [diff] [blame] | 169 | __ret; \ |
| 170 | }) |
| 171 | |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 172 | /*---------------------------------------------------------------------*/ |
| 173 | |
Michael Krufky | 2f27dfc | 2007-12-25 00:39:37 -0300 | [diff] [blame] | 174 | enum tda18271_map_type { |
| 175 | /* tda18271_pll_map */ |
| 176 | MAIN_PLL, |
| 177 | CAL_PLL, |
| 178 | /* tda18271_map */ |
| 179 | RF_CAL, |
| 180 | RF_CAL_KMCO, |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 181 | RF_CAL_DC_OVER_DT, |
Michael Krufky | 2f27dfc | 2007-12-25 00:39:37 -0300 | [diff] [blame] | 182 | BP_FILTER, |
| 183 | RF_BAND, |
| 184 | GAIN_TAPER, |
| 185 | IR_MEASURE, |
| 186 | }; |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 187 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 188 | extern int tda18271_lookup_pll_map(struct dvb_frontend *fe, |
| 189 | enum tda18271_map_type map_type, |
Michael Krufky | 2f27dfc | 2007-12-25 00:39:37 -0300 | [diff] [blame] | 190 | u32 *freq, u8 *post_div, u8 *div); |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 191 | extern int tda18271_lookup_map(struct dvb_frontend *fe, |
| 192 | enum tda18271_map_type map_type, |
Michael Krufky | 2f27dfc | 2007-12-25 00:39:37 -0300 | [diff] [blame] | 193 | u32 *freq, u8 *val); |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 194 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame] | 195 | extern int tda18271_lookup_thermometer(struct dvb_frontend *fe); |
| 196 | |
| 197 | extern int tda18271_lookup_rf_band(struct dvb_frontend *fe, |
| 198 | u32 *freq, u8 *rf_band); |
| 199 | |
| 200 | extern int tda18271_lookup_cid_target(struct dvb_frontend *fe, |
| 201 | u32 *freq, u8 *cid_target, |
| 202 | u16 *count_limit); |
| 203 | |
| 204 | extern int tda18271_assign_map_layout(struct dvb_frontend *fe); |
| 205 | |
Michael Krufky | 59067f7 | 2008-01-02 01:58:26 -0300 | [diff] [blame] | 206 | /*---------------------------------------------------------------------*/ |
| 207 | |
| 208 | extern int tda18271_read_regs(struct dvb_frontend *fe); |
| 209 | extern int tda18271_read_extended(struct dvb_frontend *fe); |
| 210 | extern int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len); |
| 211 | extern int tda18271_init_regs(struct dvb_frontend *fe); |
| 212 | |
Michael Krufky | 4efb0ca | 2008-04-22 14:46:23 -0300 | [diff] [blame] | 213 | extern int tda18271_charge_pump_source(struct dvb_frontend *fe, |
| 214 | enum tda18271_pll pll, int force); |
Michael Krufky | 518d873 | 2008-01-13 17:01:01 -0300 | [diff] [blame] | 215 | extern int tda18271_set_standby_mode(struct dvb_frontend *fe, |
| 216 | int sm, int sm_lt, int sm_xt); |
| 217 | |
Michael Krufky | 59067f7 | 2008-01-02 01:58:26 -0300 | [diff] [blame] | 218 | extern int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq); |
| 219 | extern int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq); |
| 220 | |
| 221 | extern int tda18271_calc_bp_filter(struct dvb_frontend *fe, u32 *freq); |
| 222 | extern int tda18271_calc_km(struct dvb_frontend *fe, u32 *freq); |
| 223 | extern int tda18271_calc_rf_band(struct dvb_frontend *fe, u32 *freq); |
| 224 | extern int tda18271_calc_gain_taper(struct dvb_frontend *fe, u32 *freq); |
| 225 | extern int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq); |
| 226 | extern int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq); |
| 227 | |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 228 | #endif /* __TDA18271_PRIV_H__ */ |
| 229 | |
| 230 | /* |
| 231 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 232 | * --------------------------------------------------------------------------- |
| 233 | * Local variables: |
| 234 | * c-basic-offset: 8 |
| 235 | * End: |
| 236 | */ |