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> |
| 23 | |
| 24 | #include "tda18271.h" |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 25 | #include "tda18271-priv.h" |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 26 | |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 27 | int tda18271_debug; |
Michael Krufky | 54465b0 | 2007-11-23 18:14:53 -0300 | [diff] [blame] | 28 | module_param_named(debug, tda18271_debug, int, 0644); |
Michael Krufky | 293da0e | 2007-12-02 02:45:04 -0300 | [diff] [blame] | 29 | 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] | 30 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 31 | /*---------------------------------------------------------------------*/ |
| 32 | |
Michael Krufky | 7206abb | 2007-12-09 22:13:01 -0300 | [diff] [blame] | 33 | enum tda18271_mode { |
| 34 | TDA18271_ANALOG, |
| 35 | TDA18271_DIGITAL, |
| 36 | }; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 37 | |
| 38 | struct tda18271_priv { |
| 39 | u8 i2c_addr; |
| 40 | struct i2c_adapter *i2c_adap; |
| 41 | unsigned char tda18271_regs[TDA18271_NUM_REGS]; |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 42 | |
Michael Krufky | 7206abb | 2007-12-09 22:13:01 -0300 | [diff] [blame] | 43 | enum tda18271_mode mode; |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 44 | enum tda18271_i2c_gate gate; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 45 | |
| 46 | u32 frequency; |
| 47 | u32 bandwidth; |
| 48 | }; |
| 49 | |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 50 | static int tda18271_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
| 51 | { |
| 52 | struct tda18271_priv *priv = fe->tuner_priv; |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 53 | enum tda18271_i2c_gate gate; |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 54 | int ret = 0; |
| 55 | |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 56 | switch (priv->gate) { |
| 57 | case TDA18271_GATE_DIGITAL: |
| 58 | case TDA18271_GATE_ANALOG: |
| 59 | gate = priv->gate; |
| 60 | break; |
| 61 | case TDA18271_GATE_AUTO: |
| 62 | default: |
| 63 | switch (priv->mode) { |
| 64 | case TDA18271_DIGITAL: |
| 65 | gate = TDA18271_GATE_DIGITAL; |
| 66 | break; |
| 67 | case TDA18271_ANALOG: |
| 68 | default: |
| 69 | gate = TDA18271_GATE_ANALOG; |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | switch (gate) { |
| 75 | case TDA18271_GATE_ANALOG: |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 76 | if (fe->ops.analog_ops.i2c_gate_ctrl) |
| 77 | ret = fe->ops.analog_ops.i2c_gate_ctrl(fe, enable); |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 78 | break; |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 79 | case TDA18271_GATE_DIGITAL: |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 80 | if (fe->ops.i2c_gate_ctrl) |
| 81 | ret = fe->ops.i2c_gate_ctrl(fe, enable); |
| 82 | break; |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 83 | default: |
| 84 | ret = -EINVAL; |
| 85 | break; |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | return ret; |
| 89 | }; |
| 90 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 91 | /*---------------------------------------------------------------------*/ |
| 92 | |
| 93 | static void tda18271_dump_regs(struct dvb_frontend *fe) |
| 94 | { |
| 95 | struct tda18271_priv *priv = fe->tuner_priv; |
| 96 | unsigned char *regs = priv->tda18271_regs; |
| 97 | |
Michael Krufky | 293da0e | 2007-12-02 02:45:04 -0300 | [diff] [blame] | 98 | dbg_reg("=== TDA18271 REG DUMP ===\n"); |
Michael Krufky | 5d2bf93 | 2007-12-02 17:37:38 -0300 | [diff] [blame] | 99 | dbg_reg("ID_BYTE = 0x%02x\n", 0xff & regs[R_ID]); |
| 100 | dbg_reg("THERMO_BYTE = 0x%02x\n", 0xff & regs[R_TM]); |
| 101 | dbg_reg("POWER_LEVEL_BYTE = 0x%02x\n", 0xff & regs[R_PL]); |
| 102 | dbg_reg("EASY_PROG_BYTE_1 = 0x%02x\n", 0xff & regs[R_EP1]); |
| 103 | dbg_reg("EASY_PROG_BYTE_2 = 0x%02x\n", 0xff & regs[R_EP2]); |
| 104 | dbg_reg("EASY_PROG_BYTE_3 = 0x%02x\n", 0xff & regs[R_EP3]); |
| 105 | dbg_reg("EASY_PROG_BYTE_4 = 0x%02x\n", 0xff & regs[R_EP4]); |
| 106 | dbg_reg("EASY_PROG_BYTE_5 = 0x%02x\n", 0xff & regs[R_EP5]); |
| 107 | dbg_reg("CAL_POST_DIV_BYTE = 0x%02x\n", 0xff & regs[R_CPD]); |
| 108 | dbg_reg("CAL_DIV_BYTE_1 = 0x%02x\n", 0xff & regs[R_CD1]); |
| 109 | dbg_reg("CAL_DIV_BYTE_2 = 0x%02x\n", 0xff & regs[R_CD2]); |
| 110 | dbg_reg("CAL_DIV_BYTE_3 = 0x%02x\n", 0xff & regs[R_CD3]); |
| 111 | dbg_reg("MAIN_POST_DIV_BYTE = 0x%02x\n", 0xff & regs[R_MPD]); |
| 112 | dbg_reg("MAIN_DIV_BYTE_1 = 0x%02x\n", 0xff & regs[R_MD1]); |
| 113 | dbg_reg("MAIN_DIV_BYTE_2 = 0x%02x\n", 0xff & regs[R_MD2]); |
| 114 | dbg_reg("MAIN_DIV_BYTE_3 = 0x%02x\n", 0xff & regs[R_MD3]); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | static void tda18271_read_regs(struct dvb_frontend *fe) |
| 118 | { |
| 119 | struct tda18271_priv *priv = fe->tuner_priv; |
| 120 | unsigned char *regs = priv->tda18271_regs; |
| 121 | unsigned char buf = 0x00; |
| 122 | int ret; |
| 123 | struct i2c_msg msg[] = { |
| 124 | { .addr = priv->i2c_addr, .flags = 0, |
| 125 | .buf = &buf, .len = 1 }, |
| 126 | { .addr = priv->i2c_addr, .flags = I2C_M_RD, |
| 127 | .buf = regs, .len = 16 } |
| 128 | }; |
| 129 | |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 130 | tda18271_i2c_gate_ctrl(fe, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 131 | |
| 132 | /* read all registers */ |
| 133 | ret = i2c_transfer(priv->i2c_adap, msg, 2); |
| 134 | |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 135 | tda18271_i2c_gate_ctrl(fe, 0); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 136 | |
| 137 | if (ret != 2) |
| 138 | printk("ERROR: %s: i2c_transfer returned: %d\n", |
| 139 | __FUNCTION__, ret); |
| 140 | |
Michael Krufky | 293da0e | 2007-12-02 02:45:04 -0300 | [diff] [blame] | 141 | if (tda18271_debug & DBG_REG) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 142 | tda18271_dump_regs(fe); |
| 143 | } |
| 144 | |
| 145 | static void tda18271_write_regs(struct dvb_frontend *fe, int idx, int len) |
| 146 | { |
| 147 | struct tda18271_priv *priv = fe->tuner_priv; |
| 148 | unsigned char *regs = priv->tda18271_regs; |
| 149 | unsigned char buf[TDA18271_NUM_REGS+1]; |
| 150 | struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0, |
| 151 | .buf = buf, .len = len+1 }; |
| 152 | int i, ret; |
| 153 | |
| 154 | BUG_ON((len == 0) || (idx+len > sizeof(buf))); |
| 155 | |
| 156 | buf[0] = idx; |
| 157 | for (i = 1; i <= len; i++) { |
| 158 | buf[i] = regs[idx-1+i]; |
| 159 | } |
| 160 | |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 161 | tda18271_i2c_gate_ctrl(fe, 1); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 162 | |
| 163 | /* write registers */ |
| 164 | ret = i2c_transfer(priv->i2c_adap, &msg, 1); |
| 165 | |
Michael Krufky | 7d11c53 | 2007-10-24 09:55:54 -0300 | [diff] [blame] | 166 | tda18271_i2c_gate_ctrl(fe, 0); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 167 | |
| 168 | if (ret != 1) |
| 169 | printk(KERN_WARNING "ERROR: %s: i2c_transfer returned: %d\n", |
| 170 | __FUNCTION__, ret); |
| 171 | } |
| 172 | |
| 173 | /*---------------------------------------------------------------------*/ |
| 174 | |
Michael Krufky | 22ee125 | 2007-11-22 17:13:00 -0300 | [diff] [blame] | 175 | static int tda18271_init_regs(struct dvb_frontend *fe) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 176 | { |
| 177 | struct tda18271_priv *priv = fe->tuner_priv; |
| 178 | unsigned char *regs = priv->tda18271_regs; |
| 179 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 180 | printk(KERN_INFO "tda18271: initializing registers\n"); |
| 181 | |
| 182 | /* initialize registers */ |
| 183 | regs[R_ID] = 0x83; |
| 184 | regs[R_TM] = 0x08; |
| 185 | regs[R_PL] = 0x80; |
| 186 | regs[R_EP1] = 0xc6; |
| 187 | regs[R_EP2] = 0xdf; |
| 188 | regs[R_EP3] = 0x16; |
| 189 | regs[R_EP4] = 0x60; |
| 190 | regs[R_EP5] = 0x80; |
| 191 | regs[R_CPD] = 0x80; |
| 192 | regs[R_CD1] = 0x00; |
| 193 | regs[R_CD2] = 0x00; |
| 194 | regs[R_CD3] = 0x00; |
| 195 | regs[R_MPD] = 0x00; |
| 196 | regs[R_MD1] = 0x00; |
| 197 | regs[R_MD2] = 0x00; |
| 198 | regs[R_MD3] = 0x00; |
| 199 | regs[R_EB1] = 0xff; |
| 200 | regs[R_EB2] = 0x01; |
| 201 | regs[R_EB3] = 0x84; |
| 202 | regs[R_EB4] = 0x41; |
| 203 | regs[R_EB5] = 0x01; |
| 204 | regs[R_EB6] = 0x84; |
| 205 | regs[R_EB7] = 0x40; |
| 206 | regs[R_EB8] = 0x07; |
| 207 | regs[R_EB9] = 0x00; |
| 208 | regs[R_EB10] = 0x00; |
| 209 | regs[R_EB11] = 0x96; |
| 210 | regs[R_EB12] = 0x0f; |
| 211 | regs[R_EB13] = 0xc1; |
| 212 | regs[R_EB14] = 0x00; |
| 213 | regs[R_EB15] = 0x8f; |
| 214 | regs[R_EB16] = 0x00; |
| 215 | regs[R_EB17] = 0x00; |
| 216 | regs[R_EB18] = 0x00; |
| 217 | regs[R_EB19] = 0x00; |
| 218 | regs[R_EB20] = 0x20; |
| 219 | regs[R_EB21] = 0x33; |
| 220 | regs[R_EB22] = 0x48; |
| 221 | regs[R_EB23] = 0xb0; |
| 222 | |
| 223 | tda18271_write_regs(fe, 0x00, TDA18271_NUM_REGS); |
| 224 | /* setup AGC1 & AGC2 */ |
| 225 | regs[R_EB17] = 0x00; |
| 226 | tda18271_write_regs(fe, R_EB17, 1); |
| 227 | regs[R_EB17] = 0x03; |
| 228 | tda18271_write_regs(fe, R_EB17, 1); |
| 229 | regs[R_EB17] = 0x43; |
| 230 | tda18271_write_regs(fe, R_EB17, 1); |
| 231 | regs[R_EB17] = 0x4c; |
| 232 | tda18271_write_regs(fe, R_EB17, 1); |
| 233 | |
| 234 | regs[R_EB20] = 0xa0; |
| 235 | tda18271_write_regs(fe, R_EB20, 1); |
| 236 | regs[R_EB20] = 0xa7; |
| 237 | tda18271_write_regs(fe, R_EB20, 1); |
| 238 | regs[R_EB20] = 0xe7; |
| 239 | tda18271_write_regs(fe, R_EB20, 1); |
| 240 | regs[R_EB20] = 0xec; |
| 241 | tda18271_write_regs(fe, R_EB20, 1); |
| 242 | |
| 243 | /* image rejection calibration */ |
| 244 | |
| 245 | /* low-band */ |
| 246 | regs[R_EP3] = 0x1f; |
| 247 | regs[R_EP4] = 0x66; |
| 248 | regs[R_EP5] = 0x81; |
| 249 | regs[R_CPD] = 0xcc; |
| 250 | regs[R_CD1] = 0x6c; |
| 251 | regs[R_CD2] = 0x00; |
| 252 | regs[R_CD3] = 0x00; |
| 253 | regs[R_MPD] = 0xcd; |
| 254 | regs[R_MD1] = 0x77; |
| 255 | regs[R_MD2] = 0x08; |
| 256 | regs[R_MD3] = 0x00; |
| 257 | |
| 258 | tda18271_write_regs(fe, R_EP3, 11); |
| 259 | msleep(5); /* pll locking */ |
| 260 | |
| 261 | regs[R_EP1] = 0xc6; |
| 262 | tda18271_write_regs(fe, R_EP1, 1); |
| 263 | msleep(5); /* wanted low measurement */ |
| 264 | |
| 265 | regs[R_EP3] = 0x1f; |
| 266 | regs[R_EP4] = 0x66; |
| 267 | regs[R_EP5] = 0x85; |
| 268 | regs[R_CPD] = 0xcb; |
| 269 | regs[R_CD1] = 0x66; |
| 270 | regs[R_CD2] = 0x70; |
| 271 | regs[R_CD3] = 0x00; |
| 272 | |
| 273 | tda18271_write_regs(fe, R_EP3, 7); |
| 274 | msleep(5); /* pll locking */ |
| 275 | |
| 276 | regs[R_EP2] = 0xdf; |
| 277 | tda18271_write_regs(fe, R_EP2, 1); |
| 278 | msleep(30); /* image low optimization completion */ |
| 279 | |
| 280 | /* mid-band */ |
| 281 | regs[R_EP3] = 0x1f; |
| 282 | regs[R_EP4] = 0x66; |
| 283 | regs[R_EP5] = 0x82; |
| 284 | regs[R_CPD] = 0xa8; |
| 285 | regs[R_CD1] = 0x66; |
| 286 | regs[R_CD2] = 0x00; |
| 287 | regs[R_CD3] = 0x00; |
| 288 | regs[R_MPD] = 0xa9; |
| 289 | regs[R_MD1] = 0x73; |
| 290 | regs[R_MD2] = 0x1a; |
| 291 | regs[R_MD3] = 0x00; |
| 292 | |
| 293 | tda18271_write_regs(fe, R_EP3, 11); |
| 294 | msleep(5); /* pll locking */ |
| 295 | |
| 296 | regs[R_EP1] = 0xc6; |
| 297 | tda18271_write_regs(fe, R_EP1, 1); |
| 298 | msleep(5); /* wanted mid measurement */ |
| 299 | |
| 300 | regs[R_EP3] = 0x1f; |
| 301 | regs[R_EP4] = 0x66; |
| 302 | regs[R_EP5] = 0x86; |
| 303 | regs[R_CPD] = 0xa8; |
| 304 | regs[R_CD1] = 0x66; |
| 305 | regs[R_CD2] = 0xa0; |
| 306 | regs[R_CD3] = 0x00; |
| 307 | |
| 308 | tda18271_write_regs(fe, R_EP3, 7); |
| 309 | msleep(5); /* pll locking */ |
| 310 | |
| 311 | regs[R_EP2] = 0xdf; |
| 312 | tda18271_write_regs(fe, R_EP2, 1); |
| 313 | msleep(30); /* image mid optimization completion */ |
| 314 | |
| 315 | /* high-band */ |
| 316 | regs[R_EP3] = 0x1f; |
| 317 | regs[R_EP4] = 0x66; |
| 318 | regs[R_EP5] = 0x83; |
| 319 | regs[R_CPD] = 0x98; |
| 320 | regs[R_CD1] = 0x65; |
| 321 | regs[R_CD2] = 0x00; |
| 322 | regs[R_CD3] = 0x00; |
| 323 | regs[R_MPD] = 0x99; |
| 324 | regs[R_MD1] = 0x71; |
| 325 | regs[R_MD2] = 0xcd; |
| 326 | regs[R_MD3] = 0x00; |
| 327 | |
| 328 | tda18271_write_regs(fe, R_EP3, 11); |
| 329 | msleep(5); /* pll locking */ |
| 330 | |
| 331 | regs[R_EP1] = 0xc6; |
| 332 | tda18271_write_regs(fe, R_EP1, 1); |
| 333 | msleep(5); /* wanted high measurement */ |
| 334 | |
| 335 | regs[R_EP3] = 0x1f; |
| 336 | regs[R_EP4] = 0x66; |
| 337 | regs[R_EP5] = 0x87; |
| 338 | regs[R_CPD] = 0x98; |
| 339 | regs[R_CD1] = 0x65; |
| 340 | regs[R_CD2] = 0x50; |
| 341 | regs[R_CD3] = 0x00; |
| 342 | |
| 343 | tda18271_write_regs(fe, R_EP3, 7); |
| 344 | msleep(5); /* pll locking */ |
| 345 | |
| 346 | regs[R_EP2] = 0xdf; |
| 347 | |
| 348 | tda18271_write_regs(fe, R_EP2, 1); |
| 349 | msleep(30); /* image high optimization completion */ |
| 350 | |
| 351 | regs[R_EP4] = 0x64; |
| 352 | tda18271_write_regs(fe, R_EP4, 1); |
| 353 | |
| 354 | regs[R_EP1] = 0xc6; |
| 355 | tda18271_write_regs(fe, R_EP1, 1); |
Michael Krufky | 22ee125 | 2007-11-22 17:13:00 -0300 | [diff] [blame] | 356 | |
| 357 | return 0; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 358 | } |
| 359 | |
Michael Krufky | efce841 | 2007-12-01 17:40:16 -0300 | [diff] [blame] | 360 | static int tda18271_init(struct dvb_frontend *fe) |
| 361 | { |
| 362 | struct tda18271_priv *priv = fe->tuner_priv; |
| 363 | unsigned char *regs = priv->tda18271_regs; |
| 364 | |
| 365 | tda18271_read_regs(fe); |
| 366 | |
| 367 | /* test IR_CAL_OK to see if we need init */ |
| 368 | if ((regs[R_EP1] & 0x08) == 0) |
| 369 | tda18271_init_regs(fe); |
| 370 | |
| 371 | return 0; |
| 372 | } |
| 373 | |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame^] | 374 | static int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq) |
| 375 | { |
| 376 | /* Sets Main Post-Divider & Divider bytes, but does not write them */ |
| 377 | struct tda18271_priv *priv = fe->tuner_priv; |
| 378 | unsigned char *regs = priv->tda18271_regs; |
| 379 | u8 d, pd; |
| 380 | u32 div; |
| 381 | |
| 382 | tda18271_lookup_main_pll(&freq, &pd, &d); |
| 383 | |
| 384 | regs[R_MPD] = (0x77 & pd); |
| 385 | |
| 386 | switch (priv->mode) { |
| 387 | case TDA18271_ANALOG: |
| 388 | regs[R_MPD] &= ~0x08; |
| 389 | break; |
| 390 | case TDA18271_DIGITAL: |
| 391 | regs[R_MPD] |= 0x08; |
| 392 | break; |
| 393 | } |
| 394 | |
| 395 | div = ((d * (freq / 1000)) << 7) / 125; |
| 396 | |
| 397 | regs[R_MD1] = 0x7f & (div >> 16); |
| 398 | regs[R_MD2] = 0xff & (div >> 8); |
| 399 | regs[R_MD3] = 0xff & div; |
| 400 | |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq) |
| 405 | { |
| 406 | /* Sets Cal Post-Divider & Divider bytes, but does not write them */ |
| 407 | struct tda18271_priv *priv = fe->tuner_priv; |
| 408 | unsigned char *regs = priv->tda18271_regs; |
| 409 | u8 d, pd; |
| 410 | u32 div; |
| 411 | |
| 412 | tda18271_lookup_cal_pll(&freq, &pd, &d); |
| 413 | |
| 414 | regs[R_CPD] = pd; |
| 415 | |
| 416 | div = ((d * (freq / 1000)) << 7) / 125; |
| 417 | |
| 418 | regs[R_CD1] = 0x7f & (div >> 16); |
| 419 | regs[R_CD2] = 0xff & (div >> 8); |
| 420 | regs[R_CD3] = 0xff & div; |
| 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 425 | static int tda18271_tune(struct dvb_frontend *fe, |
| 426 | u32 ifc, u32 freq, u32 bw, u8 std) |
| 427 | { |
| 428 | struct tda18271_priv *priv = fe->tuner_priv; |
| 429 | unsigned char *regs = priv->tda18271_regs; |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame^] | 430 | u32 N = 0; |
| 431 | u8 val; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 432 | |
Michael Krufky | 1457263 | 2007-12-02 02:32:49 -0300 | [diff] [blame] | 433 | tda18271_init(fe); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 434 | |
Michael Krufky | 293da0e | 2007-12-02 02:45:04 -0300 | [diff] [blame] | 435 | dbg_info("freq = %d, ifc = %d\n", freq, ifc); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 436 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 437 | /* RF tracking filter calibration */ |
| 438 | |
| 439 | /* calculate BP_Filter */ |
Michael Krufky | f0bd504 | 2007-12-24 04:35:21 -0300 | [diff] [blame] | 440 | tda18271_lookup_bp_filter(&freq, &val); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 441 | |
| 442 | regs[R_EP1] &= ~0x07; /* clear bp filter bits */ |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 443 | regs[R_EP1] |= val; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 444 | tda18271_write_regs(fe, R_EP1, 1); |
| 445 | |
| 446 | regs[R_EB4] &= 0x07; |
| 447 | regs[R_EB4] |= 0x60; |
| 448 | tda18271_write_regs(fe, R_EB4, 1); |
| 449 | |
| 450 | regs[R_EB7] = 0x60; |
| 451 | tda18271_write_regs(fe, R_EB7, 1); |
| 452 | |
| 453 | regs[R_EB14] = 0x00; |
| 454 | tda18271_write_regs(fe, R_EB14, 1); |
| 455 | |
| 456 | regs[R_EB20] = 0xcc; |
| 457 | tda18271_write_regs(fe, R_EB20, 1); |
| 458 | |
| 459 | /* set CAL mode to RF tracking filter calibration */ |
Michael Krufky | 26501a7 | 2007-12-21 14:28:46 -0300 | [diff] [blame] | 460 | regs[R_EP4] |= 0x03; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 461 | |
| 462 | /* calculate CAL PLL */ |
| 463 | |
| 464 | switch (priv->mode) { |
| 465 | case TDA18271_ANALOG: |
| 466 | N = freq - 1250000; |
| 467 | break; |
| 468 | case TDA18271_DIGITAL: |
| 469 | N = freq + bw / 2; |
| 470 | break; |
| 471 | } |
| 472 | |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame^] | 473 | tda18271_calc_cal_pll(fe, N); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 474 | |
| 475 | /* calculate MAIN PLL */ |
| 476 | |
| 477 | switch (priv->mode) { |
| 478 | case TDA18271_ANALOG: |
| 479 | N = freq - 250000; |
| 480 | break; |
| 481 | case TDA18271_DIGITAL: |
| 482 | N = freq + bw / 2 + 1000000; |
| 483 | break; |
| 484 | } |
| 485 | |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame^] | 486 | tda18271_calc_main_pll(fe, N); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 487 | |
| 488 | tda18271_write_regs(fe, R_EP3, 11); |
| 489 | msleep(5); /* RF tracking filter calibration initialization */ |
| 490 | |
| 491 | /* search for K,M,CO for RF Calibration */ |
Michael Krufky | f0bd504 | 2007-12-24 04:35:21 -0300 | [diff] [blame] | 492 | tda18271_lookup_km(&freq, &val); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 493 | |
| 494 | regs[R_EB13] &= 0x83; |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 495 | regs[R_EB13] |= val; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 496 | tda18271_write_regs(fe, R_EB13, 1); |
| 497 | |
| 498 | /* search for RF_BAND */ |
Michael Krufky | f0bd504 | 2007-12-24 04:35:21 -0300 | [diff] [blame] | 499 | tda18271_lookup_rf_band(&freq, &val); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 500 | |
| 501 | regs[R_EP2] &= ~0xe0; /* clear rf band bits */ |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 502 | regs[R_EP2] |= (val << 5); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 503 | |
| 504 | /* search for Gain_Taper */ |
Michael Krufky | f0bd504 | 2007-12-24 04:35:21 -0300 | [diff] [blame] | 505 | tda18271_lookup_gain_taper(&freq, &val); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 506 | |
| 507 | regs[R_EP2] &= ~0x1f; /* clear gain taper bits */ |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 508 | regs[R_EP2] |= val; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 509 | |
| 510 | tda18271_write_regs(fe, R_EP2, 1); |
| 511 | tda18271_write_regs(fe, R_EP1, 1); |
| 512 | tda18271_write_regs(fe, R_EP2, 1); |
| 513 | tda18271_write_regs(fe, R_EP1, 1); |
| 514 | |
| 515 | regs[R_EB4] &= 0x07; |
| 516 | regs[R_EB4] |= 0x40; |
| 517 | tda18271_write_regs(fe, R_EB4, 1); |
| 518 | |
| 519 | regs[R_EB7] = 0x40; |
| 520 | tda18271_write_regs(fe, R_EB7, 1); |
| 521 | msleep(10); |
| 522 | |
| 523 | regs[R_EB20] = 0xec; |
| 524 | tda18271_write_regs(fe, R_EB20, 1); |
| 525 | msleep(60); /* RF tracking filter calibration completion */ |
| 526 | |
| 527 | regs[R_EP4] &= ~0x03; /* set cal mode to normal */ |
| 528 | tda18271_write_regs(fe, R_EP4, 1); |
| 529 | |
| 530 | tda18271_write_regs(fe, R_EP1, 1); |
| 531 | |
| 532 | /* RF tracking filer correction for VHF_Low band */ |
Michael Krufky | f0bd504 | 2007-12-24 04:35:21 -0300 | [diff] [blame] | 533 | tda18271_lookup_rf_cal(&freq, &val); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 534 | |
| 535 | /* VHF_Low band only */ |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 536 | if (val != 0) { |
| 537 | regs[R_EB14] = val; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 538 | tda18271_write_regs(fe, R_EB14, 1); |
| 539 | } |
| 540 | |
| 541 | /* Channel Configuration */ |
| 542 | |
| 543 | switch (priv->mode) { |
| 544 | case TDA18271_ANALOG: |
| 545 | regs[R_EB22] = 0x2c; |
| 546 | break; |
| 547 | case TDA18271_DIGITAL: |
| 548 | regs[R_EB22] = 0x37; |
| 549 | break; |
| 550 | } |
| 551 | tda18271_write_regs(fe, R_EB22, 1); |
| 552 | |
| 553 | regs[R_EP1] |= 0x40; /* set dis power level on */ |
| 554 | |
| 555 | /* set standard */ |
| 556 | regs[R_EP3] &= ~0x1f; /* clear std bits */ |
| 557 | |
| 558 | /* see table 22 */ |
| 559 | regs[R_EP3] |= std; |
| 560 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 561 | regs[R_EP4] &= ~0x03; /* set cal mode to normal */ |
| 562 | |
| 563 | regs[R_EP4] &= ~0x1c; /* clear if level bits */ |
| 564 | switch (priv->mode) { |
| 565 | case TDA18271_ANALOG: |
| 566 | regs[R_MPD] &= ~0x80; /* IF notch = 0 */ |
| 567 | break; |
| 568 | case TDA18271_DIGITAL: |
| 569 | regs[R_EP4] |= 0x04; |
| 570 | regs[R_MPD] |= 0x80; |
| 571 | break; |
| 572 | } |
| 573 | |
| 574 | regs[R_EP4] &= ~0x80; /* turn this bit on only for fm */ |
| 575 | |
Michael Krufky | aaeccba | 2007-12-02 11:03:57 -0300 | [diff] [blame] | 576 | /* image rejection validity EP5[2:0] */ |
Michael Krufky | f0bd504 | 2007-12-24 04:35:21 -0300 | [diff] [blame] | 577 | tda18271_lookup_ir_measure(&freq, &val); |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 578 | |
Michael Krufky | aaeccba | 2007-12-02 11:03:57 -0300 | [diff] [blame] | 579 | regs[R_EP5] &= ~0x07; |
Michael Krufky | b5f3e1e | 2007-12-02 16:36:05 -0300 | [diff] [blame] | 580 | regs[R_EP5] |= val; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 581 | |
| 582 | /* calculate MAIN PLL */ |
| 583 | N = freq + ifc; |
| 584 | |
Michael Krufky | fe0bf6d | 2007-12-24 05:05:05 -0300 | [diff] [blame^] | 585 | tda18271_calc_main_pll(fe, N); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 586 | |
| 587 | tda18271_write_regs(fe, R_TM, 15); |
| 588 | msleep(5); |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 589 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | /* ------------------------------------------------------------------ */ |
| 594 | |
| 595 | static int tda18271_set_params(struct dvb_frontend *fe, |
| 596 | struct dvb_frontend_parameters *params) |
| 597 | { |
| 598 | struct tda18271_priv *priv = fe->tuner_priv; |
| 599 | u8 std; |
| 600 | u32 bw, sgIF = 0; |
| 601 | |
| 602 | u32 freq = params->frequency; |
| 603 | |
| 604 | priv->mode = TDA18271_DIGITAL; |
| 605 | |
| 606 | /* see table 22 */ |
| 607 | if (fe->ops.info.type == FE_ATSC) { |
| 608 | switch (params->u.vsb.modulation) { |
| 609 | case VSB_8: |
| 610 | case VSB_16: |
| 611 | std = 0x1b; /* device-specific (spec says 0x1c) */ |
| 612 | sgIF = 5380000; |
| 613 | break; |
| 614 | case QAM_64: |
| 615 | case QAM_256: |
| 616 | std = 0x18; /* device-specific (spec says 0x1d) */ |
| 617 | sgIF = 4000000; |
| 618 | break; |
| 619 | default: |
| 620 | printk(KERN_WARNING "%s: modulation not set!\n", |
| 621 | __FUNCTION__); |
| 622 | return -EINVAL; |
| 623 | } |
Michael Krufky | 14e3c15 | 2007-12-07 00:33:08 -0300 | [diff] [blame] | 624 | #if 0 |
| 625 | /* userspace request is already center adjusted */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 626 | freq += 1750000; /* Adjust to center (+1.75MHZ) */ |
Michael Krufky | 14e3c15 | 2007-12-07 00:33:08 -0300 | [diff] [blame] | 627 | #endif |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 628 | bw = 6000000; |
| 629 | } else if (fe->ops.info.type == FE_OFDM) { |
| 630 | switch (params->u.ofdm.bandwidth) { |
| 631 | case BANDWIDTH_6_MHZ: |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 632 | std = 0x1b; /* device-specific (spec says 0x1c) */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 633 | bw = 6000000; |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 634 | sgIF = 3300000; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 635 | break; |
| 636 | case BANDWIDTH_7_MHZ: |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 637 | std = 0x19; /* device-specific (spec says 0x1d) */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 638 | bw = 7000000; |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 639 | sgIF = 3800000; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 640 | break; |
| 641 | case BANDWIDTH_8_MHZ: |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 642 | std = 0x1a; /* device-specific (spec says 0x1e) */ |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 643 | bw = 8000000; |
Michael Krufky | 6ca04de | 2007-11-23 16:52:15 -0300 | [diff] [blame] | 644 | sgIF = 4300000; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 645 | break; |
| 646 | default: |
| 647 | printk(KERN_WARNING "%s: bandwidth not set!\n", |
| 648 | __FUNCTION__); |
| 649 | return -EINVAL; |
| 650 | } |
| 651 | } else { |
| 652 | printk(KERN_WARNING "%s: modulation type not supported!\n", |
| 653 | __FUNCTION__); |
| 654 | return -EINVAL; |
| 655 | } |
| 656 | |
| 657 | return tda18271_tune(fe, sgIF, freq, bw, std); |
| 658 | } |
| 659 | |
| 660 | static int tda18271_set_analog_params(struct dvb_frontend *fe, |
| 661 | struct analog_parameters *params) |
| 662 | { |
| 663 | struct tda18271_priv *priv = fe->tuner_priv; |
| 664 | u8 std; |
| 665 | unsigned int sgIF; |
| 666 | char *mode; |
| 667 | |
| 668 | priv->mode = TDA18271_ANALOG; |
| 669 | |
| 670 | /* see table 22 */ |
| 671 | if (params->std & V4L2_STD_MN) { |
| 672 | std = 0x0d; |
| 673 | sgIF = 92; |
| 674 | mode = "MN"; |
| 675 | } else if (params->std & V4L2_STD_B) { |
| 676 | std = 0x0e; |
| 677 | sgIF = 108; |
| 678 | mode = "B"; |
| 679 | } else if (params->std & V4L2_STD_GH) { |
| 680 | std = 0x0f; |
| 681 | sgIF = 124; |
| 682 | mode = "GH"; |
| 683 | } else if (params->std & V4L2_STD_PAL_I) { |
| 684 | std = 0x0f; |
| 685 | sgIF = 124; |
| 686 | mode = "I"; |
| 687 | } else if (params->std & V4L2_STD_DK) { |
| 688 | std = 0x0f; |
| 689 | sgIF = 124; |
| 690 | mode = "DK"; |
| 691 | } else if (params->std & V4L2_STD_SECAM_L) { |
| 692 | std = 0x0f; |
| 693 | sgIF = 124; |
| 694 | mode = "L"; |
| 695 | } else if (params->std & V4L2_STD_SECAM_LC) { |
| 696 | std = 0x0f; |
| 697 | sgIF = 20; |
| 698 | mode = "LC"; |
| 699 | } else { |
| 700 | std = 0x0f; |
| 701 | sgIF = 124; |
| 702 | mode = "xx"; |
| 703 | } |
| 704 | |
| 705 | if (params->mode == V4L2_TUNER_RADIO) |
| 706 | sgIF = 88; /* if frequency is 5.5 MHz */ |
| 707 | |
Michael Krufky | 293da0e | 2007-12-02 02:45:04 -0300 | [diff] [blame] | 708 | dbg_info("setting tda18271 to system %s\n", mode); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 709 | |
| 710 | return tda18271_tune(fe, sgIF * 62500, params->frequency * 62500, |
| 711 | 0, std); |
| 712 | } |
| 713 | |
| 714 | static int tda18271_release(struct dvb_frontend *fe) |
| 715 | { |
| 716 | kfree(fe->tuner_priv); |
| 717 | fe->tuner_priv = NULL; |
| 718 | return 0; |
| 719 | } |
| 720 | |
| 721 | static int tda18271_get_frequency(struct dvb_frontend *fe, u32 *frequency) |
| 722 | { |
| 723 | struct tda18271_priv *priv = fe->tuner_priv; |
| 724 | *frequency = priv->frequency; |
| 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | static int tda18271_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth) |
| 729 | { |
| 730 | struct tda18271_priv *priv = fe->tuner_priv; |
| 731 | *bandwidth = priv->bandwidth; |
| 732 | return 0; |
| 733 | } |
| 734 | |
Michael Krufky | 49e7aaf | 2007-12-24 04:15:20 -0300 | [diff] [blame] | 735 | static int tda18271_get_id(struct dvb_frontend *fe) |
| 736 | { |
| 737 | struct tda18271_priv *priv = fe->tuner_priv; |
| 738 | unsigned char *regs = priv->tda18271_regs; |
| 739 | char *name; |
| 740 | int ret = 0; |
| 741 | |
| 742 | tda18271_read_regs(fe); |
| 743 | |
| 744 | switch (regs[R_ID] & 0x7f) { |
| 745 | case 3: |
| 746 | name = "TDA18271HD/C1"; |
| 747 | break; |
| 748 | case 4: |
| 749 | name = "TDA18271HD/C2"; |
| 750 | ret = -EPROTONOSUPPORT; |
| 751 | break; |
| 752 | default: |
| 753 | name = "Unknown device"; |
| 754 | ret = -EINVAL; |
| 755 | break; |
| 756 | } |
| 757 | |
| 758 | dbg_info("%s detected @ %d-%04x%s\n", name, |
| 759 | i2c_adapter_id(priv->i2c_adap), priv->i2c_addr, |
| 760 | (0 == ret) ? "" : ", device not supported."); |
| 761 | |
| 762 | return ret; |
| 763 | } |
| 764 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 765 | static struct dvb_tuner_ops tda18271_tuner_ops = { |
| 766 | .info = { |
| 767 | .name = "NXP TDA18271HD", |
| 768 | .frequency_min = 45000000, |
| 769 | .frequency_max = 864000000, |
| 770 | .frequency_step = 62500 |
| 771 | }, |
Michael Krufky | efce841 | 2007-12-01 17:40:16 -0300 | [diff] [blame] | 772 | .init = tda18271_init, |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 773 | .set_params = tda18271_set_params, |
| 774 | .set_analog_params = tda18271_set_analog_params, |
| 775 | .release = tda18271_release, |
| 776 | .get_frequency = tda18271_get_frequency, |
| 777 | .get_bandwidth = tda18271_get_bandwidth, |
| 778 | }; |
| 779 | |
| 780 | struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr, |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 781 | struct i2c_adapter *i2c, |
| 782 | enum tda18271_i2c_gate gate) |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 783 | { |
| 784 | struct tda18271_priv *priv = NULL; |
| 785 | |
Michael Krufky | 293da0e | 2007-12-02 02:45:04 -0300 | [diff] [blame] | 786 | dbg_info("@ %d-%04x\n", i2c_adapter_id(i2c), addr); |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 787 | priv = kzalloc(sizeof(struct tda18271_priv), GFP_KERNEL); |
| 788 | if (priv == NULL) |
| 789 | return NULL; |
| 790 | |
| 791 | priv->i2c_addr = addr; |
| 792 | priv->i2c_adap = i2c; |
Michael Krufky | e435f95 | 2007-12-09 22:23:30 -0300 | [diff] [blame] | 793 | priv->gate = gate; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 794 | |
Michael Krufky | 49e7aaf | 2007-12-24 04:15:20 -0300 | [diff] [blame] | 795 | fe->tuner_priv = priv; |
| 796 | |
| 797 | if (tda18271_get_id(fe) < 0) |
| 798 | goto fail; |
| 799 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 800 | memcpy(&fe->ops.tuner_ops, &tda18271_tuner_ops, |
| 801 | sizeof(struct dvb_tuner_ops)); |
| 802 | |
Michael Krufky | efce841 | 2007-12-01 17:40:16 -0300 | [diff] [blame] | 803 | tda18271_init_regs(fe); |
| 804 | |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 805 | return fe; |
Michael Krufky | 49e7aaf | 2007-12-24 04:15:20 -0300 | [diff] [blame] | 806 | fail: |
| 807 | tda18271_release(fe); |
| 808 | return NULL; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 809 | } |
| 810 | EXPORT_SYMBOL_GPL(tda18271_attach); |
| 811 | MODULE_DESCRIPTION("NXP TDA18271HD analog / digital tuner driver"); |
| 812 | MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); |
| 813 | MODULE_LICENSE("GPL"); |
| 814 | |
| 815 | /* |
| 816 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 817 | * --------------------------------------------------------------------------- |
| 818 | * Local variables: |
| 819 | * c-basic-offset: 8 |
| 820 | * End: |
| 821 | */ |