Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1 | /* |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 2 | tda18271-fe.c - driver for the Philips / NXP TDA18271 silicon tuner |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 3 | |
| 4 | Copyright (C) 2007 Michael Krufky (mkrufky@linuxtv.org) |
| 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 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 21 | #include <linux/delay.h> |
| 22 | #include <linux/videodev2.h> |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 23 | #include "tda18271-priv.h" |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 24 | |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 25 | int tda18271_debug; |
Michael Krufky | 54465b0 | 2007-11-23 18:14:53 -0300 | [diff] [blame] | 26 | module_param_named(debug, tda18271_debug, int, 0644); |
Michael Krufky | 293da0e | 2007-12-02 02:45:04 -0300 | [diff] [blame] | 27 | MODULE_PARM_DESC(debug, "set debug level (info=1, map=2, reg=4 (or-able))"); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 28 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 29 | /*---------------------------------------------------------------------*/ |
| 30 | |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 31 | static int tda18271_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
| 32 | { |
| 33 | struct tda18271_priv *priv = fe->tuner_priv; |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 34 | enum tda18271_i2c_gate gate; |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 35 | int ret = 0; |
| 36 | |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 37 | switch (priv->gate) { |
| 38 | case TDA18271_GATE_DIGITAL: |
| 39 | case TDA18271_GATE_ANALOG: |
| 40 | gate = priv->gate; |
| 41 | break; |
| 42 | case TDA18271_GATE_AUTO: |
| 43 | default: |
| 44 | switch (priv->mode) { |
| 45 | case TDA18271_DIGITAL: |
| 46 | gate = TDA18271_GATE_DIGITAL; |
| 47 | break; |
| 48 | case TDA18271_ANALOG: |
| 49 | default: |
| 50 | gate = TDA18271_GATE_ANALOG; |
| 51 | break; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | switch (gate) { |
| 56 | case TDA18271_GATE_ANALOG: |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 57 | if (fe->ops.analog_ops.i2c_gate_ctrl) |
| 58 | ret = fe->ops.analog_ops.i2c_gate_ctrl(fe, enable); |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 59 | break; |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 60 | case TDA18271_GATE_DIGITAL: |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 61 | if (fe->ops.i2c_gate_ctrl) |
| 62 | ret = fe->ops.i2c_gate_ctrl(fe, enable); |
| 63 | break; |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 64 | default: |
| 65 | ret = -EINVAL; |
| 66 | break; |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | return ret; |
| 70 | }; |
| 71 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 72 | /*---------------------------------------------------------------------*/ |
| 73 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 74 | static void tda18271_dump_regs(struct dvb_frontend *fe, int extended) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 75 | { |
| 76 | struct tda18271_priv *priv = fe->tuner_priv; |
| 77 | unsigned char *regs = priv->tda18271_regs; |
| 78 | |
Michael Krufky | 182519f | 2007-12-25 15:10:11 -0300 | [diff] [blame] | 79 | tda_reg("=== TDA18271 REG DUMP ===\n"); |
| 80 | tda_reg("ID_BYTE = 0x%02x\n", 0xff & regs[R_ID]); |
| 81 | tda_reg("THERMO_BYTE = 0x%02x\n", 0xff & regs[R_TM]); |
| 82 | tda_reg("POWER_LEVEL_BYTE = 0x%02x\n", 0xff & regs[R_PL]); |
| 83 | tda_reg("EASY_PROG_BYTE_1 = 0x%02x\n", 0xff & regs[R_EP1]); |
| 84 | tda_reg("EASY_PROG_BYTE_2 = 0x%02x\n", 0xff & regs[R_EP2]); |
| 85 | tda_reg("EASY_PROG_BYTE_3 = 0x%02x\n", 0xff & regs[R_EP3]); |
| 86 | tda_reg("EASY_PROG_BYTE_4 = 0x%02x\n", 0xff & regs[R_EP4]); |
| 87 | tda_reg("EASY_PROG_BYTE_5 = 0x%02x\n", 0xff & regs[R_EP5]); |
| 88 | tda_reg("CAL_POST_DIV_BYTE = 0x%02x\n", 0xff & regs[R_CPD]); |
| 89 | tda_reg("CAL_DIV_BYTE_1 = 0x%02x\n", 0xff & regs[R_CD1]); |
| 90 | tda_reg("CAL_DIV_BYTE_2 = 0x%02x\n", 0xff & regs[R_CD2]); |
| 91 | tda_reg("CAL_DIV_BYTE_3 = 0x%02x\n", 0xff & regs[R_CD3]); |
| 92 | tda_reg("MAIN_POST_DIV_BYTE = 0x%02x\n", 0xff & regs[R_MPD]); |
| 93 | tda_reg("MAIN_DIV_BYTE_1 = 0x%02x\n", 0xff & regs[R_MD1]); |
| 94 | tda_reg("MAIN_DIV_BYTE_2 = 0x%02x\n", 0xff & regs[R_MD2]); |
| 95 | tda_reg("MAIN_DIV_BYTE_3 = 0x%02x\n", 0xff & regs[R_MD3]); |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 96 | |
| 97 | /* only dump extended regs if DBG_ADV is set */ |
| 98 | if (!(tda18271_debug & DBG_ADV)) |
| 99 | return; |
| 100 | |
| 101 | /* W indicates write-only registers. |
| 102 | * Register dump for write-only registers shows last value written. */ |
| 103 | |
| 104 | tda_reg("EXTENDED_BYTE_1 = 0x%02x\n", 0xff & regs[R_EB1]); |
| 105 | tda_reg("EXTENDED_BYTE_2 = 0x%02x\n", 0xff & regs[R_EB2]); |
| 106 | tda_reg("EXTENDED_BYTE_3 = 0x%02x\n", 0xff & regs[R_EB3]); |
| 107 | tda_reg("EXTENDED_BYTE_4 = 0x%02x\n", 0xff & regs[R_EB4]); |
| 108 | tda_reg("EXTENDED_BYTE_5 = 0x%02x\n", 0xff & regs[R_EB5]); |
| 109 | tda_reg("EXTENDED_BYTE_6 = 0x%02x\n", 0xff & regs[R_EB6]); |
| 110 | tda_reg("EXTENDED_BYTE_7 = 0x%02x\n", 0xff & regs[R_EB7]); |
| 111 | tda_reg("EXTENDED_BYTE_8 = 0x%02x\n", 0xff & regs[R_EB8]); |
| 112 | tda_reg("EXTENDED_BYTE_9 W = 0x%02x\n", 0xff & regs[R_EB9]); |
| 113 | tda_reg("EXTENDED_BYTE_10 = 0x%02x\n", 0xff & regs[R_EB10]); |
| 114 | tda_reg("EXTENDED_BYTE_11 = 0x%02x\n", 0xff & regs[R_EB11]); |
| 115 | tda_reg("EXTENDED_BYTE_12 = 0x%02x\n", 0xff & regs[R_EB12]); |
| 116 | tda_reg("EXTENDED_BYTE_13 = 0x%02x\n", 0xff & regs[R_EB13]); |
| 117 | tda_reg("EXTENDED_BYTE_14 = 0x%02x\n", 0xff & regs[R_EB14]); |
| 118 | tda_reg("EXTENDED_BYTE_15 = 0x%02x\n", 0xff & regs[R_EB15]); |
| 119 | tda_reg("EXTENDED_BYTE_16 W = 0x%02x\n", 0xff & regs[R_EB16]); |
| 120 | tda_reg("EXTENDED_BYTE_17 W = 0x%02x\n", 0xff & regs[R_EB17]); |
| 121 | tda_reg("EXTENDED_BYTE_18 = 0x%02x\n", 0xff & regs[R_EB18]); |
| 122 | tda_reg("EXTENDED_BYTE_19 W = 0x%02x\n", 0xff & regs[R_EB19]); |
| 123 | tda_reg("EXTENDED_BYTE_20 W = 0x%02x\n", 0xff & regs[R_EB20]); |
| 124 | tda_reg("EXTENDED_BYTE_21 = 0x%02x\n", 0xff & regs[R_EB21]); |
| 125 | tda_reg("EXTENDED_BYTE_22 = 0x%02x\n", 0xff & regs[R_EB22]); |
| 126 | tda_reg("EXTENDED_BYTE_23 = 0x%02x\n", 0xff & regs[R_EB23]); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static void tda18271_read_regs(struct dvb_frontend *fe) |
| 130 | { |
| 131 | struct tda18271_priv *priv = fe->tuner_priv; |
| 132 | unsigned char *regs = priv->tda18271_regs; |
| 133 | unsigned char buf = 0x00; |
| 134 | int ret; |
| 135 | struct i2c_msg msg[] = { |
| 136 | { .addr = priv->i2c_addr, .flags = 0, |
| 137 | .buf = &buf, .len = 1 }, |
| 138 | { .addr = priv->i2c_addr, .flags = I2C_M_RD, |
| 139 | .buf = regs, .len = 16 } |
| 140 | }; |
| 141 | |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 142 | tda18271_i2c_gate_ctrl(fe, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 143 | |
| 144 | /* read all registers */ |
| 145 | ret = i2c_transfer(priv->i2c_adap, msg, 2); |
| 146 | |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 147 | tda18271_i2c_gate_ctrl(fe, 0); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 148 | |
| 149 | if (ret != 2) |
Michael Krufky | 182519f | 2007-12-25 15:10:11 -0300 | [diff] [blame] | 150 | tda_err("ERROR: i2c_transfer returned: %d\n", ret); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 151 | |
Michael Krufky | 293da0e | 2007-12-02 02:45:04 -0300 | [diff] [blame] | 152 | if (tda18271_debug & DBG_REG) |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 153 | tda18271_dump_regs(fe, 0); |
| 154 | } |
| 155 | |
| 156 | static void tda18271_read_extended(struct dvb_frontend *fe) |
| 157 | { |
| 158 | struct tda18271_priv *priv = fe->tuner_priv; |
| 159 | unsigned char *regs = priv->tda18271_regs; |
| 160 | unsigned char regdump[TDA18271_NUM_REGS]; |
| 161 | unsigned char buf = 0x00; |
| 162 | int ret, i; |
| 163 | struct i2c_msg msg[] = { |
| 164 | { .addr = priv->i2c_addr, .flags = 0, |
| 165 | .buf = &buf, .len = 1 }, |
| 166 | { .addr = priv->i2c_addr, .flags = I2C_M_RD, |
| 167 | .buf = regdump, .len = TDA18271_NUM_REGS } |
| 168 | }; |
| 169 | |
| 170 | tda18271_i2c_gate_ctrl(fe, 1); |
| 171 | |
| 172 | /* read all registers */ |
| 173 | ret = i2c_transfer(priv->i2c_adap, msg, 2); |
| 174 | |
| 175 | tda18271_i2c_gate_ctrl(fe, 0); |
| 176 | |
| 177 | if (ret != 2) |
| 178 | tda_err("ERROR: i2c_transfer returned: %d\n", ret); |
| 179 | |
| 180 | for (i = 0; i <= TDA18271_NUM_REGS; i++) { |
| 181 | /* don't update write-only registers */ |
| 182 | if ((i != R_EB9) && |
| 183 | (i != R_EB16) && |
| 184 | (i != R_EB17) && |
| 185 | (i != R_EB19) && |
| 186 | (i != R_EB20)) |
| 187 | regs[i] = regdump[i]; |
| 188 | } |
| 189 | |
| 190 | if (tda18271_debug & DBG_REG) |
| 191 | tda18271_dump_regs(fe, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static void tda18271_write_regs(struct dvb_frontend *fe, int idx, int len) |
| 195 | { |
| 196 | struct tda18271_priv *priv = fe->tuner_priv; |
| 197 | unsigned char *regs = priv->tda18271_regs; |
| 198 | unsigned char buf[TDA18271_NUM_REGS+1]; |
| 199 | struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0, |
| 200 | .buf = buf, .len = len+1 }; |
| 201 | int i, ret; |
| 202 | |
| 203 | BUG_ON((len == 0) || (idx+len > sizeof(buf))); |
| 204 | |
| 205 | buf[0] = idx; |
| 206 | for (i = 1; i <= len; i++) { |
| 207 | buf[i] = regs[idx-1+i]; |
| 208 | } |
| 209 | |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 210 | tda18271_i2c_gate_ctrl(fe, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 211 | |
| 212 | /* write registers */ |
| 213 | ret = i2c_transfer(priv->i2c_adap, &msg, 1); |
| 214 | |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 215 | tda18271_i2c_gate_ctrl(fe, 0); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 216 | |
| 217 | if (ret != 1) |
Michael Krufky | 182519f | 2007-12-25 15:10:11 -0300 | [diff] [blame] | 218 | tda_err("ERROR: i2c_transfer returned: %d\n", ret); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /*---------------------------------------------------------------------*/ |
| 222 | |
Michael Krufky | 22ee125 | 2007-11-22 17:13:00 -0300 | [diff] [blame] | 223 | static int tda18271_init_regs(struct dvb_frontend *fe) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 224 | { |
| 225 | struct tda18271_priv *priv = fe->tuner_priv; |
| 226 | unsigned char *regs = priv->tda18271_regs; |
| 227 | |
Michael Krufky | 182519f | 2007-12-25 15:10:11 -0300 | [diff] [blame] | 228 | tda_dbg("initializing registers for device @ %d-%04x\n", |
| 229 | i2c_adapter_id(priv->i2c_adap), priv->i2c_addr); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 230 | |
| 231 | /* initialize registers */ |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 232 | switch (priv->id) { |
| 233 | case TDA18271HDC1: |
| 234 | regs[R_ID] = 0x83; |
| 235 | break; |
| 236 | case TDA18271HDC2: |
| 237 | regs[R_ID] = 0x84; |
| 238 | break; |
| 239 | }; |
| 240 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 241 | regs[R_TM] = 0x08; |
| 242 | regs[R_PL] = 0x80; |
| 243 | regs[R_EP1] = 0xc6; |
| 244 | regs[R_EP2] = 0xdf; |
| 245 | regs[R_EP3] = 0x16; |
| 246 | regs[R_EP4] = 0x60; |
| 247 | regs[R_EP5] = 0x80; |
| 248 | regs[R_CPD] = 0x80; |
| 249 | regs[R_CD1] = 0x00; |
| 250 | regs[R_CD2] = 0x00; |
| 251 | regs[R_CD3] = 0x00; |
| 252 | regs[R_MPD] = 0x00; |
| 253 | regs[R_MD1] = 0x00; |
| 254 | regs[R_MD2] = 0x00; |
| 255 | regs[R_MD3] = 0x00; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 256 | |
| 257 | switch (priv->id) { |
| 258 | case TDA18271HDC1: |
| 259 | regs[R_EB1] = 0xff; |
| 260 | break; |
| 261 | case TDA18271HDC2: |
| 262 | regs[R_EB1] = 0xfc; |
| 263 | break; |
| 264 | }; |
| 265 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 266 | regs[R_EB2] = 0x01; |
| 267 | regs[R_EB3] = 0x84; |
| 268 | regs[R_EB4] = 0x41; |
| 269 | regs[R_EB5] = 0x01; |
| 270 | regs[R_EB6] = 0x84; |
| 271 | regs[R_EB7] = 0x40; |
| 272 | regs[R_EB8] = 0x07; |
| 273 | regs[R_EB9] = 0x00; |
| 274 | regs[R_EB10] = 0x00; |
| 275 | regs[R_EB11] = 0x96; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 276 | |
| 277 | switch (priv->id) { |
| 278 | case TDA18271HDC1: |
| 279 | regs[R_EB12] = 0x0f; |
| 280 | break; |
| 281 | case TDA18271HDC2: |
| 282 | regs[R_EB12] = 0x33; |
| 283 | break; |
| 284 | }; |
| 285 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 286 | regs[R_EB13] = 0xc1; |
| 287 | regs[R_EB14] = 0x00; |
| 288 | regs[R_EB15] = 0x8f; |
| 289 | regs[R_EB16] = 0x00; |
| 290 | regs[R_EB17] = 0x00; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 291 | |
| 292 | switch (priv->id) { |
| 293 | case TDA18271HDC1: |
| 294 | regs[R_EB18] = 0x00; |
| 295 | break; |
| 296 | case TDA18271HDC2: |
| 297 | regs[R_EB18] = 0x8c; |
| 298 | break; |
| 299 | }; |
| 300 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 301 | regs[R_EB19] = 0x00; |
| 302 | regs[R_EB20] = 0x20; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 303 | |
| 304 | switch (priv->id) { |
| 305 | case TDA18271HDC1: |
| 306 | regs[R_EB21] = 0x33; |
| 307 | break; |
| 308 | case TDA18271HDC2: |
| 309 | regs[R_EB21] = 0xb3; |
| 310 | break; |
| 311 | }; |
| 312 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 313 | regs[R_EB22] = 0x48; |
| 314 | regs[R_EB23] = 0xb0; |
| 315 | |
| 316 | tda18271_write_regs(fe, 0x00, TDA18271_NUM_REGS); |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 317 | |
| 318 | /* setup agc1 gain */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 319 | regs[R_EB17] = 0x00; |
| 320 | tda18271_write_regs(fe, R_EB17, 1); |
| 321 | regs[R_EB17] = 0x03; |
| 322 | tda18271_write_regs(fe, R_EB17, 1); |
| 323 | regs[R_EB17] = 0x43; |
| 324 | tda18271_write_regs(fe, R_EB17, 1); |
| 325 | regs[R_EB17] = 0x4c; |
| 326 | tda18271_write_regs(fe, R_EB17, 1); |
| 327 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 328 | /* setup agc2 gain */ |
| 329 | if ((priv->id) == TDA18271HDC1) { |
| 330 | regs[R_EB20] = 0xa0; |
| 331 | tda18271_write_regs(fe, R_EB20, 1); |
| 332 | regs[R_EB20] = 0xa7; |
| 333 | tda18271_write_regs(fe, R_EB20, 1); |
| 334 | regs[R_EB20] = 0xe7; |
| 335 | tda18271_write_regs(fe, R_EB20, 1); |
| 336 | regs[R_EB20] = 0xec; |
| 337 | tda18271_write_regs(fe, R_EB20, 1); |
| 338 | } |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 339 | |
| 340 | /* image rejection calibration */ |
| 341 | |
| 342 | /* low-band */ |
| 343 | regs[R_EP3] = 0x1f; |
| 344 | regs[R_EP4] = 0x66; |
| 345 | regs[R_EP5] = 0x81; |
| 346 | regs[R_CPD] = 0xcc; |
| 347 | regs[R_CD1] = 0x6c; |
| 348 | regs[R_CD2] = 0x00; |
| 349 | regs[R_CD3] = 0x00; |
| 350 | regs[R_MPD] = 0xcd; |
| 351 | regs[R_MD1] = 0x77; |
| 352 | regs[R_MD2] = 0x08; |
| 353 | regs[R_MD3] = 0x00; |
| 354 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 355 | switch (priv->id) { |
| 356 | case TDA18271HDC1: |
| 357 | tda18271_write_regs(fe, R_EP3, 11); |
| 358 | break; |
| 359 | case TDA18271HDC2: |
| 360 | tda18271_write_regs(fe, R_EP3, 12); |
| 361 | break; |
| 362 | }; |
| 363 | |
| 364 | if ((priv->id) == TDA18271HDC2) { |
| 365 | /* main pll cp source on */ |
| 366 | regs[R_EB4] = 0x61; |
| 367 | tda18271_write_regs(fe, R_EB4, 1); |
| 368 | msleep(1); |
| 369 | |
| 370 | /* main pll cp source off */ |
| 371 | regs[R_EB4] = 0x41; |
| 372 | tda18271_write_regs(fe, R_EB4, 1); |
| 373 | } |
| 374 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 375 | msleep(5); /* pll locking */ |
| 376 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 377 | /* launch detector */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 378 | tda18271_write_regs(fe, R_EP1, 1); |
| 379 | msleep(5); /* wanted low measurement */ |
| 380 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 381 | regs[R_EP5] = 0x85; |
| 382 | regs[R_CPD] = 0xcb; |
| 383 | regs[R_CD1] = 0x66; |
| 384 | regs[R_CD2] = 0x70; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 385 | |
| 386 | tda18271_write_regs(fe, R_EP3, 7); |
| 387 | msleep(5); /* pll locking */ |
| 388 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 389 | /* launch optimization algorithm */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 390 | tda18271_write_regs(fe, R_EP2, 1); |
| 391 | msleep(30); /* image low optimization completion */ |
| 392 | |
| 393 | /* mid-band */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 394 | regs[R_EP5] = 0x82; |
| 395 | regs[R_CPD] = 0xa8; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 396 | regs[R_CD2] = 0x00; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 397 | regs[R_MPD] = 0xa9; |
| 398 | regs[R_MD1] = 0x73; |
| 399 | regs[R_MD2] = 0x1a; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 400 | |
| 401 | tda18271_write_regs(fe, R_EP3, 11); |
| 402 | msleep(5); /* pll locking */ |
| 403 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 404 | tda18271_write_regs(fe, R_EP1, 1); |
| 405 | msleep(5); /* wanted mid measurement */ |
| 406 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 407 | regs[R_EP5] = 0x86; |
| 408 | regs[R_CPD] = 0xa8; |
| 409 | regs[R_CD1] = 0x66; |
| 410 | regs[R_CD2] = 0xa0; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 411 | |
| 412 | tda18271_write_regs(fe, R_EP3, 7); |
| 413 | msleep(5); /* pll locking */ |
| 414 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 415 | /* launch optimization algorithm */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 416 | tda18271_write_regs(fe, R_EP2, 1); |
| 417 | msleep(30); /* image mid optimization completion */ |
| 418 | |
| 419 | /* high-band */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 420 | regs[R_EP5] = 0x83; |
| 421 | regs[R_CPD] = 0x98; |
| 422 | regs[R_CD1] = 0x65; |
| 423 | regs[R_CD2] = 0x00; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 424 | regs[R_MPD] = 0x99; |
| 425 | regs[R_MD1] = 0x71; |
| 426 | regs[R_MD2] = 0xcd; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 427 | |
| 428 | tda18271_write_regs(fe, R_EP3, 11); |
| 429 | msleep(5); /* pll locking */ |
| 430 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 431 | /* launch detector */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 432 | tda18271_write_regs(fe, R_EP1, 1); |
| 433 | msleep(5); /* wanted high measurement */ |
| 434 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 435 | regs[R_EP5] = 0x87; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 436 | regs[R_CD1] = 0x65; |
| 437 | regs[R_CD2] = 0x50; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 438 | |
| 439 | tda18271_write_regs(fe, R_EP3, 7); |
| 440 | msleep(5); /* pll locking */ |
| 441 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 442 | /* launch optimization algorithm */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 443 | tda18271_write_regs(fe, R_EP2, 1); |
| 444 | msleep(30); /* image high optimization completion */ |
| 445 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 446 | /* return to normal mode */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 447 | regs[R_EP4] = 0x64; |
| 448 | tda18271_write_regs(fe, R_EP4, 1); |
| 449 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 450 | /* synchronize */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 451 | tda18271_write_regs(fe, R_EP1, 1); |
Michael Krufky | 22ee125 | 2007-11-22 17:13:00 -0300 | [diff] [blame] | 452 | |
| 453 | return 0; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 454 | } |
| 455 | |
Michael Krufky | efce841 | 2007-12-01 17:40:16 -0300 | [diff] [blame] | 456 | static int tda18271_init(struct dvb_frontend *fe) |
| 457 | { |
| 458 | struct tda18271_priv *priv = fe->tuner_priv; |
| 459 | unsigned char *regs = priv->tda18271_regs; |
| 460 | |
| 461 | tda18271_read_regs(fe); |
| 462 | |
| 463 | /* test IR_CAL_OK to see if we need init */ |
| 464 | if ((regs[R_EP1] & 0x08) == 0) |
| 465 | tda18271_init_regs(fe); |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame] | 470 | static int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq) |
| 471 | { |
| 472 | /* Sets Main Post-Divider & Divider bytes, but does not write them */ |
| 473 | struct tda18271_priv *priv = fe->tuner_priv; |
| 474 | unsigned char *regs = priv->tda18271_regs; |
| 475 | u8 d, pd; |
| 476 | u32 div; |
| 477 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 478 | int ret = tda18271_lookup_pll_map(fe, MAIN_PLL, &freq, &pd, &d); |
Michael Krufky | 2f27dfc | 2007-12-25 00:39:37 -0300 | [diff] [blame] | 479 | if (ret < 0) |
| 480 | goto fail; |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame] | 481 | |
| 482 | regs[R_MPD] = (0x77 & pd); |
| 483 | |
| 484 | switch (priv->mode) { |
| 485 | case TDA18271_ANALOG: |
| 486 | regs[R_MPD] &= ~0x08; |
| 487 | break; |
| 488 | case TDA18271_DIGITAL: |
| 489 | regs[R_MPD] |= 0x08; |
| 490 | break; |
| 491 | } |
| 492 | |
| 493 | div = ((d * (freq / 1000)) << 7) / 125; |
| 494 | |
| 495 | regs[R_MD1] = 0x7f & (div >> 16); |
| 496 | regs[R_MD2] = 0xff & (div >> 8); |
| 497 | regs[R_MD3] = 0xff & div; |
Michael Krufky | 2f27dfc | 2007-12-25 00:39:37 -0300 | [diff] [blame] | 498 | fail: |
| 499 | return ret; |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq) |
| 503 | { |
| 504 | /* Sets Cal Post-Divider & Divider bytes, but does not write them */ |
| 505 | struct tda18271_priv *priv = fe->tuner_priv; |
| 506 | unsigned char *regs = priv->tda18271_regs; |
| 507 | u8 d, pd; |
| 508 | u32 div; |
| 509 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 510 | int ret = tda18271_lookup_pll_map(fe, CAL_PLL, &freq, &pd, &d); |
Michael Krufky | 2f27dfc | 2007-12-25 00:39:37 -0300 | [diff] [blame] | 511 | if (ret < 0) |
| 512 | goto fail; |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame] | 513 | |
| 514 | regs[R_CPD] = pd; |
| 515 | |
| 516 | div = ((d * (freq / 1000)) << 7) / 125; |
| 517 | |
| 518 | regs[R_CD1] = 0x7f & (div >> 16); |
| 519 | regs[R_CD2] = 0xff & (div >> 8); |
| 520 | regs[R_CD3] = 0xff & div; |
Michael Krufky | 2f27dfc | 2007-12-25 00:39:37 -0300 | [diff] [blame] | 521 | fail: |
| 522 | return ret; |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame] | 523 | } |
| 524 | |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 525 | static int tda18271_calc_bp_filter(struct dvb_frontend *fe, u32 *freq) |
| 526 | { |
| 527 | /* Sets BP filter bits, but does not write them */ |
| 528 | struct tda18271_priv *priv = fe->tuner_priv; |
| 529 | unsigned char *regs = priv->tda18271_regs; |
| 530 | u8 val; |
| 531 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 532 | int ret = tda18271_lookup_map(fe, BP_FILTER, freq, &val); |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 533 | if (ret < 0) |
| 534 | goto fail; |
| 535 | |
| 536 | regs[R_EP1] &= ~0x07; /* clear bp filter bits */ |
| 537 | regs[R_EP1] |= (0x07 & val); |
| 538 | fail: |
| 539 | return ret; |
| 540 | } |
| 541 | |
| 542 | static int tda18271_calc_km(struct dvb_frontend *fe, u32 *freq) |
| 543 | { |
| 544 | /* Sets K & M bits, but does not write them */ |
| 545 | struct tda18271_priv *priv = fe->tuner_priv; |
| 546 | unsigned char *regs = priv->tda18271_regs; |
| 547 | u8 val; |
| 548 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 549 | int ret = tda18271_lookup_map(fe, RF_CAL_KMCO, freq, &val); |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 550 | if (ret < 0) |
| 551 | goto fail; |
| 552 | |
| 553 | regs[R_EB13] &= ~0x7c; /* clear k & m bits */ |
| 554 | regs[R_EB13] |= (0x7c & val); |
| 555 | fail: |
| 556 | return ret; |
| 557 | } |
| 558 | |
| 559 | static int tda18271_calc_rf_band(struct dvb_frontend *fe, u32 *freq) |
| 560 | { |
| 561 | /* Sets RF Band bits, but does not write them */ |
| 562 | struct tda18271_priv *priv = fe->tuner_priv; |
| 563 | unsigned char *regs = priv->tda18271_regs; |
| 564 | u8 val; |
| 565 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 566 | int ret = tda18271_lookup_map(fe, RF_BAND, freq, &val); |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 567 | if (ret < 0) |
| 568 | goto fail; |
| 569 | |
| 570 | regs[R_EP2] &= ~0xe0; /* clear rf band bits */ |
| 571 | regs[R_EP2] |= (0xe0 & (val << 5)); |
| 572 | fail: |
| 573 | return ret; |
| 574 | } |
| 575 | |
| 576 | static int tda18271_calc_gain_taper(struct dvb_frontend *fe, u32 *freq) |
| 577 | { |
| 578 | /* Sets Gain Taper bits, but does not write them */ |
| 579 | struct tda18271_priv *priv = fe->tuner_priv; |
| 580 | unsigned char *regs = priv->tda18271_regs; |
| 581 | u8 val; |
| 582 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 583 | int ret = tda18271_lookup_map(fe, GAIN_TAPER, freq, &val); |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 584 | if (ret < 0) |
| 585 | goto fail; |
| 586 | |
| 587 | regs[R_EP2] &= ~0x1f; /* clear gain taper bits */ |
| 588 | regs[R_EP2] |= (0x1f & val); |
| 589 | fail: |
| 590 | return ret; |
| 591 | } |
| 592 | |
| 593 | static int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq) |
| 594 | { |
| 595 | /* Sets IR Meas bits, but does not write them */ |
| 596 | struct tda18271_priv *priv = fe->tuner_priv; |
| 597 | unsigned char *regs = priv->tda18271_regs; |
| 598 | u8 val; |
| 599 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 600 | int ret = tda18271_lookup_map(fe, IR_MEASURE, freq, &val); |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 601 | if (ret < 0) |
| 602 | goto fail; |
| 603 | |
| 604 | regs[R_EP5] &= ~0x07; |
| 605 | regs[R_EP5] |= (0x07 & val); |
| 606 | fail: |
| 607 | return ret; |
| 608 | } |
| 609 | |
| 610 | static int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq) |
| 611 | { |
| 612 | /* Sets RF Cal bits, but does not write them */ |
| 613 | struct tda18271_priv *priv = fe->tuner_priv; |
| 614 | unsigned char *regs = priv->tda18271_regs; |
| 615 | u8 val; |
| 616 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 617 | int ret = tda18271_lookup_map(fe, RF_CAL, freq, &val); |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 618 | if (ret < 0) |
| 619 | goto fail; |
| 620 | |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 621 | regs[R_EB14] = val; |
| 622 | fail: |
| 623 | return ret; |
| 624 | } |
| 625 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 626 | /* ------------------------------------------------------------------ */ |
| 627 | |
| 628 | static int tda18271_channel_configuration(struct dvb_frontend *fe, |
| 629 | u32 ifc, u32 freq, u32 bw, u8 std) |
| 630 | { |
| 631 | struct tda18271_priv *priv = fe->tuner_priv; |
| 632 | unsigned char *regs = priv->tda18271_regs; |
| 633 | u32 N; |
| 634 | |
| 635 | /* update TV broadcast parameters */ |
| 636 | |
| 637 | /* set standard */ |
| 638 | regs[R_EP3] &= ~0x1f; /* clear std bits */ |
| 639 | regs[R_EP3] |= std; |
| 640 | |
| 641 | /* set cal mode to normal */ |
| 642 | regs[R_EP4] &= ~0x03; |
| 643 | |
| 644 | /* update IF output level & IF notch frequency */ |
| 645 | regs[R_EP4] &= ~0x1c; /* clear if level bits */ |
| 646 | |
| 647 | switch (priv->mode) { |
| 648 | case TDA18271_ANALOG: |
| 649 | regs[R_MPD] &= ~0x80; /* IF notch = 0 */ |
| 650 | break; |
| 651 | case TDA18271_DIGITAL: |
| 652 | regs[R_EP4] |= 0x04; /* IF level = 1 */ |
| 653 | regs[R_MPD] |= 0x80; /* IF notch = 1 */ |
| 654 | break; |
| 655 | } |
| 656 | regs[R_EP4] &= ~0x80; /* FM_RFn: turn this bit on only for fm radio */ |
| 657 | |
| 658 | /* update RF_TOP / IF_TOP */ |
| 659 | switch (priv->mode) { |
| 660 | case TDA18271_ANALOG: |
| 661 | regs[R_EB22] = 0x2c; |
| 662 | break; |
| 663 | case TDA18271_DIGITAL: |
| 664 | regs[R_EB22] = 0x37; |
| 665 | break; |
| 666 | } |
| 667 | tda18271_write_regs(fe, R_EB22, 1); |
| 668 | |
| 669 | /* --------------------------------------------------------------- */ |
| 670 | |
| 671 | /* disable Power Level Indicator */ |
| 672 | regs[R_EP1] |= 0x40; |
| 673 | |
| 674 | /* frequency dependent parameters */ |
| 675 | |
| 676 | tda18271_calc_ir_measure(fe, &freq); |
| 677 | |
| 678 | tda18271_calc_bp_filter(fe, &freq); |
| 679 | |
| 680 | tda18271_calc_rf_band(fe, &freq); |
| 681 | |
| 682 | tda18271_calc_gain_taper(fe, &freq); |
| 683 | |
| 684 | /* --------------------------------------------------------------- */ |
| 685 | |
| 686 | /* dual tuner and agc1 extra configuration */ |
| 687 | |
| 688 | /* main vco when Master, cal vco when slave */ |
| 689 | regs[R_EB1] |= 0x04; /* FIXME: assumes master */ |
| 690 | |
| 691 | /* agc1 always active */ |
| 692 | regs[R_EB1] &= ~0x02; |
| 693 | |
| 694 | /* agc1 has priority on agc2 */ |
| 695 | regs[R_EB1] &= ~0x01; |
| 696 | |
| 697 | tda18271_write_regs(fe, R_EB1, 1); |
| 698 | |
| 699 | /* --------------------------------------------------------------- */ |
| 700 | |
| 701 | N = freq + ifc; |
| 702 | |
| 703 | /* FIXME: assumes master */ |
| 704 | tda18271_calc_main_pll(fe, N); |
| 705 | tda18271_write_regs(fe, R_MPD, 4); |
| 706 | |
| 707 | tda18271_write_regs(fe, R_TM, 7); |
| 708 | |
| 709 | /* main pll charge pump source */ |
| 710 | regs[R_EB4] |= 0x20; |
| 711 | tda18271_write_regs(fe, R_EB4, 1); |
| 712 | |
| 713 | msleep(1); |
| 714 | |
| 715 | /* normal operation for the main pll */ |
| 716 | regs[R_EB4] &= ~0x20; |
| 717 | tda18271_write_regs(fe, R_EB4, 1); |
| 718 | |
| 719 | msleep(5); |
| 720 | |
| 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | static int tda18271_read_thermometer(struct dvb_frontend *fe) |
| 725 | { |
| 726 | struct tda18271_priv *priv = fe->tuner_priv; |
| 727 | unsigned char *regs = priv->tda18271_regs; |
| 728 | int tm; |
| 729 | |
| 730 | /* switch thermometer on */ |
| 731 | regs[R_TM] |= 0x10; |
| 732 | tda18271_write_regs(fe, R_TM, 1); |
| 733 | |
| 734 | /* read thermometer info */ |
| 735 | tda18271_read_regs(fe); |
| 736 | |
| 737 | if ((((regs[R_TM] & 0x0f) == 0x00) && ((regs[R_TM] & 0x20) == 0x20)) || |
| 738 | (((regs[R_TM] & 0x0f) == 0x08) && ((regs[R_TM] & 0x20) == 0x00))) { |
| 739 | |
| 740 | if ((regs[R_TM] & 0x20) == 0x20) |
| 741 | regs[R_TM] &= ~0x20; |
| 742 | else |
| 743 | regs[R_TM] |= 0x20; |
| 744 | |
| 745 | tda18271_write_regs(fe, R_TM, 1); |
| 746 | |
| 747 | msleep(10); /* temperature sensing */ |
| 748 | |
| 749 | /* read thermometer info */ |
| 750 | tda18271_read_regs(fe); |
| 751 | } |
| 752 | |
| 753 | tm = tda18271_lookup_thermometer(fe); |
| 754 | |
| 755 | /* switch thermometer off */ |
| 756 | regs[R_TM] &= ~0x10; |
| 757 | tda18271_write_regs(fe, R_TM, 1); |
| 758 | |
| 759 | /* set CAL mode to normal */ |
| 760 | regs[R_EP4] &= ~0x03; |
| 761 | tda18271_write_regs(fe, R_EP4, 1); |
| 762 | |
| 763 | return tm; |
| 764 | } |
| 765 | |
| 766 | static int tda18271_rf_tracking_filters_correction(struct dvb_frontend *fe, |
| 767 | u32 freq, int tm_rfcal) |
| 768 | { |
| 769 | struct tda18271_priv *priv = fe->tuner_priv; |
| 770 | struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state; |
| 771 | unsigned char *regs = priv->tda18271_regs; |
| 772 | int tm_current, rfcal_comp, approx, i; |
| 773 | u8 dc_over_dt, rf_tab; |
| 774 | |
| 775 | /* power up */ |
| 776 | regs[R_EP3] &= ~0xe0; /* sm = 0, sm_lt = 0, sm_xt = 0 */ |
| 777 | tda18271_write_regs(fe, R_EP3, 1); |
| 778 | |
| 779 | /* read die current temperature */ |
| 780 | tm_current = tda18271_read_thermometer(fe); |
| 781 | |
| 782 | /* frequency dependent parameters */ |
| 783 | |
| 784 | tda18271_calc_rf_cal(fe, &freq); |
| 785 | rf_tab = regs[R_EB14]; |
| 786 | |
| 787 | i = tda18271_lookup_rf_band(fe, &freq, NULL); |
| 788 | if (i < 0) |
| 789 | return -EINVAL; |
| 790 | |
| 791 | if ((0 == map[i].rf3) || (freq / 1000 < map[i].rf2)) { |
| 792 | approx = map[i].rf_a1 * |
| 793 | (freq / 1000 - map[i].rf1) + map[i].rf_b1 + rf_tab; |
| 794 | } else { |
| 795 | approx = map[i].rf_a2 * |
| 796 | (freq / 1000 - map[i].rf2) + map[i].rf_b2 + rf_tab; |
| 797 | } |
| 798 | |
| 799 | if (approx < 0) |
| 800 | approx = 0; |
| 801 | if (approx > 255) |
| 802 | approx = 255; |
| 803 | |
| 804 | tda18271_lookup_map(fe, RF_CAL_DC_OVER_DT, &freq, &dc_over_dt); |
| 805 | |
| 806 | /* calculate temperature compensation */ |
| 807 | rfcal_comp = dc_over_dt * (tm_current - tm_rfcal); |
| 808 | |
| 809 | regs[R_EB14] = approx + rfcal_comp; |
| 810 | tda18271_write_regs(fe, R_EB14, 1); |
| 811 | |
| 812 | return 0; |
| 813 | } |
| 814 | |
| 815 | static int tda18271_por(struct dvb_frontend *fe) |
| 816 | { |
| 817 | struct tda18271_priv *priv = fe->tuner_priv; |
| 818 | unsigned char *regs = priv->tda18271_regs; |
| 819 | |
| 820 | /* power up detector 1 */ |
| 821 | regs[R_EB12] &= ~0x20; |
| 822 | tda18271_write_regs(fe, R_EB12, 1); |
| 823 | |
| 824 | regs[R_EB18] &= ~0x80; /* turn agc1 loop on */ |
| 825 | regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */ |
| 826 | tda18271_write_regs(fe, R_EB18, 1); |
| 827 | |
| 828 | regs[R_EB21] |= 0x03; /* set agc2_gain to -6 dB */ |
| 829 | |
| 830 | /* POR mode */ |
| 831 | regs[R_EP3] &= ~0xe0; /* clear sm, sm_lt, sm_xt */ |
| 832 | regs[R_EP3] |= 0x80; /* sm = 1, sm_lt = 0, sm_xt = 0 */ |
| 833 | tda18271_write_regs(fe, R_EP3, 1); |
| 834 | |
| 835 | /* disable 1.5 MHz low pass filter */ |
| 836 | regs[R_EB23] &= ~0x04; /* forcelp_fc2_en = 0 */ |
| 837 | regs[R_EB23] &= ~0x02; /* XXX: lp_fc[2] = 0 */ |
| 838 | tda18271_write_regs(fe, R_EB21, 3); |
| 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | static int tda18271_calibrate_rf(struct dvb_frontend *fe, u32 freq) |
| 844 | { |
| 845 | struct tda18271_priv *priv = fe->tuner_priv; |
| 846 | unsigned char *regs = priv->tda18271_regs; |
| 847 | u32 N; |
| 848 | |
| 849 | /* set CAL mode to normal */ |
| 850 | regs[R_EP4] &= ~0x03; |
| 851 | tda18271_write_regs(fe, R_EP4, 1); |
| 852 | |
| 853 | /* switch off agc1 */ |
| 854 | regs[R_EP3] |= 0x40; /* sm_lt = 1 */ |
| 855 | |
| 856 | regs[R_EB18] |= 0x03; /* set agc1_gain to 15 dB */ |
| 857 | tda18271_write_regs(fe, R_EB18, 1); |
| 858 | |
| 859 | /* frequency dependent parameters */ |
| 860 | |
| 861 | tda18271_calc_bp_filter(fe, &freq); |
| 862 | tda18271_calc_gain_taper(fe, &freq); |
| 863 | tda18271_calc_rf_band(fe, &freq); |
| 864 | tda18271_calc_km(fe, &freq); |
| 865 | |
| 866 | tda18271_write_regs(fe, R_EP1, 3); |
| 867 | tda18271_write_regs(fe, R_EB13, 1); |
| 868 | |
| 869 | /* main pll charge pump source */ |
| 870 | regs[R_EB4] |= 0x20; |
| 871 | tda18271_write_regs(fe, R_EB4, 1); |
| 872 | |
| 873 | /* cal pll charge pump source */ |
| 874 | regs[R_EB7] |= 0x20; |
| 875 | tda18271_write_regs(fe, R_EB7, 1); |
| 876 | |
| 877 | /* force dcdc converter to 0 V */ |
| 878 | regs[R_EB14] = 0x00; |
| 879 | tda18271_write_regs(fe, R_EB14, 1); |
| 880 | |
| 881 | /* disable plls lock */ |
| 882 | regs[R_EB20] &= ~0x20; |
| 883 | tda18271_write_regs(fe, R_EB20, 1); |
| 884 | |
| 885 | /* set CAL mode to RF tracking filter calibration */ |
| 886 | regs[R_EP4] |= 0x03; |
| 887 | tda18271_write_regs(fe, R_EP4, 2); |
| 888 | |
| 889 | /* --------------------------------------------------------------- */ |
| 890 | |
| 891 | /* set the internal calibration signal */ |
| 892 | N = freq; |
| 893 | |
| 894 | tda18271_calc_main_pll(fe, N); |
| 895 | tda18271_write_regs(fe, R_MPD, 4); |
| 896 | |
| 897 | /* downconvert internal calibration */ |
| 898 | N += 1000000; |
| 899 | |
| 900 | tda18271_calc_main_pll(fe, N); |
| 901 | tda18271_write_regs(fe, R_MPD, 4); |
| 902 | |
| 903 | msleep(5); |
| 904 | |
| 905 | tda18271_write_regs(fe, R_EP2, 1); |
| 906 | tda18271_write_regs(fe, R_EP1, 1); |
| 907 | tda18271_write_regs(fe, R_EP2, 1); |
| 908 | tda18271_write_regs(fe, R_EP1, 1); |
| 909 | |
| 910 | /* --------------------------------------------------------------- */ |
| 911 | |
| 912 | /* normal operation for the main pll */ |
| 913 | regs[R_EB4] &= ~0x20; |
| 914 | tda18271_write_regs(fe, R_EB4, 1); |
| 915 | |
| 916 | /* normal operation for the cal pll */ |
| 917 | regs[R_EB7] &= ~0x20; |
| 918 | tda18271_write_regs(fe, R_EB7, 1); |
| 919 | |
| 920 | msleep(5); /* plls locking */ |
| 921 | |
| 922 | /* launch the rf tracking filters calibration */ |
| 923 | regs[R_EB20] |= 0x20; |
| 924 | tda18271_write_regs(fe, R_EB20, 1); |
| 925 | |
| 926 | msleep(60); /* calibration */ |
| 927 | |
| 928 | /* --------------------------------------------------------------- */ |
| 929 | |
| 930 | /* set CAL mode to normal */ |
| 931 | regs[R_EP4] &= ~0x03; |
| 932 | |
| 933 | /* switch on agc1 */ |
| 934 | regs[R_EP3] &= ~0x40; /* sm_lt = 0 */ |
| 935 | |
| 936 | regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */ |
| 937 | tda18271_write_regs(fe, R_EB18, 1); |
| 938 | |
| 939 | tda18271_write_regs(fe, R_EP3, 2); |
| 940 | |
| 941 | /* synchronization */ |
| 942 | tda18271_write_regs(fe, R_EP1, 1); |
| 943 | |
| 944 | /* get calibration result */ |
| 945 | tda18271_read_extended(fe); |
| 946 | |
| 947 | return regs[R_EB14]; |
| 948 | } |
| 949 | |
| 950 | static int tda18271_powerscan(struct dvb_frontend *fe, |
| 951 | u32 *freq_in, u32 *freq_out) |
| 952 | { |
| 953 | struct tda18271_priv *priv = fe->tuner_priv; |
| 954 | unsigned char *regs = priv->tda18271_regs; |
| 955 | int sgn, bcal, count, wait; |
| 956 | u8 cid_target; |
| 957 | u16 count_limit; |
| 958 | u32 freq; |
| 959 | |
| 960 | freq = *freq_in; |
| 961 | |
| 962 | tda18271_calc_rf_band(fe, &freq); |
| 963 | tda18271_calc_rf_cal(fe, &freq); |
| 964 | tda18271_calc_gain_taper(fe, &freq); |
| 965 | tda18271_lookup_cid_target(fe, &freq, &cid_target, &count_limit); |
| 966 | |
| 967 | tda18271_write_regs(fe, R_EP2, 1); |
| 968 | tda18271_write_regs(fe, R_EB14, 1); |
| 969 | |
| 970 | /* downconvert frequency */ |
| 971 | freq += 1000000; |
| 972 | |
| 973 | tda18271_calc_main_pll(fe, freq); |
| 974 | tda18271_write_regs(fe, R_MPD, 4); |
| 975 | |
| 976 | msleep(5); /* pll locking */ |
| 977 | |
| 978 | /* detection mode */ |
| 979 | regs[R_EP4] &= ~0x03; |
| 980 | regs[R_EP4] |= 0x01; |
| 981 | tda18271_write_regs(fe, R_EP4, 1); |
| 982 | |
| 983 | /* launch power detection measurement */ |
| 984 | tda18271_write_regs(fe, R_EP2, 1); |
| 985 | |
| 986 | /* read power detection info, stored in EB10 */ |
| 987 | tda18271_read_extended(fe); |
| 988 | |
| 989 | /* algorithm initialization */ |
| 990 | sgn = 1; |
| 991 | *freq_out = *freq_in; |
| 992 | bcal = 0; |
| 993 | count = 0; |
| 994 | wait = false; |
| 995 | |
| 996 | while ((regs[R_EB10] & 0x3f) < cid_target) { |
| 997 | /* downconvert updated freq to 1 MHz */ |
| 998 | freq = *freq_in + (sgn * count) + 1000000; |
| 999 | |
| 1000 | tda18271_calc_main_pll(fe, freq); |
| 1001 | tda18271_write_regs(fe, R_MPD, 4); |
| 1002 | |
| 1003 | if (wait) { |
| 1004 | msleep(5); /* pll locking */ |
| 1005 | wait = false; |
| 1006 | } else |
| 1007 | udelay(100); /* pll locking */ |
| 1008 | |
| 1009 | /* launch power detection measurement */ |
| 1010 | tda18271_write_regs(fe, R_EP2, 1); |
| 1011 | |
| 1012 | /* read power detection info, stored in EB10 */ |
| 1013 | tda18271_read_extended(fe); |
| 1014 | |
| 1015 | count += 200; |
| 1016 | |
| 1017 | if (count < count_limit) |
| 1018 | continue; |
| 1019 | |
| 1020 | if (sgn <= 0) |
| 1021 | break; |
| 1022 | |
| 1023 | sgn = -1 * sgn; |
| 1024 | count = 200; |
| 1025 | wait = true; |
| 1026 | } |
| 1027 | |
| 1028 | if ((regs[R_EB10] & 0x3f) >= cid_target) { |
| 1029 | bcal = 1; |
| 1030 | *freq_out = freq - 1000000; |
| 1031 | } else |
| 1032 | bcal = 0; |
| 1033 | |
| 1034 | tda_dbg("bcal = %d, freq_in = %d, freq_out = %d (freq = %d)\n", |
| 1035 | bcal, *freq_in, *freq_out, freq); |
| 1036 | |
| 1037 | return bcal; |
| 1038 | } |
| 1039 | |
| 1040 | static int tda18271_powerscan_init(struct dvb_frontend *fe) |
| 1041 | { |
| 1042 | struct tda18271_priv *priv = fe->tuner_priv; |
| 1043 | unsigned char *regs = priv->tda18271_regs; |
| 1044 | |
| 1045 | /* set standard to digital */ |
| 1046 | regs[R_EP3] &= ~0x1f; /* clear std bits */ |
| 1047 | regs[R_EP3] |= 0x12; |
| 1048 | |
| 1049 | /* set cal mode to normal */ |
| 1050 | regs[R_EP4] &= ~0x03; |
| 1051 | |
| 1052 | /* update IF output level & IF notch frequency */ |
| 1053 | regs[R_EP4] &= ~0x1c; /* clear if level bits */ |
| 1054 | |
| 1055 | tda18271_write_regs(fe, R_EP3, 2); |
| 1056 | |
| 1057 | regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */ |
| 1058 | tda18271_write_regs(fe, R_EB18, 1); |
| 1059 | |
| 1060 | regs[R_EB21] &= ~0x03; /* set agc2_gain to -15 dB */ |
| 1061 | |
| 1062 | /* 1.5 MHz low pass filter */ |
| 1063 | regs[R_EB23] |= 0x04; /* forcelp_fc2_en = 1 */ |
| 1064 | regs[R_EB23] |= 0x02; /* lp_fc[2] = 1 */ |
| 1065 | |
| 1066 | tda18271_write_regs(fe, R_EB21, 3); |
| 1067 | |
| 1068 | return 0; |
| 1069 | } |
| 1070 | |
| 1071 | static int tda18271_rf_tracking_filters_init(struct dvb_frontend *fe, u32 freq) |
| 1072 | { |
| 1073 | struct tda18271_priv *priv = fe->tuner_priv; |
| 1074 | struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state; |
| 1075 | unsigned char *regs = priv->tda18271_regs; |
| 1076 | int bcal, rf, i; |
| 1077 | #define RF1 0 |
| 1078 | #define RF2 1 |
| 1079 | #define RF3 2 |
| 1080 | u32 rf_default[3]; |
| 1081 | u32 rf_freq[3]; |
| 1082 | u8 prog_cal[3]; |
| 1083 | u8 prog_tab[3]; |
| 1084 | |
| 1085 | i = tda18271_lookup_rf_band(fe, &freq, NULL); |
| 1086 | |
| 1087 | if (i < 0) |
| 1088 | return i; |
| 1089 | |
| 1090 | rf_default[RF1] = 1000 * map[i].rf1_def; |
| 1091 | rf_default[RF2] = 1000 * map[i].rf2_def; |
| 1092 | rf_default[RF3] = 1000 * map[i].rf3_def; |
| 1093 | |
| 1094 | for (rf = RF1; rf <= RF3; rf++) { |
| 1095 | if (0 == rf_default[rf]) |
| 1096 | return 0; |
| 1097 | tda_dbg("freq = %d, rf = %d\n", freq, rf); |
| 1098 | |
| 1099 | /* look for optimized calibration frequency */ |
| 1100 | bcal = tda18271_powerscan(fe, &rf_default[rf], &rf_freq[rf]); |
| 1101 | |
| 1102 | tda18271_calc_rf_cal(fe, &rf_freq[rf]); |
| 1103 | prog_tab[rf] = regs[R_EB14]; |
| 1104 | |
| 1105 | if (1 == bcal) |
| 1106 | prog_cal[rf] = tda18271_calibrate_rf(fe, rf_freq[rf]); |
| 1107 | else |
| 1108 | prog_cal[rf] = prog_tab[rf]; |
| 1109 | |
| 1110 | switch (rf) { |
| 1111 | case RF1: |
| 1112 | map[i].rf_a1 = 0; |
| 1113 | map[i].rf_b1 = prog_cal[RF1] - prog_tab[RF1]; |
| 1114 | map[i].rf1 = rf_freq[RF1] / 1000; |
| 1115 | break; |
| 1116 | case RF2: |
| 1117 | map[i].rf_a1 = (prog_cal[RF2] - prog_tab[RF2] - |
| 1118 | prog_cal[RF1] + prog_tab[RF1]) / |
| 1119 | ((rf_freq[RF2] - rf_freq[RF1]) / 1000); |
| 1120 | map[i].rf2 = rf_freq[RF2] / 1000; |
| 1121 | break; |
| 1122 | case RF3: |
| 1123 | map[i].rf_a2 = (prog_cal[RF3] - prog_tab[RF3] - |
| 1124 | prog_cal[RF2] + prog_tab[RF2]) / |
| 1125 | ((rf_freq[RF3] - rf_freq[RF2]) / 1000); |
| 1126 | map[i].rf_b2 = prog_cal[RF2] - prog_tab[RF2]; |
| 1127 | map[i].rf3 = rf_freq[RF3] / 1000; |
| 1128 | break; |
| 1129 | default: |
| 1130 | BUG(); |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | return 0; |
| 1135 | } |
| 1136 | |
| 1137 | static int tda18271_calc_rf_filter_curve(struct dvb_frontend *fe, |
| 1138 | int *tm_rfcal) |
| 1139 | { |
| 1140 | struct tda18271_priv *priv = fe->tuner_priv; |
| 1141 | unsigned int i; |
| 1142 | |
| 1143 | tda_info("tda18271: performing RF tracking filter calibration\n"); |
| 1144 | |
| 1145 | /* wait for die temperature stabilization */ |
| 1146 | msleep(200); |
| 1147 | |
| 1148 | tda18271_powerscan_init(fe); |
| 1149 | |
| 1150 | /* rf band calibration */ |
| 1151 | for (i = 0; priv->rf_cal_state[i].rfmax != 0; i++) |
| 1152 | tda18271_rf_tracking_filters_init(fe, 1000 * |
| 1153 | priv->rf_cal_state[i].rfmax); |
| 1154 | |
| 1155 | *tm_rfcal = tda18271_read_thermometer(fe); |
| 1156 | |
| 1157 | return 0; |
| 1158 | } |
| 1159 | |
| 1160 | /* ------------------------------------------------------------------ */ |
| 1161 | |
| 1162 | static int tda18271_init_cal(struct dvb_frontend *fe, int *tm) |
| 1163 | { |
| 1164 | struct tda18271_priv *priv = fe->tuner_priv; |
| 1165 | |
| 1166 | if (priv->cal_initialized) |
| 1167 | return 0; |
| 1168 | |
| 1169 | /* initialization */ |
| 1170 | tda18271_init(fe); |
| 1171 | |
| 1172 | tda18271_calc_rf_filter_curve(fe, tm); |
| 1173 | |
| 1174 | tda18271_por(fe); |
| 1175 | |
| 1176 | priv->cal_initialized = true; |
| 1177 | |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
| 1181 | static int tda18271c2_tune(struct dvb_frontend *fe, |
| 1182 | u32 ifc, u32 freq, u32 bw, u8 std) |
| 1183 | { |
| 1184 | int tm = 0; |
| 1185 | |
| 1186 | tda_dbg("freq = %d, ifc = %d\n", freq, ifc); |
| 1187 | |
| 1188 | tda18271_init_cal(fe, &tm); |
| 1189 | |
| 1190 | tda18271_rf_tracking_filters_correction(fe, freq, tm); |
| 1191 | |
| 1192 | tda18271_channel_configuration(fe, ifc, freq, bw, std); |
| 1193 | |
| 1194 | return 0; |
| 1195 | } |
| 1196 | |
| 1197 | /* ------------------------------------------------------------------ */ |
| 1198 | |
| 1199 | static int tda18271c1_tune(struct dvb_frontend *fe, |
| 1200 | u32 ifc, u32 freq, u32 bw, u8 std) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1201 | { |
| 1202 | struct tda18271_priv *priv = fe->tuner_priv; |
| 1203 | unsigned char *regs = priv->tda18271_regs; |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame] | 1204 | u32 N = 0; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1205 | |
Michael Krufky | 1457263 | 2007-12-02 02:32:49 -0300 | [diff] [blame] | 1206 | tda18271_init(fe); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1207 | |
Michael Krufky | 182519f | 2007-12-25 15:10:11 -0300 | [diff] [blame] | 1208 | tda_dbg("freq = %d, ifc = %d\n", freq, ifc); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1209 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1210 | /* RF tracking filter calibration */ |
| 1211 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1212 | /* calculate bp filter */ |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 1213 | tda18271_calc_bp_filter(fe, &freq); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1214 | tda18271_write_regs(fe, R_EP1, 1); |
| 1215 | |
| 1216 | regs[R_EB4] &= 0x07; |
| 1217 | regs[R_EB4] |= 0x60; |
| 1218 | tda18271_write_regs(fe, R_EB4, 1); |
| 1219 | |
| 1220 | regs[R_EB7] = 0x60; |
| 1221 | tda18271_write_regs(fe, R_EB7, 1); |
| 1222 | |
| 1223 | regs[R_EB14] = 0x00; |
| 1224 | tda18271_write_regs(fe, R_EB14, 1); |
| 1225 | |
| 1226 | regs[R_EB20] = 0xcc; |
| 1227 | tda18271_write_regs(fe, R_EB20, 1); |
| 1228 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1229 | /* set cal mode to RF tracking filter calibration */ |
Michael Krufky | 26501a7 | 2007-12-21 14:28:46 -0300 | [diff] [blame] | 1230 | regs[R_EP4] |= 0x03; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1231 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1232 | /* calculate cal pll */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1233 | |
| 1234 | switch (priv->mode) { |
| 1235 | case TDA18271_ANALOG: |
| 1236 | N = freq - 1250000; |
| 1237 | break; |
| 1238 | case TDA18271_DIGITAL: |
| 1239 | N = freq + bw / 2; |
| 1240 | break; |
| 1241 | } |
| 1242 | |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame] | 1243 | tda18271_calc_cal_pll(fe, N); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1244 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1245 | /* calculate main pll */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1246 | |
| 1247 | switch (priv->mode) { |
| 1248 | case TDA18271_ANALOG: |
| 1249 | N = freq - 250000; |
| 1250 | break; |
| 1251 | case TDA18271_DIGITAL: |
| 1252 | N = freq + bw / 2 + 1000000; |
| 1253 | break; |
| 1254 | } |
| 1255 | |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame] | 1256 | tda18271_calc_main_pll(fe, N); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1257 | |
| 1258 | tda18271_write_regs(fe, R_EP3, 11); |
| 1259 | msleep(5); /* RF tracking filter calibration initialization */ |
| 1260 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1261 | /* search for K,M,CO for RF calibration */ |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 1262 | tda18271_calc_km(fe, &freq); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1263 | tda18271_write_regs(fe, R_EB13, 1); |
| 1264 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1265 | /* search for rf band */ |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 1266 | tda18271_calc_rf_band(fe, &freq); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1267 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1268 | /* search for gain taper */ |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 1269 | tda18271_calc_gain_taper(fe, &freq); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1270 | |
| 1271 | tda18271_write_regs(fe, R_EP2, 1); |
| 1272 | tda18271_write_regs(fe, R_EP1, 1); |
| 1273 | tda18271_write_regs(fe, R_EP2, 1); |
| 1274 | tda18271_write_regs(fe, R_EP1, 1); |
| 1275 | |
| 1276 | regs[R_EB4] &= 0x07; |
| 1277 | regs[R_EB4] |= 0x40; |
| 1278 | tda18271_write_regs(fe, R_EB4, 1); |
| 1279 | |
| 1280 | regs[R_EB7] = 0x40; |
| 1281 | tda18271_write_regs(fe, R_EB7, 1); |
| 1282 | msleep(10); |
| 1283 | |
| 1284 | regs[R_EB20] = 0xec; |
| 1285 | tda18271_write_regs(fe, R_EB20, 1); |
| 1286 | msleep(60); /* RF tracking filter calibration completion */ |
| 1287 | |
| 1288 | regs[R_EP4] &= ~0x03; /* set cal mode to normal */ |
| 1289 | tda18271_write_regs(fe, R_EP4, 1); |
| 1290 | |
| 1291 | tda18271_write_regs(fe, R_EP1, 1); |
| 1292 | |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 1293 | /* RF tracking filter correction for VHF_Low band */ |
| 1294 | if (0 == tda18271_calc_rf_cal(fe, &freq)) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1295 | tda18271_write_regs(fe, R_EB14, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1296 | |
| 1297 | /* Channel Configuration */ |
| 1298 | |
| 1299 | switch (priv->mode) { |
| 1300 | case TDA18271_ANALOG: |
| 1301 | regs[R_EB22] = 0x2c; |
| 1302 | break; |
| 1303 | case TDA18271_DIGITAL: |
| 1304 | regs[R_EB22] = 0x37; |
| 1305 | break; |
| 1306 | } |
| 1307 | tda18271_write_regs(fe, R_EB22, 1); |
| 1308 | |
| 1309 | regs[R_EP1] |= 0x40; /* set dis power level on */ |
| 1310 | |
| 1311 | /* set standard */ |
| 1312 | regs[R_EP3] &= ~0x1f; /* clear std bits */ |
| 1313 | |
| 1314 | /* see table 22 */ |
| 1315 | regs[R_EP3] |= std; |
| 1316 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1317 | regs[R_EP4] &= ~0x03; /* set cal mode to normal */ |
| 1318 | |
| 1319 | regs[R_EP4] &= ~0x1c; /* clear if level bits */ |
| 1320 | switch (priv->mode) { |
| 1321 | case TDA18271_ANALOG: |
| 1322 | regs[R_MPD] &= ~0x80; /* IF notch = 0 */ |
| 1323 | break; |
| 1324 | case TDA18271_DIGITAL: |
| 1325 | regs[R_EP4] |= 0x04; |
| 1326 | regs[R_MPD] |= 0x80; |
| 1327 | break; |
| 1328 | } |
| 1329 | |
| 1330 | regs[R_EP4] &= ~0x80; /* turn this bit on only for fm */ |
| 1331 | |
Michael Krufky | b92bf0f | 2007-12-25 18:54:22 -0300 | [diff] [blame] | 1332 | /* image rejection validity */ |
| 1333 | tda18271_calc_ir_measure(fe, &freq); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1334 | |
| 1335 | /* calculate MAIN PLL */ |
| 1336 | N = freq + ifc; |
| 1337 | |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame] | 1338 | tda18271_calc_main_pll(fe, N); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1339 | |
| 1340 | tda18271_write_regs(fe, R_TM, 15); |
| 1341 | msleep(5); |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 1342 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1343 | return 0; |
| 1344 | } |
| 1345 | |
| 1346 | /* ------------------------------------------------------------------ */ |
| 1347 | |
| 1348 | static int tda18271_set_params(struct dvb_frontend *fe, |
| 1349 | struct dvb_frontend_parameters *params) |
| 1350 | { |
| 1351 | struct tda18271_priv *priv = fe->tuner_priv; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1352 | struct tda18271_std_map *std_map = priv->std; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1353 | u8 std; |
| 1354 | u32 bw, sgIF = 0; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1355 | u32 freq = params->frequency; |
| 1356 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1357 | BUG_ON(!priv->tune || !priv->std); |
| 1358 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1359 | priv->mode = TDA18271_DIGITAL; |
| 1360 | |
| 1361 | /* see table 22 */ |
| 1362 | if (fe->ops.info.type == FE_ATSC) { |
| 1363 | switch (params->u.vsb.modulation) { |
| 1364 | case VSB_8: |
| 1365 | case VSB_16: |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1366 | std = std_map->atsc_6.std_bits; |
| 1367 | sgIF = std_map->atsc_6.if_freq; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1368 | break; |
| 1369 | case QAM_64: |
| 1370 | case QAM_256: |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1371 | std = std_map->qam_6.std_bits; |
| 1372 | sgIF = std_map->qam_6.if_freq; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1373 | break; |
| 1374 | default: |
Michael Krufky | 182519f | 2007-12-25 15:10:11 -0300 | [diff] [blame] | 1375 | tda_warn("modulation not set!\n"); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1376 | return -EINVAL; |
| 1377 | } |
Michael Krufky | 14e3c15 | 2007-12-07 00:33:08 -0300 | [diff] [blame] | 1378 | #if 0 |
| 1379 | /* userspace request is already center adjusted */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1380 | freq += 1750000; /* Adjust to center (+1.75MHZ) */ |
Michael Krufky | 14e3c15 | 2007-12-07 00:33:08 -0300 | [diff] [blame] | 1381 | #endif |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1382 | bw = 6000000; |
| 1383 | } else if (fe->ops.info.type == FE_OFDM) { |
| 1384 | switch (params->u.ofdm.bandwidth) { |
| 1385 | case BANDWIDTH_6_MHZ: |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1386 | bw = 6000000; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1387 | std = std_map->dvbt_6.std_bits; |
| 1388 | sgIF = std_map->dvbt_6.if_freq; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1389 | break; |
| 1390 | case BANDWIDTH_7_MHZ: |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1391 | bw = 7000000; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1392 | std = std_map->dvbt_7.std_bits; |
| 1393 | sgIF = std_map->dvbt_7.if_freq; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1394 | break; |
| 1395 | case BANDWIDTH_8_MHZ: |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1396 | bw = 8000000; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1397 | std = std_map->dvbt_8.std_bits; |
| 1398 | sgIF = std_map->dvbt_8.if_freq; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1399 | break; |
| 1400 | default: |
Michael Krufky | 182519f | 2007-12-25 15:10:11 -0300 | [diff] [blame] | 1401 | tda_warn("bandwidth not set!\n"); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1402 | return -EINVAL; |
| 1403 | } |
| 1404 | } else { |
Michael Krufky | 182519f | 2007-12-25 15:10:11 -0300 | [diff] [blame] | 1405 | tda_warn("modulation type not supported!\n"); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1406 | return -EINVAL; |
| 1407 | } |
| 1408 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1409 | return priv->tune(fe, sgIF, freq, bw, std); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | static int tda18271_set_analog_params(struct dvb_frontend *fe, |
| 1413 | struct analog_parameters *params) |
| 1414 | { |
| 1415 | struct tda18271_priv *priv = fe->tuner_priv; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1416 | struct tda18271_std_map *std_map = priv->std; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1417 | char *mode; |
Michael Krufky | 95af8a2 | 2008-01-01 18:31:34 -0300 | [diff] [blame] | 1418 | u8 std; |
| 1419 | u32 sgIF, freq = params->frequency * 62500; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1420 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1421 | BUG_ON(!priv->tune || !priv->std); |
| 1422 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1423 | priv->mode = TDA18271_ANALOG; |
| 1424 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1425 | if (params->std & V4L2_STD_MN) { |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1426 | std = std_map->atv_mn.std_bits; |
| 1427 | sgIF = std_map->atv_mn.if_freq; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1428 | mode = "MN"; |
| 1429 | } else if (params->std & V4L2_STD_B) { |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1430 | std = std_map->atv_b.std_bits; |
| 1431 | sgIF = std_map->atv_b.if_freq; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1432 | mode = "B"; |
| 1433 | } else if (params->std & V4L2_STD_GH) { |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1434 | std = std_map->atv_gh.std_bits; |
| 1435 | sgIF = std_map->atv_gh.if_freq; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1436 | mode = "GH"; |
| 1437 | } else if (params->std & V4L2_STD_PAL_I) { |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1438 | std = std_map->atv_i.std_bits; |
| 1439 | sgIF = std_map->atv_i.if_freq; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1440 | mode = "I"; |
| 1441 | } else if (params->std & V4L2_STD_DK) { |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1442 | std = std_map->atv_dk.std_bits; |
| 1443 | sgIF = std_map->atv_dk.if_freq; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1444 | mode = "DK"; |
| 1445 | } else if (params->std & V4L2_STD_SECAM_L) { |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1446 | std = std_map->atv_l.std_bits; |
| 1447 | sgIF = std_map->atv_l.if_freq; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1448 | mode = "L"; |
| 1449 | } else if (params->std & V4L2_STD_SECAM_LC) { |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1450 | std = std_map->atv_lc.std_bits; |
| 1451 | sgIF = std_map->atv_lc.if_freq; |
Michael Krufky | 95af8a2 | 2008-01-01 18:31:34 -0300 | [diff] [blame] | 1452 | mode = "L'"; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1453 | } else { |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1454 | std = std_map->atv_i.std_bits; |
| 1455 | sgIF = std_map->atv_i.if_freq; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1456 | mode = "xx"; |
| 1457 | } |
| 1458 | |
Michael Krufky | 182519f | 2007-12-25 15:10:11 -0300 | [diff] [blame] | 1459 | tda_dbg("setting tda18271 to system %s\n", mode); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1460 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1461 | return priv->tune(fe, sgIF, freq, 0, std); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | static int tda18271_release(struct dvb_frontend *fe) |
| 1465 | { |
| 1466 | kfree(fe->tuner_priv); |
| 1467 | fe->tuner_priv = NULL; |
| 1468 | return 0; |
| 1469 | } |
| 1470 | |
| 1471 | static int tda18271_get_frequency(struct dvb_frontend *fe, u32 *frequency) |
| 1472 | { |
| 1473 | struct tda18271_priv *priv = fe->tuner_priv; |
| 1474 | *frequency = priv->frequency; |
| 1475 | return 0; |
| 1476 | } |
| 1477 | |
| 1478 | static int tda18271_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth) |
| 1479 | { |
| 1480 | struct tda18271_priv *priv = fe->tuner_priv; |
| 1481 | *bandwidth = priv->bandwidth; |
| 1482 | return 0; |
| 1483 | } |
| 1484 | |
Michael Krufky | 49e7aaf | 2007-12-24 04:15:20 -0300 | [diff] [blame] | 1485 | static int tda18271_get_id(struct dvb_frontend *fe) |
| 1486 | { |
| 1487 | struct tda18271_priv *priv = fe->tuner_priv; |
| 1488 | unsigned char *regs = priv->tda18271_regs; |
| 1489 | char *name; |
| 1490 | int ret = 0; |
| 1491 | |
| 1492 | tda18271_read_regs(fe); |
| 1493 | |
| 1494 | switch (regs[R_ID] & 0x7f) { |
| 1495 | case 3: |
| 1496 | name = "TDA18271HD/C1"; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1497 | priv->id = TDA18271HDC1; |
| 1498 | priv->tune = tda18271c1_tune; |
Michael Krufky | 49e7aaf | 2007-12-24 04:15:20 -0300 | [diff] [blame] | 1499 | break; |
| 1500 | case 4: |
| 1501 | name = "TDA18271HD/C2"; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1502 | priv->id = TDA18271HDC2; |
| 1503 | priv->tune = tda18271c2_tune; |
Michael Krufky | 49e7aaf | 2007-12-24 04:15:20 -0300 | [diff] [blame] | 1504 | break; |
| 1505 | default: |
| 1506 | name = "Unknown device"; |
| 1507 | ret = -EINVAL; |
| 1508 | break; |
| 1509 | } |
| 1510 | |
Michael Krufky | 182519f | 2007-12-25 15:10:11 -0300 | [diff] [blame] | 1511 | tda_info("%s detected @ %d-%04x%s\n", name, |
Michael Krufky | 49e7aaf | 2007-12-24 04:15:20 -0300 | [diff] [blame] | 1512 | i2c_adapter_id(priv->i2c_adap), priv->i2c_addr, |
| 1513 | (0 == ret) ? "" : ", device not supported."); |
| 1514 | |
| 1515 | return ret; |
| 1516 | } |
| 1517 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1518 | static struct dvb_tuner_ops tda18271_tuner_ops = { |
| 1519 | .info = { |
| 1520 | .name = "NXP TDA18271HD", |
| 1521 | .frequency_min = 45000000, |
| 1522 | .frequency_max = 864000000, |
| 1523 | .frequency_step = 62500 |
| 1524 | }, |
Michael Krufky | efce841 | 2007-12-01 17:40:16 -0300 | [diff] [blame] | 1525 | .init = tda18271_init, |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1526 | .set_params = tda18271_set_params, |
| 1527 | .set_analog_params = tda18271_set_analog_params, |
| 1528 | .release = tda18271_release, |
| 1529 | .get_frequency = tda18271_get_frequency, |
| 1530 | .get_bandwidth = tda18271_get_bandwidth, |
| 1531 | }; |
| 1532 | |
| 1533 | struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr, |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 1534 | struct i2c_adapter *i2c, |
| 1535 | enum tda18271_i2c_gate gate) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1536 | { |
| 1537 | struct tda18271_priv *priv = NULL; |
| 1538 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1539 | priv = kzalloc(sizeof(struct tda18271_priv), GFP_KERNEL); |
| 1540 | if (priv == NULL) |
| 1541 | return NULL; |
| 1542 | |
| 1543 | priv->i2c_addr = addr; |
| 1544 | priv->i2c_adap = i2c; |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 1545 | priv->gate = gate; |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1546 | priv->cal_initialized = false; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1547 | |
Michael Krufky | 49e7aaf | 2007-12-24 04:15:20 -0300 | [diff] [blame] | 1548 | fe->tuner_priv = priv; |
| 1549 | |
| 1550 | if (tda18271_get_id(fe) < 0) |
| 1551 | goto fail; |
| 1552 | |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1553 | if (tda18271_assign_map_layout(fe) < 0) |
| 1554 | goto fail; |
| 1555 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1556 | memcpy(&fe->ops.tuner_ops, &tda18271_tuner_ops, |
| 1557 | sizeof(struct dvb_tuner_ops)); |
| 1558 | |
Michael Krufky | efce841 | 2007-12-01 17:40:16 -0300 | [diff] [blame] | 1559 | tda18271_init_regs(fe); |
| 1560 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1561 | return fe; |
Michael Krufky | 49e7aaf | 2007-12-24 04:15:20 -0300 | [diff] [blame] | 1562 | fail: |
| 1563 | tda18271_release(fe); |
| 1564 | return NULL; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1565 | } |
| 1566 | EXPORT_SYMBOL_GPL(tda18271_attach); |
| 1567 | MODULE_DESCRIPTION("NXP TDA18271HD analog / digital tuner driver"); |
| 1568 | MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); |
| 1569 | MODULE_LICENSE("GPL"); |
Michael Krufky | 255b511 | 2008-01-01 22:52:09 -0300 | [diff] [blame^] | 1570 | MODULE_VERSION("0.2"); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 1571 | |
| 1572 | /* |
| 1573 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 1574 | * --------------------------------------------------------------------------- |
| 1575 | * Local variables: |
| 1576 | * c-basic-offset: 8 |
| 1577 | * End: |
| 1578 | */ |