Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1 | /* |
| 2 | * NXP TDA10071 + Conexant CX24118A DVB-S/S2 demodulator + tuner driver |
| 3 | * |
| 4 | * Copyright (C) 2011 Antti Palosaari <crope@iki.fi> |
| 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 along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | #include "tda10071_priv.h" |
| 22 | |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 23 | /* Max transfer size done by I2C transfer functions */ |
| 24 | #define MAX_XFER_SIZE 64 |
| 25 | |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 26 | static struct dvb_frontend_ops tda10071_ops; |
| 27 | |
| 28 | /* write multiple registers */ |
| 29 | static int tda10071_wr_regs(struct tda10071_priv *priv, u8 reg, u8 *val, |
| 30 | int len) |
| 31 | { |
| 32 | int ret; |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 33 | u8 buf[MAX_XFER_SIZE]; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 34 | struct i2c_msg msg[1] = { |
| 35 | { |
Michael Krufky | 41f55d5 | 2012-12-16 19:37:11 -0300 | [diff] [blame] | 36 | .addr = priv->cfg.demod_i2c_addr, |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 37 | .flags = 0, |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 38 | .len = 1 + len, |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 39 | .buf = buf, |
| 40 | } |
| 41 | }; |
| 42 | |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 43 | if (1 + len > sizeof(buf)) { |
| 44 | dev_warn(&priv->i2c->dev, |
Antti Palosaari | 116802f | 2014-02-11 15:13:46 -0300 | [diff] [blame] | 45 | "%s: i2c wr reg=%04x: len=%d is too big!\n", |
| 46 | KBUILD_MODNAME, reg, len); |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 47 | return -EINVAL; |
| 48 | } |
| 49 | |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 50 | buf[0] = reg; |
| 51 | memcpy(&buf[1], val, len); |
| 52 | |
| 53 | ret = i2c_transfer(priv->i2c, msg, 1); |
| 54 | if (ret == 1) { |
| 55 | ret = 0; |
| 56 | } else { |
Antti Palosaari | 116802f | 2014-02-11 15:13:46 -0300 | [diff] [blame] | 57 | dev_warn(&priv->i2c->dev, |
| 58 | "%s: i2c wr failed=%d reg=%02x len=%d\n", |
| 59 | KBUILD_MODNAME, ret, reg, len); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 60 | ret = -EREMOTEIO; |
| 61 | } |
| 62 | return ret; |
| 63 | } |
| 64 | |
| 65 | /* read multiple registers */ |
| 66 | static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val, |
| 67 | int len) |
| 68 | { |
| 69 | int ret; |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 70 | u8 buf[MAX_XFER_SIZE]; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 71 | struct i2c_msg msg[2] = { |
| 72 | { |
Michael Krufky | 41f55d5 | 2012-12-16 19:37:11 -0300 | [diff] [blame] | 73 | .addr = priv->cfg.demod_i2c_addr, |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 74 | .flags = 0, |
| 75 | .len = 1, |
| 76 | .buf = ®, |
| 77 | }, { |
Michael Krufky | 41f55d5 | 2012-12-16 19:37:11 -0300 | [diff] [blame] | 78 | .addr = priv->cfg.demod_i2c_addr, |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 79 | .flags = I2C_M_RD, |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 80 | .len = len, |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 81 | .buf = buf, |
| 82 | } |
| 83 | }; |
| 84 | |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 85 | if (len > sizeof(buf)) { |
| 86 | dev_warn(&priv->i2c->dev, |
Antti Palosaari | 116802f | 2014-02-11 15:13:46 -0300 | [diff] [blame] | 87 | "%s: i2c wr reg=%04x: len=%d is too big!\n", |
| 88 | KBUILD_MODNAME, reg, len); |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 89 | return -EINVAL; |
| 90 | } |
| 91 | |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 92 | ret = i2c_transfer(priv->i2c, msg, 2); |
| 93 | if (ret == 2) { |
| 94 | memcpy(val, buf, len); |
| 95 | ret = 0; |
| 96 | } else { |
Antti Palosaari | 116802f | 2014-02-11 15:13:46 -0300 | [diff] [blame] | 97 | dev_warn(&priv->i2c->dev, |
| 98 | "%s: i2c rd failed=%d reg=%02x len=%d\n", |
| 99 | KBUILD_MODNAME, ret, reg, len); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 100 | ret = -EREMOTEIO; |
| 101 | } |
| 102 | return ret; |
| 103 | } |
| 104 | |
| 105 | /* write single register */ |
| 106 | static int tda10071_wr_reg(struct tda10071_priv *priv, u8 reg, u8 val) |
| 107 | { |
| 108 | return tda10071_wr_regs(priv, reg, &val, 1); |
| 109 | } |
| 110 | |
| 111 | /* read single register */ |
| 112 | static int tda10071_rd_reg(struct tda10071_priv *priv, u8 reg, u8 *val) |
| 113 | { |
| 114 | return tda10071_rd_regs(priv, reg, val, 1); |
| 115 | } |
| 116 | |
| 117 | /* write single register with mask */ |
Mauro Carvalho Chehab | babb618 | 2012-10-27 11:27:24 -0300 | [diff] [blame] | 118 | static int tda10071_wr_reg_mask(struct tda10071_priv *priv, |
| 119 | u8 reg, u8 val, u8 mask) |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 120 | { |
| 121 | int ret; |
| 122 | u8 tmp; |
| 123 | |
| 124 | /* no need for read if whole reg is written */ |
| 125 | if (mask != 0xff) { |
| 126 | ret = tda10071_rd_regs(priv, reg, &tmp, 1); |
| 127 | if (ret) |
| 128 | return ret; |
| 129 | |
| 130 | val &= mask; |
| 131 | tmp &= ~mask; |
| 132 | val |= tmp; |
| 133 | } |
| 134 | |
| 135 | return tda10071_wr_regs(priv, reg, &val, 1); |
| 136 | } |
| 137 | |
| 138 | /* read single register with mask */ |
Mauro Carvalho Chehab | babb618 | 2012-10-27 11:27:24 -0300 | [diff] [blame] | 139 | static int tda10071_rd_reg_mask(struct tda10071_priv *priv, |
| 140 | u8 reg, u8 *val, u8 mask) |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 141 | { |
| 142 | int ret, i; |
| 143 | u8 tmp; |
| 144 | |
| 145 | ret = tda10071_rd_regs(priv, reg, &tmp, 1); |
| 146 | if (ret) |
| 147 | return ret; |
| 148 | |
| 149 | tmp &= mask; |
| 150 | |
| 151 | /* find position of the first bit */ |
| 152 | for (i = 0; i < 8; i++) { |
| 153 | if ((mask >> i) & 0x01) |
| 154 | break; |
| 155 | } |
| 156 | *val = tmp >> i; |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | /* execute firmware command */ |
| 162 | static int tda10071_cmd_execute(struct tda10071_priv *priv, |
| 163 | struct tda10071_cmd *cmd) |
| 164 | { |
| 165 | int ret, i; |
| 166 | u8 tmp; |
| 167 | |
| 168 | if (!priv->warm) { |
| 169 | ret = -EFAULT; |
| 170 | goto error; |
| 171 | } |
| 172 | |
| 173 | /* write cmd and args for firmware */ |
| 174 | ret = tda10071_wr_regs(priv, 0x00, cmd->args, cmd->len); |
| 175 | if (ret) |
| 176 | goto error; |
| 177 | |
| 178 | /* start cmd execution */ |
| 179 | ret = tda10071_wr_reg(priv, 0x1f, 1); |
| 180 | if (ret) |
| 181 | goto error; |
| 182 | |
| 183 | /* wait cmd execution terminate */ |
| 184 | for (i = 1000, tmp = 1; i && tmp; i--) { |
| 185 | ret = tda10071_rd_reg(priv, 0x1f, &tmp); |
| 186 | if (ret) |
| 187 | goto error; |
| 188 | |
Antti Palosaari | d102b73 | 2011-09-13 11:51:23 -0300 | [diff] [blame] | 189 | usleep_range(200, 5000); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 190 | } |
| 191 | |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 192 | dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 193 | |
| 194 | if (i == 0) { |
| 195 | ret = -ETIMEDOUT; |
| 196 | goto error; |
| 197 | } |
| 198 | |
| 199 | return ret; |
| 200 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 201 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 202 | return ret; |
| 203 | } |
| 204 | |
| 205 | static int tda10071_set_tone(struct dvb_frontend *fe, |
| 206 | fe_sec_tone_mode_t fe_sec_tone_mode) |
| 207 | { |
| 208 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 209 | struct tda10071_cmd cmd; |
| 210 | int ret; |
| 211 | u8 tone; |
| 212 | |
| 213 | if (!priv->warm) { |
| 214 | ret = -EFAULT; |
| 215 | goto error; |
| 216 | } |
| 217 | |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 218 | dev_dbg(&priv->i2c->dev, "%s: tone_mode=%d\n", __func__, |
| 219 | fe_sec_tone_mode); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 220 | |
| 221 | switch (fe_sec_tone_mode) { |
| 222 | case SEC_TONE_ON: |
| 223 | tone = 1; |
| 224 | break; |
| 225 | case SEC_TONE_OFF: |
| 226 | tone = 0; |
| 227 | break; |
| 228 | default: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 229 | dev_dbg(&priv->i2c->dev, "%s: invalid fe_sec_tone_mode\n", |
| 230 | __func__); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 231 | ret = -EINVAL; |
| 232 | goto error; |
| 233 | } |
| 234 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 235 | cmd.args[0] = CMD_LNB_PCB_CONFIG; |
| 236 | cmd.args[1] = 0; |
| 237 | cmd.args[2] = 0x00; |
| 238 | cmd.args[3] = 0x00; |
| 239 | cmd.args[4] = tone; |
| 240 | cmd.len = 5; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 241 | ret = tda10071_cmd_execute(priv, &cmd); |
| 242 | if (ret) |
| 243 | goto error; |
| 244 | |
| 245 | return ret; |
| 246 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 247 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 248 | return ret; |
| 249 | } |
| 250 | |
| 251 | static int tda10071_set_voltage(struct dvb_frontend *fe, |
| 252 | fe_sec_voltage_t fe_sec_voltage) |
| 253 | { |
| 254 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 255 | struct tda10071_cmd cmd; |
| 256 | int ret; |
| 257 | u8 voltage; |
| 258 | |
| 259 | if (!priv->warm) { |
| 260 | ret = -EFAULT; |
| 261 | goto error; |
| 262 | } |
| 263 | |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 264 | dev_dbg(&priv->i2c->dev, "%s: voltage=%d\n", __func__, fe_sec_voltage); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 265 | |
| 266 | switch (fe_sec_voltage) { |
| 267 | case SEC_VOLTAGE_13: |
| 268 | voltage = 0; |
| 269 | break; |
| 270 | case SEC_VOLTAGE_18: |
| 271 | voltage = 1; |
| 272 | break; |
| 273 | case SEC_VOLTAGE_OFF: |
| 274 | voltage = 0; |
| 275 | break; |
| 276 | default: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 277 | dev_dbg(&priv->i2c->dev, "%s: invalid fe_sec_voltage\n", |
| 278 | __func__); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 279 | ret = -EINVAL; |
| 280 | goto error; |
Peter Senna Tschudin | 8f5c997 | 2012-09-07 11:24:43 -0300 | [diff] [blame] | 281 | } |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 282 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 283 | cmd.args[0] = CMD_LNB_SET_DC_LEVEL; |
| 284 | cmd.args[1] = 0; |
| 285 | cmd.args[2] = voltage; |
| 286 | cmd.len = 3; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 287 | ret = tda10071_cmd_execute(priv, &cmd); |
| 288 | if (ret) |
| 289 | goto error; |
| 290 | |
| 291 | return ret; |
| 292 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 293 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe, |
| 298 | struct dvb_diseqc_master_cmd *diseqc_cmd) |
| 299 | { |
| 300 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 301 | struct tda10071_cmd cmd; |
| 302 | int ret, i; |
| 303 | u8 tmp; |
| 304 | |
| 305 | if (!priv->warm) { |
| 306 | ret = -EFAULT; |
| 307 | goto error; |
| 308 | } |
| 309 | |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 310 | dev_dbg(&priv->i2c->dev, "%s: msg_len=%d\n", __func__, |
| 311 | diseqc_cmd->msg_len); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 312 | |
Antti Palosaari | 84431c2 | 2012-07-01 15:29:15 -0300 | [diff] [blame] | 313 | if (diseqc_cmd->msg_len < 3 || diseqc_cmd->msg_len > 6) { |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 314 | ret = -EINVAL; |
| 315 | goto error; |
| 316 | } |
| 317 | |
| 318 | /* wait LNB TX */ |
| 319 | for (i = 500, tmp = 0; i && !tmp; i--) { |
| 320 | ret = tda10071_rd_reg_mask(priv, 0x47, &tmp, 0x01); |
| 321 | if (ret) |
| 322 | goto error; |
| 323 | |
Antti Palosaari | d102b73 | 2011-09-13 11:51:23 -0300 | [diff] [blame] | 324 | usleep_range(10000, 20000); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 325 | } |
| 326 | |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 327 | dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 328 | |
| 329 | if (i == 0) { |
| 330 | ret = -ETIMEDOUT; |
| 331 | goto error; |
| 332 | } |
| 333 | |
| 334 | ret = tda10071_wr_reg_mask(priv, 0x47, 0x00, 0x01); |
| 335 | if (ret) |
| 336 | goto error; |
| 337 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 338 | cmd.args[0] = CMD_LNB_SEND_DISEQC; |
| 339 | cmd.args[1] = 0; |
| 340 | cmd.args[2] = 0; |
| 341 | cmd.args[3] = 0; |
| 342 | cmd.args[4] = 2; |
| 343 | cmd.args[5] = 0; |
| 344 | cmd.args[6] = diseqc_cmd->msg_len; |
| 345 | memcpy(&cmd.args[7], diseqc_cmd->msg, diseqc_cmd->msg_len); |
| 346 | cmd.len = 7 + diseqc_cmd->msg_len; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 347 | ret = tda10071_cmd_execute(priv, &cmd); |
| 348 | if (ret) |
| 349 | goto error; |
| 350 | |
| 351 | return ret; |
| 352 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 353 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 354 | return ret; |
| 355 | } |
| 356 | |
| 357 | static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe, |
| 358 | struct dvb_diseqc_slave_reply *reply) |
| 359 | { |
| 360 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 361 | struct tda10071_cmd cmd; |
| 362 | int ret, i; |
| 363 | u8 tmp; |
| 364 | |
| 365 | if (!priv->warm) { |
| 366 | ret = -EFAULT; |
| 367 | goto error; |
| 368 | } |
| 369 | |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 370 | dev_dbg(&priv->i2c->dev, "%s:\n", __func__); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 371 | |
| 372 | /* wait LNB RX */ |
| 373 | for (i = 500, tmp = 0; i && !tmp; i--) { |
| 374 | ret = tda10071_rd_reg_mask(priv, 0x47, &tmp, 0x02); |
| 375 | if (ret) |
| 376 | goto error; |
| 377 | |
Antti Palosaari | d102b73 | 2011-09-13 11:51:23 -0300 | [diff] [blame] | 378 | usleep_range(10000, 20000); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 379 | } |
| 380 | |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 381 | dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 382 | |
| 383 | if (i == 0) { |
| 384 | ret = -ETIMEDOUT; |
| 385 | goto error; |
| 386 | } |
| 387 | |
| 388 | /* reply len */ |
| 389 | ret = tda10071_rd_reg(priv, 0x46, &tmp); |
| 390 | if (ret) |
| 391 | goto error; |
| 392 | |
Peter Senna Tschudin | 8f5c997 | 2012-09-07 11:24:43 -0300 | [diff] [blame] | 393 | reply->msg_len = tmp & 0x1f; /* [4:0] */ |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 394 | if (reply->msg_len > sizeof(reply->msg)) |
| 395 | reply->msg_len = sizeof(reply->msg); /* truncate API max */ |
| 396 | |
| 397 | /* read reply */ |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 398 | cmd.args[0] = CMD_LNB_UPDATE_REPLY; |
| 399 | cmd.args[1] = 0; |
| 400 | cmd.len = 2; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 401 | ret = tda10071_cmd_execute(priv, &cmd); |
| 402 | if (ret) |
| 403 | goto error; |
| 404 | |
| 405 | ret = tda10071_rd_regs(priv, cmd.len, reply->msg, reply->msg_len); |
| 406 | if (ret) |
| 407 | goto error; |
| 408 | |
| 409 | return ret; |
| 410 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 411 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 412 | return ret; |
| 413 | } |
| 414 | |
| 415 | static int tda10071_diseqc_send_burst(struct dvb_frontend *fe, |
| 416 | fe_sec_mini_cmd_t fe_sec_mini_cmd) |
| 417 | { |
| 418 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 419 | struct tda10071_cmd cmd; |
| 420 | int ret, i; |
| 421 | u8 tmp, burst; |
| 422 | |
| 423 | if (!priv->warm) { |
| 424 | ret = -EFAULT; |
| 425 | goto error; |
| 426 | } |
| 427 | |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 428 | dev_dbg(&priv->i2c->dev, "%s: fe_sec_mini_cmd=%d\n", __func__, |
| 429 | fe_sec_mini_cmd); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 430 | |
| 431 | switch (fe_sec_mini_cmd) { |
| 432 | case SEC_MINI_A: |
| 433 | burst = 0; |
| 434 | break; |
| 435 | case SEC_MINI_B: |
| 436 | burst = 1; |
| 437 | break; |
| 438 | default: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 439 | dev_dbg(&priv->i2c->dev, "%s: invalid fe_sec_mini_cmd\n", |
| 440 | __func__); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 441 | ret = -EINVAL; |
| 442 | goto error; |
| 443 | } |
| 444 | |
| 445 | /* wait LNB TX */ |
| 446 | for (i = 500, tmp = 0; i && !tmp; i--) { |
| 447 | ret = tda10071_rd_reg_mask(priv, 0x47, &tmp, 0x01); |
| 448 | if (ret) |
| 449 | goto error; |
| 450 | |
Antti Palosaari | d102b73 | 2011-09-13 11:51:23 -0300 | [diff] [blame] | 451 | usleep_range(10000, 20000); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 452 | } |
| 453 | |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 454 | dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 455 | |
| 456 | if (i == 0) { |
| 457 | ret = -ETIMEDOUT; |
| 458 | goto error; |
| 459 | } |
| 460 | |
| 461 | ret = tda10071_wr_reg_mask(priv, 0x47, 0x00, 0x01); |
| 462 | if (ret) |
| 463 | goto error; |
| 464 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 465 | cmd.args[0] = CMD_LNB_SEND_TONEBURST; |
| 466 | cmd.args[1] = 0; |
| 467 | cmd.args[2] = burst; |
| 468 | cmd.len = 3; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 469 | ret = tda10071_cmd_execute(priv, &cmd); |
| 470 | if (ret) |
| 471 | goto error; |
| 472 | |
| 473 | return ret; |
| 474 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 475 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 476 | return ret; |
| 477 | } |
| 478 | |
| 479 | static int tda10071_read_status(struct dvb_frontend *fe, fe_status_t *status) |
| 480 | { |
| 481 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 482 | int ret; |
| 483 | u8 tmp; |
| 484 | |
| 485 | *status = 0; |
| 486 | |
| 487 | if (!priv->warm) { |
| 488 | ret = 0; |
| 489 | goto error; |
| 490 | } |
| 491 | |
| 492 | ret = tda10071_rd_reg(priv, 0x39, &tmp); |
| 493 | if (ret) |
| 494 | goto error; |
| 495 | |
Antti Palosaari | 0711560 | 2014-02-11 00:17:37 -0300 | [diff] [blame] | 496 | /* 0x39[0] tuner PLL */ |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 497 | if (tmp & 0x02) /* demod PLL */ |
Antti Palosaari | 0711560 | 2014-02-11 00:17:37 -0300 | [diff] [blame] | 498 | *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 499 | if (tmp & 0x04) /* viterbi or LDPC*/ |
| 500 | *status |= FE_HAS_VITERBI; |
| 501 | if (tmp & 0x08) /* RS or BCH */ |
| 502 | *status |= FE_HAS_SYNC | FE_HAS_LOCK; |
| 503 | |
| 504 | priv->fe_status = *status; |
| 505 | |
| 506 | return ret; |
| 507 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 508 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 509 | return ret; |
| 510 | } |
| 511 | |
| 512 | static int tda10071_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 513 | { |
| 514 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 515 | int ret; |
| 516 | u8 buf[2]; |
| 517 | |
| 518 | if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) { |
| 519 | *snr = 0; |
| 520 | ret = 0; |
| 521 | goto error; |
| 522 | } |
| 523 | |
| 524 | ret = tda10071_rd_regs(priv, 0x3a, buf, 2); |
| 525 | if (ret) |
| 526 | goto error; |
| 527 | |
| 528 | /* Es/No dBx10 */ |
| 529 | *snr = buf[0] << 8 | buf[1]; |
| 530 | |
| 531 | return ret; |
| 532 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 533 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 534 | return ret; |
| 535 | } |
| 536 | |
| 537 | static int tda10071_read_signal_strength(struct dvb_frontend *fe, u16 *strength) |
| 538 | { |
| 539 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 540 | struct tda10071_cmd cmd; |
| 541 | int ret; |
| 542 | u8 tmp; |
| 543 | |
| 544 | if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) { |
| 545 | *strength = 0; |
| 546 | ret = 0; |
| 547 | goto error; |
| 548 | } |
| 549 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 550 | cmd.args[0] = CMD_GET_AGCACC; |
| 551 | cmd.args[1] = 0; |
| 552 | cmd.len = 2; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 553 | ret = tda10071_cmd_execute(priv, &cmd); |
| 554 | if (ret) |
| 555 | goto error; |
| 556 | |
| 557 | /* input power estimate dBm */ |
| 558 | ret = tda10071_rd_reg(priv, 0x50, &tmp); |
| 559 | if (ret) |
| 560 | goto error; |
| 561 | |
| 562 | if (tmp < 181) |
| 563 | tmp = 181; /* -75 dBm */ |
| 564 | else if (tmp > 236) |
| 565 | tmp = 236; /* -20 dBm */ |
| 566 | |
| 567 | /* scale value to 0x0000-0xffff */ |
| 568 | *strength = (tmp-181) * 0xffff / (236-181); |
| 569 | |
| 570 | return ret; |
| 571 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 572 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 573 | return ret; |
| 574 | } |
| 575 | |
| 576 | static int tda10071_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 577 | { |
| 578 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 579 | struct tda10071_cmd cmd; |
| 580 | int ret, i, len; |
| 581 | u8 tmp, reg, buf[8]; |
| 582 | |
| 583 | if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) { |
| 584 | *ber = priv->ber = 0; |
| 585 | ret = 0; |
| 586 | goto error; |
| 587 | } |
| 588 | |
| 589 | switch (priv->delivery_system) { |
| 590 | case SYS_DVBS: |
| 591 | reg = 0x4c; |
| 592 | len = 8; |
| 593 | i = 1; |
| 594 | break; |
| 595 | case SYS_DVBS2: |
| 596 | reg = 0x4d; |
| 597 | len = 4; |
| 598 | i = 0; |
| 599 | break; |
| 600 | default: |
| 601 | *ber = priv->ber = 0; |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | ret = tda10071_rd_reg(priv, reg, &tmp); |
| 606 | if (ret) |
| 607 | goto error; |
| 608 | |
| 609 | if (priv->meas_count[i] == tmp) { |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 610 | dev_dbg(&priv->i2c->dev, "%s: meas not ready=%02x\n", __func__, |
| 611 | tmp); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 612 | *ber = priv->ber; |
| 613 | return 0; |
| 614 | } else { |
| 615 | priv->meas_count[i] = tmp; |
| 616 | } |
| 617 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 618 | cmd.args[0] = CMD_BER_UPDATE_COUNTERS; |
| 619 | cmd.args[1] = 0; |
| 620 | cmd.args[2] = i; |
| 621 | cmd.len = 3; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 622 | ret = tda10071_cmd_execute(priv, &cmd); |
| 623 | if (ret) |
| 624 | goto error; |
| 625 | |
| 626 | ret = tda10071_rd_regs(priv, cmd.len, buf, len); |
| 627 | if (ret) |
| 628 | goto error; |
| 629 | |
| 630 | if (priv->delivery_system == SYS_DVBS) { |
| 631 | *ber = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; |
| 632 | priv->ucb += (buf[4] << 8) | buf[5]; |
| 633 | } else { |
| 634 | *ber = (buf[0] << 8) | buf[1]; |
| 635 | } |
| 636 | priv->ber = *ber; |
| 637 | |
| 638 | return ret; |
| 639 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 640 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 641 | return ret; |
| 642 | } |
| 643 | |
| 644 | static int tda10071_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
| 645 | { |
| 646 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 647 | int ret = 0; |
| 648 | |
| 649 | if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) { |
| 650 | *ucblocks = 0; |
| 651 | goto error; |
| 652 | } |
| 653 | |
| 654 | /* UCB is updated when BER is read. Assume BER is read anyway. */ |
| 655 | |
| 656 | *ucblocks = priv->ucb; |
| 657 | |
| 658 | return ret; |
| 659 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 660 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 661 | return ret; |
| 662 | } |
| 663 | |
Mauro Carvalho Chehab | b2a29b5 | 2011-12-26 14:46:22 -0300 | [diff] [blame] | 664 | static int tda10071_set_frontend(struct dvb_frontend *fe) |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 665 | { |
| 666 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 667 | struct tda10071_cmd cmd; |
| 668 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 669 | int ret, i; |
| 670 | u8 mode, rolloff, pilot, inversion, div; |
Antti Palosaari | db4175a | 2014-07-04 05:44:39 -0300 | [diff] [blame] | 671 | fe_modulation_t modulation; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 672 | |
Antti Palosaari | 116802f | 2014-02-11 15:13:46 -0300 | [diff] [blame] | 673 | dev_dbg(&priv->i2c->dev, |
| 674 | "%s: delivery_system=%d modulation=%d frequency=%d symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n", |
| 675 | __func__, c->delivery_system, c->modulation, |
| 676 | c->frequency, c->symbol_rate, c->inversion, c->pilot, |
| 677 | c->rolloff); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 678 | |
| 679 | priv->delivery_system = SYS_UNDEFINED; |
| 680 | |
| 681 | if (!priv->warm) { |
| 682 | ret = -EFAULT; |
| 683 | goto error; |
| 684 | } |
| 685 | |
| 686 | switch (c->inversion) { |
| 687 | case INVERSION_OFF: |
| 688 | inversion = 1; |
| 689 | break; |
| 690 | case INVERSION_ON: |
| 691 | inversion = 0; |
| 692 | break; |
| 693 | case INVERSION_AUTO: |
| 694 | /* 2 = auto; try first on then off |
| 695 | * 3 = auto; try first off then on */ |
| 696 | inversion = 3; |
| 697 | break; |
| 698 | default: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 699 | dev_dbg(&priv->i2c->dev, "%s: invalid inversion\n", __func__); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 700 | ret = -EINVAL; |
| 701 | goto error; |
| 702 | } |
| 703 | |
| 704 | switch (c->delivery_system) { |
| 705 | case SYS_DVBS: |
Antti Palosaari | db4175a | 2014-07-04 05:44:39 -0300 | [diff] [blame] | 706 | modulation = QPSK; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 707 | rolloff = 0; |
| 708 | pilot = 2; |
| 709 | break; |
| 710 | case SYS_DVBS2: |
Antti Palosaari | db4175a | 2014-07-04 05:44:39 -0300 | [diff] [blame] | 711 | modulation = c->modulation; |
| 712 | |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 713 | switch (c->rolloff) { |
| 714 | case ROLLOFF_20: |
| 715 | rolloff = 2; |
| 716 | break; |
| 717 | case ROLLOFF_25: |
| 718 | rolloff = 1; |
| 719 | break; |
| 720 | case ROLLOFF_35: |
| 721 | rolloff = 0; |
| 722 | break; |
| 723 | case ROLLOFF_AUTO: |
| 724 | default: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 725 | dev_dbg(&priv->i2c->dev, "%s: invalid rolloff\n", |
| 726 | __func__); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 727 | ret = -EINVAL; |
| 728 | goto error; |
| 729 | } |
| 730 | |
| 731 | switch (c->pilot) { |
| 732 | case PILOT_OFF: |
| 733 | pilot = 0; |
| 734 | break; |
| 735 | case PILOT_ON: |
| 736 | pilot = 1; |
| 737 | break; |
| 738 | case PILOT_AUTO: |
| 739 | pilot = 2; |
| 740 | break; |
| 741 | default: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 742 | dev_dbg(&priv->i2c->dev, "%s: invalid pilot\n", |
| 743 | __func__); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 744 | ret = -EINVAL; |
| 745 | goto error; |
| 746 | } |
| 747 | break; |
| 748 | default: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 749 | dev_dbg(&priv->i2c->dev, "%s: invalid delivery_system\n", |
| 750 | __func__); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 751 | ret = -EINVAL; |
| 752 | goto error; |
| 753 | } |
| 754 | |
| 755 | for (i = 0, mode = 0xff; i < ARRAY_SIZE(TDA10071_MODCOD); i++) { |
| 756 | if (c->delivery_system == TDA10071_MODCOD[i].delivery_system && |
Antti Palosaari | db4175a | 2014-07-04 05:44:39 -0300 | [diff] [blame] | 757 | modulation == TDA10071_MODCOD[i].modulation && |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 758 | c->fec_inner == TDA10071_MODCOD[i].fec) { |
| 759 | mode = TDA10071_MODCOD[i].val; |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 760 | dev_dbg(&priv->i2c->dev, "%s: mode found=%02x\n", |
| 761 | __func__, mode); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 762 | break; |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | if (mode == 0xff) { |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 767 | dev_dbg(&priv->i2c->dev, "%s: invalid parameter combination\n", |
| 768 | __func__); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 769 | ret = -EINVAL; |
| 770 | goto error; |
| 771 | } |
| 772 | |
| 773 | if (c->symbol_rate <= 5000000) |
| 774 | div = 14; |
| 775 | else |
| 776 | div = 4; |
| 777 | |
| 778 | ret = tda10071_wr_reg(priv, 0x81, div); |
| 779 | if (ret) |
| 780 | goto error; |
| 781 | |
| 782 | ret = tda10071_wr_reg(priv, 0xe3, div); |
| 783 | if (ret) |
| 784 | goto error; |
| 785 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 786 | cmd.args[0] = CMD_CHANGE_CHANNEL; |
| 787 | cmd.args[1] = 0; |
| 788 | cmd.args[2] = mode; |
| 789 | cmd.args[3] = (c->frequency >> 16) & 0xff; |
| 790 | cmd.args[4] = (c->frequency >> 8) & 0xff; |
| 791 | cmd.args[5] = (c->frequency >> 0) & 0xff; |
| 792 | cmd.args[6] = ((c->symbol_rate / 1000) >> 8) & 0xff; |
| 793 | cmd.args[7] = ((c->symbol_rate / 1000) >> 0) & 0xff; |
| 794 | cmd.args[8] = (tda10071_ops.info.frequency_tolerance >> 8) & 0xff; |
| 795 | cmd.args[9] = (tda10071_ops.info.frequency_tolerance >> 0) & 0xff; |
| 796 | cmd.args[10] = rolloff; |
| 797 | cmd.args[11] = inversion; |
| 798 | cmd.args[12] = pilot; |
| 799 | cmd.args[13] = 0x00; |
| 800 | cmd.args[14] = 0x00; |
| 801 | cmd.len = 15; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 802 | ret = tda10071_cmd_execute(priv, &cmd); |
| 803 | if (ret) |
| 804 | goto error; |
| 805 | |
| 806 | priv->delivery_system = c->delivery_system; |
| 807 | |
| 808 | return ret; |
| 809 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 810 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 811 | return ret; |
| 812 | } |
| 813 | |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 814 | static int tda10071_get_frontend(struct dvb_frontend *fe) |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 815 | { |
| 816 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 817 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 818 | int ret, i; |
| 819 | u8 buf[5], tmp; |
| 820 | |
| 821 | if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) { |
| 822 | ret = -EFAULT; |
| 823 | goto error; |
| 824 | } |
| 825 | |
| 826 | ret = tda10071_rd_regs(priv, 0x30, buf, 5); |
| 827 | if (ret) |
| 828 | goto error; |
| 829 | |
| 830 | tmp = buf[0] & 0x3f; |
| 831 | for (i = 0; i < ARRAY_SIZE(TDA10071_MODCOD); i++) { |
| 832 | if (tmp == TDA10071_MODCOD[i].val) { |
| 833 | c->modulation = TDA10071_MODCOD[i].modulation; |
| 834 | c->fec_inner = TDA10071_MODCOD[i].fec; |
| 835 | c->delivery_system = TDA10071_MODCOD[i].delivery_system; |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | switch ((buf[1] >> 0) & 0x01) { |
| 840 | case 0: |
Antti Palosaari | b32725e | 2014-07-07 09:52:28 -0300 | [diff] [blame] | 841 | c->inversion = INVERSION_ON; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 842 | break; |
| 843 | case 1: |
Antti Palosaari | b32725e | 2014-07-07 09:52:28 -0300 | [diff] [blame] | 844 | c->inversion = INVERSION_OFF; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 845 | break; |
| 846 | } |
| 847 | |
| 848 | switch ((buf[1] >> 7) & 0x01) { |
| 849 | case 0: |
| 850 | c->pilot = PILOT_OFF; |
| 851 | break; |
| 852 | case 1: |
| 853 | c->pilot = PILOT_ON; |
| 854 | break; |
| 855 | } |
| 856 | |
| 857 | c->frequency = (buf[2] << 16) | (buf[3] << 8) | (buf[4] << 0); |
| 858 | |
| 859 | ret = tda10071_rd_regs(priv, 0x52, buf, 3); |
| 860 | if (ret) |
| 861 | goto error; |
| 862 | |
Antti Palosaari | c2c1a6e | 2014-07-08 02:48:28 -0300 | [diff] [blame] | 863 | c->symbol_rate = ((buf[0] << 16) | (buf[1] << 8) | (buf[2] << 0)) * 1000; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 864 | |
| 865 | return ret; |
| 866 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 867 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 868 | return ret; |
| 869 | } |
| 870 | |
| 871 | static int tda10071_init(struct dvb_frontend *fe) |
| 872 | { |
| 873 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 874 | struct tda10071_cmd cmd; |
Antti Palosaari | 75d404e | 2011-09-13 07:30:11 -0300 | [diff] [blame] | 875 | int ret, i, len, remaining, fw_size; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 876 | const struct firmware *fw; |
Antti Palosaari | 03f4efc | 2012-09-12 11:37:29 -0300 | [diff] [blame] | 877 | u8 *fw_file = TDA10071_FIRMWARE; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 878 | u8 tmp, buf[4]; |
| 879 | struct tda10071_reg_val_mask tab[] = { |
| 880 | { 0xcd, 0x00, 0x07 }, |
| 881 | { 0x80, 0x00, 0x02 }, |
| 882 | { 0xcd, 0x00, 0xc0 }, |
| 883 | { 0xce, 0x00, 0x1b }, |
| 884 | { 0x9d, 0x00, 0x01 }, |
| 885 | { 0x9d, 0x00, 0x02 }, |
| 886 | { 0x9e, 0x00, 0x01 }, |
| 887 | { 0x87, 0x00, 0x80 }, |
| 888 | { 0xce, 0x00, 0x08 }, |
| 889 | { 0xce, 0x00, 0x10 }, |
| 890 | }; |
| 891 | struct tda10071_reg_val_mask tab2[] = { |
| 892 | { 0xf1, 0x70, 0xff }, |
| 893 | { 0x88, priv->cfg.pll_multiplier, 0x3f }, |
| 894 | { 0x89, 0x00, 0x10 }, |
| 895 | { 0x89, 0x10, 0x10 }, |
| 896 | { 0xc0, 0x01, 0x01 }, |
| 897 | { 0xc0, 0x00, 0x01 }, |
| 898 | { 0xe0, 0xff, 0xff }, |
| 899 | { 0xe0, 0x00, 0xff }, |
| 900 | { 0x96, 0x1e, 0x7e }, |
| 901 | { 0x8b, 0x08, 0x08 }, |
| 902 | { 0x8b, 0x00, 0x08 }, |
| 903 | { 0x8f, 0x1a, 0x7e }, |
| 904 | { 0x8c, 0x68, 0xff }, |
| 905 | { 0x8d, 0x08, 0xff }, |
| 906 | { 0x8e, 0x4c, 0xff }, |
| 907 | { 0x8f, 0x01, 0x01 }, |
| 908 | { 0x8b, 0x04, 0x04 }, |
| 909 | { 0x8b, 0x00, 0x04 }, |
| 910 | { 0x87, 0x05, 0x07 }, |
| 911 | { 0x80, 0x00, 0x20 }, |
| 912 | { 0xc8, 0x01, 0xff }, |
| 913 | { 0xb4, 0x47, 0xff }, |
| 914 | { 0xb5, 0x9c, 0xff }, |
| 915 | { 0xb6, 0x7d, 0xff }, |
| 916 | { 0xba, 0x00, 0x03 }, |
| 917 | { 0xb7, 0x47, 0xff }, |
| 918 | { 0xb8, 0x9c, 0xff }, |
| 919 | { 0xb9, 0x7d, 0xff }, |
| 920 | { 0xba, 0x00, 0x0c }, |
| 921 | { 0xc8, 0x00, 0xff }, |
| 922 | { 0xcd, 0x00, 0x04 }, |
| 923 | { 0xcd, 0x00, 0x20 }, |
| 924 | { 0xe8, 0x02, 0xff }, |
| 925 | { 0xcf, 0x20, 0xff }, |
| 926 | { 0x9b, 0xd7, 0xff }, |
| 927 | { 0x9a, 0x01, 0x03 }, |
| 928 | { 0xa8, 0x05, 0x0f }, |
| 929 | { 0xa8, 0x65, 0xf0 }, |
| 930 | { 0xa6, 0xa0, 0xf0 }, |
| 931 | { 0x9d, 0x50, 0xfc }, |
| 932 | { 0x9e, 0x20, 0xe0 }, |
| 933 | { 0xa3, 0x1c, 0x7c }, |
| 934 | { 0xd5, 0x03, 0x03 }, |
| 935 | }; |
| 936 | |
Andreas Matthies | 6894c07 | 2013-09-30 13:08:16 -0300 | [diff] [blame] | 937 | if (priv->warm) { |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 938 | /* warm state - wake up device from sleep */ |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 939 | |
| 940 | for (i = 0; i < ARRAY_SIZE(tab); i++) { |
| 941 | ret = tda10071_wr_reg_mask(priv, tab[i].reg, |
| 942 | tab[i].val, tab[i].mask); |
| 943 | if (ret) |
| 944 | goto error; |
| 945 | } |
| 946 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 947 | cmd.args[0] = CMD_SET_SLEEP_MODE; |
| 948 | cmd.args[1] = 0; |
| 949 | cmd.args[2] = 0; |
| 950 | cmd.len = 3; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 951 | ret = tda10071_cmd_execute(priv, &cmd); |
| 952 | if (ret) |
| 953 | goto error; |
| 954 | } else { |
| 955 | /* cold state - try to download firmware */ |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 956 | |
| 957 | /* request the firmware, this will block and timeout */ |
| 958 | ret = request_firmware(&fw, fw_file, priv->i2c->dev.parent); |
| 959 | if (ret) { |
Antti Palosaari | 116802f | 2014-02-11 15:13:46 -0300 | [diff] [blame] | 960 | dev_err(&priv->i2c->dev, |
| 961 | "%s: did not find the firmware file. (%s) Please see linux/Documentation/dvb/ for more details on firmware-problems. (%d)\n", |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 962 | KBUILD_MODNAME, fw_file, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 963 | goto error; |
| 964 | } |
| 965 | |
| 966 | /* init */ |
| 967 | for (i = 0; i < ARRAY_SIZE(tab2); i++) { |
| 968 | ret = tda10071_wr_reg_mask(priv, tab2[i].reg, |
| 969 | tab2[i].val, tab2[i].mask); |
| 970 | if (ret) |
| 971 | goto error_release_firmware; |
| 972 | } |
| 973 | |
| 974 | /* download firmware */ |
| 975 | ret = tda10071_wr_reg(priv, 0xe0, 0x7f); |
| 976 | if (ret) |
| 977 | goto error_release_firmware; |
| 978 | |
| 979 | ret = tda10071_wr_reg(priv, 0xf7, 0x81); |
| 980 | if (ret) |
| 981 | goto error_release_firmware; |
| 982 | |
| 983 | ret = tda10071_wr_reg(priv, 0xf8, 0x00); |
| 984 | if (ret) |
| 985 | goto error_release_firmware; |
| 986 | |
| 987 | ret = tda10071_wr_reg(priv, 0xf9, 0x00); |
| 988 | if (ret) |
| 989 | goto error_release_firmware; |
| 990 | |
Antti Palosaari | 116802f | 2014-02-11 15:13:46 -0300 | [diff] [blame] | 991 | dev_info(&priv->i2c->dev, |
| 992 | "%s: found a '%s' in cold state, will try to load a firmware\n", |
| 993 | KBUILD_MODNAME, tda10071_ops.info.name); |
| 994 | dev_info(&priv->i2c->dev, |
| 995 | "%s: downloading firmware from file '%s'\n", |
| 996 | KBUILD_MODNAME, fw_file); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 997 | |
Antti Palosaari | 75d404e | 2011-09-13 07:30:11 -0300 | [diff] [blame] | 998 | /* do not download last byte */ |
| 999 | fw_size = fw->size - 1; |
| 1000 | |
| 1001 | for (remaining = fw_size; remaining > 0; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1002 | remaining -= (priv->cfg.i2c_wr_max - 1)) { |
| 1003 | len = remaining; |
| 1004 | if (len > (priv->cfg.i2c_wr_max - 1)) |
| 1005 | len = (priv->cfg.i2c_wr_max - 1); |
| 1006 | |
| 1007 | ret = tda10071_wr_regs(priv, 0xfa, |
Antti Palosaari | 75d404e | 2011-09-13 07:30:11 -0300 | [diff] [blame] | 1008 | (u8 *) &fw->data[fw_size - remaining], len); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1009 | if (ret) { |
Antti Palosaari | 116802f | 2014-02-11 15:13:46 -0300 | [diff] [blame] | 1010 | dev_err(&priv->i2c->dev, |
| 1011 | "%s: firmware download failed=%d\n", |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 1012 | KBUILD_MODNAME, ret); |
Dan Carpenter | a3a528b | 2014-01-30 09:00:34 -0300 | [diff] [blame] | 1013 | goto error_release_firmware; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1014 | } |
| 1015 | } |
| 1016 | release_firmware(fw); |
| 1017 | |
| 1018 | ret = tda10071_wr_reg(priv, 0xf7, 0x0c); |
| 1019 | if (ret) |
| 1020 | goto error; |
| 1021 | |
| 1022 | ret = tda10071_wr_reg(priv, 0xe0, 0x00); |
| 1023 | if (ret) |
| 1024 | goto error; |
| 1025 | |
| 1026 | /* wait firmware start */ |
| 1027 | msleep(250); |
| 1028 | |
| 1029 | /* firmware status */ |
| 1030 | ret = tda10071_rd_reg(priv, 0x51, &tmp); |
| 1031 | if (ret) |
| 1032 | goto error; |
| 1033 | |
| 1034 | if (tmp) { |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 1035 | dev_info(&priv->i2c->dev, "%s: firmware did not run\n", |
| 1036 | KBUILD_MODNAME); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1037 | ret = -EFAULT; |
| 1038 | goto error; |
| 1039 | } else { |
Mauro Carvalho Chehab | 79a5ee7 | 2014-09-03 15:26:07 -0300 | [diff] [blame] | 1040 | priv->warm = true; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1041 | } |
| 1042 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 1043 | cmd.args[0] = CMD_GET_FW_VERSION; |
| 1044 | cmd.len = 1; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1045 | ret = tda10071_cmd_execute(priv, &cmd); |
| 1046 | if (ret) |
| 1047 | goto error; |
| 1048 | |
| 1049 | ret = tda10071_rd_regs(priv, cmd.len, buf, 4); |
| 1050 | if (ret) |
| 1051 | goto error; |
| 1052 | |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 1053 | dev_info(&priv->i2c->dev, "%s: firmware version %d.%d.%d.%d\n", |
| 1054 | KBUILD_MODNAME, buf[0], buf[1], buf[2], buf[3]); |
| 1055 | dev_info(&priv->i2c->dev, "%s: found a '%s' in warm state\n", |
| 1056 | KBUILD_MODNAME, tda10071_ops.info.name); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1057 | |
| 1058 | ret = tda10071_rd_regs(priv, 0x81, buf, 2); |
| 1059 | if (ret) |
| 1060 | goto error; |
| 1061 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 1062 | cmd.args[0] = CMD_DEMOD_INIT; |
| 1063 | cmd.args[1] = ((priv->cfg.xtal / 1000) >> 8) & 0xff; |
| 1064 | cmd.args[2] = ((priv->cfg.xtal / 1000) >> 0) & 0xff; |
| 1065 | cmd.args[3] = buf[0]; |
| 1066 | cmd.args[4] = buf[1]; |
| 1067 | cmd.args[5] = priv->cfg.pll_multiplier; |
| 1068 | cmd.args[6] = priv->cfg.spec_inv; |
| 1069 | cmd.args[7] = 0x00; |
| 1070 | cmd.len = 8; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1071 | ret = tda10071_cmd_execute(priv, &cmd); |
| 1072 | if (ret) |
| 1073 | goto error; |
| 1074 | |
Antti Palosaari | 116802f | 2014-02-11 15:13:46 -0300 | [diff] [blame] | 1075 | if (priv->cfg.tuner_i2c_addr) |
| 1076 | tmp = priv->cfg.tuner_i2c_addr; |
| 1077 | else |
| 1078 | tmp = 0x14; |
| 1079 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 1080 | cmd.args[0] = CMD_TUNER_INIT; |
| 1081 | cmd.args[1] = 0x00; |
| 1082 | cmd.args[2] = 0x00; |
| 1083 | cmd.args[3] = 0x00; |
| 1084 | cmd.args[4] = 0x00; |
Antti Palosaari | 116802f | 2014-02-11 15:13:46 -0300 | [diff] [blame] | 1085 | cmd.args[5] = tmp; |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 1086 | cmd.args[6] = 0x00; |
| 1087 | cmd.args[7] = 0x03; |
| 1088 | cmd.args[8] = 0x02; |
| 1089 | cmd.args[9] = 0x02; |
| 1090 | cmd.args[10] = 0x00; |
| 1091 | cmd.args[11] = 0x00; |
| 1092 | cmd.args[12] = 0x00; |
| 1093 | cmd.args[13] = 0x00; |
| 1094 | cmd.args[14] = 0x00; |
| 1095 | cmd.len = 15; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1096 | ret = tda10071_cmd_execute(priv, &cmd); |
| 1097 | if (ret) |
| 1098 | goto error; |
| 1099 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 1100 | cmd.args[0] = CMD_MPEG_CONFIG; |
| 1101 | cmd.args[1] = 0; |
| 1102 | cmd.args[2] = priv->cfg.ts_mode; |
| 1103 | cmd.args[3] = 0x00; |
| 1104 | cmd.args[4] = 0x04; |
| 1105 | cmd.args[5] = 0x00; |
| 1106 | cmd.len = 6; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1107 | ret = tda10071_cmd_execute(priv, &cmd); |
| 1108 | if (ret) |
| 1109 | goto error; |
| 1110 | |
| 1111 | ret = tda10071_wr_reg_mask(priv, 0xf0, 0x01, 0x01); |
| 1112 | if (ret) |
| 1113 | goto error; |
| 1114 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 1115 | cmd.args[0] = CMD_LNB_CONFIG; |
| 1116 | cmd.args[1] = 0; |
| 1117 | cmd.args[2] = 150; |
| 1118 | cmd.args[3] = 3; |
| 1119 | cmd.args[4] = 22; |
| 1120 | cmd.args[5] = 1; |
| 1121 | cmd.args[6] = 1; |
| 1122 | cmd.args[7] = 30; |
| 1123 | cmd.args[8] = 30; |
| 1124 | cmd.args[9] = 30; |
| 1125 | cmd.args[10] = 30; |
| 1126 | cmd.len = 11; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1127 | ret = tda10071_cmd_execute(priv, &cmd); |
| 1128 | if (ret) |
| 1129 | goto error; |
| 1130 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 1131 | cmd.args[0] = CMD_BER_CONTROL; |
| 1132 | cmd.args[1] = 0; |
| 1133 | cmd.args[2] = 14; |
| 1134 | cmd.args[3] = 14; |
| 1135 | cmd.len = 4; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1136 | ret = tda10071_cmd_execute(priv, &cmd); |
| 1137 | if (ret) |
| 1138 | goto error; |
| 1139 | } |
| 1140 | |
| 1141 | return ret; |
| 1142 | error_release_firmware: |
| 1143 | release_firmware(fw); |
| 1144 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 1145 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1146 | return ret; |
| 1147 | } |
| 1148 | |
| 1149 | static int tda10071_sleep(struct dvb_frontend *fe) |
| 1150 | { |
| 1151 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 1152 | struct tda10071_cmd cmd; |
| 1153 | int ret, i; |
| 1154 | struct tda10071_reg_val_mask tab[] = { |
| 1155 | { 0xcd, 0x07, 0x07 }, |
| 1156 | { 0x80, 0x02, 0x02 }, |
| 1157 | { 0xcd, 0xc0, 0xc0 }, |
| 1158 | { 0xce, 0x1b, 0x1b }, |
| 1159 | { 0x9d, 0x01, 0x01 }, |
| 1160 | { 0x9d, 0x02, 0x02 }, |
| 1161 | { 0x9e, 0x01, 0x01 }, |
| 1162 | { 0x87, 0x80, 0x80 }, |
| 1163 | { 0xce, 0x08, 0x08 }, |
| 1164 | { 0xce, 0x10, 0x10 }, |
| 1165 | }; |
| 1166 | |
| 1167 | if (!priv->warm) { |
| 1168 | ret = -EFAULT; |
| 1169 | goto error; |
| 1170 | } |
| 1171 | |
Antti Palosaari | 21c8ba3 | 2012-07-01 15:59:13 -0300 | [diff] [blame] | 1172 | cmd.args[0] = CMD_SET_SLEEP_MODE; |
| 1173 | cmd.args[1] = 0; |
| 1174 | cmd.args[2] = 1; |
| 1175 | cmd.len = 3; |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1176 | ret = tda10071_cmd_execute(priv, &cmd); |
| 1177 | if (ret) |
| 1178 | goto error; |
| 1179 | |
| 1180 | for (i = 0; i < ARRAY_SIZE(tab); i++) { |
| 1181 | ret = tda10071_wr_reg_mask(priv, tab[i].reg, tab[i].val, |
| 1182 | tab[i].mask); |
| 1183 | if (ret) |
| 1184 | goto error; |
| 1185 | } |
| 1186 | |
| 1187 | return ret; |
| 1188 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 1189 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1190 | return ret; |
| 1191 | } |
| 1192 | |
| 1193 | static int tda10071_get_tune_settings(struct dvb_frontend *fe, |
| 1194 | struct dvb_frontend_tune_settings *s) |
| 1195 | { |
| 1196 | s->min_delay_ms = 8000; |
| 1197 | s->step_size = 0; |
| 1198 | s->max_drift = 0; |
| 1199 | |
| 1200 | return 0; |
| 1201 | } |
| 1202 | |
| 1203 | static void tda10071_release(struct dvb_frontend *fe) |
| 1204 | { |
| 1205 | struct tda10071_priv *priv = fe->demodulator_priv; |
| 1206 | kfree(priv); |
| 1207 | } |
| 1208 | |
| 1209 | struct dvb_frontend *tda10071_attach(const struct tda10071_config *config, |
| 1210 | struct i2c_adapter *i2c) |
| 1211 | { |
| 1212 | int ret; |
| 1213 | struct tda10071_priv *priv = NULL; |
| 1214 | u8 tmp; |
| 1215 | |
| 1216 | /* allocate memory for the internal priv */ |
| 1217 | priv = kzalloc(sizeof(struct tda10071_priv), GFP_KERNEL); |
| 1218 | if (priv == NULL) { |
| 1219 | ret = -ENOMEM; |
| 1220 | goto error; |
| 1221 | } |
| 1222 | |
Michael Krufky | 41f55d5 | 2012-12-16 19:37:11 -0300 | [diff] [blame] | 1223 | /* make sure demod i2c address is specified */ |
| 1224 | if (!config->demod_i2c_addr) { |
Antti Palosaari | 116802f | 2014-02-11 15:13:46 -0300 | [diff] [blame] | 1225 | dev_dbg(&i2c->dev, "%s: invalid demod i2c address\n", __func__); |
Mauro Carvalho Chehab | 1c12bf8 | 2012-12-21 14:43:19 -0200 | [diff] [blame] | 1226 | ret = -EINVAL; |
Michael Krufky | 41f55d5 | 2012-12-16 19:37:11 -0300 | [diff] [blame] | 1227 | goto error; |
| 1228 | } |
| 1229 | |
| 1230 | /* make sure tuner i2c address is specified */ |
| 1231 | if (!config->tuner_i2c_addr) { |
Antti Palosaari | 116802f | 2014-02-11 15:13:46 -0300 | [diff] [blame] | 1232 | dev_dbg(&i2c->dev, "%s: invalid tuner i2c address\n", __func__); |
Mauro Carvalho Chehab | 1c12bf8 | 2012-12-21 14:43:19 -0200 | [diff] [blame] | 1233 | ret = -EINVAL; |
Michael Krufky | 41f55d5 | 2012-12-16 19:37:11 -0300 | [diff] [blame] | 1234 | goto error; |
| 1235 | } |
| 1236 | |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1237 | /* setup the priv */ |
| 1238 | priv->i2c = i2c; |
| 1239 | memcpy(&priv->cfg, config, sizeof(struct tda10071_config)); |
| 1240 | |
| 1241 | /* chip ID */ |
| 1242 | ret = tda10071_rd_reg(priv, 0xff, &tmp); |
| 1243 | if (ret || tmp != 0x0f) |
| 1244 | goto error; |
| 1245 | |
| 1246 | /* chip type */ |
| 1247 | ret = tda10071_rd_reg(priv, 0xdd, &tmp); |
| 1248 | if (ret || tmp != 0x00) |
| 1249 | goto error; |
| 1250 | |
| 1251 | /* chip version */ |
| 1252 | ret = tda10071_rd_reg(priv, 0xfe, &tmp); |
| 1253 | if (ret || tmp != 0x01) |
| 1254 | goto error; |
| 1255 | |
| 1256 | /* create dvb_frontend */ |
| 1257 | memcpy(&priv->fe.ops, &tda10071_ops, sizeof(struct dvb_frontend_ops)); |
| 1258 | priv->fe.demodulator_priv = priv; |
| 1259 | |
| 1260 | return &priv->fe; |
| 1261 | error: |
Antti Palosaari | 279bba0 | 2012-07-02 03:46:46 -0300 | [diff] [blame] | 1262 | dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1263 | kfree(priv); |
| 1264 | return NULL; |
| 1265 | } |
| 1266 | EXPORT_SYMBOL(tda10071_attach); |
| 1267 | |
| 1268 | static struct dvb_frontend_ops tda10071_ops = { |
Antti Palosaari | 2b49fad | 2012-03-12 18:21:20 -0300 | [diff] [blame] | 1269 | .delsys = { SYS_DVBS, SYS_DVBS2 }, |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1270 | .info = { |
| 1271 | .name = "NXP TDA10071", |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1272 | .frequency_min = 950000, |
| 1273 | .frequency_max = 2150000, |
| 1274 | .frequency_tolerance = 5000, |
| 1275 | .symbol_rate_min = 1000000, |
| 1276 | .symbol_rate_max = 45000000, |
| 1277 | .caps = FE_CAN_INVERSION_AUTO | |
| 1278 | FE_CAN_FEC_1_2 | |
| 1279 | FE_CAN_FEC_2_3 | |
| 1280 | FE_CAN_FEC_3_4 | |
| 1281 | FE_CAN_FEC_4_5 | |
| 1282 | FE_CAN_FEC_5_6 | |
| 1283 | FE_CAN_FEC_6_7 | |
| 1284 | FE_CAN_FEC_7_8 | |
| 1285 | FE_CAN_FEC_8_9 | |
| 1286 | FE_CAN_FEC_AUTO | |
| 1287 | FE_CAN_QPSK | |
| 1288 | FE_CAN_RECOVER | |
| 1289 | FE_CAN_2G_MODULATION |
| 1290 | }, |
| 1291 | |
| 1292 | .release = tda10071_release, |
| 1293 | |
| 1294 | .get_tune_settings = tda10071_get_tune_settings, |
| 1295 | |
| 1296 | .init = tda10071_init, |
| 1297 | .sleep = tda10071_sleep, |
| 1298 | |
Mauro Carvalho Chehab | b2a29b5 | 2011-12-26 14:46:22 -0300 | [diff] [blame] | 1299 | .set_frontend = tda10071_set_frontend, |
| 1300 | .get_frontend = tda10071_get_frontend, |
Antti Palosaari | de8e420 | 2011-08-01 01:07:39 -0300 | [diff] [blame] | 1301 | |
| 1302 | .read_status = tda10071_read_status, |
| 1303 | .read_snr = tda10071_read_snr, |
| 1304 | .read_signal_strength = tda10071_read_signal_strength, |
| 1305 | .read_ber = tda10071_read_ber, |
| 1306 | .read_ucblocks = tda10071_read_ucblocks, |
| 1307 | |
| 1308 | .diseqc_send_master_cmd = tda10071_diseqc_send_master_cmd, |
| 1309 | .diseqc_recv_slave_reply = tda10071_diseqc_recv_slave_reply, |
| 1310 | .diseqc_send_burst = tda10071_diseqc_send_burst, |
| 1311 | |
| 1312 | .set_tone = tda10071_set_tone, |
| 1313 | .set_voltage = tda10071_set_voltage, |
| 1314 | }; |
| 1315 | |
| 1316 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 1317 | MODULE_DESCRIPTION("NXP TDA10071 DVB-S/S2 demodulator driver"); |
| 1318 | MODULE_LICENSE("GPL"); |
Antti Palosaari | 03f4efc | 2012-09-12 11:37:29 -0300 | [diff] [blame] | 1319 | MODULE_FIRMWARE(TDA10071_FIRMWARE); |